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.bookkos.bircle.CaptureActivity.java

private void titleInputDialog(final String isbn, final JSONArray json_array) {
    // ?????//w w w . jav  a2  s .com
    final EditText titleEditText = new EditText(_activity);

    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setTitle("???????????");
    alertDialogBuilder.setMessage("??????????!");
    alertDialogBuilder.setView(titleEditText);
    alertDialogBuilder.setPositiveButton("????",
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String title = titleEditText.getText().toString();
                    // ?????manually_catalog_register???
                    if (!title.isEmpty() || title != " " || title != "") {
                        title = title.replaceAll(" ", "_");
                        title = title.replaceAll("", "_");
                        String request_url = initManuallyCatalogRegistUrl + isbn + "&title=" + title;
                        HttpConnectPostReturnFlag manuallyCatalogRegist = new HttpConnectPostReturnFlag(
                                _activity, request_url);
                        manuallyCatalogRegist.execute();

                        // ???????????, ??json_array?????????, ???
                        if (json_array != null) {
                            parseShelfData(isbn, json_array);
                        } else {
                            // ??????, ?ISBN??????
                            if (registFlag == 1) {
                                // ?????????????
                                arrayList.add("&book_code[]=" + lastResult);
                                if (bookListViewAdapter.isEmpty()) {
                                    animateTranslationY(bookRegistRelativeLayout, displayHeight,
                                            displayHeight - displayHeight / 4 - titleBarHeight);
                                    borrowReturnButton.setEnabled(false);
                                    registButton.setEnabled(false);
                                }
                                bookListViewAdapter.add(new BookListViewItem(lastResult.toString()));
                                //                        for(int i=0; i < arrayList.size(); i++){
                                //                           text += arrayList.get(i) + "\n";
                                //                        }
                                Toast.makeText(_context, "ISBN = " + lastResult + " ?????.",
                                        Toast.LENGTH_SHORT).show();
                                bircleBeepManager.playBeepSoundAndVibrate(2);
                                restartPreviewAfterDelay(BULK_MODE_SCAN_DELAY_MS);
                            }
                        }
                    } else {
                        Toast.makeText(_context, "???????!", Toast.LENGTH_LONG)
                                .show();
                    }
                }
            });
    alertDialogBuilder.setNeutralButton("", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            restartPreviewAfterDelay(BULK_MODE_SCAN_DELAY_MS);
        }
    });

    alertDialogBuilder.setCancelable(true);
    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialogBuilder.show();
}

From source file:com.juick.android.MessageMenu.java

