Example usage for android.content.res TypedArray getResourceId

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

Introduction

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

Prototype

@AnyRes
public int getResourceId(@StyleableRes int index, int defValue) 

Source Link

Document

Retrieves the resource identifier for the attribute at index.

Usage

From source file:com.example.pyrkesa.shwc.MainActivity.java

public void set(String[] navMenuTitles, TypedArray navMenuIcons, int NumActivity) {
    if ((NumActivity >= 0) && (NumActivity <= 4))
        mTitle = navMenuTitles[NumActivity];
    else//  ww  w  . j  a v  a  2 s  .  com
        mTitle = getTitle();

    mDrawerTitle = "Menu";
    mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.left_drawer);

    navDrawerItems = new ArrayList<NavDrawerItem>();

    // adding nav drawer items
    if (navMenuIcons == null) {
        for (int i = 0; i < navMenuTitles.length; i++) {
            navDrawerItems.add(new NavDrawerItem(navMenuTitles[i]));
        }
    } else {
        for (int i = 0; i < navMenuTitles.length; i++) {
            navDrawerItems.add(new NavDrawerItem(navMenuTitles[i], navMenuIcons.getResourceId(i, -1)));
        }
    }

    mDrawerList.setOnItemClickListener(new SlideMenuClickListener());

    // setting the nav drawer list adapter
    adapter = new NavDrawerListAdapter(getApplicationContext(), navDrawerItems);
    mDrawerList.setAdapter(adapter);

    // enabling action bar app icon and behaving it as toggle button
    getActionBar().setDisplayHomeAsUpEnabled(true);
    getActionBar().setHomeButtonEnabled(true);
    // getSupportActionBar().setIcon(R.drawable.ic_drawer);

    mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.drawable.mini_logo, // nav menu toggle icon
            R.string.app_name, // nav drawer open - description for
            // accessibility
            R.string.app_name // nav drawer close - description for
    // accessibility
    ) {
        public void onDrawerClosed(View view) {
            getActionBar().setTitle(mTitle);
            // calling onPrepareOptionsMenu() to show action bar icons
            invalidateOptionsMenu();
        }

        public void onDrawerOpened(View drawerView) {
            getActionBar().setTitle(mDrawerTitle);
            // calling onPrepareOptionsMenu() to hide action bar icons
            invalidateOptionsMenu();
        }
    };
    mDrawerLayout.setDrawerListener(mDrawerToggle);

}

From source file:SwipeListView.java

/**
 * Init ListView/*from  w  w w .  j a  v a  2s  . c om*/
 *
 * @param attrs AttributeSet
 */
