Example usage for android.app AlertDialog.Builder setCancelable

List of usage examples for android.app AlertDialog.Builder setCancelable

Introduction

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

Prototype

public void setCancelable(boolean flag) 

Source Link

Document

Sets whether this dialog is cancelable with the KeyEvent#KEYCODE_BACK BACK key.

Usage

From source file:com.ezac.gliderlogs.FlightOverviewActivity.java

public void DoFlightMember() {
    // get member_list.xml view
    LayoutInflater li = LayoutInflater.from(context);
    membersView = li.inflate(R.layout.member_list, null);

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
    // set member_list.xml to alertdialog builder
    alertDialogBuilder.setView(membersView);
    //// w w w .  ja  v  a 2s.  co  m
    Button mMember_Btn;
    final EditText mDetailInfo;
    Button mGlider_Btn;
    // set dialog message
    alertDialogBuilder.setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            String fRegi = (String) mGliderSpin.getSelectedItem();
            String fPilo = (String) mMemberSpin.getSelectedItem();
            if (!fPilo.equals("") && !fRegi.equals("")) {
                String fRegiPilo = "";
                for (int i = 0; i < mGliderSpin.getCount(); i++) {
                    String s = (String) mGliderSpin.getItemAtPosition(i);
                    if (s.equalsIgnoreCase(fRegi)) {
                        fRegiPilo = GliderList.get(i);
                    }
                }
                for (int i = 0; i < mMemberSpin.getCount(); i++) {
                    String s = (String) mMemberSpin.getItemAtPosition(i);
                    if (s.equalsIgnoreCase(fPilo)) {
                        fRegiPilo = fRegiPilo + ":" + MemberIndexList.get(i);
                    }
                }
                DoFlightFilter(7, fRegiPilo);
                OptionSelect(R.id.action_my, R.id.action_all, R.id.action_open, R.id.action_ready,
                        R.id.action_45min);
            } else if (!fRegi.equals("")) {
                for (int i = 0; i < mGliderSpin.getCount(); i++) {
                    String s = (String) mGliderSpin.getItemAtPosition(i);
                    if (s.equalsIgnoreCase(fRegi)) {
                        // set filter criteria for selected member
                        DoFlightFilter(6, GliderList.get(i));
                        OptionSelect(R.id.action_my, R.id.action_all, R.id.action_open, R.id.action_ready,
                                R.id.action_45min);
                    }
                }
            } else if (!fPilo.equals("")) {
                for (int i = 0; i < mMemberSpin.getCount(); i++) {
                    String s = (String) mMemberSpin.getItemAtPosition(i);
                    if (s.equalsIgnoreCase(fPilo)) {
                        // set filter criteria for selected member
                        DoFlightFilter(5, MemberIndexList.get(i));
                        OptionSelect(R.id.action_my, R.id.action_all, R.id.action_open, R.id.action_ready,
                                R.id.action_45min);
                    }
                }
            }
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            DoFlightFilter(4, "");
            OptionSelect(R.id.action_all, R.id.action_my, R.id.action_open, R.id.action_ready,
                    R.id.action_45min);
            dialog.cancel();
        }
    });
    AlertDialog alertDialog = alertDialogBuilder.create();
    // get reference to and fill spinner with members
    mMemberSpin = (Spinner) membersView.findViewById(R.id.flight_member);
    ArrayAdapter<String> dataAdapter_1 = new ArrayAdapter<String>(FlightOverviewActivity.this,
            android.R.layout.simple_spinner_item, MemberList);
    dataAdapter_1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mMemberSpin.setAdapter(dataAdapter_1);
    // get reference to and fill spinner with gliders
    mGliderSpin = (Spinner) membersView.findViewById(R.id.flight_glider);
    ArrayAdapter<String> dataAdapter_2 = new ArrayAdapter<String>(FlightOverviewActivity.this,
            android.R.layout.simple_spinner_item, GliderList);
    dataAdapter_2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mGliderSpin.setAdapter(dataAdapter_2);
    mDetailInfo = (EditText) membersView.findViewById(R.id.editText1);
    // make field read only
    mDetailInfo.setClickable(false);
    mDetailInfo.setFocusable(false);
    mGlider_Btn = (Button) membersView.findViewById(R.id.flight_glider_detail);
    mGlider_Btn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            String fRegi = (String) mGliderSpin.getSelectedItem();
            if (fRegi.equals(null) || fRegi.equals("")) {
                mDetailInfo.setText("Geen Registratie selectie gevonden,\nmaak een keuze !");
            } else {
                String fRegiPilo = "";
                for (int i = 0; i < mGliderSpin.getCount(); i++) {
                    String s = (String) mGliderSpin.getItemAtPosition(i);
                    if (s.equalsIgnoreCase(fRegi)) {
                        fRegiPilo = GliderList.get(i);
                    }
                }
                mDetailInfo.setText(getDetailInfo(FlightsContentProvider.CONTENT_URI_GLIDER, fRegiPilo, 0));
            }
        }
    });
    mMember_Btn = (Button) membersView.findViewById(R.id.flight_member_detail);
    mMember_Btn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            String fPilo = (String) mMemberSpin.getSelectedItem();
            if (fPilo.equals(null) || fPilo.equals("")) {
                mDetailInfo.setText("Geen Naam selectie gevonden,\nmaak een keuze !");
            } else {
                String fRegiPilo = "";
                for (int i = 0; i < mMemberSpin.getCount(); i++) {
                    String s = (String) mMemberSpin.getItemAtPosition(i);
                    if (s.equalsIgnoreCase(fPilo)) {
                        fRegiPilo = MemberIndexList.get(i);
                    }
                }
                mDetailInfo.setText(getDetailInfo(FlightsContentProvider.CONTENT_URI_MEMBER, fRegiPilo, 1));
            }
        }
    });
    alertDialog.show();
}

From source file:com.android.mms.ui.MessageUtils.java

public static void confirmDeleteMessage(final Activity activity, final Uri msgUri) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setTitle(R.string.confirm_dialog_title);
    builder.setIconAttribute(android.R.attr.alertDialogIcon);
    builder.setCancelable(true);
    builder.setMessage(R.string.confirm_delete_message);
    builder.setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            /// M: fix bug ALPS00351620; for requery searchactivity.
            SearchActivity.setNeedRequery();
            SqliteWrapper.delete(activity.getApplicationContext(), activity.getContentResolver(), msgUri, null,
                    null);// ww  w . ja  va 2 s  . co m
            dialog.dismiss();
            activity.finish();
        }
    });
    builder.setNegativeButton(R.string.no, null);
    builder.show();
}

