Example usage for android.app AlertDialog.OnClickListener AlertDialog.OnClickListener

List of usage examples for android.app AlertDialog.OnClickListener AlertDialog.OnClickListener

Introduction

In this page you can find the example usage for android.app AlertDialog.OnClickListener AlertDialog.OnClickListener.

Prototype

AlertDialog.OnClickListener

Source Link

Usage

From source file:de.NeonSoft.neopowermenu.Preferences.PreferencesPartFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // TODO: Implement this method
    MainActivity.visibleFragment = "Main";

    mContext = getActivity();/*from www.  j  a va  2s .  c  om*/

    ActiveStyle = MainActivity.preferences.getString("DialogTheme", "Material");
    hideicon = MainActivity.preferences.getBoolean("HideLauncherIcon", false);
    DeepXposedLogging = MainActivity.preferences.getBoolean("DeepXposedLogging", false);

    InflatedView = inflater.inflate(R.layout.activity_preferences, container, false);

    TextView_ModuleStateTitle = (TextView) InflatedView
            .findViewById(R.id.activitypreferencesTextView_ModuleStateTitle);
    TextView_ModuleStateDesc = (TextView) InflatedView
            .findViewById(R.id.activitypreferencesTextView_ModuleStateDesc);

    LinearLayout_Style = (LinearLayout) InflatedView.findViewById(R.id.activitypreferencesLinearLayout_Style);
    TextView_StyleTitle = (TextView) InflatedView.findViewById(R.id.activitypreferencesTextView_StyleTitle);
    TextView_StyleDesc = (TextView) InflatedView.findViewById(R.id.activitypreferencesTextView_StyleDesc);
    TextView_StyleDesc.setText(getString(R.string.preferencesDesc_Style).replace("[STYLENAME]", ActiveStyle));

    LinearLayout_Theme = (LinearLayout) InflatedView.findViewById(R.id.activitypreferencesLinearLayout_Theme);

    LinearLayout_VisibilityOrder = (LinearLayout) InflatedView
            .findViewById(R.id.activitypreferencesLinearLayout_VisibilityOrder);

    LinearLayout_Advanced = (LinearLayout) InflatedView
            .findViewById(R.id.activitypreferencesLinearLayout_Advanced);

    LinearLayout_HideLauncherIcon = (LinearLayout) InflatedView
            .findViewById(R.id.activitypreferencesLinearLayout_HideLauncherIcon);
    Switch_HideLauncherIcon = (Switch) InflatedView
            .findViewById(R.id.activitypreferencesSwitch_HideLauncherIcon);
    Switch_HideLauncherIcon.setChecked(hideicon);
    Switch_HideLauncherIcon.setClickable(false);
    Switch_HideLauncherIcon.setFocusable(false);

    LinearLayout_DeepXposedLogging = (LinearLayout) InflatedView
            .findViewById(R.id.activitypreferencesLinearLayout_DeepXposedLogging);
    Switch_DeepXposedLogging = (Switch) InflatedView
            .findViewById(R.id.activitypreferencesSwitch_DeepXposedLogging);
    Switch_DeepXposedLogging.setChecked(DeepXposedLogging);
    Switch_DeepXposedLogging.setClickable(false);
    Switch_DeepXposedLogging.setFocusable(false);

    LinearLayout_Source = (LinearLayout) InflatedView.findViewById(R.id.activitypreferencesLinearLayout_Source);
    LinearLayout_OrigSource = (LinearLayout) InflatedView
            .findViewById(R.id.activitypreferencesLinearLayout_OrigSource);

    LinearLayout_Share = (LinearLayout) InflatedView.findViewById(R.id.activitypreferencesLinearLayout_Share);

    LinearLayout_Translator = (LinearLayout) InflatedView
            .findViewById(R.id.activitypreferencesLinearLayout_Translator);

    LinearLayout_About = (LinearLayout) InflatedView.findViewById(R.id.activitypreferencesLinearLayout_About);

    LinearLayout_Style.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View p1) {
            // TODO: Implement this method
            AlertDialog.Builder alertdb = new AlertDialog.Builder(getActivity());
            alertdb.setTitle(R.string.preferencesTitle_Style);
            String[] styleList = new String[1];
            styleList[0] = "Material";
            for (int i = 0; i < styleList.length; i++) {
                if (styleList[i].equalsIgnoreCase(ActiveStyle)) {
                    ActiveStyleId = i;
                    //presetsList[i] = "(Active) "+ presetsFiles[i].getName().split(".nps")[0];
                }
            }
            alertdb.setSingleChoiceItems(styleList, ActiveStyleId, null);
            alertdb.setNegativeButton(R.string.Dialog_Cancel, new AlertDialog.OnClickListener() {

                @Override
                public void onClick(DialogInterface p1, int p2) {
                    // TODO: Implement this method
                }
            });
            alertdb.setPositiveButton(R.string.Dialog_Ok, new AlertDialog.OnClickListener() {

                @Override
                public void onClick(DialogInterface p1, int p2) {
                    // TODO: Implement this method
                    try {
                        int selectedPosition = (ad).getListView().getCheckedItemPosition();
                        String selectedName = (ad).getListView().getItemAtPosition(selectedPosition).toString();
                        MainActivity.preferences.edit().putString("DialogTheme", selectedName).commit();
                        ActiveStyle = selectedName;
                        TextView_StyleDesc.setText(
                                getString(R.string.preferencesDesc_Style).replace("[STYLENAME]", ActiveStyle));
                    } catch (Throwable t) {
                    }
                }
            });
            ad = alertdb.create();
            ad.show();
        }
    });

    LinearLayout_Theme.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View p1) {
            MainActivity.fragmentManager.beginTransaction()
                    .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
                    .replace(R.id.pref_container, new PreferencesColorFragment()).commit();
        }
    });

    LinearLayout_VisibilityOrder.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View p1) {
            MainActivity.fragmentManager.beginTransaction()
                    .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
                    .replace(R.id.pref_container, new PreferencesVisibilityOrderFragment()).commit();
        }
    });

    LinearLayout_Advanced.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View p1) {
            MainActivity.fragmentManager.beginTransaction()
                    .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE)
                    .replace(R.id.pref_container, new PreferencesAdvancedFragment()).commit();
        }
    });

    LinearLayout_HideLauncherIcon.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View p1) {
            hideicon = !hideicon;
            String packageName = getActivity().getPackageName();
            ComponentName componentSettings = new ComponentName(packageName, packageName + ".SettingsActivity");
            if (hideicon) {
                getActivity().getPackageManager().setComponentEnabledSetting(componentSettings,
                        PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
            } else {
                getActivity().getPackageManager().setComponentEnabledSetting(componentSettings,
                        PackageManager.COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP);
            }
            Switch_HideLauncherIcon.setChecked(hideicon);
            MainActivity.preferences.edit().putBoolean("HideLauncherIcon", hideicon).commit();
        }
    });

    LinearLayout_DeepXposedLogging.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View p1) {
            DeepXposedLogging = !DeepXposedLogging;
            Switch_DeepXposedLogging.setChecked(DeepXposedLogging);
            MainActivity.preferences.edit().putBoolean("DeepXposedLogging", DeepXposedLogging).commit();
        }
    });

    LinearLayout_Source.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View p1) {
            // TODO: Implement this method
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(Urlgithub));
            startActivity(i);
        }
    });

    LinearLayout_OrigSource.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View p1) {
            // TODO: Implement this method
            Intent i = new Intent(Intent.ACTION_VIEW);
            i.setData(Uri.parse(Urloriggithub));
            startActivity(i);
        }
    });

    LinearLayout_Share.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View p1) {
            // TODO: Implement this method
            Intent i = new Intent(Intent.ACTION_SEND);
            i.setType("text/plain");
            i.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name));
            String sAux = getString(R.string.ShareMessage);
            sAux = sAux + "repo.xposed.info/module/de.NeonSoft.neopowermenu \n\n";
            i.putExtra(Intent.EXTRA_TEXT, sAux);
            startActivity(Intent.createChooser(i, getString(R.string.preferencesTitle_Share)));
        }
    });

    LinearLayout_About.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View p1) {
            // TODO: Implement this method
            adb = new AlertDialog.Builder(getActivity());
            adb.setTitle("About");

            adb.setMessage("NeoPowerMenu by Neon-Soft / DrAcHe981\n"
                    + "based on a Source from Naman Dwivedi (naman14)\n\n" + "< Used Librarys >\n"
                    + "> HoloColorPicker from Lars Werkman\n"
                    + "An Android Holo themed colorpicker designed by Marie Schweiz\n\n"
                    + "Licensed under the Apache License, Version 2.0\n\n" + "> DragSortListView from Bauerca\n"
                    + "DragSortListView (DSLV) is an extension of the Android ListView that enables drag-and-drop reordering of list items.\n\n"
                    + "Licensed under the Apache License, Version 2.0\n\n"
                    + "> libsuperuser from Chainfire / ChainsDD\n\n"
                    + "Licensed under the Apache License, Version 2.0\n\n" + "");

            adb.setPositiveButton(R.string.Dialog_Ok, null);

            ad = adb.create();
            ad.show();
        }
    });

    checkState();
    if (!MainActivity.RootAvailable) {
        pd = new ProgressDialog(getActivity());
        pd.setMessage(getString(R.string.Dialog_WaitForRoot));
        pd.setIndeterminate(true);
        pd.setCancelable(false);
        pd.setCanceledOnTouchOutside(false);
        pd.setButton(pd.BUTTON_NEGATIVE, getString(R.string.Dialog_Cancel),
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface p1, int p2) {
                        pd.dismiss();
                        getActivity().finish();
                    }
                });
        pd.setButton(pd.BUTTON_NEUTRAL, getString(R.string.Dialog_Ignore),
                new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface p1, int p2) {
                        pd.dismiss();
                    }
                });
        pd.show();
    } else if (MainActivity.RootAvailable) {
        rootAvailable();
    }

    getPermissions();
    return InflatedView;
}

