blob: 788b1f702585c433e84d5f80a1f9251744d88ce6 [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 Lision48b49eb2014-02-11 13:37:33 -050058public class AccountWizard extends Activity implements 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;
Alexandre Lisiond16bad92013-10-09 17:16:20 -040061 private ISipService service;
alision5cfc35d2013-07-11 15:11:39 -040062 ViewPager mViewPager;
alision5cfc35d2013-07-11 15:11:39 -040063 private SectionsPagerAdapter mSectionsPagerAdapter;
64
Alexandre Lisiond16bad92013-10-09 17:16:20 -040065 private ServiceConnection mConnection = new ServiceConnection() {
66
67 @Override
68 public void onServiceConnected(ComponentName className, IBinder binder) {
69 service = ISipService.Stub.asInterface(binder);
70 mBound = true;
71 }
72
73 @Override
74 public void onServiceDisconnected(ComponentName arg0) {
75
76 }
77 };
78
alision5cfc35d2013-07-11 15:11:39 -040079 @Override
80 public void onCreate(Bundle savedInstanceState) {
81 super.onCreate(savedInstanceState);
82
83 setContentView(R.layout.activity_wizard);
84 mViewPager = (ViewPager) findViewById(R.id.pager);
85
86 getActionBar().setDisplayHomeAsUpEnabled(true);
87 getActionBar().setHomeButtonEnabled(true);
Alexandre Lision6e8931e2013-09-19 16:49:34 -040088 mSectionsPagerAdapter = new SectionsPagerAdapter(AccountWizard.this, getFragmentManager());
89 mViewPager.setAdapter(mSectionsPagerAdapter);
alision5cfc35d2013-07-11 15:11:39 -040090
Alexandre Lisiond16bad92013-10-09 17:16:20 -040091 if (!mBound) {
92 Log.i(TAG, "onCreate: Binding service...");
93 Intent intent = new Intent(this, SipService.class);
94 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
95 }
96
alision5cfc35d2013-07-11 15:11:39 -040097 }
98
99 /* activity finishes itself or is being killed by the system */
100 @Override
101 protected void onDestroy() {
alision5cfc35d2013-07-11 15:11:39 -0400102 super.onDestroy();
Alexandre Lisiond16bad92013-10-09 17:16:20 -0400103 if (mBound) {
104 unbindService(mConnection);
105 mBound = false;
106 }
alision5cfc35d2013-07-11 15:11:39 -0400107 }
108
alision5cfc35d2013-07-11 15:11:39 -0400109 @Override
110 public boolean onOptionsItemSelected(MenuItem item) {
111 switch (item.getItemId()) {
112 case android.R.id.home:
113 finish();
114 return true;
115 default:
116 return true;
117 }
118 }
119
alision5cfc35d2013-07-11 15:11:39 -0400120 public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
121
122 Context mContext;
alision5cfc35d2013-07-11 15:11:39 -0400123 ArrayList<Fragment> fragments;
124
125 public SectionsPagerAdapter(Context c, FragmentManager fm) {
126 super(fm);
127 mContext = c;
128 fragments = new ArrayList<Fragment>();
129 fragments.add(new AccountCreationFragment());
130
131 }
132
133 @Override
134 public Fragment getItem(int i) {
135
136 return fragments.get(i);
137 }
138
139 public String getClassName(int i) {
140 String name;
141
142 switch (i) {
143 case 0:
144 name = AccountCreationFragment.class.getName();
145 break;
146
147 default:
148 Log.e(TAG, "getClassName: unknown fragment position " + i);
149 return null;
150 }
151
152 // Log.w(TAG, "getClassName: name=" + name);
153 return name;
154 }
155
156 @Override
157 public int getCount() {
158 return 1;
159 }
160
alision5cfc35d2013-07-11 15:11:39 -0400161 @Override
162 public CharSequence getPageTitle(int position) {
163 switch (position) {
164 case 0:
Alexandre Lision6e8931e2013-09-19 16:49:34 -0400165 return mContext.getString(R.string.title_section0).toUpperCase(Locale.getDefault());
alision5cfc35d2013-07-11 15:11:39 -0400166 default:
167 Log.e(TAG, "getPageTitle: unknown tab position " + position);
168 break;
169 }
170 return null;
171 }
172 }
173
Alexandre Lisiond16bad92013-10-09 17:16:20 -0400174 @Override
175 public ISipService getService() {
176 return service;
177 }
178
alision5cfc35d2013-07-11 15:11:39 -0400179}