Example usage for android.app AlertDialog setTitle

List of usage examples for android.app AlertDialog setTitle

Introduction

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

Prototype

@Override
    public void setTitle(CharSequence title) 

Source Link

Usage

From source file:net.fabiszewski.ulogger.MainActivity.java

/**
 * Called when the user clicks the track text view
 * @param view View// w  w  w  .  j  a  va  2 s .co m
 */
public void trackSummary(@SuppressWarnings("UnusedParameters") View view) {
    final TrackSummary summary = db.getTrackSummary();
    if (summary == null) {
        showToast(getString(R.string.no_positions));
        return;
    }

    @SuppressLint("InflateParams")
    View summaryView = getLayoutInflater().inflate(R.layout.summary, null, false);
    AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
    alertDialog.setTitle(getString(R.string.track_summary));
    alertDialog.setView(summaryView);
    alertDialog.setIcon(R.drawable.ic_equalizer_white_24dp);
    alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, getString(R.string.ok),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
    alertDialog.show();

    final TextView summaryDistance = (TextView) alertDialog.findViewById(R.id.summary_distance);
    final TextView summaryDuration = (TextView) alertDialog.findViewById(R.id.summary_duration);
    final TextView summaryPositions = (TextView) alertDialog.findViewById(R.id.summary_positions);
    double distance = (double) summary.getDistance() / 1000;
    String unitName = getString(R.string.unit_kilometer);
    if (pref_units.equals(getString(R.string.pref_units_imperial))) {
        distance *= KM_MILE;
        unitName = getString(R.string.unit_mile);
    }
    final NumberFormat nf = NumberFormat.getInstance();
    nf.setMaximumFractionDigits(2);
    final String distanceString = nf.format(distance);
    summaryDistance.setText(getString(R.string.summary_distance, distanceString, unitName));
    final long h = summary.getDuration() / 3600;
    final long m = summary.getDuration() % 3600 / 60;
    summaryDuration.setText(getString(R.string.summary_duration, h, m));
    int positionsCount = (int) summary.getPositionsCount();
    if (needsPluralFewHack(positionsCount)) {
        summaryPositions.setText(getResources().getString(R.string.summary_positions_few, positionsCount));
    } else {
        summaryPositions.setText(
                getResources().getQuantityString(R.plurals.summary_positions, positionsCount, positionsCount));
    }
}

From source file:com.haibison.android.anhuu.utils.ui.bookmark.BookmarkFragment.java

/**
 * Shows a dialog to let the user enter new name or change current name of a
 * bookmark./*from   w w  w . j  ava  2s . co m*/
 * 
 * @param context
 *            {@link Context}
 * @param providerId
 *            the provider ID.
 * @param id
 *            the bookmark ID.
 * @param uri
 *            the URI to the bookmark.
 * @param name
 *            the name. To enter new name, this is the suggested name you
 *            provide. To rename, this is the old name.
 */
