Java Code Examples for android.support.v7.app.AlertDialog.Builder

The following are Jave code examples for showing how to use Builder of the android.support.v7.app.AlertDialog class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: GitHub   File: Buildable.java   Source Code and License Vote up 6 votes
protected BuildBean buildMdLoading(BuildBean bean) {
    AlertDialog.Builder builder = new AlertDialog.Builder(bean.mContext);
    View root;
    if (bean.isVertical) {
        root = View.inflate(bean.mContext, R.layout.dialogui_loading_vertical, null);
    } else {
        root = View.inflate(bean.mContext, R.layout.dialogui_loading_horizontal, null);
    }
    View llBg = (View) root.findViewById(R.id.dialogui_ll_bg);
    ProgressBar pbBg = (ProgressBar) root.findViewById(R.id.pb_bg);
    TextView tvMsg = (TextView) root.findViewById(R.id.dialogui_tv_msg);
    tvMsg.setText(bean.msg);
    if (bean.isWhiteBg) {
        llBg.setBackgroundResource(R.drawable.dialogui_shape_wihte_round_corner);
        pbBg.setIndeterminateDrawable(bean.mContext.getResources().getDrawable(R.drawable.dialogui_rotate_mum));
        tvMsg.setTextColor(bean.mContext.getResources().getColor(R.color.text_black));
    } else {
        llBg.setBackgroundResource(R.drawable.dialogui_shape_gray_round_corner);
        pbBg.setIndeterminateDrawable(bean.mContext.getResources().getDrawable(R.drawable.dialogui_rotate_mum_light));
        tvMsg.setTextColor(Color.WHITE);
    }
    builder.setView(root);
    AlertDialog dialog = builder.create();
    bean.alertDialog = dialog;
    return bean;
}
 
Example 2
Project: Guanajoven   File: TwitterFragment.java   Source Code and License Vote up 6 votes
private void actualizar() {
    PAGINA = 1;
    statuses.clear();
    adapter.notifyDataSetChanged();
    adapter = null;

    try {
        tvEmptyTweets.setVisibility(View.GONE);
        Paging page = new Paging(PAGINA, 10);
        statuses.addAll(TWITTER.getUserTimeline(USER, page));
        PAGINA++;
    } catch (TwitterException exception) {
        AlertDialog.Builder mensajeError = new AlertDialog.Builder(getContext());
        mensajeError.create();
        mensajeError.setMessage("Necesitas estar conectado para poder ver los ultimos tweets");
        mensajeError.show();
        tvEmptyTweets.setVisibility(View.VISIBLE);
    }

    adapter = new RVTweetAdapter(getActivity(), statuses);
    rvTweets.setAdapter(adapter);
    swipeRefreshLayoutTwitter.setRefreshing(false);
}
 
Example 3
Project: CollegeDoc   File: Subjects.java   Source Code and License Vote up 6 votes
public void confirmation_dialogbox(final DatabaseReference databaseReference1, final String new_subject)
{
    DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            switch (which){
                case DialogInterface.BUTTON_POSITIVE:
                    databaseReference1.push().setValue(new_subject);
                    //Yes button clicked
                    break;

                case DialogInterface.BUTTON_NEGATIVE:
                    //No button clicked
                    break;
            }
        }
    };

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setMessage("Are you sure want to create new subject with name "+new_subject+" ?").setPositiveButton("Yes", dialogClickListener)
            .setNegativeButton("No", dialogClickListener).show();
}
 
Example 4
Project: Swface   File: FaceDetailActivity.java   Source Code and License Vote up 6 votes
private void showDetailDialog(Face face) {
	AlertDialog.Builder builder = new AlertDialog.Builder(this);
	builder.setTitle("人脸分析详情");
	ScrollView scrollView = new ScrollView(this);
	TextView textView = new TextView(this);
	textView.setTextColor(Color.BLACK);
	textView.setText(face.toString());
	scrollView.addView(textView);
	//builder.setMessage(face.toString());
	builder.setView(scrollView);
	builder.setCancelable(true);
	builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
		@Override
		public void onClick(DialogInterface dialogInterface, int i) {
			dialogInterface.dismiss();
		}
	});
	dialog = builder.show();
	WindowManager.LayoutParams layoutParams = dialog.getWindow().getAttributes();
	layoutParams.alpha = 0.6f;
	dialog.getWindow().setAttributes(layoutParams);
}
 
