Jason Monk | beb171d | 2015-05-21 15:24:37 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2015 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | package com.android.settings.applications; |
| 17 | |
| 18 | import android.content.Context; |
| 19 | import android.content.res.TypedArray; |
Fan Zhang | c7162cd | 2018-06-18 15:21:41 -0700 | [diff] [blame] | 20 | import android.util.AttributeSet; |
| 21 | import android.view.ViewGroup.LayoutParams; |
| 22 | |
Aurimas Liutikas | e0069d3 | 2018-04-17 11:22:43 -0700 | [diff] [blame] | 23 | import androidx.core.content.res.TypedArrayUtils; |
| 24 | import androidx.preference.Preference; |
| 25 | import androidx.preference.PreferenceViewHolder; |
Jason Monk | beb171d | 2015-05-21 15:24:37 -0400 | [diff] [blame] | 26 | |
Fan Zhang | 23f8d59 | 2018-08-28 15:11:40 -0700 | [diff] [blame] | 27 | import com.android.settings.R; |
| 28 | |
Jason Monk | beb171d | 2015-05-21 15:24:37 -0400 | [diff] [blame] | 29 | /** |
| 30 | * A blank preference that has a specified height by android:layout_height. It can be used |
| 31 | * to fine tune screens that combine custom layouts and standard preferences. |
| 32 | */ |
| 33 | public class SpacePreference extends Preference { |
| 34 | |
| 35 | private int mHeight; |
| 36 | |
| 37 | public SpacePreference(Context context, AttributeSet attrs) { |
Daniel Nishi | d8dce76 | 2017-06-27 14:28:21 -0700 | [diff] [blame] | 38 | this(context, attrs, TypedArrayUtils.getAttr(context, |
Aurimas Liutikas | e0069d3 | 2018-04-17 11:22:43 -0700 | [diff] [blame] | 39 | androidx.preference.R.attr.preferenceStyle, |
Daniel Nishi | d8dce76 | 2017-06-27 14:28:21 -0700 | [diff] [blame] | 40 | android.R.attr.preferenceStyle)); |
Jason Monk | beb171d | 2015-05-21 15:24:37 -0400 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | public SpacePreference(Context context, AttributeSet attrs, int defStyleAttr) { |
| 44 | this(context, attrs, defStyleAttr, 0); |
| 45 | } |
| 46 | |
| 47 | public SpacePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { |
| 48 | super(context, attrs, defStyleAttr, defStyleRes); |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 49 | setLayoutResource(R.layout.space_preference); |
Jason Monk | beb171d | 2015-05-21 15:24:37 -0400 | [diff] [blame] | 50 | |
| 51 | final TypedArray a = context.obtainStyledAttributes(attrs, |
| 52 | new int[] { com.android.internal.R.attr.layout_height }, defStyleAttr, defStyleRes); |
| 53 | mHeight = a.getDimensionPixelSize(0, 0); |
Rajeev Kumar | b0ec265 | 2017-07-13 18:48:08 -0700 | [diff] [blame] | 54 | a.recycle(); |
Jason Monk | beb171d | 2015-05-21 15:24:37 -0400 | [diff] [blame] | 55 | } |
| 56 | |
| 57 | public void setHeight(int height) { |
| 58 | mHeight = height; |
| 59 | } |
| 60 | |
| 61 | @Override |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 62 | public void onBindViewHolder(PreferenceViewHolder view) { |
| 63 | super.onBindViewHolder(view); |
Jason Monk | beb171d | 2015-05-21 15:24:37 -0400 | [diff] [blame] | 64 | |
| 65 | LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, mHeight); |
Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 66 | view.itemView.setLayoutParams(params); |
Jason Monk | beb171d | 2015-05-21 15:24:37 -0400 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | } |