pkleczko/CustomGauge

How to refresh

Closed this issue · 9 comments

Hi I have there drop downs one today tomorrow and yesterday once click today I got data from API I showed to the progress bar when going to second tomorrow it will load once I back to today data is not refreshed

Hi I am using fragment in that fragment I used the spinner in if I select one position I set values to gauge if I select two positions I set monthly values when back to the first position that gauge does not refresh how to do this

Hi Paweł Kleczkowski,

Please find attached screen shot and code here if select Spinner item one I got results from the server when going to the second item I got results updated but when go back to one guage not updated results

device-2018-08-07-112327
device-2018-08-07-112404
device-2018-08-07-112404

package com.example.bizsense004.qdos.fragments;

import android.app.ProgressDialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.CardView;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.android.volley.Request;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.VolleyLog;
import com.android.volley.toolbox.JsonObjectRequest;
import com.app.progresviews.ProgressWheel;
import com.example.bizsense004.qdos.Actvityviewgraph;
import com.example.bizsense004.qdos.Customerviewgraph;
import com.example.bizsense004.qdos.LocationTimeview;
import com.example.bizsense004.qdos.R;
import com.example.bizsense004.qdos.Timespent;
import com.example.bizsense004.qdos.VisitRearongraph;
import com.example.bizsense004.qdos.app_config.AppController;
import com.example.bizsense004.qdos.app_config.utils;
import com.example.bizsense004.qdos.beans.Data;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import pl.pawelkleczkowski.customgauge.CustomGauge;

import static com.android.volley.VolleyLog.TAG;
import static com.example.bizsense004.qdos.fragments.Homefragment.PREF_NAME;