Example 5
Project: GitHub   File: MessageDialog.java   Source Code and License Vote up 6 votes
@SuppressLint("InflateParams")
@Override
public AlertDialog onCreateDialog(Bundle savedInstanceState) {
	View dialogView = LayoutInflater.from(getActivity())
			.inflate(R.layout.dialog_message, null);

	TextView messageView = (TextView) dialogView.findViewById(R.id.message);
	messageView.setMovementMethod(LinkMovementMethod.getInstance());
	messageView.setText(Html.fromHtml(getArguments().getString(ARG_MESSAGE)));

	AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), R.style.AppTheme_AlertDialog);
	builder.setTitle(getArguments().getString(ARG_TITLE))
			.setIcon(getArguments().getInt(ARG_ICON))
			.setView(dialogView)
			.setPositiveButton(R.string.OK, new OnClickListener() {
				@Override
				public void onClick(DialogInterface dialog, int which) {
					dialog.dismiss();
				}
			});

	return builder.create();
}
 
Example 6
Project: Farmacias   File: DialogOpeningHoursPharmacy.java   Source Code and License Vote up 6 votes
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    Bundle bundle = getArguments();
    this.layoutId = bundle.getInt(LAYOUT_KEY);
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View v = inflater.inflate(layoutId, null);
    RelativeLayout title = (RelativeLayout) v.findViewById(R.id.titleDialog);
    if (bundle.containsKey(COLOR_KEY)) {
        this.backgroundTitleColor = bundle.getInt(COLOR_KEY);
        title.setBackgroundColor(backgroundTitleColor);
    }


    //    View title = inflater.inflate(R.layout.dialog_openinghours_title,null);
    builder.setView(v);
    builder.setPositiveButton(R.string.dialog_ok_button, null);
    //    builder.setCustomTitle(title);
    builder.setIcon(R.drawable.clock);
    //  builder.setMessage(R.string.dialog_mensaje);


    return builder.create();
}
 
Example 7
Project: XposedNavigationBar   File: ClipboardActivity.java   Source Code and License Vote up 6 votes
private void initAction() {
    View dialogView = LayoutInflater.from(this).inflate(R.layout.d_clip, null);
    rcvDialogApps = (RecyclerView) dialogView.findViewById(R.id.rcv_dialog_clip);
    rcvDialogApps.setLayoutManager(new LinearLayoutManager(this));
    rcvDialogApps.setHasFixedSize(true);
    DialogClipAdapter adapter = new DialogClipAdapter(clipData);
    rcvDialogApps.setAdapter(adapter);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle(getResources().getString(R.string.clipboard))
            .setView(dialogView)
            .setNegativeButton(R.string.no,null)
            .setOnDismissListener(new DialogInterface.OnDismissListener() {
                @Override
                public void onDismiss(DialogInterface dialogInterface) {
                    Log.i(TAG, "onDismiss: ");
                    finish();
                }
            }).create().show();
}
 
Example 8
Project: VelocityCalculator   File: CalibrationActivity.java   Source Code and License Vote up 5 votes
public void calibrate(View view) {
    // Show calibration screen
    EditText editText2 = (EditText)findViewById(R.id.editText2);
    EditText editText3 = (EditText)findViewById(R.id.editText3);
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
    SharedPreferences.Editor editor = sharedPreferences.edit();
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    try {
        if (!editText2.getText().toString().isEmpty() && !editText3.getText().toString().isEmpty()) {
            // Save valuesget vid
            calibrationWidth = Double.parseDouble(editText2.getText().toString());
            calibrationDistance = Double.parseDouble(editText3.getText().toString());
            editor.putLong(getString(R.string.calibration_distance_key), Double.doubleToLongBits(calibrationDistance));
            editor.putLong(getString(R.string.calibration_width_key), Double.doubleToLongBits(calibrationWidth));
            editor.apply();
            alertDialogBuilder.setMessage(getString(R.string.text_calibrationsuccess))
                    .setCancelable(false)
                    .setPositiveButton(getString(android.R.string.ok), new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            finish();
                        }
                    })
                    .show();


        } else {
            alertDialogBuilder.setMessage(R.string.text_notCalibrated)
                    .show();

        }
    } catch (NullPointerException e) {
        e.printStackTrace();
        alertDialogBuilder.setMessage(R.string.text_notCalibrated)
                .show();
    }
}
 
