Example usage for android.app ProgressDialog show

List of usage examples for android.app ProgressDialog show

Introduction

In this page you can find the example usage for android.app ProgressDialog show.

Prototype

public static ProgressDialog show(Context context, CharSequence title, CharSequence message,
        boolean indeterminate) 

Source Link

Document

Creates and shows a ProgressDialog.

Usage

From source file:com.hypers.frame.http.core.AsyncHttpResponseHandler.java

/**
 * Fired when the request is started, override to handle in your own code
 *///  ww w . j ava2  s. co  m
public void onStart() {
    if (isShowProgress) {
        progressDialog = ProgressDialog.show(context, "", "?...", true);
        progressDialog.setCancelable(true);
    }
}

From source file:com.progym.custom.fragments.FoodProgressYearlyLineFragment.java

public void setYearProgressData(final Date date, final boolean isLeftIn) {

    final ProgressDialog ringProgressDialog = ProgressDialog.show(getActivity(),
            getResources().getString(R.string.please_wait), getResources().getString(R.string.populating_data),
            true);/*from  ww  w  . ja  va  2s.c  om*/
    ringProgressDialog.setCancelable(true);
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                int yMaxAxisValue = 0;

                getActivity().runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            rlRootGraphLayout.removeView(viewChart);
                        } catch (Exception edsx) {
                            edsx.printStackTrace();
                        }

                    }
                });

                DATE = date;
                // Get amount of days in a month to find out average
                int daysInMonth = Utils.getDaysInMonth(date.getMonth(),
                        Integer.valueOf(Utils.formatDate(date, DataBaseUtils.DATE_PATTERN_YYYY)));
                // set January as first month
                date.setMonth(0);
                date.setDate(1);

                int[] x = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };

                final XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
                CategorySeries seriesProtein = new CategorySeries("Protein");
                CategorySeries seriesFat = new CategorySeries("Fat");
                CategorySeries seriesCarbs = new CategorySeries("Carbs");

                List<Ingridient> list;
                Date dt = date;
                for (int element : x) {
                    list = DataBaseUtils.getAllFoodConsumedInMonth(
                            Utils.formatDate(dt, DataBaseUtils.DATE_PATTERN_YYYY_MM));

                    // init "average" data
                    double totalProtein = 0, totalFat = 0, totalCarbs = 0, totalCallories = 0;
                    for (Ingridient ingridient : list) {
                        totalProtein += ingridient.protein;
                        totalFat += ingridient.fat;
                        totalCarbs += ingridient.carbohydrates;
                        totalCallories += ingridient.kkal;
                    }

                    seriesProtein.add((double) Math.round(totalProtein * 100) / 100);
                    seriesFat.add((double) Math.round(totalFat * 100) / 100);
                    seriesCarbs.add((double) Math.round(totalCarbs * 100) / 100);

                    // calculate maximum Y axis values
                    yMaxAxisValue = Math.max(yMaxAxisValue, (int) totalProtein);
                    yMaxAxisValue = Math.max(yMaxAxisValue, (int) totalFat);
                    yMaxAxisValue = Math.max(yMaxAxisValue, (int) totalCarbs);

                    // increment month
                    dt = DateUtils.addMonths(dt, 1);
                }

                int[] colors = new int[] { getActivity().getResources().getColor(R.color.green),
                        getActivity().getResources().getColor(R.color.orange),
                        getActivity().getResources().getColor(R.color.purple) };
                final XYMultipleSeriesRenderer renderer = buildBarRenderer(colors);
                setChartSettings(renderer,
                        String.format("Protein/Carbohydrates/Fat statistic for %s year",
                                Utils.getSpecificDateValue(DATE, "yyyy")),
                        "Months", "Amount (g)           ", 0.7, 12.3, 0, yMaxAxisValue + 30, Color.GRAY,
                        Color.LTGRAY);

                renderer.getSeriesRendererAt(0).setDisplayChartValues(true);
                renderer.getSeriesRendererAt(1).setDisplayChartValues(true);
                renderer.getSeriesRendererAt(2).setDisplayChartValues(true);

                renderer.getSeriesRendererAt(0).setChartValuesTextSize(15f);
                renderer.getSeriesRendererAt(1).setChartValuesTextSize(15f);
                renderer.getSeriesRendererAt(2).setChartValuesTextSize(15f);

                // renderer.getSeriesRendererAt(0).setChartValuesTextAlign(Align.CENTER);
                // renderer.getSeriesRendererAt(1).setChartValuesTextAlign(Align.LEFT);
                // renderer.getSeriesRendererAt(2).setChartValuesTextAlign(Align.RIGHT);

                renderer.setXLabels(0);
                // renderer.setYLabels(10);
                // renderer.setXLabelsAlign(Align.LEFT);
                // renderer.setYLabelsAlign(Align.LEFT);
                // renderer.setPanEnabled(true, false);
                renderer.setClickEnabled(false);
                renderer.setZoomEnabled(false);
                renderer.setPanEnabled(false, false);
                renderer.setZoomButtonsVisible(false);
                renderer.setPanLimits(new double[] { 1, 11 });
                // renderer.setZoomEnabled(false);
                // renderer.setZoomRate(1.1f);
                renderer.setShowGrid(true);
                renderer.setShowLegend(true);
                renderer.setFitLegend(true);

                for (int i = 0; i < ActivityWaterProgress.months_short.length; i++) {
                    renderer.addXTextLabel(i + 1, ActivityWaterProgress.months_short[i]);

                }

                dataset.addSeries(seriesProtein.toXYSeries());
                dataset.addSeries(seriesFat.toXYSeries());
                dataset.addSeries(seriesCarbs.toXYSeries());

                getActivity().runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            viewChart = ChartFactory.getLineChartView(getActivity(), dataset,
                                    renderer/* , Type.STACKED */);
                            rlRootGraphLayout.addView(viewChart, 0);
                            if (isLeftIn) {
                                rightIn.setDuration(1000);
                                viewChart.startAnimation(rightIn);
                            } else {
                                leftIn.setDuration(1000);
                                viewChart.startAnimation(leftIn);
                            }
                        } catch (Exception edsx) {
                            edsx.printStackTrace();
                        }

                    }
                });

            } catch (Exception e) {
                e.printStackTrace();
            }
            ringProgressDialog.dismiss();
        }
    }).start();

}

