|
Android example source code file (PreferenceGroupAdapter.java)
The PreferenceGroupAdapter.java Android example source code/* * 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 android.preference; import java.util.ArrayList; import java.util.Collections; import java.util.List; import android.os.Handler; import android.preference.Preference.OnPreferenceChangeInternalListener; import android.view.View; import android.view.ViewGroup; import android.widget.Adapter; import android.widget.BaseAdapter; import android.widget.ListView; /** * An adapter that returns the {@link Preference} contained in this group. * In most cases, this adapter should be the base class for any custom * adapters from {@link Preference#getAdapter()}. * <p> * This adapter obeys the * {@link Preference}'s adapter rule (the * {@link Adapter#getView(int, View, ViewGroup)} should be used instead of * {@link Preference#getView(ViewGroup)} if a {@link Preference} has an * adapter via {@link Preference#getAdapter()}). * <p> * This adapter also propagates data change/invalidated notifications upward. * <p> * This adapter does not include this {@link PreferenceGroup} in the returned * adapter, use {@link PreferenceCategoryAdapter} instead. * * @see PreferenceCategoryAdapter */ class PreferenceGroupAdapter extends BaseAdapter implements OnPreferenceChangeInternalListener { private static final String TAG = "PreferenceGroupAdapter"; /** * The group that we are providing data from. */ private PreferenceGroup mPreferenceGroup; /** * Maps a position into this adapter -> {@link Preference}. These * {@link Preference}s don't have to be direct children of this * {@link PreferenceGroup}, they can be grand children or younger) */ private List<Preference> mPreferenceList; /** * List of unique Preference and its subclasses' names. This is used to find * out how many types of views this adapter can return. Once the count is * returned, this cannot be modified (since the ListView only checks the * count once--when the adapter is being set). We will not recycle views for * Preference subclasses seen after the count has been returned. */ private ArrayList<PreferenceLayout> mPreferenceLayouts; private PreferenceLayout mTempPreferenceLayout = new PreferenceLayout(); /** * Blocks the mPreferenceClassNames from being changed anymore. */ private boolean mHasReturnedViewTypeCount = false; private volatile boolean mIsSyncing = false; private Handler mHandler = new Handler(); private Runnable mSyncRunnable = new Runnable() { public void run() { syncMyPreferences(); } }; private static class PreferenceLayout implements Comparable<PreferenceLayout> { private int resId; private int widgetResId; private String name; public int compareTo(PreferenceLayout other) { int compareNames = name.compareTo(other.name); if (compareNames == 0) { if (resId == other.resId) { if (widgetResId == other.widgetResId) { return 0; } else { return widgetResId - other.widgetResId; } } else { return resId - other.resId; } } else { return compareNames; } } } public PreferenceGroupAdapter(PreferenceGroup preferenceGroup) { mPreferenceGroup = preferenceGroup; // If this group gets or loses any children, let us know mPreferenceGroup.setOnPreferenceChangeInternalListener(this); mPreferenceList = new ArrayList<Preference>(); mPreferenceLayouts = new ArrayList<PreferenceLayout>(); syncMyPreferences(); } private void syncMyPreferences() { synchronized(this) { if (mIsSyncing) { return; } mIsSyncing = true; } List<Preference> newPreferenceList = new ArrayList Other Android examples (source code examples)Here is a short list of links related to this Android PreferenceGroupAdapter.java source code file: |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.