protected void runActions() {
    if (!isDialogMode()) {
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        final CharSequence[] items = new CharSequence[menuActions.size()];
        for (int j = 0; j < items.length; j++) {
            items[j] = menuActions.get(j).title;
        }//from w w  w  . j a v a2s  .  co m
        builder.setItems(items, this);
        final AlertDialog alertDialog = builder.create();
        alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                ColorsTheme.ColorTheme colorTheme = JuickMessagesAdapter.getColorTheme(activity);
                ColorDrawable divider = new ColorDrawable(
                        colorTheme.getColor(ColorsTheme.ColorKey.COMMON_BACKGROUND, 0xFFFFFFFF));
                alertDialog.getListView().setDivider(divider);
                alertDialog.getListView().setDividerHeight(1);
            }
        });
        alertDialog.show();

        final ListAdapter adapter = alertDialog.getListView().getAdapter();
        SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(activity);
        float menuFontScale = 1;
        try {
            menuFontScale = Float.parseFloat(sp.getString("menuFontScale", "1.0"));
        } catch (Exception e) {
            e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
        }
        final boolean compressedMenu = sp.getBoolean("compressedMenu", false);
        final boolean singleLineMenu = sp.getBoolean("singleLineMenu", false);
        final float finalMenuFontScale = menuFontScale;
        final int screenHeight = activity.getWindow().getWindowManager().getDefaultDisplay().getHeight();
        alertDialog.getListView().setAdapter(new ListAdapter() {
            @Override
            public boolean areAllItemsEnabled() {
                return adapter.areAllItemsEnabled();
            }

            @Override
            public boolean isEnabled(int position) {
                return adapter.isEnabled(position);
            }

            @Override
            public void registerDataSetObserver(DataSetObserver observer) {
                adapter.registerDataSetObserver(observer);
            }

            @Override
            public void unregisterDataSetObserver(DataSetObserver observer) {
                adapter.unregisterDataSetObserver(observer);
            }

            @Override
            public int getCount() {
                return items.length;
            }

            @Override
            public Object getItem(int position) {
                return adapter.getItem(position);
            }

            @Override
            public long getItemId(int position) {
                return adapter.getItemId(position);
            }

            @Override
            public boolean hasStableIds() {
                return adapter.hasStableIds();
            }

            @Override
            public View getView(int position, View convertView, ViewGroup parent) {
                View retval = adapter.getView(position, null, parent);
                if (retval instanceof TextView) {
                    TextView tv = (TextView) retval;
                    if (compressedMenu) {
                        int minHeight = (int) ((screenHeight * 0.7) / getCount());
                        tv.setMinHeight(minHeight);
                        tv.setMinimumHeight(minHeight);
                    }
                    if (singleLineMenu) {
                        tv.setSingleLine(true);
                        tv.setEllipsize(TextUtils.TruncateAt.MIDDLE);
                    }
                    tv.setTextSize(22 * finalMenuFontScale);
                }
                return retval;
            }

            @Override
            public int getItemViewType(int position) {
                return adapter.getItemViewType(position);
            }

            @Override
            public int getViewTypeCount() {
                return adapter.getViewTypeCount();
            }

            @Override
            public boolean isEmpty() {
                return adapter.isEmpty();
            }
        });
    } else {
        AlertDialog.Builder builder = new AlertDialog.Builder(
                new ContextThemeWrapper(activity, R.style.Theme_Sherlock));
        View dialogView = activity.getLayoutInflater().inflate(R.layout.message_menu2, null);
        builder.setView(dialogView);
        builder.setCancelable(true);
        int width = activity.getWindowManager().getDefaultDisplay().getWidth();
        View scrollView = dialogView.findViewById(R.id.scrollView);
        scrollView.getLayoutParams().width = (int) (width * 0.90);
        final AlertDialog alertDialog = builder.create();
        alertDialog.setOnShowListener(new DialogInterface.OnShowListener() {
            @Override
            public void onShow(DialogInterface dialog) {
                //MainActivity.restyleChildrenOrWidget(alertDialog.getWindow().getDecorView());
            }
        });
        TextView messageNo = (TextView) dialogView.findViewById(R.id.message_no);
        messageNo.setText(listSelectedItem.getDisplayMessageNo());
        Spinner openUrl = (Spinner) dialogView.findViewById(R.id.open_url);
        Button singleURL = (Button) dialogView.findViewById(R.id.single_url);
        if (urls != null && urls.size() == 1) {
            singleURL.setVisibility(View.VISIBLE);
            openUrl.setVisibility(View.GONE);
            SpannableStringBuilder sb = new SpannableStringBuilder();
            sb.append(urls.get(0));
            sb.setSpan(new UnderlineSpan(), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
            singleURL.setText(sb);
            singleURL.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    alertDialog.dismiss();
                    launchURL(listSelectedItem.getMID(), urls.get(0));
                }
            });
        } else if (urls != null && urls.size() > 0) {
            singleURL.setVisibility(View.GONE);
            openUrl.setVisibility(View.VISIBLE);
            openUrl.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                @Override
                public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                    if (position != 0) {
                        alertDialog.dismiss();
                        launchURL(listSelectedItem.getMID(), urls.get(position));
                    }
                }

                @Override
                public void onNothingSelected(AdapterView<?> parent) {
                    //To change body of implemented methods use File | Settings | File Templates.
                }
            });
            urls.add(0, activity.getString(R.string.ClickToSelectURL));
            openUrl.setAdapter(new BaseAdapter() {
                @Override
                public int getCount() {
                    return urls.size();
                }

                @Override
                public Object getItem(int position) {
                    return position;
                }

                @Override
                public long getItemId(int position) {
                    return position;
                }

                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                    View rowView = activity.getLayoutInflater().inflate(android.R.layout.simple_list_item_1,
                            null);
                    TextView textView = (TextView) rowView.findViewById(android.R.id.text1);
                    textView.setSingleLine(false);
                    textView.setMaxLines(5);
                    SpannableStringBuilder sb = new SpannableStringBuilder();
                    sb.append(urls.get(position));
                    if (position == 0) {
                        textView.setTextColor(0xFF808080);
                    } else {
                        sb.setSpan(new UnderlineSpan(), 0, sb.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                    }
                    textView.setText(sb);
                    return rowView;
                }
            });
        } else {
            openUrl.setVisibility(View.GONE);
            singleURL.setVisibility(View.GONE);
        }
        final String UName = listSelectedItem.User.UName;
        View recommendMessage = dialogView.findViewById(R.id.recommend_message);
        View deleteMessage = dialogView.findViewById(R.id.delete_message);
        View saveMessage = dialogView.findViewById(R.id.save_message);
        View unsaveMessage = dialogView.findViewById(R.id.unsave_message);
        //View subscribeUser = dialogView.findViewById(R.id.subscribe_user);
        View subscribeMessage = dialogView.findViewById(R.id.subscribe_message);
        //View unsubscribeUser = dialogView.findViewById(R.id.unsubscribe_user);
        View unsubscribeMessage = dialogView.findViewById(R.id.unsubscribe_message);
        View translateMessage = dialogView.findViewById(R.id.translate_message);
        View shareMessage = dialogView.findViewById(R.id.share_message);
        //View blacklistUser = dialogView.findViewById(R.id.blacklist_user);
        //View filterUser = dialogView.findViewById(R.id.filter_user);
        //View userBlog = dialogView.findViewById(R.id.user_blog);
        //View userStats = dialogView.findViewById(R.id.user_stats);
        View openMessageInBrowser = dialogView.findViewById(R.id.open_message_in_browser);
        Button userCenter = (Button) dialogView.findViewById(R.id.user_center);
        if (null == dialogView.findViewById(R.id.column_3)) {
            // only for portrait
            userCenter.setText("@" + listSelectedItem.User.UName + " " + userCenter.getText());
        }

        unsubscribeMessage.setEnabled(listSelectedItem.getRID() == 0);
        subscribeMessage.setEnabled(listSelectedItem.getRID() == 0);
        unsaveMessage.setEnabled(listSelectedItem.getRID() == 0);
        recommendMessage.setEnabled(listSelectedItem.getRID() == 0);

        if (UName.equalsIgnoreCase(JuickAPIAuthorizer.getJuickAccountName(activity.getApplicationContext()))) {
            recommendMessage.setVisibility(View.GONE);
        } else {
            deleteMessage.setVisibility(View.GONE);
        }
        if (messagesSource instanceof SavedMessagesSource) {
            saveMessage.setVisibility(View.GONE);
        } else {
            unsaveMessage.setVisibility(View.GONE);
        }
        recommendMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionRecommendMessage();
            }
        });
        deleteMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionDeleteMessage();
            }
        });
        saveMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionSaveMessage();
            }
        });
        unsaveMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionUnsaveMessage();
            }
        });
        //            subscribeUser.setOnClickListener(new View.OnClickListener() {
        //                @Override
        //                public void onClick(View v) {
        //                    alertDialog.dismiss();
        //                    actionSubscribeUser();
        //                }
        //            });
        subscribeMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionSubscribeMessage();
            }
        });
        //            unsubscribeUser.setOnClickListener(new View.OnClickListener() {
        //                @Override
        //                public void onClick(View v) {
        //                    alertDialog.dismiss();
        //                    actionUnsubscribeUser();
        //                }
        //            });
        unsubscribeMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionUnsubscribeMessage();
            }
        });
        translateMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionTranslateMessage();
            }
        });
        shareMessage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionShareMessage();
            }
        });
        //            blacklistUser.setOnClickListener(new View.OnClickListener() {
        //                @Override
        //                public void onClick(View v) {
        //                    alertDialog.dismiss();
        //                    actionBlacklistUser();
        //                }
        //            });
        //            filterUser.setOnClickListener(new View.OnClickListener() {
        //                @Override
        //                public void onClick(View v) {
        //                    alertDialog.dismiss();
        //                    actionFilterUser(UName);
        //                }
        //            });
        //            userBlog.setOnClickListener(new View.OnClickListener() {
        //                @Override
        //                public void onClick(View v) {
        //                    alertDialog.dismiss();
        //                    actionUserBlog();
        //                }
        //            });
        //            userStats.setOnClickListener(new View.OnClickListener() {
        //                @Override
        //                public void onClick(View v) {
        //                    alertDialog.dismiss();
        //                    actionUserStats();
        //                }
        //            });
        openMessageInBrowser.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionOpenMessageInBrowser();
            }
        });
        userCenter.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                alertDialog.dismiss();
                actionUserCenter();
            }
        });
        completeInitDialogMode(alertDialog, dialogView);
        alertDialog.show();
    }
}

