Merge "Update date during time tick event" into pi-dev

am: e22a7bc9d4

Change-Id: I843ec43c885efa2e93a9f53e83dd57c45ad6e6ea
This commit is contained in:
Lucas Dupin
2018-05-07 15:02:31 -07:00
committed by android-build-merger
7 changed files with 95 additions and 32 deletions

View File

@@ -57,6 +57,7 @@ import java.util.function.Consumer;
import androidx.slice.Slice; import androidx.slice.Slice;
import androidx.slice.SliceItem; import androidx.slice.SliceItem;
import androidx.slice.SliceManager;
import androidx.slice.core.SliceQuery; import androidx.slice.core.SliceQuery;
import androidx.slice.widget.ListContent; import androidx.slice.widget.ListContent;
import androidx.slice.widget.RowContent; import androidx.slice.widget.RowContent;
@@ -390,6 +391,11 @@ public class KeyguardSliceView extends LinearLayout implements View.OnClickListe
} }
} }
public void refresh() {
Slice slice = SliceManager.getInstance(getContext()).bindSlice(mKeyguardSliceUri);
onChanged(slice);
}
public static class Row extends LinearLayout { public static class Row extends LinearLayout {
/** /**

View File

@@ -287,7 +287,12 @@ public class KeyguardStatusView extends GridLayout implements
} }
} }
public void refreshTime() { public void dozeTimeTick() {
refreshTime();
mKeyguardSlice.refresh();
}
private void refreshTime() {
mClockView.refresh(); mClockView.refresh();
} }

View File

@@ -79,7 +79,6 @@ public class KeyguardSliceProvider extends SliceProvider implements
private DateFormat mDateFormat; private DateFormat mDateFormat;
private String mLastText; private String mLastText;
private boolean mRegistered; private boolean mRegistered;
private boolean mRegisteredEveryMinute;
private String mNextAlarm; private String mNextAlarm;
private NextAlarmController mNextAlarmController; private NextAlarmController mNextAlarmController;
protected AlarmManager mAlarmManager; protected AlarmManager mAlarmManager;
@@ -175,7 +174,7 @@ public class KeyguardSliceProvider extends SliceProvider implements
mZenModeController = new ZenModeControllerImpl(getContext(), mHandler); mZenModeController = new ZenModeControllerImpl(getContext(), mHandler);
mZenModeController.addCallback(this); mZenModeController.addCallback(this);
mDatePattern = getContext().getString(R.string.system_ui_aod_date_pattern); mDatePattern = getContext().getString(R.string.system_ui_aod_date_pattern);
registerClockUpdate(false /* everyMinute */); registerClockUpdate();
updateClock(); updateClock();
return true; return true;
} }
@@ -214,22 +213,13 @@ public class KeyguardSliceProvider extends SliceProvider implements
/** /**
* Registers a broadcast receiver for clock updates, include date, time zone and manually * Registers a broadcast receiver for clock updates, include date, time zone and manually
* changing the date/time via the settings app. * changing the date/time via the settings app.
*
* @param everyMinute {@code true} if you also want updates every minute.
*/ */
protected void registerClockUpdate(boolean everyMinute) { private void registerClockUpdate() {
if (mRegistered) { if (mRegistered) {
if (mRegisteredEveryMinute == everyMinute) { return;
return;
} else {
unregisterClockUpdate();
}
} }
IntentFilter filter = new IntentFilter(); IntentFilter filter = new IntentFilter();
if (everyMinute) {
filter.addAction(Intent.ACTION_TIME_TICK);
}
filter.addAction(Intent.ACTION_DATE_CHANGED); filter.addAction(Intent.ACTION_DATE_CHANGED);
filter.addAction(Intent.ACTION_TIME_CHANGED); filter.addAction(Intent.ACTION_TIME_CHANGED);
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
@@ -237,15 +227,6 @@ public class KeyguardSliceProvider extends SliceProvider implements
getContext().registerReceiver(mIntentReceiver, filter, null /* permission*/, getContext().registerReceiver(mIntentReceiver, filter, null /* permission*/,
null /* scheduler */); null /* scheduler */);
mRegistered = true; mRegistered = true;
mRegisteredEveryMinute = everyMinute;
}
protected void unregisterClockUpdate() {
if (!mRegistered) {
return;
}
getContext().unregisterReceiver(mIntentReceiver);
mRegistered = false;
} }
@VisibleForTesting @VisibleForTesting

