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:com.github.snowdream.android.widget.NotFoundWebView.java

@SuppressLint({ "SetJavaScriptEnabled", "NewApi" })
private void init(Context context, AttributeSet attrs, int defStyle) {
    if (context == null) {
        return;/*from  www .j av a  2  s. c o m*/
    }

    // enable JavaScript
    WebSettings settings = this.getSettings();
    settings.setJavaScriptEnabled(true);

    settings.setSupportZoom(true);
    settings.setBuiltInZoomControls(true);
    settings.setLoadWithOverviewMode(true);
    settings.setDefaultZoom(ZoomDensity.FAR);

    //settings.setUseWideViewPort(true);
    //webView.setInitialScale(1);

    // init attrs
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.CustomWebView);

    try {
        int type = a.getInteger(R.styleable.CustomWebView_type, 0);
        switch (type) {
        case 0:
            script = context.getString(R.string.html_notfound);
            break;
        case 1:
            script = context.getString(R.string.html_qq_narrow);
            break;
        case 2:
            script = context.getString(R.string.html_qq_narrow);
            break;
        case 3:
            script = context.getString(R.string.html_qq_wide);
            break;
        case 4:
            script = context.getString(R.string.html_yibo);
            break;
        default:
            script = a.getString(R.styleable.CustomWebView_script);
            break;
        }
    } finally {
        a.recycle();
    }
}

From source file:android.support.v7.widget.AppCompatCompoundButtonHelper.java

void loadFromAttributes(AttributeSet attrs, int defStyleAttr) {
    TypedArray a = mView.getContext().obtainStyledAttributes(attrs, R.styleable.CompoundButton, defStyleAttr,
            0);//  w ww .  ja  v  a  2  s . c  o m
    try {
        if (a.hasValue(R.styleable.CompoundButton_android_button)) {
            final int resourceId = a.getResourceId(R.styleable.CompoundButton_android_button, 0);
            if (resourceId != 0) {
                mView.setButtonDrawable(mDrawableManager.getDrawable(mView.getContext(), resourceId));
            }
        }
        if (a.hasValue(R.styleable.CompoundButton_buttonTint)) {
            CompoundButtonCompat.setButtonTintList(mView,
                    a.getColorStateList(R.styleable.CompoundButton_buttonTint));
        }
        if (a.hasValue(R.styleable.CompoundButton_buttonTintMode)) {
            CompoundButtonCompat.setButtonTintMode(mView,
                    DrawableUtils.parseTintMode(a.getInt(R.styleable.CompoundButton_buttonTintMode, -1), null));
        }
    } finally {
        a.recycle();
    }
}

From source file:eu.faircode.netguard.AdapterRule.java

public AdapterRule(Activity context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);

    this.context = context;

    if (prefs.getBoolean("dark_theme", false))
        colorChanged = Color.argb(128, Color.red(Color.DKGRAY), Color.green(Color.DKGRAY),
                Color.blue(Color.DKGRAY));
    else/* ww  w  .  j a v a2  s .  c  om*/
        colorChanged = Color.argb(128, Color.red(Color.LTGRAY), Color.green(Color.LTGRAY),
                Color.blue(Color.LTGRAY));

    TypedArray ta = context.getTheme().obtainStyledAttributes(new int[] { android.R.attr.textColorSecondary });
    try {
        colorText = ta.getColor(0, 0);
    } finally {
        ta.recycle();
    }

    TypedValue tv = new TypedValue();
    context.getTheme().resolveAttribute(R.attr.colorOn, tv, true);
    colorOn = tv.data;
    context.getTheme().resolveAttribute(R.attr.colorOff, tv, true);
    colorOff = tv.data;

    colorGrayed = ContextCompat.getColor(context, R.color.colorGrayed);

    iconSize = Util.dips2pixels(48, context);
}

From source file:github.popeen.dsub.activity.SubsonicFragmentActivity.java

