Wednesday, September 24, 2014

Android: Material Theme in Kitkat

Material Theme look and feel can be easily achieve in KitKat because of the new features Translucent UI in KitKat, where you have the ability to sit behind status and navigation bars

We can getting material theme look and feel in 2 ways.

1. We can write our own styles.xml and modify according to our needs.
2. Import SystemBarTint library and apply changes as per need.

First Approach using styles.xml:

We can build our own theme by setting with Translucent Theme in xml

If you are seeking more control over translucent decor, consider using a custom theme that extends something other than *.TranslucentDecor and use the following style properties in your theme:

 <item name="android:windowTranslucentStatus">true</item>  
 <item name="android:windowTranslucentNavigation">true</item>  

If your content does not need to be full bleed you can structure your layouts in such a way that the content will reside in an area of the screen that is not blocked by the status or navigation bar. To do this you would set android:fitsSystemWindows="true" on the content layout/view in your layout xml or in style.xml as
  <item name="android:fitsSystemWindows">true</item>.  
.
Add Some Color to the status bar, just set the windowBackground attribute in my theme.
 <item name="android:windowBackground">@color/window_bg</item>  

Second Approach Using SystemBarTine:

This library jgilfelt-SystemBarTint offers a simple way to create a background "tint" for the system bars. Internally even this library is depended on the Translucent  theme.


Source Code
You can download the source code by clicking here: MaterialThemeLookInKitKat.  This project is built using eclipse IDE. Unzip and import the project into Eclipse, it’s a good idea to use the Project by clean and rebuild from the project menu. This example is built using 2nd approach.

Output:



Thanks for reading :) 
Whether this post is helpful?

Have something to add to this post? If you have any other quick thoughts/hints that you think people will find useful? Share it in the comments.

Tuesday, September 23, 2014

Solution: Stuck @ installing apps from Google Play Store

Problem

If you are stuck at some percentage while installing apps from Google Play Store.

Reason

The reason behind this is Google Play Store transfers data in background to update itself. Without completing the background data transfer, Play Store won’t start downloading apps.
It will be showing progress bar/loading bar will be running and showing percentage but the download won’t start until your Google services job is finished.

Solution

Wait a few minutes until the Google Play Store is completely upgraded.

Even after, If the problem persists, then follow the steps below.

  • Go the play store and start installing application.
  • Now, minimize play Store and go to Settings  Apps  RUNNING
  • Find the Google Play services. Tap and stop all the Google Play Services.
  • Now Go back to play store again and your download will start and finishes... 

Thanks for reading :) 
Whether this post is helpful?

Have something to add to this post? If you have any other quick thoughts/hints that you think people will find useful? feedback are welcome.

Friday, September 12, 2014

Android: Image loading libraries Picasso vs Glide

This post is about image loading libraries, which could help us in avoiding complex codes.

Downloading of images, caching and reusing of images are know part of all the application and it became part of developers life. While doing this process, We need to consider few things...

  • Loading process should be asynchronously.
  • Image should display when it is loaded successfully, In case if it is not downloaded then placing some place holders.
  • Caching Image rather than downloading every time.

There are more libraries in the market which helps us in avoiding to do all these exercises and here I am going to discuss about Picasso and Glide. Where this two libraries looks similar in the way of implementation and Its easy to integrate in the middle of the application, since its a just a one line code to load image.

There are lot of features in the two libraries and few are listed below, where I can compare them easily.

Wednesday, September 10, 2014

Android Wear : Solution for "You cannot combine swipe dismissal and the action bar"

While running my first application in android wear in eclipse. I have faced with the exception.

Exception:
android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2197)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2258)
at android.app.ActivityThread.access$800(ActivityThread.java:138)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1209)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5026)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:602)
at dalvik.system.NativeStart.main(Native Method)
Caused by: android.util.AndroidRuntimeException: You cannot combine swipe dismissal and the action bar.
Workaround Solution:
There should be some SDK issues where it is behaving weirdly.
So, I have tried by removing android:targetSdkVersion and change the android:minSdkVersion as shown below it worked out for me.

