Search in sources :

Example 86 with OnClickListener

use of android.content.DialogInterface.OnClickListener in project Pix-Art-Messenger by kriztan.

the class StartConversationActivity method askForContactsPermissions.

private void askForContactsPermissions() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (checkSelfPermission(Manifest.permission.READ_CONTACTS) != PackageManager.PERMISSION_GRANTED) {
            if (mRequestedContactsPermission.compareAndSet(false, true)) {
                if (shouldShowRequestPermissionRationale(Manifest.permission.READ_CONTACTS)) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(this);
                    builder.setTitle(R.string.sync_with_contacts);
                    builder.setMessage(R.string.sync_with_contacts_long);
                    builder.setPositiveButton(R.string.next, new OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                                requestPermissions(new String[] { Manifest.permission.READ_CONTACTS }, REQUEST_SYNC_CONTACTS);
                            }
                        }
                    });
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
                        builder.setOnDismissListener(new DialogInterface.OnDismissListener() {

                            @Override
                            public void onDismiss(DialogInterface dialog) {
                                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
                                    requestPermissions(new String[] { Manifest.permission.READ_CONTACTS }, REQUEST_SYNC_CONTACTS);
                                }
                            }
                        });
                    }
                    builder.create().show();
                } else {
                    requestPermissions(new String[] { Manifest.permission.READ_CONTACTS }, 0);
                }
            }
        }
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnClickListener(android.content.DialogInterface.OnClickListener) SpannableString(android.text.SpannableString) SuppressLint(android.annotation.SuppressLint)

Example 87 with OnClickListener

use of android.content.DialogInterface.OnClickListener in project AnExplorer by 1hakr.

the class RenameFragment method onCreateDialog.

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Context context = getActivity();
    final DocumentsActivity activity = (DocumentsActivity) getActivity();
    final AlertDialog.Builder builder = new AlertDialog.Builder(context);
    final LayoutInflater dialogInflater = LayoutInflater.from(builder.getContext());
    final View view = dialogInflater.inflate(R.layout.dialog_create_dir, null, false);
    final EditText text1 = (EditText) view.findViewById(android.R.id.text1);
    Utils.tintWidget(text1);
    String nameOnly = editExtension ? doc.displayName : FileUtils.removeExtension(doc.mimeType, doc.displayName);
    text1.setText(nameOnly);
    text1.setSelection(text1.getText().length());
    builder.setTitle(R.string.menu_rename);
    builder.setView(view);
    builder.setPositiveButton(R.string.menu_rename, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            final String displayName = text1.getText().toString();
            final String fileName = editExtension ? displayName : FileUtils.addExtension(doc.mimeType, displayName);
            new RenameTask(activity, doc, fileName).executeOnExecutor(ProviderExecutor.forAuthority(doc.authority));
        }
    });
    builder.setNegativeButton(android.R.string.cancel, null);
    return builder.create();
}
Also used : Context(android.content.Context) AlertDialog(android.support.v7.app.AlertDialog) EditText(android.widget.EditText) DocumentsActivity(dev.dworks.apps.anexplorer.DocumentsActivity) DialogInterface(android.content.DialogInterface) View(android.view.View) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.content.DialogInterface.OnClickListener)

Example 88 with OnClickListener

use of android.content.DialogInterface.OnClickListener in project platform_packages_apps_Settings by BlissRoms.

the class ZenModeRuleSettingsBase method showDeleteRuleDialog.

private void showDeleteRuleDialog() {
    final AlertDialog dialog = new AlertDialog.Builder(mContext).setMessage(getString(R.string.zen_mode_delete_rule_confirmation, mRule.getName())).setNegativeButton(R.string.cancel, null).setPositiveButton(R.string.zen_mode_delete_rule_button, new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            mMetricsFeatureProvider.action(mContext, MetricsEvent.ACTION_ZEN_DELETE_RULE_OK);
            mDeleting = true;
            removeZenRule(mId);
        }
    }).show();
    final View messageView = dialog.findViewById(android.R.id.message);
    if (messageView != null) {
        messageView.setTextDirection(View.TEXT_DIRECTION_LOCALE);
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) OnClickListener(android.content.DialogInterface.OnClickListener) View(android.view.View)

Example 89 with OnClickListener

use of android.content.DialogInterface.OnClickListener in project platform_packages_apps_Settings by BlissRoms.

