Example usage for android.content.res TypedArray recycle

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

Introduction

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

Prototype

public void recycle() 

Source Link

Document

Recycles the TypedArray, to be re-used by a later caller.

Usage

From source file:cc.flydev.launcher.Page.java

public PagedView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagedView, defStyle, 0);
    setPageSpacing(a.getDimensionPixelSize(R.styleable.PagedView_pageSpacing, 0));
    if (mPageSpacing < 0) {
        mAutoComputePageSpacing = mRecomputePageSpacing = true;
    }//  w w w .  j  a  v a 2 s .  co  m
    mPageLayoutPaddingTop = a.getDimensionPixelSize(R.styleable.PagedView_pageLayoutPaddingTop, 0);
    mPageLayoutPaddingBottom = a.getDimensionPixelSize(R.styleable.PagedView_pageLayoutPaddingBottom, 0);
    mPageLayoutPaddingLeft = a.getDimensionPixelSize(R.styleable.PagedView_pageLayoutPaddingLeft, 0);
    mPageLayoutPaddingRight = a.getDimensionPixelSize(R.styleable.PagedView_pageLayoutPaddingRight, 0);
    mPageLayoutWidthGap = a.getDimensionPixelSize(R.styleable.PagedView_pageLayoutWidthGap, 0);
    mPageLayoutHeightGap = a.getDimensionPixelSize(R.styleable.PagedView_pageLayoutHeightGap, 0);
    mPageIndicatorViewId = a.getResourceId(R.styleable.PagedView_pageIndicator, -1);
    a.recycle();

    setHapticFeedbackEnabled(false);
    init();
}

From source file:android.app.FragmentState.java

/**
 * Called when a fragment is being created as part of a view layout
 * inflation, typically from setting the content view of an activity.  This
 * may be called immediately after the fragment is created from a <fragment>
 * tag in a layout file.  Note this is <em>before</em> the fragment's
 * {@link #onAttach(Activity)} has been called; all you should do here is
 * parse the attributes and save them away.
 *
 * <p>This is called every time the fragment is inflated, even if it is
 * being inflated into a new instance with saved state.  It typically makes
 * sense to re-parse the parameters each time, to allow them to change with
 * different configurations.</p>/*w  w  w.j  a  va  2s  .c  om*/
 *
 * <p>Here is a typical implementation of a fragment that can take parameters
 * both through attributes supplied here as well from {@link #getArguments()}:</p>
 *
 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentArguments.java
 *      fragment}
 *
 * <p>Note that parsing the XML attributes uses a "styleable" resource.  The
 * declaration for the styleable used here is:</p>
 *
 * {@sample development/samples/ApiDemos/res/values/attrs.xml fragment_arguments}
 * 
 * <p>The fragment can then be declared within its activity's content layout
 * through a tag like this:</p>
 *
 * {@sample development/samples/ApiDemos/res/layout/fragment_arguments.xml from_attributes}
 *
 * <p>This fragment can also be created dynamically from arguments given
 * at runtime in the arguments Bundle; here is an example of doing so at
 * creation of the containing activity:</p>
 *
 * {@sample development/samples/ApiDemos/src/com/example/android/apis/app/FragmentArguments.java
 *      create}
 *
 * @param activity The Activity that is inflating this fragment.
 * @param attrs The attributes at the tag where the fragment is
 * being created.
 * @param savedInstanceState If the fragment is being re-created from
 * a previous saved state, this is the state.
 */
public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) {
    onInflate(attrs, savedInstanceState);
    mCalled = true;

    TypedArray a = activity.obtainStyledAttributes(attrs, com.android.internal.R.styleable.Fragment);
    mEnterTransition = loadTransition(activity, a, mEnterTransition, null,
            com.android.internal.R.styleable.Fragment_fragmentEnterTransition);
    mReturnTransition = loadTransition(activity, a, mReturnTransition, USE_DEFAULT_TRANSITION,
            com.android.internal.R.styleable.Fragment_fragmentReturnTransition);
    mExitTransition = loadTransition(activity, a, mExitTransition, null,
            com.android.internal.R.styleable.Fragment_fragmentExitTransition);
    mReenterTransition = loadTransition(activity, a, mReenterTransition, USE_DEFAULT_TRANSITION,
            com.android.internal.R.styleable.Fragment_fragmentReenterTransition);
    mSharedElementEnterTransition = loadTransition(activity, a, mSharedElementEnterTransition, null,
            com.android.internal.R.styleable.Fragment_fragmentSharedElementEnterTransition);
    mSharedElementReturnTransition = loadTransition(activity, a, mSharedElementReturnTransition,
            USE_DEFAULT_TRANSITION,
            com.android.internal.R.styleable.Fragment_fragmentSharedElementReturnTransition);
    if (mAllowEnterTransitionOverlap == null) {
        mAllowEnterTransitionOverlap = a.getBoolean(
                com.android.internal.R.styleable.Fragment_fragmentAllowEnterTransitionOverlap, true);
    }
    if (mAllowReturnTransitionOverlap == null) {
        mAllowReturnTransitionOverlap = a.getBoolean(
                com.android.internal.R.styleable.Fragment_fragmentAllowReturnTransitionOverlap, true);
    }
    a.recycle();
}