Change to  
<uses-sdk android:minSdkVersion="8" /> 

from 
<uses-sdk android:minSdkVersion="20" android:targetSdkVersion="20" />



Monday, September 8, 2014

Glide, an Android media loading library...

Recently I have came across new image loader library Glide from iosched Git Code

Glide

Glide is a fast and efficient open source media management framework for Android that wraps media decoding, memory and disk caching, and resource pooling into a simple and easy to use interface.

Glide's primary focus is on making scrolling any kind of a list of images as smooth and fast as possible, but Glide is also effective for almost any case where you need to fetch, resize, and display a remote image.

Implementation / Usage

When we see the implementation of Glide. It looks similar to the Picasso.

Let Looks the implementation of Picasso and Glide.

Picasso.with(this).load("http://i.imgur.com/DvpvklR.png").into(imageView);

Glide.with(this).load("http://i.imgur.com/DvpvklR.png").into(imageView);

Using the Picasso or Glide are easy and straight forward.

Advantage of Glide here is... Inbuilt it supports caching...

Let us assume, I am having two ImageView where one is loaded with Picasso and othere with Glide as shown below.

Saturday, September 6, 2014

Android L: UI Widgets : RecyclerView

RecyclerView is a more advanced and flexible version of ListView. This widget is a container for large sets of views that can be recycled and scrolled very efficiently. Use the RecyclerView widget when you have lists with elements that change dynamically.

RecyclerView is easy to use, because it provides:
  • A layout manager for positioning items
  • Default animations for common item operations
You also have the flexibility to define custom layout managers and animations for this widget.

To use the RecyclerView widget, we have to specify an adapter and a layout manager.

LayoutManager

The LayoutManager is probably the most interesting part of the RecyclerView. This class is responsible for the layout of all child views. There is one default implementation available: LinearLayoutManager which you can use for vertical as well as horizontal lists. To create a custom layout, you extend the RecyclerView.LayoutManager class.

// use a linear layout manager
mLayoutManager = new LinearLayoutManager(this);
mRecyclerView.setLayoutManager(mLayoutManager);


// improve performance if you know that changes in content
// do not change the size of the RecyclerView
mRecyclerView.setHasFixedSize(true);

Animations

Animations for adding and removing items are enabled by default in RecyclerView.
use the RecyclerView.setItemAnimator method for animations, to customize just extend the RecyclerView.ItemAnimator class

Android provide DefaultItemAnimator and we can customize according to our needs.
mRecyclerView.setItemAnimator(new DefaultItemAnimator());

Adapter:

To create an adapter, you extend the RecyclerView.Adapter class.
The RecyclerView.Adapter class contains few notifyItemXXXX()methods. Which help us in modifying the View.

Two methods used in the example are insert and remove and they are
notifyItemInserted(position);
notifyItemRemoved(position);

mRecyclerView.setAdapter(mAdapter);

// insert or remove item from the view. This methods are in the adapter class.

public void addToList(String name) {
int position = 0;
if (mDataset.size() > 1) {
  position = new Random().nextInt(mDataset.size() - 1);
}
mDataset.add(position, name);
notifyItemInserted(position);
}

public void removeItemFromList(String name) {
int position = mDataset.indexOf(name);
if (position != -1) {
  mDataset.remove(position);
  notifyItemRemoved(position);
}
}



Source Code
You can download the source code by clicking here: Sample RecyclerView .  This project is built using eclipse IDE. Unzip and import the project into Eclipse, it’s a good idea to use the Project by clean and rebuild from the project menu.

Screenshot:
Initial screen with four items.

Added two rows to the recyclerView
Removed one item which is added from RecyclerView
Thanks for reading :) 
Whether this post is helpful?


Have something to add to this post? If you have any other quick thoughts/hints that you think people will find useful? Share it in the comments and feedback are welcome

Friday, September 5, 2014

Android: RecyclerView cannot be resolved to a type

RecyclerView cannot be resolved to a type? How to resolve it?

