android.content.res.XmlResourceParser Java Examples

The following examples show how to use android.content.res.XmlResourceParser. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AutoInstallsLayout.java    From LB-Launcher with Apache License 2.0 6 votes vote down vote up
@Override
public long parseAndAdd(XmlResourceParser parser) {
    final String packageName = getAttributeValue(parser, ATTR_PACKAGE_NAME);
    final String className = getAttributeValue(parser, ATTR_CLASS_NAME);
    if (TextUtils.isEmpty(packageName) || TextUtils.isEmpty(className)) {
        if (LOGD) Log.d(TAG, "Skipping invalid <favorite> with no component");
        return -1;
    }

    mValues.put(Favorites.RESTORED, ShortcutInfo.FLAG_AUTOINTALL_ICON);
    final Intent intent = new Intent(Intent.ACTION_MAIN, null)
        .addCategory(Intent.CATEGORY_LAUNCHER)
        .setComponent(new ComponentName(packageName, className))
        .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK |
                Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    return addShortcut(mContext.getString(R.string.package_state_unknown), intent,
            Favorites.ITEM_TYPE_APPLICATION);
}
 
Example #2
Source File: XmlPreferenceParser.java    From WearPreferenceActivity with Apache License 2.0 6 votes vote down vote up
@NonNull
private WearPreferenceScreen parseScreen(@NonNull final Context context, @NonNull final XmlResourceParser parser)
        throws XmlPullParserException, IOException {

    while(parser.getName() == null) {
        parser.next();
    }

    if("PreferenceScreen".equals(parser.getName())) {
        final WearPreferenceScreen screen = new WearPreferenceScreen(context, parser);
        parsePreferences(context, parser, screen);
        return screen;
    } else {
        throw new IllegalArgumentException("Preferences file must start with a PreferenceScreen element");
    }
}
 
Example #3
Source File: ResourceDump.java    From AppTroy with Apache License 2.0 6 votes vote down vote up
private void getAttributes(StringBuilder sb, XmlResourceParser parser) throws XmlPullParserException {
    int count = parser.getAttributeCount();
    for (int i = 0; i < count; i++) {
        sb.append(" ");
        String namespace = parser.getAttributeNamespace(i);
        if (namespace != null) {
            int index = namespace.lastIndexOf("/");
            if (index > 0) {
                namespace = namespace.substring(index + 1);
            }
            sb.append(namespace);
            sb.append(":");
        }
        sb.append(parser.getAttributeName(i));
        sb.append("=");
        sb.append(parser.getAttributeValue(i));
    }
}
 
Example #4
Source File: DefaultLayoutParser.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
@Override
public long parseAndAdd(XmlResourceParser parser) throws XmlPullParserException,
        IOException {
    // Folder contents come from an external XML resource
    final Partner partner = Partner.get(mPackageManager);
    if (partner != null) {
        final Resources partnerRes = partner.getResources();
        final int resId = partnerRes.getIdentifier(Partner.RES_FOLDER,
                "xml", partner.getPackageName());
        if (resId != 0) {
            final XmlResourceParser partnerParser = partnerRes.getXml(resId);
            beginDocument(partnerParser, TAG_FOLDER);

            FolderParser folderParser = new FolderParser(getFolderElementsMap(partnerRes));
            return folderParser.parseAndAdd(partnerParser);
        }
    }
    return -1;
}
 
Example #5
Source File: KeyboardLayoutSet.java    From simple-keyboard with Apache License 2.0 6 votes vote down vote up
private void parseKeyboardLayoutSet(final Resources res, final int resId)
        throws XmlPullParserException, IOException {
    final XmlResourceParser parser = res.getXml(resId);
    try {
        while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
            final int event = parser.next();
            if (event == XmlPullParser.START_TAG) {
                final String tag = parser.getName();
                if (TAG_KEYBOARD_SET.equals(tag)) {
                    parseKeyboardLayoutSetContent(parser);
                } else {
                    throw new XmlParseUtils.IllegalStartTag(parser, tag, TAG_KEYBOARD_SET);
                }
            }
        }
    } finally {
        parser.close();
    }
}
 
