Sunday, July 27, 2014

Android Supporting tools for Developers / Designers

This post is going to give some useful tools which android developers could be found easy during application development. I have listed down few useful tools below.

Tools Used for Designers / Developers


Android Button Maker is online tool to generate buttons code for Android Apps. Android API provide Drawable Resources where XML file defines geometric shape, including colors, border and gradients.
These button is generating based on shape drawable XML code which load faster compare to normal png buttons. You can customize button properties in setting panel and get source code.




Android uses Density Independent Pixel (dpi) values to scales the actual screen size. To get device pixel density use getResources().getDisplayMetrics().density;


Open Source Utilities to Optimize PNG Images

There are free tools such as OptiPNG or PNGCrush or TinyPNG for optimizing PNG image files. These tools are open-source and use command line utilities for optimizing PNG images. They can compress the image by using various combinations of algorithms, such as changing the bit depth, replacing unwanted chucks of data with text, delta filters, and so forth to provide the smallest compressed output.

If your app is highly depend on art/creative then you should think over optimizing and shrinking art/creative to decrease file size, it would help you to decrease APK size.



A web-based set of tools for generating graphics and other assets that would eventually be in an Android application's res/ directory.
Currently available asset generators area available for:
OTHER GENERATORS MISCELLANEOUS ASSET CREATION TOOLS
COMMUNITY TOOLS SIMILAR TOOLS FROM THE OPEN SOURCE COMMUNITY

Tools Used for Developers


During development you typically add a lot of resources such as files, layouts, or drawables. As you go back and made changes and improvements, some of these resources are no longer used, and get left in your code. To detect such unused resources and remove them from your APK file, use the android-unused-resources tool. It scans your project and identifies unused resources. Removing them minimizes the build time and reduces the APK file size.



The Android Layout Finder helps you create the code that ties your Android UI and Java code together.
It's real easy! Just paste your Android XML layout code in the first text field, pick the views that you need, and your code is automatically generated for you.
No more typing out all those nearly identical findViewById() and findFragmentById() calls in your activities or fragments whenever you change your Android layouts.
This tools having special output settings, which helps us in generating code type using RoboGuice, member variable and so on.




Similar to the above layout to Java code generator, we have one android-code-generator-plugin for eclipse which generates code from xml, which Generating Activity Class code based on XML layout.


Generate Plain Old Java Objects from JSON or JSON-Schema.
This tools helps in giving annotation style like Jackson 2.x, Jackson 1.x, Gson.
Note: Your input Json Cannot be more than 51200 characters.




There are some other tool for Json to POJO conversion, but it is not like the above one, we can't copy and paste the Json, rather than we should give the json url as input. For more info check Jsongen.byingtondesign


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, July 11, 2014

Android: iOS Style Badge App Icon for Sony, Samsung and HTC devices

This post is continue to one of my old post Android Get iOS Style Badge App Icon

Know a days we are seeing facebook,whatsapp and lots of apps are using badges on the app icon and  they are not replacing any app icon and they are able to achieve badge on app icon and we should be having question, How it is possible?

iOS style badge icon is achieved in android by few manufactures (Sony, Samsung, HTC...) but the way of implementation is different from each one of the manufacture for the badge on app icon.

Before implementing the badge on app icon, check the manufacture and then support.

// The manufacturer of the product/hardware.
Build.MANUFACTURER;

Lets go with each of the manufacture implementation:
Sony:

Manifest File changes:

 <uses-permission android:name="com.sonyericsson.home.permission.BROADCAST_BADGE" />  

Code Changes:

 try {  
      intent.setAction("com.sonyericsson.home.action.UPDATE_BADGE");  
      intent.putExtra("com.sonyericsson.home.intent.extra.badge.ACTIVITY_NAME", "com.vardhan.notificationbadgesample.MainActivity");  
      intent.putExtra("com.sonyericsson.home.intent.extra.badge.SHOW_MESSAGE", true);  
      intent.putExtra("com.sonyericsson.home.intent.extra.badge.MESSAGE", badgeno);  
      intent.putExtra("com.sonyericsson.home.intent.extra.badge.PACKAGE_NAME", "com.vardhan.notificationbadgesample");  
      sendBroadcast(intent);  
 } catch (Exception localException) {  
      Log.e("CHECK", "Sony : " + localException.getLocalizedMessage());  
 }  


HTC:

Manifest File changes:

 <uses-permission android:name="com.htc.launcher.permission.READ_SETTINGS" />  
 <uses-permission android:name="com.htc.launcher.permission.UPDATE_SHORTCUT" />  


