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 | d45da71 | 2013-05-30 09:18:49 -0400 | [diff] [blame] | 34 | import java.util.HashMap; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 35 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 36 | import android.app.ActionBar; |
| 37 | import android.app.Activity; |
| 38 | import android.app.Fragment; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 39 | import android.app.FragmentTransaction; |
| 40 | import android.content.ComponentName; |
| 41 | import android.content.Context; |
| 42 | import android.content.Intent; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 43 | import android.content.IntentFilter; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 44 | import android.content.ServiceConnection; |
| 45 | import android.os.Bundle; |
| 46 | import android.os.IBinder; |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 47 | import android.os.RemoteException; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 48 | import android.support.v4.app.ActionBarDrawerToggle; |
| 49 | import android.support.v4.view.GravityCompat; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 50 | import android.support.v4.view.ViewPager; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 51 | import android.support.v4.widget.DrawerLayout; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 52 | import android.util.Log; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 53 | import android.view.MenuItem; |
| 54 | import android.view.View; |
alision | 7297bdb | 2013-05-21 11:56:55 -0400 | [diff] [blame] | 55 | import android.widget.RelativeLayout; |
alision | d45da71 | 2013-05-30 09:18:49 -0400 | [diff] [blame] | 56 | import android.widget.TabHost; |
alision | 3c5c2a9 | 2013-05-30 09:50:47 -0400 | [diff] [blame^] | 57 | import android.widget.TabHost.OnTabChangeListener; |
alision | d45da71 | 2013-05-30 09:18:49 -0400 | [diff] [blame] | 58 | import android.widget.TabHost.TabContentFactory; |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 59 | import android.widget.Toast; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 60 | |
| 61 | import com.savoirfairelinux.sflphone.R; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 62 | import com.savoirfairelinux.sflphone.adapters.SectionsPagerAdapter; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 63 | import com.savoirfairelinux.sflphone.client.receiver.CallReceiver; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 64 | import com.savoirfairelinux.sflphone.fragments.CallElementListFragment; |
| 65 | import com.savoirfairelinux.sflphone.fragments.ContactListFragment; |
alision | 7297bdb | 2013-05-21 11:56:55 -0400 | [diff] [blame] | 66 | import com.savoirfairelinux.sflphone.fragments.DialingFragment; |
alision | d9e2944 | 2013-04-17 16:10:18 -0400 | [diff] [blame] | 67 | import com.savoirfairelinux.sflphone.fragments.HistoryFragment; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 68 | import com.savoirfairelinux.sflphone.fragments.MenuFragment; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 69 | import com.savoirfairelinux.sflphone.interfaces.CallInterface; |
| 70 | import com.savoirfairelinux.sflphone.model.CallContact; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 71 | import com.savoirfairelinux.sflphone.model.SipCall; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 72 | import com.savoirfairelinux.sflphone.service.CallManagerCallBack; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 73 | import com.savoirfairelinux.sflphone.service.ISipService; |
| 74 | import com.savoirfairelinux.sflphone.service.SipService; |
alision | 7297bdb | 2013-05-21 11:56:55 -0400 | [diff] [blame] | 75 | import com.savoirfairelinux.sflphone.views.CustomSlidingDrawer; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 76 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 77 | public class SFLPhoneHomeActivity extends Activity implements ActionBar.TabListener, DialingFragment.Callbacks, ContactListFragment.Callbacks, |
| 78 | CallElementListFragment.Callbacks, HistoryFragment.Callbacks, CallInterface { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 79 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 80 | SectionsPagerAdapter mSectionsPagerAdapter = null; |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 81 | static final String TAG = "SFLPhoneHomeActivity"; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 82 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 83 | private ContactListFragment mContactsFragment = null; |
| 84 | private DialingFragment mDialingFragment = null; |
| 85 | private CallElementListFragment mCallElementList = null; |
| 86 | private HistoryFragment mHistorySectionFragment = null; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 87 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 88 | Fragment fMenu; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 89 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 90 | private boolean mBound = false; |
| 91 | private ISipService service; |
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 CharSequence mDrawerTitle; |
| 94 | private CharSequence mTitle; |
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 static final int REQUEST_CODE_PREFERENCES = 1; |
| 97 | private static final int REQUEST_CODE_CALL = 2; |
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 static final int ACTION_BAR_TAB_DIALING = 0; |
| 100 | private static final int ACTION_BAR_TAB_CALL = 1; |
| 101 | private static final int ACTION_BAR_TAB_HISTORY = 2; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 102 | |
alision | 0b55383 | 2013-05-30 09:31:06 -0400 | [diff] [blame] | 103 | RelativeLayout mSliderButton; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 104 | CustomSlidingDrawer mDrawer; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 105 | private DrawerLayout mDrawerLayout; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 106 | private ActionBarDrawerToggle mDrawerToggle; |
| 107 | /** |
| 108 | * The {@link ViewPager} that will host the section contents. |
| 109 | */ |
| 110 | ViewPager mViewPager; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 111 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 112 | CallReceiver receiver; |
| 113 | |
alision | 3c5c2a9 | 2013-05-30 09:50:47 -0400 | [diff] [blame^] | 114 | |
| 115 | private TabHost mTabHost; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 116 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 117 | // public SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener |
| 118 | |
| 119 | /* called before activity is killed, e.g. rotation */ |
| 120 | @Override |
| 121 | protected void onSaveInstanceState(Bundle bundle) { |
| 122 | super.onSaveInstanceState(bundle); |
| 123 | for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { |
| 124 | try { |
| 125 | getFragmentManager().putFragment(bundle, mSectionsPagerAdapter.getClassName(i), mSectionsPagerAdapter.getItem(i)); |
| 126 | } catch (IllegalStateException e) { |
| 127 | Log.e(TAG, "fragment=" + mSectionsPagerAdapter.getItem(i)); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | getFragmentManager().putFragment(bundle, "ContactsListFragment", mContactsFragment); |
| 132 | Log.w(TAG, "onSaveInstanceState()"); |
| 133 | } |
| 134 | |
| 135 | @Override |
| 136 | public void onCreate(Bundle savedInstanceState) { |
| 137 | super.onCreate(savedInstanceState); |
| 138 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 139 | receiver = new CallReceiver(this); |
| 140 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 141 | String libraryPath = getApplicationInfo().dataDir + "/lib"; |
| 142 | Log.i(TAG, libraryPath); |
| 143 | |
| 144 | // Bind to LocalService |
| 145 | if (!mBound) { |
| 146 | Log.i(TAG, "onStart: Binding service..."); |
| 147 | Intent intent = new Intent(this, SipService.class); |
| 148 | bindService(intent, mConnection, Context.BIND_AUTO_CREATE); |
| 149 | } |
| 150 | |
| 151 | setContentView(R.layout.activity_sflphone_home); |
| 152 | |
| 153 | if (mSectionsPagerAdapter == null) { |
| 154 | mSectionsPagerAdapter = new SectionsPagerAdapter(this, getFragmentManager()); |
| 155 | } |
| 156 | |
| 157 | /* getFragment(Bundle, String) */ |
| 158 | if (savedInstanceState != null) { |
| 159 | Log.w(TAG, "Activity restarted, recreating PagerAdapter..."); |
| 160 | /* getFragment (Bundle bundle, String key) */ |
| 161 | mDialingFragment = (DialingFragment) getFragmentManager().getFragment(savedInstanceState, |
| 162 | mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_DIALING)); |
| 163 | mCallElementList = (CallElementListFragment) getFragmentManager().getFragment(savedInstanceState, |
| 164 | mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_CALL)); |
| 165 | mHistorySectionFragment = (HistoryFragment) getFragmentManager().getFragment(savedInstanceState, |
| 166 | mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_HISTORY)); |
| 167 | } |
| 168 | |
| 169 | if (mDialingFragment == null) { |
| 170 | mDialingFragment = new DialingFragment(); |
alision | 7297bdb | 2013-05-21 11:56:55 -0400 | [diff] [blame] | 171 | Log.w(TAG, "Recreated mDialingFragment=" + mDialingFragment); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 172 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 173 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 174 | if (mContactsFragment == null) { |
| 175 | mContactsFragment = new ContactListFragment(); |
| 176 | Log.w(TAG, "Recreated mContactListFragment=" + mContactsFragment); |
| 177 | getFragmentManager().beginTransaction().replace(R.id.contacts_frame, mContactsFragment).commit(); |
| 178 | } |
| 179 | if (mCallElementList == null) { |
| 180 | mCallElementList = new CallElementListFragment(); |
| 181 | Log.w(TAG, "Recreated mCallElementList=" + mCallElementList); |
| 182 | } |
| 183 | if (mHistorySectionFragment == null) { |
| 184 | mHistorySectionFragment = new HistoryFragment(); |
| 185 | Log.w(TAG, "Recreated mHistorySectionFragment=" + mHistorySectionFragment); |
| 186 | } |
| 187 | |
| 188 | mDrawer = (CustomSlidingDrawer) findViewById(R.id.custom_sliding_drawer); |
alision | 7297bdb | 2013-05-21 11:56:55 -0400 | [diff] [blame] | 189 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 190 | mContactsFragment.setHandleView((RelativeLayout) findViewById(R.id.slider_button)); |
alision | 7297bdb | 2013-05-21 11:56:55 -0400 | [diff] [blame] | 191 | |
| 192 | mDrawer.setmTrackHandle(findViewById(R.id.handle_title)); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 193 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 194 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 195 | // Set up the ViewPager with the sections adapter. |
| 196 | mViewPager = (ViewPager) findViewById(R.id.pager); |
| 197 | mViewPager.setAdapter(mSectionsPagerAdapter); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 198 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 199 | mTitle = mDrawerTitle = getTitle(); |
| 200 | mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 201 | |
alision | 0b55383 | 2013-05-30 09:31:06 -0400 | [diff] [blame] | 202 | // set a custom shadow that overlays the main content when the drawer opens |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 203 | mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 204 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 205 | getActionBar().setDisplayHomeAsUpEnabled(true); |
| 206 | getActionBar().setHomeButtonEnabled(true); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 207 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [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 | ) { |
alision | 0b55383 | 2013-05-30 09:31:06 -0400 | [diff] [blame] | 214 | @Override |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 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 | |
alision | 0b55383 | 2013-05-30 09:31:06 -0400 | [diff] [blame] | 220 | @Override |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 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 | |
alision | 3c5c2a9 | 2013-05-30 09:50:47 -0400 | [diff] [blame^] | 227 | mTabHost = (TabHost) findViewById(android.R.id.tabhost); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 228 | mDrawerLayout.setDrawerListener(mDrawerToggle); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 229 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 230 | mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { |
| 231 | @Override |
| 232 | public void onPageSelected(int position) { |
alision | 3c5c2a9 | 2013-05-30 09:50:47 -0400 | [diff] [blame^] | 233 | mTabHost.setCurrentTab(position); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 234 | } |
| 235 | }); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 236 | |
alision | 3c5c2a9 | 2013-05-30 09:50:47 -0400 | [diff] [blame^] | 237 | initialiseTabHost(savedInstanceState); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 238 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 239 | fMenu = new MenuFragment(); |
| 240 | getFragmentManager().beginTransaction().replace(R.id.left_drawer, fMenu).commit(); |
| 241 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 242 | |
alision | 3c5c2a9 | 2013-05-30 09:50:47 -0400 | [diff] [blame^] | 243 | private void initialiseTabHost(Bundle args) { |
| 244 | |
| 245 | |
| 246 | mTabHost.setup(); |
| 247 | TabInfo tabInfo = null; |
| 248 | SFLPhoneHomeActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab1").setIndicator(mSectionsPagerAdapter.getPageTitle(0),getResources().getDrawable(mSectionsPagerAdapter.getIconOf(0))), (tabInfo = new TabInfo("Tab1", |
| 249 | DialingFragment.class, args))); |
| 250 | this.mapTabInfo.put(tabInfo.tag, tabInfo); |
| 251 | SFLPhoneHomeActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab2").setIndicator(mSectionsPagerAdapter.getPageTitle(1),getResources().getDrawable(mSectionsPagerAdapter.getIconOf(1))), (tabInfo = new TabInfo("Tab2", |
| 252 | CallElementListFragment.class, args))); |
| 253 | this.mapTabInfo.put(tabInfo.tag, tabInfo); |
| 254 | SFLPhoneHomeActivity.AddTab(this, this.mTabHost, this.mTabHost.newTabSpec("Tab3").setIndicator(mSectionsPagerAdapter.getPageTitle(2),getResources().getDrawable(mSectionsPagerAdapter.getIconOf(2))), (tabInfo = new TabInfo("Tab3", |
| 255 | HistoryFragment.class, args))); |
| 256 | this.mapTabInfo.put(tabInfo.tag, tabInfo); |
| 257 | |
| 258 | mTabHost.setOnTabChangedListener(new OnTabChangeListener() { |
| 259 | |
| 260 | @Override |
| 261 | public void onTabChanged(String tabId) { |
| 262 | int pos = mTabHost.getCurrentTab(); |
| 263 | mViewPager.setCurrentItem(pos); |
| 264 | |
| 265 | } |
| 266 | }); |
| 267 | } |
| 268 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 269 | @Override |
| 270 | protected void onStart() { |
| 271 | Log.i(TAG, "onStart"); |
| 272 | super.onStart(); |
| 273 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 274 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 275 | /* user gets back to the activity, e.g. through task manager */ |
| 276 | @Override |
| 277 | protected void onRestart() { |
| 278 | super.onRestart(); |
| 279 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 280 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 281 | /* activity gets back to the foreground and user input */ |
| 282 | @Override |
| 283 | protected void onResume() { |
| 284 | Log.i(TAG, "onResume"); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 285 | IntentFilter intentFilter = new IntentFilter(); |
| 286 | intentFilter.addAction(CallManagerCallBack.INCOMING_CALL); |
| 287 | intentFilter.addAction(CallManagerCallBack.INCOMING_TEXT); |
| 288 | intentFilter.addAction(CallManagerCallBack.CALL_STATE_CHANGED); |
| 289 | registerReceiver(receiver, intentFilter); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 290 | super.onResume(); |
| 291 | } |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 292 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 293 | /* activity no more in foreground */ |
| 294 | @Override |
| 295 | protected void onPause() { |
| 296 | super.onPause(); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 297 | unregisterReceiver(receiver); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 298 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 299 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 300 | /* activity is no longer visible */ |
| 301 | @Override |
| 302 | protected void onStop() { |
| 303 | super.onStop(); |
| 304 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 305 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 306 | /* activity finishes itself or is being killed by the system */ |
| 307 | @Override |
| 308 | protected void onDestroy() { |
| 309 | /* stop the service, if no other bound user, no need to check if it is running */ |
| 310 | if (mBound) { |
| 311 | Log.i(TAG, "onDestroy: Unbinding service..."); |
| 312 | unbindService(mConnection); |
| 313 | mBound = false; |
| 314 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 315 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 316 | super.onDestroy(); |
| 317 | } |
alision | 73424b6 | 2013-04-26 11:49:18 -0400 | [diff] [blame] | 318 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 319 | public void launchCallActivity(SipCall infos, String action) { |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 320 | Log.i(TAG, "Launch Call Activity"); |
| 321 | Bundle bundle = new Bundle(); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 322 | bundle.putString("action", action); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 323 | bundle.putParcelable("CallInfo", infos); |
| 324 | Intent intent = new Intent().setClass(this, CallActivity.class); |
| 325 | intent.putExtras(bundle); |
| 326 | startActivityForResult(intent, REQUEST_CODE_CALL); |
| 327 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 328 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 329 | /** Defines callbacks for service binding, passed to bindService() */ |
| 330 | private ServiceConnection mConnection = new ServiceConnection() { |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 331 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 332 | @Override |
| 333 | public void onServiceConnected(ComponentName className, IBinder binder) { |
| 334 | service = ISipService.Stub.asInterface(binder); |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 335 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 336 | mBound = true; |
| 337 | mCallElementList.onServiceSipBinded(service); |
| 338 | mHistorySectionFragment.onServiceSipBinded(service); |
| 339 | mDialingFragment.onServiceSipBinded(service); |
| 340 | Log.d(TAG, "Service connected service=" + service); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 341 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 342 | } |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 343 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 344 | @Override |
| 345 | public void onServiceDisconnected(ComponentName arg0) { |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 346 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 347 | mBound = false; |
| 348 | Log.d(TAG, "Service disconnected service=" + service); |
| 349 | } |
| 350 | }; |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 351 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 352 | @Override |
| 353 | public boolean onOptionsItemSelected(MenuItem item) { |
| 354 | Log.i(TAG, "onOptionsItemSelected " + item.getItemId()); |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 355 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 356 | if (mDrawerToggle.onOptionsItemSelected(item)) { |
| 357 | return true; |
| 358 | } |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 359 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 360 | return super.onOptionsItemSelected(item); |
| 361 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 362 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 363 | @Override |
| 364 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 365 | super.onActivityResult(requestCode, resultCode, data); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 366 | |
| 367 | switch (requestCode) { |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 368 | case REQUEST_CODE_PREFERENCES: |
| 369 | mCallElementList.onServiceSipBinded(service); |
| 370 | break; |
| 371 | case REQUEST_CODE_CALL: |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 372 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 373 | break; |
| 374 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 375 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 376 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 377 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 378 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 379 | @Override |
| 380 | public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { |
| 381 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 382 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 383 | @Override |
| 384 | public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { |
| 385 | // When the given tab is selected, switch to the corresponding page in the ViewPager. |
alision | 0b55383 | 2013-05-30 09:31:06 -0400 | [diff] [blame] | 386 | mViewPager.setCurrentItem(tab.getPosition()); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 387 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 388 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 389 | @Override |
| 390 | public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { |
| 391 | // Log.d(TAG, "onTabReselected"); |
| 392 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 393 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 394 | @Override |
| 395 | public void onCallSelected(SipCall c) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 396 | // launchCallActivity(c.mCallInfo); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 397 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 398 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 399 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 400 | @Override |
| 401 | public ISipService getService() { |
| 402 | return service; |
| 403 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 404 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 405 | /** |
| 406 | * Interface implemented to handle incoming events |
| 407 | */ |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 408 | @Override |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 409 | public void incomingCall(Intent call) { |
| 410 | Toast.makeText(this, "New Call incoming", Toast.LENGTH_LONG).show(); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 411 | SipCall infos = call.getParcelableExtra("newcall"); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 412 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 413 | mCallElementList.addCall(infos); |
| 414 | |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 415 | launchCallActivity(infos, CallManagerCallBack.INCOMING_CALL); |
| 416 | |
| 417 | } |
| 418 | |
| 419 | @Override |
| 420 | public void callStateChanged(Intent callState) { |
| 421 | Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate"); |
| 422 | String cID = b.getString("CallID"); |
| 423 | String state = b.getString("State"); |
| 424 | Log.i(TAG, "callStateChanged" + cID + " " + state); |
| 425 | mCallElementList.updateCall(cID, state); |
| 426 | |
| 427 | } |
| 428 | |
| 429 | @Override |
| 430 | public void incomingText(Intent msg) { |
| 431 | Bundle b = msg.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext"); |
| 432 | b.getString("CallID"); |
| 433 | String from = b.getString("From"); |
| 434 | String mess = b.getString("Msg"); |
| 435 | Toast.makeText(getApplicationContext(), "text from " + from + " : " + mess, Toast.LENGTH_LONG).show(); |
| 436 | } |
| 437 | |
| 438 | @Override |
| 439 | public void onContactSelected(CallContact c) { |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 440 | |
| 441 | SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance(); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 442 | try { |
alision | 0b55383 | 2013-05-30 09:31:06 -0400 | [diff] [blame] | 443 | callBuilder.startCallCreation().setAccountID(service.getAccountList().get(0).toString()).setCallType(SipCall.state.CALL_TYPE_OUTGOING); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 444 | } catch (RemoteException e1) { |
alision | d45da71 | 2013-05-30 09:18:49 -0400 | [diff] [blame] | 445 | Log.e(TAG, e1.toString()); |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 446 | } |
| 447 | callBuilder.addContact(c); |
| 448 | |
| 449 | try { |
| 450 | launchCallActivity(callBuilder.build(), "call"); |
| 451 | } catch (Exception e) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 452 | Log.e(TAG, e.toString()); |
| 453 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 454 | |
| 455 | } |
| 456 | |
| 457 | @Override |
| 458 | public void onCallDialed(String accountID, String to) { |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 459 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 460 | SipCall.SipCallBuilder callBuilder = SipCall.SipCallBuilder.getInstance(); |
| 461 | callBuilder.startCallCreation().setAccountID(accountID).setCallType(SipCall.state.CALL_TYPE_OUTGOING); |
| 462 | callBuilder.addContact(CallContact.ContactBuilder.buildUnknownContact(to)); |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 463 | |
alision | fde875f | 2013-05-28 17:01:54 -0400 | [diff] [blame] | 464 | try { |
| 465 | launchCallActivity(callBuilder.build(), "call"); |
| 466 | } catch (Exception e) { |
| 467 | Log.e(TAG, e.toString()); |
| 468 | } |
alision | 84813a1 | 2013-05-27 17:40:39 -0400 | [diff] [blame] | 469 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame] | 470 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 471 | |
alision | d45da71 | 2013-05-30 09:18:49 -0400 | [diff] [blame] | 472 | @Override |
| 473 | public void onContactDragged() { |
| 474 | |
| 475 | mDrawer.close(); |
| 476 | getActionBar().setSelectedNavigationItem(ACTION_BAR_TAB_CALL); |
| 477 | |
| 478 | } |
| 479 | |
| 480 | private HashMap<String, TabInfo> mapTabInfo = new HashMap<String, SFLPhoneHomeActivity.TabInfo>(); |
| 481 | |
| 482 | /** |
| 483 | * A simple factory that returns dummy views to the Tabhost |
| 484 | * |
| 485 | * @author mwho |
| 486 | */ |
| 487 | class TabFactory implements TabContentFactory { |
| 488 | |
| 489 | private final Context mContext; |
| 490 | |
| 491 | /** |
| 492 | * @param context |
| 493 | */ |
| 494 | public TabFactory(Context context) { |
| 495 | mContext = context; |
| 496 | } |
| 497 | |
| 498 | /** |
| 499 | * (non-Javadoc) |
| 500 | * |
| 501 | * @see android.widget.TabHost.TabContentFactory#createTabContent(java.lang.String) |
| 502 | */ |
| 503 | public View createTabContent(String tag) { |
| 504 | View v = new View(mContext); |
| 505 | v.setMinimumWidth(0); |
| 506 | v.setMinimumHeight(0); |
| 507 | return v; |
| 508 | } |
| 509 | |
| 510 | } |
| 511 | |
| 512 | /** |
| 513 | * |
| 514 | * @author mwho Maintains extrinsic info of a tab's construct |
| 515 | */ |
| 516 | private class TabInfo { |
| 517 | private String tag; |
| 518 | private Class<?> clss; |
| 519 | private Bundle args; |
| 520 | private Fragment fragment; |
| 521 | |
| 522 | TabInfo(String tag, Class<?> clazz, Bundle args) { |
| 523 | this.tag = tag; |
| 524 | this.clss = clazz; |
| 525 | this.args = args; |
| 526 | } |
| 527 | |
| 528 | } |
| 529 | |
| 530 | private static void AddTab(SFLPhoneHomeActivity activity, TabHost tabHost, TabHost.TabSpec tabSpec, TabInfo tabInfo) { |
| 531 | // Attach a Tab view factory to the spec |
| 532 | tabSpec.setContent(activity.new TabFactory(activity)); |
| 533 | tabHost.addTab(tabSpec); |
| 534 | } |
| 535 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 536 | } |