public static void doEnterNewNameOrRenameBookmark(final Context context, final String providerId, final int id,
        final Uri uri, final String name) {
    final AlertDialog dialog = Dlg.newAlertDlg(context);

    View view = LayoutInflater.from(context).inflate(R.layout.anhuu_f5be488d_simple_text_input_view, null);
    final EditText textName = (EditText) view.findViewById(R.id.anhuu_f5be488d_text1);
    textName.setText(name);
    textName.selectAll();
    textName.setHint(R.string.anhuu_f5be488d_hint_new_name);
    textName.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                UI.showSoftKeyboard(textName, false);
                Button btn = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
                if (btn.isEnabled())
                    btn.performClick();
                return true;
            }
            return false;
        }// onEditorAction()
    });

    dialog.setView(view);
    dialog.setIcon(R.drawable.anhuu_f5be488d_bookmarks_dark);
    dialog.setTitle(id < 0 ? R.string.anhuu_f5be488d_title_new_bookmark : R.string.anhuu_f5be488d_title_rename);
    dialog.setButton(DialogInterface.BUTTON_POSITIVE, context.getString(android.R.string.ok),
            new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String newName = textName.getText().toString().trim();
                    if (android.text.TextUtils.isEmpty(newName)) {
                        Dlg.toast(context, R.string.anhuu_f5be488d_msg_bookmark_name_is_invalid,
                                Dlg.LENGTH_SHORT);
                        return;
                    }

                    UI.showSoftKeyboard(textName, false);

                    ContentValues values = new ContentValues();
                    values.put(BookmarkContract.COLUMN_NAME, newName);

                    if (id >= 0) {
                        values.put(BookmarkContract.COLUMN_MODIFICATION_TIME,
                                DbUtils.formatNumber(new Date().getTime()));
                        context.getContentResolver().update(
                                ContentUris.withAppendedId(BookmarkContract.genContentIdUriBase(context), id),
                                values, null, null);
                    } else {
                        /*
                         * Check if the URI exists or doesn't. If it exists,
                         * update it instead of inserting the new one.
                         */
                        Cursor cursor = context.getContentResolver().query(
                                BookmarkContract.genContentUri(context), null,
                                String.format("%s = %s AND %s LIKE %s", BookmarkContract.COLUMN_PROVIDER_ID,
                                        DatabaseUtils.sqlEscapeString(providerId), BookmarkContract.COLUMN_URI,
                                        DatabaseUtils.sqlEscapeString(uri.toString())),
                                null, null);
                        try {
                            if (cursor != null && cursor.moveToFirst()) {
                                values.put(BookmarkContract.COLUMN_MODIFICATION_TIME,
                                        DbUtils.formatNumber(new Date().getTime()));
                                context.getContentResolver().update(
                                        Uri.withAppendedPath(BookmarkContract.genContentIdUriBase(context),
                                                Uri.encode(cursor.getString(
                                                        cursor.getColumnIndex(BookmarkContract._ID)))),
                                        values, null, null);
                            } else {
                                values.put(BookmarkContract.COLUMN_PROVIDER_ID, providerId);
                                values.put(BookmarkContract.COLUMN_URI, uri.toString());

                                context.getContentResolver().insert(BookmarkContract.genContentUri(context),
                                        values);
                            }
                        } finally {
                            if (cursor != null)
                                cursor.close();
                        }
                    }

                    Dlg.toast(context, context.getString(R.string.anhuu_f5be488d_msg_done), Dlg.LENGTH_SHORT);
                }// onClick()
            });

    dialog.show();
    UI.showSoftKeyboard(textName, true);

    final Button buttonOk = dialog.getButton(DialogInterface.BUTTON_POSITIVE);
    buttonOk.setEnabled(id < 0);

    textName.addTextChangedListener(new TextWatcher() {

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

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

        @Override
        public void afterTextChanged(Editable s) {
            String newName = s.toString().trim();
            boolean enabled = !android.text.TextUtils.isEmpty(newName);
            buttonOk.setEnabled(enabled);

            /*
             * If renaming, only enable button OK if new name is not equal
             * to the old one.
             */
            if (enabled && id >= 0)
                buttonOk.setEnabled(!newName.equals(name));
        }
    });
}

From source file:fm.smart.r1.activity.ItemActivity.java

public void addToList(final String item_id) {
    final ProgressDialog myOtherProgressDialog = new ProgressDialog(this);
    myOtherProgressDialog.setTitle("Please Wait ...");
    myOtherProgressDialog.setMessage("Adding item to study list ...");
    myOtherProgressDialog.setIndeterminate(true);
    myOtherProgressDialog.setCancelable(true);

    final Thread add = new Thread() {
        public void run() {
            ItemActivity.add_item_result = addItemToList(Main.default_study_list_id, item_id,
                    ItemActivity.this);

            myOtherProgressDialog.dismiss();
            ItemActivity.this.runOnUiThread(new Thread() {
                public void run() {
                    final AlertDialog dialog = new AlertDialog.Builder(ItemActivity.this).create();
                    dialog.setTitle(ItemActivity.add_item_result.getTitle());
                    dialog.setMessage(ItemActivity.add_item_result.getMessage());
                    ItemActivity.add_item_result = null;
                    dialog.setButton("OK", new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                        }//from   ww  w .  ja  v a 2 s . co  m
                    });

                    dialog.show();
                }
            });

        }
    };
    myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            add.interrupt();
        }
    });
    OnCancelListener ocl = new OnCancelListener() {
        public void onCancel(DialogInterface arg0) {
            add.interrupt();
        }
    };
    myOtherProgressDialog.setOnCancelListener(ocl);
    closeMenu();
    myOtherProgressDialog.show();
    add.start();
}