private void init(AttributeSet attrs) {

    int swipeMode = SWIPE_MODE_BOTH;
    boolean swipeOpenOnLongPress = true;
    boolean swipeCloseAllItemsWhenMoveList = true;
    long swipeAnimationTime = 0;
    float swipeOffsetLeft = 0;
    float swipeOffsetRight = 0;
    int swipeDrawableChecked = 0;
    int swipeDrawableUnchecked = 0;

    int swipeActionLeft = SWIPE_ACTION_REVEAL;
    int swipeActionRight = SWIPE_ACTION_REVEAL;

    if (attrs != null) {
        TypedArray styled = getContext().obtainStyledAttributes(attrs, R.styleable.SwipeListView);
        swipeMode = styled.getInt(R.styleable.SwipeListView_swipeMode, SWIPE_MODE_BOTH);
        swipeActionLeft = styled.getInt(R.styleable.SwipeListView_swipeActionLeft, SWIPE_ACTION_REVEAL);
        swipeActionRight = styled.getInt(R.styleable.SwipeListView_swipeActionRight, SWIPE_ACTION_REVEAL);
        swipeOffsetLeft = styled.getDimension(R.styleable.SwipeListView_swipeOffsetLeft, 0);
        swipeOffsetRight = styled.getDimension(R.styleable.SwipeListView_swipeOffsetRight, 0);
        swipeOpenOnLongPress = styled.getBoolean(R.styleable.SwipeListView_swipeOpenOnLongPress, true);
        swipeAnimationTime = styled.getInteger(R.styleable.SwipeListView_swipeAnimationTime, 0);
        swipeCloseAllItemsWhenMoveList = styled
                .getBoolean(R.styleable.SwipeListView_swipeCloseAllItemsWhenMoveList, true);
        swipeDrawableChecked = styled.getResourceId(R.styleable.SwipeListView_swipeDrawableChecked, 0);
        swipeDrawableUnchecked = styled.getResourceId(R.styleable.SwipeListView_swipeDrawableUnchecked, 0);
        swipeFrontView = styled.getResourceId(R.styleable.SwipeListView_swipeFrontView, 0);
        swipeBackView = styled.getResourceId(R.styleable.SwipeListView_swipeBackView, 0);
    }

    if (swipeFrontView == 0 || swipeBackView == 0) {
        swipeFrontView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_FRONT_VIEW, "id",
                getContext().getPackageName());
        swipeBackView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_BACK_VIEW, "id",
                getContext().getPackageName());

        if (swipeFrontView == 0 || swipeBackView == 0) {
            throw new RuntimeException(String.format(
                    "You forgot the attributes swipeFrontView or swipeBackView. You can add this attributes or use '%s' and '%s' identifiers",
                    SWIPE_DEFAULT_FRONT_VIEW, SWIPE_DEFAULT_BACK_VIEW));
        }
    }

    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    touchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    touchListener = new SwipeListViewTouchListener(this, swipeFrontView, swipeBackView);
    if (swipeAnimationTime > 0) {
        touchListener.setAnimationTime(swipeAnimationTime);
    }
    touchListener.setRightOffset(swipeOffsetRight);
    touchListener.setLeftOffset(swipeOffsetLeft);
    touchListener.setSwipeActionLeft(swipeActionLeft);
    touchListener.setSwipeActionRight(swipeActionRight);
    touchListener.setSwipeMode(swipeMode);
    touchListener.setSwipeClosesAllItemsWhenListMoves(swipeCloseAllItemsWhenMoveList);
    touchListener.setSwipeOpenOnLongPress(swipeOpenOnLongPress);
    touchListener.setSwipeDrawableChecked(swipeDrawableChecked);
    touchListener.setSwipeDrawableUnchecked(swipeDrawableUnchecked);
    setOnTouchListener(touchListener);
    setOnScrollListener(touchListener.makeScrollListener());
}

From source file:com.daniel.view.swipelistview.SwipeListView.java

/**
 * Init ListView/*from  w  w w . j  a v  a2 s  .c  o m*/
 *
 * @param attrs AttributeSet
 */
private void init(AttributeSet attrs) {

    int swipeMode = SWIPE_MODE_BOTH;
    boolean swipeOpenOnLongPress = true;
    boolean swipeCloseAllItemsWhenMoveList = true;
    long swipeAnimationTime = 0;
    float swipeOffsetLeft = 0;
    float swipeOffsetRight = 0;
    int swipeDrawableChecked = 0;
    int swipeDrawableUnchecked = 0;

    int swipeActionLeft = SWIPE_ACTION_NONE;
    int swipeActionRight = SWIPE_ACTION_NONE;

    if (attrs != null) {
        TypedArray styled = getContext().obtainStyledAttributes(attrs, R.styleable.SwipeListView);
        swipeMode = styled.getInt(R.styleable.SwipeListView_swipeMode, SWIPE_MODE_BOTH);
        swipeActionLeft = styled.getInt(R.styleable.SwipeListView_swipeActionLeft, SWIPE_ACTION_REVEAL);
        swipeActionRight = styled.getInt(R.styleable.SwipeListView_swipeActionRight, SWIPE_ACTION_REVEAL);
        swipeOffsetLeft = styled.getDimension(R.styleable.SwipeListView_swipeOffsetLeft, 0);
        swipeOffsetRight = styled.getDimension(R.styleable.SwipeListView_swipeOffsetRight, 0);
        swipeOpenOnLongPress = styled.getBoolean(R.styleable.SwipeListView_swipeOpenOnLongPress, true);
        swipeAnimationTime = styled.getInteger(R.styleable.SwipeListView_swipeAnimationTime, 0);
        swipeCloseAllItemsWhenMoveList = styled
                .getBoolean(R.styleable.SwipeListView_swipeCloseAllItemsWhenMoveList, true);
        swipeDrawableChecked = styled.getResourceId(R.styleable.SwipeListView_swipeDrawableChecked, 0);
        swipeDrawableUnchecked = styled.getResourceId(R.styleable.SwipeListView_swipeDrawableUnchecked, 0);
        swipeFrontView = styled.getResourceId(R.styleable.SwipeListView_swipeFrontView, 0);
        swipeBackView = styled.getResourceId(R.styleable.SwipeListView_swipeBackView, 0);
    }

    if (swipeFrontView == 0 || swipeBackView == 0) {
        swipeFrontView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_FRONT_VIEW, "id",
                getContext().getPackageName());
        swipeBackView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_BACK_VIEW, "id",
                getContext().getPackageName());

        if (swipeFrontView == 0 || swipeBackView == 0) {
            throw new RuntimeException(String.format(
                    "You forgot the attributes swipeFrontView or swipeBackView. You can add this attributes or use '%s' and '%s' identifiers",
                    SWIPE_DEFAULT_FRONT_VIEW, SWIPE_DEFAULT_BACK_VIEW));
        }
    }

    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    touchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    touchListener = new SwipeListViewTouchListener(this, swipeFrontView, swipeBackView);
    if (swipeAnimationTime > 0) {
        touchListener.setAnimationTime(swipeAnimationTime);
    }
    touchListener.setRightOffset(swipeOffsetRight);
    touchListener.setLeftOffset(swipeOffsetLeft);
    touchListener.setSwipeActionLeft(swipeActionLeft);
    touchListener.setSwipeActionRight(swipeActionRight);
    touchListener.setSwipeMode(swipeMode);
    touchListener.setSwipeClosesAllItemsWhenListMoves(swipeCloseAllItemsWhenMoveList);
    touchListener.setSwipeOpenOnLongPress(swipeOpenOnLongPress);
    touchListener.setSwipeDrawableChecked(swipeDrawableChecked);
    touchListener.setSwipeDrawableUnchecked(swipeDrawableUnchecked);
    setOnTouchListener(touchListener);
    scrollListener = touchListener.makeScrollListener();
    setOnScrollListener(scrollListener);
}

