Example usage for android.graphics Color rgb

List of usage examples for android.graphics Color rgb

Introduction

In this page you can find the example usage for android.graphics Color rgb.

Prototype

@ColorInt
public static int rgb(float red, float green, float blue) 

Source Link

Document

Return a color-int from red, green, blue float components in the range \([0..1]\).

Usage

From source file:java_lang_programming.com.android_media_demo.article80.ImageFragment.java

/**
 * Bitmap??//from   w w  w . j  a v  a 2s . co  m
 * ??
 * grayscale using Bitmap
 * SimpleMeanMethod
 */
private void grayScaleSimpleMeanMethod() {
    long start = System.currentTimeMillis();
    Bitmap mutableBitmap = getMutableBitmap();

    int width = mutableBitmap.getWidth();
    int height = mutableBitmap.getHeight();
    for (int i = 0; i < width; i++) {
        for (int j = 0; j < height; j++) {

            // Returns the Color at the specified location.
            int pixel = mutableBitmap.getPixel(i, j);

            int red = Color.red(pixel);
            int green = Color.green(pixel);
            int blue = Color.blue(pixel);

            int average = (red + green + blue) / 3;
            int gray_rgb = Color.rgb(average, average, average);

            mutableBitmap.setPixel(i, j, gray_rgb);
        }
    }
    imageView.setImageBitmap(mutableBitmap);
    long end = System.currentTimeMillis();
    Log.d(TAG, ((end - start) + "ms"));
}

From source file:com.bangqu.eshow.view.sliding.ESSlidingTabView.java

/**
 * Inits the view.//from  w w w  .j a v  a  2  s.  com
 */
