summaryrefslogtreecommitdiff
path: root/packages/SettingsLib/src/com/android/settingslib/TwoTargetPreference.java
diff options
context:
space:
mode:
authorEdgar Wang <edgarwang@google.com>2021-02-13 12:28:26 +0800
committerEdgar Wang <edgarwang@google.com>2021-03-17 01:27:50 +0000
commit506c0cfab42ff7e212a7cae530324d23cc88ae20 (patch)
treed9e24db837f0a020865c20efd24af8d6f5b3d908 /packages/SettingsLib/src/com/android/settingslib/TwoTargetPreference.java
parent242cc497ab12ffcabfc26042367bc9f79a8d3a8b (diff)
Create SettingsLibTwoTargetPreference
Bug: 180156703 Test: robotest Change-Id: I4a9958efa47ac24f88e06c8fdb1c9d0a5542e360
Diffstat (limited to 'packages/SettingsLib/src/com/android/settingslib/TwoTargetPreference.java')
-rw-r--r--packages/SettingsLib/src/com/android/settingslib/TwoTargetPreference.java116
1 files changed, 0 insertions, 116 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/TwoTargetPreference.java b/packages/SettingsLib/src/com/android/settingslib/TwoTargetPreference.java
deleted file mode 100644
index 02895a479352..000000000000
--- a/packages/SettingsLib/src/com/android/settingslib/TwoTargetPreference.java
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * Copyright (C) 2017 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.settingslib;
-
-import android.annotation.IntDef;
-import android.content.Context;
-import android.util.AttributeSet;
-import android.view.View;
-import android.widget.ImageView;
-import android.widget.LinearLayout;
-
-import androidx.preference.Preference;
-import androidx.preference.PreferenceViewHolder;
-
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-
-public class TwoTargetPreference extends Preference {
-
- @IntDef({ICON_SIZE_DEFAULT, ICON_SIZE_MEDIUM, ICON_SIZE_SMALL})
- @Retention(RetentionPolicy.SOURCE)
- public @interface IconSize {
- }
-
- public static final int ICON_SIZE_DEFAULT = 0;
- public static final int ICON_SIZE_MEDIUM = 1;
- public static final int ICON_SIZE_SMALL = 2;
-
- @IconSize
- private int mIconSize;
- private int mSmallIconSize;
- private int mMediumIconSize;
-
- public TwoTargetPreference(Context context, AttributeSet attrs,
- int defStyleAttr, int defStyleRes) {
- super(context, attrs, defStyleAttr, defStyleRes);
- init(context);
- }
-
- public TwoTargetPreference(Context context, AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- init(context);
- }
-
- public TwoTargetPreference(Context context, AttributeSet attrs) {
- super(context, attrs);
- init(context);
- }
-
- public TwoTargetPreference(Context context) {
- super(context);
- init(context);
- }
-
- private void init(Context context) {
- setLayoutResource(R.layout.preference_two_target);
- mSmallIconSize = context.getResources().getDimensionPixelSize(
- R.dimen.two_target_pref_small_icon_size);
- mMediumIconSize = context.getResources().getDimensionPixelSize(
- R.dimen.two_target_pref_medium_icon_size);
- final int secondTargetResId = getSecondTargetResId();
- if (secondTargetResId != 0) {
- setWidgetLayoutResource(secondTargetResId);
- }
- }
-
- public void setIconSize(@IconSize int iconSize) {
- mIconSize = iconSize;
- }
-
- @Override
- public void onBindViewHolder(PreferenceViewHolder holder) {
- super.onBindViewHolder(holder);
- final ImageView icon = holder.itemView.findViewById(android.R.id.icon);
- switch (mIconSize) {
- case ICON_SIZE_SMALL:
- icon.setLayoutParams(new LinearLayout.LayoutParams(mSmallIconSize, mSmallIconSize));
- break;
- case ICON_SIZE_MEDIUM:
- icon.setLayoutParams(
- new LinearLayout.LayoutParams(mMediumIconSize, mMediumIconSize));
- break;
- }
- final View divider = holder.findViewById(R.id.two_target_divider);
- final View widgetFrame = holder.findViewById(android.R.id.widget_frame);
- final boolean shouldHideSecondTarget = shouldHideSecondTarget();
- if (divider != null) {
- divider.setVisibility(shouldHideSecondTarget ? View.GONE : View.VISIBLE);
- }
- if (widgetFrame != null) {
- widgetFrame.setVisibility(shouldHideSecondTarget ? View.GONE : View.VISIBLE);
- }
- }
-
- protected boolean shouldHideSecondTarget() {
- return getSecondTargetResId() == 0;
- }
-
- protected int getSecondTargetResId() {
- return 0;
- }
-}