Search in sources :

Example 76 with AttributeSet

use of android.util.AttributeSet in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class SettingsInjector method parseServiceInfo.

/**
     * Returns the settings parsed from the attributes of the
     * {@link SettingInjectorService#META_DATA_NAME} tag, or null.
     *
     * Duplicates some code from {@link android.content.pm.RegisteredServicesCache}.
     */
private InjectedSetting parseServiceInfo(ResolveInfo service, UserHandle userHandle, PackageManager pm) throws XmlPullParserException, IOException {
    ServiceInfo si = service.serviceInfo;
    ApplicationInfo ai = si.applicationInfo;
    if ((ai.flags & ApplicationInfo.FLAG_SYSTEM) == 0) {
        if (Log.isLoggable(TAG, Log.WARN)) {
            Log.w(TAG, "Ignoring attempt to inject setting from app not in system image: " + service);
            return null;
        }
    } else if (!DimmableIZatIconPreference.showIzat(mContext, si.packageName)) {
        return null;
    }
    XmlResourceParser parser = null;
    try {
        parser = si.loadXmlMetaData(pm, SettingInjectorService.META_DATA_NAME);
        if (parser == null) {
            throw new XmlPullParserException("No " + SettingInjectorService.META_DATA_NAME + " meta-data for " + service + ": " + si);
        }
        AttributeSet attrs = Xml.asAttributeSet(parser);
        int type;
        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
        }
        String nodeName = parser.getName();
        if (!SettingInjectorService.ATTRIBUTES_NAME.equals(nodeName)) {
            throw new XmlPullParserException("Meta-data does not start with " + SettingInjectorService.ATTRIBUTES_NAME + " tag");
        }
        Resources res = pm.getResourcesForApplicationAsUser(si.packageName, userHandle.getIdentifier());
        return parseAttributes(si.packageName, si.name, userHandle, res, attrs);
    } catch (PackageManager.NameNotFoundException e) {
        throw new XmlPullParserException("Unable to load resources for package " + si.packageName);
    } finally {
        if (parser != null) {
            parser.close();
        }
    }
}
Also used : ServiceInfo(android.content.pm.ServiceInfo) XmlResourceParser(android.content.res.XmlResourceParser) PackageManager(android.content.pm.PackageManager) AttributeSet(android.util.AttributeSet) ApplicationInfo(android.content.pm.ApplicationInfo) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) Resources(android.content.res.Resources)

Example 77 with AttributeSet

use of android.util.AttributeSet in project android_frameworks_base by ResurrectionRemix.

the class KeyphraseEnrollmentInfo method getKeyphraseMetadataFromApplicationInfo.

private KeyphraseMetadata getKeyphraseMetadataFromApplicationInfo(PackageManager pm, ApplicationInfo ai, List<String> parseErrors) {
    XmlResourceParser parser = null;
    String packageName = ai.packageName;
    KeyphraseMetadata keyphraseMetadata = null;
    try {
        parser = ai.loadXmlMetaData(pm, VOICE_KEYPHRASE_META_DATA);
        if (parser == null) {
            String error = "No " + VOICE_KEYPHRASE_META_DATA + " meta-data for " + packageName;
            parseErrors.add(error);
            Slog.w(TAG, error);
            return null;
        }
        Resources res = pm.getResourcesForApplication(ai);
        AttributeSet attrs = Xml.asAttributeSet(parser);
        int type;
        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
        }
        String nodeName = parser.getName();
        if (!"voice-enrollment-application".equals(nodeName)) {
            String error = "Meta-data does not start with voice-enrollment-application tag for " + packageName;
            parseErrors.add(error);
            Slog.w(TAG, error);
            return null;
        }
        TypedArray array = res.obtainAttributes(attrs, com.android.internal.R.styleable.VoiceEnrollmentApplication);
        keyphraseMetadata = getKeyphraseFromTypedArray(array, packageName, parseErrors);
        array.recycle();
    } catch (XmlPullParserException e) {
        String error = "Error parsing keyphrase enrollment meta-data for " + packageName;
        parseErrors.add(error + ": " + e);
        Slog.w(TAG, error, e);
    } catch (IOException e) {
        String error = "Error parsing keyphrase enrollment meta-data for " + packageName;
        parseErrors.add(error + ": " + e);
        Slog.w(TAG, error, e);
    } catch (PackageManager.NameNotFoundException e) {
        String error = "Error parsing keyphrase enrollment meta-data for " + packageName;
        parseErrors.add(error + ": " + e);
        Slog.w(TAG, error, e);
    } finally {
        if (parser != null)
            parser.close();
    }
    return keyphraseMetadata;
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) PackageManager(android.content.pm.PackageManager) AttributeSet(android.util.AttributeSet) TypedArray(android.content.res.TypedArray) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) Resources(android.content.res.Resources) IOException(java.io.IOException)

Example 78 with AttributeSet

use of android.util.AttributeSet in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class VoiceInputHelper method buildUi.