public class Dashboardfragment extends Fragment{
private CustomGauge pg1,pg2,pg3;
Spinner spinner;
private int pStatus = 0;
private Handler handler = new Handler();
String dashboard="";
String WeeknlyID="1";
String MonthlyID="2";
String YearlyID="3";
String RUname="";
String MonthlyCount="";
String YearyCount="";
String Weeklyqdosrating="";
String Weeklytimecheckin="";
String WeeklyCount="";
String MonthlyCountqdos="";
String MonthlyCounttime="";
String YearyCountqdos="";
String YearyCounttimecheckin="";
JSONObject jsonBody;
Handler handler1 = new Handler();
Runnable refresh;

int Weeknlyvisitvalue;
int Weeklyqdosvalue;
int Weeklytimecheckinvalue;
int monthlyvisitvalue;
int monthlyqdosvalue;
int monthlytimecheckinvalue;
int convertedVal;
int convertedVal1;
int convertedVal11;
int  Nooftotal;
int Nofvisits;
int timecheckin;
int c=0,q=0;
int per=0;
int qdoscheckin;
public Dashboardfragment() {
    // Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
                         Bundle savedInstanceState) {
    SharedPreferences setting = getActivity().getApplicationContext().getSharedPreferences("MyPrefss", 0);
    RUname = setting.getString("USEREMAIL", "Not found!");
    // Inflate the layout for this fragment
    SharedPreferences settings=getActivity().getSharedPreferences(PREF_NAME,0);
    WeeklyCount=settings.getString("weelycount", WeeklyCount);
    Weeklyqdosrating=settings.getString("weelycountqdos",Weeklyqdosrating);
    Weeklytimecheckin=settings.getString("weelycounttime",Weeklytimecheckin);
    MonthlyCount=settings.getString("monthlycount",MonthlyCount);
    MonthlyCountqdos=settings.getString("monthlycountqdos",MonthlyCountqdos);
    MonthlyCounttime=settings.getString("monthlycounttimecheckin",MonthlyCounttime);
    YearyCount=settings.getString("yearlycount",YearyCount);
    YearyCountqdos=settings.getString("yearlycountqdos",YearyCountqdos);
    YearyCounttimecheckin=settings.getString("yearlycounttimecheckin",YearyCounttimecheckin);
    View rootView = inflater.inflate(R.layout.dashboardfragment, container, false);
     pg1=(CustomGauge)rootView.findViewById(R.id.gauge);

pg2=(CustomGauge)rootView.findViewById(R.id.gauge1);
pg3=(CustomGauge)rootView.findViewById(R.id.gauge2);
final TextView visits=(TextView)rootView.findViewById(R.id.visitsno);
final TextView qdostating=(TextView)rootView.findViewById(R.id.qdosvalue);
final TextView timecheckin=(TextView)rootView.findViewById(R.id.timecheckinvalue);

    try {
        Weeknlyvisitvalue = Integer.parseInt(WeeklyCount);



    }catch (NumberFormatException e){
        System.out.print(e);
    }

    try {
        Weeklyqdosvalue = Integer.parseInt(Weeklyqdosrating);



    }catch (NumberFormatException e){
        System.out.print(e);
    }
    try {
        Weeklytimecheckinvalue = (int) Double.parseDouble(Weeklytimecheckin);



    }catch (NumberFormatException e){
        System.out.print(e);
    }

    try {
        monthlyvisitvalue = Integer.parseInt(MonthlyCount);



    }catch (NumberFormatException e){
        System.out.print(e);
    }

    try {
        monthlyqdosvalue = Integer.parseInt(MonthlyCountqdos);



    }catch (NumberFormatException e){
        System.out.print(e);
    }
    try {
        monthlytimecheckinvalue = (int) Double.parseDouble(MonthlyCounttime);



    }catch (NumberFormatException e){
        System.out.print(e);
    }
    try {
        convertedVal = Integer.parseInt(YearyCount);



    }catch (NumberFormatException e){
        System.out.print(e);
    }

    try {
        convertedVal1 = Integer.parseInt(YearyCountqdos);



    }catch (NumberFormatException e){
        System.out.print(e);
    }
    try {
        convertedVal11 = (int) Double.parseDouble(YearyCounttimecheckin);



    }catch (NumberFormatException e){
        System.out.print(e);
    }
    spinner=(Spinner)rootView.findViewById(R.id.Spidas);
    List<String> view=new ArrayList<>();
    view.add("Weekly");
    view.add("Monthly");
    view.add("Yearly");
    ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(getActivity(), R.layout.spinner_item, view);

    // Drop down layout style - list view with radio button
    dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    // attaching data adapter to spinner
    spinner.setAdapter(dataAdapter);
    spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            getweekly(WeeknlyID);
            getmonthly(MonthlyID);
            getyearly(YearlyID);
            dashboard = parent.getSelectedItem().toString();
            Toast.makeText(parent.getContext(), "Selected Country : " + parent.getItemAtPosition(position).toString(), Toast.LENGTH_SHORT).show();
            if (parent.getItemAtPosition(position).equals("Weekly")) {

                new Thread(new Runnable() {
                    @Override
                    public void run() {


                        while (pStatus <= Weeknlyvisitvalue) {
                            handler.post(new Runnable() {
                                @Override
                                public void run() {

                                    pg1.setValue(pStatus);


                                }
                            });
                            try {
                                Thread.sleep(25);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                            pStatus++;
                        }

                    }
                }).start();
                new Thread(new Runnable() {
                    @Override
                    public void run() {

                        while(pStatus<=Weeklyqdosvalue){
                            handler.post(new Runnable() {
                                @Override
                                public void run() {
                                    pg2.setValue(pStatus);
                                }
                            });
                            try {
                                Thread.sleep(25);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                            pStatus++;
                        }
                    }
                }).start();
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        // int Nofvisits=convertedVal*100;
                        //  final int Nooftotal=Nofvisits/100;
                        while(pStatus<=Weeklytimecheckinvalue){
                            handler.post(new Runnable() {
                                @Override
                                public void run() {
                                    pg3.setValue(pStatus);

                                  //  Toast.makeText(getActivity(),"value"+pStatus,Toast.LENGTH_SHORT).show();
                                }
                            });
                            try {
                                Thread.sleep(25);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                            pStatus++;
                        }
                    }
                }).start();
                visits.setText(WeeklyCount);
                qdostating.setText(Weeklyqdosrating);
                timecheckin.setText(Weeklytimecheckin);

            }else if (parent.getItemAtPosition(position).equals("Monthly")) {
                getweekly(WeeknlyID);
                getmonthly(MonthlyID);
                getyearly(YearlyID);
                new Thread(new Runnable() {
                    @Override
                    public void run() {


                        while (pStatus <= monthlyvisitvalue) {
                            handler.post(new Runnable() {
                                @Override
                                public void run() {
                                    pg1.setValue(pStatus);



                                    //Toast.makeText(getActivity(),"value"+pStatus,Toast.LENGTH_SHORT).show();
                                }
                            });
                            try {
                                Thread.sleep(25);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                            pStatus++;
                        }



                    }
                }).start();
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        // int Nofvisits=convertedVal*100;
                        //  final int Nooftotal=Nofvisits/100;
                        while(pStatus<=monthlyqdosvalue){
                            handler.post(new Runnable() {
                                @Override
                                public void run() {
                                    pg2.setValue(pStatus);


                                    //Toast.makeText(getActivity(),"value"+pStatus,Toast.LENGTH_SHORT).show();
                                }
                            });
                            try {
                                Thread.sleep(25);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                            pStatus++;
                        }
                    }
                }).start();
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        // int Nofvisits=convertedVal*100;
                        //  final int Nooftotal=Nofvisits/100;
                        while(pStatus<=monthlytimecheckinvalue){
                            handler.post(new Runnable() {
                                @Override
                                public void run() {
                                    pg3.setValue(pStatus);

                                   // Toast.makeText(getActivity(),"value"+pStatus,Toast.LENGTH_SHORT).show();
                                }
                            });
                            try {
                                Thread.sleep(25);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                            pStatus++;
                        }
                    }
                }).start();
                visits.setText(MonthlyCount);
                qdostating.setText(MonthlyCountqdos);
                timecheckin.setText(MonthlyCounttime);
            }
            else if (parent.getItemAtPosition(position).equals("Yearly")){
                getweekly(WeeknlyID);
                getmonthly(MonthlyID);
                getyearly(YearlyID);
                new Thread(new Runnable() {
                    @Override
                    public void run() {


                        while (pStatus <= convertedVal) {
                            handler.post(new Runnable() {
                                @Override
                                public void run() {
                                    pg1.setValue(pStatus);
                                    //Toast.makeText(getActivity(),"value"+pStatus,Toast.LENGTH_SHORT).show();
                                }
                            });
                            try {
                                Thread.sleep(25);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                            pStatus++;
                        }

                    }
                }).start();
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        // int Nofvisits=convertedVal*100;
                        //  final int Nooftotal=Nofvisits/100;
                        while(pStatus<=convertedVal1){
                            handler.post(new Runnable() {
                                @Override
                                public void run() {
                                    pg2.setValue(pStatus);
                                    //Toast.makeText(getActivity(),"value"+pStatus,Toast.LENGTH_SHORT).show();
                                }
                            });
                            try {
                                Thread.sleep(25);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                            pStatus++;
                        }
                    }
                }).start();
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        // int Nofvisits=convertedVal*100;
                        //  final int Nooftotal=Nofvisits/100;
                        while(pStatus<=convertedVal11){
                            handler.post(new Runnable() {
                                @Override
                                public void run() {
                                    pg3.setValue(pStatus);
                                    //Toast.makeText(getActivity(),"value"+pStatus,Toast.LENGTH_SHORT).show();
                                }
                            });
                            try {
                                Thread.sleep(25);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                            }
                            pStatus++;
                        }
                    }
                }).start();
                visits.setText(YearyCount);
                qdostating.setText(YearyCountqdos);
                timecheckin.setText(YearyCounttimecheckin);
            }



        }
        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    return rootView;
}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // Do something that differs the Activity's menu here
    super.onCreateOptionsMenu(menu, inflater);


}


