下面列出了android.app.Dialog#findViewById ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void testButtons() throws Throwable {
runTestOnUiThread(new Runnable() {
@Override
public void run() {
activity.findViewById(R.id.btn_buttons).performClick();
activity.getSupportFragmentManager().executePendingTransactions();
}
});
getInstrumentation().waitForIdleSync();
Fragment f = getActivity().getSupportFragmentManager().findFragmentByTag("dialog");
assertNotNull(f);
Dialog d = ((SimpleAlertDialogSupportFragment) f).getDialog();
assertNotNull(d);
View positive = d.findViewById(R.id.button_positive);
assertNotNull(positive);
final View negative = d.findViewById(R.id.button_negative);
assertNotNull(negative);
runTestOnUiThread(new Runnable() {
@Override
public void run() {
negative.performClick();
}
});
getInstrumentation().waitForIdleSync();
}
private void eula(Context context) {
// Run the guardian
Guardian.initiate(this);
// Load the EULA
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.eula);
dialog.setTitle("EULA");
WebView web = (WebView) dialog.findViewById(R.id.eula);
web.loadUrl("file:///android_asset/eula.html");
Button accept = (Button) dialog.findViewById(R.id.accept);
accept.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
dialog.show();
}
private void updateDateText(Dialog dialog) {
mDateStartText.setText(mStartDate == null ? getString(R.string.start) : mFormatter.format(mStartDate.getTime()));
mDateEndText.setText(mEndDate == null ? getString(R.string.end) : mFormatter.format(mEndDate.getTime()));
final LinearLayout filterDateLayout = (LinearLayout) dialog.findViewById(R.id.filter_date_layout);
final RelativeLayout.LayoutParams lp = (RelativeLayout.LayoutParams) filterDateLayout.getLayoutParams();
if (mStartDate != null && mEndDate != null) {
lp.addRule(RelativeLayout.BELOW, R.id.filter_date);
lp.addRule(RelativeLayout.RIGHT_OF, 0);
lp.leftMargin = Math.round(getActivity().getResources().getDimensionPixelOffset(R.dimen.checkbox_text_offset));
} else {
lp.addRule(RelativeLayout.BELOW, 0);
lp.addRule(RelativeLayout.RIGHT_OF, R.id.filter_date);
lp.leftMargin = 0;
}
filterDateLayout.setLayoutParams(lp);
}
public void testMessage() throws Throwable {
runTestOnUiThread(new Runnable() {
@Override
public void run() {
activity.findViewById(R.id.btn_message).performClick();
activity.getSupportFragmentManager().executePendingTransactions();
}
});
getInstrumentation().waitForIdleSync();
Fragment f = getActivity().getSupportFragmentManager().findFragmentByTag("dialog");
assertNotNull(f);
Dialog d = ((SimpleAlertDialogSupportFragment) f).getDialog();
assertNotNull(d);
final View positive = d.findViewById(R.id.button_positive);
assertNotNull(positive);
runTestOnUiThread(new Runnable() {
@Override
public void run() {
positive.performClick();
}
});
getInstrumentation().waitForIdleSync();
}
public static void showCastDialog(final Context context) {
final Dialog dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_cast);
Button button = (Button) dialog.findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setPackage("com.android.vending");
intent.setData(Uri.parse("market://details?id=" + Config.PLAY_STORE_CAST_UPGRADE_PACKAGE_NAME));
context.startActivity(intent);
} catch (android.content.ActivityNotFoundException anfe) {
context.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(Config.SLIDEME_UPGRADE_URL)));
}
dialog.dismiss();
}
});
dialog.show();
}
/**
* 键盘左侧菜单
*/
private void menuKeyboard(Dialog dialog) {
evLatexView = (EditView) dialog.findViewById(R.id.evLatexView);
hsvLatex = (HorizontalScrollView) dialog.findViewById(R.id.hsvLatex);
tvConfirm = (TextView) dialog.findViewById(R.id.tvConfirm);
llMathKeyBoardLayout = (LinearLayout) dialog.findViewById(R.id.llMathKeyBoardLayout);
llLatterKeyBoardLayout = (LinearLayout) dialog.findViewById(R.id.llLatterKeyBoardLayout);
llDefaultLayout = (LinearLayout) dialog.findViewById(R.id.llDefaultLayout);
tlAlgebraLayout = (LinearLayout) dialog.findViewById(R.id.tlAlgebraLayout);
llGeometryLayout = (LinearLayout) dialog.findViewById(R.id.llGeometryLayout);
tvDefault = (TextView) dialog.findViewById(R.id.tvDefault);
tvAlgebra = (TextView) dialog.findViewById(R.id.tvAlgebra);
tvGeometry = (TextView) dialog.findViewById(R.id.tvGeometry);
tvLetter = (TextView) dialog.findViewById(R.id.tvLetter);
tvConfirm.setOnClickListener(onClickListener);
tvDefault.setOnClickListener(onClickListener);
tvAlgebra.setOnClickListener(onClickListener);
tvGeometry.setOnClickListener(onClickListener);
tvLetter.setOnClickListener(onClickListener);
}
/**
* INITIALIZES LOADING DIALOG
*******************************************************/
private void initLoading() {
loadingdialog = new Dialog(this);
loadingdialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
loadingdialog.setContentView(R.layout.loadingdialog);
loadingimage = loadingdialog.findViewById(R.id.connecting_spinner);
loadingLog = loadingdialog.findViewById(R.id.loadingLog);
loadingHeader = loadingdialog.findViewById(R.id.loading_header);
}
public static Dialog infoPopupWithListner(Context context, String message, String buttonName, final View.OnClickListener listener) {
final Dialog dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.custom_dialog);
dialog.getWindow().getAttributes().windowAnimations = R.style.animationdialog;
dialog.setCancelable(false);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
Window window = dialog.getWindow();
window.setGravity(Gravity.CENTER);
window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
final TextView btnTxt = (TextView) dialog.findViewById(R.id.txtOK);
TextView txt = (TextView) dialog.findViewById(R.id.txt);
txt.setText(message);
btnTxt.setText(buttonName);
if (listener != null) {
btnTxt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
listener.onClick(view);
}
});
}
dialog.show();
return dialog;
}
@SuppressWarnings("deprecation")
private void aboutClicked()
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.appName);
DateFormat dateFormat = DateFormat.getDateTimeInstance();
SpannableStringBuilder spannable =
new SpannableStringBuilder(getText(R.string.version));
Pattern pattern = Pattern.compile("%s");
Matcher matcher = pattern.matcher(spannable);
if (matcher.find())
spannable.replace(matcher.start(), matcher.end(),
BuildConfig.VERSION_NAME);
matcher.reset(spannable);
if (matcher.find())
spannable.replace(matcher.start(), matcher.end(),
dateFormat.format(BuildConfig.BUILT));
builder.setMessage(spannable);
// Add the button
builder.setPositiveButton(R.string.ok, null);
// Create the AlertDialog
Dialog dialog = builder.show();
// Set movement method
TextView text = dialog.findViewById(android.R.id.message);
if (text != null)
{
text.setTextAppearance(builder.getContext(),
android.R.style.TextAppearance_Small);
text.setMovementMethod(LinkMovementMethod.getInstance());
}
}
@Override
public void onStart() {
super.onStart();
Dialog dialog = getDialog();
if (dialog != null) {
etOwnServerName = dialog.findViewById(R.id.etOwnServerName);
etOwnServerDescription = dialog.findViewById(R.id.etOwnServerDescription);
etOwnServerSDNS = dialog.findViewById(R.id.etOwnServerSDNS);
}
}
/**
* @Description 初始化音量对话框
*/
private void initSoundVolumeDlg() {
soundVolumeDialog = new Dialog(this, R.style.SoundVolumeStyle);
soundVolumeDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
soundVolumeDialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
soundVolumeDialog.setContentView(R.layout.tt_sound_volume_dialog);
soundVolumeDialog.setCanceledOnTouchOutside(true);
soundVolumeImg = (ImageView) soundVolumeDialog.findViewById(R.id.sound_volume_img);
soundVolumeLayout = (LinearLayout) soundVolumeDialog.findViewById(R.id.sound_volume_bk);
}
@Test
public void openShouldOpenDialogWithCurrentDateAndTime() {
mTravelTimePicker.open(getSupportFragmentManager());
final Dialog dialog = mTravelTimePicker.getDialog();
final DatePicker picker = dialog.findViewById(R.id.travel_date);
final Calendar calendar = Calendar.getInstance();
assertThat(picker.getYear(), equalTo(calendar.get(Calendar.YEAR)));
assertThat(picker.getMonth(), equalTo(calendar.get(Calendar.MONTH)));
assertThat(picker.getDayOfMonth(), equalTo(calendar.get(Calendar.DAY_OF_MONTH)));
final TimePicker timePicker = dialog.findViewById(R.id.travel_time);
assertThat(timePicker.getCurrentHour(), equalTo(calendar.get(Calendar.HOUR_OF_DAY)));
assertThat(timePicker.getCurrentMinute(), equalTo(calendar.get(Calendar.MINUTE)));
}
/**
* INITIALIZES ABOUT DIALOG
*******************************************************/
private void initAboutDialog() {
dialogLicense = new Dialog(this);
dialogLicense.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialogLicense.setContentView(R.layout.dialog_about_silicon_labs_blue_gecko);
WebView webView = dialogLicense.findViewById(R.id.menu_item_license);
Button closeButton = dialogLicense.findViewById(R.id.close_about_btn);
webView.loadUrl(ABOUT_DIALOG_HTML_ASSET_FILE_PATH);
closeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialogLicense.dismiss();
}
});
}
@Override
protected Dialog onCreateDialog(final int id) {
final Dialog d = new Dialog(this);
d.setCancelable(true);
d.setTitle(id == 1 ? R.string.period_from : R.string.period_to);
d.setContentView(R.layout.filter_period_select);
Button bOk = d.findViewById(R.id.bOK);
bOk.setOnClickListener(v -> {
setDialogResult(d, id == 1 ? cFrom : cTo);
d.dismiss();
});
Button bCancel = d.findViewById(R.id.bCancel);
bCancel.setOnClickListener(v -> d.cancel());
return d;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog mDialog = new Dialog(getActivity(), R.style.BottomDialog);
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mDialog.setContentView(R.layout.dialog_fragment_comment_layout);
mDialog.setCanceledOnTouchOutside(true);
Window window = mDialog.getWindow();
WindowManager.LayoutParams layoutParams;
if (window != null) {
layoutParams = window.getAttributes();
layoutParams.gravity = Gravity.BOTTOM;
layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
window.setAttributes(layoutParams);
}
commentEditText = (EditText) mDialog.findViewById(R.id.edit_comment);
photoButton = (ImageView) mDialog.findViewById(R.id.image_btn_photo);
atButton = (ImageView) mDialog.findViewById(R.id.image_btn_at);
sendButton = (ImageView) mDialog.findViewById(R.id.image_btn_comment_send);
fillEditText();
setSoftKeyboard();
commentEditText.addTextChangedListener(mTextWatcher);
photoButton.setOnClickListener(this);
atButton.setOnClickListener(this);
sendButton.setOnClickListener(this);
return mDialog;
}
public void showNoticeDialog(final Context context, final UpdateResponse response) {
if(response != null && TextUtils.isEmpty(response.path)){
return;
}
StringBuilder updateMsg = new StringBuilder();
updateMsg.append(response.version);
updateMsg.append(context.getString(R.string.analysissdk_update_new_impress));
updateMsg.append("\n");
updateMsg.append(response.content);
updateMsg.append("\n");
updateMsg.append(context.getString(R.string.analysissdk_update_apk_size, sizeToString(response.size)));
final Dialog dialog = new Dialog(context, R.style.AnalysisSDK_CommonDialog);
dialog.setContentView(R.layout.analysissdk_update_notify_dialog);
TextView tvContent = (TextView) dialog.findViewById(R.id.update_tv_dialog_content);
tvContent.setMovementMethod(ScrollingMovementMethod.getInstance());
tvContent.setText(updateMsg);
final CheckBox cBox = (CheckBox) dialog.findViewById(R.id.update_cb_ignore);
if(UpdateConfig.isUpdateForce()){
cBox.setVisibility(View.GONE);
}else {
cBox.setVisibility(View.VISIBLE);
}
android.view.View.OnClickListener ocl = new android.view.View.OnClickListener() {
public void onClick(View v) {
if(v.getId() == R.id.update_btn_dialog_ok){
dialogBtnClick = UpdateStatus.Update;
}else if(v.getId() == R.id.update_btn_dialog_cancel){
if(cBox.isChecked()){
dialogBtnClick = UpdateStatus.Ignore;
}
}
dialog.dismiss();
UpdateAgent.updateDialogDismiss(context, dialogBtnClick, response);
}
};
dialog.findViewById(R.id.update_btn_dialog_ok).setOnClickListener(ocl);
dialog.findViewById(R.id.update_btn_dialog_cancel).setOnClickListener(ocl);
dialog.setCanceledOnTouchOutside(false);
dialog.setCancelable(true);
dialog.show();
}
public static < T extends View > T find(final Dialog dialog, final int id) {
return (T) dialog.findViewById(id);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);
MobileAds.initialize(this, "ca-app-pub-3341550634619945~1422870532");
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setDefaultFontPath("fonts/brownregular.ttf")
.setFontAttrId(R.attr.fontPath)
.build()
);
prefs = getSharedPreferences("Plex", Activity.MODE_PRIVATE);
editor = prefs.edit();
mContext = MainActivity.this;
btn_one = findViewById(R.id.btn_one);
btn_two = findViewById(R.id.btn_two);
btn_three = findViewById(R.id.btn_three);
btn_four = findViewById(R.id.btn_four);
btn_five = findViewById(R.id.btn_five);
btn_one.setOnClickListener(this);
btn_two.setOnClickListener(this);
btn_three.setOnClickListener(this);
btn_four.setOnClickListener(this);
btn_five.setOnClickListener(this);
upadate_retrofit();
get_API_keys();
analytics();
if(!isPackageInstalled()){
final Dialog dialog = new Dialog(MainActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.alertdialog_update);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
dialog.setCancelable(true);
dialog.show();
Button update_btn = dialog.findViewById(R.id.update_btn);
TextView title_view = dialog.findViewById(R.id.title);
TextView message_update = dialog.findViewById(R.id.message_update);
ImageView background_image = dialog.findViewById(R.id.background_image);
background_image.setImageResource(R.drawable.mxplayer);
title_view.setText("");
message_update.setText("For better streaming quality and subtitle \nDownload MX Player app");
update_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.cancel();
final String appPackageName = "com.mxtech.videoplayer.ad"; // getPackageName() from Context or Activity object
try {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + appPackageName)));
} catch (android.content.ActivityNotFoundException anfe) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + appPackageName)));
}
}
});
}
}
public void test3Buttons() throws Throwable {
runTestOnUiThread(new Runnable() {
@Override
public void run() {
activity.findViewById(R.id.btn_3_buttons).performClick();
activity.getSupportFragmentManager().executePendingTransactions();
}
});
getInstrumentation().waitForIdleSync();
Fragment f = getActivity().getSupportFragmentManager().findFragmentByTag("dialog");
assertNotNull(f);
Dialog d = ((SimpleAlertDialogSupportFragment) f).getDialog();
assertNotNull(d);
View positive = d.findViewById(R.id.button_positive);
assertNotNull(positive);
final View negative = d.findViewById(R.id.button_negative);
assertNotNull(negative);
runTestOnUiThread(new Runnable() {
@Override
public void run() {
negative.performClick();
}
});
getInstrumentation().waitForIdleSync();
runTestOnUiThread(new Runnable() {
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void run() {
activity.findViewById(R.id.btn_3_buttons).performClick();
activity.getSupportFragmentManager().executePendingTransactions();
}
});
getInstrumentation().waitForIdleSync();
f = getActivity().getSupportFragmentManager().findFragmentByTag("dialog");
assertNotNull(f);
d = ((SimpleAlertDialogSupportFragment) f).getDialog();
assertNotNull(d);
final View neutral = d.findViewById(R.id.button_neutral);
assertNotNull(neutral);
runTestOnUiThread(new Runnable() {
@Override
public void run() {
neutral.performClick();
}
});
getInstrumentation().waitForIdleSync();
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
switch (item.getItemId()) {
case R.id.changelog:
final Dialog popup = new Dialog(this);
popup.requestWindowFeature(Window.FEATURE_NO_TITLE);
popup.setContentView(R.layout.dialog);
TextView text1 = (TextView) popup.findViewById(R.id.text1);
text1.setText(getString(R.string.changelog_title));
TextView text2 = (TextView) popup.findViewById(R.id.text2);
text2.setText(getString(R.string.changelog));
popup.show();
Button closebutton = (Button) popup.findViewById(R.id.button2);
closebutton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Close dialog
popup.dismiss();
}
});
return true;
}
return super.onOptionsItemSelected(item);
}