Skip to content

santoshmodi/Skittles

 
 

Repository files navigation

#Skittles Android Arsenal Build Status Download

A simple,clean api for adding PushBullet style skittles to your app for more material design glory.This library uses the FloatingActionButton provided in the android design support library

##Guide (Sample)

First some housekeeping code:

Use SkittleLayout as a root view in your layouts

<snow.skittles.SkittleLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/skittleLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:mainSkittleColor="@color/material_deep_teal_500"
app:mainSkittleIcon="@drawable/ic_android_white_18dp"
tools:context=".MainActivity">

<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/appBarMaxHeight"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
...

</snow.skittles.SkittleLayout>

Some further housekeeping...

Declare a SkittleBuilder,used to add skittles and pass the root SkittleLayout to it

SkittleLayout skittleLayout = (SkittleLayout) findViewById(R.id.skittleLayout);
SkittleBuilder skittleBuilder = new SkittleBuilder(this, skittleLayout, false, R.color.material_deep_purple_500, R.color.material_deep_teal_500);

Now for the fun part

Add skittles to your activity/fragment

skittleBuilder.addSkittle(R.drawable.lannister_icon, R.color.lannister);
skittleBuilder.addSkittle(R.drawable.barratheon_icon, R.color.barratheon);
skittleBuilder.addSkittle(R.drawable.stark_icon, R.color.stark);

A bit more work for adding Text Skittle

TextSkittle textSkittle = skittleBuilder.makeTextSkittle
(R.drawable.lannister_icon, getResources().getString(R.string.house_lannister), R.color.lannister);
textSkittle.setTextBackgroundColor(R.color.textBackground);
textSkittle.setTextColor(android.R.color.black);
skittleBuilder.addTextSkittle(textSkittle);

Flexible callback for clicks:

  • Add a click listener(SkittleBuilder.SkittleClickListener) to the SkittleBuilder object skittleBuilder.setSkittleListener(this);

  • This exposes two methods for Skittle and TextSkittle click events for convenience

void onSkittleClick(Skittle skittle);

void onTextSkittleClick(TextSkittle textSkittle);

Use skittle.getPosition() which return the position of the clicked skittle starting from 1 and starting from bottom

public void onSkittleClick(Skittle skittle) {

  switch (skittle.getPosition()) {
    case 1:
    Toast.makeText(this, "Skittle 1", Toast.LENGTH_LONG).show();
    break;
    case 2:
    Toast.makeText(this, "Skittle 2", Toast.LENGTH_LONG).show();
    break;
  }

}

Similarly for Text Skittle

public void onTextSkittleClick(TextSkittle textSkittle) {

  switch (textSkittle.getPosition()) {
    case 1:
    Toast.makeText(this, "Skittle 1", Toast.LENGTH_LONG).show();
    break;
    case 2:
    Toast.makeText(this, "Skittle 2", Toast.LENGTH_LONG).show();
    break;
  }
}

##Snackbar Support

When using snackbars ensure that you use SkittleContainer

Snackbar.make(skittleLayout.getSkittleContainer(), "Skittle Pressed", Snackbar.LENGTH_LONG)
.show();

##Gradle

dependencies{
compile 'com.rlj.library:skittles:1.0.1'
}

See the Sample and JavaDoc for further guidance

##Upcoming

  • Better support for animations
  • Option for adding skittles by xml (inspired by Navigation View)
  • Better support for most versions

#Taste the rainbow ![Skittles](art/Taste the rainbow.jpg)

About

PushButllet style skittles for android made dead-easy

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%