blob: 129a6bf9519d3a58fd35cf30ff797e775878db8e [file] [log] [blame]
alision5cfc35d2013-07-11 15:11:39 -04001/*
2 * Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
3 *
4 * Author: Alexandre Lision <alexandre.lision@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.ArrayList;
Alexandre Lision6e8931e2013-09-19 16:49:34 -040035import java.util.Locale;
alision5cfc35d2013-07-11 15:11:39 -040036
37import android.app.Activity;
38import android.app.Fragment;
39import android.app.FragmentManager;
alision5cfc35d2013-07-11 15:11:39 -040040import android.content.Context;
41import android.content.Intent;
alision5cfc35d2013-07-11 15:11:39 -040042import android.os.Bundle;
alision5cfc35d2013-07-11 15:11:39 -040043import android.support.v13.app.FragmentStatePagerAdapter;
44import android.support.v4.view.ViewPager;
45import android.util.Log;
46import android.view.MenuItem;
47
48import com.savoirfairelinux.sflphone.R;
49import com.savoirfairelinux.sflphone.fragments.AccountCreationFragment;
50import com.savoirfairelinux.sflphone.interfaces.AccountsInterface;
alision5cfc35d2013-07-11 15:11:39 -040051
52public class AccountWizard extends Activity implements AccountsInterface {
53 static final String TAG = "AccountWizard";
54
55 public static final int ACCOUNT_CREATED = Activity.RESULT_OK;
56
57 ViewPager mViewPager;
alision5cfc35d2013-07-11 15:11:39 -040058 private SectionsPagerAdapter mSectionsPagerAdapter;
59
60 @Override
61 public void onCreate(Bundle savedInstanceState) {
62 super.onCreate(savedInstanceState);
63
64 setContentView(R.layout.activity_wizard);
65 mViewPager = (ViewPager) findViewById(R.id.pager);
66
67 getActionBar().setDisplayHomeAsUpEnabled(true);
68 getActionBar().setHomeButtonEnabled(true);
Alexandre Lision6e8931e2013-09-19 16:49:34 -040069 mSectionsPagerAdapter = new SectionsPagerAdapter(AccountWizard.this, getFragmentManager());
70 mViewPager.setAdapter(mSectionsPagerAdapter);
alision5cfc35d2013-07-11 15:11:39 -040071
72 }
73
74 /* activity finishes itself or is being killed by the system */
75 @Override
76 protected void onDestroy() {
alision5cfc35d2013-07-11 15:11:39 -040077 super.onDestroy();
78 }
79
alision5cfc35d2013-07-11 15:11:39 -040080 @Override
81 public boolean onOptionsItemSelected(MenuItem item) {
82 switch (item.getItemId()) {
83 case android.R.id.home:
84 finish();
85 return true;
86 default:
87 return true;
88 }
89 }
90
91 @Override
92 public void accountsChanged() {
93 // TODO Auto-generated method stub
94
95 }
96
97 @Override
98 public void accountStateChanged(Intent accountState) {
99 // TODO Auto-generated method stub
100
101 }
102
103 public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
104
105 Context mContext;
106 final private int[] icon_res_id = { R.drawable.ic_tab_call, R.drawable.ic_tab_call, R.drawable.ic_tab_history };
107 ArrayList<Fragment> fragments;
108
109 public SectionsPagerAdapter(Context c, FragmentManager fm) {
110 super(fm);
111 mContext = c;
112 fragments = new ArrayList<Fragment>();
113 fragments.add(new AccountCreationFragment());
114
115 }
116
117 @Override
118 public Fragment getItem(int i) {
119
120 return fragments.get(i);
121 }
122
123 public String getClassName(int i) {
124 String name;
125
126 switch (i) {
127 case 0:
128 name = AccountCreationFragment.class.getName();
129 break;
130
131 default:
132 Log.e(TAG, "getClassName: unknown fragment position " + i);
133 return null;
134 }
135
136 // Log.w(TAG, "getClassName: name=" + name);
137 return name;
138 }
139
140 @Override
141 public int getCount() {
142 return 1;
143 }
144
145 public int getIconOf(int pos) {
146 return icon_res_id[pos];
147 }
148
149 @Override
150 public CharSequence getPageTitle(int position) {
151 switch (position) {
152 case 0:
Alexandre Lision6e8931e2013-09-19 16:49:34 -0400153 return mContext.getString(R.string.title_section0).toUpperCase(Locale.getDefault());
alision5cfc35d2013-07-11 15:11:39 -0400154 default:
155 Log.e(TAG, "getPageTitle: unknown tab position " + position);
156 break;
157 }
158 return null;
159 }
160 }
161
162}