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

Commit facfb174 authored by Charlotte Lu's avatar Charlotte Lu Committed by Android (Google) Code Review
Browse files

Merge "Bluetooth switch show ripple twice." into main

parents f98963f3 d4cb0e31
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  Copyright (C) 2023 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.
  -->

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:state_enabled="false"
        android:drawable="@drawable/settingslib_switch_bar_bg_disabled"/>
    <item
        android:state_activated="true"
        android:drawable="@drawable/settingslib_switch_bar_bg_on"/>
    <item
        android:state_activated="false"
        android:drawable="@drawable/settingslib_switch_bar_bg_off"/>
</selector>
+2 −1
Original line number Diff line number Diff line
@@ -32,7 +32,8 @@
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:paddingStart="@dimen/settingslib_switchbar_padding_left"
        android:paddingEnd="@dimen/settingslib_switchbar_padding_right">
        android:paddingEnd="@dimen/settingslib_switchbar_padding_right"
        android:background="@drawable/settingslib_switch_bar_bg">

        <TextView
            android:id="@+id/switch_text"
+2 −1
Original line number Diff line number Diff line
@@ -32,7 +32,8 @@
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:paddingStart="@dimen/settingslib_switchbar_padding_left"
        android:paddingEnd="@dimen/settingslib_switchbar_padding_right">
        android:paddingEnd="@dimen/settingslib_switchbar_padding_right"
        android:background="@drawable/settingslib_switch_bar_bg">

        <TextView
            android:id="@+id/switch_text"
+4 −16
Original line number Diff line number Diff line
@@ -18,7 +18,6 @@ package com.android.settingslib.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Parcel;
import android.os.Parcelable;
import android.util.AttributeSet;
@@ -52,9 +51,6 @@ public class MainSwitchBar extends LinearLayout implements CompoundButton.OnChec

    protected TextView mTextView;
    protected Switch mSwitch;
    private Drawable mBackgroundOn;
    private Drawable mBackgroundOff;
    private Drawable mBackgroundDisabled;
    private View mFrameView;

    public MainSwitchBar(Context context) {
@@ -89,12 +85,6 @@ public class MainSwitchBar extends LinearLayout implements CompoundButton.OnChec
        mFrameView = findViewById(R.id.frame);
        mTextView = (TextView) findViewById(R.id.switch_text);
        mSwitch = (Switch) findViewById(android.R.id.switch_widget);
        if (BuildCompatUtils.isAtLeastS()) {
            mBackgroundOn = getContext().getDrawable(R.drawable.settingslib_switch_bar_bg_on);
            mBackgroundOff = getContext().getDrawable(R.drawable.settingslib_switch_bar_bg_off);
            mBackgroundDisabled = getContext().getDrawable(
                    R.drawable.settingslib_switch_bar_bg_disabled);
        }
        addOnSwitchChangeListener((switchView, isChecked) -> setChecked(isChecked));

        if (mSwitch.getVisibility() == VISIBLE) {
@@ -217,17 +207,15 @@ public class MainSwitchBar extends LinearLayout implements CompoundButton.OnChec
    /**
     * Enable or disable the text and switch.
     */
    @Override
    public void setEnabled(boolean enabled) {
        super.setEnabled(enabled);
        mTextView.setEnabled(enabled);
        mSwitch.setEnabled(enabled);

        if (BuildCompatUtils.isAtLeastS()) {
            if (enabled) {
                mFrameView.setBackground(isChecked() ? mBackgroundOn : mBackgroundOff);
            } else {
                mFrameView.setBackground(mBackgroundDisabled);
            }
            mFrameView.setEnabled(enabled);
            mFrameView.setActivated(isChecked());
        }
    }

@@ -244,7 +232,7 @@ public class MainSwitchBar extends LinearLayout implements CompoundButton.OnChec
        if (!BuildCompatUtils.isAtLeastS()) {
            setBackgroundColor(isChecked ? mBackgroundActivatedColor : mBackgroundColor);
        } else {
            mFrameView.setBackground(isChecked ? mBackgroundOn : mBackgroundOff);
            mFrameView.setActivated(isChecked);
        }
    }