From source file:com.chrynan.guitarchords.view.GuitarChordView.java

private void init(Context context, AttributeSet attrs) {
    detector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
        @Override//from  ww  w . ja v a 2s .  com
        public boolean onDown(MotionEvent event) {
            boolean isMarkerInChord = false;
            int fret = NO_FRET, string = -1;
            fret = getSelectedFret(event);
            string = getSelectedString(event);
            touchEventMarker = new ChordMarker(string, fret, NO_FINGER);
            return true;
        }

        @Override
        public void onLongPress(MotionEvent event) {
            if (editable && touchEventMarker != null && chord != null && chord.contains(touchEventMarker)) {
                InputMethodManager imm = (InputMethodManager) getContext()
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(GuitarChordView.this, InputMethodManager.SHOW_IMPLICIT);
            }
        }
    });
    chord = new Chord();
    showFretNumbers = true;
    showFingerNumbers = true;
    editable = false;
    stringCount = 6;
    listeners = new ArrayList<>();
    fretNumberListeners = new ArrayList<>();
    stringListeners = new ArrayList<>();
    touchEventMarker = null;
    mutedText = MUTED_TEXT;
    openStringText = OPEN_STRING_TEXT;
    initPaint();
    if (attrs != null) {
        //TODO handle custom attribute values
        TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs, R.styleable.GuitarChordView, 0, 0);
        try {
            bridgeNutColor = a.getColor(R.styleable.GuitarChordView_bridgeNutColor, DEFAULT_COLOR);
            bridgeNutPaint.setColor(bridgeNutColor);
            fretMarkerColor = a.getColor(R.styleable.GuitarChordView_fretMarkerColor, DEFAULT_COLOR);
            fretMarkerPaint.setColor(fretMarkerColor);
            stringColor = a.getColor(R.styleable.GuitarChordView_stringColor, DEFAULT_COLOR);
            stringPaint.setColor(stringColor);
            fretNumberColor = a.getColor(R.styleable.GuitarChordView_fretNumberColor, DEFAULT_COLOR);
            fretNumberPaint.setColor(fretNumberColor);
            stringMarkerColor = a.getColor(R.styleable.GuitarChordView_stringMarkerColor, DEFAULT_COLOR);
            stringMarkerPaint.setColor(stringMarkerColor);
            noteColor = a.getColor(R.styleable.GuitarChordView_noteColor, DEFAULT_COLOR);
            notePaint.setColor(noteColor);
            noteNumberColor = a.getColor(R.styleable.GuitarChordView_noteNumberColor, WHITE);
            noteNumberPaint.setColor(noteNumberColor);
            barLineColor = a.getColor(R.styleable.GuitarChordView_barLineColor, DEFAULT_COLOR);
            barLinePaint.setColor(barLineColor);
            mutedText = a.getString(R.styleable.GuitarChordView_mutedText);
            mutedText = (mutedText == null) ? MUTED_TEXT : mutedText;
            openStringText = a.getString(R.styleable.GuitarChordView_openStringText);
            openStringText = (openStringText == null) ? OPEN_STRING_TEXT : openStringText;
            stringCount = a.getInt(R.styleable.GuitarChordView_stringAmount, 6);
            editable = a.getBoolean(R.styleable.GuitarChordView_editable, false);
            showFingerNumbers = a.getBoolean(R.styleable.GuitarChordView_showFingerNumbers, true);
            showFretNumbers = a.getBoolean(R.styleable.GuitarChordView_showFretNumbers, true);
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            a.recycle();
        }
    }
}

From source file:android.support.v7.preference.Preference.java