Example 9
Project: tumbviewer   File: SearchActivity.java   Source Code and License Vote up 5 votes
private void showDeleteDialog(final  String text, final int position) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.download_delete_title);
        builder.setPositiveButton(R.string.delete_positive, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
//                historyHelper.remove(text);
                adapter.notifyItemRemoved(position);
            }
        });
        builder.create().show();
    }
 
Example 10
Project: OpenPad-for-Android   File: MainActivity.java   Source Code and License Vote up 5 votes
/**
 * 메인 리스트에서 파일을 제거하는 메소드
 * @param _index 제거할 파일의 인덱스
 */
private void deleteFile(final int _index) {
    AlertDialog.Builder dialog = new AlertDialog.Builder(this);
    dialog.setTitle(R.string.file_dialog_title_delete);
    dialog.setMessage(R.string.file_dialog_message_question_delete);
    DialogInterface.OnClickListener clickListener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface _dialog, int _which) {
            if (_which == AlertDialog.BUTTON_POSITIVE) {
                File file = new File(mCurFolderFileList.get(_index).mFilePath);
                if (file.exists()) {
                    if (file.delete()) {
                        Snackbar.make(mContextView, R.string.file_dialog_toast_delete, Snackbar.LENGTH_SHORT).show();
                        mCurFolderFileList.remove(_index);
                        mCurFolderGridView.removeViewAt(_index);
                        mCurFileAdapter.notifyItemRemoved(_index);
                        mCurFileAdapter.notifyItemRangeChanged(_index, mCurFolderFileList.size());
                        mCurFileAdapter.notifyDataSetChanged();
                    } else {
                        Snackbar.make(mContextView, R.string.error_folder_not_exist, Snackbar.LENGTH_SHORT).show();
                    }
                }
            }
            _dialog.dismiss();
        }
    };
    dialog.setNegativeButton(R.string.folder_dialog_button_cancel, clickListener);
    dialog.setPositiveButton(R.string.folder_dialog_button_delete, clickListener);
    dialog.show();
}
 
Example 11
Project: ActivityDiary   File: HistoryRecyclerViewAdapter.java   Source Code and License Vote up 5 votes
@Override
public boolean onDetailItemLongClick(final int adapterPosition) {
    //TODO: generalize the DetailView to include this code also
    //      such that it is not duplicated between MainActivity and HistoryRecyclerViewAdapter
    AlertDialog.Builder builder = new AlertDialog.Builder(mContext)
            .setTitle(R.string.dlg_delete_image_title)
            .setMessage(R.string.dlg_delete_image_text)
            .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {

                public void onClick(DialogInterface dialog, int whichButton) {
                    ContentValues values = new ContentValues();
                    values.put(ActivityDiaryContract.DiaryImage._DELETED, 1);

                    mContext.mQHandler.startUpdate(0,
                            null,
                            ActivityDiaryContract.DiaryImage.CONTENT_URI,
                            values,
                            ActivityDiaryContract.DiaryImage._ID + "=?",
                            new String[]{Long.toString(
                                    mViewHolders.get(adapterPosition).mDetailAdapter.getDiaryImageIdAt(adapterPosition))}
                    );

                }})
            .setNegativeButton(android.R.string.no, null);

    builder.create().show();
    return true;
}
 
Example 12
Project: OSchina_resources_android   File: DialogHelper.java   Source Code and License Vote up 5 votes
/**
 * 获取一个验证对话框,没有点击事件,取消、确定
 */
public static AlertDialog.Builder getConfirmDialog(
        Context context,
        String title,
        String message) {
    return getConfirmDialog(context, title, message, "确定", "取消", false, null, null);
}
 
