Search in sources :

Example 1 with OnDismissListener

use of android.content.DialogInterface.OnDismissListener in project android-app by spark.

the class TinkerFragment method showTinkerSelect.

private void showTinkerSelect(Pin pin) {
    // No current action on the pin
    mutePinsExcept(pin);
    toggleViewVisibilityWithFade(R.id.tinker_logo, false);
    final View selectDialogView = getActivity().getLayoutInflater().inflate(R.layout.tinker_select, null);
    selectDialog = new AlertDialog.Builder(getActivity(), R.style.AppTheme_DialogNoDimBackground).setView(selectDialogView).setCancelable(true).setOnCancelListener(new OnCancelListener() {

        @Override
        public void onCancel(DialogInterface dialog) {
            dialog.dismiss();
        }
    }).create();
    selectDialog.setCanceledOnTouchOutside(true);
    selectDialog.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            unmutePins();
            toggleViewVisibilityWithFade(R.id.tinker_logo, true);
            selectDialog = null;
        }
    });
    final View analogRead = Ui.findView(selectDialogView, R.id.tinker_button_analog_read);
    final View analogWrite = Ui.findView(selectDialogView, R.id.tinker_button_analog_write);
    final View digitalRead = Ui.findView(selectDialogView, R.id.tinker_button_digital_read);
    final View digitalWrite = Ui.findView(selectDialogView, R.id.tinker_button_digital_write);
    final List<View> allButtons = list(analogRead, analogWrite, digitalRead, digitalWrite);
    analogRead.setOnTouchListener(new OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                setTinkerSelectButtonSelected(analogRead, allButtons);
            }
            return false;
        }
    });
    analogWrite.setOnTouchListener(new OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                setTinkerSelectButtonSelected(analogWrite, allButtons);
            }
            return false;
        }
    });
    digitalRead.setOnTouchListener(new OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                setTinkerSelectButtonSelected(digitalRead, allButtons);
            }
            return false;
        }
    });
    digitalWrite.setOnTouchListener(new OnTouchListener() {

        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                setTinkerSelectButtonSelected(digitalWrite, allButtons);
            }
            return false;
        }
    });
    digitalWrite.setOnClickListener(this);
    digitalRead.setOnClickListener(this);
    analogRead.setOnClickListener(this);
    analogWrite.setOnClickListener(this);
    if (!digitalWritePins.contains(pin)) {
        digitalWrite.setVisibility(View.INVISIBLE);
    } else {
        digitalWrite.setVisibility(View.VISIBLE);
    }
    if (!digitalReadPins.contains(pin)) {
        digitalRead.setVisibility(View.INVISIBLE);
    } else {
        digitalRead.setVisibility(View.VISIBLE);
    }
    if (!analogReadPins.contains(pin)) {
        analogRead.setVisibility(View.INVISIBLE);
    } else {
        analogRead.setVisibility(View.VISIBLE);
    }
    if (!analogWritePins.contains(pin)) {
        analogWrite.setVisibility(View.INVISIBLE);
    } else {
        analogWrite.setVisibility(View.VISIBLE);
    }
    ((TextView) selectDialogView.findViewById(R.id.tinker_select_pin)).setText(pin.name);
    PinAction action = pin.getConfiguredAction();
    switch(action) {
        case ANALOG_READ:
            setTinkerSelectButtonSelected(analogRead, allButtons);
            break;
        case ANALOG_WRITE:
            setTinkerSelectButtonSelected(analogWrite, allButtons);
            break;
        case DIGITAL_READ:
            setTinkerSelectButtonSelected(digitalRead, allButtons);
            break;
        case DIGITAL_WRITE:
            setTinkerSelectButtonSelected(digitalWrite, allButtons);
            break;
        case NONE:
            setTinkerSelectButtonSelected(null, allButtons);
            break;
    }
    selectDialog.show();
    View decorView = selectDialog.getWindow().getDecorView();
    noIReallyMeanItIWantThisToBeTransparent(decorView);
}
Also used : AlertDialog(android.app.AlertDialog) OnTouchListener(android.view.View.OnTouchListener) DialogInterface(android.content.DialogInterface) OnDismissListener(android.content.DialogInterface.OnDismissListener) TextView(android.widget.TextView) View(android.view.View) TextView(android.widget.TextView) OnCancelListener(android.content.DialogInterface.OnCancelListener) MotionEvent(android.view.MotionEvent)