private void getyearly(String yearlyID) {
    final ProgressDialog pDialog = new ProgressDialog(getActivity());

    pDialog.setMessage("Loading...");
    pDialog.show();




    {
        try {
            jsonBody = new JSONObject();

       /*     jsonBody.put("latitude", lat);
            jsonBody.put("longitude", lang);*/
            jsonBody.put("id", YearlyID);



      /*      jsonBody.put("starttime", StartTime);
            jsonBody.put("endtime", EndTime);
            jsonBody.put("reflection", Compid);

*/
} catch (JSONException e) {
e.printStackTrace();
}
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
utils.DashboardPOstyearly+RUname, jsonBody,
new Response.Listener() {
@OverRide
public void onResponse(JSONObject response) {
Log.d(TAG, response.toString());
pDialog.hide();
JSONObject data = null;
try {
data = new JSONObject(String.valueOf(response));
} catch (JSONException e) {
e.printStackTrace();
}
try {
YearyCount = data.getString("Meeting").toString().trim();
YearyCountqdos = data.getString("Rating").toString().trim();
YearyCounttimecheckin = data.getString("checked-In").toString().trim();
} catch (JSONException e) {
e.printStackTrace();
}
SharedPreferences settings = getActivity().getSharedPreferences(PREF_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("yearlycount",YearyCount );
editor.putString("yearlycountqdos",YearyCountqdos );
editor.putString("yearlycounttimecheckin",YearyCounttimecheckin );
// System.out.println("userId..." + Count);
editor.commit();
}

                }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {


                VolleyLog.d(TAG, "Error: " + error.getMessage());
                pDialog.hide();
            }
        }) {

            @Override
            protected Map<String, String> getParams() {
                Map<String, String> params = new HashMap<String, String>();

                return params;
            }

        };
        AppController.getInstance().addToRequestQueue(jsonObjReq);
    }

}

