1 package eu
.alefzero
.owncloud
.ui
.activity
;
3 import java
.util
.HashMap
;
4 import java
.util
.LinkedList
;
8 import android
.accounts
.Account
;
9 import android
.accounts
.AccountManager
;
10 import android
.content
.Context
;
11 import android
.content
.Intent
;
12 import android
.os
.Bundle
;
13 import android
.view
.View
;
14 import android
.view
.ViewGroup
;
15 import android
.widget
.CheckedTextView
;
16 import android
.widget
.ListView
;
17 import android
.widget
.SimpleAdapter
;
18 import android
.widget
.TextView
;
20 import com
.actionbarsherlock
.app
.ActionBar
;
21 import com
.actionbarsherlock
.app
.SherlockListActivity
;
22 import com
.actionbarsherlock
.view
.Menu
;
23 import com
.actionbarsherlock
.view
.MenuInflater
;
24 import com
.actionbarsherlock
.view
.MenuItem
;
26 import eu
.alefzero
.owncloud
.authenticator
.AccountAuthenticator
;
27 import eu
.alefzero
.owncloud
.AccountUtils
;
28 import eu
.alefzero
.owncloud
.R
;
30 public class AccountSelectActivity
extends SherlockListActivity
{
33 protected void onCreate(Bundle savedInstanceState
) {
34 super.onCreate(savedInstanceState
);
36 ActionBar action_bar
= getSupportActionBar();
37 action_bar
.setDisplayShowTitleEnabled(true
);
38 action_bar
.setDisplayHomeAsUpEnabled(false
);
42 protected void onResume() {
45 AccountManager am
= (AccountManager
) getSystemService(ACCOUNT_SERVICE
);
46 Account accounts
[] = am
.getAccountsByType(AccountAuthenticator
.ACCOUNT_TYPE
);
47 LinkedList
< HashMap
<String
, String
>> ll
= new LinkedList
<HashMap
<String
,String
>>();
48 for (Account a
: accounts
) {
49 HashMap
<String
, String
> h
= new HashMap
<String
, String
>();
50 h
.put("NAME", a
.name
);
51 h
.put("VER", "ownCloud version: " + am
.getUserData(a
, AccountAuthenticator
.KEY_OC_VERSION
));
55 setListAdapter(new AccountCheckedSimpleAdepter(this,
57 android
.R
.layout
.simple_list_item_single_choice
,
59 new int[]{android
.R
.id
.text1
}));
63 public boolean onCreateOptionsMenu(Menu menu
) {
64 MenuInflater inflater
= getSherlock().getMenuInflater();
65 inflater
.inflate(eu
.alefzero
.owncloud
.R
.menu
.account_picker
, menu
);
70 protected void onListItemClick(ListView l
, View v
, int position
, long id
) {
71 String accountName
= ((TextView
)v
.findViewById(android
.R
.id
.text1
)).getText().toString();
72 AccountUtils
.setCurrentOwnCloudAccount(this, accountName
);
73 Intent i
= new Intent(this, FileDisplayActivity
.class);
79 public boolean onMenuItemSelected(int featureId
, MenuItem item
) {
80 if (item
.getItemId() == R
.id
.createAccount
) {
81 Intent intent
= new Intent(android
.provider
.Settings
.ACTION_ADD_ACCOUNT
);
82 intent
.putExtra("authorities",
83 new String
[] { AccountAuthenticator
.AUTH_TOKEN_TYPE
});
84 startActivity(intent
);
90 private class AccountCheckedSimpleAdepter
extends SimpleAdapter
{
91 private Account mCurrentAccount
;
92 private List
<?
extends Map
<String
, ?
>> mPrivateData
;
94 public AccountCheckedSimpleAdepter(Context context
,
95 List
<?
extends Map
<String
, ?
>> data
,
99 super(context
, data
, resource
, from
, to
);
100 mCurrentAccount
= AccountUtils
.getCurrentOwnCloudAccount(AccountSelectActivity
.this);
105 public View
getView(int position
, View convertView
, ViewGroup parent
) {
106 View v
= super.getView(position
, convertView
, parent
);
107 CheckedTextView ctv
= (CheckedTextView
) v
.findViewById(android
.R
.id
.text1
);
108 if (mPrivateData
.get(position
).get("NAME").equals(mCurrentAccount
.name
)) {
109 ctv
.setChecked(true
);