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