From source file:com.hobby.uiframework.widget.PagerSlidingTab.java

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

    setFillViewport(true);//from w  w  w .j  a  va 2  s. c om
    setWillNotDraw(false);

    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // get system attrs (android:textSize and android:textColor)

    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

    tabTextSize = a.getDimensionPixelSize(0, tabTextSize);
    tabTextColor = a.getColor(1, tabTextColor);

    a.recycle();

    // get custom attrs

    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);

    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);

    a.recycle();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }
}

From source file:cn.qiuc.org.igoogleplay.lib.pagerslidingtab.PagerSlidingTab.java

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

    setFillViewport(true);/*ww w  .j  a  v  a2  s .  co m*/
    setWillNotDraw(false);

    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabTextSize, dm);

    // get system attrs (android:textSize and android:textColor)

    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

    tabTextSize = a.getDimensionPixelSize(0, tabTextSize);
    tabTextColor = a.getColor(1, tabTextColor);

    a.recycle();

    // get custom attrs

    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTab);

    indicatorColor = a.getColor(R.styleable.PagerSlidingTab_indicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTab_underlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTab_dividerColor, dividerColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTab_indicatorHeight, indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTab_underlineHeight, underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTab_pst_dividerPadding, dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTab_tabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTab_tabBackground, tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTab_shouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTab_scrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTab_pst_textAllCaps, textAllCaps);

    a.recycle();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }
}

From source file:com.contentful.discovery.ui.PagerSlidingTabStrip.java

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

    setFillViewport(true);//from   w  w w .  j  a v a  2 s  . co  m
    setWillNotDraw(false);

    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, tabTextSize, dm);

    // get system attrs (android:textSize and android:textColor)

    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

    tabTextSize = a.getDimensionPixelSize(0, tabTextSize);

    a.recycle();

    // get custom attrs

    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTabStrip);

    indicatorColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsIndicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsUnderlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTabStrip_pstsDividerColor, dividerColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsIndicatorHeight,
            indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsUnderlineHeight,
            underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsDividerPadding,
            dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsTabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTabStrip_pstsTabBackground,
            tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsShouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTabStrip_pstsScrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTabStrip_pstsTextAllCaps, textAllCaps);

    a.recycle();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }
}

From source file:cn.fantasee.swipwmenulistview.swipelistview.SwipeListView.java

/**
 * Init ListView//from  www  .java  2  s .  c  o  m
 *
 * @param attrs AttributeSet
 */
