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> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 3 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | * |
| 20 | * Additional permission under GNU GPL version 3 section 7: |
| 21 | * |
| 22 | * If you modify this program, or any covered work, by linking or |
| 23 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 24 | * modified version of that library), containing parts covered by the |
| 25 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 26 | * grants you additional permission to convey the resulting work. |
| 27 | * Corresponding Source for a non-source form of such a combination |
| 28 | * shall include the source code for the parts of OpenSSL used as well |
| 29 | * as that of the covered work. |
| 30 | */ |
| 31 | package com.savoirfairelinux.sflphone.client; |
| 32 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 33 | import android.app.ActionBar; |
| 34 | import android.app.Activity; |
| 35 | import android.app.Fragment; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 36 | import android.app.FragmentTransaction; |
| 37 | import android.content.ComponentName; |
| 38 | import android.content.Context; |
| 39 | import android.content.Intent; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 40 | import android.content.ServiceConnection; |
| 41 | import android.os.Bundle; |
| 42 | import android.os.IBinder; |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 43 | import android.os.RemoteException; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 44 | import android.support.v4.app.ActionBarDrawerToggle; |
| 45 | import android.support.v4.view.GravityCompat; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 46 | import android.support.v4.view.ViewPager; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 47 | import android.support.v4.widget.DrawerLayout; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 48 | import android.util.Log; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 49 | import android.view.MenuItem; |
| 50 | import android.view.View; |
| 51 | import android.view.View.OnClickListener; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 52 | import android.widget.ImageButton; |
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 | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 58 | import com.savoirfairelinux.sflphone.fragments.CallElementListFragment; |
| 59 | import com.savoirfairelinux.sflphone.fragments.ContactListFragment; |
alision | 7297bdb | 2013-05-21 11:56:55 -0400 | [diff] [blame] | 60 | import com.savoirfairelinux.sflphone.fragments.DialingFragment; |
alision | d9e2944 | 2013-04-17 16:10:18 -0400 | [diff] [blame] | 61 | import com.savoirfairelinux.sflphone.fragments.HistoryFragment; |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 62 | import com.savoirfairelinux.sflphone.fragments.MenuFragment; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 63 | import com.savoirfairelinux.sflphone.model.SipCall; |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 64 | import com.savoirfairelinux.sflphone.service.ISipClient; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 65 | import com.savoirfairelinux.sflphone.service.ISipService; |
| 66 | import com.savoirfairelinux.sflphone.service.SipService; |
alision | 7297bdb | 2013-05-21 11:56:55 -0400 | [diff] [blame] | 67 | import com.savoirfairelinux.sflphone.views.CustomSlidingDrawer; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 68 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 69 | public class SFLPhoneHomeActivity extends Activity implements ActionBar.TabListener, DialingFragment.Callbacks, CallElementListFragment.Callbacks, |
| 70 | HistoryFragment.Callbacks { |
| 71 | SectionsPagerAdapter mSectionsPagerAdapter = null; |
| 72 | static final String TAG = "SFLPhoneHome"; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 73 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 74 | ImageButton buttonCall, buttonHangup; |
| 75 | private ContactListFragment mContactsFragment = null; |
| 76 | private DialingFragment mDialingFragment = null; |
| 77 | private CallElementListFragment mCallElementList = null; |
| 78 | private HistoryFragment mHistorySectionFragment = null; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 79 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 80 | Fragment fMenu; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 81 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 82 | private boolean mBound = false; |
| 83 | private ISipService service; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 84 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 85 | private CharSequence mDrawerTitle; |
| 86 | private CharSequence mTitle; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 87 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 88 | private static final int REQUEST_CODE_PREFERENCES = 1; |
| 89 | private static final int REQUEST_CODE_CALL = 2; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 90 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 91 | private static final int ACTION_BAR_TAB_DIALING = 0; |
| 92 | private static final int ACTION_BAR_TAB_CALL = 1; |
| 93 | private static final int ACTION_BAR_TAB_HISTORY = 2; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 94 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 95 | RelativeLayout mSliderButton; |
| 96 | CustomSlidingDrawer mDrawer; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 97 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 98 | private DrawerLayout mDrawerLayout; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 99 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 100 | private ActionBarDrawerToggle mDrawerToggle; |
| 101 | /** |
| 102 | * The {@link ViewPager} that will host the section contents. |
| 103 | */ |
| 104 | ViewPager mViewPager; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 105 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 106 | 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] | 107 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 108 | // public SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener |
| 109 | |
| 110 | /* called before activity is killed, e.g. rotation */ |
| 111 | @Override |
| 112 | protected void onSaveInstanceState(Bundle bundle) { |
| 113 | super.onSaveInstanceState(bundle); |
| 114 | for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { |
| 115 | try { |
| 116 | getFragmentManager().putFragment(bundle, mSectionsPagerAdapter.getClassName(i), mSectionsPagerAdapter.getItem(i)); |
| 117 | } catch (IllegalStateException e) { |
| 118 | Log.e(TAG, "fragment=" + mSectionsPagerAdapter.getItem(i)); |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | getFragmentManager().putFragment(bundle, "ContactsListFragment", mContactsFragment); |
| 123 | Log.w(TAG, "onSaveInstanceState()"); |
| 124 | } |
| 125 | |
| 126 | @Override |
| 127 | public void onCreate(Bundle savedInstanceState) { |
| 128 | super.onCreate(savedInstanceState); |
| 129 | |
| 130 | String libraryPath = getApplicationInfo().dataDir + "/lib"; |
| 131 | Log.i(TAG, libraryPath); |
| 132 | |
| 133 | // Bind to LocalService |
| 134 | if (!mBound) { |
| 135 | Log.i(TAG, "onStart: Binding service..."); |
| 136 | Intent intent = new Intent(this, SipService.class); |
| 137 | bindService(intent, mConnection, Context.BIND_AUTO_CREATE); |
| 138 | } |
| 139 | |
| 140 | setContentView(R.layout.activity_sflphone_home); |
| 141 | |
| 142 | if (mSectionsPagerAdapter == null) { |
| 143 | mSectionsPagerAdapter = new SectionsPagerAdapter(this, getFragmentManager()); |
| 144 | } |
| 145 | |
| 146 | /* getFragment(Bundle, String) */ |
| 147 | if (savedInstanceState != null) { |
| 148 | Log.w(TAG, "Activity restarted, recreating PagerAdapter..."); |
| 149 | /* getFragment (Bundle bundle, String key) */ |
| 150 | mDialingFragment = (DialingFragment) getFragmentManager().getFragment(savedInstanceState, |
| 151 | mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_DIALING)); |
| 152 | mCallElementList = (CallElementListFragment) getFragmentManager().getFragment(savedInstanceState, |
| 153 | mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_CALL)); |
| 154 | mHistorySectionFragment = (HistoryFragment) getFragmentManager().getFragment(savedInstanceState, |
| 155 | mSectionsPagerAdapter.getClassName(ACTION_BAR_TAB_HISTORY)); |
| 156 | } |
| 157 | |
| 158 | if (mDialingFragment == null) { |
| 159 | mDialingFragment = new DialingFragment(); |
alision | 7297bdb | 2013-05-21 11:56:55 -0400 | [diff] [blame] | 160 | Log.w(TAG, "Recreated mDialingFragment=" + mDialingFragment); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 161 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 162 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 163 | if (mContactsFragment == null) { |
| 164 | mContactsFragment = new ContactListFragment(); |
| 165 | Log.w(TAG, "Recreated mContactListFragment=" + mContactsFragment); |
| 166 | getFragmentManager().beginTransaction().replace(R.id.contacts_frame, mContactsFragment).commit(); |
| 167 | } |
| 168 | if (mCallElementList == null) { |
| 169 | mCallElementList = new CallElementListFragment(); |
| 170 | Log.w(TAG, "Recreated mCallElementList=" + mCallElementList); |
| 171 | } |
| 172 | if (mHistorySectionFragment == null) { |
| 173 | mHistorySectionFragment = new HistoryFragment(); |
| 174 | Log.w(TAG, "Recreated mHistorySectionFragment=" + mHistorySectionFragment); |
| 175 | } |
| 176 | |
| 177 | mDrawer = (CustomSlidingDrawer) findViewById(R.id.custom_sliding_drawer); |
alision | 7297bdb | 2013-05-21 11:56:55 -0400 | [diff] [blame] | 178 | mSliderButton = (RelativeLayout) findViewById(R.id.slider_button); |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 179 | ((ImageButton) mSliderButton.findViewById(R.id.contact_search)).setTag(R.id.contact_search, false); |
| 180 | ((ImageButton) mSliderButton.findViewById(R.id.contact_search)).setOnClickListener(new OnClickListener() { |
alision | 7297bdb | 2013-05-21 11:56:55 -0400 | [diff] [blame] | 181 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 182 | @Override |
| 183 | public void onClick(View v) { |
| 184 | Log.i(TAG, "Click on serach"); |
| 185 | mDrawer.toggle(); |
alision | 7297bdb | 2013-05-21 11:56:55 -0400 | [diff] [blame] | 186 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 187 | } |
| 188 | }); |
alision | 7297bdb | 2013-05-21 11:56:55 -0400 | [diff] [blame] | 189 | mDrawer.setmTrackHandle(findViewById(R.id.handle_title)); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 190 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 191 | final ActionBar actionBar = getActionBar(); |
| 192 | actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 193 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 194 | // Set up the ViewPager with the sections adapter. |
| 195 | mViewPager = (ViewPager) findViewById(R.id.pager); |
| 196 | mViewPager.setAdapter(mSectionsPagerAdapter); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 197 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 198 | mTitle = mDrawerTitle = getTitle(); |
| 199 | mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); |
| 200 | // mDrawerList = (ListView) findViewById(R.id.left_drawer); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 201 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 202 | // set a custom shadow that overlays the main content when the drawer opens |
| 203 | mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); |
| 204 | // set up the drawer's list view with items and click listener |
| 205 | // mDrawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, mPlanetTitles)); |
| 206 | // mDrawerList.setOnItemClickListener(new DrawerItemClickListener()); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 207 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 208 | getActionBar().setDisplayHomeAsUpEnabled(true); |
| 209 | getActionBar().setHomeButtonEnabled(true); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 210 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 211 | mDrawerToggle = new ActionBarDrawerToggle(this, /* host Activity */ |
| 212 | mDrawerLayout, /* DrawerLayout object */ |
| 213 | R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */ |
| 214 | R.string.drawer_open, /* "open drawer" description for accessibility */ |
| 215 | R.string.drawer_close /* "close drawer" description for accessibility */ |
| 216 | ) { |
| 217 | public void onDrawerClosed(View view) { |
| 218 | getActionBar().setTitle(mTitle); |
| 219 | invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() |
| 220 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 221 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 222 | public void onDrawerOpened(View drawerView) { |
| 223 | getActionBar().setTitle(mDrawerTitle); |
| 224 | invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu() |
| 225 | } |
| 226 | }; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 227 | |
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) { |
| 233 | actionBar.setSelectedNavigationItem(position); |
| 234 | } |
| 235 | }); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 236 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 237 | // For each of the sections in the app, add a tab to the action bar. |
| 238 | for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 239 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 240 | actionBar.addTab(actionBar.newTab().setIcon(icon_res_id[i]).setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); |
| 241 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 242 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 243 | actionBar.setSelectedNavigationItem(ACTION_BAR_TAB_CALL); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 244 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 245 | fMenu = new MenuFragment(); |
| 246 | getFragmentManager().beginTransaction().replace(R.id.left_drawer, fMenu).commit(); |
| 247 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 248 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 249 | @Override |
| 250 | protected void onStart() { |
| 251 | Log.i(TAG, "onStart"); |
| 252 | super.onStart(); |
| 253 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 254 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 255 | /* user gets back to the activity, e.g. through task manager */ |
| 256 | @Override |
| 257 | protected void onRestart() { |
| 258 | super.onRestart(); |
| 259 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 260 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 261 | /* activity gets back to the foreground and user input */ |
| 262 | @Override |
| 263 | protected void onResume() { |
| 264 | Log.i(TAG, "onResume"); |
| 265 | super.onResume(); |
| 266 | } |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 267 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 268 | /* activity no more in foreground */ |
| 269 | @Override |
| 270 | protected void onPause() { |
| 271 | super.onPause(); |
| 272 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 273 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 274 | /* activity is no longer visible */ |
| 275 | @Override |
| 276 | protected void onStop() { |
| 277 | super.onStop(); |
| 278 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 279 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 280 | /* activity finishes itself or is being killed by the system */ |
| 281 | @Override |
| 282 | protected void onDestroy() { |
| 283 | /* stop the service, if no other bound user, no need to check if it is running */ |
| 284 | if (mBound) { |
| 285 | Log.i(TAG, "onDestroy: Unbinding service..."); |
| 286 | unbindService(mConnection); |
| 287 | mBound = false; |
| 288 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 289 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 290 | /* unregister broadcast receiver */ |
| 291 | // LocalBroadcastManager.getInstance(this).unregisterReceiver(mCallList); |
| 292 | // LocalBroadcastManager.getInstance(this).unregisterReceiver(mAccountList); |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 293 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 294 | super.onDestroy(); |
| 295 | } |
alision | 73424b6 | 2013-04-26 11:49:18 -0400 | [diff] [blame] | 296 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 297 | public void launchCallActivity(SipCall.CallInfo infos) { |
| 298 | Log.i(TAG, "Launch Call Activity"); |
| 299 | Bundle bundle = new Bundle(); |
| 300 | bundle.putString("action", "incoming"); |
| 301 | // bundle.putParcelable("CallContact", mListAdapter.getItem(pos)); |
| 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 | } |
| 307 | |
| 308 | private ISipClient callback = new ISipClient.Stub() { |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 309 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 310 | @Override |
| 311 | public void incomingCall(Intent call) throws RemoteException { |
| 312 | Log.i(TAG, "Incoming call transfered from Service"); |
| 313 | SipCall.CallInfo infos = new SipCall.CallInfo(call); |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 314 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 315 | SipCall c = new SipCall(infos); |
| 316 | mCallElementList.addCall(c); |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 317 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 318 | launchCallActivity(infos); |
| 319 | } |
Adrien Béraud | 3326888 | 2013-05-18 03:41:15 +1000 | [diff] [blame] | 320 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 321 | @Override |
| 322 | public void callStateChanged(Intent callState) throws RemoteException { |
| 323 | Bundle b = callState.getBundleExtra("com.savoirfairelinux.sflphone.service.newstate"); |
| 324 | String cID = b.getString("CallID"); |
| 325 | String state = b.getString("State"); |
| 326 | Log.i(TAG, "callStateChanged" + cID + " " + state); |
| 327 | mCallElementList.updateCall(cID, state); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 328 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 329 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 330 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 331 | @Override |
| 332 | public void incomingText(Intent msg) throws RemoteException { |
| 333 | Bundle b = msg.getBundleExtra("com.savoirfairelinux.sflphone.service.newtext"); |
| 334 | b.getString("CallID"); |
| 335 | String from = b.getString("From"); |
| 336 | String mess = b.getString("Msg"); |
| 337 | Toast.makeText(getApplicationContext(), "text from " + from + " : " + mess, Toast.LENGTH_LONG).show(); |
alision | 04a0018 | 2013-05-10 17:05:29 -0400 | [diff] [blame] | 338 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 339 | } |
| 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 | |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 346 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 347 | @Override |
| 348 | public void onServiceConnected(ComponentName className, IBinder binder) { |
| 349 | service = ISipService.Stub.asInterface(binder); |
alision | e2a38e1 | 2013-04-25 14:20:20 -0400 | [diff] [blame] | 350 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 351 | mBound = true; |
| 352 | mCallElementList.onServiceSipBinded(service); |
| 353 | mHistorySectionFragment.onServiceSipBinded(service); |
| 354 | mDialingFragment.onServiceSipBinded(service); |
| 355 | Log.d(TAG, "Service connected service=" + service); |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 356 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 357 | try { |
| 358 | service.registerClient(callback); |
| 359 | } catch (RemoteException e) { |
| 360 | Log.e(TAG, e.toString()); |
| 361 | } |
| 362 | } |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 363 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 364 | @Override |
| 365 | public void onServiceDisconnected(ComponentName arg0) { |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 366 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 367 | mBound = false; |
| 368 | Log.d(TAG, "Service disconnected service=" + service); |
| 369 | } |
| 370 | }; |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 371 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 372 | @Override |
| 373 | public boolean onOptionsItemSelected(MenuItem item) { |
| 374 | Log.i(TAG, "onOptionsItemSelected " + item.getItemId()); |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 375 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 376 | if (mDrawerToggle.onOptionsItemSelected(item)) { |
| 377 | return true; |
| 378 | } |
| 379 | // switch(item.getItemId()){ |
| 380 | // case R.id.menu_settings : |
| 381 | // Intent launchPreferencesIntent = new Intent().setClass(this, SFLPhonePreferenceActivity.class); |
| 382 | // startActivityForResult(launchPreferencesIntent, REQUEST_CODE_PREFERENCES); |
| 383 | // break; |
| 384 | // case R.id.menu_custom_draw: |
| 385 | // Intent launchNewInterfaceIntent = new Intent().setClass(this, BubblesViewActivity.class); |
| 386 | // startActivityForResult(launchNewInterfaceIntent, 0); |
| 387 | // break; |
| 388 | // } |
alision | 5f89963 | 2013-04-22 17:26:56 -0400 | [diff] [blame] | 389 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 390 | return super.onOptionsItemSelected(item); |
| 391 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 392 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 393 | @Override |
| 394 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 395 | super.onActivityResult(requestCode, resultCode, data); |
| 396 | |
| 397 | switch (requestCode){ |
| 398 | case REQUEST_CODE_PREFERENCES: |
| 399 | mCallElementList.onServiceSipBinded(service); |
| 400 | break; |
| 401 | case REQUEST_CODE_CALL: |
| 402 | try { |
| 403 | service.registerClient(callback); |
| 404 | } catch (RemoteException e) { |
| 405 | Log.e(TAG,e.toString()); |
| 406 | } |
| 407 | break; |
| 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 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 411 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 412 | // @Override |
| 413 | // public boolean onCreateOptionsMenu(Menu menu) { |
| 414 | // getMenuInflater().inflate(R.menu.activity_sflphone_home, menu); |
| 415 | // return true; |
| 416 | // } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 417 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 418 | @Override |
| 419 | public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { |
| 420 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 421 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 422 | @Override |
| 423 | public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { |
| 424 | // When the given tab is selected, switch to the corresponding page in the ViewPager. |
| 425 | mViewPager.setCurrentItem(tab.getPosition()); |
| 426 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 427 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 428 | @Override |
| 429 | public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) { |
| 430 | // Log.d(TAG, "onTabReselected"); |
| 431 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 432 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 433 | public void processingHangUpAction() { |
| 434 | SipCall call = (SipCall) buttonHangup.getTag(); |
| 435 | if (call != null) |
| 436 | call.notifyServiceHangup(service); |
| 437 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 438 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 439 | @Override |
| 440 | public void onCallSelected(SipCall c) { |
| 441 | launchCallActivity(c.mCallInfo); |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 442 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 443 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 444 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 445 | @Override |
| 446 | public ISipService getService() { |
| 447 | return service; |
| 448 | } |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 449 | |
alision | 9f7a6ec | 2013-05-24 16:26:26 -0400 | [diff] [blame^] | 450 | @Override |
| 451 | public void onCallCreated(SipCall c) { |
| 452 | mCallElementList.addCall(c); |
| 453 | launchCallActivity(c.mCallInfo); |
| 454 | |
| 455 | } |
alision | 371b77e | 2013-04-23 14:51:26 -0400 | [diff] [blame] | 456 | |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 457 | } |