Example usage for android.content.res TypedArray getInteger

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

Introduction

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

Prototype

public int getInteger(@StyleableRes int index, int defValue) 

Source Link

Document

Retrieve the integer value for the attribute at index.

Usage

From source file:com.jungle.widgets.view.JungleLanternView.java

private void initLayout(Context context, AttributeSet attrs) {
    View.inflate(context, R.layout.layout_lantern_view, this);

    mAdapter = new ViewPagerAdapter();
    mViewPager = (FixedSpeedViewPager) findViewById(R.id.lantern_view_pager);
    mViewPager.setAdapter(mAdapter);//from  ww  w .  ja  va2  s  .c  o  m
    mViewPager.setSetItemListener(new FixedSpeedViewPager.OnSetItemListener() {
        @Override
        public void onSetNewItem() {
            scheduleLanternSwitch();
        }
    });

    if (attrs != null) {
        TypedArray arr = context.obtainStyledAttributes(attrs, R.styleable.JungleLanternView);
        mAutoSwitch = arr.getBoolean(R.styleable.JungleLanternView_autoScroll, mAutoSwitch);
        mSwitchIntervalMs = arr.getInteger(R.styleable.JungleLanternView_switchIntervalMs, mSwitchIntervalMs);

        arr.recycle();
    }

    mViewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            if (mPageChangeListener != null) {
                mPageChangeListener.onPageScrolled(position, positionOffset, positionOffsetPixels);
            }
        }

        @Override
        public void onPageSelected(int position) {
            if (!mAdapter.isNeedExtraItem()) {
                mIndicator.setCurrSeledIndex(position);
                if (mPageChangeListener != null) {
                    mPageChangeListener.onPageSelected(position);
                }

                return;
            }

            int index = 0;
            int rawCount = mAdapter.getRawCount();
            if (position == rawCount + 1) {
                index = 0;
            } else if (position == 0) {
                index = rawCount - 1;
            } else {
                index = position - 1;
            }

            mIndicator.setCurrSeledIndex(index);
            mViewPager.setScrollDurationFactor(1);

            if (mPageChangeListener != null) {
                mPageChangeListener.onPageSelected(index);
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {
            if (mPageChangeListener != null) {
                mPageChangeListener.onPageScrollStateChanged(state);
            }

            if (!mAdapter.isNeedExtraItem()) {
                return;
            }

            if (state == ViewPager.SCROLL_STATE_IDLE) {
                int rawCount = mAdapter.getRawCount();
                int currItemIndex = mViewPager.getCurrentItem();

                if (currItemIndex == rawCount + 1) {
                    mViewPager.setCurrentItemManual(1, false);
                } else if (currItemIndex == 0) {
                    mViewPager.setCurrentItemManual(rawCount, false);
                }
            }
        }
    });

    if (context instanceof BaseActivity) {
        BaseActivity activity = (BaseActivity) context;
        activity.addLifeCycleListener(mLifeCycleListener);
    }
}

From source file:com.github.andrewlord1990.snackbarbuilder.SnackbarBuilder.java

private void loadDuration(TypedArray attrs) {
    int durationAttr = attrs.getInteger(R.styleable.SnackbarBuilderStyle_snackbarBuilder_duration,
            Integer.MIN_VALUE);/*from w ww  .j  av a 2  s . c  o m*/
    if (durationAttr > Integer.MIN_VALUE) {
        duration = durationAttr;
    }
}

From source file:com.tingtingapps.securesms.preferences.ColorPreference.java

private void initAttrs(AttributeSet attrs, int defStyle) {
    TypedArray a = getContext().getTheme().obtainStyledAttributes(attrs,
            com.tingtingapps.securesms.R.styleable.ColorPreference, defStyle, defStyle);

    try {/*ww  w .  j  ava2s . c om*/
        mItemLayoutId = a.getResourceId(com.tingtingapps.securesms.R.styleable.ColorPreference_itemLayout,
                mItemLayoutId);
        mNumColumns = a.getInteger(com.tingtingapps.securesms.R.styleable.ColorPreference_numColumns,
                mNumColumns);
        //      int choicesResId = a.getResourceId(R.styleable.ColorPreference_choices,
        //                                         R.array.default_color_choice_values);
        //      if (choicesResId > 0) {
        //        String[] choices = a.getResources().getStringArray(choicesResId);
        //        mColorChoices = new int[choices.length];
        //        for (int i = 0; i < choices.length; i++) {
        //          mColorChoices[i] = Color.parseColor(choices[i]);
        //        }
        //      }

    } finally {
        a.recycle();
    }

    setWidgetLayoutResource(mItemLayoutId);
}

From source file:com.dnielfe.manager.Browser.java

