alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 1 | /* |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 2 | * Copyright (C) 2004-2013 Savoir-Faire Linux Inc. |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 3 | * |
| 4 | * Author: Adrien Beraud <adrien.beraud@gmail.com> |
alision | 11e8e16 | 2013-05-28 10:33:14 -0400 | [diff] [blame] | 5 | * Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | * |
| 21 | * Additional permission under GNU GPL version 3 section 7: |
| 22 | * |
| 23 | * If you modify this program, or any covered work, by linking or |
| 24 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 25 | * modified version of that library), containing parts covered by the |
| 26 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 27 | * grants you additional permission to convey the resulting work. |
| 28 | * Corresponding Source for a non-source form of such a combination |
| 29 | * shall include the source code for the parts of OpenSSL used as well |
| 30 | * as that of the covered work. |
| 31 | */ |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 32 | package org.sflphone.client; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 33 | |
Alexandre Lision | 3557713 | 2013-12-06 15:21:15 -0500 | [diff] [blame] | 34 | import java.io.File; |
| 35 | import java.io.FileOutputStream; |
| 36 | import java.io.IOException; |
| 37 | import java.io.InputStream; |
Alexandre Lision | 5ed2c97 | 2013-10-11 15:36:33 -0400 | [diff] [blame] | 38 | import java.io.InvalidObjectException; |
Alexandre Lision | 3557713 | 2013-12-06 15:21:15 -0500 | [diff] [blame] | 39 | import java.io.OutputStream; |
alision | bd45a82 | 2013-06-06 17:35:35 -0400 | [diff] [blame] | 40 | import java.util.Timer; |
| 41 | import java.util.TimerTask; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 42 | |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 43 | import org.sflphone.R; |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 44 | import org.sflphone.fragments.AboutFragment; |
| 45 | import org.sflphone.fragments.AccountsManagementFragment; |
| 46 | import org.sflphone.fragments.CallListFragment; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 47 | import org.sflphone.fragments.ContactListFragment; |
| 48 | import org.sflphone.fragments.DialingFragment; |
| 49 | import org.sflphone.fragments.HistoryFragment; |
| 50 | import org.sflphone.fragments.HomeFragment; |
| 51 | import org.sflphone.fragments.MenuFragment; |
| 52 | import org.sflphone.interfaces.CallInterface; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 53 | import org.sflphone.model.CallContact; |
| 54 | import org.sflphone.model.Conference; |
| 55 | import org.sflphone.model.SipCall; |
| 56 | import org.sflphone.receivers.CallReceiver; |
| 57 | import org.sflphone.service.CallManagerCallBack; |
| 58 | import org.sflphone.service.ISipService; |
| 59 | import org.sflphone.service.SipService; |
Alexandre Lision | 450458a | 2013-11-22 11:33:12 -0500 | [diff] [blame] | 60 | import org.sflphone.views.SlidingUpPanelLayout; |
| 61 | import org.sflphone.views.SlidingUpPanelLayout.PanelSlideListener; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 62 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 63 | import android.app.Activity; |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 64 | import android.app.AlertDialog; |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 65 | import android.app.Fragment; |
| 66 | import android.app.FragmentManager.BackStackEntry; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 67 | import android.content.ComponentName; |
| 68 | import android.content.Context; |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 69 | import android.content.DialogInterface; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 70 | import android.content.Intent; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 71 | import android.content.IntentFilter; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 72 | import android.content.ServiceConnection; |
Alexandre Lision | 3557713 | 2013-12-06 15:21:15 -0500 | [diff] [blame] | 73 | import android.content.res.AssetManager; |
alision | f57d8a6 | 2013-07-02 09:37:12 -0400 | [diff] [blame] | 74 | import android.content.res.Configuration; |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 75 | import android.database.Cursor; |
Alexandre Lision | c59685a | 2013-10-04 16:36:36 -0400 | [diff] [blame] | 76 | import android.net.Uri; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 77 | import android.os.Bundle; |
| 78 | import android.os.IBinder; |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 79 | import android.os.RemoteException; |
Alexandre Lision | 3557713 | 2013-12-06 15:21:15 -0500 | [diff] [blame] | 80 | import android.preference.PreferenceManager; |
Alexandre Lision | c59685a | 2013-10-04 16:36:36 -0400 | [diff] [blame] | 81 | import android.provider.ContactsContract; |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 82 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
| 83 | import android.provider.ContactsContract.CommonDataKinds.SipAddress; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 84 | import android.support.v4.app.ActionBarDrawerToggle; |
| 85 | import android.support.v4.view.GravityCompat; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 86 | import android.support.v4.widget.DrawerLayout; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 87 | import android.util.Log; |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 88 | import android.view.Gravity; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 89 | import android.view.MenuItem; |
| 90 | import android.view.View; |
alision | 7297bdb | 2013-05-21 11:56:55 -0400 | [diff] [blame] | 91 | import android.widget.RelativeLayout; |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 92 | import android.widget.Toast; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 93 | |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 94 | public class HomeActivity extends Activity implements DialingFragment.Callbacks, AccountsManagementFragment.Callbacks, ContactListFragment.Callbacks, |
| 95 | CallListFragment.Callbacks, HistoryFragment.Callbacks, CallInterface, MenuFragment.Callbacks { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 96 | |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 97 | static final String TAG = HomeActivity.class.getSimpleName(); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 98 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 99 | private ContactListFragment mContactsFragment = null; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 100 | private MenuFragment fMenu; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 101 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 102 | private boolean mBound = false; |
| 103 | private ISipService service; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 104 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 105 | public static final int REQUEST_CODE_PREFERENCES = 1; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 106 | private static final int REQUEST_CODE_CALL = 2; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 107 | |
alision | 0b55383 | 2013-05-30 09:31:06 -0400 | [diff] [blame] | 108 | RelativeLayout mSliderButton; |
Alexandre Lision | 450458a | 2013-11-22 11:33:12 -0500 | [diff] [blame] | 109 | SlidingUpPanelLayout mContactDrawer; |
Alexandre Lision | 6890005 | 2013-11-01 11:34:56 -0400 | [diff] [blame] | 110 | private DrawerLayout mNavigationDrawer; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 111 | private ActionBarDrawerToggle mDrawerToggle; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 112 | |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 113 | CallReceiver callReceiver; |
Alexandre Lision | 9d052a1 | 2013-11-06 15:13:34 -0500 | [diff] [blame] | 114 | private boolean isClosing = false; |
| 115 | private Timer t = new Timer(); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 116 | |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 117 | private Fragment fContent; |
| 118 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 119 | /* called before activity is killed, e.g. rotation */ |
| 120 | @Override |
| 121 | protected void onSaveInstanceState(Bundle bundle) { |
| 122 | super.onSaveInstanceState(bundle); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 123 | getFragmentManager().putFragment(bundle, "ContactsListFragment", mContactsFragment); |
| 124 | Log.w(TAG, "onSaveInstanceState()"); |
| 125 | } |
| 126 | |
| 127 | @Override |
| 128 | public void onCreate(Bundle savedInstanceState) { |
| 129 | super.onCreate(savedInstanceState); |
| 130 | |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 131 | callReceiver = new CallReceiver(this); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 132 | |
Alexandre Lision | 269e604 | 2013-12-11 16:15:13 -0500 | [diff] [blame] | 133 | setContentView(R.layout.activity_home); |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 134 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 135 | // Bind to LocalService |
| 136 | if (!mBound) { |
| 137 | Log.i(TAG, "onStart: Binding service..."); |
| 138 | Intent intent = new Intent(this, SipService.class); |
Alexandre Lision | 0f550ee | 2013-10-25 15:34:38 -0400 | [diff] [blame] | 139 | startService(intent); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 140 | bindService(intent, mConnection, Context.BIND_AUTO_CREATE); |
| 141 | } |
Alexandre Lision | 8b9d8e8 | 2013-10-04 09:21:27 -0400 | [diff] [blame] | 142 | |
| 143 | if (savedInstanceState != null) { |
Alexandre Lision | 23628c1 | 2013-09-24 11:17:05 -0400 | [diff] [blame] | 144 | mContactsFragment = (ContactListFragment) getFragmentManager().getFragment(savedInstanceState, "ContactsListFragment"); |
| 145 | } |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 146 | if (mContactsFragment == null) { |
| 147 | mContactsFragment = new ContactListFragment(); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 148 | getFragmentManager().beginTransaction().replace(R.id.contacts_frame, mContactsFragment).commit(); |
| 149 | } |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 150 | |
Alexandre Lision | 450458a | 2013-11-22 11:33:12 -0500 | [diff] [blame] | 151 | mContactDrawer = (SlidingUpPanelLayout) findViewById(R.id.contact_panel); |
| 152 | // mContactDrawer.setShadowDrawable(getResources().getDrawable(R.drawable.above_shadow)); |
| 153 | mContactDrawer.setAnchorPoint(0.3f); |
| 154 | mContactDrawer.setDragView(findViewById(R.id.contacts_frame)); |
| 155 | mContactDrawer.setEnableDragViewTouchEvents(true); |
Alexandre Lision | 450458a | 2013-11-22 11:33:12 -0500 | [diff] [blame] | 156 | mContactDrawer.setPanelSlideListener(new PanelSlideListener() { |
Alexandre Lision | 8b9d8e8 | 2013-10-04 09:21:27 -0400 | [diff] [blame] | 157 | |
| 158 | @Override |
Alexandre Lision | 450458a | 2013-11-22 11:33:12 -0500 | [diff] [blame] | 159 | public void onPanelSlide(View panel, float slideOffset) { |
| 160 | if (slideOffset < 0.2) { |
| 161 | if (getActionBar().isShowing()) { |
| 162 | getActionBar().hide(); |
| 163 | } |
| 164 | } else { |
| 165 | if (!getActionBar().isShowing()) { |
| 166 | getActionBar().show(); |
| 167 | } |
Alexandre Lision | 8b9d8e8 | 2013-10-04 09:21:27 -0400 | [diff] [blame] | 168 | } |
| 169 | } |
Alexandre Lision | 450458a | 2013-11-22 11:33:12 -0500 | [diff] [blame] | 170 | |
| 171 | @Override |
| 172 | public void onPanelExpanded(View panel) { |
| 173 | |
| 174 | } |
| 175 | |
| 176 | @Override |
| 177 | public void onPanelCollapsed(View panel) { |
| 178 | |
| 179 | } |
| 180 | |
| 181 | @Override |
| 182 | public void onPanelAnchored(View panel) { |
| 183 | |
| 184 | } |
Alexandre Lision | 8b9d8e8 | 2013-10-04 09:21:27 -0400 | [diff] [blame] | 185 | }); |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 186 | |
Alexandre Lision | 6890005 | 2013-11-01 11:34:56 -0400 | [diff] [blame] | 187 | mNavigationDrawer = (DrawerLayout) findViewById(R.id.drawer_layout); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 188 | |
alision | 0b55383 | 2013-05-30 09:31:06 -0400 | [diff] [blame] | 189 | // set a custom shadow that overlays the main content when the drawer opens |
Alexandre Lision | 6890005 | 2013-11-01 11:34:56 -0400 | [diff] [blame] | 190 | mNavigationDrawer.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 191 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 192 | getActionBar().setDisplayHomeAsUpEnabled(true); |
| 193 | getActionBar().setHomeButtonEnabled(true); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 194 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 195 | mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ |
Alexandre Lision | 6890005 | 2013-11-01 11:34:56 -0400 | [diff] [blame] | 196 | mNavigationDrawer, /* DrawerLayout object */ |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 197 | R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ |
| 198 | R.string.drawer_open, /* "open drawer" description for accessibility */ |
| 199 | R.string.drawer_close /* "close drawer" description for accessibility */ |
| 200 | ) { |
alision | 0b55383 | 2013-05-30 09:31:06 -0400 | [diff] [blame] | 201 | @Override |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 202 | public void onDrawerClosed(View view) { |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 203 | invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() |
| 204 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 205 | |
alision | 0b55383 | 2013-05-30 09:31:06 -0400 | [diff] [blame] | 206 | @Override |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 207 | public void onDrawerOpened(View drawerView) { |
Alexandre Lision | 4d20c81 | 2013-12-12 17:44:50 -0500 | [diff] [blame^] | 208 | // getActionBar().setTitle(mDrawerTitle); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 209 | invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() |
| 210 | } |
| 211 | }; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 212 | |
Alexandre Lision | 6890005 | 2013-11-01 11:34:56 -0400 | [diff] [blame] | 213 | mNavigationDrawer.setDrawerListener(mDrawerToggle); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 214 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 215 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 216 | |
alision | f57d8a6 | 2013-07-02 09:37:12 -0400 | [diff] [blame] | 217 | @Override |
| 218 | protected void onPostCreate(Bundle savedInstanceState) { |
| 219 | super.onPostCreate(savedInstanceState); |
| 220 | // Sync the toggle state after onRestoreInstanceState has occurred. |
| 221 | mDrawerToggle.syncState(); |
Alexandre Lision | 450458a | 2013-11-22 11:33:12 -0500 | [diff] [blame] | 222 | if (mContactDrawer.isExpanded()) { |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 223 | getActionBar().hide(); |
| 224 | } |
alision | f57d8a6 | 2013-07-02 09:37:12 -0400 | [diff] [blame] | 225 | } |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 226 | |
alision | f57d8a6 | 2013-07-02 09:37:12 -0400 | [diff] [blame] | 227 | @Override |
| 228 | public void onConfigurationChanged(Configuration newConfig) { |
| 229 | super.onConfigurationChanged(newConfig); |
| 230 | mDrawerToggle.onConfigurationChanged(newConfig); |
| 231 | } |
alision | 3c5c2a9 | 2013-05-30 09:50:47 -0400 | [diff] [blame] | 232 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 233 | @Override |
| 234 | protected void onStart() { |
| 235 | Log.i(TAG, "onStart"); |
Alexandre Lision | 3557713 | 2013-12-06 15:21:15 -0500 | [diff] [blame] | 236 | |
| 237 | if (!PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).getBoolean("installed", false)) { |
| 238 | PreferenceManager.getDefaultSharedPreferences(getApplicationContext()).edit().putBoolean("installed", true).commit(); |
| 239 | |
| 240 | copyAssetFolder(getAssets(), "ringtones", getFilesDir().getAbsolutePath() + "/ringtones"); |
| 241 | } |
| 242 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 243 | super.onStart(); |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 244 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 245 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 246 | |
Alexandre Lision | 3557713 | 2013-12-06 15:21:15 -0500 | [diff] [blame] | 247 | private static boolean copyAssetFolder(AssetManager assetManager, String fromAssetPath, String toPath) { |
| 248 | try { |
| 249 | String[] files = assetManager.list(fromAssetPath); |
| 250 | new File(toPath).mkdirs(); |
| 251 | Log.i(TAG, "Creating :" + toPath); |
| 252 | boolean res = true; |
| 253 | for (String file : files) |
| 254 | if (file.contains(".")) { |
| 255 | Log.i(TAG, "Copying file :" + fromAssetPath + "/" + file + " to " + toPath + "/" + file); |
| 256 | res &= copyAsset(assetManager, fromAssetPath + "/" + file, toPath + "/" + file); |
| 257 | } else { |
| 258 | Log.i(TAG, "Copying folder :" + fromAssetPath + "/" + file + " to " + toPath + "/" + file); |
| 259 | res &= copyAssetFolder(assetManager, fromAssetPath + "/" + file, toPath + "/" + file); |
| 260 | } |
| 261 | return res; |
| 262 | } catch (Exception e) { |
| 263 | e.printStackTrace(); |
| 264 | return false; |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | private static boolean copyAsset(AssetManager assetManager, String fromAssetPath, String toPath) { |
| 269 | InputStream in = null; |
| 270 | OutputStream out = null; |
| 271 | try { |
| 272 | in = assetManager.open(fromAssetPath); |
| 273 | new File(toPath).createNewFile(); |
| 274 | out = new FileOutputStream(toPath); |
| 275 | copyFile(in, out); |
| 276 | in.close(); |
| 277 | in = null; |
| 278 | out.flush(); |
| 279 | out.close(); |
| 280 | out = null; |
| 281 | return true; |
| 282 | } catch (Exception e) { |
| 283 | e.printStackTrace(); |
| 284 | return false; |
| 285 | } |
| 286 | } |
| 287 | |
| 288 | private static void copyFile(InputStream in, OutputStream out) throws IOException { |
| 289 | byte[] buffer = new byte[1024]; |
| 290 | int read; |
| 291 | while ((read = in.read(buffer)) != -1) { |
| 292 | out.write(buffer, 0, read); |
| 293 | } |
| 294 | } |
| 295 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 296 | /* user gets back to the activity, e.g. through task manager */ |
| 297 | @Override |
| 298 | protected void onRestart() { |
| 299 | super.onRestart(); |
| 300 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 301 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 302 | /* activity gets back to the foreground and user input */ |
| 303 | @Override |
| 304 | protected void onResume() { |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 305 | super.onResume(); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 306 | IntentFilter intentFilter = new IntentFilter(); |
| 307 | intentFilter.addAction(CallManagerCallBack.INCOMING_CALL); |
| 308 | intentFilter.addAction(CallManagerCallBack.INCOMING_TEXT); |
| 309 | intentFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED); |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 310 | registerReceiver(callReceiver, intentFilter); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 311 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 312 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 313 | |
alision | bd45a82 | 2013-06-06 17:35:35 -0400 | [diff] [blame] | 314 | @Override |
| 315 | public void onBackPressed() { |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 316 | |
Alexandre Lision | 6890005 | 2013-11-01 11:34:56 -0400 | [diff] [blame] | 317 | if (mNavigationDrawer.isDrawerVisible(Gravity.LEFT)) { |
| 318 | mNavigationDrawer.closeDrawer(Gravity.LEFT); |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 319 | return; |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 320 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 321 | |
Alexandre Lision | 450458a | 2013-11-22 11:33:12 -0500 | [diff] [blame] | 322 | if (mContactDrawer.isExpanded() || mContactDrawer.isAnchored()) { |
| 323 | mContactDrawer.collapsePane(); |
alision | bd45a82 | 2013-06-06 17:35:35 -0400 | [diff] [blame] | 324 | return; |
| 325 | } |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 326 | |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 327 | if (getFragmentManager().getBackStackEntryCount() > 0) { |
| 328 | BackStackEntry entry = getFragmentManager().getBackStackEntryAt(getFragmentManager().getBackStackEntryCount() - 1); |
| 329 | |
| 330 | fContent = getFragmentManager().findFragmentByTag(entry.getName()); |
| 331 | |
| 332 | getFragmentManager().popBackStack(); |
| 333 | return; |
| 334 | } |
| 335 | |
alision | bd45a82 | 2013-06-06 17:35:35 -0400 | [diff] [blame] | 336 | if (isClosing) { |
| 337 | super.onBackPressed(); |
| 338 | t.cancel(); |
| 339 | finish(); |
| 340 | } else { |
| 341 | |
| 342 | t.schedule(new TimerTask() { |
| 343 | @Override |
| 344 | public void run() { |
| 345 | isClosing = false; |
| 346 | } |
| 347 | }, 3000); |
| 348 | Toast.makeText(this, getResources().getString(R.string.close_msg), Toast.LENGTH_SHORT).show(); |
| 349 | isClosing = true; |
| 350 | } |
| 351 | } |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 352 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 353 | /* activity no more in foreground */ |
| 354 | @Override |
| 355 | protected void onPause() { |
| 356 | super.onPause(); |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 357 | unregisterReceiver(callReceiver); |
Alexandre Lision | b4a9e39 | 2013-10-01 14:39:43 -0400 | [diff] [blame] | 358 | if (mBound) { |
| 359 | unbindService(mConnection); |
| 360 | mBound = false; |
| 361 | } |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 362 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 363 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 364 | /* activity finishes itself or is being killed by the system */ |
| 365 | @Override |
| 366 | protected void onDestroy() { |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 367 | super.onDestroy(); |
Alexandre Lision | b4a9e39 | 2013-10-01 14:39:43 -0400 | [diff] [blame] | 368 | Log.i(TAG, "onDestroy: destroying service..."); |
| 369 | Intent sipServiceIntent = new Intent(this, SipService.class); |
| 370 | stopService(sipServiceIntent); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 371 | } |
alision | 73424b6 | 2013-04-26 11:49:18 -0400 | [diff] [blame] | 372 | |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 373 | public void launchCallActivity(SipCall infos) { |
Alexandre Lision | c59685a | 2013-10-04 16:36:36 -0400 | [diff] [blame] | 374 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 375 | Bundle bundle = new Bundle(); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 376 | Conference tmp = new Conference("-1"); |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 377 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 378 | tmp.getParticipants().add(infos); |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 379 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 380 | bundle.putParcelable("conference", tmp); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 381 | Intent intent = new Intent().setClass(this, CallActivity.class); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 382 | intent.putExtra("resuming", false); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 383 | intent.putExtras(bundle); |
| 384 | startActivityForResult(intent, REQUEST_CODE_CALL); |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 385 | |
Alexandre Lision | 8b9d8e8 | 2013-10-04 09:21:27 -0400 | [diff] [blame] | 386 | // overridePendingTransition(R.anim.slide_down, R.anim.slide_up); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 387 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 388 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 389 | /** Defines callbacks for service binding, passed to bindService() */ |
| 390 | private ServiceConnection mConnection = new ServiceConnection() { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 391 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 392 | @Override |
| 393 | public void onServiceConnected(ComponentName className, IBinder binder) { |
| 394 | service = ISipService.Stub.asInterface(binder); |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 395 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 396 | try { |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 397 | |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 398 | fMenu = new MenuFragment(); |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 399 | fContent = new HomeFragment(); |
| 400 | getFragmentManager().beginTransaction().replace(R.id.left_drawer, fMenu).replace(R.id.main_frame, fContent).commit(); |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 401 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 402 | service.destroyNotification(); |
| 403 | } catch (RemoteException e) { |
| 404 | Log.e(TAG, e.toString()); |
| 405 | } |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 406 | mBound = true; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 407 | Log.d(TAG, "Service connected service=" + service); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 408 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 409 | } |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 410 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 411 | @Override |
| 412 | public void onServiceDisconnected(ComponentName arg0) { |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 413 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 414 | mBound = false; |
| 415 | Log.d(TAG, "Service disconnected service=" + service); |
| 416 | } |
| 417 | }; |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 418 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 419 | @Override |
| 420 | public boolean onOptionsItemSelected(MenuItem item) { |
| 421 | Log.i(TAG, "onOptionsItemSelected " + item.getItemId()); |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 422 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 423 | if (mDrawerToggle.onOptionsItemSelected(item)) { |
| 424 | return true; |
| 425 | } |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 426 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 427 | return super.onOptionsItemSelected(item); |
| 428 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 429 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 430 | @Override |
| 431 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 432 | super.onActivityResult(requestCode, resultCode, data); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 433 | |
| 434 | switch (requestCode) { |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 435 | case REQUEST_CODE_PREFERENCES: |
Alexandre Lision | e5b6602 | 2013-10-30 11:34:15 -0400 | [diff] [blame] | 436 | if (fMenu != null) |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 437 | fMenu.updateAllAccounts(); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 438 | break; |
| 439 | case REQUEST_CODE_CALL: |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 440 | if (resultCode == CallActivity.RESULT_FAILURE) { |
Alexandre Lision | 8b9d8e8 | 2013-10-04 09:21:27 -0400 | [diff] [blame] | 441 | Log.w(TAG, "Call Failed"); |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 442 | } |
| 443 | // if (mSectionsPagerAdapter != null && mSectionsPagerAdapter.getItem(2) != null) |
| 444 | // getLoaderManager().restartLoader(LoaderConstants.HISTORY_LOADER, null, (HistoryFragment) mSectionsPagerAdapter.getItem(2)); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 445 | break; |
| 446 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 447 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 448 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 449 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 450 | @Override |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 451 | public ISipService getService() { |
| 452 | return service; |
| 453 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 454 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 455 | /** |
| 456 | * Interface implemented to handle incoming events |
| 457 | */ |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 458 | @Override |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 459 | public void incomingCall(Intent call) { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 460 | SipCall infos = call.getParcelableExtra("newcall"); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 461 | |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 462 | launchCallActivity(infos); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 463 | |
| 464 | } |
| 465 | |
| 466 | @Override |
| 467 | public void callStateChanged(Intent callState) { |
| 468 | Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate"); |
| 469 | String cID = b.getString("CallID"); |
| 470 | String state = b.getString("State"); |
| 471 | Log.i(TAG, "callStateChanged" + cID + " " + state); |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 472 | // mSectionsPagerAdapter.updateHome(); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 473 | |
| 474 | } |
| 475 | |
| 476 | @Override |
| 477 | public void incomingText(Intent msg) { |
| 478 | Bundle b = msg.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext"); |
| 479 | b.getString("CallID"); |
| 480 | String from = b.getString("From"); |
| 481 | String mess = b.getString("Msg"); |
| 482 | Toast.makeText(getApplicationContext(), "text from " + from + " : " + mess, Toast.LENGTH_LONG).show(); |
| 483 | } |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 484 | |
Alexandre Lision | e1c96db | 2013-10-04 14:34:21 -0400 | [diff] [blame] | 485 | @Override |
| 486 | public void onTextContact(final CallContact c) { |
| 487 | // TODO |
| 488 | } |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 489 | |
Alexandre Lision | c59685a | 2013-10-04 16:36:36 -0400 | [diff] [blame] | 490 | @Override |
| 491 | public void onEditContact(final CallContact c) { |
| 492 | Intent intent = new Intent(Intent.ACTION_VIEW); |
| 493 | Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(c.getId())); |
| 494 | intent.setData(uri); |
| 495 | startActivity(intent); |
| 496 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 497 | |
| 498 | @Override |
Alexandre Lision | e1c96db | 2013-10-04 14:34:21 -0400 | [diff] [blame] | 499 | public void onCallContact(final CallContact c) { |
Alexandre Lision | 8b9d8e8 | 2013-10-04 09:21:27 -0400 | [diff] [blame] | 500 | |
Alexandre Lision | f0b993d | 2013-09-12 13:25:10 -0400 | [diff] [blame] | 501 | if (fMenu.getSelectedAccount() == null) { |
Alexandre Lision | f0b993d | 2013-09-12 13:25:10 -0400 | [diff] [blame] | 502 | createAccountDialog().show(); |
| 503 | return; |
| 504 | } |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 505 | |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 506 | if (!fMenu.getSelectedAccount().isRegistered()) { |
| 507 | createNotRegisteredDialog().show(); |
| 508 | return; |
| 509 | } |
| 510 | |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 511 | getActionBar().show(); |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 512 | Thread launcher = new Thread(new Runnable() { |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 513 | |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 514 | final String[] CONTACTS_PHONES_PROJECTION = new String[] { Phone.NUMBER, Phone.TYPE }; |
| 515 | final String[] CONTACTS_SIP_PROJECTION = new String[] { SipAddress.SIP_ADDRESS, SipAddress.TYPE }; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 516 | |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 517 | @Override |
| 518 | public void run() { |
| 519 | SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance(); |
| 520 | try { |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 521 | callBuilder.startCallCreation().setAccount(fMenu.getSelectedAccount()).setCallType(SipCall.state.CALL_TYPE_OUTGOING); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 522 | Cursor cPhones = getContentResolver().query(Phone.CONTENT_URI, CONTACTS_PHONES_PROJECTION, Phone.CONTACT_ID + " =" + c.getId(), |
| 523 | null, null); |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 524 | |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 525 | while (cPhones.moveToNext()) { |
| 526 | c.addPhoneNumber(cPhones.getString(cPhones.getColumnIndex(Phone.NUMBER)), cPhones.getInt(cPhones.getColumnIndex(Phone.TYPE))); |
| 527 | } |
| 528 | cPhones.close(); |
| 529 | |
| 530 | Cursor cSip = getContentResolver().query(Phone.CONTENT_URI, CONTACTS_SIP_PROJECTION, Phone.CONTACT_ID + "=" + c.getId(), null, |
| 531 | null); |
| 532 | |
| 533 | while (cSip.moveToNext()) { |
| 534 | c.addSipNumber(cSip.getString(cSip.getColumnIndex(SipAddress.SIP_ADDRESS)), cSip.getInt(cSip.getColumnIndex(SipAddress.TYPE))); |
| 535 | } |
| 536 | cSip.close(); |
| 537 | callBuilder.setContact(c); |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 538 | launchCallActivity(callBuilder.build()); |
Alexandre Lision | 5ed2c97 | 2013-10-11 15:36:33 -0400 | [diff] [blame] | 539 | } catch (InvalidObjectException e) { |
| 540 | e.printStackTrace(); |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 541 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 542 | |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 543 | } |
| 544 | }); |
| 545 | launcher.start(); |
Alexandre Lision | 450458a | 2013-11-22 11:33:12 -0500 | [diff] [blame] | 546 | mContactDrawer.collapsePane(); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 547 | |
| 548 | } |
| 549 | |
| 550 | @Override |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 551 | public void onCallDialed(String to) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 552 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 553 | if (fMenu.getSelectedAccount() == null) { |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 554 | createAccountDialog().show(); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 555 | return; |
| 556 | } |
| 557 | |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 558 | if (fMenu.getSelectedAccount().isRegistered()) { |
| 559 | SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance(); |
| 560 | callBuilder.startCallCreation().setAccount(fMenu.getSelectedAccount()).setCallType(SipCall.state.CALL_TYPE_OUTGOING); |
| 561 | callBuilder.setContact(CallContact.ContactBuilder.buildUnknownContact(to)); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 562 | |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 563 | try { |
| 564 | launchCallActivity(callBuilder.build()); |
| 565 | } catch (Exception e) { |
| 566 | Log.e(TAG, e.toString()); |
| 567 | } |
| 568 | } else { |
Alexandre Lision | 5ed2c97 | 2013-10-11 15:36:33 -0400 | [diff] [blame] | 569 | createNotRegisteredDialog().show(); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 570 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 571 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 572 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 573 | |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 574 | private AlertDialog createNotRegisteredDialog() { |
| 575 | final Activity ownerActivity = this; |
| 576 | AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity); |
| 577 | |
| 578 | builder.setMessage(getResources().getString(R.string.cannot_pass_sipcall)) |
| 579 | .setTitle(getResources().getString(R.string.cannot_pass_sipcall_title)) |
| 580 | .setPositiveButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() { |
| 581 | public void onClick(DialogInterface dialog, int whichButton) { |
Alexandre Lision | 5ed2c97 | 2013-10-11 15:36:33 -0400 | [diff] [blame] | 582 | |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 583 | } |
| 584 | }); |
| 585 | |
| 586 | AlertDialog alertDialog = builder.create(); |
| 587 | alertDialog.setOwnerActivity(ownerActivity); |
| 588 | |
| 589 | return alertDialog; |
| 590 | } |
| 591 | |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 592 | private AlertDialog createAccountDialog() { |
| 593 | final Activity ownerActivity = this; |
| 594 | AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity); |
| 595 | |
| 596 | builder.setMessage(getResources().getString(R.string.create_new_account_dialog)) |
| 597 | .setTitle(getResources().getString(R.string.create_new_account_dialog_title)) |
| 598 | .setPositiveButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() { |
| 599 | public void onClick(DialogInterface dialog, int whichButton) { |
| 600 | Intent in = new Intent(); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 601 | in.setClass(ownerActivity, AccountWizard.class); |
Alexandre Lision | 4ab5397 | 2013-11-04 16:59:18 -0500 | [diff] [blame] | 602 | ownerActivity.startActivityForResult(in, HomeActivity.REQUEST_CODE_PREFERENCES); |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 603 | } |
| 604 | }).setNegativeButton(getResources().getString(android.R.string.cancel), new DialogInterface.OnClickListener() { |
| 605 | public void onClick(DialogInterface dialog, int whichButton) { |
| 606 | dialog.dismiss(); |
| 607 | } |
| 608 | }); |
| 609 | |
| 610 | AlertDialog alertDialog = builder.create(); |
| 611 | alertDialog.setOwnerActivity(ownerActivity); |
| 612 | |
| 613 | return alertDialog; |
| 614 | } |
| 615 | |
alision | d45da71 | 2013-05-30 09:18:49 -0400 | [diff] [blame] | 616 | @Override |
| 617 | public void onContactDragged() { |
Alexandre Lision | 450458a | 2013-11-22 11:33:12 -0500 | [diff] [blame] | 618 | mContactDrawer.collapsePane(); |
alision | d45da71 | 2013-05-30 09:18:49 -0400 | [diff] [blame] | 619 | } |
| 620 | |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 621 | @Override |
Alexandre Lision | 0936ba6 | 2013-11-25 10:04:56 -0500 | [diff] [blame] | 622 | public void toggleDrawer() { |
Alexandre Lision | c985b36 | 2013-12-10 17:45:03 -0500 | [diff] [blame] | 623 | if (mContactDrawer.isAnchored()) |
Alexandre Lision | 0936ba6 | 2013-11-25 10:04:56 -0500 | [diff] [blame] | 624 | mContactDrawer.expandPane(); |
Alexandre Lision | c985b36 | 2013-12-10 17:45:03 -0500 | [diff] [blame] | 625 | else if (!mContactDrawer.isExpanded()) |
| 626 | mContactDrawer.expandPane(0.3f); |
Alexandre Lision | c9b4e9e | 2013-11-27 10:27:28 -0500 | [diff] [blame] | 627 | else |
| 628 | mContactDrawer.collapsePane(); |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 629 | } |
| 630 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 631 | @Override |
Alexandre Lision | a458ba2 | 2013-12-11 15:04:11 -0500 | [diff] [blame] | 632 | public void toggleForSearchDrawer() { |
| 633 | if (mContactDrawer.isExpanded()) { |
| 634 | mContactDrawer.collapsePane(); |
| 635 | } else |
| 636 | mContactDrawer.expandPane(); |
| 637 | } |
| 638 | |
| 639 | @Override |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 640 | public void confCreated(Intent intent) { |
| 641 | // TODO Auto-generated method stub |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 642 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 643 | } |
| 644 | |
| 645 | @Override |
| 646 | public void confRemoved(Intent intent) { |
| 647 | // TODO Auto-generated method stub |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 648 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 649 | } |
| 650 | |
| 651 | @Override |
| 652 | public void confChanged(Intent intent) { |
| 653 | // TODO Auto-generated method stub |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 654 | |
| 655 | } |
| 656 | |
| 657 | @Override |
| 658 | public void recordingChanged(Intent intent) { |
| 659 | // TODO Auto-generated method stub |
| 660 | |
| 661 | } |
| 662 | |
| 663 | @Override |
Alexandre Lision | 1a9e3b1 | 2013-09-16 11:06:07 -0400 | [diff] [blame] | 664 | public void selectedCall(Conference c) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 665 | Intent intent = new Intent().setClass(this, CallActivity.class); |
| 666 | intent.putExtra("resuming", true); |
Alexandre Lision | 1a9e3b1 | 2013-09-16 11:06:07 -0400 | [diff] [blame] | 667 | intent.putExtra("conference", c); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 668 | startActivityForResult(intent, REQUEST_CODE_CALL); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 669 | } |
Alexandre Lision | 8b9d8e8 | 2013-10-04 09:21:27 -0400 | [diff] [blame] | 670 | |
Alexandre Lision | 0936ba6 | 2013-11-25 10:04:56 -0500 | [diff] [blame] | 671 | @Override |
| 672 | public void setDragView(RelativeLayout relativeLayout) { |
| 673 | mContactDrawer.setDragView(relativeLayout); |
| 674 | } |
| 675 | |
Alexandre Lision | 269e604 | 2013-12-11 16:15:13 -0500 | [diff] [blame] | 676 | @Override |
| 677 | public void onSectionSelected(int pos) { |
| 678 | Intent in = new Intent(); |
| 679 | |
| 680 | switch (pos) { |
| 681 | case 0: |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 682 | fContent = new HomeFragment(); |
| 683 | getFragmentManager().beginTransaction().replace(R.id.main_frame, fContent).addToBackStack("HomeTransac").commit(); |
Alexandre Lision | 269e604 | 2013-12-11 16:15:13 -0500 | [diff] [blame] | 684 | break; |
| 685 | case 1: |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 686 | fContent = new AccountsManagementFragment(); |
| 687 | getFragmentManager().beginTransaction().replace(R.id.main_frame, fContent).addToBackStack("AccountsTransac").commit(); |
| 688 | break; |
| 689 | case 2: |
| 690 | fContent = new AboutFragment(); |
| 691 | getFragmentManager().beginTransaction().replace(R.id.main_frame, fContent).addToBackStack("AboutTransac").commit(); |
Alexandre Lision | 269e604 | 2013-12-11 16:15:13 -0500 | [diff] [blame] | 692 | break; |
| 693 | } |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 694 | |
| 695 | mNavigationDrawer.closeDrawers(); |
Alexandre Lision | 269e604 | 2013-12-11 16:15:13 -0500 | [diff] [blame] | 696 | } |
| 697 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 698 | } |