Saturday, February 22, 2014

Android: Slider from right to left similar to Navigation Drawer


Google added new pattern for displaying app’s main navigation option as Navigation Drawer.

What is Navigation Drawer?

The navigation drawer is a panel that transitions in from the left edge of the screen and displays the app’s main navigation options.

Displaying the navigation drawer

The user can bring the navigation drawer onto the screen by swiping from the left edge of the screen or by touching the application icon on the action bar.
As the navigation drawer expands, it overlays the content but not the action bar. When the drawer is fully extended, the action bar adjusts its content by replacing the current action bar title with the app name and removing all actions that are contextual to the view underneath the navigation drawer. The overflow menu with the standard action items for Settings and Help remains visible.
The usage of the pattern helps in lot of ways as follows
  • You don't want to give up the vertical screen real estate for a dedicated tab bar.
  • You have a large number of top-level views.
  • You want to provide direct access to screens on lower levels.
  • You want to provide quick navigation to views which don't have direct relationships between each other.
  • You have particularly deep navigation branches

Dismissing the navigation drawer

When the navigation drawer is expanded, the user can dismiss it in one of four ways:
  • Touching the content outside the navigation drawer
  • Swiping to the left anywhere on the screen (including edge swipe from right)
  • Touching the app icon/title in the action bar
  • Pressing Back
We have lot of questions for slider menus?

For displaying contents like navigation option we have navigation drawers provided by Google but options like filters, notifications, downloads etc.., we have any options in android?

Whether we have any option like navigation drawer sliding from right to left?

Answer: yes, we have lot of third party libraries which can help us from achieving this.

One of the *.jar named slider.jar I found recently, which I felt very easy to achieve the slider from right to left.
There are some pre defined funstions in "slider.jar" which help us to create fb style slide menu.
  • setLeftBehindContentView(left_layout) is used to set left menu.
  • setRightBehindContentView(right_layout) is used to set right menu.
  •  toggleLeftDrawer() is used to show the left menu.
  • toggleRightDrawer() is used to show the right menu.
Usage:

It's very easy to use the slider in your project.
Remember two things.
  1. Create *.xml (eg:  slider_right_2_left.xml) where your content can be displayed.
  2. Use the xml file in the program
// Initialize variable
SimpleSideDrawer slide_me;

// declaration and setting the content *.xml to the View
slide_me = new SimpleSideDrawer(this);
slide_me.setRightBehindContentView(R.layout.slider_right_2_left);

// Use for slide from right to left
slide_me.toggleRightDrawer();
In the current example, we have used the method in onOptionsItemSelected override method.



 



Thanks for reading :)
If you have any other quick thoughts/hints that you think people will find useful, feel free to leave a comment.

Friday, February 14, 2014

3rd Party Libraries for Android Developers

Benefits of third party library Building

  1. Less effort for app development.
  2. Quick implementaion.
  3. Reusable components

3rd Party Libraries
Usage

The Android Support Library package is a set of code libraries that provide backward-compatible versions of Android framework APIs as well as features that are only available through the library APIs. 

The Android Action Bar Style Generator allows you to easily create a simple, attractive and seamless custom action bar style for your Android application. It will generate all necessary nine patch assets plus associated XML drawables and styles which you can copy straight into your project.
Paging indicator widgets compatible with the ViewPager from the Android Support Library and ActionBarSherlock. Originally based on Patrik Ã…kerfeldt's ViewFlow.
ActionBarSherlock is an extension of the support library designed to facilitate the use of the action bar design pattern across all versions of Android with a single API.


Object Relational Mapping Lite (ORM Lite) provides some simple, lightweight functionality for persisting Java objects to SQL databases while avoiding the complexity and overhead of more standard ORM packages.
greenDAO is an open source project to help Android developers working with data stored in SQLite. 
probably the fastest ORM for Android

This project aims to provide a reusable instrument for asynchronous image loading, caching and displaying. It is originally based on Fedor Vlasov's project and has been vastly refactored and improved since then.

This project aims to provide a reusable pull to refresh widget for Android.


Spring for Android is a framework that is designed to provide components of the Spring family of projects for use in Android apps. Like all Spring projects, the real power of Spring for Android is found in how easily it can be extended.

Used for JSON parsing

Used for XML parsing

AChartEngine is a charting library for Android applications.  It currently supports the following chart types:
  • line chart
  • area chart
  • scatter chart
  • time chart
  • bar chart
  • pie chart
  • bubble chart
  • doughnut chart
  • range (high-low) bar chart
  • dial chart / gauge
  • combined (any combination of line, cubic line, scatter, bar, range bar, bubble) chart
  • cubic line chart

Android-Query (AQuery) is a light-weight library for doing asynchronous tasks and manipulating UI elements in Android. Our goal is to make Android coding simpler, easier, and more fun!
Scripting Layer for Android (SL4A) brings scripting languages to Android by allowing you to edit and execute scripts and interactive interpreters directly on the Android device. These scripts have access to many of the APIs available to full-fledged Android applications, but with a greatly simplified interface that makes it easy to get things done.

qPDF Toolkit is an Android Java SDK that allows app developers to quickly add PDF functionality to their Android apps.
aftek-RTMP-library
The library uses the Real time messaging protocol (RTMP) from Adobe for streaming audio, video and data over internet. This also facilitates Audio / video streaming, Remote procedure calls, Messaging and communication using shared objects.

A component for flip animation on Android, which is similar to the effect in Flipboard iPhone/Android





Thanks for all the 3rd party library developers...
There is an article which told about the tips of using 3rd party libraries 

1. Use Only Actively Maintained Libraries

Look at things like the date of the latest release, the number of developers contributing, and the sponsoring organizations.

2. Use Only Libraries With an Appropriate License