From source file:com.progym.custom.fragments.CalloriesProgressYearlyLineFragment.java

public void setYearProgressData(final Date date, final boolean isLeftIn) {

    final ProgressDialog ringProgressDialog = ProgressDialog.show(getActivity(),
            getResources().getString(R.string.please_wait), getResources().getString(R.string.populating_data),
            true);//  w  w  w.  j a v a2  s  .  c o m
    ringProgressDialog.setCancelable(true);
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                int yMaxAxisValue = 0;

                getActivity().runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            rlRootGraphLayout.removeView(viewChart);
                        } catch (Exception edsx) {
                            edsx.printStackTrace();
                        }
                    }
                });

                DATE = date;
                // Get amount of days in a month to find out average
                int daysInMonth = Utils.getDaysInMonth(date.getMonth(),
                        Integer.valueOf(Utils.formatDate(date, DataBaseUtils.DATE_PATTERN_YYYY)));
                // set January as first month
                date.setMonth(0);
                date.setDate(1);

                int[] x = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };

                final XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
                CategorySeries seriesCallories = new CategorySeries("Callories");

                List<Ingridient> list;
                Date dt = date; // *
                for (int element : x) {
                    list = DataBaseUtils.getAllFoodConsumedInMonth(
                            Utils.formatDate(dt, DataBaseUtils.DATE_PATTERN_YYYY_MM));

                    // init "average" data
                    int totalCallories = 0;
                    for (Ingridient ingridient : list) {
                        totalCallories += ingridient.kkal;
                    }
                    // add value to series
                    seriesCallories.add(totalCallories / daysInMonth);
                    // calculate maximum Y axis values
                    yMaxAxisValue = Math.max(yMaxAxisValue, totalCallories / daysInMonth);
                    // increment month
                    dt = DateUtils.addMonths(dt, 1);
                }

                int[] colors = new int[] { getActivity().getResources().getColor(R.color.purple) };
                final XYMultipleSeriesRenderer renderer = buildBarRenderer(colors);
                setChartSettings(renderer,
                        String.format("Callories statistic for %s year",
                                Utils.getSpecificDateValue(DATE, "yyyy")),
                        "Months", "Calories consumption", 0.7, 12.3, 0, yMaxAxisValue + 30, Color.GRAY,
                        Color.LTGRAY);

                renderer.getSeriesRendererAt(0).setDisplayChartValues(true);
                renderer.getSeriesRendererAt(0).setChartValuesTextSize(15f);
                renderer.setXLabels(0);
                renderer.setClickEnabled(false);
                renderer.setZoomEnabled(false);
                renderer.setPanEnabled(false, false);
                renderer.setZoomButtonsVisible(false);
                renderer.setPanLimits(new double[] { 1, 11 });
                renderer.setShowGrid(true);
                renderer.setShowLegend(true);
                renderer.setFitLegend(true);

                for (int i = 0; i < ActivityWaterProgress.months_short.length; i++) {
                    renderer.addXTextLabel(i + 1, ActivityWaterProgress.months_short[i]);

                }
                dataset.addSeries(seriesCallories.toXYSeries());

                getActivity().runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        viewChart = ChartFactory.getBarChartView(getActivity(), dataset, renderer,
                                Type.DEFAULT);
                        rlRootGraphLayout.addView(viewChart, 0);

                        if (isLeftIn) {
                            rightIn.setDuration(1000);
                            viewChart.startAnimation(rightIn);
                        } else {
                            leftIn.setDuration(1000);
                            viewChart.startAnimation(leftIn);
                        }
                    }
                });

            } catch (Exception e) {
            }
            ringProgressDialog.dismiss();
        }
    }).start();

}