public void buildUi() {
    // Get the currently selected interactor from the secure setting.
    String currentSetting = Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.VOICE_INTERACTION_SERVICE);
    if (currentSetting != null && !currentSetting.isEmpty()) {
        mCurrentVoiceInteraction = ComponentName.unflattenFromString(currentSetting);
    } else {
        mCurrentVoiceInteraction = null;
    }
    ArraySet<ComponentName> interactorRecognizers = new ArraySet<>();
    // Iterate through all the available interactors and load up their info to show
    // in the preference.
    int size = mAvailableVoiceInteractions.size();
    for (int i = 0; i < size; i++) {
        ResolveInfo resolveInfo = mAvailableVoiceInteractions.get(i);
        VoiceInteractionServiceInfo info = new VoiceInteractionServiceInfo(mContext.getPackageManager(), resolveInfo.serviceInfo);
        if (info.getParseError() != null) {
            Log.w("VoiceInteractionService", "Error in VoiceInteractionService " + resolveInfo.serviceInfo.packageName + "/" + resolveInfo.serviceInfo.name + ": " + info.getParseError());
            continue;
        }
        mAvailableInteractionInfos.add(new InteractionInfo(mContext.getPackageManager(), info));
        interactorRecognizers.add(new ComponentName(resolveInfo.serviceInfo.packageName, info.getRecognitionService()));
    }
    Collections.sort(mAvailableInteractionInfos);
    // Get the currently selected recognizer from the secure setting.
    currentSetting = Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.VOICE_RECOGNITION_SERVICE);
    if (currentSetting != null && !currentSetting.isEmpty()) {
        mCurrentRecognizer = ComponentName.unflattenFromString(currentSetting);
    } else {
        mCurrentRecognizer = null;
    }
    // Iterate through all the available recognizers and load up their info to show
    // in the preference.
    size = mAvailableRecognition.size();
    for (int i = 0; i < size; i++) {
        ResolveInfo resolveInfo = mAvailableRecognition.get(i);
        ComponentName comp = new ComponentName(resolveInfo.serviceInfo.packageName, resolveInfo.serviceInfo.name);
        if (interactorRecognizers.contains(comp)) {
        //continue;
        }
        ServiceInfo si = resolveInfo.serviceInfo;
        XmlResourceParser parser = null;
        String settingsActivity = null;
        try {
            parser = si.loadXmlMetaData(mContext.getPackageManager(), RecognitionService.SERVICE_META_DATA);
            if (parser == null) {
                throw new XmlPullParserException("No " + RecognitionService.SERVICE_META_DATA + " meta-data for " + si.packageName);
            }
            Resources res = mContext.getPackageManager().getResourcesForApplication(si.applicationInfo);
            AttributeSet attrs = Xml.asAttributeSet(parser);
            int type;
            while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
            }
            String nodeName = parser.getName();
            if (!"recognition-service".equals(nodeName)) {
                throw new XmlPullParserException("Meta-data does not start with recognition-service tag");
            }
            TypedArray array = res.obtainAttributes(attrs, com.android.internal.R.styleable.RecognitionService);
            settingsActivity = array.getString(com.android.internal.R.styleable.RecognitionService_settingsActivity);
            array.recycle();
        } catch (XmlPullParserException e) {
            Log.e(TAG, "error parsing recognition service meta-data", e);
        } catch (IOException e) {
            Log.e(TAG, "error parsing recognition service meta-data", e);
        } catch (PackageManager.NameNotFoundException e) {
            Log.e(TAG, "error parsing recognition service meta-data", e);
        } finally {
            if (parser != null)
                parser.close();
        }
        mAvailableRecognizerInfos.add(new RecognizerInfo(mContext.getPackageManager(), resolveInfo.serviceInfo, settingsActivity));
    }
    Collections.sort(mAvailableRecognizerInfos);
}
Also used : ArraySet(android.util.ArraySet) XmlResourceParser(android.content.res.XmlResourceParser) IOException(java.io.IOException) ResolveInfo(android.content.pm.ResolveInfo) VoiceInteractionServiceInfo(android.service.voice.VoiceInteractionServiceInfo) ServiceInfo(android.content.pm.ServiceInfo) PackageManager(android.content.pm.PackageManager) AttributeSet(android.util.AttributeSet) VoiceInteractionServiceInfo(android.service.voice.VoiceInteractionServiceInfo) TypedArray(android.content.res.TypedArray) ComponentName(android.content.ComponentName) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) Resources(android.content.res.Resources)

Example 79 with AttributeSet

use of android.util.AttributeSet in project MagicaSakura by Bilibili.

the class DrawableUtils method createDrawable.