private void setupDrawer() {
    final TypedArray array = obtainStyledAttributes(new int[] { R.attr.themeId });
    final int themeId = array.getInteger(0, SimpleExplorer.THEME_ID_LIGHT);
    array.recycle();/* w  ww. ja v a  2 s  .co m*/

    mDrawer = (LinearLayout) findViewById(R.id.left_drawer);

    // Set shadow of navigation drawer
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START);

    int icon = themeId == SimpleExplorer.THEME_ID_LIGHT ? R.drawable.holo_light_ic_drawer
            : R.drawable.holo_dark_ic_drawer;

    // Add Navigation Drawer to ActionBar
    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, icon, R.string.drawer_open,
            R.string.drawer_close) {

        @Override
        public void onDrawerOpened(View view) {
            super.onDrawerOpened(view);
            mActionBar.setDisplayOptions(
                    ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE);
            mActionBar.setTitle(R.string.app_name);
            invalidateOptionsMenu();
        }

        @Override
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            mActionBar.setDisplayOptions(
                    ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_CUSTOM);
            invalidateOptionsMenu();
        }
    };

    mDrawerLayout.setDrawerListener(mDrawerToggle);
}

From source file:spirit.freewill.view.indicator.UnderlinePageIndicator.java

public UnderlinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;/*from  w w  w .j  a  va2 s.c om*/

    final Resources res = getResources();

    //Load defaults from resources
    final boolean defaultFades = true;
    final int defaultFadeDelay = 300;
    final int defaultFadeLength = 400;
    //        final int defaultSelectedColor = 0;

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

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

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

    a.recycle();

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

From source file:com.augustopicciani.drawablepageindicator.widget.DrawablePagerIndicator.java

public DrawablePagerIndicator(Context context, AttributeSet attrs) {

    super(context, attrs);
    this.mContext = context;
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DrawablePagerIndicator, 0, 0);
    drawableSelectedId = a.getResourceId(R.styleable.DrawablePagerIndicator_drawableSelected,
            R.drawable.ic_slider_on);//from  w  w w.j  a v a  2 s.  c  o m
    drawableDefaultId = a.getResourceId(R.styleable.DrawablePagerIndicator_drawableDefault,
            R.drawable.ic_slider_off);
    imageSpacing = a.getInteger(R.styleable.DrawablePagerIndicator_imageSpacing, 0);
    this.mCentered = a.getBoolean(R.styleable.DrawablePagerIndicator_centered, false);
    a.recycle();

}

From source file:com.gxy.fastscrollrecyclerview.views.FastScroller.java

public FastScroller(Context context, FastScrollRecyclerView recyclerView, AttributeSet attrs) {

    Resources resources = context.getResources();
    mRecyclerView = recyclerView;//from   w ww.java 2s  . c  o  m
    mPopup = new FastScrollPopup(resources, recyclerView);
    mThumbHeight = Utils.toPixels(resources, 32);
    mWidth = Utils.toPixels(resources, 4);
    mWidthBg = Utils.toPixels(resources, 2);
    mTouchInset = Utils.toPixels(resources, -30);
    mThumb = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTrack = new Paint(Paint.ANTI_ALIAS_FLAG);

    TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.FastScrollRecyclerView,
            0, 0);
    try {
        mAutoHideEnabled = typedArray.getBoolean(R.styleable.FastScrollRecyclerView_fastScrollAutoHide, true);
        mAutoHideDelay = typedArray.getInteger(R.styleable.FastScrollRecyclerView_fastScrollAutoHideDelay,
                DEFAULT_AUTO_HIDE_DELAY);

        int trackColor = typedArray.getColor(R.styleable.FastScrollRecyclerView_fastScrollTrackColor,
                0x1f000000);
        int thumbColor = typedArray.getColor(R.styleable.FastScrollRecyclerView_fastScrollThumbColor,
                0xff000000);
        int popupBgColor = typedArray.getColor(R.styleable.FastScrollRecyclerView_fastScrollPopupBgColor,
                0xff000000);
        int popupTextColor = typedArray.getColor(R.styleable.FastScrollRecyclerView_fastScrollPopupTextColor,
                0xffffffff);

        mTrack.setColor(trackColor);
        mThumb.setColor(thumbColor);
        mPopup.setBgColor(popupBgColor);
        mPopup.setTextColor(popupTextColor);
    } finally {
        typedArray.recycle();
    }

    mHideRunnable = new Runnable() {
        @Override
        public void run() {
            if (!mIsDragging) {
                if (mAutoHideAnimator != null) {
                    mAutoHideAnimator.cancel();
                }
                mAutoHideAnimator = ObjectAnimator.ofInt(FastScroller.this, "offsetX",
                        (Utils.isRtl(mRecyclerView.getResources()) ? -1 : 1) * mWidth);
                mAutoHideAnimator.setInterpolator(new FastOutLinearInInterpolator());
                mAutoHideAnimator.setDuration(200);
                mAutoHideAnimator.start();
            }
        }
    };

    mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            show();
        }
    });

    if (mAutoHideEnabled) {
        postAutoHideDelayed();
    }
}

