Merge "Update visual style shortcut picker and make it async"
This commit is contained in:
commit
0cefe81b47
@ -147,10 +147,13 @@
|
||||
|
||||
<activity
|
||||
android:name=".activity.AccountShortcutPicker"
|
||||
android:label="@string/app_name"
|
||||
android:label="@string/account_shortcut_picker_title"
|
||||
android:enabled="false"
|
||||
android:theme="@android:style/Theme.Holo.DialogWhenLarge"
|
||||
>
|
||||
<intent-filter>
|
||||
<intent-filter
|
||||
android:label="@string/account_shortcut_picker_name"
|
||||
>
|
||||
<action android:name="android.intent.action.CREATE_SHORTCUT" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
|
37
res/layout/account_shortcut_picker.xml
Normal file
37
res/layout/account_shortcut_picker.xml
Normal file
@ -0,0 +1,37 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2010 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
>
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dip"
|
||||
android:layout_weight="1"
|
||||
/>
|
||||
<!-- TODO selectableItemBackground is a placeholder for the new "cancel" style -->
|
||||
<Button
|
||||
android:id="@+id/cancel"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/cancel_action"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
/>
|
||||
</LinearLayout>
|
39
res/layout/account_shortcut_picker_item.xml
Normal file
39
res/layout/account_shortcut_picker_item.xml
Normal file
@ -0,0 +1,39 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2010 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?android:attr/listPreferredItemHeight"
|
||||
android:orientation="vertical"
|
||||
android:paddingRight="4dip"
|
||||
android:paddingLeft="6dip"
|
||||
>
|
||||
<TextView
|
||||
android:id="@+id/description"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
/>
|
||||
<TextView
|
||||
android:id="@+id/email"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
/>
|
||||
</LinearLayout>
|
@ -1,56 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2008 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:id="@+id/empty"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="20sp"
|
||||
android:text="@string/accounts_welcome"
|
||||
android:textColor="?android:attr/textColorPrimary" />
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dip"
|
||||
android:layout_weight="1" />
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="54dip"
|
||||
android:background="@android:drawable/bottom_bar">
|
||||
<Button
|
||||
android:id="@+id/add_new_account"
|
||||
android:layout_width="wrap_content"
|
||||
android:minWidth="@dimen/button_minWidth"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/next_action"
|
||||
android:drawableRight="@drawable/button_indicator_next"
|
||||
android:layout_alignParentRight="true"
|
||||
android:layout_centerVertical="true" />
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
@ -1,59 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- Copyright (C) 2008 The Android Open Source Project
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
|
||||
<LinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?android:attr/listPreferredItemHeight"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical"
|
||||
android:paddingRight="4dip">
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingLeft="6dip">
|
||||
<TextView
|
||||
android:id="@+id/description"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView
|
||||
android:id="@+id/email"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
</LinearLayout>
|
||||
<View
|
||||
android:layout_height="match_parent"
|
||||
android:layout_width="0dip"
|
||||
android:layout_weight="1" />
|
||||
<TextView
|
||||
android:id="@+id/new_message_count"
|
||||
android:ellipsize="end"
|
||||
android:singleLine="true"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/text_box_light"
|
||||
android:paddingLeft="10dip"
|
||||
android:paddingRight="10dip"
|
||||
android:minWidth="64dip"
|
||||
android:gravity="right" />
|
||||
</LinearLayout>
|
@ -823,8 +823,15 @@ save attachment.</string>
|
||||
<!-- On Settings screen, settings option for delete account [CHAR LIMIT=none] -->
|
||||
<string name="account_settings_delete_account_label">Remove account</string>
|
||||
|
||||
<!-- Strings used for account shortcut picker -->
|
||||
<!-- String displayed in launcher [CHAR_LIMIT=10] -->
|
||||
<string name="account_shortcut_picker_name">Email account</string>
|
||||
<!-- Title of activity/dialog containing shortcut picker (list of accounts) [CHAR_LIMIT=20] -->
|
||||
<string name="account_shortcut_picker_title">Select an account</string>
|
||||
|
||||
<!-- Title of Upgrade Accounts activity -->
|
||||
<string name="upgrade_accounts_title">Upgrade accounts</string>
|
||||
<!-- Error shown when Upgrade Accounts fails (shown below name of that account) -->
|
||||
<string name="upgrade_accounts_error">Unable to upgrade account</string>
|
||||
|
||||
<!-- Message that appears when adding a Windows Live Hotmail Plus account -->
|
||||
|
@ -17,33 +17,33 @@
|
||||
package com.android.email.activity;
|
||||
|
||||
import com.android.email.R;
|
||||
import com.android.email.Utility;
|
||||
import com.android.email.provider.EmailContent;
|
||||
import com.android.email.provider.EmailContent.Account;
|
||||
|
||||
import android.app.ListActivity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ListView;
|
||||
import android.widget.SimpleCursorAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
/**
|
||||
*
|
||||
* This class implements a launcher shortcut for directly accessing a single account.
|
||||
*
|
||||
* This is simply a lightweight version of Accounts, and should almost certainly be merged with it
|
||||
* (or, one could be a base class of the other).
|
||||
*
|
||||
* TODO Handle upgraded shortcuts for the phone UI release. Shortcuts used to launch MessageList
|
||||
* directly. We need to detect this and redirect to Welcome.
|
||||
*/
|
||||
public class AccountShortcutPicker extends ListActivity implements OnItemClickListener {
|
||||
public class AccountShortcutPicker extends ListActivity
|
||||
implements OnClickListener, OnItemClickListener {
|
||||
|
||||
private AccountTask mAccountTask;
|
||||
|
||||
/**
|
||||
* Support for list adapter
|
||||
@ -51,12 +51,10 @@ public class AccountShortcutPicker extends ListActivity implements OnItemClickLi
|
||||
private final static String[] FROM_COLUMNS = new String[] {
|
||||
EmailContent.AccountColumns.DISPLAY_NAME,
|
||||
EmailContent.AccountColumns.EMAIL_ADDRESS,
|
||||
EmailContent.RECORD_ID
|
||||
};
|
||||
private final static int[] TO_IDS = new int[] {
|
||||
R.id.description,
|
||||
R.id.email,
|
||||
R.id.new_message_count
|
||||
};
|
||||
|
||||
@Override
|
||||
@ -69,27 +67,40 @@ public class AccountShortcutPicker extends ListActivity implements OnItemClickLi
|
||||
return;
|
||||
}
|
||||
|
||||
// finish() immediately if no accounts are configured
|
||||
// TODO: lightweight projection with only those columns needed for this display
|
||||
// TODO: query outside of UI thread
|
||||
Cursor c = this.managedQuery(
|
||||
EmailContent.Account.CONTENT_URI,
|
||||
EmailContent.Account.CONTENT_PROJECTION,
|
||||
null, null, null);
|
||||
if (c.getCount() == 0) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
setContentView(R.layout.account_shortcut_picker);
|
||||
findViewById(R.id.cancel).setOnClickListener(this);
|
||||
|
||||
setContentView(R.layout.accounts);
|
||||
ListView listView = getListView();
|
||||
listView.setOnItemClickListener(this);
|
||||
listView.setItemsCanFocus(false);
|
||||
listView.setEmptyView(findViewById(R.id.empty));
|
||||
|
||||
AccountsAdapter a = new AccountsAdapter(this,
|
||||
R.layout.accounts_item, c, FROM_COLUMNS, TO_IDS);
|
||||
listView.setAdapter(a);
|
||||
mAccountTask = new AccountTask();
|
||||
mAccountTask.execute();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
// Cleanup running async task (if any)
|
||||
Utility.cancelTaskInterrupt(mAccountTask);
|
||||
mAccountTask = null;
|
||||
// Cleanup accounts cursor (if any)
|
||||
SimpleCursorAdapter adapter = (SimpleCursorAdapter) getListAdapter();
|
||||
if (adapter != null) {
|
||||
adapter.changeCursor(null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Implements View.OnClickListener
|
||||
*/
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.cancel:
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
@ -99,33 +110,40 @@ public class AccountShortcutPicker extends ListActivity implements OnItemClickLi
|
||||
finish();
|
||||
}
|
||||
|
||||
private static class AccountsAdapter extends SimpleCursorAdapter {
|
||||
/**
|
||||
* Load the accounts and create the adapter.
|
||||
*/
|
||||
private class AccountTask extends AsyncTask<Void, Void, Cursor> {
|
||||
|
||||
public AccountsAdapter(Context context, int layout, Cursor c, String[] from, int[] to) {
|
||||
super(context, layout, c, from, to);
|
||||
setViewBinder(new MyViewBinder());
|
||||
@Override
|
||||
protected Cursor doInBackground(Void... params) {
|
||||
Cursor cursor = AccountShortcutPicker.this.getContentResolver().query(
|
||||
EmailContent.Account.CONTENT_URI,
|
||||
EmailContent.Account.CONTENT_PROJECTION,
|
||||
null, null, null);
|
||||
if (isCancelled()) {
|
||||
cursor.close();
|
||||
cursor = null;
|
||||
}
|
||||
return cursor;
|
||||
}
|
||||
|
||||
/**
|
||||
* This is only used for the unread messages count. Most of the views are handled
|
||||
* normally by SimpleCursorAdapter.
|
||||
*/
|
||||
private static class MyViewBinder implements SimpleCursorAdapter.ViewBinder {
|
||||
|
||||
public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
|
||||
if (view.getId() == R.id.new_message_count) {
|
||||
|
||||
int unreadMessageCount = 0; // TODO get unread count from Account
|
||||
if (unreadMessageCount <= 0) {
|
||||
view.setVisibility(View.GONE);
|
||||
} else {
|
||||
((TextView)view).setText(String.valueOf(unreadMessageCount));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
@Override
|
||||
protected void onPostExecute(Cursor cursor) {
|
||||
// If canceled, get out immediately
|
||||
if (cursor == null) {
|
||||
return;
|
||||
}
|
||||
// If there are no accounts, we should never have been here - exit the activity
|
||||
if (cursor.getCount() == 0) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
// Create an adapter and connect to the ListView
|
||||
AccountShortcutPicker activity = AccountShortcutPicker.this;
|
||||
SimpleCursorAdapter adapter = new SimpleCursorAdapter(activity,
|
||||
R.layout.account_shortcut_picker_item, cursor, FROM_COLUMNS, TO_IDS);
|
||||
activity.getListView().setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user