From source file:net.homelinux.penecoptero.android.citybikes.donation.app.MainActivity.java

private void fillData(boolean all) {
    if (mNDBAdapter != null && mNDBAdapter.isConfigured()) {
        Bundle data = new Bundle();
        if (!all) {
            GeoPoint center = locator.getCurrentGeoPoint();

            if (center == null) {

                //Do something..
                int nid = settings.getInt("network_id", -1);
                //Log.i("CityBikes","Current network is id: "+Integer.toString(nid));
                if (nid != -1) {
                    try {
                        mNDBAdapter.load();
                        JSONObject network = mNDBAdapter.getNetworks(nid);
                        //Log.i("CityBikes",network.toString());
                        double lat = Integer.parseInt(network.getString("lat")) / 1E6;
                        double lng = Integer.parseInt(network.getString("lng")) / 1E6;
                        Location fallback = new Location("fallback");
                        fallback.setLatitude(lat);
                        fallback.setLongitude(lng);
                        locator.setFallbackLocation(fallback);
                        locator.unlockCenter();
                        center = locator.getCurrentGeoPoint();
                    } catch (Exception e) {
                        //Log.i("CityBikes","We re fucked, that network aint existin");
                        e.printStackTrace();
                    }/*from   w  w  w.j av a 2  s  .  com*/
                } else {
                    //Log.i("CityBikes","We re fucked, why re we here?");
                }
            }
            data.putInt(StationsDBAdapter.CENTER_LAT_KEY, center.getLatitudeE6());
            data.putInt(StationsDBAdapter.CENTER_LNG_KEY, center.getLongitudeE6());
            data.putInt(StationsDBAdapter.RADIUS_KEY, hOverlay.getRadius());
        }

        progressDialog = new ProgressDialog(this);
        progressDialog.setTitle("");
        progressDialog.setMessage(getString(R.string.loading));
        progressDialog.show();
        try {
            mDbHelper.sync(all, data);
        } catch (Exception e) {
            ////Log.i("openBicing", "Error Updating?");
            e.printStackTrace();
            progressDialog.dismiss();
        }
        ;
    } else {
        //Log.i("CityBikes","First time!!! :D");
        try {
            mNDBAdapter.update();
            AlertDialog alertDialog = new AlertDialog.Builder(this).create();
            alertDialog.setIcon(android.R.drawable.ic_dialog_map);
            alertDialog.setTitle(R.string.bike_network_alert_title);
            alertDialog.setMessage(getString(R.string.bike_network_alert_text));
            alertDialog.setButton(getString(R.string.automatic), new DialogInterface.OnClickListener() {

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

                }

            });
            alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.automatic),
                    new DialogInterface.OnClickListener() {

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

                            showAutoNetworkDialog(0);

                        }

                    });
            alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.manual),
                    new DialogInterface.OnClickListener() {

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

                    });
            alertDialog.show();
        } catch (Exception e) {
            e.printStackTrace();
            Toast toast = Toast.makeText(getApplicationContext(), getString(R.string.network_error),
                    Toast.LENGTH_LONG);
            toast.show();
        }
    }
}

From source file:net.homelinux.penecoptero.android.citybikes.app.MainActivity.java