What’s appropriate for you obviously depends on your context. For instance, if you’re building and distributing a commercial, closed source application, you shouldn’t use any library that only comes with the GPL.

3. Limit the Amount of Code That Touches the Library

Use the Facade design pattern to wrap the library in your own interface. This has several advantages:
  • It allows you to easily replace the library with another, should the need arise
  • It documents what parts of the library you are actually using
  • It allows you to add functionality that the library should have provided but doesn’t, and do so in a logical place

4. Keep the Library Up-to-date

Many developers live by the rule “if it ain’t broke, don’t fix it”. However, you may not notice some of the things that are broken. For instance, many libraries contain security vulnerabilities that are fixed in later versions. You won’t notice these problems until a hacker breaches your application.

5. Write Regression Tests For the Library

If you’re regularly going to update the library, as I suggest, then you’d better know whether they broke anything in a new release. So you need to write some tests that prove the functionality that you want to use from the library.
As a bonus, these tests double as documentation on how to use the library.

6. Know What Libraries You Use

You should always be able to tell what libraries you are using at
any given moment, as well as their versions and licenses. You just never know when someone from the security team is going to call you about a critical vulnerability in a specific version of a library, or when the legal department suddenly decides to forbid the use of a certain license.

7. Take Ownership of the Library

Your application provides functionality to its users. They don’t care whether you build that functionality yourself, or whether you use a library. Not should they. When there is a problem anywhere in your code, you need to be able to fix it.
So think about how you are going to do that for the libraries you plan on using. Are the developing organizations responsive to bug reports? Do you have access to the source? Are the developing organizations willing to apply your patches? Does the license permit modifying the code for private use?


Some of the libraries which I am aware off. If you use/known one not listed here and you think people will find useful, feel free to leave a comment.

Friday, November 15, 2013

Android: Get iOS Style Badge App Icon


Android is not iOS and one should not try to make it so.
Android have its one way of showing notifications.
Still in Android, we have two options to do it:
1.    Use widget.  
2.    Change application / Launcher icon dynamically.

First approach:

App Widgets
App Widgets are miniature application views that can be embedded in other applications (such as the Home screen) and receive periodic updates. These views are referred to as Widgets in the user interface, and you can publish one with an App Widget provider. An application component that is able to hold other App Widgets is called an App Widget host.

The Basics
To create an App Widget, you need the following:
AppWidgetProviderInfo object
Describes the metadata for an App Widget, such as the App Widget's layout, update frequency, and the AppWidgetProvider class. This should be defined in XML.
AppWidgetProvider class implementation
Defines the basic methods that allow you to programmatically interface with the App Widget, based on broadcast events. Through it, you will receive broadcasts when the App Widget is updated, enabled, disabled and deleted.
View layout

Defines the initial layout for the App Widget, defined in XML.

Widget:
1.    Create a appwidget-provider xml name it as widget_badge_icon.xml and add it in xml folder
2.    Create a widget_badge_layout .xml as per need.
3.    Create a receiver in manifest file.
4.    Create BadgeNotificationWidget Class:

public class BadgeNotificationWidgetActivity extends AppWidgetProvider {
}

5.    Create BadgeService Service Class:

add the code snippet in our onHandleIntent method:

/**
 * Update ChangeAppIcon widget.
 */
RemoteViews remoteView = new RemoteViews(
                   getApplicationContext().getPackageName(),
                   R.layout.widget_badge_layout);

ComponentName componentName = new ComponentName(
                   getApplicationContext(),
                   BadgeNotificationWidgetActivity.class);

AppWidgetManager appWidgetManager = AppWidgetManager
                   .getInstance(getApplicationContext());

Log.d("BadgeNotificationWidgetActivity",
                   "BadgeService randomNo" + randomNo);
if (randomNo == 0) {
          remoteView.setViewVisibility(R.id.badgeNum, View.GONE);
} else {
          remoteView.setViewVisibility(R.id.badgeNum, View.VISIBLE);
}

remoteView.setTextViewText(R.id.badgeNum,
                   String.valueOf(randomNo));
// apply changes to widget
appWidgetManager.updateAppWidget(componentName, remoteView);

Output:



Second approach:
Even though it is not good approach to do but our goal is to get the badge on the app icon.
Android does not allow us to change the icons. The icons are fixed on an apk compilation as a part but still we can do if the pre-defined icons are in our drawable folders.
Aliases for an activity, named by the targetActivity attribute. The target must be in the same application as the alias and it must be declared before the alias in the manifest.

Programmatically we can enable or disable the activity-alias component by setComponentEnabledSetting method of PackageManger.

Set the enabled setting for a package component (activity, receiver, service, provider). This setting will override any enabled state which may have been set by the component in its manifest.
Parameters
componentName
The component to enable
newState
The new enabled state for the component. The legal values for this state are: COMPONENT_ENABLED_STATE_ENABLED, COMPONENT_ENABLED_STATE_DISABLED and COMPONENT_ENABLED_STATE_DEFAULT The last one removes the setting, thereby restoring the component's state to whatever was set in it's manifest (or enabled, by default).
flags
Optional behavior flags: DONT_KILL_APP or 0.


getPackageManager().setComponentEnabledSetting(
new ComponentName(this,
"com.vardhan.changeappicon.ChangeAppIconActivity-" + iconPosition),
          isIconEnable ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED
                             : PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
          PackageManager.DONT_KILL_APP);


Source Code: Here
Output:




sample source code for first approach : Badge Icon Using Widget


Improvements
If you want to see an example without changing the app icon and widget then, have a look @ Android ios Style Badge App Icon like facebook, whatsapp..... This example shows badge on app icon with small changes in the application. This example code supports from API level 9

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. feedback are welcome.