blob: 30181a83194c41119bac05559e704b5da0a715df [file] [log] [blame]
Alexandre Savard2b370f02012-09-06 16:06:01 -04001/*
alision5cfc35d2013-07-11 15:11:39 -04002 * Copyright (C) 2004-2013 Savoir-Faire Linux Inc.
Alexandre Savard2b370f02012-09-06 16:06:01 -04003 *
4 * Author: Alexandre Savard <alexandre.savard@savoirfairelinux.com>
alision5cfc35d2013-07-11 15:11:39 -04005 * Alexandre Lision <alexandre.lision@savoirfairelinux.com>
Alexandre Savard2b370f02012-09-06 16:06:01 -04006 *
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
Alexandre Lision064e1e02013-10-01 16:18:42 -040033package org.sflphone.fragments;
alisionf76de3b2013-04-16 15:35:22 -040034
Alexandre Lision4cf78702013-10-16 13:43:23 -040035import java.io.File;
alisionf76de3b2013-04-16 15:35:22 -040036import java.util.ArrayList;
Alexandre Savard2b370f02012-09-06 16:06:01 -040037
Alexandre Lision064e1e02013-10-01 16:18:42 -040038import org.sflphone.R;
Alexandre Lision8b9d8e82013-10-04 09:21:27 -040039import org.sflphone.client.AccountEditionActivity;
Alexandre Lision064e1e02013-10-01 16:18:42 -040040import org.sflphone.client.AccountWizard;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040041import org.sflphone.interfaces.AccountsInterface;
42import org.sflphone.loaders.AccountsLoader;
43import org.sflphone.loaders.LoaderConstants;
Alexandre Lision064e1e02013-10-01 16:18:42 -040044import org.sflphone.model.Account;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040045import org.sflphone.receivers.AccountsReceiver;
Alexandre Lision064e1e02013-10-01 16:18:42 -040046import org.sflphone.service.ConfigurationManagerCallback;
47import org.sflphone.service.ISipService;
Alexandre Lision7f0bba52013-10-16 14:43:11 -040048import org.sflphone.views.dragsortlv.DragSortListView;
Alexandre Lision064e1e02013-10-01 16:18:42 -040049
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -040050import android.animation.Animator;
51import android.animation.AnimatorListenerAdapter;
Alexandre Savard9a93f062012-09-11 10:42:43 -040052import android.app.Activity;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040053import android.app.ListFragment;
54import android.app.LoaderManager.LoaderCallbacks;
Alexandre Savardae992932012-10-17 10:26:12 -040055import android.content.Context;
Alexandre Savard53d2ddd2012-09-30 22:04:40 -040056import android.content.Intent;
Alexandre Savard4f11d7a2012-10-18 13:15:36 -040057import android.content.IntentFilter;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040058import android.content.Loader;
alisionf76de3b2013-04-16 15:35:22 -040059import android.os.Bundle;
60import android.os.RemoteException;
Alexandre Savard2b370f02012-09-06 16:06:01 -040061import android.util.Log;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040062import android.view.LayoutInflater;
Alexandre Lisiona764c682013-09-09 10:02:07 -040063import android.view.Menu;
64import android.view.MenuInflater;
65import android.view.MenuItem;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040066import android.view.View;
Alexandre Lision059da9d2013-10-22 11:17:25 -040067import android.view.View.OnClickListener;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040068import android.view.ViewGroup;
69import android.widget.AdapterView;
70import android.widget.AdapterView.OnItemClickListener;
71import android.widget.BaseAdapter;
72import android.widget.CheckBox;
Alexandre Lision230d66e2013-10-22 12:32:12 -040073import android.widget.ListView;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040074import android.widget.TextView;
Alexandre Savard2b370f02012-09-06 16:06:01 -040075
Alexandre Lisiona3650992013-11-13 14:19:35 -050076public class AccountsManagementFragment extends ListFragment implements LoaderCallbacks<Bundle>, AccountsInterface {
Alexandre Savard2b370f02012-09-06 16:06:01 -040077 static final String TAG = "AccountManagementFragment";
Alexandre Savarda6c0d992012-09-28 09:24:13 -040078 static final String DEFAULT_ACCOUNT_ID = "IP2IP";
Alexandre Savard53d2ddd2012-09-30 22:04:40 -040079 static final int ACCOUNT_CREATE_REQUEST = 1;
Alexandre Savard68838112012-10-30 11:34:43 -040080 static final int ACCOUNT_EDIT_REQUEST = 2;
Alexandre Lision3ccccf02013-10-07 14:10:46 -040081 AccountsReceiver accountReceiver;
Alexandre Lision230d66e2013-10-22 12:32:12 -040082 AccountsAdapter mAccountsAdapter;
83 AccountsAdapter mIP2IPAdapter;
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -040084
85 DragSortListView mDnDListView;
86 private View mLoadingView;
87 private int mShortAnimationDuration;
88
Alexandre Lision4cf78702013-10-16 13:43:23 -040089 private DragSortListView.DropListener onDrop = new DragSortListView.DropListener() {
90 @Override
91 public void drop(int from, int to) {
92 if (from != to) {
Alexandre Lision230d66e2013-10-22 12:32:12 -040093 Account item = mAccountsAdapter.getItem(from);
94 mAccountsAdapter.remove(item);
95 mAccountsAdapter.insert(item, to);
Alexandre Lision4cf78702013-10-16 13:43:23 -040096 try {
Alexandre Lision230d66e2013-10-22 12:32:12 -040097 mCallbacks.getService().setAccountOrder(mAccountsAdapter.generateAccountOrder());
Alexandre Lision4cf78702013-10-16 13:43:23 -040098 } catch (RemoteException e) {
99 e.printStackTrace();
100 }
101 }
102 }
103
Alexandre Lision4cf78702013-10-16 13:43:23 -0400104 };
105
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400106 private Callbacks mCallbacks = sDummyCallbacks;
Alexandre Lision059da9d2013-10-22 11:17:25 -0400107 private Account ip2ip;
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400108 private static Callbacks sDummyCallbacks = new Callbacks() {
109
110 @Override
111 public ISipService getService() {
112 return null;
113 }
114 };
115
116 public interface Callbacks {
117
118 public ISipService getService();
119
120 }
Alexandre Savardae992932012-10-17 10:26:12 -0400121
Emeric Vigier1f1ced32012-11-02 16:56:32 -0400122 @Override
123 public void onAttach(Activity activity) {
124 super.onAttach(activity);
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400125 if (!(activity instanceof Callbacks)) {
126 throw new IllegalStateException("Activity must implement fragment's callbacks.");
127 }
128
129 mCallbacks = (Callbacks) activity;
Emeric Vigier1f1ced32012-11-02 16:56:32 -0400130 }
Alexandre Savard12dc3ac2012-09-27 11:17:39 -0400131
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400132 @Override
133 public void onDetach() {
134 super.onDetach();
135 mCallbacks = sDummyCallbacks;
alisiond9e29442013-04-17 16:10:18 -0400136 }
Alexandre Savard2b370f02012-09-06 16:06:01 -0400137
138 @Override
alisiond9e29442013-04-17 16:10:18 -0400139 public void onCreate(Bundle savedInstanceState) {
Alexandre Savard2b370f02012-09-06 16:06:01 -0400140 super.onCreate(savedInstanceState);
141
Alexandre Savard9a93f062012-09-11 10:42:43 -0400142 Log.i(TAG, "Create Account Management Fragment");
Alexandre Lision230d66e2013-10-22 12:32:12 -0400143 mAccountsAdapter = new AccountsAdapter(getActivity(), new ArrayList<Account>());
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400144 mIP2IPAdapter = new AccountsAdapter(getActivity(), new ArrayList<Account>());
Alexandre Lisiona764c682013-09-09 10:02:07 -0400145 this.setHasOptionsMenu(true);
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400146 accountReceiver = new AccountsReceiver(this);
Alexandre Lisiond16bad92013-10-09 17:16:20 -0400147
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400148 mShortAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);
149 Log.i(TAG,"anim time: "+ mShortAnimationDuration);
150
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400151 }
Alexandre Lisiona764c682013-09-09 10:02:07 -0400152
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400153 @Override
154 public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
Alexandre Lision4cf78702013-10-16 13:43:23 -0400155 View inflatedView = inflater.inflate(R.layout.frag_accounts_list, parent, false);
Alexandre Lision230d66e2013-10-22 12:32:12 -0400156 setListAdapter(mAccountsAdapter);
Alexandre Lision4cf78702013-10-16 13:43:23 -0400157
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400158 return inflatedView;
159 }
160
161 @Override
Alexandre Lision4cf78702013-10-16 13:43:23 -0400162 public DragSortListView getListView() {
163 return (DragSortListView) super.getListView();
164 }
165
166 @Override
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400167 public void onViewCreated(View view, Bundle savedInstanceState) {
168 super.onViewCreated(view, savedInstanceState);
Alexandre Lision4cf78702013-10-16 13:43:23 -0400169
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400170 mDnDListView = getListView();
171
172 mDnDListView.setDropListener(onDrop);
173 mDnDListView.setOnItemClickListener(new OnItemClickListener() {
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400174
175 @Override
176 public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
Alexandre Lision230d66e2013-10-22 12:32:12 -0400177 launchAccountEditActivity(mAccountsAdapter.getItem(pos));
Emeric Vigier0038a612012-11-06 18:51:19 -0500178 }
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400179 });
Alexandre Lision230d66e2013-10-22 12:32:12 -0400180
181 ((ListView) getView().findViewById(R.id.ip2ip)).setAdapter(mIP2IPAdapter);
182 ((ListView) getView().findViewById(R.id.ip2ip)).setOnItemClickListener(new OnItemClickListener() {
183
Alexandre Lision059da9d2013-10-22 11:17:25 -0400184 @Override
Alexandre Lision230d66e2013-10-22 12:32:12 -0400185 public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Alexandre Lision059da9d2013-10-22 11:17:25 -0400186 launchAccountEditActivity(ip2ip);
Alexandre Lision230d66e2013-10-22 12:32:12 -0400187
Alexandre Lision059da9d2013-10-22 11:17:25 -0400188 }
189 });
Alexandre Lision40954dc2013-10-09 15:24:03 -0400190
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400191
192 mLoadingView = view.findViewById(R.id.loading_spinner);
Alexandre Savard2b370f02012-09-06 16:06:01 -0400193 }
194
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400195 @Override
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400196 public void onPause() {
197 super.onPause();
198 getActivity().unregisterReceiver(accountReceiver);
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400199 }
200
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400201 public void onResume() {
202 super.onResume();
203 IntentFilter intentFilter2 = new IntentFilter();
204 intentFilter2.addAction(ConfigurationManagerCallback.ACCOUNT_STATE_CHANGED);
205 intentFilter2.addAction(ConfigurationManagerCallback.ACCOUNTS_CHANGED);
206 getActivity().registerReceiver(accountReceiver, intentFilter2);
Alexandre Lisiond16bad92013-10-09 17:16:20 -0400207 getActivity().getLoaderManager().restartLoader(LoaderConstants.ACCOUNTS_LOADER, null, this);
Alexandre Lision4cf78702013-10-16 13:43:23 -0400208
alisiona4325152013-04-19 11:10:03 -0400209 }
alision73424b62013-04-26 11:49:18 -0400210
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400211 @Override
Alexandre Lisiond2e9e062013-10-21 16:27:33 -0400212 public Loader<Bundle> onCreateLoader(int id, Bundle args) {
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400213 AccountsLoader l = new AccountsLoader(getActivity(), mCallbacks.getService());
Alexandre Lision4cf78702013-10-16 13:43:23 -0400214
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400215 l.forceLoad();
Alexandre Lision059da9d2013-10-22 11:17:25 -0400216
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400217 return l;
218 }
219
220 @Override
Alexandre Lision059da9d2013-10-22 11:17:25 -0400221 public void onLoadFinished(Loader<Bundle> loader, Bundle results) {
Alexandre Lision230d66e2013-10-22 12:32:12 -0400222 mAccountsAdapter.removeAll();
Alexandre Lision059da9d2013-10-22 11:17:25 -0400223 ArrayList<Account> tmp = results.getParcelableArrayList(AccountsLoader.ACCOUNTS);
224 ip2ip = results.getParcelable(AccountsLoader.ACCOUNT_IP2IP);
Alexandre Lision230d66e2013-10-22 12:32:12 -0400225 mAccountsAdapter.addAll(tmp);
226 mIP2IPAdapter.removeAll();
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400227 mIP2IPAdapter.insert(ip2ip, 0);
228 if(mAccountsAdapter.isEmpty()){
229 mDnDListView.setEmptyView(getView().findViewById(R.id.empty_account_list));
230 }
231 crossfade();
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400232 }
233
234 @Override
Alexandre Lisiond2e9e062013-10-21 16:27:33 -0400235 public void onLoaderReset(Loader<Bundle> arg0) {
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400236 // TODO Auto-generated method stub
237
238 }
239
Alexandre Lisiona764c682013-09-09 10:02:07 -0400240 @Override
241 public void onCreateOptionsMenu(Menu m, MenuInflater inf) {
242 super.onCreateOptionsMenu(m, inf);
243 inf.inflate(R.menu.account_creation, m);
244 }
245
246 @Override
247 public boolean onOptionsItemSelected(MenuItem item) {
248 super.onOptionsItemSelected(item);
249 switch (item.getItemId()) {
250 case R.id.menuitem_create:
251 Intent intent = new Intent().setClass(getActivity(), AccountWizard.class);
252 startActivityForResult(intent, ACCOUNT_CREATE_REQUEST);
253 break;
254 }
255
256 return true;
257 }
258
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400259 private void launchAccountEditActivity(Account acc) {
Alexandre Savard68838112012-10-30 11:34:43 -0400260 Log.i(TAG, "Launch account edit activity");
Alexandre Savard833616f2012-10-30 16:02:30 -0400261
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400262 Intent intent = new Intent().setClass(getActivity(), AccountEditionActivity.class);
263 Bundle bundle = new Bundle();
Alexandre Lisiond2e9e062013-10-21 16:27:33 -0400264 bundle.putParcelable("account", acc);
Alexandre Lision059da9d2013-10-22 11:17:25 -0400265
Alexandre Savard833616f2012-10-30 16:02:30 -0400266 intent.putExtras(bundle);
267
Alexandre Savard68838112012-10-30 11:34:43 -0400268 startActivityForResult(intent, ACCOUNT_EDIT_REQUEST);
269 }
270
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400271 @Override
272 public void accountsChanged() {
273 if (getActivity() != null)
274 getActivity().getLoaderManager().restartLoader(LoaderConstants.ACCOUNTS_LOADER, null, this);
Alexandre Savard52a72522012-09-27 16:40:13 -0400275 }
276
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400277 @Override
278 public void accountStateChanged(Intent accountState) {
Alexandre Lision230d66e2013-10-22 12:32:12 -0400279 mAccountsAdapter.updateAccount(accountState);
Alexandre Savard9a93f062012-09-11 10:42:43 -0400280 }
281
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400282 /**
283 *
284 * Adapter for accounts List
Alexandre Lision40954dc2013-10-09 15:24:03 -0400285 *
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400286 * @author lisional
Alexandre Lision40954dc2013-10-09 15:24:03 -0400287 *
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400288 */
289 public class AccountsAdapter extends BaseAdapter {
Alexandre Savard52a72522012-09-27 16:40:13 -0400290
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400291 // private static final String TAG = AccountSelectionAdapter.class.getSimpleName();
Alexandre Savard70982012012-09-27 17:15:50 -0400292
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400293 ArrayList<Account> accounts;
294 Context mContext;
Alexandre Savard70982012012-09-27 17:15:50 -0400295
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400296 public AccountsAdapter(Context cont, ArrayList<Account> newList) {
297 super();
298 accounts = newList;
299 mContext = cont;
Alexandre Savarde990d052012-10-18 14:43:09 -0400300 }
alisiond9e29442013-04-17 16:10:18 -0400301
Alexandre Lision4cf78702013-10-16 13:43:23 -0400302 public void insert(Account item, int to) {
303 accounts.add(to, item);
304 notifyDataSetChanged();
305 }
306
307 public void remove(Account item) {
308 accounts.remove(item);
309 notifyDataSetChanged();
310 }
Alexandre Lisiond2e9e062013-10-21 16:27:33 -0400311
Alexandre Lision4cf78702013-10-16 13:43:23 -0400312 @Override
Alexandre Lisiond2e9e062013-10-21 16:27:33 -0400313 public boolean hasStableIds() {
Alexandre Lision4cf78702013-10-16 13:43:23 -0400314 return true;
315 }
316
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400317 @Override
318 public int getCount() {
319 return accounts.size();
320 }
Alexandre Savard70982012012-09-27 17:15:50 -0400321
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400322 @Override
323 public Account getItem(int pos) {
324 return accounts.get(pos);
325 }
Alexandre Savard68838112012-10-30 11:34:43 -0400326
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400327 @Override
328 public long getItemId(int pos) {
329 return 0;
330 }
Alexandre Savard68838112012-10-30 11:34:43 -0400331
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400332 @Override
333 public View getView(final int pos, View convertView, ViewGroup parent) {
334 View rowView = convertView;
335 AccountView entryView = null;
Alexandre Savard68838112012-10-30 11:34:43 -0400336
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400337 if (rowView == null) {
338 LayoutInflater inflater = LayoutInflater.from(mContext);
339 rowView = inflater.inflate(R.layout.item_account_pref, null);
alisiond9e29442013-04-17 16:10:18 -0400340
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400341 entryView = new AccountView();
342 entryView.alias = (TextView) rowView.findViewById(R.id.account_alias);
343 entryView.host = (TextView) rowView.findViewById(R.id.account_host);
344 entryView.enabled = (CheckBox) rowView.findViewById(R.id.account_checked);
345 rowView.setTag(entryView);
346 } else {
347 entryView = (AccountView) rowView.getTag();
348 }
349
Alexandre Lision059da9d2013-10-22 11:17:25 -0400350 final Account item = accounts.get(pos);
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400351 entryView.alias.setText(accounts.get(pos).getAlias());
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400352 if (item.isIP2IP()) {
Alexandre Lision230d66e2013-10-22 12:32:12 -0400353 entryView.host.setText(item.getRegistered_state());
354 entryView.enabled.setVisibility(View.GONE);
355 } else {
356 entryView.host.setText(item.getHost() + " - " + item.getRegistered_state());
357 entryView.enabled.setChecked(item.isEnabled());
358 entryView.enabled.setOnClickListener(new OnClickListener() {
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400359
Alexandre Lision230d66e2013-10-22 12:32:12 -0400360 @Override
361 public void onClick(View v) {
362 item.setEnabled(!item.isEnabled());
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400363
Alexandre Lision230d66e2013-10-22 12:32:12 -0400364 try {
365 mCallbacks.getService().setAccountDetails(item.getAccountID(), item.getDetails());
366 } catch (RemoteException e) {
367 e.printStackTrace();
368 }
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400369 }
Alexandre Lision230d66e2013-10-22 12:32:12 -0400370 });
371 }
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400372
373 return rowView;
374 }
375
376 /*********************
377 * ViewHolder Pattern
378 *********************/
379 public class AccountView {
380 public TextView alias;
381 public TextView host;
382 public CheckBox enabled;
383 }
384
385 public void removeAll() {
386 accounts.clear();
387 notifyDataSetChanged();
388
389 }
390
391 public void addAll(ArrayList<Account> results) {
392 accounts.addAll(results);
393 notifyDataSetChanged();
394 }
395
396 /**
397 * Modify state of specific account
398 *
399 * @param accountState
400 */
401 public void updateAccount(Intent accountState) {
402 Log.i(TAG, "updateAccount");
403 String id = accountState.getStringExtra("Account");
404 String newState = accountState.getStringExtra("state");
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400405
406 for (Account a : accounts) {
407 if (a.getAccountID().contentEquals(id)) {
408 a.setRegistered_state(newState);
409 notifyDataSetChanged();
410 return;
411 }
412 }
413
414 }
Alexandre Lisiond2e9e062013-10-21 16:27:33 -0400415
Alexandre Lision4cf78702013-10-16 13:43:23 -0400416 private String generateAccountOrder() {
417 String result = DEFAULT_ACCOUNT_ID + File.separator;
418 for (Account a : accounts) {
419 result += a.getAccountID() + File.separator;
420 }
421 return result;
422 }
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400423
Alexandre Savard68838112012-10-30 11:34:43 -0400424 }
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400425
426 private void crossfade() {
427
428 // Set the content view to 0% opacity but visible, so that it is visible
429 // (but fully transparent) during the animation.
430 mDnDListView.setAlpha(0f);
431 mDnDListView.setVisibility(View.VISIBLE);
432
433 // Animate the content view to 100% opacity, and clear any animation
434 // listener set on the view.
435 mDnDListView.animate().alpha(1f).setDuration(mShortAnimationDuration).setListener(null);
436
437 // Animate the loading view to 0% opacity. After the animation ends,
438 // set its visibility to GONE as an optimization step (it won't
439 // participate in layout passes, etc.)
440 mLoadingView.animate().alpha(0f).setDuration(mShortAnimationDuration).setListener(new AnimatorListenerAdapter() {
441 @Override
442 public void onAnimationEnd(Animator animation) {
443 mLoadingView.setVisibility(View.GONE);
444 }
445 });
446 }
Alexandre Savard2b370f02012-09-06 16:06:01 -0400447}