173e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin/*
273e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin * Copyright (C) 2009 The Android Open Source Project
373e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin *
473e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin * Licensed under the Apache License, Version 2.0 (the "License");
573e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin * you may not use this file except in compliance with the License.
673e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin * You may obtain a copy of the License at
773e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin *
873e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin *      http://www.apache.org/licenses/LICENSE-2.0
973e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin *
1073e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin * Unless required by applicable law or agreed to in writing, software
1173e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin * distributed under the License is distributed on an "AS IS" BASIS,
1273e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1373e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin * See the License for the specific language governing permissions and
1473e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin * limitations under the License.
1573e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin */
1673e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin
1773e782de608cbe2ddffd75c055009ff2e208f78bOwen Linpackage com.android.camera;
1873e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin
1973e782de608cbe2ddffd75c055009ff2e208f78bOwen Linimport android.content.Context;
2073e782de608cbe2ddffd75c055009ff2e208f78bOwen Linimport android.content.SharedPreferences;
2173e782de608cbe2ddffd75c055009ff2e208f78bOwen Linimport android.content.res.TypedArray;
2273e782de608cbe2ddffd75c055009ff2e208f78bOwen Linimport android.util.AttributeSet;
2373e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin
24e480f77352d670b2892a9b7b7cd503838b71ca9fRomain Guyimport com.android.camera.R;
253889cf31101cfd4d336f1ce5ae5122c2cb3c0fdcChih-Chung Chang
2673e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin/**
2773e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin * The base class of all Preferences used in Camera. The preferences can be
2873e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin * loaded from XML resource by <code>PreferenceInflater</code>.
2973e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin */
3073e782de608cbe2ddffd75c055009ff2e208f78bOwen Linpublic abstract class CameraPreference {
3173e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin
32c24155c65b45f554ffc29c523d7ea8e63ea10d33Owen Lin    private final String mTitle;
3373e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin    private SharedPreferences mSharedPreferences;
34c24155c65b45f554ffc29c523d7ea8e63ea10d33Owen Lin    private final Context mContext;
3573e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin
36adab2bddc93bf4af535cb58e7167bf8690d97d8cChung-yih Wang    static public interface OnPreferenceChangedListener {
37adab2bddc93bf4af535cb58e7167bf8690d97d8cChung-yih Wang        public void onSharedPreferenceChanged();
38adab2bddc93bf4af535cb58e7167bf8690d97d8cChung-yih Wang        public void onRestorePreferencesClicked();
39adab2bddc93bf4af535cb58e7167bf8690d97d8cChung-yih Wang        public void onOverriddenPreferencesClicked();
40adab2bddc93bf4af535cb58e7167bf8690d97d8cChung-yih Wang    }
41adab2bddc93bf4af535cb58e7167bf8690d97d8cChung-yih Wang
4273e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin    public CameraPreference(Context context, AttributeSet attrs) {
4373e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin        mContext = context;
4473e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin        TypedArray a = context.obtainStyledAttributes(
4573e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin                attrs, R.styleable.CameraPreference, 0, 0);
4673e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin        mTitle = a.getString(R.styleable.CameraPreference_title);
4773e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin        a.recycle();
4873e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin    }
4973e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin
5073e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin    public String getTitle() {
5173e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin        return mTitle;
5273e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin    }
5373e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin
54c24155c65b45f554ffc29c523d7ea8e63ea10d33Owen Lin    public SharedPreferences getSharedPreferences() {
5573e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin        if (mSharedPreferences == null) {
561ef634d277d550ed55b5b7089dfd56ed71815bd6Chih-Chung Chang            mSharedPreferences = ComboPreferences.get(mContext);
5773e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin        }
5873e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin        return mSharedPreferences;
5973e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin    }
6052064aa4bacfae605823b99f675649b1786e8c8aOwen Lin
6152064aa4bacfae605823b99f675649b1786e8c8aOwen Lin    public abstract void reloadValue();
6273e782de608cbe2ddffd75c055009ff2e208f78bOwen Lin}
63