1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-14 05:25:07 -05:00

This add a new setup screen. It displays all accounts found on the device. It's made to be extended with accounts from the backup files ( commented where this code should go ).

This commit is contained in:
Sander Bogaert 2011-06-23 22:40:36 +02:00 committed by Andrew Chen
parent 5804b617b6
commit ee020ed4b9
8 changed files with 321 additions and 10 deletions

View File

@ -102,6 +102,12 @@
android:configChanges="locale" android:configChanges="locale"
> >
</activity> </activity>
<activity
android:name="com.fsck.k9.activity.setup.AccountSetupIndex"
android:label="@string/account_setup_basics_title"
android:configChanges="locale"
>
</activity>
<activity <activity
android:name="com.fsck.k9.activity.setup.AccountSetupAccountType" android:name="com.fsck.k9.activity.setup.AccountSetupAccountType"
android:label="@string/account_setup_account_type_title" android:label="@string/account_setup_account_type_title"

View File

@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:padding="15dp">
<TextView android:id="@+id/help_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/accounts_setup_help"
android:layout_marginBottom="10dp"/>
<Button android:id="@+id/new_account"
android:text="@string/account_setup_basics_other_acount"
android:minWidth="@dimen/button_minWidth"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_below="@id/help_text"
android:layout_centerHorizontal="true"/>
</RelativeLayout>
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:textSize="16sp"
android:background="#AAA">
</TextView>

View File

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dp"
android:layout_marginLeft="5dp"
android:textSize="16sp" >
</TextView>

View File

@ -347,6 +347,10 @@ http://k9mail.googlecode.com/
<string name="quiet_time_ends">Quiet Time ends</string> <string name="quiet_time_ends">Quiet Time ends</string>
<string name="account_setup_basics_title">Set up a new account</string> <string name="account_setup_basics_title">Set up a new account</string>
<string name="account_setup_basics_other_acount">Other account</string>
<string name="accounts_setup_help">
Select an account here to setup, press menu to load more backup files or create an new account.
</string>
<string name="account_setup_basics_instructions">Enter this account\'s email address:</string> <string name="account_setup_basics_instructions">Enter this account\'s email address:</string>
<string name="account_setup_basics_email_hint">Email address</string> <string name="account_setup_basics_email_hint">Email address</string>
<string name="account_setup_basics_password_hint">Password</string> <string name="account_setup_basics_password_hint">Password</string>

View File

@ -59,17 +59,11 @@ import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemClickListener;
import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.CompoundButton.OnCheckedChangeListener;
import com.fsck.k9.Account; import com.fsck.k9.*;
import com.fsck.k9.AccountStats;
import com.fsck.k9.BaseAccount;
import com.fsck.k9.FontSizes;
import com.fsck.k9.K9;
import com.fsck.k9.Preferences;
import com.fsck.k9.R;
import com.fsck.k9.SearchAccount;
import com.fsck.k9.SearchSpecification;
import com.fsck.k9.activity.misc.ExtendedAsyncTask; import com.fsck.k9.activity.misc.ExtendedAsyncTask;
import com.fsck.k9.activity.misc.NonConfigurationInstance; import com.fsck.k9.activity.misc.NonConfigurationInstance;
import com.fsck.k9.activity.setup.AccountSetupIndex;
import com.fsck.k9.helper.SizeFormatter;
import com.fsck.k9.activity.setup.AccountSettings; import com.fsck.k9.activity.setup.AccountSettings;
import com.fsck.k9.activity.setup.AccountSetupBasics; import com.fsck.k9.activity.setup.AccountSetupBasics;
import com.fsck.k9.activity.setup.Prefs; import com.fsck.k9.activity.setup.Prefs;
@ -515,7 +509,7 @@ public class Accounts extends K9ListActivity implements OnItemClickListener, OnC
} }
private void onAddNewAccount() { private void onAddNewAccount() {
AccountSetupBasics.actionNewAccount(this); AccountSetupIndex.actionNewAccount(this);
} }
private void onEditAccount(Account account) { private void onEditAccount(Account account) {

View File

@ -0,0 +1,127 @@
package com.fsck.k9.activity.setup;
import android.accounts.AccountManager;
import android.content.Context;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.*;
import android.widget.AdapterView.OnItemClickListener;
import com.fsck.k9.EmailAddressValidator;
import com.fsck.k9.R;
import com.fsck.k9.activity.K9ListActivity;
import com.fsck.k9.helper.SectionListAdapter;
import static com.fsck.k9.activity.setup.AccountSetupBasics.*;
/**
* User: dzan
* Date: 18/06/11
*/
public class AccountSetupIndex extends K9ListActivity implements OnItemClickListener, OnClickListener {
private static final String DEVICE_STRING = "Device";
public enum SuggestionType { DEVICE, BACKUP, NEW }
public static void actionNewAccount(Context context) {
Intent i = new Intent(context, AccountSetupIndex.class);
context.startActivity(i);
}
private Button mNewAccountButton;
private SectionListAdapter<AccountSuggestion> accountAdapter;
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
// layout
setContentView(R.layout.account_setup_index);
mNewAccountButton = (Button)findViewById(R.id.new_account);
// button callbacks
mNewAccountButton.setOnClickListener(this);
// creating the adaptor and start filling it
accountAdapter = new SectionListAdapter<AccountSuggestion>(this,
R.layout.account_setup_index_list_header,
R.layout.account_setup_index_list_item);
fillFromDevice(accountAdapter);
new BackupScan().execute();
// configuring the view
ListView listView = getListView();
listView.setOnItemClickListener(this);
listView.setAdapter(accountAdapter);
}
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
Toast.LENGTH_SHORT).show();
}
public void onClick(View view) {
switch (view.getId()) {
case R.id.new_account:
onNew();
break;
}
}
protected void onNew() {
AccountSetupBasics.actionNewAccount(this);
}
/*
Scans device for email addresses and adds them as suggestions
*/
private void fillFromDevice(SectionListAdapter<AccountSuggestion> adp){
EmailAddressValidator mEmailValidator = new EmailAddressValidator();
for( android.accounts.Account acc : AccountManager.get(this).getAccounts() )
if( mEmailValidator.isValidAddressOnly(acc.name) )
adp.add(DEVICE_STRING, new AccountSuggestion(acc.name, SuggestionType.DEVICE));
// TEMP DATA TO TEST
accountAdapter.add("file1", new AccountSuggestion("piet@snot.com",SuggestionType.BACKUP));
accountAdapter.add("file1", new AccountSuggestion("piet@snot.com",SuggestionType.BACKUP));
accountAdapter.add("file1", new AccountSuggestion("piet@snot.com",SuggestionType.BACKUP));
accountAdapter.add("file2", new AccountSuggestion("piet@snot.com",SuggestionType.BACKUP));
accountAdapter.add("file2", new AccountSuggestion("piet@snot.com",SuggestionType.BACKUP));
accountAdapter.add("file3", new AccountSuggestion("piet@snot.com",SuggestionType.BACKUP));
}
/*
Task to scan for backup accounts and add them to the list
*/
private class BackupScan extends AsyncTask<Void, Void, Boolean> {
@Override
protected Boolean doInBackground(Void... objects) {
// scan for .k9s files
// scan each file for accounts
// add them to the list ( with addBackupAccount )
return true;
}
}
/*
Simple class to wrap account suggestion data
*/
private class AccountSuggestion
{
private String account;
private SuggestionType type;
public AccountSuggestion(String account, SuggestionType type){
this.account = account;
this.type = type;
}
public String toString(){ return account; }
public String getAccount(){ return account; }
public SuggestionType getSuggestionType(){ return type; }
}
}

