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

Commit 6b860590 authored by Fabian Kozynski's avatar Fabian Kozynski Committed by Android (Google) Code Review
Browse files

Merge "Prevent NPE in DateView"

parents 75aa043d 52b8b9e0
Loading
Loading
Loading
Loading
+9 −2
Original line number Original line Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.IntentFilter;
import android.content.res.TypedArray;
import android.content.res.TypedArray;
import android.icu.text.DateFormat;
import android.icu.text.DateFormat;
import android.icu.text.DisplayContext;
import android.icu.text.DisplayContext;
import android.os.Handler;
import android.text.TextUtils;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.widget.TextView;
import android.widget.TextView;
@@ -47,6 +48,12 @@ public class DateView extends TextView {
    private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
    private BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
        @Override
        @Override
        public void onReceive(Context context, Intent intent) {
        public void onReceive(Context context, Intent intent) {
            // If the handler is null, it means we received a broadcast while the view has not
            // finished being attached or in the process of being detached.
            // In that case, do not post anything.
            Handler handler = getHandler();
            if (handler == null) return;

            final String action = intent.getAction();
            final String action = intent.getAction();
            if (Intent.ACTION_TIME_TICK.equals(action)
            if (Intent.ACTION_TIME_TICK.equals(action)
                    || Intent.ACTION_TIME_CHANGED.equals(action)
                    || Intent.ACTION_TIME_CHANGED.equals(action)
@@ -55,9 +62,9 @@ public class DateView extends TextView {
                if (Intent.ACTION_LOCALE_CHANGED.equals(action)
                if (Intent.ACTION_LOCALE_CHANGED.equals(action)
                        || Intent.ACTION_TIMEZONE_CHANGED.equals(action)) {
                        || Intent.ACTION_TIMEZONE_CHANGED.equals(action)) {
                    // need to get a fresh date format
                    // need to get a fresh date format
                    getHandler().post(() -> mDateFormat = null);
                    handler.post(() -> mDateFormat = null);
                }
                }
                getHandler().post(() -> updateClock());
                handler.post(() -> updateClock());
            }
            }
        }
        }
    };
    };