From source file:com.free.searcher.MainFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup viewContainer, Bundle savedInstanceState) {

    super.onCreateView(inflater, viewContainer, savedInstanceState);
    this.activity = getActivity();
    actionBar = activity.getActionBar();

    View v = inflater.inflate(R.layout.main, viewContainer, false);
    v.setOnSystemUiVisibilityChangeListener(this);

    webView = (WebView) v.findViewById(R.id.webView1);
    statusView = (TextView) v.findViewById(R.id.statusView);

    if (webViewBundle != null) {
        webView.restoreState(webViewBundle);
        Log.d("onCreateView.webView.restoreState", webViewBundle + "");
    } else if (currentUrl.length() > 0) {
        Log.d("onCreateView.locX, locY", locX + ", " + locY + ", " + currentUrl);
        webView.loadUrl(currentUrl);/*ww w.  jav  a 2  s  . c  o  m*/
        webView.setScrollX(locX);
        webView.setScrollY(locY);
        Log.d("currentUrl 8", currentUrl);
    }
    statusView.setText(status);

    Log.d("onCreateView.savedInstanceState", savedInstanceState + "vvv");
    mNotificationManager = (NotificationManager) activity.getSystemService(activity.NOTIFICATION_SERVICE);

    webView.setFocusable(true);
    webView.setFocusableInTouchMode(true);
    webView.requestFocus();
    webView.requestFocusFromTouch();
    webView.getSettings().setAllowContentAccess(false);
    webView.getSettings().setPluginState(WebSettings.PluginState.OFF);
    // webView.setBackgroundColor(LIGHT_BLUE);
    webView.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
    webView.setBackgroundColor(getResources().getColor(R.color.lightyellow));

    webView.setOnLongClickListener(this);
    statusView.setOnLongClickListener(this);

    webView.setWebViewClient(new WebViewClient() {

        private void jumpTo(final int xLocation, final int yLocation) {
            webView.postDelayed(new Runnable() {
                @Override
                public void run() {
                    Log.d("jumpTo1.locX, locY", xLocation + ", " + yLocation + ", " + currentUrl);
                    try {
                        webView.scrollTo(xLocation, yLocation);
                        webView.setScrollX(xLocation);
                        webView.setScrollY(yLocation);
                        //                           locX = 0;
                        //                           locY = 0;
                    } catch (RuntimeException e) {
                        Log.e("error jumpTo2.locX, locY", locX + ", " + locY + ", " + currentUrl);
                    }
                }
            }, 100);
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, final String url) {
            if (currentZipFileName.length() > 0 && (extractFile == null || extractFile.isClosed())) {
                try {
                    extractFile = new ExtractFile(currentZipFileName,
                            MainFragment.PRIVATE_PATH + currentZipFileName);
                } catch (RarException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            int ind = url.indexOf("?deleteFile=");
            if (ind >= 0) {
                if (dupTask == null) {
                    showToast("Please do duplicate finding again.");
                    return true;
                }

                String urlStatus = Util.getUrlStatus(url);
                final String selectedFile = urlStatus.substring(urlStatus.indexOf("?deleteFile=") + 12,
                        urlStatus.length());
                Log.d("deleteFile", "url=" + url + ", urlStatus=" + urlStatus);

                AlertDialog.Builder alert = new AlertDialog.Builder(activity);
                alert.setTitle("Delete File?");
                alert.setMessage("Do you really want to delete file \"" + selectedFile + "\"?");
                alert.setCancelable(true);
                alert.setNegativeButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        try {
                            locX = webView.getScrollX();
                            locY = webView.getScrollY();
                            webView.loadUrl(
                                    new File(dupTask.deleteFile(selectedFile)).toURI().toURL().toString());
                        } catch (IOException e) {
                            statusView.setText(e.getMessage());
                            Log.d("deleteFile", e.getMessage(), e);
                        }
                    }
                });
                alert.setPositiveButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
                AlertDialog alertDialog = alert.create();
                alertDialog.show();
                return true;
            }

            ind = url.indexOf("?deleteGroup=");
            if (ind >= 0) {
                if (dupTask == null) {
                    showToast("Please do duplicate finding again.");
                    return true;
                }

                String urlStatus = Util.getUrlStatus(url);
                final String groupFile = urlStatus.substring(urlStatus.indexOf("?deleteGroup=") + 13,
                        urlStatus.length());
                int indexOf = groupFile.indexOf(",");
                final int group = Integer.parseInt(groupFile.substring(0, indexOf));
                final String selectedFile = groupFile.substring(indexOf + 1);
                Log.d("groupFile", ",groupFile=" + groupFile + ", url=" + url + ", urlStatus=" + urlStatus);

                AlertDialog.Builder alert = new AlertDialog.Builder(activity);
                alert.setTitle("Delete Group of Files?");
                alert.setMessage(
                        "Do you really want to delete this group, except file \"" + selectedFile + "\"?");
                alert.setCancelable(true);
                alert.setNegativeButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        locX = webView.getScrollX();
                        locY = webView.getScrollY();
                        webView.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                try {
                                    webView.loadUrl(new File(dupTask.deleteGroup(group, selectedFile)).toURI()
                                            .toURL().toString());
                                } catch (Throwable e) {
                                    statusView.setText(e.getMessage());
                                    Log.e("Delete Group", e.getMessage(), e);
                                    Log.e("Delete Group", locX + ", " + locY + ", " + currentUrl);
                                }
                            }
                        }, 0);
                    }
                });
                alert.setPositiveButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
                AlertDialog alertDialog = alert.create();
                alertDialog.show();
                return true;
            }

            ind = url.indexOf("?deleteFolder=");
            if (ind >= 0) {
                if (dupTask == null) {
                    showToast("Please do duplicate finding again.");
                    return true;
                }

                String urlStatus = Util.getUrlStatus(url);
                final String selectedFile = urlStatus.substring(urlStatus.indexOf("?deleteFolder=") + 14,
                        urlStatus.length());
                Log.d("deleteFolder",
                        ",deleteFolder=" + selectedFile + ", url=" + url + ", urlStatus=" + urlStatus);
                AlertDialog.Builder alert = new AlertDialog.Builder(activity);
                alert.setTitle("Delete folder?");
                alert.setMessage("Do you really want to delete duplicate in folder \""
                        + selectedFile.substring(0, selectedFile.lastIndexOf("/")) + "\"?");
                alert.setCancelable(true);
                alert.setNegativeButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        locX = webView.getScrollX();
                        locY = webView.getScrollY();
                        webView.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                try {
                                    webView.loadUrl(new File(dupTask.deleteFolder(selectedFile)).toURI().toURL()
                                            .toString());
                                } catch (Throwable e) {
                                    statusView.setText(e.getMessage());
                                    Log.e("Delete folder", e.getMessage(), e);
                                    Log.e("Delete folder", locX + ", " + locY + ", " + currentUrl);
                                }
                            }
                        }, 0);
                    }
                });
                alert.setPositiveButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
                AlertDialog alertDialog = alert.create();
                alertDialog.show();
                return true;
            }

            ind = url.indexOf("?deleteSub=");
            if (ind >= 0) {
                if (dupTask == null) {
                    showToast("Please do duplicate finding again.");
                    return true;
                }

                String urlStatus = Util.getUrlStatus(url);

                final String selectedFile = urlStatus.substring(urlStatus.indexOf("?deleteSub=") + 11,
                        urlStatus.length());
                Log.d("deleteSub", ",deleteSub=" + selectedFile + ", url=" + url + ", urlStatus=" + urlStatus);
                AlertDialog.Builder alert = new AlertDialog.Builder(activity);
                alert.setTitle("Delete sub folder?");
                alert.setMessage("Do you really want to delete duplicate files in sub folder of \""
                        + selectedFile.substring(0, selectedFile.lastIndexOf("/")) + "\"?");
                alert.setCancelable(true);
                alert.setNegativeButton("Yes", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        locX = webView.getScrollX();
                        locY = webView.getScrollY();
                        webView.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                try {
                                    webView.loadUrl(new File(dupTask.deleteSubFolder(selectedFile)).toURI()
                                            .toURL().toString());
                                } catch (Throwable e) {
                                    statusView.setText(e.getMessage());
                                    Log.e("Delete sub folder", e.getMessage(), e);
                                    Log.e("Delete sub folder", locX + ", " + locY + ", " + currentUrl);
                                }
                            }
                        }, 0);
                    }
                });
                alert.setPositiveButton("No", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
                AlertDialog alertDialog = alert.create();
                alertDialog.show();
                return true;
            }

            ind = url.indexOf("?viewName");
            if (ind >= 0) {
                if (dupTask == null) {
                    showToast("Please do duplicate finding again.");
                    return true;
                }
                nameOrder = !nameOrder;
                locX = 0;
                locY = 0;
                Log.d("url=", url + ", viewName");
                try {
                    webView.loadUrl(new File(dupTask.genFile(dupTask.groupList, dupTask.NAME_VIEW)).toURI()
                            .toURL().toString());
                } catch (IOException e) {
                    Log.e("viewName", e.getMessage(), e);
                }
                return true;
            }

            ind = url.indexOf("?viewGroup");
            if (ind >= 0) {
                if (dupTask == null) {
                    showToast("Please do duplicate finding again.");
                    return true;
                }
                groupViewChanged = true;
                locX = 0;
                locY = 0;
                Log.d("url=", url + ", viewGroup");
                try {
                    webView.loadUrl(new File(dupTask.genFile(dupTask.groupList, dupTask.GROUP_VIEW)).toURI()
                            .toURL().toString());
                } catch (IOException e) {
                    Log.e("viewGroup", e.getMessage(), e);
                }
                return true;
            }
            if (zextr == null) {
                locX = 0;
                locY = 0;
            } else {
                zextr = null;
            }

            if (MainActivity.popup) {
                final MainFragment frag = ((MainActivity) activity).addFragmentToStack();
                frag.status = Util.getUrlStatus(url);
                frag.load = load;
                frag.currentSearching = currentSearching;
                frag.selectedFiles = selectedFiles;
                frag.files = files;
                frag.currentZipFileName = currentZipFileName;
                if (extractFile != null) {
                    try {
                        frag.extractFile = new ExtractFile();
                        extractFile.copyTo(frag.extractFile);
                    } catch (RarException e) {
                        e.printStackTrace();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }

                frag.home = home;
                //                  if (mSearchView != null && mSearchView.getQuery().length() > 0) {
                //                     frag.mSearchView.setQuery(mSearchView.getQuery(), false);
                //                  }
                view.getHandler().postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        frag.webTask = new WebTask(MainFragment.this);
                        frag.webTask.init(frag.webView, url);
                        frag.webTask.execute();
                        frag.statusView.setText(frag.status);
                    }
                }, 100);
            } else {
                currentUrl = url;
                Log.d("currentUrl 19", currentUrl);
                status = Util.getUrlStatus(url);
                statusView.setText("Opening " + url + "...");
                webTask = new WebTask(MainFragment.this, webView, url, status.toString());
                webTask.execute();
            }
            //               setNavVisibility(false);
            return true;
        }

        //         @Override
        //         public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
        //         }

        @Override
        public void onPageFinished(WebView view, String url) {
            if (container != null) {
                if (showFind) {
                    container.setVisibility(View.VISIBLE);
                    webView.findAllAsync(findBox.getText().toString());
                } else {
                    container.setVisibility(View.INVISIBLE);
                }
            }
            Log.d("onPageFinished", locX + ", " + locY + ", currentUrl=" + currentUrl + ", url=" + url);
            setNavVisibility(false);
            if (!backForward) { //if (zextr != null) {
                // zextr = null;
                jumpTo(locX, locY);
            } else {
                backForward = false;
            }
            //               locX = 0;
            //               locY = 0;
            Log.d("onPageFinished", url);
            /* This call inject JavaScript into the page which just finished loading. */
            //              webView.loadUrl("javascript:window.HTMLOUT.processHTML(" +
            //                    "'<head>'+document.getElementsByTagName('html')[0].innerHTML+'</head>');");
        }
    });

    WebSettings settings = webView.getSettings();
    //      webView.setWebViewClient(new WebViewClient());
    //      webView.setWebChromeClient(new WebChromeClient());
    //      webView.addJavascriptInterface(new HtmlSourceViewJavaScriptInterface(), "HTMLOUT");
    settings.setMinimumFontSize(13);
    settings.setJavaScriptEnabled(true);
    settings.setDefaultTextEncodingName("UTF-8");
    settings.setBuiltInZoomControls(true);
    // settings.setSansSerifFontFamily("Tahoma");
    settings.setEnableSmoothTransition(true);

    return v;
}

