Example usage for android.content.res Resources getColor

List of usage examples for android.content.res Resources getColor

Introduction

In this page you can find the example usage for android.content.res Resources getColor.

Prototype

@ColorInt
@Deprecated
public int getColor(@ColorRes int id) throws NotFoundException 

Source Link

Document

Returns a color integer associated with a particular resource ID.

Usage

From source file:com.example.expand.test.testfeature.view.SwipeRefreshLayout.java

/**
 * Set the four colors used in the progress animation. The first color will
 * also be the color of the bar that grows in response to a user swipe
 * gesture./*from w  w  w  .ja va 2  s  .  c o  m*/
 *
 * @param colorRes1 Color resource.
 * @param colorRes2 Color resource.
 * @param colorRes3 Color resource.
 * @param colorRes4 Color resource.
 */
public void setColorScheme(int colorRes1, int colorRes2, int colorRes3, int colorRes4) {
    ensureTarget();
    final Resources res = getResources();
    final int color1 = res.getColor(colorRes1);
    final int color2 = res.getColor(colorRes2);
    final int color3 = res.getColor(colorRes3);
    final int color4 = res.getColor(colorRes4);
    //        mProgressBar.setColorScheme(color1, color2, color3,color4);
}

From source file:com.google.android.apps.gutenberg.ScannerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_scanner);
    // Resources//from ww w  . j  ava2 s  .  c  o m
    final Resources resources = getResources();
    mColorTabSelected = resources.getColor(R.color.tab_selected);
    mColorTabUnselected = resources.getColor(R.color.tab_unselected);
    mColorTabIndicator = resources.getColor(R.color.primary_dark);
    mToolbarElevation = resources.getDimensionPixelSize(R.dimen.toolbar_elevation);
    GutenbergApplication app = GutenbergApplication.from(this);
    mImageLoader = new ImageLoader(app.getRequestQueue(), app.getBitmapCache());
    // Set up the Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    // Set up the Fragments
    if (savedInstanceState == null) {
        getSupportFragmentManager().beginTransaction().replace(R.id.scanner, ScannerFragment.newInstance())
                .replace(R.id.event_selector, EventSelectionFragment.newInstance()).commit();
    }
    // Set up the ViewPager
    mPanelLayout = (RecyclerViewSlidingUpPanelLayout) findViewById(R.id.layout);
    mTabLayout = (TabLayout) findViewById(R.id.tabs);
    mTabLayout.getViewTreeObserver().addOnGlobalLayoutListener(mTabLayoutListener);
    mViewPager = (DrawerViewPager) findViewById(R.id.pager);
    mAdapter = new ScannerPagerAdapter(getSupportFragmentManager(), this);
    mViewPager.setAdapter(mAdapter);
    mTabLayout.addTabsFromPagerAdapter(mAdapter);
    int tabCount = mAdapter.getCount();
    mTabs = new AppCompatTextView[tabCount];
    LayoutInflater inflater = LayoutInflater.from(this);
    for (int i = 0; i < tabCount; i++) {
        mTabs[i] = (AppCompatTextView) inflater.inflate(R.layout.tab, mTabLayout, false);
        mTabs[i].setText(mAdapter.getPageTitle(i));
        mTabLayout.getTabAt(i).setCustomView(mTabs[i]);
    }
    mTabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
        @Override
        public void onTabSelected(TabLayout.Tab tab) {
            mViewPager.setCurrentItem(tab.getPosition(), true);
            mTabs[tab.getPosition()].setTextColor(mColorTabSelected);
        }

        @Override
        public void onTabUnselected(TabLayout.Tab tab) {
            mTabs[tab.getPosition()].setTextColor(mColorTabUnselected);
        }

        @Override
        public void onTabReselected(TabLayout.Tab tab) {
        }
    });
    mPanelLayout.setPanelSlideListener(mPanelSlideListener);
    mViewPager.setPageMargin((int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
            VIEW_PAGER_PAGE_MARGIN, resources.getDisplayMetrics()));
    mViewPager.setPageMarginDrawable(resources.getDrawable(R.drawable.page_margin));
    final ViewPager.OnPageChangeListener onPageChangeListener = mTabLayout.createOnPageChangeListener();
    mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            onPageChangeListener.onPageScrolled(position, positionOffset, positionOffsetPixels);
        }

        @Override
        public void onPageSelected(int position) {
            onPageChangeListener.onPageSelected(position);
            mPanelLayout.setRecyclerView(mAdapter.getItem(position).getRecyclerView());
        }
    });
    mAdapter.getItem(mViewPager.getCurrentItem())
            .setOnRecyclerViewReadyListener(new RecyclerViewFragment.OnRecyclerViewReadyListener() {
                @Override
                public void onRecyclerViewReady(RecyclerView rv) {
                    mPanelLayout.setRecyclerView(rv);
                }
            });
    mViewPager.setOnClickListenerWhenClosed(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED);
        }
    });
}