Example #6
Source File: DefaultLayoutParser.java    From LB-Launcher with Apache License 2.0 6 votes vote down vote up
@Override
public long parseAndAdd(XmlResourceParser parser) throws XmlPullParserException,
        IOException {
    // Folder contents come from an external XML resource
    final Partner partner = Partner.get(mPackageManager);
    if (partner != null) {
        final Resources partnerRes = partner.getResources();
        final int resId = partnerRes.getIdentifier(Partner.RES_FOLDER,
                "xml", partner.getPackageName());
        if (resId != 0) {
            final XmlResourceParser partnerParser = partnerRes.getXml(resId);
            beginDocument(partnerParser, TAG_FOLDER);

            FolderParser folderParser = new FolderParser(getFolderElementsMap(partnerRes));
            return folderParser.parseAndAdd(partnerParser);
        }
    }
    return -1;
}
 
Example #7
Source File: Keyboard.java    From libcommon with Apache License 2.0 6 votes vote down vote up
public Row(Resources res, @NonNull final  Keyboard parent, XmlResourceParser parser) {
	if (DEBUG) Log.v(TAG, "コンストラクタ:");
	this.parent = parent;
	TypedArray a = res.obtainAttributes(Xml.asAttributeSet(parser),
		R.styleable.Keyboard);
	defaultWidth = getDimensionOrFraction(a,
		R.styleable.Keyboard_keyWidth,
		parent.mDisplayWidth, parent.mDefaultWidth);
	defaultHeight = getDimensionOrFraction(a,
		R.styleable.Keyboard_keyHeight,
		parent.mDisplayHeight, parent.mDefaultHeight);
	defaultHorizontalGap = getDimensionOrFraction(a,
		R.styleable.Keyboard_horizontalGap,
		parent.mDisplayWidth, parent.mDefaultHorizontalGap);
	verticalGap = getDimensionOrFraction(a,
		R.styleable.Keyboard_verticalGap,
		parent.mDisplayHeight, parent.mDefaultVerticalGap);
	a.recycle();
	a = res.obtainAttributes(Xml.asAttributeSet(parser), R.styleable.Keyboard_Row);
	rowEdgeFlags = a.getInt(R.styleable.Keyboard_Row_rowEdgeFlags, 0);
	mode = a.getResourceId(R.styleable.Keyboard_Row_keyboardMode, 0);
	a.recycle();
}
 
Example #8
Source File: LatinKeyboard.java    From hackerskeyboard with Apache License 2.0 6 votes vote down vote up
@Override
protected Key createKeyFromXml(Resources res, Row parent, int x, int y,
        XmlResourceParser parser) {
    Key key = new LatinKey(res, parent, x, y, parser);
    if (key.codes == null) return key;
    switch (key.codes[0]) {
    case LatinIME.ASCII_ENTER:
        mEnterKey = key;
        break;
    case LatinKeyboardView.KEYCODE_F1:
        mF1Key = key;
        break;
    case LatinIME.ASCII_SPACE:
        mSpaceKey = key;
        break;
    case KEYCODE_MODE_CHANGE:
        m123Key = key;
        m123Label = key.label;
        break;
    }

    return key;
}
 
Example #9
Source File: KeyboardLayoutSet.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 6 votes vote down vote up
static int readScriptId(final Resources resources, final InputMethodSubtype subtype) {
    final String layoutSetName = KEYBOARD_LAYOUT_SET_RESOURCE_PREFIX
            + SubtypeLocaleUtils.getKeyboardLayoutSetName(subtype);
    final int xmlId = getXmlId(resources, layoutSetName);
    final XmlResourceParser parser = resources.getXml(xmlId);
    try {
        while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
            // Bovinate through the XML stupidly searching for TAG_FEATURE, and read
            // the script Id from it.
            parser.next();
            final String tag = parser.getName();
            if (TAG_FEATURE.equals(tag)) {
                return readScriptIdFromTagFeature(resources, parser);
            }
        }
    } catch (final IOException | XmlPullParserException e) {
        throw new RuntimeException(e.getMessage() + " in " + layoutSetName, e);
    } finally {
        parser.close();
    }
    // If the tag is not found, then the default script is Latin.
    return ScriptUtils.SCRIPT_LATIN;
}
 
