Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -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 | |
Emeric Vigier | e89b48b | 2012-08-30 14:16:46 -0400 | [diff] [blame] | 33 | import java.util.Random; |
| 34 | |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 35 | import android.app.ActionBar; |
| 36 | import android.app.Activity; |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame] | 37 | import android.app.AlertDialog; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 38 | import android.app.Fragment; |
| 39 | import android.app.FragmentManager; |
| 40 | import android.app.FragmentTransaction; |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 41 | import android.content.Intent; |
Emeric Vigier | 7a255aa | 2012-08-29 09:49:18 -0400 | [diff] [blame] | 42 | import android.content.pm.PackageInfo; |
| 43 | import android.content.pm.PackageManager; |
| 44 | import android.content.pm.PackageManager.NameNotFoundException; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 45 | import android.os.Bundle; |
Emeric Vigier | 383b2a2 | 2012-08-27 14:20:05 -0400 | [diff] [blame] | 46 | import android.os.Handler; |
| 47 | import android.os.Message; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 48 | import android.support.v13.app.FragmentStatePagerAdapter; |
| 49 | import android.support.v4.view.ViewPager; |
Emeric Vigier | 05e894e | 2012-08-20 13:53:02 -0400 | [diff] [blame] | 50 | import android.util.Log; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 51 | import android.view.Gravity; |
| 52 | import android.view.LayoutInflater; |
| 53 | import android.view.Menu; |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 54 | import android.view.MenuItem; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 55 | import android.view.View; |
Emeric Vigier | 05e894e | 2012-08-20 13:53:02 -0400 | [diff] [blame] | 56 | import android.view.View.OnClickListener; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 57 | import android.view.ViewGroup; |
Emeric Vigier | a6bdb70 | 2012-08-31 15:34:53 -0400 | [diff] [blame] | 58 | import android.view.animation.AlphaAnimation; |
| 59 | import android.view.animation.Animation; |
| 60 | import android.view.animation.LinearInterpolator; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 61 | import android.widget.Button; |
Emeric Vigier | d5c17f5 | 2012-08-29 09:29:33 -0400 | [diff] [blame] | 62 | import android.widget.EditText; |
Emeric Vigier | e89b48b | 2012-08-30 14:16:46 -0400 | [diff] [blame] | 63 | import android.widget.ImageButton; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 64 | import android.widget.TextView; |
| 65 | |
| 66 | import com.savoirfairelinux.sflphone.R; |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame] | 67 | import com.savoirfairelinux.sflphone.service.ServiceConstants; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 68 | import com.savoirfairelinux.sflphone.service.SipService; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 69 | |
Emeric Vigier | 62ca14d | 2012-08-24 11:05:09 -0400 | [diff] [blame] | 70 | public class SFLPhoneHome extends Activity implements ActionBar.TabListener, OnClickListener |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 71 | { |
| 72 | SectionsPagerAdapter mSectionsPagerAdapter; |
Emeric Vigier | 62ca14d | 2012-08-24 11:05:09 -0400 | [diff] [blame] | 73 | static final String TAG = "SFLPhoneHome"; |
Emeric Vigier | a6bdb70 | 2012-08-31 15:34:53 -0400 | [diff] [blame] | 74 | private ButtonSectionFragment buttonFragment; |
Emeric Vigier | 383b2a2 | 2012-08-27 14:20:05 -0400 | [diff] [blame] | 75 | Handler callbackHandler; |
Emeric Vigier | 9701e03 | 2012-09-12 12:38:01 -0400 | [diff] [blame] | 76 | private Manager manager; |
Emeric Vigier | 78a53e9 | 2012-08-29 18:15:34 -0400 | [diff] [blame] | 77 | /* default callID */ |
| 78 | static String callID = "007"; |
Emeric Vigier | e89b48b | 2012-08-30 14:16:46 -0400 | [diff] [blame] | 79 | static boolean callOnGoing = false; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 80 | static boolean serviceIsOn = false; |
Emeric Vigier | a6bdb70 | 2012-08-31 15:34:53 -0400 | [diff] [blame] | 81 | private String incomingCallID = ""; |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 82 | private static final int REQUEST_CODE_PREFERENCES = 1; |
Emeric Vigier | 090ab60 | 2012-09-17 11:09:46 -0400 | [diff] [blame] | 83 | ImageButton buttonCall, buttonHangup; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 84 | Button buttonService; |
Emeric Vigier | 419ba7b | 2012-09-19 14:55:14 -0400 | [diff] [blame] | 85 | static Animation animation; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 86 | |
| 87 | /** |
| 88 | * The {@link ViewPager} that will host the section contents. |
| 89 | */ |
| 90 | ViewPager mViewPager; |
| 91 | |
Alexandre Savard | a04c520 | 2012-09-18 17:19:53 -0400 | [diff] [blame] | 92 | final private int[] icon_res_id = {R.drawable.ic_tab_call, R.drawable.ic_tab_call, R.drawable.ic_tab_history, R.drawable.ic_tab_play_selected}; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 93 | |
| 94 | @Override |
| 95 | public void onCreate(Bundle savedInstanceState) |
| 96 | { |
| 97 | super.onCreate(savedInstanceState); |
| 98 | setContentView(R.layout.activity_sflphone_home); |
| 99 | |
| 100 | mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager()); |
| 101 | |
| 102 | final ActionBar actionBar = getActionBar(); |
| 103 | actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); |
Alexandre Savard | def3bfa | 2012-09-12 16:20:06 -0400 | [diff] [blame] | 104 | // final ActionBar actionBar = getActionBar(); |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 105 | |
| 106 | // Set up the ViewPager with the sections adapter. |
| 107 | mViewPager = (ViewPager) findViewById(R.id.pager); |
| 108 | mViewPager.setAdapter(mSectionsPagerAdapter); |
| 109 | |
| 110 | // When swiping between different sections, select the corresponding tab. |
| 111 | // We can also use ActionBar.Tab#select() to do this if we have a reference to the |
| 112 | // Tab. |
| 113 | mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() |
| 114 | { |
| 115 | @Override |
| 116 | public void onPageSelected(int position) |
| 117 | { |
| 118 | actionBar.setSelectedNavigationItem(position); |
| 119 | } |
| 120 | }); |
| 121 | |
| 122 | // For each of the sections in the app, add a tab to the action bar. |
| 123 | for (int i = 0; i < mSectionsPagerAdapter.getCount(); i++) { |
| 124 | // Create a tab with text corresponding to the page title defined by the adapter. |
| 125 | // Also specify this Activity object, which implements the TabListener interface, as the |
| 126 | // listener for when this tab is selected. |
Alexandre Savard | a04c520 | 2012-09-18 17:19:53 -0400 | [diff] [blame] | 127 | Log.i(TAG, "adding tab: " + i); |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 128 | actionBar.addTab(actionBar.newTab().setIcon(icon_res_id[i]).setText(mSectionsPagerAdapter.getPageTitle(i)).setTabListener(this)); |
| 129 | } |
Emeric Vigier | 383b2a2 | 2012-08-27 14:20:05 -0400 | [diff] [blame] | 130 | |
| 131 | // FIXME |
| 132 | callbackHandler = new Handler() { |
| 133 | public void handleMessage(Message msg) { |
| 134 | Bundle b = msg.getData(); |
| 135 | TextView callVoidText; |
| 136 | |
Emeric Vigier | c411ce3 | 2012-08-29 09:28:28 -0400 | [diff] [blame] | 137 | Log.i(TAG, "handleMessage"); |
Emeric Vigier | 383b2a2 | 2012-08-27 14:20:05 -0400 | [diff] [blame] | 138 | |
| 139 | callVoidText = buttonFragment.getcallVoidText(); |
| 140 | if (callVoidText == null) |
| 141 | Log.e(TAG, "SFLPhoneHome: callVoidText is " + callVoidText); |
| 142 | callVoidText.setText(b.getString("callback_string")); |
| 143 | |
Emeric Vigier | c411ce3 | 2012-08-29 09:28:28 -0400 | [diff] [blame] | 144 | Log.i(TAG, "handleMessage: " + b.getString("callback_string")); |
Emeric Vigier | 383b2a2 | 2012-08-27 14:20:05 -0400 | [diff] [blame] | 145 | } |
| 146 | }; |
Emeric Vigier | a6bdb70 | 2012-08-31 15:34:53 -0400 | [diff] [blame] | 147 | |
| 148 | buttonCall = (ImageButton) findViewById(R.id.buttonCall); |
| 149 | buttonHangup = (ImageButton) findViewById(R.id.buttonHangUp); |
Alexandre Savard | def3bfa | 2012-09-12 16:20:06 -0400 | [diff] [blame] | 150 | |
Emeric Vigier | 419ba7b | 2012-09-19 14:55:14 -0400 | [diff] [blame] | 151 | // Change alpha from fully visible to invisible |
| 152 | animation = new AlphaAnimation(1, 0); |
| 153 | // duration - half a second |
| 154 | animation.setDuration(500); |
| 155 | // do not alter animation rate |
| 156 | animation.setInterpolator(new LinearInterpolator()); |
| 157 | // Repeat animation infinitely |
| 158 | animation.setRepeatCount(Animation.INFINITE); |
| 159 | // Reverse |
| 160 | animation.setRepeatMode(Animation.REVERSE); |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 161 | } |
| 162 | |
Emeric Vigier | 62ca14d | 2012-08-24 11:05:09 -0400 | [diff] [blame] | 163 | // FIXME |
| 164 | static { |
| 165 | System.loadLibrary("gnustl_shared"); |
| 166 | System.loadLibrary("expat"); |
| 167 | System.loadLibrary("yaml"); |
| 168 | System.loadLibrary("ccgnu2"); |
| 169 | System.loadLibrary("crypto"); |
| 170 | System.loadLibrary("ssl"); |
| 171 | System.loadLibrary("ccrtp1"); |
| 172 | System.loadLibrary("dbus"); |
| 173 | System.loadLibrary("dbus-c++-1"); |
| 174 | System.loadLibrary("samplerate"); |
| 175 | System.loadLibrary("codec_ulaw"); |
| 176 | System.loadLibrary("codec_alaw"); |
| 177 | System.loadLibrary("speexresampler"); |
| 178 | System.loadLibrary("sflphone"); |
| 179 | } |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 180 | |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame] | 181 | @Override |
| 182 | protected void onStart() { |
| 183 | Log.i(TAG, "onStart"); |
| 184 | super.onStart(); |
| 185 | } |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 186 | |
Emeric Vigier | 12d61d8 | 2012-09-19 15:08:18 -0400 | [diff] [blame] | 187 | @Override |
| 188 | protected void onRestart() { |
| 189 | super.onRestart(); |
| 190 | } |
| 191 | |
| 192 | @Override |
| 193 | protected void onResume() { |
| 194 | Log.i(TAG, "onResume"); |
| 195 | super.onResume(); |
| 196 | |
| 197 | Log.i(TAG, "starting SipService"); |
| 198 | startSipService(); |
| 199 | } |
| 200 | |
| 201 | @Override |
| 202 | protected void onPause() { |
| 203 | /* stop the service, no need to check if it is running */ |
| 204 | stopService(new Intent(this, SipService.class)); |
| 205 | serviceIsOn = false; |
| 206 | super.onPause(); |
| 207 | } |
| 208 | |
| 209 | @Override |
| 210 | protected void onStop() { |
| 211 | super.onStop(); |
| 212 | } |
| 213 | |
| 214 | @Override |
| 215 | protected void onDestroy() { |
| 216 | super.onDestroy(); |
| 217 | } |
| 218 | |
| 219 | private void startSipService() { |
| 220 | Thread thread = new Thread("StartSFLphoneService") { |
| 221 | public void run() { |
| 222 | Intent sipServiceIntent = new Intent(SFLPhoneHome.this, SipService.class); |
| 223 | //sipServiceIntent.putExtra(ServiceConstants.EXTRA_OUTGOING_ACTIVITY, new ComponentName(SFLPhoneHome.this, SFLPhoneHome.class)); |
| 224 | startService(sipServiceIntent); |
| 225 | }; |
| 226 | }; |
| 227 | try { |
| 228 | thread.start(); |
| 229 | } catch (IllegalThreadStateException e) { |
| 230 | AlertDialog.Builder builder = new AlertDialog.Builder(this); |
| 231 | builder.setMessage("Cannot start SFLPhone SipService!"); |
| 232 | AlertDialog alert = builder.create(); |
| 233 | alert.show(); |
| 234 | finish(); |
| 235 | } |
| 236 | |
| 237 | // FIXME |
| 238 | callbackHandler = new Handler() { |
| 239 | public void handleMessage(Message msg) { |
| 240 | Bundle b = msg.getData(); |
| 241 | TextView callVoidText; |
| 242 | |
| 243 | Log.i(TAG, "handleMessage"); |
| 244 | |
| 245 | callVoidText = buttonFragment.getcallVoidText(); |
| 246 | if (callVoidText == null) |
| 247 | Log.e(TAG, "SFLPhoneHome: callVoidText is " + callVoidText); |
| 248 | callVoidText.setText(b.getString("callback_string")); |
| 249 | |
| 250 | Log.i(TAG, "handleMessage: " + b.getString("callback_string")); |
| 251 | } |
| 252 | }; |
| 253 | |
| 254 | manager = new Manager(callbackHandler); |
| 255 | Log.i(TAG, "ManagerImpl::instance() = " + Manager.managerImpl); |
| 256 | Manager.setActivity(this); |
| 257 | /* set static AppPath before calling manager.init */ |
| 258 | Manager.managerImpl.setPath(getAppPath()); |
| 259 | Log.i(TAG, "manager created with callbackHandler " + callbackHandler); |
| 260 | } |
| 261 | |
| 262 | @Override |
| 263 | public boolean onOptionsItemSelected(MenuItem item) { |
| 264 | Log.i("SFLphone", "onOptionsItemSelected " + item.getItemId()); |
Alexandre Savard | ebc9443 | 2012-09-13 14:30:55 -0400 | [diff] [blame] | 265 | if(item.getItemId() != 0) { |
| 266 | // When the button is clicked, launch an activity through this intent |
| 267 | Intent launchPreferencesIntent = new Intent().setClass(this, SFLPhonePreferenceActivity.class); |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 268 | |
Alexandre Savard | ebc9443 | 2012-09-13 14:30:55 -0400 | [diff] [blame] | 269 | // Make it a subactivity so we know when it returns |
| 270 | startActivityForResult(launchPreferencesIntent, REQUEST_CODE_PREFERENCES); |
| 271 | } |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 272 | |
| 273 | return super.onOptionsItemSelected(item); |
| 274 | } |
Emeric Vigier | 62ca14d | 2012-08-24 11:05:09 -0400 | [diff] [blame] | 275 | |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 276 | @Override |
| 277 | public boolean onCreateOptionsMenu(Menu menu) |
| 278 | { |
| 279 | getMenuInflater().inflate(R.menu.activity_sflphone_home, menu); |
| 280 | return true; |
| 281 | } |
| 282 | |
| 283 | @Override |
| 284 | public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) |
| 285 | { |
| 286 | } |
| 287 | |
| 288 | @Override |
| 289 | public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) |
| 290 | { |
| 291 | // When the given tab is selected, switch to the corresponding page in the ViewPager. |
| 292 | mViewPager.setCurrentItem(tab.getPosition()); |
| 293 | } |
| 294 | |
| 295 | @Override |
| 296 | public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) |
| 297 | { |
Emeric Vigier | 05e894e | 2012-08-20 13:53:02 -0400 | [diff] [blame] | 298 | // Log.d(TAG, "onTabReselected"); |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 299 | } |
| 300 | |
Emeric Vigier | 419ba7b | 2012-09-19 14:55:14 -0400 | [diff] [blame] | 301 | public void setIncomingCallID(String accountID, String callID, String from) { |
| 302 | Log.i(TAG, "incomingCall(" + accountID + ", " + callID + ", " + from + ")"); |
| 303 | incomingCallID = callID; |
| 304 | buttonCall.startAnimation(animation); |
| 305 | buttonCall.setImageResource(R.drawable.ic_incomingcall); |
Emeric Vigier | a6bdb70 | 2012-08-31 15:34:53 -0400 | [diff] [blame] | 306 | } |
| 307 | |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 308 | /** |
| 309 | * A {@link FragmentStatePagerAdapter} that returns a fragment corresponding to |
| 310 | * one of the primary sections of the app. |
| 311 | */ |
| 312 | public class SectionsPagerAdapter extends FragmentStatePagerAdapter |
| 313 | { |
| 314 | |
| 315 | public SectionsPagerAdapter(FragmentManager fm) |
| 316 | { |
| 317 | super(fm); |
| 318 | } |
| 319 | |
| 320 | @Override |
| 321 | public Fragment getItem(int i) |
| 322 | { |
| 323 | Fragment fragment; |
Emeric Vigier | 62ca14d | 2012-08-24 11:05:09 -0400 | [diff] [blame] | 324 | |
Emeric Vigier | 05e894e | 2012-08-20 13:53:02 -0400 | [diff] [blame] | 325 | switch (i) { |
Alexandre Savard | a04c520 | 2012-09-18 17:19:53 -0400 | [diff] [blame] | 326 | case 0: |
Alexandre Savard | 23240c1 | 2012-09-19 18:23:44 -0400 | [diff] [blame] | 327 | fragment = new ContactListFragment(manager); |
Alexandre Savard | a04c520 | 2012-09-18 17:19:53 -0400 | [diff] [blame] | 328 | break; |
| 329 | case 1: |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 330 | fragment = new CallElementList(); |
Emeric Vigier | 05e894e | 2012-08-20 13:53:02 -0400 | [diff] [blame] | 331 | break; |
Alexandre Savard | a04c520 | 2012-09-18 17:19:53 -0400 | [diff] [blame] | 332 | case 2: |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 333 | fragment = new DummySectionFragment(); |
Emeric Vigier | 05e894e | 2012-08-20 13:53:02 -0400 | [diff] [blame] | 334 | break; |
Alexandre Savard | a04c520 | 2012-09-18 17:19:53 -0400 | [diff] [blame] | 335 | case 3: |
Alexandre Savard | def3bfa | 2012-09-12 16:20:06 -0400 | [diff] [blame] | 336 | fragment = new ButtonSectionFragment(); |
| 337 | Log.i(TAG, "getItem: fragment is " + fragment); |
Emeric Vigier | 05e894e | 2012-08-20 13:53:02 -0400 | [diff] [blame] | 338 | break; |
| 339 | default: |
| 340 | Log.e(TAG, "getItem: unknown tab position " + i); |
| 341 | return null; |
| 342 | } |
| 343 | |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 344 | Bundle args = new Bundle(); |
| 345 | args.putInt(DummySectionFragment.ARG_SECTION_NUMBER, i + 1); |
| 346 | fragment.setArguments(args); |
| 347 | return fragment; |
| 348 | } |
| 349 | |
| 350 | @Override |
| 351 | public int getCount() |
| 352 | { |
Alexandre Savard | a04c520 | 2012-09-18 17:19:53 -0400 | [diff] [blame] | 353 | return 4; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | @Override |
| 357 | public CharSequence getPageTitle(int position) |
| 358 | { |
| 359 | switch (position) { |
Alexandre Savard | a04c520 | 2012-09-18 17:19:53 -0400 | [diff] [blame] | 360 | case 0: |
| 361 | return getString(R.string.title_section0).toUpperCase(); |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 362 | case 1: |
Alexandre Savard | a04c520 | 2012-09-18 17:19:53 -0400 | [diff] [blame] | 363 | return getString(R.string.title_section1).toUpperCase(); |
Emeric Vigier | 05e894e | 2012-08-20 13:53:02 -0400 | [diff] [blame] | 364 | case 2: |
Alexandre Savard | a04c520 | 2012-09-18 17:19:53 -0400 | [diff] [blame] | 365 | return getString(R.string.title_section2).toUpperCase(); |
| 366 | case 3: |
Emeric Vigier | 05e894e | 2012-08-20 13:53:02 -0400 | [diff] [blame] | 367 | return getString(R.string.title_section3).toUpperCase(); |
| 368 | default: |
| 369 | Log.e(TAG, "getPageTitle: unknown tab position " + position); |
| 370 | break; |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 371 | } |
| 372 | return null; |
| 373 | } |
| 374 | } |
| 375 | |
| 376 | /** |
| 377 | * A dummy fragment representing a section of the app, but that simply |
| 378 | * displays dummy text. |
| 379 | */ |
| 380 | public static class DummySectionFragment extends Fragment |
| 381 | { |
| 382 | public DummySectionFragment() |
| 383 | { |
| 384 | setRetainInstance(true); |
| 385 | } |
| 386 | |
| 387 | public static final String ARG_SECTION_NUMBER = "section_number"; |
| 388 | |
| 389 | @Override |
Emeric Vigier | 05e894e | 2012-08-20 13:53:02 -0400 | [diff] [blame] | 390 | public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 391 | { |
| 392 | TextView textView = new TextView(getActivity()); |
| 393 | textView.setGravity(Gravity.CENTER); |
| 394 | Bundle args = getArguments(); |
| 395 | textView.setText(Integer.toString(args.getInt(ARG_SECTION_NUMBER))); |
Emeric Vigier | 05e894e | 2012-08-20 13:53:02 -0400 | [diff] [blame] | 396 | textView.setText("java sucks"); |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 397 | return textView; |
| 398 | } |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 399 | } |
Emeric Vigier | 05e894e | 2012-08-20 13:53:02 -0400 | [diff] [blame] | 400 | |
Emeric Vigier | 7a255aa | 2012-08-29 09:49:18 -0400 | [diff] [blame] | 401 | public String getAppPath() { |
| 402 | PackageManager pkgMng = getPackageManager(); |
| 403 | String pkgName = getPackageName(); |
| 404 | |
| 405 | try { |
| 406 | PackageInfo pkgInfo = pkgMng.getPackageInfo(pkgName, 0); |
| 407 | pkgName = pkgInfo.applicationInfo.dataDir; |
| 408 | } catch (NameNotFoundException e) { |
| 409 | Log.w(TAG, "Error Package name not found ", e); |
| 410 | } |
| 411 | |
| 412 | Log.d(TAG, "Application path: " + pkgName); |
| 413 | return pkgName; |
Emeric Vigier | 62ca14d | 2012-08-24 11:05:09 -0400 | [diff] [blame] | 414 | } |
Emeric Vigier | 05e894e | 2012-08-20 13:53:02 -0400 | [diff] [blame] | 415 | |
Emeric Vigier | 62ca14d | 2012-08-24 11:05:09 -0400 | [diff] [blame] | 416 | @Override |
| 417 | public void onClick(View view) |
Emeric Vigier | e89b48b | 2012-08-30 14:16:46 -0400 | [diff] [blame] | 418 | { |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 419 | buttonService = (Button) findViewById(R.id.buttonService); |
| 420 | |
Emeric Vigier | 62ca14d | 2012-08-24 11:05:09 -0400 | [diff] [blame] | 421 | switch (view.getId()) { |
Emeric Vigier | d5c17f5 | 2012-08-29 09:29:33 -0400 | [diff] [blame] | 422 | case R.id.buttonCall: |
Emeric Vigier | 39a11fa | 2012-08-29 15:25:09 -0400 | [diff] [blame] | 423 | TextView textView = (TextView) findViewById(R.id.editAccountID); |
| 424 | String accountID = textView.getText().toString(); |
| 425 | EditText editText; |
Emeric Vigier | 78a53e9 | 2012-08-29 18:15:34 -0400 | [diff] [blame] | 426 | Random random = new Random(); |
Emeric Vigier | e89b48b | 2012-08-30 14:16:46 -0400 | [diff] [blame] | 427 | |
Emeric Vigier | a6bdb70 | 2012-08-31 15:34:53 -0400 | [diff] [blame] | 428 | if (incomingCallID != "") { |
| 429 | buttonCall.clearAnimation(); |
Emeric Vigier | 9380ae5 | 2012-09-14 17:40:39 -0400 | [diff] [blame] | 430 | // manager.managerImpl.answerCall(incomingCallID); |
| 431 | manager.callmanagerJNI.accept(incomingCallID); |
Emeric Vigier | a6bdb70 | 2012-08-31 15:34:53 -0400 | [diff] [blame] | 432 | callID = incomingCallID; |
| 433 | incomingCallID=""; |
Emeric Vigier | e89b48b | 2012-08-30 14:16:46 -0400 | [diff] [blame] | 434 | callOnGoing = true; |
Emeric Vigier | a6bdb70 | 2012-08-31 15:34:53 -0400 | [diff] [blame] | 435 | buttonCall.setEnabled(false); |
| 436 | buttonHangup.setEnabled(true); |
| 437 | } else { |
| 438 | if (callOnGoing == false) { |
| 439 | editText = (EditText) findViewById(R.id.editTo); |
| 440 | String to = editText.getText().toString(); |
| 441 | if (to == null) { |
| 442 | Log.e(TAG, "to string is " + to); |
| 443 | break; |
| 444 | } |
| 445 | |
Emeric Vigier | a6bdb70 | 2012-08-31 15:34:53 -0400 | [diff] [blame] | 446 | callID = Integer.toString(random.nextInt()); |
| 447 | |
Emeric Vigier | 9701e03 | 2012-09-12 12:38:01 -0400 | [diff] [blame] | 448 | Log.d(TAG, "manager.managerImpl.placeCall(" + accountID + ", " + callID + ", " + to + ");"); |
Emeric Vigier | 9380ae5 | 2012-09-14 17:40:39 -0400 | [diff] [blame] | 449 | // manager.managerImpl.outgoingCall(accountID, callID, to); |
| 450 | manager.callmanagerJNI.placeCall(accountID, callID, to); |
Emeric Vigier | a6bdb70 | 2012-08-31 15:34:53 -0400 | [diff] [blame] | 451 | callOnGoing = true; |
| 452 | buttonCall.setEnabled(false); |
| 453 | buttonHangup.setEnabled(true); |
| 454 | } |
Emeric Vigier | d5c17f5 | 2012-08-29 09:29:33 -0400 | [diff] [blame] | 455 | } |
Emeric Vigier | d5c17f5 | 2012-08-29 09:29:33 -0400 | [diff] [blame] | 456 | break; |
Emeric Vigier | 78a53e9 | 2012-08-29 18:15:34 -0400 | [diff] [blame] | 457 | case R.id.buttonHangUp: |
Emeric Vigier | a6bdb70 | 2012-08-31 15:34:53 -0400 | [diff] [blame] | 458 | if (incomingCallID != "") { |
| 459 | buttonCall.clearAnimation(); |
Emeric Vigier | 9380ae5 | 2012-09-14 17:40:39 -0400 | [diff] [blame] | 460 | // manager.managerImpl.refuseCall(incomingCallID); |
| 461 | manager.callmanagerJNI.refuse(incomingCallID); |
Emeric Vigier | a6bdb70 | 2012-08-31 15:34:53 -0400 | [diff] [blame] | 462 | incomingCallID=""; |
| 463 | buttonCall.setEnabled(true); |
| 464 | buttonHangup.setEnabled(true); |
| 465 | } else { |
| 466 | if (callOnGoing == true) { |
Emeric Vigier | 9701e03 | 2012-09-12 12:38:01 -0400 | [diff] [blame] | 467 | Log.d(TAG, "manager.managerImpl.hangUp(" + callID + ");"); |
Emeric Vigier | 9380ae5 | 2012-09-14 17:40:39 -0400 | [diff] [blame] | 468 | // manager.managerImpl.hangupCall(callID); |
| 469 | manager.callmanagerJNI.hangUp(callID); |
Emeric Vigier | a6bdb70 | 2012-08-31 15:34:53 -0400 | [diff] [blame] | 470 | callOnGoing = false; |
| 471 | buttonCall.setEnabled(true); |
| 472 | buttonHangup.setEnabled(false); |
| 473 | } |
Emeric Vigier | e89b48b | 2012-08-30 14:16:46 -0400 | [diff] [blame] | 474 | } |
Emeric Vigier | a6bdb70 | 2012-08-31 15:34:53 -0400 | [diff] [blame] | 475 | |
| 476 | buttonCall.setImageResource(R.drawable.ic_call); |
Emeric Vigier | 78a53e9 | 2012-08-29 18:15:34 -0400 | [diff] [blame] | 477 | break; |
Emeric Vigier | 62ca14d | 2012-08-24 11:05:09 -0400 | [diff] [blame] | 478 | case R.id.buttonInit: |
Emeric Vigier | 9701e03 | 2012-09-12 12:38:01 -0400 | [diff] [blame] | 479 | Manager.managerImpl.setPath(""); |
| 480 | Manager.managerImpl.init(""); |
Emeric Vigier | 62ca14d | 2012-08-24 11:05:09 -0400 | [diff] [blame] | 481 | break; |
Emeric Vigier | eaf2c49 | 2012-09-19 14:38:20 -0400 | [diff] [blame] | 482 | case R.id.buttonService: |
| 483 | if (!serviceIsOn) { |
| 484 | startService(new Intent(this, SipService.class)); |
| 485 | serviceIsOn = true; |
| 486 | buttonService.setText("disable Service"); |
| 487 | } |
| 488 | else { |
| 489 | stopService(new Intent(this, SipService.class)); |
| 490 | serviceIsOn = false; |
| 491 | buttonService.setText("enable Service"); |
| 492 | } |
| 493 | break; |
Emeric Vigier | 62ca14d | 2012-08-24 11:05:09 -0400 | [diff] [blame] | 494 | case R.id.buttonCallVoid: |
Emeric Vigier | 9701e03 | 2012-09-12 12:38:01 -0400 | [diff] [blame] | 495 | Manager.callVoid(); |
Emeric Vigier | 62ca14d | 2012-08-24 11:05:09 -0400 | [diff] [blame] | 496 | break; |
| 497 | case R.id.buttonGetNewData: |
Emeric Vigier | 9701e03 | 2012-09-12 12:38:01 -0400 | [diff] [blame] | 498 | Data d = Manager.getNewData(42, "foo"); |
Emeric Vigier | 62ca14d | 2012-08-24 11:05:09 -0400 | [diff] [blame] | 499 | if (d != null) |
| 500 | buttonFragment.getNewDataText().setText("getNewData(42, \"foo\") == Data(" + d.i + ", \"" + d.s + "\")"); |
| 501 | break; |
| 502 | case R.id.buttonGetDataString: |
Emeric Vigier | 383b2a2 | 2012-08-27 14:20:05 -0400 | [diff] [blame] | 503 | Data daita = new Data(43, "bar"); |
Emeric Vigier | 9701e03 | 2012-09-12 12:38:01 -0400 | [diff] [blame] | 504 | String s = Manager.getDataString(daita); |
Emeric Vigier | 62ca14d | 2012-08-24 11:05:09 -0400 | [diff] [blame] | 505 | if (s != "") { |
Emeric Vigier | 383b2a2 | 2012-08-27 14:20:05 -0400 | [diff] [blame] | 506 | buttonFragment.getDataStringText().setText("getDataString(Data(43, \"bar\")) == \"" + s + "\""); |
Emeric Vigier | 62ca14d | 2012-08-24 11:05:09 -0400 | [diff] [blame] | 507 | } |
| 508 | break; |
| 509 | default: |
| 510 | Log.w(TAG, "unknown button " + view.getId()); |
| 511 | break; |
Emeric Vigier | 05e894e | 2012-08-20 13:53:02 -0400 | [diff] [blame] | 512 | } |
Emeric Vigier | 05e894e | 2012-08-20 13:53:02 -0400 | [diff] [blame] | 513 | } |
Adrien Béraud | ffd3241 | 2012-08-07 18:39:23 -0400 | [diff] [blame] | 514 | } |