blob: 43cd2ba70b4a2d68daffda4a8dfac4cd395c45ea [file] [log] [blame]
Adrien BĂ©raud04d822c2015-04-02 17:44:36 -04001/*
2 * Copyright (C) 2004-2014 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 cx.ring.client;
33
34import android.app.Activity;
35import android.app.Fragment;
36import android.app.FragmentManager;
37import android.content.ComponentName;
38import android.content.Context;
39import android.content.Intent;
40import android.content.ServiceConnection;
41import android.os.Bundle;
42import android.os.IBinder;
43import android.support.v13.app.FragmentStatePagerAdapter;
44import android.support.v4.view.ViewPager;
45import android.util.Log;
46import android.view.MenuItem;
47import cx.ring.R;
48import cx.ring.fragments.AccountCreationFragment;
49import cx.ring.service.ISipService;
50import cx.ring.service.SipService;
51
52import java.util.ArrayList;
53import java.util.Locale;
54
55public class AccountWizard extends Activity implements AccountCreationFragment.Callbacks {
56 static final String TAG = "AccountWizard";
57 private boolean mBound = false;
58 private ISipService service;
59 ViewPager mViewPager;
60
61 private ServiceConnection mConnection = new ServiceConnection() {
62
63 @Override
64 public void onServiceConnected(ComponentName className, IBinder binder) {
65 service = ISipService.Stub.asInterface(binder);
66 mBound = true;
67 }
68
69 @Override
70 public void onServiceDisconnected(ComponentName arg0) {
71
72 }
73 };
74
75 @Override
76 public void onCreate(Bundle savedInstanceState) {
77 super.onCreate(savedInstanceState);
78
79 setContentView(R.layout.activity_wizard);
80 mViewPager = (ViewPager) findViewById(R.id.pager);
81
82 getActionBar().setDisplayHomeAsUpEnabled(true);
83 getActionBar().setHomeButtonEnabled(true);
84 SectionsPagerAdapter mSectionsPagerAdapter = new SectionsPagerAdapter(AccountWizard.this, getFragmentManager());
85 mViewPager.setAdapter(mSectionsPagerAdapter);
86
87 if (!mBound) {
88 Log.i(TAG, "onCreate: Binding service...");
89 Intent intent = new Intent(this, SipService.class);
90 bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
91 }
92
93 }
94
95 /* activity finishes itself or is being killed by the system */
96 @Override
97 protected void onDestroy() {
98 super.onDestroy();
99 if (mBound) {
100 unbindService(mConnection);
101 mBound = false;
102 }
103 }
104
105 @Override
106 public boolean onOptionsItemSelected(MenuItem item) {
107 switch (item.getItemId()) {
108 case android.R.id.home:
109 finish();
110 return true;
111 default:
112 return true;
113 }
114 }
115
116 public class SectionsPagerAdapter extends FragmentStatePagerAdapter {
117
118 Context mContext;
119 ArrayList<Fragment> fragments;
120
121 public SectionsPagerAdapter(Context c, FragmentManager fm) {
122 super(fm);
123 mContext = c;
124 fragments = new ArrayList<Fragment>();
125 fragments.add(new AccountCreationFragment());
126
127 }
128
129 @Override
130 public Fragment getItem(int i) {
131
132 return fragments.get(i);
133 }
134
135 public String getClassName(int i) {
136 String name;
137
138 switch (i) {
139 case 0:
140 name = AccountCreationFragment.class.getName();
141 break;
142
143 default:
144 Log.e(TAG, "getClassName: unknown fragment position " + i);
145 return null;
146 }
147
148 // Log.w(TAG, "getClassName: name=" + name);
149 return name;
150 }
151
152 @Override
153 public int getCount() {
154 return 1;
155 }
156
157 @Override
158 public CharSequence getPageTitle(int position) {
159 switch (position) {
160 case 0:
161 return mContext.getString(R.string.title_section0).toUpperCase(Locale.getDefault());
162 default:
163 Log.e(TAG, "getPageTitle: unknown tab position " + position);
164 break;
165 }
166 return null;
167 }
168 }
169
170 @Override
171 public ISipService getService() {
172 return service;
173 }
174
175}