From source file:ca.zadrox.dota2esportticker.ui.MatchActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_matches);

    mViewPager = (ViewPager) findViewById(R.id.view_pager);

    mSwipeRefreshLayout = (MultiSwipeRefreshLayout) findViewById(R.id.swipe_refresh_layout);
    mSwipeRefreshLayout.setOnRefreshListener(this);
    mSwipeRefreshLayout.setCanChildScrollUpCallback(this);

    mMatchPagerAdapter = new MatchPagerAdapter(getFragmentManager());
    mViewPager.setAdapter(mMatchPagerAdapter);

    mSlidingTabLayout = (SlidingTabLayout) findViewById(R.id.sliding_tabs);
    mSlidingTabLayout.setCustomTabView(R.layout.tab_indicator, android.R.id.text1);

    Resources res = getResources();
    mSlidingTabLayout.setSelectedIndicatorColors(res.getColor(R.color.tab_selected_strip));
    mSlidingTabLayout.setDistributeEvenly(true);
    mSlidingTabLayout.setViewPager(mViewPager);

    if (mSlidingTabLayout != null) {
        mSlidingTabLayout.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override//w w  w .  j ava 2 s  . c  o m
            public void onPageScrolled(int i, float v, int i2) {

            }

            @Override
            public void onPageSelected(int i) {
                for (MatchListFragment fragment : mMatchListFragments) {

                    if (fragment.getArguments().getInt(MatchListFragment.ARG_LIST_POSITION) == i) {
                        if (mCurrentListView != null) {
                            // why set an empty onscroll listener?
                            // enableactionbarautohide sets its own one, and we need to remove it.
                            mCurrentListView.setOnScrollListener(new AbsListView.OnScrollListener() {
                                @Override
                                public void onScrollStateChanged(AbsListView view, int scrollState) {

                                }

                                @Override
                                public void onScroll(AbsListView view, int firstVisibleItem,
                                        int visibleItemCount, int totalItemCount) {

                                }
                            });
                        }
                        enableActionBarAutoHide(fragment.getListView());
                        mCurrentListView = fragment.getListView();
                    }

                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {
                enableDisableSwipeRefresh(state == ViewPager.SCROLL_STATE_IDLE);
            }
        });
    }

}

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

/**
 * Set the four colors used in the progress animation. The first color will
 * also be the color of the bar that grows in response to a user swipe
 * gesture./*from   w w  w.  ja  v  a2s  . c o m*/
 *
 * @param colorRes1 Color resource.
 * @param colorRes2 Color resource.
 * @param colorRes3 Color resource.
 * @param colorRes4 Color resource.
 */
public void setColorScheme(int colorRes1, int colorRes2, int colorRes3, int colorRes4) {
    ensureTarget();
    final Resources res = getResources();
    final int color1 = res.getColor(colorRes1);
    final int color2 = res.getColor(colorRes2);
    final int color3 = res.getColor(colorRes3);
    final int color4 = res.getColor(colorRes4);
    mProgressBar.setColorScheme(color1, color2, color3, color4);
}

From source file:com.moblin.cellcomsms.utils.CirclePageIndicator.java

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

    // Load defaults from resources
    final Resources res = getResources();
    final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
    final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
    final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
    final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
    final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
    final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);

    // Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CirclePageIndicator, defStyle,
            R.style.Widget_CirclePageIndicator);

    mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered);
    mOrientation = a.getInt(R.styleable.CirclePageIndicator_orientation, defaultOrientation);
    mPaintStroke = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaintStroke.setStyle(Style.FILL_AND_STROKE);
    mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke// w  w  w  .  j a v a 2  s.  c o m
            .setStrokeWidth(a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintFill = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaintFill.setStyle(Style.FILL);
    mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor));
    mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius);
    mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);

    a.recycle();
}

From source file:com.vadimbasco.carousel.CirclePageIndicator.java

