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:android.support.wear.widget.CircularProgressLayout.java

private int[] getColorListFromResources(Resources resources, int arrayResId) {
    TypedArray colorArray = resources.obtainTypedArray(arrayResId);
    int[] colors = new int[colorArray.length()];
    for (int i = 0; i < colorArray.length(); i++) {
        colors[i] = colorArray.getColor(i, 0);
    }//from  w  w  w  . j ava  2  s.co m
    colorArray.recycle();
    return colors;
}

From source file:es.uniovi.imovil.fcrtrainer.highscores.HighscoresFragment.java

private void initializeLevelSpinner() {
    ArrayList<String> levelNames = new ArrayList<String>();

    TypedArray array = getResources().obtainTypedArray(R.array.pref_level_values);

    for (int i = 0; i < array.length(); i++) {
        int defaultId = 0;
        int resourceId = array.getResourceId(i, defaultId);

        String name = getResources().getString(resourceId);
        levelNames.add(name);/* ww  w  . j a v  a  2 s .  co  m*/
    }

    array.recycle();

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item,
            levelNames);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    mLevelSpinner = (Spinner) mRootView.findViewById(R.id.spinner_level);
    mLevelSpinner.setAdapter(adapter);

    mLevelSpinner.setOnItemSelectedListener(this);
}

From source file:cn.sdgundam.comicatsdgo.extension.SwipeRefreshLayout.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 * @param context/* w ww.  ja  va  2  s . co  m*/
 * @param attrs
 */
public SwipeRefreshLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMediumAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);

    setWillNotDraw(false);
    mProgressBar = new SwipeProgressBar(this);
    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    mProgressBarHeight = (int) (metrics.density * PROGRESS_BAR_HEIGHT);
    mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);
    mAccelerateInterpolator = new AccelerateInterpolator(ACCELERATE_INTERPOLATION_FACTOR);

    final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
    setEnabled(a.getBoolean(0, true));
    a.recycle();
}

From source file:cn.njmeter.njmeter.widget.spinner.NiceSpinner.java

private int getDefaultTextColor(Context context) {
    TypedValue typedValue = new TypedValue();
    context.getTheme().resolveAttribute(android.R.attr.textColorPrimary, typedValue, true);
    TypedArray typedArray = context.obtainStyledAttributes(typedValue.data,
            new int[] { android.R.attr.textColorPrimary });
    int defaultTextColor = typedArray.getColor(0, Color.BLACK);
    typedArray.recycle();
    return defaultTextColor;
}

From source file:es.uniovi.imovil.fcrtrainer.highscores.HighscoresFragment.java

private void addExerciseModule(ArrayList<Exercise> exercises, int arrayResourceId) {
    TypedArray array = getResources().obtainTypedArray(arrayResourceId);

    for (int i = 0; i < array.length(); i++) {
        int defaultId = 0;
        int resourceId = array.getResourceId(i, defaultId);

        Exercise exercise = new Exercise(getResources().getString(resourceId), resourceId);
        exercises.add(exercise);//from  w  ww .  j av  a  2  s .  com
    }

    array.recycle();
}

From source file:ca.hoogit.garagepi.Controls.DoorView.java

private void init(Context context, AttributeSet attrs, int defStyle) {
    inflate(getContext(), R.layout.door_view, this);
    ButterKnife.bind(this);

    final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.DoorView, defStyle, 0);
    mOpenedColor = a.getColor(R.styleable.DoorView_openedColor,
            ContextCompat.getColor(context, R.color.colorAccent));
    mClosedColor = a.getColor(R.styleable.DoorView_closedColor,
            ContextCompat.getColor(context, R.color.colorPrimary));
    mDoorName = a.getString(R.styleable.DoorView_doorName);
    a.recycle();

    mContext = context;//from w  ww  .ja va  2  s. co m

    mToggleContainer.setOnClickListener(OnSingleClickListener.wrap(v -> {
        if (mOnToggle != null) {
            mOnToggle.onToggle(mDoorName);
        }
    }));

    mToggleContainer.setOnTouchListener((v, event) -> {
        int origColor = mDoorValue ? mOpenedColor : mClosedColor;
        if (event.getAction() == MotionEvent.ACTION_DOWN) {
            mToggleContainer.setBackgroundColor(ColorUtil.darken(origColor));
        } else if (event.getAction() == MotionEvent.ACTION_UP
                || event.getAction() == MotionEvent.ACTION_CANCEL) {
            mToggleContainer.setBackgroundColor(origColor);
        }
        return false;
    });

    setupViews();
}

From source file:cn.bvin.app.swiperefresh.OldSwipeRefreshLayout.java

/**
 * Constructor that is called when inflating SwipeRefreshLayout from XML.
 *
 * @param context/*from  www .  ja v a  2s  .  c o m*/
 * @param attrs
 */
public OldSwipeRefreshLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMediumAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);

    setWillNotDraw(false);
    mProgressBar = new SwipeProgressBar(this);
    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    mProgressBarHeight = (int) (metrics.density * PROGRESS_BAR_HEIGHT);
    mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);
    mAccelerateInterpolator = new AccelerateInterpolator(ACCELERATE_INTERPOLATION_FACTOR);

    final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
    setEnabled(a.getBoolean(0, true));
    a.recycle();
}

From source file:com.abewy.android.apps.klyph.messenger.widget.BezelImageView.java

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

    // Attribute initialization
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BezelImageView, defStyle, 0);

    setMaskDrawable(a.getDrawable(R.styleable.BezelImageView_maskDrawable));

    setBorderDrawable(a.getDrawable(R.styleable.BezelImageView_borderDrawable));

    mDesaturateOnPress = a.getBoolean(R.styleable.BezelImageView_desaturateOnPress, mDesaturateOnPress);

    a.recycle();

    // Other initialization
    mBlackPaint = new Paint();
    mBlackPaint.setColor(0xff000000);/*from  w w w  .  j  a v a2  s  .c o  m*/

    mMaskedPaint = new Paint();
    mMaskedPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));

    // Always want a cache allocated.
    mCacheBitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);

    if (mDesaturateOnPress) {
        // Create a desaturate color filter for pressed state.
        ColorMatrix cm = new ColorMatrix();
        cm.setSaturation(0);
        mDesaturateColorFilter = new ColorMatrixColorFilter(cm);
    }
}

From source file:am.widget.tabstrip.TabStripView.java

private void initView(Context context, @Nullable AttributeSet attrs) {
    final TypedArray custom = context.obtainStyledAttributes(attrs, R.styleable.TabStripView);
    mHelper.set(custom.getResourceId(R.styleable.TabStripView_tsvViewPager, NO_ID),
            custom.getBoolean(R.styleable.TabStripView_tsvAutoFindViewPager, true),
            custom.getBoolean(R.styleable.TabStripView_tsvClickSmoothScroll, false));
    custom.recycle();
}

From source file:net.sf.sprockets.app.ui.SprocketsPreferenceFragment.java

@Override
public void onInflate(Activity a, AttributeSet attrs, Bundle savedInstanceState) {
    super.onInflate(a, attrs, savedInstanceState);
    TypedArray array = a.obtainStyledAttributes(attrs, R.styleable.SprocketsPreferenceFragment);
    Bundle args = Fragments.arguments(this);
    args.putInt(PREFS, array.getResourceId(R.styleable.SprocketsPreferenceFragment_preferences, 0));
    args.putBoolean(TRACK_CHANGES,/*from  www.ja va 2 s.c om*/
            array.getBoolean(R.styleable.SprocketsPreferenceFragment_trackChanges, false));
    array.recycle();
}