From source file:info.xuluan.podcast.SearchActivity.java

private void start_search(String search_url) {
    SearchActivity.this.progress = ProgressDialog.show(SearchActivity.this,
            getResources().getText(R.string.dialog_title_loading),
            getResources().getText(R.string.dialog_message_loading), true);
    AsyncTask<String, ProgressDialog, String> asyncTask = new AsyncTask<String, ProgressDialog, String>() {
        String url;/*from   w  w w  .j  a  v  a  2s. c o m*/

        @Override
        protected String doInBackground(String... params) {

            url = params[0];
            // log.debug("doInBackground URL ="+url);
            return fetchChannelInfo(url);

        }

        @Override
        protected void onPostExecute(String result) {

            if (SearchActivity.this.progress != null) {
                SearchActivity.this.progress.dismiss();
                SearchActivity.this.progress = null;
            }

            if (result == null) {
                Toast.makeText(SearchActivity.this, getResources().getString(R.string.network_fail),
                        Toast.LENGTH_SHORT).show();
            } else {
                List<SearchItem> items = parseResult(result);
                if (items.size() == 0) {
                    Toast.makeText(SearchActivity.this, getResources().getString(R.string.no_data_found),
                            Toast.LENGTH_SHORT).show();
                } else {
                    mStart += items.size();
                    for (int i = 0; i < items.size(); i++) {
                        mItems.add(items.get(i));
                        mAdapter.add(items.get(i).title);

                    }
                }
            }

            updateBtn();
        }
    };
    asyncTask.execute(search_url);
}

From source file:com.guardtrax.ui.screens.SplashScreen.java