From source file:co.dilaver.quoter.activities.ShareActivity.java

private void showFontSelectionDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setAdapter(textFontAdapter, new DialogInterface.OnClickListener() {
        @Override/*ww w  .  ja  v a  2s .  c o m*/
        public void onClick(DialogInterface dialog, int which) {
            String textFontString = "";
            switch (which) {
            case Fonts.ALEXBRUSH_REGULAR:
                textFontString = "AlexBrush-Regular.ttf";
                break;
            case Fonts.ALLER_LT:
                textFontString = "Aller_Lt.ttf";
                break;
            case Fonts.ALLURA_REGULAR:
                textFontString = "Allura-Regular.otf";
                break;
            case Fonts.AMATICSC_REGULAR:
                textFontString = "AmaticSC-Regular.ttf";
                break;
            case Fonts.ANTONIO_REGULAR:
                textFontString = "Antonio-Regular.ttf";
                break;
            case Fonts.ARIZONIA_REGULAR:
                textFontString = "Arizonia-Regular.ttf";
                break;
            case Fonts.BEBAS___:
                textFontString = "BEBAS___.ttf";
                break;
            case Fonts.CAPTURE_IT:
                textFontString = "Capture_it.ttf";
                break;
            case Fonts.CAVIARDREAMS:
                textFontString = "CaviarDreams.ttf";
                break;
            case Fonts.CHUNKFIVE:
                textFontString = "Chunkfive.otf";
                break;
            case Fonts.DANCINGSCRIPT_REGULAR:
                textFontString = "DancingScript-Regular.otf";
                break;
            case Fonts.DOSIS_REGULAR:
                textFontString = "Dosis-Regular.otf";
                break;
            case Fonts.EXO_REGULAR:
                textFontString = "Exo-Regular.otf";
                break;
            case Fonts.FFF_TUSJ:
                textFontString = "FFF_Tusj.ttf";
                break;
            case Fonts.GOODDOG:
                textFontString = "GoodDog.otf";
                break;
            case Fonts.GRANDHOTEL_REGULAR:
                textFontString = "GrandHotel-Regular.otf";
                break;
            case Fonts.GREATVIBES_REGULAR:
                textFontString = "GreatVibes-Regular.otf";
                break;
            case Fonts.KAUSHANSCRIPT_REGULAR:
                textFontString = "KaushanScript-Regular.otf";
                break;
            case Fonts.LATO_REGULAR:
                textFontString = "Lato-Regular.ttf";
                break;
            case Fonts.LEAGUEGOTHIC_REGULAR:
                textFontString = "LeagueGothic-Regular.otf";
                break;
            case Fonts.LEARNINGCURVE_OT:
                textFontString = "LearningCurve_OT.otf";
                break;
            case Fonts.LOBSTERTWO_REGULAR:
                textFontString = "LobsterTwo-Regular.otf";
                break;
            case Fonts.LOBSTER:
                textFontString = "Lobster.otf";
                break;
            case Fonts.MATHLETE_BULKY:
                textFontString = "Mathlete-Bulky.otf";
                break;
            case Fonts.MONTSERRAT_REGULAR:
                textFontString = "Montserrat-Regular.otf";
                break;
            case Fonts.OPENSANS_REGULAR:
                textFontString = "OpenSans-Regular.ttf";
                break;
            case Fonts.OSWALD_REGULAR:
                textFontString = "Oswald-Regular.ttf";
                break;
            case Fonts.PACIFICO:
                textFontString = "Pacifico.ttf";
                break;
            case Fonts.PLAYFAIRDISPLAYSC_REGULAR:
                textFontString = "PlayfairDisplaySC-Regular.ttf";
                break;
            case Fonts.QUICKSAND_REGULAR:
                textFontString = "Quicksand-Regular.otf";
                break;
            case Fonts.RALEWAY_REGULAR:
                textFontString = "Raleway-Regular.ttf";
                break;
            case Fonts.ROBOTO_REGULAR:
                textFontString = "Roboto-Regular.ttf";
                break;
            case Fonts.ROBOTOSLAB_REGULAR:
                textFontString = "RobotoSlab-Regular.ttf";
                break;
            case Fonts.SEASRN__:
                textFontString = "SEASRN__.ttf";
                break;
            case Fonts.SOFIA_REGULAR:
                textFontString = "Sofia-Regular.otf";
                break;
            case Fonts.SOURCESANSPRO_REGULAR:
                textFontString = "SourceSansPro-Regular.otf";
                break;
            case Fonts.TITILLIUM_REGULAR:
                textFontString = "Titillium-Regular.otf";
                break;
            case Fonts.WALKWAY_BOLD:
                textFontString = "Walkway_Bold.ttf";
                break;
            case Fonts.WINDSONG:
                textFontString = "Windsong.ttf";
                break;
            case Fonts.BLACK_JACK:
                textFontString = "black_jack.ttf";
                break;
            case Fonts.CAC_CHAMPAGNE:
                textFontString = "cac_champagne.ttf";
                break;
            case Fonts.OSTRICH_REGULAR:
                textFontString = "ostrich-regular.ttf";
                break;
            }

            Typeface typeface = Typeface.createFromAsset(getAssets(), textFontString);
            chooseTextFont.setTypeface(typeface);
            previewQuote.setTypeface(typeface);
            previewAuthor.setTypeface(typeface);
        }
    });
    builder.setTitle(getString(R.string.str_ChooseTextFont));
    builder.setCancelable(true);
    builder.show();
}

