blob: 93ef560374dc0929798028cf780de2f1ee51e7e7 [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
34import java.util.List;
35
36import android.app.ActionBar;
37import android.app.Activity;
38import android.app.Fragment;
39import android.app.FragmentManager;
40import android.app.FragmentTransaction;
41import android.app.ListFragment;
42import android.content.Intent;
43import android.os.Bundle;
44import android.preference.PreferenceActivity;
45import android.util.Log;
46import android.support.v4.view.ViewPager;
47import android.support.v13.app.FragmentStatePagerAdapter;
48import android.view.View;
49import android.widget.Button;
50import android.widget.TextView;
51
52import com.savoirfairelinux.sflphone.R;
53
Alexandre Savard150352e2012-09-05 18:10:02 -040054public class SFLPhonePreferenceActivity extends Activity implements ActionBar.TabListener
55{
Alexandre Savard1bcaf532012-09-05 16:23:02 -040056 static final int NUM_PAGES = 2;
57 static final String TAG = "SFLPhonePreferenceActivity";
58 PreferencesPagerAdapter mPreferencesPagerAdapter;
59 ViewPager mViewPager;
60
61 @Override
62 public void onCreate(Bundle savedInstanceState)
63 {
64 super.onCreate(savedInstanceState);
65
66 Log.i(TAG,"onCreate SFLPhonePreferenceActivity");
67
68 setContentView(R.layout.activity_sflphone_preferences);
69
70 mPreferencesPagerAdapter = new PreferencesPagerAdapter(getFragmentManager());
71
72 final ActionBar actionBar = getActionBar();
73 actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
74
75 mViewPager = (ViewPager) findViewById(R.id.preferences_pager);
76 mViewPager.setAdapter(mPreferencesPagerAdapter);
77
Alexandre Savard150352e2012-09-05 18:10:02 -040078 mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener()
79 {
80 @Override
81 public void onPageSelected(int position)
82 {
83 actionBar.setSelectedNavigationItem(position);
84 }
85 });
Alexandre Savard1bcaf532012-09-05 16:23:02 -040086
87 for(int i = 0; i < mPreferencesPagerAdapter.getCount(); i++) {
Alexandre Savard150352e2012-09-05 18:10:02 -040088 actionBar.addTab(actionBar.newTab().setText(mPreferencesPagerAdapter.getPageTitle(i)).setTabListener(this));
Alexandre Savard1bcaf532012-09-05 16:23:02 -040089 }
90
91
92 }
93
94 @Override
95 public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
96 {
97 }
98
99 @Override
100 public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
101 {
102 mViewPager.setCurrentItem(tab.getPosition());
103 }
104
105 @Override
106 public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction)
107 {
108 }
109
Alexandre Savard150352e2012-09-05 18:10:02 -0400110 public class PreferencesPagerAdapter extends FragmentStatePagerAdapter {
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400111
Alexandre Savard150352e2012-09-05 18:10:02 -0400112 public PreferencesPagerAdapter(FragmentManager fm)
113 {
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400114 super(fm);
115 }
116
117 @Override
Alexandre Savard150352e2012-09-05 18:10:02 -0400118 public int getCount()
119 {
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400120 return NUM_PAGES;
121 }
122
123 @Override
Alexandre Savard150352e2012-09-05 18:10:02 -0400124 public Fragment getItem(int position)
125 {
Alexandre Savard2b370f02012-09-06 16:06:01 -0400126 Fragment fragment;
127
128 switch (position) {
129 case 0:
130 fragment = new AccountManagementFragment();
131 break;
132 case 1:
133 fragment = ArrayListFragment.newInstance(position);
134 break;
135 default:
136 Log.i(TAG, "Get new fragment " + position + " is null");
137 return null;
138 }
139
140 return fragment;
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400141 }
Alexandre Savard150352e2012-09-05 18:10:02 -0400142
143 @Override
144 public CharSequence getPageTitle(int position)
145 {
146 switch(position) {
147 case 0:
148 return getString(R.string.preference_section1).toUpperCase();
149 case 1:
150 return getString(R.string.preference_section2).toUpperCase();
151 default:
152 Log.e(TAG, "getPreferencePageTitle: unknown tab position " + position);
153 break;
154 }
155 return null;
156 }
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400157 }
158
159 public static class ArrayListFragment extends ListFragment {
160 int mNum;
161
162 static ArrayListFragment newInstance(int num) {
163 ArrayListFragment f = new ArrayListFragment();
164
165 // Supply num input as an argument.
166 Bundle args = new Bundle();
167 args.putInt("num", num);
168 f.setArguments(args);
169
170 return f;
171 }
172
173 @Override
174 public void onCreate(Bundle savedInstanceState) {
175 super.onCreate(savedInstanceState);
176 mNum = getArguments() != null ? getArguments().getInt("num") : 1;
177 }
178
179 @Override
180 public void onActivityCreated(Bundle savedInstanceState) {
181 super.onActivityCreated(savedInstanceState);
182 // setListAdapter(new ArrayAdapter<String>(getActivity(),
183 // android.R.layout.simple_list_item_1, Cheeses.sCheeseStrings));
184 }
185
186 }
187}