Example 2 with OnDismissListener

use of android.content.DialogInterface.OnDismissListener in project LiveSDK-for-Android by liveservices.

the class MainActivity method onCreateDialog.

@Override
protected Dialog onCreateDialog(final int id) {
    Dialog dialog = null;
    switch(id) {
        case DIALOG_LOGOUT_ID:
            {
                AlertDialog.Builder builder = new AlertDialog.Builder(this);
                builder.setTitle("Logout").setMessage("The Live Connect Session will be cleared.").setPositiveButton("OK", new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        mAuthClient.logout(new LiveAuthListener() {

                            @Override
                            public void onAuthError(LiveAuthException exception, Object userState) {
                                showToast(exception.getMessage());
                            }

                            @Override
                            public void onAuthComplete(LiveStatus status, LiveConnectSession session, Object userState) {
                                LiveSdkSampleApplication app = (LiveSdkSampleApplication) getApplication();
                                app.setSession(null);
                                app.setConnectClient(null);
                                finish();
                            }
                        });
                    }
                }).setNegativeButton("Cancel", new OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
                dialog = builder.create();
                break;
            }
    }
    if (dialog != null) {
        dialog.setOnDismissListener(new OnDismissListener() {

            @Override
            public void onDismiss(DialogInterface dialog) {
                removeDialog(id);
            }
        });
    }
    return dialog;
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) LiveConnectSession(com.microsoft.live.LiveConnectSession) OnDismissListener(android.content.DialogInterface.OnDismissListener) LiveAuthException(com.microsoft.live.LiveAuthException) LiveAuthListener(com.microsoft.live.LiveAuthListener) LiveStatus(com.microsoft.live.LiveStatus) Dialog(android.app.Dialog) AlertDialog(android.app.AlertDialog) OnClickListener(android.content.DialogInterface.OnClickListener)

Example 3 with OnDismissListener

use of android.content.DialogInterface.OnDismissListener in project android_frameworks_base by DirtyUnicorns.

the class PowerNotificationWarnings method showStartSaverConfirmation.

private void showStartSaverConfirmation() {
    if (mSaverConfirmation != null)
        return;
    final SystemUIDialog d = new SystemUIDialog(mContext);
    d.setTitle(R.string.battery_saver_confirmation_title);
    d.setMessage(com.android.internal.R.string.battery_saver_description);
    d.setNegativeButton(android.R.string.cancel, null);
    d.setPositiveButton(R.string.battery_saver_confirmation_ok, mStartSaverMode);
    d.setShowForAllUsers(true);
    d.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            mSaverConfirmation = null;
        }
    });
    d.show();
    mSaverConfirmation = d;
}
Also used : SystemUIDialog(com.android.systemui.statusbar.phone.SystemUIDialog) DialogInterface(android.content.DialogInterface) OnDismissListener(android.content.DialogInterface.OnDismissListener)

Example 4 with OnDismissListener

use of android.content.DialogInterface.OnDismissListener in project android_frameworks_base by AOSPA.

the class PowerNotificationWarnings method showStartSaverConfirmation.

private void showStartSaverConfirmation() {
    if (mSaverConfirmation != null)
        return;
    final SystemUIDialog d = new SystemUIDialog(mContext);
    d.setTitle(R.string.battery_saver_confirmation_title);
    d.setMessage(com.android.internal.R.string.battery_saver_description);
    d.setNegativeButton(android.R.string.cancel, null);
    d.setPositiveButton(R.string.battery_saver_confirmation_ok, mStartSaverMode);
    d.setShowForAllUsers(true);
    d.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            mSaverConfirmation = null;
        }
    });
    d.show();
    mSaverConfirmation = d;
}
Also used : SystemUIDialog(com.android.systemui.statusbar.phone.SystemUIDialog) DialogInterface(android.content.DialogInterface) OnDismissListener(android.content.DialogInterface.OnDismissListener)

Example 5 with OnDismissListener

use of android.content.DialogInterface.OnDismissListener in project AndroidChromium by JackyAndroid.

the class ShareHelper method showShareDialog.