Example 13
Project: eyeRS   File: NewItemActivity.java   Source Code and License Vote up 5 votes
private void selectImage() {
        final String[] items = {"Take Photo", /*"Choose from Library",*/ "Cancel"};

        try {

            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Add Photo!");
            builder.setItems(items, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int item) {
                    boolean result = EyeRS.checkPermission(NewItemActivity.this);

                    if (items[item].equals("Take Photo")) {
                        userChoosenTask = "Take Photo";
                        if (result) {
                            cameraIntent();
                        }
                    }
//                    else if (items[item].equals("Choose from Library")) {
//                        userChoosenTask = "Choose from Library";
//                        if (result)
//                            galleryIntent();
//
//                    }
                    else if (items[item].equals("Cancel")) {
                        dialog.dismiss();
                    }
                }
            });
            builder.show();
        } catch (Exception ex) {

            Log.e("selectImage()", ex.getMessage(), ex);
        }
    }
 
Example 14
Project: social-app-android   File: BaseActivity.java   Source Code and License Vote up 4 votes
public void showWarningDialog(String message) {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage(message);
    builder.setPositiveButton(R.string.button_ok, null);
    builder.show();
}
 
Example 15
Project: Idea-ijkplayer   File: IjkVideoView.java   Source Code and License Vote up 4 votes
public void showMediaInfo() {
    if (mMediaPlayer == null)
        return;

    int selectedVideoTrack = MediaPlayerCompat.getSelectedTrack(mMediaPlayer, ITrackInfo.MEDIA_TRACK_TYPE_VIDEO);
    int selectedAudioTrack = MediaPlayerCompat.getSelectedTrack(mMediaPlayer, ITrackInfo.MEDIA_TRACK_TYPE_AUDIO);
    int selectedSubtitleTrack = MediaPlayerCompat.getSelectedTrack(mMediaPlayer, ITrackInfo.MEDIA_TRACK_TYPE_TIMEDTEXT);

    TableLayoutBinder builder = new TableLayoutBinder(getContext());
    builder.appendSection(R.string.mi_player);
    builder.appendRow2(R.string.mi_player, MediaPlayerCompat.getName(mMediaPlayer));
    builder.appendSection(R.string.mi_media);
    builder.appendRow2(R.string.mi_resolution, buildResolution(mVideoWidth, mVideoHeight, mVideoSarNum, mVideoSarDen));
    builder.appendRow2(R.string.mi_length, buildTimeMilli(mMediaPlayer.getDuration()));

    ITrackInfo trackInfos[] = mMediaPlayer.getTrackInfo();
    if (trackInfos != null) {
        int index = -1;
        for (ITrackInfo trackInfo : trackInfos) {
            index++;

            int trackType = trackInfo.getTrackType();
            if (index == selectedVideoTrack) {
                builder.appendSection(getContext().getString(R.string.mi_stream_fmt1, index) + " " + getContext().getString(R.string.mi__selected_video_track));
            } else if (index == selectedAudioTrack) {
                builder.appendSection(getContext().getString(R.string.mi_stream_fmt1, index) + " " + getContext().getString(R.string.mi__selected_audio_track));
            } else if (index == selectedSubtitleTrack) {
                builder.appendSection(getContext().getString(R.string.mi_stream_fmt1, index) + " " + getContext().getString(R.string.mi__selected_subtitle_track));
            } else {
                builder.appendSection(getContext().getString(R.string.mi_stream_fmt1, index));
            }
            builder.appendRow2(R.string.mi_type, buildTrackType(trackType));
            builder.appendRow2(R.string.mi_language, buildLanguage(trackInfo.getLanguage()));

            IMediaFormat mediaFormat = trackInfo.getFormat();
            if (mediaFormat == null) {
            } else if (mediaFormat instanceof IjkMediaFormat) {
                switch (trackType) {
                    case ITrackInfo.MEDIA_TRACK_TYPE_VIDEO:
                        builder.appendRow2(R.string.mi_codec, mediaFormat.getString(IjkMediaFormat.KEY_IJK_CODEC_LONG_NAME_UI));
                        builder.appendRow2(R.string.mi_profile_level, mediaFormat.getString(IjkMediaFormat.KEY_IJK_CODEC_PROFILE_LEVEL_UI));
                        builder.appendRow2(R.string.mi_pixel_format, mediaFormat.getString(IjkMediaFormat.KEY_IJK_CODEC_PIXEL_FORMAT_UI));
                        builder.appendRow2(R.string.mi_resolution, mediaFormat.getString(IjkMediaFormat.KEY_IJK_RESOLUTION_UI));
                        builder.appendRow2(R.string.mi_frame_rate, mediaFormat.getString(IjkMediaFormat.KEY_IJK_FRAME_RATE_UI));
                        builder.appendRow2(R.string.mi_bit_rate, mediaFormat.getString(IjkMediaFormat.KEY_IJK_BIT_RATE_UI));
                        break;
                    case ITrackInfo.MEDIA_TRACK_TYPE_AUDIO:
                        builder.appendRow2(R.string.mi_codec, mediaFormat.getString(IjkMediaFormat.KEY_IJK_CODEC_LONG_NAME_UI));
                        builder.appendRow2(R.string.mi_profile_level, mediaFormat.getString(IjkMediaFormat.KEY_IJK_CODEC_PROFILE_LEVEL_UI));
                        builder.appendRow2(R.string.mi_sample_rate, mediaFormat.getString(IjkMediaFormat.KEY_IJK_SAMPLE_RATE_UI));
                        builder.appendRow2(R.string.mi_channels, mediaFormat.getString(IjkMediaFormat.KEY_IJK_CHANNEL_UI));
                        builder.appendRow2(R.string.mi_bit_rate, mediaFormat.getString(IjkMediaFormat.KEY_IJK_BIT_RATE_UI));
                        break;
                    default:
                        break;
                }
            }
        }
    }

    AlertDialog.Builder adBuilder = builder.buildAlertDialogBuilder();
    adBuilder.setTitle(R.string.media_information);
    adBuilder.setNegativeButton(R.string.close, null);
    adBuilder.show();
}
 
