blob: f895e21f7c6a4a360d03fa0669e46de09afd9199 [file] [log] [blame]
package org.wordpress.android.ui.prefs;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.preference.SwitchPreference;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.widget.TextView;
import org.wordpress.android.R;
public class WPSwitchPreference extends SwitchPreference implements PreferenceHint {
private String mHint;
public WPSwitchPreference(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.SummaryEditTextPreference);
for (int i = 0; i < array.getIndexCount(); ++i) {
int index = array.getIndex(i);
if (index == R.styleable.SummaryEditTextPreference_longClickHint) {
mHint = array.getString(index);
}
}
array.recycle();
}
@Override
protected void onBindView(@NonNull View view) {
super.onBindView(view);
TextView titleView = (TextView) view.findViewById(android.R.id.title);
if (titleView != null) {
Resources res = getContext().getResources();
titleView.setTextSize(TypedValue.COMPLEX_UNIT_PX, res.getDimensionPixelSize(R.dimen.text_sz_large));
titleView.setTextColor(res.getColor(isEnabled() ? R.color.grey_dark : R.color.grey_lighten_10));
}
}
@Override
public boolean hasHint() {
return !TextUtils.isEmpty(mHint);
}
@Override
public String getHint() {
return mHint;
}
@Override
public void setHint(String hint) {
mHint = hint;
}
}