public void initView() {
    this.setOrientation(LinearLayout.VERTICAL);
    this.setBackgroundColor(Color.rgb(255, 255, 255));

    mTabScrollView = new HorizontalScrollView(context);
    mTabScrollView.setHorizontalScrollBarEnabled(false);
    mTabScrollView.setSmoothScrollingEnabled(true);

    mTabLayout = new LinearLayout(context);
    mTabLayout.setOrientation(LinearLayout.HORIZONTAL);
    mTabLayout.setGravity(Gravity.CENTER);

    //mTabLayout
    mTabScrollView.addView(mTabLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    this.addView(mTabScrollView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    //View?
    mViewPager = new ESViewPager(context);
    //ViewPager,setId()id
    mViewPager.setId(1985);
    pagerItemList = new ArrayList<Fragment>();
    //Tab?
    tabItemList = new ArrayList<TextView>();
    tabItemTextList = new ArrayList<String>();
    tabItemDrawableList = new ArrayList<Drawable>();

    //?FragmentActivity
    if (!(this.context instanceof FragmentActivity)) {
        ESLogUtil.e(ESSlidingTabView.class,
                "AbSlidingTabView?context,FragmentActivity");
    }
}

From source file:cn.org.eshow.framwork.view.sliding.AbSlidingTabView.java

/**
 * Inits the view.// ww w  . ja  v a 2  s  . c o  m
 */
public void initView() {
    this.setOrientation(LinearLayout.VERTICAL);
    this.setBackgroundColor(Color.rgb(255, 255, 255));

    mTabScrollView = new HorizontalScrollView(context);
    mTabScrollView.setHorizontalScrollBarEnabled(false);
    mTabScrollView.setSmoothScrollingEnabled(true);

    mTabLayout = new LinearLayout(context);
    mTabLayout.setOrientation(LinearLayout.HORIZONTAL);
    mTabLayout.setGravity(Gravity.CENTER);

    //mTabLayout
    mTabScrollView.addView(mTabLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    this.addView(mTabScrollView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    //View?
    mViewPager = new AbViewPager(context);
    //ViewPager,setId()id
    mViewPager.setId(1985);
    pagerItemList = new ArrayList<Fragment>();
    //Tab?
    tabItemList = new ArrayList<TextView>();
    tabItemTextList = new ArrayList<String>();
    tabItemDrawableList = new ArrayList<Drawable>();

    //?FragmentActivity
    if (!(this.context instanceof FragmentActivity)) {
        AbLogUtil.e(AbSlidingTabView.class,
                "AbSlidingTabView?context,FragmentActivity");
    }
}

From source file:project.pamela.slambench.fragments.DurationPlot.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    // Replace LinearLayout by the type of the root element of the layout you're trying to load
    LinearLayout llLayout = (LinearLayout) inflater.inflate(R.layout.fragment_plot, container, false);

    // Retrieve bench number
    Intent mIntent = super.getActivity().getIntent();
    final int intValue = mIntent.getIntExtra(ResultActivity.SELECTED_TEST_TAG, 0);
    SLAMResult value = SLAMBenchApplication.getResults().get(intValue);

    if (!value.isFinished()) {
        Log.e(SLAMBenchApplication.LOG_TAG,
                this.getResources().getString(R.string.debug_proposed_value_not_valid));
        return llLayout;
    }//from w  ww. j  a  va2s .c om

    // initialize our XYPlot reference:
    XYPlot plot = (XYPlot) llLayout.findViewById(R.id.mySimpleXYPlot);

    plot.setTitle(value.test.name);
    plot.setDomainLabel(this.getResources().getString(R.string.legend_frame_number));
    plot.setRangeLabel(this.getResources().getString(R.string.legend_duration));
    plot.setBackgroundColor(Color.WHITE);
    plot.getGraphWidget().getBackgroundPaint().setColor(Color.WHITE);
    plot.getGraphWidget().getGridBackgroundPaint().setColor(Color.WHITE);

    plot.getGraphWidget().getDomainLabelPaint().setColor(Color.BLACK);
    plot.getGraphWidget().getRangeLabelPaint().setColor(Color.BLACK);

    plot.getGraphWidget().getDomainOriginLabelPaint().setColor(Color.BLACK);
    plot.getGraphWidget().getDomainOriginLinePaint().setColor(Color.BLACK);
    plot.getGraphWidget().getRangeOriginLinePaint().setColor(Color.BLACK);

    plot.getGraphWidget().setRangeValueFormat(new DecimalFormat("#####.##"));

    int border = 60;
    int legendsize = 110;

    plot.getGraphWidget().position(border, XLayoutStyle.ABSOLUTE_FROM_LEFT, border,
            YLayoutStyle.ABSOLUTE_FROM_BOTTOM, AnchorPosition.LEFT_BOTTOM);
    plot.getGraphWidget()
            .setSize(new SizeMetrics(border + legendsize, SizeLayoutType.FILL, border, SizeLayoutType.FILL));

    // reduce the number of range labels
    plot.setDomainStep(XYStepMode.INCREMENT_BY_VAL, 10);
    plot.setDomainValueFormat(new DecimalFormat("#"));
    plot.setRangeStep(XYStepMode.SUBDIVIDE, 10);

    //Remove legend
    //plot.getLayoutManager().remove(plot.getLegendWidget());
    //plot.getLayoutManager().remove(plot.getDomainLabelWidget());
    //plot.getLayoutManager().remove(plot.getRangeLabelWidget());
    plot.getLayoutManager().remove(plot.getTitleWidget());

    // Set legend
    plot.getLegendWidget().setTableModel(new DynamicTableModel(4, 2));

    Paint bgPaint = new Paint();
    bgPaint.setColor(Color.BLACK);
    bgPaint.setStyle(Paint.Style.FILL);
    bgPaint.setAlpha(140);

    plot.getLegendWidget().setBackgroundPaint(bgPaint);

    plot.getLegendWidget()
            .setSize(new SizeMetrics(legendsize, SizeLayoutType.ABSOLUTE, 0, SizeLayoutType.FILL));

    plot.getLegendWidget().position(0, XLayoutStyle.ABSOLUTE_FROM_RIGHT, 0, YLayoutStyle.ABSOLUTE_FROM_TOP,
            AnchorPosition.RIGHT_TOP);

    plot.getDomainLabelWidget().position(0, XLayoutStyle.ABSOLUTE_FROM_CENTER, 0,
            YLayoutStyle.RELATIVE_TO_BOTTOM, AnchorPosition.BOTTOM_MIDDLE);

    // Prepare Data (fill stack and add lines)

    KFusion.FieldIndex[] stackIndex = new KFusion.FieldIndex[] { (KFusion.FieldIndex.AQUISITION_DURATION),
            (KFusion.FieldIndex.PREPROCESSING_DURATION), (KFusion.FieldIndex.TRACKING_DURATION),
            (KFusion.FieldIndex.INTEGRATION_DURATION), (KFusion.FieldIndex.RAYCASTING_DURATION),
            (KFusion.FieldIndex.RENDERING_DURATION), (KFusion.FieldIndex.TOTAL_DURATION) };

    Double[][] stackNumbers = new Double[][] { value.getField(stackIndex[0]), value.getField(stackIndex[1]),
            value.getField(stackIndex[2]), value.getField(stackIndex[3]), value.getField(stackIndex[4]),
            value.getField(stackIndex[5]) };

    Double[][] stack = new Double[stackNumbers.length + 1][stackNumbers[0].length];

    int[] stackColor = new int[] { Color.rgb(240, 0, 0), Color.rgb(255, 155, 0), Color.rgb(255, 255, 0),
            Color.rgb(155, 255, 98), Color.rgb(0, 212, 255), Color.rgb(0, 155, 255), Color.rgb(0, 0, 127) };

    stack[0] = stackNumbers[0];

    for (int i = 0; i < stackNumbers[0].length; ++i) {
        for (int j = 1; j < stackNumbers.length; ++j) {
            stack[j][i] = stack[j - 1][i] + stackNumbers[j][i];
        }
    }
    stack[stackNumbers.length] = value.getField(KFusion.FieldIndex.TOTAL_DURATION);

    for (int i = stack.length - 1; i >= 0; --i) {
        // Turn the above arrays into XYSeries':
        XYSeries series = new SimpleXYSeries(Arrays.asList(stack[i]), SimpleXYSeries.ArrayFormat.Y_VALS_ONLY,
                stackIndex[i].getName());

        LineAndPointFormatter seriesFormat = new LineAndPointFormatter(Color.rgb(73, 73, 73), null,
                stackColor[i], null);
        Paint paint = seriesFormat.getLinePaint();
        paint.setStrokeWidth(1.0f);
        seriesFormat.setLinePaint(paint);

        // setup our line fill paint to be a slightly transparent gradient:
        //Paint lineFill = new Paint();
        // lineFill.setAlpha(200);
        //lineFill.setShader(new LinearGradient(0, 0, 0, 250, Color.WHITE, stackColor[i], Shader.TileMode.MIRROR));
        //seriesFormat.setFillPaint(lineFill);

        plot.addSeries(series, seriesFormat);

    }

    // same as above
    LineAndPointFormatter lineFormat = new LineAndPointFormatter(Color.BLACK, null, null, null);
    //change the line width
    Paint paint = lineFormat.getLinePaint();
    paint.setStrokeWidth(5);
    lineFormat.setLinePaint(paint);

    Number[] line = { 0, 0.033, stack[0].length - 1, 0.033 };
    XYSeries expected = new SimpleXYSeries(Arrays.asList(line), SimpleXYSeries.ArrayFormat.XY_VALS_INTERLEAVED,
            getResources().getString(R.string.legend_realtime_limit));
    plot.addSeries(expected, lineFormat);

    plot.redraw();

    plot.calculateMinMaxVals();
    PointF maxXY = new PointF(plot.getCalculatedMaxX().floatValue(), plot.getCalculatedMaxY().floatValue());

    plot.setDomainBoundaries(0, value.test.dataset.getFrameCount() - 1, BoundaryMode.FIXED);
    plot.setRangeBoundaries(0, maxXY.y * 1.2f, BoundaryMode.FIXED);

    plot.redraw();

    return llLayout;
}

From source file:it.redturtle.mobile.apparpav.MeteogramAdapter.java

/**
 * DOUBLE TITLE ROW//ww  w.  j a  v  a2 s.  c  o m
 * @param att
 * @param linear
 * @return
 */
public LinearLayout getDoubleTitleRow(Map<String, String> att, LinearLayout linear) {
    LinearLayout container_layout = new LinearLayout(context);
    container_layout.setMinimumHeight(30);
    container_layout
            .setBackgroundDrawable(context.getResources().getDrawable(R.drawable.view_shape_meteo_blue));
    container_layout.setVerticalGravity(Gravity.CENTER);
    container_layout.setOrientation(LinearLayout.HORIZONTAL);

    LinearLayout.LayoutParams value_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.3f);
    TextView tx = new TextView(context);
    tx.setText("");
    tx.setTextColor(Color.rgb(66, 66, 66));
    container_layout.addView(tx, value_params);

    LinearLayout.LayoutParams ltext1 = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.35f);
    TextView t1 = new TextView(context);
    t1.setText(att.get("value1"));
    t1.setTextSize(11);
    t1.setGravity(Gravity.CENTER_HORIZONTAL);
    t1.setPadding(2, 0, 0, 2);
    t1.setTextColor(Color.rgb(255, 255, 255));
    container_layout.addView(t1, ltext1);

    LinearLayout.LayoutParams ltext2 = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.35f);
    TextView t2 = new TextView(context);
    t2.setText(att.get("value2"));
    t2.setTextSize(11);
    t2.setGravity(Gravity.CENTER_HORIZONTAL);
    t2.setPadding(2, 0, 0, 2);
    t2.setTextColor(Color.rgb(255, 255, 255));
    container_layout.addView(t2, ltext2);

    linear.addView(container_layout);
    return linear;
}

