Example usage for android.app ProgressDialog setCancelable

List of usage examples for android.app ProgressDialog setCancelable

Introduction

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

Prototype

public void setCancelable(boolean flag) 

Source Link

Document

Sets whether this dialog is cancelable with the KeyEvent#KEYCODE_BACK BACK key.

Usage

From source file:com.mobility.android.ui.vehicle.AddVehicleActivity.java

private void uploadVehicle() {
    ProgressDialog dialog = new ProgressDialog(this, R.style.DialogStyle);
    dialog.setMessage("Adding vehicle...");
    dialog.setIndeterminate(true);//from   w  w  w  .j  a v  a 2  s  .  c  o m
    dialog.setCancelable(false);
    dialog.show();

    vehicle.lat = (float) place.getLatLng().latitude;
    vehicle.lng = (float) place.getLatLng().longitude;
    vehicle.address = place.getAddress().toString();
    vehicle.country = "IT";

    vehicle.name = name.getText().toString();
    vehicle.availability = availability.getText().toString();
    vehicle.licencePlate = isCar ? licencePlate.getText().toString() : null;
    vehicle.description = description.getText().toString();
    vehicle.pricePerHour = Float.parseFloat(price.getText().toString());
    vehicle.currency = "EUR";

    vehicle.type = isCar ? "car" : "bike";

    Timber.e("Uploading vehicle: %s", vehicle);

    VehicleApi api = RestClient.ADAPTER.create(VehicleApi.class);
    api.addVehicle(vehicle).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Observer<VehicleObject>() {
                @Override
                public void onCompleted() {

                }

                @Override
                public void onError(Throwable e) {
                    e.printStackTrace();
                    dialog.dismiss();
                    UIUtils.okDialog(AddVehicleActivity.this, "Error", "Couldn't add vehicle.");
                }

                @Override
                public void onNext(VehicleObject object) {
                    Timber.w("Added vehicle");
                    dialog.dismiss();

                    Intent intent = new Intent(AddVehicleActivity.this, VehicleDetailsActivity.class);
                    intent.putExtra(Config.EXTRA_VEHICLE, object);
                    startActivity(intent);
                    finish();
                }
            });
}

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