From source file:com.example.android.lightcontrol.MainActivity.java

private void theme_to_who() {
    LayoutInflater inflater = LayoutInflater.from(this);
    final View v = inflater.inflate(R.layout.theme_to_who, null);
    final AlertDialog.Builder dialog = new AlertDialog.Builder(this);

    Spinner theme_to_who = (Spinner) v.findViewById(R.id.theme_to_who);
    final Spinner theme_to_area1 = (Spinner) v.findViewById(R.id.area_1);
    final Spinner theme_to_area2 = (Spinner) v.findViewById(R.id.area_2);
    final TextView region1 = (TextView) v.findViewById(R.id.textView16);
    final TextView region2 = (TextView) v.findViewById(R.id.textView17);
    ArrayAdapter<String> arr_theme_to_who_list;
    ArrayAdapter<String> arr_theme_to_area1_list;
    ArrayAdapter<String> arr_theme_to_area2_list;
    final String[] theme_to_who_list = { "All Lights", "Group" };
    final String[] theme_to_area1_list = { "Group 1" };
    final String[] theme_to_area2_list = { "Group 2" };
    arr_theme_to_who_list = new ArrayAdapter<String>(this, R.layout.my_spinner, theme_to_who_list);
    theme_to_who.setAdapter(arr_theme_to_who_list);
    arr_theme_to_area1_list = new ArrayAdapter<String>(this, R.layout.my_spinner, theme_to_area1_list);
    theme_to_area1.setAdapter(arr_theme_to_area1_list);
    arr_theme_to_area2_list = new ArrayAdapter<String>(this, R.layout.my_spinner, theme_to_area2_list);
    theme_to_area2.setAdapter(arr_theme_to_area2_list);

    theme_to_who.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override/*from   w w  w  .jav  a2  s . co m*/
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            if (theme_to_who_list[i].equals("All Lights")) {
                theme_to_area1.setVisibility(View.INVISIBLE);
                theme_to_area2.setVisibility(View.INVISIBLE);
                region1.setVisibility(View.INVISIBLE);
                region2.setVisibility(View.INVISIBLE);
                GlobalVariable.Theme_to_group_or_all = "ff";
                GlobalVariable.Theme_to_area1_group_8X = "";
                GlobalVariable.Theme_to_area2_group_8X = "";
            }
            if (theme_to_who_list[i].equals("Group")) {
                GlobalVariable.Theme_to_group_or_all = "8";
                theme_to_area1.setVisibility(View.VISIBLE);
                theme_to_area2.setVisibility(View.VISIBLE);
                region1.setVisibility(View.VISIBLE);
                region2.setVisibility(View.VISIBLE);
            }

        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });

    theme_to_area1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {

            if (theme_to_area1_list[i].equals("Group 1")) {
                GlobalVariable.Theme_to_area1_group_8X = "1";
            }

        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });

    theme_to_area2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {

            if (theme_to_area2_list[i].equals("Group 2")) {
                GlobalVariable.Theme_to_area2_group_8X = "3";
            }

        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });

    dialog.setCancelable(false);
    dialog.setTitle(R.string.about_title);
    dialog.setView(v);
    dialog.setPositiveButton(R.string.ok_label_1, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialoginterface, int i) {

        }
    });
    dialog.show();

}

From source file:com.codename1.impl.android.AndroidImplementation.java

