blob: 198754193cdfb77a8d95c2508afa4d6371f6bc43 [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
Alexandre Lision064e1e02013-10-01 16:18:42 -040032package org.sflphone.client;
alision5cfc35d2013-07-11 15:11:39 -040033
34import java.util.ArrayList;
Alexandre Lision6e8931e2013-09-19 16:49:34 -040035import java.util.Locale;
alision5cfc35d2013-07-11 15:11:39 -040036
Alexandre Lision064e1e02013-10-01 16:18:42 -040037import org.sflphone.R;
38import org.sflphone.fragments.AccountCreationFragment;
39import org.sflphone.interfaces.AccountsInterface;
40
alision5cfc35d2013-07-11 15:11:39 -040041import android.app.Activity;
42import android.app.Fragment;
43import android.app.FragmentManager;
alision5cfc35d2013-07-11 15:11:39 -040044import android.content.Context;
45import android.content.Intent;
alision5cfc35d2013-07-11 15:11:39 -040046import android.os.Bundle;
alision5cfc35d2013-07-11 15:11:39 -040047import android.support.v13.app.FragmentStatePagerAdapter;
48import android.support.v4.view.ViewPager;
49import android.util.Log;
50import android.view.MenuItem;
51
alision5cfc35d2013-07-11 15:11:39 -040052public 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;
alision5cfc35d2013-07-11 15:11:39 -0400106 ArrayList<Fragment> fragments;
107
108 public SectionsPagerAdapter(Context c, FragmentManager fm) {
109 super(fm);
110 mContext = c;
111 fragments = new ArrayList<Fragment>();
112 fragments.add(new AccountCreationFragment());
113
114 }
115
116 @Override
117 public Fragment getItem(int i) {
118
119 return fragments.get(i);
120 }
121
122 public String getClassName(int i) {
123 String name;
124
125 switch (i) {
126 case 0:
127 name = AccountCreationFragment.class.getName();
128 break;
129
130 default:
131 Log.e(TAG, "getClassName: unknown fragment position " + i);
132 return null;
133 }
134
135 // Log.w(TAG, "getClassName: name=" + name);
136 return name;
137 }
138
139 @Override
140 public int getCount() {
141 return 1;
142 }
143
alision5cfc35d2013-07-11 15:11:39 -0400144 @Override
145 public CharSequence getPageTitle(int position) {
146 switch (position) {
147 case 0:
Alexandre Lision6e8931e2013-09-19 16:49:34 -0400148 return mContext.getString(R.string.title_section0).toUpperCase(Locale.getDefault());
alision5cfc35d2013-07-11 15:11:39 -0400149 default:
150 Log.e(TAG, "getPageTitle: unknown tab position " + position);
151 break;
152 }
153 return null;
154 }
155 }
156
157}