public void setLineData3(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 w w  w  .  j av  a  2  s. co 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(mChartView);
                        } catch (Exception edsx) {
                            edsx.printStackTrace();
                        }
                    }
                });

                DATE = date;
                // 31 - Amount of days in a month
                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 };

                // Creating an XYSeries for Consumed water
                XYSeries consumedSeries = new XYSeries("Consumed");

                List<WaterConsumed> list;
                // int userShouldConsume = (int) DataBaseUtils.getWaterUserShouldConsumePerDay();
                Date dt = date; // *
                // Adding data to Income and Expense Series
                for (int i = 0; i < x.length; i++) {
                    // get all water records consumed per this month
                    list = DataBaseUtils.getAllWaterConsumedInMonth(
                            Utils.formatDate(dt, DataBaseUtils.DATE_PATTERN_YYYY_MM));
                    // init "average" data
                    int averageWaterConsumedOnYaxis = 0;
                    for (int j = 0; j < list.size(); j++) {
                        // calculate sum of all water consumed by user in a month
                        averageWaterConsumedOnYaxis += list.get(j).volumeConsumed;
                    }
                    averageWaterConsumedOnYaxis = averageWaterConsumedOnYaxis / daysInMonth;
                    consumedSeries.add(i, averageWaterConsumedOnYaxis);
                    // normaSeries.add(i, userShouldConsume);
                    dt = DateUtils.addMonths(dt, 1);
                    yMaxAxisValue = Math.max(yMaxAxisValue, averageWaterConsumedOnYaxis);
                }

                // Creating a dataset to hold each series
                final XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
                // Adding Expense Series to dataset
                // dataset.addSeries(normaSeries);
                // Adding Income Series to the dataset
                dataset.addSeries(consumedSeries);

                // Creating XYSeriesRenderer to customize incomeSeries
                XYSeriesRenderer incomeRenderer = new XYSeriesRenderer();
                incomeRenderer.setColor(Color.rgb(50, 255, 50));
                incomeRenderer.setFillPoints(true);
                incomeRenderer.setLineWidth(2);
                incomeRenderer.setDisplayChartValues(true);

                /*
                 * // Creating XYSeriesRenderer to customize expenseSeries
                 * XYSeriesRenderer expenseRenderer = new XYSeriesRenderer();
                 * expenseRenderer.setColor(Color.rgb(80, 220, 80));
                 * expenseRenderer.setFillPoints(true);
                 * expenseRenderer.setLineWidth(2);
                 * expenseRenderer.setDisplayChartValues(true);
                 */

                // Creating a XYMultipleSeriesRenderer to customize the whole chart
                final XYMultipleSeriesRenderer multiRenderer = new XYMultipleSeriesRenderer();
                multiRenderer.setXLabels(0);

                for (int i = 0; i < x.length; i++) {
                    multiRenderer.addXTextLabel(i, ActivityWaterProgress.months_short[i]);
                }

                // Adding incomeRenderer and expenseRenderer to multipleRenderer
                // Note: The order of adding dataseries to dataset and renderers to multipleRenderer
                // should be same
                multiRenderer.setChartTitle(String.format("Water statistic for %s year",
                        Utils.formatDate(DATE, DataBaseUtils.DATE_PATTERN_YYYY)));
                multiRenderer.setXTitle("Months");
                multiRenderer.setYTitle("Water volume (ml)");
                multiRenderer.setAxesColor(Color.WHITE);
                multiRenderer.setShowLegend(true);
                multiRenderer.addSeriesRenderer(incomeRenderer);
                multiRenderer.setShowGrid(true);
                multiRenderer.setClickEnabled(true);
                // multiRenderer.addSeriesRenderer(expenseRenderer);
                multiRenderer.setXLabelsAngle(30);
                // multiRenderer.setBackgroundColor(Color.parseColor("#B3FFFFFF"));
                // multiRenderer.setApplyBackgroundColor(true);
                multiRenderer.setXLabelsColor(Color.WHITE);
                multiRenderer.setZoomButtonsVisible(false);
                // configure visible area
                multiRenderer.setXAxisMax(11.5);
                multiRenderer.setXAxisMin(-0.5);
                multiRenderer.setYAxisMax(yMaxAxisValue + (yMaxAxisValue / 5));
                multiRenderer.setYAxisMin(-0.1);

                multiRenderer.setAxisTitleTextSize(15);
                multiRenderer.setBarSpacing(0.1);
                multiRenderer.setZoomEnabled(true);

                getActivity().runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        mChartView = ChartFactory.getBarChartView(getActivity(), dataset, multiRenderer,
                                Type.DEFAULT);

                        rlRootGraphLayout.addView(mChartView, 0);
                        if (isLeftIn) {
                            rightIn.setDuration(1000);
                            mChartView.startAnimation(rightIn);
                        } else {
                            leftIn.setDuration(1000);
                            mChartView.startAnimation(leftIn);
                        }
                    }
                });

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

}

From source file:com.gmail.nagamatu.radiko.installer.RadikoInstallerActivity.java

private Dialog onCreateProgressDialog() {
    final ProgressDialog dialog = new ProgressDialog(this);
    dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    dialog.setMessage("Loading...");
    dialog.setCancelable(false);
    return dialog;
}

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