private void init(AttributeSet attrs) {

    int swipeMode = SWIPE_MODE_BOTH;
    boolean swipeOpenOnLongPress = true;
    boolean swipeCloseAllItemsWhenMoveList = true;
    long swipeAnimationTime = 0;
    float swipeOffsetLeft = 0;
    float swipeOffsetRight = 0;
    int swipeDrawableChecked = 0;
    int swipeDrawableUnchecked = 0;

    int swipeActionLeft = SWIPE_ACTION_REVEAL;
    int swipeActionRight = SWIPE_ACTION_REVEAL;

    if (attrs != null) {
        TypedArray styled = getContext().obtainStyledAttributes(attrs, R.styleable.SwipeListView);
        swipeMode = styled.getInt(R.styleable.SwipeListView_swipeMode, SWIPE_MODE_BOTH);
        swipeActionLeft = styled.getInt(R.styleable.SwipeListView_swipeActionLeft, SWIPE_ACTION_REVEAL);
        swipeActionRight = styled.getInt(R.styleable.SwipeListView_swipeActionRight, SWIPE_ACTION_REVEAL);
        swipeOffsetLeft = styled.getDimension(R.styleable.SwipeListView_swipeOffsetLeft, 0);
        swipeOffsetRight = styled.getDimension(R.styleable.SwipeListView_swipeOffsetRight, 0);
        swipeOpenOnLongPress = styled.getBoolean(R.styleable.SwipeListView_swipeOpenOnLongPress, true);
        swipeAnimationTime = styled.getInteger(R.styleable.SwipeListView_swipeAnimationTime, 0);
        swipeCloseAllItemsWhenMoveList = styled
                .getBoolean(R.styleable.SwipeListView_swipeCloseAllItemsWhenMoveList, true);
        swipeDrawableChecked = styled.getResourceId(R.styleable.SwipeListView_swipeDrawableChecked, 0);
        swipeDrawableUnchecked = styled.getResourceId(R.styleable.SwipeListView_swipeDrawableUnchecked, 0);
        swipeFrontView = styled.getResourceId(R.styleable.SwipeListView_swipeFrontView, 0);
        swipeBackView = styled.getResourceId(R.styleable.SwipeListView_swipeBackView, 0);
        styled.recycle();
    }

    if (swipeFrontView == 0 || swipeBackView == 0) {
        swipeFrontView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_FRONT_VIEW, "id",
                getContext().getPackageName());
        swipeBackView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_BACK_VIEW, "id",
                getContext().getPackageName());

        if (swipeFrontView == 0 || swipeBackView == 0) {
            throw new RuntimeException(String.format(
                    "You forgot the attributes swipeFrontView or swipeBackView. You can add this attributes or use '%s' and '%s' identifiers",
                    SWIPE_DEFAULT_FRONT_VIEW, SWIPE_DEFAULT_BACK_VIEW));
        }
    }

    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    touchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    touchListener = new SwipeListViewTouchListener(this, swipeFrontView, swipeBackView);
    if (swipeAnimationTime > 0) {
        touchListener.setAnimationTime(swipeAnimationTime);
    }
    touchListener.setRightOffset(swipeOffsetRight);
    touchListener.setLeftOffset(swipeOffsetLeft);
    touchListener.setSwipeActionLeft(swipeActionLeft);
    touchListener.setSwipeActionRight(swipeActionRight);
    touchListener.setSwipeMode(swipeMode);
    touchListener.setSwipeClosesAllItemsWhenListMoves(swipeCloseAllItemsWhenMoveList);
    touchListener.setSwipeOpenOnLongPress(swipeOpenOnLongPress);
    touchListener.setSwipeDrawableChecked(swipeDrawableChecked);
    touchListener.setSwipeDrawableUnchecked(swipeDrawableUnchecked);
    setOnTouchListener(touchListener);
    setOnScrollListener(touchListener.makeScrollListener());
}

From source file:com.example.zhangyipeng.swipelibrary.SwipeListView.java

/**
 * Init ListView/*  w w w.  j a  v a2  s  .co  m*/
 *
 * @param attrs AttributeSet
 */
