alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2012 Savoir-Faire Linux Inc. |
| 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 | */ |
| 32 | package com.savoirfairelinux.sflphone.client; |
| 33 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 34 | import android.app.ActionBar; |
| 35 | import android.app.Activity; |
| 36 | import android.app.Fragment; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 37 | import android.app.FragmentTransaction; |
| 38 | import android.content.ComponentName; |
| 39 | import android.content.Context; |
| 40 | import android.content.Intent; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 41 | import android.content.IntentFilter; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 42 | import android.content.ServiceConnection; |
| 43 | import android.os.Bundle; |
| 44 | import android.os.IBinder; |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 45 | import android.os.RemoteException; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 46 | import android.support.v4.app.ActionBarDrawerToggle; |
| 47 | import android.support.v4.view.GravityCompat; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 48 | import android.support.v4.view.ViewPager; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 49 | import android.support.v4.widget.DrawerLayout; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 50 | import android.util.Log; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 51 | import android.view.MenuItem; |
| 52 | import android.view.View; |
alision | 7297bdb | 2013-05-21 11:56:55 -0400 | [diff] [blame] | 53 | import android.widget.RelativeLayout; |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 54 | import android.widget.Toast; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 55 | |
| 56 | import com.savoirfairelinux.sflphone.R; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 57 | import com.savoirfairelinux.sflphone.adapters.SectionsPagerAdapter; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 58 | import com.savoirfairelinux.sflphone.client.receiver.CallReceiver; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 59 | import com.savoirfairelinux.sflphone.fragments.CallElementListFragment; |
| 60 | import com.savoirfairelinux.sflphone.fragments.ContactListFragment; |
alision | 7297bdb | 2013-05-21 11:56:55 -0400 | [diff] [blame] | 61 | import com.savoirfairelinux.sflphone.fragments.DialingFragment; |
alision | d9e2944 | 2013-04-17 16:10:18 -0400 | [diff] [blame] | 62 | import com.savoirfairelinux.sflphone.fragments.HistoryFragment; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 63 | import com.savoirfairelinux.sflphone.fragments.MenuFragment; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 64 | import com.savoirfairelinux.sflphone.interfaces.CallInterface; |
| 65 | import com.savoirfairelinux.sflphone.model.CallContact; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 66 | import com.savoirfairelinux.sflphone.model.SipCall; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 67 | import com.savoirfairelinux.sflphone.service.CallManagerCallBack; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 68 | import com.savoirfairelinux.sflphone.service.ISipService; |
| 69 | import com.savoirfairelinux.sflphone.service.SipService; |
alision | 7297bdb | 2013-05-21 11:56:55 -0400 | [diff] [blame] | 70 | import com.savoirfairelinux.sflphone.views.CustomSlidingDrawer; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 71 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 72 | public class SFLPhoneHomeActivity extends Activity implements ActionBar.TabListener, DialingFragment.Callbacks, ContactListFragment.Callbacks, |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 73 | CallElementListFragment.Callbacks, HistoryFragment.Callbacks, CallInterface { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 74 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 75 | SectionsPagerAdapter mSectionsPagerAdapter = null; |
| 76 | static final String TAG = "SFLPhoneHomeActivity"; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 77 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 78 | private ContactListFragment mContactsFragment = null; |
| 79 | private DialingFragment mDialingFragment = null; |
| 80 | private CallElementListFragment mCallElementList = null; |
| 81 | private HistoryFragment mHistorySectionFragment = null; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 82 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 83 | Fragment fMenu; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 84 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 85 | private boolean mBound = false; |
| 86 | private ISipService service; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 87 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 88 | private CharSequence mDrawerTitle; |
| 89 | private CharSequence mTitle; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 90 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 91 | private static final int REQUEST_CODE_PREFERENCES = 1; |
| 92 | private static final int REQUEST_CODE_CALL = 2; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 93 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 94 | private static final int ACTION_BAR_TAB_DIALING = 0; |
| 95 | private static final int ACTION_BAR_TAB_CALL = 1; |
| 96 | private static final int ACTION_BAR_TAB_HISTORY = 2; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 97 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 98 | RelativeLayout mSliderButton; |
| 99 | CustomSlidingDrawer mDrawer; |
| 100 | private DrawerLayout mDrawerLayout; |
| 101 | private ActionBarDrawerToggle mDrawerToggle; |
| 102 | /** |
| 103 | * The {@link ViewPager} that will host the section contents. |
| 104 | */ |
| 105 | ViewPager mViewPager; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 106 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 107 | CallReceiver receiver; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 108 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 109 | final private int[] icon_res_id = { R.drawable.ic_tab_call, R.drawable.ic_tab_call, R.drawable.ic_tab_history }; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 110 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 111 | // public SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 112 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 113 | /* called before activity is killed, e.g. rotation */ |
| 114 | @Override |
| 115 | protected void onSaveInstanceState(Bundle bundle) { |
| 116 | super.onSaveInstanceState(bundle); |
| 117 | for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { |
| 118 | try { |
| 119 | getFragmentManager().putFragment(bundle, mSectionsPagerAdapter.getClassName(i), mSectionsPagerAdapter.getItem(i)); |
| 120 | } catch (IllegalStateException e) { |
| 121 | Log.e(TAG, "fragment=" + mSectionsPagerAdapter.getItem(i)); |
| 122 | } |
| 123 | } |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 124 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 125 | getFragmentManager().putFragment(bundle, "ContactsListFragment", mContactsFragment); |
| 126 | Log.w(TAG, "onSaveInstanceState()"); |
| 127 | } |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 128 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 129 | @Override |
| 130 | public void onCreate(Bundle savedInstanceState) { |
| 131 | super.onCreate(savedInstanceState); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 132 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 133 | receiver = new CallReceiver(this); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 134 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 135 | String libraryPath = getApplicationInfo().dataDir + "/lib"; |
| 136 | Log.i(TAG, libraryPath); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 137 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 138 | // Bind to LocalService |
| 139 | if (!mBound) { |
| 140 | Log.i(TAG, "onStart: Binding service..."); |
| 141 | Intent intent = new Intent(this, SipService.class); |
| 142 | bindService(intent, mConnection, Context.BIND_AUTO_CREATE); |
| 143 | } |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 144 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 145 | setContentView(R.layout.activity_sflphone_home); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 146 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 147 | if (mSectionsPagerAdapter == null) { |
| 148 | mSectionsPagerAdapter = new SectionsPagerAdapter(this, getFragmentManager()); |
| 149 | } |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 150 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 151 | /* getFragment(Bundle, String) */ |
| 152 | if (savedInstanceState != null) { |
| 153 | Log.w(TAG, "Activity restarted, recreating PagerAdapter..."); |
| 154 | /* getFragment (Bundle bundle, String key) */ |
| 155 | mDialingFragment = (DialingFragment) getFragmentManager().getFragment(savedInstanceState, |
| 156 | mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_DIALING)); |
| 157 | mCallElementList = (CallElementListFragment) getFragmentManager().getFragment(savedInstanceState, |
| 158 | mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_CALL)); |
| 159 | mHistorySectionFragment = (HistoryFragment) getFragmentManager().getFragment(savedInstanceState, |
| 160 | mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_HISTORY)); |
| 161 | } |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 162 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 163 | if (mDialingFragment == null) { |
| 164 | mDialingFragment = new DialingFragment(); |
| 165 | Log.w(TAG, "Recreated mDialingFragment=" + mDialingFragment); |
| 166 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 167 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 168 | if (mContactsFragment == null) { |
| 169 | mContactsFragment = new ContactListFragment(); |
| 170 | Log.w(TAG, "Recreated mContactListFragment=" + mContactsFragment); |
| 171 | getFragmentManager().beginTransaction().replace(R.id.contacts_frame, mContactsFragment).commit(); |
| 172 | } |
| 173 | if (mCallElementList == null) { |
| 174 | mCallElementList = new CallElementListFragment(); |
| 175 | Log.w(TAG, "Recreated mCallElementList=" + mCallElementList); |
| 176 | } |
| 177 | if (mHistorySectionFragment == null) { |
| 178 | mHistorySectionFragment = new HistoryFragment(); |
| 179 | Log.w(TAG, "Recreated mHistorySectionFragment=" + mHistorySectionFragment); |
| 180 | } |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 181 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 182 | mDrawer = (CustomSlidingDrawer) findViewById(R.id.custom_sliding_drawer); |
alision | 7297bdb | 2013-05-21 11:56:55 -0400 | [diff] [blame] | 183 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 184 | mContactsFragment.setHandleView((RelativeLayout) findViewById(R.id.slider_button)); |
alision | 7297bdb | 2013-05-21 11:56:55 -0400 | [diff] [blame] | 185 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 186 | mDrawer.setmTrackHandle(findViewById(R.id.handle_title)); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 187 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 188 | final ActionBar actionBar = getActionBar(); |
| 189 | actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 190 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 191 | // Set up the ViewPager with the sections adapter. |
| 192 | mViewPager = (ViewPager) findViewById(R.id.pager); |
| 193 | mViewPager.setAdapter(mSectionsPagerAdapter); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 194 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 195 | mTitle = mDrawerTitle = getTitle(); |
| 196 | mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); |
| 197 | // mDrawerList = (ListView) findViewById(R.id.left_drawer); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 198 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 199 | // set a custom shadow that overlays the main content when the drawer opens |
| 200 | mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); |
| 201 | // set up the drawer's list view with items and click listener |
| 202 | // mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mPlanetTitles)); |
| 203 | // mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 204 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 205 | getActionBar().setDisplayHomeAsUpEnabled(true); |
| 206 | getActionBar().setHomeButtonEnabled(true); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 207 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 208 | mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ |
| 209 | mDrawerLayout, /* DrawerLayout object */ |
| 210 | R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ |
| 211 | R.string.drawer_open, /* "open drawer" description for accessibility */ |
| 212 | R.string.drawer_close /* "close drawer" description for accessibility */ |
| 213 | ) { |
| 214 | @Override |
| 215 | public void onDrawerClosed(View view) { |
| 216 | getActionBar().setTitle(mTitle); |
| 217 | invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() |
| 218 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 219 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 220 | @Override |
| 221 | public void onDrawerOpened(View drawerView) { |
| 222 | getActionBar().setTitle(mDrawerTitle); |
| 223 | invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() |
| 224 | } |
| 225 | }; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 226 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 227 | mDrawerLayout.setDrawerListener(mDrawerToggle); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 228 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 229 | mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { |
| 230 | @Override |
| 231 | public void onPageSelected(int position) { |
| 232 | actionBar.setSelectedNavigationItem(position); |
| 233 | } |
| 234 | }); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 235 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 236 | // For each of the sections in the app, add a tab to the action bar. |
| 237 | for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 238 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 239 | actionBar.addTab(actionBar.newTab().setIcon(icon_res_id[i]).setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); |
| 240 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 241 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 242 | actionBar.setSelectedNavigationItem(ACTION_BAR_TAB_CALL); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 243 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 244 | fMenu = new MenuFragment(); |
| 245 | getFragmentManager().beginTransaction().replace(R.id.left_drawer, fMenu).commit(); |
| 246 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 247 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 248 | @Override |
| 249 | protected void onStart() { |
| 250 | Log.i(TAG, "onStart"); |
| 251 | super.onStart(); |
| 252 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 253 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 254 | /* user gets back to the activity, e.g. through task manager */ |
| 255 | @Override |
| 256 | protected void onRestart() { |
| 257 | super.onRestart(); |
| 258 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 259 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 260 | /* activity gets back to the foreground and user input */ |
| 261 | @Override |
| 262 | protected void onResume() { |
| 263 | Log.i(TAG, "onResume"); |
| 264 | IntentFilter intentFilter = new IntentFilter(); |
| 265 | intentFilter.addAction(CallManagerCallBack.INCOMING_CALL); |
| 266 | intentFilter.addAction(CallManagerCallBack.INCOMING_TEXT); |
| 267 | intentFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED); |
| 268 | registerReceiver(receiver, intentFilter); |
| 269 | super.onResume(); |
| 270 | } |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 271 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 272 | /* activity no more in foreground */ |
| 273 | @Override |
| 274 | protected void onPause() { |
| 275 | super.onPause(); |
| 276 | unregisterReceiver(receiver); |
| 277 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 278 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 279 | /* activity is no longer visible */ |
| 280 | @Override |
| 281 | protected void onStop() { |
| 282 | super.onStop(); |
| 283 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 284 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 285 | /* activity finishes itself or is being killed by the system */ |
| 286 | @Override |
| 287 | protected void onDestroy() { |
| 288 | /* stop the service, if no other bound user, no need to check if it is running */ |
| 289 | if (mBound) { |
| 290 | Log.i(TAG, "onDestroy: Unbinding service..."); |
| 291 | unbindService(mConnection); |
| 292 | mBound = false; |
| 293 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 294 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 295 | super.onDestroy(); |
| 296 | } |
alision | 73424b6 | 2013-04-26 11:49:18 -0400 | [diff] [blame] | 297 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 298 | public void launchCallActivity(SipCall infos, String action) { |
| 299 | Log.i(TAG, "Launch Call Activity"); |
| 300 | Bundle bundle = new Bundle(); |
| 301 | bundle.putString("action", action); |
| 302 | bundle.putParcelable("CallInfo", infos); |
| 303 | Intent intent = new Intent().setClass(this, CallActivity.class); |
| 304 | intent.putExtras(bundle); |
| 305 | startActivityForResult(intent, REQUEST_CODE_CALL); |
| 306 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 307 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 308 | /** Defines callbacks for service binding, passed to bindService() */ |
| 309 | private ServiceConnection mConnection = new ServiceConnection() { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 310 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 311 | @Override |
| 312 | public void onServiceConnected(ComponentName className, IBinder binder) { |
| 313 | service = ISipService.Stub.asInterface(binder); |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 314 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 315 | mBound = true; |
| 316 | mCallElementList.onServiceSipBinded(service); |
| 317 | mHistorySectionFragment.onServiceSipBinded(service); |
| 318 | mDialingFragment.onServiceSipBinded(service); |
| 319 | Log.d(TAG, "Service connected service=" + service); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 320 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 321 | } |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 322 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 323 | @Override |
| 324 | public void onServiceDisconnected(ComponentName arg0) { |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 325 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 326 | mBound = false; |
| 327 | Log.d(TAG, "Service disconnected service=" + service); |
| 328 | } |
| 329 | }; |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 330 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 331 | @Override |
| 332 | public boolean onOptionsItemSelected(MenuItem item) { |
| 333 | Log.i(TAG, "onOptionsItemSelected " + item.getItemId()); |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 334 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 335 | if (mDrawerToggle.onOptionsItemSelected(item)) { |
| 336 | return true; |
| 337 | } |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 338 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 339 | return super.onOptionsItemSelected(item); |
| 340 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 341 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 342 | @Override |
| 343 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 344 | super.onActivityResult(requestCode, resultCode, data); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 345 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 346 | switch (requestCode) { |
| 347 | case REQUEST_CODE_PREFERENCES: |
| 348 | mCallElementList.onServiceSipBinded(service); |
| 349 | break; |
| 350 | case REQUEST_CODE_CALL: |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 351 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 352 | break; |
| 353 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 354 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 355 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 356 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 357 | // @Override |
| 358 | // public boolean onCreateOptionsMenu(Menu menu) { |
| 359 | // getMenuInflater().inflate(R.menu.activity_sflphone_home, menu); |
| 360 | // return true; |
| 361 | // } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 362 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 363 | @Override |
| 364 | public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { |
| 365 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 366 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 367 | @Override |
| 368 | public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { |
| 369 | // When the given tab is selected, switch to the corresponding page in the ViewPager. |
| 370 | mViewPager.setCurrentItem(tab.getPosition()); |
| 371 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 372 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 373 | @Override |
| 374 | public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { |
| 375 | // Log.d(TAG, "onTabReselected"); |
| 376 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 377 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 378 | @Override |
| 379 | public void onCallSelected(SipCall c) { |
| 380 | // launchCallActivity(c.mCallInfo); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 381 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 382 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 383 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 384 | @Override |
| 385 | public ISipService getService() { |
| 386 | return service; |
| 387 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 388 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 389 | /** |
| 390 | * Interface implemented to handle incoming events |
| 391 | */ |
| 392 | @Override |
| 393 | public void incomingCall(Intent call) { |
| 394 | Toast.makeText(this, "New Call incoming", Toast.LENGTH_LONG).show(); |
| 395 | SipCall infos = call.getParcelableExtra("newcall"); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 396 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 397 | mCallElementList.addCall(infos); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 398 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 399 | launchCallActivity(infos, CallManagerCallBack.INCOMING_CALL); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 400 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 401 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 402 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 403 | @Override |
| 404 | public void callStateChanged(Intent callState) { |
| 405 | Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate"); |
| 406 | String cID = b.getString("CallID"); |
| 407 | String state = b.getString("State"); |
| 408 | Log.i(TAG, "callStateChanged" + cID + " " + state); |
| 409 | mCallElementList.updateCall(cID, state); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 410 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 411 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 412 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 413 | @Override |
| 414 | public void incomingText(Intent msg) { |
| 415 | Bundle b = msg.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext"); |
| 416 | b.getString("CallID"); |
| 417 | String from = b.getString("From"); |
| 418 | String mess = b.getString("Msg"); |
| 419 | Toast.makeText(getApplicationContext(), "text from " + from + " : " + mess, Toast.LENGTH_LONG).show(); |
| 420 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 421 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 422 | @Override |
| 423 | public void onContactSelected(CallContact c) { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 424 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 425 | SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance(); |
| 426 | try { |
| 427 | callBuilder.startCallCreation().setAccountID(service.getAccountList().get(0).toString()).setCallType(SipCall.state.CALL_TYPE_OUTGOING); |
| 428 | } catch (RemoteException e1) { |
| 429 | Log.e(TAG,e1.toString()); |
| 430 | } |
| 431 | callBuilder.addContact(c); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 432 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 433 | try { |
| 434 | launchCallActivity(callBuilder.build(), "call"); |
| 435 | } catch (Exception e) { |
| 436 | Log.e(TAG, e.toString()); |
| 437 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 438 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 439 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 440 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 441 | @Override |
| 442 | public void onCallDialed(String accountID, String to) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 443 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 444 | SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance(); |
| 445 | callBuilder.startCallCreation().setAccountID(accountID).setCallType(SipCall.state.CALL_TYPE_OUTGOING); |
| 446 | callBuilder.addContact(CallContact.ContactBuilder.buildUnknownContact(to)); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 447 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 448 | try { |
| 449 | launchCallActivity(callBuilder.build(), "call"); |
| 450 | } catch (Exception e) { |
| 451 | Log.e(TAG, e.toString()); |
| 452 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 453 | |
Adrien Béraud | 0c9bd8f | 2013-05-30 16:16:57 +1000 | [diff] [blame] | 454 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 455 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 456 | } |