public void setLineData3(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);/*  www  .  j  a  va2  s . 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(graphView);
                        } catch (Exception edsx) {
                            edsx.printStackTrace();
                        }

                    }
                });

                date.setDate(1);
                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 First day of the month as first month

                int[] x = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22,
                        23, 24, 25, 26, 27, 28, 29, 30, 31 };

                // Creating an XYSeries for Consumed water
                XYSeries protein = new XYSeries("Protein");
                XYSeries fat = new XYSeries("Fat");
                XYSeries carbs = new XYSeries("Carbs");

                List<Ingridient> list;
                Date dt = date; // *
                // Adding data to Income and Expense Series
                for (int i = 1; i <= daysInMonth; i++) {
                    // get all water records consumed per this month
                    list = DataBaseUtils.getAllFoodConsumedInMonth(
                            Utils.formatDate(dt, DataBaseUtils.DATE_PATTERN_YYYY_MM_DD));
                    // init "average" data
                    double totalProtein = 0, totalFat = 0, totalCarbs = 0;
                    if (null != list) {
                        for (Ingridient ingridient : list) {
                            totalProtein += ingridient.protein;
                            totalFat += ingridient.fat;
                            totalCarbs += ingridient.carbohydrates;
                        }
                    }

                    protein.add(i, (double) Math.round(totalProtein * 100) / 100);
                    fat.add(i, (double) Math.round(totalFat * 100) / 100);
                    carbs.add(i, (double) Math.round(totalCarbs * 100) / 100);
                    // calories.add(i, totalCallories);
                    dt = DateUtils.addDays(dt, 1);

                    yMaxAxisValue = Math.max(yMaxAxisValue, (int) totalProtein);
                    yMaxAxisValue = Math.max(yMaxAxisValue, (int) totalFat);
                    yMaxAxisValue = Math.max(yMaxAxisValue, (int) totalCarbs);
                }

                // Creating a dataset to hold each series
                final XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset();
                // Adding Income Series to the dataset
                dataset.addSeries(protein);
                dataset.addSeries(carbs);
                dataset.addSeries(fat);

                // Creating XYSeriesRenderer to customize protein series
                XYSeriesRenderer proteinRenderer = new XYSeriesRenderer();
                proteinRenderer.setColor(Color.rgb(50, 255, 50));
                proteinRenderer.setFillPoints(true);
                proteinRenderer.setLineWidth(3);
                proteinRenderer.setDisplayChartValues(true);

                // Creating XYSeriesRenderer to customize protein series
                XYSeriesRenderer fatRenderer = new XYSeriesRenderer();
                fatRenderer.setColor(Color.rgb(123, 111, 00));
                fatRenderer.setFillPoints(true);
                fatRenderer.setLineWidth(3);
                fatRenderer.setDisplayChartValues(true);

                // Creating XYSeriesRenderer to customize protein series
                XYSeriesRenderer carbsRenderer = new XYSeriesRenderer();
                carbsRenderer.setColor(Color.rgb(222, 13, 11));
                carbsRenderer.setFillPoints(true);
                carbsRenderer.setLineWidth(3);
                carbsRenderer.setDisplayChartValues(true);

                // Creating a XYMultipleSeriesRenderer to customize the whole chart
                final XYMultipleSeriesRenderer multiRenderer = new XYMultipleSeriesRenderer();
                // multiRenderer.setXLabels(0);

                for (int i = 0; i < x.length; i++) {
                    multiRenderer.addXTextLabel(i, String.valueOf(x[i]));
                }

                // Adding incomeRenderer and expenseRenderer to multipleRenderer
                // Note: The order of adding dataseries to dataset and renderers to multipleRenderer
                // should be same
                multiRenderer.setChartTitle(String.format("Protein/Carbs/Fat statistic "));
                multiRenderer.setXTitle(Utils.getSpecificDateValue(DATE, "MMM") + " of "
                        + Utils.formatDate(DATE, DataBaseUtils.DATE_PATTERN_YYYY));
                multiRenderer.setYTitle("Amount (g)          ");
                multiRenderer.setAxesColor(Color.WHITE);
                multiRenderer.setShowLegend(true);
                multiRenderer.addSeriesRenderer(proteinRenderer);
                multiRenderer.addSeriesRenderer(carbsRenderer);
                multiRenderer.addSeriesRenderer(fatRenderer);

                multiRenderer.setShowGrid(true);
                multiRenderer.setClickEnabled(true);
                multiRenderer.setXLabelsAngle(20);
                multiRenderer.setXLabelsColor(Color.WHITE);
                multiRenderer.setZoomButtonsVisible(false);
                // configure visible area
                multiRenderer.setXAxisMax(31);
                multiRenderer.setXAxisMin(1);
                multiRenderer.setYAxisMax(yMaxAxisValue + 30);
                multiRenderer.setAxisTitleTextSize(15);
                multiRenderer.setZoomEnabled(true);

                getActivity().runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            graphView = ChartFactory.getLineChartView(getActivity(), dataset, multiRenderer);
                            rlRootGraphLayout.addView(graphView, 0);

                            if (isLeftIn) {
                                rightIn.setDuration(1000);
                                graphView.startAnimation(rightIn);
                            } else {
                                leftIn.setDuration(1000);
                                graphView.startAnimation(leftIn);
                            }
                        } catch (Exception edsx) {
                            edsx.printStackTrace();
                        }

                    }
                });

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

}

From source file:org.sickstache.fragments.ShowsFragment.java

@Override
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    if (actionMode == null) {
        actionMode = getSherlockActivity().startActionMode(new ActionMode.Callback() {

            @Override//from  ww  w.  j  av a2  s .  c  om
            public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            @Override
            public void onDestroyActionMode(ActionMode mode) {
                showAdapter.notifyDataSetChanged();
                selected.clear();
                actionMode = null;
            }

            @Override
            public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                MenuInflater inflate = getSherlockActivity().getSupportMenuInflater();
                inflate.inflate(R.menu.shows_cab_menu, menu);
                return true;
            }

            @Override
            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                switch (item.getItemId()) {
                case R.id.pauseMenuItem:
                    final PauseDialog pDialog = new PauseDialog();
                    pDialog.setTitle("Set Pause");
                    pDialog.setOnOkClick(new OnClickListener() {
                        @Override
                        public void onClick(DialogInterface arg0, int arg1) {
                            final ProgressDialog dialog = ProgressDialog.show(
                                    ShowsFragment.this.getSherlockActivity(), "",
                                    "Pausing Shows. Please wait...", true);
                            dialog.setCancelable(true);
                            dialog.show();
                            String[] tvdbids = new String[selected.size()];
                            for (int i = 0; i < selected.size(); i++) {
                                tvdbids[i] = showAdapter.getItem(selected.get(i)).id;
                            }
                            Preferences pref = Preferences
                                    .getSingleton(ShowsFragment.this.getSherlockActivity());
                            PauseTask pause = new PauseTask(pref, tvdbids, pDialog.getPause()) {
                                @Override
                                protected void onPostExecute(Boolean result) {
                                    if (dialog != null && dialog.isShowing())
                                        dialog.dismiss();
                                    if (error != null && getFragmentManager() != null) {
                                        ErrorDialog dialog = new ErrorDialog();
                                        dialog.setMessage("Error pausing show.\nERROR: " + error.getMessage());
                                        dialog.show(getFragmentManager(), "pauseError");
                                    }
                                }
                            };
                            pause.execute();
                        }
                    });
                    pDialog.show(getFragmentManager(), "update");
                    return true;
                case R.id.refreshMenuItem: {
                    final ProgressDialog dialog = ProgressDialog.show(ShowsFragment.this.getSherlockActivity(),
                            "", "Refreshing Shows. Please wait...", true);
                    dialog.setCancelable(true);
                    dialog.show();
                    String[] tvdbids = new String[selected.size()];
                    for (int i = 0; i < selected.size(); i++) {
                        tvdbids[i] = showAdapter.getItem(selected.get(i)).id;
                    }
                    Preferences pref = Preferences.getSingleton(ShowsFragment.this.getSherlockActivity());
                    RefreshTask refresh = new RefreshTask(pref, tvdbids) {
                        @Override
                        protected void onPostExecute(Boolean result) {
                            if (dialog != null && dialog.isShowing())
                                dialog.dismiss();
                            if (error != null && getFragmentManager() != null) {
                                ErrorDialog dialog = new ErrorDialog();
                                dialog.setMessage("Error refreshing show.\nERROR: " + error.getMessage());
                                dialog.show(getFragmentManager(), "refreshError");
                            }
                        }
                    };
                    refresh.execute();
                }
                    return true;
                case R.id.updateMenuItem: {
                    final ProgressDialog dialog = ProgressDialog.show(ShowsFragment.this.getSherlockActivity(),
                            "", "Updating Shows. Please wait...", true);
                    dialog.setCancelable(true);
                    dialog.show();
                    String[] tvdbids = new String[selected.size()];
                    for (int i = 0; i < selected.size(); i++) {
                        tvdbids[i] = showAdapter.getItem(selected.get(i)).id;
                    }
                    Preferences pref = Preferences.getSingleton(ShowsFragment.this.getSherlockActivity());
                    UpdateTask update = new UpdateTask(pref, tvdbids) {
                        @Override
                        protected void onPostExecute(Boolean result) {
                            if (dialog != null && dialog.isShowing())
                                dialog.dismiss();
                            if (error != null && getFragmentManager() != null) {
                                ErrorDialog dialog = new ErrorDialog();
                                dialog.setMessage("Error updating show.\nERROR: " + error.getMessage());
                                dialog.show(getFragmentManager(), "updateError");
                            }
                        }
                    };
                    update.execute();
                }
                    return true;
                //               case R.id.editMenuItem:
                //                  // get all selected items and create the edit show activity passing all of them
                //                  actionMode.finish();
                //                  return true;
                }
                return false;
            }
        });
    }
    ImageView overlay = (ImageView) arg1.findViewById(R.id.showSelectedOverlay);
    int i = selected.indexOf(arg2);
    if (i >= 0) {
        selected.remove(i);
        overlay.setVisibility(View.INVISIBLE);
    } else {
        selected.add(arg2);
        overlay.setVisibility(View.VISIBLE);
    }
    actionMode.setTitle(selected.size() + " Items Selected");
    if (selected.size() == 0) {
        actionMode.finish();
    }
    return true;
}

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

public void onClick(View v) {
    EditText cueInput = (EditText) findViewById(R.id.cue);
    EditText responseInput = (EditText) findViewById(R.id.response);
    Spinner posInput = (Spinner) findViewById(R.id.pos);
    EditText characterResponseInput = (EditText) findViewById(R.id.response_character);
    EditText characterCueInput = (EditText) findViewById(R.id.cue_character);
    final String cue = cueInput.getText().toString();
    final String response = responseInput.getText().toString();
    final String pos = posInput.getSelectedItem().toString();
    final String character_cue = characterCueInput.getText().toString();
    final String character_response = characterResponseInput.getText().toString();
    String pos_code = Utils.POS_MAP.get(pos);
    if (TextUtils.isEmpty(pos_code)) {
        pos_code = "NONE";
    }//from www  . j a  v a2s  .co  m
    final String final_pos_code = pos_code;

    if (Main.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 = CreateItemActivity.class.getName();
        LoginActivity.params = new HashMap<String, String>();
        LoginActivity.params.put("list_id", list_id);
        LoginActivity.params.put("cue", cue);
        LoginActivity.params.put("response", response);
        LoginActivity.params.put("cue_language", cue_language);
        LoginActivity.params.put("response_language", response_language);
        LoginActivity.params.put("pos", pos);
        LoginActivity.params.put("character_cue", character_cue);
        LoginActivity.params.put("character_response", character_response);
        startActivity(intent);
    } else {
        // TODO cue and response languages need to be inferred from list we are
        // adding to ... Might want to fix those, i.e. not allow variation
        // on
        // search ...
        // TODO wondering whether there is some way to edit existing items
        // ...

        final ProgressDialog myOtherProgressDialog = new ProgressDialog(this);
        myOtherProgressDialog.setTitle("Please Wait ...");
        myOtherProgressDialog.setMessage("Creating Item ...");
        myOtherProgressDialog.setIndeterminate(true);
        myOtherProgressDialog.setCancelable(true);

        final Thread create_item = new Thread() {
            public void run() {
                // TODO make this interruptable .../*if
                // (!this.isInterrupted())*/
                CreateItemActivity.create_item_result = createItem(cue, cue_language, character_cue,
                        final_pos_code, response, response_language, character_response, list_id);

                myOtherProgressDialog.dismiss();

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

