List of usage examples for android.content.res TypedArray recycle
public void recycle()
From source file:com.actionbarsherlock.internal.view.menu.ActionMenuItemView.java
public ActionMenuItemView(Context context, AttributeSet attrs, int defStyle) { //TODO super(context, attrs, defStyle); super(context, attrs); mAllowTextWithIcon = getResources_getBoolean(context, R.bool.abs__config_allowActionMenuItemTextWithIcon); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SherlockActionMenuItemView, 0, 0); mMinWidth = a.getDimensionPixelSize(R.styleable.SherlockActionMenuItemView_android_minWidth, 0); a.recycle(); }
From source file:android.support.v7ox.view.ActionBarPolicy.java
public int getTabContainerHeight() { TypedArray a = mContext.obtainStyledAttributes(null, R.styleable.ActionBar, R.attr.actionBarStyle_ox, 0); int height = a.getLayoutDimension(R.styleable.ActionBar_height, 0); Resources r = mContext.getResources(); if (!hasEmbeddedTabs()) { // Stacked tabs; limit the height height = Math.min(height, r.getDimensionPixelSize(R.dimen.abc_action_bar_stacked_max_height)); }/* ww w. ja v a 2s .com*/ a.recycle(); return height; }
From source file:android.support.v7.internal.view.menu.ActionMenuItemView.java
public ActionMenuItemView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); final Resources res = context.getResources(); mAllowTextWithIcon = res.getBoolean(R.bool.abc_config_allowActionMenuItemTextWithIcon); TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ActionMenuItemView, defStyle, 0); mMinWidth = a.getDimensionPixelSize(R.styleable.ActionMenuItemView_android_minWidth, 0); a.recycle(); final float density = res.getDisplayMetrics().density; mMaxIconSize = (int) (MAX_ICON_SIZE * density + 0.5f); setOnClickListener(this); setOnLongClickListener(this); mSavedPaddingLeft = -1;//from w w w. j a va2 s . c om }
From source file:com.eutectoid.dosomething.picker.FriendPickerFragment.java
@Override public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) { super.onInflate(activity, attrs, savedInstanceState); TypedArray a = activity.obtainStyledAttributes(attrs, R.styleable.picker_friend_picker_fragment); setMultiSelect(a.getBoolean(R.styleable.picker_friend_picker_fragment_multi_select, multiSelect)); a.recycle(); }
From source file:android.support.v7.app.DrawerLayoutActivity.java
@Override protected void onContentViewSet() { super.onContentViewSet(); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); mDrawer = (ListView) findViewById(R.id.start_drawer); mContent = (TextView) findViewById(R.id.content_text); mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // The drawer title must be set in order to announce state changes when // accessibility is turned on. This is typically a simple description, // e.g. "Navigation". mDrawerLayout.setDrawerTitle(GravityCompat.START, getString(R.string.drawer_title)); mDrawer.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, Shakespeare.TITLES)); mDrawer.setOnItemClickListener(new DrawerItemClickListener()); // Find the toolbar in our layout and set it as the support action bar on the activity. // This is required to have the drawer slide "over" the toolbar. mToolbar = (Toolbar) findViewById(R.id.toolbar); mToolbar.setTitle(R.string.drawer_title); setSupportActionBar(mToolbar);/* ww w . ja v a2 s . c o m*/ getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(false); // ActionBarDrawerToggle provides convenient helpers for tying together the // prescribed interactions between a top-level sliding drawer and the action bar. // Note that, as the Javadocs of ActionBarDrawerToggle constructors say, we are // *not* using a constructor that gets a Toolbar since we're setting our toolbar // dynamically at runtime. Furthermore, as the drawer is sliding over the toolbar, // we are suppressing the morphing animation from hamburger to back arrow by // calling super.onDrawerSlide with slideOffset=0.0f. In case your app only has // top-level pages and doesn't need back arrow visuals at all, you can set up // your activity theme to have attribute named "drawerArrowStyle" that points // to an extension of Widget.AppCompat.DrawerArrowToggle that has its "spinBars" // attribute set to false. mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close) { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); super.onDrawerSlide(drawerView, 0.0f); } @Override public void onDrawerSlide(View drawerView, float slideOffset) { super.onDrawerSlide(drawerView, 0.0f); } }; mDrawerLayout.addDrawerListener(mDrawerToggle); // Configure the background color fill of the system status bar (on supported platform // versions) and the toolbar itself. We're using the same color, and android:statusBar // from the theme makes the status bar slightly darker. final int metalBlueColor = getResources().getColor(R.color.drawer_sample_metal_blue); mDrawerLayout.setStatusBarBackgroundColor(metalBlueColor); mToolbar.setBackgroundColor(metalBlueColor); // Register a pre-draw listener to get the initial width of the DrawerLayout so // that we can determine the width of the drawer based on the Material spec at // https://www.google.com/design/spec/patterns/navigation-drawer.html#navigation-drawer-specs mDrawerLayout.getViewTreeObserver().addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { @Override public boolean onPreDraw() { // What is the width of the entire DrawerLayout? final int drawerLayoutWidth = mDrawerLayout.getWidth(); // What is the action bar size? final Resources.Theme theme = mDrawerLayout.getContext().getTheme(); final TypedArray a = theme .obtainStyledAttributes(new int[] { android.support.v7.appcompat.R.attr.actionBarSize }); final int actionBarSize = a.getDimensionPixelSize(0, 0); if (a != null) { a.recycle(); } // Compute the width of the drawer and set it on the layout params. final int idealDrawerWidth = 5 * actionBarSize; final int maxDrawerWidth = Math.max(0, drawerLayoutWidth - actionBarSize); final int drawerWidth = Math.min(idealDrawerWidth, maxDrawerWidth); final DrawerLayout.LayoutParams drawerLp = (DrawerLayout.LayoutParams) mDrawer.getLayoutParams(); drawerLp.width = drawerWidth; mDrawer.setLayoutParams(drawerLp); // Remove ourselves as the pre-draw listener since this is a one-time // configuration. mDrawerLayout.getViewTreeObserver().removeOnPreDrawListener(this); return true; } }); }
From source file:com.actionbarsherlock.internal.widget.AbsActionBarView.java
@Override public void onConfigurationChanged(Configuration newConfig) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) { super.onConfigurationChanged(newConfig); } else if (mMenuView != null) { mMenuView.onConfigurationChanged(newConfig); }// www .j a v a 2 s.c om // Action bar can change size on configuration changes. // Reread the desired height from the theme-specified style. TypedArray a = getContext().obtainStyledAttributes(null, R.styleable.SherlockActionBar, R.attr.actionBarStyle, 0); setContentHeight(a.getLayoutDimension(R.styleable.SherlockActionBar_height, 0)); a.recycle(); if (mSplitWhenNarrow) { setSplitActionBar(getResources_getBoolean(getContext(), R.bool.abs__split_action_bar_is_narrow)); } if (mActionMenuPresenter != null) { mActionMenuPresenter.onConfigurationChanged(newConfig); } }
From source file:cn.ieclipse.af.view.ScrollLayout.java
private void init(Context context, AttributeSet attrs) { if (attrs != null) { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ScrollLayout); debug = a.getBoolean(R.styleable.ScrollLayout_debug, false); mSnapVelocity = a.getInt(R.styleable.ScrollLayout_snapVelocity, SNAP_VELOCITY); a.recycle(); }// w ww .j av a2 s .c om }
From source file:androidx.navigation.NavDestination.java
/** * Called when inflating a destination from a resource. * * @param context local context performing inflation * @param attrs attrs to parse during inflation *///w ww .ja v a 2s . c o m @CallSuper public void onInflate(@NonNull Context context, @NonNull AttributeSet attrs) { final TypedArray a = context.getResources().obtainAttributes(attrs, R.styleable.Navigator); setId(a.getResourceId(R.styleable.Navigator_android_id, 0)); setLabel(a.getText(R.styleable.Navigator_android_label)); a.recycle(); }
From source file:co.paulburke.android.textviewpager.TextViewPager.java
public TextViewPager(Context context, AttributeSet attrs, int defStyle) { super(context, attrs); mPagerAdapter = new TextViewPagerAdapter(context, mMeasureListener); if (attrs != null) { TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.TextViewPager); int layout = attributes.getResourceId(R.styleable.TextViewPager_textViewLayout, -1); CharSequence text = attributes.getText(R.styleable.TextViewPager_android_text); mPagerAdapter.setTextViewLayout(layout); mPagerAdapter.setText(text);/*from ww w .j av a2 s . c om*/ attributes.recycle(); } setAdapter(mPagerAdapter); }
From source file:android.support.v7.app.AppCompatViewInflater.java
/** * android:onClick doesn't handle views with a ContextWrapper context. This method * backports new framework functionality to traverse the Context wrappers to find a * suitable target.//from ww w . j a v a 2 s.co m */ private void checkOnClickListener(View view, AttributeSet attrs) { final Context context = view.getContext(); if (!(context instanceof ContextWrapper) || (Build.VERSION.SDK_INT >= 15 && !ViewCompat.hasOnClickListeners(view))) { // Skip our compat functionality if: the Context isn't a ContextWrapper, or // the view doesn't have an OnClickListener (we can only rely on this on API 15+ so // always use our compat code on older devices) return; } final TypedArray a = context.obtainStyledAttributes(attrs, sOnClickAttrs); final String handlerName = a.getString(0); if (handlerName != null) { view.setOnClickListener(new DeclaredOnClickListener(view, handlerName)); } a.recycle(); }