@Override
public void onStateUpdate(DownloadFile downloadFile, PlayerState playerState) {
    int[] attrs = new int[] {
            (playerState == PlayerState.STARTED) ? R.attr.actionbar_pause : R.attr.actionbar_start };
    TypedArray typedArray = this.obtainStyledAttributes(attrs);
    startButton.setImageResource(typedArray.getResourceId(0, 0));
    typedArray.recycle();
}

From source file:cn.usmaker.ben.view.refresh.NeuSwipeRefreshLayout.java

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

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

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

    setWillNotDraw(false);
    mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);

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

    final TypedArray a2 = context.obtainStyledAttributes(attrs, R.styleable.NeuSwipeRefreshLayout);
    NeuSwipeRefreshLayoutDirection direction = NeuSwipeRefreshLayoutDirection
            .getFromInt(a2.getInt(R.styleable.NeuSwipeRefreshLayout_direction, 0));
    if (direction != NeuSwipeRefreshLayoutDirection.BOTH) {
        mDirection = direction;
        mBothDirection = false;
    } else {
        mDirection = NeuSwipeRefreshLayoutDirection.TOP;
        mBothDirection = true;
    }
    a2.recycle();

    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    mCircleWidth = (int) (CIRCLE_DIAMETER * metrics.density);
    mCircleHeight = (int) (CIRCLE_DIAMETER * metrics.density);

    createProgressView();
    ViewCompat.setChildrenDrawingOrderEnabled(this, true);
    // the absolute offset has to take into account that the circle starts at an offset
    mSpinnerFinalOffset = DEFAULT_CIRCLE_TARGET * metrics.density;
}

From source file:be.virtualsushi.gaz.view.ActivityChooserView.java

/**
 * Create a new instance.//from ww w  .j ava  2s .co  m
 * 
 * @param context
 *            The application environment.
 * @param attrs
 *            A collection of attributes.
 * @param defStyle
 *            The default style to apply to this view.
 */
public ActivityChooserView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray attributesArray = context.obtainStyledAttributes(attrs, R.styleable.ActivityChooserView,
            defStyle, 0);

    mInitialActivityCount = attributesArray.getInt(R.styleable.ActivityChooserView_initialActivityCount,
            ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_DEFAULT);

    Drawable expandActivityOverflowButtonDrawable = attributesArray
            .getDrawable(R.styleable.ActivityChooserView_expandActivityOverflowButtonDrawable);

    attributesArray.recycle();

    LayoutInflater inflater = LayoutInflater.from(getContext());
    inflater.inflate(R.layout.abc_activity_chooser_view, this, true);

    mCallbacks = new Callbacks();

    mActivityChooserContent = (LinearLayout) findViewById(R.id.activity_chooser_view_content);
    mActivityChooserContent.setBackgroundDrawable(null);
    findViewById(R.id.default_activity_button).setVisibility(GONE);

    mExpandActivityOverflowButton = (FrameLayout) findViewById(R.id.expand_activities_button);
    mExpandActivityOverflowButton.setOnClickListener(mCallbacks);
    mExpandActivityOverflowButtonImage = (ImageView) mExpandActivityOverflowButton.findViewById(R.id.image);
    mExpandActivityOverflowButtonImage.setImageDrawable(expandActivityOverflowButtonDrawable);

    mAdapter = new ActivityChooserViewAdapter();
    mAdapter.registerDataSetObserver(new DataSetObserver() {
        @Override
        public void onChanged() {
            super.onChanged();
            updateAppearance();
        }
    });

    Resources resources = context.getResources();
    mListPopupMaxWidth = Math.max(resources.getDisplayMetrics().widthPixels / 2,
            resources.getDimensionPixelSize(R.dimen.abc_config_prefDialogWidth));
}

From source file:codetail.graphics.drawables.LayerDrawable.java

@Override
public void inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Theme theme)
        throws XmlPullParserException, IOException {
    super.inflate(r, parser, attrs, theme);

    final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.LayerDrawable);
    updateStateFromTypedArray(theme, a, null);
    a.recycle();

    inflateLayers(r, parser, attrs, theme);

    ensurePadding();/*  w w w. j  av a 2s.  c o  m*/
    onStateChange(getState());
}

