Java Code Examples for android.app.Dialog#BUTTON_POSITIVE

The following examples show how to use android.app.Dialog#BUTTON_POSITIVE . 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: WvWebView.java    From YCWebView with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onJsConfirm(WebView view, String url, String message, final JsResult result) {
    if(!alertBoxBlock){
        result.confirm();
    }
    DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if(alertBoxBlock) {
                if (which == Dialog.BUTTON_POSITIVE) {
                    result.confirm();
                } else {
                    result.cancel();
                }
            }
        }
    };
    new AlertDialog.Builder(getContext())
            .setMessage(message)
            .setCancelable(false)
            .setPositiveButton(android.R.string.ok, listener)
            .setNegativeButton(android.R.string.cancel, listener).show();
    return true;
}
 
Example 2
Source File: RationaleDialogClickListener.java    From BaseProject with MIT License 6 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
    if (which == Dialog.BUTTON_POSITIVE) {
        if (mHost instanceof Fragment) {
            PermissionHelper.newInstance((Fragment) mHost).directRequestPermissions(
                    mConfig.requestCode, mConfig.permissions);
        } else if (mHost instanceof android.app.Fragment) {
            PermissionHelper.newInstance((android.app.Fragment) mHost).directRequestPermissions(
                    mConfig.requestCode, mConfig.permissions);
        } else if (mHost instanceof Activity) {
            PermissionHelper.newInstance((Activity) mHost).directRequestPermissions(
                    mConfig.requestCode, mConfig.permissions);
        } else {
            throw new RuntimeException("Host must be an Activity or Fragment!");
        }
    } else {
        notifyPermissionDenied();
    }
}
 
Example 3
Source File: RationaleDialogClickListener.java    From easypermissions with Apache License 2.0 6 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
    int requestCode = mConfig.requestCode;
    if (which == Dialog.BUTTON_POSITIVE) {
        String[] permissions = mConfig.permissions;
        if (mRationaleCallbacks != null) {
            mRationaleCallbacks.onRationaleAccepted(requestCode);
        }
        if (mHost instanceof Fragment) {
            PermissionHelper.newInstance((Fragment) mHost).directRequestPermissions(requestCode, permissions);
        } else if (mHost instanceof Activity) {
            PermissionHelper.newInstance((Activity) mHost).directRequestPermissions(requestCode, permissions);
        } else {
            throw new RuntimeException("Host must be an Activity or Fragment!");
        }
    } else {
        if (mRationaleCallbacks != null) {
            mRationaleCallbacks.onRationaleDenied(requestCode);
        }
        notifyPermissionDenied();
    }
}
 
Example 4
Source File: AppSettingsDialogHolderActivity.java    From BaseProject with MIT License 5 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
    if (which == Dialog.BUTTON_POSITIVE) {
        startActivityForResult(
                new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
                        .setData(Uri.fromParts("package", getPackageName(), null)),
                APP_SETTINGS_RC);
    } else if (which == Dialog.BUTTON_NEGATIVE) {
        setResult(Activity.RESULT_CANCELED);
        finish();
    } else {
        throw new IllegalStateException("Unknown button type: " + which);
    }
}
 
Example 5
Source File: LabelDialogManager.java    From talkback with Apache License 2.0 5 votes vote down vote up
@Override
public void handleDialogClick(int buttonClicked) {
  if (buttonClicked == Dialog.BUTTON_POSITIVE) {
    onPositiveAction();
  } else if (buttonClicked == Dialog.BUTTON_NEGATIVE) {
    dismissDialog();
  }
}
 
Example 6
Source File: LabelDialogManager.java    From talkback with Apache License 2.0 5 votes vote down vote up
@Override
public void handleDialogClick(int buttonClicked) {
  if (buttonClicked == Dialog.BUTTON_POSITIVE) {
    labelManager.removeLabel(existing);
  } else if (buttonClicked == Dialog.BUTTON_NEGATIVE) {
    dismissDialog();
  }
}
 
Example 7
Source File: AppSettingsDialogHolderActivity.java    From easypermissions with Apache License 2.0 5 votes vote down vote up
@Override
public void onClick(DialogInterface dialog, int which) {
    if (which == Dialog.BUTTON_POSITIVE) {
        Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS)
                .setData(Uri.fromParts("package", getPackageName(), null));
        intent.addFlags(mIntentFlags);
        startActivityForResult(intent, APP_SETTINGS_RC);
    } else if (which == Dialog.BUTTON_NEGATIVE) {
        setResult(Activity.RESULT_CANCELED);
        finish();
    } else {
        throw new IllegalStateException("Unknown button type: " + which);
    }
}
 
Example 8
Source File: VerifyHostnameActivity.java    From tapchat-android with Apache License 2.0 5 votes vote down vote up
private void onDialogResult(int result) {
    int decisionId = getIntent().getIntExtra(MemorizingHostnameVerifier.EXTRA_DECISION_ID, -1);
    boolean allow = result == Dialog.BUTTON_POSITIVE;
    mBus.post(new HostnameVerifyDecisionEvent(decisionId, allow));

    finish();
}
 
Example 9
Source File: WvWebView.java    From YCWebView with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onJsPrompt(WebView view, String url, final String message,
                          String defaultValue, final JsPromptResult result) {
    if(Build.VERSION.SDK_INT<= Build.VERSION_CODES.JELLY_BEAN){
        String prefix="_wvjbxx";
        if(message.equals(prefix)){
            Message msg = mainThreadHandler.obtainMessage(HANDLE_MESSAGE, defaultValue);
            mainThreadHandler.sendMessage(msg);
        }
        return true;
    }
    if(!alertBoxBlock){
        result.confirm();
    }
    final EditText editText = new EditText(getContext());
    editText.setText(defaultValue);
    if (defaultValue != null) {
        editText.setSelection(defaultValue.length());
    }
    float dpi = getContext().getResources().getDisplayMetrics().density;
    DialogInterface.OnClickListener listener = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if(alertBoxBlock) {
                if (which == Dialog.BUTTON_POSITIVE) {
                    result.confirm(editText.getText().toString());
                } else {
                    result.cancel();
                }
            }
        }
    };
    new AlertDialog.Builder(getContext())
            .setTitle(message)
            .setView(editText)
            .setCancelable(false)
            .setPositiveButton(android.R.string.ok, listener)
            .setNegativeButton(android.R.string.cancel, listener)
            .show();
    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    int t = (int) (dpi * 16);
    layoutParams.setMargins(t, 0, t, 0);
    layoutParams.gravity = Gravity.CENTER_HORIZONTAL;
    editText.setLayoutParams(layoutParams);
    int padding = (int) (15 * dpi);
    editText.setPadding(padding - (int) (5 * dpi), padding, padding, padding);
    return true;
}