Example usage for android.os Handler postDelayed

List of usage examples for android.os Handler postDelayed

Introduction

In this page you can find the example usage for android.os Handler postDelayed.

Prototype

public final boolean postDelayed(Runnable r, long delayMillis) 

Source Link

Document

Causes the Runnable r to be added to the message queue, to be run after the specified amount of time elapses.

Usage

From source file:com.carapp.login.splashActivity.java

private void getClientBranch() {

    MultipartEntity entity = new MultipartEntity();
    try {/*from w w  w .  jav  a2 s.  co  m*/
        entity.addPart("action", new StringBody("init_config"));

        new AsyncWebServiceProcessingTask(context, entity, messagecheck, new AsynckCallback() {

            @Override
            public void run(String result) {
                if (UIUtils.checkJson(result, context)) {
                    try {
                        JSONObject jsonObject = new JSONObject(result);
                        if (jsonObject.optString("satus").equals("success")) {
                            PdfInfo.client = jsonObject.optString("client");
                            PdfInfo.branch = jsonObject.optString("branch");
                            Util.showCustomDialogWithoutButton(context, "Message", messagechecksucces,
                                    new Callback2() {
                                        @Override
                                        public void ok(final Dialog dialog) {
                                            final Handler handler = new Handler();
                                            final Runnable runnable = new Runnable() {
                                                @Override
                                                public void run() {
                                                    dialog.dismiss();
                                                    new AsyncWebServiceProcessingTask(context, null,
                                                            "Please wait while checking date",
                                                            new AsynckCallback() {

                                                                @Override
                                                                public void run(String result) {
                                                                    Log.e("date", "" + result);
                                                                    String sysdate = android.text.format.DateFormat
                                                                            .format("dd/MM/yyyy",
                                                                                    new java.util.Date())
                                                                            .toString();
                                                                    if (result.equals(sysdate)) {
                                                                        Toast.makeText(context, "date match",
                                                                                Toast.LENGTH_SHORT).show();
                                                                        new AsyncWebServiceProcessingTask(
                                                                                context, null, messagecheckday,
                                                                                new AsynckCallback() {
                                                                                    @Override
                                                                                    public void run(
                                                                                            String result) {
                                                                                        int day = Integer
                                                                                                .parseInt(
                                                                                                        result);
                                                                                        Calendar calendar = Calendar
                                                                                                .getInstance();
                                                                                        int Today = calendar
                                                                                                .get(Calendar.DAY_OF_WEEK);
                                                                                        day++;
                                                                                        if (day == Today) {
                                                                                            Toast.makeText(
                                                                                                    context,
                                                                                                    "day is correct",
                                                                                                    Toast.LENGTH_SHORT)
                                                                                                    .show();
                                                                                            String ma_a = null;

                                                                                            try {
                                                                                                WifiManager wiman = (WifiManager) getSystemService(
                                                                                                        Context.WIFI_SERVICE);
                                                                                                ma_a = wiman
                                                                                                        .getConnectionInfo()
                                                                                                        .getMacAddress();
                                                                                                Log.i(t, ""
                                                                                                        + ma_a);
                                                                                            } catch (Exception e1) {

                                                                                                e1.printStackTrace();
                                                                                                Log.i(t, " "
                                                                                                        + e1);
                                                                                            }
                                                                                            MultipartEntity entity = new MultipartEntity();
                                                                                            try {
                                                                                                entity.addPart(
                                                                                                        "action",
                                                                                                        new StringBody(
                                                                                                                "device_authentication"));
                                                                                                entity.addPart(
                                                                                                        "mac_address",
                                                                                                        new StringBody(
                                                                                                                ma_a));
                                                                                                new AsyncWebServiceProcessingTask(
                                                                                                        context,
                                                                                                        entity,
                                                                                                        "Checking License",
                                                                                                        new AsynckCallback() {

                                                                                                            @Override
                                                                                                            public void run(
                                                                                                                    String result) {

                                                                                                                if (UIUtils
                                                                                                                        .checkJson(
                                                                                                                                result,
                                                                                                                                context)) {
                                                                                                                    try {
                                                                                                                        JSONObject jsonObject = new JSONObject(
                                                                                                                                result);
                                                                                                                        if (jsonObject
                                                                                                                                .optString(
                                                                                                                                        "satus")
                                                                                                                                .equals("success")) {
                                                                                                                            Toast.makeText(
                                                                                                                                    context,
                                                                                                                                    "LicenseCheck sucesses",
                                                                                                                                    Toast.LENGTH_SHORT)
                                                                                                                                    .show();
                                                                                                                            startActivity(
                                                                                                                                    new Intent(
                                                                                                                                            context,
                                                                                                                                            LoginActivity.class));
                                                                                                                            finish();

                                                                                                                        } else if (jsonObject
                                                                                                                                .optString(
                                                                                                                                        "satus")
                                                                                                                                .equals("error")) {
                                                                                                                            Util.showCustomDialog(
                                                                                                                                    context,
                                                                                                                                    "Error",
                                                                                                                                    jsonObject
                                                                                                                                            .optString(
                                                                                                                                                    "msg"));

                                                                                                                        }

                                                                                                                    } catch (Exception e) {

                                                                                                                        e.printStackTrace();

                                                                                                                    }

                                                                                                                }
                                                                                                            }
                                                                                                        }).execute(
                                                                                                                PdfInfo.newjobcard);

                                                                                            } catch (Exception e) {

                                                                                                e.printStackTrace();
                                                                                            }

                                                                                        } else {
                                                                                            Util.showCustomDialogWithoutButton(
                                                                                                    context,
                                                                                                    "Error",
                                                                                                    messagecheckdayerror
                                                                                                            + " server day is "
                                                                                                            + day
                                                                                                            + " but your device is"
                                                                                                            + Today,
                                                                                                    new Callback2() {

                                                                                                        @Override
                                                                                                        public void ok(
                                                                                                                final Dialog dialog) {

                                                                                                            final Handler handler = new Handler();
                                                                                                            final Runnable runnable = new Runnable() {
                                                                                                                @Override
                                                                                                                public void run() {
                                                                                                                    dialog.dismiss();
                                                                                                                    finish();
                                                                                                                }
                                                                                                            };
                                                                                                            handler.postDelayed(
                                                                                                                    runnable,
                                                                                                                    5000);

                                                                                                        }
                                                                                                    });
                                                                                        }

                                                                                    }
                                                                                }).execute(PdfInfo.dayaddress);
                                                                    } else {

                                                                        Util.showCustomDialogWithoutButton(
                                                                                context, "Error",
                                                                                messagecheckdateerror
                                                                                        + " server date is "
                                                                                        + result
                                                                                        + " but device date is "
                                                                                        + sysdate,
                                                                                new Callback2() {

                                                                                    @Override
                                                                                    public void ok(
                                                                                            final Dialog dialog) {

                                                                                        new Timer().schedule(
                                                                                                new TimerTask() {

                                                                                                    @Override
                                                                                                    public void run() {
                                                                                                        dialog.dismiss();
                                                                                                        finish();

                                                                                                    }
                                                                                                }, 5000);
                                                                                    }
                                                                                });

                                                                    }
                                                                }
                                                            }).execute(PdfInfo.dateaddress);

                                                }
                                            };
                                            handler.postDelayed(runnable, 5000);

                                        }
                                    });

                        } else if (jsonObject.optString("satus").equals("error")) {
                            Util.showCustomDialogWithoutButton(context, "Message", messagechecksucces,
                                    new Callback2() {

                                        @Override
                                        public void ok(final Dialog dialog) {

                                            new Timer().schedule(new TimerTask() {

                                                @Override
                                                public void run() {
                                                    dialog.dismiss();
                                                    finish();

                                                }
                                            }, 5000);
                                        }
                                    });

                        }

                    } catch (Exception e) {

                        e.printStackTrace();

                    }

                }
            }
        }).execute(PdfInfo.newjobcard);

    } catch (Exception e) {

        e.printStackTrace();
    }

}