From source file:com.rowland.hashtrace.ui.fragments.subfragment.FavouriteListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // The CursorAdapter will take data from a source and use it to populate the ListView it's attached to.
    mTweetFavListAdapter = new TweetFavListAdapter(getActivity(), null, 0);
    creator = new SwipeMenuCreator() {

        @Override/* w  w  w . j  a  v a  2  s  . c  o  m*/
        public void create(SwipeMenu menu) {
            // create "share" item
            SwipeMenuItem shareItem = new SwipeMenuItem(getActivity().getApplicationContext());
            // set item background
            shareItem.setBackground(new ColorDrawable(Color.rgb(211, 214, 219)));
            // set item width
            shareItem.setWidth(Utility.convertDpToPixel(100, getResources().getDisplayMetrics()));
            // set icon resource
            shareItem.setIcon(R.drawable.selector_swipemenuitem_share);
            // set item title
            shareItem.setTitle("Share");
            // set item title fontsize
            shareItem.setTitleSize(18);
            // set item title font color
            shareItem.setTitleColor(Color.WHITE);
            // add to menu
            menu.addMenuItem(shareItem);

            // create "favour" item
            SwipeMenuItem favourItem = new SwipeMenuItem(getActivity().getApplicationContext());
            // set item background
            favourItem.setBackground(new ColorDrawable(Color.rgb(211, 214, 219)));
            // set item width
            favourItem.setWidth(Utility.convertDpToPixel(100, getResources().getDisplayMetrics()));
            // set icon resource
            favourItem.setIcon(R.drawable.selector_swipemenuitem_discard);
            // set item title
            favourItem.setTitle("Delete");
            // set item title fontsize
            favourItem.setTitleSize(18);
            // set item title font color
            favourItem.setTitleColor(Color.WHITE);
            // add to menu
            menu.addMenuItem(favourItem);
        }
    };

    View rootView = inflater.inflate(R.layout.fragment_tweetfav_list, container, false);

    mListView = (SwipeMenuListView) rootView.findViewById(android.R.id.list);
    mListView.setAdapter(mTweetFavListAdapter);
    mListView.setMenuCreator(creator);
    mListView.setOnItemLongClickListener(new OnItemLongClickListener() {

        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
            // Do the onItemLongClick action
            mListView.smoothOpenMenu(position);

            return true;
        }
    });
    mListView.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
            switch (index) {
            case 0:
                // Share
                shareTweet();
                break;
            case 1:
                // Favourite
                DeleteTweet();
                break;
            }
            // false : close the menu; true : not close the menu
            return false;
        }
    });
    mListView.setCloseInterpolator(new BounceInterpolator());

    // If there's instance state, mine it for useful information.
    // The end-goal here is that the user never knows that turning their
    // device sideways does crazy lifecycle related things. It should
    // feel like some stuff stretched out, or magically appeared to take
    // advantage of room, but data or place in the app was never actually *lost*.
    if (savedInstanceState != null && savedInstanceState.containsKey(SELECTED_KEY)) {
        // The listview probably hasn't even been populated yet. Actually
        // perform the
        // swapout in onLoadFinished.
        mPosition = savedInstanceState.getInt(SELECTED_KEY);
    }

    return rootView;
}