From source file:com.free.searcher.MainFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    Log.d("data", "" + data);
    Log.d("requestCode", "" + requestCode);
    Log.d("resultCode", "" + resultCode);
    locX = 0;/*from www  .jav a2s  .com*/
    locY = 0;
    try {
        if (data != null) {
            String[] stringExtra = data.getStringArrayExtra(FolderChooserActivity.SELECTED_DIR);
            if (requestCode == SEARCH_REQUEST_CODE) {
                if (resultCode == Activity.RESULT_OK) {
                    stopReadAndSearch();
                    Log.d("SEARCH_REQUEST_CODE.selectedFiles",
                            Util.arrayToString(stringExtra, true, MainFragment.LINE_SEP));
                    currentZipFileName = ""; // lm du  kh?i show web getSourceFile
                    selectedFiles = stringExtra;
                    getSourceFileTask = new GetSourceFileTask(MainFragment.this);
                    getSourceFileTask.execute();
                    load = "Search";
                } else { // RESULT_CANCEL
                    if (selectedFiles.length == 0) {
                        showToast("Nothing to search");
                        statusView.setText("Nothing to search");
                    }
                }
            } else if (requestCode == ZIP_REQUEST_CODE) {
                if (resultCode == Activity.RESULT_OK) {
                    stopReadAndSearch();
                    currentZipFileName = stringExtra[0];
                    selectedFiles = stringExtra;
                    load = "Zip Reader";
                    Log.d("ZIP_REQUEST_CODE.currentZFile", currentZipFileName);
                    statusView.setText("reading " + currentZipFileName + "...");
                    try {
                        zr = new ZipReadingTask(MainFragment.this);
                        zr.execute();
                    } catch (Exception e) {
                        statusView.setText(e.getMessage());
                        Log.d("zip result", e.getMessage(), e);
                        showToast(e.getMessage());
                    }
                } else if (currentZipFileName.length() == 0) {
                    showToast("Nothing to read");
                    statusView.setText("Nothing to read");
                }
                //            } else if (requestCode == COMPARE_REQUEST_CODE1) {
                //               if (resultCode == Activity.RESULT_OK) {
                //                  oriDoc = stringExtra[0];
                //                  Log.d("COMPARE_REQUEST_CODE1.oriDoc", oriDoc);
                //                  Intent intent = new Intent(activity, FolderChooserActivity.class);
                //                  intent.putExtra(MainFragment.SELECTED_DIR,
                //                              new String[] { oriDoc });
                //                  intent.putExtra(MainFragment.SUFFIX, DOC_FILES_SUFFIX);
                //                  intent.putExtra(MainFragment.MODE, !MULTI_FILES);
                //                  intent.putExtra(MainFragment.CHOOSER_TITLE,MODI_SUFFIX_TITLE);
                //                  activity.startActivityForResult(intent, COMPARE_REQUEST_CODE2);
                //               } else { // RESULT_CANCEL
                //                  if (selectedFiles.length == 0) {
                //                     showToast("Nothing to compare");
                //                     statusView.setText("Nothing to compare");
                //                  }
                //               }
                //            } else if (requestCode == COMPARE_REQUEST_CODE2) {
                //               if (resultCode == Activity.RESULT_OK) {
                //                  stopReadAndSearch();
                //                  modifiedDoc = stringExtra[0];
                //                  Log.d("COMPARE_REQUEST_CODE2.modifiedDoc", modifiedDoc);
                //                  currentZipFileName = ""; // lm du  kh?i show web getSourceFile
                //                  selectedFiles = new  String[] {oriDoc, modifiedDoc};
                //                  load = "Search";
                //                  requestCompare = true;
                //                  requestSearching = false;
                //                  getSourceFileTask = new GetSourceFileTask(MainFragment.this);
                //                  getSourceFileTask.execute();
                //               } else { // RESULT_CANCEL
                //                  if (selectedFiles.length == 0) {
                //                     showToast("Nothing to compare");
                //                     statusView.setText("Nothing to compare");
                //                  }
                //               }
            } else if (requestCode == GEN_REQUEST_CODE) {
                if (resultCode == Activity.RESULT_OK) {
                    Log.d("GEN_REQUEST_CODE.selectedFiles", stringExtra[0]);
                    genStardictTask = new GenStardictTask(MainFragment.this, stringExtra[0]);
                    genStardictTask.execute();
                } else { // RESULT_CANCEL
                    if (selectedFiles.length == 0) {
                        showToast("Nothing to generate");
                        statusView.setText("Nothing to generate");
                    }
                }
            } else if (requestCode == RESTORE_REQUEST_CODE) {
                if (resultCode == Activity.RESULT_OK) {
                    Log.d("RESTORE_REQUEST_CODE.selectedFiles", stringExtra[0]);
                    restoreStardictTask = new RestoreStardictTask(MainFragment.this, stringExtra[0]);
                    restoreStardictTask.execute();
                } else { // RESULT_CANCEL
                    if (selectedFiles.length == 0) {
                        showToast("Nothing to restore");
                        statusView.setText("Nothing to restore");
                    }
                }
            } else if (requestCode == DUP_REQUEST_CODE) {
                if (resultCode == Activity.RESULT_OK) {
                    stopReadAndSearch();
                    Log.d("DUP_REQUEST_CODE.selectedFiles",
                            Util.arrayToString(stringExtra, true, MainFragment.LINE_SEP));

                    if (FileUtils.treeUri == null) {// && !checkFolder(new File(st).getParentFile(), WRITE_REQUEST_CODE)) {
                        FileUtils.applicationContext = activity;
                        FileUtils.treeUri = FileUtils
                                .getSharedPreferenceUri(R.string.key_internal_uri_extsdcard);
                        if (FileUtils.treeUri == null) {
                            AlertDialog.Builder alert = new AlertDialog.Builder(activity);
                            alert.setTitle("Grant Permission in extSdCard");
                            alert.setMessage("In the following Android dialog, "
                                    + "please select the external SD card and confirm at the bottom.");
                            alert.setCancelable(true);
                            alert.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    triggerStorageAccessFramework(INTENT_WRITE_REQUEST_CODE);
                                }
                            });
                            alert.setNegativeButton("No", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    dialog.cancel();
                                }
                            });
                            AlertDialog alertDialog = alert.create();
                            alertDialog.show();
                        }
                    }
                    dupTask = new DupFinderTask(MainFragment.this, stringExtra);
                    dupTask.execute();
                } else { // RESULT_CANCEL
                    if (selectedFiles.length == 0) {
                        showToast("Nothing to find");
                        statusView.setText("Nothing to find");
                    }
                }
            } else if (requestCode == INTENT_WRITE_REQUEST_CODE) {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    onActivityResultLollipop(requestCode, resultCode, data);
                }
            } else if (requestCode == TRANSLATE_REQUEST_CODE) {
                if (resultCode == Activity.RESULT_OK) {
                    Log.d("TRANSLATE_REQUEST_CODE.selectedFiles", stringExtra[0]);
                    stopReadAndSearch();
                    currentZipFileName = ""; // lm du  kh?i show web getSourceFile
                    selectedFiles = stringExtra;
                    load = "Search";
                    requestCompare = false;
                    requestTranslate = true;
                    requestSearching = false;
                    getSourceFileTask = new GetSourceFileTask(MainFragment.this);
                    getSourceFileTask.execute();
                } else { // RESULT_CANCEL
                    if (selectedFiles.length == 0) {
                        showToast("Nothing to translate");
                        statusView.setText("Nothing to translate");
                    }
                }
                //            } else if (requestCode == REPLACE_REQUEST_CODE) {
                //               if (resultCode == Activity.RESULT_OK) {
                //                  Log.d("REPLACE_REQUEST_CODE.selectedFiles", stringExtra[0]);
                //                  stopReadAndSearch();
                //                  currentZipFileName = ""; // lm du  kh?i show web getSourceFile
                //                  selectedFiles = stringExtra;
                //                  load = "Search";
                //                  requestCompare = false;
                //                  requestTranslate = false;
                //                  requestSearching = false;
                //                  List<File> lf = FileUtil.getFiles(selectedFiles);
                //                  if (includeEnter) { // multiline
                //                     new ReplaceAllTask(this, lf, isRegex, caseSensitive, new String[]{replace}, new String[]{by}).execute();
                //                  } else {
                //                     String[] replaces = replace.split("\r?\n");
                //                     String[] bys = by.split("\r?\n");
                //                     Log.d("bys.length ", bys.length + ".");
                //                     if (replaces.length == bys.length) {
                //                        new ReplaceAllTask(this, lf, isRegex, caseSensitive, replaces, bys).execute();
                //                     } else {
                //                        showToast("The number of lines of replace and by are not equal");
                //                     }
                //                  }
                //                  getSourceFileTask = new GetSourceFileTask(MainFragment.this);
                //                  getSourceFileTask.execute();
                //               } else { // RESULT_CANCEL
                //                  if (selectedFiles.length == 0) {
                //                     showToast("Nothing to translate");
                //                     statusView.setText("Nothing to translate");
                //                  }
                //               }
                //            } else if (requestCode == BATCH_REQUEST_CODE_1) {
                //               if (resultCode == Activity.RESULT_OK) {
                //                  selectedFiles = stringExtra;
                //                  Log.d("BATCH_REQUEST_CODE_1.selectedFiles", Util.arrayToString(selectedFiles, true, "\n"));
                //                  Intent intent = new Intent(activity, FolderChooserActivity.class);
                //                  intent.putExtra(SearchFragment.SELECTED_DIR,
                //                              selectedFiles);
                //                  intent.putExtra(SearchFragment.SUFFIX, "");
                //                  intent.putExtra(SearchFragment.MODE, !MULTI_FILES);
                //                  intent.putExtra(SearchFragment.CHOOSER_TITLE, "Output Folder");
                //                  activity.startActivityForResult(intent, BATCH_REQUEST_CODE_2);
                //               } else { // RESULT_CANCEL
                //                  if (selectedFiles.length == 0) {
                //                     showToast("Nothing to convert");
                //                     statusView.setText("Nothing to convert");
                //                  }
                //               }
                //            } else if (requestCode == BATCH_REQUEST_CODE_2) {
                //               if (resultCode == Activity.RESULT_OK) {
                //                  stopReadAndSearch();
                //                  outputFolder = stringExtra[0];
                //                  Log.d("BATCH_REQUEST_CODE_2.outputfolder", outputFolder);
                //                  currentZipFileName = ""; // lm du  kh?i show web getSourceFile
                //                  load = "Convert";
                //                  
                //                  Log.i(Prefs.TAG, "onCreate ffmpeg4android ProgressBarExample");
                ////                  demoVideoFolder = Environment.getExternalStorageDirectory().getAbsolutePath() + "/videokit/";
                //                  Log.i(Prefs.TAG, getString(R.string.app_name) + " version: " + GeneralUtils.getVersionName(activity.getApplicationContext()) );
                //                  workFolder = SearchFragment.PRIVATE_PATH + "/"; //activity.getApplicationContext().getFilesDir() + "/";
                //                  Log.i(Prefs.TAG, "workFolder (license and logs location) path: " + workFolder);
                //                  vkLogPath = SearchFragment.PRIVATE_PATH + "/vk.log";
                //                  Log.i(Prefs.TAG, "vk log (native log) path: " + vkLogPath);
                //                  GeneralUtils.copyLicenseFromAssetsToSDIfNeeded(activity, workFolder);
                //                  //GeneralUtils.copyDemoVideoFromAssetsToSDIfNeeded(activity, demoVideoFolder);
                //                  int rc = GeneralUtils.isLicenseValid(activity.getApplicationContext(), workFolder);
                //                  Log.i(Prefs.TAG, "License check RC: " + rc);
                //                  new Thread (new Runnable() {
                //                        @Override
                //                        public void run() {
                //                           List<File> lf = FileUtil.getFiles(selectedFiles);
                //                           for (File f : lf) {
                //                              Log.i(Prefs.TAG, "f = " + f);
                //                              synchronized (command) {
                //                                 convertingFile = f.getAbsolutePath();
                //                                 Log.i(Prefs.TAG, convertingFile + "2=" + convertingFile);
                //                                 runTranscoding();
                //                                 while (!progresssBarFinished) {
                //                                    try {
                //                                       Thread.sleep(250);
                //                                    } catch (InterruptedException e) {}
                //                                 }
                //                              }
                //                           }
                //                        }
                //                  }).start();
                //               } else { // RESULT_CANCEL
                //                  if (selectedFiles.length == 0) {
                //                     showToast("Nothing to convert");
                //                     statusView.setText("Nothing to convert");
                //                  }
                //               }
            }
        }
    } catch (Throwable t) {
        Log.e("onActivityResult", t.getMessage(), t);
    }
    Log.d("onActivityResult.load", load + " onActivityResult");
    webView.requestFocus();
}

