android.app.AlertDialog#findViewById ( )源码实例Demo

下面列出了android.app.AlertDialog#findViewById ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: msdkui-android   文件: NumericOptionItemTest.java
@Test
public void testValueEditDialogPositive() {
    int newValue = 10;
    mNumericOptionItem.setLabel(getString(R.string.msdkui_violate_truck_options));
    final TextView valueView = mNumericOptionItem.findViewById(R.id.numeric_item_value);

    assertNotNull(valueView);
    valueView.performClick();

    AlertDialog alertDialog = (AlertDialog) ShadowDialog.getLatestDialog();
    assertTrue(alertDialog.isShowing());

    EditText valueEdit = alertDialog.findViewById(R.id.numeric_item_value_text);
    valueEdit.setText(String.valueOf(newValue));
    alertDialog.getButton(DialogInterface.BUTTON_POSITIVE).performClick();
    assertEquals(newValue, mNumericOptionItem.getValue().intValue());
}
 
源代码2 项目: WiFiAnalyzer   文件: AboutFragment.java
@Override
public void onClick(View view) {
    if (!activity.isFinishing()) {
        String text = FileUtils.readFile(activity.getResources(), resourceId);
        AlertDialog alertDialog = new AlertDialog
            .Builder(view.getContext())
            .setTitle(titleId)
            .setMessage(text)
            .setNeutralButton(android.R.string.ok, new Close())
            .create();
        alertDialog.show();
        if (isSmallFont) {
            TextView textView = alertDialog.findViewById(android.R.id.message);
            textView.setTextSize(8);
        }
    }
}
 
源代码3 项目: caffeine   文件: DialogUtils.java
/**
 * Show a model dialog box.  The <code>android.app.AlertDialog</code> object is returned so that
 * you can specify an OnDismissListener (or other listeners) if required.
 * <b>Note:</b> show() is already called on the AlertDialog being returned.
 *
 * @param context The current Context or Activity that this method is called from.
 * @param message Message to display in the dialog.
 * @return AlertDialog that is being displayed.
 */
public static AlertDialog quickDialog(final Activity context, final String message) {
    final SpannableString s = new SpannableString(message); //Make links clickable
    Linkify.addLinks(s, Linkify.ALL);

    final Builder builder = new AlertDialog.Builder(context);
    builder.setMessage(s);
    builder.setPositiveButton(android.R.string.ok, closeDialogListener());
    AlertDialog dialog = builder.create();
    if(!context.isFinishing()) {
        dialog.show();
        final TextView textView = (TextView) dialog.findViewById(android.R.id.message);
        if (textView != null) {
            textView.setMovementMethod(LinkMovementMethod.getInstance()); //Make links clickable
        }
    }

    return dialog;
}
 
public void onShow(DialogInterface dialogInterface) {
    final AlertDialog dialog = (AlertDialog) dialogInterface;
    final RecyclerView listView = dialog.findViewById(android.R.id.list);
    listView.setAdapter(mAdapter);
    if (mDividerDecoration == null) {
        mDividerDecoration = new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL);
        mDividerDecoration.setDoNotDrawForLastItem(true);
    }
    listView.addItemDecoration(mDividerDecoration);
    mAdapter.submitList(mData);
}
 
@Test
public void testCreateDirectoryDialogDisallowFolderNameModification() {
    final String directoryName = "mydir";
    final DirectoryChooserFragment fragment = DirectoryChooserFragment.newInstance(
            DirectoryChooserConfig.builder()
                    .newDirectoryName(directoryName)
                    .initialDirectory("")
                    .allowReadOnlyDirectory(false)
                    .allowNewDirectoryNameModification(false)
                    .build());

    startFragment(fragment, DirectoryChooserActivityMock.class);

    fragment.onOptionsItemSelected(new TestMenuItem() {
        @Override
        public int getItemId() {
            return R.id.new_folder_item;
        }
    });

    final AlertDialog dialog = (AlertDialog) ShadowDialog.getLatestDialog();
    final ShadowAlertDialog shadowAlertDialog = Shadows.shadowOf(dialog);
    assertThat(shadowAlertDialog.getTitle()).isEqualTo("Create folder");
    assertThat(ShadowDialog.getShownDialogs()).contains(dialog);

    final TextView msgView = (TextView) dialog.findViewById(R.id.msgText);
    assertThat(msgView).hasText("Create new folder with name \"mydir\"?");

    final EditText editText = (EditText) dialog.findViewById(R.id.editText);
    assertThat(editText).isGone();
}
 
