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:samples.piggate.com.piggateCompleteExample.Activity_SingIn.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    _piggate = new Piggate(this, null); //Initialize the Piggate object

    getSupportActionBar().setTitle("Login");
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

    setContentView(R.layout.activity_login);
    //EditTexts for user email and password
    editEmail = (EditText) findViewById(R.id.editText1);
    editPass = (EditText) findViewById(R.id.editText2);
    Button login = (Button) findViewById(R.id.buttonlogin);

    errorDialog = new AlertDialog.Builder(this).create();
    errorDialog.setTitle("Login error");
    errorDialog.setMessage("There is an error with the login");
    errorDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override/*from ww w  .  j  ava 2s .com*/
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    networkErrorDialog = new AlertDialog.Builder(this).create();
    networkErrorDialog.setTitle("Network error");
    networkErrorDialog.setMessage("There is an error with the network connection");
    networkErrorDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    //OnClick listener for the login button
    //Handles the login request to the server with the email and password fields
    login.setOnClickListener(new View.OnClickListener() {
        @Override
        synchronized public void onClick(View v) {
            String email = editEmail.getText().toString();
            String pass = editPass.getText().toString();

            //If the internet connection is working
            if (checkInternetConnection() == true) {

                if (editEmail.getText().toString().equals("") || editPass.getText().toString().equals("")) {
                    if (editEmail.getText().toString().equals(""))
                        editEmail.setError("Enter your email");
                    if (editPass.getText().toString().equals(""))
                        editPass.setError("Enter your password");
                } else {
                    loadingDialog = ProgressDialog.show(v.getContext(), "Singing In", "Wait a few seconds",
                            true);
                    RequestParams params = new RequestParams();
                    params.put("email", email);
                    params.put("password", pass);

                    //Request of the Piggate object. Handles the login into the application with the user email and password
                    _piggate.RequestOpenSession(params).setListenerRequest(new Piggate.PiggateCallBack() {

                        //Method onComplete for JSONObject
                        //When the request is correct start Activity_Logged activity
                        @Override
                        public void onComplete(int statusCode, Header[] headers, String msg, JSONObject data) {
                            loadingDialog.dismiss();
                            Intent slideactivity = new Intent(Activity_SingIn.this, Activity_Logged.class);
                            slideactivity
                                    .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                            Bundle bndlanimation = ActivityOptions.makeCustomAnimation(getApplicationContext(),
                                    R.anim.slidefromright, R.anim.slidetoleft).toBundle();
                            startActivity(slideactivity, bndlanimation);
                        }

                        //Method onError for JSONObject
                        //If there's an error with the request displays the error message to the user
                        @Override
                        public void onError(int statusCode, Header[] headers, String msg, JSONObject data) {
                            loadingDialog.dismiss();
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    errorDialog.show();
                                }
                            });
                        }

                        //Method onComplete for JSONArray
                        @Override
                        public void onComplete(int statusCode, Header[] headers, String msg, JSONArray data) {
                            //Unused
                        }

                        //Method onError for JSONArray
                        @Override
                        public void onError(int statusCode, Header[] headers, String msg, JSONArray data) {
                            //Unused
                        }
                    }).exec();
                }
            } else { //If the internet connection is not working
                networkErrorDialog.show();
            }
        }
    });
}

From source file:net.idlesoft.android.apps.github.activities.CreateIssue.java

@Override
public void onCreate(final Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.create_issue);

    mPrefs = getSharedPreferences(Hubroid.PREFS_NAME, 0);

    mUsername = mPrefs.getString("username", "");
    mPassword = mPrefs.getString("password", "");

    mGapi.authenticate(mUsername, mPassword);

    final Bundle extras = getIntent().getExtras();
    if (extras != null) {
        if (extras.containsKey("repo_owner")) {
            mRepositoryOwner = extras.getString("repo_owner");
        } else {//w  w  w.ja  va2s .  co m
            mRepositoryOwner = mUsername;
        }
        if (extras.containsKey("repo_name")) {
            mRepositoryName = extras.getString("repo_name");
        }
    } else {
        mRepositoryOwner = mUsername;
    }

    mCreateIssueTask = (CreateIssueTask) getLastNonConfigurationInstance();
    if (mCreateIssueTask == null) {
        mCreateIssueTask = new CreateIssueTask();
    }
    mCreateIssueTask.activity = this;

    if (mCreateIssueTask.getStatus() == AsyncTask.Status.RUNNING) {
        mProgressDialog = ProgressDialog.show(CreateIssue.this, "Please Wait...", "Creating issue...", true);
    }

    ((TextView) findViewById(R.id.tv_page_title)).setText("New Issue");

    ((Button) findViewById(R.id.btn_create_issue_submit)).setOnClickListener(new OnClickListener() {
        public void onClick(final View v) {
            if (mCreateIssueTask.getStatus() == AsyncTask.Status.FINISHED) {
                mCreateIssueTask = new CreateIssueTask();
                mCreateIssueTask.activity = CreateIssue.this;
            }
            if (mCreateIssueTask.getStatus() == AsyncTask.Status.PENDING) {
                mCreateIssueTask.execute();
            }
        }
    });
}