Code Changes:

 try {  
      Intent localIntent1 = new Intent("com.htc.launcher.action.UPDATE_SHORTCUT");  
      localIntent1.putExtra("packagename", "com.vardhan.notificationbadgesample");  
      localIntent1.putExtra("count", badgeno);  
      sendBroadcast(localIntent1);  
      Intent localIntent2 = new Intent("com.htc.launcher.action.SET_NOTIFICATION");  
      ComponentName localComponentName = new ComponentName(this, "com.vardhan.notificationbadgesample.MainActivity");  
      localIntent2.putExtra("com.htc.launcher.extra.COMPONENT",      localComponentName.flattenToShortString());  
         localIntent2.putExtra("com.htc.launcher.extra.COUNT", 10);  
      sendBroadcast(localIntent2);  
 } catch (Exception localException) {  
      Log.e("CHECK", "HTC : " + localException.getLocalizedMessage());  
 }  


Samsung:

Manifest File changes:

   <uses-permission android:name="com.sec.android.provider.badge.permission.READ" />  
   <uses-permission android:name="com.sec.android.provider.badge.permission.WRITE" />  


Code Changes:

 try {  
    ContentResolver localContentResolver = getContentResolver();  
    Uri localUri = Uri.parse("content://com.sec.badge/apps");  
    ContentValues localContentValues = new ContentValues();  
    localContentValues.put("package", "com.vardhan.notificationbadgesample");  
    localContentValues.put("class", "com.vardhan.notificationbadgesample.MainActivity");  
    localContentValues.put("badgecount", Integer.valueOf(badgeno));  
    String str = "package=? AND class=?";  
    String[] arrayOfString = new String[2];  
    arrayOfString[0] = "com.vardhan.notificationbadgesample";  
    arrayOfString[1] = "com.vardhan.notificationbadgesample.MainActivity";  
      int update = localContentResolver.update(localUri, localContentValues, str, arrayOfString);  
      if (update == 0) {  
           localContentResolver.insert(localUri, localContentValues);  
      }  
 } catch (IllegalArgumentException localIllegalArgumentException) {  
      Log.e("CHECK", "Samsung1F : " + localIllegalArgumentException.getLocalizedMessage());  
 } catch (Exception localException) {  
      Log.e("CHECK", "Samsung : " + localException.getLocalizedMessage());  
 }  


Output


Source Code
You can download the source code by clicking Source Code Click Here: .  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. It works in all API levels above 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? comments/feedback are welcome.

Tuesday, July 1, 2014

Android : Workaround for webview not loading https url

Basic steps to show WebView in the application
  1. Use WebView element in the layout xml.
  2. Provide internet permission in the AndroidManifest.xml file.
  3. loadUrl on WebView object.
  1. main.xml in the res/layout folder

 <?xml version="1.0" encoding="utf-8"?>  
 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"  
      android:layout_width="fill_parent"  
      android:layout_height="fill_parent"  
      android:orientation="vertical" >  
      <WebView  
           android:id="@+id/ displayWebview "  
           android:layout_width="fill_parent"  
           android:layout_height="fill_parent" />  
 </LinearLayout>   
  1. Application must have access to the Internet. To get Internet access, request the INTERNET permission in the AndroidManifest.xml file

 <manifest ... >  
   <uses-permission android:name="android.permission.INTERNET" />  
     ...  
 </manifest>  
  1. call the loadUrl() on webview object inside the onCreate() method of your activity class and pass the url as a parameter to it .

WebView webView = (WebView) findViewById(R.id.displayWebview);
webView.setWebViewClient(new WebViewClient());
webView.loadUrl("https://www.google.co.in/");

Problem: WebView is not loading if the request is https.
When we try url with https request, we may face blank page or error message saying “web page not available”

Issue:
WebView support ssl default and If we want to support third party then with few methods like setCertificate and so on we can make it. However, WebView Shows blank screen if it is not supporting the certificates. So, Catch the exception in onReceivedSslError method and do respective action when certificate is not supported. When certificate is not supported we may get blank screen or “Web Page not available, The webpage at might be temporarily down or it may have moved permanently to a new web address”.

Solution:

There is a Work around to solve the issue by Overriding onReceivedSslError method of WebViewClient as shown below.

webView = (WebView) findViewById(R.id.displayWebview);
webView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedSslError(final WebView view, final SslErrorHandler handler, SslError error) {
    Log.d("CHECK", "onReceivedSslError");
    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    AlertDialog alertDialog = builder.create();
    String message = "Certificate error.";
    switch (error.getPrimaryError()) {
        case SslError.SSL_UNTRUSTED:
            message = "The certificate authority is not trusted.";
            break;
        case SslError.SSL_EXPIRED:
            message = "The certificate has expired.";
            break;
        case SslError.SSL_IDMISMATCH:
            message = "The certificate Hostname mismatch.";
            break;
        case SslError.SSL_NOTYETVALID:
            message = "The certificate is not yet valid.";
            break;
    }
    message += " Do you want to continue anyway?";
    alertDialog.setTitle("SSL Certificate Error");
    alertDialog.setMessage(message);
    alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "OK", new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Log.d("CHECK", "Button ok pressed");
            // Ignore SSL certificate errors
            handler.proceed();
        }
    });
    alertDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Log.d("CHECK", "Button cancel pressed");
            handler.cancel();
        }
    });
    alertDialog.show();
    }
});
webView.loadUrl("https://www.google.co.in/");




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