源代码6 项目: TGPassportAndroidSDK   文件: TelegramPassport.java
/**
 * Show an app installation alert, in case you need to do that yourself.
 * @param activity calling Activity
 */
public static void showAppInstallAlert(final Activity activity){
	String appName=null;
	try{
		PackageManager pm=activity.getPackageManager();
		appName=pm.getApplicationLabel(pm.getApplicationInfo(activity.getPackageName(), 0)).toString().replace("<", "&lt;");
	}catch(PackageManager.NameNotFoundException ignore){}
	ImageView banner=new ImageView(activity);
	banner.setImageResource(R.drawable.telegram_logo_large);
	banner.setBackgroundColor(0xFF4fa9e6);
	float dp=activity.getResources().getDisplayMetrics().density;
	int pad=Math.round(34*dp);
	banner.setPadding(0, pad, 0, pad);
	LinearLayout content=new LinearLayout(activity);
	content.setOrientation(LinearLayout.VERTICAL);
	content.addView(banner);
	TextView alertText=new TextView(activity);
	alertText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
	alertText.setTextColor(0xFF000000);
	alertText.setText(Html.fromHtml(activity.getString(R.string.PassportSDK_DownloadTelegram, appName).replaceAll("\\*\\*([^*]+)\\*\\*", "<b>$1</b>")));
	alertText.setPadding(Math.round(24*dp), Math.round(24*dp), Math.round(24*dp), Build.VERSION.SDK_INT<Build.VERSION_CODES.LOLLIPOP ? Math.round(24*dp) : Math.round(2*dp));
	content.addView(alertText);
	AlertDialog alert=new AlertDialog.Builder(activity, /*Build.VERSION.SDK_INT<Build.VERSION_CODES.LOLLIPOP ? AlertDialog.THEME_HOLO_LIGHT :*/ R.style.Theme_Telegram_Alert)
			.setView(content)
			.setPositiveButton(R.string.PassportSDK_OpenGooglePlay, new DialogInterface.OnClickListener(){
				@Override
				public void onClick(DialogInterface dialog, int which){
					activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=org.telegram.messenger")));
				}
			})
			.setNegativeButton(R.string.PassportSDK_Cancel, null)
			.show();
	if(Build.VERSION.SDK_INT<Build.VERSION_CODES.LOLLIPOP){
		int titleDividerId=activity.getResources().getIdentifier("titleDivider", "id", "android");
		View titleDivider=alert.findViewById(titleDividerId);
		if(titleDivider!=null){
			titleDivider.setVisibility(View.GONE);
		}
	}
}
 
源代码7 项目: lrkFM   文件: BaseArrayAdapter.java
/**
 * Sets file name in the text field of a dialog.
 *
 * @param alertDialog     the dialog
 * @param destinationName the id of the EditText
 * @param name            the name
 */
public void presetNameForDialog(AlertDialog alertDialog, @IdRes int destinationName, String name) {
    EditText editText = alertDialog.findViewById(destinationName);
    if (editText != null) {
        editText.setText(name);
    } else {
        Log.w(TAG, "Unable to find view, can not set file title.");
    }
}
 
源代码8 项目: DMusic   文件: AlertDialogFactory.java
/**
 * LoadingDialog
 */