From source file:com.free.searcher.MainFragment.java

public boolean clearCache(MenuItem item) {

    AlertDialog.Builder alert = new AlertDialog.Builder(activity);
    alert.setTitle("Clear Caching Files");
    long[] entry = new long[] { 0, 0, 0 };
    FileUtil.getDirSize(MainFragment.PRIVATE_DIR, entry);
    alert.setMessage("Cache has " + MainFragment.nf.format(entry[2]) + " folders, "
            + MainFragment.nf.format(entry[0]) + " files, " + MainFragment.nf.format(entry[1]) + " bytes. "
            + "\r\nAre you sure you want to clear the cached files? "
            + "\r\nAfter cleaning searching will be slow for the first times "
            + "and the searching task maybe incorrect.");
    alert.setCancelable(true);

    alert.setNegativeButton("Yes", new DialogInterface.OnClickListener() {

        @Override/*  w w w.  j  a va  2  s . com*/
        public void onClick(DialogInterface dialog, int which) {
            Log.d("Cleaning files",
                    FileUtil.deleteFiles(MainFragment.PRIVATE_DIR, MainFragment.LINE_SEP, true, ""));
        }
    });

    alert.setPositiveButton("No", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    AlertDialog alertDialog = alert.create();
    alertDialog.show();
    return true;
}

From source file:biz.bokhorst.xprivacy.ActivityMain.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final int userId = Util.getUserId(Process.myUid());

    // Check privacy service client
    if (!PrivacyService.checkClient())
        return;//from ww w. j a va  2 s.com

    // Import license file
    if (Intent.ACTION_VIEW.equals(getIntent().getAction()))
        if (Util.importProLicense(new File(getIntent().getData().getPath())) != null)
            Toast.makeText(this, getString(R.string.menu_pro), Toast.LENGTH_LONG).show();

    // Set layout
    setContentView(R.layout.mainlist);
    setSupportActionBar((Toolbar) findViewById(R.id.widgetToolbar));
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    // Set sub title
    if (Util.hasProLicense(this) != null)
        getSupportActionBar().setSubtitle(R.string.menu_pro);

    // Annotate
    Meta.annotate(this.getResources());

    // Get localized restriction name
    List<String> listRestrictionName = new ArrayList<String>(
            PrivacyManager.getRestrictions(this).navigableKeySet());
    listRestrictionName.add(0, getString(R.string.menu_all));

    // Build spinner adapter
    SpinnerAdapter spAdapter = new SpinnerAdapter(this, android.R.layout.simple_spinner_item);
    spAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spAdapter.addAll(listRestrictionName);

    // Handle info
    ImageView imgInfo = (ImageView) findViewById(R.id.imgInfo);
    imgInfo.setOnClickListener(new View.OnClickListener() {
        @SuppressLint("SetJavaScriptEnabled")
        @Override
        public void onClick(View view) {
            int position = spRestriction.getSelectedItemPosition();
            if (position != AdapterView.INVALID_POSITION) {
                String query = (position == 0 ? "restrictions"
                        : (String) PrivacyManager.getRestrictions(ActivityMain.this).values().toArray()[position
                                - 1]);

                WebView webview = new WebView(ActivityMain.this);
                webview.getSettings().setUserAgentString("Mozilla/5.0");
                // needed for hashtag
                webview.getSettings().setJavaScriptEnabled(true);
                webview.loadUrl("https://github.com/M66B/XPrivacy#" + query);

                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityMain.this);
                alertDialogBuilder.setTitle((String) spRestriction.getSelectedItem());
                alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
                alertDialogBuilder.setView(webview);
                alertDialogBuilder.setCancelable(true);
                AlertDialog alertDialog = alertDialogBuilder.create();
                alertDialog.show();
            }
        }
    });

    // Setup category spinner
    spRestriction = (Spinner) findViewById(R.id.spRestriction);
    spRestriction.setAdapter(spAdapter);
    spRestriction.setOnItemSelectedListener(this);
    int pos = getSelectedCategory(userId);
    spRestriction.setSelection(pos);

    // Setup sort
    mSortMode = Integer.parseInt(PrivacyManager.getSetting(userId, PrivacyManager.cSettingSortMode, "0"));
    mSortInvert = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingSortInverted, false);

    // Start task to get app list
    AppListTask appListTask = new AppListTask();
    appListTask.executeOnExecutor(mExecutor, (Object) null);

    // Check environment
    Requirements.check(this);

    // Licensing
    checkLicense();

    // Listen for package add/remove
    IntentFilter iff = new IntentFilter();
    iff.addAction(Intent.ACTION_PACKAGE_ADDED);
    iff.addAction(Intent.ACTION_PACKAGE_REMOVED);
    iff.addDataScheme("package");
    registerReceiver(mPackageChangeReceiver, iff);
    mPackageChangeReceiverRegistered = true;

    boolean showChangelog = true;

    // First run
    if (PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFirstRun, true)) {
        showChangelog = false;
        optionAbout();
    }

    // Tutorial
    if (!PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingTutorialMain, false)) {
        showChangelog = false;
        ((ScrollView) findViewById(R.id.svTutorialHeader)).setVisibility(View.VISIBLE);
        ((ScrollView) findViewById(R.id.svTutorialDetails)).setVisibility(View.VISIBLE);
    }
    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ViewParent parent = view.getParent();
            while (!parent.getClass().equals(ScrollView.class))
                parent = parent.getParent();
            ((View) parent).setVisibility(View.GONE);
            PrivacyManager.setSetting(userId, PrivacyManager.cSettingTutorialMain, Boolean.TRUE.toString());
        }
    };
    ((Button) findViewById(R.id.btnTutorialHeader)).setOnClickListener(listener);
    ((Button) findViewById(R.id.btnTutorialDetails)).setOnClickListener(listener);

    // Legacy
    if (!PrivacyManager.cVersion3) {
        long now = new Date().getTime();
        String legacy = PrivacyManager.getSetting(userId, PrivacyManager.cSettingLegacy, null);
        if (legacy == null || now > Long.parseLong(legacy) + 7 * 24 * 60 * 60 * 1000L) {
            showChangelog = false;
            PrivacyManager.setSetting(userId, PrivacyManager.cSettingLegacy, Long.toString(now));

            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
            alertDialogBuilder.setTitle(R.string.app_name);
            alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
            alertDialogBuilder.setMessage(R.string.title_update_legacy);
            alertDialogBuilder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Util.viewUri(ActivityMain.this,
                            Uri.parse("https://github.com/M66B/XPrivacy/blob/master/CHANGELOG.md#xprivacy3"));
                }
            });
            alertDialogBuilder.setNegativeButton(android.R.string.cancel,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // Do nothing
                        }
                    });

            // Show dialog
            AlertDialog alertDialog = alertDialogBuilder.create();
            alertDialog.show();
        }
    }

    // Show changelog
    if (showChangelog) {
        String sVersion = PrivacyManager.getSetting(userId, PrivacyManager.cSettingChangelog, null);
        Version changelogVersion = new Version(sVersion == null ? "0.0" : sVersion);
        Version currentVersion = new Version(Util.getSelfVersionName(this));
        if (sVersion == null || changelogVersion.compareTo(currentVersion) < 0)
            optionChangelog();
    }
}

