Created
November 6, 2013 15:22
-
-
Save takke/7337833 to your computer and use it in GitHub Desktop.
twiccaプラグイン設定とかなんとか
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SuppressWarnings("deprecation") | |
protected void showTwiccaPluginConfig() { | |
// twicca 対応アプリ一覧探索 | |
final PackageManager pm = getPackageManager(); | |
final Intent intent = new Intent("jp.r246.twicca.ACTION_PLUGIN_SETTINGS"); | |
final List<ResolveInfo> resolveInfo = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); | |
if (resolveInfo.size() == 0) { | |
Toast.makeText(this, R.string.twicca_plugin_not_found, Toast.LENGTH_SHORT).show(); | |
return; | |
} | |
final AlertDialog.Builder ab = new AlertDialog.Builder(this); | |
final ArrayList<IconAlertDialogUtil.IconItem> items = new ArrayList<IconAlertDialogUtil.IconItem>(); | |
final int n = resolveInfo.size(); | |
for (int i=0; i<n; i++) { | |
final ResolveInfo ri = resolveInfo.get(i); | |
final Bitmap bitmap = ((BitmapDrawable)ri.loadIcon(pm)).getBitmap(); | |
final int size = TkUtil.dipToPixel(this, 48); | |
final Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, size, size, false); | |
items.add(new IconItem(ri.loadLabel(pm).toString(), new BitmapDrawable(scaledBitmap))); | |
} | |
final ListAdapter adapter = IconAlertDialogUtil.createAdapter(this, items); | |
ab.setAdapter(adapter, new DialogInterface.OnClickListener() { | |
@Override | |
public void onClick(DialogInterface dialog, int which) { | |
final ResolveInfo ri = resolveInfo.get(which); | |
final Intent intent = new Intent("jp.r246.twicca.ACTION_PLUGIN_SETTINGS"); | |
final ActivityInfo ai = ri.activityInfo; | |
final ComponentName name=new ComponentName( | |
ai.applicationInfo.packageName, | |
ai.name); | |
intent.setComponent(name); | |
startActivity(intent); | |
} | |
}); | |
ab.create().show(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment