Example usage for android.app AlertDialog.Builder setTitle

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

Introduction

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

Prototype

@Override
    public void setTitle(CharSequence title) 

Source Link

Usage

From source file:com.chaturs.notepad.NoteEditor.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {

    case SELECT_STUDY_GROUP:

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(" Select Study Group(s)");
        final CharSequence[] charArray = new CharSequence[studyGroupNames.size()];

        for (int i = 0; i < studyGroupNames.size(); i++) {
            charArray[i] = studyGroupNames.get(i).substring(0);
        }/*from   w ww  .  j  a  va 2 s.c o  m*/

        builder.setMultiChoiceItems(charArray, null, new DialogInterface.OnMultiChoiceClickListener() {
            public void onClick(DialogInterface dialog, int which, boolean isChecked) {
                if (isChecked) {
                    selectedStudyGroupList.add(studyGroupList.get(which));
                } else {
                    if (!selectedStudyGroupList.isEmpty()) {
                        selectedStudyGroupList.remove(studyGroupList.get(which));
                    }
                }
            }
        });

        builder.setPositiveButton("Send", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {

                if (selectedStudyGroupList.isEmpty()) {
                    Toast.makeText(getApplicationContext(), "No option selected to send", Toast.LENGTH_SHORT)
                            .show();
                    return;
                }

                if (title == null) {
                    title = "Sample Note";
                }

                DatabaseHandler databaseHandler = DatabaseHandler.getInstance();
                String text = mText.getText().toString();
                if (text == null || text.length() == 0) {
                    text = "empty Note";
                }

                StringBuffer Ids = new StringBuffer();
                for (int i = 0; i < selectedStudyGroupList.size(); i++) {
                    if (Ids.length() > 0) {
                        Ids.append("|");
                    }
                    long id = selectedStudyGroupList.get(i).getServerId();
                    Ids.append(id);
                }
                String user = preferences.getString(KEY_USERNAME, "android");
                note = new Note(Ids.toString(), title, text, user, "");
                selectedStudyGroupList.clear();

                dismissDialog(SELECT_STUDY_GROUP);
                showDialog(PROGRESS_DIALOG_KEY);

                new Thread(new Runnable() {
                    public void run() {
                        response = postData();
                        handler.sendEmptyMessage(0);
                    }
                }).start();
            }
        });

        builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {

            }
        });
        Dialog dialog = builder.create();
        return dialog;

    case PROGRESS_DIALOG_KEY:
        ProgressDialog progressDialog = new ProgressDialog(this);
        progressDialog.setMessage("sending....");
        progressDialog.setIndeterminate(true);
        return progressDialog;

    }
    return null;
}

From source file:notused.Login.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.login);//from  w  w w . jav  a  2s. c om

    txtEmail = (TextView) findViewById(R.id.email);
    txtPassword = (TextView) findViewById(R.id.password);
    btnLogin = (Button) findViewById(R.id.login);
    ckRememberMe = (CheckBox) findViewById(R.id.checkbox);
    txtForgotPassword = (TextView) findViewById(R.id.forgotPassword);
    txtSignUp = (TextView) findViewById(R.id.signUp);
    validator = new Validator();
    config = new Config(Login.this);
    dbAdapter = new UserDBAdapter(this);

    baseUrl = "http://lawpavilionstore.com/android/login";

    dbAdapter.open(DB_NAME);
    //TODO: remove drop table query
    dbAdapter.executeQuery("DROP TABLE IF EXISTS" + dbAdapter.TABLE_NAME + ";");
    //dbAdapter.createUserTable();

    Cursor cursor = dbAdapter.fetch("SELECT * from " + dbAdapter.TABLE_NAME);

    if (cursor != null) {
        //new user
        if (cursor.getCount() == 1) {

            String loggedOut = cursor.getString(cursor.getColumnIndex(dbAdapter.LOG_OUT));
            if (loggedOut.equalsIgnoreCase("0")) {
                //User not looged out..continue
                String token = cursor.getString(cursor.getColumnIndex(dbAdapter.TOKEN));
                Toast.makeText(Login.this, "Existing", Toast.LENGTH_SHORT).show();

                Login.this.finish();
                String set_up_status = cursor.getString(cursor.getColumnIndex(dbAdapter.SET_UP_STATUS));

                if (set_up_status.equalsIgnoreCase("pending")) {

                    Intent intent = new Intent(Login.this, Module.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(intent);
                } else {
                    Intent intent = new Intent(Login.this, Dashboard.class);
                    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(intent);
                }

            } else {
                //user has been forced to login..
                SIGN_IN_TYPE = LOGGED_OUT_USER_TYPE;
            }
        } else {
            //New user account..
            SIGN_IN_TYPE = NEW_USER_TYPE;
        }
    } else {
        Toast.makeText(Login.this, "DB error", Toast.LENGTH_SHORT).show();
        //Do something here
    }
    dbAdapter.close();
    btnLogin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            _email = txtEmail.getText().toString().trim();
            _password = txtPassword.getText().toString().trim();
            boolean isFieldSet = true;

            if (!validator.isValidEmail(_email)) {

                txtEmail.setError(Validator.emailErrorMessage);
                isFieldSet = false;
            }

            if (validator.isEmpty(_password)) {
                txtPassword.setError(Validator.defaultErrorMessage);
                isFieldSet = false;
            }

            Toast.makeText(Login.this, "Ready for Async Task", Toast.LENGTH_SHORT).show();

            if (isFieldSet) {
                if (config.isConnectingToInternet()) {

                    AsyncLogin asyncLogin = new AsyncLogin();
                    asyncLogin.execute();
                } else {
                    AlertDialog.Builder builder = new AlertDialog.Builder(Login.this);
                    builder.setTitle("Error");
                    builder.setMessage("Oops! Something went wrong!\n\nplease check your internet connection")
                            .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {

                                }
                            }).setPositiveButton("Retry", new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialog, int which) {
                                    AsyncLogin asyncLogin = new AsyncLogin();
                                    asyncLogin.execute();
                                }
                            });
                    AlertDialog dialog = builder.create();
                    dialog.show();
                }

            } else {
                return;
            }

        }
    });
    txtForgotPassword.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(Login.this, ForgotPassword.class);
            startActivity(intent);
        }
    });

    txtSignUp.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            Intent intent = new Intent(Login.this, SignUp.class);
            startActivity(intent);
        }
    });

}

From source file:com.nextgis.maplibui.dialog.CreateFromQMSLayerDialog.java

@NonNull
@Override//from ww w  . jav  a2  s  .c o m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    super.onCreateDialog(savedInstanceState);
    mNet = new NetworkUtil(mContext);
    mQMSIconsDir = MapUtil.prepareTempDir(mContext, "qms_icons");

    if (null != savedInstanceState) {
        int id = savedInstanceState.getInt(KEY_ID);
        MapBase map = MapBase.getInstance();
        if (null != map) {
            ILayer iLayer = map.getLayerById(id);
            if (iLayer instanceof LayerGroup) {
                mGroupLayer = (LayerGroup) iLayer;
            }
        }
    }

    AlertDialog.Builder builder = new AlertDialog.Builder(mContext);
    builder.setTitle(mTitle).setView(R.layout.list_content).setPositiveButton(R.string.add, null)
            .setNeutralButton(R.string.new_tms, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    CreateRemoteTMSLayerDialog newFragment = new CreateRemoteTMSLayerDialog();
                    newFragment.setLayerGroup(mGroupLayer)
                            .setTitle(mContext.getString(R.string.create_tms_layer))
                            .setTheme(((NGActivity) getActivity()).getThemeId())
                            .show(getActivity().getSupportFragmentManager(), "create_tms_layer");
                }
            }).setNegativeButton(R.string.cancel, null);

    final AlertDialog dialog = builder.create();
    dialog.setCanceledOnTouchOutside(false);

    mData = new ArrayList<>();
    mChecked = new ArrayList<>();

    IGISApplication application = (IGISApplication) getActivity().getApplication();
    application.sendScreen(ConstantsUI.GA_DIALOG_QMS);
    return dialog;
}

From source file:com.speed.traquer.app.Feedback_rate_taxi.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK)) {
        if (actv_comp_taxi.length() != 0 || inputTaxi.length() != 0) {
            final AlertDialog.Builder alertBox = new AlertDialog.Builder(Feedback_rate_taxi.this);
            alertBox.setIcon(R.drawable.info_icon);
            alertBox.setCancelable(false);
            alertBox.setTitle("Do you want to cancel feedback?");
            alertBox.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface arg0, int arg1) {
                    // finish used for destroyed activity
                    easyTracker.send(MapBuilder.createEvent("Feedback taxi", "Cancel Feedback taxi (Yes)",
                            "Feedback taxi event", null).build());
                    finish();//from  w  ww  .j av  a  2s . c o m
                    Intent intent = new Intent(Feedback_rate_taxi.this, Speedometer.class);
                    Feedback_rate_taxi.this.startActivity(intent);
                }
            });

            alertBox.setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int arg1) {
                    easyTracker.send(MapBuilder.createEvent("Feedback taxi", "Cancel Feedback taxi (No)",
                            "Feedback taxi event", null).build());
                    dialog.cancel();
                }
            });

            alertBox.show();
        } else {
            NavUtils.navigateUpFromSameTask(this);
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:me.willowcheng.makerthings.ui.OpenHABWidgetListFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    Log.d(TAG, "onActivityCreated()");
    Log.d(TAG, "isAdded = " + isAdded());
    mActivity = (OpenHABMainActivity) getActivity();
    openHABWidgetDataSource = new OpenHABWidgetDataSource();
    openHABWidgetAdapter = new OpenHABWidgetAdapter(getActivity(), R.layout.openhabwidgetlist_genericitem,
            widgetList);/*  w w  w .  j  a  va  2s . co  m*/
    getListView().setAdapter(openHABWidgetAdapter);
    openHABBaseUrl = mActivity.getOpenHABBaseUrl();
    openHABUsername = mActivity.getOpenHABUsername();
    openHABPassword = mActivity.getOpenHABPassword();
    openHABWidgetAdapter.setOpenHABUsername(openHABUsername);
    openHABWidgetAdapter.setOpenHABPassword(openHABPassword);
    openHABWidgetAdapter.setOpenHABBaseUrl(openHABBaseUrl);
    openHABWidgetAdapter.setAsyncHttpClient(mAsyncHttpClient);
    getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Log.d(TAG, "Widget clicked " + String.valueOf(position));
            OpenHABWidget openHABWidget = openHABWidgetAdapter.getItem(position);
            if (openHABWidget.hasLinkedPage()) {
                // Widget have a page linked to it
                String[] splitString;
                splitString = openHABWidget.getLinkedPage().getTitle().split("\\[|\\]");
                if (OpenHABWidgetListFragment.this.widgetSelectedListener != null) {
                    widgetSelectedListener.onWidgetSelectedListener(openHABWidget.getLinkedPage(),
                            OpenHABWidgetListFragment.this);
                }
                //                        navigateToPage(openHABWidget.getLinkedPage().getLink(), splitString[0]);
                mOldSelectedItem = position;
            } else {
                Log.d(TAG, String.format("Click on item with no linked page, reverting selection to item %d",
                        mOldSelectedItem));
                // If an item without a linked page is clicked this will clear the selection
                // and revert it to previously selected item (if any) when CHOICE_MODE_SINGLE
                // is switched on for widget listview in multi-column mode on tablets
                getListView().clearChoices();
                getListView().requestLayout();
                getListView().setItemChecked(mOldSelectedItem, true);
            }
        }

    });
    getListView().setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            Log.d(TAG, "Widget long-clicked " + String.valueOf(position));
            OpenHABWidget openHABWidget = openHABWidgetAdapter.getItem(position);
            Log.d(TAG, "Widget type = " + openHABWidget.getType());
            if (openHABWidget.getType().equals("Switch") || openHABWidget.getType().equals("Selection")
                    || openHABWidget.getType().equals("Colorpicker")) {
                selectedOpenHABWidget = openHABWidget;
                AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
                builder.setTitle(R.string.nfc_dialog_title);
                OpenHABNFCActionList nfcActionList = new OpenHABNFCActionList(selectedOpenHABWidget);
                builder.setItems(nfcActionList.getNames(), new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                        Intent writeTagIntent = new Intent(getActivity().getApplicationContext(),
                                OpenHABWriteTagActivity.class);
                        writeTagIntent.putExtra("sitemapPage", displayPageUrl);
                        writeTagIntent.putExtra("item", selectedOpenHABWidget.getItem().getName());
                        writeTagIntent.putExtra("itemType", selectedOpenHABWidget.getItem().getType());
                        OpenHABNFCActionList nfcActionList = new OpenHABNFCActionList(selectedOpenHABWidget);
                        writeTagIntent.putExtra("command", nfcActionList.getCommands()[which]);
                        startActivityForResult(writeTagIntent, 0);
                        Util.overridePendingTransition(getActivity(), false);
                        selectedOpenHABWidget = null;
                    }
                });
                builder.show();
                return true;
            }
            return true;
        }
    });
    if (getResources().getInteger(R.integer.pager_columns) > 1) {
        Log.d(TAG, "More then 1 column, setting selector on");
        getListView().setChoiceMode(ListView.CHOICE_MODE_SINGLE);
    }
}