From source file:com.ezac.gliderlogs.FlightOverviewActivity.java

public void DoSettings() {
    // get settings.xml view
    LayoutInflater li = LayoutInflater.from(context);
    settingsView = li.inflate(R.layout.settings, null);
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
    // set settings.xml to alertdialog builder
    alertDialogBuilder.setView(settingsView);
    // get user input for service code
    final EditText userInput = (EditText) settingsView.findViewById(R.id.editTextDialogUserInput);
    // set dialog message
    alertDialogBuilder.setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override//from  w ww  . j  a v  a 2 s .  c om
        public void onClick(DialogInterface dialog, int id) {
            SharedPreferences prefs = context.getSharedPreferences("Share", Context.MODE_PRIVATE);
            prefs.edit().clear();
            SharedPreferences.Editor es = prefs.edit();
            String[] mTestArray;
            if (userInput.getText().toString().equals("NoAccess")) {
                // prefs URL
                EditText et1 = (EditText) settingsView.findViewById(R.id.setting_url);
                appURL = et1.getText().toString();
                es.putString("com.ezac.gliderlogs.url", appURL).apply();
            }
            // prefs PRE
            EditText et2 = (EditText) settingsView.findViewById(R.id.setting_pre);
            appPRE = et2.getText().toString().replace(" ", "");
            es.putString("com.ezac.gliderlogs.pre", appPRE).apply();
            if (userInput.getText().toString().equals("NoAccess")) {
                // prefs SCN
                EditText et3 = (EditText) settingsView.findViewById(R.id.setting_scn);
                appSCN = et3.getText().toString();
                es.putString("com.ezac.gliderlogs.scn", appSCN).apply();
                // prefs KEY
                EditText et4 = (EditText) settingsView.findViewById(R.id.setting_key);
                appKEY = et4.getText().toString();
                es.putString("com.ezac.gliderlogs.key", appKEY).apply();
                // prefs KEY
                EditText et5 = (EditText) settingsView.findViewById(R.id.setting_secret);
                appSCT = et5.getText().toString();
                es.putString("com.ezac.gliderlogs.sct", appSCT).apply();
                // prefs Meteo

                mTestArray = getResources().getStringArray(R.array.meteo_id_arrays);
                Spinner et6 = (Spinner) settingsView.findViewById(R.id.setting_station);
                String sel6 = (String) et6.getSelectedItem();
                //String sel6_id = "";
                for (int i = 0; i < et6.getCount(); i++) {
                    String s1 = (String) et6.getItemAtPosition(i);
                    if (s1.equalsIgnoreCase(sel6)) {
                        appMST = mTestArray[i];
                    }
                }
                es.putString("com.ezac.gliderlogs.mst", appMST).apply();
                // prefs Metar
                EditText et7 = (EditText) settingsView.findViewById(R.id.setting_metar);
                appMTR = et7.getText().toString();
                es.putString("com.ezac.gliderlogs.mst", appMST).apply();
            }
            // prefs Flags
            CheckBox et9a = (CheckBox) settingsView.findViewById(R.id.setting_menu01);
            CheckBox et9b = (CheckBox) settingsView.findViewById(R.id.setting_menu02);

            CheckBox et9c = (CheckBox) settingsView.findViewById(R.id.setting_menu11);
            CheckBox et9d = (CheckBox) settingsView.findViewById(R.id.setting_menu12);
            CheckBox et9e = (CheckBox) settingsView.findViewById(R.id.setting_menu13);
            CheckBox et9f = (CheckBox) settingsView.findViewById(R.id.setting_menu14);
            CheckBox et9g = (CheckBox) settingsView.findViewById(R.id.setting_menu21);
            CheckBox et9h = (CheckBox) settingsView.findViewById(R.id.setting_menu22);
            String et9aa, et9ab;
            String v[];
            if (userInput.getText().toString().equals("To3Myd4T")) {
                et9aa = et9a.isChecked() ? "true" : "false";
                et9ab = et9b.isChecked() ? "true" : "false";
            } else {
                v = appFLG.split(";");
                et9aa = v[0];
                et9ab = v[1];
            }
            String et9ac = et9c.isChecked() ? "true" : "false";
            String et9ad = et9d.isChecked() ? "true" : "false";
            String et9ae = et9e.isChecked() ? "true" : "false";
            String et9af = et9f.isChecked() ? "true" : "false";
            String et9ag = et9g.isChecked() ? "true" : "false";
            String et9ah = et9h.isChecked() ? "true" : "false";
            appFLG = et9aa + ";" + et9ab + ";" + et9ac + ";" + et9ad + ";" + et9ae + ";" + et9af + ";" + et9ag
                    + ";" + et9ah + ";false;false";
            v = appFLG.split(";");

            menu.findItem(R.id.action_ezac).setVisible(Boolean.parseBoolean(v[2]));
            menu.findItem(R.id.action_meteo_group).setVisible(Boolean.parseBoolean(v[3]));
            menu.findItem(R.id.action_ntm_nld).setVisible(Boolean.parseBoolean(v[4]));
            menu.findItem(R.id.action_ntm_blx).setVisible(Boolean.parseBoolean(v[4]));
            menu.findItem(R.id.action_ogn_flarm).setVisible(Boolean.parseBoolean(v[5]));
            menu.findItem(R.id.action_adsb).setVisible(Boolean.parseBoolean(v[6]));
            menu.findItem(R.id.action_adsb_lcl).setVisible(Boolean.parseBoolean(v[7]));
            es.putString("com.ezac.gliderlogs.flg", appFLG).apply();
            // adjust value in menu button to value in use
            MenuItem MenuItem_dur = menu.findItem(R.id.action_45min);
            MenuItem_dur.setTitle(" " + appPRE + " Min ");
            if (userInput.getText().toString().equals("To3Myd4T")) {
                // prefs airfield heading
                mTestArray = getResources().getStringArray(R.array.heading_arrays);
                Spinner et10 = (Spinner) settingsView.findViewById(R.id.setting_heading);
                String sel10 = (String) et10.getSelectedItem();
                //String sel10_id = "";
                for (int i = 0; i < et10.getCount(); i++) {
                    String s2 = (String) et10.getItemAtPosition(i);
                    if (s2.equalsIgnoreCase(sel10)) {
                        appLND = mTestArray[i];
                        es.putString("com.ezac.gliderlogs.lnd", appLND).apply();
                    }
                }
            }
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });
    // create alert dialog & and load it's data
    AlertDialog alertDialog = alertDialogBuilder.create();
    EditText et1 = (EditText) settingsView.findViewById(R.id.setting_url);
    EditText et2 = (EditText) settingsView.findViewById(R.id.setting_pre);
    EditText et3 = (EditText) settingsView.findViewById(R.id.setting_scn);
    EditText et4 = (EditText) settingsView.findViewById(R.id.setting_key);
    EditText et5 = (EditText) settingsView.findViewById(R.id.setting_secret);
    Spinner et6 = (Spinner) settingsView.findViewById(R.id.setting_station);
    EditText et7 = (EditText) settingsView.findViewById(R.id.setting_metar);
    //EditText et8 = (EditText) settingsView.findViewById(R.id.setting_ntp);
    CheckBox et9a = (CheckBox) settingsView.findViewById(R.id.setting_menu01);
    CheckBox et9b = (CheckBox) settingsView.findViewById(R.id.setting_menu02);
    CheckBox et9c = (CheckBox) settingsView.findViewById(R.id.setting_menu11);
    CheckBox et9d = (CheckBox) settingsView.findViewById(R.id.setting_menu12);
    CheckBox et9e = (CheckBox) settingsView.findViewById(R.id.setting_menu13);
    CheckBox et9f = (CheckBox) settingsView.findViewById(R.id.setting_menu14);
    CheckBox et9g = (CheckBox) settingsView.findViewById(R.id.setting_menu21);
    CheckBox et9h = (CheckBox) settingsView.findViewById(R.id.setting_menu22);
    Spinner et10 = (Spinner) settingsView.findViewById(R.id.setting_heading);
    et1.setText(appURL);
    et2.setText(appPRE);
    et3.setText(appSCN);
    et4.setText(appKEY);
    et5.setText(appSCT);
    // get settings value for meteo station and set spinner
    String[] mTestArray;
    mTestArray = getResources().getStringArray(R.array.meteo_id_arrays);
    for (int i = 0; i < mTestArray.length; i++) {
        String s = mTestArray[i];
        if (s.equals(appMST)) {
            et6.setSelection(i);
        }
    }
    et7.setText(appMTR);
    // get settings value for menu tabs and set checkboxes
    String v[] = appFLG.split(";");
    et9a.setChecked(Boolean.parseBoolean(v[0]));
    et9b.setChecked(Boolean.parseBoolean(v[1]));
    et9c.setChecked(Boolean.parseBoolean(v[2]));
    et9d.setChecked(Boolean.parseBoolean(v[3]));
    et9e.setChecked(Boolean.parseBoolean(v[4]));
    et9f.setChecked(Boolean.parseBoolean(v[5]));
    et9g.setChecked(Boolean.parseBoolean(v[6]));
    et9h.setChecked(Boolean.parseBoolean(v[7]));
    // re-use mTestArray
    mTestArray = getResources().getStringArray(R.array.heading_arrays);
    for (int i = 0; i < mTestArray.length; i++) {
        String s = mTestArray[i];
        if (s.equals(appLND)) {
            et10.setSelection(i);
        }
    }
    // show it
    alertDialog.show();
}