From source file:com.appsummary.luoxf.myappsummary.recyclerView.fastscroll.Views.FastScroller.java

public FastScroller(Context context, FastScrollRecyclerView recyclerView, AttributeSet attrs) {

    Resources resources = context.getResources();

    mRecyclerView = recyclerView;// w w  w .  j  av a 2s.  c  o m
    mPopup = new FastScrollPopup(resources, recyclerView);

    mThumbHeight = Utils.toPixels(resources, 48);
    mWidth = Utils.toPixels(resources, 8);

    mTouchInset = Utils.toPixels(resources, -24);

    mThumb = new Paint(Paint.ANTI_ALIAS_FLAG);
    mTrack = new Paint(Paint.ANTI_ALIAS_FLAG);

    TypedArray typedArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.FastScrollRecyclerView,
            0, 0);
    try {
        mAutoHideEnabled = typedArray.getBoolean(R.styleable.FastScrollRecyclerView_fastScrollAutoHide, true);
        mAutoHideDelay = typedArray.getInteger(R.styleable.FastScrollRecyclerView_fastScrollAutoHideDelay,
                DEFAULT_AUTO_HIDE_DELAY);

        int trackColor = typedArray.getColor(R.styleable.FastScrollRecyclerView_fastScrollTrackColor,
                0x1f000000);
        int thumbColor = typedArray.getColor(R.styleable.FastScrollRecyclerView_fastScrollThumbColor,
                0xff000000);
        int popupBgColor = typedArray.getColor(R.styleable.FastScrollRecyclerView_fastScrollPopupBgColor,
                0xff000000);
        int popupTextColor = typedArray.getColor(R.styleable.FastScrollRecyclerView_fastScrollPopupTextColor,
                0xffffffff);

        mTrack.setColor(trackColor);
        mThumb.setColor(thumbColor);
        mPopup.setBgColor(popupBgColor);
        mPopup.setTextColor(popupTextColor);
    } finally {
        typedArray.recycle();
    }

    mHideRunnable = new Runnable() {
        @Override
        public void run() {
            if (!mIsDragging) {
                if (mAutoHideAnimator != null) {
                    mAutoHideAnimator.cancel();
                }
                mAutoHideAnimator = ObjectAnimator.ofInt(FastScroller.this, "offsetX",
                        (Utils.isRtl(mRecyclerView.getResources()) ? -1 : 1) * mWidth);
                mAutoHideAnimator.setInterpolator(new FastOutLinearInInterpolator());
                mAutoHideAnimator.setDuration(200);
                mAutoHideAnimator.start();
            }
        }
    };

    mRecyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            super.onScrolled(recyclerView, dx, dy);
            show();
        }
    });

    if (mAutoHideEnabled) {
        postAutoHideDelayed();
    }
}

From source file:com.augustopicciani.drawablepageindicator.widget.DrawablePagerIndicator.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public DrawablePagerIndicator(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {

    super(context, attrs, defStyleAttr, defStyleRes);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DrawablePagerIndicator, defStyleAttr, 0);
    drawableSelectedId = a.getResourceId(R.styleable.DrawablePagerIndicator_drawableSelected,
            R.drawable.ic_slider_on);// w  w w.ja v a  2s  .co m
    drawableDefaultId = a.getResourceId(R.styleable.DrawablePagerIndicator_drawableDefault,
            R.drawable.ic_slider_off);
    imageSpacing = a.getInteger(R.styleable.DrawablePagerIndicator_imageSpacing, 0);
    a.recycle();
}

From source file:com.augustopicciani.drawablepageindicator.widget.DrawablePagerIndicator.java

public DrawablePagerIndicator(Context context, AttributeSet attrs, int defStyleAttr) {

    super(context, attrs, defStyleAttr);
    this.mContext = context;
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DrawablePagerIndicator, defStyleAttr, 0);
    drawableSelectedId = a.getResourceId(R.styleable.DrawablePagerIndicator_drawableSelected,
            R.drawable.ic_slider_on);/*from  ww w.  j  a va  2 s  .  c o  m*/
    drawableDefaultId = a.getResourceId(R.styleable.DrawablePagerIndicator_drawableDefault,
            R.drawable.ic_slider_off);
    imageSpacing = a.getInteger(R.styleable.DrawablePagerIndicator_imageSpacing, 0);
    this.mCentered = a.getBoolean(R.styleable.DrawablePagerIndicator_centered, false);

    a.recycle();

}