package kr.co.compcarecompany.Util;

import android.app.Activity;
import android.widget.Toast;

public class BackPressCloseHandler {

    public long backKeyPressedTime = 0;
    private Toast toast;

    private Activity activity;

    public BackPressCloseHandler(Activity activity) {
        this.activity = activity;
    }

    public void onBackPressed() {
        if (System.currentTimeMillis() > backKeyPressedTime + 2000) {
            backKeyPressedTime = System.currentTimeMillis();
            Common.getInstance().toastShow(activity, "\'뒤로 가기\'버튼을 한번 더 누르시면 종료됩니다.");
            return;
        }
        if (System.currentTimeMillis() <= backKeyPressedTime + 2000) {
            activity.moveTaskToBack(true);
            android.os.Process.killProcess(android.os.Process.myPid());
            toast.cancel();
        }
    }
}