From source file:com.tony.selene.sliding.AbSlidingTabView.java

/**
 * Inits the view./* w  w w.java 2 s  .  co m*/
 */
public void initView() {
    this.setOrientation(LinearLayout.VERTICAL);
    this.setBackgroundColor(Color.rgb(255, 255, 255));

    mTabScrollView = new HorizontalScrollView(context);
    mTabScrollView.setHorizontalScrollBarEnabled(false);
    mTabScrollView.setSmoothScrollingEnabled(true);

    mTabLayout = new LinearLayout(context);
    mTabLayout.setOrientation(LinearLayout.HORIZONTAL);
    mTabLayout.setGravity(Gravity.CENTER);

    // mTabLayout
    mTabScrollView.addView(mTabLayout, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.FILL_PARENT));

    this.addView(mTabScrollView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    // View?
    mViewPager = new AbViewPager(context);
    // ViewPager,setId()id
    mViewPager.setId(1985);
    pagerItemList = new ArrayList<Fragment>();
    // Tab?
    tabItemList = new ArrayList<TextView>();
    tabItemTextList = new ArrayList<String>();
    tabItemDrawableList = new ArrayList<Drawable>();

    // ?FragmentActivity
    if (!(this.context instanceof FragmentActivity)) {
        AbLogUtil.e(AbSlidingTabView.class,
                "AbSlidingTabView?context,FragmentActivity");
    }
}

