Merge "Add Grayscale conditional"
This commit is contained in:
25
res/drawable/ic_gray_scale_24dp.xml
Normal file
25
res/drawable/ic_gray_scale_24dp.xml
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
<!--
|
||||||
|
Copyright (C) 2019 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.
|
||||||
|
-->
|
||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M12,2C6.48,2 2,6.48 2,12s4.48,10 10,10s10,-4.48 10,-10S17.52,2 12,2zM11,19.93C7.06,19.44 4,16.08 4,12s3.05,-7.44 7,-7.93V19.93zM13,4.07C14.03,4.2 15,4.52 15.87,5H13V4.07zM13,7h5.24c0.25,0.31 0.48,0.65 0.68,1H13V7zM13,10h6.74c0.08,0.33 0.15,0.66 0.19,1H13V10zM13,19.93V19h2.87C15,19.48 14.03,19.8 13,19.93zM18.24,17H13v-1h5.92C18.72,16.35 18.49,16.69 18.24,17zM19.74,14H13v-1h6.93C19.89,13.34 19.82,13.67 19.74,14z"/>
|
||||||
|
</vector>
|
||||||
|
|
@@ -356,4 +356,7 @@
|
|||||||
|
|
||||||
<!-- Slice Uri to query nearby devices. -->
|
<!-- Slice Uri to query nearby devices. -->
|
||||||
<string name="config_nearby_devices_slice_uri" translatable="false">content://com.google.android.gms.nearby.fastpair/device_status_list_item</string>
|
<string name="config_nearby_devices_slice_uri" translatable="false">content://com.google.android.gms.nearby.fastpair/device_status_list_item</string>
|
||||||
|
|
||||||
|
<!-- Grayscale settings intent -->
|
||||||
|
<string name="config_grayscale_settings_intent" translate="false"></string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -9328,6 +9328,12 @@
|
|||||||
<!-- Summary of condition that night display is on (renamed "Night Light" with title caps). [CHAR LIMIT=NONE] -->
|
<!-- Summary of condition that night display is on (renamed "Night Light" with title caps). [CHAR LIMIT=NONE] -->
|
||||||
<string name="condition_night_display_summary">Screen tinted amber</string>
|
<string name="condition_night_display_summary">Screen tinted amber</string>
|
||||||
|
|
||||||
|
<!-- Title of condition that gray scale is on [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="condition_grayscale_title">Greyscale</string>
|
||||||
|
|
||||||
|
<!-- Summary of condition that gray scale is on [CHAR LIMIT=NONE] -->
|
||||||
|
<string name="condition_grayscale_summary">Display only in grey color</string>
|
||||||
|
|
||||||
<!-- Summary for the condition section on the dashboard, representing number of conditions. [CHAR LIMIT=10] -->
|
<!-- Summary for the condition section on the dashboard, representing number of conditions. [CHAR LIMIT=10] -->
|
||||||
<string name="condition_summary" translatable="false"><xliff:g name="count" example="3">%1$d</xliff:g></string>
|
<string name="condition_summary" translatable="false"><xliff:g name="count" example="3">%1$d</xliff:g></string>
|
||||||
|
|
||||||
|
@@ -162,6 +162,7 @@ public class ConditionManager {
|
|||||||
mCardControllers.add(new RingerVibrateConditionController(mAppContext, this /* manager */));
|
mCardControllers.add(new RingerVibrateConditionController(mAppContext, this /* manager */));
|
||||||
mCardControllers.add(new RingerMutedConditionController(mAppContext, this /* manager */));
|
mCardControllers.add(new RingerMutedConditionController(mAppContext, this /* manager */));
|
||||||
mCardControllers.add(new WorkModeConditionController(mAppContext, this /* manager */));
|
mCardControllers.add(new WorkModeConditionController(mAppContext, this /* manager */));
|
||||||
|
mCardControllers.add(new GrayscaleConditionController(mAppContext, this /* manager */));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -0,0 +1,103 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 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.settings.homepage.contextualcards.conditional;
|
||||||
|
|
||||||
|
import android.app.settings.SettingsEnums;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.hardware.display.ColorDisplayManager;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.homepage.contextualcards.ContextualCard;
|
||||||
|
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
public class GrayscaleConditionController implements ConditionalCardController {
|
||||||
|
static final int ID = Objects.hash("GrayscaleConditionController");
|
||||||
|
|
||||||
|
private static final String TAG = "GrayscaleCondition";
|
||||||
|
|
||||||
|
private final Context mAppContext;
|
||||||
|
private final ConditionManager mConditionManager;
|
||||||
|
private final ColorDisplayManager mColorDisplayManager;
|
||||||
|
|
||||||
|
private Intent mIntent;
|
||||||
|
|
||||||
|
public GrayscaleConditionController(Context appContext, ConditionManager conditionManager) {
|
||||||
|
mAppContext = appContext;
|
||||||
|
mConditionManager = conditionManager;
|
||||||
|
mColorDisplayManager = mAppContext.getSystemService(ColorDisplayManager.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getId() {
|
||||||
|
return ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDisplayable() {
|
||||||
|
try {
|
||||||
|
mIntent = Intent.parseUri(
|
||||||
|
mAppContext.getString(R.string.config_grayscale_settings_intent),
|
||||||
|
Intent.URI_INTENT_SCHEME);
|
||||||
|
} catch (URISyntaxException e) {
|
||||||
|
Log.w(TAG, "Failure parsing grayscale settings intent, skipping", e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return mColorDisplayManager.isSaturationActivated();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPrimaryClick(Context context) {
|
||||||
|
mAppContext.startActivity(mIntent);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onActionClick() {
|
||||||
|
// Turn off grayscale
|
||||||
|
mColorDisplayManager.setSaturationLevel(100 /* staturationLevel */);
|
||||||
|
mConditionManager.onConditionChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ContextualCard buildContextualCard() {
|
||||||
|
return new ConditionalContextualCard.Builder()
|
||||||
|
.setConditionId(ID)
|
||||||
|
.setMetricsConstant(SettingsEnums.SETTINGS_CONDITION_GRAYSCALE_MODE)
|
||||||
|
.setActionText(mAppContext.getText(R.string.condition_turn_off))
|
||||||
|
.setName(mAppContext.getPackageName() + "/" + mAppContext.getText(
|
||||||
|
R.string.condition_grayscale_title))
|
||||||
|
.setTitleText(mAppContext.getText(R.string.condition_grayscale_title).toString())
|
||||||
|
.setSummaryText(
|
||||||
|
mAppContext.getText(R.string.condition_grayscale_summary).toString())
|
||||||
|
.setIconDrawable(mAppContext.getDrawable(R.drawable.ic_gray_scale_24dp))
|
||||||
|
.setViewType(ConditionContextualCardRenderer.VIEW_TYPE_HALF_WIDTH)
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void startMonitoringStateChange() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void stopMonitoringStateChange() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@@ -91,4 +91,7 @@
|
|||||||
|
|
||||||
<!-- Email address for the homepage contextual cards feedback -->
|
<!-- Email address for the homepage contextual cards feedback -->
|
||||||
<string name="config_contextual_card_feedback_email" translatable="false">test@test.test</string>
|
<string name="config_contextual_card_feedback_email" translatable="false">test@test.test</string>
|
||||||
|
|
||||||
|
<!-- Grayscale settings intent -->
|
||||||
|
<string name="config_grayscale_settings_intent" translate="false">intent:#Intent;action=test.test;end</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2019 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.settings.homepage.contextualcards.conditional;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.doReturn;
|
||||||
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.hardware.display.ColorDisplayManager;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
import org.robolectric.RobolectricTestRunner;
|
||||||
|
import org.robolectric.RuntimeEnvironment;
|
||||||
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
|
@RunWith(RobolectricTestRunner.class)
|
||||||
|
public class GrayscaleConditionControllerTest {
|
||||||
|
|
||||||
|
@Mock
|
||||||
|
private ConditionManager mConditionManager;
|
||||||
|
|
||||||
|
private ColorDisplayManager mColorDisplayManager;
|
||||||
|
private Context mContext;
|
||||||
|
private GrayscaleConditionController mController;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
mContext = spy(RuntimeEnvironment.application);
|
||||||
|
mColorDisplayManager = spy(mContext.getSystemService(ColorDisplayManager.class));
|
||||||
|
doReturn(mColorDisplayManager).when(mContext).getSystemService(ColorDisplayManager.class);
|
||||||
|
mController = new GrayscaleConditionController(mContext, mConditionManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isDisplayable_noIntent_shouldReturnFalse() {
|
||||||
|
assertThat(mController.isDisplayable()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(qualifiers = "mcc999")
|
||||||
|
public void isDisplayable_validIntentAndGrayscaleOn_shouldReturnTrue() {
|
||||||
|
doReturn(true).when(mColorDisplayManager).isSaturationActivated();
|
||||||
|
|
||||||
|
assertThat(mController.isDisplayable()).isTrue();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@Config(qualifiers = "mcc999")
|
||||||
|
public void isDisplayable_validIntentAndGrayscaleOff_shouldReturnFalse() {
|
||||||
|
doReturn(false).when(mColorDisplayManager).isSaturationActivated();
|
||||||
|
|
||||||
|
assertThat(mController.isDisplayable()).isFalse();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void onActionClick_shouldRefreshCondition() {
|
||||||
|
mController.onActionClick();
|
||||||
|
|
||||||
|
verify(mConditionManager).onConditionChanged();
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user