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

Commit 88ad3307 authored by Mill Chen's avatar Mill Chen
Browse files

Add Grayscale conditional

Build Grayscale conditional that lets users quickly turn off Grayscale
in Settings if it is on.

Bug: 118387886
Test: visual, robotests
Change-Id: Ibfc2d88f4f3f60f9b0acf084a49084030674de37
parent be15baa1
Loading
Loading
Loading
Loading
+25 −0
Original line number Diff line number Diff line
<!--
  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>
+3 −0
Original line number Diff line number Diff line
@@ -356,4 +356,7 @@

    <!-- 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>

    <!-- Grayscale settings intent -->
    <string name="config_grayscale_settings_intent" translate="false"></string>
</resources>
+6 −0
Original line number Diff line number Diff line
@@ -9275,6 +9275,12 @@
    <!-- 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>
    <!-- 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] -->
    <string name="condition_summary" translatable="false"><xliff:g name="count" example="3">%1$d</xliff:g></string>
+1 −0
Original line number Diff line number Diff line
@@ -162,6 +162,7 @@ public class ConditionManager {
        mCardControllers.add(new RingerVibrateConditionController(mAppContext, this /* manager */));
        mCardControllers.add(new RingerMutedConditionController(mAppContext, this /* manager */));
        mCardControllers.add(new WorkModeConditionController(mAppContext, this /* manager */));
        mCardControllers.add(new GrayscaleConditionController(mAppContext, this /* manager */));
    }

    /**
+103 −0
Original line number Diff line number Diff line
/*
 * 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() {

    }
}
Loading