View File

@@ -2267,7 +2267,7 @@ public class NotificationPanelView extends PanelView implements
} }
public void onScreenTurningOn() { public void onScreenTurningOn() {
mKeyguardStatusView.refreshTime(); mKeyguardStatusView.dozeTimeTick();
} }
@Override @Override
@@ -2690,7 +2690,7 @@ public class NotificationPanelView extends PanelView implements
} }
public void dozeTimeTick() { public void dozeTimeTick() {
mKeyguardStatusView.refreshTime(); mKeyguardStatusView.dozeTimeTick();
mKeyguardBottomArea.dozeTimeTick(); mKeyguardBottomArea.dozeTimeTick();
if (mDarkAmount > 0) { if (mDarkAmount > 0) {
positionClockAndNotifications(); positionClockAndNotifications();

View File

@@ -89,6 +89,17 @@ public class KeyguardSliceViewTest extends SysuiTestCase {
Assert.assertTrue("View should have a header", mKeyguardSliceView.hasHeader()); Assert.assertTrue("View should have a header", mKeyguardSliceView.hasHeader());
} }
@Test
public void refresh_replacesSliceContentAndNotifiesListener() {
AtomicBoolean notified = new AtomicBoolean();
mKeyguardSliceView.setContentChangeListener((hasHeader)-> {
notified.set(true);
});
mKeyguardSliceView.refresh();
Assert.assertTrue("Listener should be notified about slice changes.",
notified.get());
}
@Test @Test
public void getTextColor_whiteTextWhenAOD() { public void getTextColor_whiteTextWhenAOD() {
// Set text color to red since the default is white and test would always pass // Set text color to red since the default is white and test would always pass

View File

@@ -0,0 +1,67 @@
/*
* Copyright (C) 2018 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*/
package com.android.keyguard;
import static org.mockito.Mockito.verify;
import android.test.suitebuilder.annotation.SmallTest;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper.RunWithLooper;
import android.view.LayoutInflater;
import android.widget.TextClock;
import com.android.systemui.SysuiTestCase;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
@SmallTest
@RunWithLooper(setAsMainLooper = true)
@RunWith(AndroidTestingRunner.class)
public class KeyguardStatusViewTest extends SysuiTestCase {
@Mock
KeyguardSliceView mKeyguardSlice;
@Mock
TextClock mClockView;
@InjectMocks
KeyguardStatusView mKeyguardStatusView;
@Before
public void setUp() {
LayoutInflater layoutInflater = LayoutInflater.from(getContext());
mKeyguardStatusView =
(KeyguardStatusView) layoutInflater.inflate(R.layout.keyguard_status_view, null);
org.mockito.MockitoAnnotations.initMocks(this);
}
@Test
public void dozeTimeTick_updatesSlice() {
mKeyguardStatusView.dozeTimeTick();
verify(mKeyguardSlice).refresh();
}
@Test
public void dozeTimeTick_updatesClock() {
mKeyguardStatusView.dozeTimeTick();
verify(mClockView).refresh();
}
}

View File

@@ -84,13 +84,6 @@ public class KeyguardSliceProviderTest extends SysuiTestCase {
mProvider.isRegistered()); mProvider.isRegistered());
} }
@Test
public void unregisterClockUpdate() {
mProvider.unregisterClockUpdate();
Assert.assertFalse("Clock updates should have been unregistered.",
mProvider.isRegistered());
}
@Test @Test
public void returnsValidSlice() { public void returnsValidSlice() {
Slice slice = mProvider.onBindSlice(mProvider.getUri()); Slice slice = mProvider.onBindSlice(mProvider.getUri());