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

Added ability to add multiple Actions or a Custom View #49

Open
wants to merge 7 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
2 changes: 1 addition & 1 deletion TSnackBar.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="TSnackBar" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<module external.linked.project.id="TSnackBar" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
Expand Down
42 changes: 18 additions & 24 deletions app/app.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="TSnackBar" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand All @@ -9,7 +9,6 @@
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<afterSyncTasks>
Expand All @@ -23,7 +22,7 @@
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/test/debug" />
<exclude-output />
Expand All @@ -45,41 +44,36 @@
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/blame" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
Expand Down Expand Up @@ -107,15 +101,15 @@
</content>
<orderEntry type="jdk" jdkName="Android API 24 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="design-24.1.1" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-24.1.1" level="project" />
<orderEntry type="library" exported="" name="support-v4-24.1.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="hamcrest-core-1.3" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="junit-4.12" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-24.1.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-24.1.1" level="project" />
<orderEntry type="library" exported="" name="animated-vector-drawable-24.1.1" level="project" />
<orderEntry type="library" exported="" name="support-vector-drawable-24.1.1" level="project" />
<orderEntry type="library" exported="" name="com.android.support:support-annotations:24.1.1@jar" level="project" />
<orderEntry type="library" exported="" name="com.android.support:support-vector-drawable-24.1.1" level="project" />
<orderEntry type="library" exported="" name="com.android.support:support-v4-24.1.1" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="org.hamcrest:hamcrest-core:1.3@jar" level="project" />
<orderEntry type="library" exported="" scope="TEST" name="junit:junit:4.12@jar" level="project" />
<orderEntry type="library" exported="" name="com.android.support:animated-vector-drawable-24.1.1" level="project" />
<orderEntry type="library" exported="" name="com.android.support:recyclerview-v7-24.1.1" level="project" />
<orderEntry type="library" exported="" name="com.android.support:appcompat-v7-24.1.1" level="project" />
<orderEntry type="library" exported="" name="com.android.support:design-24.1.1" level="project" />
<orderEntry type="module" module-name="topsnackbar" exported="" />
</component>
</module>
25 changes: 25 additions & 0 deletions app/src/main/java/com/androidadvance/tsnackbar/DemoCustomView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.androidadvance.tsnackbar;

import android.content.Context;
import android.view.LayoutInflater;
import android.widget.LinearLayout;
import android.widget.Button;
import android.widget.TextView;

public class DemoCustomView extends LinearLayout {
public Button CloseButton;

public DemoCustomView(Context context) {
super(context);

LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

inflater.inflate(R.layout.demo_custom_view_include, this, true);

CloseButton = (Button) findViewById(R.id.demo_close_btn);
}



}
69 changes: 67 additions & 2 deletions app/src/main/java/com/androidadvance/tsnackbar/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ protected void onCreate(Bundle savedInstanceState) {
Button button_example_4 = (Button) findViewById(R.id.button_example_4);
Button button_example_5 = (Button) findViewById(R.id.button_example_5);
Button button_example_6 = (Button) findViewById(R.id.button_example_6);
Button button_example_7 = (Button) findViewById(R.id.button_example_7);
Button button_example_8 = (Button) findViewById(R.id.button_example_8);


relative_layout_main = (RelativeLayout) findViewById(R.id.relative_layout_main);
Expand All @@ -44,7 +46,6 @@ public void onClick(View v) {
@Override
public void onClick(View v) {


TSnackbar snackbar = TSnackbar
.make(relative_layout_main, "Had a snack at Snackbar", TSnackbar.LENGTH_LONG)
.setAction("Undo", new View.OnClickListener() {
Expand Down Expand Up @@ -74,7 +75,7 @@ public void onClick(View v) {
.setAction("Action", new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("CLICKED Action", "CLIDKED Action");
Log.d("CLICKED Action", "CLICKED Action");
}
});
snackbar.setActionTextColor(Color.WHITE);
Expand Down Expand Up @@ -143,5 +144,69 @@ public void onClick(View v) {

}
});

button_example_7.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {


final TSnackbar snackbar = TSnackbar
.make(relative_layout_main, "Had a snack at Snackbar", TSnackbar.LENGTH_INDEFINITE);

snackbar.setAction("Action", new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.d("CLICKED Action", "CLICKED Action");
}
}).setAction("Close", new View.OnClickListener() {
@Override
public void onClick(View v) {
snackbar.dismiss();
Log.d("CLICKED Close", "CLICKED Close");
}
});


snackbar.setActionTextColor(Color.LTGRAY,0);
snackbar.setActionTextColor(Color.RED,1);
snackbar.setCancelable(false); // Will not dismiss snackbar automatically when tapping on an action. Explicit dismiss required.

snackbar.addIcon(R.mipmap.ic_core, 200);
View snackbarView = snackbar.getView();
snackbarView.setBackgroundColor(Color.parseColor("#555555"));
TextView textView = (TextView) snackbarView.findViewById(com.androidadvance.topsnackbar.R.id.snackbar_text);
textView.setTextColor(Color.WHITE);
snackbar.show();

}
});

button_example_8.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

final TSnackbar snackbar = TSnackbar
.make(relative_layout_main, "Had a snack at Snackbar", TSnackbar.LENGTH_INDEFINITE);

DemoCustomView demoView = new DemoCustomView(MainActivity.this);
demoView.CloseButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
snackbar.dismiss();
Log.d("CLICKED Close", "CLICKED Close");
}
});

snackbar.setView(demoView); // Inflate a custom view to the Actions side of the Snackbar
snackbar.setCancelable(false); // Will not dismiss snackbar automatically when tapping on an action. Explicit dismiss required.

snackbar.addIcon(R.mipmap.ic_core, 200);
View snackbarView = snackbar.getView();
snackbarView.setBackgroundColor(Color.parseColor("#555555"));
TextView textView = (TextView) snackbarView.findViewById(com.androidadvance.topsnackbar.R.id.snackbar_text);
textView.setTextColor(Color.WHITE);
snackbar.show();

}
});
}
}
24 changes: 24 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,30 @@
android:id="@+id/button_example_6"
android:layout_weight="1" />
</LinearLayout>

<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:gravity="bottom"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">

<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Multiple Actions"
android:id="@+id/button_example_7"
android:layout_weight="1" />

<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Custom View"
android:id="@+id/button_example_8"
android:layout_weight="1" />
</LinearLayout>
</LinearLayout>

</RelativeLayout>
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/layout/demo_custom_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<view xmlns:android="http://schemas.android.com/apk/res/android"
class="com.androidadvance.topsnackbar.TSnackbar$DemoCustomView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
34 changes: 34 additions & 0 deletions app/src/main/res/layout/demo_custom_view_include.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>

<ProgressBar
android:id="@+id/indeterminateBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:paddingTop="14dp"
android:layout_weight="1"
/>

<Button xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/demo_close_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="@dimen/design_snackbar_extra_spacing_horizontal"
android:layout_marginStart="@dimen/design_snackbar_extra_spacing_horizontal"
android:layout_gravity="center_horizontal"
android:paddingTop="@dimen/design_snackbar_padding_vertical"
android:paddingBottom="@dimen/design_snackbar_padding_vertical"
android:paddingLeft="@dimen/design_snackbar_padding_horizontal"
android:paddingRight="@dimen/design_snackbar_padding_horizontal"
android:visibility="visible"
android:textColor="#FF0000"
android:text="Close"
style="?attr/borderlessButtonStyle" />
</LinearLayout>
Loading