From source file:uz.efir.alqalam.SurahActivity.java

private void showData() {
    AyatIconifiedText ait;/*from w w  w  .j  a  v a2 s .  c om*/
    final Drawable iconBismillah = ResourcesCompat.getDrawable(getResources(), R.drawable.bismillah, null);
    final Drawable bookmarkImage = ResourcesCompat.getDrawable(getResources(), R.drawable.bookmark_icon, null);

    surahAdapter.clear();
    resetData();

    for (int i = 0; i < Utils.SURAH_NUMBER_OF_AYATS[mSurahNumber]; i++) {
        ait = new AyatIconifiedText(i, i + 1, AYATSARABIC[i], AYATSTRANS[i]);
        // check if BISMILLAH must be shown
        if (i == 0 && mSurahNumber != 0 && mSurahNumber != 8) {
            ait.setBismillahImage(iconBismillah);
        }
        // Put bookmarks
        if (mBookmarks != null && Arrays.binarySearch(mBookmarks, i + 1) >= 0) {
            ait.setAyatBookmarkImage(bookmarkImage);
            ait.setAyatBackground(Color.rgb(243, 255, 140));
        }
        // Put juz and/or sajda icons
        ait.setAyatSpecialImage(getSpecialImage(mSurahNumber + 1, i + 1));
        surahAdapter.addItem(ait);
    }

    // make verses appear in list view
    ayatList.setAdapter(surahAdapter);
    ayatList.setDivider(null);

    // Jump to specific Ayat (if defined);
    if (mCurrentAyat > 0) {
        ayatList.setSelectionFromTop(mCurrentAyat - 1, 0);
    }
}

From source file:com.ryan.ryanreader.reddit.prepared.RedditPreparedComment.java

