blob: 6218ab98ec10e666f844da79db8bfda18cb23e07 [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;
35
36import android.app.Activity;
37import android.app.Fragment;
38import android.app.FragmentManager;
39import android.content.ComponentName;
40import android.content.Context;
41import android.content.Intent;
42import android.content.ServiceConnection;
43import android.os.Bundle;
44import android.os.IBinder;
45import android.support.v13.app.FragmentStatePagerAdapter;
46import android.support.v4.view.ViewPager;
47import android.util.Log;
48import android.view.MenuItem;
49
50import com.savoirfairelinux.sflphone.R;
51import com.savoirfairelinux.sflphone.fragments.AccountCreationFragment;
52import com.savoirfairelinux.sflphone.interfaces.AccountsInterface;
53import com.savoirfairelinux.sflphone.service.ISipService;
54import com.savoirfairelinux.sflphone.service.SipService;
55
56public class AccountWizard extends Activity implements AccountsInterface {
57 static final String TAG = "AccountWizard";
58
59 public static final int ACCOUNT_CREATED = Activity.RESULT_OK;
60
61 ViewPager mViewPager;
62 private ISipService service;
63 private SectionsPagerAdapter mSectionsPagerAdapter;
64
65 @Override
66 public void onCreate(Bundle savedInstanceState) {
67 super.onCreate(savedInstanceState);
68
69 setContentView(R.layout.activity_wizard);
70 mViewPager = (ViewPager) findViewById(R.id.pager);
71
72 getActionBar().setDisplayHomeAsUpEnabled(true);
73 getActionBar().setHomeButtonEnabled(true);
74
75 Intent intent = new Intent(this, SipService.class);
76 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
77
78 }
79
80 /* activity finishes itself or is being killed by the system */
81 @Override
82 protected void onDestroy() {
83 /* stop the service, if no other bound user, no need to check if it is running */
84
85 unbindService(mConnection);
86
87 super.onDestroy();
88 }
89
90 /** Defines callbacks for service binding, passed to bindService() */
91 private ServiceConnection mConnection = new ServiceConnection() {
92
93 @Override
94 public void onServiceConnected(ComponentName className, IBinder binder) {
95 service = ISipService.Stub.asInterface(binder);
96
97 mSectionsPagerAdapter = new SectionsPagerAdapter(AccountWizard.this, getFragmentManager());
98 mViewPager.setAdapter(mSectionsPagerAdapter);
99
100 }
101
102 @Override
103 public void onServiceDisconnected(ComponentName arg0) {
104
105 }
106 };
107
108 @Override
109 public boolean onOptionsItemSelected(MenuItem item) {
110 switch (item.getItemId()) {
111 case android.R.id.home:
112 finish();
113 return true;
114 default:
115 return true;
116 }
117 }
118
119 @Override
120 public void accountsChanged() {
121 // TODO Auto-generated method stub
122
123 }
124
125 @Override
126 public void accountStateChanged(Intent accountState) {
127 // TODO Auto-generated method stub
128
129 }
130
131 public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
132
133 Context mContext;
134 final private int[] icon_res_id = { R.drawable.ic_tab_call, R.drawable.ic_tab_call, R.drawable.ic_tab_history };
135 ArrayList<Fragment> fragments;
136
137 public SectionsPagerAdapter(Context c, FragmentManager fm) {
138 super(fm);
139 mContext = c;
140 fragments = new ArrayList<Fragment>();
141 fragments.add(new AccountCreationFragment());
142
143 }
144
145 @Override
146 public Fragment getItem(int i) {
147
148 return fragments.get(i);
149 }
150
151 public String getClassName(int i) {
152 String name;
153
154 switch (i) {
155 case 0:
156 name = AccountCreationFragment.class.getName();
157 break;
158
159 default:
160 Log.e(TAG, "getClassName: unknown fragment position " + i);
161 return null;
162 }
163
164 // Log.w(TAG, "getClassName: name=" + name);
165 return name;
166 }
167
168 @Override
169 public int getCount() {
170 return 1;
171 }
172
173 public int getIconOf(int pos) {
174 return icon_res_id[pos];
175 }
176
177 @Override
178 public CharSequence getPageTitle(int position) {
179 switch (position) {
180 case 0:
181 return mContext.getString(R.string.title_section0).toUpperCase();
182 default:
183 Log.e(TAG, "getPageTitle: unknown tab position " + position);
184 break;
185 }
186 return null;
187 }
188 }
189
190}