Example #10
Source File: XmlConfigSource.java    From cwac-netsecurity with Apache License 2.0 6 votes vote down vote up
private CertificatesEntryRef parseCertificatesEntry(XmlResourceParser parser,
            boolean defaultOverridePins)
            throws IOException, XmlPullParserException, ParserException {
        boolean overridePins =
                parser.getAttributeBooleanValue(null, "overridePins", defaultOverridePins);
        int sourceId = parser.getAttributeResourceValue(null, "src", -1);
        String sourceString = parser.getAttributeValue(null, "src");
        CertificateSource source = null;
        if (sourceString == null) {
            throw new ParserException(parser, "certificates element missing src attribute");
        }
        if (sourceId != -1) {
            // TODO: Cache ResourceCertificateSources by sourceId
            source = new ResourceCertificateSource(sourceId, mContext);
        } else if ("system".equals(sourceString) || "user".equals(sourceString)) {
            // MLM treat user as system
            source = SystemCertificateSource.getInstance();
//        } else if ("user".equals(sourceString)) {
//            source = UserCertificateSource.getInstance();
        } else {
            throw new ParserException(parser, "Unknown certificates src. "
                    + "Should be one of system|user|@resourceVal");
        }
        XmlUtils.skipCurrentTag(parser);
        return new CertificatesEntryRef(source, overridePins);
    }
 
Example #11
Source File: LatinKeyboard.java    From java-n-IDE-for-Android with Apache License 2.0 6 votes vote down vote up
@Override
protected Key createKeyFromXml(Resources res, Row parent, int x, int y, XmlResourceParser parser) {
    Key key = new LatinKey(res, parent, x, y, parser);

    if (key.codes[0] == 13) {
        mEnterKey = key;
    } else if (key.codes[0] == TerminalKeyboard.CTRL_KEY) {
        mCtrlKey = key;
    } else if (key.codes[0] == TerminalKeyboard.ALT_KEY) {
        mALTKey = key;
    } else if (key.codes[0] == -1) {
        mShiftKeyLeft = key;
    } else if (key.codes[0] == -999) {
        mShiftKeyRight = key;
    } else if (key.codes[0] == -2) {
        mFNKey = key;
    }

    return key;
}
 
Example #12
Source File: PreferencesXmlParser.java    From aptoide-client-v8 with GNU General Public License v3.0 6 votes vote down vote up
public List<String[]> parse(XmlResourceParser parser) throws IOException, XmlPullParserException {
  ArrayList<String[]> data = new ArrayList<>();
  while (eventType != XmlResourceParser.END_DOCUMENT) {
    if (eventType == XmlResourceParser.START_TAG) {
      String defaultValue = parser.getAttributeValue(NAMESPACE, DEFAULT_VALUE);
      String key = parser.getAttributeValue(NAMESPACE, KEY);
      if (defaultValue != null) {
        String[] keyValue = new String[2];
        keyValue[0] = key;
        keyValue[1] = defaultValue;
        data.add(keyValue);
      }
    }
    eventType = parser.next();
  }
  return data;
}
 
Example #13
Source File: FloatingSearchView.java    From FloatingSearchView with Apache License 2.0 6 votes vote down vote up
public void inflateMenu(@MenuRes int menuRes) {
    if(menuRes == 0) return;
    if (isInEditMode()) return;
    getActivity().getMenuInflater().inflate(menuRes, mActionMenu.getMenu());

    XmlResourceParser parser = null;
    try {
        //noinspection ResourceType
        parser = getResources().getLayout(menuRes);
        AttributeSet attrs = Xml.asAttributeSet(parser);
        parseMenu(parser, attrs);
    } catch (XmlPullParserException | IOException e) {
        // should not happens
        throw new InflateException("Error parsing menu XML", e);
    } finally {
        if (parser != null) parser.close();
    }
}
 
Example #14
Source File: UENavigationFragmentActivity.java    From Auie with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 读取XML配置文件
 * @param id 配置文件索引
 */