the class WifiP2pSettings method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    final Activity activity = getActivity();
    mWifiP2pManager = (WifiP2pManager) getSystemService(Context.WIFI_P2P_SERVICE);
    if (mWifiP2pManager != null) {
        mChannel = mWifiP2pManager.initialize(activity.getApplicationContext(), getActivity().getMainLooper(), null);
        if (mChannel == null) {
            // Failure to set up connection
            Log.e(TAG, "Failed to set up connection with wifi p2p service");
            mWifiP2pManager = null;
        }
    } else {
        Log.e(TAG, "mWifiP2pManager is null !");
    }
    if (savedInstanceState != null && savedInstanceState.containsKey(SAVE_DIALOG_PEER)) {
        WifiP2pDevice device = savedInstanceState.getParcelable(SAVE_DIALOG_PEER);
        mSelectedWifiPeer = new WifiP2pPeer(getPrefContext(), device);
    }
    if (savedInstanceState != null && savedInstanceState.containsKey(SAVE_DEVICE_NAME)) {
        mSavedDeviceName = savedInstanceState.getString(SAVE_DEVICE_NAME);
    }
    if (savedInstanceState != null && savedInstanceState.containsKey(SAVE_SELECTED_GROUP)) {
        mSelectedGroupName = savedInstanceState.getString(SAVE_SELECTED_GROUP);
    }
    mRenameListener = new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == DialogInterface.BUTTON_POSITIVE) {
                if (mWifiP2pManager != null) {
                    String name = mDeviceNameText.getText().toString();
                    if (name != null) {
                        for (int i = 0; i < name.length(); i++) {
                            char cur = name.charAt(i);
                            if (!Character.isDigit(cur) && !Character.isLetter(cur) && cur != '-' && cur != '_' && cur != ' ') {
                                Toast.makeText(getActivity(), R.string.wifi_p2p_failed_rename_message, Toast.LENGTH_LONG).show();
                                return;
                            }
                        }
                    }
                    mWifiP2pManager.setDeviceName(mChannel, mDeviceNameText.getText().toString(), new WifiP2pManager.ActionListener() {

                        public void onSuccess() {
                            if (DBG)
                                Log.d(TAG, " device rename success");
                        }

                        public void onFailure(int reason) {
                            Toast.makeText(getActivity(), R.string.wifi_p2p_failed_rename_message, Toast.LENGTH_LONG).show();
                        }
                    });
                }
            }
        }
    };
    // disconnect dialog listener
    mDisconnectListener = new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == DialogInterface.BUTTON_POSITIVE) {
                if (mWifiP2pManager != null) {
                    mWifiP2pManager.removeGroup(mChannel, new WifiP2pManager.ActionListener() {

                        public void onSuccess() {
                            if (DBG)
                                Log.d(TAG, " remove group success");
                        }

                        public void onFailure(int reason) {
                            if (DBG)
                                Log.d(TAG, " remove group fail " + reason);
                        }
                    });
                }
            }
        }
    };
    // cancel connect dialog listener
    mCancelConnectListener = new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == DialogInterface.BUTTON_POSITIVE) {
                if (mWifiP2pManager != null) {
                    mWifiP2pManager.cancelConnect(mChannel, new WifiP2pManager.ActionListener() {

                        public void onSuccess() {
                            if (DBG)
                                Log.d(TAG, " cancel connect success");
                        }

                        public void onFailure(int reason) {
                            if (DBG)
                                Log.d(TAG, " cancel connect fail " + reason);
                        }
                    });
                }
            }
        }
    };
    // delete persistent group dialog listener
    mDeleteGroupListener = new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == DialogInterface.BUTTON_POSITIVE) {
                if (mWifiP2pManager != null) {
                    if (mSelectedGroup != null) {
                        if (DBG)
                            Log.d(TAG, " deleting group " + mSelectedGroup.getGroupName());
                        mWifiP2pManager.deletePersistentGroup(mChannel, mSelectedGroup.getNetworkId(), new WifiP2pManager.ActionListener() {

                            public void onSuccess() {
                                if (DBG)
                                    Log.d(TAG, " delete group success");
                            }

                            public void onFailure(int reason) {
                                if (DBG)
                                    Log.d(TAG, " delete group fail " + reason);
                            }
                        });
                        mSelectedGroup = null;
                    } else {
                        if (DBG)
                            Log.w(TAG, " No selected group to delete!");
                    }
                }
            } else if (which == DialogInterface.BUTTON_NEGATIVE) {
                if (DBG) {
                    Log.d(TAG, " forgetting selected group " + mSelectedGroup.getGroupName());
                }
                mSelectedGroup = null;
            }
        }
    };
    super.onActivityCreated(savedInstanceState);
}
Also used : WifiP2pDevice(android.net.wifi.p2p.WifiP2pDevice) DialogInterface(android.content.DialogInterface) Activity(android.app.Activity) OnClickListener(android.content.DialogInterface.OnClickListener)