From source file:jp.watnow.plugins.dialog.Notification.java

/**
 * Builds and shows a native Android alert with given Strings
 * @param message           The message the alert should display
 * @param title             The title of the alert
 * @param buttonLabel       The label of the button
 * @param callbackContext   The callback context
 *//*from  w  ww . j av a2 s  .c  o m*/
public synchronized void alert(final String message, final String title, final String buttonLabel,
        final CallbackContext callbackContext) {
    final CordovaInterface cordova = this.cordova;

    Runnable runnable = new Runnable() {
        public void run() {

            AlertDialog.Builder dlg = createDialog(cordova); // new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
            dlg.setMessage(message);
            dlg.setTitle(title);
            dlg.setCancelable(false);
            dlg.setPositiveButton(buttonLabel, new AlertDialog.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0));
                }
            });
            dlg.setOnCancelListener(new AlertDialog.OnCancelListener() {
                public void onCancel(DialogInterface dialog) {
                    dialog.dismiss();
                    callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, 0));
                }
            });

            changeTextDirection(dlg);
        };
    };
    this.cordova.getActivity().runOnUiThread(runnable);
}

From source file:com.andybotting.tramhunter.activity.StopDetailsActivity.java

/**
 * Show a dialog message for a given 'Special Event'
 * @param message/*from   w  w  w. j a  v  a2  s  .co  m*/
 */
private void showSpecialEvent(String message) {
    AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
    dialogBuilder.setTitle("Special Event");
    dialogBuilder.setMessage(message);
    dialogBuilder.setPositiveButton("OK", null);
    dialogBuilder.setIcon(R.drawable.ic_dialog_alert);
    dialogBuilder.show();
}

