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.android.gallery3d.v5.filtershow.category.CategoryView.java

public CategoryView(Context context) {
    super(context);
    setOnClickListener(this);
    Resources res = getResources();
    mSelectionStroke = res.getDimensionPixelSize(R.dimen.thumbnail_margin);
    mSelectPaint = new Paint();
    mSelectPaint.setStyle(Paint.Style.FILL);
    mSelectionColor = res.getColor(R.color.filtershow_category_selection);
    mSpacerColor = res.getColor(R.color.filtershow_categoryview_text);

    mSelectPaint.setColor(mSelectionColor);
    mBorderPaint = new Paint(mSelectPaint);
    mBorderPaint.setColor(Color.BLACK);
    mBorderStroke = mSelectionStroke / 2;
}

From source file:com.chn.halo.view.progressbar.MaterialProgressBar.java

public void setBackgroundColor(int colorRes) {
    if (getBackground() instanceof ShapeDrawable) {
        final Resources res = getResources();
        ((ShapeDrawable) getBackground()).getPaint().setColor(res.getColor(colorRes));
    }/*from   www.  j a  v  a2 s  . c  o  m*/
}

From source file:com.github.suzukaze.yarulistfortodoly.fragment.ToDoFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.todo, container, false);
    ButterKnife.bind(this, view);

    final MainActivity mainActivity = (MainActivity) getActivity();
    todoViewModel = new TodoViewModel(accountManager, dataManager, historyManager);
    todoViewModel.setOnSyncFinishListener(this);
    Toolbar toolbar = mainActivity.getToolbar();
    toolbar.setTitle(getResources().getString(R.string.yarulist));
    mainActivity.showToolbar();//from w w  w  .j  av a2s. c  o  m

    if (dataManager.getProjects().size() > 0) {
        currentProject = dataManager.getProjects().get(0);
    }

    syncLayout = mainActivity.getSyncLayout();
    final LinearLayout finalSyncLayout = syncLayout;
    finalSyncLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (underCommunication)
                return;
            finalSyncLayout.setVisibility(View.INVISIBLE);
            todoViewModel.sync();
        }
    });

    final ToDoFragment toDoFragment = this;

    LinearLayout addProject = mainActivity.getAddProjectLayout();
    addProject.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ProjectViewModel projectViewModel = new ProjectViewModel(dataManager, historyManager);
            projectViewModel.setProjectId(Project.PROJECT_ID_NONE);
            projectView.init(projectViewModel, mainActivity.getInputMethodManager(), toDoFragment, mainActivity,
                    currentProject, ProjectMode.ADD_PROJECT, accountManager, compositeSubscription);
            projectView.show();
        }
    });

    LinearLayout editProjectLayout = mainActivity.getEditProjectLayout();
    editProjectLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ProjectViewModel projectViewModel = new ProjectViewModel(dataManager, historyManager);
            projectViewModel.setProjectId(currentProject.getId());
            projectView.init(projectViewModel, mainActivity.getInputMethodManager(), toDoFragment, mainActivity,
                    currentProject, ProjectMode.UPDATE_PROJECT, accountManager, compositeSubscription);
            projectView.show();
        }
    });

    mainActivity.setEditItemView(editItemView);
    mainActivity.setProjectView(null);

    Resources r = getResources();
    tabs.setTextColor(r.getColor(R.color.white));
    tabs.setTextSize(TypedValue.COMPLEX_UNIT_DIP, TABS_TEXT_SIZE);
    tabs.setTabIndicatorColor(r.getColor(R.color.white));

    dataManager = mainActivity.getDataManager();

    dataManager.clear();
    dataManager.load();
    if (sync) {
        todoViewModel.sync();
    } else {
        changeTabs();
    }

    return view;
}

From source file:com.webarch.srmobile.activities.sub.views.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}./*from w  ww  . j a va2  s .  c  om*/
 */
protected TextView createDefaultTabView(Context context) {
    Text text = new Text(context, null);
    text.setGravity(Gravity.CENTER);
    Resources resources = getResources();
    text.setTextSize(TypedValue.COMPLEX_UNIT_PX, resources.getDimension(R.dimen.text_2));
    text.setTextColor(resources.getColor(R.color.dark));
    int border1 = (int) resources.getDimension(R.dimen.border_1),
            border2 = (int) resources.getDimension(R.dimen.border_2);
    text.setPadding(border1, border2, border1, border2);
    return text;
}