Example 90 with OnClickListener

use of android.content.DialogInterface.OnClickListener in project android-aosp-mms by slvn.

the class MessageUtils method handleReadReport.

public static void handleReadReport(final Context context, final Collection<Long> threadIds, final int status, final Runnable callback) {
    StringBuilder selectionBuilder = new StringBuilder(Mms.MESSAGE_TYPE + " = " + PduHeaders.MESSAGE_TYPE_RETRIEVE_CONF + " AND " + Mms.READ + " = 0" + " AND " + Mms.READ_REPORT + " = " + PduHeaders.VALUE_YES);
    String[] selectionArgs = null;
    if (threadIds != null) {
        String threadIdSelection = null;
        StringBuilder buf = new StringBuilder();
        selectionArgs = new String[threadIds.size()];
        int i = 0;
        for (long threadId : threadIds) {
            if (i > 0) {
                buf.append(" OR ");
            }
            buf.append(Mms.THREAD_ID).append("=?");
            selectionArgs[i++] = Long.toString(threadId);
        }
        threadIdSelection = buf.toString();
        selectionBuilder.append(" AND (" + threadIdSelection + ")");
    }
    final Cursor c = SqliteWrapper.query(context, context.getContentResolver(), Mms.Inbox.CONTENT_URI, new String[] { Mms._ID, Mms.MESSAGE_ID }, selectionBuilder.toString(), selectionArgs, null);
    if (c == null) {
        return;
    }
    final Map<String, String> map = new HashMap<String, String>();
    try {
        if (c.getCount() == 0) {
            if (callback != null) {
                callback.run();
            }
            return;
        }
        while (c.moveToNext()) {
            Uri uri = ContentUris.withAppendedId(Mms.CONTENT_URI, c.getLong(0));
            map.put(c.getString(1), AddressUtils.getFrom(context, uri));
        }
    } finally {
        c.close();
    }
    OnClickListener positiveListener = new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            for (final Map.Entry<String, String> entry : map.entrySet()) {
                MmsMessageSender.sendReadRec(context, entry.getValue(), entry.getKey(), status);
            }
            if (callback != null) {
                callback.run();
            }
            dialog.dismiss();
        }
    };
    OnClickListener negativeListener = new OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (callback != null) {
                callback.run();
            }
            dialog.dismiss();
        }
    };
    OnCancelListener cancelListener = new OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            if (callback != null) {
                callback.run();
            }
            dialog.dismiss();
        }
    };
    confirmReadReportDialog(context, positiveListener, negativeListener, cancelListener);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) DialogInterface(android.content.DialogInterface) Cursor(android.database.Cursor) Uri(android.net.Uri) OnClickListener(android.content.DialogInterface.OnClickListener) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) OnCancelListener(android.content.DialogInterface.OnCancelListener)

Aggregations

OnClickListener (android.content.DialogInterface.OnClickListener)264 DialogInterface (android.content.DialogInterface)259 AlertDialog (android.app.AlertDialog)161 View (android.view.View)75 TextView (android.widget.TextView)52 Intent (android.content.Intent)44 SuppressLint (android.annotation.SuppressLint)41 Context (android.content.Context)35 AlertDialog (android.support.v7.app.AlertDialog)32 LayoutInflater (android.view.LayoutInflater)30 EditText (android.widget.EditText)30 Activity (android.app.Activity)27 Bundle (android.os.Bundle)25 OnCancelListener (android.content.DialogInterface.OnCancelListener)21 ImageView (android.widget.ImageView)17 Builder (android.app.AlertDialog.Builder)16 Dialog (android.app.Dialog)16 ProgressDialog (android.app.ProgressDialog)15 Paint (android.graphics.Paint)15 AdapterView (android.widget.AdapterView)15