From source file:fr.pasteque.client.Configure.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case MENU_EXPORT_ID:
        export();//  w w w  .  j  av  a 2 s .  c om
        break;
    case MENU_IMPORT_ID:
        // Get properties file
        // TODO: check external storage state and access
        File path = Environment.getExternalStorageDirectory();
        path = new File(path, "pasteque");
        File file = new File(path, "pasteque.properties");
        FileInputStream fis;
        try {
            fis = new FileInputStream(file);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            Toast t = Toast.makeText(this, R.string.cfg_import_file_not_found, Toast.LENGTH_SHORT);
            t.show();
            return true;
        }
        Properties props = new Properties();
        try {
            props.load(fis);
        } catch (IOException e) {
            e.printStackTrace();
            Toast t = Toast.makeText(this, R.string.cfg_import_read_error, Toast.LENGTH_SHORT);
            t.show();
            return true;
        }
        // Load props
        String host = props.getProperty("host", DEMO_HOST);
        String machineName = props.getProperty("machine_name", null);
        String ticketsMode = props.getProperty("tickets_mode", "simple");
        String user = props.getProperty("user", null);
        String password = props.getProperty("password", null);
        String location = props.getProperty("stock_location", "");
        String printDrv = props.getProperty("printer_driver", "None");
        String printModel = props.getProperty("printer_model", "");
        String printAddr = props.getProperty("printer_address", "");
        String printCtxTry = String.valueOf(getPref("printer_connect_try", DEFAULT_PRINTER_CONNECT_TRY));
        // Save
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putString("host", host);
        edit.putString("machine_name", machineName);
        // Set tickets mode, simple by default
        switch (ticketsMode) {
        case "restaurant":
            edit.putString("tickets_mode", String.valueOf(RESTAURANT_MODE));
            break;
        case "standard":
            edit.putString("tickets_mode", String.valueOf(STANDARD_MODE));
            break;
        default:
            edit.putString("tickets_mode", String.valueOf(SIMPLE_MODE));
            break;
        }
        edit.putString("user", user);
        edit.putString("password", password);
        edit.putString("stock_location", location);
        edit.putString("printer_driver", printDrv);
        edit.putString("printer_model", printModel);
        edit.putString("printer_address", printAddr);
        edit.putString("printer_connect_try", printCtxTry);
        edit.apply();
        Toast t = Toast.makeText(this, R.string.cfg_import_done, Toast.LENGTH_SHORT);
        t.show();
        // Reset activity to reload values
        this.finish();
        Intent i = new Intent(this, Configure.class);
        this.startActivity(i);
        break;
    case MENU_DEBUG_ID:
        AlertDialog.Builder b = new AlertDialog.Builder(this);
        b.setTitle(R.string.cfg_debug_alert_title);
        b.setMessage(R.string.cfg_debug_alert_message);
        b.setIcon(android.R.drawable.ic_dialog_alert);
        b.setNegativeButton(android.R.string.cancel, null);
        b.setPositiveButton(R.string.cfg_debug_alert_continue, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
                Intent i = new Intent(Configure.this, Debug.class);
                Configure.this.startActivity(i);
            }
        });
        b.show();
        break;
    }
    return true;
}

