/* * Copyright (C) 2007 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.joelapenna.foursquared.preferences; import android.content.Context; import android.content.res.TypedArray; import android.os.Parcelable; import android.preference.Preference; import android.util.AttributeSet; import android.view.View; /** * This is an example of a custom preference type. The preference counts the number of clicks it has * received and stores/retrieves it from the storage. */ public class ClickPreference extends Preference { // This is the constructor called by the inflater public ClickPreference(Context context, AttributeSet attrs) { super(context, attrs); } @Override protected void onBindView(View view) { super.onBindView(view); } @Override protected void onClick() { // Data has changed, notify so UI can be refreshed! notifyChanged(); } @Override protected Object onGetDefaultValue(TypedArray a, int index) { // This preference type's value type is Integer, so we read the default // value from the attributes as an Integer. return a.getInteger(index, 0); } @Override protected void onSetInitialValue(boolean restoreValue, Object defaultValue) { } @Override protected void onRestoreInstanceState(Parcelable state) { super.onRestoreInstanceState(state); notifyChanged(); } }