/**
 * Perform inflation from XML and apply a class-specific base style. This
 * constructor of Preference allows subclasses to use their own base style
 * when they are inflating. For example, a {@link CheckBoxPreference}
 * constructor calls this version of the super class constructor and
 * supplies {@code android.R.attr.checkBoxPreferenceStyle} for
 * <var>defStyleAttr</var>. This allows the theme's checkbox preference
 * style to modify all of the base preference attributes as well as the
 * {@link CheckBoxPreference} class's attributes.
 *
 * @param context The Context this is associated with, through which it can
 *            access the current theme, resources,
 *            {@link android.content.SharedPreferences}, etc.
 * @param attrs The attributes of the XML tag that is inflating the
 *            preference.//from w w w  .  ja  v  a2 s  .  co  m
 * @param defStyleAttr An attribute in the current theme that contains a
 *            reference to a style resource that supplies default values for
 *            the view. Can be 0 to not look for defaults.
 * @param defStyleRes A resource identifier of a style resource that
 *            supplies default values for the view, used only if
 *            defStyleAttr is 0 or can not be found in the theme. Can be 0
 *            to not look for defaults.
 * @see #Preference(Context, android.util.AttributeSet)
 */
public Preference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    mContext = context;

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

    mIconResId = TypedArrayUtils.getResourceId(a, R.styleable.Preference_icon,
            R.styleable.Preference_android_icon, 0);

    mKey = TypedArrayUtils.getString(a, R.styleable.Preference_key, R.styleable.Preference_android_key);

    mTitle = TypedArrayUtils.getString(a, R.styleable.Preference_title, R.styleable.Preference_android_title);

    mSummary = TypedArrayUtils.getString(a, R.styleable.Preference_summary,
            R.styleable.Preference_android_summary);

    mOrder = TypedArrayUtils.getInt(a, R.styleable.Preference_order, R.styleable.Preference_android_order,
            DEFAULT_ORDER);

    mFragment = TypedArrayUtils.getString(a, R.styleable.Preference_fragment,
            R.styleable.Preference_android_fragment);

    mLayoutResId = TypedArrayUtils.getResourceId(a, R.styleable.Preference_layout,
            R.styleable.Preference_android_layout, R.layout.preference);

    mWidgetLayoutResId = TypedArrayUtils.getResourceId(a, R.styleable.Preference_widgetLayout,
            R.styleable.Preference_android_widgetLayout, 0);

    mEnabled = TypedArrayUtils.getBoolean(a, R.styleable.Preference_enabled,
            R.styleable.Preference_android_enabled, true);

    mSelectable = TypedArrayUtils.getBoolean(a, R.styleable.Preference_selectable,
            R.styleable.Preference_android_selectable, true);

    mPersistent = TypedArrayUtils.getBoolean(a, R.styleable.Preference_persistent,
            R.styleable.Preference_android_persistent, true);

    mDependencyKey = TypedArrayUtils.getString(a, R.styleable.Preference_dependency,
            R.styleable.Preference_android_dependency);

    if (a.hasValue(R.styleable.Preference_defaultValue)) {
        mDefaultValue = onGetDefaultValue(a, R.styleable.Preference_defaultValue);
    } else if (a.hasValue(R.styleable.Preference_android_defaultValue)) {
        mDefaultValue = onGetDefaultValue(a, R.styleable.Preference_android_defaultValue);
    }

    mShouldDisableView = TypedArrayUtils.getBoolean(a, R.styleable.Preference_shouldDisableView,
            R.styleable.Preference_android_shouldDisableView, true);

    a.recycle();
}

From source file:com.mikecorrigan.trainscorekeeper.FragmentSummary.java