private void readXML(int id){
	String name;
	String className = getClass().getSimpleName();
	XmlResourceParser xrp = getResources().getXml(id);
	try {
		while(xrp.getEventType() != XmlResourceParser.END_DOCUMENT){
			if (xrp.getEventType() == XmlResourceParser.START_TAG) {
				name = xrp.getName();
				if (name.equals("BackgroundColor")) {
					mNavigationView.setBackgroundColor(xrp.getAttributeIntValue(0, mNavigationView.getBackgroundColor()));
				}
				if (name.equals("StatusType")) {
					mNavigationView.setStatusType(xrp.getAttributeIntValue(0, mNavigationView.getStatusType()));
				}
				if (name.equals("TitleColor")) {
					mNavigationView.setTitleColor(xrp.getAttributeIntValue(0, mNavigationView.getTitleColor()));
				}
				if (name.equals("LineBackgroundColor")) {
					mNavigationView.setLineBackgroundColor(xrp.getAttributeIntValue(0, mNavigationView.getTitleColor()));
				}
				if (name.equals("NavigationTextColor")) {
					mNavigationView.setNavigationTextColor(xrp.getAttributeIntValue(0, mNavigationView.getNavigationTextColor()));
				}
				if (name.equals("Title") && xrp.getAttributeValue(0).equals(className)) {
					mNavigationView.setTitle(xrp.getAttributeValue(1));
				}
			}
			xrp.next();
		}
	} catch (Exception e) {
		Log.d(UE.TAG, "UEConfig配置出错"+e.toString());
	}
}
 
Example #15
Source File: BrowserServicePackageValidator.java    From Jockey with Apache License 2.0 5 votes vote down vote up
private Map<String, ArrayList<CallerInfo>> readValidCertificates(XmlResourceParser parser) {
    HashMap<String, ArrayList<CallerInfo>> validCertificates = new HashMap<>();
    try {
        int eventType = parser.next();
        while (eventType != XmlResourceParser.END_DOCUMENT) {
            if (eventType == XmlResourceParser.START_TAG
                    && parser.getName().equals("signing_certificate")) {

                String name = parser.getAttributeValue(null, "name");
                String packageName = parser.getAttributeValue(null, "package");
                boolean isRelease = parser.getAttributeBooleanValue(null, "release", false);
                String certificate = parser.nextText().replaceAll("\\s|\\n", "");

                CallerInfo info = new CallerInfo(name, packageName, isRelease);

                ArrayList<CallerInfo> infos = validCertificates.get(certificate);
                if (infos == null) {
                    infos = new ArrayList<>();
                    validCertificates.put(certificate, infos);
                }
                Timber.v("Adding allowed caller: %s package=%s release=%b certificate=%s",
                        info.name, info.packageName, info.release, certificate);
                infos.add(info);
            }
            eventType = parser.next();
        }
    } catch (XmlPullParserException | IOException e) {
        Timber.e(e, "Could not read allowed callers from XML.");
    }

    return validCertificates;
}
 
Example #16
Source File: EnvThirdResources.java    From Android_Skin_2.0 with Apache License 2.0 5 votes vote down vote up
private ColorStateList loadColorStateList(TypedValue value, int id) throws NotFoundException {
	final long key = (((long) value.assetCookie) << 32) | value.data;
	ColorStateList csl;
	if (value.type >= TypedValue.TYPE_FIRST_COLOR_INT && value.type <= TypedValue.TYPE_LAST_COLOR_INT) {
		csl = ColorStateList.valueOf(value.data);
		return csl;
	}
	csl = getCachedColorStateList(key);
	if (csl != null) {
		return csl;
	}
	if (value.string == null) {
		throw new NotFoundException("Resource is not a ColorStateList (color or path): " + value);
	}
	String file = value.string.toString();
	if (file.endsWith(".xml")) {
		try {
			XmlResourceParser rp = loadXmlResourceParserReflect(file, id, value.assetCookie, "colorstatelist");
			if (rp == null) {
				rp = loadXmlResourceParserEqual(file, id, value.assetCookie, "colorstatelist");
			}
			csl = ColorStateList.createFromXml(this, rp);
			rp.close();
		} catch (Exception e) {
			NotFoundException rnf = new NotFoundException("File " + file + " from color state list resource ID #0x" + Integer.toHexString(id));
			rnf.initCause(e);
			throw rnf;
		}
	} else {
		throw new NotFoundException("File " + file + " from drawable resource ID #0x" + Integer.toHexString(id) + ": .xml extension required");
	}
	if (csl != null) {
		synchronized (mAccessLock) {
			mColorStateListCache.put(key, new WeakReference<ColorStateList>(csl));
		}
	}
	return csl;
}
 