private void initialize() {
    if (locationManagerObj == null) {
        locationManagerObj = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

        try {/*ww  w .j  a va 2 s.  c o m*/
            gps_enabled = locationManagerObj.isProviderEnabled(LocationManager.GPS_PROVIDER);

            //network_enabled = locationManagerObj.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
        } catch (Exception ex) {
        }
    }

    // don't start listeners if no provider is enabled - Changed to to look for both
    //if (!gps_enabled) 
    if (!gps_enabled && !network_enabled) {
        AlertDialog.Builder dialog = new AlertDialog.Builder(SplashScreen.this);
        dialog.setTitle("Info");
        dialog.setMessage("Please enable GPS!");
        dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                System.exit(0);
            }
        });
        dialog.show();
    } else {
        Runnable showWaitDialog = new Runnable() {
            @Override
            public void run() {
                Looper.prepare();

                int i = 0;

                //if syncComplete is true already it means that we are not trying to sync, hence delay so that splash screen can close slowly
                if (syncComplete) {
                    try {
                        Thread.sleep(1000);
                    } catch (Exception e) {
                    }
                } else {
                    while (!syncComplete || i++ < 10) {
                        try {
                            Thread.sleep(1000);
                        } catch (Exception e) {
                            break;
                        }
                    }

                    //make sure background task is completed.  If not, force it closed
                    if (!syncComplete) {
                        try {
                            if (syncdb.getStatus() != AsyncTask.Status.FINISHED)
                                syncdb.cancel(true);
                        } catch (Exception e) {
                        }
                    }
                }

                //After receiving first GPS Fix dismiss the Progress Dialog
                dialog.dismiss();

                //calling the tab class causes the current tab to be displayed (set to tab(0) which is the HomeScreen)

                Intent intent = new Intent();
                intent.setClass(SplashScreen.this, HomeScreen.class);
                startActivity(intent);

                //transition from splash to main menu is slowed down to a fade by this command
                overridePendingTransition(R.anim.activityfadein, R.anim.splashfadeout);

                SplashScreen.this.finish();
            }
        };

        // Create a Dialog to let the User know that we're waiting for a GPS Fix
        dialog = ProgressDialog.show(SplashScreen.this, "Please wait", "Initializing ...", true);

        Thread t = new Thread(showWaitDialog);
        t.start();
    }
}

From source file:com.myandroidremote.AccountsActivity.java

private void showLoadingScreen() {
    progressDialog = ProgressDialog.show(AccountsActivity.this, "", "Loading. Please wait...", true);
}

From source file:com.example.polytech.orientatewatch.ForecastFragment.java

public void updateWeather() {
    FetchWeatherTask weatherTask = new FetchWeatherTask();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    String range = prefs.getString(getString(R.string.pref_range_key), getString(R.string.pref_range_default));
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    String tspType = sharedPrefs.getString(getString(R.string.pref_trnspt_key),
            getString(R.string.pref_trnspt_pied));

    SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    String typePOI = sharedPrefs.getString(getString(R.string.pref_type_key), "restaurant");

    String modeTsp;//from   w  ww .j  a va 2  s  . co m
    if (tspType.equals(getString(R.string.pref_trnspt_voiture))) {
        modeTsp = "driving";
    } else {
        modeTsp = "walking";
    }

    if (range != Utility.actualRange || modeTsp != Utility.actualTrspt || typePOI != Utility.actualType) {
        myProgressDialog = ProgressDialog.show(getActivity(), "", "Chargement", true);
        Utility.nextPageToken = null;
        Utility.actualRange = range;
        Utility.actualTrspt = modeTsp;
        Utility.actualType = typePOI;
        weatherTask.execute(range);
        sendMessage(WEAR_MESSAGE_PATH2, "Debut");
    }

}

From source file:com.jakebasile.android.linkshrink.ShortenUrl.java

private void shortenWithIsgd(final String longUrl) {
    String display = String.format(getResources().getString(R.string.shortening_message), ISGD);
    final ProgressDialog pd = ProgressDialog.show(ShortenUrl.this,
            getResources().getString(R.string.shortening_title), display, true);
    new Thread() {
        @Override// www  .  j  a v  a 2s  .c o m
        public void run() {
            try {
                String requestUrl = String.format(ISGD_URL, URLEncoder.encode(longUrl));
                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                HttpClient httpClient = new DefaultHttpClient();
                HttpGet request = new HttpGet(new URI(requestUrl));
                HttpResponse response = httpClient.execute(request);
                if (response.getStatusLine().getStatusCode() == 200) {
                    response.getEntity().writeTo(stream);
                    _shortUrl = new String(stream.toByteArray()).trim();
                } else {
                    _shortUrl = null;
                }
                _handler.sendEmptyMessage(0);
            } catch (IOException ex) {
                _handler.sendEmptyMessage(1);
            } catch (URISyntaxException ex) {
                _handler.sendEmptyMessage(2);
            } finally {
                pd.dismiss();
            }
        }
    }.start();
}