From source file:com.echo.holographlibrarysample.BarFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View v = inflater.inflate(R.layout.fragment_bargraph, container, false);
    final Resources resources = getResources();
    ArrayList<Bar> aBars = new ArrayList<Bar>();
    Bar bar = new Bar();
    bar.setColor(resources.getColor(R.color.green_light));
    bar.setSelectedColor(resources.getColor(R.color.transparent_orange));
    bar.setName("Test1");
    bar.setValue(1000);/*from w w  w.  ja  v  a2 s  .c o  m*/
    bar.setValueString("$1,000");
    aBars.add(bar);
    bar = new Bar();
    bar.setColor(resources.getColor(R.color.orange));
    bar.setName("Test2");
    bar.setValue(2000);
    bar.setValueString("$2,000");
    aBars.add(bar);
    bar = new Bar();
    bar.setColor(resources.getColor(R.color.purple));
    bar.setName("Test3");
    bar.setValue(1500);
    bar.setValueString("$1,500");
    aBars.add(bar);

    final BarGraph barGraph = (BarGraph) v.findViewById(R.id.bargraph);
    bg = barGraph;
    barGraph.setBars(aBars);

    barGraph.setOnBarClickedListener(new OnBarClickedListener() {

        @Override
        public void onClick(int index) {
            Toast.makeText(getActivity(),
                    "Bar " + index + " clicked " + String.valueOf(barGraph.getBars().get(index).getValue()),
                    Toast.LENGTH_SHORT).show();
        }
    });
    Button animateBarButton = (Button) v.findViewById(R.id.animateBarButton);
    Button animateInsertBarButton = (Button) v.findViewById(R.id.animateInsertBarButton);
    Button animateDelteBarButton = (Button) v.findViewById(R.id.animateDeleteBarButton);

    //animate to random values
    animateBarButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            for (Bar b : barGraph.getBars()) {
                b.setGoalValue((float) Math.random() * 1000);
                b.setValuePrefix("$");//display the prefix throughout the animation
                Log.d("goal val", String.valueOf(b.getGoalValue()));
            }
            barGraph.setDuration(1200);//default if unspecified is 300 ms
            barGraph.setInterpolator(new AccelerateDecelerateInterpolator());//Only use over/undershoot  when not inserting/deleting
            barGraph.setAnimationListener(getAnimationListener());
            barGraph.animateToGoalValues();

        }
    });

    //insert a bar
    animateInsertBarButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            barGraph.cancelAnimating(); //must clear existing to call onAnimationEndListener cleanup BEFORE adding new bars
            int newPosition = barGraph.getBars().size() == 0 ? 0
                    : new Random().nextInt(barGraph.getBars().size());
            Bar bar = new Bar();
            bar.setColor(Color.parseColor("#AA0000FF"));
            bar.setName("Insert bar " + String.valueOf(barGraph.getBars().size()));
            bar.setValue(0);
            bar.mAnimateSpecial = HoloGraphAnimate.ANIMATE_INSERT;
            barGraph.getBars().add(newPosition, bar);
            for (Bar b : barGraph.getBars()) {
                b.setGoalValue((float) Math.random() * 1000);
                b.setValuePrefix("$");//display the prefix throughout the animation
                Log.d("goal val", String.valueOf(b.getGoalValue()));
            }
            barGraph.setDuration(1200);//default if unspecified is 300 ms
            barGraph.setInterpolator(new AccelerateDecelerateInterpolator());//Don't use over/undershoot interpolator for insert/delete
            barGraph.setAnimationListener(getAnimationListener());
            barGraph.animateToGoalValues();

        }
    });

    //delete a bar
    animateDelteBarButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            barGraph.cancelAnimating(); //must clear existing to call onAnimationEndListener cleanup BEFORE adding new bars
            if (barGraph.getBars().size() == 0)
                return;

            for (Bar b : barGraph.getBars()) {
                b.setGoalValue((float) Math.random() * 1000);
                b.setValuePrefix("$");//display the prefix throughout the animation
                Log.d("goal val", String.valueOf(b.getGoalValue()));
            }
            int newPosition = new Random().nextInt(barGraph.getBars().size());
            Bar bar = barGraph.getBars().get(newPosition);
            bar.mAnimateSpecial = HoloGraphAnimate.ANIMATE_DELETE;
            bar.setGoalValue(0);//animate to 0 then delete
            barGraph.setDuration(1200);//default if unspecified is 300 ms
            barGraph.setInterpolator(new AccelerateInterpolator());//Don't use over/undershoot interpolator for insert/delete
            barGraph.setAnimationListener(getAnimationListener());
            barGraph.animateToGoalValues();

        }
    });
    return v;
}

