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