From source file:org.loon.framework.android.game.LGameAndroid2DActivity.java

/**
 * ??Android//from www .ja  v a 2  s.  com
 * 
 * @param exception
 */
private void androidException(Exception exception) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(this);
    try {
        throw exception;
    } catch (IOException e) {
        if (e.getMessage().startsWith("Network unreachable")) {
            builder.setTitle("No network");
            builder.setMessage(
                    "LGame-Android Remote needs local network access. Please make sure that your wireless network is activated. You can click on the Settings button below to directly access your network settings.");
            builder.setNeutralButton("Settings", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));
                }
            });
        } else {
            builder.setTitle("Unknown I/O Exception");
            builder.setMessage(e.getMessage().toString());
        }
    } catch (HttpException e) {
        if (e.getMessage().startsWith("401")) {
            builder.setTitle("HTTP 401: Unauthorized");
            builder.setMessage(
                    "The supplied username and/or password is incorrect. Please check your settings.");
            builder.setNeutralButton("Settings", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    startActivity(new Intent());
                }
            });
        }
    } catch (RuntimeException e) {
        builder.setTitle("RuntimeException");
        builder.setMessage(e.getStackTrace().toString());
    } catch (Exception e) {
        builder.setTitle("Exception");
        builder.setMessage(e.getMessage());
    } finally {
        exception.printStackTrace();
        builder.setCancelable(true);
        builder.setNegativeButton("Close", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.cancel();
            }
        });
        final AlertDialog alert = builder.create();
        try {
            alert.show();
        } catch (Throwable e) {
        } finally {
            LSystem.destroy();
        }
    }
}

