Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2004-2013 Savoir-Faire Linux Inc. |
| 3 | * |
| 4 | * Author: Alexandre Lision <alexandre.lision@savoirfairelinux.com> |
| 5 | * Alexandre Savard <alexandre.savard@savoirfairelinux.com> |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; either version 3 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 20 | * |
| 21 | * Additional permission under GNU GPL version 3 section 7: |
| 22 | * |
| 23 | * If you modify this program, or any covered work, by linking or |
| 24 | * combining it with the OpenSSL project's OpenSSL library (or a |
| 25 | * modified version of that library), containing parts covered by the |
| 26 | * terms of the OpenSSL or SSLeay licenses, Savoir-Faire Linux Inc. |
| 27 | * grants you additional permission to convey the resulting work. |
| 28 | * Corresponding Source for a non-source form of such a combination |
| 29 | * shall include the source code for the parts of OpenSSL used as well |
| 30 | * as that of the covered work. |
| 31 | */ |
| 32 | |
| 33 | package org.sflphone.client; |
| 34 | |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 35 | import java.util.ArrayList; |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 36 | import java.util.Locale; |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 37 | |
| 38 | import org.sflphone.R; |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 39 | import org.sflphone.account.AccountDetailBasic; |
Alexandre Lision | c48c36a | 2013-11-12 16:26:10 -0500 | [diff] [blame] | 40 | import org.sflphone.fragments.AdvancedAccountFragment; |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 41 | import org.sflphone.fragments.AudioManagementFragment; |
Alexandre Lision | 8907c1c | 2013-11-12 11:40:14 -0500 | [diff] [blame] | 42 | import org.sflphone.fragments.GeneralAccountFragment; |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 43 | import org.sflphone.fragments.NestedSettingsFragment; |
Alexandre Lision | c48c36a | 2013-11-12 16:26:10 -0500 | [diff] [blame] | 44 | import org.sflphone.fragments.SecurityAccountFragment; |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 45 | import org.sflphone.model.Account; |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 46 | import org.sflphone.service.ISipService; |
| 47 | import org.sflphone.service.SipService; |
Alexandre Lision | 8907c1c | 2013-11-12 11:40:14 -0500 | [diff] [blame] | 48 | import org.sflphone.views.PagerSlidingTabStrip; |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 49 | |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 50 | import android.app.ActionBar.Tab; |
| 51 | import android.app.ActionBar.TabListener; |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 52 | import android.app.Activity; |
| 53 | import android.app.AlertDialog; |
| 54 | import android.app.Dialog; |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 55 | import android.app.Fragment; |
| 56 | import android.app.FragmentManager; |
| 57 | import android.app.FragmentTransaction; |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 58 | import android.content.ComponentName; |
| 59 | import android.content.Context; |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 60 | import android.content.DialogInterface; |
| 61 | import android.content.Intent; |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 62 | import android.content.ServiceConnection; |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 63 | import android.os.Bundle; |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 64 | import android.os.IBinder; |
| 65 | import android.os.RemoteException; |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 66 | import android.support.v13.app.FragmentStatePagerAdapter; |
| 67 | import android.support.v4.view.ViewPager; |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 68 | import android.util.Log; |
| 69 | import android.view.Menu; |
| 70 | import android.view.MenuInflater; |
| 71 | import android.view.MenuItem; |
| 72 | |
Alexandre Lision | c48c36a | 2013-11-12 16:26:10 -0500 | [diff] [blame] | 73 | public class AccountEditionActivity extends Activity implements TabListener, GeneralAccountFragment.Callbacks, AudioManagementFragment.Callbacks, |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 74 | AdvancedAccountFragment.Callbacks, SecurityAccountFragment.Callbacks, NestedSettingsFragment.Callbacks { |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 75 | private static final String TAG = "AccoutPreferenceActivity"; |
| 76 | |
| 77 | public static final String KEY_MODE = "mode"; |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 78 | private boolean mBound = false; |
| 79 | private ISipService service; |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 80 | |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 81 | private Account acc_selected; |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 82 | |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 83 | PreferencesPagerAdapter mPreferencesPagerAdapter; |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 84 | private ServiceConnection mConnection = new ServiceConnection() { |
| 85 | |
| 86 | @Override |
| 87 | public void onServiceConnected(ComponentName className, IBinder binder) { |
| 88 | service = ISipService.Stub.asInterface(binder); |
| 89 | mBound = true; |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 90 | |
| 91 | ArrayList<Fragment> fragments = new ArrayList<Fragment>(); |
| 92 | if (acc_selected.isIP2IP()) { |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 93 | fragments.add(new AudioManagementFragment()); |
| 94 | } else { |
Alexandre Lision | 8907c1c | 2013-11-12 11:40:14 -0500 | [diff] [blame] | 95 | fragments.add(new GeneralAccountFragment()); |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 96 | fragments.add(new AudioManagementFragment()); |
Alexandre Lision | c48c36a | 2013-11-12 16:26:10 -0500 | [diff] [blame] | 97 | fragments.add(new AdvancedAccountFragment()); |
| 98 | fragments.add(new SecurityAccountFragment()); |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | mPreferencesPagerAdapter = new PreferencesPagerAdapter(AccountEditionActivity.this, getFragmentManager(), fragments); |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 102 | mViewPager.setAdapter(mPreferencesPagerAdapter); |
Alexandre Lision | c48c36a | 2013-11-12 16:26:10 -0500 | [diff] [blame] | 103 | mViewPager.setOffscreenPageLimit(3); |
| 104 | |
Alexandre Lision | 8907c1c | 2013-11-12 11:40:14 -0500 | [diff] [blame] | 105 | final PagerSlidingTabStrip strip = PagerSlidingTabStrip.class.cast(findViewById(R.id.pager_sliding_strip)); |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 106 | |
Alexandre Lision | 8907c1c | 2013-11-12 11:40:14 -0500 | [diff] [blame] | 107 | // strip.setBackgroundColor(getResources().getColor(R.color.sfl_blue_0)); |
| 108 | strip.setViewPager(mViewPager); |
Alexandre Lision | c48c36a | 2013-11-12 16:26:10 -0500 | [diff] [blame] | 109 | // getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); |
| 110 | // for (int i = 0; i < mPreferencesPagerAdapter.getCount(); i++) { |
| 111 | // getActionBar().addTab( |
| 112 | // getActionBar().newTab().setText(mPreferencesPagerAdapter.getPageTitle(i)).setTabListener(AccountEditionActivity.this)); |
| 113 | // |
| 114 | // } |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | @Override |
| 118 | public void onServiceDisconnected(ComponentName arg0) { |
| 119 | |
| 120 | } |
| 121 | }; |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 122 | |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 123 | private ViewPager mViewPager; |
| 124 | |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 125 | // private ArrayList<String> requiredFields = null; |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 126 | // EditionFragment mEditionFragment; |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 127 | |
| 128 | @Override |
| 129 | protected void onCreate(Bundle savedInstanceState) { |
| 130 | super.onCreate(savedInstanceState); |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 131 | |
Alexandre Lision | 8907c1c | 2013-11-12 11:40:14 -0500 | [diff] [blame] | 132 | setContentView(R.layout.activity_account_settings); |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 133 | |
| 134 | getActionBar().setDisplayHomeAsUpEnabled(true); |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 135 | mViewPager = (ViewPager) findViewById(R.id.pager); |
| 136 | mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { |
| 137 | @Override |
| 138 | public void onPageSelected(int position) { |
| 139 | getActionBar().setSelectedNavigationItem(position); |
| 140 | } |
| 141 | }); |
| 142 | |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 143 | acc_selected = getIntent().getExtras().getParcelable("account"); |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 144 | |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 145 | if (!mBound) { |
| 146 | Log.i(TAG, "onCreate: Binding service..."); |
| 147 | Intent intent = new Intent(this, SipService.class); |
| 148 | bindService(intent, mConnection, Context.BIND_AUTO_CREATE); |
| 149 | } |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 150 | |
| 151 | } |
| 152 | |
| 153 | @Override |
| 154 | public boolean onCreateOptionsMenu(Menu menu) { |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 155 | if (acc_selected.isIP2IP()) { |
| 156 | return true; |
| 157 | } |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 158 | MenuInflater inflater = getMenuInflater(); |
| 159 | inflater.inflate(R.menu.account_edition, menu); |
| 160 | return true; |
| 161 | } |
| 162 | |
| 163 | @Override |
| 164 | public void onBackPressed() { |
| 165 | |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 166 | if (acc_selected.isIP2IP()) { |
| 167 | super.onBackPressed(); |
| 168 | return; |
| 169 | } |
| 170 | |
Alexandre Lision | 8907c1c | 2013-11-12 11:40:14 -0500 | [diff] [blame] | 171 | if (mPreferencesPagerAdapter.getItem(0) != null && ((GeneralAccountFragment) mPreferencesPagerAdapter.getItem(0)).isDifferent()) { |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 172 | AlertDialog dialog = createCancelDialog(); |
| 173 | dialog.show(); |
| 174 | } else { |
| 175 | super.onBackPressed(); |
| 176 | } |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 177 | } |
| 178 | |
| 179 | @Override |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 180 | protected void onDestroy() { |
| 181 | |
| 182 | if (mBound) { |
| 183 | unbindService(mConnection); |
| 184 | mBound = false; |
| 185 | } |
| 186 | |
| 187 | // stopService(new Intent(this, SipService.class)); |
| 188 | // serviceIsOn = false; |
| 189 | super.onDestroy(); |
| 190 | } |
| 191 | |
| 192 | @Override |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 193 | public boolean onOptionsItemSelected(MenuItem item) { |
| 194 | |
| 195 | switch (item.getItemId()) { |
| 196 | case android.R.id.home: |
| 197 | finish(); |
| 198 | return true; |
| 199 | case R.id.menuitem_delete: |
| 200 | AlertDialog dialog = createDeleteDialog(); |
| 201 | dialog.show(); |
| 202 | break; |
| 203 | case R.id.menuitem_edit: |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 204 | processAccount(); |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 205 | break; |
| 206 | |
| 207 | } |
| 208 | |
| 209 | return true; |
| 210 | } |
| 211 | |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 212 | private void processAccount() { |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 213 | AlertDialog dialog; |
| 214 | ArrayList<String> missingValue = new ArrayList<String>(); |
Alexandre Lision | c48c36a | 2013-11-12 16:26:10 -0500 | [diff] [blame] | 215 | |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 216 | if (validateAccountCreation(missingValue)) { |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 217 | try { |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 218 | service.setAccountDetails(acc_selected.getAccountID(), acc_selected.getDetails()); |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 219 | } catch (RemoteException e) { |
| 220 | e.printStackTrace(); |
| 221 | } |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 222 | finish(); |
| 223 | } else { |
| 224 | dialog = createCouldNotValidateDialog(missingValue); |
| 225 | dialog.show(); |
| 226 | } |
| 227 | |
| 228 | } |
Alexandre Lision | c48c36a | 2013-11-12 16:26:10 -0500 | [diff] [blame] | 229 | |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 230 | public boolean validateAccountCreation(ArrayList<String> missingValue) { |
| 231 | boolean valid = true; |
| 232 | ArrayList<String> requiredFields = new ArrayList<String>(); |
| 233 | requiredFields.add(AccountDetailBasic.CONFIG_ACCOUNT_ALIAS); |
| 234 | requiredFields.add(AccountDetailBasic.CONFIG_ACCOUNT_HOSTNAME); |
| 235 | requiredFields.add(AccountDetailBasic.CONFIG_ACCOUNT_USERNAME); |
| 236 | requiredFields.add(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD); |
| 237 | for (String s : requiredFields) { |
Alexandre Lision | c48c36a | 2013-11-12 16:26:10 -0500 | [diff] [blame] | 238 | |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 239 | if (acc_selected.getBasicDetails().getDetailString(s).isEmpty()) { |
| 240 | valid = false; |
| 241 | missingValue.add(s); |
| 242 | } |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 243 | } |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 244 | |
| 245 | return valid; |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 246 | } |
| 247 | |
| 248 | /****************************************** |
| 249 | * |
| 250 | * AlertDialogs |
| 251 | * |
| 252 | ******************************************/ |
| 253 | |
| 254 | private AlertDialog createCouldNotValidateDialog(ArrayList<String> missingValue) { |
| 255 | String message = "The following parameters are missing:"; |
| 256 | |
| 257 | for (String s : missingValue) |
| 258 | message += "\n - " + s; |
| 259 | |
| 260 | Activity ownerActivity = this; |
| 261 | AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity); |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 262 | builder.setMessage(message).setTitle("Missing Parameters").setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 263 | @Override |
| 264 | public void onClick(DialogInterface dialog, int whichButton) { |
| 265 | /* Nothing to be done */ |
| 266 | } |
| 267 | }); |
| 268 | |
| 269 | AlertDialog alertDialog = builder.create(); |
| 270 | return alertDialog; |
| 271 | } |
| 272 | |
| 273 | private AlertDialog createCancelDialog() { |
| 274 | Activity ownerActivity = this; |
| 275 | AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity); |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 276 | builder.setMessage("Modifications will be lost").setTitle("Account Edition") |
| 277 | .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { |
| 278 | @Override |
| 279 | public void onClick(DialogInterface dialog, int whichButton) { |
| 280 | Activity activity = ((Dialog) dialog).getOwnerActivity(); |
| 281 | activity.finish(); |
| 282 | } |
| 283 | }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
| 284 | @Override |
| 285 | public void onClick(DialogInterface dialog, int whichButton) { |
| 286 | /* Terminate with no action */ |
| 287 | } |
| 288 | }); |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 289 | |
| 290 | AlertDialog alertDialog = builder.create(); |
| 291 | alertDialog.setOwnerActivity(ownerActivity); |
| 292 | |
| 293 | return alertDialog; |
| 294 | } |
| 295 | |
| 296 | private AlertDialog createDeleteDialog() { |
| 297 | Activity ownerActivity = this; |
| 298 | AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity); |
| 299 | builder.setMessage("Do you really want to delete this account").setTitle("Delete Account") |
| 300 | .setPositiveButton("Ok", new DialogInterface.OnClickListener() { |
| 301 | @Override |
| 302 | public void onClick(DialogInterface dialog, int whichButton) { |
| 303 | Bundle bundle = new Bundle(); |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 304 | bundle.putString("AccountID", acc_selected.getAccountID()); |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 305 | |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 306 | try { |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 307 | service.removeAccount(acc_selected.getAccountID()); |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 308 | } catch (RemoteException e) { |
| 309 | e.printStackTrace(); |
| 310 | } |
| 311 | finish(); |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 312 | } |
| 313 | }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
| 314 | @Override |
| 315 | public void onClick(DialogInterface dialog, int whichButton) { |
| 316 | /* Terminate with no action */ |
| 317 | } |
| 318 | }); |
| 319 | |
| 320 | AlertDialog alertDialog = builder.create(); |
| 321 | alertDialog.setOwnerActivity(ownerActivity); |
| 322 | |
| 323 | return alertDialog; |
| 324 | } |
| 325 | |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 326 | public class PreferencesPagerAdapter extends FragmentStatePagerAdapter { |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 327 | |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 328 | Context mContext; |
| 329 | ArrayList<Fragment> fragments; |
| 330 | |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 331 | public PreferencesPagerAdapter(Context c, FragmentManager fm, ArrayList<Fragment> items) { |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 332 | super(fm); |
| 333 | mContext = c; |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 334 | fragments = new ArrayList<Fragment>(items); |
| 335 | |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 336 | } |
| 337 | |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 338 | @Override |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 339 | public int getCount() { |
| 340 | return fragments.size(); |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 341 | } |
| 342 | |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 343 | @Override |
| 344 | public Fragment getItem(int position) { |
| 345 | return fragments.get(position); |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 346 | } |
| 347 | |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 348 | @Override |
| 349 | public CharSequence getPageTitle(int position) { |
| 350 | switch (position) { |
| 351 | case 0: |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 352 | if (acc_selected.isIP2IP()) { |
| 353 | return getString(R.string.account_preferences_audio).toUpperCase(Locale.getDefault()); |
| 354 | } else { |
| 355 | return getString(R.string.account_preferences_basic).toUpperCase(Locale.getDefault()); |
| 356 | } |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 357 | case 1: |
| 358 | return getString(R.string.account_preferences_audio).toUpperCase(Locale.getDefault()); |
Alexandre Lision | c48c36a | 2013-11-12 16:26:10 -0500 | [diff] [blame] | 359 | case 2: |
| 360 | return getString(R.string.account_preferences_advanced).toUpperCase(Locale.getDefault()); |
| 361 | case 3: |
| 362 | return getString(R.string.account_preferences_security).toUpperCase(Locale.getDefault()); |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 363 | default: |
| 364 | Log.e(TAG, "getPreferencePageTitle: unknown tab position " + position); |
| 365 | break; |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 366 | } |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 367 | return null; |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 368 | } |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 369 | } |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 370 | |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 371 | @Override |
| 372 | public void onTabReselected(Tab arg0, FragmentTransaction arg1) { |
| 373 | // TODO Stub de la méthode généré automatiquement |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 374 | |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 375 | } |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 376 | |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 377 | @Override |
| 378 | public void onTabSelected(Tab tab, FragmentTransaction ft) { |
| 379 | mViewPager.setCurrentItem(tab.getPosition()); |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 380 | |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 381 | } |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 382 | |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 383 | @Override |
| 384 | public void onTabUnselected(Tab tab, FragmentTransaction ft) { |
| 385 | // TODO Stub de la méthode généré automatiquement |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 386 | |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 387 | } |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 388 | |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 389 | @Override |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 390 | public ISipService getService() { |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 391 | return service; |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 392 | } |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 393 | |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 394 | @Override |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 395 | public String getAccountID() { |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 396 | return acc_selected.getAccountID(); |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 397 | } |
| 398 | |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 399 | @Override |
| 400 | public Account getAccount() { |
| 401 | return acc_selected; |
| 402 | } |
| 403 | |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 404 | } |