From source file:com.nbos.phonebook.sync.authenticator.AuthenticatorActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    final ProgressDialog dialog = new ProgressDialog(this);
    dialog.setMessage(getText(R.string.ui_activity_authenticating));
    dialog.setIndeterminate(true);//from   w  w  w.  j  a  va2  s. c  om
    dialog.setCancelable(true);
    dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            Log.i(tag, "dialog cancel has been invoked");
            if (mAuthThread != null) {
                mAuthThread.interrupt();
                finish();
            }
        }
    });
    return dialog;
}

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 . java  2s  .com*/
    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:edu.mit.mobile.android.locast.accounts.AuthenticatorActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_PROGRESS:

        final ProgressDialog dialog = new ProgressDialog(this);
        dialog.setMessage(getText(R.string.login_message_authenticating));
        dialog.setIndeterminate(true);//from w w  w. j av  a  2 s.c o m
        dialog.setCancelable(true);
        dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            public void onCancel(DialogInterface dialog) {
                Log.i(TAG, "dialog cancel has been invoked");
                if (mAuthenticationTask != null) {
                    mAuthenticationTask.cancel(true);
                    mAuthenticationTask = null;
                    finish();
                }
            }
        });
        return dialog;

    case DIALOG_SET_BASE_URL:

        final EditText baseUrl = new EditText(this);
        baseUrl.setText(getString(R.string.default_api_url));
        final AlertDialog.Builder db = new AlertDialog.Builder(this);
        return db.create();

    default:
        return null;
    }
}

