Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2012 Savoir-Faire Linux Inc. |
| 3 | * |
| 4 | * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.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 | |
| 32 | package com.savoirfairelinux.sflphone.client; |
| 33 | |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 34 | import android.app.ActionBar; |
| 35 | import android.app.Activity; |
| 36 | import android.app.Fragment; |
| 37 | import android.app.FragmentManager; |
| 38 | import android.app.FragmentTransaction; |
| 39 | import android.app.ListFragment; |
Alexandre Savard | 12dc3ac | 2012-09-27 11:17:39 -0400 | [diff] [blame] | 40 | import android.content.ComponentName; |
| 41 | import android.content.Context; |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 42 | import android.content.Intent; |
Alexandre Savard | 12dc3ac | 2012-09-27 11:17:39 -0400 | [diff] [blame] | 43 | import android.content.ServiceConnection; |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 44 | import android.os.Bundle; |
Alexandre Savard | 12dc3ac | 2012-09-27 11:17:39 -0400 | [diff] [blame] | 45 | import android.os.IBinder; |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 46 | import android.support.v13.app.FragmentStatePagerAdapter; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 47 | import android.support.v4.view.ViewPager; |
| 48 | import android.util.Log; |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 49 | |
| 50 | import com.savoirfairelinux.sflphone.R; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 51 | import com.savoirfairelinux.sflphone.fragments.AccountManagementFragment; |
alision | d9e2944 | 2013-04-17 16:10:18 -0400 | [diff] [blame] | 52 | import com.savoirfairelinux.sflphone.fragments.AudioManagementFragment; |
Alexandre Savard | 12dc3ac | 2012-09-27 11:17:39 -0400 | [diff] [blame] | 53 | import com.savoirfairelinux.sflphone.service.ISipService; |
alision | f76de3b | 2013-04-16 15:35:22 -0400 | [diff] [blame] | 54 | import com.savoirfairelinux.sflphone.service.SipService; |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 55 | |
Alexandre Savard | 150352e | 2012-09-05 18:10:02 -0400 | [diff] [blame] | 56 | public class SFLPhonePreferenceActivity extends Activity implements ActionBar.TabListener |
| 57 | { |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 58 | static final int NUM_PAGES = 2; |
alision | d9e2944 | 2013-04-17 16:10:18 -0400 | [diff] [blame] | 59 | static final String TAG = SFLPhonePreferenceActivity.class.getSimpleName(); |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 60 | PreferencesPagerAdapter mPreferencesPagerAdapter; |
Alexandre Savard | 12dc3ac | 2012-09-27 11:17:39 -0400 | [diff] [blame] | 61 | private boolean mBound = false; |
| 62 | static boolean serviceIsOn = false; |
| 63 | private ISipService service; |
| 64 | |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 65 | ViewPager mViewPager; |
| 66 | |
Alexandre Savard | 12dc3ac | 2012-09-27 11:17:39 -0400 | [diff] [blame] | 67 | private ServiceConnection mConnection = new ServiceConnection() { |
| 68 | |
| 69 | @Override |
| 70 | public void onServiceConnected(ComponentName className, IBinder binder) { |
| 71 | service = ISipService.Stub.asInterface(binder); |
| 72 | mBound = true; |
| 73 | Log.d(TAG, "Service connected"); |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public void onServiceDisconnected(ComponentName arg0) { |
| 78 | mBound = false; |
| 79 | Log.d(TAG, "Service disconnected"); |
| 80 | } |
| 81 | }; |
| 82 | |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 83 | @Override |
| 84 | public void onCreate(Bundle savedInstanceState) |
| 85 | { |
| 86 | super.onCreate(savedInstanceState); |
| 87 | |
| 88 | Log.i(TAG,"onCreate SFLPhonePreferenceActivity"); |
| 89 | |
| 90 | setContentView(R.layout.activity_sflphone_preferences); |
| 91 | |
| 92 | mPreferencesPagerAdapter = new PreferencesPagerAdapter(getFragmentManager()); |
| 93 | |
| 94 | final ActionBar actionBar = getActionBar(); |
| 95 | actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); |
| 96 | |
| 97 | mViewPager = (ViewPager) findViewById(R.id.preferences_pager); |
| 98 | mViewPager.setAdapter(mPreferencesPagerAdapter); |
| 99 | |
Alexandre Savard | 150352e | 2012-09-05 18:10:02 -0400 | [diff] [blame] | 100 | mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() |
| 101 | { |
| 102 | @Override |
| 103 | public void onPageSelected(int position) |
| 104 | { |
| 105 | actionBar.setSelectedNavigationItem(position); |
| 106 | } |
| 107 | }); |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 108 | |
| 109 | for(int i = 0; i < mPreferencesPagerAdapter.getCount(); i++) { |
Alexandre Savard | 150352e | 2012-09-05 18:10:02 -0400 | [diff] [blame] | 110 | actionBar.addTab(actionBar.newTab().setText(mPreferencesPagerAdapter.getPageTitle(i)).setTabListener(this)); |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 111 | } |
| 112 | |
Alexandre Savard | 12dc3ac | 2012-09-27 11:17:39 -0400 | [diff] [blame] | 113 | if(!mBound) { |
Emeric Vigier | 364499e | 2012-11-06 19:15:45 -0500 | [diff] [blame] | 114 | Log.i(TAG, "onCreate: Binding service..."); |
Alexandre Savard | 12dc3ac | 2012-09-27 11:17:39 -0400 | [diff] [blame] | 115 | Intent intent = new Intent(this, SipService.class); |
| 116 | bindService(intent, mConnection, Context.BIND_AUTO_CREATE); |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | @Override |
Alexandre Savard | 833616f | 2012-10-30 16:02:30 -0400 | [diff] [blame] | 121 | protected void onStart() { |
| 122 | Log.i(TAG, "onStart"); |
| 123 | super.onStart(); |
| 124 | } |
| 125 | |
| 126 | @Override |
Alexandre Savard | 12dc3ac | 2012-09-27 11:17:39 -0400 | [diff] [blame] | 127 | protected void onStop() { |
| 128 | super.onStop(); |
Alexandre Savard | 12dc3ac | 2012-09-27 11:17:39 -0400 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | @Override |
| 132 | protected void onDestroy() { |
| 133 | Log.i(TAG, "onDestroy: stopping SipService..."); |
Alexandre Savard | 833616f | 2012-10-30 16:02:30 -0400 | [diff] [blame] | 134 | |
| 135 | if(mBound) { |
| 136 | unbindService(mConnection); |
| 137 | mBound = false; |
| 138 | } |
| 139 | |
Emeric Vigier | 0038a61 | 2012-11-06 18:51:19 -0500 | [diff] [blame] | 140 | // stopService(new Intent(this, SipService.class)); |
| 141 | // serviceIsOn = false; |
Alexandre Savard | 12dc3ac | 2012-09-27 11:17:39 -0400 | [diff] [blame] | 142 | super.onDestroy(); |
| 143 | } |
| 144 | |
Emeric Vigier | 1f1ced3 | 2012-11-02 16:56:32 -0400 | [diff] [blame] | 145 | public ISipService getSipService() { |
| 146 | return service; |
| 147 | } |
| 148 | |
Alexandre Savard | 12dc3ac | 2012-09-27 11:17:39 -0400 | [diff] [blame] | 149 | @Override |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 150 | public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) |
| 151 | { |
| 152 | } |
| 153 | |
| 154 | @Override |
| 155 | public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) |
| 156 | { |
| 157 | mViewPager.setCurrentItem(tab.getPosition()); |
| 158 | } |
| 159 | |
| 160 | @Override |
| 161 | public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) |
| 162 | { |
| 163 | } |
| 164 | |
Alexandre Savard | 150352e | 2012-09-05 18:10:02 -0400 | [diff] [blame] | 165 | public class PreferencesPagerAdapter extends FragmentStatePagerAdapter { |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 166 | |
Alexandre Savard | 150352e | 2012-09-05 18:10:02 -0400 | [diff] [blame] | 167 | public PreferencesPagerAdapter(FragmentManager fm) |
| 168 | { |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 169 | super(fm); |
| 170 | } |
| 171 | |
| 172 | @Override |
Alexandre Savard | 150352e | 2012-09-05 18:10:02 -0400 | [diff] [blame] | 173 | public int getCount() |
| 174 | { |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 175 | return NUM_PAGES; |
| 176 | } |
| 177 | |
| 178 | @Override |
Alexandre Savard | 150352e | 2012-09-05 18:10:02 -0400 | [diff] [blame] | 179 | public Fragment getItem(int position) |
| 180 | { |
Alexandre Savard | 2b370f0 | 2012-09-06 16:06:01 -0400 | [diff] [blame] | 181 | Fragment fragment; |
| 182 | |
| 183 | switch (position) { |
| 184 | case 0: |
Emeric Vigier | 1f1ced3 | 2012-11-02 16:56:32 -0400 | [diff] [blame] | 185 | fragment = new AccountManagementFragment(); |
Alexandre Savard | 2b370f0 | 2012-09-06 16:06:01 -0400 | [diff] [blame] | 186 | break; |
| 187 | case 1: |
alision | d9e2944 | 2013-04-17 16:10:18 -0400 | [diff] [blame] | 188 | fragment = new AudioManagementFragment(); |
Alexandre Savard | 2b370f0 | 2012-09-06 16:06:01 -0400 | [diff] [blame] | 189 | break; |
| 190 | default: |
| 191 | Log.i(TAG, "Get new fragment " + position + " is null"); |
| 192 | return null; |
| 193 | } |
| 194 | |
| 195 | return fragment; |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 196 | } |
Alexandre Savard | 150352e | 2012-09-05 18:10:02 -0400 | [diff] [blame] | 197 | |
| 198 | @Override |
| 199 | public CharSequence getPageTitle(int position) |
| 200 | { |
| 201 | switch(position) { |
| 202 | case 0: |
| 203 | return getString(R.string.preference_section1).toUpperCase(); |
| 204 | case 1: |
| 205 | return getString(R.string.preference_section2).toUpperCase(); |
| 206 | default: |
| 207 | Log.e(TAG, "getPreferencePageTitle: unknown tab position " + position); |
| 208 | break; |
| 209 | } |
| 210 | return null; |
| 211 | } |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 212 | } |
| 213 | |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 214 | } |