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

@@ -58,7 +58,6 @@ import android.widget.ListView;
import android.widget.TabWidget;
import com.android.settings.dashboard.DashboardCategory;
import com.android.settings.dashboard.DashboardTile;
import com.android.settings.dashboard.Header;
import java.io.IOException;
import java.io.InputStream;
@@ -152,154 +151,6 @@ public class Utils {
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,
DashboardCategory target, DashboardTile tile) {