From source file:github.popeen.dsub.activity.SubsonicFragmentActivity.java

@Override
public void onMetadataUpdate(MusicDirectory.Entry song, int fieldChange) {
    if (song != null && coverArtView != null && fieldChange == DownloadService.METADATA_UPDATED_COVER_ART) {
        int height = coverArtView.getHeight();
        if (height <= 0) {
            int[] attrs = new int[] { R.attr.actionBarSize };
            TypedArray typedArray = this.obtainStyledAttributes(attrs);
            height = typedArray.getDimensionPixelSize(0, 0);
            typedArray.recycle();
        }/*from  w  ww  . j  a  v  a 2 s.  c o  m*/
        getImageLoader().loadImage(coverArtView, song, false, height, false);

        // We need to update it immediately since it won't update if updater is not running for it
        if (nowPlayingFragment != null
                && slideUpPanel.getPanelState() == SlidingUpPanelLayout.PanelState.COLLAPSED) {
            nowPlayingFragment.onMetadataUpdate(song, fieldChange);
        }
    }
}

From source file:android.support.v14.preference.SwitchPreference.java

/**
 * Construct a new SwitchPreference with the given style options.
 *
 * @param context The Context that will style this preference
 * @param attrs Style attributes that differ from the default
 * @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./*from   www  .  jav a  2  s  .com*/
 */
public SwitchPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

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

    setSummaryOn(TypedArrayUtils.getString(a, R.styleable.SwitchPreference_summaryOn,
            R.styleable.SwitchPreference_android_summaryOn));

    setSummaryOff(TypedArrayUtils.getString(a, R.styleable.SwitchPreference_summaryOff,
            R.styleable.SwitchPreference_android_summaryOff));

    setSwitchTextOn(TypedArrayUtils.getString(a, R.styleable.SwitchPreference_switchTextOn,
            R.styleable.SwitchPreference_android_switchTextOn));

    setSwitchTextOff(TypedArrayUtils.getString(a, R.styleable.SwitchPreference_switchTextOff,
            R.styleable.SwitchPreference_android_switchTextOff));

    setDisableDependentsState(TypedArrayUtils.getBoolean(a, R.styleable.SwitchPreference_disableDependentsState,
            R.styleable.SwitchPreference_android_disableDependentsState, false));

    a.recycle();
}

From source file:com.adkdevelopment.e_contact.utils.UnderlinePageIndicator.java

@TargetApi(Build.VERSION_CODES.M)
public UnderlinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;/*from www . j a  v  a  2  s .  co m*/

    final Resources res = getResources();

    //Load defaults from resources
    final boolean defaultFades = res.getBoolean(R.bool.default_underline_indicator_fades);
    final int defaultFadeDelay = res.getInteger(R.integer.default_underline_indicator_fade_delay);
    final int defaultFadeLength = res.getInteger(R.integer.default_underline_indicator_fade_length);

    int defaultSelectedColor;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        defaultSelectedColor = res.getColor(R.color.white, context.getTheme());
    } else {
        //noinspection deprecation
        defaultSelectedColor = res.getColor(R.color.white);
    }

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.UnderlinePageIndicator, defStyle, 0);

    setFades(a.getBoolean(R.styleable.UnderlinePageIndicator_fades, defaultFades));
    setSelectedColor(a.getColor(R.styleable.UnderlinePageIndicator_selectedColor, defaultSelectedColor));
    setFadeDelay(a.getInteger(R.styleable.UnderlinePageIndicator_fadeDelay, defaultFadeDelay));
    setFadeLength(a.getInteger(R.styleable.UnderlinePageIndicator_fadeLength, defaultFadeLength));

    mCornerRadius = a.getDimension(R.styleable.UnderlinePageIndicator_vpi_corner_radius, 0);

    Drawable background = a.getDrawable(R.styleable.UnderlinePageIndicator_android_background);
    if (background != null) {
        setBackground(background);
    }

    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}