Example usage for android.content.res TypedArray getResourceId

List of usage examples for android.content.res TypedArray getResourceId

Introduction

In this page you can find the example usage for android.content.res TypedArray getResourceId.

Prototype

@AnyRes
public int getResourceId(@StyleableRes int index, int defValue) 

Source Link

Document

Retrieves the resource identifier for the attribute at index.

Usage

From source file:android.content.pm.PackageParser.java

private Permission parsePermission(Package owner, Resources res, XmlPullParser parser, AttributeSet attrs,
        String[] outError) throws XmlPullParserException, IOException {
    Permission perm = new Permission(owner);

    TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestPermission);

    if (!parsePackageItemInfo(owner, perm.info, outError, "<permission>", sa,
            com.android.internal.R.styleable.AndroidManifestPermission_name,
            com.android.internal.R.styleable.AndroidManifestPermission_label,
            com.android.internal.R.styleable.AndroidManifestPermission_icon,
            com.android.internal.R.styleable.AndroidManifestPermission_logo,
            com.android.internal.R.styleable.AndroidManifestPermission_banner)) {
        sa.recycle();//from   w ww  .java2s .  c  o m
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    // Note: don't allow this value to be a reference to a resource
    // that may change.
    perm.info.group = sa
            .getNonResourceString(com.android.internal.R.styleable.AndroidManifestPermission_permissionGroup);
    if (perm.info.group != null) {
        perm.info.group = perm.info.group.intern();
    }

    perm.info.descriptionRes = sa
            .getResourceId(com.android.internal.R.styleable.AndroidManifestPermission_description, 0);

    perm.info.protectionLevel = sa.getInt(
            com.android.internal.R.styleable.AndroidManifestPermission_protectionLevel,
            PermissionInfo.PROTECTION_NORMAL);

    perm.info.flags = sa.getInt(com.android.internal.R.styleable.AndroidManifestPermission_permissionFlags, 0);

    sa.recycle();

    if (perm.info.protectionLevel == -1) {
        outError[0] = "<permission> does not specify protectionLevel";
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    perm.info.protectionLevel = PermissionInfo.fixProtectionLevel(perm.info.protectionLevel);

    if ((perm.info.protectionLevel & PermissionInfo.PROTECTION_MASK_FLAGS) != 0) {
        if ((perm.info.protectionLevel
                & PermissionInfo.PROTECTION_MASK_BASE) != PermissionInfo.PROTECTION_SIGNATURE) {
            outError[0] = "<permission>  protectionLevel specifies a flag but is "
                    + "not based on signature type";
            mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
            return null;
        }
    }

    if (!parseAllMetaData(res, parser, attrs, "<permission>", perm, outError)) {
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return null;
    }

    owner.permissions.add(perm);

    return perm;
}

From source file:com.glview.widget.AbsListView.java

public AbsListView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);
    initAbsListView();/*  ww w.jav  a2s.  c  o m*/

    mOwnerThread = Thread.currentThread();

    final TypedArray a = context.obtainStyledAttributes(attrs, com.glview.R.styleable.AbsListView, defStyleAttr,
            defStyleRes);

    Drawable d = GLContext.get().getResources()
            .getDrawable(a.getResourceId(com.glview.R.styleable.AbsListView_listSelector, 0));
    if (d != null) {
        setSelector(d);
    }

    mDrawSelectorOnTop = a.getBoolean(com.glview.R.styleable.AbsListView_drawSelectorOnTop, false);

    boolean stackFromBottom = a.getBoolean(com.glview.R.styleable.AbsListView_stackFromBottom, false);
    setStackFromBottom(stackFromBottom);

    boolean scrollingCacheEnabled = a.getBoolean(com.glview.R.styleable.AbsListView_scrollingCache, true);
    setScrollingCacheEnabled(scrollingCacheEnabled);

    boolean useTextFilter = a.getBoolean(com.glview.R.styleable.AbsListView_textFilterEnabled, false);
    setTextFilterEnabled(useTextFilter);

    int transcriptMode = a.getInt(com.glview.R.styleable.AbsListView_transcriptMode, TRANSCRIPT_MODE_DISABLED);
    setTranscriptMode(transcriptMode);

    int color = a.getColor(com.glview.R.styleable.AbsListView_cacheColorHint, 0);
    setCacheColorHint(color);

    boolean enableFastScroll = a.getBoolean(com.glview.R.styleable.AbsListView_fastScrollEnabled, false);
    setFastScrollEnabled(enableFastScroll);

    int fastScrollStyle = a.getResourceId(com.glview.R.styleable.AbsListView_fastScrollStyle, 0);
    setFastScrollStyle(fastScrollStyle);

    boolean smoothScrollbar = a.getBoolean(com.glview.R.styleable.AbsListView_smoothScrollbar, true);
    setSmoothScrollbarEnabled(smoothScrollbar);

    setChoiceMode(a.getInt(com.glview.R.styleable.AbsListView_choiceMode, CHOICE_MODE_NONE));
    setFastScrollAlwaysVisible(a.getBoolean(com.glview.R.styleable.AbsListView_fastScrollAlwaysVisible, false));

    a.recycle();
}

From source file:android.app.Activity.java