@SuppressLint("NewApi")
@Override//  www . j  av  a  2s . co  m
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.vc(VERBOSE, TAG, "onCreateView: inflater=" + inflater + ", container=" + container
            + ", savedInstanceState=" + Utils.bundleToString(savedInstanceState));

    View rootView = inflater.inflate(R.layout.fragment_summary, container, false);

    final MainActivity activity = (MainActivity) getActivity();
    final Context context = activity;
    final Resources resources = context.getResources();

    // Get the model and attach a listener.
    game = activity.getGame();
    if (game != null) {
        game.addListener(mGameListener);
    }

    players = activity.getPlayers();

    // Get resources.
    String[] playerNames = resources.getStringArray(R.array.playerNames);

    TypedArray drawablesArray = resources.obtainTypedArray(R.array.playerDrawables);

    TypedArray playerTextColorsArray = resources.obtainTypedArray(R.array.playerTextColors);
    int[] playerTextColorsIds = new int[playerTextColorsArray.length()];
    for (int i = 0; i < playerTextColorsArray.length(); i++) {
        playerTextColorsIds[i] = playerTextColorsArray.getResourceId(i, -1);
    }

    // Get root view.
    ScrollView scrollView = (ScrollView) rootView.findViewById(R.id.scroll_view);

    // Create table.
    tableLayout = new TableLayout(context);
    TableLayout.LayoutParams tableLayoutParams = new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    tableLayout.setLayoutParams(tableLayoutParams);
    scrollView.addView(tableLayout);

    // Add header.
    {
        TableRow row = new TableRow(context);
        row.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        tableLayout.addView(row);

        TextView tv = new TextView(context);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(10, 10, 10, 10);
        tv.setText(resources.getString(R.string.player));
        tv.setTypeface(null, Typeface.BOLD);
        row.addView(tv);

        tv = new TextView(context);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(10, 10, 10, 10);
        tv.setText(resources.getString(R.string.trains));
        tv.setTypeface(null, Typeface.BOLD);
        row.addView(tv);

        tv = new TextView(context);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(10, 10, 10, 10);
        tv.setText(resources.getString(R.string.contracts));
        tv.setTypeface(null, Typeface.BOLD);
        row.addView(tv);

        tv = new TextView(context);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(10, 10, 10, 10);
        tv.setText(resources.getString(R.string.bonuses));
        tv.setTypeface(null, Typeface.BOLD);
        row.addView(tv);

    }

    // Add rows.
    for (int i = 0; i < players.getNum(); i++) {
        TableRow row = new TableRow(context);
        row.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        tableLayout.addView(row);

        ToggleButton toggleButton = new ToggleButton(context);
        toggleButton.setGravity(Gravity.CENTER);
        toggleButton.setPadding(10, 10, 10, 10);
        toggleButton.setText(playerNames[i]);
        toggleButton.setClickable(false);
        Drawable drawable = drawablesArray.getDrawable(i);
        int sdk = android.os.Build.VERSION.SDK_INT;
        if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
            toggleButton.setBackgroundDrawable(drawable);
        } else {
            toggleButton.setBackground(drawable);
        }
        toggleButton.setTextColor(resources.getColor(playerTextColorsIds[i]));
        row.addView(toggleButton);

        TextView tv = new TextView(context);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(10, 10, 10, 10);
        row.addView(tv);

        tv = new TextView(context);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(10, 10, 10, 10);
        row.addView(tv);

        tv = new TextView(context);
        tv.setGravity(Gravity.CENTER);
        tv.setPadding(10, 10, 10, 10);
        row.addView(tv);

    }

    Bundle args = getArguments();
    if (args == null) {
        Log.e(TAG, "onCreateView: missing arguments");
        return rootView;
    }

    drawablesArray.recycle();
    playerTextColorsArray.recycle();

    // final int index = args.getInt(ARG_INDEX);
    // final String tabSpec = args.getString(ARG_TAB_SPEC);

    return rootView;
}