View File

@ -0,0 +1,129 @@
package com.fsck.k9.helper;
import android.content.Context;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.TextView;
import com.fsck.k9.service.PollService;
import java.util.*;
/**
* Author: dzan
* Date: 21/06/11
*
* This is a generic ListAdapter enabling the view to have subsections. To display an element the toString() is used from
* the supplied type. When adding items new groups will be created as needed. If an item is added belonging to a preexisting group
* it will be merged. Group titles are displayed with simple TextViews, this can't be changed ( unless in the code itself ofc ).
*
* Usage: Declare, initialise then just use add(string:sectionname, T:item).
* The constructor takes the context, a resource_id to draw headers with ( textview! ) and one to draw the list items with.
*/
public class SectionListAdapter<T> extends BaseAdapter{
// These represent the different list item types
private final int VIEWTYPE_HEADER = 0;
private final int VIEWTYPE_CONTENT = 1;
// Model holding our data
private List<String> headers = new ArrayList<String>();
private List<Integer> headersPos = new ArrayList<Integer>();
private Map<String, ArrayAdapter> sections = new LinkedHashMap<String, ArrayAdapter>(); // important: we need the constant order property
// Android-view stuff
private Context context;
private int headerResourceId, normalResourceId;
public SectionListAdapter(Context context, int headerResourceId, int normalResourceId){
super();
this.context = context;
this.headerResourceId = headerResourceId;
this.normalResourceId = normalResourceId;
}
public int getCount() {
int total = headers.size();
for( Adapter a : sections.values() ) total += a.getCount();
return total;
}
public void add(String section, T item){
if( !headers.contains(section) ){
headersPos.add(getCount()); // no +1 ! order important here
headers.add(section);
ArrayAdapter<T> tmp = new ArrayAdapter<T>(context,normalResourceId);
tmp.add(item);
sections.put(section, tmp);
}else{
sections.get(section).add(item);
for(int i=headers.indexOf(section)+1; i<headersPos.size(); ++i)
headersPos.set(i, headersPos.get(i)+1);
}
notifyDataSetChanged();
}
private boolean isHeader(int pos){ return headersPos.contains(pos); }
private int numberOfSections(){ return headersPos.size(); }
public Object getItem(int pos) {
if( isHeader(pos) ){
return headers.get(headersPos.indexOf(pos));
}else{
for(int i=0; i<headersPos.size(); ++i ){
if( i != numberOfSections()-1 && pos >= headersPos.get(i+1) ) continue;
return sections.get(headers.get(i));
}
return null; // should never happen, means pos > element count
}
}
public long getItemId(int pos) { return pos; }
public View getView(int pos, View view, ViewGroup viewGroup) {
if( isHeader(pos) ){
TextView result = (TextView) view;
if (view == null){
//result = (TextView) LayoutInflater.from(context).inflate(headerResourceId, viewGroup);
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
result = (TextView) inflater.inflate(headerResourceId, viewGroup, false);
}
String tmp = headers.get(headersPos.indexOf(pos));
result.setText(tmp);
return (result);
}else{
for(int i=0; i<numberOfSections(); ++i ) // do for each section
{
if( i != numberOfSections()-1 && pos >= headersPos.get(i+1) ) continue;
return sections.get(headers.get(i)).getView(pos - headersPos.get(i)-1, view, viewGroup);
}
return null; // should never happen, means pos > element count
}
}
@Override
public int getItemViewType(int pos){
if( headersPos.contains(pos) ) return VIEWTYPE_HEADER;
else return VIEWTYPE_CONTENT;
}
@Override
public int getViewTypeCount(){ return 2; }
@Override
public boolean areAllItemsEnabled() { return false; }
@Override
public boolean isEnabled(int pos) { return !isHeader(pos); }
@Override
public boolean isEmpty(){ return headers.isEmpty() && sections.isEmpty(); }
}