mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-30 13:12:25 -05:00
added launcher shortcuts to accounts, refs issue 1025
This commit is contained in:
parent
5d4073072f
commit
00a8f948eb
@ -2,15 +2,15 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:versionCode="2902"
|
||||
android:versionName="2.902" package="com.fsck.k9">
|
||||
<uses-sdk
|
||||
android:minSdkVersion="3"
|
||||
android:targetSdkVersion="4"
|
||||
/>
|
||||
<supports-screens
|
||||
largeScreens="true"
|
||||
normalScreens="true"
|
||||
smallScreens="true"
|
||||
/>
|
||||
<uses-sdk
|
||||
android:minSdkVersion="3"
|
||||
android:targetSdkVersion="4"
|
||||
/>
|
||||
<supports-screens
|
||||
largeScreens="true"
|
||||
normalScreens="true"
|
||||
smallScreens="true"
|
||||
/>
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||
<uses-permission android:name="android.permission.READ_CONTACTS"/>
|
||||
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS"/>
|
||||
@ -32,9 +32,9 @@
|
||||
android:label="@string/remote_control_label"
|
||||
android:description="@string/remote_control_desc"/>
|
||||
<uses-permission android:name="com.fsck.k9.permission.REMOTE_CONTROL"/>
|
||||
<application
|
||||
android:icon="@drawable/icon"
|
||||
android:label="@string/app_name"
|
||||
<application
|
||||
android:icon="@drawable/icon"
|
||||
android:label="@string/app_name"
|
||||
android:name="K9"
|
||||
android:allowTaskReparenting="false"
|
||||
>
|
||||
@ -77,10 +77,10 @@
|
||||
android:label="@string/account_setup_incoming_title"
|
||||
>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.fsck.k9.activity.setup.AccountSetupComposition"
|
||||
android:label="@string/account_settings_composition_title"
|
||||
>
|
||||
<activity
|
||||
android:name="com.fsck.k9.activity.setup.AccountSetupComposition"
|
||||
android:label="@string/account_settings_composition_title"
|
||||
>
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.fsck.k9.activity.setup.AccountSetupOutgoing"
|
||||
@ -132,7 +132,7 @@
|
||||
android:label="@string/account_settings_title_fmt"
|
||||
>
|
||||
</activity>
|
||||
|
||||
|
||||
<activity
|
||||
android:name="com.fsck.k9.activity.setup.FolderSettings"
|
||||
android:theme="@android:style/Theme.Dialog"
|
||||
@ -142,34 +142,19 @@
|
||||
|
||||
<activity
|
||||
android:name="com.fsck.k9.activity.FolderList"
|
||||
android:launchMode="singleTask"
|
||||
>
|
||||
<!--
|
||||
android:launchMode="singleTask">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<data
|
||||
android:scheme="email"
|
||||
android:host="accounts"
|
||||
/>
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<!-- This action is only to allow an entry point for launcher shortcuts -->
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
</intent-filter>
|
||||
-->
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.fsck.k9.activity.MessageList"
|
||||
android:launchMode="singleTask"
|
||||
|
||||
>
|
||||
<!--
|
||||
android:launchMode="singleTask">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<data
|
||||
android:scheme="email"
|
||||
android:host="folders"
|
||||
/>
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<!-- This action is only to allow an entry point for launcher shortcuts -->
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
</intent-filter>
|
||||
-->
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.fsck.k9.activity.MessageView"
|
||||
@ -221,6 +206,14 @@
|
||||
<meta-data android:name="android.app.searchable"
|
||||
android:resource="@xml/searchable" />
|
||||
</activity>
|
||||
<activity android:name="com.fsck.k9.activity.LauncherShortcuts"
|
||||
android:label="@string/shortcuts_title">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.CREATE_SHORTCUT" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<receiver android:name="com.fsck.k9.service.BootReceiver"
|
||||
android:enabled="true"
|
||||
>
|
||||
@ -258,7 +251,7 @@
|
||||
<action android:name="com.fsck.k9.K9RemoteControl.requestAccounts"/>
|
||||
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</receiver>
|
||||
<receiver android:name="com.fsck.k9.service.CoreReceiver"
|
||||
android:enabled="true"
|
||||
>
|
||||
|
11
res/layout/launcher_shortcuts.xml
Normal file
11
res/layout/launcher_shortcuts.xml
Normal file
@ -0,0 +1,11 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_width="fill_parent">
|
||||
<ListView
|
||||
android:id="@android:id/list"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
/>
|
||||
</LinearLayout>
|
@ -15,6 +15,7 @@
|
||||
<string name="accounts_title">Accounts</string>
|
||||
<string name="advanced">Advanced</string>
|
||||
<string name="folder_list_title"><xliff:g id="account">%s</xliff:g> </string>
|
||||
<string name="shortcuts_title">K-9 Accounts</string>
|
||||
|
||||
<string name="message_list_title"><xliff:g id="account">%s</xliff:g>:<xliff:g id="folder">%s</xliff:g> </string>
|
||||
|
||||
|
@ -208,7 +208,12 @@ public class FolderList extends K9ListActivity
|
||||
sendMail(mAccount);
|
||||
}
|
||||
|
||||
private static void actionHandleAccount(Context context, Account account, String initialFolder)
|
||||
public static Intent actionHandleAccountIntent(Context context, Account account)
|
||||
{
|
||||
return actionHandleAccountIntent(context, account, null);
|
||||
}
|
||||
|
||||
public static Intent actionHandleAccountIntent(Context context, Account account, String initialFolder)
|
||||
{
|
||||
Intent intent = new Intent(context, FolderList.class);
|
||||
intent.putExtra(EXTRA_ACCOUNT, account.getUuid());
|
||||
@ -217,7 +222,12 @@ public class FolderList extends K9ListActivity
|
||||
{
|
||||
intent.putExtra(EXTRA_INITIAL_FOLDER, initialFolder);
|
||||
}
|
||||
return intent;
|
||||
}
|
||||
|
||||
private static void actionHandleAccount(Context context, Account account, String initialFolder)
|
||||
{
|
||||
Intent intent = actionHandleAccountIntent(context, account, initialFolder);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
|
189
src/com/fsck/k9/activity/LauncherShortcuts.java
Normal file
189
src/com/fsck/k9/activity/LauncherShortcuts.java
Normal file
@ -0,0 +1,189 @@
|
||||
|
||||
package com.fsck.k9.activity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.os.Parcelable;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.AdapterView.OnItemClickListener;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RelativeLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.fsck.k9.Account;
|
||||
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;
|
||||
|
||||
public class LauncherShortcuts extends K9ListActivity implements OnItemClickListener
|
||||
{
|
||||
private AccountsAdapter mAdapter;
|
||||
private FontSizes mFontSizes = K9.getFontSizes();
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle)
|
||||
{
|
||||
super.onCreate(icicle);
|
||||
|
||||
// finish() immediately if we aren't supposed to be here
|
||||
if (!Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction())) {
|
||||
finish();
|
||||
return;
|
||||
}
|
||||
|
||||
setContentView(R.layout.launcher_shortcuts);
|
||||
ListView listView = getListView();
|
||||
listView.setOnItemClickListener(this);
|
||||
listView.setItemsCanFocus(false);
|
||||
|
||||
refresh();
|
||||
}
|
||||
|
||||
private void refresh()
|
||||
{
|
||||
Account[] accounts = Preferences.getPreferences(this).getAccounts();
|
||||
|
||||
mAdapter = new AccountsAdapter(accounts);
|
||||
getListView().setAdapter(mAdapter);
|
||||
}
|
||||
|
||||
private void setupShortcut(Account account)
|
||||
{
|
||||
Intent shortcutIntent = null;
|
||||
if (K9.FOLDER_NONE.equals(account.getAutoExpandFolderName()))
|
||||
{
|
||||
shortcutIntent = FolderList.actionHandleAccountIntent(this, account);
|
||||
}
|
||||
else
|
||||
{
|
||||
shortcutIntent =
|
||||
MessageList.actionHandleFolderIntent(this, account,
|
||||
account.getAutoExpandFolderName());
|
||||
}
|
||||
|
||||
Intent intent = new Intent();
|
||||
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
|
||||
String description = account.getDescription();
|
||||
if (description == null || description.length() == 0)
|
||||
{
|
||||
description = account.getEmail();
|
||||
}
|
||||
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, description);
|
||||
Parcelable iconResource = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
|
||||
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
|
||||
|
||||
setResult(RESULT_OK, intent);
|
||||
finish();
|
||||
}
|
||||
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id)
|
||||
{
|
||||
Account account = (Account) parent.getItemAtPosition(position);
|
||||
setupShortcut(account);
|
||||
}
|
||||
|
||||
class AccountsAdapter extends ArrayAdapter<Account>
|
||||
{
|
||||
public AccountsAdapter(Account[] accounts)
|
||||
{
|
||||
super(LauncherShortcuts.this, 0, accounts);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent)
|
||||
{
|
||||
final BaseAccount account = getItem(position);
|
||||
View view;
|
||||
if (convertView != null)
|
||||
{
|
||||
view = convertView;
|
||||
}
|
||||
else
|
||||
{
|
||||
view = getLayoutInflater().inflate(R.layout.accounts_item, parent, false);
|
||||
}
|
||||
AccountViewHolder holder = (AccountViewHolder) view.getTag();
|
||||
if (holder == null)
|
||||
{
|
||||
holder = new AccountViewHolder();
|
||||
holder.description = (TextView) view.findViewById(R.id.description);
|
||||
holder.email = (TextView) view.findViewById(R.id.email);
|
||||
holder.newMessageCount = (TextView) view.findViewById(R.id.new_message_count);
|
||||
holder.flaggedMessageCount = (TextView) view.findViewById(R.id.flagged_message_count);
|
||||
holder.activeIcons = (RelativeLayout) view.findViewById(R.id.active_icons);
|
||||
|
||||
holder.chip = view.findViewById(R.id.chip);
|
||||
holder.folders = (ImageButton) view.findViewById(R.id.folders);
|
||||
|
||||
view.setTag(holder);
|
||||
}
|
||||
|
||||
if (account.getEmail().equals(account.getDescription()))
|
||||
{
|
||||
holder.email.setVisibility(View.GONE);
|
||||
}
|
||||
else
|
||||
{
|
||||
holder.email.setVisibility(View.VISIBLE);
|
||||
holder.email.setText(account.getEmail());
|
||||
}
|
||||
|
||||
String description = account.getDescription();
|
||||
if (description == null || description.length() == 0)
|
||||
{
|
||||
description = account.getEmail();
|
||||
}
|
||||
|
||||
holder.description.setText(description);
|
||||
|
||||
holder.newMessageCount.setVisibility(View.GONE);
|
||||
holder.flaggedMessageCount.setVisibility(View.GONE);
|
||||
if (account instanceof Account)
|
||||
{
|
||||
Account realAccount = (Account)account;
|
||||
|
||||
holder.chip.setBackgroundColor(realAccount.getChipColor());
|
||||
holder.chip.getBackground().setAlpha(255);
|
||||
}
|
||||
else
|
||||
{
|
||||
holder.chip.setBackgroundColor(0x00000000);
|
||||
}
|
||||
|
||||
holder.description.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizes.getAccountName());
|
||||
holder.email.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizes.getAccountDescription());
|
||||
|
||||
|
||||
holder.folders.setVisibility(View.VISIBLE);
|
||||
holder.folders.setOnClickListener(new OnClickListener()
|
||||
{
|
||||
public void onClick(View v)
|
||||
{
|
||||
FolderList.actionHandleAccount(LauncherShortcuts.this, (Account)account);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
class AccountViewHolder
|
||||
{
|
||||
public TextView description;
|
||||
public TextView email;
|
||||
public TextView newMessageCount;
|
||||
public TextView flaggedMessageCount;
|
||||
public RelativeLayout activeIcons;
|
||||
public View chip;
|
||||
public ImageButton folders;
|
||||
}
|
||||
}
|
||||
}
|
@ -327,6 +327,7 @@ public class MessageList
|
||||
context.startActivity(intent);
|
||||
|
||||
}
|
||||
|
||||
public static Intent actionHandleFolderIntent(Context context, Account account, String folder)
|
||||
{
|
||||
Intent intent = new Intent(context, MessageList.class);
|
||||
|
Loading…
Reference in New Issue
Block a user