From source file:android.support.designox.widget.CollapsingToolbarLayout.java

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

    ThemeUtils.checkAppCompatTheme(context);

    mCollapsingTextHelper = new CollapsingTextHelper(this);
    mCollapsingTextHelper.setTextSizeInterpolator(AnimationUtils.DECELERATE_INTERPOLATOR);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CollapsingToolbarLayout, defStyleAttr,
            R.style.Widget_Design_CollapsingToolbar);

    mCollapsingTextHelper.setExpandedTextGravity(a.getInt(
            R.styleable.CollapsingToolbarLayout_expandedTitleGravity, GravityCompat.START | Gravity.BOTTOM));
    mCollapsingTextHelper/*from w w w  . ja  v a2  s  .co  m*/
            .setCollapsedTextGravity(a.getInt(R.styleable.CollapsingToolbarLayout_collapsedTitleGravity,
                    GravityCompat.START | Gravity.CENTER_VERTICAL));

    mExpandedMarginStart = mExpandedMarginTop = mExpandedMarginEnd = mExpandedMarginBottom = a
            .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMargin, 0);

    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginStart)) {
        mExpandedMarginStart = a
                .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginStart, 0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginEnd)) {
        mExpandedMarginEnd = a.getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginEnd,
                0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginTop)) {
        mExpandedMarginTop = a.getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginTop,
                0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginBottom)) {
        mExpandedMarginBottom = a
                .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginBottom, 0);
    }

    mCollapsingTitleEnabled = a.getBoolean(R.styleable.CollapsingToolbarLayout_titleEnabled, true);
    setTitle(a.getText(R.styleable.CollapsingToolbarLayout_title));

    // First load the default text appearances
    mCollapsingTextHelper.setExpandedTextAppearance(R.style.TextAppearance_Design_CollapsingToolbar_Expanded);
    mCollapsingTextHelper.setCollapsedTextAppearance(R.style.TextAppearance_AppCompat_Widget_ActionBar_Title);

    // Now overlay any custom text appearances
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleTextAppearance)) {
        mCollapsingTextHelper.setExpandedTextAppearance(
                a.getResourceId(R.styleable.CollapsingToolbarLayout_expandedTitleTextAppearance, 0));
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_collapsedTitleTextAppearance)) {
        mCollapsingTextHelper.setCollapsedTextAppearance(
                a.getResourceId(R.styleable.CollapsingToolbarLayout_collapsedTitleTextAppearance, 0));
    }

    setContentScrim(a.getDrawable(R.styleable.CollapsingToolbarLayout_contentScrim));
    setStatusBarScrim(a.getDrawable(R.styleable.CollapsingToolbarLayout_statusBarScrim));

    mToolbarId = a.getResourceId(R.styleable.CollapsingToolbarLayout_toolbarId, -1);

    a.recycle();

    setWillNotDraw(false);

    ViewCompat.setOnApplyWindowInsetsListener(this,
            new android.support.v4ox.view.OnApplyWindowInsetsListener() {
                @Override
                public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
                    return setWindowInsets(insets);
                }
            });
}

From source file:co.lujun.popmenulayout.PopMenuLayout.java

private void initAttrs(Context context, AttributeSet attrs, int defStyleAttr) {
    TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.PopMenuLayout, defStyleAttr, 0);
    mConfigJson = attributes.getString(R.styleable.PopMenuLayout_config_json);
    mLevel2MenuAnimStyle = attributes.getResourceId(R.styleable.PopMenuLayout_level2_menu_anim_style,
            mLevel2MenuAnimStyle);/*from w  ww.j a va2s .  c  o  m*/
    mLevel1MenuItemHeight = attributes.getDimension(R.styleable.PopMenuLayout_level1_menu_item_height,
            Util.dp2px(context, mLevel1MenuItemHeight));
    mChildMenuItemHeight = attributes.getDimension(R.styleable.PopMenuLayout_child_menu_item_height,
            Util.dp2px(context, mChildMenuItemHeight));
    isWithLevel1MenuWidth = attributes.getBoolean(R.styleable.PopMenuLayout_cmenu_w_follow_level1_menu,
            isWithLevel1MenuWidth);
    mMenuDividerDp = attributes.getDimension(R.styleable.PopMenuLayout_menu_divider_width,
            Util.dp2px(context, mMenuDividerDp));
    mMenuTextPaddingLeft = attributes.getDimension(R.styleable.PopMenuLayout_menu_left_padding,
            Util.dp2px(context, mMenuTextPaddingLeft));
    mMenuTextPaddingRight = attributes.getDimension(R.styleable.PopMenuLayout_menu_right_padding,
            Util.dp2px(context, mMenuTextPaddingRight));
    mMenuTextPaddingTop = attributes.getDimension(R.styleable.PopMenuLayout_menu_top_padding,
            Util.dp2px(context, mMenuTextPaddingTop));
    mMenuTextPaddingBottom = attributes.getDimension(R.styleable.PopMenuLayout_menu_bottom_padding,
            Util.dp2px(context, mMenuTextPaddingBottom));
    mDividerColor = attributes.getColor(R.styleable.PopMenuLayout_menu_divider_color, mDividerColor);
    mExpandableIcon = attributes.getResourceId(R.styleable.PopMenuLayout_menu_expandable_icon, mExpandableIcon);
    mMenuTextColor = attributes.getColor(R.styleable.PopMenuLayout_menu_text_color, mMenuTextColor);
    mHorizontalMenuBackgroundRes = attributes.getResourceId(R.styleable.PopMenuLayout_horizontal_menu_bg,
            mHorizontalMenuBackgroundRes);
    mVerticalMenuBackgroundRes = attributes.getResourceId(R.styleable.PopMenuLayout_vertical_menu_bg,
            mVerticalMenuBackgroundRes);
    mMenuTextSize = attributes.getDimension(R.styleable.PopMenuLayout_menu_text_size,
            Util.sp2px(context, mMenuTextSize));
    mMaxMenuItemCount = attributes.getInteger(R.styleable.PopMenuLayout_child_menu_max_count,
            mMaxMenuItemCount);
    mLevel1MenuLayoutBgColor = attributes.getColor(R.styleable.PopMenuLayout_level1_menu_layout_bg_color,
            mLevel1MenuLayoutBgColor);
    mChildMenuLayoutBgColor = attributes.getColor(R.styleable.PopMenuLayout_cmenu_layout_bg_color,
            mChildMenuLayoutBgColor);
    mDividerMarginLeft = attributes.getDimension(R.styleable.PopMenuLayout_divider_margin_left,
            Util.dp2px(context, mDividerMarginLeft));
    mDividerMarginRight = attributes.getDimension(R.styleable.PopMenuLayout_divider_margin_right,
            Util.dp2px(context, mDividerMarginRight));
    mDividerMarginTop = attributes.getDimension(R.styleable.PopMenuLayout_divider_margin_top,
            Util.dp2px(context, mDividerMarginTop));
    mDividerMarginBottom = attributes.getDimension(R.styleable.PopMenuLayout_divider_margin_bottom,
            Util.dp2px(context, mDividerMarginBottom));
    attributes.recycle();
}

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