@Override
public Object showNativePicker(final int type, final Component source, final Object currentValue,
        final Object data) {
    if (getActivity() == null) {
        return null;
    }/*from   www .j a va2s. c o m*/
    final boolean[] canceled = new boolean[1];
    final boolean[] dismissed = new boolean[1];

    if (editInProgress()) {
        stopEditing(true);
    }
    if (type == Display.PICKER_TYPE_TIME) {

        class TimePick
                implements TimePickerDialog.OnTimeSetListener, TimePickerDialog.OnCancelListener, Runnable {
            int result = ((Integer) currentValue).intValue();

            public void onTimeSet(TimePicker tp, int hour, int minute) {
                result = hour * 60 + minute;
                dismissed[0] = true;
                synchronized (this) {
                    notify();
                }
            }

            public void run() {
                while (!dismissed[0]) {
                    synchronized (this) {
                        try {
                            wait(50);
                        } catch (InterruptedException er) {
                        }
                    }
                }
            }

            @Override
            public void onCancel(DialogInterface di) {
                dismissed[0] = true;
                canceled[0] = true;
                synchronized (this) {
                    notify();
                }
            }
        }
        final TimePick pickInstance = new TimePick();
        getActivity().runOnUiThread(new Runnable() {
            public void run() {
                int hour = ((Integer) currentValue).intValue() / 60;
                int minute = ((Integer) currentValue).intValue() % 60;
                TimePickerDialog tp = new TimePickerDialog(getActivity(), pickInstance, hour, minute, true) {

                    @Override
                    public void cancel() {
                        super.cancel();
                        dismissed[0] = true;
                        canceled[0] = true;
                    }

                    @Override
                    public void dismiss() {
                        super.dismiss();
                        dismissed[0] = true;
                    }

                };
                tp.setOnCancelListener(pickInstance);
                //DateFormat.is24HourFormat(activity));
                tp.show();
            }
        });
        Display.getInstance().invokeAndBlock(pickInstance);
        if (canceled[0]) {
            return null;
        }
        return new Integer(pickInstance.result);
    }
    if (type == Display.PICKER_TYPE_DATE) {
        final java.util.Calendar cl = java.util.Calendar.getInstance();
        if (currentValue != null) {
            cl.setTime((Date) currentValue);
        }
        class DatePick
                implements DatePickerDialog.OnDateSetListener, DatePickerDialog.OnCancelListener, Runnable {
            Date result = (Date) currentValue;

            public void onDateSet(DatePicker dp, int year, int month, int day) {
                java.util.Calendar c = java.util.Calendar.getInstance();
                c.set(java.util.Calendar.YEAR, year);
                c.set(java.util.Calendar.MONTH, month);
                c.set(java.util.Calendar.DAY_OF_MONTH, day);
                result = c.getTime();
                dismissed[0] = true;
                synchronized (this) {
                    notify();
                }
            }

            public void run() {
                while (!dismissed[0]) {
                    synchronized (this) {
                        try {
                            wait(50);
                        } catch (InterruptedException er) {
                        }
                    }
                }
            }

            public void onCancel(DialogInterface di) {
                result = null;
                dismissed[0] = true;
                canceled[0] = true;
                synchronized (this) {
                    notify();
                }
            }
        }
        final DatePick pickInstance = new DatePick();
        getActivity().runOnUiThread(new Runnable() {
            public void run() {
                DatePickerDialog tp = new DatePickerDialog(getActivity(), pickInstance,
                        cl.get(java.util.Calendar.YEAR), cl.get(java.util.Calendar.MONTH),
                        cl.get(java.util.Calendar.DAY_OF_MONTH)) {

                    @Override
                    public void cancel() {
                        super.cancel();
                        dismissed[0] = true;
                        canceled[0] = true;
                    }

                    @Override
                    public void dismiss() {
                        super.dismiss();
                        dismissed[0] = true;
                    }

                };
                tp.setOnCancelListener(pickInstance);
                tp.show();
            }
        });
        Display.getInstance().invokeAndBlock(pickInstance);
        return pickInstance.result;
    }
    if (type == Display.PICKER_TYPE_STRINGS) {
        final String[] values = (String[]) data;
        class StringPick implements Runnable, NumberPicker.OnValueChangeListener {
            int result = -1;

            StringPick() {
            }

            public void run() {
                while (!dismissed[0]) {
                    synchronized (this) {
                        try {
                            wait(50);
                        } catch (InterruptedException er) {
                        }
                    }
                }
            }

            public void cancel() {
                dismissed[0] = true;
                canceled[0] = true;
                synchronized (this) {
                    notify();
                }
            }

            public void ok() {
                canceled[0] = false;
                dismissed[0] = true;
                synchronized (this) {
                    notify();
                }
            }

            @Override
            public void onValueChange(NumberPicker np, int oldVal, int newVal) {
                result = newVal;
            }
        }

        final StringPick pickInstance = new StringPick();
        for (int iter = 0; iter < values.length; iter++) {
            if (values[iter].equals(currentValue)) {
                pickInstance.result = iter;
                break;
            }
        }
        if (pickInstance.result == -1 && values.length > 0) {
            // The picker will default to showing the first element anyways
            // If we don't set the result to 0, then the user has to first
            // scroll to a different number, then back to the first option
            // to pick the first option.
            pickInstance.result = 0;
        }

        getActivity().runOnUiThread(new Runnable() {
            public void run() {
                NumberPicker picker = new NumberPicker(getActivity());
                if (source.getClientProperty("showKeyboard") == null) {
                    picker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
                }
                picker.setMinValue(0);
                picker.setMaxValue(values.length - 1);
                picker.setDisplayedValues(values);
                picker.setOnValueChangedListener(pickInstance);
                if (pickInstance.result > -1) {
                    picker.setValue(pickInstance.result);
                }
                RelativeLayout linearLayout = new RelativeLayout(getActivity());
                RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(50, 50);
                RelativeLayout.LayoutParams numPicerParams = new RelativeLayout.LayoutParams(
                        RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
                numPicerParams.addRule(RelativeLayout.CENTER_HORIZONTAL);

                linearLayout.setLayoutParams(params);
                linearLayout.addView(picker, numPicerParams);

                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getActivity());
                alertDialogBuilder.setView(linearLayout);
                alertDialogBuilder.setCancelable(false)
                        .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                pickInstance.ok();
                            }
                        }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.cancel();
                                pickInstance.cancel();
                            }
                        });
                AlertDialog alertDialog = alertDialogBuilder.create();
                alertDialog.show();
            }
        });
        Display.getInstance().invokeAndBlock(pickInstance);
        if (canceled[0]) {
            return null;
        }
        if (pickInstance.result < 0) {
            return null;
        }
        return values[pickInstance.result];
    }
    return null;
}