Example #17
Source File: BundleParser.java    From Small with Apache License 2.0 5 votes vote down vote up
private static void skipCurrentTag(XmlResourceParser parser)
        throws XmlPullParserException, IOException {
    int outerDepth = parser.getDepth();
    int type;
    while ((type=parser.next()) != XmlResourceParser.END_DOCUMENT
            && (type != XmlResourceParser.END_TAG
            || parser.getDepth() > outerDepth)) {
    }
}
 
Example #18
Source File: ResourceUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 获取 Animation
 * @param id resource identifier
 * @return XmlResourceParser
 */
public static XmlResourceParser getAnimation(@AnimatorRes @AnimRes final int id) {
    try {
        return DevUtils.getContext().getResources().getAnimation(id);
    } catch (Exception e) {
        LogPrintUtils.eTag(TAG, e, "getAnimation");
    }
    return null;
}
 
Example #19
Source File: AutoInstallsLayout.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Return attribute resource value, attempting launcher-specific namespace
 * first before falling back to anonymous attribute.
 */
static int getAttributeResourceValue(XmlResourceParser parser, String attribute,
        int defaultValue) {
    int value = parser.getAttributeResourceValue(
            "http://schemas.android.com/apk/res-auto/com.enrico.launcher3", attribute,
            defaultValue);
    if (value == defaultValue) {
        value = parser.getAttributeResourceValue(null, attribute, defaultValue);
    }
    return value;
}
 
Example #20
Source File: SpriteSheetAnimation.java    From tilt-game-android with MIT License 5 votes vote down vote up
public void setSpriteSheet(String animationId, Bitmap spritesheet, XmlResourceParser xml) {
	if (!animationId.equals(_animationId) || _animation == null) {
		_animationId = animationId;

		_animation = spritesheet;
		_index = 0;

		_frames = parseXML(xml);
	}
}
 
Example #21
Source File: XmlPreferenceParser.java    From WearPreferenceActivity with Apache License 2.0 5 votes vote down vote up
@NonNull
private WearPreference parsePreferenceInternal(@NonNull final Context context, @NonNull final String name, @NonNull final XmlResourceParser parser) {
    switch(parser.getName()) {
        case "ListPreference":
            return new WearListPreference(context, parser);
        case "SwitchPreference":
        case "CheckBoxPreference":
            return new WearTwoStatePreference(context, parser);
        default:
            return parsePreferenceUsingReflection(context, name, parser);
    }
}
 
Example #22
Source File: DevicePluginXmlUtil.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * 指定されたパッケージ名からサービスのコンポーネント情報を取得します.
 *
 * @param context コンテキスト
 * @param packageName パッケージ名
 * @return コンポーネント情報
 */
private static ServiceInfo getServiceInfo(final Context context, final String packageName) {
    try {
        PackageManager pkgMgr = context.getPackageManager();
        PackageInfo pkg = pkgMgr.getPackageInfo(packageName, PackageManager.GET_SERVICES);
        if (pkg != null) {
            ServiceInfo[] services = pkg.services;
            if (services != null) {
                for (int i = 0; i < services.length; i++) {
                    String pkgName = services[i].packageName;
                    String className = services[i].name;
                    ComponentName component = new ComponentName(pkgName, className);
                    ServiceInfo serviceInfo = pkgMgr.getServiceInfo(component, PackageManager.GET_META_DATA);
                    if (serviceInfo.metaData != null) {
                        Object xmlData = serviceInfo.metaData.get(PLUGIN_META_DATA);
                        if (xmlData instanceof Integer) {
                            XmlResourceParser xrp = serviceInfo.loadXmlMetaData(pkgMgr, PLUGIN_META_DATA);
                            if (xrp != null) {
                                return serviceInfo;
                            }
                        }
                    }
                }
            }
        }
        return null;
    } catch (NameNotFoundException e) {
        return null;
    }
}
 
