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

Dev into master #7

Merged
merged 2 commits into from
Sep 9, 2014
Merged
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
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
* Swipe down to dismiss all notifications as per documentation
* Backwards compatible to 2.3.x

![Snackbar Screenshot via Google](http://material-design.storage.googleapis.com/images/components-toasts-specs-spec_toast_03_1_large_mdpi.png)
![SnackBar Screenshot via Google](http://material-design.storage.googleapis.com/images/components-toasts-specs-spec_toast_03_1_large_mdpi.png)


[![Snackbar on Google Play](http://developer.android.com/images/brand/en_generic_rgb_wo_60.png)](https://play.google.com/store/apps/details?id=com.mrengineer13.snackbar.sample)
[![SnackBar on Google Play](http://developer.android.com/images/brand/en_generic_rgb_wo_60.png)](https://play.google.com/store/apps/details?id=com.mrengineer13.snackbar.sample)

# Usage
##1. Adding Snacks to your project
##1. Add SnackBar to your project
###Maven
Just add the following to your `build.gradle`.

Expand All @@ -46,7 +46,6 @@ Just add the following to your `build.gradle`.


# Contribution
=============
## Pull requests are welcome!

Feel free to contribute to SnackBar.
Expand All @@ -55,4 +54,3 @@ If you've implemented a bug fix or new feature, just create a pull request.

If you have a bug to report a feature to request or have other questions, [file an issue](https://github.com/MrEngineer13/SnackBar/issues/new). I'll try to answer as soon as I can.


18 changes: 0 additions & 18 deletions gradle.properties

This file was deleted.

4 changes: 2 additions & 2 deletions sample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.mrengineer13.snackbar.sample"
minSdkVersion 9
targetSdkVersion 20
versionCode 3
versionName "1.2"
versionCode 4
versionName "1.3"
}

packagingOptions {
Expand Down
41 changes: 17 additions & 24 deletions sample/sample.iml
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
</facet>
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugJava" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
<option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugTestSources" />
<option name="SELECTED_BUILD_VARIANT" value="release" />
<option name="ASSEMBLE_TASK_NAME" value="assembleRelease" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileReleaseJava" />
<option name="SOURCE_GEN_TASK_NAME" value="generateReleaseSources" />
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
Expand All @@ -23,26 +21,21 @@
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<output url="file://$MODULE_DIR$/build/intermediates/classes/release" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/test/debug" isTestSource="true" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/test/debug" type="java-test-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<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$/build/generated/source/r/release" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/release" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/release" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/release" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/release" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/release/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/release/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/release/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/release/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/release/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/release/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/release/rs" isTestSource="false" />
<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" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
package com.mrengineer13.snackbar.sample;

import android.os.Bundle;
import android.os.Parcelable;
import android.support.v7.app.ActionBarActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Spinner;

import com.github.mrengineer13.snackbar.SnackBar;

Expand All @@ -31,6 +31,16 @@ public class SnackBarActivity extends ActionBarActivity {

public static final String SAVED_COUNT = "SAVED_COUNT";

static final int SHORT_MSG = 0, LONG_MSG = 1;

static final int SHORT_SNACK = 0, MED_SNACK = 1, LONG_SNACK = 2;

static final int RED = 0, ORANGE = 1, YELLOW = 2, GREEN = 3, BLUE = 4, PURPLE = 5, PINK = 6, DEFAULT = 7, ALERT = 8, CONFIRM = 9, INFO = 10;

static final int ACTION_BTN = 0, NO_ACTION_BTN = 1;

private Spinner mMsgLengthOptions, mDurationOptions, mActionBtnOptions, mActionBtnColorOptions;

private String[] mSnackNames;

private int mSnackIndex = 0;
Expand All @@ -44,6 +54,11 @@ protected void onCreate(Bundle savedInstanceState) {

mSnackNames = getResources().getStringArray(R.array.snack_names);
mSnackBar = new SnackBar(this);

mMsgLengthOptions = (Spinner) findViewById(R.id.message_length_selector);
mDurationOptions = (Spinner) findViewById(R.id.snack_duration_selector);
mActionBtnOptions = (Spinner) findViewById(R.id.action_btn_presence_selector);
mActionBtnColorOptions = (Spinner) findViewById(R.id.action_btn_color);
}


Expand All @@ -66,19 +81,82 @@ public boolean onOptionsItemSelected(MenuItem item) {
return super.onOptionsItemSelected(item);
}

public void onSnackClicked(View v){
mSnackBar.show(mSnackNames[mSnackIndex++ % mSnackNames.length], SnackBar.MED_SNACK);
}
public void onCreateClicked(View view){
String message = "";
short duration = 0;
SnackBar.Style style = SnackBar.Style.DEFAULT;

int selectedMessageLength = mMsgLengthOptions.getSelectedItemPosition();
switch (selectedMessageLength){
case SHORT_MSG:
message = "This is a one-line message.";
break;
case LONG_MSG:
message = "This message is a lot longer, it should stretch at least two lines. ";
break;
}

int selectedDuration = mDurationOptions.getSelectedItemPosition();
switch (selectedDuration){
case SHORT_SNACK:
duration = SnackBar.SHORT_SNACK;
break;
case MED_SNACK:
duration = SnackBar.MED_SNACK;
break;
case LONG_SNACK:
duration = SnackBar.LONG_SNACK;
break;
}

int selectedActionBtnColor = mActionBtnColorOptions.getSelectedItemPosition();
switch (selectedActionBtnColor){
case RED:
style = SnackBar.Style.RED;
break;
case ORANGE:
style = SnackBar.Style.ORANGE;
break;
case YELLOW:
style = SnackBar.Style.YELLOW;
break;
case GREEN:
style = SnackBar.Style.GREEN;
break;
case BLUE:
style = SnackBar.Style.BLUE;
break;
case PURPLE:
style = SnackBar.Style.PURPLE;
break;
case PINK:
style = SnackBar.Style.PINK;
break;
case DEFAULT:
style = SnackBar.Style.DEFAULT;
break;
case ALERT:
style = SnackBar.Style.ALERT;
break;
case CONFIRM:
style = SnackBar.Style.CONFIRM;
break;
case INFO:
style = SnackBar.Style.INFO;
break;
}

int selectedActionBtnExistance = mActionBtnOptions.getSelectedItemPosition();
switch (selectedActionBtnExistance){
case ACTION_BTN:
mSnackBar.show(message, "Action", style, duration);
break;
case NO_ACTION_BTN:
mSnackBar.show(message, duration);
break;
}


public void onPourSyrupClicked(View v){
mSnackBar.show(String.format(getString(R.string.syrup_added), mSnackNames[mSnackIndex++ % mSnackNames.length].toLowerCase()), getString(R.string.undo), SnackBar.Style.INFO);
mSnackBar.setOnClickListener(new SnackBar.OnMessageClickListener() {
@Override
public void onMessageClick(Parcelable token) {
mSnackBar.clear();
mSnackBar.show(getString(R.string.crisis_averted));
}
});
}

@Override
Expand Down
87 changes: 74 additions & 13 deletions sample/src/main/res/layout/activity_snack_bar.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,82 @@
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".SnackBarActivity">

<Button
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I'm Hungry"
android:id="@+id/button"
android:onClick="onSnackClicked"
android:layout_centerInParent="true" />
android:orientation="vertical"
android:layout_centerInParent="true">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pour Syrup"
android:id="@+id/button2"
android:layout_centerInParent="true"
android:layout_below="@+id/button"
android:onClick="onPourSyrupClicked" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Build a SnackBar with:"
android:layout_marginBottom="24dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Message Length" />

<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/message_length_selector"
android:entries="@array/text_length"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Duration" />

<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/snack_duration_selector"
android:entries="@array/snack_duration"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Action button presence" />

<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/action_btn_presence_selector"
android:entries="@array/action_present"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Action button color" />

<Spinner
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/action_btn_color"
android:entries="@array/action_color"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Create"
android:id="@+id/button3"
android:onClick="onCreateClicked"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:paddingLeft="24dp"
android:paddingRight="24dp" />

</LinearLayout>

</RelativeLayout>
29 changes: 29 additions & 0 deletions sample/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="text_length">
<item>Short message</item>
<item>Long message</item>
</string-array>
<string-array name="snack_duration">
<item>Short</item>
<item>Medium</item>
<item>Long</item>
</string-array>
<string-array name="action_present">
<item>Action button present</item>
<item>No action button</item>
</string-array>
<string-array name="action_color">
<item>Red</item>
<item>Orange</item>
<item>Yellow</item>
<item>Green</item>
<item>Blue</item>
<item>Purple</item>
<item>Pink</item>
<item>Default</item>
<item>Alert</item>
<item>Confirm</item>
<item>Info</item>
</string-array>
</resources>
Loading