Home | History | Annotate | Download | only in shadows
      1 package com.xtremelabs.robolectric.shadows;
      2 
      3 import android.content.Context;
      4 import android.content.Intent;
      5 import android.preference.Preference;
      6 import android.util.AttributeSet;
      7 
      8 import com.xtremelabs.robolectric.internal.Implementation;
      9 import com.xtremelabs.robolectric.internal.Implements;
     10 import com.xtremelabs.robolectric.internal.RealObject;
     11 
     12 @Implements(Preference.class)
     13 public class ShadowPreference {
     14 
     15     @RealObject private Preference realPreference;
     16 
     17     protected Context context;
     18 	protected AttributeSet attrs;
     19 	protected int defStyle;
     20 
     21 	protected String key;
     22 	protected CharSequence title;
     23 	protected CharSequence summary;
     24 	protected Object defaultValue;
     25 	protected int order;
     26 	protected boolean enabled = true;
     27 	protected String dependencyKey;
     28 	protected boolean persistent = false;
     29 	protected int persistedInt;
     30 	protected Object callChangeListenerValue = null;
     31 
     32 	protected Preference.OnPreferenceClickListener  onClickListener;
     33 	private Intent intent;
     34 
     35 	public void __constructor__(Context context) {
     36 		__constructor__(context, null, 0);
     37 	}
     38 
     39 	public void __constructor__(Context context, AttributeSet attributeSet) {
     40 		__constructor__(context, attributeSet, 0);
     41 	}
     42 
     43 	public void __constructor__(Context context, AttributeSet attributeSet, int defStyle) {
     44 		this.context = context;
     45 		this.attrs = attributeSet;
     46 		this.defStyle = defStyle;
     47 
     48 		if (attributeSet != null) {
     49 			key = attributeSet.getAttributeValue("android", "key");
     50         }
     51 	}
     52 
     53 	@Implementation
     54 	public Context getContext() {
     55     	return context;
     56     }
     57 
     58     public AttributeSet getAttrs() {
     59     	return attrs;
     60     }
     61 
     62     public int getDefStyle() {
     63     	return defStyle;
     64     }
     65 
     66 	@Implementation
     67 	public void setEnabled(boolean enabled) {
     68 		this.enabled = enabled;
     69 	}
     70 
     71 	@Implementation
     72 	public boolean isEnabled() {
     73 		return enabled;
     74 	}
     75 
     76 	@Implementation
     77 	public boolean shouldPersist() {
     78 		return persistent;
     79 	}
     80 
     81 	@Implementation
     82 	public boolean isPersistent() {
     83 		return persistent;
     84 	}
     85 
     86 	@Implementation
     87 	public void setPersistent(boolean persistent) {
     88 		this.persistent = persistent;
     89 	}
     90 
     91 	@Implementation
     92 	public int getPersistedInt(int defaultReturnValue) {
     93 		return persistent ? persistedInt : defaultReturnValue;
     94 	}
     95 
     96 	@Implementation
     97 	public boolean persistInt(int value) {
     98 		this.persistedInt = value;
     99 		return persistent;
    100 	}
    101 
    102 	@Implementation
    103 	public boolean callChangeListener(Object newValue) {
    104 		callChangeListenerValue = newValue;
    105 		return true;
    106 	}
    107 
    108 	public Object getCallChangeListenerValue() {
    109 		return callChangeListenerValue;
    110 	}
    111 
    112 	@Implementation
    113 	public void setSummary(int summaryResId) {
    114 		this.summary = context.getResources().getText(summaryResId);
    115 	}
    116 
    117 	@Implementation
    118 	public void setSummary(CharSequence summary) {
    119 		this.summary = summary;
    120 	}
    121 
    122 	@Implementation
    123 	public CharSequence getSummary() {
    124 		return summary;
    125 	}
    126 
    127 	@Implementation
    128 	public void setTitle(int titleResId) {
    129 		this.title = context.getResources().getText(titleResId);
    130 	}
    131 
    132 	@Implementation
    133 	public void setTitle(CharSequence title) {
    134 		this.title = title;
    135 	}
    136 
    137 	@Implementation
    138 	public CharSequence getTitle() {
    139 		return title;
    140 	}
    141 
    142 	@Implementation
    143 	public void setKey(String key) {
    144 		this.key = key;
    145 	}
    146 
    147 	@Implementation
    148 	public String getKey() {
    149 		return key;
    150 	}
    151 
    152 	@Implementation
    153 	public void setDefaultValue(Object defaultValue) {
    154 		this.defaultValue = defaultValue;
    155 	}
    156 
    157 	public Object getDefaultValue() {
    158 		return defaultValue;
    159 	}
    160 
    161 	@Implementation
    162 	public int getOrder() {
    163 		return order;
    164 	}
    165 
    166 	@Implementation
    167 	public void setOrder(int order) {
    168 		this.order = order;
    169 	}
    170 
    171 	@Implementation
    172 	public void setOnPreferenceClickListener( Preference.OnPreferenceClickListener onPreferenceClickListener ) {
    173 		this.onClickListener = onPreferenceClickListener;
    174 	}
    175 
    176 	@Implementation
    177 	public Preference.OnPreferenceClickListener getOnPreferenceClickListener() {
    178 		return onClickListener;
    179 	}
    180 
    181 	public boolean click() {
    182 		return onClickListener.onPreferenceClick(realPreference);
    183 	}
    184 
    185 	@Implementation
    186 	public void setIntent(Intent i) {
    187 		this.intent = i;
    188 	}
    189 
    190 	@Implementation
    191 	public Intent getIntent() {
    192 		return this.intent;
    193 
    194 	}
    195 
    196 	@Implementation
    197 	public void setDependency(String dependencyKey) {
    198 		this.dependencyKey = dependencyKey;
    199 	}
    200 
    201 	@Implementation
    202 	public String getDependency() {
    203 		return this.dependencyKey;
    204 	}
    205 }
    206