Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 49f52984 authored by Diogo Ferreira's avatar Diogo Ferreira Committed by Gerrit Code Review
Browse files

protected-apps: don't show a progress dialog for short operations

This code has been ported from a time where devices were much lower
end and currently the operation of writing protected apps state to
permanent storage is really fast. However, the progress dialog would
still flash for a few milliseconds but it is in fact useless since the
user cannot read it and will only see it flash.

This patch delays showing the dialog for 50ms which will ensure that
modern devices won't actually show it but slower devices will still
see it.

Change-Id: I43c347822d205bd930912ea5c03951e2abb9354d
parent 26fe05e0
Loading
Loading
Loading
Loading
+14 −1
Original line number Diff line number Diff line
@@ -13,6 +13,8 @@ import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import android.view.LayoutInflater;
import android.view.Menu;
@@ -261,8 +263,11 @@ public class ProtectedAppsActivity extends Activity {
    }

    public class StoreComponentProtectedStatus extends AsyncTask<AppProtectList, Void, Void> {
        private static final int SHOW_SAVE_PROGRESS_THRESHOLD_MS = 50;

        private ProgressDialog mDialog;
        private Context mContext;
        private Handler mDialogHandler = new Handler(Looper.getMainLooper());

        public StoreComponentProtectedStatus(Context context) {
            mContext = context;
@@ -274,11 +279,19 @@ public class ProtectedAppsActivity extends Activity {
            mDialog.setMessage(getResources().getString(R.string.saving_protected_components));
            mDialog.setCancelable(false);
            mDialog.setCanceledOnTouchOutside(false);

            mDialogHandler.postDelayed(new Runnable() {
                @Override
                public void run() {
                    mDialog.show();
                }
            }, SHOW_SAVE_PROGRESS_THRESHOLD_MS);
        }

        @Override
        protected void onPostExecute(Void aVoid) {
            mDialogHandler.removeCallbacksAndMessages(null);

            if (mDialog.isShowing()) {
                mDialog.dismiss();
            }