Example #23
Source File: Keyboard.java    From WirelessHid with Apache License 2.0 5 votes vote down vote up
private String getStringAttributeValue(XmlResourceParser xmlParser, String attributeName,
        String defaultValue) {
    String value = xmlParser.getAttributeValue(null, attributeName);
    if (value != null)
        return value;
    return defaultValue;
}
 
Example #24
Source File: SettingChangeLogDialog.java    From iBeebo with GNU General Public License v3.0 5 votes vote down vote up
private String ParseReleaseTag(XmlResourceParser aXml) throws XmlPullParserException, IOException {
    String _Result = "<h1>Release: " + aXml.getAttributeValue(null, "version") + "</h1><ul>";
    int eventType = aXml.getEventType();
    while ((eventType != XmlPullParser.END_TAG) || (aXml.getName().equals("change"))) {
        if ((eventType == XmlPullParser.START_TAG) && (aXml.getName().equals("change"))) {
            eventType = aXml.next();
            _Result = _Result + "<li>" + aXml.getText() + "</li>";
        }
        eventType = aXml.next();
    }
    _Result = _Result + "</ul>";
    return _Result;
}
 
Example #25
Source File: CustomKeyboard.java    From FirefoxReality with Mozilla Public License 2.0 5 votes vote down vote up
@Override
protected Key createKeyFromXml(Resources res, Row parent, int x, int y, XmlResourceParser parser) {
    Key key = super.createKeyFromXml(res, parent, x, y, parser);
    if (key.codes[0] == KeyEvent.KEYCODE_ENTER || key.codes[0] == Keyboard.KEYCODE_DONE) {
        mEnterKey = key;
    } else if (key.codes[0] == ' ') {
        mSpaceKey = key;
    } else if (key.codes[0] == Keyboard.KEYCODE_MODE_CHANGE) {
        mModeChangeKey = key;
    }

    return key;
}
 
Example #26
Source File: AutoInstallsLayout.java    From LB-Launcher with Apache License 2.0 5 votes vote down vote up
/**
 * Parses the current node and returns the number of elements added.
 */
protected int parseAndAddNode(
        XmlResourceParser parser,
        HashMap<String, TagParser> tagParserMap,
        ArrayList<Long> screenIds)
                throws XmlPullParserException, IOException {
    mValues.clear();
    parseContainerAndScreen(parser, mTemp);
    final long container = mTemp[0];
    final long screenId = mTemp[1];

    mValues.put(Favorites.CONTAINER, container);
    mValues.put(Favorites.SCREEN, screenId);
    mValues.put(Favorites.CELLX, getAttributeValue(parser, ATTR_X));
    mValues.put(Favorites.CELLY, getAttributeValue(parser, ATTR_Y));

    TagParser tagParser = tagParserMap.get(parser.getName());
    if (tagParser == null) {
        if (LOGD) Log.d(TAG, "Ignoring unknown element tag: " + parser.getName());
        return 0;
    }
    long newElementId = tagParser.parseAndAdd(parser);
    if (newElementId >= 0) {
        // Keep track of the set of screens which need to be added to the db.
        if (!screenIds.contains(screenId) &&
                container == Favorites.CONTAINER_DESKTOP) {
            screenIds.add(screenId);
        }
        return 1;
    }
    return 0;
}
 
Example #27
Source File: Keyboard.java    From libcommon with Apache License 2.0 5 votes vote down vote up
protected Key createKeyFromXml(@NonNull final Resources res,
	@NonNull final Row parent,
	final int x, final int y,
	@NonNull final XmlResourceParser parser) {

	if (DEBUG) Log.v(TAG, "createKeyFromXml:");
	return new Key(res, parent, x, y, parser);
}
 