private void init(AttributeSet attrs) {

    int swipeMode = SWIPE_MODE_BOTH;
    boolean swipeOpenOnLongPress = true;
    boolean swipeCloseAllItemsWhenMoveList = true;
    long swipeAnimationTime = 0;
    float swipeOffsetLeft = 0;
    float swipeOffsetRight = 0;
    int swipeDrawableChecked = 0;
    int swipeDrawableUnchecked = 0;

    int swipeActionLeft = SWIPE_ACTION_REVEAL;
    int swipeActionRight = SWIPE_ACTION_REVEAL;

    if (attrs != null) {
        TypedArray styled = getContext().obtainStyledAttributes(attrs, R.styleable.SwipeListView);
        swipeMode = styled.getInt(R.styleable.SwipeListView_swipeMode, SWIPE_MODE_BOTH);
        swipeActionLeft = styled.getInt(R.styleable.SwipeListView_swipeActionLeft, SWIPE_ACTION_REVEAL);
        swipeActionRight = styled.getInt(R.styleable.SwipeListView_swipeActionRight, SWIPE_ACTION_REVEAL);
        swipeOffsetLeft = styled.getDimension(R.styleable.SwipeListView_swipeOffsetLeft, 0);
        swipeOffsetRight = styled.getDimension(R.styleable.SwipeListView_swipeOffsetRight, 0);
        swipeOpenOnLongPress = styled.getBoolean(R.styleable.SwipeListView_swipeOpenOnLongPress, true);
        swipeAnimationTime = styled.getInteger(R.styleable.SwipeListView_swipeAnimationTime, 0);
        swipeCloseAllItemsWhenMoveList = styled
                .getBoolean(R.styleable.SwipeListView_swipeCloseAllItemsWhenMoveList, true);
        swipeDrawableChecked = styled.getResourceId(R.styleable.SwipeListView_swipeDrawableChecked, 0);
        swipeDrawableUnchecked = styled.getResourceId(R.styleable.SwipeListView_swipeDrawableUnchecked, 0);
        swipeFrontView = styled.getResourceId(R.styleable.SwipeListView_swipeFrontView, 0);
        swipeBackView = styled.getResourceId(R.styleable.SwipeListView_swipeBackView, 0);
        styled.recycle();
    }

    if (swipeFrontView == 0 || swipeBackView == 0) {
        swipeFrontView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_FRONT_VIEW, "id",
                getContext().getPackageName());
        swipeBackView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_BACK_VIEW, "id",
                getContext().getPackageName());

        if (swipeFrontView == 0 || swipeBackView == 0) {
            throw new RuntimeException(String.format(
                    "You forgot the attributes swipeFrontView or swipeBackView. You can add this attributes or use '%s' and '%s' identifiers",
                    SWIPE_DEFAULT_FRONT_VIEW, SWIPE_DEFAULT_BACK_VIEW));
        }
    }

    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    touchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);//?
    touchListener = new SwipeListViewTouchListener(this, swipeFrontView, swipeBackView);
    if (swipeAnimationTime > 0) {
        touchListener.setAnimationTime(swipeAnimationTime);
    }
    touchListener.setRightOffset(swipeOffsetRight);
    touchListener.setLeftOffset(swipeOffsetLeft);
    touchListener.setSwipeActionLeft(swipeActionLeft);
    touchListener.setSwipeActionRight(swipeActionRight);
    touchListener.setSwipeMode(swipeMode);
    touchListener.setSwipeClosesAllItemsWhenListMoves(swipeCloseAllItemsWhenMoveList);
    touchListener.setSwipeOpenOnLongPress(swipeOpenOnLongPress);
    touchListener.setSwipeDrawableChecked(swipeDrawableChecked);
    touchListener.setSwipeDrawableUnchecked(swipeDrawableUnchecked);
    setOnTouchListener(touchListener);
    setOnScrollListener(touchListener.makeScrollListener());
}

