Java Code Examples for android.app.AlertDialog#findViewById()

The following examples show how to use android.app.AlertDialog#findViewById() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NumericOptionItemTest.java    From msdkui-android with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example 2
Source File: DialogUtils.java    From caffeine with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * 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;
}
 
Example 3
Source File: AboutFragment.java    From WiFiAnalyzer with GNU General Public License v3.0 6 votes vote down vote up
@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);
        }
    }
}
 
Example 4
Source File: DirectoryChooserFragmentTest.java    From Android-DirectoryChooser with Apache License 2.0 5 votes vote down vote up
@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);
}
 
Example 5
Source File: Notification.java    From reader with MIT License 5 votes vote down vote up
@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);
    }
}
 
Example 6
Source File: Notification.java    From reader with MIT License 5 votes vote down vote up
@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);
    }
}
 
Example 7
Source File: Notification.java    From reader with MIT License 5 votes vote down vote up
@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);
    }
}
 
Example 8
Source File: RenameDialog.java    From writeily-pro with MIT License 5 votes vote down vote up
@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;
}
 
Example 9
Source File: MeasurementView.java    From openScale with GNU General Public License v3.0 5 votes vote down vote up
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);
    }
}
 
Example 10
Source File: CustomProgressDialog.java    From commcare-android with Apache License 2.0 5 votes vote down vote up
private void updateTextView(String newText, int idOfViewToUpdate) {
    AlertDialog dialog = (AlertDialog)getDialog();
    if (dialog != null) {
        TextView tv = dialog.findViewById(idOfViewToUpdate);
        tv.setText(newText);
    }
}
 
Example 11
Source File: ReadPixelsActivity.java    From grafika with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example 12
Source File: DialogGPS.java    From cordova-dialog-gps with MIT License 5 votes vote down vote up
@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);
    }
}
 
Example 13
Source File: DialogUtilsTest.java    From caffeine with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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());
}
 
Example 14
Source File: Notification.java    From reacteu-app with MIT License 5 votes vote down vote up
@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);
    }
}
 
Example 15
Source File: Settings.java    From Hangar with GNU General Public License v3.0 5 votes vote down vote up
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);
    }
 
Example 16
Source File: AlertDialogFactory.java    From DMusic with Apache License 2.0 5 votes vote down vote up
/**
 * 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;
}
 
Example 17
Source File: BaseArrayAdapter.java    From lrkFM with MIT License 5 votes vote down vote up
/**
 * 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.");
    }
}
 
Example 18
Source File: TelegramPassport.java    From TGPassportAndroidSDK with MIT License 5 votes vote down vote up
/**
 * 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);
		}
	}
}
 
Example 19
Source File: DirectoryChooserFragmentTest.java    From Android-DirectoryChooser with Apache License 2.0 5 votes vote down vote up
@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();
}
 
Example 20
Source File: ViewBarcodeActivity.java    From EnhancedScreenshotNotification with GNU General Public License v3.0 5 votes vote down vote up
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);
}