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 | 5ed2c97 | 2013-10-11 15:36:33 -0400 | [diff] [blame] | 34 | import java.io.InvalidObjectException; |
alision | bd45a82 | 2013-06-06 17:35:35 -0400 | [diff] [blame] | 35 | import java.util.Timer; |
| 36 | import java.util.TimerTask; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 37 | |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 38 | import org.sflphone.R; |
| 39 | import org.sflphone.adapters.SectionsPagerAdapter; |
| 40 | import org.sflphone.fragments.ContactListFragment; |
| 41 | import org.sflphone.fragments.DialingFragment; |
| 42 | import org.sflphone.fragments.HistoryFragment; |
| 43 | import org.sflphone.fragments.HomeFragment; |
| 44 | import org.sflphone.fragments.MenuFragment; |
| 45 | import org.sflphone.interfaces.CallInterface; |
| 46 | import org.sflphone.loaders.LoaderConstants; |
| 47 | import org.sflphone.model.CallContact; |
| 48 | import org.sflphone.model.Conference; |
| 49 | import org.sflphone.model.SipCall; |
| 50 | import org.sflphone.receivers.CallReceiver; |
| 51 | import org.sflphone.service.CallManagerCallBack; |
| 52 | import org.sflphone.service.ISipService; |
| 53 | import org.sflphone.service.SipService; |
| 54 | import org.sflphone.views.CustomSlidingDrawer; |
Alexandre Lision | 8b9d8e8 | 2013-10-04 09:21:27 -0400 | [diff] [blame] | 55 | import org.sflphone.views.CustomSlidingDrawer.OnDrawerScrollListener; |
Alexandre Lision | e5b6602 | 2013-10-30 11:34:15 -0400 | [diff] [blame] | 56 | import org.sflphone.views.PagerSlidingTabStrip; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 57 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 58 | import android.app.Activity; |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 59 | import android.app.AlertDialog; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 60 | import android.content.ComponentName; |
| 61 | import android.content.Context; |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 62 | import android.content.DialogInterface; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 63 | import android.content.Intent; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 64 | import android.content.IntentFilter; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 65 | import android.content.ServiceConnection; |
alision | f57d8a6 | 2013-07-02 09:37:12 -0400 | [diff] [blame] | 66 | import android.content.res.Configuration; |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 67 | import android.database.Cursor; |
Alexandre Lision | c59685a | 2013-10-04 16:36:36 -0400 | [diff] [blame] | 68 | import android.net.Uri; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 69 | import android.os.Bundle; |
| 70 | import android.os.IBinder; |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 71 | import android.os.RemoteException; |
Alexandre Lision | c59685a | 2013-10-04 16:36:36 -0400 | [diff] [blame] | 72 | import android.provider.ContactsContract; |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 73 | import android.provider.ContactsContract.CommonDataKinds.Phone; |
| 74 | import android.provider.ContactsContract.CommonDataKinds.SipAddress; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 75 | import android.support.v4.app.ActionBarDrawerToggle; |
| 76 | import android.support.v4.view.GravityCompat; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 77 | import android.support.v4.view.ViewPager; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 78 | import android.support.v4.widget.DrawerLayout; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 79 | import android.util.Log; |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 80 | import android.view.Gravity; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 81 | import android.view.MenuItem; |
| 82 | import android.view.View; |
Alexandre Lision | 6890005 | 2013-11-01 11:34:56 -0400 | [diff] [blame] | 83 | import android.widget.ImageView; |
alision | 7297bdb | 2013-05-21 11:56:55 -0400 | [diff] [blame] | 84 | import android.widget.RelativeLayout; |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 85 | import android.widget.Toast; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 86 | |
Alexandre Lision | 4ab5397 | 2013-11-04 16:59:18 -0500 | [diff] [blame^] | 87 | public class HomeActivity extends Activity implements DialingFragment.Callbacks, ContactListFragment.Callbacks, HomeFragment.Callbacks, |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 88 | HistoryFragment.Callbacks, CallInterface, MenuFragment.Callbacks { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 89 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 90 | SectionsPagerAdapter mSectionsPagerAdapter = null; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 91 | static final String TAG = "SFLPhoneHomeActivity"; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 92 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 93 | private ContactListFragment mContactsFragment = null; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 94 | private MenuFragment fMenu; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 95 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 96 | private boolean mBound = false; |
| 97 | private ISipService service; |
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 CharSequence mDrawerTitle; |
| 100 | private CharSequence mTitle; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 101 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 102 | public static final int REQUEST_CODE_PREFERENCES = 1; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 103 | private static final int REQUEST_CODE_CALL = 2; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 104 | |
alision | 0b55383 | 2013-05-30 09:31:06 -0400 | [diff] [blame] | 105 | RelativeLayout mSliderButton; |
Alexandre Lision | 6890005 | 2013-11-01 11:34:56 -0400 | [diff] [blame] | 106 | CustomSlidingDrawer mContactDrawer; |
| 107 | private DrawerLayout mNavigationDrawer; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 108 | private ActionBarDrawerToggle mDrawerToggle; |
Alexandre Lision | c87763a | 2013-11-01 12:53:38 -0400 | [diff] [blame] | 109 | ImageView mShadow; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 110 | /** |
| 111 | * The {@link ViewPager} that will host the section contents. |
| 112 | */ |
| 113 | ViewPager mViewPager; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 114 | |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 115 | CallReceiver callReceiver; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 116 | |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 117 | // private TabHost mTabHost; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 118 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 119 | // public SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener |
| 120 | |
| 121 | /* called before activity is killed, e.g. rotation */ |
| 122 | @Override |
| 123 | protected void onSaveInstanceState(Bundle bundle) { |
| 124 | super.onSaveInstanceState(bundle); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 125 | getFragmentManager().putFragment(bundle, "ContactsListFragment", mContactsFragment); |
| 126 | Log.w(TAG, "onSaveInstanceState()"); |
| 127 | } |
| 128 | |
| 129 | @Override |
| 130 | public void onCreate(Bundle savedInstanceState) { |
| 131 | super.onCreate(savedInstanceState); |
| 132 | |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 133 | callReceiver = new CallReceiver(this); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 134 | |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 135 | setContentView(R.layout.activity_sflphone_home); |
| 136 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 137 | // Bind to LocalService |
| 138 | if (!mBound) { |
| 139 | Log.i(TAG, "onStart: Binding service..."); |
| 140 | Intent intent = new Intent(this, SipService.class); |
Alexandre Lision | 0f550ee | 2013-10-25 15:34:38 -0400 | [diff] [blame] | 141 | startService(intent); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 142 | bindService(intent, mConnection, Context.BIND_AUTO_CREATE); |
| 143 | } |
Alexandre Lision | 8b9d8e8 | 2013-10-04 09:21:27 -0400 | [diff] [blame] | 144 | |
| 145 | if (savedInstanceState != null) { |
Alexandre Lision | 23628c1 | 2013-09-24 11:17:05 -0400 | [diff] [blame] | 146 | mContactsFragment = (ContactListFragment) getFragmentManager().getFragment(savedInstanceState, "ContactsListFragment"); |
| 147 | } |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 148 | if (mContactsFragment == null) { |
| 149 | mContactsFragment = new ContactListFragment(); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 150 | getFragmentManager().beginTransaction().replace(R.id.contacts_frame, mContactsFragment).commit(); |
| 151 | } |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 152 | |
Alexandre Lision | 6890005 | 2013-11-01 11:34:56 -0400 | [diff] [blame] | 153 | mContactDrawer = (CustomSlidingDrawer) findViewById(R.id.custom_sliding_drawer); |
alision | 7297bdb | 2013-05-21 11:56:55 -0400 | [diff] [blame] | 154 | |
Alexandre Lision | 6890005 | 2013-11-01 11:34:56 -0400 | [diff] [blame] | 155 | mContactDrawer.setOnDrawerScrollListener(new OnDrawerScrollListener() { |
Alexandre Lision | 8b9d8e8 | 2013-10-04 09:21:27 -0400 | [diff] [blame] | 156 | |
| 157 | @Override |
| 158 | public void onScrollStarted() { |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 159 | // getActionBar().hide(); |
Alexandre Lision | 8b9d8e8 | 2013-10-04 09:21:27 -0400 | [diff] [blame] | 160 | |
| 161 | } |
| 162 | |
| 163 | @Override |
| 164 | public void onScrollEnded() { |
Alexandre Lision | c87763a | 2013-11-01 12:53:38 -0400 | [diff] [blame] | 165 | if (!mContactDrawer.isOpened()) { |
| 166 | mShadow.setAlpha(0f); |
| 167 | } |
Alexandre Lision | 8b9d8e8 | 2013-10-04 09:21:27 -0400 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | @Override |
| 171 | public void onScroll(int offset) { |
Alexandre Lision | c87763a | 2013-11-01 12:53:38 -0400 | [diff] [blame] | 172 | |
| 173 | float relativeOffset = offset + getResources().getDimension(R.dimen.contact_drawer_handle_height); |
| 174 | float alpha = 1 - (((float) relativeOffset) / ((float) getResources().getDisplayMetrics().heightPixels)); |
| 175 | mShadow.setAlpha(alpha); |
Alexandre Lision | 8b9d8e8 | 2013-10-04 09:21:27 -0400 | [diff] [blame] | 176 | if (offset < 400) { |
| 177 | getActionBar().hide(); |
Alexandre Lision | c87763a | 2013-11-01 12:53:38 -0400 | [diff] [blame] | 178 | // mNavigationDrawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); |
Alexandre Lision | 8b9d8e8 | 2013-10-04 09:21:27 -0400 | [diff] [blame] | 179 | } else if (offset > 450) { |
| 180 | getActionBar().show(); |
Alexandre Lision | c87763a | 2013-11-01 12:53:38 -0400 | [diff] [blame] | 181 | // mNavigationDrawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED); |
Alexandre Lision | 8b9d8e8 | 2013-10-04 09:21:27 -0400 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | }); |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 185 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 186 | mContactsFragment.setHandleView((RelativeLayout) findViewById(R.id.slider_button)); |
Alexandre Lision | c87763a | 2013-11-01 12:53:38 -0400 | [diff] [blame] | 187 | mShadow = (ImageView) findViewById(R.id.overall_shadow); |
Alexandre Lision | 6890005 | 2013-11-01 11:34:56 -0400 | [diff] [blame] | 188 | mContactDrawer.setmTrackHandle(findViewById(R.id.handle_title)); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 189 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 190 | // Set up the ViewPager with the sections adapter. |
| 191 | mViewPager = (ViewPager) findViewById(R.id.pager); |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 192 | mViewPager.setPageTransformer(true, new ZoomOutPageTransformer(0.7f)); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 193 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 194 | mTitle = mDrawerTitle = getTitle(); |
Alexandre Lision | 6890005 | 2013-11-01 11:34:56 -0400 | [diff] [blame] | 195 | mNavigationDrawer = (DrawerLayout) findViewById(R.id.drawer_layout); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 196 | |
alision | 0b55383 | 2013-05-30 09:31:06 -0400 | [diff] [blame] | 197 | // 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] | 198 | mNavigationDrawer.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 199 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 200 | getActionBar().setDisplayHomeAsUpEnabled(true); |
| 201 | getActionBar().setHomeButtonEnabled(true); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 202 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 203 | mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ |
Alexandre Lision | 6890005 | 2013-11-01 11:34:56 -0400 | [diff] [blame] | 204 | mNavigationDrawer, /* DrawerLayout object */ |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 205 | R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ |
| 206 | R.string.drawer_open, /* "open drawer" description for accessibility */ |
| 207 | R.string.drawer_close /* "close drawer" description for accessibility */ |
| 208 | ) { |
alision | 0b55383 | 2013-05-30 09:31:06 -0400 | [diff] [blame] | 209 | @Override |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 210 | public void onDrawerClosed(View view) { |
| 211 | getActionBar().setTitle(mTitle); |
| 212 | invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() |
| 213 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 214 | |
alision | 0b55383 | 2013-05-30 09:31:06 -0400 | [diff] [blame] | 215 | @Override |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 216 | public void onDrawerOpened(View drawerView) { |
| 217 | getActionBar().setTitle(mDrawerTitle); |
| 218 | invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() |
| 219 | } |
| 220 | }; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 221 | |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 222 | // mTabHost = (TabHost) findViewById(android.R.id.tabhost); |
Alexandre Lision | 6890005 | 2013-11-01 11:34:56 -0400 | [diff] [blame] | 223 | mNavigationDrawer.setDrawerListener(mDrawerToggle); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 224 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 225 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 226 | |
alision | f57d8a6 | 2013-07-02 09:37:12 -0400 | [diff] [blame] | 227 | @Override |
| 228 | protected void onPostCreate(Bundle savedInstanceState) { |
| 229 | super.onPostCreate(savedInstanceState); |
| 230 | // Sync the toggle state after onRestoreInstanceState has occurred. |
| 231 | mDrawerToggle.syncState(); |
Alexandre Lision | 6890005 | 2013-11-01 11:34:56 -0400 | [diff] [blame] | 232 | if (mContactDrawer.isOpened()) { |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 233 | getActionBar().hide(); |
| 234 | } |
alision | f57d8a6 | 2013-07-02 09:37:12 -0400 | [diff] [blame] | 235 | } |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 236 | |
alision | f57d8a6 | 2013-07-02 09:37:12 -0400 | [diff] [blame] | 237 | @Override |
| 238 | public void onConfigurationChanged(Configuration newConfig) { |
| 239 | super.onConfigurationChanged(newConfig); |
| 240 | mDrawerToggle.onConfigurationChanged(newConfig); |
| 241 | } |
alision | 3c5c2a9 | 2013-05-30 09:50:47 -0400 | [diff] [blame] | 242 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 243 | @Override |
| 244 | protected void onStart() { |
| 245 | Log.i(TAG, "onStart"); |
| 246 | super.onStart(); |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 247 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 248 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 249 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 250 | /* user gets back to the activity, e.g. through task manager */ |
| 251 | @Override |
| 252 | protected void onRestart() { |
| 253 | super.onRestart(); |
| 254 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 255 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 256 | /* activity gets back to the foreground and user input */ |
| 257 | @Override |
| 258 | protected void onResume() { |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 259 | super.onResume(); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 260 | IntentFilter intentFilter = new IntentFilter(); |
| 261 | intentFilter.addAction(CallManagerCallBack.INCOMING_CALL); |
| 262 | intentFilter.addAction(CallManagerCallBack.INCOMING_TEXT); |
| 263 | intentFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED); |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 264 | registerReceiver(callReceiver, intentFilter); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 265 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 266 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 267 | |
alision | bd45a82 | 2013-06-06 17:35:35 -0400 | [diff] [blame] | 268 | private boolean isClosing = false; |
| 269 | private Timer t = new Timer(); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 270 | |
alision | bd45a82 | 2013-06-06 17:35:35 -0400 | [diff] [blame] | 271 | @Override |
| 272 | public void onBackPressed() { |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 273 | |
Alexandre Lision | 6890005 | 2013-11-01 11:34:56 -0400 | [diff] [blame] | 274 | if (mNavigationDrawer.isDrawerVisible(Gravity.LEFT)) { |
| 275 | mNavigationDrawer.closeDrawer(Gravity.LEFT); |
Alexandre Lision | 6885547 | 2013-10-10 16:20:46 -0400 | [diff] [blame] | 276 | return; |
Alexandre Lision | 3ccccf0 | 2013-10-07 14:10:46 -0400 | [diff] [blame] | 277 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 278 | if (getActionBar().getCustomView() != null) { |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 279 | getActionBar().setDisplayShowCustomEnabled(false); |
| 280 | getActionBar().setCustomView(null); |
| 281 | // Display all the contacts again |
| 282 | getLoaderManager().restartLoader(LoaderConstants.CONTACT_LOADER, null, mContactsFragment); |
| 283 | return; |
| 284 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 285 | |
Alexandre Lision | 6890005 | 2013-11-01 11:34:56 -0400 | [diff] [blame] | 286 | if (mContactDrawer.isOpened()) { |
| 287 | mContactDrawer.animateClose(); |
alision | bd45a82 | 2013-06-06 17:35:35 -0400 | [diff] [blame] | 288 | return; |
| 289 | } |
alision | 2ec64f9 | 2013-06-17 17:28:58 -0400 | [diff] [blame] | 290 | |
alision | bd45a82 | 2013-06-06 17:35:35 -0400 | [diff] [blame] | 291 | if (isClosing) { |
| 292 | super.onBackPressed(); |
| 293 | t.cancel(); |
| 294 | finish(); |
| 295 | } else { |
| 296 | |
| 297 | t.schedule(new TimerTask() { |
| 298 | @Override |
| 299 | public void run() { |
| 300 | isClosing = false; |
| 301 | } |
| 302 | }, 3000); |
| 303 | Toast.makeText(this, getResources().getString(R.string.close_msg), Toast.LENGTH_SHORT).show(); |
| 304 | isClosing = true; |
| 305 | } |
| 306 | } |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 307 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 308 | /* activity no more in foreground */ |
| 309 | @Override |
| 310 | protected void onPause() { |
| 311 | super.onPause(); |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 312 | unregisterReceiver(callReceiver); |
Alexandre Lision | b4a9e39 | 2013-10-01 14:39:43 -0400 | [diff] [blame] | 313 | if (mBound) { |
| 314 | unbindService(mConnection); |
| 315 | mBound = false; |
| 316 | } |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 317 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 318 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 319 | /* activity finishes itself or is being killed by the system */ |
| 320 | @Override |
| 321 | protected void onDestroy() { |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 322 | super.onDestroy(); |
Alexandre Lision | b4a9e39 | 2013-10-01 14:39:43 -0400 | [diff] [blame] | 323 | Log.i(TAG, "onDestroy: destroying service..."); |
| 324 | Intent sipServiceIntent = new Intent(this, SipService.class); |
| 325 | stopService(sipServiceIntent); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 326 | } |
alision | 73424b6 | 2013-04-26 11:49:18 -0400 | [diff] [blame] | 327 | |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 328 | public void launchCallActivity(SipCall infos) { |
Alexandre Lision | c59685a | 2013-10-04 16:36:36 -0400 | [diff] [blame] | 329 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 330 | Bundle bundle = new Bundle(); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 331 | Conference tmp = new Conference("-1"); |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 332 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 333 | tmp.getParticipants().add(infos); |
alision | 465ceba | 2013-07-04 09:24:30 -0400 | [diff] [blame] | 334 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 335 | bundle.putParcelable("conference", tmp); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 336 | Intent intent = new Intent().setClass(this, CallActivity.class); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 337 | intent.putExtra("resuming", false); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 338 | intent.putExtras(bundle); |
| 339 | startActivityForResult(intent, REQUEST_CODE_CALL); |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 340 | |
Alexandre Lision | 8b9d8e8 | 2013-10-04 09:21:27 -0400 | [diff] [blame] | 341 | // overridePendingTransition(R.anim.slide_down, R.anim.slide_up); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 342 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 343 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 344 | /** Defines callbacks for service binding, passed to bindService() */ |
| 345 | private ServiceConnection mConnection = new ServiceConnection() { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 346 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 347 | @Override |
| 348 | public void onServiceConnected(ComponentName className, IBinder binder) { |
| 349 | service = ISipService.Stub.asInterface(binder); |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 350 | |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 351 | try { |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 352 | |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 353 | fMenu = new MenuFragment(); |
| 354 | getFragmentManager().beginTransaction().replace(R.id.left_drawer, fMenu).commit(); |
Alexandre Lision | 4ab5397 | 2013-11-04 16:59:18 -0500 | [diff] [blame^] | 355 | mSectionsPagerAdapter = new SectionsPagerAdapter(HomeActivity.this, getFragmentManager()); |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 356 | |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 357 | // initialiseTabHost(null); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 358 | mViewPager.setOffscreenPageLimit(2); |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 359 | mViewPager.setAdapter(mSectionsPagerAdapter); |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 360 | mViewPager.setCurrentItem(1); |
Alexandre Lision | e5b6602 | 2013-10-30 11:34:15 -0400 | [diff] [blame] | 361 | |
| 362 | final PagerSlidingTabStrip strip = PagerSlidingTabStrip.class.cast(findViewById(R.id.pts_main)); |
| 363 | |
Alexandre Lision | 6890005 | 2013-11-01 11:34:56 -0400 | [diff] [blame] | 364 | // strip.setBackgroundColor(getResources().getColor(R.color.sfl_blue_0)); |
Alexandre Lision | e5b6602 | 2013-10-30 11:34:15 -0400 | [diff] [blame] | 365 | strip.setViewPager(mViewPager); |
| 366 | |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 367 | // mTabHost.setCurrentTab(1); |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 368 | service.destroyNotification(); |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 369 | // mAdapter = new AccountSelectionAdapter(SFLPhoneHomeActivity.this, service, new ArrayList<Account>()); |
| 370 | // spinnerAccounts.setAdapter(mAdapter); |
alision | 2cb9956 | 2013-05-30 17:02:20 -0400 | [diff] [blame] | 371 | } catch (RemoteException e) { |
| 372 | Log.e(TAG, e.toString()); |
| 373 | } |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 374 | mBound = true; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 375 | Log.d(TAG, "Service connected service=" + service); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 376 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 377 | } |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 378 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 379 | @Override |
| 380 | public void onServiceDisconnected(ComponentName arg0) { |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 381 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 382 | mBound = false; |
| 383 | Log.d(TAG, "Service disconnected service=" + service); |
| 384 | } |
| 385 | }; |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 386 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 387 | @Override |
| 388 | public boolean onOptionsItemSelected(MenuItem item) { |
| 389 | Log.i(TAG, "onOptionsItemSelected " + item.getItemId()); |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 390 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 391 | if (mDrawerToggle.onOptionsItemSelected(item)) { |
| 392 | return true; |
| 393 | } |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 394 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 395 | return super.onOptionsItemSelected(item); |
| 396 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 397 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 398 | @Override |
| 399 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 400 | super.onActivityResult(requestCode, resultCode, data); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 401 | |
| 402 | switch (requestCode) { |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 403 | case REQUEST_CODE_PREFERENCES: |
Alexandre Lision | e5b6602 | 2013-10-30 11:34:15 -0400 | [diff] [blame] | 404 | if (fMenu != null) |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 405 | fMenu.updateAllAccounts(); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 406 | break; |
| 407 | case REQUEST_CODE_CALL: |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 408 | if (resultCode == CallActivity.RESULT_FAILURE) { |
Alexandre Lision | 8b9d8e8 | 2013-10-04 09:21:27 -0400 | [diff] [blame] | 409 | Log.w(TAG, "Call Failed"); |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 410 | } |
| 411 | // if (mSectionsPagerAdapter != null && mSectionsPagerAdapter.getItem(2) != null) |
| 412 | // getLoaderManager().restartLoader(LoaderConstants.HISTORY_LOADER, null, (HistoryFragment) mSectionsPagerAdapter.getItem(2)); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 413 | break; |
| 414 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 415 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 416 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 417 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 418 | @Override |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 419 | public ISipService getService() { |
| 420 | return service; |
| 421 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 422 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 423 | /** |
| 424 | * Interface implemented to handle incoming events |
| 425 | */ |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 426 | @Override |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 427 | public void incomingCall(Intent call) { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 428 | SipCall infos = call.getParcelableExtra("newcall"); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 429 | |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 430 | // mCallElementList.addCall(infos); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 431 | |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 432 | launchCallActivity(infos); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 433 | |
| 434 | } |
| 435 | |
| 436 | @Override |
| 437 | public void callStateChanged(Intent callState) { |
| 438 | Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate"); |
| 439 | String cID = b.getString("CallID"); |
| 440 | String state = b.getString("State"); |
| 441 | Log.i(TAG, "callStateChanged" + cID + " " + state); |
Alexandre Lision | 1a9e3b1 | 2013-09-16 11:06:07 -0400 | [diff] [blame] | 442 | mSectionsPagerAdapter.updateHome(); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 443 | |
| 444 | } |
| 445 | |
| 446 | @Override |
| 447 | public void incomingText(Intent msg) { |
| 448 | Bundle b = msg.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext"); |
| 449 | b.getString("CallID"); |
| 450 | String from = b.getString("From"); |
| 451 | String mess = b.getString("Msg"); |
| 452 | Toast.makeText(getApplicationContext(), "text from " + from + " : " + mess, Toast.LENGTH_LONG).show(); |
| 453 | } |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 454 | |
Alexandre Lision | e1c96db | 2013-10-04 14:34:21 -0400 | [diff] [blame] | 455 | @Override |
| 456 | public void onTextContact(final CallContact c) { |
| 457 | // TODO |
| 458 | } |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 459 | |
Alexandre Lision | c59685a | 2013-10-04 16:36:36 -0400 | [diff] [blame] | 460 | @Override |
| 461 | public void onEditContact(final CallContact c) { |
| 462 | Intent intent = new Intent(Intent.ACTION_VIEW); |
| 463 | Uri uri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(c.getId())); |
| 464 | intent.setData(uri); |
| 465 | startActivity(intent); |
| 466 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 467 | |
| 468 | @Override |
Alexandre Lision | e1c96db | 2013-10-04 14:34:21 -0400 | [diff] [blame] | 469 | public void onCallContact(final CallContact c) { |
Alexandre Lision | 8b9d8e8 | 2013-10-04 09:21:27 -0400 | [diff] [blame] | 470 | |
Alexandre Lision | f0b993d | 2013-09-12 13:25:10 -0400 | [diff] [blame] | 471 | if (fMenu.getSelectedAccount() == null) { |
Alexandre Lision | f0b993d | 2013-09-12 13:25:10 -0400 | [diff] [blame] | 472 | createAccountDialog().show(); |
| 473 | return; |
| 474 | } |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 475 | |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 476 | if (!fMenu.getSelectedAccount().isRegistered()) { |
| 477 | createNotRegisteredDialog().show(); |
| 478 | return; |
| 479 | } |
| 480 | |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 481 | getActionBar().show(); |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 482 | Thread launcher = new Thread(new Runnable() { |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 483 | |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 484 | final String[] CONTACTS_PHONES_PROJECTION = new String[] { Phone.NUMBER, Phone.TYPE }; |
| 485 | final String[] CONTACTS_SIP_PROJECTION = new String[] { SipAddress.SIP_ADDRESS, SipAddress.TYPE }; |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 486 | |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 487 | @Override |
| 488 | public void run() { |
| 489 | SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance(); |
| 490 | try { |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 491 | callBuilder.startCallCreation().setAccount(fMenu.getSelectedAccount()).setCallType(SipCall.state.CALL_TYPE_OUTGOING); |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 492 | Cursor cPhones = getContentResolver().query(Phone.CONTENT_URI, CONTACTS_PHONES_PROJECTION, Phone.CONTACT_ID + " =" + c.getId(), |
| 493 | null, null); |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 494 | |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 495 | while (cPhones.moveToNext()) { |
| 496 | c.addPhoneNumber(cPhones.getString(cPhones.getColumnIndex(Phone.NUMBER)), cPhones.getInt(cPhones.getColumnIndex(Phone.TYPE))); |
| 497 | } |
| 498 | cPhones.close(); |
| 499 | |
| 500 | Cursor cSip = getContentResolver().query(Phone.CONTENT_URI, CONTACTS_SIP_PROJECTION, Phone.CONTACT_ID + "=" + c.getId(), null, |
| 501 | null); |
| 502 | |
| 503 | while (cSip.moveToNext()) { |
| 504 | c.addSipNumber(cSip.getString(cSip.getColumnIndex(SipAddress.SIP_ADDRESS)), cSip.getInt(cSip.getColumnIndex(SipAddress.TYPE))); |
| 505 | } |
| 506 | cSip.close(); |
| 507 | callBuilder.setContact(c); |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 508 | launchCallActivity(callBuilder.build()); |
Alexandre Lision | 5ed2c97 | 2013-10-11 15:36:33 -0400 | [diff] [blame] | 509 | } catch (InvalidObjectException e) { |
| 510 | e.printStackTrace(); |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 511 | } |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 512 | |
alision | 55c36cb | 2013-06-14 14:57:38 -0400 | [diff] [blame] | 513 | } |
| 514 | }); |
| 515 | launcher.start(); |
Alexandre Lision | 4ab5397 | 2013-11-04 16:59:18 -0500 | [diff] [blame^] | 516 | mContactDrawer.animateClose(); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 517 | |
| 518 | } |
| 519 | |
| 520 | @Override |
alision | 907bde7 | 2013-06-20 14:40:37 -0400 | [diff] [blame] | 521 | public void onCallDialed(String to) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 522 | |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 523 | if (fMenu.getSelectedAccount() == null) { |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 524 | createAccountDialog().show(); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 525 | return; |
| 526 | } |
| 527 | |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 528 | if (fMenu.getSelectedAccount().isRegistered()) { |
| 529 | SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance(); |
| 530 | callBuilder.startCallCreation().setAccount(fMenu.getSelectedAccount()).setCallType(SipCall.state.CALL_TYPE_OUTGOING); |
| 531 | callBuilder.setContact(CallContact.ContactBuilder.buildUnknownContact(to)); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 532 | |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 533 | try { |
| 534 | launchCallActivity(callBuilder.build()); |
| 535 | } catch (Exception e) { |
| 536 | Log.e(TAG, e.toString()); |
| 537 | } |
| 538 | } else { |
Alexandre Lision | 5ed2c97 | 2013-10-11 15:36:33 -0400 | [diff] [blame] | 539 | createNotRegisteredDialog().show(); |
| 540 | ; |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 541 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 542 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 543 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 544 | |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 545 | private AlertDialog createNotRegisteredDialog() { |
| 546 | final Activity ownerActivity = this; |
| 547 | AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity); |
| 548 | |
| 549 | builder.setMessage(getResources().getString(R.string.cannot_pass_sipcall)) |
| 550 | .setTitle(getResources().getString(R.string.cannot_pass_sipcall_title)) |
| 551 | .setPositiveButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() { |
| 552 | public void onClick(DialogInterface dialog, int whichButton) { |
Alexandre Lision | 5ed2c97 | 2013-10-11 15:36:33 -0400 | [diff] [blame] | 553 | |
Alexandre Lision | d588bff | 2013-10-08 12:43:01 -0400 | [diff] [blame] | 554 | } |
| 555 | }); |
| 556 | |
| 557 | AlertDialog alertDialog = builder.create(); |
| 558 | alertDialog.setOwnerActivity(ownerActivity); |
| 559 | |
| 560 | return alertDialog; |
| 561 | } |
| 562 | |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 563 | private AlertDialog createAccountDialog() { |
| 564 | final Activity ownerActivity = this; |
| 565 | AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity); |
| 566 | |
| 567 | builder.setMessage(getResources().getString(R.string.create_new_account_dialog)) |
| 568 | .setTitle(getResources().getString(R.string.create_new_account_dialog_title)) |
| 569 | .setPositiveButton(getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() { |
| 570 | public void onClick(DialogInterface dialog, int whichButton) { |
| 571 | Intent in = new Intent(); |
Alexandre Lision | 40954dc | 2013-10-09 15:24:03 -0400 | [diff] [blame] | 572 | in.setClass(ownerActivity, AccountWizard.class); |
Alexandre Lision | 4ab5397 | 2013-11-04 16:59:18 -0500 | [diff] [blame^] | 573 | ownerActivity.startActivityForResult(in, HomeActivity.REQUEST_CODE_PREFERENCES); |
Alexandre Lision | c51ccb1 | 2013-09-11 16:00:30 -0400 | [diff] [blame] | 574 | } |
| 575 | }).setNegativeButton(getResources().getString(android.R.string.cancel), new DialogInterface.OnClickListener() { |
| 576 | public void onClick(DialogInterface dialog, int whichButton) { |
| 577 | dialog.dismiss(); |
| 578 | } |
| 579 | }); |
| 580 | |
| 581 | AlertDialog alertDialog = builder.create(); |
| 582 | alertDialog.setOwnerActivity(ownerActivity); |
| 583 | |
| 584 | return alertDialog; |
| 585 | } |
| 586 | |
alision | d45da71 | 2013-05-30 09:18:49 -0400 | [diff] [blame] | 587 | @Override |
| 588 | public void onContactDragged() { |
Alexandre Lision | 4ab5397 | 2013-11-04 16:59:18 -0500 | [diff] [blame^] | 589 | mContactDrawer.animateClose(); |
alision | d45da71 | 2013-05-30 09:18:49 -0400 | [diff] [blame] | 590 | } |
| 591 | |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 592 | @Override |
| 593 | public void openDrawer() { |
Alexandre Lision | 6890005 | 2013-11-01 11:34:56 -0400 | [diff] [blame] | 594 | mContactDrawer.animateOpen(); |
alision | 58356b7 | 2013-06-03 17:13:36 -0400 | [diff] [blame] | 595 | } |
| 596 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 597 | @Override |
| 598 | public void confCreated(Intent intent) { |
| 599 | // TODO Auto-generated method stub |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 600 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | @Override |
| 604 | public void confRemoved(Intent intent) { |
| 605 | // TODO Auto-generated method stub |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 606 | |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 607 | } |
| 608 | |
| 609 | @Override |
| 610 | public void confChanged(Intent intent) { |
| 611 | // TODO Auto-generated method stub |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 612 | |
| 613 | } |
| 614 | |
| 615 | @Override |
| 616 | public void recordingChanged(Intent intent) { |
| 617 | // TODO Auto-generated method stub |
| 618 | |
| 619 | } |
| 620 | |
| 621 | @Override |
Alexandre Lision | 1a9e3b1 | 2013-09-16 11:06:07 -0400 | [diff] [blame] | 622 | public void selectedCall(Conference c) { |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 623 | Intent intent = new Intent().setClass(this, CallActivity.class); |
| 624 | intent.putExtra("resuming", true); |
Alexandre Lision | 1a9e3b1 | 2013-09-16 11:06:07 -0400 | [diff] [blame] | 625 | intent.putExtra("conference", c); |
alision | df1dac9 | 2013-06-27 17:35:53 -0400 | [diff] [blame] | 626 | startActivityForResult(intent, REQUEST_CODE_CALL); |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 627 | } |
Alexandre Lision | 8b9d8e8 | 2013-10-04 09:21:27 -0400 | [diff] [blame] | 628 | |
Alexandre Lision | ee37f7c | 2013-09-25 17:36:39 -0400 | [diff] [blame] | 629 | private class ZoomOutPageTransformer implements ViewPager.PageTransformer { |
| 630 | private static final float MIN_ALPHA = .6f; |
Alexandre Lision | 8b9d8e8 | 2013-10-04 09:21:27 -0400 | [diff] [blame] | 631 | |
| 632 | // private final float scalingStart; |
Alexandre Lision | ee37f7c | 2013-09-25 17:36:39 -0400 | [diff] [blame] | 633 | |
| 634 | public ZoomOutPageTransformer(float scalingStart) { |
| 635 | super(); |
Alexandre Lision | 8b9d8e8 | 2013-10-04 09:21:27 -0400 | [diff] [blame] | 636 | // this.scalingStart = 1 - scalingStart; |
Alexandre Lision | ee37f7c | 2013-09-25 17:36:39 -0400 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | @Override |
| 640 | public void transformPage(View page, float position) { |
| 641 | // page.setRotationY(position * -30); |
| 642 | final float normalizedposition = Math.abs(Math.abs(position) - 1); |
Alexandre Lision | 8b9d8e8 | 2013-10-04 09:21:27 -0400 | [diff] [blame] | 643 | page.setAlpha(MIN_ALPHA + (1.f - MIN_ALPHA) * normalizedposition); |
Alexandre Lision | ee37f7c | 2013-09-25 17:36:39 -0400 | [diff] [blame] | 644 | } |
| 645 | } |
alision | 806e18e | 2013-06-21 15:30:17 -0400 | [diff] [blame] | 646 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 647 | } |