Home | History | Annotate | Download | only in applications
      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;
     20 import android.preference.Preference;
     21 import android.util.AttributeSet;
     22 import android.view.View;
     23 import android.view.ViewGroup;
     24 import android.view.ViewGroup.LayoutParams;
     25 import android.widget.Space;
     26 
     27 /**
     28  * A blank preference that has a specified height by android:layout_height.  It can be used
     29  * to fine tune screens that combine custom layouts and standard preferences.
     30  */
     31 public class SpacePreference extends Preference {
     32 
     33     private int mHeight;
     34 
     35     public SpacePreference(Context context, AttributeSet attrs) {
     36         this(context, attrs, com.android.internal.R.attr.preferenceStyle);
     37     }
     38 
     39     public SpacePreference(Context context, AttributeSet attrs, int defStyleAttr) {
     40         this(context, attrs, defStyleAttr, 0);
     41     }
     42 
     43     public SpacePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
     44         super(context, attrs, defStyleAttr, defStyleRes);
     45 
     46         final TypedArray a = context.obtainStyledAttributes(attrs,
     47                 new int[] { com.android.internal.R.attr.layout_height }, defStyleAttr, defStyleRes);
     48         mHeight = a.getDimensionPixelSize(0, 0);
     49     }
     50 
     51     public void setHeight(int height) {
     52         mHeight = height;
     53     }
     54 
     55     @Override
     56     protected View onCreateView(ViewGroup parent) {
     57         return new Space(getContext());
     58     }
     59 
     60     @Override
     61     protected void onBindView(View view) {
     62         super.onBindView(view);
     63 
     64         LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, mHeight);
     65         view.setLayoutParams(params);
     66     }
     67 
     68 }
     69