blob: f68d9b4259b56b8266d3f85bd93be5813b261295 [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 Lisiond2e9e062013-10-21 16:27:33 -040076public class AccountManagementFragment 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;
Alexandre Lision059da9d2013-10-22 11:17:25 -0400130 getActivity().getLoaderManager().restartLoader(LoaderConstants.ACCOUNTS_LOADER, null, this);
Emeric Vigier1f1ced32012-11-02 16:56:32 -0400131 }
Alexandre Savard12dc3ac2012-09-27 11:17:39 -0400132
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400133 @Override
134 public void onDetach() {
135 super.onDetach();
136 mCallbacks = sDummyCallbacks;
alisiond9e29442013-04-17 16:10:18 -0400137 }
Alexandre Savard2b370f02012-09-06 16:06:01 -0400138
139 @Override
alisiond9e29442013-04-17 16:10:18 -0400140 public void onCreate(Bundle savedInstanceState) {
Alexandre Savard2b370f02012-09-06 16:06:01 -0400141 super.onCreate(savedInstanceState);
142
Alexandre Savard9a93f062012-09-11 10:42:43 -0400143 Log.i(TAG, "Create Account Management Fragment");
Alexandre Lision230d66e2013-10-22 12:32:12 -0400144 mAccountsAdapter = new AccountsAdapter(getActivity(), new ArrayList<Account>());
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400145 mIP2IPAdapter = new AccountsAdapter(getActivity(), new ArrayList<Account>());
Alexandre Lisiona764c682013-09-09 10:02:07 -0400146 this.setHasOptionsMenu(true);
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400147 accountReceiver = new AccountsReceiver(this);
Alexandre Lisiond16bad92013-10-09 17:16:20 -0400148
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400149 mShortAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime);
150 Log.i(TAG,"anim time: "+ mShortAnimationDuration);
151
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400152 }
Alexandre Lisiona764c682013-09-09 10:02:07 -0400153
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400154 @Override
155 public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
Alexandre Lision4cf78702013-10-16 13:43:23 -0400156 View inflatedView = inflater.inflate(R.layout.frag_accounts_list, parent, false);
Alexandre Lision230d66e2013-10-22 12:32:12 -0400157 setListAdapter(mAccountsAdapter);
Alexandre Lision4cf78702013-10-16 13:43:23 -0400158
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400159 return inflatedView;
160 }
161
162 @Override
Alexandre Lision4cf78702013-10-16 13:43:23 -0400163 public DragSortListView getListView() {
164 return (DragSortListView) super.getListView();
165 }
166
167 @Override
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400168 public void onViewCreated(View view, Bundle savedInstanceState) {
169 super.onViewCreated(view, savedInstanceState);
Alexandre Lision4cf78702013-10-16 13:43:23 -0400170
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400171 mDnDListView = getListView();
172
173 mDnDListView.setDropListener(onDrop);
174 mDnDListView.setOnItemClickListener(new OnItemClickListener() {
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400175
176 @Override
177 public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
Alexandre Lision230d66e2013-10-22 12:32:12 -0400178 launchAccountEditActivity(mAccountsAdapter.getItem(pos));
Emeric Vigier0038a612012-11-06 18:51:19 -0500179 }
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400180 });
Alexandre Lision230d66e2013-10-22 12:32:12 -0400181
182 ((ListView) getView().findViewById(R.id.ip2ip)).setAdapter(mIP2IPAdapter);
183 ((ListView) getView().findViewById(R.id.ip2ip)).setOnItemClickListener(new OnItemClickListener() {
184
Alexandre Lision059da9d2013-10-22 11:17:25 -0400185 @Override
Alexandre Lision230d66e2013-10-22 12:32:12 -0400186 public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
Alexandre Lision059da9d2013-10-22 11:17:25 -0400187 launchAccountEditActivity(ip2ip);
Alexandre Lision230d66e2013-10-22 12:32:12 -0400188
Alexandre Lision059da9d2013-10-22 11:17:25 -0400189 }
190 });
Alexandre Lision40954dc2013-10-09 15:24:03 -0400191
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400192
193 mLoadingView = view.findViewById(R.id.loading_spinner);
Alexandre Savard2b370f02012-09-06 16:06:01 -0400194 }
195
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400196 @Override
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400197 public void onPause() {
198 super.onPause();
199 getActivity().unregisterReceiver(accountReceiver);
Alexandre Savard8b7d4332012-09-30 20:02:11 -0400200 }
201
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400202 public void onResume() {
203 super.onResume();
204 IntentFilter intentFilter2 = new IntentFilter();
205 intentFilter2.addAction(ConfigurationManagerCallback.ACCOUNT_STATE_CHANGED);
206 intentFilter2.addAction(ConfigurationManagerCallback.ACCOUNTS_CHANGED);
207 getActivity().registerReceiver(accountReceiver, intentFilter2);
Alexandre Lisiond16bad92013-10-09 17:16:20 -0400208 getActivity().getLoaderManager().restartLoader(LoaderConstants.ACCOUNTS_LOADER, null, this);
Alexandre Lision4cf78702013-10-16 13:43:23 -0400209
alisiona4325152013-04-19 11:10:03 -0400210 }
alision73424b62013-04-26 11:49:18 -0400211
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400212 @Override
Alexandre Lisiond2e9e062013-10-21 16:27:33 -0400213 public Loader<Bundle> onCreateLoader(int id, Bundle args) {
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400214 AccountsLoader l = new AccountsLoader(getActivity(), mCallbacks.getService());
Alexandre Lision4cf78702013-10-16 13:43:23 -0400215
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400216 l.forceLoad();
Alexandre Lision059da9d2013-10-22 11:17:25 -0400217
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400218 return l;
219 }
220
221 @Override
Alexandre Lision059da9d2013-10-22 11:17:25 -0400222 public void onLoadFinished(Loader<Bundle> loader, Bundle results) {
Alexandre Lision230d66e2013-10-22 12:32:12 -0400223 mAccountsAdapter.removeAll();
Alexandre Lision059da9d2013-10-22 11:17:25 -0400224 ArrayList<Account> tmp = results.getParcelableArrayList(AccountsLoader.ACCOUNTS);
225 ip2ip = results.getParcelable(AccountsLoader.ACCOUNT_IP2IP);
Alexandre Lision230d66e2013-10-22 12:32:12 -0400226 mAccountsAdapter.addAll(tmp);
227 mIP2IPAdapter.removeAll();
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400228 mIP2IPAdapter.insert(ip2ip, 0);
229 if(mAccountsAdapter.isEmpty()){
230 mDnDListView.setEmptyView(getView().findViewById(R.id.empty_account_list));
231 }
232 crossfade();
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400233 }
234
235 @Override
Alexandre Lisiond2e9e062013-10-21 16:27:33 -0400236 public void onLoaderReset(Loader<Bundle> arg0) {
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400237 // TODO Auto-generated method stub
238
239 }
240
Alexandre Lisiona764c682013-09-09 10:02:07 -0400241 @Override
242 public void onCreateOptionsMenu(Menu m, MenuInflater inf) {
243 super.onCreateOptionsMenu(m, inf);
244 inf.inflate(R.menu.account_creation, m);
245 }
246
247 @Override
248 public boolean onOptionsItemSelected(MenuItem item) {
249 super.onOptionsItemSelected(item);
250 switch (item.getItemId()) {
251 case R.id.menuitem_create:
252 Intent intent = new Intent().setClass(getActivity(), AccountWizard.class);
253 startActivityForResult(intent, ACCOUNT_CREATE_REQUEST);
254 break;
255 }
256
257 return true;
258 }
259
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400260 private void launchAccountEditActivity(Account acc) {
Alexandre Savard68838112012-10-30 11:34:43 -0400261 Log.i(TAG, "Launch account edit activity");
Alexandre Savard833616f2012-10-30 16:02:30 -0400262
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400263 Intent intent = new Intent().setClass(getActivity(), AccountEditionActivity.class);
264 Bundle bundle = new Bundle();
Alexandre Lisiond2e9e062013-10-21 16:27:33 -0400265 bundle.putParcelable("account", acc);
Alexandre Lision059da9d2013-10-22 11:17:25 -0400266
Alexandre Savard833616f2012-10-30 16:02:30 -0400267 intent.putExtras(bundle);
268
Alexandre Savard68838112012-10-30 11:34:43 -0400269 startActivityForResult(intent, ACCOUNT_EDIT_REQUEST);
270 }
271
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400272 @Override
273 public void accountsChanged() {
274 if (getActivity() != null)
275 getActivity().getLoaderManager().restartLoader(LoaderConstants.ACCOUNTS_LOADER, null, this);
Alexandre Savard52a72522012-09-27 16:40:13 -0400276 }
277
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400278 @Override
279 public void accountStateChanged(Intent accountState) {
Alexandre Lision230d66e2013-10-22 12:32:12 -0400280 mAccountsAdapter.updateAccount(accountState);
Alexandre Savard9a93f062012-09-11 10:42:43 -0400281 }
282
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400283 /**
284 *
285 * Adapter for accounts List
Alexandre Lision40954dc2013-10-09 15:24:03 -0400286 *
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400287 * @author lisional
Alexandre Lision40954dc2013-10-09 15:24:03 -0400288 *
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400289 */
290 public class AccountsAdapter extends BaseAdapter {
Alexandre Savard52a72522012-09-27 16:40:13 -0400291
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400292 // private static final String TAG = AccountSelectionAdapter.class.getSimpleName();
Alexandre Savard70982012012-09-27 17:15:50 -0400293
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400294 ArrayList<Account> accounts;
295 Context mContext;
Alexandre Savard70982012012-09-27 17:15:50 -0400296
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400297 public AccountsAdapter(Context cont, ArrayList<Account> newList) {
298 super();
299 accounts = newList;
300 mContext = cont;
Alexandre Savarde990d052012-10-18 14:43:09 -0400301 }
alisiond9e29442013-04-17 16:10:18 -0400302
Alexandre Lision4cf78702013-10-16 13:43:23 -0400303 public void insert(Account item, int to) {
304 accounts.add(to, item);
305 notifyDataSetChanged();
306 }
307
308 public void remove(Account item) {
309 accounts.remove(item);
310 notifyDataSetChanged();
311 }
Alexandre Lisiond2e9e062013-10-21 16:27:33 -0400312
Alexandre Lision4cf78702013-10-16 13:43:23 -0400313 @Override
Alexandre Lisiond2e9e062013-10-21 16:27:33 -0400314 public boolean hasStableIds() {
Alexandre Lision4cf78702013-10-16 13:43:23 -0400315 return true;
316 }
317
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400318 @Override
319 public int getCount() {
320 return accounts.size();
321 }
Alexandre Savard70982012012-09-27 17:15:50 -0400322
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400323 @Override
324 public Account getItem(int pos) {
325 return accounts.get(pos);
326 }
Alexandre Savard68838112012-10-30 11:34:43 -0400327
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400328 @Override
329 public long getItemId(int pos) {
330 return 0;
331 }
Alexandre Savard68838112012-10-30 11:34:43 -0400332
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400333 @Override
334 public View getView(final int pos, View convertView, ViewGroup parent) {
335 View rowView = convertView;
336 AccountView entryView = null;
Alexandre Savard68838112012-10-30 11:34:43 -0400337
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400338 if (rowView == null) {
339 LayoutInflater inflater = LayoutInflater.from(mContext);
340 rowView = inflater.inflate(R.layout.item_account_pref, null);
alisiond9e29442013-04-17 16:10:18 -0400341
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400342 entryView = new AccountView();
343 entryView.alias = (TextView) rowView.findViewById(R.id.account_alias);
344 entryView.host = (TextView) rowView.findViewById(R.id.account_host);
345 entryView.enabled = (CheckBox) rowView.findViewById(R.id.account_checked);
346 rowView.setTag(entryView);
347 } else {
348 entryView = (AccountView) rowView.getTag();
349 }
350
Alexandre Lision059da9d2013-10-22 11:17:25 -0400351 final Account item = accounts.get(pos);
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400352 entryView.alias.setText(accounts.get(pos).getAlias());
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400353 if (item.isIP2IP()) {
Alexandre Lision230d66e2013-10-22 12:32:12 -0400354 entryView.host.setText(item.getRegistered_state());
355 entryView.enabled.setVisibility(View.GONE);
356 } else {
357 entryView.host.setText(item.getHost() + " - " + item.getRegistered_state());
358 entryView.enabled.setChecked(item.isEnabled());
359 entryView.enabled.setOnClickListener(new OnClickListener() {
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400360
Alexandre Lision230d66e2013-10-22 12:32:12 -0400361 @Override
362 public void onClick(View v) {
363 item.setEnabled(!item.isEnabled());
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400364
Alexandre Lision230d66e2013-10-22 12:32:12 -0400365 try {
366 mCallbacks.getService().setAccountDetails(item.getAccountID(), item.getDetails());
367 } catch (RemoteException e) {
368 e.printStackTrace();
369 }
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400370 }
Alexandre Lision230d66e2013-10-22 12:32:12 -0400371 });
372 }
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400373
374 return rowView;
375 }
376
377 /*********************
378 * ViewHolder Pattern
379 *********************/
380 public class AccountView {
381 public TextView alias;
382 public TextView host;
383 public CheckBox enabled;
384 }
385
386 public void removeAll() {
387 accounts.clear();
388 notifyDataSetChanged();
389
390 }
391
392 public void addAll(ArrayList<Account> results) {
393 accounts.addAll(results);
394 notifyDataSetChanged();
395 }
396
397 /**
398 * Modify state of specific account
399 *
400 * @param accountState
401 */
402 public void updateAccount(Intent accountState) {
403 Log.i(TAG, "updateAccount");
404 String id = accountState.getStringExtra("Account");
405 String newState = accountState.getStringExtra("state");
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400406
407 for (Account a : accounts) {
408 if (a.getAccountID().contentEquals(id)) {
409 a.setRegistered_state(newState);
410 notifyDataSetChanged();
411 return;
412 }
413 }
414
415 }
Alexandre Lisiond2e9e062013-10-21 16:27:33 -0400416
Alexandre Lision4cf78702013-10-16 13:43:23 -0400417 private String generateAccountOrder() {
418 String result = DEFAULT_ACCOUNT_ID + File.separator;
419 for (Account a : accounts) {
420 result += a.getAccountID() + File.separator;
421 }
422 return result;
423 }
Alexandre Lision3ccccf02013-10-07 14:10:46 -0400424
Alexandre Savard68838112012-10-30 11:34:43 -0400425 }
Alexandre Lisionef2aa9e2013-10-25 16:22:52 -0400426
427 private void crossfade() {
428
429 // Set the content view to 0% opacity but visible, so that it is visible
430 // (but fully transparent) during the animation.
431 mDnDListView.setAlpha(0f);
432 mDnDListView.setVisibility(View.VISIBLE);
433
434 // Animate the content view to 100% opacity, and clear any animation
435 // listener set on the view.
436 mDnDListView.animate().alpha(1f).setDuration(mShortAnimationDuration).setListener(null);
437
438 // Animate the loading view to 0% opacity. After the animation ends,
439 // set its visibility to GONE as an optimization step (it won't
440 // participate in layout passes, etc.)
441 mLoadingView.animate().alpha(0f).setDuration(mShortAnimationDuration).setListener(new AnimatorListenerAdapter() {
442 @Override
443 public void onAnimationEnd(Animator animation) {
444 mLoadingView.setVisibility(View.GONE);
445 }
446 });
447 }
Alexandre Savard2b370f02012-09-06 16:06:01 -0400448}