private void fillData(boolean all) {
    if (mNDBAdapter != null && mNDBAdapter.isConfigured()) {
        Bundle data = new Bundle();
        if (!all) {
            GeoPoint center = locator.getCurrentGeoPoint();

            if (center == null) {

                //Do something..
                int nid = settings.getInt("network_id", -1);
                //Log.i("CityBikes","Current network is id: "+Integer.toString(nid));
                if (nid != -1) {
                    try {
                        mNDBAdapter.load();
                        JSONObject network = mNDBAdapter.getNetworks(nid);
                        //Log.i("CityBikes",network.toString());
                        double lat = Integer.parseInt(network.getString("lat")) / 1E6;
                        double lng = Integer.parseInt(network.getString("lng")) / 1E6;
                        Location fallback = new Location("fallback");
                        fallback.setLatitude(lat);
                        fallback.setLongitude(lng);
                        locator.setFallbackLocation(fallback);
                        locator.unlockCenter();
                        center = locator.getCurrentGeoPoint();
                    } catch (Exception e) {
                        //Log.i("CityBikes","We re fucked, that network aint existin");
                        e.printStackTrace();
                    }/*  w ww .  j a va  2  s  .c  om*/
                } else {
                    //Log.i("CityBikes","We re fucked, why re we here?");
                }
            }
            data.putInt(StationsDBAdapter.CENTER_LAT_KEY, center.getLatitudeE6());
            data.putInt(StationsDBAdapter.CENTER_LNG_KEY, center.getLongitudeE6());
            data.putInt(StationsDBAdapter.RADIUS_KEY, hOverlay.getRadius());
        }

        progressDialog = new ProgressDialog(this);
        progressDialog.setTitle("");
        progressDialog.setMessage(getString(R.string.loading));
        progressDialog.show();
        try {
            mDbHelper.sync(all, data);
        } catch (Exception e) {
            ////Log.i("openBicing", "Error Updating?");
            e.printStackTrace();
            progressDialog.dismiss();
        }
        ;
    } else {
        //Log.i("CityBikes","First time!!! :D");
        try {
            mNDBAdapter.update();
            AlertDialog alertDialog = new AlertDialog.Builder(this).create();
            alertDialog.setIcon(android.R.drawable.ic_dialog_map);
            alertDialog.setTitle(R.string.bike_network_alert_title);
            alertDialog.setMessage(getString(R.string.bike_network_alert_text));
            alertDialog.setButton(getString(R.string.automatic), new DialogInterface.OnClickListener() {

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

                }

            });
            alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, getString(R.string.automatic),
                    new DialogInterface.OnClickListener() {

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

                            showAutoNetworkDialog(0);

                        }

                    });
            alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, getString(R.string.manual),
                    new DialogInterface.OnClickListener() {

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

                    });
            alertDialog.show();
        } catch (Exception e) {
            e.printStackTrace();
            Toast toast = Toast.makeText(getApplicationContext(), getString(R.string.network_error),
                    Toast.LENGTH_LONG);
            toast.show();
        }
    }
    infoLayer.update();
}

From source file:bikebadger.RideFragment.java

public void onInit(int initStatus) {
    // assert  (false);
    //check for successful instantiation
    if (initStatus == TextToSpeech.SUCCESS) {
        //if(RideManager.mTTS.isLanguageAvailable(Locale.US)==TextToSpeech.LANG_AVAILABLE)
        //  RideManager.mTTS.setLanguage(Locale.US);
    } else if (initStatus == TextToSpeech.ERROR) {
        Toast.makeText(mRideManager.mAppContext, "Sorry! Text To Speech failed...", Toast.LENGTH_LONG).show();
        AlertDialog ad = new AlertDialog.Builder(getActivity()).create();
        ad.setCancelable(false);//  w ww .  j a va  2 s.  c  om
        ad.setTitle("Text To Speech Engine Not Found");
        ad.setMessage(
                "There was a problem finding the Text To Speech Engine. Make sure it's install properly under Language and Input Settings.");
        ad.setButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        ad.show();
    }
}

From source file:fm.smart.r1.ItemActivity.java

