blob: 11c46d6bccd14b34ee92f86bdddf28a566180727 [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 Savard1bcaf532012-09-05 16:23:02 -0400126 return ArrayListFragment.newInstance(position);
127 }
Alexandre Savard150352e2012-09-05 18:10:02 -0400128
129 @Override
130 public CharSequence getPageTitle(int position)
131 {
132 switch(position) {
133 case 0:
134 return getString(R.string.preference_section1).toUpperCase();
135 case 1:
136 return getString(R.string.preference_section2).toUpperCase();
137 default:
138 Log.e(TAG, "getPreferencePageTitle: unknown tab position " + position);
139 break;
140 }
141 return null;
142 }
Alexandre Savard1bcaf532012-09-05 16:23:02 -0400143 }
144
145 public static class ArrayListFragment extends ListFragment {
146 int mNum;
147
148 static ArrayListFragment newInstance(int num) {
149 ArrayListFragment f = new ArrayListFragment();
150
151 // Supply num input as an argument.
152 Bundle args = new Bundle();
153 args.putInt("num", num);
154 f.setArguments(args);
155
156 return f;
157 }
158
159 @Override
160 public void onCreate(Bundle savedInstanceState) {
161 super.onCreate(savedInstanceState);
162 mNum = getArguments() != null ? getArguments().getInt("num") : 1;
163 }
164
165 @Override
166 public void onActivityCreated(Bundle savedInstanceState) {
167 super.onActivityCreated(savedInstanceState);
168 // setListAdapter(new ArrayAdapter<String>(getActivity(),
169 // android.R.layout.simple_list_item_1, Cheeses.sCheeseStrings));
170 }
171
172 }
173}