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