From source file:com.csipsimple.wizards.impl.MondotalkCreate.java

@Override
public void onClick(View v) {
    int id = v.getId();
    if (id == R.id.cancel_bt) {
        setResult(RESULT_CANCELED);//www . j a  v  a 2  s . com
        finish();
    } else if (id == R.id.save_bt) {
        if (canSave()) {
            progressDialog = ProgressDialog.show(this, getResources().getText(R.string.create_account),
                    getResources().getText(R.string.loading), true);
            Thread t = new Thread() {
                public void run() {
                    saveOnline(getEditTextValue(firstName), getEditTextValue(lastName),
                            getEditTextValue(emailAddr), getEditTextValue(phone), getEditTextValue(countryCode),
                            getEditTextValue(captcha));

                };
            };
            t.start();
        }
    }
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    _piggate = new Piggate(this, null); //Initialize the Piggate object

    getSupportActionBar().setTitle("Register");
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);

    setContentView(R.layout.activity_register);
    //EditTexts for user email and password
    editEmail = (EditText) findViewById(R.id.editText1);
    editPass = (EditText) findViewById(R.id.editText2);
    Button register = (Button) findViewById(R.id.buttonregister);

    errorDialog = new AlertDialog.Builder(this).create();
    errorDialog.setTitle("Login error");
    errorDialog.setMessage("There is an error with the login");
    errorDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override//  w w  w . j a  v  a2  s  . c  o  m
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    networkErrorDialog = new AlertDialog.Builder(this).create();
    networkErrorDialog.setTitle("Network error");
    networkErrorDialog.setMessage("There is an error with the network connection");
    networkErrorDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    //OnClick listener for the login button
    //Handles the register request to the server with the email and password fields
    //and the login request if the fields are correct
    register.setOnClickListener(new View.OnClickListener() {
        @Override
        synchronized public void onClick(View v) {
            String email = editEmail.getText().toString();
            String pass = editPass.getText().toString();

            //If the internet connection is working
            if (checkInternetConnection() == true) {

                if (editEmail.getText().toString().equals("") || editPass.getText().toString().equals("")) {
                    if (editEmail.getText().toString().equals(""))
                        editEmail.setError("Enter your email");
                    if (editPass.getText().toString().equals(""))
                        editPass.setError("Enter your password");
                } else {
                    loadingDialog = ProgressDialog.show(v.getContext(), "Singing Up", "Wait a few seconds",
                            true);
                    RequestParams params = new RequestParams();
                    params.put("email", email);
                    params.put("password", pass);

                    //Request of the Piggate object. Handles the register into the application
                    // and the login with the user email and password
                    _piggate.RequestNewUser(params).setListenerRequest(new Piggate.PiggateCallBack() {

                        //Method onComplete for JSONObject
                        //When the request is correct start Activity_Logged activity
                        @Override
                        public void onComplete(int statusCode, Header[] headers, String msg, JSONObject data) {
                            loadingDialog.dismiss();
                            Intent slideactivity = new Intent(Activity_SingUp.this, Activity_Logged.class);
                            slideactivity
                                    .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                            Bundle bndlanimation = ActivityOptions.makeCustomAnimation(getApplicationContext(),
                                    R.anim.slidefromright, R.anim.slidetoleft).toBundle();
                            startActivity(slideactivity, bndlanimation);
                        }

                        //Method onError for JSONObject
                        //If there's an error with the request displays the error message to the user
                        @Override
                        public void onError(int statusCode, Header[] headers, String msg, JSONObject data) {
                            loadingDialog.dismiss();
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    errorDialog.show();
                                }
                            });
                        }

                        //Method onComplete for JSONArray
                        @Override
                        public void onComplete(int statusCode, Header[] headers, String msg, JSONArray data) {
                            //Unused
                        }

                        //Method onError for JSONArray
                        @Override
                        public void onError(int statusCode, Header[] headers, String msg, JSONArray data) {
                            //Unused
                        }
                    }).exec();
                }
            } else { //If the internet connection is not working
                networkErrorDialog.show();
            }
        }
    });
}