/**
 * Standard implementation of/*ww w  . j  a  v  a 2s  .  c om*/
 * {@link android.view.LayoutInflater.Factory2#onCreateView(View, String, Context, AttributeSet)}
 * used when inflating with the LayoutInflater returned by {@link #getSystemService}.
 * This implementation handles <fragment> tags to embed fragments inside
 * of the activity.
 *
 * @see android.view.LayoutInflater#createView
 * @see android.view.Window#getLayoutInflater
 */
public View onCreateView(View parent, String name, Context context, AttributeSet attrs) {
    if (!"fragment".equals(name)) {
        return onCreateView(name, context, attrs);
    }

    String fname = attrs.getAttributeValue(null, "class");
    TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.Fragment);
    if (fname == null) {
        fname = a.getString(com.android.internal.R.styleable.Fragment_name);
    }
    int id = a.getResourceId(com.android.internal.R.styleable.Fragment_id, View.NO_ID);
    String tag = a.getString(com.android.internal.R.styleable.Fragment_tag);
    a.recycle();

    int containerId = parent != null ? parent.getId() : 0;
    if (containerId == View.NO_ID && id == View.NO_ID && tag == null) {
        throw new IllegalArgumentException(attrs.getPositionDescription()
                + ": Must specify unique android:id, android:tag, or have a parent with an id for " + fname);
    }

    // If we restored from a previous state, we may already have
    // instantiated this fragment from the state and should use
    // that instance instead of making a new one.
    Fragment fragment = id != View.NO_ID ? mFragments.findFragmentById(id) : null;
    if (fragment == null && tag != null) {
        fragment = mFragments.findFragmentByTag(tag);
    }
    if (fragment == null && containerId != View.NO_ID) {
        fragment = mFragments.findFragmentById(containerId);
    }

    if (FragmentManagerImpl.DEBUG)
        Log.v(TAG,
                "onCreateView: id=0x" + Integer.toHexString(id) + " fname=" + fname + " existing=" + fragment);
    if (fragment == null) {
        fragment = Fragment.instantiate(this, fname);
        fragment.mFromLayout = true;
        fragment.mFragmentId = id != 0 ? id : containerId;
        fragment.mContainerId = containerId;
        fragment.mTag = tag;
        fragment.mInLayout = true;
        fragment.mFragmentManager = mFragments;
        fragment.onInflate(this, attrs, fragment.mSavedFragmentState);
        mFragments.addFragment(fragment, true);

    } else if (fragment.mInLayout) {
        // A fragment already exists and it is not one we restored from
        // previous state.
        throw new IllegalArgumentException(attrs.getPositionDescription() + ": Duplicate id 0x"
                + Integer.toHexString(id) + ", tag " + tag + ", or parent id 0x"
                + Integer.toHexString(containerId) + " with another fragment for " + fname);
    } else {
        // This fragment was retained from a previous instance; get it
        // going now.
        fragment.mInLayout = true;
        // If this fragment is newly instantiated (either right now, or
        // from last saved state), then give it the attributes to
        // initialize itself.
        if (!fragment.mRetaining) {
            fragment.onInflate(this, attrs, fragment.mSavedFragmentState);
        }
        mFragments.moveToState(fragment);
    }

    if (fragment.mView == null) {
        throw new IllegalStateException("Fragment " + fname + " did not create a view.");
    }
    if (id != 0) {
        fragment.mView.setId(id);
    }
    if (fragment.mView.getTag() == null) {
        fragment.mView.setTag(tag);
    }
    return fragment.mView;
}

From source file:android.content.pm.PackageParser.java

private Activity parseActivity(Package owner, Resources res, XmlPullParser parser, AttributeSet attrs,
        int flags, String[] outError, boolean receiver, boolean hardwareAccelerated)
        throws XmlPullParserException, IOException {
    TypedArray sa = res.obtainAttributes(attrs, R.styleable.AndroidManifestActivity);

    if (mParseActivityArgs == null) {
        mParseActivityArgs = new ParseComponentArgs(owner, outError, R.styleable.AndroidManifestActivity_name,
                R.styleable.AndroidManifestActivity_label, R.styleable.AndroidManifestActivity_icon,
                R.styleable.AndroidManifestActivity_logo, R.styleable.AndroidManifestActivity_banner,
                mSeparateProcesses, R.styleable.AndroidManifestActivity_process,
                R.styleable.AndroidManifestActivity_description, R.styleable.AndroidManifestActivity_enabled);
    }// ww w  .ja  va2  s . c om

    mParseActivityArgs.tag = receiver ? "<receiver>" : "<activity>";
    mParseActivityArgs.sa = sa;
    mParseActivityArgs.flags = flags;

    Activity a = new Activity(mParseActivityArgs, new ActivityInfo());
    if (outError[0] != null) {
        sa.recycle();
        return null;
    }

    boolean setExported = sa.hasValue(R.styleable.AndroidManifestActivity_exported);
    if (setExported) {
        a.info.exported = sa.getBoolean(R.styleable.AndroidManifestActivity_exported, false);
    }

    a.info.theme = sa.getResourceId(R.styleable.AndroidManifestActivity_theme, 0);

    a.info.uiOptions = sa.getInt(R.styleable.AndroidManifestActivity_uiOptions,
            a.info.applicationInfo.uiOptions);

    String parentName = sa.getNonConfigurationString(R.styleable.AndroidManifestActivity_parentActivityName,
            Configuration.NATIVE_CONFIG_VERSION);
    if (parentName != null) {
        String parentClassName = buildClassName(a.info.packageName, parentName, outError);
        if (outError[0] == null) {
            a.info.parentActivityName = parentClassName;
        } else {
            Log.e(TAG, "Activity " + a.info.name + " specified invalid parentActivityName " + parentName);
            outError[0] = null;
        }
    }

    String str;
    str = sa.getNonConfigurationString(R.styleable.AndroidManifestActivity_permission, 0);
    if (str == null) {
        a.info.permission = owner.applicationInfo.permission;
    } else {
        a.info.permission = str.length() > 0 ? str.toString().intern() : null;
    }

    str = sa.getNonConfigurationString(R.styleable.AndroidManifestActivity_taskAffinity,
            Configuration.NATIVE_CONFIG_VERSION);
    a.info.taskAffinity = buildTaskAffinityName(owner.applicationInfo.packageName,
            owner.applicationInfo.taskAffinity, str, outError);

    a.info.flags = 0;
    if (sa.getBoolean(R.styleable.AndroidManifestActivity_multiprocess, false)) {
        a.info.flags |= ActivityInfo.FLAG_MULTIPROCESS;
    }

    if (sa.getBoolean(R.styleable.AndroidManifestActivity_finishOnTaskLaunch, false)) {
        a.info.flags |= ActivityInfo.FLAG_FINISH_ON_TASK_LAUNCH;
    }

    if (sa.getBoolean(R.styleable.AndroidManifestActivity_clearTaskOnLaunch, false)) {
        a.info.flags |= ActivityInfo.FLAG_CLEAR_TASK_ON_LAUNCH;
    }

    if (sa.getBoolean(R.styleable.AndroidManifestActivity_noHistory, false)) {
        a.info.flags |= ActivityInfo.FLAG_NO_HISTORY;
    }

    if (sa.getBoolean(R.styleable.AndroidManifestActivity_alwaysRetainTaskState, false)) {
        a.info.flags |= ActivityInfo.FLAG_ALWAYS_RETAIN_TASK_STATE;
    }

    if (sa.getBoolean(R.styleable.AndroidManifestActivity_stateNotNeeded, false)) {
        a.info.flags |= ActivityInfo.FLAG_STATE_NOT_NEEDED;
    }

    if (sa.getBoolean(R.styleable.AndroidManifestActivity_excludeFromRecents, false)) {
        a.info.flags |= ActivityInfo.FLAG_EXCLUDE_FROM_RECENTS;
    }

    if (sa.getBoolean(R.styleable.AndroidManifestActivity_allowTaskReparenting,
            (owner.applicationInfo.flags & ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING) != 0)) {
        a.info.flags |= ActivityInfo.FLAG_ALLOW_TASK_REPARENTING;
    }

    if (sa.getBoolean(R.styleable.AndroidManifestActivity_finishOnCloseSystemDialogs, false)) {
        a.info.flags |= ActivityInfo.FLAG_FINISH_ON_CLOSE_SYSTEM_DIALOGS;
    }

    if (sa.getBoolean(R.styleable.AndroidManifestActivity_showOnLockScreen, false)
            || sa.getBoolean(R.styleable.AndroidManifestActivity_showForAllUsers, false)) {
        a.info.flags |= ActivityInfo.FLAG_SHOW_FOR_ALL_USERS;
    }

    if (sa.getBoolean(R.styleable.AndroidManifestActivity_immersive, false)) {
        a.info.flags |= ActivityInfo.FLAG_IMMERSIVE;
    }

    if (sa.getBoolean(R.styleable.AndroidManifestActivity_primaryUserOnly, false)) {
        a.info.flags |= ActivityInfo.FLAG_PRIMARY_USER_ONLY;
    }

    if (!receiver) {
        if (sa.getBoolean(R.styleable.AndroidManifestActivity_hardwareAccelerated, hardwareAccelerated)) {
            a.info.flags |= ActivityInfo.FLAG_HARDWARE_ACCELERATED;
        }

        a.info.launchMode = sa.getInt(R.styleable.AndroidManifestActivity_launchMode,
                ActivityInfo.LAUNCH_MULTIPLE);
        a.info.documentLaunchMode = sa.getInt(R.styleable.AndroidManifestActivity_documentLaunchMode,
                ActivityInfo.DOCUMENT_LAUNCH_NONE);
        a.info.maxRecents = sa.getInt(R.styleable.AndroidManifestActivity_maxRecents,
                ActivityManager.getDefaultAppRecentsLimitStatic());
        a.info.configChanges = sa.getInt(R.styleable.AndroidManifestActivity_configChanges, 0);
        a.info.softInputMode = sa.getInt(R.styleable.AndroidManifestActivity_windowSoftInputMode, 0);

        a.info.persistableMode = sa.getInteger(R.styleable.AndroidManifestActivity_persistableMode,
                ActivityInfo.PERSIST_ROOT_ONLY);

        if (sa.getBoolean(R.styleable.AndroidManifestActivity_allowEmbedded, false)) {
            a.info.flags |= ActivityInfo.FLAG_ALLOW_EMBEDDED;
        }

        if (sa.getBoolean(R.styleable.AndroidManifestActivity_autoRemoveFromRecents, false)) {
            a.info.flags |= ActivityInfo.FLAG_AUTO_REMOVE_FROM_RECENTS;
        }

        if (sa.getBoolean(R.styleable.AndroidManifestActivity_relinquishTaskIdentity, false)) {
            a.info.flags |= ActivityInfo.FLAG_RELINQUISH_TASK_IDENTITY;
        }

        if (sa.getBoolean(R.styleable.AndroidManifestActivity_resumeWhilePausing, false)) {
            a.info.flags |= ActivityInfo.FLAG_RESUME_WHILE_PAUSING;
        }

        a.info.resizeable = sa.getBoolean(R.styleable.AndroidManifestActivity_resizeableActivity, false);
        if (a.info.resizeable) {
            // Fixed screen orientation isn't supported with resizeable activities.
            a.info.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;
        } else {
            a.info.screenOrientation = sa.getInt(R.styleable.AndroidManifestActivity_screenOrientation,
                    ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
        }

        a.info.lockTaskLaunchMode = sa.getInt(R.styleable.AndroidManifestActivity_lockTaskMode, 0);
    } else {
        a.info.launchMode = ActivityInfo.LAUNCH_MULTIPLE;
        a.info.configChanges = 0;

        if (sa.getBoolean(R.styleable.AndroidManifestActivity_singleUser, false)) {
            a.info.flags |= ActivityInfo.FLAG_SINGLE_USER;
            if (a.info.exported && (flags & PARSE_IS_PRIVILEGED) == 0) {
                Slog.w(TAG, "Activity exported request ignored due to singleUser: " + a.className + " at "
                        + mArchiveSourcePath + " " + parser.getPositionDescription());
                a.info.exported = false;
                setExported = true;
            }
        }
    }

    sa.recycle();

    if (receiver && (owner.applicationInfo.privateFlags & ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE) != 0) {
        // A heavy-weight application can not have receives in its main process
        // We can do direct compare because we intern all strings.
        if (a.info.processName == owner.packageName) {
            outError[0] = "Heavy-weight applications can not have receivers in main process";
        }
    }

    if (outError[0] != null) {
        return null;
    }

    int outerDepth = parser.getDepth();
    int type;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
            && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            continue;
        }

        if (parser.getName().equals("intent-filter")) {
            ActivityIntentInfo intent = new ActivityIntentInfo(a);
            if (!parseIntent(res, parser, attrs, true, true, intent, outError)) {
                return null;
            }
            if (intent.countActions() == 0) {
                Slog.w(TAG, "No actions in intent filter at " + mArchiveSourcePath + " "
                        + parser.getPositionDescription());
            } else {
                a.intents.add(intent);
            }
        } else if (!receiver && parser.getName().equals("preferred")) {
            ActivityIntentInfo intent = new ActivityIntentInfo(a);
            if (!parseIntent(res, parser, attrs, false, false, intent, outError)) {
                return null;
            }
            if (intent.countActions() == 0) {
                Slog.w(TAG, "No actions in preferred at " + mArchiveSourcePath + " "
                        + parser.getPositionDescription());
            } else {
                if (owner.preferredActivityFilters == null) {
                    owner.preferredActivityFilters = new ArrayList<ActivityIntentInfo>();
                }
                owner.preferredActivityFilters.add(intent);
            }
        } else if (parser.getName().equals("meta-data")) {
            if ((a.metaData = parseMetaData(res, parser, attrs, a.metaData, outError)) == null) {
                return null;
            }
        } else {
            if (!RIGID_PARSER) {
                Slog.w(TAG, "Problem in package " + mArchiveSourcePath + ":");
                if (receiver) {
                    Slog.w(TAG, "Unknown element under <receiver>: " + parser.getName() + " at "
                            + mArchiveSourcePath + " " + parser.getPositionDescription());
                } else {
                    Slog.w(TAG, "Unknown element under <activity>: " + parser.getName() + " at "
                            + mArchiveSourcePath + " " + parser.getPositionDescription());
                }
                XmlUtils.skipCurrentTag(parser);
                continue;
            } else {
                if (receiver) {
                    outError[0] = "Bad element under <receiver>: " + parser.getName();
                } else {
                    outError[0] = "Bad element under <activity>: " + parser.getName();
                }
                return null;
            }
        }
    }

    if (!setExported) {
        a.info.exported = a.intents.size() > 0;
    }

    return a;
}

From source file:android.content.pm.PackageParser.java

/**
 * Parse the manifest of a <em>base APK</em>.
 * <p>//from  w ww . j a  va  2 s  . co  m
 * When adding new features, carefully consider if they should also be
 * supported by split APKs.
 */