private void getmonthly(String monthlyID) {
    final ProgressDialog pDialog = new ProgressDialog(getActivity());
    pDialog.setMessage("Loading...");
    pDialog.show();


    {
        try {
            jsonBody = new JSONObject();

       /*     jsonBody.put("latitude", lat);
            jsonBody.put("longitude", lang);*/
            jsonBody.put("id", MonthlyID);



      /*      jsonBody.put("starttime", StartTime);
            jsonBody.put("endtime", EndTime);
            jsonBody.put("reflection", Compid);

*/
} catch (JSONException e) {
e.printStackTrace();
}
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
utils.DashboardPOstMonthly+RUname, jsonBody,
new Response.Listener() {
@OverRide
public void onResponse(JSONObject response) {
Log.d(TAG, response.toString());
pDialog.hide();
JSONObject data = null;
try {
data = new JSONObject(String.valueOf(response));
} catch (JSONException e) {
e.printStackTrace();
}
try {
MonthlyCount = data.getString("Meeting").toString().trim();
MonthlyCountqdos = data.getString("Rating").toString().trim();
MonthlyCounttime = data.getString("checked-In").toString().trim();
} catch (JSONException e) {
e.printStackTrace();
}
SharedPreferences settings = getActivity().getSharedPreferences(PREF_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("monthlycount",MonthlyCount );
editor.putString("monthlycountqdos",MonthlyCountqdos );
editor.putString("monthlycounttimecheckin",MonthlyCounttime );
// System.out.println("userId..." + Count);
editor.commit();
}

                }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {


                VolleyLog.d(TAG, "Error: " + error.getMessage());
                pDialog.hide();
            }
        }) {

            @Override
            protected Map<String, String> getParams() {
                Map<String, String> params = new HashMap<String, String>();

                return params;
            }

        };
        AppController.getInstance().addToRequestQueue(jsonObjReq);
    }
}

private void getweekly(String weeknlyID) {
  /*  final ProgressDialog pDialog = new ProgressDialog(getActivity());
    pDialog.setMessage("Loading...");
    pDialog.show();*/


    {
        try {
            jsonBody = new JSONObject();

       /*     jsonBody.put("latitude", lat);
            jsonBody.put("longitude", lang);*/
            jsonBody.put("id", WeeknlyID);



      /*      jsonBody.put("starttime", StartTime);
            jsonBody.put("endtime", EndTime);
            jsonBody.put("reflection", Compid);

*/
} catch (JSONException e) {
e.printStackTrace();
}
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
utils.DashboardPOstWeekly+RUname, jsonBody,
new Response.Listener() {
@OverRide
public void onResponse(JSONObject response) {
Log.d(TAG, response.toString());
// pDialog.hide();
JSONObject data = null;
try {
data = new JSONObject(String.valueOf(response));
} catch (JSONException e) {
e.printStackTrace();
}
try {
WeeklyCount= data.getString("Meeting").toString().trim();
Weeklyqdosrating=data.getString("Rating").toString();
Weeklytimecheckin=data.getString("checked-In").toString();
} catch (JSONException e) {
e.printStackTrace();
}
SharedPreferences settings = getActivity().getSharedPreferences(PREF_NAME, 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("weelycount",WeeklyCount );
editor.putString("weelycountqdos",Weeklyqdosrating );
editor.putString("weelycounttime",Weeklytimecheckin );
// System.out.println("userId..." + Count);
editor.commit();
}

                }, new Response.ErrorListener() {

            @Override
            public void onErrorResponse(VolleyError error) {


                VolleyLog.d(TAG, "Error: " + error.getMessage());
               // pDialog.hide();
            }
        }) {

            @Override
            protected Map<String, String> getParams() {
                Map<String, String> params = new HashMap<String, String>();

                return params;
            }

        };
        AppController.getInstance().addToRequestQueue(jsonObjReq);
    }
}
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
}
@Override
public void onPrepareOptionsMenu(Menu menu) {
    menu.findItem(R.id.add).setVisible(false);
    menu.findItem(R.id.app_bar_menu_search).setVisible(false);
    super.onPrepareOptionsMenu(menu);
}
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    getActivity().setTitle("Dashboard");

}

}

i did same whatever you said but that gauge value once you data update next time click that gauge is not refreshed tell one thing how refresh guage

HI how to overlap guage if it is more than 100 values how show

HI how to overlap guage if it is more than 100 values how show