From source file:PagerSlidingTab.java

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

    setFillViewport(true);/*from w ww .  j a  va 2 s.c o m*/
    setWillNotDraw(false);

    tabsContainer = new LinearLayout(context);
    tabsContainer.setOrientation(LinearLayout.HORIZONTAL);
    tabsContainer.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    addView(tabsContainer);

    DisplayMetrics dm = getResources().getDisplayMetrics();

    scrollOffset = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, scrollOffset, dm);
    indicatorHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, indicatorHeight, dm);
    underlineHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, underlineHeight, dm);
    dividerPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerPadding, dm);
    tabPadding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabPadding, dm);
    dividerWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dividerWidth, dm);
    tabTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, tabTextSize, dm);

    // get system attrs (android:textSize and android:textColor)

    TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);

    tabTextSize = a.getDimensionPixelSize(0, tabTextSize);
    tabTextColor = a.getColor(0, tabTextColor);

    a.recycle();

    // get custom attrs

    a = context.obtainStyledAttributes(attrs, R.styleable.PagerSlidingTab);

    indicatorColor = a.getColor(R.styleable.PagerSlidingTab_indicatorColor, indicatorColor);
    underlineColor = a.getColor(R.styleable.PagerSlidingTab_underlineColor, underlineColor);
    dividerColor = a.getColor(R.styleable.PagerSlidingTab_dividerColor, dividerColor);
    indicatorHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTab_indicatorHeight, indicatorHeight);
    underlineHeight = a.getDimensionPixelSize(R.styleable.PagerSlidingTab_underlineHeight, underlineHeight);
    dividerPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTab_pst_dividerPadding, dividerPadding);
    tabPadding = a.getDimensionPixelSize(R.styleable.PagerSlidingTab_tabPaddingLeftRight, tabPadding);
    tabBackgroundResId = a.getResourceId(R.styleable.PagerSlidingTab_tabBackground, tabBackgroundResId);
    shouldExpand = a.getBoolean(R.styleable.PagerSlidingTab_shouldExpand, shouldExpand);
    scrollOffset = a.getDimensionPixelSize(R.styleable.PagerSlidingTab_scrollOffset, scrollOffset);
    textAllCaps = a.getBoolean(R.styleable.PagerSlidingTab_pst_textAllCaps, textAllCaps);

    a.recycle();

    rectPaint = new Paint();
    rectPaint.setAntiAlias(true);
    rectPaint.setStyle(Style.FILL);

    dividerPaint = new Paint();
    dividerPaint.setAntiAlias(true);
    dividerPaint.setStrokeWidth(dividerWidth);

    defaultTabLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.MATCH_PARENT);
    expandedTabLayoutParams = new LinearLayout.LayoutParams(0, LayoutParams.MATCH_PARENT, 1.0f);

    if (locale == null) {
        locale = getResources().getConfiguration().locale;
    }
}

From source file:com.discord.chipsview.ChipsView.java

private void initAttr(Context context, AttributeSet attrs) {
    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ChipsView, 0, 0);

    try {/*from  w  w  w  .j av a 2  s.co m*/
        mMaxHeight = a.getDimensionPixelSize(R.styleable.ChipsView_cv_max_height, DEFAULT_MAX_HEIGHT);

        mVerticalSpacing = a.getDimensionPixelSize(R.styleable.ChipsView_cv_vertical_spacing,
                (int) (DEFAULT_VERTICAL_SPACING * mDensity));

        mChipsColor = a.getColor(R.styleable.ChipsView_cv_color,
                ContextCompat.getColor(context, android.R.color.darker_gray));

        mChipsColorClicked = a.getColor(R.styleable.ChipsView_cv_color_clicked,
                ContextCompat.getColor(context, android.R.color.white));

        mChipsBgColor = a.getColor(R.styleable.ChipsView_cv_bg_color,
                ContextCompat.getColor(context, android.R.color.white));

        mChipsBgColorClicked = a.getColor(R.styleable.ChipsView_cv_bg_color_clicked,
                ContextCompat.getColor(context, android.R.color.holo_blue_dark));

        mChipsTextColor = a.getColor(R.styleable.ChipsView_cv_text_color, Color.BLACK);

        mChipsTextColorClicked = a.getColor(R.styleable.ChipsView_cv_text_color_clicked, Color.WHITE);

        mChipsPlaceholderResId = a.getResourceId(R.styleable.ChipsView_cv_icon_placeholder, 0);

        mChipsDeleteResId = a.getResourceId(R.styleable.ChipsView_cv_icon_delete,
                R.drawable.drawable_chip_delete);

        mChipsSearchTextColor = a.getColor(R.styleable.ChipsView_cv_search_text_color, Color.BLACK);

        mChipsSearchTextSize = a.getDimensionPixelSize(R.styleable.ChipsView_cv_search_text_size, 49);

        mChipLayout = a.getResourceId(R.styleable.ChipsView_cv_chip_layout, R.layout.view_chip_default);

    } finally {
        a.recycle();
    }
}