public AlertDialog getLoadingDialog(String text) {
    final AlertDialog dlg = new AlertDialog
            .Builder(new ContextThemeWrapper(mContext, R.style.lib_pub_dialog_style))
            .create();
    if (mContext instanceof Activity && !((Activity) mContext).isFinishing()) {
        dlg.show();
    }
    dlg.setContentView(R.layout.lib_pub_dialog_loading);
    TextView tips = (TextView) dlg.findViewById(R.id.tv_tips);
    if (text != null) {
        tips.setText(text);
    }
    return dlg;
}
 
源代码9 项目: Hangar   文件: Settings.java
protected void launchThanks(int which) {
        String thankYouMsg = getResources().getString(R.string.donate_thanks);
//        if (which == THANK_YOU_PAYPAL)
//                thankYouMsg += "\n\n" + getResources().getString(R.string.donate_thanks_paypal);

        AlertDialog alert = new AlertDialog.Builder(Settings.this)
                .setTitle(R.string.donate_thanks_title)
                .setIcon(R.drawable.ic_logo)
                .setMessage(thankYouMsg)
                .setPositiveButton(R.string.donate_thanks_continue, null)
                .show();

        TextView msgTxt = (TextView) alert.findViewById(android.R.id.message);
        msgTxt.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);
    }
 
源代码10 项目: reacteu-app   文件: Notification.java
@SuppressLint("NewApi")
private void changeTextDirection(Builder dlg){
    int currentapiVersion = android.os.Build.VERSION.SDK_INT;
    dlg.create();
    AlertDialog dialog =  dlg.show();
    if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
        TextView messageview = (TextView)dialog.findViewById(android.R.id.message);
        messageview.setTextDirection(android.view.View.TEXT_DIRECTION_LOCALE);
    }
}
 
源代码11 项目: caffeine   文件: DialogUtilsTest.java
public void testQuickDialog(){
    AlertDialog alertDialog = DialogUtils.quickDialog(getActivity(), "Test Message");
    assertTrue(alertDialog.isShowing());
    final TextView textView = (TextView) alertDialog.findViewById(android.R.id.message);
    assertEquals("Test Message", textView.getText().toString());
    alertDialog.dismiss();
    assertFalse(alertDialog.isShowing());
}
 
源代码12 项目: cordova-dialog-gps   文件: DialogGPS.java
@SuppressLint("NewApi")
private void changeTextDirection(Builder dlg){
    int currentapiVersion = android.os.Build.VERSION.SDK_INT;
    dlg.create();
    AlertDialog dialog =  dlg.show();
    if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
        TextView messageview = (TextView)dialog.findViewById(android.R.id.message);
        messageview.setTextDirection(android.view.View.TEXT_DIRECTION_LOCALE);
    }
}
 
源代码13 项目: grafika   文件: ReadPixelsActivity.java
/**
 * Prepare for the glReadPixels test.
 */
public ReadPixelsTask(AlertDialog dialog, int resultTextId,
        int width, int height, int iterations) {
    mDialog = dialog;
    mResultTextId = resultTextId;
    mWidth = width;
    mHeight = height;
    mIterations = iterations;

    mProgressBar = (ProgressBar) dialog.findViewById(R.id.work_progress);
    mProgressBar.setMax(mIterations);
}
 
源代码14 项目: commcare-android   文件: CustomProgressDialog.java
private void updateTextView(String newText, int idOfViewToUpdate) {
    AlertDialog dialog = (AlertDialog)getDialog();
    if (dialog != null) {
        TextView tv = dialog.findViewById(idOfViewToUpdate);
        tv.setText(newText);
    }
}
 
源代码15 项目: openScale   文件: MeasurementView.java
private void prepareInputDialog(final AlertDialog dialog) {
    dialog.setTitle(getName());
    dialog.setIcon(getIcon());

    final View input = getInputView();

    FrameLayout fl = dialog.findViewById(android.R.id.custom);
    fl.removeAllViews();
    fl.addView(input, new LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
            LinearLayout.LayoutParams.WRAP_CONTENT));

    View.OnClickListener clickListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (view == dialog.getButton(DialogInterface.BUTTON_POSITIVE)
                && !validateAndSetInput(input)) {
                return;
            }
            dialog.dismiss();
        }
    };

    dialog.getButton(DialogInterface.BUTTON_POSITIVE).setOnClickListener(clickListener);
    dialog.getButton(DialogInterface.BUTTON_NEGATIVE).setOnClickListener(clickListener);

    final MeasurementView next = getNextView();
    if (next != null) {
        dialog.getButton(DialogInterface.BUTTON_NEUTRAL).setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (validateAndSetInput(input)) {
                    next.prepareInputDialog(dialog);
                }
            }
        });
    }
    else {
        dialog.getButton(DialogInterface.BUTTON_NEUTRAL).setVisibility(GONE);
    }
}
 
