Thursday, 19 February 2015

Logan Square


The fastest JSON parsing and serializing library available for Android. Based on Jackson's streaming API, LoganSquare is able to consistently outperform GSON and Jackson's Databind library by 400% or more. By relying on compile-time annotation processing to generate code, you know that your JSON will parse and serialize faster than any other method available.
By using this library, you'll be able to utilize the power of Jackson's streaming API without having to code tedius, low-level code involving JsonParsers orJsonGenerators. Instead, just annotate your model objects as a @JsonObject and your fields as @JsonFields and we'll do the heavy lifting for you.
Don't believe it could improve upon Jackson Databind's or GSON's performance that much? Well, then check out the nifty graphs below for yourself. Not convinced? Feel free to build and run the BenchmarkDemo app included in this repository.


Note that Gradle is the only supported build configuration for LoganSquare. To add the library to your app's build.gradle file.
  apply plugin: ''

  dependencies {
    apt 'com.bluelinelabs:logansquare-compiler:1.0.3'
    compile 'com.bluelinelabs:logansquare:1.0.3'
For the curious, the first line adds the apt plugin, which is what allows us to do compile-time annotation processing. The first dependency is what tells Gradle to process your JSON annotations, and the second dependency is our tiny 19kb runtime library that interfaces with the generated code for you.


Using LoganSquare is about as easy as it gets. Here are a few docs to get you started:


Like all libraries that generate dynamic code, Proguard might think some classes are unused and remove them. To prevent this, the following lines can be added to your proguard config file.
-keep class com.bluelinelabs.logansquare.** { *; }
-keep class **$$JsonObjectMapper { *; }

Why LoganSquare?

We're BlueLine Labs, a mobile app development company based in Chicago. We love this city so much that we named our company after the blue line of the iconic 'L.' And what's one of the most popular stops on the blue line? Well, that would be Logan Square of course. Does it have anything to do with JSON? Nope, but we're okay with that.

Android Random Color

Android Random Color

Inspired by David Merfield's randomColor.js. And onevcat's RandomColorSwift It is a ported version to Android. You can use the library to generate attractive random colors on Android.
See the demo and site to know why does this exist.


dependencies {
    compile 'com.github.lzyzsd.randomcolor:library:1.0.0'


// Returns a random int color value

RandomColor randomColor = new RandomColor();
int color = randomColor.randomColor();

// Returns an array of 10 random color values

RandomColor randomColor = new RandomColor();
int[] color = randomColor.randomColor(10);

//This lib also predefine some colors, so than you can random color by these predefined colors

// Returns an array of ten green colors

randomColor.random(RandomColor.Color.GREEN, 10);

// Returns a random color use hue, saturation, luminosity
// saturation has two kinds of value: RANDOM, MONOCHROME
// luminosity has for kinds of value: BRIGHT, LIGHT, DARK, RANDOM

randomColor(int value, SaturationType saturationType, Luminosity luminosity)

Mini Equalizer Library for Android

Mini Equalizer Library for Android

This Android Library project is created to let you use a animated equalizer inside your music related apps.

How to use it

Add this to your dependencies:
compile 'com.github.claucookie.miniequalizer:library:1.0.0'




There is some custom attributes you can adjust from the xml:
  • foregroundColor : the equalizer bars color (default is black)
  • animDuration : (millisecs) the animation follows a pattern and the number of loops is infinite. To set the duration of each loop, use this attribute.


Initialization + animation

To start animating the equalizer you should add:
EqualizerView equalizer = (EqualizerView) findViewById(;
equalizer.animateBars(); // Whenever you want to tart the animation
equalizer.stopBars(); // When you want equalizer stops animating

Monday, 16 February 2015

You Tube Player Activity


Simply pass a url to play youtube video on new activity. It supports screen orientation, media volume control and etc.

Set Up AndroidManifest.xml

<uses-permission android:name="android.permission.INTERNET" />

    android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" />

    android:value="your_google_api_key" />


Intent intent = new Intent(MainActivity.this, YouTubePlayerActivity.class);

// Youtube video ID or Url (Required)
intent.putExtra(YouTubePlayerActivity.EXTRA_VIDEO_ID, "iS1g8G_njx8");
// These kind of url can be parsed!!
intent.putExtra(YouTubePlayerActivity.EXTRA_VIDEO_URL, "");

// Show audio interface when user adjust volume
// true for default
intent.putExtra(YouTubePlayerActivity.EXTRA_SHOW_AUDIO_UI, true);

// If the video is not playable, use Youtube app or Internet Browser to play it
// true for default
intent.putExtra(YouTubePlayerActivity.EXTRA_HANDLE_ERROR, true);

// Animation when closing youtubeplayeractivity (none for default)
intent.putExtra(YouTubePlayerActivity.EXTRA_ANIM_ENTER, R.anim.fade_in);
intent.putExtra(YouTubePlayerActivity.EXTRA_ANIM_EXIT, R.anim.fade_out);



This util helps to retrieve youtube video id from youtube url or vice versa. Reference
String vidoeId = YoutubeUrlParser.getVideoId(videoUrl);
String vidoeUrl = YoutubeUrlParser.getVideoId(videoId);

Wonder Adapter


How many times do you copy ArrayAdapter, CursorAdapter and ViewHolders code? I've developed this library based mostly on the idea of UniversalAdapter library, but I've implemented a few improvements like ViewHolder pattern, multi view and cursor compatibility.


You just have to use the adapter that fits better to your needs. For now, there are only 3 wonder adapters you can use:
  • WArrayAdapter
  • WBaseAdapter
  • WCursorAdapter
Steps to use any of these adapters within a ListView:
  1. Create Custom Holder and let implement SingleWonder, MultiWonder or CursorWonder depending on the Adapter we want to use with. ..* T is the class of the item we want to show. ..* W the Holder class.
  2. Basic methods to implement (on single views): ..* W newInstance() returns an instance of W(holder) for every row in the list. Our holder contains row view fields initialized. ..*void bind(...) needed to draw desired object fields on the initialized view fields contained inside our class W. ..* View inflateView(...) needs explanation? :-).
Example: ListView with array list of items within a single row view
WArrayAdapter<Wonder, SingleViewHolder> adapter = new WArrayAdapter(this, getData(cursor), new SingleViewHolder());
and our SingleViewHolder implementation:
public class SingleViewHolder implements SingleWonder<Wonder, SingleViewHolder> {

  // UI
  @InjectView( ImageView imageView;
  @InjectView( TextView titleView;

  @Override public SingleViewHolder newInstance() {
    return new SingleViewHolder();

  @Override public void bind(Context context, Wonder item) {

  @Override public View inflateView(LayoutInflater inflater, ViewGroup parent) {
    View view = inflater.inflate(R.layout.row_wonder, parent, false);
    ButterKnife.inject(this, view);
    return view;

I've used Jake Wharton's Butterknife library to avoid using findViewById on every view in our row layout :-)
Check the code for full demo samples.

Crop Image View


An ImageView that supports different kind of cropping rather than the only Android is currently supporting: centerCrop
Using this library, you can crop your desired image by sides described below:
Crop options
Development idea borns at the point in [Kerad Games] we needed images cropped by somewhere no matter the image size.


Step 1

dependencies {
   compile ''

Step 2

Define in xml:
   custom:crop="value" />
where value can take values
Or in code:
CropImageView cropImageView = new CropImageView(CropActivity.this);
final Resources res = getResources();
final CropImageView.CropType cropType = imageCrops[position];

Friday, 13 February 2015

Image Blurring


Android Blurring Image (Bitmap) By Java And JNI.


  • RenderScript
    • Call Android's RenderScript to blur image
    • Speed is generally, with direct blur little difference in the Java layer
    • This need Android >= 4.4
  • Fast Blur
    • Call Java class to blur iamge
    • Fast Blur is blurring project's methods
    • Fast Blur is stack blur
  • JniArray
    • Fuzzy method is blur C language implementation of the stack blur
    • After the blur JNI layer, and then back to the blur data
    • In the Java layer of class parsed pixel array passed to JNI layer
    • After the blur back to the Array
  • JniBitMap
    • Fuzzy method is fuzzy C language implementation of the stack blur
    • After the blur JNI layer, and then back to the blur data
    • After the blur back to the Bitmap

Parallax View Pager


An easy-to-use ViewPager subclass with parallax background.
Setup requires little extra effort, using the ParallaxViewPager is just like using a standard ViewPager, with the same adapter. Of course, there's no silver bullet - the developer has to supply a background tailored to the current needs (eg. the number of items in the adapter and the size of the ViewPager). Check out this gif and this blog post to see what it's all about.
  1. Include it in your project as a Gradle dependency:
  2.     dependencies {
            compile 'com.andraskindler.parallaxviewpager:parallaxviewpager:0.3.1'
    1. Create a ParallaxViewPager programmatically or in a layout xml.
    2. Set the background via xml or one of the following methods:
      • setBackgroundResource(int resid)
      • setBackground(Drawable background) or setBackgroundDrawable(Drawable background)
      • setBackground(Bitmap bitmap)
    3. (Optional) Specify how the view should scale the background with the setScaleType(final int scaleType) method. Choose from the following parameters:
      • FIT_HEIGHT means the height of the image is resized to matched the height of the View, also stretching the width to keep the aspect ratio. The non-visible part of the bitmap is divided into equal parts, each of them sliding in at the proper position. This is the default value.
      • FIT_WIDTH means the width of the background image is divided into equal chunks, each taking up the whole width of the screen. This mode is not the usual parallax-effect, as the speed of the background scrolling equals the speed of the views.
    4. (Optional) Set the amount of overlapping with the setOverlapPercentage(final float percentage) method. This is a number between 0 and 1, the smaller it is, the slower is the background scrolling. The default value is 50 percent. This only works with FIT_HEIGHT.

An example, inside the 
onCreate() of an activity:

  1.     //...
        final ParallaxViewPager parallaxViewPager = new ParallaxViewPager(this);
        parallaxViewPager.setAdapter(new MyPagerAdapter());

Circle Avatar Image View


Subclass of ImageView to create a circle avatar image view with user name initial image view.

XML (Use Circle avatar image view)


XML (Use user name initial view) output 'SJ'

        app:name="steve jobs"
You may use the following properties in your XML to customize your DSAvataImageView.

  • app:border (boolean) -> default true
  • app:border_color (color) -> default GRAY
  • app:border_width (dimension) -> default 2dp
  • app:name (String) -> default
  • app:background_color (color) -> default WHITE
  • app:text_color (color) -> default GRAY ###JAVA (Use Circle avatar image view)
    DSAvatarImageView avataImageView=getView(convertView,;

JAVA (Use user name initial view) output 'SJ'

    DSAvatarImageView avataImageView=getView(convertView,;
    avataImageView.setName("steve jobs")