alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 1 | /* |
| 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 Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 32 | package org.sflphone.client; |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 33 | |
| 34 | import java.util.ArrayList; |
Alexandre Lision | 6e8931e | 2013-09-19 16:49:34 -0400 | [diff] [blame] | 35 | import java.util.Locale; |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 36 | |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 37 | import org.sflphone.R; |
| 38 | import org.sflphone.fragments.AccountCreationFragment; |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 39 | import org.sflphone.fragments.AccountCreationFragment.Callbacks; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 40 | import org.sflphone.interfaces.AccountsInterface; |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 41 | import org.sflphone.service.ISipService; |
| 42 | import org.sflphone.service.SipService; |
Alexandre Lision | 064e1e0 | 2013-10-01 16:18:42 -0400 | [diff] [blame] | 43 | |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 44 | import android.app.Activity; |
| 45 | import android.app.Fragment; |
| 46 | import android.app.FragmentManager; |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 47 | import android.content.ComponentName; |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 48 | import android.content.Context; |
| 49 | import android.content.Intent; |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 50 | import android.content.ServiceConnection; |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 51 | import android.os.Bundle; |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 52 | import android.os.IBinder; |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 53 | import android.support.v13.app.FragmentStatePagerAdapter; |
| 54 | import android.support.v4.view.ViewPager; |
| 55 | import android.util.Log; |
| 56 | import android.view.MenuItem; |
| 57 | |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 58 | public class AccountWizard extends Activity implements AccountsInterface, Callbacks { |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 59 | static final String TAG = "AccountWizard"; |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 60 | private boolean mBound = false; |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 61 | public static final int ACCOUNT_CREATED = Activity.RESULT_OK; |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 62 | private ISipService service; |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 63 | ViewPager mViewPager; |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 64 | private SectionsPagerAdapter mSectionsPagerAdapter; |
| 65 | |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 66 | 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 | |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 80 | @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 Lision | 6e8931e | 2013-09-19 16:49:34 -0400 | [diff] [blame] | 89 | mSectionsPagerAdapter = new SectionsPagerAdapter(AccountWizard.this, getFragmentManager()); |
| 90 | mViewPager.setAdapter(mSectionsPagerAdapter); |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 91 | |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 92 | 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 | |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | /* activity finishes itself or is being killed by the system */ |
| 101 | @Override |
| 102 | protected void onDestroy() { |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 103 | super.onDestroy(); |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 104 | if (mBound) { |
| 105 | unbindService(mConnection); |
| 106 | mBound = false; |
| 107 | } |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 108 | } |
| 109 | |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 110 | @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; |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 136 | 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 | |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 174 | @Override |
| 175 | public CharSequence getPageTitle(int position) { |
| 176 | switch (position) { |
| 177 | case 0: |
Alexandre Lision | 6e8931e | 2013-09-19 16:49:34 -0400 | [diff] [blame] | 178 | return mContext.getString(R.string.title_section0).toUpperCase(Locale.getDefault()); |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 179 | default: |
| 180 | Log.e(TAG, "getPageTitle: unknown tab position " + position); |
| 181 | break; |
| 182 | } |
| 183 | return null; |
| 184 | } |
| 185 | } |
| 186 | |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 187 | @Override |
| 188 | public ISipService getService() { |
| 189 | return service; |
| 190 | } |
| 191 | |
alision | 5cfc35d | 2013-07-11 15:11:39 -0400 | [diff] [blame] | 192 | } |