From source file:com.jakewharton.android.viewpagerindicator.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 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);
    mPaintStroke = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaintStroke.setStyle(Style.STROKE);
    mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke/*w w w  .  j  a va 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.hxsn.witwork.ui.ViewfinderView.java

public ViewfinderView(Context context, AttributeSet attrs) {
    super(context, attrs);
    con = context;/*from  w ww.j  ava  2 s  .c  o m*/
    name = new ArrayList<String>();
    density = context.getResources().getDisplayMetrics().density;
    // ???dp
    ScreenRate = (int) (20 * density);

    paint = new Paint();
    Resources resources = getResources();
    maskColor = resources.getColor(R.color.viewfinder_mask);
    resultColor = resources.getColor(R.color.result_view);

    resultPointColor = resources.getColor(R.color.possible_result_points);
    possibleResultPoints = new HashSet<ResultPoint>(5);
}

From source file:com.balch.mocktrade.TradeApplication.java

@Override
public void configureActivity(TemplateActivity activity, NavBar navBar, Bundle savedInstanceState) {
    activity.showProgress();//w w w  . j a v a2 s.  c  o m
    this.activity = activity;

    Resources resources = activity.getResources();

    activity.setBackground(resources.getDrawable(R.drawable.main_bmp_rpt));

    navBar.setBackground(resources.getDrawable(R.drawable.navbar_bkg));

    navBar.configure(resources.getColor(R.color.nav_on_color), resources.getColor(R.color.nav_off_color));

    Fragment mainFragment = new PortfolioFragment();
    this.buttonMap.put(navBar.addButton(R.string.nav_money_center, R.drawable.ic_nav_money_center),
            mainFragment);
    this.buttonMap.put(navBar.addButton(R.string.nav_research, R.drawable.ic_nav_research),
            new YourContentHereFragment().setCustomArguments("http://www.cnbc.com/"));
    this.buttonMap.put(navBar.addButton(R.string.nav_ideas, R.drawable.ic_nav_ideas),
            new YourContentHereFragment()
                    .setCustomArguments("http://wallstcheatsheet.com/category/investing/"));
    this.buttonMap.put(navBar.addButton(R.string.nav_settings, R.drawable.ic_nav_settings),
            new SettingsFragment());

    navBar.setOnNavClickListener(new NavBar.OnNavClickListener() {
        @Override
        public void onClick(NavButton button) {
            Fragment fragment = TradeApplication.this.buttonMap.get(button);
            if (fragment != null) {
                TradeApplication.this.activity.showView(fragment);
            }
        }
    });

    if (savedInstanceState == null) {
        this.activity.showView(mainFragment);
    }

    // not sure if we need this here for the first time the app launches
    FinanceModel financeModel = this.getModelFactory().getModel(FinanceModel.class);
    financeModel.setQuoteServiceAlarm();
}

From source file:com.github.piasy.chatrecyclerview.example.InputDialog.java

@Override
public void onStart() {
    super.onStart();
    // without title and title divider

    // Less dimmed background; see http://stackoverflow.com/q/13822842/56285
    Window window = getDialog().getWindow();
    WindowManager.LayoutParams params = window.getAttributes();
    //CHECKSTYLE:OFF
    params.dimAmount = 0;/*from  w  w w .j  a v  a  2  s .  co  m*/
    //CHECKSTYLE:ON
    window.setAttributes(params);

    window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    window.setGravity(Gravity.BOTTOM);

    // Transparent background; see http://stackoverflow.com/q/15007272/56285
    // (Needed to make dialog's alpha shadow look good)
    window.setBackgroundDrawableResource(android.R.color.transparent);

    final Resources res = getResources();
    final int titleDividerId = res.getIdentifier("titleDivider", "id", "android");
    if (titleDividerId > 0) {
        final View titleDivider = getDialog().findViewById(titleDividerId);
        if (titleDivider != null) {
            titleDivider.setBackgroundColor(res.getColor(android.R.color.transparent));
        }
    }
}

From source file:com.github.refreshloadlayout.ProgressView.java

/**
 * Update the background color of the mBgCircle image view.
 *///from ww w . jav a  2s.c om
public void setBackgroundColorResource(int colorRes) {
    if (getBackground() instanceof ShapeDrawable) {
        final Resources res = getResources();
        ((ShapeDrawable) getBackground()).getPaint().setColor(res.getColor(colorRes));
    }
}