mirror of
				https://github.com/nerzhul/ownCloud-SMS-App.git
				synced 2025-10-28 08:57:43 +00:00 
			
		
		
		
	Proper account list creation
This commit is contained in:
		
							parent
							
								
									d39e314707
								
							
						
					
					
						commit
						21c10614e2
					
				
							
								
								
									
										13
									
								
								res/layout/account_list_item.xml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								res/layout/account_list_item.xml
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,13 @@ | ||||
| <?xml version="1.0" encoding="utf-8"?> | ||||
| <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||
|     android:layout_width="match_parent" | ||||
|     android:layout_height="match_parent" > | ||||
|     <TextView | ||||
| 		android:id="@+id/accountname" | ||||
| 		android:layout_width="wrap_content" | ||||
| 		android:layout_height="wrap_content" | ||||
| 		android:padding="20dp" | ||||
| 		android:textSize="18sp" | ||||
|    /> | ||||
| 
 | ||||
| </RelativeLayout> | ||||
| @ -2,28 +2,41 @@ package fr.unix_experience.owncloud_sms.activities; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| 
 | ||||
| import android.accounts.Account; | ||||
| import android.accounts.AccountManager; | ||||
| import android.app.ListActivity; | ||||
| import android.os.Bundle; | ||||
| import android.widget.ArrayAdapter; | ||||
| import fr.unix_experience.owncloud_sms.R; | ||||
| import fr.unix_experience.owncloud_sms.adapters.AndroidAccountAdapter; | ||||
| 
 | ||||
| public class RestoreSMSAccountListActivity extends ListActivity { | ||||
| 	ArrayList<String> listItems = new ArrayList<String>(); | ||||
| 	ArrayAdapter<String> adapter; | ||||
| 	ArrayList<Account> listItems = new ArrayList<Account>(); | ||||
| 	AndroidAccountAdapter adapter; | ||||
| 
 | ||||
| 	private static String _accountType; | ||||
| 	private static AccountManager _accountMgr; | ||||
| 
 | ||||
| 	@Override | ||||
| 	public void onCreate(final Bundle icicle) { | ||||
| 		super.onCreate(icicle); | ||||
| 
 | ||||
| 		_accountType = getString(R.string.account_type); | ||||
| 		_accountMgr = AccountManager.get(getBaseContext()); | ||||
| 
 | ||||
| 		setContentView(R.layout.restore_activity_accountlist); | ||||
| 		adapter = new ArrayAdapter<String>(this, | ||||
| 		adapter = new AndroidAccountAdapter(this, | ||||
| 				android.R.layout.simple_list_item_1, | ||||
| 				listItems); | ||||
| 				listItems, | ||||
| 				R.layout.account_list_item, | ||||
| 				R.id.accountname); | ||||
| 		setListAdapter(adapter); | ||||
| 
 | ||||
| 		listItems.add("test"); | ||||
| 		listItems.add("test2"); | ||||
| 		listItems.add("test3"); | ||||
| 		listItems.add("test4s"); | ||||
| 		final Account[] myAccountList = _accountMgr.getAccountsByType(_accountType); | ||||
| 		for (final Account element : myAccountList) { | ||||
| 			listItems.add(element); | ||||
| 		} | ||||
| 
 | ||||
| 
 | ||||
| 		adapter.notifyDataSetChanged(); | ||||
| 	} | ||||
| } | ||||
|  | ||||
| @ -0,0 +1,47 @@ | ||||
| package fr.unix_experience.owncloud_sms.adapters; | ||||
| 
 | ||||
| import java.util.ArrayList; | ||||
| 
 | ||||
| import android.accounts.Account; | ||||
| import android.content.Context; | ||||
| import android.view.LayoutInflater; | ||||
| import android.view.View; | ||||
| import android.view.ViewGroup; | ||||
| import android.widget.ArrayAdapter; | ||||
| import android.widget.TextView; | ||||
| 
 | ||||
| public class AndroidAccountAdapter extends ArrayAdapter<Account> { | ||||
| 
 | ||||
| 	private final ArrayList<Account> _accounts; | ||||
| 	private static int _itemLayout; | ||||
| 	private static int _accountFieldId; | ||||
| 
 | ||||
| 	public AndroidAccountAdapter(final Context context, final int resource, | ||||
| 			final ArrayList<Account> objects, final int itemLayout, final int accountFieldId) { | ||||
| 		super(context, resource, objects); | ||||
| 		_accounts = objects; | ||||
| 		_itemLayout = itemLayout; | ||||
| 		_accountFieldId = accountFieldId; | ||||
| 	} | ||||
| 
 | ||||
| 	@Override | ||||
| 	public View getView(final int position, final View convertView, final ViewGroup parent) { | ||||
| 		View v = convertView; | ||||
| 		if (v == null) { | ||||
| 			final LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); | ||||
| 			v = inflater.inflate(_itemLayout, null); | ||||
| 		} | ||||
| 
 | ||||
| 		final Account account = _accounts.get(position); | ||||
| 
 | ||||
| 		if (account != null) { | ||||
| 			final TextView label = (TextView) v.findViewById(_accountFieldId); | ||||
| 			if (label != null) { | ||||
| 				label.setText(account.name + "  -->"); | ||||
| 			} | ||||
| 		} | ||||
| 
 | ||||
| 		return v; | ||||
| 	} | ||||
| 
 | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user