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