Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/use hex colors #29

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions app/src/main/java/org/aviran/cookiebarsample/JavaDemoFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void onViewCreated(@NonNull View rootView, @Nullable Bundle savedInstance
public void onClick(View view) {
CookieBar.build(getActivity())
.setTitle(R.string.top_cookie_title)
.setTitleColor(R.color.yellow)
.setTitleColor("#FFFF00")
.setMessage(getString(R.string.top_cookie_message, ++topCookieCounter))
.setIcon(R.drawable.ic_android_white_48dp)
.setDuration(5000)
Expand Down Expand Up @@ -95,9 +95,9 @@ public void onClick(View view) {
.setTitle(R.string.bottom_cookie_title)
.setIcon(R.mipmap.ic_launcher)
.setMessage(R.string.bottom_cookie_message)
.setBackgroundColor(R.color.colorPrimary)
.setActionColor(R.color.yellow)
.setTitleColor(R.color.yellow)
.setBackgroundColor("#315F97")
.setActionColor("#FFFF00")
.setTitleColor("#FFFF00")
.setCookiePosition(CookieBar.BOTTOM)
.setAction(R.string.cookie_action, new OnActionClickListener() {
@Override
Expand All @@ -118,8 +118,8 @@ public void onClick(View view) {
.setTitle(R.string.custom_anim_cookie_title)
.setMessage(R.string.custom_anim_cookie_message)
.setIcon(R.drawable.ic_android_white_48dp)
.setMessageColor(R.color.liteblue)
.setBackgroundColor(R.color.orange)
.setMessageColor("#315F97")
.setBackgroundColor("#FF0000")
.setDuration(5000)
.setAnimationIn(android.R.anim.slide_in_left, android.R.anim.slide_in_left)
.setAnimationOut(android.R.anim.slide_out_right, android.R.anim.slide_out_right)
Expand All @@ -137,10 +137,10 @@ public void onClick(View view) {
.setMessage(R.string.fancy_cookie_message)
.setIcon(R.drawable.ic_settings_white_48dp)
.setIconAnimation(R.animator.iconspin)
.setTitleColor(R.color.fancyTitle)
.setActionColor(R.color.fancyAction)
.setMessageColor(R.color.fancyMessage)
.setBackgroundColor(R.color.fancyBackground)
.setTitleColor("#FFFF00")
.setActionColor("#FFFFFF")
.setMessageColor("#FF0000")
.setBackgroundColor("#315F97")
.setDuration(5000)
.setCookiePosition(CookieBar.BOTTOM)
.setAction("OPEN SETTINGS", new OnActionClickListener() {
Expand Down
20 changes: 10 additions & 10 deletions app/src/main/java/org/aviran/cookiebarsample/MainFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class MainFragment : Fragment() {
btnTop.setOnClickListener {
CookieBar.build(activity)
.setTitle(R.string.top_cookie_title)
.setTitleColor(R.color.yellow)
.setTitleColor(R.color.default_title_color)
.setMessage(getString(R.string.top_cookie_message, ++topCookieCounter))
.setIcon(R.drawable.ic_android_white_48dp)
.setDuration(5000)
Expand All @@ -57,9 +57,9 @@ class MainFragment : Fragment() {
.setTitle(R.string.bottom_cookie_title)
.setIcon(R.mipmap.ic_launcher)
.setMessage(R.string.bottom_cookie_message)
.setBackgroundColor(R.color.colorPrimary)
.setActionColor(R.color.yellow)
.setTitleColor(R.color.yellow)
.setBackgroundColor(R.color.liteblue)
.setActionColor("#FFFF00")
.setTitleColor("#FFFF00")
.setCookiePosition(CookieBar.BOTTOM)
.setAction(R.string.cookie_action) {
infoTextView.text = getString(R.string.action_engaged)
Expand All @@ -72,8 +72,8 @@ class MainFragment : Fragment() {
.setTitle(R.string.custom_anim_cookie_title)
.setMessage(R.string.custom_anim_cookie_message)
.setIcon(R.drawable.ic_android_white_48dp)
.setMessageColor(R.color.liteblue)
.setBackgroundColor(R.color.orange)
.setMessageColor(R.color.white)
.setBackgroundColor(R.color.colorAccent)
.setDuration(5000)
.setAnimationIn(android.R.anim.slide_in_left, android.R.anim.slide_in_left)
.setAnimationOut(android.R.anim.slide_out_right, android.R.anim.slide_out_right)
Expand All @@ -87,10 +87,10 @@ class MainFragment : Fragment() {
.setMessage(R.string.fancy_cookie_message)
.setIcon(R.drawable.ic_settings_white_48dp)
.setIconAnimation(R.animator.iconspin)
.setTitleColor(R.color.fancyTitle)
.setActionColor(R.color.fancyAction)
.setMessageColor(R.color.fancyMessage)
.setBackgroundColor(R.color.fancyBackground)
.setTitleColor("#FFFF00")
.setActionColor("#FFFFFF")
.setMessageColor("#FF0000")
.setBackgroundColor("#315F97")
.setDuration(5000)
.setCookiePosition(CookieBar.BOTTOM)
.setAction("OPEN SETTINGS") {
Expand Down
42 changes: 33 additions & 9 deletions cookiebar2/src/main/java/org/aviran/cookiebar2/Cookie.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,29 @@ public void setParams(final CookieBar.Params params) {
if (titleTextView != null && !TextUtils.isEmpty(params.title)) {
titleTextView.setVisibility(VISIBLE);
titleTextView.setText(params.title);
if (params.titleColor != 0) {
titleTextView.setTextColor(ContextCompat.getColor(getContext(), params.titleColor));
if (params.titleColor != null) {
try {
titleTextView.setTextColor(Color.parseColor(params.titleColor));
} catch (Exception e) {
e.printStackTrace();
}
} else if (params.titleColorRes != 0){
titleTextView.setTextColor(ContextCompat.getColor(getContext(), params.titleColorRes));
}
setDefaultTextSize(titleTextView, R.attr.cookieTitleSize);
}

if (messageTextView != null && !TextUtils.isEmpty(params.message)) {
messageTextView.setVisibility(VISIBLE);
messageTextView.setText(params.message);
if (params.messageColor != 0) {
messageTextView.setTextColor(ContextCompat.getColor(getContext(), params.messageColor));
if (params.messageColor != null) {
try {
messageTextView.setTextColor(Color.parseColor(params.messageColor));
} catch (Exception e) {
e.printStackTrace();
}
} else if (params.messageColorRes != 0){
messageTextView.setTextColor(ContextCompat.getColor(getContext(), params.messageColorRes));
}
setDefaultTextSize(messageTextView, R.attr.cookieMessageSize);
}
Expand All @@ -189,16 +201,28 @@ public void onClick(View view) {
}
});

if (params.actionColor != 0) {
actionButton.setTextColor(ContextCompat.getColor(getContext(), params.actionColor));
if (params.actionColor != null) {
try {
actionButton.setTextColor(Color.parseColor(params.actionColor));
} catch (Exception e) {
e.printStackTrace();
}
} else if (params.actionColorRes != 0){
actionButton.setTextColor(ContextCompat.getColor(getContext(), params.actionColorRes));
}

setDefaultTextSize(actionButton, R.attr.cookieActionSize);
}

if (params.backgroundColor != 0) {
layoutCookie
.setBackgroundColor(ContextCompat.getColor(getContext(), params.backgroundColor));
if (params.backgroundColor != null) {
try {
layoutCookie
.setBackgroundColor(Color.parseColor(params.backgroundColor));
} catch (Exception e) {
e.printStackTrace();
}
} else if (params.backgroundColorRes != 0){
layoutCookie.setBackgroundColor(ContextCompat.getColor(getContext(), params.backgroundColorRes));
}

int defaultPadding = getContext().getResources().getDimensionPixelSize(R.dimen.default_padding);
Expand Down
32 changes: 28 additions & 4 deletions cookiebar2/src/main/java/org/aviran/cookiebar2/CookieBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -171,21 +171,41 @@ public Builder setDuration(long duration) {
}

public Builder setTitleColor(@ColorRes int titleColor) {
params.titleColorRes = titleColor;
return this;
}

public Builder setTitleColor(String titleColor) {
params.titleColor = titleColor;
return this;
}

public Builder setMessageColor(@ColorRes int messageColor) {
params.messageColorRes = messageColor;
return this;
}

public Builder setMessageColor(String messageColor) {
params.messageColor = messageColor;
return this;
}

public Builder setBackgroundColor(@ColorRes int backgroundColor) {
params.backgroundColorRes = backgroundColor;
return this;
}

public Builder setBackgroundColor(String backgroundColor) {
params.backgroundColor = backgroundColor;
return this;
}

public Builder setActionColor(@ColorRes int actionColor) {
params.actionColorRes = actionColor;
return this;
}

public Builder setActionColor(String actionColor) {
params.actionColor = actionColor;
return this;
}
Expand Down Expand Up @@ -292,10 +312,14 @@ final static class Params {
public boolean enableSwipeToDismiss = true;
public boolean enableAutoDismiss = true;
public int iconResId;
public int backgroundColor;
public int titleColor;
public int messageColor;
public int actionColor;
public String backgroundColor;
public int backgroundColorRes;
public String titleColor;
public int titleColorRes;
public String messageColor;
public int messageColorRes;
public String actionColor;
public int actionColorRes;
public long duration = 2000;
public int cookiePosition = Gravity.TOP;
public int customViewResource;
Expand Down
4 changes: 2 additions & 2 deletions cookiebar2/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="default_bg_color">#ab47bc</color>
<color name="default_bg_color">#315F97</color>
<color name="default_title_color">#ffffff</color>
<color name="default_message_color">#ffffff</color>
<color name="default_action_color">#26a69a</color>
<color name="default_action_color">#ffffff</color>
</resources>