public void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // this should be called once image has been chosen by user
    // using requestCode to pass item id - haven't worked out any other way
    // to do it/*from   ww w.  j av a  2  s.  c o m*/
    // if (requestCode == SELECT_IMAGE)
    if (resultCode == Activity.RESULT_OK) {
        // TODO check if user is logged in
        if (LoginActivity.isNotLoggedIn(this)) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setClassName(this, LoginActivity.class.getName());
            intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
            // avoid navigation back to this?
            LoginActivity.return_to = ItemActivity.class.getName();
            LoginActivity.params = new HashMap<String, String>();
            LoginActivity.params.put("item_id", (String) item.getId());
            startActivity(intent);
            // TODO in this case forcing the user to rechoose the image
            // seems a little
            // rude - should probably auto-submit here ...
        } else {
            // Bundle extras = data.getExtras();
            // String sentence_id = (String) extras.get("sentence_id");
            final ProgressDialog myOtherProgressDialog = new ProgressDialog(this);
            myOtherProgressDialog.setTitle("Please Wait ...");
            myOtherProgressDialog.setMessage("Uploading image ...");
            myOtherProgressDialog.setIndeterminate(true);
            myOtherProgressDialog.setCancelable(true);

            final Thread add_image = new Thread() {
                public void run() {
                    // TODO needs to check for interruptibility

                    String sentence_id = Integer.toString(requestCode);
                    Uri selectedImage = data.getData();
                    // Bitmap bitmap = Media.getBitmap(getContentResolver(),
                    // selectedImage);
                    // ByteArrayOutputStream bytes = new
                    // ByteArrayOutputStream();
                    // bitmap.compress(Bitmap.CompressFormat.JPEG, 40,
                    // bytes);
                    // ByteArrayInputStream fileInputStream = new
                    // ByteArrayInputStream(
                    // bytes.toByteArray());

                    // TODO Might have to save to file system first to get
                    // this
                    // to work,
                    // argh!
                    // could think of it as saving to cache ...

                    // add image to sentence
                    FileInputStream is = null;
                    FileOutputStream os = null;
                    File file = null;
                    ContentResolver resolver = getContentResolver();
                    try {
                        Bitmap bitmap = Media.getBitmap(getContentResolver(), selectedImage);
                        ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                        bitmap.compress(Bitmap.CompressFormat.JPEG, 40, bytes);
                        // ByteArrayInputStream bais = new
                        // ByteArrayInputStream(bytes.toByteArray());

                        // FileDescriptor fd =
                        // resolver.openFileDescriptor(selectedImage,
                        // "r").getFileDescriptor();
                        // is = new FileInputStream(fd);

                        String filename = "test.jpg";
                        File dir = ItemActivity.this.getDir("images", MODE_WORLD_READABLE);
                        file = new File(dir, filename);
                        os = new FileOutputStream(file);

                        // while (bais.available() > 0) {
                        // / os.write(bais.read());
                        // }
                        os.write(bytes.toByteArray());

                        os.close();

                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    } finally {
                        if (os != null) {
                            try {
                                os.close();
                            } catch (IOException e) {
                            }
                        }
                        if (is != null) {
                            try {
                                is.close();
                            } catch (IOException e) {
                            }
                        }
                    }

                    // File file = new
                    // File(Uri.decode(selectedImage.toString()));

                    // ensure item is in users default list

                    ItemActivity.add_item_result = new AddItemResult(Main.lookup.addItemToGoal(Main.transport,
                            Main.default_study_goal_id, item.getId(), null));

                    Result result = ItemActivity.add_item_result;

                    if (ItemActivity.add_item_result.success()
                            || ItemActivity.add_item_result.alreadyInList()) {

                        // ensure sentence is in users default goal

                        ItemActivity.add_sentence_goal_result = new AddSentenceResult(
                                Main.lookup.addSentenceToGoal(Main.transport, Main.default_study_goal_id,
                                        item.getId(), sentence_id, null));

                        result = ItemActivity.add_sentence_goal_result;
                        if (ItemActivity.add_sentence_goal_result.success()) {

                            String media_entity = "http://test.com/test.jpg";
                            String author = "tansaku";
                            String author_url = "http://smart.fm/users/tansaku";
                            Log.d("DEBUG-IMAGE-URI", selectedImage.toString());
                            ItemActivity.add_image_result = addImage(file, media_entity, author, author_url,
                                    "1", sentence_id, (String) item.getId(), Main.default_study_goal_id);
                            result = ItemActivity.add_image_result;
                        }
                    }
                    final Result display = result;
                    myOtherProgressDialog.dismiss();
                    ItemActivity.this.runOnUiThread(new Thread() {
                        public void run() {
                            final AlertDialog dialog = new AlertDialog.Builder(ItemActivity.this).create();
                            dialog.setTitle(display.getTitle());
                            dialog.setMessage(display.getMessage());
                            dialog.setButton("OK", new DialogInterface.OnClickListener() {
                                public void onClick(DialogInterface dialog, int which) {
                                    if (ItemActivity.add_image_result != null
                                            && ItemActivity.add_image_result.success()) {
                                        ItemListActivity.loadItem(ItemActivity.this, item.getId().toString());
                                    }
                                }
                            });

                            dialog.show();
                        }
                    });

                }

            };

            myOtherProgressDialog.setButton("Cancel", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    add_image.interrupt();
                }
            });
            OnCancelListener ocl = new OnCancelListener() {
                public void onCancel(DialogInterface arg0) {
                    add_image.interrupt();
                }
            };
            myOtherProgressDialog.setOnCancelListener(ocl);
            closeMenu();
            myOtherProgressDialog.show();
            add_image.start();

        }
    }
}

From source file:hr.foicore.varazdinlandmarksdemo.POIMapActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {

    int id = item.getItemId();
    if (id == R.id.action_view_as_grid) {
        Intent i = new Intent(POIMapActivity.this, POIGridActivity.class);

        i.putExtra("playOn", mActionPlay);

        i.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        // finish();
        overridePendingTransition(0, 0);

        startActivityForResult(i, 1);//from   w  w  w.j  av  a  2  s  .  co m
        overridePendingTransition(0, 0);

    } else if (id == R.id.action_directions) {

        if (mActionDirections == 1) { // cancel directions action
            item.setIcon(R.drawable.ic_action_directions);
            mActionDirections = 0;
            tvMapDirectionsInfo.setVisibility(View.INVISIBLE);
            if (mRoute != null) {
                mRoute.remove();
            }
        } else if (mActionDirections == 0) { // set directions action on

            item.setIcon(R.drawable.ic_action_directions_pressed);
            mActionDirections = 1;

            gmm.handleMapWarningMessages(POIMapActivity.this, tvMapMessage);
            if (gmm.myLocationEnabled && gmm.internetEnabled) {
                Toast.makeText(POIMapActivity.this,
                        POIMapActivity.this.getResources().getString(R.string.tap_route_destination),
                        Toast.LENGTH_SHORT).show();

            } else {
                tvMapMessage.setBackgroundColor(
                        POIMapActivity.this.getResources().getColor(R.color.red_transparent));

                item.setIcon(R.drawable.ic_action_directions);
                mActionDirections = 0;
                tvMapDirectionsInfo.setVisibility(View.INVISIBLE);

            }
        } else { // mActionDirections == 3
            item.setIcon(R.drawable.ic_action_directions);
            mActionDirections = 0;
            tvMapDirectionsInfo.setVisibility(View.INVISIBLE);
            if (mRoute != null) {
                mRoute.remove();
            }
        }

    } else if (id == R.id.action_play) {

        if (mActionPlay) { // cancel play mode
            gmm.addAllMarkers(POIMapActivity.this);
            item.setIcon(R.drawable.ic_action_play);
            mActionPlay = false;

            miDirections.setIcon(R.drawable.ic_action_directions);
            mActionDirections = 0;
            tvMapDirectionsInfo.setVisibility(View.INVISIBLE);
            if (mRoute != null) {
                mRoute.remove();
            }
        } else {
            gmm.addPlayMarkers(POIMapActivity.this);
            item.setIcon(R.drawable.ic_action_pause_red);
            if (gmm.activePOIMarker != null) {
                drawUserDestRoute(gmm.activePOIMarker.getPosition());
            }
            mActionPlay = true;

        }

    } else if (id == R.id.action_google_map_type) {
        // get google map type names
        String[] googleMapTypeNames = getResources().getStringArray(R.array.google_map_type_names);

        // creating and Building the Dialog
        AlertDialog.Builder builderMapType = new AlertDialog.Builder(this);
        builderMapType.setTitle(getResources().getString(R.string.action_google_map_type));
        builderMapType.setSingleChoiceItems(googleMapTypeNames, selectedMapType,
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int item) {

                        if (item != selectedMapType) {
                            switchGoogleMapType(item);
                            // save selected type in settings
                            SharedPreferences preferences = PreferenceManager
                                    .getDefaultSharedPreferences(POIMapActivity.this);
                            SharedPreferences.Editor editor = preferences.edit();
                            editor.putString("googleMapType", String.valueOf(item));
                            editor.commit();
                        }
                        mapTypeDialog.dismiss();
                    }
                });
        mapTypeDialog = builderMapType.create();
        mapTypeDialog.show();

    } else if (id == R.id.action_legal_notices) {

        String licenseInfo = GooglePlayServicesUtil.getOpenSourceSoftwareLicenseInfo(getApplicationContext());
        AlertDialog.Builder licenseDialog = new AlertDialog.Builder(POIMapActivity.this);
        licenseDialog.setTitle(getString(R.string.action_legal_notices));
        licenseDialog.setMessage(licenseInfo);
        licenseDialog.show();

    } else if (id == R.id.action_scan_qr_code) {

        handleQRcodeScanRequest();

    } else if (id == R.id.action_about) {
        String about = getString(R.string.about_application);
        AlertDialog alertDialog;
        alertDialog = new AlertDialog.Builder(POIMapActivity.this).create();

        alertDialog.setTitle(getString(R.string.action_about));
        alertDialog.setMessage(Html.fromHtml(about));

        alertDialog.setButton(Dialog.BUTTON_NEGATIVE, getString(R.string.ok),
                new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
        alertDialog.show();
    }
    return super.onOptionsItemSelected(item);
}