Example #28
Source File: AppfilterReader.java    From NanoIconPack with Apache License 2.0 5 votes vote down vote up
private boolean init(@NonNull Resources resources) {
    try {
        XmlResourceParser parser = resources.getXml(R.xml.appfilter);
        int event = parser.getEventType();
        while (event != XmlPullParser.END_DOCUMENT) {
            if (event == XmlPullParser.START_TAG) {
                if (!"item".equals(parser.getName())) {
                    event = parser.next();
                    continue;
                }
                String drawable = parser.getAttributeValue(null, "drawable");
                if (TextUtils.isEmpty(drawable)) {
                    event = parser.next();
                    continue;
                }
                String component = parser.getAttributeValue(null, "component");
                if (TextUtils.isEmpty(component)) {
                    event = parser.next();
                    continue;
                }
                Matcher matcher = componentPattern.matcher(component);
                if (!matcher.matches()) {
                    event = parser.next();
                    continue;
                }
                dataList.add(new Bean(matcher.group(1), matcher.group(2), drawable));
            }
            event = parser.next();
        }
        return true;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return false;
}
 
Example #29
Source File: SearchableInfo.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
/**
 * Gets search information for the given activity.
 *
 * @param context Context to use for reading activity resources.
 * @param activityInfo Activity to get search information from.
 * @return Search information about the given activity, or {@code null} if
 *         the activity has no or invalid searchability meta-data.
 *
 * @hide For use by SearchManagerService.
 */
public static SearchableInfo getActivityMetaData(Context context, ActivityInfo activityInfo,
        int userId) {
    Context userContext = null;
    try {
        userContext = context.createPackageContextAsUser("system", 0,
            new UserHandle(userId));
    } catch (NameNotFoundException nnfe) {
        Log.e(LOG_TAG, "Couldn't create package context for user " + userId);
        return null;
    }
    // for each component, try to find metadata
    XmlResourceParser xml = 
            activityInfo.loadXmlMetaData(userContext.getPackageManager(), MD_LABEL_SEARCHABLE);
    if (xml == null) {
        return null;
    }
    ComponentName cName = new ComponentName(activityInfo.packageName, activityInfo.name);
    
    SearchableInfo searchable = getActivityMetaData(userContext, xml, cName);
    xml.close();
    
    if (DBG) {
        if (searchable != null) {
            Log.d(LOG_TAG, "Checked " + activityInfo.name
                    + ",label=" + searchable.getLabelId()
                    + ",icon=" + searchable.getIconId()
                    + ",suggestAuthority=" + searchable.getSuggestAuthority()
                    + ",target=" + searchable.getSearchActivity().getClassName()
                    + ",global=" + searchable.shouldIncludeInGlobalSearch()
                    + ",settingsDescription=" + searchable.getSettingsDescriptionId()
                    + ",threshold=" + searchable.getSuggestThreshold());
        } else {
            Log.d(LOG_TAG, "Checked " + activityInfo.name + ", no searchable meta-data");
        }
    }
    return searchable;
}
 
Example #30
Source File: AutoInstallsLayout.java    From LaunchEnr with GNU General Public License v3.0 5 votes vote down vote up
@Override
public long parseAndAdd(XmlResourceParser parser)
        throws XmlPullParserException, IOException {
    final String packageName = getAttributeValue(parser, ATTR_PACKAGE_NAME);
    final String className = getAttributeValue(parser, ATTR_CLASS_NAME);
    if (TextUtils.isEmpty(packageName) || TextUtils.isEmpty(className)) {
        return -1;
    }

    mValues.put(Favorites.SPANX, getAttributeValue(parser, ATTR_SPAN_X));
    mValues.put(Favorites.SPANY, getAttributeValue(parser, ATTR_SPAN_Y));
    mValues.put(Favorites.ITEM_TYPE, Favorites.ITEM_TYPE_APPWIDGET);

    // Read the extras
    Bundle extras = new Bundle();
    int widgetDepth = parser.getDepth();
    int type;
    while ((type = parser.next()) != XmlPullParser.END_TAG ||
            parser.getDepth() > widgetDepth) {
        if (type != XmlPullParser.START_TAG) {
            continue;
        }

        if (TAG_EXTRA.equals(parser.getName())) {
            String key = getAttributeValue(parser, ATTR_KEY);
            String value = getAttributeValue(parser, ATTR_VALUE);
            if (key != null && value != null) {
                extras.putString(key, value);
            } else {
                throw new RuntimeException("Widget extras must have a key and value");
            }
        } else {
            throw new RuntimeException("Widgets can contain only extras");
        }
    }

    return verifyAndInsert(new ComponentName(packageName, className), extras);
}