blob: fbb5780463e8a2fbd8d2c2a8b0708a554eaecbde [file] [log] [blame]
alision5cfc35d2013-07-11 15:11:39 -04001/*
Alexandre Lisionc1024c02014-01-06 11:12:53 -05002 * Copyright (C) 2004-2014 Savoir-Faire Linux Inc.
alision5cfc35d2013-07-11 15:11:39 -04003 *
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;
Alexandre Lisiond16bad92013-10-09 17:16:20 -040039import org.sflphone.fragments.AccountCreationFragment.Callbacks;
Alexandre Lision064e1e02013-10-01 16:18:42 -040040import org.sflphone.interfaces.AccountsInterface;
Alexandre Lisiond16bad92013-10-09 17:16:20 -040041import org.sflphone.service.ISipService;
42import org.sflphone.service.SipService;
Alexandre Lision064e1e02013-10-01 16:18:42 -040043
alision5cfc35d2013-07-11 15:11:39 -040044import android.app.Activity;
45import android.app.Fragment;
46import android.app.FragmentManager;
Alexandre Lisiond16bad92013-10-09 17:16:20 -040047import android.content.ComponentName;
alision5cfc35d2013-07-11 15:11:39 -040048import android.content.Context;
49import android.content.Intent;
Alexandre Lisiond16bad92013-10-09 17:16:20 -040050import android.content.ServiceConnection;
alision5cfc35d2013-07-11 15:11:39 -040051import android.os.Bundle;
Alexandre Lisiond16bad92013-10-09 17:16:20 -040052import android.os.IBinder;
alision5cfc35d2013-07-11 15:11:39 -040053import android.support.v13.app.FragmentStatePagerAdapter;
54import android.support.v4.view.ViewPager;
55import android.util.Log;
56import android.view.MenuItem;
57
Alexandre Lisiond16bad92013-10-09 17:16:20 -040058public class AccountWizard extends Activity implements AccountsInterface, Callbacks {
alision5cfc35d2013-07-11 15:11:39 -040059 static final String TAG = "AccountWizard";
Alexandre Lisiond16bad92013-10-09 17:16:20 -040060 private boolean mBound = false;
alision5cfc35d2013-07-11 15:11:39 -040061 public static final int ACCOUNT_CREATED = Activity.RESULT_OK;
Alexandre Lisiond16bad92013-10-09 17:16:20 -040062 private ISipService service;
alision5cfc35d2013-07-11 15:11:39 -040063 ViewPager mViewPager;
alision5cfc35d2013-07-11 15:11:39 -040064 private SectionsPagerAdapter mSectionsPagerAdapter;
65
Alexandre Lisiond16bad92013-10-09 17:16:20 -040066 private ServiceConnection mConnection = new ServiceConnection() {
67
68 @Override
69 public void onServiceConnected(ComponentName className, IBinder binder) {
70 service = ISipService.Stub.asInterface(binder);
71 mBound = true;
72 }
73
74 @Override
75 public void onServiceDisconnected(ComponentName arg0) {
76
77 }
78 };
79
alision5cfc35d2013-07-11 15:11:39 -040080 @Override
81 public void onCreate(Bundle savedInstanceState) {
82 super.onCreate(savedInstanceState);
83
84 setContentView(R.layout.activity_wizard);
85 mViewPager = (ViewPager) findViewById(R.id.pager);
86
87 getActionBar().setDisplayHomeAsUpEnabled(true);
88 getActionBar().setHomeButtonEnabled(true);
Alexandre Lision6e8931e2013-09-19 16:49:34 -040089 mSectionsPagerAdapter = new SectionsPagerAdapter(AccountWizard.this, getFragmentManager());
90 mViewPager.setAdapter(mSectionsPagerAdapter);
alision5cfc35d2013-07-11 15:11:39 -040091
Alexandre Lisiond16bad92013-10-09 17:16:20 -040092 if (!mBound) {
93 Log.i(TAG, "onCreate: Binding service...");
94 Intent intent = new Intent(this, SipService.class);
95 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
96 }
97
alision5cfc35d2013-07-11 15:11:39 -040098 }
99
100 /* activity finishes itself or is being killed by the system */
101 @Override
102 protected void onDestroy() {
alision5cfc35d2013-07-11 15:11:39 -0400103 super.onDestroy();
Alexandre Lisiond16bad92013-10-09 17:16:20 -0400104 if (mBound) {
105 unbindService(mConnection);
106 mBound = false;
107 }
alision5cfc35d2013-07-11 15:11:39 -0400108 }
109
alision5cfc35d2013-07-11 15:11:39 -0400110 @Override
111 public boolean onOptionsItemSelected(MenuItem item) {
112 switch (item.getItemId()) {
113 case android.R.id.home:
114 finish();
115 return true;
116 default:
117 return true;
118 }
119 }
120
121 @Override
122 public void accountsChanged() {
123 // TODO Auto-generated method stub
124
125 }
126
127 @Override
128 public void accountStateChanged(Intent accountState) {
129 // TODO Auto-generated method stub
130
131 }
132
133 public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
134
135 Context mContext;
alision5cfc35d2013-07-11 15:11:39 -0400136 ArrayList<Fragment> fragments;
137
138 public SectionsPagerAdapter(Context c, FragmentManager fm) {
139 super(fm);
140 mContext = c;
141 fragments = new ArrayList<Fragment>();
142 fragments.add(new AccountCreationFragment());
143
144 }
145
146 @Override
147 public Fragment getItem(int i) {
148
149 return fragments.get(i);
150 }
151
152 public String getClassName(int i) {
153 String name;
154
155 switch (i) {
156 case 0:
157 name = AccountCreationFragment.class.getName();
158 break;
159
160 default:
161 Log.e(TAG, "getClassName: unknown fragment position " + i);
162 return null;
163 }
164
165 // Log.w(TAG, "getClassName: name=" + name);
166 return name;
167 }
168
169 @Override
170 public int getCount() {
171 return 1;
172 }
173
alision5cfc35d2013-07-11 15:11:39 -0400174 @Override
175 public CharSequence getPageTitle(int position) {
176 switch (position) {
177 case 0:
Alexandre Lision6e8931e2013-09-19 16:49:34 -0400178 return mContext.getString(R.string.title_section0).toUpperCase(Locale.getDefault());
alision5cfc35d2013-07-11 15:11:39 -0400179 default:
180 Log.e(TAG, "getPageTitle: unknown tab position " + position);
181 break;
182 }
183 return null;
184 }
185 }
186
Alexandre Lisiond16bad92013-10-09 17:16:20 -0400187 @Override
188 public ISipService getService() {
189 return service;
190 }
191
alision5cfc35d2013-07-11 15:11:39 -0400192}