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; |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame^] | 72 | import android.view.View; |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 73 | |
Alexandre Lision | c48c36a | 2013-11-12 16:26:10 -0500 | [diff] [blame] | 74 | public class AccountEditionActivity extends Activity implements TabListener, GeneralAccountFragment.Callbacks, AudioManagementFragment.Callbacks, |
Alexandre Lision | a365099 | 2013-11-13 14:19:35 -0500 | [diff] [blame] | 75 | AdvancedAccountFragment.Callbacks, SecurityAccountFragment.Callbacks, NestedSettingsFragment.Callbacks { |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 76 | private static final String TAG = "AccoutPreferenceActivity"; |
| 77 | |
| 78 | public static final String KEY_MODE = "mode"; |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 79 | private boolean mBound = false; |
| 80 | private ISipService service; |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 81 | |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame^] | 82 | private View mOverlayContainer; |
| 83 | |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 84 | private Account acc_selected; |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 85 | |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 86 | PreferencesPagerAdapter mPreferencesPagerAdapter; |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 87 | private ServiceConnection mConnection = new ServiceConnection() { |
| 88 | |
| 89 | @Override |
| 90 | public void onServiceConnected(ComponentName className, IBinder binder) { |
| 91 | service = ISipService.Stub.asInterface(binder); |
| 92 | mBound = true; |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 93 | |
| 94 | ArrayList<Fragment> fragments = new ArrayList<Fragment>(); |
| 95 | if (acc_selected.isIP2IP()) { |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 96 | fragments.add(new AudioManagementFragment()); |
| 97 | } else { |
Alexandre Lision | 8907c1c | 2013-11-12 11:40:14 -0500 | [diff] [blame] | 98 | fragments.add(new GeneralAccountFragment()); |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 99 | fragments.add(new AudioManagementFragment()); |
Alexandre Lision | c48c36a | 2013-11-12 16:26:10 -0500 | [diff] [blame] | 100 | fragments.add(new AdvancedAccountFragment()); |
| 101 | fragments.add(new SecurityAccountFragment()); |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | mPreferencesPagerAdapter = new PreferencesPagerAdapter(AccountEditionActivity.this, getFragmentManager(), fragments); |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 105 | mViewPager.setAdapter(mPreferencesPagerAdapter); |
Alexandre Lision | c48c36a | 2013-11-12 16:26:10 -0500 | [diff] [blame] | 106 | mViewPager.setOffscreenPageLimit(3); |
| 107 | |
Alexandre Lision | 8907c1c | 2013-11-12 11:40:14 -0500 | [diff] [blame] | 108 | final PagerSlidingTabStrip strip = PagerSlidingTabStrip.class.cast(findViewById(R.id.pager_sliding_strip)); |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 109 | |
Alexandre Lision | 8907c1c | 2013-11-12 11:40:14 -0500 | [diff] [blame] | 110 | // strip.setBackgroundColor(getResources().getColor(R.color.sfl_blue_0)); |
| 111 | strip.setViewPager(mViewPager); |
Alexandre Lision | c48c36a | 2013-11-12 16:26:10 -0500 | [diff] [blame] | 112 | // getActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); |
| 113 | // for (int i = 0; i < mPreferencesPagerAdapter.getCount(); i++) { |
| 114 | // getActionBar().addTab( |
| 115 | // getActionBar().newTab().setText(mPreferencesPagerAdapter.getPageTitle(i)).setTabListener(AccountEditionActivity.this)); |
| 116 | // |
| 117 | // } |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | @Override |
| 121 | public void onServiceDisconnected(ComponentName arg0) { |
| 122 | |
| 123 | } |
| 124 | }; |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 125 | |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 126 | private ViewPager mViewPager; |
| 127 | |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 128 | // private ArrayList<String> requiredFields = null; |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 129 | // EditionFragment mEditionFragment; |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 130 | |
| 131 | @Override |
| 132 | protected void onCreate(Bundle savedInstanceState) { |
| 133 | super.onCreate(savedInstanceState); |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 134 | |
Alexandre Lision | 8907c1c | 2013-11-12 11:40:14 -0500 | [diff] [blame] | 135 | setContentView(R.layout.activity_account_settings); |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 136 | |
| 137 | getActionBar().setDisplayHomeAsUpEnabled(true); |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 138 | mViewPager = (ViewPager) findViewById(R.id.pager); |
| 139 | mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() { |
| 140 | @Override |
| 141 | public void onPageSelected(int position) { |
| 142 | getActionBar().setSelectedNavigationItem(position); |
| 143 | } |
| 144 | }); |
| 145 | |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame^] | 146 | mOverlayContainer = findViewById(R.id.hidden_container); |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 147 | acc_selected = getIntent().getExtras().getParcelable("account"); |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 148 | |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 149 | if (!mBound) { |
| 150 | Log.i(TAG, "onCreate: Binding service..."); |
| 151 | Intent intent = new Intent(this, SipService.class); |
| 152 | bindService(intent, mConnection, Context.BIND_AUTO_CREATE); |
| 153 | } |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 154 | |
| 155 | } |
| 156 | |
| 157 | @Override |
| 158 | public boolean onCreateOptionsMenu(Menu menu) { |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 159 | if (acc_selected.isIP2IP()) { |
| 160 | return true; |
| 161 | } |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 162 | MenuInflater inflater = getMenuInflater(); |
| 163 | inflater.inflate(R.menu.account_edition, menu); |
| 164 | return true; |
| 165 | } |
| 166 | |
| 167 | @Override |
| 168 | public void onBackPressed() { |
| 169 | |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 170 | if (acc_selected.isIP2IP()) { |
| 171 | super.onBackPressed(); |
| 172 | return; |
| 173 | } |
| 174 | |
Alexandre Lision | 8907c1c | 2013-11-12 11:40:14 -0500 | [diff] [blame] | 175 | if (mPreferencesPagerAdapter.getItem(0) != null && ((GeneralAccountFragment) mPreferencesPagerAdapter.getItem(0)).isDifferent()) { |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 176 | AlertDialog dialog = createCancelDialog(); |
| 177 | dialog.show(); |
| 178 | } else { |
| 179 | super.onBackPressed(); |
| 180 | } |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | @Override |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 184 | protected void onDestroy() { |
| 185 | |
| 186 | if (mBound) { |
| 187 | unbindService(mConnection); |
| 188 | mBound = false; |
| 189 | } |
| 190 | |
| 191 | // stopService(new Intent(this, SipService.class)); |
| 192 | // serviceIsOn = false; |
| 193 | super.onDestroy(); |
| 194 | } |
| 195 | |
| 196 | @Override |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 197 | public boolean onOptionsItemSelected(MenuItem item) { |
| 198 | |
| 199 | switch (item.getItemId()) { |
| 200 | case android.R.id.home: |
| 201 | finish(); |
| 202 | return true; |
| 203 | case R.id.menuitem_delete: |
| 204 | AlertDialog dialog = createDeleteDialog(); |
| 205 | dialog.show(); |
| 206 | break; |
| 207 | case R.id.menuitem_edit: |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 208 | processAccount(); |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 209 | break; |
| 210 | |
| 211 | } |
| 212 | |
| 213 | return true; |
| 214 | } |
| 215 | |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 216 | private void processAccount() { |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 217 | AlertDialog dialog; |
| 218 | ArrayList<String> missingValue = new ArrayList<String>(); |
Alexandre Lision | c48c36a | 2013-11-12 16:26:10 -0500 | [diff] [blame] | 219 | |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 220 | if (validateAccountCreation(missingValue)) { |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 221 | try { |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 222 | service.setAccountDetails(acc_selected.getAccountID(), acc_selected.getDetails()); |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 223 | } catch (RemoteException e) { |
| 224 | e.printStackTrace(); |
| 225 | } |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 226 | finish(); |
| 227 | } else { |
| 228 | dialog = createCouldNotValidateDialog(missingValue); |
| 229 | dialog.show(); |
| 230 | } |
| 231 | |
| 232 | } |
Alexandre Lision | c48c36a | 2013-11-12 16:26:10 -0500 | [diff] [blame] | 233 | |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 234 | public boolean validateAccountCreation(ArrayList<String> missingValue) { |
| 235 | boolean valid = true; |
| 236 | ArrayList<String> requiredFields = new ArrayList<String>(); |
| 237 | requiredFields.add(AccountDetailBasic.CONFIG_ACCOUNT_ALIAS); |
| 238 | requiredFields.add(AccountDetailBasic.CONFIG_ACCOUNT_HOSTNAME); |
| 239 | requiredFields.add(AccountDetailBasic.CONFIG_ACCOUNT_USERNAME); |
| 240 | requiredFields.add(AccountDetailBasic.CONFIG_ACCOUNT_PASSWORD); |
| 241 | for (String s : requiredFields) { |
Alexandre Lision | c48c36a | 2013-11-12 16:26:10 -0500 | [diff] [blame] | 242 | |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 243 | if (acc_selected.getBasicDetails().getDetailString(s).isEmpty()) { |
| 244 | valid = false; |
| 245 | missingValue.add(s); |
| 246 | } |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 247 | } |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 248 | |
| 249 | return valid; |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | /****************************************** |
| 253 | * |
| 254 | * AlertDialogs |
| 255 | * |
| 256 | ******************************************/ |
| 257 | |
| 258 | private AlertDialog createCouldNotValidateDialog(ArrayList<String> missingValue) { |
| 259 | String message = "The following parameters are missing:"; |
| 260 | |
| 261 | for (String s : missingValue) |
| 262 | message += "\n - " + s; |
| 263 | |
| 264 | Activity ownerActivity = this; |
| 265 | AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity); |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 266 | 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] | 267 | @Override |
| 268 | public void onClick(DialogInterface dialog, int whichButton) { |
| 269 | /* Nothing to be done */ |
| 270 | } |
| 271 | }); |
| 272 | |
| 273 | AlertDialog alertDialog = builder.create(); |
| 274 | return alertDialog; |
| 275 | } |
| 276 | |
| 277 | private AlertDialog createCancelDialog() { |
| 278 | Activity ownerActivity = this; |
| 279 | AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity); |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 280 | builder.setMessage("Modifications will be lost").setTitle("Account Edition") |
| 281 | .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { |
| 282 | @Override |
| 283 | public void onClick(DialogInterface dialog, int whichButton) { |
| 284 | Activity activity = ((Dialog) dialog).getOwnerActivity(); |
| 285 | activity.finish(); |
| 286 | } |
| 287 | }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
| 288 | @Override |
| 289 | public void onClick(DialogInterface dialog, int whichButton) { |
| 290 | /* Terminate with no action */ |
| 291 | } |
| 292 | }); |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 293 | |
| 294 | AlertDialog alertDialog = builder.create(); |
| 295 | alertDialog.setOwnerActivity(ownerActivity); |
| 296 | |
| 297 | return alertDialog; |
| 298 | } |
| 299 | |
| 300 | private AlertDialog createDeleteDialog() { |
| 301 | Activity ownerActivity = this; |
| 302 | AlertDialog.Builder builder = new AlertDialog.Builder(ownerActivity); |
| 303 | builder.setMessage("Do you really want to delete this account").setTitle("Delete Account") |
| 304 | .setPositiveButton("Ok", new DialogInterface.OnClickListener() { |
| 305 | @Override |
| 306 | public void onClick(DialogInterface dialog, int whichButton) { |
| 307 | Bundle bundle = new Bundle(); |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 308 | bundle.putString("AccountID", acc_selected.getAccountID()); |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 309 | |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 310 | try { |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 311 | service.removeAccount(acc_selected.getAccountID()); |
Alexandre Lision | d16bad9 | 2013-10-09 17:16:20 -0400 | [diff] [blame] | 312 | } catch (RemoteException e) { |
| 313 | e.printStackTrace(); |
| 314 | } |
| 315 | finish(); |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 316 | } |
| 317 | }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { |
| 318 | @Override |
| 319 | public void onClick(DialogInterface dialog, int whichButton) { |
| 320 | /* Terminate with no action */ |
| 321 | } |
| 322 | }); |
| 323 | |
| 324 | AlertDialog alertDialog = builder.create(); |
| 325 | alertDialog.setOwnerActivity(ownerActivity); |
| 326 | |
| 327 | return alertDialog; |
| 328 | } |
| 329 | |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 330 | public class PreferencesPagerAdapter extends FragmentStatePagerAdapter { |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 331 | |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 332 | Context mContext; |
| 333 | ArrayList<Fragment> fragments; |
| 334 | |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 335 | public PreferencesPagerAdapter(Context c, FragmentManager fm, ArrayList<Fragment> items) { |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 336 | super(fm); |
| 337 | mContext = c; |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 338 | fragments = new ArrayList<Fragment>(items); |
| 339 | |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 340 | } |
| 341 | |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 342 | @Override |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 343 | public int getCount() { |
| 344 | return fragments.size(); |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 345 | } |
| 346 | |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 347 | @Override |
| 348 | public Fragment getItem(int position) { |
| 349 | return fragments.get(position); |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 350 | } |
| 351 | |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 352 | @Override |
| 353 | public CharSequence getPageTitle(int position) { |
| 354 | switch (position) { |
| 355 | case 0: |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 356 | if (acc_selected.isIP2IP()) { |
| 357 | return getString(R.string.account_preferences_audio).toUpperCase(Locale.getDefault()); |
| 358 | } else { |
| 359 | return getString(R.string.account_preferences_basic).toUpperCase(Locale.getDefault()); |
| 360 | } |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 361 | case 1: |
| 362 | return getString(R.string.account_preferences_audio).toUpperCase(Locale.getDefault()); |
Alexandre Lision | c48c36a | 2013-11-12 16:26:10 -0500 | [diff] [blame] | 363 | case 2: |
| 364 | return getString(R.string.account_preferences_advanced).toUpperCase(Locale.getDefault()); |
| 365 | case 3: |
| 366 | return getString(R.string.account_preferences_security).toUpperCase(Locale.getDefault()); |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 367 | default: |
| 368 | Log.e(TAG, "getPreferencePageTitle: unknown tab position " + position); |
| 369 | break; |
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 | return null; |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 372 | } |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 373 | } |
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 | @Override |
| 376 | public void onTabReselected(Tab arg0, FragmentTransaction arg1) { |
| 377 | // TODO Stub de la méthode généré automatiquement |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 378 | |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 379 | } |
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 | @Override |
| 382 | public void onTabSelected(Tab tab, FragmentTransaction ft) { |
| 383 | mViewPager.setCurrentItem(tab.getPosition()); |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 384 | |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 385 | } |
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 | @Override |
| 388 | public void onTabUnselected(Tab tab, FragmentTransaction ft) { |
| 389 | // TODO Stub de la méthode généré automatiquement |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 390 | |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 391 | } |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 392 | |
Alexandre Lision | afd40e4 | 2013-10-15 13:48:37 -0400 | [diff] [blame] | 393 | @Override |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 394 | public ISipService getService() { |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 395 | return service; |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 396 | } |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 397 | |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 398 | @Override |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 399 | public String getAccountID() { |
Alexandre Lision | d2e9e06 | 2013-10-21 16:27:33 -0400 | [diff] [blame] | 400 | return acc_selected.getAccountID(); |
Alexandre Lision | 933ef0a | 2013-10-15 17:28:40 -0400 | [diff] [blame] | 401 | } |
| 402 | |
Alexandre Lision | 059da9d | 2013-10-22 11:17:25 -0400 | [diff] [blame] | 403 | @Override |
| 404 | public Account getAccount() { |
| 405 | return acc_selected; |
| 406 | } |
| 407 | |
Alexandre Lision | 3b7148e | 2013-11-13 17:23:06 -0500 | [diff] [blame^] | 408 | @Override |
| 409 | public void displayCredentialsScreen() { |
| 410 | Fragment toDisplay = new NestedSettingsFragment(); |
| 411 | Bundle b = new Bundle(); |
| 412 | b.putInt("MODE", 0); |
| 413 | toDisplay.setArguments(b); |
| 414 | getFragmentManager().beginTransaction().replace(R.id.hidden_container, toDisplay).commit(); |
| 415 | } |
| 416 | |
Alexandre Lision | 227b59c | 2013-10-03 17:37:57 -0400 | [diff] [blame] | 417 | } |