unittest.TestCaseを継承したクラスがあるファイルの階層、もしくはそのファイルがサブディレクトリにある状態で、
コマンドを実行すると、テストが実行される。
ViewGroup#setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);を設定して、ピッカーにフォーカスがいかないように設定することによって、ピッカーをタップしてもキーボードが表示されなくなる。
// 矢印の色変更 final Drawable upArrow = getResources().getDrawable(R.drawable.abc_ic_ab_back_mtrl_am_alpha); upArrow.setColorFilter(getResources().getColor(R.color.drawer_arrows), PorterDuff.Mode.SRC_ATOP); getSupportActionBar().setHomeAsUpIndicator(upArrow);
public class AutoHideKeyboardEditText extends EditText {
protected boolean mHideKeyboardEnable = true;
public AutoHideKeyboardEditText(Context context) {
super(context);
}
public AutoHideKeyboardEditText(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setHideKeyboardEnable(final boolean enabled) {
mHideKeyboardEnable = enabled;
}
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
super.onFocusChanged(focused, direction, previouslyFocusedRect);
if (mHideKeyboardEnable && !focused) {
// ソフトキーボードを非表示にする
final InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
}
}
}
public static void openBrowser(final Context context, final String url) {
try {
// 標準ブラウザ起動
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.setClassName("com.android.browser", "com.android.browser.BrowserActivity");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
} catch (ActivityNotFoundException e) {
try {
// chrome起動
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.setClassName("com.android.chrome", "com.google.android.apps.chrome.Main");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
} catch (ActivityNotFoundException e2) {
// 暗黙的intentでブラウザ起動
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
}
}
}
public boolean isInstalled(final Context context) {
final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("scheme:"));
final List resolveInfos = context.getApplicationContext()
.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
return (resolveInfos != null && !resolveInfos.isEmpty());
}