Last active
August 29, 2015 14:08
-
-
Save realdadfish/f412e02dc87864726d76 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ChromeTint implements Parcelable | |
{ | |
private int mToolbarColor; | |
private int mToolbarTitleColor; | |
private int mStatusbarColor; | |
public static ChromeTint createFromBitmap(Bitmap bm, int defaultToolbarColor, int defaultTitleColor, int defaultStatusbarColor) | |
{ | |
Palette pal = Palette.generate(bm); | |
Palette.Swatch vibrant = pal.getVibrantSwatch(); | |
Palette.Swatch darkVibrant = pal.getDarkVibrantSwatch(); | |
int toolbarColor = defaultToolbarColor, | |
titleColor = defaultTitleColor, | |
statusColor = defaultStatusbarColor; | |
if (vibrant != null) | |
{ | |
toolbarColor = vibrant.getRgb(); | |
titleColor = vibrant.getTitleTextColor(); | |
} | |
if (darkVibrant != null) | |
{ | |
statusColor = darkVibrant.getRgb(); | |
} | |
return new ChromeTint(toolbarColor, titleColor, statusColor); | |
} | |
private ChromeTint(int toolbarColor, int toolbarTitleColor, int statusbarColor) | |
{ | |
mToolbarColor = toolbarColor; | |
mToolbarTitleColor = toolbarTitleColor; | |
mStatusbarColor = statusbarColor; | |
} | |
public int getToolbarColor() | |
{ | |
return mToolbarColor; | |
} | |
public int getToolbarTitleColor() | |
{ | |
return mToolbarTitleColor; | |
} | |
public int getStatusbarColor() | |
{ | |
return mStatusbarColor; | |
} | |
@Override | |
public int describeContents() | |
{ | |
return 0; | |
} | |
@Override | |
public void writeToParcel(Parcel dest, int flags) | |
{ | |
dest.writeInt(mToolbarColor); | |
dest.writeInt(mToolbarTitleColor); | |
dest.writeInt(mStatusbarColor); | |
} | |
public static final Parcelable.Creator<ChromeTint> CREATOR = new Parcelable.Creator<ChromeTint>() | |
{ | |
@Override | |
public ChromeTint createFromParcel(Parcel in) | |
{ | |
return new ChromeTint(in.readInt(), in.readInt(), in.readInt()); | |
} | |
@Override | |
public ChromeTint[] newArray(int size) | |
{ | |
return new ChromeTint[size]; | |
} | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SomeActivity extends Activity { | |
... | |
public void onCreate(Bundle state) { | |
... | |
Toolbar toolbar = findViewById(R.id.my_toolbar); | |
ChromeTint tint = getIntent().getParcelableExtra(EXTRA_CHROME_TINT); | |
if (tint != null) | |
{ | |
toolbar.setBackgroundColor(tint.getToolbarColor()); | |
toolbar.setTitleTextColor(tint.getToolbarTitleColor()); | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) | |
{ | |
getWindow().setStatusBarColor(tint.getStatusbarColor()); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment