blob: 00d302350fda9e0e369143eda2cc94abfca44302 [file] [log] [blame]
Alexandre Savard1bcaf532012-09-05 16:23:02 -04001/*
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
32package com.savoirfairelinux.sflphone.client;
33
Alexandre Savard1bcaf532012-09-05 16:23:02 -040034import android.app.ActionBar;
35import android.app.Activity;
36import android.app.Fragment;
37import android.app.FragmentManager;
38import android.app.FragmentTransaction;
39import android.app.ListFragment;
Alexandre Savard12dc3ac2012-09-27 11:17:39 -040040import android.content.ComponentName;
41import android.content.Context;
Alexandre Savard1bcaf532012-09-05 16:23:02 -040042import android.content.Intent;
Alexandre Savard12dc3ac2012-09-27 11:17:39 -040043import android.content.ServiceConnection;
Alexandre Savard1bcaf532012-09-05 16:23:02 -040044import android.os.Bundle;
Alexandre Savard12dc3ac2012-09-27 11:17:39 -040045import android.os.IBinder;
Alexandre Savard1bcaf532012-09-05 16:23:02 -040046import android.support.v13.app.FragmentStatePagerAdapter;
alisionf76de3b2013-04-16 15:35:22 -040047import android.support.v4.view.ViewPager;
48import android.util.Log;
Alexandre Savard1bcaf532012-09-05 16:23:02 -040049
50import com.savoirfairelinux.sflphone.R;
alisionf76de3b2013-04-16 15:35:22 -040051import com.savoirfairelinux.sflphone.fragments.AccountManagementFragment;
alisiond9e29442013-04-17 16:10:18 -040052import com.savoirfairelinux.sflphone.fragments.AudioManagementFragment;
Alexandre Savard12dc3ac2012-09-27 11:17:39 -040053import com.savoirfairelinux.sflphone.service.ISipService;
alisionf76de3b2013-04-16 15:35:22 -040054import com.savoirfairelinux.sflphone.service.SipService;
Alexandre Savard1bcaf532012-09-05 16:23:02 -040055
Alexandre Savard150352e2012-09-05 18:10:02 -040056public class SFLPhonePreferenceActivity extends Activity implements ActionBar.TabListener
57{
Alexandre Savard1bcaf532012-09-05 16:23:02 -040058 static final int NUM_PAGES = 2;
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;
64
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;
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 Savard1bcaf532012-09-05 16:23:02 -040083 @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 Savard150352e2012-09-05 18:10:02 -0400100 mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener()
101 {
102 @Override
103 public void onPageSelected(int position)
104 {
105 actionBar.setSelectedNavigationItem(position);
106 }
107 });
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400108
109 for(int i = 0; i < mPreferencesPagerAdapter.getCount(); i++) {
Alexandre Savard150352e2012-09-05 18:10:02 -0400110 actionBar.addTab(actionBar.newTab().setText(mPreferencesPagerAdapter.getPageTitle(i)).setTabListener(this));
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400111 }
112
Alexandre Savard12dc3ac2012-09-27 11:17:39 -0400113 if(!mBound) {
Emeric Vigier364499e2012-11-06 19:15:45 -0500114 Log.i(TAG, "onCreate: Binding service...");
Alexandre Savard12dc3ac2012-09-27 11:17:39 -0400115 Intent intent = new Intent(this, SipService.class);
116 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
117 }
118 }
119
120 @Override
Alexandre Savard833616f2012-10-30 16:02:30 -0400121 protected void onStart() {
122 Log.i(TAG, "onStart");
123 super.onStart();
124 }
125
126 @Override
Alexandre Savard12dc3ac2012-09-27 11:17:39 -0400127 protected void onStop() {
128 super.onStop();
Alexandre Savard12dc3ac2012-09-27 11:17:39 -0400129 }
130
131 @Override
132 protected void onDestroy() {
133 Log.i(TAG, "onDestroy: stopping SipService...");
Alexandre Savard833616f2012-10-30 16:02:30 -0400134
135 if(mBound) {
136 unbindService(mConnection);
137 mBound = false;
138 }
139
Emeric Vigier0038a612012-11-06 18:51:19 -0500140// stopService(new Intent(this, SipService.class));
141// serviceIsOn = false;
Alexandre Savard12dc3ac2012-09-27 11:17:39 -0400142 super.onDestroy();
143 }
144
Emeric Vigier1f1ced32012-11-02 16:56:32 -0400145 public ISipService getSipService() {
146 return service;
147 }
148
Alexandre Savard12dc3ac2012-09-27 11:17:39 -0400149 @Override
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400150 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 Savard150352e2012-09-05 18:10:02 -0400165 public class PreferencesPagerAdapter extends FragmentStatePagerAdapter {
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400166
Alexandre Savard150352e2012-09-05 18:10:02 -0400167 public PreferencesPagerAdapter(FragmentManager fm)
168 {
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400169 super(fm);
170 }
171
172 @Override
Alexandre Savard150352e2012-09-05 18:10:02 -0400173 public int getCount()
174 {
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400175 return NUM_PAGES;
176 }
177
178 @Override
Alexandre Savard150352e2012-09-05 18:10:02 -0400179 public Fragment getItem(int position)
180 {
Alexandre Savard2b370f02012-09-06 16:06:01 -0400181 Fragment fragment;
182
183 switch (position) {
184 case 0:
Emeric Vigier1f1ced32012-11-02 16:56:32 -0400185 fragment = new AccountManagementFragment();
Alexandre Savard2b370f02012-09-06 16:06:01 -0400186 break;
187 case 1:
alisiond9e29442013-04-17 16:10:18 -0400188 fragment = new AudioManagementFragment();
Alexandre Savard2b370f02012-09-06 16:06:01 -0400189 break;
190 default:
191 Log.i(TAG, "Get new fragment " + position + " is null");
192 return null;
193 }
194
195 return fragment;
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400196 }
Alexandre Savard150352e2012-09-05 18:10:02 -0400197
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 Savard1bcaf532012-09-05 16:23:02 -0400212 }
213
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400214}