Example 16
Project: referendum_1o_android   File: MainActivity.java   Source Code and License Vote up 4 votes
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.action_share:
            //Allow changing the share message via Firebase
            FirebaseRemoteConfig firebaseRemoteConfig = FirebaseRemoteConfig.getInstance();
            firebaseRemoteConfig.setDefaults(R.xml.remote_config_defaults);
            String shareBody = firebaseRemoteConfig.getString(Constants.FIREBASE_CONFIG_SHARE_APP_MESSAGEREQUIRED + "_" + StringsManager.getCurrentLanguage());
            Intent sharingIntent = new Intent(android.content.Intent.ACTION_SEND);
            sharingIntent.setType("text/plain");
            sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, StringsManager.getString("share_subject"));
            sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, shareBody);
            startActivity(Intent.createChooser(sharingIntent, StringsManager.getString("share_select")));
            return true;
        case R.id.action_language:
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle(StringsManager.getString("change_language_title"));

            String[] languages = new String[]{"Català", "Aranés", "Castellano", "English"};

            builder.setItems(languages, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String newLang;
                    switch (which) {
                        case 0:
                        default:
                            newLang = "ca";
                            break;
                        case 1:
                            newLang = "oc";
                            break;
                        case 2:
                            newLang = "es";
                            break;
                        case 3:
                            newLang = "en";
                            break;
                    }
                    if (!newLang.equals(StringsManager.getCurrentLanguage())) {
                        StringsManager.setLanguage(newLang);
                        Intent intent = new Intent(MainActivity.this, MainActivity.class);
                        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                        startActivity(intent);
                        finish();
                    }
                    dialog.dismiss();
                }
            });
            builder.show();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example 17
Project: topnews   File: SignActivity.java   Source Code and License Vote up 4 votes
/**
 * 验证码输入框
 */
private void showCodeDialog(){

    AlertDialog.Builder builder=new AlertDialog.Builder(SignActivity.this);
    builder.setTitle("请输入验证码");

    View view=View.inflate(SignActivity.this,R.layout.sms_code_confirm,null);

    editText = (SecurityCodeView) view.findViewById(R.id.scv_edittext);
    text = (TextView) view.findViewById(R.id.tv_text);

    setListener();

    builder.setView(view);
    dialog = builder.show();
}
 