private static VerifierInfo parseVerifier(Resources res, XmlPullParser parser, AttributeSet attrs, int flags) {
    final TypedArray sa = res.obtainAttributes(attrs,
            com.android.internal.R.styleable.AndroidManifestPackageVerifier);

    final String packageName = sa
            .getNonResourceString(com.android.internal.R.styleable.AndroidManifestPackageVerifier_name);

    final String encodedPublicKey = sa
            .getNonResourceString(com.android.internal.R.styleable.AndroidManifestPackageVerifier_publicKey);

    sa.recycle();

    if (packageName == null || packageName.length() == 0) {
        Slog.i(TAG, "verifier package name was null; skipping");
        return null;
    }/*from w w w.  j a v a2s .  c  o m*/

    final PublicKey publicKey = parsePublicKey(encodedPublicKey);
    if (publicKey == null) {
        Slog.i(TAG, "Unable to parse verifier public key for " + packageName);
        return null;
    }

    return new VerifierInfo(packageName, publicKey);
}

From source file:android.support.v7.app.AppCompatDelegateImplV7.java

private void applyFixedSizeWindow() {
    TypedArray a = mContext.obtainStyledAttributes(R.styleable.Theme);

    TypedValue mFixedWidthMajor = null;/*w  w w. java 2 s  .c om*/
    TypedValue mFixedWidthMinor = null;
    TypedValue mFixedHeightMajor = null;
    TypedValue mFixedHeightMinor = null;

    if (a.hasValue(R.styleable.Theme_windowFixedWidthMajor)) {
        if (mFixedWidthMajor == null)
            mFixedWidthMajor = new TypedValue();
        a.getValue(R.styleable.Theme_windowFixedWidthMajor, mFixedWidthMajor);
    }
    if (a.hasValue(R.styleable.Theme_windowFixedWidthMinor)) {
        if (mFixedWidthMinor == null)
            mFixedWidthMinor = new TypedValue();
        a.getValue(R.styleable.Theme_windowFixedWidthMinor, mFixedWidthMinor);
    }
    if (a.hasValue(R.styleable.Theme_windowFixedHeightMajor)) {
        if (mFixedHeightMajor == null)
            mFixedHeightMajor = new TypedValue();
        a.getValue(R.styleable.Theme_windowFixedHeightMajor, mFixedHeightMajor);
    }
    if (a.hasValue(R.styleable.Theme_windowFixedHeightMinor)) {
        if (mFixedHeightMinor == null)
            mFixedHeightMinor = new TypedValue();
        a.getValue(R.styleable.Theme_windowFixedHeightMinor, mFixedHeightMinor);
    }

    final DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
    final boolean isPortrait = metrics.widthPixels < metrics.heightPixels;
    int w = ViewGroup.LayoutParams.MATCH_PARENT;
    int h = ViewGroup.LayoutParams.MATCH_PARENT;

    final TypedValue tvw = isPortrait ? mFixedWidthMinor : mFixedWidthMajor;
    if (tvw != null && tvw.type != TypedValue.TYPE_NULL) {
        if (tvw.type == TypedValue.TYPE_DIMENSION) {
            w = (int) tvw.getDimension(metrics);
        } else if (tvw.type == TypedValue.TYPE_FRACTION) {
            w = (int) tvw.getFraction(metrics.widthPixels, metrics.widthPixels);
        }
    }

    final TypedValue tvh = isPortrait ? mFixedHeightMajor : mFixedHeightMinor;
    if (tvh != null && tvh.type != TypedValue.TYPE_NULL) {
        if (tvh.type == TypedValue.TYPE_DIMENSION) {
            h = (int) tvh.getDimension(metrics);
        } else if (tvh.type == TypedValue.TYPE_FRACTION) {
            h = (int) tvh.getFraction(metrics.heightPixels, metrics.heightPixels);
        }
    }

    if (w != ViewGroup.LayoutParams.MATCH_PARENT || h != ViewGroup.LayoutParams.MATCH_PARENT) {
        mWindow.setLayout(w, h);
    }

    a.recycle();
}