private void rebuildHeader(final Context context) {

    final BetterSSB sb = new BetterSSB();

    final int pointsCol;
    int score = src.ups - src.downs;

    if (Boolean.TRUE.equals(src.likes))
        score--;//from w  ww  .  j a va2s  . com
    if (Boolean.FALSE.equals(src.likes))
        score++;

    if (isUpvoted()) {
        pointsCol = rrPostSubtitleUpvoteCol;
        score++;
    } else if (isDownvoted()) {
        pointsCol = rrPostSubtitleDownvoteCol;
        score--;
    } else {
        pointsCol = rrCommentHeaderBoldCol;
    }

    if (headerItems.contains(PrefsUtility.AppearanceCommentHeaderItems.AUTHOR)) {
        if (parentPost != null && src.author.equalsIgnoreCase(parentPost.src.author)) {
            sb.append(" " + src.author + " ",
                    BetterSSB.BACKGROUND_COLOR | BetterSSB.FOREGROUND_COLOR | BetterSSB.BOLD, Color.WHITE,
                    Color.rgb(0, 126, 168), 1f); // TODO color
        } else {
            sb.append(src.author, BetterSSB.FOREGROUND_COLOR | BetterSSB.BOLD, rrCommentHeaderAuthorCol, 0, 1f);
        }
    }

    if (headerItems.contains(PrefsUtility.AppearanceCommentHeaderItems.FLAIR) && flair != null
            && flair.length() > 0) {

        if (headerItems.contains(PrefsUtility.AppearanceCommentHeaderItems.AUTHOR)) {
            sb.append("  ", 0);
        }

        sb.append(" " + flair + " ", BetterSSB.FOREGROUND_COLOR | BetterSSB.BACKGROUND_COLOR,
                Color.rgb(30, 30, 30), Color.rgb(230, 230, 230), 1f); // TODO theme properly
    }

    if (headerItems.contains(PrefsUtility.AppearanceCommentHeaderItems.AUTHOR)
            || headerItems.contains(PrefsUtility.AppearanceCommentHeaderItems.FLAIR)) {
        sb.append("   ", 0);
    }

    if (headerItems.contains(PrefsUtility.AppearanceCommentHeaderItems.SCORE)) {

        if (!Boolean.TRUE.equals(src.score_hidden)) {
            sb.append(String.valueOf(score), BetterSSB.FOREGROUND_COLOR | BetterSSB.BOLD, pointsCol, 0, 1f);
        } else {
            sb.append("??", BetterSSB.FOREGROUND_COLOR | BetterSSB.BOLD, pointsCol, 0, 1f);
        }

        sb.append(" " + context.getString(R.string.subtitle_points) + " ", 0);
    }

    if (!Boolean.TRUE.equals(src.score_hidden)
            && headerItems.contains(PrefsUtility.AppearanceCommentHeaderItems.UPS_DOWNS)) {
        sb.append("(", 0);
        sb.append(String.valueOf(src.ups), BetterSSB.FOREGROUND_COLOR | BetterSSB.BOLD, rrPostSubtitleUpvoteCol,
                0, 1f);
        sb.append(" | ", 0);
        sb.append(String.valueOf(src.downs), BetterSSB.FOREGROUND_COLOR | BetterSSB.BOLD,
                rrPostSubtitleDownvoteCol, 0, 1f);
        sb.append(")  ", 0);
    }

    if (headerItems.contains(PrefsUtility.AppearanceCommentHeaderItems.AGE)) {
        sb.append(RRTime.formatDurationMsAgo(context, RRTime.utcCurrentTimeMillis() - src.created_utc * 1000L),
                BetterSSB.FOREGROUND_COLOR | BetterSSB.BOLD, rrCommentHeaderBoldCol, 0, 1f);
    }

    header = sb.get();
}

