0
votes

below are my codes

    public class CalendarView extends Activity {

       ArrayList<String> start_time,end_time;
        String doctor_id ,  hospital_id,da_id,status,date,time_interval,appointment_type,no_of_patient,doctor_name,specialty,hospital_name;
        public GregorianCalendar month, itemmonth;// calendar instances.
        String temp_start,temp_end;
        public CalendarAdapter adapter;// adapter instance
        public Handler handler;// for grabbing some event values for showing the dot
        // marker.
        public ArrayList<String> items,items2; // container to store calendar items which
        // needs showing the event marker
        ProgressDialog pDialog;

    JSONParser jParser = new JSONParser();

    ArrayList<HashMap<String, String>> productsList;

    private static String url_get_appointment = "http://pupqc.net/android_connect/get_appointments.php";

    private static final String TAG_SUCCESS = "success";
    private static final String TAG_APPOINTMENTS = "appointments";
    private static final String TAG_DA_ID = "da_id";
    private static final String TAG_STATUS = "status";
    private static final String TAG_DATE = "date";
    private static final String TAG_START_TIME = "start_time";
    private static final String TAG_END_TIME = "end_time";
    private static final String TAG_TIME_INTERVAL = "time_interval";
    private static final String TAG_APPOINTMENT_TYPE = "appointment_type";
    private static final String TAG_NO_OF_PATIENT = "no_of_patient";
    private static final String TAG_DOCTOR_NAME = "doctor_name";
    private static final String TAG_SPECIALTY = "specialty";
    private static final String TAG_HOSPITAL_NAME = "hospital_name";

    JSONArray products = null;


    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.calendar);
        Locale.setDefault( Locale.US );
        month = (GregorianCalendar) GregorianCalendar.getInstance();
        itemmonth = (GregorianCalendar) month.clone();

        items = new ArrayList<String>();
        items2 = new ArrayList<String>();
        adapter = new CalendarAdapter(this, month);

        GridView gridview = (GridView) findViewById(R.id.gridview);
        gridview.setAdapter(adapter);

        handler = new Handler();
        handler.post(calendarUpdater);


        //Getting Information

        doctor_id=getIntent().getStringExtra("TAG_DOCTOR");
        hospital_id=getIntent().getStringExtra("TAG_HOSPITAL_ID");


        productsList = new ArrayList<HashMap<String, String>>();

        // Loading products in Background Thread
        new LoadAllProducts().execute();


        TextView title = (TextView) findViewById(R.id.title);
        title.setText(android.text.format.DateFormat.format("MMMM yyyy", month));

        RelativeLayout previous = (RelativeLayout) findViewById(R.id.previous);

        previous.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                setPreviousMonth();
                refreshCalendar();
            }
        });

        RelativeLayout next = (RelativeLayout) findViewById(R.id.next);
        next.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                setNextMonth();
                refreshCalendar();

            }
        });

        gridview.setOnItemClickListener(new OnItemClickListener() {
            public void onItemClick(AdapterView<?> parent, View v,
                                    int position, long id) {

                ((CalendarAdapter) parent.getAdapter()).setSelected(v);
                String selectedGridDate = CalendarAdapter.dayString
                        .get(position);
                String[] separatedTime = selectedGridDate.split("-");
                String gridvalueString = separatedTime[2].replaceFirst("^0*",
                        "");// taking last part of date. ie; 2 from 2012-12-02.
                int gridvalue = Integer.parseInt(gridvalueString);
                // navigate to next or previous month on clicking offdays.
                if ((gridvalue > 10) && (position < 8)) {
                    setPreviousMonth();
                    refreshCalendar();
                } else if ((gridvalue < 7) && (position > 28)) {
                    setNextMonth();
                    refreshCalendar();
                }
                ((CalendarAdapter) parent.getAdapter()).setSelected(v);
                pDialog.dismiss();
                if(items2.contains(selectedGridDate)) {
                    Intent i = new Intent(getApplicationContext(),
                            requestconfirmation.class);
                    // Closing all previous activities
                    i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    i.putExtra("date",date);
                    i.putExtra("da_id",TAG_DA_ID);
                    i.putExtra("status",status);
                    i.putExtra("time_interval",time_interval);
                    i.putExtra("appointment_type",appointment_type);
                    i.putExtra("no_of_patient",no_of_patient);
                    i.putExtra("doctor_name",doctor_name);
                    i.putExtra("specialty",specialty);
                    i.putExtra("hospital_name",hospital_name);
                    i.putExtra("start_time",start_time);
                    i.putExtra("end_time",end_time);

                    startActivity(i);
                }
                else {
                    showToast("No Appointment is set in this date.");
                }
            }
        });
    }

    protected void setNextMonth() {
        if (month.get(GregorianCalendar.MONTH) == month
                .getActualMaximum(GregorianCalendar.MONTH)) {
            month.set((month.get(GregorianCalendar.YEAR) + 1),
                    month.getActualMinimum(GregorianCalendar.MONTH), 1);
        } else {
            month.set(GregorianCalendar.MONTH,
                    month.get(GregorianCalendar.MONTH) + 1);
        }

    }

    protected void setPreviousMonth() {
        if (month.get(GregorianCalendar.MONTH) == month
                .getActualMinimum(GregorianCalendar.MONTH)) {
            month.set((month.get(GregorianCalendar.YEAR) - 1),
                    month.getActualMaximum(GregorianCalendar.MONTH), 1);
        } else {
            month.set(GregorianCalendar.MONTH,
                    month.get(GregorianCalendar.MONTH) - 1);
        }

    }

    protected void showToast(String string) {
        Toast.makeText(this, string, Toast.LENGTH_SHORT).show();

    }

    public void refreshCalendar() {
        TextView title = (TextView) findViewById(R.id.title);

        adapter.refreshDays();
        adapter.notifyDataSetChanged();
        handler.post(calendarUpdater); // generate some calendar items

        title.setText(android.text.format.DateFormat.format("MMMM yyyy", month));
    }

    public Runnable calendarUpdater = new Runnable() {

        @Override
        public void run() {
            items.clear();

            // Print dates of the current week
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd",Locale.US);
            String itemvalue;
            for (int i = 0; i < 7; i++) {
                itemvalue = df.format(itemmonth.getTime());
                itemmonth.add(GregorianCalendar.DATE, 1);

            }

            adapter.setItems(items);
            adapter.notifyDataSetChanged();
        }
    };

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        // if result code 100
        if (resultCode == 100) {
            // if result code 100 is received
            // means user edited/deleted product
            // reload this screen again
            Intent intent = getIntent();
            finish();
            startActivity(intent);
        }

    }

    /**
     * Background Async Task to Load all product by making HTTP Request
     * */
    class LoadAllProducts extends AsyncTask<String, String, String> {

        /**
         * Before starting background thread Show Progress Dialog
         * */
        @Override
        protected void onPreExecute() {
            super.onPreExecute();
            pDialog = new ProgressDialog(CalendarView.this);
            pDialog.setMessage("Loading Appointments. Please wait...");
            pDialog.setIndeterminate(false);
            pDialog.setCancelable(false);
            pDialog.show();
        }

        /**
         * getting All products from url
         * */
        protected String doInBackground(String... args) {
            // Building Parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("doctor_id", doctor_id));
            params.add(new BasicNameValuePair("hospital_id", hospital_id));
            // getting JSON string from URL
            JSONObject json = jParser.makeHttpRequest(url_get_appointment, "POST", params);

            // Check your log cat for JSON reponse
            Log.d("All Appointments: ", json.toString());

            try {
                // Checking for SUCCESS TAG
                int success = json.getInt(TAG_SUCCESS);

                if (success == 1) {
                    // products found
                    // Getting Array of Products
                    products = json.getJSONArray(TAG_APPOINTMENTS);
                    items2.clear();
                    // looping through All Products
                    for (int i = 0; i < products.length(); i++) {
                        JSONObject c = products.getJSONObject(i);

                        // Storing each json item in variable
                        date = c.getString(TAG_DATE);
                        da_id = c.getString(TAG_DA_ID);
                        status = c.getString(TAG_STATUS);
                        time_interval=c.getString(TAG_TIME_INTERVAL);
                        appointment_type=c.getString(TAG_APPOINTMENT_TYPE);
                        no_of_patient=c.getString(TAG_NO_OF_PATIENT);
                        doctor_name=c.getString(TAG_DOCTOR_NAME);
                        specialty=c.getString(TAG_SPECIALTY);
                        hospital_name=c.getString(TAG_HOSPITAL_NAME);
                        temp_start = c.getString(TAG_START_TIME);
                        temp_end = c.getString(TAG_END_TIME);
                        // creating new HashMap
                        HashMap<String, String> map = new HashMap<String, String>();

                        // adding each child node to HashMap key => value
                        map.put(TAG_DATE, date);
                        map.put(TAG_DA_ID, da_id);
                        map.put(TAG_STATUS, status);

                        start_time.add(temp_start);
                        end_time.add(temp_end);
                        items2.add(date);

                        // adding HashList to ArrayList
                        productsList.add(map);
                    }

                } else {
                    // no products found
                    // Launch Add New product Activity

                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

            return null;
        }

        /**
         * After completing background task Dismiss the progress dialog
         * **/
        protected void onPostExecute(String file_url) {
            // dismiss the dialog after getting all products
            pDialog.dismiss();
            // updating UI from Background Thread
            runOnUiThread(new Runnable() {
                public void run() {
                    items.clear();

                    // Print dates of the current week
                    DateFormat df = new SimpleDateFormat("yyyy-MM-dd",Locale.US);
                    String itemvalue;
                    for (int i = 0; i < 7; i++) {
                        itemvalue = df.format(itemmonth.getTime());
                        itemmonth.add(GregorianCalendar.DATE, 1);

                    }

                    adapter.setItems(items2);
                    adapter.notifyDataSetChanged();

                }
            });

        }

    }
}

and here is the error

10-30 02:47:02.699 2195-2195/com.srg.ibc.appointmentapplication W/EGL_genymotion﹕ eglSurfaceAttrib not implemented 10-30 02:47:03.075 2195-2195/com.srg.ibc.appointmentapplication E/WindowManager﹕ Activity com.srg.ibc.appointmentapplication.CalendarView has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@53698880 that was originally added here android.view.WindowLeaked: Activity com.srg.ibc.appointmentapplication.CalendarView has leaked window com.android.internal.policy.impl.PhoneWindow$DecorView@53698880 that was originally added here at android.view.ViewRootImpl.(ViewRootImpl.java:374) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:292) at android.view.WindowManagerImpl.addView(WindowManagerImpl.java:224) at android.view.WindowManagerImpl$CompatModeWrapper.addView(WindowManagerImpl.java:149) at android.view.Window$LocalWindowManager.addView(Window.java:547) at android.app.Dialog.show(Dialog.java:277) at com.srg.ibc.appointmentapplication.CalendarView$LoadAllProducts.onPreExecute(CalendarView.java:264) at android.os.AsyncTask.executeOnExecutor(AsyncTask.java:586) at android.os.AsyncTask.execute(AsyncTask.java:534) at com.srg.ibc.appointmentapplication.CalendarView.onCreate(CalendarView.java:100) at android.app.Activity.performCreate(Activity.java:5008) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1079) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2023) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2084) at android.app.ActivityThread.access$600(ActivityThread.java:130) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1195) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:137) at android.app.ActivityThread.main(ActivityThread.java:4745) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:511) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) at dalvik.system.NativeStart.main(Native Method)

Hope you can help me guys. thanks in advance.

2
Just do a search here or at google. Lots of info out there already.Endor

2 Answers

0
votes

Your code might trying to dismiss progress dialog pDialog.dismiss(); after you call finish().

You can just put try catch block around that dismissal procedure .

0
votes

You're trying to show a Dialog after you've exited an Activity.