2010-07-07 12:17:13 -04:00
|
|
|
package com.fsck.k9.activity;
|
|
|
|
|
2012-01-31 21:07:19 -05:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Arrays;
|
|
|
|
import java.util.List;
|
|
|
|
|
2010-07-07 12:17:13 -04:00
|
|
|
import android.content.Intent;
|
|
|
|
import android.os.Bundle;
|
|
|
|
import android.os.Parcelable;
|
|
|
|
import android.util.TypedValue;
|
|
|
|
import android.view.View;
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
import android.widget.AdapterView;
|
|
|
|
import android.widget.AdapterView.OnItemClickListener;
|
|
|
|
import android.widget.ArrayAdapter;
|
|
|
|
import android.widget.ListView;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import com.fsck.k9.Account;
|
2012-01-31 21:07:19 -05:00
|
|
|
import com.fsck.k9.BaseAccount;
|
2010-07-07 12:17:13 -04:00
|
|
|
import com.fsck.k9.FontSizes;
|
|
|
|
import com.fsck.k9.K9;
|
|
|
|
import com.fsck.k9.Preferences;
|
|
|
|
import com.fsck.k9.R;
|
2012-01-31 21:07:19 -05:00
|
|
|
import com.fsck.k9.SearchAccount;
|
|
|
|
import com.fsck.k9.SearchSpecification;
|
|
|
|
import com.fsck.k9.helper.Utility;
|
2010-07-07 12:17:13 -04:00
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public class LauncherShortcuts extends K9ListActivity implements OnItemClickListener {
|
2010-07-07 12:17:13 -04:00
|
|
|
private AccountsAdapter mAdapter;
|
|
|
|
private FontSizes mFontSizes = K9.getFontSizes();
|
|
|
|
|
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public void onCreate(Bundle icicle) {
|
2010-07-07 12:17:13 -04:00
|
|
|
super.onCreate(icicle);
|
|
|
|
|
|
|
|
// finish() immediately if we aren't supposed to be here
|
2011-02-06 17:09:48 -05:00
|
|
|
if (!Intent.ACTION_CREATE_SHORTCUT.equals(getIntent().getAction())) {
|
2010-07-07 12:17:13 -04:00
|
|
|
finish();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-02-06 19:00:16 -05:00
|
|
|
setContentView(R.layout.account_list);
|
2010-07-07 12:17:13 -04:00
|
|
|
ListView listView = getListView();
|
|
|
|
listView.setOnItemClickListener(this);
|
|
|
|
listView.setItemsCanFocus(false);
|
|
|
|
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
private void refresh() {
|
2012-01-31 21:07:19 -05:00
|
|
|
List<BaseAccount> accounts = new ArrayList<BaseAccount>();
|
|
|
|
|
|
|
|
if (!K9.isHideSpecialAccounts()) {
|
|
|
|
BaseAccount integratedInboxAccount = new SearchAccount(this, true, null, null);
|
|
|
|
integratedInboxAccount.setDescription(
|
|
|
|
getString(R.string.integrated_inbox_title));
|
|
|
|
integratedInboxAccount.setEmail(
|
|
|
|
getString(R.string.integrated_inbox_detail));
|
|
|
|
|
|
|
|
BaseAccount unreadAccount = new SearchAccount(this, false, null, null);
|
|
|
|
unreadAccount.setDescription(
|
|
|
|
getString(R.string.search_all_messages_title));
|
|
|
|
unreadAccount.setEmail(
|
|
|
|
getString(R.string.search_all_messages_detail));
|
|
|
|
|
|
|
|
accounts.add(integratedInboxAccount);
|
|
|
|
accounts.add(unreadAccount);
|
|
|
|
}
|
|
|
|
|
|
|
|
accounts.addAll(Arrays.asList(Preferences.getPreferences(this).getAccounts()));
|
2010-07-07 12:17:13 -04:00
|
|
|
|
|
|
|
mAdapter = new AccountsAdapter(accounts);
|
|
|
|
getListView().setAdapter(mAdapter);
|
|
|
|
}
|
|
|
|
|
2012-01-31 21:07:19 -05:00
|
|
|
private void setupShortcut(BaseAccount account) {
|
|
|
|
Intent shortcutIntent = null;
|
|
|
|
|
|
|
|
if (account instanceof SearchSpecification) {
|
|
|
|
shortcutIntent = MessageList.actionHandleAccountIntent(
|
|
|
|
this, account.getDescription(), (SearchSpecification) account);
|
|
|
|
} else {
|
|
|
|
shortcutIntent = FolderList.actionHandleAccountIntent(this,
|
|
|
|
(Account) account, null, true);
|
|
|
|
}
|
2010-07-07 12:17:13 -04:00
|
|
|
|
|
|
|
Intent intent = new Intent();
|
|
|
|
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
|
|
|
|
String description = account.getDescription();
|
2011-02-06 17:09:48 -05:00
|
|
|
if (description == null || description.length() == 0) {
|
2010-07-07 12:17:13 -04:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
2012-01-31 21:07:19 -05:00
|
|
|
BaseAccount account = (BaseAccount) parent.getItemAtPosition(position);
|
2010-07-07 12:17:13 -04:00
|
|
|
setupShortcut(account);
|
|
|
|
}
|
|
|
|
|
2012-01-31 21:07:19 -05:00
|
|
|
class AccountsAdapter extends ArrayAdapter<BaseAccount> {
|
|
|
|
public AccountsAdapter(List<BaseAccount> accounts) {
|
2010-07-07 12:17:13 -04:00
|
|
|
super(LauncherShortcuts.this, 0, accounts);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2011-02-06 17:09:48 -05:00
|
|
|
public View getView(int position, View convertView, ViewGroup parent) {
|
2012-01-31 21:07:19 -05:00
|
|
|
final BaseAccount account = getItem(position);
|
2010-11-18 04:09:57 -05:00
|
|
|
|
|
|
|
final View view;
|
2011-02-06 17:09:48 -05:00
|
|
|
if (convertView != null) {
|
2010-07-07 12:17:13 -04:00
|
|
|
view = convertView;
|
2011-02-06 17:09:48 -05:00
|
|
|
} else {
|
2010-07-07 12:17:13 -04:00
|
|
|
view = getLayoutInflater().inflate(R.layout.accounts_item, parent, false);
|
2010-11-18 04:09:57 -05:00
|
|
|
view.findViewById(R.id.active_icons).setVisibility(View.GONE);
|
2010-07-07 12:17:13 -04:00
|
|
|
}
|
2010-11-18 04:09:57 -05:00
|
|
|
|
2010-07-07 12:17:13 -04:00
|
|
|
AccountViewHolder holder = (AccountViewHolder) view.getTag();
|
2011-02-06 17:09:48 -05:00
|
|
|
if (holder == null) {
|
2010-07-07 12:17:13 -04:00
|
|
|
holder = new AccountViewHolder();
|
|
|
|
holder.description = (TextView) view.findViewById(R.id.description);
|
|
|
|
holder.email = (TextView) view.findViewById(R.id.email);
|
|
|
|
holder.chip = view.findViewById(R.id.chip);
|
|
|
|
|
|
|
|
view.setTag(holder);
|
|
|
|
}
|
|
|
|
|
2010-11-18 04:09:57 -05:00
|
|
|
String description = account.getDescription();
|
2011-02-06 17:09:48 -05:00
|
|
|
if (account.getEmail().equals(description)) {
|
2010-07-07 12:17:13 -04:00
|
|
|
holder.email.setVisibility(View.GONE);
|
2011-02-06 17:09:48 -05:00
|
|
|
} else {
|
2010-07-07 12:17:13 -04:00
|
|
|
holder.email.setVisibility(View.VISIBLE);
|
|
|
|
holder.email.setText(account.getEmail());
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
if (description == null || description.length() == 0) {
|
2010-07-07 12:17:13 -04:00
|
|
|
description = account.getEmail();
|
|
|
|
}
|
|
|
|
|
|
|
|
holder.description.setText(description);
|
|
|
|
|
2012-01-31 21:07:19 -05:00
|
|
|
if (account instanceof Account) {
|
|
|
|
holder.chip.setBackgroundColor(((Account) account).getChipColor());
|
|
|
|
}
|
|
|
|
|
2010-11-18 04:09:57 -05:00
|
|
|
holder.chip.getBackground().setAlpha(255);
|
2010-07-07 12:17:13 -04:00
|
|
|
|
2012-01-11 20:18:41 -05:00
|
|
|
holder.description.setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getAccountName());
|
|
|
|
holder.email.setTextSize(TypedValue.COMPLEX_UNIT_SP, mFontSizes.getAccountDescription());
|
2010-07-07 12:17:13 -04:00
|
|
|
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
class AccountViewHolder {
|
2010-07-07 12:17:13 -04:00
|
|
|
public TextView description;
|
|
|
|
public TextView email;
|
|
|
|
public View chip;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|