We need recyclerview-v7 Support Library to solve the issue. but how to get? letc check...

Check whether Recyclerview is existing in the SDK or not because it is a part of the support library.

If you're not find the folder “recyclerview-v7” in the following sdk directory "..\sdk\extras\android\m2repository\com\android\support" then follow the steps otherwise follow from step 3.

Steps to achieve:
  1. Select the latest Android SDK Tools, Platform-tools, and Build-tools.
  2. Select latest Android Support Library & Android Support Repository.
  3. After updating Android Support Repository from SDK Manager go to..\sdk\extras\android\m2repository\com\android\support\recyclerview-v7\21.0.0-rc1
  4. Unzip recyclerview-v7-21.0.0-rc1.aar
  5. After unzipping recyclerview-v7-21.0.0-rc1.aar you will get classes.jar
  6. rename classes.jar to recyclerView.jar for feature reference and add to your Android app under /lib folder
Overview:
RecyclerView updates and replaces ListView. It's claimed to be easier to use and feature performance improvements in dynamic views.

RecyclerView is easy to use, because it provides:
  • A layout manager for positioning items
  • Default animations for common item operations

The most important classes of the RecyclerView API.

Class
Usage
Adapter
The Adapter is also responsible for making a View for each item in the data set.
LayoutManager
A layout manager positions item views inside a RecyclerView and determines when to reuse item views that are no longer visible to the user.
ItemAnimator
Animations for adding and removing items are enabled by default in RecyclerView



Thanks for reading :)
Any suggestions can be added in comments. feedback are welcome.

Thursday, September 4, 2014

Android: Notification in L

Notification in Android L:

In L, notifications receive an important structural visual and functional update:
  • Visual changes to notifications as part of material design
  • Notifications are now available on the device lock screen, yet sensitive content can still be hidden behind it
  • A new presentation format called Heads-up for receiving high priority notifications while using the device
  • Cloud-synced notifications - act on a notification on your Android tablet and it is also dismissed on your phone.
  • And starting now (in Android 4.4W, API Level 20, the platform release for Android Wear), your notifications will bridge to Android Wear devices. You can extend the functionality of notifications on Wear in two different ways. First, you can add speech input and canned responses to Actions on Wear, allowing users to complete tasks from their wrists. Second, you can write Wear apps that hook into your notifications to go even further in terms of creating interactive experiences for users.

For more information of notifications ref android notifications.

Sample Code for showing notification

      /**  
       * Send a sample notification using the NotificationCompat API.  
       */  
      public void sendNotification(View view) {  
           Intent intent = new Intent(  
                     Intent.ACTION_VIEW,  
                     Uri.parse("http://developer.android.com/reference/android/app/Notification.html"));  
           PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,  
                     intent, 0);  
           NotificationCompat.Builder builder = new NotificationCompat.Builder(  
                     this);  
           builder.setSmallIcon(R.drawable.ic_stat_notification);  
           // Set the intent that will fire when the user taps the notification.  
           builder.setContentIntent(pendingIntent);  
           builder.setAutoCancel(true);  
           builder.setLargeIcon(BitmapFactory.decodeResource(getResources(),  
                     R.drawable.ic_launcher));  
           builder.setContentTitle("BasicNotifications Sample");  
           builder.setContentText("Time to learn about notifications!");  
           builder.setSubText("Tap to view documentation about notifications.");  
           NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);  
           notificationManager.notify(NOTIFICATION_ID, builder.build());  
      }  

Output:



In first pic, we can see the notification received in the status bar.
On drag of screen from top. We can see, how the basic notification appears.


Wednesday, September 3, 2014

Quick glance of Android L features

Android L

Android L is a next version of kitkat, Coming with new designs, features and updates...

Android L is Faster, better looking and more efficient.

Android L is going to change the way it looks with material design- These projects extend Android to the TV (Android TV), to the car (Android Auto) and to wearables (Android Wear), among others.

See the API overview for more information on the rest of the new and updated features. Lets look a quick view of all the API's.