From source file:org.mozilla.gecko.GeckoApp.java

public void handleMessage(String event, JSONObject message) {
    Log.i(LOGTAG, "Got message: " + event);
    try {//w  w w  .j  a va2s  .c  o  m
        if (event.equals("Menu:Add")) {
            ExtraMenuItem item = new ExtraMenuItem();
            item.label = message.getString("name");
            item.id = message.getInt("id");
            try { // icon is optional
                item.icon = message.getString("icon");
            } catch (Exception ex) {
            }
            sExtraMenuItems.add(item);
        } else if (event.equals("Menu:Remove")) {
            // remove it from the menu and from our vector
            Iterator<ExtraMenuItem> i = sExtraMenuItems.iterator();
            int id = message.getInt("id");
            while (i.hasNext()) {
                ExtraMenuItem item = i.next();
                if (item.id == id) {
                    sExtraMenuItems.remove(item);
                    if (sMenu == null)
                        return;
                    MenuItem menu = sMenu.findItem(id);
                    if (menu != null)
                        sMenu.removeItem(id);
                }
            }
        } else if (event.equals("Toast:Show")) {
            final String msg = message.getString("message");
            final String duration = message.getString("duration");
            handleShowToast(msg, duration);
        } else if (event.equals("DOMContentLoaded")) {
            final int tabId = message.getInt("tabID");
            final String uri = message.getString("uri");
            final String title = message.getString("title");
            handleContentLoaded(tabId, uri, title);
            Log.i(LOGTAG, "URI - " + uri + ", title - " + title);
        } else if (event.equals("DOMTitleChanged")) {
            final int tabId = message.getInt("tabID");
            final String title = message.getString("title");
            handleTitleChanged(tabId, title);
            Log.i(LOGTAG, "title - " + title);
        } else if (event.equals("DOMLinkAdded")) {
            final int tabId = message.getInt("tabID");
            final String rel = message.getString("rel");
            final String href = message.getString("href");
            Log.i(LOGTAG, "link rel - " + rel + ", href - " + href);
            handleLinkAdded(tabId, rel, href);
        } else if (event.equals("DOMWindowClose")) {
            final int tabId = message.getInt("tabID");
            handleWindowClose(tabId);
        } else if (event.equals("log")) {
            // generic log listener
            final String msg = message.getString("msg");
            Log.i(LOGTAG, "Log: " + msg);
        } else if (event.equals("Content:LocationChange")) {
            final int tabId = message.getInt("tabID");
            final String uri = message.getString("uri");
            final String documentURI = message.getString("documentURI");
            final String contentType = message.getString("contentType");
            Log.i(LOGTAG, "URI - " + uri);
            handleLocationChange(tabId, uri, documentURI, contentType);
        } else if (event.equals("Content:SecurityChange")) {
            final int tabId = message.getInt("tabID");
            final String mode = message.getString("mode");
            Log.i(LOGTAG, "Security Mode - " + mode);
            handleSecurityChange(tabId, mode);
        } else if (event.equals("Content:StateChange")) {
            final int tabId = message.getInt("tabID");
            int state = message.getInt("state");
            Log.i(LOGTAG, "State - " + state);
            if ((state & GeckoAppShell.WPL_STATE_IS_NETWORK) != 0) {
                if ((state & GeckoAppShell.WPL_STATE_START) != 0) {
                    Log.i(LOGTAG, "Got a document start");
                    final boolean showProgress = message.getBoolean("showProgress");
                    handleDocumentStart(tabId, showProgress);
                } else if ((state & GeckoAppShell.WPL_STATE_STOP) != 0) {
                    Log.i(LOGTAG, "Got a document stop");
                    handleDocumentStop(tabId);
                }
            }
        } else if (event.equals("Content:LoadError")) {
            final int tabId = message.getInt("tabID");
            final String uri = message.getString("uri");
            final String title = message.getString("title");
            handleLoadError(tabId, uri, title);
        } else if (event.equals("onCameraCapture")) {
            //GeckoApp.mAppContext.doCameraCapture(message.getString("path"));
            doCameraCapture();
        } else if (event.equals("Doorhanger:Add")) {
            handleDoorHanger(message);
        } else if (event.equals("Doorhanger:Remove")) {
            handleDoorHangerRemove(message);
        } else if (event.equals("Gecko:Ready")) {
            sIsGeckoReady = true;
            mMainHandler.post(new Runnable() {
                public void run() {
                    if (sMenu != null)
                        sMenu.findItem(R.id.settings).setEnabled(true);
                }
            });
            setLaunchState(LaunchState.GeckoRunning);
            GeckoAppShell.sendPendingEventsToGecko();
            connectGeckoLayerClient();
        } else if (event.equals("ToggleChrome:Hide")) {
            mMainHandler.post(new Runnable() {
                public void run() {
                    mBrowserToolbar.hide();
                }
            });
        } else if (event.equals("ToggleChrome:Show")) {
            mMainHandler.post(new Runnable() {
                public void run() {
                    mBrowserToolbar.show();
                }
            });
        } else if (event.equals("DOMFullScreen:Start")) {
            mDOMFullScreen = true;
        } else if (event.equals("DOMFullScreen:Stop")) {
            mDOMFullScreen = false;
        } else if (event.equals("FormAssist:AutoComplete")) {
            final JSONArray suggestions = message.getJSONArray("suggestions");
            if (suggestions.length() == 0) {
                mMainHandler.post(new Runnable() {
                    public void run() {
                        mAutoCompletePopup.hide();
                    }
                });
            } else {
                final JSONArray rect = message.getJSONArray("rect");
                final double zoom = message.getDouble("zoom");
                mMainHandler.post(new Runnable() {
                    public void run() {
                        // Don't show autocomplete popup when using fullscreen VKB
                        InputMethodManager imm = (InputMethodManager) getSystemService(
                                Context.INPUT_METHOD_SERVICE);
                        if (!imm.isFullscreenMode())
                            mAutoCompletePopup.show(suggestions, rect, zoom);
                    }
                });
            }
        } else if (event.equals("Permissions:Data")) {
            String host = message.getString("host");
            JSONArray permissions = message.getJSONArray("permissions");
            showSiteSettingsDialog(host, permissions);
        } else if (event.equals("Downloads:Done")) {
            String displayName = message.getString("displayName");
            String path = message.getString("path");
            String mimeType = message.getString("mimeType");
            int size = message.getInt("size");

            handleDownloadDone(displayName, path, mimeType, size);
        } else if (event.equals("CharEncoding:Data")) {
            final JSONArray charsets = message.getJSONArray("charsets");
            int selected = message.getInt("selected");

            final int len = charsets.length();
            final String[] titleArray = new String[len];
            for (int i = 0; i < len; i++) {
                JSONObject charset = charsets.getJSONObject(i);
                titleArray[i] = charset.getString("title");
            }

            final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
            dialogBuilder.setSingleChoiceItems(titleArray, selected, new AlertDialog.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    try {
                        JSONObject charset = charsets.getJSONObject(which);
                        GeckoAppShell.sendEventToGecko(
                                GeckoEvent.createBroadcastEvent("CharEncoding:Set", charset.getString("code")));
                        dialog.dismiss();
                    } catch (JSONException e) {
                        Log.e(LOGTAG, "error parsing json", e);
                    }
                }
            });
            dialogBuilder.setNegativeButton(R.string.button_cancel, new AlertDialog.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            mMainHandler.post(new Runnable() {
                public void run() {
                    dialogBuilder.show();
                }
            });
        } else if (event.equals("CharEncoding:State")) {
            final boolean visible = message.getString("visible").equals("true");
            GeckoPreferences.setCharEncodingState(visible);
            if (sMenu != null) {
                mMainHandler.post(new Runnable() {
                    public void run() {
                        sMenu.findItem(R.id.char_encoding).setVisible(visible);
                    }
                });
            }
        } else if (event.equals("Update:Restart")) {
            doRestart("org.mozilla.gecko.restart_update");
        } else if (event.equals("Tab:HasTouchListener")) {
            int tabId = message.getInt("tabID");
            Tab tab = Tabs.getInstance().getTab(tabId);
            tab.setHasTouchListeners(true);
            if (Tabs.getInstance().isSelectedTab(tab)) {
                mMainHandler.post(new Runnable() {
                    public void run() {
                        mLayerController.setWaitForTouchListeners(true);
                    }
                });
            }
        } else if (event.equals("Session:StatePurged")) {
            if (mAboutHomeContent != null) {
                mMainHandler.post(new Runnable() {
                    public void run() {
                        mAboutHomeContent.setLastTabsVisibility(false);
                    }
                });
            }
        } else if (event.equals("Bookmark:Insert")) {
            final String url = message.getString("url");
            final String title = message.getString("title");
            mMainHandler.post(new Runnable() {
                public void run() {
                    Toast.makeText(GeckoApp.mAppContext, R.string.bookmark_added, Toast.LENGTH_SHORT).show();
                    GeckoAppShell.getHandler().post(new Runnable() {
                        public void run() {
                            BrowserDB.addBookmark(GeckoApp.mAppContext.getContentResolver(), title, url);
                        }
                    });
                }
            });
        }
    } catch (Exception e) {
        Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e);
    }
}