/**
     * Creates and shows a share intent picker dialog.
     *
     * @param saveLastUsed Whether to save the chosen activity for future direct sharing.
     * @param activity Activity that is used to access package manager.
     * @param title Title of the page to be shared.
     * @param text Text to be shared. If both |text| and |url| are supplied, they are concatenated
     *             with a space.
     * @param url URL of the page to be shared.
     * @oaram offlineUri URI of the offline page to be shared.
     * @param screenshotUri Uri of the screenshot of the page to be shared.
     * @param callback Optional callback to be called when user makes a choice. Will not be called
     *                 if receiving a response when the user makes a choice is not supported (on
     *                 older Android versions).
     */
private static void showShareDialog(final boolean saveLastUsed, final Activity activity, final String title, final String text, final String url, final Uri offlineUri, final Uri screenshotUri, @Nullable final TargetChosenCallback callback) {
    Intent intent = getShareIntent(activity, title, text, url, null, null);
    PackageManager manager = activity.getPackageManager();
    List<ResolveInfo> resolveInfoList = manager.queryIntentActivities(intent, 0);
    assert resolveInfoList.size() > 0;
    if (resolveInfoList.size() == 0)
        return;
    Collections.sort(resolveInfoList, new ResolveInfo.DisplayNameComparator(manager));
    final ShareDialogAdapter adapter = new ShareDialogAdapter(activity, manager, resolveInfoList);
    AlertDialog.Builder builder = new AlertDialog.Builder(activity, R.style.AlertDialogTheme);
    builder.setTitle(activity.getString(R.string.share_link_chooser_title));
    builder.setAdapter(adapter, null);
    // Need a mutable object to record whether the callback has been fired.
    final boolean[] callbackCalled = new boolean[1];
    final AlertDialog dialog = builder.create();
    dialog.show();
    dialog.getListView().setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            ResolveInfo info = adapter.getItem(position);
            ActivityInfo ai = info.activityInfo;
            ComponentName component = new ComponentName(ai.applicationInfo.packageName, ai.name);
            if (callback != null && !callbackCalled[0]) {
                callback.onTargetChosen(component);
                callbackCalled[0] = true;
            }
            if (saveLastUsed)
                setLastShareComponentName(component);
            makeIntentAndShare(false, activity, title, text, url, offlineUri, screenshotUri, component, null);
            dialog.dismiss();
        }
    });
    if (callback != null) {
        dialog.setOnDismissListener(new OnDismissListener() {

            @Override
            public void onDismiss(DialogInterface dialog) {
                if (!callbackCalled[0]) {
                    callback.onCancel();
                    callbackCalled[0] = true;
                }
            }
        });
    }
    if (sFakeIntentReceiverForTesting != null) {
        sFakeIntentReceiverForTesting.onCustomChooserShown(dialog);
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ActivityInfo(android.content.pm.ActivityInfo) OnItemClickListener(android.widget.AdapterView.OnItemClickListener) DialogInterface(android.content.DialogInterface) OnDismissListener(android.content.DialogInterface.OnDismissListener) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) ComponentName(android.content.ComponentName)

Aggregations

DialogInterface (android.content.DialogInterface)12 OnDismissListener (android.content.DialogInterface.OnDismissListener)12 SystemUIDialog (com.android.systemui.statusbar.phone.SystemUIDialog)5 AlertDialog (android.app.AlertDialog)4 Dialog (android.app.Dialog)2 OnCancelListener (android.content.DialogInterface.OnCancelListener)2 View (android.view.View)2 PendingIntent (android.app.PendingIntent)1 ProgressDialog (android.app.ProgressDialog)1 ComponentName (android.content.ComponentName)1 OnClickListener (android.content.DialogInterface.OnClickListener)1 Intent (android.content.Intent)1 ActivityInfo (android.content.pm.ActivityInfo)1 PackageManager (android.content.pm.PackageManager)1 ResolveInfo (android.content.pm.ResolveInfo)1 AlertDialog (android.support.v7.app.AlertDialog)1 MotionEvent (android.view.MotionEvent)1 OnClickListener (android.view.View.OnClickListener)1 OnTouchListener (android.view.View.OnTouchListener)1 AdapterView (android.widget.AdapterView)1