From 410390ef37fa36315790b4a7ef31a05452b37b39 Mon Sep 17 00:00:00 2001 From: James Ellerbee Date: Fri, 8 Oct 2021 20:33:37 -0500 Subject: [PATCH 1/2] Created documentation.md file and move documentation on how to use the built-in ChocoBars, fixed issue with 'Blocked Chocobar' button eclipsing 'Notifications On' button Update README.md --- Documentation.md | 144 ++++++++++++++++++ README.md | 98 +----------- .../java/com/pd/snickers/MainActivity.java | 11 +- app/src/main/res/layout/content_example.xml | 4 +- chocobar/src/main/AndroidManifest.xml | 1 - 5 files changed, 162 insertions(+), 96 deletions(-) create mode 100644 Documentation.md diff --git a/Documentation.md b/Documentation.md new file mode 100644 index 0000000..1c406ef --- /dev/null +++ b/Documentation.md @@ -0,0 +1,144 @@ +## Usage + +Chocobar has several built-in types which specifies color, icon, text, and text color. + +Each method always returns a `Snackbar` object, so you can customize the Snackbar further and much more. + +Check out the following examples: + +- To display a `green` ChocoBar: + +``` java +ChocoBar.builder().setActivity(v) + .setText("GREEN") + .setDuration(ChocoBar.LENGTH_SHORT) + .green() // built-in green ChocoBar + .show(); +``` + +- To display an `orange` Chocobar + +``` java +ChocoBar.builder().setActivity(v) + .setText("ORANGE") + .setDuration(ChocoBar.LENGTH_SHORT) + .orange() // built-in orange ChocoBar + .show(); +``` +- To display a `red` ChocoBar: + +``` java +ChocoBar.builder().setView(v) + .setText("RED") + .setDuration(ChocoBar.LENGTH_INDEFINITE) + .setActionText(android.R.string.ok) + .red() // built-in red ChocoBar + .show(); +``` + +- To display a `cyan` Chocobar: + +``` java +ChocoBar.builder().setView(v) + .setText("CYAN") + .setDuration(ChocoBar.LENGTH_INDEFINITE) + .setActionText(android.R.string.ok) + .cyan() // built-in cyan ChocoBar + .show(); +``` + +- To display a `gray` ChocoBar: + +``` java +ChocoBar.builder().setView(v) + .setText("GRAY_GOOD") + .centerText() + .setDuration(ChocoBar.LENGTH_LONG) + .good() + .show(); + +ChocoBar.builder().setView(v) + .setText("GRAY_BAD") + .centerText() + .setDuration(ChocoBar.LENGTH_LONG) + .bad() + .show(); +``` + +- To display a `love` ChocoBar: + +``` java +ChocoBar.builder().setView(v) + .setText("Love") + .setDuration(ChocoBar.LENGTH_INDEFINITE) + .setActionText(android.R.string.ok) + .love() // built-in red ChocoBar + .show(); +``` + +- To display a `default` ChocoBar that provides an action: + +``` java +ChocoBar.builder().setActivity(v) + .setActionText("ACTION") + .setActionClickListener(v1 -> + Toast.makeText(MainActivity.this,"You clicked",Toast.LENGTH_LONG).show();) + .setText("This is a default ChocoBar") + .setDuration(ChocoBar.LENGTH_INDEFINITE) + .build() + .show(); +``` + +- To display a `black` ChocoBar: + +```java +ChocoBar.builder() + .setView(v) + .centerText() + .setDuration(ChocoBar.LENGTH_LONG) + .black() // built-in black ChocoBar + .show()); +``` + +- To display a `notifications on` Chocobar: + +```java +ChocoBar.builder() + .setView(v) + .centerText() + .setDuration(ChocoBar.LENGTH_LONG) + .notificationsOn() // built-in notifications on ChocoBar + .show()); +``` + +- To display a `blocked` Chocobar: + +```java +ChocoBar.builder() + .setView(v) + .centerText() + .setDuration(ChocoBar.LENGTH_LONG) + .blocked() // built-in blocked on ChocoBar + .show()); +``` + +- You can also create highly customized ChocoBars: + +``` java +ChocoBar.builder().setBackgroundColor(Color.parseColor("#00bfff")) + .setTextSize(18) + .setTextColor(Color.parseColor("#FFFFFF")) + .setTextTypefaceStyle(Typeface.ITALIC) + .setText("This is a custom Chocobar") + .setMaxLines(4) + .centerText() + .setActionText("ChocoBar") + .setActionTextColor(Color.parseColor("#66FFFFFF")) + .setActionTextSize(20) + .setActionTextTypefaceStyle(Typeface.BOLD) + .setIcon(R.mipmap.ic_launcher) + .setActivity(MainActivity.this) + .setDuration(ChocoBar.LENGTH_INDEFINITE) + .build() + .show(); +``` \ No newline at end of file diff --git a/README.md b/README.md index d4ee76e..e17d5ff 100644 --- a/README.md +++ b/README.md @@ -48,13 +48,16 @@ ![screenshot 2018-12-31 at 4 26 00 am](https://user-images.githubusercontent.com/37071007/68586351-d6fb0700-04c7-11ea-8133-dd0e14fcd8c8.png) ![screenshot 2018-12-31 at 4 26 00 am](https://user-images.githubusercontent.com/37071007/68586380-e5e1b980-04c7-11ea-95eb-612167d59448.png) ![Love Chocobar](https://user-images.githubusercontent.com/35525781/96970060-c012c080-1530-11eb-926c-59edd1844413.png) -![Screenshot_1633403711](https://user-images.githubusercontent.com/26584526/135955251-1a5ef862-8e84-4571-9685-33b70ade14bd.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) + +## Documentation +[Find how to use the built-in Chocobars here](https://github.com/Pradyuman7/ChocoBar/blob/master/Documentation.md) ## Prerequisites Add this in your root `build.gradle` file (**not** your module `build.gradle` file): - ```gradle allprojects { repositories { @@ -76,99 +79,10 @@ dependencies { } ``` -## Usage - -Each method always returns a `Snackbar` object, so you can customize the Snackbar and much more. Check out the following examples: - -- To display a green ChocoBar: - -``` java -ChocoBar.builder().setActivity(MainActivity.this) - .setText("GREEN") - .setDuration(ChocoBar.LENGTH_SHORT) - .green() // in built green ChocoBar - .show(); -``` -- To display a red ChocoBar: - -``` java -ChocoBar.builder().setView(v) - .setText("RED") - .setDuration(ChocoBar.LENGTH_INDEFINITE) - .setActionText(android.R.string.ok) - .red() // in built red ChocoBar - .show(); -``` -- To display a gray ChocoBar: - -``` java -ChocoBar.builder().setView(v) - .setText("GRAY_GOOD") - .centerText() - .setDuration(ChocoBar.LENGTH_LONG) - .good() - .show(); - -ChocoBar.builder().setView(v) - .setText("GRAY_BAD") - .centerText() - .setDuration(ChocoBar.LENGTH_LONG) - .bad() - .show(); -``` - -- To display a love ChocoBar: - -``` java -ChocoBar.builder().setView(v) - .setText("Love") - .setDuration(ChocoBar.LENGTH_INDEFINITE) - .setActionText(android.R.string.ok) - .love() // in built red ChocoBar - .show(); -``` - -- To display a simple ChocoBar with a button and some action on clicking the button. - -``` java -ChocoBar.builder().setActivity(MainActivity.this).setActionText("ACTION") - .setActionClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - Toast.makeText(MainActivity.this,"You clicked",Toast.LENGTH_LONG).show(); - } - }) - .setText("This is a normal ChocoBar") - .setDuration(ChocoBar.LENGTH_INDEFINITE) - .build() - .show(); -``` - -- You can also create custom ChocoBars with tons of customizations like this: -``` java -ChocoBar.builder().setBackgroundColor(Color.parseColor("#00bfff")) - .setTextSize(18) - .setTextColor(Color.parseColor("#FFFFFF")) - .setTextTypefaceStyle(Typeface.ITALIC) - .setText("This is a custom Chocobar") - .setMaxLines(4) - .centerText() - .setActionText("ChocoBar") - .setActionTextColor(Color.parseColor("#66FFFFFF")) - .setActionTextSize(20) - .setActionTextTypefaceStyle(Typeface.BOLD) - .setIcon(R.mipmap.ic_launcher) - .setActivity(MainActivity.this) - .setDuration(ChocoBar.LENGTH_INDEFINITE) - .build() - .show(); - -``` - ## Pull Request Have some new ideas or found a bug? Do not hesitate to open an `issue` and make a `pull request`. ## License -**ChocoBar** is under [![License: MIT](https://img.shields.io/badge/License-MIT-red.svg)](https://opensource.org/licenses/MIT). See the [LICENSE](LICENSE.md) file for more info. \ No newline at end of file +**ChocoBar** is under [![License: MIT](https://img.shields.io/badge/License-MIT-red.svg)](https://opensource.org/licenses/MIT). See the [LICENSE](LICENSE.md) file for more info. diff --git a/app/src/main/java/com/pd/snickers/MainActivity.java b/app/src/main/java/com/pd/snickers/MainActivity.java index 6e6bd21..525f067 100644 --- a/app/src/main/java/com/pd/snickers/MainActivity.java +++ b/app/src/main/java/com/pd/snickers/MainActivity.java @@ -17,6 +17,7 @@ public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); findViewById(R.id.button_default).setOnClickListener(v -> ChocoBar.builder() @@ -106,6 +107,14 @@ protected void onCreate(Bundle savedInstanceState) { .setView(v) .centerText() .setDuration(ChocoBar.LENGTH_LONG) - .notificationsOn().show()); + .notificationsOn() + .show()); + + findViewById(R.id.button_blocked).setOnClickListener(v -> ChocoBar.builder() + .setView(v) + .centerText() + .setDuration(ChocoBar.LENGTH_LONG) + .blocked() + .show()); } } \ No newline at end of file diff --git a/app/src/main/res/layout/content_example.xml b/app/src/main/res/layout/content_example.xml index e4e7e9c..414f192 100644 --- a/app/src/main/res/layout/content_example.xml +++ b/app/src/main/res/layout/content_example.xml @@ -227,13 +227,13 @@ android:text="@string/blocked_chocobar" android:layout_width="match_parent" android:layout_height="wrap_content" - android:layout_below="@+id/button_off_notification" + android:layout_below="@+id/button_on_notification" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:id="@+id/button_blocked" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" - app:layout_constraintTop_toBottomOf="@+id/button_off_notification" + app:layout_constraintTop_toBottomOf="@+id/button_on_notification" android:layout_marginLeft="8dp" app:layout_constraintLeft_toLeftOf="parent" android:layout_marginRight="8dp" diff --git a/chocobar/src/main/AndroidManifest.xml b/chocobar/src/main/AndroidManifest.xml index e6d8886..a549b0e 100644 --- a/chocobar/src/main/AndroidManifest.xml +++ b/chocobar/src/main/AndroidManifest.xml @@ -4,7 +4,6 @@ - From db3652d7e017d502be1a49247a3d361b8583fbb3 Mon Sep 17 00:00:00 2001 From: Pradyuman Dixit Date: Sat, 9 Oct 2021 14:12:19 +0530 Subject: [PATCH 2/2] Update link to the documentation --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e17d5ff..f86ef3e 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ ![image](https://user-images.githubusercontent.com/26584526/136639381-19bfd6f0-a34e-49f9-8b7e-4e34c4e02ba7.png) ## Documentation -[Find how to use the built-in Chocobars here](https://github.com/Pradyuman7/ChocoBar/blob/master/Documentation.md) +[Find how to use the built-in Chocobars here](Documentation.md) ## Prerequisites