Code cleaning: remove all remaining references to the old Header class

- goodbye Header(s) !

Change-Id: Ied27f1f01dbed9c51cc74d28800d9ca7cab47d5a
This commit is contained in:
Fabrice Di Meglio
2014-05-13 12:49:14 -07:00
parent 488cae39da
commit e9326d2761
3 changed files with 3 additions and 349 deletions

View File

@@ -77,7 +77,6 @@ import com.android.settings.bluetooth.BluetoothSettings;
import com.android.settings.dashboard.DashboardCategory; import com.android.settings.dashboard.DashboardCategory;
import com.android.settings.dashboard.DashboardSummary; import com.android.settings.dashboard.DashboardSummary;
import com.android.settings.dashboard.DashboardTile; import com.android.settings.dashboard.DashboardTile;
import com.android.settings.dashboard.Header;
import com.android.settings.dashboard.NoHomeDialogFragment; import com.android.settings.dashboard.NoHomeDialogFragment;
import com.android.settings.dashboard.SearchResultsSummary; import com.android.settings.dashboard.SearchResultsSummary;
import com.android.settings.deviceinfo.Memory; import com.android.settings.deviceinfo.Memory;
@@ -115,7 +114,7 @@ import java.util.Collections;
import java.util.Comparator; import java.util.Comparator;
import java.util.List; import java.util.List;
import static com.android.settings.dashboard.Header.HEADER_ID_UNDEFINED; import static com.android.settings.dashboard.DashboardTile.TILE_ID_UNDEFINED;
public class SettingsActivity extends Activity public class SettingsActivity extends Activity
implements PreferenceManager.OnPreferenceTreeClickListener, implements PreferenceManager.OnPreferenceTreeClickListener,
@@ -492,7 +491,7 @@ public class SettingsActivity extends Activity
switchToFragment( initialFragmentName, initialArguments, true, false, switchToFragment( initialFragmentName, initialArguments, true, false,
mInitialTitle, false); mInitialTitle, false);
} else { } else {
// No UP if we are displaying the Headers // No UP if we are displaying the main Dashboard
mDisplayHomeAsUpEnabled = false; mDisplayHomeAsUpEnabled = false;
if (mCategories.size() > 0) { if (mCategories.size() > 0) {
mInitialTitle = getText(R.string.dashboard_title); mInitialTitle = getText(R.string.dashboard_title);
@@ -671,25 +670,6 @@ public class SettingsActivity extends Activity
return false; return false;
} }
/**
* When in two-pane mode, switch to the fragment pane to show the given
* preference fragment.
*
* @param header The new header to display.
* @param position The position of the Header in the list.
*/
private void onHeaderClick(Header header, int position) {
if (header == null) {
return;
}
if (header.fragment != null) {
Utils.startWithFragment(this, header.fragment, header.fragmentArguments, null, 0,
header.getTitle(getResources()));
} else if (header.intent != null) {
startActivity(header.intent);
}
}
/** /**
* Called to determine whether the header list should be hidden. * Called to determine whether the header list should be hidden.
* The default implementation returns the * The default implementation returns the
@@ -919,7 +899,7 @@ public class SettingsActivity extends Activity
attrs, com.android.internal.R.styleable.PreferenceHeader); attrs, com.android.internal.R.styleable.PreferenceHeader);
tile.id = sa.getResourceId( tile.id = sa.getResourceId(
com.android.internal.R.styleable.PreferenceHeader_id, com.android.internal.R.styleable.PreferenceHeader_id,
(int)HEADER_ID_UNDEFINED); (int)TILE_ID_UNDEFINED);
tv = sa.peekValue( tv = sa.peekValue(
com.android.internal.R.styleable.PreferenceHeader_title); com.android.internal.R.styleable.PreferenceHeader_title);
if (tv != null && tv.type == TypedValue.TYPE_STRING) { if (tv != null && tv.type == TypedValue.TYPE_STRING) {

View File

@@ -58,7 +58,6 @@ import android.widget.ListView;
import android.widget.TabWidget; import android.widget.TabWidget;
import com.android.settings.dashboard.DashboardCategory; import com.android.settings.dashboard.DashboardCategory;
import com.android.settings.dashboard.DashboardTile; import com.android.settings.dashboard.DashboardTile;
import com.android.settings.dashboard.Header;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@@ -152,154 +151,6 @@ public class Utils {
return false; return false;
} }
/**
* Finds a matching activity for a preference's intent. If a matching
* activity is not found, it will remove the preference. The icon, title and
* summary of the preference will also be updated with the values retrieved
* from the activity's meta-data elements. If no meta-data elements are
* specified then the preference title will be set to match the label of the
* activity, an icon and summary text will not be displayed.
*
* @param context The context.
* @param parentPreferenceGroup The preference group that contains the
* preference whose intent is being resolved.
* @param preferenceKey The key of the preference whose intent is being
* resolved.
*
* @return Whether an activity was found. If false, the preference was
* removed.
*
* @see {@link #META_DATA_PREFERENCE_ICON}
* {@link #META_DATA_PREFERENCE_TITLE}
* {@link #META_DATA_PREFERENCE_SUMMARY}
*/
public static boolean updatePreferenceToSpecificActivityFromMetaDataOrRemove(Context context,
PreferenceGroup parentPreferenceGroup, String preferenceKey) {
IconPreferenceScreen preference = (IconPreferenceScreen)parentPreferenceGroup
.findPreference(preferenceKey);
if (preference == null) {
return false;
}
Intent intent = preference.getIntent();
if (intent != null) {
// Find the activity that is in the system image
PackageManager pm = context.getPackageManager();
List<ResolveInfo> list = pm.queryIntentActivities(intent, PackageManager.GET_META_DATA);
int listSize = list.size();
for (int i = 0; i < listSize; i++) {
ResolveInfo resolveInfo = list.get(i);
if ((resolveInfo.activityInfo.applicationInfo.flags
& ApplicationInfo.FLAG_SYSTEM) != 0) {
Drawable icon = null;
String title = null;
String summary = null;
// Get the activity's meta-data
try {
Resources res = pm
.getResourcesForApplication(resolveInfo.activityInfo.packageName);
Bundle metaData = resolveInfo.activityInfo.metaData;
if (res != null && metaData != null) {
icon = res.getDrawable(metaData.getInt(META_DATA_PREFERENCE_ICON));
title = res.getString(metaData.getInt(META_DATA_PREFERENCE_TITLE));
summary = res.getString(metaData.getInt(META_DATA_PREFERENCE_SUMMARY));
}
} catch (NameNotFoundException e) {
// Ignore
} catch (NotFoundException e) {
// Ignore
}
// Set the preference title to the activity's label if no
// meta-data is found
if (TextUtils.isEmpty(title)) {
title = resolveInfo.loadLabel(pm).toString();
}
// Set icon, title and summary for the preference
preference.setIcon(icon);
preference.setTitle(title);
preference.setSummary(summary);
// Replace the intent with this specific activity
preference.setIntent(new Intent().setClassName(
resolveInfo.activityInfo.packageName,
resolveInfo.activityInfo.name));
return true;
}
}
}
// Did not find a matching activity, so remove the preference
parentPreferenceGroup.removePreference(preference);
return false;
}
public static boolean updateHeaderToSpecificActivityFromMetaDataOrRemove(Context context,
List<Header> target, Header header) {
Intent intent = header.intent;
if (intent != null) {
// Find the activity that is in the system image
PackageManager pm = context.getPackageManager();
List<ResolveInfo> list = pm.queryIntentActivities(intent, PackageManager.GET_META_DATA);
int listSize = list.size();
for (int i = 0; i < listSize; i++) {
ResolveInfo resolveInfo = list.get(i);
if ((resolveInfo.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM)
!= 0) {
Drawable icon = null;
String title = null;
String summary = null;
// Get the activity's meta-data
try {
Resources res = pm.getResourcesForApplication(
resolveInfo.activityInfo.packageName);
Bundle metaData = resolveInfo.activityInfo.metaData;
if (res != null && metaData != null) {
icon = res.getDrawable(metaData.getInt(META_DATA_PREFERENCE_ICON));
title = res.getString(metaData.getInt(META_DATA_PREFERENCE_TITLE));
summary = res.getString(metaData.getInt(META_DATA_PREFERENCE_SUMMARY));
}
} catch (NameNotFoundException e) {
// Ignore
} catch (NotFoundException e) {
// Ignore
}
// Set the preference title to the activity's label if no
// meta-data is found
if (TextUtils.isEmpty(title)) {
title = resolveInfo.loadLabel(pm).toString();
}
// Set icon, title and summary for the preference
// TODO:
//header.icon = icon;
header.title = title;
header.summary = summary;
// Replace the intent with this specific activity
header.intent = new Intent().setClassName(resolveInfo.activityInfo.packageName,
resolveInfo.activityInfo.name);
return true;
}
}
}
// Did not find a matching activity, so remove the preference
target.remove(header);
return false;
}
public static boolean updateTileToSpecificActivityFromMetaDataOrRemove(Context context, public static boolean updateTileToSpecificActivityFromMetaDataOrRemove(Context context,
DashboardCategory target, DashboardTile tile) { DashboardCategory target, DashboardTile tile) {

View File

@@ -1,177 +0,0 @@
/*
* Copyright (C) 2014 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.android.settings.dashboard;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;
/**
* Description of a single Header item that the user can select.
*/
public class Header implements Parcelable {
/**
* Default value for {@link Header#id Header.id} indicating that no
* identifier value is set. All other values (including those below -1)
* are valid.
*/
public static final long HEADER_ID_UNDEFINED = -1;
/**
* Identifier for this header, to correlate with a new list when
* it is updated. The default value is
* {@link Header#HEADER_ID_UNDEFINED}, meaning no id.
* @attr ref android.R.styleable#PreferenceHeader_id
*/
public long id = HEADER_ID_UNDEFINED;
/**
* Resource ID of title of the header that is shown to the user.
* @attr ref android.R.styleable#PreferenceHeader_title
*/
public int titleRes;
/**
* Title of the header that is shown to the user.
* @attr ref android.R.styleable#PreferenceHeader_title
*/
public CharSequence title;
/**
* Resource ID of optional summary describing what this header controls.
* @attr ref android.R.styleable#PreferenceHeader_summary
*/
public int summaryRes;
/**
* Optional summary describing what this header controls.
* @attr ref android.R.styleable#PreferenceHeader_summary
*/
public CharSequence summary;
/**
* Optional icon resource to show for this header.
* @attr ref android.R.styleable#PreferenceHeader_icon
*/
public int iconRes;
/**
* Full class name of the fragment to display when this header is
* selected.
* @attr ref android.R.styleable#PreferenceHeader_fragment
*/
public String fragment;
/**
* Optional arguments to supply to the fragment when it is
* instantiated.
*/
public Bundle fragmentArguments;
/**
* Intent to launch when the preference is selected.
*/
public Intent intent;
/**
* Optional additional data for use by subclasses of the activity
*/
public Bundle extras;
public Header() {
// Empty
}
/**
* Return the currently set title. If {@link #titleRes} is set,
* this resource is loaded from <var>res</var> and returned. Otherwise
* {@link #title} is returned.
*/
public CharSequence getTitle(Resources res) {
if (titleRes != 0) {
return res.getText(titleRes);
}
return title;
}
/**
* Return the currently set summary. If {@link #summaryRes} is set,
* this resource is loaded from <var>res</var> and returned. Otherwise
* {@link #summary} is returned.
*/
public CharSequence getSummary(Resources res) {
if (summaryRes != 0) {
return res.getText(summaryRes);
}
return summary;
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeLong(id);
dest.writeInt(titleRes);
TextUtils.writeToParcel(title, dest, flags);
dest.writeInt(summaryRes);
TextUtils.writeToParcel(summary, dest, flags);
dest.writeInt(iconRes);
dest.writeString(fragment);
dest.writeBundle(fragmentArguments);
if (intent != null) {
dest.writeInt(1);
intent.writeToParcel(dest, flags);
} else {
dest.writeInt(0);
}
dest.writeBundle(extras);
}
public void readFromParcel(Parcel in) {
id = in.readLong();
titleRes = in.readInt();
title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
summaryRes = in.readInt();
summary = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in);
iconRes = in.readInt();
fragment = in.readString();
fragmentArguments = in.readBundle();
if (in.readInt() != 0) {
intent = Intent.CREATOR.createFromParcel(in);
}
extras = in.readBundle();
}
Header(Parcel in) {
readFromParcel(in);
}
public static final Creator<Header> CREATOR = new Creator<Header>() {
public Header createFromParcel(Parcel source) {
return new Header(source);
}
public Header[] newArray(int size) {
return new Header[size];
}
};
}