2010-07-07 12:17:13 -04:00
|
|
|
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.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;
|
|
|
|
import com.fsck.k9.FontSizes;
|
|
|
|
import com.fsck.k9.K9;
|
|
|
|
import com.fsck.k9.Preferences;
|
|
|
|
import com.fsck.k9.R;
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
setContentView(R.layout.launcher_shortcuts);
|
|
|
|
ListView listView = getListView();
|
|
|
|
listView.setOnItemClickListener(this);
|
|
|
|
listView.setItemsCanFocus(false);
|
|
|
|
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
private void refresh() {
|
2010-07-07 12:17:13 -04:00
|
|
|
Account[] accounts = Preferences.getPreferences(this).getAccounts();
|
|
|
|
|
|
|
|
mAdapter = new AccountsAdapter(accounts);
|
|
|
|
getListView().setAdapter(mAdapter);
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
private void setupShortcut(Account account) {
|
2010-07-07 14:31:16 -04:00
|
|
|
final Intent shortcutIntent = FolderList.actionHandleAccountIntent(this, 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) {
|
2010-07-07 12:17:13 -04:00
|
|
|
Account account = (Account) parent.getItemAtPosition(position);
|
|
|
|
setupShortcut(account);
|
|
|
|
}
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
class AccountsAdapter extends ArrayAdapter<Account> {
|
|
|
|
public AccountsAdapter(Account[] 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) {
|
2010-11-18 04:09:57 -05:00
|
|
|
final Account account = getItem(position);
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
2010-11-18 04:09:57 -05:00
|
|
|
holder.chip.setBackgroundColor(account.getChipColor());
|
|
|
|
holder.chip.getBackground().setAlpha(255);
|
2010-07-07 12:17:13 -04:00
|
|
|
|
|
|
|
holder.description.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizes.getAccountName());
|
|
|
|
holder.email.setTextSize(TypedValue.COMPLEX_UNIT_DIP, mFontSizes.getAccountDescription());
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|