Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 1 | /* |
| 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 | |
| 32 | package com.savoirfairelinux.sflphone.client; |
| 33 | |
| 34 | import java.util.List; |
| 35 | |
| 36 | import android.app.ActionBar; |
| 37 | import android.app.Activity; |
| 38 | import android.app.Fragment; |
| 39 | import android.app.FragmentManager; |
| 40 | import android.app.FragmentTransaction; |
| 41 | import android.app.ListFragment; |
| 42 | import android.content.Intent; |
| 43 | import android.os.Bundle; |
| 44 | import android.preference.PreferenceActivity; |
| 45 | import android.util.Log; |
| 46 | import android.support.v4.view.ViewPager; |
| 47 | import android.support.v13.app.FragmentStatePagerAdapter; |
| 48 | import android.view.View; |
| 49 | import android.widget.Button; |
| 50 | import android.widget.TextView; |
| 51 | |
| 52 | import com.savoirfairelinux.sflphone.R; |
| 53 | |
Alexandre Savard | 150352e | 2012-09-05 18:10:02 -0400 | [diff] [blame] | 54 | public class SFLPhonePreferenceActivity extends Activity implements ActionBar.TabListener |
| 55 | { |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 56 | 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 Savard | 150352e | 2012-09-05 18:10:02 -0400 | [diff] [blame] | 78 | mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() |
| 79 | { |
| 80 | @Override |
| 81 | public void onPageSelected(int position) |
| 82 | { |
| 83 | actionBar.setSelectedNavigationItem(position); |
| 84 | } |
| 85 | }); |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 86 | |
| 87 | for(int i = 0; i < mPreferencesPagerAdapter.getCount(); i++) { |
Alexandre Savard | 150352e | 2012-09-05 18:10:02 -0400 | [diff] [blame] | 88 | actionBar.addTab(actionBar.newTab().setText(mPreferencesPagerAdapter.getPageTitle(i)).setTabListener(this)); |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 89 | } |
| 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 Savard | 150352e | 2012-09-05 18:10:02 -0400 | [diff] [blame] | 110 | public class PreferencesPagerAdapter extends FragmentStatePagerAdapter { |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 111 | |
Alexandre Savard | 150352e | 2012-09-05 18:10:02 -0400 | [diff] [blame] | 112 | public PreferencesPagerAdapter(FragmentManager fm) |
| 113 | { |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 114 | super(fm); |
| 115 | } |
| 116 | |
| 117 | @Override |
Alexandre Savard | 150352e | 2012-09-05 18:10:02 -0400 | [diff] [blame] | 118 | public int getCount() |
| 119 | { |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 120 | return NUM_PAGES; |
| 121 | } |
| 122 | |
| 123 | @Override |
Alexandre Savard | 150352e | 2012-09-05 18:10:02 -0400 | [diff] [blame] | 124 | public Fragment getItem(int position) |
| 125 | { |
Alexandre Savard | 2b370f0 | 2012-09-06 16:06:01 -0400 | [diff] [blame] | 126 | Fragment fragment; |
| 127 | |
| 128 | switch (position) { |
| 129 | case 0: |
| 130 | fragment = new AccountManagementFragment(); |
| 131 | break; |
| 132 | case 1: |
Alexandre Savard | dcd3740 | 2012-09-06 18:36:48 -0400 | [diff] [blame] | 133 | fragment = new PrefManagementFragment(); |
Alexandre Savard | 2b370f0 | 2012-09-06 16:06:01 -0400 | [diff] [blame] | 134 | break; |
| 135 | default: |
| 136 | Log.i(TAG, "Get new fragment " + position + " is null"); |
| 137 | return null; |
| 138 | } |
| 139 | |
| 140 | return fragment; |
Alexandre Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 141 | } |
Alexandre Savard | 150352e | 2012-09-05 18:10:02 -0400 | [diff] [blame] | 142 | |
| 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 Savard | 1bcaf53 | 2012-09-05 16:23:02 -0400 | [diff] [blame] | 157 | } |
| 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 | } |