Example 18
Project: FireFiles   File: CreateConnectionFragment.java   Source Code and License Vote up 4 votes
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Context context = getActivity();

    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    final LayoutInflater dialogInflater = getActivity().getLayoutInflater();

    final View view = dialogInflater.inflate(R.layout.dialog_create_connection, null, false);
    name = (AppCompatEditText) view.findViewById(R.id.name);
    host = (AppCompatEditText) view.findViewById(R.id.host);
    port = (AppCompatEditText) view.findViewById(R.id.port);
    path = (AppCompatEditText) view.findViewById(R.id.path);
    hostContainer = view.findViewById(R.id.hostContainer);
    pathContainer = view.findViewById(R.id.pathContainer);
    username = (AppCompatEditText) view.findViewById(R.id.username);
    usernameContainer = view.findViewById(R.id.usernameContainer);
    password = (AppCompatEditText) view.findViewById(R.id.password);
    passwordContainer = view.findViewById(R.id.passwordContainer);
    scheme = (AppCompatSpinner) view.findViewById(R.id.scheme);
    anonymous = (AppCompatCheckBox) view.findViewById(R.id.anonymous);
    anonymous.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            usernameContainer.setVisibility(b ? View.GONE : View.VISIBLE);
            passwordContainer.setVisibility(b ? View.GONE : View.VISIBLE);
        }
    });

    if(connection_id != 0){
        NetworkConnection connection =
                NetworkConnection.fromConnectionId(getActivity(), connection_id);

        ArrayAdapter myAdap = (ArrayAdapter) scheme.getAdapter();
        int spinnerPosition = myAdap.getPosition(connection.getScheme().toUpperCase());
        scheme.setSelection(spinnerPosition);

        name.setText(connection.getName());
        host.setText(connection.getHost());
        port.setText(Integer.toString(connection.getPort()));
        path.setText(connection.getPath());
        username.setText(connection.getUserName());
        password.setText(connection.getPassword());
        anonymous.setChecked(connection.isAnonymousLogin());
        if(SERVER.equals(connection.getType())){
            hostContainer.setVisibility(View.GONE);
            pathContainer.setVisibility(View.VISIBLE);
        }
    }
    builder.setTitle( (connection_id == 0 ? "New" : "Edit") + " Connection");
    builder.setView(view);

    builder.setPositiveButton(connection_id == 0 ? "ADD" : "SAVE", new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            final BaseActivity activity = (BaseActivity) getActivity();

            NetworkConnection networkConnection = getNetworkConnection();
            if(validate(networkConnection)){
                new CreateConnectionTask(activity, networkConnection).executeOnExecutor(
                        ProviderExecutor.forAuthority(ExplorerProvider.AUTHORITY));
            }

        }
    });
    builder.setNegativeButton(android.R.string.cancel, null);

    return builder.create();
}
 
Example 19
Project: Phoenix-for-VK   File: InputTextDialog.java   Source Code and License Vote up 4 votes
public void show() {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(titleRes);
    View view = View.inflate(context, R.layout.dialog_enter_text, null);

    final EditText input = (EditText) view.findViewById(R.id.editText);
    input.setText(value);
    input.setSelection(input.getText().length());

    if (hint != null) {
        input.setHint(hint);
    }

    input.setInputType(inputType);
    builder.setView(view);
    builder.setPositiveButton(R.string.button_ok, null);
    builder.setNegativeButton(R.string.button_cancel, (dialog, which) -> dialog.cancel());

    final AlertDialog alertDialog = builder.create();
    alertDialog.setOnShowListener(dialog -> {
        Button b = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);

        b.setOnClickListener(view1 -> {
            input.setError(null);
            String newValue = input.getText().toString().trim();

            if (TextUtils.isEmpty(newValue) && !allowEmpty) {
                input.setError(context.getString(R.string.field_is_required));
                input.requestFocus();
            } else {
                try {
                    if (validator != null) {
                        validator.validate(newValue);
                    }

                    if (callback != null) {
                        callback.onChanged(newValue);
                    }

                    if (target != null) {
                        target.setText(newValue);
                    }

                    alertDialog.dismiss();
                } catch (IllegalArgumentException e) {
                    input.setError(e.getMessage());
                    input.requestFocus();
                }
            }
        });
    });

    alertDialog.setOnDismissListener(onDismissListener);
    alertDialog.show();

    input.post(() -> {
        InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(input, InputMethodManager.SHOW_IMPLICIT);
    });
}
 
Example 20
Project: PictureShow   File: ConfirmDialog.java   Source Code and License Vote up 4 votes
public AlertDialog.Builder setView(int resLayout, int editId) {
    mEditable = true;
    View v = layoutInflater.inflate(resLayout, null);
    editText = v.findViewById(editId);
    return internalDialogBuilder.setView(v);
}