From source file:net.granoeste.scaffold.app.ScaffoldAlertDialogFragment.java

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {
    int iconId = getArguments().getInt(ICON_ID, 0);
    String title = getArguments().getString(TITLE);
    String message = getArguments().getString(MESSAGE);
    boolean hasPositive = getArguments().getBoolean(HAS_POSITIVE, false);
    boolean hasNeutral = getArguments().getBoolean(HAS_NEUTRAL, false);
    boolean hasNegative = getArguments().getBoolean(HAS_NEGATIVE, false);
    String positiveText = getArguments().getString(POSITIVE_TEXT);
    String neutralText = getArguments().getString(NEUTRAL_TEXT);
    String negativeText = getArguments().getString(NEGATIVE_TEXT);
    boolean cancelable = getArguments().getBoolean(CANCELABLE, true);
    boolean canceledOnTouchOutside = getArguments().getBoolean(CANCELED_ON_TOUCH_OUTSIDE, false);

    final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    if (iconId > 0) {
        builder.setIcon(iconId);/*from  w ww  .  j  a v  a  2  s .c  o  m*/
    }
    if (StringUtils.isNoneEmpty(title)) {
        builder.setTitle(title);
    }
    if (StringUtils.isNoneEmpty(message)) {
        builder.setMessage(message);
    }
    if (hasPositive) {
        if (StringUtils.isEmpty(positiveText)) {
            positiveText = getResources().getString(R.string.yes);
        }
        builder.setPositiveButton(positiveText, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(final DialogInterface dialog, final int whichButton) {
                synchronized (mOnAlertDialogEventListeners) {
                    for (OnAlertDialogEventListener listener : mOnAlertDialogEventListeners) {
                        listener.onDialogClick(dialog, whichButton, getTag());
                    }
                }
            }
        });
    }
    if (hasNeutral) {
        if (StringUtils.isEmpty(neutralText)) {
            neutralText = getResources().getString(R.string.no);
        }
        builder.setNeutralButton(neutralText, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(final DialogInterface dialog, final int whichButton) {
                synchronized (mOnAlertDialogEventListeners) {
                    for (OnAlertDialogEventListener listener : mOnAlertDialogEventListeners) {
                        listener.onDialogClick(dialog, whichButton, getTag());
                    }
                }
            }
        });
    }
    if (hasNegative) {
        if (StringUtils.isEmpty(negativeText)) {
            negativeText = getResources().getString(hasNeutral ? R.string.cancel : R.string.no);
        }
        builder.setNegativeButton(negativeText, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(final DialogInterface dialog, final int whichButton) {
                synchronized (mOnAlertDialogEventListeners) {
                    for (OnAlertDialogEventListener listener : mOnAlertDialogEventListeners) {
                        listener.onDialogClick(dialog, whichButton, getTag());
                    }
                }
            }
        });
    }
    builder.setCancelable(cancelable);
    if (cancelable) {
        builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(final DialogInterface dialog) {
                synchronized (mOnAlertDialogEventListeners) {
                    for (OnAlertDialogEventListener listener : mOnAlertDialogEventListeners) {
                        listener.onDialogCancel(dialog, getTag());
                    }
                }
            }
        });
    }
    //        View customView = getCustomView();
    if (mCustomView != null) {
        builder.setView(mCustomView);
    }

    Dialog dialog = builder.create();
    dialog.setCanceledOnTouchOutside(canceledOnTouchOutside);

    return dialog;
}

From source file:com.smc.tw.waltz.MainActivity.java

private void showQuitDialog() {
    if (DEBUG)/*from  w  w  w  . j a v  a  2  s  . c  om*/
        Log.d(TAG, "showQuitDialog");

    AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.WaltzDialog);

    builder.setIcon(R.drawable.ic_launcher);
    builder.setTitle(R.string.app_name);
    builder.setMessage(R.string.sure_to_quit);
    builder.setCancelable(false);
    builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int id) {
            finish();
        }
    });

    builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialogInterface, int id) {
        }
    });

    builder.create().show();
}