From source file:android.support.design.widget.CollapsingToolbarLayout.java

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

    ThemeUtils.checkAppCompatTheme(context);

    mCollapsingTextHelper = new CollapsingTextHelper(this);
    mCollapsingTextHelper.setTextSizeInterpolator(AnimationUtils.DECELERATE_INTERPOLATOR);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CollapsingToolbarLayout, defStyleAttr,
            R.style.Widget_Design_CollapsingToolbar);

    mCollapsingTextHelper.setExpandedTextGravity(a.getInt(
            R.styleable.CollapsingToolbarLayout_expandedTitleGravity, GravityCompat.START | Gravity.BOTTOM));
    mCollapsingTextHelper//from   w  w w  .  ja v  a 2  s.c  o m
            .setCollapsedTextGravity(a.getInt(R.styleable.CollapsingToolbarLayout_collapsedTitleGravity,
                    GravityCompat.START | Gravity.CENTER_VERTICAL));

    mExpandedMarginStart = mExpandedMarginTop = mExpandedMarginEnd = mExpandedMarginBottom = a
            .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMargin, 0);

    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginStart)) {
        mExpandedMarginStart = a
                .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginStart, 0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginEnd)) {
        mExpandedMarginEnd = a.getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginEnd,
                0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginTop)) {
        mExpandedMarginTop = a.getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginTop,
                0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginBottom)) {
        mExpandedMarginBottom = a
                .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginBottom, 0);
    }

    mCollapsingTitleEnabled = a.getBoolean(R.styleable.CollapsingToolbarLayout_titleEnabled, true);
    setTitle(a.getText(R.styleable.CollapsingToolbarLayout_title));

    // First load the default text appearances
    mCollapsingTextHelper.setExpandedTextAppearance(R.style.TextAppearance_Design_CollapsingToolbar_Expanded);
    mCollapsingTextHelper.setCollapsedTextAppearance(
            android.support.v7.appcompat.R.style.TextAppearance_AppCompat_Widget_ActionBar_Title);

    // Now overlay any custom text appearances
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleTextAppearance)) {
        mCollapsingTextHelper.setExpandedTextAppearance(
                a.getResourceId(R.styleable.CollapsingToolbarLayout_expandedTitleTextAppearance, 0));
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_collapsedTitleTextAppearance)) {
        mCollapsingTextHelper.setCollapsedTextAppearance(
                a.getResourceId(R.styleable.CollapsingToolbarLayout_collapsedTitleTextAppearance, 0));
    }

    mScrimVisibleHeightTrigger = a
            .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_scrimVisibleHeightTrigger, -1);

    mScrimAnimationDuration = a.getInt(R.styleable.CollapsingToolbarLayout_scrimAnimationDuration,
            DEFAULT_SCRIM_ANIMATION_DURATION);

    setContentScrim(a.getDrawable(R.styleable.CollapsingToolbarLayout_contentScrim));
    setStatusBarScrim(a.getDrawable(R.styleable.CollapsingToolbarLayout_statusBarScrim));

    mToolbarId = a.getResourceId(R.styleable.CollapsingToolbarLayout_toolbarId, -1);

    a.recycle();

    setWillNotDraw(false);

    ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            return onWindowInsetChanged(insets);
        }
    });
}