blob: 549873e2c59d8b620b5e650bc5fedf848267f0f9 [file] [log] [blame]
Alexandre Savard1bcaf532012-09-05 16:23:02 -04001/*
alision5de91782013-07-10 10:47:30 -04002 * Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
Alexandre Savard1bcaf532012-09-05 16:23:02 -04003 *
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 Lision064e1e02013-10-01 16:18:42 -040032package org.sflphone.client;
Alexandre Savard1bcaf532012-09-05 16:23:02 -040033
Alexandre Lision6e8931e2013-09-19 16:49:34 -040034import java.util.Locale;
35
Alexandre Lision064e1e02013-10-01 16:18:42 -040036import org.sflphone.R;
37import org.sflphone.fragments.AccountManagementFragment;
38import org.sflphone.service.ISipService;
39import org.sflphone.service.SipService;
40
Alexandre Savard1bcaf532012-09-05 16:23:02 -040041import android.app.ActionBar;
42import android.app.Activity;
43import android.app.Fragment;
44import android.app.FragmentManager;
45import android.app.FragmentTransaction;
Alexandre Savard12dc3ac2012-09-27 11:17:39 -040046import android.content.ComponentName;
47import android.content.Context;
Alexandre Savard1bcaf532012-09-05 16:23:02 -040048import android.content.Intent;
Alexandre Savard12dc3ac2012-09-27 11:17:39 -040049import android.content.ServiceConnection;
Alexandre Savard1bcaf532012-09-05 16:23:02 -040050import android.os.Bundle;
Alexandre Savard12dc3ac2012-09-27 11:17:39 -040051import android.os.IBinder;
Alexandre Savard1bcaf532012-09-05 16:23:02 -040052import android.support.v13.app.FragmentStatePagerAdapter;
alisionf76de3b2013-04-16 15:35:22 -040053import android.support.v4.view.ViewPager;
54import android.util.Log;
alisioncc7bb422013-06-06 15:31:39 -040055import android.view.MenuItem;
Alexandre Savard1bcaf532012-09-05 16:23:02 -040056
Alexandre Lision3ccccf02013-10-07 14:10:46 -040057public class SFLPhonePreferenceActivity extends Activity implements AccountManagementFragment.Callbacks{
Alexandre Lisioncdec5952013-07-17 14:18:22 -040058 static final int NUM_PAGES = 1;
alisiond9e29442013-04-17 16:10:18 -040059 static final String TAG = SFLPhonePreferenceActivity.class.getSimpleName();
Alexandre Savard1bcaf532012-09-05 16:23:02 -040060 PreferencesPagerAdapter mPreferencesPagerAdapter;
Alexandre Savard12dc3ac2012-09-27 11:17:39 -040061 private boolean mBound = false;
62 static boolean serviceIsOn = false;
63 private ISipService service;
alisioncc7bb422013-06-06 15:31:39 -040064
Alexandre Savard1bcaf532012-09-05 16:23:02 -040065 ViewPager mViewPager;
66
Alexandre Savard12dc3ac2012-09-27 11:17:39 -040067 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;
alisioncc7bb422013-06-06 15:31:39 -040073 mPreferencesPagerAdapter = new PreferencesPagerAdapter(getFragmentManager());
74 mViewPager.setAdapter(mPreferencesPagerAdapter);
Alexandre Lision3ccccf02013-10-07 14:10:46 -040075 // getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
76 // for (int i = 0; i < mPreferencesPagerAdapter.getCount(); i++) {
77 // getActionBar().addTab(
78 // getActionBar().newTab().setText(mPreferencesPagerAdapter.getPageTitle(i)).setTabListener(SFLPhonePreferenceActivity.this));
79 //
80 // }
Alexandre Savard12dc3ac2012-09-27 11:17:39 -040081 Log.d(TAG, "Service connected");
82 }
83
84 @Override
85 public void onServiceDisconnected(ComponentName arg0) {
86 mBound = false;
87 Log.d(TAG, "Service disconnected");
alisioncc7bb422013-06-06 15:31:39 -040088 }
Alexandre Savard12dc3ac2012-09-27 11:17:39 -040089 };
90
Alexandre Savard1bcaf532012-09-05 16:23:02 -040091 @Override
alisioncc7bb422013-06-06 15:31:39 -040092 public void onCreate(Bundle savedInstanceState) {
Alexandre Savard1bcaf532012-09-05 16:23:02 -040093 super.onCreate(savedInstanceState);
94
alisioncc7bb422013-06-06 15:31:39 -040095 Log.i(TAG, "onCreate SFLPhonePreferenceActivity");
Alexandre Savard1bcaf532012-09-05 16:23:02 -040096
97 setContentView(R.layout.activity_sflphone_preferences);
98
Alexandre Savard1bcaf532012-09-05 16:23:02 -040099 mViewPager = (ViewPager) findViewById(R.id.preferences_pager);
alisioncc7bb422013-06-06 15:31:39 -0400100 mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
Alexandre Savard150352e2012-09-05 18:10:02 -0400101 @Override
alisioncc7bb422013-06-06 15:31:39 -0400102 public void onPageSelected(int position) {
103 getActionBar().setSelectedNavigationItem(position);
Alexandre Savard150352e2012-09-05 18:10:02 -0400104 }
105 });
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400106
alisioncc7bb422013-06-06 15:31:39 -0400107 getActionBar().setDisplayHomeAsUpEnabled(true);
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400108
alisioncc7bb422013-06-06 15:31:39 -0400109 if (!mBound) {
Emeric Vigier364499e2012-11-06 19:15:45 -0500110 Log.i(TAG, "onCreate: Binding service...");
Alexandre Savard12dc3ac2012-09-27 11:17:39 -0400111 Intent intent = new Intent(this, SipService.class);
112 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
113 }
114 }
115
116 @Override
alisioncc7bb422013-06-06 15:31:39 -0400117 public boolean onOptionsItemSelected(MenuItem item) {
118 switch (item.getItemId()) {
119 case android.R.id.home:
120 finish();
121 return true;
122 default:
Alexandre Lisiona764c682013-09-09 10:02:07 -0400123 return false;
alisioncc7bb422013-06-06 15:31:39 -0400124 }
125 }
126
127 @Override
Alexandre Savard833616f2012-10-30 16:02:30 -0400128 protected void onStart() {
129 Log.i(TAG, "onStart");
130 super.onStart();
131 }
132
133 @Override
Alexandre Savard12dc3ac2012-09-27 11:17:39 -0400134 protected void onStop() {
135 super.onStop();
Alexandre Savard12dc3ac2012-09-27 11:17:39 -0400136 }
137
138 @Override
139 protected void onDestroy() {
Alexandre Savard833616f2012-10-30 16:02:30 -0400140
alisioncc7bb422013-06-06 15:31:39 -0400141 if (mBound) {
Alexandre Savard833616f2012-10-30 16:02:30 -0400142 unbindService(mConnection);
143 mBound = false;
144 }
145
alisioncc7bb422013-06-06 15:31:39 -0400146 // stopService(new Intent(this, SipService.class));
147 // serviceIsOn = false;
Alexandre Savard12dc3ac2012-09-27 11:17:39 -0400148 super.onDestroy();
149 }
150
Alexandre Savard150352e2012-09-05 18:10:02 -0400151 public class PreferencesPagerAdapter extends FragmentStatePagerAdapter {
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400152
alisioncc7bb422013-06-06 15:31:39 -0400153 public PreferencesPagerAdapter(FragmentManager fm) {
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400154 super(fm);
155 }
156
157 @Override
alisioncc7bb422013-06-06 15:31:39 -0400158 public int getCount() {
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400159 return NUM_PAGES;
160 }
161
162 @Override
alisioncc7bb422013-06-06 15:31:39 -0400163 public Fragment getItem(int position) {
Alexandre Savard2b370f02012-09-06 16:06:01 -0400164 Fragment fragment;
165
166 switch (position) {
167 case 0:
Emeric Vigier1f1ced32012-11-02 16:56:32 -0400168 fragment = new AccountManagementFragment();
Alexandre Savard2b370f02012-09-06 16:06:01 -0400169 break;
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400170 // case 1:
171 // fragment = new AudioManagementFragment();
172 // break;
Alexandre Savard2b370f02012-09-06 16:06:01 -0400173 default:
174 Log.i(TAG, "Get new fragment " + position + " is null");
175 return null;
176 }
177
178 return fragment;
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400179 }
Alexandre Savard150352e2012-09-05 18:10:02 -0400180
181 @Override
alisioncc7bb422013-06-06 15:31:39 -0400182 public CharSequence getPageTitle(int position) {
183 switch (position) {
Alexandre Savard150352e2012-09-05 18:10:02 -0400184 case 0:
Alexandre Lision6e8931e2013-09-19 16:49:34 -0400185 return getString(R.string.preference_section1).toUpperCase(Locale.getDefault());
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400186 // case 1:
187 // return getString(R.string.preference_section2).toUpperCase();
Alexandre Savard150352e2012-09-05 18:10:02 -0400188 default:
189 Log.e(TAG, "getPreferencePageTitle: unknown tab position " + position);
190 break;
191 }
192 return null;
193 }
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400194 }
195
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400196 @Override
197 public ISipService getService() {
198 return service;
199 }
200
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400201}