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 | |
| 54 | public class SFLPhonePreferenceActivity extends Activity implements ActionBar.TabListener { |
| 55 | static final int NUM_PAGES = 2; |
| 56 | static final String TAG = "SFLPhonePreferenceActivity"; |
| 57 | PreferencesPagerAdapter mPreferencesPagerAdapter; |
| 58 | ViewPager mViewPager; |
| 59 | |
| 60 | @Override |
| 61 | public void onCreate(Bundle savedInstanceState) |
| 62 | { |
| 63 | super.onCreate(savedInstanceState); |
| 64 | |
| 65 | Log.i(TAG,"onCreate SFLPhonePreferenceActivity"); |
| 66 | |
| 67 | setContentView(R.layout.activity_sflphone_preferences); |
| 68 | |
| 69 | mPreferencesPagerAdapter = new PreferencesPagerAdapter(getFragmentManager()); |
| 70 | |
| 71 | final ActionBar actionBar = getActionBar(); |
| 72 | actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); |
| 73 | |
| 74 | mViewPager = (ViewPager) findViewById(R.id.preferences_pager); |
| 75 | mViewPager.setAdapter(mPreferencesPagerAdapter); |
| 76 | |
| 77 | |
| 78 | for(int i = 0; i < mPreferencesPagerAdapter.getCount(); i++) { |
| 79 | actionBar.addTab(actionBar.newTab().setTabListener(this)); |
| 80 | } |
| 81 | |
| 82 | |
| 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public void onTabUnselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) |
| 87 | { |
| 88 | } |
| 89 | |
| 90 | @Override |
| 91 | public void onTabSelected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) |
| 92 | { |
| 93 | mViewPager.setCurrentItem(tab.getPosition()); |
| 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public void onTabReselected(ActionBar.Tab tab, FragmentTransaction fragmentTransaction) |
| 98 | { |
| 99 | } |
| 100 | |
| 101 | public static class PreferencesPagerAdapter extends FragmentStatePagerAdapter { |
| 102 | |
| 103 | public PreferencesPagerAdapter(FragmentManager fm) { |
| 104 | super(fm); |
| 105 | } |
| 106 | |
| 107 | @Override |
| 108 | public int getCount() { |
| 109 | return NUM_PAGES; |
| 110 | } |
| 111 | |
| 112 | @Override |
| 113 | public Fragment getItem(int position) { |
| 114 | return ArrayListFragment.newInstance(position); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | public static class ArrayListFragment extends ListFragment { |
| 119 | int mNum; |
| 120 | |
| 121 | static ArrayListFragment newInstance(int num) { |
| 122 | ArrayListFragment f = new ArrayListFragment(); |
| 123 | |
| 124 | // Supply num input as an argument. |
| 125 | Bundle args = new Bundle(); |
| 126 | args.putInt("num", num); |
| 127 | f.setArguments(args); |
| 128 | |
| 129 | return f; |
| 130 | } |
| 131 | |
| 132 | @Override |
| 133 | public void onCreate(Bundle savedInstanceState) { |
| 134 | super.onCreate(savedInstanceState); |
| 135 | mNum = getArguments() != null ? getArguments().getInt("num") : 1; |
| 136 | } |
| 137 | |
| 138 | @Override |
| 139 | public void onActivityCreated(Bundle savedInstanceState) { |
| 140 | super.onActivityCreated(savedInstanceState); |
| 141 | // setListAdapter(new ArrayAdapter<String>(getActivity(), |
| 142 | // android.R.layout.simple_list_item_1, Cheeses.sCheeseStrings)); |
| 143 | } |
| 144 | |
| 145 | } |
| 146 | } |