From source file:com.applift.api.tester.activity.RequestActivity.java

private void sendRequest(final boolean raw) {
    loadingDialog = ProgressDialog.show(this, null, getString(R.string.loading___), true);
    ///*  w ww.j  a va  2 s  .  co  m*/
    final AdFormat format = nativeResponseRB.isChecked() ? AdFormat.NATIVE : AdFormat.IMAGE;
    AsyncTaskResultListener<JSONObject> resultListener = new AsyncTaskResultListener<JSONObject>() {

        @Override
        public void onAsyncTaskSuccess(JSONObject resp) {
            loadingDialog.dismiss();
            Intent intent = null;
            if (raw) {
                intent = RawResponseActivity.getIntent(RequestActivity.this, resp);
            } else {
                intent = RenderedResponseActivity.getIntent(RequestActivity.this, format, resp);
            }
            startActivity(intent);
        }

        @Override
        public void onAsyncTaskFailure(Exception ex) {
            loadingDialog.dismiss();
            Toast.makeText(RequestActivity.this, ex.getMessage(), Toast.LENGTH_LONG).show();
        }

    };
    AdRequest req = new AdRequest(format);
    req.params.putAll(getParams());
    new GetAdsJSONTask(this, req, resultListener).execute();
}

From source file:com.max2idea.android.fwknop.Fwknop.java