static Drawable createDrawable(Context context, int resId) {
    if (resId <= 0)
        return null;
    final TypedValue typedValue = new TypedValue();
    final Resources res = context.getResources();
    res.getValue(resId, typedValue, true);
    Drawable dr = null;
    if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT && typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) {
        dr = new ColorDrawable(ThemeUtils.replaceColorById(context, resId));
    } else {
        try {
            if (typedValue.string != null && typedValue.string.toString().endsWith("xml")) {
                final XmlResourceParser rp = res.getXml(resId);
                final AttributeSet attrs = Xml.asAttributeSet(rp);
                int type;
                while ((type = rp.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
                // Empty loop
                }
                if (type != XmlPullParser.START_TAG) {
                    throw new XmlPullParserException("No start tag found");
                }
                dr = createFromXmlInner(context, rp, attrs);
                rp.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (XmlPullParserException e) {
            e.printStackTrace();
        }
    }
    return dr;
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) ColorDrawable(android.graphics.drawable.ColorDrawable) AttributeSet(android.util.AttributeSet) ColorDrawable(android.graphics.drawable.ColorDrawable) Drawable(android.graphics.drawable.Drawable) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) Resources(android.content.res.Resources) IOException(java.io.IOException) TypedValue(android.util.TypedValue)

Example 80 with AttributeSet

use of android.util.AttributeSet in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class KeyboardBuilder method parseKeyboardAttributes.

private void parseKeyboardAttributes(final XmlPullParser parser) {
    final AttributeSet attr = Xml.asAttributeSet(parser);
    final TypedArray keyboardAttr = mContext.obtainStyledAttributes(attr, R.styleable.Keyboard, R.attr.keyboardStyle, R.style.Keyboard);
    final TypedArray keyAttr = mResources.obtainAttributes(attr, R.styleable.Keyboard_Key);
    try {
        final KeyboardParams params = mParams;
        final int height = params.mId.mHeight;
        final int width = params.mId.mWidth;
        params.mOccupiedHeight = height;
        params.mOccupiedWidth = width;
        params.mTopPadding = (int) keyboardAttr.getFraction(R.styleable.Keyboard_keyboardTopPadding, height, height, 0);
        params.mBottomPadding = (int) keyboardAttr.getFraction(R.styleable.Keyboard_keyboardBottomPadding, height, height, 0);
        params.mLeftPadding = (int) keyboardAttr.getFraction(R.styleable.Keyboard_keyboardLeftPadding, width, width, 0);
        params.mRightPadding = (int) keyboardAttr.getFraction(R.styleable.Keyboard_keyboardRightPadding, width, width, 0);
        final int baseWidth = params.mOccupiedWidth - params.mLeftPadding - params.mRightPadding;
        params.mBaseWidth = baseWidth;
        params.mDefaultKeyWidth = (int) keyAttr.getFraction(R.styleable.Keyboard_Key_keyWidth, baseWidth, baseWidth, baseWidth / DEFAULT_KEYBOARD_COLUMNS);
        params.mHorizontalGap = (int) keyboardAttr.getFraction(R.styleable.Keyboard_horizontalGap, baseWidth, baseWidth, 0);
        // TODO: Fix keyboard geometry calculation clearer. Historically vertical gap between
        // rows are determined based on the entire keyboard height including top and bottom
        // paddings.
        params.mVerticalGap = (int) keyboardAttr.getFraction(R.styleable.Keyboard_verticalGap, height, height, 0);
        final int baseHeight = params.mOccupiedHeight - params.mTopPadding - params.mBottomPadding + params.mVerticalGap;
        params.mBaseHeight = baseHeight;
        params.mDefaultRowHeight = (int) ResourceUtils.getDimensionOrFraction(keyboardAttr, R.styleable.Keyboard_rowHeight, baseHeight, baseHeight / DEFAULT_KEYBOARD_ROWS);
        params.mKeyVisualAttributes = KeyVisualAttributes.newInstance(keyAttr);
        params.mMoreKeysTemplate = keyboardAttr.getResourceId(R.styleable.Keyboard_moreKeysTemplate, 0);
        params.mMaxMoreKeysKeyboardColumn = keyAttr.getInt(R.styleable.Keyboard_Key_maxMoreKeysColumn, 5);
        params.mThemeId = keyboardAttr.getInt(R.styleable.Keyboard_themeId, 0);
        params.mIconsSet.loadIcons(keyboardAttr);
        params.mTextsSet.setLocale(params.mId.getLocale(), mContext);
        final int resourceId = keyboardAttr.getResourceId(R.styleable.Keyboard_touchPositionCorrectionData, 0);
        if (resourceId != 0) {
            final String[] data = mResources.getStringArray(resourceId);
            params.mTouchPositionCorrection.load(data);
        }
    } finally {
        keyAttr.recycle();
        keyboardAttr.recycle();
    }
}
Also used : AttributeSet(android.util.AttributeSet) TypedArray(android.content.res.TypedArray)

Aggregations

AttributeSet (android.util.AttributeSet)262 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)160 IOException (java.io.IOException)125 XmlResourceParser (android.content.res.XmlResourceParser)113 TypedArray (android.content.res.TypedArray)78 Resources (android.content.res.Resources)46 Test (org.junit.Test)42 TypedValue (android.util.TypedValue)34 InflateException (android.view.InflateException)28 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)24 PackageManager (android.content.pm.PackageManager)22 Context (android.content.Context)20 ComponentName (android.content.ComponentName)18 XmlPullParser (org.xmlpull.v1.XmlPullParser)17 Intent (android.content.Intent)11 RemoteException (android.os.RemoteException)11 Bundle (android.os.Bundle)9 ArrayList (java.util.ArrayList)9 ActivityInfo (android.content.pm.ActivityInfo)7 ApplicationInfo (android.content.pm.ApplicationInfo)7