From source file:com.entradahealth.entrada.android.app.personal.activities.job_list.JobListActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    activity = this;
    application = (EntradaApplication) EntradaApplication.getAppContext();
    sp = getSharedPreferences("Entrada", Context.MODE_WORLD_READABLE);
    if (sp.getBoolean("SECURE_MSG", true))
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE);
    else/*from ww w.  ja  v  a 2  s  .c  o  m*/
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_SECURE);
    final JobListActivity thisActivity = this;

    //Custom view as action bar
    LayoutInflater mInflater = LayoutInflater.from(this);
    View mCustomView = mInflater.inflate(R.layout.acbar_job_list, null);
    tvAcTitle = (TextView) mCustomView.findViewById(R.id.tvAcTitle);
    ivInbox = (ImageView) mCustomView.findViewById(R.id.ivInbox);
    ivAddJob = (ImageView) mCustomView.findViewById(R.id.ivAddJob);
    ivSync = (ImageView) mCustomView.findViewById(R.id.ivSync);
    ivSchedule = (ImageView) mCustomView.findViewById(R.id.ivSchedule);
    tvAcTitle.setText(BundleKeys.title);

    //Sample icon badger on Action bar item
    badge = new BadgeView(this, ivInbox);
    if (BundleKeys.fromSecureMessaging || !application.isJobListEnabled()) {
        startActivity(new Intent(JobListActivity.this, SecureMessaging.class));
        finish();
    }

    ivInbox.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            startActivity(new Intent(JobListActivity.this, SecureMessaging.class));
            finish();
        }
    });

    ivAddJob.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent addJobIntent = new Intent(JobListActivity.this, AddJobActivity.class);
            addJobIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(addJobIntent);
            finish();
        }
    });

    ivSync.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            ns = new NetworkState(getApplicationContext());
            isConnected = ns.isConnectingToInternet();
            if (isConnected) {
                running = false;
                ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
                for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
                    if ("com.entradahealth.entrada.android.app.personal.sync.SyncService"
                            .equals(service.service.getClassName())
                            || "com.entradahealth.entrada.android.app.personal.sync.DictationUploadService"
                                    .equals(service.service.getClassName())) {
                        running = true;
                    }
                }

                if (!running) {
                    etSearch.setText(null);
                    if (!isFinishing()) {

                        //retryUploads();
                        boolean canSync = true;
                        try {
                            List<Job> jobs = AndroidState.getInstance().getUserState()
                                    .getProvider(currentAccount).getJobs();

                            for (Job j : jobs) {
                                if (j.isPending()) {
                                    canSync = false;
                                    UserState state = AndroidState.getInstance().getUserState();
                                    Log.e("", "onOptionsItemSelected-syncMenuItem--" + j.id);
                                    DictationUploadService.startUpload(JobListActivity.this, state,
                                            currentAccount, j);
                                }
                            }
                        } catch (Exception ex) {
                            ACRA.getErrorReporter().handleSilentException(ex);
                            canSync = false;
                        }

                        if (!canSync) {
                            Toast.makeText(JobListActivity.this,
                                    "Please wait for all uploads to complete before syncing.",
                                    Toast.LENGTH_SHORT).show();

                        } else {
                            rlSyncError.setVisibility(View.GONE);
                            rlUpdated.setVisibility(View.INVISIBLE);
                            tvUpdating.setVisibility(View.VISIBLE);

                            Intent i = new Intent(JobListActivity.this, SyncService.class);
                            startService(i);

                        }

                        isSyncing = true;
                        BundleKeys.SYNC_FOR_ACC = currentAccount.getDisplayName();
                        //BundleKeys.SYNC_FOR_CLINIC = currentAccount.getClinicCode(); 

                        /*task1 = buildMinderTask();
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                           task1.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
                        } else {
                           task1.execute();
                        }*/

                    }
                } else {
                    if (!isResumed)
                        Toast.makeText(JobListActivity.this,
                                "Please wait for all uploads to complete before syncing.", Toast.LENGTH_SHORT)
                                .show();
                }
                isResumed = false;
            } else {
                rlSyncError.setVisibility(View.VISIBLE);
                rlUpdated.setVisibility(View.GONE);
                tvUpdating.setVisibility(View.GONE);
            }

        }
    });

    ivSchedule.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            startActivity(new Intent(JobListActivity.this, ScheduleActivity.class));
            finish();
        }
    });

    getActionBar().setCustomView(mCustomView);
    getActionBar().setDisplayShowCustomEnabled(true);

    //ActionBar ab = getActionBar();
    //ab.setTitle(BundleKeys.title);
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
    registerReceiver(broadcastReceiver, new IntentFilter("CONNECTIVITY_CHANGED"));
    jobIds = new ArrayList<Long>();
    BundleKeys.fromImageDisplay = false;
    BundleKeys.fromCaputreImages = false;
    BundleKeys.fromSecureMessaging = false;

    /*Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
         @Override
         public void uncaughtException(Thread paramThread, Throwable paramThrowable) {
       Log.e("Job-List-Activity","Uncaught-Exception");
       System.exit(2);
         }
     });*/

    setBehindContentView(R.layout.job_list_sliding_menu);
    tvListTitle = (TextView) findViewById(R.id.tvListTitle);
    tvListTitle.setText("Jobs");
    lvSliding = (ListView) findViewById(R.id.lvSlidingMenu);
    lvSliding.setBackgroundColor(Color.parseColor("#262b38"));

    // Get screen width and set sliding width to 3/4
    Display display = getWindowManager().getDefaultDisplay();
    int width = display.getWidth();
    int req_width = width * 3 / 4;

    slidingMenu = getSlidingMenu();
    slidingMenu.setFadeEnabled(true);
    slidingMenu.setFadeDegree(0.35f);
    slidingMenu.setBehindWidth(req_width);
    slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);

    setContentView(R.layout.job_list);

    ivDrawer = (ImageView) findViewById(R.id.ivDrawer);
    ivDrawer.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            slidingMenu.toggle();
            // JobCountTask();
        }
    });

    rlUpdated = (RelativeLayout) findViewById(R.id.rlDateTime);
    rlSyncError = (RelativeLayout) findViewById(R.id.rlSyncError);
    rlSyncError.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            AlertDialog.Builder builder = new AlertDialog.Builder(JobListActivity.this);
            builder.setTitle(R.string.title_sync_error);
            builder.setMessage(R.string.msg_sync_error);
            builder.setPositiveButton("OK", null);
            dgSyncError = builder.create();
            dgSyncError.show();
        }
    });

    tvDate = (TextView) findViewById(R.id.tvDate);
    tvTime = (TextView) findViewById(R.id.tvTime);
    tvUpdating = (TextView) findViewById(R.id.lblUpdating);
    tvSyncFailed = (TextView) findViewById(R.id.lblSyncError);

    handler = new Handler();
    handler.postDelayed(runnable, BundleKeys.mins_to_sync * 60 * 1000);
    handler.postDelayed(runnable_logs, 5 * 60 * 1000);

    jobListView = (ListView) findViewById(R.id.jobListView);
    jobListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    jobListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
            // TODO: evaluate whether to save search text in
            // UserState to repopulate on back press.

            itemClicked = true;
            if (searchTask != null) {
                searchTask.cancel(true);
            }

            Log.d("", "-- Job ItemClick --");
            List<Long> jobList = thisActivity.getJobIdList();
            Preconditions.checkNotNull(jobList, "null List<Job> when adapter view clicked.");
            Job job = AndroidState.getInstance().getUserState().getProvider(currentAccount)
                    .getJob(jobList.get(position));
            if (job != null) {
                Preconditions.checkNotNull(job, "null item in List<Job> when adapter view clicked.");

                if (job.isFlagSet(Job.Flags.UPLOAD_COMPLETED) || job.isFlagSet(Job.Flags.UPLOAD_IN_PROGRESS)
                        || (job.isFlagSet(Job.Flags.UPLOAD_PENDING) && BundleKeys.which == 6))

                {
                    Toast.makeText(thisActivity, "Cannot open a completed dictation.", Toast.LENGTH_SHORT)
                            .show();
                    return;
                } else if (job.isFlagSet(Job.Flags.LOCALLY_DELETED)) {
                    return;
                }

                Intent intent = new Intent(thisActivity, JobDisplayActivity.class);
                Bundle b = new Bundle();
                if (!job.isFlagSet(Flags.HOLD))
                    job = job.setFlag(Flags.IS_FIRST);
                else
                    job = job.clearFlag(Flags.IS_FIRST);
                try {
                    AndroidState.getInstance().getUserState().getProvider(currentAccount).updateJob(job);
                } catch (DomainObjectWriteException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                b.putBoolean("isFirst", true);
                b.putBoolean("isFromList", true);
                b.putBoolean("isNew", false);
                b.putLong(BundleKeys.SELECTED_JOB, job.id);
                b.putString(BundleKeys.SELECTED_JOB_ACCOUNT, currentAccount.getName());
                intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                intent.putExtras(b);
                thisActivity.startActivity(intent);
                thisActivity.finish();
            }
        }

    });

    jobListView.setMultiChoiceModeListener(new JobListMultiChoiceModeListener(this));

    slidingMenu.setOnOpenListener(new OnOpenListener() {

        @Override
        public void onOpen() {
            // TODO Auto-generated method stub

            openSlide();
        }
    });

    lvSliding.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View arg1, int pos, long arg3) {
            // TODO Auto-generated method stub

            switch (pos) {

            case 1:
                //getActionBar().setTitle("Today's Jobs");
                tvAcTitle.setText("Today's Jobs");
                BundleKeys.title = "Today's Jobs";
                BundleKeys.which = 1;
                //menuItem = j_Menu.findItem(R.id.addJobMenuItem);
                //menuItem.setVisible(true);
                ivAddJob.setVisibility(View.VISIBLE);
                jobListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
                etSearch.setText("");
                break;
            case 2:
                //getActionBar().setTitle("Tomorrow's Jobs");
                tvAcTitle.setText("Tomorrow's Jobs");
                BundleKeys.which = 2;
                BundleKeys.title = "Tomorrow's Jobs";
                //menuItem = j_Menu.findItem(R.id.addJobMenuItem);
                //menuItem.setVisible(true);
                ivAddJob.setVisibility(View.VISIBLE);
                jobListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
                etSearch.setText("");
                break;
            case 3:
                //getActionBar().setTitle("Stat Jobs");
                tvAcTitle.setText("Stat Jobs");
                BundleKeys.which = 3;
                BundleKeys.title = "Stat Jobs";
                //menuItem = j_Menu.findItem(R.id.addJobMenuItem);
                //menuItem.setVisible(true);
                ivAddJob.setVisibility(View.VISIBLE);
                jobListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
                etSearch.setText("");
                break;
            case 4:
                //getActionBar().setTitle("All Jobs");
                tvAcTitle.setText("All Jobs");
                BundleKeys.which = 4;
                BundleKeys.title = "All Jobs";
                //menuItem = j_Menu.findItem(R.id.addJobMenuItem);
                //menuItem.setVisible(true);
                ivAddJob.setVisibility(View.VISIBLE);
                jobListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
                etSearch.setText("");
                break;
            case 6:
                //getActionBar().setTitle("Hold Jobs");
                tvAcTitle.setText("Hold Jobs");
                BundleKeys.which = 5;
                BundleKeys.title = "Hold Jobs";
                //menuItem = j_Menu.findItem(R.id.addJobMenuItem);
                //menuItem.setVisible(true);
                ivAddJob.setVisibility(View.VISIBLE);
                jobListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
                etSearch.setText("");
                break;
            case 7:
                //getActionBar().setTitle("Deleted Jobs");
                tvAcTitle.setText("Deleted Jobs");
                BundleKeys.which = 7;
                BundleKeys.title = "Deleted Jobs";
                // Hide "Add Job" menu item
                //menuItem = j_Menu.findItem(R.id.addJobMenuItem);
                //menuItem.setVisible(false);
                ivAddJob.setVisibility(View.GONE);
                jobListView.setChoiceMode(ListView.CHOICE_MODE_NONE);
                etSearch.setText("");
                break;
            case 8:
                //getActionBar().setTitle("Completed Jobs");
                tvAcTitle.setText("Completed Jobs");
                BundleKeys.which = 6;
                BundleKeys.title = "Completed Jobs";
                // Hide "Add Job" menu item
                //menuItem = j_Menu.findItem(R.id.addJobMenuItem);
                //menuItem.setVisible(false);
                ivAddJob.setVisibility(View.GONE);
                jobListView.setChoiceMode(ListView.CHOICE_MODE_NONE);
                etSearch.setText("");
                break;

            case 10:
                isSetting = true;
                //getActionBar().setTitle("Settings");
                tvAcTitle.setText("Settings Jobs");
                startActivity(new Intent(JobListActivity.this, EntradaSettings.class)
                        .setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
                finish();
                break;

            case 11:
                // Check if there are any held jobs or any uploads in
                // progress
                boolean isHeld = true, isPending = true;
                try {
                    List<Job> jobs = AndroidState.getInstance().getUserState().getProvider(currentAccount)
                            .getJobs();

                    for (Job j : jobs) {
                        if (j.isPending())
                            isPending = false;
                        if (j.isFlagSet(Job.Flags.HOLD))
                            isHeld = false;

                    }
                } catch (Exception ex) {
                    ACRA.getErrorReporter().handleSilentException(ex);
                    isPending = false;
                    isHeld = false;
                }
                if (SyncService.isRunning()) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(JobListActivity.this);
                    builder.setTitle(R.string.del_acc_err_title);
                    builder.setMessage(R.string.manage_q_upload_error);
                    builder.setPositiveButton("OK", null);
                    builder.setCancelable(true);
                    dgManageQ = builder.create();
                    dgManageQ.show();
                } else if (isPending && isHeld) {
                    Intent qIntent = new Intent(JobListActivity.this, ManageQueuesActivity.class);
                    qIntent.putExtra("from_settings", false);
                    qIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(qIntent);
                    finish();
                } else if (!isHeld) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(JobListActivity.this);
                    builder.setTitle(R.string.del_acc_err_title);
                    builder.setMessage(R.string.manage_q_hold_error);
                    builder.setPositiveButton("OK", null);
                    builder.setCancelable(true);
                    dgManageQ = builder.create();
                    dgManageQ.show();
                } else if (!isPending) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(JobListActivity.this);
                    builder.setTitle(R.string.del_acc_err_title);
                    builder.setMessage(R.string.manage_q_upload_error);
                    builder.setPositiveButton("OK", null);
                    builder.setCancelable(true);
                    dgManageQ = builder.create();
                    dgManageQ.show();
                }

                break;

            default:
                //getActionBar().setTitle("Today's Jobs");
                tvAcTitle.setText("Today's Jobs");
                BundleKeys.title = "Today's Jobs";
                BundleKeys.which = 1;
                //menuItem = j_Menu.findItem(R.id.addJobMenuItem);
                //menuItem.setVisible(true);
                ivAddJob.setVisibility(View.VISIBLE);
                jobListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
            }
            Log.e(LOG_NAME, Integer.toString(BundleKeys.which) + " - " + BundleKeys.title);
            isSync = false;
            slidingMenu.toggle(true);
            /*
             * Log.e("isSetting", Boolean.toString(isSetting));
             * if(BundleKeys.which != 8 && BundleKeys.which != 9 &&
             * !isSetting) etSearch.setText("");
             */
        }

    });

    rlSearch = (RelativeLayout) findViewById(R.id.rlSearch);

    etSearch = (EditText) findViewById(R.id.etSearch);
    etSearch.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

            //launchSearchTask();

        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // TODO Auto-generated method stub

        }

        @Override
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            launchSearchTask();
        }
    });

    GetResourcesTask task = new GetResourcesTask();
    task.execute();

}