源代码16 项目: writeily-pro   文件: RenameDialog.java
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final File file = new File(getArguments().getString(Constants.SOURCE_FILE));

    LayoutInflater inflater = LayoutInflater.from(getActivity());
    String theme = PreferenceManager.getDefaultSharedPreferences(getActivity()).getString(getString(R.string.pref_theme_key), "");
    AlertDialog.Builder dialogBuilder = setUpDialog(file, inflater, theme);
    AlertDialog dialog = dialogBuilder.show();
    dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);

    newNameField = (EditText) dialog.findViewById(R.id.new_name);
    return dialog;
}
 
源代码17 项目: reader   文件: Notification.java
@SuppressLint("NewApi")
private void changeTextDirection(Builder dlg){
    int currentapiVersion = android.os.Build.VERSION.SDK_INT;
    dlg.create();
    AlertDialog dialog =  dlg.show();
    if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
        TextView messageview = (TextView)dialog.findViewById(android.R.id.message);
        messageview.setTextDirection(android.view.View.TEXT_DIRECTION_LOCALE);
    }
}
 
源代码18 项目: reader   文件: Notification.java
@SuppressLint("NewApi")
private void changeTextDirection(Builder dlg){
    int currentapiVersion = android.os.Build.VERSION.SDK_INT;
    dlg.create();
    AlertDialog dialog =  dlg.show();
    if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
        TextView messageview = (TextView)dialog.findViewById(android.R.id.message);
        messageview.setTextDirection(android.view.View.TEXT_DIRECTION_LOCALE);
    }
}
 
源代码19 项目: reader   文件: Notification.java
@SuppressLint("NewApi")
private void changeTextDirection(Builder dlg){
    int currentapiVersion = android.os.Build.VERSION.SDK_INT;
    dlg.create();
    AlertDialog dialog =  dlg.show();
    if (currentapiVersion >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1) {
        TextView messageview = (TextView)dialog.findViewById(android.R.id.message);
        messageview.setTextDirection(android.view.View.TEXT_DIRECTION_LOCALE);
    }
}
 
@Test
public void testCreateDirectoryDialogAllowFolderNameModification() {
    final String directoryName = "mydir";
    final DirectoryChooserFragment fragment = DirectoryChooserFragment.newInstance(
            DirectoryChooserConfig.builder()
                    .newDirectoryName(directoryName)
                    .initialDirectory("")
                    .allowReadOnlyDirectory(false)
                    .allowNewDirectoryNameModification(true)
                    .build());

    startFragment(fragment, DirectoryChooserActivityMock.class);

    fragment.onOptionsItemSelected(new TestMenuItem() {
        @Override
        public int getItemId() {
            return R.id.new_folder_item;
        }
    });

    final AlertDialog dialog = (AlertDialog) ShadowDialog.getLatestDialog();
    final ShadowAlertDialog shadowAlertDialog = Shadows.shadowOf(dialog);
    assertThat(shadowAlertDialog.getTitle()).isEqualTo("Create folder");
    assertThat(ShadowDialog.getShownDialogs()).contains(dialog);

    final TextView msgView = (TextView) dialog.findViewById(R.id.msgText);
    assertThat(msgView).hasText("Create new folder with name \"mydir\"?");

    final EditText editText = (EditText) dialog.findViewById(R.id.editText);
    assertThat(editText).isVisible();
    assertThat(editText).hasTextString(directoryName);
}