From source file:org.telegram.ui.ChangeUsernameActivity.java

private void saveName() {
    if (!checkUserName(firstNameField.getText().toString(), true)) {
        return;// w  ww  .  ja  v a 2  s . com
    }
    TLRPC.User user = UserConfig.getCurrentUser();
    if (getParentActivity() == null || user == null) {
        return;
    }
    String currentName = user.username;
    if (currentName == null) {
        currentName = "";
    }
    String newName = firstNameField.getText().toString();
    if (currentName.equals(newName)) {
        finishFragment();
        return;
    }

    final ProgressDialog progressDialog = new ProgressDialog(getParentActivity());
    progressDialog.setMessage(LocaleController.getString("Loading", R.string.Loading));
    progressDialog.setCanceledOnTouchOutside(false);
    progressDialog.setCancelable(false);

    TLRPC.TL_account_updateUsername req = new TLRPC.TL_account_updateUsername();
    req.username = newName;

    NotificationCenter.getInstance().postNotificationName(NotificationCenter.updateInterfaces,
            MessagesController.UPDATE_MASK_NAME);
    final int reqId = ConnectionsManager.getInstance().sendRequest(req, new RequestDelegate() {
        @Override
        public void run(TLObject response, final TLRPC.TL_error error) {
            if (error == null) {
                final TLRPC.User user = (TLRPC.User) response;
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            progressDialog.dismiss();
                        } catch (Exception e) {
                            FileLog.e("tmessages", e);
                        }
                        ArrayList<TLRPC.User> users = new ArrayList<>();
                        users.add(user);
                        MessagesController.getInstance().putUsers(users, false);
                        MessagesStorage.getInstance().putUsersAndChats(users, null, false, true);
                        UserConfig.saveConfig(true);
                        finishFragment();
                    }
                });
            } else {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            progressDialog.dismiss();
                        } catch (Exception e) {
                            FileLog.e("tmessages", e);
                        }
                        showErrorAlert(error.text);
                    }
                });
            }
        }
    }, ConnectionsManager.RequestFlagFailOnServerErrors);
    ConnectionsManager.getInstance().bindRequestToGuid(reqId, classGuid);

    progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE,
            LocaleController.getString("Cancel", R.string.Cancel), new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    ConnectionsManager.getInstance().cancelRequest(reqId, true);
                    try {
                        dialog.dismiss();
                    } catch (Exception e) {
                        FileLog.e("tmessages", e);
                    }
                }
            });
    progressDialog.show();
}