private Package parseBaseApk(Resources res, XmlResourceParser parser, int flags, String[] outError)
        throws XmlPullParserException, IOException {
    final boolean trustedOverlay = (flags & PARSE_TRUSTED_OVERLAY) != 0;

    AttributeSet attrs = parser;

    mParseInstrumentationArgs = null;
    mParseActivityArgs = null;
    mParseServiceArgs = null;
    mParseProviderArgs = null;

    final String pkgName;
    final String splitName;
    try {
        Pair<String, String> packageSplit = parsePackageSplitNames(parser, attrs, flags);
        pkgName = packageSplit.first;
        splitName = packageSplit.second;
    } catch (PackageParserException e) {
        mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
        return null;
    }

    int type;

    if (!TextUtils.isEmpty(splitName)) {
        outError[0] = "Expected base APK, but found split " + splitName;
        mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_PACKAGE_NAME;
        return null;
    }

    final Package pkg = new Package(pkgName);
    boolean foundApp = false;

    TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifest);
    pkg.mVersionCode = pkg.applicationInfo.versionCode = sa
            .getInteger(com.android.internal.R.styleable.AndroidManifest_versionCode, 0);
    pkg.baseRevisionCode = sa.getInteger(com.android.internal.R.styleable.AndroidManifest_revisionCode, 0);
    pkg.mVersionName = sa
            .getNonConfigurationString(com.android.internal.R.styleable.AndroidManifest_versionName, 0);
    if (pkg.mVersionName != null) {
        pkg.mVersionName = pkg.mVersionName.intern();
    }
    String str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifest_sharedUserId, 0);
    if (str != null && str.length() > 0) {
        String nameError = validateName(str, true, false);
        if (nameError != null && !"android".equals(pkgName)) {
            outError[0] = "<manifest> specifies bad sharedUserId name \"" + str + "\": " + nameError;
            mParseError = PackageManager.INSTALL_PARSE_FAILED_BAD_SHARED_USER_ID;
            return null;
        }
        pkg.mSharedUserId = str.intern();
        pkg.mSharedUserLabel = sa
                .getResourceId(com.android.internal.R.styleable.AndroidManifest_sharedUserLabel, 0);
    }

    pkg.installLocation = sa.getInteger(com.android.internal.R.styleable.AndroidManifest_installLocation,
            PARSE_DEFAULT_INSTALL_LOCATION);
    pkg.applicationInfo.installLocation = pkg.installLocation;

    pkg.coreApp = attrs.getAttributeBooleanValue(null, "coreApp", false);

    sa.recycle();

    /* Set the global "forward lock" flag */
    if ((flags & PARSE_FORWARD_LOCK) != 0) {
        pkg.applicationInfo.privateFlags |= ApplicationInfo.PRIVATE_FLAG_FORWARD_LOCK;
    }

    /* Set the global "on SD card" flag */
    if ((flags & PARSE_EXTERNAL_STORAGE) != 0) {
        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_EXTERNAL_STORAGE;
    }

    // Resource boolean are -1, so 1 means we don't know the value.
    int supportsSmallScreens = 1;
    int supportsNormalScreens = 1;
    int supportsLargeScreens = 1;
    int supportsXLargeScreens = 1;
    int resizeable = 1;
    int anyDensity = 1;

    int outerDepth = parser.getDepth();
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
            && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            continue;
        }

        String tagName = parser.getName();
        if (tagName.equals("application")) {
            if (foundApp) {
                if (RIGID_PARSER) {
                    outError[0] = "<manifest> has more than one <application>";
                    mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                    return null;
                } else {
                    Slog.w(TAG, "<manifest> has more than one <application>");
                    XmlUtils.skipCurrentTag(parser);
                    continue;
                }
            }

            foundApp = true;
            if (!parseBaseApplication(pkg, res, parser, attrs, flags, outError)) {
                return null;
            }
        } else if (tagName.equals("overlay")) {
            pkg.mTrustedOverlay = trustedOverlay;

            sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestResourceOverlay);
            pkg.mOverlayTarget = sa
                    .getString(com.android.internal.R.styleable.AndroidManifestResourceOverlay_targetPackage);
            pkg.mOverlayPriority = sa
                    .getInt(com.android.internal.R.styleable.AndroidManifestResourceOverlay_priority, -1);
            sa.recycle();

            if (pkg.mOverlayTarget == null) {
                outError[0] = "<overlay> does not specify a target package";
                mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return null;
            }
            if (pkg.mOverlayPriority < 0 || pkg.mOverlayPriority > 9999) {
                outError[0] = "<overlay> priority must be between 0 and 9999";
                mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return null;
            }
            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("key-sets")) {
            if (!parseKeySets(pkg, res, parser, attrs, outError)) {
                return null;
            }
        } else if (tagName.equals("permission-group")) {
            if (parsePermissionGroup(pkg, flags, res, parser, attrs, outError) == null) {
                return null;
            }
        } else if (tagName.equals("permission")) {
            if (parsePermission(pkg, res, parser, attrs, outError) == null) {
                return null;
            }
        } else if (tagName.equals("permission-tree")) {
            if (parsePermissionTree(pkg, res, parser, attrs, outError) == null) {
                return null;
            }
        } else if (tagName.equals("uses-permission")) {
            if (!parseUsesPermission(pkg, res, parser, attrs)) {
                return null;
            }
        } else if (tagName.equals("uses-permission-sdk-m") || tagName.equals("uses-permission-sdk-23")) {
            if (!parseUsesPermission(pkg, res, parser, attrs)) {
                return null;
            }
        } else if (tagName.equals("uses-configuration")) {
            ConfigurationInfo cPref = new ConfigurationInfo();
            sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestUsesConfiguration);
            cPref.reqTouchScreen = sa.getInt(
                    com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqTouchScreen,
                    Configuration.TOUCHSCREEN_UNDEFINED);
            cPref.reqKeyboardType = sa.getInt(
                    com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqKeyboardType,
                    Configuration.KEYBOARD_UNDEFINED);
            if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqHardKeyboard,
                    false)) {
                cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_HARD_KEYBOARD;
            }
            cPref.reqNavigation = sa.getInt(
                    com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqNavigation,
                    Configuration.NAVIGATION_UNDEFINED);
            if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestUsesConfiguration_reqFiveWayNav,
                    false)) {
                cPref.reqInputFeatures |= ConfigurationInfo.INPUT_FEATURE_FIVE_WAY_NAV;
            }
            sa.recycle();
            pkg.configPreferences = ArrayUtils.add(pkg.configPreferences, cPref);

            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("uses-feature")) {
            FeatureInfo fi = parseUsesFeature(res, attrs);
            pkg.reqFeatures = ArrayUtils.add(pkg.reqFeatures, fi);

            if (fi.name == null) {
                ConfigurationInfo cPref = new ConfigurationInfo();
                cPref.reqGlEsVersion = fi.reqGlEsVersion;
                pkg.configPreferences = ArrayUtils.add(pkg.configPreferences, cPref);
            }

            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("feature-group")) {
            FeatureGroupInfo group = new FeatureGroupInfo();
            ArrayList<FeatureInfo> features = null;
            final int innerDepth = parser.getDepth();
            while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
                    && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
                if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
                    continue;
                }

                final String innerTagName = parser.getName();
                if (innerTagName.equals("uses-feature")) {
                    FeatureInfo featureInfo = parseUsesFeature(res, attrs);
                    // FeatureGroups are stricter and mandate that
                    // any <uses-feature> declared are mandatory.
                    featureInfo.flags |= FeatureInfo.FLAG_REQUIRED;
                    features = ArrayUtils.add(features, featureInfo);
                } else {
                    Slog.w(TAG, "Unknown element under <feature-group>: " + innerTagName + " at "
                            + mArchiveSourcePath + " " + parser.getPositionDescription());
                }
                XmlUtils.skipCurrentTag(parser);
            }

            if (features != null) {
                group.features = new FeatureInfo[features.size()];
                group.features = features.toArray(group.features);
            }
            pkg.featureGroups = ArrayUtils.add(pkg.featureGroups, group);

        } else if (tagName.equals("uses-sdk")) {
            if (SDK_VERSION > 0) {
                sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestUsesSdk);

                int minVers = 0;
                String minCode = null;
                int targetVers = 0;
                String targetCode = null;

                TypedValue val = sa
                        .peekValue(com.android.internal.R.styleable.AndroidManifestUsesSdk_minSdkVersion);
                if (val != null) {
                    if (val.type == TypedValue.TYPE_STRING && val.string != null) {
                        targetCode = minCode = val.string.toString();
                    } else {
                        // If it's not a string, it's an integer.
                        targetVers = minVers = val.data;
                    }
                }

                val = sa.peekValue(com.android.internal.R.styleable.AndroidManifestUsesSdk_targetSdkVersion);
                if (val != null) {
                    if (val.type == TypedValue.TYPE_STRING && val.string != null) {
                        targetCode = minCode = val.string.toString();
                    } else {
                        // If it's not a string, it's an integer.
                        targetVers = val.data;
                    }
                }

                sa.recycle();

                if (minCode != null) {
                    boolean allowedCodename = false;
                    for (String codename : SDK_CODENAMES) {
                        if (minCode.equals(codename)) {
                            allowedCodename = true;
                            break;
                        }
                    }
                    if (!allowedCodename) {
                        if (SDK_CODENAMES.length > 0) {
                            outError[0] = "Requires development platform " + minCode
                                    + " (current platform is any of " + Arrays.toString(SDK_CODENAMES) + ")";
                        } else {
                            outError[0] = "Requires development platform " + minCode
                                    + " but this is a release platform.";
                        }
                        mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
                        return null;
                    }
                } else if (minVers > SDK_VERSION) {
                    outError[0] = "Requires newer sdk version #" + minVers + " (current version is #"
                            + SDK_VERSION + ")";
                    mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
                    return null;
                }

                if (targetCode != null) {
                    boolean allowedCodename = false;
                    for (String codename : SDK_CODENAMES) {
                        if (targetCode.equals(codename)) {
                            allowedCodename = true;
                            break;
                        }
                    }
                    if (!allowedCodename) {
                        if (SDK_CODENAMES.length > 0) {
                            outError[0] = "Requires development platform " + targetCode
                                    + " (current platform is any of " + Arrays.toString(SDK_CODENAMES) + ")";
                        } else {
                            outError[0] = "Requires development platform " + targetCode
                                    + " but this is a release platform.";
                        }
                        mParseError = PackageManager.INSTALL_FAILED_OLDER_SDK;
                        return null;
                    }
                    // If the code matches, it definitely targets this SDK.
                    pkg.applicationInfo.targetSdkVersion = android.os.Build.VERSION_CODES.CUR_DEVELOPMENT;
                } else {
                    pkg.applicationInfo.targetSdkVersion = targetVers;
                }
            }

            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("supports-screens")) {
            sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestSupportsScreens);

            pkg.applicationInfo.requiresSmallestWidthDp = sa.getInteger(
                    com.android.internal.R.styleable.AndroidManifestSupportsScreens_requiresSmallestWidthDp, 0);
            pkg.applicationInfo.compatibleWidthLimitDp = sa.getInteger(
                    com.android.internal.R.styleable.AndroidManifestSupportsScreens_compatibleWidthLimitDp, 0);
            pkg.applicationInfo.largestWidthLimitDp = sa.getInteger(
                    com.android.internal.R.styleable.AndroidManifestSupportsScreens_largestWidthLimitDp, 0);

            // This is a trick to get a boolean and still able to detect
            // if a value was actually set.
            supportsSmallScreens = sa.getInteger(
                    com.android.internal.R.styleable.AndroidManifestSupportsScreens_smallScreens,
                    supportsSmallScreens);
            supportsNormalScreens = sa.getInteger(
                    com.android.internal.R.styleable.AndroidManifestSupportsScreens_normalScreens,
                    supportsNormalScreens);
            supportsLargeScreens = sa.getInteger(
                    com.android.internal.R.styleable.AndroidManifestSupportsScreens_largeScreens,
                    supportsLargeScreens);
            supportsXLargeScreens = sa.getInteger(
                    com.android.internal.R.styleable.AndroidManifestSupportsScreens_xlargeScreens,
                    supportsXLargeScreens);
            resizeable = sa.getInteger(
                    com.android.internal.R.styleable.AndroidManifestSupportsScreens_resizeable, resizeable);
            anyDensity = sa.getInteger(
                    com.android.internal.R.styleable.AndroidManifestSupportsScreens_anyDensity, anyDensity);

            sa.recycle();

            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("protected-broadcast")) {
            sa = res.obtainAttributes(attrs,
                    com.android.internal.R.styleable.AndroidManifestProtectedBroadcast);

            // Note: don't allow this value to be a reference to a resource
            // that may change.
            String name = sa.getNonResourceString(
                    com.android.internal.R.styleable.AndroidManifestProtectedBroadcast_name);

            sa.recycle();

            if (name != null && (flags & PARSE_IS_SYSTEM) != 0) {
                if (pkg.protectedBroadcasts == null) {
                    pkg.protectedBroadcasts = new ArrayList<String>();
                }
                if (!pkg.protectedBroadcasts.contains(name)) {
                    pkg.protectedBroadcasts.add(name.intern());
                }
            }

            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("instrumentation")) {
            if (parseInstrumentation(pkg, res, parser, attrs, outError) == null) {
                return null;
            }

        } else if (tagName.equals("original-package")) {
            sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestOriginalPackage);

            String orig = sa.getNonConfigurationString(
                    com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);
            if (!pkg.packageName.equals(orig)) {
                if (pkg.mOriginalPackages == null) {
                    pkg.mOriginalPackages = new ArrayList<String>();
                    pkg.mRealPackage = pkg.packageName;
                }
                pkg.mOriginalPackages.add(orig);
            }

            sa.recycle();

            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("adopt-permissions")) {
            sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestOriginalPackage);

            String name = sa.getNonConfigurationString(
                    com.android.internal.R.styleable.AndroidManifestOriginalPackage_name, 0);

            sa.recycle();

            if (name != null) {
                if (pkg.mAdoptPermissions == null) {
                    pkg.mAdoptPermissions = new ArrayList<String>();
                }
                pkg.mAdoptPermissions.add(name);
            }

            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("uses-gl-texture")) {
            // Just skip this tag
            XmlUtils.skipCurrentTag(parser);
            continue;

        } else if (tagName.equals("compatible-screens")) {
            // Just skip this tag
            XmlUtils.skipCurrentTag(parser);
            continue;
        } else if (tagName.equals("supports-input")) {
            XmlUtils.skipCurrentTag(parser);
            continue;

        } else if (tagName.equals("eat-comment")) {
            // Just skip this tag
            XmlUtils.skipCurrentTag(parser);
            continue;

        } else if (RIGID_PARSER) {
            outError[0] = "Bad element under <manifest>: " + parser.getName();
            mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
            return null;

        } else {
            Slog.w(TAG, "Unknown element under <manifest>: " + parser.getName() + " at " + mArchiveSourcePath
                    + " " + parser.getPositionDescription());
            XmlUtils.skipCurrentTag(parser);
            continue;
        }
    }

    if (!foundApp && pkg.instrumentation.size() == 0) {
        outError[0] = "<manifest> does not contain an <application> or <instrumentation>";
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_EMPTY;
    }

    final int NP = PackageParser.NEW_PERMISSIONS.length;
    StringBuilder implicitPerms = null;
    for (int ip = 0; ip < NP; ip++) {
        final PackageParser.NewPermissionInfo npi = PackageParser.NEW_PERMISSIONS[ip];
        if (pkg.applicationInfo.targetSdkVersion >= npi.sdkVersion) {
            break;
        }
        if (!pkg.requestedPermissions.contains(npi.name)) {
            if (implicitPerms == null) {
                implicitPerms = new StringBuilder(128);
                implicitPerms.append(pkg.packageName);
                implicitPerms.append(": compat added ");
            } else {
                implicitPerms.append(' ');
            }
            implicitPerms.append(npi.name);
            pkg.requestedPermissions.add(npi.name);
        }
    }
    if (implicitPerms != null) {
        Slog.i(TAG, implicitPerms.toString());
    }

    final int NS = PackageParser.SPLIT_PERMISSIONS.length;
    for (int is = 0; is < NS; is++) {
        final PackageParser.SplitPermissionInfo spi = PackageParser.SPLIT_PERMISSIONS[is];
        if (pkg.applicationInfo.targetSdkVersion >= spi.targetSdk
                || !pkg.requestedPermissions.contains(spi.rootPerm)) {
            continue;
        }
        for (int in = 0; in < spi.newPerms.length; in++) {
            final String perm = spi.newPerms[in];
            if (!pkg.requestedPermissions.contains(perm)) {
                pkg.requestedPermissions.add(perm);
            }
        }
    }

    if (supportsSmallScreens < 0 || (supportsSmallScreens > 0
            && pkg.applicationInfo.targetSdkVersion >= android.os.Build.VERSION_CODES.DONUT)) {
        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SMALL_SCREENS;
    }
    if (supportsNormalScreens != 0) {
        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_NORMAL_SCREENS;
    }
    if (supportsLargeScreens < 0 || (supportsLargeScreens > 0
            && pkg.applicationInfo.targetSdkVersion >= android.os.Build.VERSION_CODES.DONUT)) {
        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_LARGE_SCREENS;
    }
    if (supportsXLargeScreens < 0 || (supportsXLargeScreens > 0
            && pkg.applicationInfo.targetSdkVersion >= android.os.Build.VERSION_CODES.GINGERBREAD)) {
        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_XLARGE_SCREENS;
    }
    if (resizeable < 0 || (resizeable > 0
            && pkg.applicationInfo.targetSdkVersion >= android.os.Build.VERSION_CODES.DONUT)) {
        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_RESIZEABLE_FOR_SCREENS;
    }
    if (anyDensity < 0 || (anyDensity > 0
            && pkg.applicationInfo.targetSdkVersion >= android.os.Build.VERSION_CODES.DONUT)) {
        pkg.applicationInfo.flags |= ApplicationInfo.FLAG_SUPPORTS_SCREEN_DENSITIES;
    }

    return pkg;
}

