Example usage for android.app AlertDialog setButton

List of usage examples for android.app AlertDialog setButton

Introduction

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

Prototype

@Deprecated
public void setButton(CharSequence text, final OnClickListener listener) 

Source Link

Document

Set a listener to be invoked when button 1 of the dialog is pressed.

Usage

From source file:cm.aptoide.pt.RemoteInTab.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case UPDATE_REPO:
        final AlertDialog upd_alrt = new AlertDialog.Builder(this).create();
        if (!db.areServers()) {
            upd_alrt.setIcon(android.R.drawable.ic_dialog_alert);
            upd_alrt.setTitle("Empty");
            upd_alrt.setMessage(/*w w w  .ja  v  a 2  s.  c o m*/
                    "There are no enabled repositories in your list.\nPlease add repository or enable the ones you have!");
            upd_alrt.setButton("Ok", new OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {

                }
            });
        } else {
            upd_alrt.setIcon(android.R.drawable.ic_dialog_alert);
            upd_alrt.setTitle("Update repositories");
            upd_alrt.setMessage(
                    "Do you wish to update repositories?\nThis can take a while (WiFi is advised)...");
            upd_alrt.setButton("Yes", new OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    updateRepos();
                }
            });
            upd_alrt.setButton2("No", new OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    upd_alrt.dismiss();
                }
            });
        }
        upd_alrt.show();
        return true;
    case MANAGE_REPO:
        Intent i = new Intent(this, ManageRepo.class);
        startActivityForResult(i, NEWREPO_FLAG);
        return true;
    case SEARCH_MENU:
        onSearchRequested();
        return true;
    case ABOUT:
        LayoutInflater li = LayoutInflater.from(this);
        View view = li.inflate(R.layout.about, null);
        Builder p = new AlertDialog.Builder(this).setView(view);
        final AlertDialog alrt = p.create();
        alrt.setIcon(R.drawable.icon);
        alrt.setTitle("APTOIDE");
        alrt.setButton("ChangeLog", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                Uri uri = Uri.parse("http://aptoide.com/changelog.html");
                startActivity(new Intent(Intent.ACTION_VIEW, uri));
            }
        });
        alrt.show();
        return true;
    case SETTINGS:
        Intent s = new Intent(RemoteInTab.this, Settings.class);
        s.putExtra("order", order_lst);
        startActivityForResult(s, SETTINGS_FLAG);
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.google.appinventor.components.runtime.FusiontablesControl.java

private void showNoticeAndDie(String message, String title, String buttonText) {
    AlertDialog alertDialog = new AlertDialog.Builder(activity).create();
    alertDialog.setTitle(title);/*from w  ww . jav  a 2s  . c o m*/
    // prevents the user from escaping the dialog by hitting the Back button
    alertDialog.setCancelable(false);
    alertDialog.setMessage(message);
    alertDialog.setButton(buttonText, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            activity.finish();
        }
    });
    alertDialog.show();
}

From source file:com.tweetlanes.android.core.view.ComposeBaseFragment.java

void showSimpleAlert(int stringID) {
    AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
    alertDialog.setMessage(getString(stringID));
    alertDialog.setButton(getString(R.string.ok), new DialogInterface.OnClickListener() {

        public void onClick(DialogInterface dialog, int which) {
        }/*from   ww  w .  ja  va2 s  .c o  m*/
    });
    alertDialog.show();
}

From source file:com.swetha.easypark.GetIndividualParkingSpotDetails.java