From source file:com.rfo.basic.Run.java

private void doAlertDialog(DialogArgs args) {
    Context context = getContext();
    Log.d(LOGTAG, "AlertDialog context " + context);

    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    String positive = args.mButton1;
    String neutral = args.mButton2;
    String negative = args.mButton3;
    String[] list = args.mList;/* w  w w.j  a  v a  2 s  .co  m*/
    AlertDialogClickListener listener = new AlertDialogClickListener();

    builder.setCancelable(true).setTitle(args.mTitle); // no title if null or empty
    if (positive != null) {
        builder.setPositiveButton(positive, listener);
    }
    if (neutral != null) {
        builder.setNeutralButton(neutral, listener);
    }
    if (negative != null) {
        builder.setNegativeButton(negative, listener);
    }

    if (list != null) {
        builder.setItems(list, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                mAlertItemID = which + 1; // convert to 1-based index
            }
        });
    } else {
        builder.setMessage(args.mMessage); // list and message are mutually exclusive
    }

    builder.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            Log.d(LOGTAG, "Alert Dialog onCancel");
            mAlertItemID = 0; // no button clicked or item selected
        }
    });

    final AlertDialog dialog = builder.create();
    dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
        public void onDismiss(DialogInterface dialog) {
            Log.d(LOGTAG, "Alert Dialog onDismiss");
            releaseLOCK(); // release the lock that executeINPUT is waiting for
        }
    });
    dialog.show();
}