blob: 3172a3460cb033a18a6d1afd30c1891a93e0d6f8 [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.Activity;
42import android.app.Fragment;
43import android.app.FragmentManager;
Alexandre Savard12dc3ac2012-09-27 11:17:39 -040044import android.content.ComponentName;
45import android.content.Context;
Alexandre Savard1bcaf532012-09-05 16:23:02 -040046import android.content.Intent;
Alexandre Savard12dc3ac2012-09-27 11:17:39 -040047import android.content.ServiceConnection;
Alexandre Savard1bcaf532012-09-05 16:23:02 -040048import android.os.Bundle;
Alexandre Savard12dc3ac2012-09-27 11:17:39 -040049import android.os.IBinder;
Alexandre Savard1bcaf532012-09-05 16:23:02 -040050import android.support.v13.app.FragmentStatePagerAdapter;
alisionf76de3b2013-04-16 15:35:22 -040051import android.support.v4.view.ViewPager;
52import android.util.Log;
alisioncc7bb422013-06-06 15:31:39 -040053import android.view.MenuItem;
Alexandre Savard1bcaf532012-09-05 16:23:02 -040054
Alexandre Lision3ccccf02013-10-07 14:10:46 -040055public class SFLPhonePreferenceActivity extends Activity implements AccountManagementFragment.Callbacks{
Alexandre Lisiond16bad92013-10-09 17:16:20 -040056
alisiond9e29442013-04-17 16:10:18 -040057 static final String TAG = SFLPhonePreferenceActivity.class.getSimpleName();
Alexandre Savard1bcaf532012-09-05 16:23:02 -040058 PreferencesPagerAdapter mPreferencesPagerAdapter;
Alexandre Savard12dc3ac2012-09-27 11:17:39 -040059 private boolean mBound = false;
Alexandre Savard12dc3ac2012-09-27 11:17:39 -040060 private ISipService service;
alisioncc7bb422013-06-06 15:31:39 -040061
Alexandre Savard1bcaf532012-09-05 16:23:02 -040062 ViewPager mViewPager;
63
Alexandre Savard12dc3ac2012-09-27 11:17:39 -040064 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;
alisioncc7bb422013-06-06 15:31:39 -040070 mPreferencesPagerAdapter = new PreferencesPagerAdapter(getFragmentManager());
71 mViewPager.setAdapter(mPreferencesPagerAdapter);
Alexandre Lision3ccccf02013-10-07 14:10:46 -040072 // 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 Savard12dc3ac2012-09-27 11:17:39 -040078 Log.d(TAG, "Service connected");
79 }
80
81 @Override
82 public void onServiceDisconnected(ComponentName arg0) {
83 mBound = false;
84 Log.d(TAG, "Service disconnected");
alisioncc7bb422013-06-06 15:31:39 -040085 }
Alexandre Savard12dc3ac2012-09-27 11:17:39 -040086 };
87
Alexandre Savard1bcaf532012-09-05 16:23:02 -040088 @Override
alisioncc7bb422013-06-06 15:31:39 -040089 public void onCreate(Bundle savedInstanceState) {
Alexandre Savard1bcaf532012-09-05 16:23:02 -040090 super.onCreate(savedInstanceState);
91
alisioncc7bb422013-06-06 15:31:39 -040092 Log.i(TAG, "onCreate SFLPhonePreferenceActivity");
Alexandre Savard1bcaf532012-09-05 16:23:02 -040093
94 setContentView(R.layout.activity_sflphone_preferences);
95
Alexandre Savard1bcaf532012-09-05 16:23:02 -040096 mViewPager = (ViewPager) findViewById(R.id.preferences_pager);
alisioncc7bb422013-06-06 15:31:39 -040097 mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
Alexandre Savard150352e2012-09-05 18:10:02 -040098 @Override
alisioncc7bb422013-06-06 15:31:39 -040099 public void onPageSelected(int position) {
100 getActionBar().setSelectedNavigationItem(position);
Alexandre Savard150352e2012-09-05 18:10:02 -0400101 }
102 });
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400103
alisioncc7bb422013-06-06 15:31:39 -0400104 getActionBar().setDisplayHomeAsUpEnabled(true);
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400105
alisioncc7bb422013-06-06 15:31:39 -0400106 if (!mBound) {
Emeric Vigier364499e2012-11-06 19:15:45 -0500107 Log.i(TAG, "onCreate: Binding service...");
Alexandre Savard12dc3ac2012-09-27 11:17:39 -0400108 Intent intent = new Intent(this, SipService.class);
109 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
110 }
111 }
112
113 @Override
alisioncc7bb422013-06-06 15:31:39 -0400114 public boolean onOptionsItemSelected(MenuItem item) {
115 switch (item.getItemId()) {
116 case android.R.id.home:
117 finish();
118 return true;
119 default:
Alexandre Lisiona764c682013-09-09 10:02:07 -0400120 return false;
alisioncc7bb422013-06-06 15:31:39 -0400121 }
122 }
123
124 @Override
Alexandre Savard833616f2012-10-30 16:02:30 -0400125 protected void onStart() {
126 Log.i(TAG, "onStart");
127 super.onStart();
128 }
129
130 @Override
Alexandre Savard12dc3ac2012-09-27 11:17:39 -0400131 protected void onStop() {
132 super.onStop();
Alexandre Savard12dc3ac2012-09-27 11:17:39 -0400133 }
134
135 @Override
136 protected void onDestroy() {
Alexandre Savard833616f2012-10-30 16:02:30 -0400137
alisioncc7bb422013-06-06 15:31:39 -0400138 if (mBound) {
Alexandre Savard833616f2012-10-30 16:02:30 -0400139 unbindService(mConnection);
140 mBound = false;
141 }
142
alisioncc7bb422013-06-06 15:31:39 -0400143 // stopService(new Intent(this, SipService.class));
144 // serviceIsOn = false;
Alexandre Savard12dc3ac2012-09-27 11:17:39 -0400145 super.onDestroy();
146 }
147
Alexandre Savard150352e2012-09-05 18:10:02 -0400148 public class PreferencesPagerAdapter extends FragmentStatePagerAdapter {
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400149
Alexandre Lisiond16bad92013-10-09 17:16:20 -0400150 static final int NUM_PAGES = 1;
151
alisioncc7bb422013-06-06 15:31:39 -0400152 public PreferencesPagerAdapter(FragmentManager fm) {
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400153 super(fm);
154 }
155
156 @Override
alisioncc7bb422013-06-06 15:31:39 -0400157 public int getCount() {
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400158 return NUM_PAGES;
159 }
160
161 @Override
alisioncc7bb422013-06-06 15:31:39 -0400162 public Fragment getItem(int position) {
Alexandre Savard2b370f02012-09-06 16:06:01 -0400163 Fragment fragment;
164
165 switch (position) {
166 case 0:
Emeric Vigier1f1ced32012-11-02 16:56:32 -0400167 fragment = new AccountManagementFragment();
Alexandre Savard2b370f02012-09-06 16:06:01 -0400168 break;
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400169 // case 1:
170 // fragment = new AudioManagementFragment();
171 // break;
Alexandre Savard2b370f02012-09-06 16:06:01 -0400172 default:
173 Log.i(TAG, "Get new fragment " + position + " is null");
174 return null;
175 }
176
177 return fragment;
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400178 }
Alexandre Savard150352e2012-09-05 18:10:02 -0400179
180 @Override
alisioncc7bb422013-06-06 15:31:39 -0400181 public CharSequence getPageTitle(int position) {
182 switch (position) {
Alexandre Savard150352e2012-09-05 18:10:02 -0400183 case 0:
Alexandre Lision6e8931e2013-09-19 16:49:34 -0400184 return getString(R.string.preference_section1).toUpperCase(Locale.getDefault());
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400185 // case 1:
186 // return getString(R.string.preference_section2).toUpperCase();
Alexandre Savard150352e2012-09-05 18:10:02 -0400187 default:
188 Log.e(TAG, "getPreferencePageTitle: unknown tab position " + position);
189 break;
190 }
191 return null;
192 }
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400193 }
194
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400195 @Override
196 public ISipService getService() {
197 return service;
198 }
199
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400200}