public void updateListView(ArrayList<LinkedHashMap<String, String>> parkingSpotMapList, int success) {
    if (success == 1) {
        mSelectedItem = 0;// w  w w .j av a2  s . c om
        for (int i = 0; i < parkingSpotMapList.size(); i++) {
            Log.i("GetIndividualParkingSpotDetails", "Inside For loop");
            RadioButtonTracker l_ts;
            LinkedHashMap<String, String> map = parkingSpotMapList.get(i);
            Log.i("GetIndividualParkingSpotDetails", "Value in map is " + map.get("vacantspotdisplay"));
            Log.i("GetIndividualParkingSpotDetails", "parking spoid is is " + map.get("parkingspotid"));
            if (i == mSelectedItem) {
                Log.i("GetIndividualParkingSpotDetails", "Before calling RadioButtonTracker constructor - if");
                l_ts = new RadioButtonTracker(map, true);
                Log.i("GetIndividualParkingSpotDetails", "After calling RadioButtonTracker constructor-if");
            } else {
                l_ts = new RadioButtonTracker(map, false);
            }
            mSelectionList.add(l_ts);
        }
        Log.i("GetIndividualParkingSpotDetails", "After -if-else condition");
        adapter = new RadioButtonTrackerListAdapter(mContext);
        adapter.setListItems(mSelectionList);
        Log.i("GetIndividualParkingSpotDetails", "After setListItems");
        this.setListAdapter(adapter);
        Log.i("GetIndividualParkingSpotDetails", "After setListAdapter");
    } else {
        AlertDialog alertDialog = new AlertDialog.Builder(GetIndividualParkingSpotDetails.this).create();

        // Setting Dialog Title
        alertDialog.setTitle("Sorry!");

        // Setting Dialog Message
        alertDialog.setMessage("No Parking spots found");

        // Setting Icon to Dialog
        // alertDialog.setIcon(R.drawable.tick);

        // Setting OK Button
        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // Write your code here to execute after dialog closed
                Intent intent = new Intent(GetIndividualParkingSpotDetails.this, GetParkingLots.class);
                startActivity(intent);
            }
        });

        // Showing Alert Message
        alertDialog.show();

    }
}

From source file:com.teamproject.shoutbox.MainActivity.java

public void showAlertDialog() {
    AlertDialog alertDialog = new AlertDialog.Builder(this).create();

    // Setting Dialog Title
    alertDialog.setTitle("ShoutBox");
    // String s= (Html.fromHtml("<a href=\"http://www.google.com\">Check this link out</a>")).toString();
    // Setting Dialog Message
    alertDialog.setMessage(//  w  w  w  .j  a v  a2 s  .  c o m
            "No abusive/offensive words please. You'll unnecessarily increase your chances of getting banned!");
    // Setting Icon to Dialog
    alertDialog.setIcon(R.drawable.icon);

    // Setting OK Button
    alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // Write your code here to execute after dialog closed
            //Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_SHORT).show();
        }
    });

    // Showing Alert Message
    alertDialog.show();
}

