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

Commit a93327e2 authored by gaurav sharma's avatar gaurav sharma Committed by Josh Guilfoyle
Browse files

Added new SpinnerPrefrence component

parent 784b193f
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -6774,6 +6774,17 @@
 visibility="public"
>
</field>
<field name="spinnerPreferenceStyle"
 type="int"
 transient="false"
 volatile="false"
 value="16843451"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="spinnerStyle"
 type="int"
 transient="false"
+152 −0
Original line number Diff line number Diff line
package com.tmobile.preferences;

import android.content.Context;
import android.content.res.TypedArray;
import android.os.Parcel;
import android.os.Parcelable;
import android.preference.Preference;
import android.util.AttributeSet;
import android.view.View;
import android.widget.SpinnerAdapter;

import com.tmobile.widget.ComboSpinner;

public class SpinnerPreference extends Preference implements
		ComboSpinner.IDataBinder {

	private int mSelected;
	private SpinnerAdapter mAdapter;

	public SpinnerPreference(Context context, AttributeSet attrs, int defStyle) {
		super(context, attrs, defStyle);
	}

	public SpinnerPreference(Context context, AttributeSet attrs) {
		this(context, attrs, com.android.internal.R.attr.spinnerPreferenceStyle);
	}

	public SpinnerPreference(Context context) {
		this(context, null); 
	}

	private int getSelectedIndex() {
		return mSelected;
	}

	private void setSelectedIndex(int pos) {
		mSelected = pos;
		persistInt(pos);
		notifyDependencyChange(shouldDisableDependents());
		notifyChanged();
	}

	@Override
	protected void onClick() {
		super.onClick();

		int newValue = getSelectedIndex();

		if (!callChangeListener(newValue)) {
			return;
		}
		setSelectedIndex(newValue);
	}

	public void setAdapter(SpinnerAdapter adapter) {
		mAdapter = adapter;
	}

	public SpinnerAdapter getAdapter() {
		return mAdapter;
	}

	@Override
	protected void onBindView(View view) {
		super.onBindView(view);
		ComboSpinner spinner = (ComboSpinner) view
				.findViewById(com.android.internal.R.id.spinner_preferences);
		if (spinner != null) {
			spinner.setAdapter(getAdapter());
			spinner.setSelection(mSelected);
			spinner.setDataBinder(this);
		}
	}
	
	@Override
    public boolean shouldDisableDependents() {
     
        return super.shouldDisableDependents();
    }

	@Override
	protected Object onGetDefaultValue(TypedArray a, int index) {
		return a.getInt(index, 0);
	}

	@Override
	protected void onSetInitialValue(boolean restoreValue, Object defaultValue) {
		setSelectedIndex(restoreValue ? getPersistedInt(mSelected)
				: (Integer) defaultValue);
	}

	@Override
	protected Parcelable onSaveInstanceState() {
		final Parcelable superState = super.onSaveInstanceState();
		if (isPersistent()) {
			// No need to save instance state since it's persistent
			return superState;
		}

		final SavedState myState = new SavedState(superState);
		myState.value = getSelectedIndex();
		return myState;
	}

	@Override
	protected void onRestoreInstanceState(Parcelable state) {
		if (state == null || !state.getClass().equals(SavedState.class)) {
			// Didn't save state for us in onSaveInstanceState
			super.onRestoreInstanceState(state);
			return;
		}

		SavedState myState = (SavedState) state;
		super.onRestoreInstanceState(myState.getSuperState());
		setSelectedIndex(myState.value);
	}

	private static class SavedState extends BaseSavedState {
		int value;

		public SavedState(Parcel source) {
			super(source);
			value = source.readInt();
		}

		@Override
		public void writeToParcel(Parcel dest, int flags) {
			super.writeToParcel(dest, flags);
			dest.writeInt(value);
		}

		public SavedState(Parcelable superState) {
			super(superState);
		}

		public static final Parcelable.Creator<SavedState> CREATOR = new Parcelable.Creator<SavedState>() {
			public SavedState createFromParcel(Parcel in) {
				return new SavedState(in);
			}

			public SavedState[] newArray(int size) {
				return new SavedState[size];
			}
		};
	}

	public void onSelectionChange(int value) {

		setSelectedIndex(value);
	}

}
+14 −2
Original line number Diff line number Diff line
@@ -87,8 +87,13 @@ public class ComboSpinner extends Spinner {
        }
    }
	
    public interface IDataBinder {
		public void onSelectionChange(int value);
	}
	
    private PopupWindow mWindow;
	private ListView mList;
	private IDataBinder dataBinder;
	
	static private final int kPopupWindowPadding = 6;
	
@@ -129,6 +134,10 @@ public class ComboSpinner extends Spinner {
			setSelection(position);
			dismissPopup();
			requestFocus();
			if (dataBinder != null) {
				dataBinder.onSelectionChange(position);
			}

		}
	};
	
@@ -163,4 +172,7 @@ public class ComboSpinner extends Spinner {
        return true;
    }
    
	public void setDataBinder(IDataBinder binder) {
		dataBinder = binder;
	}
}
+8 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>


<com.tmobile.widget.ComboSpinner xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+android:id/spinner_preferences" 
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
+2 −0
Original line number Diff line number Diff line
@@ -445,6 +445,8 @@
        <attr name="ringtonePreferenceStyle" format="reference" />
        <!-- The preference layout that has the child/tabbed effect. -->
        <attr name="preferenceLayoutChild" format="reference" />
        <!-- Default style for SpinnerPreference. -->
        <attr name="spinnerPreferenceStyle" format="reference" />
        
    </declare-styleable>

Loading