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