From source file:fm.smart.r1.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 goal ...");
    myOtherProgressDialog.setIndeterminate(true);
    myOtherProgressDialog.setCancelable(true);

    final Thread add = new Thread() {
        public void run() {
            ItemActivity.add_item_result = new AddItemResult(
                    Main.lookup.addItemToGoal(Main.transport, Main.default_study_goal_id, item_id, null));

            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 w w  w . j a  v a 2  s. c  o  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:com.swetha.easypark.GetParkingLots.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    if (!isGooglePlayServicesAvailable()) {
        finish();/*from  w  w w .jav  a 2s .  c o  m*/
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.getparkinglots);

    SupportMapFragment supportMapFragment = (SupportMapFragment) getSupportFragmentManager()
            .findFragmentById(R.id.map);
    googleMap = supportMapFragment.getMap();

    googleMap.setMyLocationEnabled(true);
    LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    gps_enabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    network_enabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

    if (gps_enabled) {
        Criteria criteria = new Criteria();

        provider = locationManager.getBestProvider(criteria, true);

        if (provider != null && !provider.equals("")) {

            locationManager.requestLocationUpdates(provider, 500, 1, GetParkingLots.this);
            // Get the location from the given provider 
            location = locationManager.getLastKnownLocation(provider);

        }
    }
    Log.i("GetParkingLots", "Value of network_enabled and location" + network_enabled + location);
    if (location == null && network_enabled) {

        location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
        locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 500, 1, GetParkingLots.this);

    }

    if (location == null && !network_enabled && !gps_enabled) {
        Toast.makeText(getBaseContext(), "Enable your location services", Toast.LENGTH_LONG).show();
    }
    if (location != null)
        onLocationChanged(location);
    else {

        Toast.makeText(getBaseContext(), "Location can't be retrieved", Toast.LENGTH_SHORT).show();
    }

    tv_fromTime = (TextView) findViewById(R.id.tv_fromTime);
    fromTimeString = Constants.dtf.format(new Date()).toString();
    tv_fromTime.setText(fromTimeString);
    long lval = DateTimeHelpers.convertToLongFromTime(Constants.dtf.format(new Date()).toString());
    Log.i("GetParkingLots",
            "The value of current time:" + Constants.dtf.format(new Date()).toString() + "in long is" + lval);
    Log.i("GetParkingLots",
            "The value of current time:" + lval + "in long is" + DateTimeHelpers.convertToTimeFromLong(lval));
    tv_toTime = (TextView) findViewById(R.id.tv_ToTime);
    // Parsing the date
    toTimeString = Constants.dtf.format(new Date()).toString();
    tv_toTime.setText(toTimeString);

    btnFromTime = (Button) findViewById(R.id.fromButton);
    btnFromTime.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            // Create the dialog
            final Dialog mDateTimeDialog = new Dialog(GetParkingLots.this);
            // Inflate the root layout
            final RelativeLayout mDateTimeDialogView = (RelativeLayout) getLayoutInflater()
                    .inflate(R.layout.date_time_dialog, null);
            // Grab widget instance
            mDateTimePicker = (DateTimePicker) mDateTimeDialogView.findViewById(R.id.DateTimePicker);
            mDateTimePicker.setDateChangedListener(GetParkingLots.this);

            // Update demo TextViews when the "OK" button is clicked 
            ((Button) mDateTimeDialogView.findViewById(R.id.SetDateTime))
                    .setOnClickListener(new OnClickListener() {
                        Calendar cal;

                        @SuppressWarnings("deprecation")
                        public void onClick(View v) {
                            mDateTimePicker.clearFocus();
                            try {
                                cal = new GregorianCalendar(mDateTimePicker.getYear(),
                                        Integer.parseInt(mDateTimePicker.getMonth()), mDateTimePicker.getDay(),
                                        mDateTimePicker.getHour(), mDateTimePicker.getMinute());
                                fromTimeString = DateTimeHelpers.dtf.format(cal.getTime());
                                tv_fromTime.setText(fromTimeString);
                            } catch (Exception e) {
                                final AlertDialog alertDialog = new AlertDialog.Builder(GetParkingLots.this)
                                        .create();

                                alertDialog.setMessage("Enter a valid date");

                                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {

                                        alertDialog.dismiss();
                                    }
                                });

                                alertDialog.show();
                            }

                            mDateTimeDialog.dismiss();
                        }
                    });

            // Cancel the dialog when the "Cancel" button is clicked
            ((Button) mDateTimeDialogView.findViewById(R.id.CancelDialog))
                    .setOnClickListener(new OnClickListener() {

                        public void onClick(View v) {
                            // TODO Auto-generated method stub
                            mDateTimeDialog.cancel();
                        }
                    });

            // Reset Date and Time pickers when the "Reset" button is clicked

            ((Button) mDateTimeDialogView.findViewById(R.id.ResetDateTime))
                    .setOnClickListener(new OnClickListener() {

                        public void onClick(View v) {
                            // TODO Auto-generated method stub
                            mDateTimePicker.reset();
                        }
                    });

            // Setup TimePicker
            // No title on the dialog window
            mDateTimeDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            // Set the dialog content view
            mDateTimeDialog.setContentView(mDateTimeDialogView);
            // Display the dialog
            mDateTimeDialog.show();

        }
    });

    btnToTime = (Button) findViewById(R.id.toButton);
    btnToTime.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            // Create the dialog
            final Dialog mDateTimeDialog = new Dialog(GetParkingLots.this);
            // Inflate the root layout
            final RelativeLayout mDateTimeDialogView = (RelativeLayout) getLayoutInflater()
                    .inflate(R.layout.date_time_dialog, null);
            // Grab widget instance
            final DateTimePicker mDateTimePicker = (DateTimePicker) mDateTimeDialogView
                    .findViewById(R.id.DateTimePicker);
            mDateTimePicker.setDateChangedListener(GetParkingLots.this);

            // Update demo TextViews when the "OK" button is clicked 
            ((Button) mDateTimeDialogView.findViewById(R.id.SetDateTime))
                    .setOnClickListener(new OnClickListener() {
                        Calendar cal;

                        @SuppressWarnings("deprecation")
                        public void onClick(View v) {
                            mDateTimePicker.clearFocus();

                            Log.i("toButton", "Value of ToString before cal" + toTimeString);
                            try {
                                cal = new GregorianCalendar(mDateTimePicker.getYear(),
                                        Integer.parseInt(mDateTimePicker.getMonth()), mDateTimePicker.getDay(),
                                        mDateTimePicker.getHour(), mDateTimePicker.getMinute());
                                toTimeString = DateTimeHelpers.dtf.format(cal.getTime());
                                Log.i("toButton", "Value of ToString before cal" + toTimeString);

                                tv_toTime.setText(toTimeString);

                            } catch (Exception e) // fixing the bug where the user doesnt enter anything in the textbox
                            {
                                final AlertDialog alertDialog = new AlertDialog.Builder(GetParkingLots.this)
                                        .create();

                                alertDialog.setMessage("Enter a valid date");
                                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int which) {
                                        alertDialog.dismiss();
                                    }
                                });

                                alertDialog.show();
                            }
                            //dateTimeTo = new DateTime(mDateTimePicker.getYear(), Integer.parseInt(mDateTimePicker.getMonth()) ,  mDateTimePicker.getDay(),  mDateTimePicker.getHour(),  mDateTimePicker.getMinute()); ;

                            mDateTimeDialog.dismiss();
                        }
                    });

            ((Button) mDateTimeDialogView.findViewById(R.id.CancelDialog))
                    .setOnClickListener(new OnClickListener() {

                        public void onClick(View v) {
                            // TODO Auto-generated method stub
                            mDateTimeDialog.cancel();
                        }
                    });

            // Reset Date and Time pickers when the "Reset" button is clicked

            ((Button) mDateTimeDialogView.findViewById(R.id.ResetDateTime))
                    .setOnClickListener(new OnClickListener() {

                        public void onClick(View v) {
                            // TODO Auto-generated method stub
                            mDateTimePicker.reset();
                        }
                    });

            // Setup TimePicker
            // No title on the dialog window
            mDateTimeDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            // Set the dialog content view
            mDateTimeDialog.setContentView(mDateTimeDialogView);
            // Display the dialog
            mDateTimeDialog.show();

        }
    });

    btnGetParkingLots = (Button) findViewById(R.id.getNearByParkingLotsButton);
    btnGetParkingLots.setOnClickListener(new View.OnClickListener() {

        @SuppressWarnings("deprecation")
        public void onClick(View v) {
            et_search = (EditText) findViewById(R.id.edittextsearch);
            rg = (RadioGroup) findViewById(R.id.rg);
            checkedRbId = rg.getCheckedRadioButtonId();
            Log.i("LOG_TAG: GetParkingLots", "checked radiobutton id is" + checkedRbId);

            if (checkedRbId == R.id.rbradius) {
                isRadiusIndicator = true;
                radius = et_search.getText().toString();
            } else {
                isRadiusIndicator = false;
                zipcode = et_search.getText().toString();
            }

            final Intent intent = new Intent(GetParkingLots.this, DisplayVacantParkingLots.class);
            Log.i(TAG, "Inside getNearByParkingLots");
            Log.i(TAG, "Value of fromString" + fromTimeString);
            long lFromVal = DateTimeHelpers.convertToLongFromTime(fromTimeString);
            Log.i(TAG, "Value of ToString" + toTimeString);
            long lToVal = DateTimeHelpers.convertToLongFromTime(toTimeString);
            if ((lToVal - lFromVal) < Constants.thrityMinInMilliSeconds) {
                final AlertDialog alertDialog = new AlertDialog.Builder(GetParkingLots.this).create();

                alertDialog.setMessage("You have to park the car for at least 30 min");

                alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {

                        alertDialog.dismiss();
                    }
                });

                alertDialog.show();

            } else {
                intent.putExtra(LATITUDE, latitude);
                intent.putExtra(LONGITUDE, longitude);
                intent.putExtra(FROMTIME, lFromVal);
                intent.putExtra(TOTIME, lToVal);
                intent.putExtra(RadiusOrZIPCODE, isRadiusIndicator);
                if (isRadiusIndicator)
                    try {

                        intent.putExtra(RADIUS, Double.parseDouble(radius));
                        startActivity(intent);
                    } catch (Exception e) {
                        final AlertDialog alertDialog = new AlertDialog.Builder(GetParkingLots.this).create();

                        alertDialog.setMessage("Enter valid radius");

                        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {

                                alertDialog.dismiss();

                            }
                        });

                        alertDialog.show();
                    }
                else {
                    try {

                        intent.putExtra(ZIPCODE, Long.parseLong(zipcode));
                        startActivity(intent);
                    } catch (Exception e) {
                        final AlertDialog alertDialog = new AlertDialog.Builder(GetParkingLots.this).create();

                        alertDialog.setMessage("Enter a valid Zip code");

                        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int which) {
                                alertDialog.dismiss();

                            }
                        });

                        alertDialog.show();
                    }
                }

            }

        }
    });

}

