Revision fea03400 src/com/rackspacecloud/android/ListAccountsActivity.java
b/src/com/rackspacecloud/android/ListAccountsActivity.java | ||
---|---|---|
26 | 26 |
import android.os.AsyncTask; |
27 | 27 |
import android.os.Bundle; |
28 | 28 |
import android.util.Log; |
29 |
import android.view.ContextMenu; |
|
30 |
import android.view.ContextMenu.ContextMenuInfo; |
|
29 | 31 |
import android.view.LayoutInflater; |
30 | 32 |
import android.view.Menu; |
31 | 33 |
import android.view.MenuInflater; |
32 | 34 |
import android.view.MenuItem; |
33 | 35 |
import android.view.View; |
34 | 36 |
import android.view.ViewGroup; |
37 |
import android.widget.AdapterView.AdapterContextMenuInfo; |
|
35 | 38 |
import android.widget.ArrayAdapter; |
36 | 39 |
import android.widget.ImageView; |
37 | 40 |
import android.widget.ListView; |
38 |
import android.widget.ProgressBar; |
|
39 | 41 |
import android.widget.TextView; |
40 | 42 |
|
41 | 43 |
public class ListAccountsActivity extends ListActivity{ |
... | ... | |
49 | 51 |
public void onCreate(Bundle savedInstanceState) { |
50 | 52 |
super.onCreate(savedInstanceState); |
51 | 53 |
restoreState(savedInstanceState); |
54 |
registerForContextMenu(getListView()); |
|
52 | 55 |
tabViewIntent = new Intent(this, TabViewActivity.class); |
53 | 56 |
} |
54 | 57 |
|
... | ... | |
79 | 82 |
} |
80 | 83 |
|
81 | 84 |
private void loadAccounts() { |
85 |
if(accounts != null) |
|
86 |
Log.d("loadAccounts", "captin the lenght is: " + accounts.size()); |
|
87 |
//check and see if there are any in memory |
|
82 | 88 |
if(accounts == null){ |
83 | 89 |
accounts = readAccounts(); |
84 | 90 |
} |
... | ... | |
86 | 92 |
if(accounts == null){ |
87 | 93 |
accounts = new ArrayList<Account>(); |
88 | 94 |
} |
95 |
Log.d("loadAccounts2", "captin the lenght is: " + accounts.size()); |
|
96 |
|
|
89 | 97 |
setAccountList(); |
90 | 98 |
} |
91 | 99 |
|
... | ... | |
162 | 170 |
} |
163 | 171 |
} |
164 | 172 |
|
165 |
protected void onListItemLongPress(ListView l, View v, int position, long id) { |
|
166 |
if (accounts != null && accounts.size() > 0) { |
|
167 |
setActivityIndicatorsVisibility(View.VISIBLE, v); |
|
168 |
accounts.remove(position); |
|
169 |
loadAccounts(); |
|
170 |
} |
|
171 |
} |
|
172 |
|
|
173 | 173 |
public void login() { |
174 | 174 |
//showActivityIndicators(); |
175 | 175 |
//setLoginPreferences(); |
... | ... | |
177 | 177 |
new AuthenticateTask().execute((Void[]) null); |
178 | 178 |
} |
179 | 179 |
|
180 |
|
|
180 |
//setup menu for when menu button is pressed |
|
181 | 181 |
public boolean onCreateOptionsMenu(Menu menu) { |
182 | 182 |
super.onCreateOptionsMenu(menu); |
183 | 183 |
MenuInflater inflater = getMenuInflater(); |
... | ... | |
186 | 186 |
} |
187 | 187 |
|
188 | 188 |
@Override |
189 |
//in options menu, when add account is selected go to add account activity |
|
189 | 190 |
public boolean onOptionsItemSelected(MenuItem item) { |
190 | 191 |
switch (item.getItemId()) { |
191 | 192 |
case R.id.add_account: |
... | ... | |
195 | 196 |
return false; |
196 | 197 |
} |
197 | 198 |
|
199 |
//the context menu for a long press on an account |
|
200 |
public void onCreateContextMenu(ContextMenu menu, View v, |
|
201 |
ContextMenuInfo menuInfo) { |
|
202 |
super.onCreateContextMenu(menu, v, menuInfo); |
|
203 |
MenuInflater inflater = getMenuInflater(); |
|
204 |
inflater.inflate(R.menu.account_context_menu, menu); |
|
205 |
} |
|
206 |
|
|
207 |
//removes the selected account from account list if remove is clicked |
|
208 |
public boolean onContextItemSelected(MenuItem item) { |
|
209 |
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo(); |
|
210 |
accounts.remove(info.position); |
|
211 |
writeAccounts(); |
|
212 |
loadAccounts(); |
|
213 |
return true; |
|
214 |
} |
|
215 |
|
|
198 | 216 |
class AccountAdapter extends ArrayAdapter<Account> { |
199 | 217 |
|
200 | 218 |
AccountAdapter() { |
... | ... | |
361 | 379 |
hideActivityIndicators(); |
362 | 380 |
} |
363 | 381 |
|
364 |
|
|
365 | 382 |
|
366 | 383 |
} |
Also available in: Unified diff