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

Commit b65897ba authored by Amith Yamasani's avatar Amith Yamasani
Browse files

Adjust preference activity margins and move the widget back to the right side.

Add a new "icon" field to Preference for adding icons to the left of the preference title.
Several screens such as BluetoothSettings and Accounts have added their own custom preferences
just to add an icon to the left. This makes it simpler going forward.
parent df224cc4
Loading
Loading
Loading
Loading
+38 −1
Original line number Diff line number Diff line
@@ -144742,6 +144742,17 @@
 visibility="public"
>
</method>
<method name="getIcon"
 return="android.graphics.drawable.Drawable"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getIntent"
 return="android.content.Intent"
 abstract="false"
@@ -145328,6 +145339,32 @@
<parameter name="fragment" type="java.lang.String">
</parameter>
</method>
<method name="setIcon"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="icon" type="android.graphics.drawable.Drawable">
</parameter>
</method>
<method name="setIcon"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="iconResId" type="int">
</parameter>
</method>
<method name="setIntent"
 return="void"
 abstract="false"
@@ -246932,7 +246969,7 @@
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="arg0" type="T">
<parameter name="t" type="T">
</parameter>
</method>
</interface>
+58 −1
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
@@ -31,6 +32,7 @@ import android.view.AbsSavedState;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

@@ -52,6 +54,7 @@ import java.util.Set;
 * {@link SharedPreferences}. It is up to the subclass to decide how to store
 * the value.
 * 
 * @attr ref android.R.styleable#Preference_icon
 * @attr ref android.R.styleable#Preference_key
 * @attr ref android.R.styleable#Preference_title
 * @attr ref android.R.styleable#Preference_summary
@@ -87,6 +90,11 @@ public class Preference implements Comparable<Preference>, OnDependencyChangeLis
    private int mOrder = DEFAULT_ORDER;
    private CharSequence mTitle;
    private CharSequence mSummary;
    /**
     * mIconResId is overridden by mIcon, if mIcon is specified.
     */
    private int mIconResId;
    private Drawable mIcon;
    private String mKey;
    private Intent mIntent;
    private String mFragment;
@@ -197,6 +205,10 @@ public class Preference implements Comparable<Preference>, OnDependencyChangeLis
        for (int i = a.getIndexCount(); i >= 0; i--) {
            int attr = a.getIndex(i); 
            switch (attr) {
                case com.android.internal.R.styleable.Preference_icon:
                    mIconResId = a.getResourceId(attr, 0);
                    break;

                case com.android.internal.R.styleable.Preference_key:
                    mKey = a.getString(attr);
                    break;
@@ -499,6 +511,15 @@ public class Preference implements Comparable<Preference>, OnDependencyChangeLis
            }
        }
        
        ImageView imageView = (ImageView) view.findViewById(com.android.internal.R.id.icon);
        if (imageView != null && (mIconResId != 0 || mIcon != null)) {
            if (mIcon == null) {
                mIcon = getContext().getResources().getDrawable(mIconResId);
            }
            if (mIcon != null) {
                imageView.setImageDrawable(mIcon);
            }
        }
        if (mShouldDisableView) {
            setEnabledStateOnViews(view, isEnabled());
        }
@@ -586,6 +607,42 @@ public class Preference implements Comparable<Preference>, OnDependencyChangeLis
        return mTitle;
    }

    /**
     * Sets the icon for this Preference with a Drawable. 
     * This icon will be placed into the ID
     * {@link android.R.id#icon} within the View created by
     * {@link #onCreateView(ViewGroup)}.
     * 
     * @param icon The optional icon for this Preference.
     */
    public void setIcon(Drawable icon) {
        if ((icon == null && mIcon != null) || (icon != null && mIcon != icon)) {
            mIcon = icon;
            notifyChanged();
        }
    }

    /**
     * Sets the icon for this Preference with a resource ID. 
     * 
     * @see #setIcon(Drawable)
     * @param iconResId The icon as a resource ID.
     */
    public void setIcon(int iconResId) {
        mIconResId = iconResId;
        setIcon(mContext.getResources().getDrawable(iconResId));
    }

    /**
     * Returns the icon of this Preference.
     * 
     * @return The icon.
     * @see #setIcon(Drawable)
     */
    public Drawable getIcon() {
        return mIcon;
    }

    /**
     * Returns the summary of this Preference.
     * 
+17 −3
Original line number Diff line number Diff line
@@ -24,13 +24,19 @@
    android:gravity="center_vertical"
    android:paddingRight="?android:attr/scrollbarSize">

    <!-- Preference should place its actual preference widget here. -->
    <LinearLayout android:id="@+android:id/widget_frame"
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:minWidth="@dimen/preference_widget_width"
        android:gravity="center"
        android:orientation="vertical" />
        android:orientation="horizontal">
        <ImageView
            android:id="@+android:id/icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            />
    </LinearLayout>

    <RelativeLayout
        android:layout_width="wrap_content"
@@ -59,4 +65,12 @@

    </RelativeLayout>

    <!-- Preference should place its actual preference widget here. -->
    <LinearLayout android:id="@+android:id/widget_frame"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:minWidth="@dimen/preference_widget_width"
        android:gravity="center"
        android:orientation="vertical" />

</LinearLayout>
+18 −4
Original line number Diff line number Diff line
@@ -20,20 +20,26 @@
    android:layout_height="wrap_content"
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:gravity="center_vertical"
    android:paddingLeft="16dip"
    android:paddingRight="?android:attr/scrollbarSize">

    <!-- Preference should place its actual preference widget here. -->
    <LinearLayout android:id="@+android:id/widget_frame"
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:minWidth="@dimen/preference_widget_width"
        android:gravity="center"
        android:orientation="vertical" />
        android:orientation="horizontal">
        <ImageView
            android:id="@+android:id/icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            />
    </LinearLayout>

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="16dip"
        android:layout_marginRight="6dip"
        android:layout_marginTop="6dip"
        android:layout_marginBottom="6dip"
@@ -58,4 +64,12 @@

    </RelativeLayout>

    <!-- Preference should place its actual preference widget here. -->
    <LinearLayout android:id="@+android:id/widget_frame"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:minWidth="@dimen/preference_widget_width"
        android:gravity="center"
        android:orientation="vertical" />

</LinearLayout>
+2 −2
Original line number Diff line number Diff line
@@ -21,6 +21,6 @@
<resources>
    <dimen name="password_keyboard_key_height">47dip</dimen>
    <dimen name="password_keyboard_spacebar_vertical_correction">2dip</dimen>
    <dimen name="preference_screen_side_margin">32dp</dimen>
    <dimen name="preference_widget_width">64dp</dimen>
    <dimen name="preference_screen_side_margin">96dp</dimen>
    <dimen name="preference_widget_width">72dp</dimen>
</resources>
 No newline at end of file
Loading