From source file:com.swetha.easypark.GetIndividualParkingSpotDetails.java

public void displayalertdialog(double latitude, double longitude, String address, int success) {
    final double lat = latitude;
    final double lng = longitude;
    if (success == 1) {
        final AlertDialog alertDialog = new AlertDialog.Builder(GetIndividualParkingSpotDetails.this).create();

        // Setting Dialog Title
        alertDialog.setTitle("Congratulations!");

        // Setting Dialog Message
        alertDialog.setMessage("Your parking spot has been blocked");

        // Setting Icon to Dialog
        // alertDialog.setIcon(R.drawable.tick);

        // Setting OK Button
        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

                alertDialog.dismiss();/*from  w  ww. j  a  v  a2 s  . co  m*/
                AlertDialog alertDialog1 = new AlertDialog.Builder(GetIndividualParkingSpotDetails.this)
                        .create();

                // Setting Dialog Title
                alertDialog1.setTitle("Do you want to get directions?");
                alertDialog1.setButton2("Yes", new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Log.e("GetIndividualParkingSpots", "Inside Yes");
                        Intent yesintent = new Intent(GetIndividualParkingSpotDetails.this,
                                GoogleDirectionsActivity.class);
                        yesintent.putExtra(GetParkingLots.LATITUDE, lat);
                        yesintent.putExtra(GetParkingLots.LONGITUDE, lng);

                        startActivity(yesintent);
                        Log.e("GetIndividualParkingSpots", "After Calling Intent");
                    }
                });

                alertDialog1.setButton3("No", new DialogInterface.OnClickListener() {

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

                        // Write your code here to execute after dialog closed
                        Intent nointent = new Intent(GetIndividualParkingSpotDetails.this,
                                GetParkingLots.class);
                        startActivity(nointent);

                    }
                });
                alertDialog1.show();

            }
        });

        // Showing Alert Message
        alertDialog.show();
        if (chk_default.isChecked()) {
            Log.i("GetIndividualParkingSpotDetails", "Inside Checkbox if ");
            Log.i("GetIndividualParkingSpotDetails", " Spot has been blocked till long " + toTime);
            Log.i("GetIndividualParkingSpotDetails",
                    " Spot has been blocked till  DateTime" + DateTimeHelpers.convertToTimeFromLong(toTime));

            Log.i("GetIndividualParkingSpotDetails", "Inside if checkbox address" + address);
            scheduleNotification(getNotification(
                    "You parked the car in" + address + "Your parking spot id is " + theParkingSpotName));

        }
    } else {
        AlertDialog alertDialog = new AlertDialog.Builder(GetIndividualParkingSpotDetails.this).create();

        // Setting Dialog Title
        alertDialog.setTitle("Sorry!");

        // Setting Dialog Message
        alertDialog.setMessage("There was a problem processing your request");

        // Setting Icon to Dialog
        // alertDialog.setIcon(R.drawable.tick);

        // Setting OK Button
        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                // Write your code here to execute after dialog closed
                Intent intent = new Intent(GetIndividualParkingSpotDetails.this, GetParkingLots.class);
                startActivity(intent);
            }
        });

        // Showing Alert Message
        alertDialog.show();
    }

}

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  a  v a  2s . 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();
        }
    }
}

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  .  ja  va  2  s .c  o  m*/
                } 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();
}