Skip to content

Commit

Permalink
InfoGray notification type added
Browse files Browse the repository at this point in the history
  • Loading branch information
istiakshihab committed Oct 18, 2021
1 parent 0ff7ee0 commit 685fcc6
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 6 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ ChocoBar is now also available in Kotlin, thanks to @JamesEllerbee
![Love Chocobar](https://user-images.githubusercontent.com/35525781/96970060-c012c080-1530-11eb-926c-59edd1844413.png)
![image](https://user-images.githubusercontent.com/26584526/136639395-7a70f775-b5d3-4ad4-8b4f-d0ce91490c18.png)
![image](https://user-images.githubusercontent.com/26584526/136639381-19bfd6f0-a34e-49f9-8b7e-4e34c4e02ba7.png)
![image](https://user-images.githubusercontent.com/36191408/137777366-738ce9c7-d942-4ccb-845a-38f4891196ea.png)

## Documentation
[Find how to use the in-built Chocobars here](documentation/ReadMe.md)
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com/pd/snickers/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ protected void onCreate(Bundle savedInstanceState) {
.blocked()
.show());

findViewById(R.id.button_info_gray).setOnClickListener(v-> ChocoBar.builder()
.setView(v)
.centerText()
.setDuration(ChocoBar.LENGTH_LONG)
.infoGray()
.show());

findViewById(R.id.button_next).setOnClickListener(v -> {
Intent secondaryActivityIntent = new Intent(this, SecondaryActivity.class);
startActivity(secondaryActivityIntent);
Expand Down
26 changes: 23 additions & 3 deletions app/src/main/res/layout/content_example.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@

<Button
android:id="@+id/button_good"

android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/button_error"
Expand Down Expand Up @@ -252,17 +251,38 @@
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="@string/blocked_chocobar"
app:layout_constraintBottom_toBottomOf="@+id/button_next"
app:layout_constraintBottom_toTopOf="@+id/info_gray"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button_on_notification" />

<Button
android:id="@+id/button_info_gray"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/button_blocked"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginStart="8dp"
android:layout_marginLeft="8dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:text="@string/info_gray"
app:layout_constraintBottom_toTopOf="@+id/button_next"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button_blocked" />

<ImageButton
android:id="@+id/button_next"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/button_blocked"
android:layout_marginTop="50dp"
android:layout_below="@id/button_info_gray"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:contentDescription="@string/kotlin_icon"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,5 @@
<string name="chocobar_kotlin">ChocoBar Kotlin</string>
<string name="kotlin_icon">Kotlin icon</string>
<string name="java_icon">java icon</string>
<string name="info_gray">Info Gray Chocobar</string>
</resources>
20 changes: 17 additions & 3 deletions chocobar/src/main/java/com/pd/chocobar/ChocoBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.PorterDuff;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Build;
Expand All @@ -18,6 +20,7 @@
import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -42,7 +45,8 @@ private enum Type {
BLACK(Color.parseColor("#000000"), R.drawable.off_notification_mark, Color.WHITE, "Black"),
LOVE(Color.parseColor("#E8290B"), R.drawable.ic_love, Color.BLACK, "LOVE"),
BLOCKED(Color.parseColor("#E8290B"), R.drawable.blocked_mark, Color.BLACK, "BLOCKED"),
NOTIFICATION_ON(Color.parseColor("#000000"), R.drawable.on_notification_mark, Color.WHITE, "NOTIFICATIONS ON");
NOTIFICATION_ON(Color.parseColor("#000000"), R.drawable.on_notification_mark, Color.WHITE, "NOTIFICATIONS ON"),
INFOGRAY(Color.parseColor("#BB353535"), R.drawable.info_mark, Color.WHITE,"INFO GRAYBLUE");

private Integer color;
private Integer iconResId;
Expand Down Expand Up @@ -203,6 +207,10 @@ else if (builder.textColor != null)
text.setCompoundDrawablesWithIntrinsicBounds(transparentHelperDrawable, null, builder.icon, null);
else
text.setCompoundDrawablesWithIntrinsicBounds(builder.icon, null, transparentHelperDrawable, null);

if (Build.VERSION.SDK_INT >= 21 && builder.type == Type.INFOGRAY){
builder.icon.setTint(Color.parseColor("#4895ED"));
}
text.setCompoundDrawablePadding(text.getResources().getDimensionPixelOffset(R.dimen.icon_padding));
}

Expand Down Expand Up @@ -440,14 +448,20 @@ public Snackbar blocked() {
return make();
}


public Snackbar notificationsOn()
{
type = Type.NOTIFICATION_ON;
return make();
}



public Snackbar infoGray()
{
type = Type.INFOGRAY;
return make();
}

private Snackbar make() {
if (view == null)
throw new IllegalStateException("ChocoBar Error: You must set an Activity or a View before making a snack");
Expand Down

0 comments on commit 685fcc6

Please sign in to comment.