From source file:samples.piggate.com.piggateCompleteExample.buyOfferActivity.java

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

    //Set action bar fields
    getSupportActionBar().setTitle(PiggateUser.getEmail());
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

    //Views/*  w w w. ja  v  a 2  s  . c o m*/
    EditCardNumber = (EditText) findViewById(R.id.cardNumber);
    EditCVC = (EditText) findViewById(R.id.CVC);
    SpinnerYear = (Spinner) findViewById(R.id.spinerYear);
    SpinnerMonth = (Spinner) findViewById(R.id.spinerMonth);
    validate = (Button) findViewById(R.id.buttonValidate);
    buttonBuy = (Button) findViewById(R.id.buttonBuy);
    buttonCancel = (Button) findViewById(R.id.buttonCancel);
    headerLayout = (LinearLayout) findViewById(R.id.headerLayout);
    cardlayout = (LinearLayout) findViewById(R.id.cardlayout);
    buylayout = (LinearLayout) findViewById(R.id.buyLayout);
    image = (SmartImageView) findViewById(R.id.offerImage2);

    //Animations
    slidetoLeft = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slidetoleft);
    slidetoRight = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slidetoright);
    slidefromRight = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slidefromright);
    slidefromLeft = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.slidefromleft);

    //Validation Error AlertDialog
    errorDialog = new AlertDialog.Builder(buyOfferActivity.this).create();
    errorDialog.setTitle("Validation error");
    errorDialog.setMessage("The credit card is not valid");
    errorDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    //Network Error AlertDialog
    networkDialog = new AlertDialog.Builder(this).create();
    networkDialog.setTitle("Network error");
    networkDialog.setMessage("Network is not working");
    networkDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    image.setImageUrl(getIntent().getExtras().getString("offerImgURL")); //Set the offer image from URL
    //(Provisional) set the default fields of the credit card
    EditCardNumber.setText("4242424242424242");
    EditCVC.setText("123");

    piggate = new Piggate(this); //Initialize Piggate Object

    //OnClick listener for the validate button
    validate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            //Validate the credit card with Stripe
            if (checkInternetConnection() == true) {
                // Credit card for testing: ("4242-4242-4242-4242", 12, 2016, "123")
                if (piggate.validateCard(EditCardNumber.getText().toString(),
                        Integer.parseInt(SpinnerMonth.getSelectedItem().toString()),
                        Integer.parseInt(SpinnerYear.getSelectedItem().toString()),
                        EditCVC.getText().toString(), "pk_test_BN86VnxiMBHkZtzPmpykc56g", //Stripe test. Will be returned by requests in next release
                        buyOfferActivity.this, "Validating", "Wait while the credit card is validated")) {
                    openBuyLayout();
                } else
                    errorDialog.show();
            } else {
                networkDialog.show();
            }
        }
    });

    //OnClick listener for the buy button
    buttonBuy.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            //Do the buy request to the server
            RequestParams params = new RequestParams();
            //Get the latest credit card Stripe token, amount to pay, type of coin and ID
            params.put("stripeToken", piggate.get_creditCards().get(piggate.get_creditCards().size() - 1)
                    .getTokenID().toString());
            params.put("amount", getIntent().getExtras().getString("offerPrice"));
            params.put("offerID", getIntent().getExtras().getString("offerID"));
            params.put("currency", getIntent().getExtras().getString("offerCurrency"));

            //Loading payment ProgressDialog
            loadingDialog = ProgressDialog.show(v.getContext(), "Payment", "Wait while the payment is finished",
                    true);

            //Do the buy request to the server (The server do the payment with Stripe)
            piggate.RequestBuy(params).setListenerRequest(new Piggate.PiggateCallBack() {

                //onComplete method for JSONObject
                @Override
                public void onComplete(int statusCode, Header[] headers, String msg, JSONObject data) {
                    loadingDialog.dismiss();

                    //Go back to the offer list passing the offer attributes (to exchange)
                    Intent slideactivity = new Intent(buyOfferActivity.this, Activity_Logged.class);
                    slideactivity.putExtra("offerID", getIntent().getExtras().getString("offerID"));
                    slideactivity.putExtra("offerName", getIntent().getExtras().getString("offerName"));
                    slideactivity.putExtra("offerDescription",
                            getIntent().getExtras().getString("offerDescription"));
                    slideactivity.putExtra("payment", true);
                    slideactivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    Bundle bndlanimation = ActivityOptions.makeCustomAnimation(getApplicationContext(),
                            R.anim.slidefromleft, R.anim.slidetoright).toBundle();
                    startActivity(slideactivity, bndlanimation);
                }

                //onError method for JSONObject
                @Override
                public void onError(int statusCode, Header[] headers, String msg, JSONObject data) {

                    //Show an error and go back to the credit card
                    loadingDialog.dismiss();
                    //Go back to the offer list with the variable payment set to false (payment error)
                    Intent slideactivity = new Intent(buyOfferActivity.this, Activity_Logged.class);
                    slideactivity.putExtra("payment", false);
                    slideactivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    Bundle bndlanimation = ActivityOptions.makeCustomAnimation(getApplicationContext(),
                            R.anim.slidefromleft, R.anim.slidetoright).toBundle();
                    startActivity(slideactivity, bndlanimation);
                }

                //onComplete method for JSONArray
                @Override
                public void onComplete(int statusCode, Header[] headers, String msg, JSONArray data) {
                    loadingDialog.dismiss();

                    //Go back to the offer list passing the offer attributes (to exchange)
                    Intent slideactivity = new Intent(buyOfferActivity.this, Activity_Logged.class);
                    slideactivity.putExtra("offerID", getIntent().getExtras().getString("offerID"));
                    slideactivity.putExtra("offerName", getIntent().getExtras().getString("offerName"));
                    slideactivity.putExtra("offerDescription",
                            getIntent().getExtras().getString("offerDescription"));
                    slideactivity.putExtra("payment", true);
                    slideactivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    Bundle bndlanimation = ActivityOptions.makeCustomAnimation(getApplicationContext(),
                            R.anim.slidefromleft, R.anim.slidetoright).toBundle();
                    startActivity(slideactivity, bndlanimation);
                }

                //onError method for JSONArray (Show an error and go back to the credit card)
                @Override
                public void onError(int statusCode, Header[] headers, String msg, JSONArray data) {

                    //Show an error and go back to the credit card
                    loadingDialog.dismiss();
                    //Go back to the offer list with the variable payment set to false (payment error)
                    Intent slideactivity = new Intent(buyOfferActivity.this, Activity_Logged.class);
                    slideactivity.putExtra("payment", false);
                    slideactivity.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                    Bundle bndlanimation = ActivityOptions.makeCustomAnimation(getApplicationContext(),
                            R.anim.slidefromleft, R.anim.slidetoright).toBundle();
                    startActivity(slideactivity, bndlanimation);
                }
            }).exec();
        }
    });

    //OnClick listener for the cancel button (Go back to the credit card)
    buttonCancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            closeBuyLayout();
        }
    });
}

From source file:com.jaguarlandrover.auto.remote.vehicleentry.LockActivity.java

@Override
public void keyShareCommand(String key) {
    Intent intent = new Intent();
    switch (key) {
    case "keyshare":
        intent.setClass(LockActivity.this, KeyShareActivity.class);
        startActivityForResult(intent, 0);
        break;//  w w w .jav  a  2  s.com
    case "keychange":
        try {
            ServerNode.requestRemoteCredentials();
            requestProgress = ProgressDialog.show(LockActivity.this, "", "Retrieving keys...", true);

            requestProgress.setCancelable(true);
            requestProgress.setOnCancelListener(new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialog) {
                    // TODO: ?
                }
            });

            startRequest();
        } catch (Exception e) {
            e.printStackTrace();
        }
        break;
    }
}