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