From source file:org.trosnoth.serveradmin.UpgradeActivity.java

private void showUpgradeDialog(int position) {
    AlertDialog.Builder builder;/* w  w w.j a v  a2  s.  co  m*/
    AlertDialog alertDialog;

    Context mContext = UpgradeActivity.this;
    LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.upgrade_dialog, (ViewGroup) findViewById(R.id.layout_root));

    final Upgrade upgrade = adapter.getItem(position);

    final EditText stars = (EditText) layout.findViewById(R.id.editStars);
    stars.setText(Integer.toString(upgrade.starCost));

    final EditText time = (EditText) layout.findViewById(R.id.editTime);
    time.setText(Double.toString(upgrade.timeLimit));

    builder = new AlertDialog.Builder(mContext);
    builder.setView(layout);
    alertDialog = builder.create();
    alertDialog.setTitle(upgrade.name);
    alertDialog.setButton(-1, getApplicationContext().getString(R.string.save),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    if (stars.getText().length() > 0) {
                        telnet.send("getGame().setUpgradeCost('" + upgrade.id + "', " + stars.getText() + ")");
                    }
                    if (time.getText().length() > 0) {
                        telnet.send("getGame().setUpgradeTime('" + upgrade.id + "', " + time.getText() + ")");
                    }
                    update();
                }
            });
    alertDialog.setButton(-2, getApplicationContext().getString(R.string.cancel),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
    alertDialog.show();
}

From source file:bikebadger.RideFragment.java

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

    Log.d(Constants.APP.TAG, "RideFragment.onCreate()");
    //setRetainInstance(true);

    mRideManager = RideManager.get(getActivity());
    Log.d(Constants.APP.TAG, "mRideManager set = RideManager.get(" + getActivity() + ")");

    setHasOptionsMenu(true);/*from   w  w w.  j a va 2  s .com*/

    // check for a Ride ID as an argument, and find the run
    Bundle args = getArguments();
    if (args != null) {
        long runId = args.getLong(ARG_RUN_ID, -1);
        Log.d(Constants.APP.TAG, "RideFragment.onCreate() runId=" + runId);
        if (runId != -1) {
            LoaderManager lm = getLoaderManager();
            lm.initLoader(LOAD_RUN, args, new RunLoaderCallbacks());
            lm.initLoader(LOAD_LOCATION, args, new LocationLoaderCallbacks());
        }
    }

    // Initialize the TextToSpeech Engine...
    // TODO this engine may not exist. Provide the ability to run without it.
    Intent checkTTSIntent = new Intent();
    checkTTSIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);

    if (checkTTSIntent.resolveActivity(mRideManager.mAppContext.getPackageManager()) != null) {
        startActivityForResult(checkTTSIntent, MY_DATA_CHECK_CODE_REQUEST);
    } else {
        Log.d(Constants.APP.TAG, "Could not find TTS Intent");
        MyToast.Show(getActivity(), "Could not find Text To Speech Service", Color.RED);
        AlertDialog ad1 = new AlertDialog.Builder(getActivity()).create();
        ad1.setCancelable(false);
        ad1.setTitle("Text To Speech Engine Not Found");
        ad1.setMessage(
                "There was a problem finding the Text To Speech Engine. Make sure it's install properly under Language and Input Settings.");
        ad1.setButton("Ok", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        ad1.show();

    }

    if (mRideManager.mLoadLastGPXFile) {
        Log.d(Constants.APP.TAG, "mLoadLastGPXFile=" + mRideManager.mLoadLastGPXFile);
        Log.d(Constants.APP.TAG, "mCurrentGPXPath=" + mRideManager.mCurrentGPXPath);

        OpenGPXFileOnNewThreadWithDialog(mRideManager.mCurrentGPXPath);
    }

    if (!mRideManager.IsGPSEnabled()) {
        ShowAlertMessageNoGps();
    }

    // keep the screen on so it doesn't time out and turn dark
    getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

}