From source file:com.metaphyze.hackernewsfrontpage.HackerNewsFrontPageActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_hacker_news_front_page);

    bookFileName = getFilesDir() + File.separator + "bookmarked_posts.js";
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawerList = (ListView) findViewById(R.id.drawer);
    location = (TextView) findViewById(R.id.location);

    webView = (WebView) findViewById(R.id.content_frame);
    webView.getSettings().setJavaScriptEnabled(true);
    webView.getSettings().setDomStorageEnabled(true);
    webView.getSettings().setAppCacheEnabled(true);
    loadingView = findViewById(R.id.loading);
    ProgressBar progressBar = ((ProgressBar) findViewById(R.id.progress_bar));
    progressBar.setIndeterminate(true);// www .  ja v a2  s .  c o  m
    drawerList.setAdapter(new HackerNewsAdapter(HackerNewsFrontPageActivity.this, R.layout.post_item,
            new ArrayList<HackerNewsPost>(), true));
    getActionBar().setTitle("Hacker News Front Page (Loading Live Stream...)");
    drawerList.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            HackerNewsPost post = (HackerNewsPost) parent.getItemAtPosition(position);

            webView.loadUrl(post.getUrl());
            webView.setWebViewClient(new WebViewClient() {

                @Override
                public void onPageStarted(WebView view, String url, Bitmap favicon) {
                    super.onPageStarted(view, url, favicon);
                    loadingView.setVisibility(View.VISIBLE);
                    location.setText("LOADING......" + url);
                }

                @Override
                public void onPageFinished(WebView view, String url) {
                    super.onPageFinished(view, url);
                    loadingView.setVisibility(View.INVISIBLE);
                    location.setText(url);
                }

                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    view.loadUrl(url);
                    return true;
                }

                @Override
                public void onReceivedError(WebView view, int errorCode, String description,
                        String failingUrl) {
                    loadingView.setVisibility(View.INVISIBLE);
                    location.setText("ERROR LOADING PAGE");
                    view.loadUrl("file:///android_asset/failed_to_load_page.html");
                }

            });
            drawerLayout.closeDrawer(drawerList);
        }
    });

    drawerList.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            final HackerNewsPost clonedPost = ((HackerNewsPost) parent.getItemAtPosition(position)).clone();
            clonedPost.setPostedAgo(new Date().toString());
            AlertDialog.Builder builder = new AlertDialog.Builder(HackerNewsFrontPageActivity.this);
            if (((HackerNewsAdapter) parent.getAdapter()).isLive()) {
                builder.setTitle("Bookmark?");
                builder.setMessage("Do you want to bookmark the post\n" + clonedPost.getTitle());
                builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        try {
                            HackerNewsFrontPageContents contents = readContentsFromBookmarksFile();
                            if (contents == null) {
                                showError("ERROR", "Failed to read bookmark file");
                                dialog.dismiss();
                                return;
                            }

                            if (!contents.addPost(clonedPost)) {
                                showError("Already Exists", "Not added becasue bookmark already exists");
                                dialog.dismiss();
                                return;
                            }

                            if (!saveContentsToBookmarksFile(contents)) {
                                showError("ERROR", "Failed to save bookmark");
                                dialog.dismiss();
                            }

                        } catch (Exception ex) {
                            ex.printStackTrace();
                            showError("ERROR", "Internal error: " + ex);
                        }
                    }
                }).setNegativeButton("No", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.dismiss();
                    }
                });
            } else {
                builder.setTitle("Delete?");
                builder.setMessage("Do you want to delete the bookmarked post:\n" + clonedPost.getTitle());
                builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        try {

                            HackerNewsFrontPageContents contents = readContentsFromBookmarksFile();
                            if (contents == null) {
                                showError("ERROR", "Unable to find or generate bookmarks file");
                                dialog.dismiss();
                                return;
                            }

                            if (!contents.removePost(clonedPost)) {
                                showError("Not Removed", "Does not exist? How's that possible?");
                                dialog.dismiss();
                                return;
                            }

                            if (saveContentsToBookmarksFile(contents)) {
                                if (contents.getItems().size() > 0) {
                                    drawerList
                                            .setAdapter(new HackerNewsAdapter(HackerNewsFrontPageActivity.this,
                                                    R.layout.post_item, contents.getItems(), false));
                                } else {
                                    showError("No more bookmarks", "Reverting to live stream");
                                    loadLiveStream();
                                }
                            } else {
                                showError("ERROR", "Failed to save bookmark deletion");
                            }
                            dialog.dismiss();

                        } catch (Exception ex) {
                            ex.printStackTrace();
                            showError("ERROR", "Internal Error: " + ex);
                        }

                    }
                }).setNegativeButton("No", new DialogInterface.OnClickListener() {

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

            builder.setCancelable(true);
            builder.create().show();

            return false;
        }
    });

    drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.drawer_icon, 0, 0);
    drawerLayout.setDrawerListener(drawerToggle);

    ActionBar actionBar = getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    //      actionBar.setHomeButtonEnabled(true);

    requestQueue = Volley.newRequestQueue(this);
    loadLiveStream();

}

From source file:edu.missouri.niaaa.ema.activity.AdminManageActivity.java

private Dialog removeDialog(Context context) {

    LayoutInflater inflater = LayoutInflater.from(context);
    final View textEntryView = inflater.inflate(R.layout.remove_id, null);
    final CheckBox rm_check = (CheckBox) textEntryView.findViewById(R.id.rm_local);
    rm_check.setText(R.string.remove_local);
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setView(textEntryView);//from w w w.  ja  va2s  .com
    builder.setCancelable(false);
    builder.setTitle(R.string.assign_remove_title);
    builder.setMessage(R.string.remove_msg);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub  

            cleanUp(ctx);//replace following

            //                    editor.putString(Utilities.SP_KEY_LOGIN_USERID, "");                       
            //                 editor.putString(Utilities.SP_KEY_LOGIN_USERPWD, "");
            //                 editor.putString(Utilities.SP_KEY_LOGIN_STUDY_STARTTIME, "");
            //                 editor.commit();

            // remove local file, if checked
            Log.d(TAG, "is checked " + rm_check.isChecked());
            if (rm_check.isChecked()) {
                deleteDirectory(Utilities.PHONE_BASE_PATH);
            }

            setHints();
            finish();
        }
    });
    builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            // TODO Auto-generated method stub  

        }
    });

    return builder.create();

}