cmsdk: Add search resources plumbing for CMParts
Change-Id: I541bbbabd81eb249b7696f23d5122b6a5f4f8f50
This commit is contained in:
@@ -36,6 +36,9 @@ public class PartInfo implements Parcelable {
|
||||
|
||||
private boolean mAvailable = true;
|
||||
|
||||
/* for search provider */
|
||||
private int mXmlRes = 0;
|
||||
|
||||
public PartInfo(String name, String title, String summary) {
|
||||
mName = name;
|
||||
mTitle = title;
|
||||
@@ -56,6 +59,7 @@ public class PartInfo implements Parcelable {
|
||||
mFragmentClass = parcel.readString();
|
||||
mIconRes = parcel.readInt();
|
||||
mAvailable = parcel.readInt() == 1;
|
||||
mXmlRes = parcel.readInt();
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@@ -90,6 +94,10 @@ public class PartInfo implements Parcelable {
|
||||
|
||||
public void setAvailable(boolean available) { mAvailable = available; }
|
||||
|
||||
public int getXmlRes() { return mXmlRes; }
|
||||
|
||||
public void setXmlRes(int xmlRes) { mXmlRes = xmlRes; }
|
||||
|
||||
public void updateFrom(PartInfo other) {
|
||||
if (other == null) {
|
||||
return;
|
||||
@@ -102,12 +110,13 @@ public class PartInfo implements Parcelable {
|
||||
setFragmentClass(other.getFragmentClass());
|
||||
setIconRes(other.getIconRes());
|
||||
setAvailable(other.isAvailable());
|
||||
setXmlRes(other.getXmlRes());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("PartInfo=[ name=%s title=%s summary=%s fragment=%s ]",
|
||||
mName, mTitle, mSummary, mFragmentClass);
|
||||
return String.format("PartInfo=[ name=%s title=%s summary=%s fragment=%s xmlRes=%x ]",
|
||||
mName, mTitle, mSummary, mFragmentClass, mXmlRes);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -125,7 +134,7 @@ public class PartInfo implements Parcelable {
|
||||
out.writeString(mFragmentClass);
|
||||
out.writeInt(mIconRes);
|
||||
out.writeInt(mAvailable ? 1 : 0);
|
||||
|
||||
out.writeInt(mXmlRes);
|
||||
parcelInfo.complete();
|
||||
}
|
||||
|
||||
@@ -135,9 +144,7 @@ public class PartInfo implements Parcelable {
|
||||
|
||||
public Intent getIntentForActivity() {
|
||||
Intent i = new Intent(getAction());
|
||||
ComponentName cn = new ComponentName(PartsList.CMPARTS_PACKAGE,
|
||||
PartsList.CMPARTS_PACKAGE + ".PartsActivity");
|
||||
i.setComponent(cn);
|
||||
i.setComponent(PartsList.CMPARTS_ACTIVITY);
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.cyanogenmod.internal.cmparts;
|
||||
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
@@ -32,6 +33,7 @@ import org.xmlpull.v1.XmlPullParserException;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import static com.android.internal.R.styleable.Preference;
|
||||
@@ -41,6 +43,8 @@ import static com.android.internal.R.styleable.Preference_key;
|
||||
import static com.android.internal.R.styleable.Preference_summary;
|
||||
import static com.android.internal.R.styleable.Preference_title;
|
||||
|
||||
import static cyanogenmod.platform.R.styleable.cm_Searchable;
|
||||
import static cyanogenmod.platform.R.styleable.cm_Searchable_xmlRes;
|
||||
|
||||
public class PartsList {
|
||||
|
||||
@@ -50,9 +54,12 @@ public class PartsList {
|
||||
public static final String EXTRA_PART_KEY = "key";
|
||||
|
||||
public static final String CMPARTS_PACKAGE = "org.cyanogenmod.cmparts";
|
||||
public static final ComponentName CMPARTS_ACTIVITY = new ComponentName(
|
||||
CMPARTS_PACKAGE, CMPARTS_PACKAGE + ".PartsActivity");
|
||||
|
||||
public static final String PARTS_ACTION_PREFIX = CMPARTS_PACKAGE + ".parts";
|
||||
|
||||
private static final Map<String, PartInfo> sParts = new ArrayMap<String, PartInfo>();
|
||||
private static final Map<String, PartInfo> sParts = new ArrayMap<>();
|
||||
|
||||
private static final AtomicBoolean sCatalogLoaded = new AtomicBoolean(false);
|
||||
|
||||
@@ -78,6 +85,15 @@ public class PartsList {
|
||||
}
|
||||
}
|
||||
|
||||
public static Set<String> getPartsList(Context context) {
|
||||
synchronized (sParts) {
|
||||
if (!sCatalogLoaded.get()) {
|
||||
loadParts(context);
|
||||
}
|
||||
return sParts.keySet();
|
||||
}
|
||||
}
|
||||
|
||||
public static PartInfo getPartInfo(Context context, String key) {
|
||||
synchronized (sParts) {
|
||||
if (!sCatalogLoaded.get()) {
|
||||
@@ -172,6 +188,10 @@ public class PartsList {
|
||||
|
||||
info.setFragmentClass(sa.getString(Preference_fragment));
|
||||
info.setIconRes(sa.getResourceId(Preference_icon, 0));
|
||||
|
||||
sa = res.obtainAttributes(attrs, cm_Searchable);
|
||||
info.setXmlRes(sa.getResourceId(cm_Searchable_xmlRes, 0));
|
||||
|
||||
sa.recycle();
|
||||
|
||||
target.put(key, info);
|
||||
|
||||
Reference in New Issue
Block a user