From source file:com.github.shareme.gwsmaterialuikit.library.material.widget.EditText.java

@Override
protected void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super.applyStyle(context, attrs, defStyleAttr, defStyleRes);

    CharSequence text = mInputView == null ? null : mInputView.getText();
    removeAllViews();/*from www .java 2 s .  co m*/

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.EditText, defStyleAttr, defStyleRes);

    int labelPadding = -1;
    int labelTextSize = -1;
    ColorStateList labelTextColor = null;
    int supportPadding = -1;
    int supportTextSize = -1;
    ColorStateList supportColors = null;
    ColorStateList supportErrorColors = null;
    String supportHelper = null;
    String supportError = null;
    ColorStateList dividerColors = null;
    ColorStateList dividerErrorColors = null;
    int dividerHeight = -1;
    int dividerPadding = -1;
    int dividerAnimDuration = -1;

    mAutoCompleteMode = a.getInteger(R.styleable.EditText_et_autoCompleteMode, mAutoCompleteMode);
    if (needCreateInputView(mAutoCompleteMode)) {
        switch (mAutoCompleteMode) {
        case AUTOCOMPLETE_MODE_SINGLE:
            mInputView = new InternalAutoCompleteTextView(context, attrs, defStyleAttr);
            break;
        case AUTOCOMPLETE_MODE_MULTI:
            mInputView = new InternalMultiAutoCompleteTextView(context, attrs, defStyleAttr);
            break;
        default:
            mInputView = new InternalEditText(context, attrs, defStyleAttr);
            break;
        }
        ViewUtil.applyFont(mInputView, attrs, defStyleAttr, defStyleRes);
        if (text != null)
            mInputView.setText(text);

        mInputView.addTextChangedListener(new InputTextWatcher());

        if (mDivider != null) {
            mDivider.setAnimEnable(false);
            ViewUtil.setBackground(mInputView, mDivider);
            mDivider.setAnimEnable(true);
        }
    } else
        ViewUtil.applyStyle(mInputView, attrs, defStyleAttr, defStyleRes);
    mInputView.setVisibility(View.VISIBLE);
    mInputView.setFocusableInTouchMode(true);

    for (int i = 0, count = a.getIndexCount(); i < count; i++) {
        int attr = a.getIndex(i);

        if (attr == R.styleable.EditText_et_labelEnable)
            mLabelEnable = a.getBoolean(attr, false);
        else if (attr == R.styleable.EditText_et_labelPadding)
            labelPadding = a.getDimensionPixelSize(attr, 0);
        else if (attr == R.styleable.EditText_et_labelTextSize)
            labelTextSize = a.getDimensionPixelSize(attr, 0);
        else if (attr == R.styleable.EditText_et_labelTextColor)
            labelTextColor = a.getColorStateList(attr);
        else if (attr == R.styleable.EditText_et_labelTextAppearance)
            getLabelView().setTextAppearance(context, a.getResourceId(attr, 0));
        else if (attr == R.styleable.EditText_et_labelEllipsize) {
            int labelEllipsize = a.getInteger(attr, 0);
            switch (labelEllipsize) {
            case 1:
                getLabelView().setEllipsize(TruncateAt.START);
                break;
            case 2:
                getLabelView().setEllipsize(TruncateAt.MIDDLE);
                break;
            case 3:
                getLabelView().setEllipsize(TruncateAt.END);
                break;
            case 4:
                getLabelView().setEllipsize(TruncateAt.MARQUEE);
                break;
            default:
                getLabelView().setEllipsize(TruncateAt.END);
                break;
            }
        } else if (attr == R.styleable.EditText_et_labelInAnim)
            mLabelInAnimId = a.getResourceId(attr, 0);
        else if (attr == R.styleable.EditText_et_labelOutAnim)
            mLabelOutAnimId = a.getResourceId(attr, 0);
        else if (attr == R.styleable.EditText_et_supportMode)
            mSupportMode = a.getInteger(attr, 0);
        else if (attr == R.styleable.EditText_et_supportPadding)
            supportPadding = a.getDimensionPixelSize(attr, 0);
        else if (attr == R.styleable.EditText_et_supportTextSize)
            supportTextSize = a.getDimensionPixelSize(attr, 0);
        else if (attr == R.styleable.EditText_et_supportTextColor)
            supportColors = a.getColorStateList(attr);
        else if (attr == R.styleable.EditText_et_supportTextErrorColor)
            supportErrorColors = a.getColorStateList(attr);
        else if (attr == R.styleable.EditText_et_supportTextAppearance)
            getSupportView().setTextAppearance(context, a.getResourceId(attr, 0));
        else if (attr == R.styleable.EditText_et_supportEllipsize) {
            int supportEllipsize = a.getInteger(attr, 0);
            switch (supportEllipsize) {
            case 1:
                getSupportView().setEllipsize(TruncateAt.START);
                break;
            case 2:
                getSupportView().setEllipsize(TruncateAt.MIDDLE);
                break;
            case 3:
                getSupportView().setEllipsize(TruncateAt.END);
                break;
            case 4:
                getSupportView().setEllipsize(TruncateAt.MARQUEE);
                break;
            default:
                getSupportView().setEllipsize(TruncateAt.END);
                break;
            }
        } else if (attr == R.styleable.EditText_et_supportMaxLines)
            getSupportView().setMaxLines(a.getInteger(attr, 0));
        else if (attr == R.styleable.EditText_et_supportLines)
            getSupportView().setLines(a.getInteger(attr, 0));
        else if (attr == R.styleable.EditText_et_supportSingleLine)
            getSupportView().setSingleLine(a.getBoolean(attr, false));
        else if (attr == R.styleable.EditText_et_supportMaxChars)
            mSupportMaxChars = a.getInteger(attr, 0);
        else if (attr == R.styleable.EditText_et_helper)
            supportHelper = a.getString(attr);
        else if (attr == R.styleable.EditText_et_error)
            supportError = a.getString(attr);
        else if (attr == R.styleable.EditText_et_inputId)
            mInputView.setId(a.getResourceId(attr, 0));
        else if (attr == R.styleable.EditText_et_dividerColor)
            dividerColors = a.getColorStateList(attr);
        else if (attr == R.styleable.EditText_et_dividerErrorColor)
            dividerErrorColors = a.getColorStateList(attr);
        else if (attr == R.styleable.EditText_et_dividerHeight)
            dividerHeight = a.getDimensionPixelSize(attr, 0);
        else if (attr == R.styleable.EditText_et_dividerPadding)
            dividerPadding = a.getDimensionPixelSize(attr, 0);
        else if (attr == R.styleable.EditText_et_dividerAnimDuration)
            dividerAnimDuration = a.getInteger(attr, 0);
        else if (attr == R.styleable.EditText_et_dividerCompoundPadding)
            mDividerCompoundPadding = a.getBoolean(attr, true);
    }

    a.recycle();

    if (mInputView.getId() == 0)
        mInputView.setId(ViewUtil.generateViewId());

    if (mDivider == null) {
        mDividerColors = dividerColors;
        mDividerErrorColors = dividerErrorColors;

        if (mDividerColors == null) {
            int[][] states = new int[][] { new int[] { -android.R.attr.state_focused },
                    new int[] { android.R.attr.state_focused, android.R.attr.state_enabled }, };
            int[] colors = new int[] { ThemeUtil.colorControlNormal(context, 0xFF000000),
                    ThemeUtil.colorControlActivated(context, 0xFF000000), };

            mDividerColors = new ColorStateList(states, colors);
        }

        if (mDividerErrorColors == null)
            mDividerErrorColors = ColorStateList.valueOf(ThemeUtil.colorAccent(context, 0xFFFF0000));

        if (dividerHeight < 0)
            dividerHeight = 0;

        if (dividerPadding < 0)
            dividerPadding = 0;

        if (dividerAnimDuration < 0)
            dividerAnimDuration = context.getResources().getInteger(android.R.integer.config_shortAnimTime);

        mDividerPadding = dividerPadding;
        mInputView.setPadding(0, 0, 0, mDividerPadding + dividerHeight);

        mDivider = new DividerDrawable(dividerHeight,
                mDividerCompoundPadding ? mInputView.getTotalPaddingLeft() : 0,
                mDividerCompoundPadding ? mInputView.getTotalPaddingRight() : 0, mDividerColors,
                dividerAnimDuration);
        mDivider.setInEditMode(isInEditMode());
        mDivider.setAnimEnable(false);
        ViewUtil.setBackground(mInputView, mDivider);
        mDivider.setAnimEnable(true);
    } else {
        if (dividerHeight >= 0 || dividerPadding >= 0) {
            if (dividerHeight < 0)
                dividerHeight = mDivider.getDividerHeight();

            if (dividerPadding >= 0)
                mDividerPadding = dividerPadding;

            mInputView.setPadding(0, 0, 0, mDividerPadding + dividerHeight);
            mDivider.setDividerHeight(dividerHeight);
            mDivider.setPadding(mDividerCompoundPadding ? mInputView.getTotalPaddingLeft() : 0,
                    mDividerCompoundPadding ? mInputView.getTotalPaddingRight() : 0);
        }

        if (dividerColors != null)
            mDividerColors = dividerColors;

        if (dividerErrorColors != null)
            mDividerErrorColors = dividerErrorColors;

        mDivider.setColor(getError() == null ? mDividerColors : mDividerErrorColors);

        if (dividerAnimDuration >= 0)
            mDivider.setAnimationDuration(dividerAnimDuration);
    }

    if (labelPadding >= 0)
        getLabelView().setPadding(mDivider.getPaddingLeft(), 0, mDivider.getPaddingRight(), labelPadding);

    if (labelTextSize >= 0)
        getLabelView().setTextSize(TypedValue.COMPLEX_UNIT_PX, labelTextSize);

    if (labelTextColor != null)
        getLabelView().setTextColor(labelTextColor);

    if (mLabelEnable) {
        mLabelVisible = true;
        getLabelView().setText(mInputView.getHint());
        addView(getLabelView(), 0, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        setLabelVisible(!TextUtils.isEmpty(mInputView.getText().toString()), false);
    }

    if (supportTextSize >= 0)
        getSupportView().setTextSize(TypedValue.COMPLEX_UNIT_PX, supportTextSize);

    if (supportColors != null)
        mSupportColors = supportColors;
    else if (mSupportColors == null)
        mSupportColors = context.getResources().getColorStateList(R.color.abc_secondary_text_material_light);

    if (supportErrorColors != null)
        mSupportErrorColors = supportErrorColors;
    else if (mSupportErrorColors == null)
        mSupportErrorColors = ColorStateList.valueOf(ThemeUtil.colorAccent(context, 0xFFFF0000));

    if (supportPadding >= 0)
        getSupportView().setPadding(mDivider.getPaddingLeft(), supportPadding, mDivider.getPaddingRight(), 0);

    if (supportHelper == null && supportError == null)
        getSupportView().setTextColor(getError() == null ? mSupportColors : mSupportErrorColors);
    else if (supportHelper != null)
        setHelper(supportHelper);
    else
        setError(supportError);

    if (mSupportMode != SUPPORT_MODE_NONE) {
        switch (mSupportMode) {
        case SUPPORT_MODE_CHAR_COUNTER:
            getSupportView().setGravity(Gravity.END);
            updateCharCounter(mInputView.getText().length());
            break;
        case SUPPORT_MODE_HELPER:
        case SUPPORT_MODE_HELPER_WITH_ERROR:
            getSupportView().setGravity(GravityCompat.START);
            break;
        }
        addView(getSupportView(), new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
    }

    addView(mInputView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    requestLayout();
}

From source file:com.codetroopers.betterpickers.radialtimepicker.RadialTimePickerDialog.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    if (getShowsDialog()) {
        getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    }/*from ww  w  .j  a  v a  2s. c  o m*/

    View view = inflater.inflate(R.layout.radial_time_picker_dialog, null);
    KeyboardListener keyboardListener = new KeyboardListener();
    view.findViewById(R.id.time_picker_dialog).setOnKeyListener(keyboardListener);

    Resources res = getResources();
    TypedArray themeColors = getActivity().obtainStyledAttributes(mStyleResId,
            R.styleable.BetterPickersRadialTimePickerDialog);

    mHourPickerDescription = res.getString(R.string.hour_picker_description);
    mSelectHours = res.getString(R.string.select_hours);
    mMinutePickerDescription = res.getString(R.string.minute_picker_description);
    mSelectMinutes = res.getString(R.string.select_minutes);
    mSelectedColor = themeColors.getColor(R.styleable.BetterPickersRadialTimePickerDialog_bpAccentColor,
            R.color.bpBlue);
    mUnselectedColor = themeColors.getColor(R.styleable.BetterPickersRadialTimePickerDialog_bpMainTextColor,
            R.color.numbers_text_color);

    mHourView = (TextView) view.findViewById(R.id.hours);
    mHourView.setOnKeyListener(keyboardListener);
    mHourSpaceView = (TextView) view.findViewById(R.id.hour_space);
    mMinuteSpaceView = (TextView) view.findViewById(R.id.minutes_space);
    mMinuteView = (TextView) view.findViewById(R.id.minutes);
    mMinuteView.setOnKeyListener(keyboardListener);
    mAmPmTextView = (TextView) view.findViewById(R.id.ampm_label);
    mAmPmTextView.setOnKeyListener(keyboardListener);
    String[] amPmTexts = new DateFormatSymbols().getAmPmStrings();
    mAmText = amPmTexts[0];
    mPmText = amPmTexts[1];

    mHapticFeedbackController = new HapticFeedbackController(getActivity());

    mTimePicker = (RadialPickerLayout) view.findViewById(R.id.time_picker);
    mTimePicker.setOnValueSelectedListener(this);
    mTimePicker.setOnKeyListener(keyboardListener);
    mTimePicker.initialize(getActivity(), mHapticFeedbackController, mInitialHourOfDay, mInitialMinute,
            mIs24HourMode);

    int currentItemShowing = HOUR_INDEX;
    if (savedInstanceState != null && savedInstanceState.containsKey(KEY_CURRENT_ITEM_SHOWING)) {
        currentItemShowing = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING);
    }
    setCurrentItemShowing(currentItemShowing, false, true, true);
    mTimePicker.invalidate();

    mHourView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(HOUR_INDEX, true, false, true);
            tryVibrate();
        }
    });
    mMinuteView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setCurrentItemShowing(MINUTE_INDEX, true, false, true);
            tryVibrate();
        }
    });

    mDoneButton = (TextView) view.findViewById(R.id.done_button);
    if (mDoneText != null) {
        mDoneButton.setText(mDoneText);
    }
    mDoneButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mInKbMode && isTypedTimeFullyLegal()) {
                finishKbMode(false);
            } else {
                tryVibrate();
            }
            if (mCallback != null) {
                mCallback.onTimeSet(RadialTimePickerDialog.this, mTimePicker.getHours(),
                        mTimePicker.getMinutes());
            }
            dismiss();
        }
    });
    mDoneButton.setOnKeyListener(keyboardListener);

    // Enable or disable the AM/PM view.
    mAmPmHitspace = view.findViewById(R.id.ampm_hitspace);
    if (mIs24HourMode) {
        mAmPmTextView.setVisibility(View.GONE);

        RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);
        paramsSeparator.addRule(RelativeLayout.CENTER_IN_PARENT);
        TextView separatorView = (TextView) view.findViewById(R.id.separator);
        separatorView.setLayoutParams(paramsSeparator);
    } else {
        mAmPmTextView.setVisibility(View.VISIBLE);
        updateAmPmDisplay(mInitialHourOfDay < 12 ? AM : PM);
        mAmPmHitspace.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                tryVibrate();
                int amOrPm = mTimePicker.getIsCurrentlyAmOrPm();
                if (amOrPm == AM) {
                    amOrPm = PM;
                } else if (amOrPm == PM) {
                    amOrPm = AM;
                }
                updateAmPmDisplay(amOrPm);
                mTimePicker.setAmOrPm(amOrPm);
            }
        });
    }

    mAllowAutoAdvance = true;
    setHour(mInitialHourOfDay, true);
    setMinute(mInitialMinute);

    // Set up for keyboard mode.
    mDoublePlaceholderText = res.getString(R.string.time_placeholder);
    mDeletedKeyFormat = res.getString(R.string.deleted_key);
    mPlaceholderText = mDoublePlaceholderText.charAt(0);
    mAmKeyCode = mPmKeyCode = -1;
    generateLegalTimesTree();
    if (mInKbMode) {
        mTypedTimes = savedInstanceState.getIntegerArrayList(KEY_TYPED_TIMES);
        tryStartingKbMode(-1);
        mHourView.invalidate();
    } else if (mTypedTimes == null) {
        mTypedTimes = new ArrayList<Integer>();
    }

    // Set the theme at the end so that the initialize()s above don't counteract the theme.
    mTimePicker.setTheme(themeColors);

    // Prepare some colors to use.
    int mainColor1 = themeColors.getColor(R.styleable.BetterPickersRadialTimePickerDialog_bpMainColor1,
            R.color.bpWhite);
    int mainColor2 = themeColors.getColor(R.styleable.BetterPickersRadialTimePickerDialog_bpMainColor2,
            R.color.circle_background);
    int lineColor = themeColors.getColor(R.styleable.BetterPickersRadialTimePickerDialog_bpLineColor,
            R.color.bpLine_background);
    int mainTextColor = themeColors.getColor(R.styleable.BetterPickersRadialTimePickerDialog_bpMainTextColor,
            R.color.numbers_text_color);
    ColorStateList doneTextColor = themeColors
            .getColorStateList(R.styleable.BetterPickersRadialTimePickerDialog_bpDoneTextColor);
    int doneBackground = themeColors.getResourceId(
            R.styleable.BetterPickersRadialTimePickerDialog_bpDoneBackgroundColor,
            R.drawable.done_background_color);

    // Set the colors for each view based on the theme.
    view.findViewById(R.id.time_display_background).setBackgroundColor(mainColor1);
    view.findViewById(R.id.time_display).setBackgroundColor(mainColor1);
    ((TextView) view.findViewById(R.id.separator)).setTextColor(mainTextColor);
    ((TextView) view.findViewById(R.id.ampm_label)).setTextColor(mainTextColor);
    view.findViewById(R.id.line).setBackgroundColor(lineColor);
    mDoneButton.setTextColor(doneTextColor);
    mTimePicker.setBackgroundColor(mainColor2);
    mDoneButton.setBackgroundResource(doneBackground);
    return view;
}