From source file:spit.matrix2017.Activities.EventDetails.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_event_details);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from   w w  w .  ja va  2s .  c om*/
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle("");

    final AppCompatTextView textViews[] = { (AppCompatTextView) findViewById(R.id.tv_event_description),
            (AppCompatTextView) findViewById(R.id.tv_event_venue_time),
            (AppCompatTextView) findViewById(R.id.tv_event_registration),
            (AppCompatTextView) findViewById(R.id.tv_event_prizes),
            (AppCompatTextView) findViewById(R.id.tv_event_organizers) };

    collapsingToolbarLayout = (CollapsingToolbarLayout) findViewById(R.id.collapsingToolbar_event);
    organizers_card = (CardView) findViewById(R.id.organizers_card);
    prizes_card = (CardView) findViewById(R.id.prizes_card);
    registration_card = (CardView) findViewById(R.id.registration_card);

    visitedCalendar = false;
    isFirstLaunch = true;

    //get intent from eventlist adapter
    if (getIntent().getStringExtra("name") != null && getSupportActionBar() != null) {
        event_name = getIntent().getStringExtra("name");
        this.setTitle(event_name);
    } else
        this.setTitle("Some event");

    setDescription(getIntent().getStringExtra("description"));
    setVenueAndTime(getIntent().getStringExtra("venue"), getIntent().getStringExtra("time"));
    setRegistration(getIntent().getStringExtra("registration"));
    setPrizes(getIntent().getStringExtra("prizes"));
    setContacts(getIntent().getStringExtra("contact1name"), getIntent().getStringExtra("contact1no"),
            getIntent().getStringExtra("contact2name"), getIntent().getStringExtra("contact2no"));

    isFavouriteEvent = getIntent().getIntExtra("favorite", 0) == 1;
    isReminderSet = getIntent().getIntExtra("reminder", 0) == 1;

    mainImageView = (ImageView) findViewById(R.id.main_imageView);
    assert mainImageView != null;
    mainImageView.setImageResource(getIntent().getIntExtra("image", R.drawable.event_vsm));

    fab = (FloatingActionButton) findViewById(R.id.fab);
    assert fab != null;
    if (isFavouriteEvent)
        fab.setImageResource(R.drawable.svg_favorite_white_48px);

    Bitmap bitmap = ((BitmapDrawable) mainImageView.getDrawable()).getBitmap();

    Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {
        @Override
        public void onGenerated(Palette palette) {
            Palette.Swatch swatch = palette.getVibrantSwatch();
            if (swatch == null)
                swatch = palette.getMutedSwatch();
            if (swatch != null) {
                int color = swatch.getRgb();
                if (Color.red(color) + Color.green(color) + Color.green(color) > 420)
                    color = Color.rgb((int) (Color.red(color) * 0.8), (int) (Color.green(color) * 0.8),
                            (int) (Color.blue(color) * 0.8));

                fab.setBackgroundTintList(ColorStateList.valueOf(color));
                fab.setRippleColor(swatch.getTitleTextColor());
                collapsingToolbarLayout.setContentScrimColor(color);
                collapsingToolbarLayout.setBackgroundColor(color);
                collapsingToolbarLayout.setStatusBarScrimColor(color);

                if (Build.VERSION.SDK_INT >= 21) {
                    getWindow().setStatusBarColor(color);
                }

                for (AppCompatTextView textView : textViews)
                    textView.setTextColor(color);
            }
        }
    });

    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            isFavouriteEvent = !isFavouriteEvent;
            ContentResolver contentResolver = getContentResolver();
            Uri uri = Uri.parse("content://spit.matrix2017.provider");
            String selection = "name = ?";
            String[] selectionArgs = { getIntent().getStringExtra("name") };
            ContentValues cv = new ContentValues();

            if (isFavouriteEvent) {
                cv.put("favorite", 1);
                contentResolver.update(uri, cv, selection, selectionArgs);
                Toast.makeText(EventDetails.this, "Added to favorites", Toast.LENGTH_SHORT).show();
                fab.setImageResource(R.drawable.svg_favorite_white_48px);
            } else {
                cv.put("favorite", 0);
                contentResolver.update(uri, cv, selection, selectionArgs);
                fab.setImageResource(R.drawable.svg_favorite_border_white_48px);
            }
        }
    });
}