diff options
author | Fan Zhang <zhfan@google.com> | 2017-03-22 10:54:03 -0700 |
---|---|---|
committer | Fan Zhang <zhfan@google.com> | 2017-03-22 16:02:37 -0700 |
commit | 035ff93430b71ef856f299c9f676f8d340403e16 (patch) | |
tree | 2d4310fb0ab41524712d0ebfada80f9b6114e461 /packages/SettingsLib/src/com/android/settingslib/TwoTargetPreference.java | |
parent | 73b841861798b9a1e1b68f871119982f6c679ced (diff) |
Move two target preference layout from settings to lib
Change-Id: I5eda0cdcc4e8d8bb25f95ee12837d90179ac5c0a
Fix: 36511169
Test: make RunSettingsLibRoboTests
Diffstat (limited to 'packages/SettingsLib/src/com/android/settingslib/TwoTargetPreference.java')
-rw-r--r-- | packages/SettingsLib/src/com/android/settingslib/TwoTargetPreference.java | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/packages/SettingsLib/src/com/android/settingslib/TwoTargetPreference.java b/packages/SettingsLib/src/com/android/settingslib/TwoTargetPreference.java new file mode 100644 index 000000000000..1c161dffced9 --- /dev/null +++ b/packages/SettingsLib/src/com/android/settingslib/TwoTargetPreference.java @@ -0,0 +1,77 @@ +/* + * 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.content.Context; +import android.support.v7.preference.Preference; +import android.support.v7.preference.PreferenceViewHolder; +import android.util.AttributeSet; +import android.view.View; + +public class TwoTargetPreference extends Preference { + + public TwoTargetPreference(Context context, AttributeSet attrs, + int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + init(); + } + + public TwoTargetPreference(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + init(); + } + + public TwoTargetPreference(Context context, AttributeSet attrs) { + super(context, attrs); + init(); + } + + public TwoTargetPreference(Context context) { + super(context); + init(); + } + + private void init() { + setLayoutResource(R.layout.preference_two_target); + final int secondTargetResId = getSecondTargetResId(); + if (secondTargetResId != 0) { + setWidgetLayoutResource(secondTargetResId); + } + } + + @Override + public void onBindViewHolder(PreferenceViewHolder holder) { + super.onBindViewHolder(holder); + 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; + } +} |