From source file:android.content.pm.PackageParser.java

/**
 * Parse the {@code application} XML tree at the current parse location in a
 * <em>base APK</em> manifest.
 * <p>/* w  ww.  j  av a  2  s .  co  m*/
 * When adding new features, carefully consider if they should also be
 * supported by split APKs.
 */
private boolean parseBaseApplication(Package owner, Resources res, XmlPullParser parser, AttributeSet attrs,
        int flags, String[] outError) throws XmlPullParserException, IOException {
    final ApplicationInfo ai = owner.applicationInfo;
    final String pkgName = owner.applicationInfo.packageName;

    TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestApplication);

    String name = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestApplication_name,
            0);
    if (name != null) {
        ai.className = buildClassName(pkgName, name, outError);
        if (ai.className == null) {
            sa.recycle();
            mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
            return false;
        }
    }

    String manageSpaceActivity = sa.getNonConfigurationString(
            com.android.internal.R.styleable.AndroidManifestApplication_manageSpaceActivity,
            Configuration.NATIVE_CONFIG_VERSION);
    if (manageSpaceActivity != null) {
        ai.manageSpaceActivityName = buildClassName(pkgName, manageSpaceActivity, outError);
    }

    boolean allowBackup = sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_allowBackup,
            true);
    if (allowBackup) {
        ai.flags |= ApplicationInfo.FLAG_ALLOW_BACKUP;

        // backupAgent, killAfterRestore, fullBackupContent and restoreAnyVersion are only
        // relevant if backup is possible for the given application.
        String backupAgent = sa.getNonConfigurationString(
                com.android.internal.R.styleable.AndroidManifestApplication_backupAgent,
                Configuration.NATIVE_CONFIG_VERSION);
        if (backupAgent != null) {
            ai.backupAgentName = buildClassName(pkgName, backupAgent, outError);
            if (DEBUG_BACKUP) {
                Slog.v(TAG,
                        "android:backupAgent = " + ai.backupAgentName + " from " + pkgName + "+" + backupAgent);
            }

            if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_killAfterRestore,
                    true)) {
                ai.flags |= ApplicationInfo.FLAG_KILL_AFTER_RESTORE;
            }
            if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_restoreAnyVersion,
                    false)) {
                ai.flags |= ApplicationInfo.FLAG_RESTORE_ANY_VERSION;
            }
            if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_fullBackupOnly,
                    false)) {
                ai.flags |= ApplicationInfo.FLAG_FULL_BACKUP_ONLY;
            }
        }

        TypedValue v = sa
                .peekValue(com.android.internal.R.styleable.AndroidManifestApplication_fullBackupContent);
        if (v != null && (ai.fullBackupContent = v.resourceId) == 0) {
            if (DEBUG_BACKUP) {
                Slog.v(TAG, "fullBackupContent specified as boolean=" + (v.data == 0 ? "false" : "true"));
            }
            // "false" => -1, "true" => 0
            ai.fullBackupContent = (v.data == 0 ? -1 : 0);
        }
        if (DEBUG_BACKUP) {
            Slog.v(TAG, "fullBackupContent=" + ai.fullBackupContent + " for " + pkgName);
        }
    }

    TypedValue v = sa.peekValue(com.android.internal.R.styleable.AndroidManifestApplication_label);
    if (v != null && (ai.labelRes = v.resourceId) == 0) {
        ai.nonLocalizedLabel = v.coerceToString();
    }

    ai.icon = sa.getResourceId(com.android.internal.R.styleable.AndroidManifestApplication_icon, 0);
    ai.logo = sa.getResourceId(com.android.internal.R.styleable.AndroidManifestApplication_logo, 0);
    ai.banner = sa.getResourceId(com.android.internal.R.styleable.AndroidManifestApplication_banner, 0);
    ai.theme = sa.getResourceId(com.android.internal.R.styleable.AndroidManifestApplication_theme, 0);
    ai.descriptionRes = sa
            .getResourceId(com.android.internal.R.styleable.AndroidManifestApplication_description, 0);

    if ((flags & PARSE_IS_SYSTEM) != 0) {
        if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_persistent, false)) {
            ai.flags |= ApplicationInfo.FLAG_PERSISTENT;
        }
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_requiredForAllUsers, false)) {
        owner.mRequiredForAllUsers = true;
    }

    String restrictedAccountType = sa
            .getString(com.android.internal.R.styleable.AndroidManifestApplication_restrictedAccountType);
    if (restrictedAccountType != null && restrictedAccountType.length() > 0) {
        owner.mRestrictedAccountType = restrictedAccountType;
    }

    String requiredAccountType = sa
            .getString(com.android.internal.R.styleable.AndroidManifestApplication_requiredAccountType);
    if (requiredAccountType != null && requiredAccountType.length() > 0) {
        owner.mRequiredAccountType = requiredAccountType;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_debuggable, false)) {
        ai.flags |= ApplicationInfo.FLAG_DEBUGGABLE;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_vmSafeMode, false)) {
        ai.flags |= ApplicationInfo.FLAG_VM_SAFE_MODE;
    }

    owner.baseHardwareAccelerated = sa.getBoolean(
            com.android.internal.R.styleable.AndroidManifestApplication_hardwareAccelerated,
            owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.ICE_CREAM_SANDWICH);
    if (owner.baseHardwareAccelerated) {
        ai.flags |= ApplicationInfo.FLAG_HARDWARE_ACCELERATED;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_hasCode, true)) {
        ai.flags |= ApplicationInfo.FLAG_HAS_CODE;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_allowTaskReparenting,
            false)) {
        ai.flags |= ApplicationInfo.FLAG_ALLOW_TASK_REPARENTING;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_allowClearUserData, true)) {
        ai.flags |= ApplicationInfo.FLAG_ALLOW_CLEAR_USER_DATA;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_testOnly, false)) {
        ai.flags |= ApplicationInfo.FLAG_TEST_ONLY;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_largeHeap, false)) {
        ai.flags |= ApplicationInfo.FLAG_LARGE_HEAP;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_usesCleartextTraffic, true)) {
        ai.flags |= ApplicationInfo.FLAG_USES_CLEARTEXT_TRAFFIC;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_supportsRtl,
            false /* default is no RTL support*/)) {
        ai.flags |= ApplicationInfo.FLAG_SUPPORTS_RTL;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_multiArch, false)) {
        ai.flags |= ApplicationInfo.FLAG_MULTIARCH;
    }

    if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_extractNativeLibs, true)) {
        ai.flags |= ApplicationInfo.FLAG_EXTRACT_NATIVE_LIBS;
    }

    String str;
    str = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestApplication_permission,
            0);
    ai.permission = (str != null && str.length() > 0) ? str.intern() : null;

    if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
        str = sa.getNonConfigurationString(
                com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity,
                Configuration.NATIVE_CONFIG_VERSION);
    } else {
        // Some older apps have been seen to use a resource reference
        // here that on older builds was ignored (with a warning).  We
        // need to continue to do this for them so they don't break.
        str = sa.getNonResourceString(com.android.internal.R.styleable.AndroidManifestApplication_taskAffinity);
    }
    ai.taskAffinity = buildTaskAffinityName(ai.packageName, ai.packageName, str, outError);

    if (outError[0] == null) {
        CharSequence pname;
        if (owner.applicationInfo.targetSdkVersion >= Build.VERSION_CODES.FROYO) {
            pname = sa.getNonConfigurationString(
                    com.android.internal.R.styleable.AndroidManifestApplication_process,
                    Configuration.NATIVE_CONFIG_VERSION);
        } else {
            // Some older apps have been seen to use a resource reference
            // here that on older builds was ignored (with a warning).  We
            // need to continue to do this for them so they don't break.
            pname = sa
                    .getNonResourceString(com.android.internal.R.styleable.AndroidManifestApplication_process);
        }
        ai.processName = buildProcessName(ai.packageName, null, pname, flags, mSeparateProcesses, outError);

        ai.enabled = sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_enabled, true);

        if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_isGame, false)) {
            ai.flags |= ApplicationInfo.FLAG_IS_GAME;
        }

        if (false) {
            if (sa.getBoolean(com.android.internal.R.styleable.AndroidManifestApplication_cantSaveState,
                    false)) {
                ai.privateFlags |= ApplicationInfo.PRIVATE_FLAG_CANT_SAVE_STATE;

                // A heavy-weight application can not be in a custom process.
                // We can do direct compare because we intern all strings.
                if (ai.processName != null && ai.processName != ai.packageName) {
                    outError[0] = "cantSaveState applications can not use custom processes";
                }
            }
        }
    }

    ai.uiOptions = sa.getInt(com.android.internal.R.styleable.AndroidManifestApplication_uiOptions, 0);

    sa.recycle();

    if (outError[0] != null) {
        mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
        return false;
    }

    final int innerDepth = parser.getDepth();
    int type;
    while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
            && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
        if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
            continue;
        }

        String tagName = parser.getName();
        if (tagName.equals("activity")) {
            Activity a = parseActivity(owner, res, parser, attrs, flags, outError, false,
                    owner.baseHardwareAccelerated);
            if (a == null) {
                mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return false;
            }

            owner.activities.add(a);

        } else if (tagName.equals("receiver")) {
            Activity a = parseActivity(owner, res, parser, attrs, flags, outError, true, false);
            if (a == null) {
                mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return false;
            }

            owner.receivers.add(a);

        } else if (tagName.equals("service")) {
            Service s = parseService(owner, res, parser, attrs, flags, outError);
            if (s == null) {
                mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return false;
            }

            owner.services.add(s);

        } else if (tagName.equals("provider")) {
            Provider p = parseProvider(owner, res, parser, attrs, flags, outError);
            if (p == null) {
                mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return false;
            }

            owner.providers.add(p);

        } else if (tagName.equals("activity-alias")) {
            Activity a = parseActivityAlias(owner, res, parser, attrs, flags, outError);
            if (a == null) {
                mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return false;
            }

            owner.activities.add(a);

        } else if (parser.getName().equals("meta-data")) {
            // note: application meta-data is stored off to the side, so it can
            // remain null in the primary copy (we like to avoid extra copies because
            // it can be large)
            if ((owner.mAppMetaData = parseMetaData(res, parser, attrs, owner.mAppMetaData,
                    outError)) == null) {
                mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return false;
            }

        } else if (tagName.equals("library")) {
            sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestLibrary);

            // Note: don't allow this value to be a reference to a resource
            // that may change.
            String lname = sa
                    .getNonResourceString(com.android.internal.R.styleable.AndroidManifestLibrary_name);

            sa.recycle();

            if (lname != null) {
                lname = lname.intern();
                if (!ArrayUtils.contains(owner.libraryNames, lname)) {
                    owner.libraryNames = ArrayUtils.add(owner.libraryNames, lname);
                }
            }

            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("uses-library")) {
            sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestUsesLibrary);

            // Note: don't allow this value to be a reference to a resource
            // that may change.
            String lname = sa
                    .getNonResourceString(com.android.internal.R.styleable.AndroidManifestUsesLibrary_name);
            boolean req = sa.getBoolean(com.android.internal.R.styleable.AndroidManifestUsesLibrary_required,
                    true);

            sa.recycle();

            if (lname != null) {
                lname = lname.intern();
                if (req) {
                    owner.usesLibraries = ArrayUtils.add(owner.usesLibraries, lname);
                } else {
                    owner.usesOptionalLibraries = ArrayUtils.add(owner.usesOptionalLibraries, lname);
                }
            }

            XmlUtils.skipCurrentTag(parser);

        } else if (tagName.equals("uses-package")) {
            // Dependencies for app installers; we don't currently try to
            // enforce this.
            XmlUtils.skipCurrentTag(parser);

        } else {
            if (!RIGID_PARSER) {
                Slog.w(TAG, "Unknown element under <application>: " + tagName + " at " + mArchiveSourcePath
                        + " " + parser.getPositionDescription());
                XmlUtils.skipCurrentTag(parser);
                continue;
            } else {
                outError[0] = "Bad element under <application>: " + tagName;
                mParseError = PackageManager.INSTALL_PARSE_FAILED_MANIFEST_MALFORMED;
                return false;
            }
        }
    }

    modifySharedLibrariesForBackwardCompatibility(owner);

    if (hasDomainURLs(owner)) {
        owner.applicationInfo.privateFlags |= ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS;
    } else {
        owner.applicationInfo.privateFlags &= ~ApplicationInfo.PRIVATE_FLAG_HAS_DOMAIN_URLS;
    }

    return true;
}