/** Called when the activity is first created. */
@Override//from w w  w . j ava2s. c  o m
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //Installer
    installNativeLibs();

    //Get IPs of client
    progDialog = ProgressDialog.show(activity, "Resolving External IP", "Please wait...", true);
    IPResolver p = new IPResolver();
    p.execute();

    //Setup UI
    this.setContentView(R.layout.main);
    this.setupWidgets();

}

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);//from  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(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: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 ww  w.  j  av  a  2  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(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.progym.custom.fragments.CalloriesProgressMonthlyLineFragment.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  va 2 s.c o  m
    ringProgressDialog.setCancelable(true);
    new Thread(new Runnable() {

        @Override
        public void run() {
            try {

                int yMaxAxisValue = 0;
                try {

                    getActivity().runOnUiThread(new Runnable() {

                        @Override
                        public void run() {
                            rlRootGraphLayout.removeView(mChartView);
                        }
                    });

                } 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 callories = new XYSeries("Callories");

                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
                    int totalCallories = 0;
                    for (Ingridient ingridient : list) {
                        totalCallories += ingridient.kkal;
                    }
                    callories.add(i, totalCallories);
                    dt = DateUtils.addDays(dt, 1);
                    yMaxAxisValue = Math.max(yMaxAxisValue, totalCallories);
                }

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

                // Creating XYSeriesRenderer to customize protein series
                XYSeriesRenderer calloriesRenderer = new XYSeriesRenderer();
                calloriesRenderer.setColor(Color.rgb(220, 255, 110));
                calloriesRenderer.setFillPoints(true);
                calloriesRenderer.setLineWidth(3);
                calloriesRenderer.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("Callories statistic"));
                multiRenderer.setXTitle(Utils.getSpecificDateValue(DATE, "MMM") + " of "
                        + Utils.formatDate(DATE, DataBaseUtils.DATE_PATTERN_YYYY));
                multiRenderer.setYTitle(getActivity().getResources().getString(R.string.callories_consumption));
                multiRenderer.setAxesColor(Color.WHITE);
                multiRenderer.setShowLegend(true);
                multiRenderer.addSeriesRenderer(calloriesRenderer);
                multiRenderer.setShowGrid(true);
                multiRenderer.setClickEnabled(true);
                multiRenderer.setXLabelsAngle(20);
                multiRenderer.setYAxisMax(yMaxAxisValue + 200);
                multiRenderer.setXLabelsColor(Color.WHITE);
                multiRenderer.setZoomButtonsVisible(false);
                // configure visible area
                multiRenderer.setXAxisMax(31);
                multiRenderer.setXAxisMin(1);
                multiRenderer.setAxisTitleTextSize(15);
                multiRenderer.setZoomEnabled(true);

                getActivity().runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        mChartView = ChartFactory.getLineChartView(getActivity(), dataset, multiRenderer);
                        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.cs411.trackallthethings.Scan.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.scan);//from  ww  w.j a v  a  2s . c o m

    //TODO: CHECK IF QR DROID IS INSTALLED

    // launch QR Droid to scan item
    Intent qrDroid = new Intent("la.droid.qr.scan");
    startActivityForResult(qrDroid, 0);

    // set up events for buttons
    Button checkout = (Button) findViewById(R.id.checkoutitem);
    Button returnItem = (Button) findViewById(R.id.returnitem);
    Button scan = (Button) findViewById(R.id.scanagain);
    Button back = (Button) findViewById(R.id.backFromScan);

    back.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            finish();
        }
    });

    scan.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            scannedItem = null;
            TextView scanItemInfo = (TextView) findViewById(R.id.scaniteminfo);
            scanItemInfo.setText("No item scanned... Please scan another item.");
            Intent qrDroid = new Intent("la.droid.qr.scan");
            startActivityForResult(qrDroid, 0);
        }
    });

    checkout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (scannedItem == null)
                return;
            if (scannedItem.getCheckedOutBy() == Main.user_id) {
                Toast.makeText(v.getContext(), "This item is checked out to you already!", 5000).show();
                return;
            }
            // this item is already checked out
            if (scannedItem.getCheckedOutBy() != -1 && scannedItem.getCheckedOutBy() != Main.user_id) {
                Toast.makeText(v.getContext(), "This item is checked out by someone else already!", 5000)
                        .show();
                return;
            }
            // no one has checked this out, so check out the item
            if (scannedItem.getCheckedOutBy() == -1) {
                String item_id = scannedItem.getId();
                checkingOutItem = ProgressDialog.show(scanContext, "", "Checking out item...", true);

                String responseString = "";
                try {
                    HttpGet httpget = new HttpGet(
                            "http://www.trackallthethings.com/mobile-api/check_out_item?user_id=" + Main.user_id
                                    + "&item_id=" + item_id);
                    HttpResponse response;
                    response = Main.httpclient.execute(httpget);
                    HttpEntity entity = response.getEntity();
                    InputStream in = entity.getContent();

                    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
                    StringBuilder sb = new StringBuilder();

                    String input = null;
                    try {
                        while ((input = reader.readLine()) != null) {
                            sb.append(input + "\n");
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    } finally {
                        try {
                            in.close();
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    }
                    //parse the response
                    responseString = sb.toString();
                    in.close();
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }

                if (responseString.contains("SUCCESS")) {
                    checkingOutItem.dismiss();
                    Toast.makeText(v.getContext(), "Item successfully checked out!", 5000).show();
                    scannedItem.setCheckedOut(Main.user_id);
                    return;
                } else {
                    checkingOutItem.dismiss();
                    Toast.makeText(v.getContext(), "The item was not succesfully checked out. :-(", 5000)
                            .show();
                }

            }
        }
    });

    returnItem.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (scannedItem == null)
                return;

            // if it's not checked out
            if (scannedItem.getCheckedOutBy() == -1) {
                Toast.makeText(v.getContext(), "This item has already been returned.", 5000).show();
                return;
            }

            // otherwise return the item
            String item_id = scannedItem.getId();
            returningItem = ProgressDialog.show(scanContext, "", "Returning item...", true);

            String responseString = "";
            try {
                HttpGet httpget = new HttpGet("http://www.trackallthethings.com/mobile-api/return_item?user_id="
                        + Main.user_id + "&item_id=" + item_id);
                HttpResponse response;
                response = Main.httpclient.execute(httpget);
                HttpEntity entity = response.getEntity();
                InputStream in = entity.getContent();

                BufferedReader reader = new BufferedReader(new InputStreamReader(in));
                StringBuilder sb = new StringBuilder();

                String input = null;
                try {
                    while ((input = reader.readLine()) != null) {
                        sb.append(input + "\n");
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                } finally {
                    try {
                        in.close();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
                //parse the response
                responseString = sb.toString();
                in.close();
            } catch (MalformedURLException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

            if (responseString.contains("SUCCESS")) {
                returningItem.dismiss();
                Toast.makeText(v.getContext(), "Item successfully returned!", 5000).show();
                scannedItem.setCheckedOut(-1);
                return;
            } else {
                returningItem.dismiss();
                Toast.makeText(v.getContext(), "The item was not succesfully returned. :-(", 5000).show();
            }
        }
    });

}