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 | be54c34 | 2014-01-21 17:10:33 -0500 | [diff] [blame] | 43 | import android.app.Activity; |
| 44 | import android.app.AlertDialog; |
| 45 | import android.support.v4.app.*; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 46 | import org.sflphone.R; |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 47 | import org.sflphone.fragments.AboutFragment; |
| 48 | import org.sflphone.fragments.AccountsManagementFragment; |
| 49 | import org.sflphone.fragments.CallListFragment; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 50 | import org.sflphone.fragments.ContactListFragment; |
| 51 | import org.sflphone.fragments.DialingFragment; |
| 52 | import org.sflphone.fragments.HistoryFragment; |
| 53 | import org.sflphone.fragments.HomeFragment; |
| 54 | import org.sflphone.fragments.MenuFragment; |
Alexandre Lision | e796a87 | 2014-01-17 17:08:13 -0500 | [diff] [blame] | 55 | import org.sflphone.history.HistoryEntry; |
| 56 | import org.sflphone.model.Account; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 57 | import org.sflphone.model.CallContact; |
| 58 | import org.sflphone.model.Conference; |
| 59 | import org.sflphone.model.SipCall; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 60 | import org.sflphone.service.ISipService; |
| 61 | import org.sflphone.service.SipService; |
Alexandre Lision | 450458a | 2013-11-22 11:33:12 -0500 | [diff] [blame] | 62 | import org.sflphone.views.SlidingUpPanelLayout; |
| 63 | import org.sflphone.views.SlidingUpPanelLayout.PanelSlideListener; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 64 | |
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 | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 69 | import android.content.ServiceConnection; |
Alexandre Lision | 3557713 | 2013-12-06 15:21:15 -0500 | [diff] [blame] | 70 | import android.content.res.AssetManager; |
alision | f57d8a6 | 2013-07-02 09:37:12 -0400 | [diff] [blame] | 71 | import android.content.res.Configuration; |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 72 | import android.database.Cursor; |
Alexandre Lision | c59685a | 2013-10-04 16:36:36 -0400 | [diff] [blame] | 73 | import android.net.Uri; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 74 | import android.os.Bundle; |
| 75 | import android.os.IBinder; |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 76 | import android.os.RemoteException; |
Alexandre Lision | 3557713 | 2013-12-06 15:21:15 -0500 | [diff] [blame] | 77 | import android.preference.PreferenceManager; |
Alexandre Lision | c59685a | 2013-10-04 16:36:36 -0400 | [diff] [blame] | 78 | import android.provider.ContactsContract; |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 79 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
| 80 | import android.provider.ContactsContract.CommonDataKinds.SipAddress; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 81 | import android.support.v4.view.GravityCompat; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 82 | import android.support.v4.widget.DrawerLayout; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 83 | import android.util.Log; |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 84 | import android.view.Gravity; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 85 | import android.view.MenuItem; |
| 86 | import android.view.View; |
alision | 7297bdb | 2013-05-21 11:56:55 -0400 | [diff] [blame] | 87 | import android.widget.RelativeLayout; |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 88 | import android.widget.Toast; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 89 | |
Alexandre Lision | a8b7872 | 2013-12-13 10:18:33 -0500 | [diff] [blame] | 90 | public class HomeActivity extends FragmentActivity implements DialingFragment.Callbacks, AccountsManagementFragment.Callbacks, |
Alexandre Lision | a9ee4eb | 2014-01-15 16:20:35 -0500 | [diff] [blame] | 91 | ContactListFragment.Callbacks, CallListFragment.Callbacks, HistoryFragment.Callbacks, MenuFragment.Callbacks { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 92 | |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 93 | static final String TAG = HomeActivity.class.getSimpleName(); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 94 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 95 | private ContactListFragment mContactsFragment = null; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 96 | private MenuFragment fMenu; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 97 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 98 | private boolean mBound = false; |
| 99 | private ISipService service; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 100 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 101 | public static final int REQUEST_CODE_PREFERENCES = 1; |
Alexandre Lision | 183bf45 | 2014-01-17 11:21:59 -0500 | [diff] [blame] | 102 | public static final int REQUEST_CODE_CALL = 3; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 103 | |
Alexandre Lision | 450458a | 2013-11-22 11:33:12 -0500 | [diff] [blame] | 104 | SlidingUpPanelLayout mContactDrawer; |
Alexandre Lision | 6890005 | 2013-11-01 11:34:56 -0400 | [diff] [blame] | 105 | private DrawerLayout mNavigationDrawer; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 106 | private ActionBarDrawerToggle mDrawerToggle; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 107 | |
Alexandre Lision | 9d052a1 | 2013-11-06 15:13:34 -0500 | [diff] [blame] | 108 | private boolean isClosing = false; |
| 109 | private Timer t = new Timer(); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 110 | |
Alexandre Lision | 9b56a29 | 2014-01-23 15:20:15 -0500 | [diff] [blame] | 111 | protected Fragment fContent; |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 112 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 113 | /* called before activity is killed, e.g. rotation */ |
| 114 | @Override |
| 115 | protected void onSaveInstanceState(Bundle bundle) { |
| 116 | super.onSaveInstanceState(bundle); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 117 | getFragmentManager().putFragment(bundle, "ContactsListFragment", mContactsFragment); |
| 118 | Log.w(TAG, "onSaveInstanceState()"); |
| 119 | } |
| 120 | |
| 121 | @Override |
| 122 | public void onCreate(Bundle savedInstanceState) { |
| 123 | super.onCreate(savedInstanceState); |
| 124 | |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 125 | |
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 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 386 | try { |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 387 | |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 388 | fMenu = new MenuFragment(); |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 389 | fContent = new HomeFragment(); |
Alexandre Lision | be54c34 | 2014-01-21 17:10:33 -0500 | [diff] [blame] | 390 | 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] | 391 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 392 | service.destroyNotification(); |
| 393 | } catch (RemoteException e) { |
| 394 | Log.e(TAG, e.toString()); |
| 395 | } |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 396 | mBound = true; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 397 | Log.d(TAG, "Service connected service=" + service); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 398 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 399 | } |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 400 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 401 | @Override |
| 402 | public void onServiceDisconnected(ComponentName arg0) { |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 403 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 404 | mBound = false; |
| 405 | Log.d(TAG, "Service disconnected service=" + service); |
| 406 | } |
| 407 | }; |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 408 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 409 | @Override |
| 410 | public boolean onOptionsItemSelected(MenuItem item) { |
| 411 | Log.i(TAG, "onOptionsItemSelected " + item.getItemId()); |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 412 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 413 | if (mDrawerToggle.onOptionsItemSelected(item)) { |
| 414 | return true; |
| 415 | } |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 416 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 417 | return super.onOptionsItemSelected(item); |
| 418 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 419 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 420 | @Override |
| 421 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 422 | super.onActivityResult(requestCode, resultCode, data); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 423 | |
| 424 | switch (requestCode) { |
Alexandre Lision | fed2a64 | 2014-01-10 12:05:47 -0500 | [diff] [blame] | 425 | case REQUEST_CODE_PREFERENCES: |
| 426 | case AccountsManagementFragment.ACCOUNT_EDIT_REQUEST: |
| 427 | if (fMenu != null) |
| 428 | fMenu.updateAllAccounts(); |
| 429 | break; |
| 430 | case REQUEST_CODE_CALL: |
| 431 | if (resultCode == CallActivity.RESULT_FAILURE) { |
| 432 | Log.w(TAG, "Call Failed"); |
| 433 | } |
| 434 | break; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 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 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 438 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 439 | @Override |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 440 | public ISipService getService() { |
| 441 | return service; |
| 442 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 443 | |
Alexandre Lision | e1c96db | 2013-10-04 14:34:21 -0400 | [diff] [blame] | 444 | @Override |
| 445 | public void onTextContact(final CallContact c) { |
| 446 | // TODO |
| 447 | } |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 448 | |
Alexandre Lision | c59685a | 2013-10-04 16:36:36 -0400 | [diff] [blame] | 449 | @Override |
| 450 | public void onEditContact(final CallContact c) { |
| 451 | Intent intent = new Intent(Intent.ACTION_VIEW); |
| 452 | Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(c.getId())); |
| 453 | intent.setData(uri); |
| 454 | startActivity(intent); |
| 455 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 456 | |
| 457 | @Override |
Alexandre Lision | e1c96db | 2013-10-04 14:34:21 -0400 | [diff] [blame] | 458 | public void onCallContact(final CallContact c) { |
Alexandre Lision | 8b9d8e8 | 2013-10-04 09:21:27 -0400 | [diff] [blame] | 459 | |
Alexandre Lision | f0b993d | 2013-09-12 13:25:10 -0400 | [diff] [blame] | 460 | if (fMenu.getSelectedAccount() == null) { |
Alexandre Lision | f0b993d | 2013-09-12 13:25:10 -0400 | [diff] [blame] | 461 | createAccountDialog().show(); |
| 462 | return; |
| 463 | } |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 464 | |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 465 | if (!fMenu.getSelectedAccount().isRegistered()) { |
| 466 | createNotRegisteredDialog().show(); |
| 467 | return; |
| 468 | } |
| 469 | |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 470 | getActionBar().show(); |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 471 | Thread launcher = new Thread(new Runnable() { |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 472 | |
Alexandre Lision | fed2a64 | 2014-01-10 12:05:47 -0500 | [diff] [blame] | 473 | final String[] CONTACTS_PHONES_PROJECTION = new String[]{Phone.NUMBER, Phone.TYPE}; |
| 474 | final String[] CONTACTS_SIP_PROJECTION = new String[]{SipAddress.SIP_ADDRESS, SipAddress.TYPE}; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 475 | |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 476 | @Override |
| 477 | public void run() { |
| 478 | SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance(); |
| 479 | try { |
Alexandre Lision | 67c70b4 | 2014-01-16 13:57:15 -0500 | [diff] [blame] | 480 | callBuilder.startCallCreation().setAccount(fMenu.getSelectedAccount()).setCallType(SipCall.direction.CALL_TYPE_OUTGOING); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 481 | Cursor cPhones = getContentResolver().query(Phone.CONTENT_URI, CONTACTS_PHONES_PROJECTION, Phone.CONTACT_ID + " =" + c.getId(), |
| 482 | null, null); |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 483 | |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 484 | while (cPhones.moveToNext()) { |
| 485 | c.addPhoneNumber(cPhones.getString(cPhones.getColumnIndex(Phone.NUMBER)), cPhones.getInt(cPhones.getColumnIndex(Phone.TYPE))); |
| 486 | } |
| 487 | cPhones.close(); |
| 488 | |
| 489 | Cursor cSip = getContentResolver().query(Phone.CONTENT_URI, CONTACTS_SIP_PROJECTION, Phone.CONTACT_ID + "=" + c.getId(), null, |
| 490 | null); |
| 491 | |
| 492 | while (cSip.moveToNext()) { |
| 493 | c.addSipNumber(cSip.getString(cSip.getColumnIndex(SipAddress.SIP_ADDRESS)), cSip.getInt(cSip.getColumnIndex(SipAddress.TYPE))); |
| 494 | } |
| 495 | cSip.close(); |
| 496 | callBuilder.setContact(c); |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 497 | launchCallActivity(callBuilder.build()); |
Alexandre Lision | 5ed2c97 | 2013-10-11 15:36:33 -0400 | [diff] [blame] | 498 | } catch (InvalidObjectException e) { |
| 499 | e.printStackTrace(); |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 500 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 501 | |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 502 | } |
| 503 | }); |
| 504 | launcher.start(); |
Alexandre Lision | 450458a | 2013-11-22 11:33:12 -0500 | [diff] [blame] | 505 | mContactDrawer.collapsePane(); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 506 | |
| 507 | } |
| 508 | |
| 509 | @Override |
Alexandre Lision | e796a87 | 2014-01-17 17:08:13 -0500 | [diff] [blame] | 510 | public void onCallHistory(HistoryEntry to) { |
| 511 | |
| 512 | Account usedAccount = fMenu.retrieveAccountById(to.getAccountID()); |
| 513 | |
| 514 | if (usedAccount == null) { |
| 515 | createAccountDialog().show(); |
| 516 | return; |
| 517 | } |
| 518 | |
| 519 | if (usedAccount.isRegistered()) { |
| 520 | SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance(); |
| 521 | callBuilder.startCallCreation().setAccount(usedAccount).setCallType(SipCall.direction.CALL_TYPE_OUTGOING); |
| 522 | callBuilder.setContact(to.getContact()); |
| 523 | try { |
| 524 | launchCallActivity(callBuilder.build()); |
| 525 | } catch (Exception e) { |
| 526 | Log.e(TAG, e.toString()); |
| 527 | } |
| 528 | } else { |
| 529 | createNotRegisteredDialog().show(); |
| 530 | } |
| 531 | } |
| 532 | |
| 533 | @Override |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 534 | public void onCallDialed(String to) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 535 | |
Alexandre Lision | e796a87 | 2014-01-17 17:08:13 -0500 | [diff] [blame] | 536 | |
| 537 | Account usedAccount = fMenu.getSelectedAccount(); |
| 538 | |
| 539 | if (usedAccount == null) { |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 540 | createAccountDialog().show(); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 541 | return; |
| 542 | } |
| 543 | |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 544 | if (fMenu.getSelectedAccount().isRegistered()) { |
| 545 | SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance(); |
Alexandre Lision | e796a87 | 2014-01-17 17:08:13 -0500 | [diff] [blame] | 546 | callBuilder.startCallCreation().setAccount(usedAccount).setCallType(SipCall.direction.CALL_TYPE_OUTGOING); |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 547 | callBuilder.setContact(CallContact.ContactBuilder.buildUnknownContact(to)); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 548 | |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 549 | try { |
| 550 | launchCallActivity(callBuilder.build()); |
| 551 | } catch (Exception e) { |
| 552 | Log.e(TAG, e.toString()); |
| 553 | } |
| 554 | } else { |
Alexandre Lision | 5ed2c97 | 2013-10-11 15:36:33 -0400 | [diff] [blame] | 555 | createNotRegisteredDialog().show(); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 556 | } |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 557 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 558 | |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 559 | private AlertDialog createNotRegisteredDialog() { |
| 560 | final Activity ownerActivity = this; |
| 561 | AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity); |
| 562 | |
| 563 | builder.setMessage(getResources().getString(R.string.cannot_pass_sipcall)) |
| 564 | .setTitle(getResources().getString(R.string.cannot_pass_sipcall_title)) |
| 565 | .setPositiveButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() { |
| 566 | public void onClick(DialogInterface dialog, int whichButton) { |
Alexandre Lision | 5ed2c97 | 2013-10-11 15:36:33 -0400 | [diff] [blame] | 567 | |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 568 | } |
| 569 | }); |
| 570 | |
| 571 | AlertDialog alertDialog = builder.create(); |
| 572 | alertDialog.setOwnerActivity(ownerActivity); |
| 573 | |
| 574 | return alertDialog; |
| 575 | } |
| 576 | |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 577 | private AlertDialog createAccountDialog() { |
| 578 | final Activity ownerActivity = this; |
| 579 | AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity); |
| 580 | |
| 581 | builder.setMessage(getResources().getString(R.string.create_new_account_dialog)) |
| 582 | .setTitle(getResources().getString(R.string.create_new_account_dialog_title)) |
| 583 | .setPositiveButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() { |
| 584 | public void onClick(DialogInterface dialog, int whichButton) { |
| 585 | Intent in = new Intent(); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 586 | in.setClass(ownerActivity, AccountWizard.class); |
Alexandre Lision | 4ab5397 | 2013-11-04 16:59:18 -0500 | [diff] [blame] | 587 | ownerActivity.startActivityForResult(in, HomeActivity.REQUEST_CODE_PREFERENCES); |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 588 | } |
| 589 | }).setNegativeButton(getResources().getString(android.R.string.cancel), new DialogInterface.OnClickListener() { |
Alexandre Lision | fed2a64 | 2014-01-10 12:05:47 -0500 | [diff] [blame] | 590 | public void onClick(DialogInterface dialog, int whichButton) { |
| 591 | dialog.dismiss(); |
| 592 | } |
| 593 | }); |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 594 | |
| 595 | AlertDialog alertDialog = builder.create(); |
| 596 | alertDialog.setOwnerActivity(ownerActivity); |
| 597 | |
| 598 | return alertDialog; |
| 599 | } |
| 600 | |
alision | d45da71 | 2013-05-30 09:18:49 -0400 | [diff] [blame] | 601 | @Override |
| 602 | public void onContactDragged() { |
Alexandre Lision | 450458a | 2013-11-22 11:33:12 -0500 | [diff] [blame] | 603 | mContactDrawer.collapsePane(); |
alision | d45da71 | 2013-05-30 09:18:49 -0400 | [diff] [blame] | 604 | } |
| 605 | |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 606 | @Override |
Alexandre Lision | 0936ba6 | 2013-11-25 10:04:56 -0500 | [diff] [blame] | 607 | public void toggleDrawer() { |
Alexandre Lision | c985b36 | 2013-12-10 17:45:03 -0500 | [diff] [blame] | 608 | if (mContactDrawer.isAnchored()) |
Alexandre Lision | 0936ba6 | 2013-11-25 10:04:56 -0500 | [diff] [blame] | 609 | mContactDrawer.expandPane(); |
Alexandre Lision | c985b36 | 2013-12-10 17:45:03 -0500 | [diff] [blame] | 610 | else if (!mContactDrawer.isExpanded()) |
| 611 | mContactDrawer.expandPane(0.3f); |
Alexandre Lision | c9b4e9e | 2013-11-27 10:27:28 -0500 | [diff] [blame] | 612 | else |
| 613 | mContactDrawer.collapsePane(); |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 614 | } |
| 615 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 616 | @Override |
Alexandre Lision | a458ba2 | 2013-12-11 15:04:11 -0500 | [diff] [blame] | 617 | public void toggleForSearchDrawer() { |
| 618 | if (mContactDrawer.isExpanded()) { |
| 619 | mContactDrawer.collapsePane(); |
| 620 | } else |
| 621 | mContactDrawer.expandPane(); |
| 622 | } |
| 623 | |
| 624 | @Override |
Alexandre Lision | 0936ba6 | 2013-11-25 10:04:56 -0500 | [diff] [blame] | 625 | public void setDragView(RelativeLayout relativeLayout) { |
| 626 | mContactDrawer.setDragView(relativeLayout); |
| 627 | } |
| 628 | |
Alexandre Lision | 269e604 | 2013-12-11 16:15:13 -0500 | [diff] [blame] | 629 | @Override |
| 630 | public void onSectionSelected(int pos) { |
Alexandre Lision | f02190d | 2013-12-12 17:26:12 -0500 | [diff] [blame] | 631 | |
| 632 | mNavigationDrawer.closeDrawers(); |
Alexandre Lision | fed2a64 | 2014-01-10 12:05:47 -0500 | [diff] [blame] | 633 | |
| 634 | switch (pos) { |
| 635 | case 0: |
| 636 | |
| 637 | if (fContent instanceof HomeFragment) |
| 638 | break; |
| 639 | |
Alexandre Lision | be54c34 | 2014-01-21 17:10:33 -0500 | [diff] [blame] | 640 | if (getSupportFragmentManager().getBackStackEntryCount() == 1) |
Alexandre Lision | fed2a64 | 2014-01-10 12:05:47 -0500 | [diff] [blame] | 641 | break; |
| 642 | |
| 643 | popCustomBackStack(); |
| 644 | |
| 645 | break; |
| 646 | case 1: |
| 647 | if (fContent instanceof AccountsManagementFragment) |
| 648 | break; |
| 649 | fContent = new AccountsManagementFragment(); |
Alexandre Lision | be54c34 | 2014-01-21 17:10:33 -0500 | [diff] [blame] | 650 | 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] | 651 | break; |
| 652 | case 2: |
| 653 | if (fContent instanceof AboutFragment) |
| 654 | break; |
| 655 | fContent = new AboutFragment(); |
Alexandre Lision | be54c34 | 2014-01-21 17:10:33 -0500 | [diff] [blame] | 656 | 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] | 657 | break; |
| 658 | } |
| 659 | |
| 660 | |
Alexandre Lision | 269e604 | 2013-12-11 16:15:13 -0500 | [diff] [blame] | 661 | } |
| 662 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 663 | } |