public CirclePageIndicator(Context context, AttributeSet attrs) {
    super(context, attrs);
    if (isInEditMode())
        return;/*from   ww  w . j  a va2s .c  o m*/

    //Load defaults from resources
    final Resources res = getResources();
    final int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color);
    final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
    final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
    final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
    final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
    final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
    final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);

    mCentered = defaultCentered;
    mOrientation = defaultOrientation;
    mPaintPageFill.setStyle(Style.FILL);
    mPaintPageFill.setColor(defaultPageColor);
    mPaintStroke.setStyle(Style.STROKE);
    mPaintStroke.setColor(defaultStrokeColor);
    mPaintStroke.setStrokeWidth(defaultStrokeWidth);
    mPaintFill.setStyle(Style.FILL);
    mPaintFill.setColor(defaultFillColor);
    mRadius = defaultRadius;
    mSnap = defaultSnap;

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

From source file:com.lovebridge.library.view.viewpagerindicator.LinePageIndicator.java

public LinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;//  w  w w .j  a  va2 s  .  co  m
    final Resources res = getResources();
    // Load defaults from resources
    final int defaultSelectedColor = res.getColor(R.color.default_line_indicator_selected_color);
    final int defaultUnselectedColor = res.getColor(R.color.default_line_indicator_unselected_color);
    final float defaultLineWidth = res.getDimension(R.dimen.default_line_indicator_line_width);
    final float defaultGapWidth = res.getDimension(R.dimen.default_line_indicator_gap_width);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_line_indicator_stroke_width);
    final boolean defaultCentered = res.getBoolean(R.bool.default_line_indicator_centered);
    // Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.LinePageIndicator, defStyle, 0);
    mCentered = a.getBoolean(R.styleable.LinePageIndicator_centered, defaultCentered);
    mLineWidth = a.getDimension(R.styleable.LinePageIndicator_lineWidth, defaultLineWidth);
    mGapWidth = a.getDimension(R.styleable.LinePageIndicator_gapWidth, defaultGapWidth);
    setStrokeWidth(a.getDimension(R.styleable.LinePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintUnselected
            .setColor(a.getColor(R.styleable.LinePageIndicator_unselectedColor, defaultUnselectedColor));
    mPaintSelected.setColor(a.getColor(R.styleable.LinePageIndicator_selectedColor, defaultSelectedColor));
    Drawable background = a.getDrawable(R.styleable.LinePageIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }
    a.recycle();
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}

From source file:com.goliathonline.android.kegbot.ui.tablet.TracksDropdownFragment.java

public void loadTrack(Cursor cursor, boolean loadTargetFragment) {
    final String trackId;
    final int trackColor;
    final Resources res = getResources();

    if (cursor != null) {
        trackId = cursor.getString(TracksAdapter.TracksQuery.KEG_ID);

        mTitle.setText(cursor.getString(TracksAdapter.TracksQuery.KEG_NAME));

    } else {//w  ww .  java2  s .  c o  m
        trackColor = res.getColor(R.color.all_track_color);
        trackId = KegbotContract.Kegs.ALL_KEG_ID;

        mTitle.setText(NEXT_TYPE_SESSIONS.equals(mNextType) ? R.string.all_sessions_title
                : R.string.all_sandbox_title);
        mAbstract.setText(NEXT_TYPE_SESSIONS.equals(mNextType) ? R.string.all_sessions_subtitle
                : R.string.all_sandbox_subtitle);
    }

    //if (isDark) {
    //    mTitle.setTextColor(res.getColor(R.color.body_text_1_inverse));
    //    mAbstract.setTextColor(res.getColor(R.color.body_text_2_inverse));
    //    mRootView.findViewById(R.id.track_dropdown_arrow).setBackgroundResource(
    //            R.drawable.track_dropdown_arrow_light);
    //} else {
    mTitle.setTextColor(res.getColor(R.color.body_text_1));
    mAbstract.setTextColor(res.getColor(R.color.body_text_2));
    mRootView.findViewById(R.id.track_dropdown_arrow)
            .setBackgroundResource(R.drawable.track_dropdown_arrow_dark);
    //}

    if (loadTargetFragment) {
        final Intent intent = new Intent(Intent.ACTION_VIEW);
        final Uri trackUri = KegbotContract.Kegs.buildKegUri(trackId);
        intent.putExtra(DrinkDetailFragment.EXTRA_TRACK, trackUri);

        if (NEXT_TYPE_SESSIONS.equals(mNextType)) {
            if (cursor == null) {
                intent.setData(KegbotContract.Drinks.CONTENT_URI);
            } else {
                intent.setData(KegbotContract.Kegs.buildDrinksUri(trackId));
            }
        } else if (NEXT_TYPE_VENDORS.equals(mNextType)) {
            if (cursor == null) {
                intent.setData(KegbotContract.Users.CONTENT_URI);
            } else {
                intent.setData(KegbotContract.Kegs.buildKegUri(trackId));
            }
        }

        ((BaseActivity) getActivity()).openActivityOrFragment(intent);
    }
}

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

/**
 * Set the four colors used in the progress animation. The first color will
 * also be the color of the bar that grows in response to a user swipe
 * gesture./* w  w w.ja v a  2  s.  c o  m*/
 *
 * @param colorRes1 Color resource.
 * @param colorRes2 Color resource.
 * @param colorRes3 Color resource.
 * @param colorRes4 Color resource.
 */
public void setColorSchemeRes(int colorRes1, int colorRes2, int colorRes3, int colorRes4) {
    ensureTarget();
    final Resources res = getResources();
    final int color1 = res.getColor(colorRes1);
    final int color2 = res.getColor(colorRes2);
    final int color3 = res.getColor(colorRes3);
    final int color4 = res.getColor(colorRes4);
    mProgressBar.setColorScheme(color1, color2, color3, color4);
}

From source file:com.threehalf.tucao.view.pageindicator.TabPageIndicator.java

public TabPageIndicator(Context context, AttributeSet attrs) {
    super(context, attrs);

    final Resources res = getResources();
    // final int textColor =
    // res.getres(R.color.default_tab_indicator_text_color);
    final int tabSelectedColor = res.getColor(R.color.default_tab_indicator_selected_color);
    final int tabUnSelectedColor = res.getColor(R.color.default_tab_indicator_unselected_color);
    final float textSize = res.getDimension(R.dimen.default_tab_indicator_textsize);
    final float paddingLeft = res.getDimension(R.dimen.default_tab_indicator_paddingleft);
    final float paddingRight = res.getDimension(R.dimen.default_tab_indicator_paddingright);
    final float paddingTop = res.getDimension(R.dimen.default_tab_indicator_paddingtop);
    final float paddingBottom = res.getDimension(R.dimen.default_tab_indicator_paddingbottom);
    final float tabSelectedHeight = res.getDimension(R.dimen.default_tab_indicator_selected_height);
    final float tabUnSelectedHeight = res.getDimension(R.dimen.default_tab_indicator_unselected_height);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TabPageIndicator);
    mTextColor = a.getResourceId(R.styleable.TabPageIndicator_textColor, R.drawable.selector_tabtextcolor);
    mTabSelectedColor = a.getColor(R.styleable.TabPageIndicator_selectedColor, tabSelectedColor);
    mTabUnSelectedColor = a.getColor(R.styleable.TabPageIndicator_unselectedColor, tabUnSelectedColor);
    mTextSize = a.getDimension(R.styleable.TabPageIndicator_textSize, textSize);
    mPaddingLeft = a.getDimension(R.styleable.TabPageIndicator_paddingLeft, paddingLeft);
    mPaddingRight = a.getDimension(R.styleable.TabPageIndicator_paddingRight, paddingRight);
    mPaddingTop = a.getDimension(R.styleable.TabPageIndicator_paddingTop, paddingTop);
    mPaddingBottom = a.getDimension(R.styleable.TabPageIndicator_paddingBottom, paddingBottom);
    mTabSelectedHeight = a.getDimension(R.styleable.TabPageIndicator_selectedHeight, tabSelectedHeight);
    mTabUnSelectedHeight = a.getDimension(R.styleable.TabPageIndicator_unSelectedHeight, tabUnSelectedHeight);

    setHorizontalScrollBarEnabled(false);

    mTabAndIndicator = new LinearLayout(context);
    mTabAndIndicator.setOrientation(LinearLayout.VERTICAL);
    mTabLayout = new LinearLayout(context);
    mTabAndIndicator.addView(mTabLayout, new LinearLayout.LayoutParams(WRAP_CONTENT, 0, 1));
    mSlideLineIndicator = new SlideLineIndicator(context);
    mTabAndIndicator.addView(mSlideLineIndicator,
            new LinearLayout.LayoutParams(MATCH_PARENT, (int) mTabSelectedHeight, 0));
    addView(mTabAndIndicator, new ViewGroup.LayoutParams(WRAP_CONTENT, MATCH_PARENT));

    a.recycle();/*  ww  w.j  a va 2s .c om*/
}