Use PreferenceActivity and FragmentBreadCrumbs as they offer the same capabilities now.
Also fix: 2997438 and a similar bug in Tether Settings Show + menu item for User Dictionary
This commit is contained in:
@@ -20,8 +20,8 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ApplicationInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.pm.ResolveInfo;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.content.res.Resources;
|
||||
import android.content.res.Resources.NotFoundException;
|
||||
import android.graphics.drawable.Drawable;
|
||||
@@ -29,9 +29,9 @@ import android.os.Bundle;
|
||||
import android.os.SystemProperties;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceGroup;
|
||||
import android.preference.PreferenceActivity.Header;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -203,6 +203,66 @@ public class Utils {
|
||||
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
|
||||
if (target.remove(header)) System.err.println("Removed " + header.id);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if Monkey is running.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user