From source file:com.appeaser.sublimenavigationviewlibrary.SublimeNavigationView.java

public SublimeNavigationView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.SublimeNavigationView, defStyleAttr,
            R.style.SnvSublimeNavigationView);

    try {/*from  ww  w. ja v  a 2  s  .co  m*/
        // Used for creating default resources
        SublimeThemer.DefaultTheme defaultTheme = SublimeThemer.DefaultTheme.LIGHT;

        if (a.hasValue(R.styleable.SublimeNavigationView_snvDefaultTheme)) {
            defaultTheme = a.getInt(R.styleable.SublimeNavigationView_snvDefaultTheme, 0) == 0
                    ? SublimeThemer.DefaultTheme.LIGHT
                    : SublimeThemer.DefaultTheme.DARK;
        }

        mThemer = new SublimeThemer(getContext(), defaultTheme);

        mThemer.setDrawerBackground(a.getDrawable(R.styleable.SublimeNavigationView_android_background));

        if (a.hasValue(R.styleable.SublimeNavigationView_elevation)) {
            mThemer.setElevation(
                    (float) a.getDimensionPixelSize(R.styleable.SublimeNavigationView_elevation, 0));
        }

        ViewCompat.setFitsSystemWindows(this,
                a.getBoolean(R.styleable.SublimeNavigationView_android_fitsSystemWindows, false));
        mMaxWidth = a.getDimensionPixelSize(R.styleable.SublimeNavigationView_android_maxWidth, 0);

        if (a.hasValue(R.styleable.SublimeNavigationView_snvItemIconTint)) {
            mThemer.setIconTintList(a.getColorStateList(R.styleable.SublimeNavigationView_snvItemIconTint));
        }

        mThemer.setGroupExpandDrawable(a.getDrawable(R.styleable.SublimeNavigationView_snvGroupExpandDrawable));

        mThemer.setGroupCollapseDrawable(
                a.getDrawable(R.styleable.SublimeNavigationView_snvGroupCollapseDrawable));

        // Text style profiles for Item, Hint, SubheaderItem & SubheaderHint
        ColorStateList itemTextColor = null, hintTextColor = null, subheaderItemTextColor = null,
                subheaderHintTextColor = null, badgeTextColor = null;
        Typeface itemTypeface = null, hintTypeface = null, subheaderItemTypeface = null,
                subheaderHintTypeface = null, badgeTypeface = null;
        int itemTypefaceStyle = 0, hintTypefaceStyle = 0, subheaderItemTypefaceStyle = 0,
                subheaderHintTypefaceStyle = 0, badgeTypefaceStyle = 0;

        if (a.hasValue(R.styleable.SublimeNavigationView_snvItemTextColor)) {
            itemTextColor = a.getColorStateList(R.styleable.SublimeNavigationView_snvItemTextColor);
        }

        if (a.hasValue(R.styleable.SublimeNavigationView_snvHintTextColor)) {
            hintTextColor = a.getColorStateList(R.styleable.SublimeNavigationView_snvHintTextColor);
        }

        if (a.hasValue(R.styleable.SublimeNavigationView_snvSubheaderItemTextColor)) {
            subheaderItemTextColor = a
                    .getColorStateList(R.styleable.SublimeNavigationView_snvSubheaderItemTextColor);
        }

        if (a.hasValue(R.styleable.SublimeNavigationView_snvSubheaderHintTextColor)) {
            subheaderHintTextColor = a
                    .getColorStateList(R.styleable.SublimeNavigationView_snvSubheaderHintTextColor);
        }

        if (a.hasValue(R.styleable.SublimeNavigationView_snvBadgeTextColor)) {
            badgeTextColor = a.getColorStateList(R.styleable.SublimeNavigationView_snvBadgeTextColor);
        }

        try { // Catch the RuntimeException thrown if
              // the Typeface filename is incorrect
            if (a.hasValue(R.styleable.SublimeNavigationView_snvItemTypefaceFilename)) {
                String itemTypefaceFilename = a
                        .getString(R.styleable.SublimeNavigationView_snvItemTypefaceFilename);
                if (!TextUtils.isEmpty(itemTypefaceFilename)) {
                    itemTypeface = Typeface.createFromAsset(context.getAssets(), itemTypefaceFilename);
                }
            }

            if (a.hasValue(R.styleable.SublimeNavigationView_snvHintTypefaceFilename)) {
                String hintTypefaceFilename = a
                        .getString(R.styleable.SublimeNavigationView_snvHintTypefaceFilename);
                if (!TextUtils.isEmpty(hintTypefaceFilename)) {
                    hintTypeface = Typeface.createFromAsset(context.getAssets(), hintTypefaceFilename);
                }
            }

            if (a.hasValue(R.styleable.SublimeNavigationView_snvSubheaderItemTypefaceFilename)) {
                String subheaderItemTypefaceFilename = a
                        .getString(R.styleable.SublimeNavigationView_snvSubheaderItemTypefaceFilename);
                if (!TextUtils.isEmpty(subheaderItemTypefaceFilename)) {
                    subheaderItemTypeface = Typeface.createFromAsset(context.getAssets(),
                            subheaderItemTypefaceFilename);
                }
            }

            if (a.hasValue(R.styleable.SublimeNavigationView_snvSubheaderHintTypefaceFilename)) {
                String subheaderHintTypefaceFilename = a
                        .getString(R.styleable.SublimeNavigationView_snvSubheaderHintTypefaceFilename);
                if (!TextUtils.isEmpty(subheaderHintTypefaceFilename)) {
                    subheaderHintTypeface = Typeface.createFromAsset(context.getAssets(),
                            subheaderHintTypefaceFilename);
                }
            }

            if (a.hasValue(R.styleable.SublimeNavigationView_snvBadgeTypefaceFilename)) {
                String badgeTypefaceFilename = a
                        .getString(R.styleable.SublimeNavigationView_snvBadgeTypefaceFilename);
                if (!TextUtils.isEmpty(badgeTypefaceFilename)) {
                    badgeTypeface = Typeface.createFromAsset(context.getAssets(), badgeTypefaceFilename);
                }
            }
        } catch (RuntimeException re) {
            Log.e(TAG,
                    "Error loading Typeface from Assets. " + "Confirm that the Typeface filename is correct:\n"
                            + "    - filename should include the extension\n"
                            + "    - filename is case-sensitive");
        }

        if (a.hasValue(R.styleable.SublimeNavigationView_snvItemTypefaceStyle)) {
            itemTypefaceStyle = a.getInt(R.styleable.SublimeNavigationView_snvItemTypefaceStyle,
                    Typeface.NORMAL);

            switch (itemTypefaceStyle) {
            case 1:
                itemTypefaceStyle = Typeface.BOLD;
                break;
            case 2:
                itemTypefaceStyle = Typeface.ITALIC;
                break;
            case 3:
                itemTypefaceStyle = Typeface.BOLD_ITALIC;
                break;
            default:
                // case 0: NORMAL
                itemTypefaceStyle = Typeface.NORMAL;
                break;
            }
        }

        if (a.hasValue(R.styleable.SublimeNavigationView_snvHintTypefaceStyle)) {
            hintTypefaceStyle = a.getInt(R.styleable.SublimeNavigationView_snvHintTypefaceStyle,
                    Typeface.NORMAL);

            switch (hintTypefaceStyle) {
            case 1:
                hintTypefaceStyle = Typeface.BOLD;
                break;
            case 2:
                hintTypefaceStyle = Typeface.ITALIC;
                break;
            case 3:
                hintTypefaceStyle = Typeface.BOLD_ITALIC;
                break;
            default:
                // case 0: NORMAL
                hintTypefaceStyle = Typeface.NORMAL;
                break;
            }
        }

        if (a.hasValue(R.styleable.SublimeNavigationView_snvSubheaderItemTypefaceStyle)) {
            subheaderItemTypefaceStyle = a
                    .getInt(R.styleable.SublimeNavigationView_snvSubheaderItemTypefaceStyle, Typeface.NORMAL);

            switch (subheaderItemTypefaceStyle) {
            case 1:
                subheaderItemTypefaceStyle = Typeface.BOLD;
                break;
            case 2:
                subheaderItemTypefaceStyle = Typeface.ITALIC;
                break;
            case 3:
                subheaderItemTypefaceStyle = Typeface.BOLD_ITALIC;
                break;
            default:
                // case 0: NORMAL
                subheaderItemTypefaceStyle = Typeface.NORMAL;
                break;
            }
        }

        if (a.hasValue(R.styleable.SublimeNavigationView_snvSubheaderHintTypefaceStyle)) {
            subheaderHintTypefaceStyle = a
                    .getInt(R.styleable.SublimeNavigationView_snvSubheaderHintTypefaceStyle, Typeface.NORMAL);

            switch (subheaderHintTypefaceStyle) {
            case 1:
                subheaderHintTypefaceStyle = Typeface.BOLD;
                break;
            case 2:
                subheaderHintTypefaceStyle = Typeface.ITALIC;
                break;
            case 3:
                subheaderHintTypefaceStyle = Typeface.BOLD_ITALIC;
                break;
            default:
                // case 0: NORMAL
                subheaderHintTypefaceStyle = Typeface.NORMAL;
                break;
            }
        }

        if (a.hasValue(R.styleable.SublimeNavigationView_snvBadgeTypefaceStyle)) {
            badgeTypefaceStyle = a.getInt(R.styleable.SublimeNavigationView_snvBadgeTypefaceStyle,
                    Typeface.NORMAL);

            switch (badgeTypefaceStyle) {
            case 1:
                badgeTypefaceStyle = Typeface.BOLD;
                break;
            case 2:
                badgeTypefaceStyle = Typeface.ITALIC;
                break;
            case 3:
                badgeTypefaceStyle = Typeface.BOLD_ITALIC;
                break;
            default:
                // case 0: NORMAL
                badgeTypefaceStyle = Typeface.NORMAL;
                break;
            }
        }

        // Item text styling
        TextViewStyleProfile itemStyleProfile = new TextViewStyleProfile(context, defaultTheme);
        itemStyleProfile.setTextColor(itemTextColor).setTypeface(itemTypeface)
                .setTypefaceStyle(itemTypefaceStyle);
        mThemer.setItemStyleProfile(itemStyleProfile);

        // Hint text styling
        TextViewStyleProfile hintStyleProfile = new TextViewStyleProfile(context, defaultTheme);
        hintStyleProfile.setTextColor(hintTextColor).setTypeface(hintTypeface)
                .setTypefaceStyle(hintTypefaceStyle);
        mThemer.setItemHintStyleProfile(hintStyleProfile);

        // Sub-header item text styling
        TextViewStyleProfile subheaderItemStyleProfile = new TextViewStyleProfile(context, defaultTheme);
        subheaderItemStyleProfile.setTextColor(subheaderItemTextColor).setTypeface(subheaderItemTypeface)
                .setTypefaceStyle(subheaderItemTypefaceStyle);
        mThemer.setSubheaderStyleProfile(subheaderItemStyleProfile);

        // Sub-header hint text styling
        TextViewStyleProfile subheaderHintStyleProfile = new TextViewStyleProfile(context, defaultTheme);
        subheaderHintStyleProfile.setTextColor(subheaderHintTextColor).setTypeface(subheaderHintTypeface)
                .setTypefaceStyle(subheaderHintTypefaceStyle);
        mThemer.setSubheaderHintStyleProfile(subheaderHintStyleProfile);

        // Badge text styling
        TextViewStyleProfile badgeStyleProfile = new TextViewStyleProfile(context, defaultTheme);
        badgeStyleProfile.setTextColor(badgeTextColor).setTypeface(badgeTypeface)
                .setTypefaceStyle(badgeTypefaceStyle);
        mThemer.setBadgeStyleProfile(badgeStyleProfile);

        mThemer.setItemBackground(a.getDrawable(R.styleable.SublimeNavigationView_snvItemBackground));

        if (a.hasValue(R.styleable.SublimeNavigationView_snvMenu)) {
            int menuResId = a.getResourceId(R.styleable.SublimeNavigationView_snvMenu, -1);

            if (menuResId == -1) {
                throw new RuntimeException("Passed menuResId was not valid");
            }

            mMenu = new SublimeMenu(menuResId);
            inflateMenu(menuResId);
        }

        mMenu.setCallback(new SublimeMenu.Callback() {
            public boolean onMenuItemSelected(SublimeMenu menu, SublimeBaseMenuItem item,
                    OnNavigationMenuEventListener.Event event) {
                return SublimeNavigationView.this.mEventListener != null
                        && SublimeNavigationView.this.mEventListener.onNavigationMenuEvent(event, item);
            }
        });

        mPresenter = new SublimeMenuPresenter();
        applyThemer();

        mMenu.setMenuPresenter(getContext(), mPresenter);
        addView(mPresenter.getMenuView(this));

        if (a.hasValue(R.styleable.SublimeNavigationView_snvHeaderLayout)) {
            inflateHeaderView(a.getResourceId(R.styleable.SublimeNavigationView_snvHeaderLayout, 0));
        }
    } finally {
        a.recycle();
    }

    // Upon creation, and until initializations are done,
    // SublimeMenuPresenter blocks all calls for invalidation.
    // We can now finalize the initialization phase to allow
    // invalidation of the menu when required.
    mPresenter.setInitializationDone();
}