Archive for July 2014

Google Play Services Migration(new Google Admob Tutorial)

Monetize and Analyze your Android apps with  Google's AdMob

In this tutorial, you will learn how to integrate the new Google Admob with banner and interstitial ads into your Android application. The new AdMob is a streamlined user interface, to make it even easier for you to monetize and promote your apps in minutes.Monetize your apps with ads from over a million Google advertisers worldwide. Get access to programmatic demand and best-in class mediation tools to maximize revenues effortlessly.On Aug. 1 2014, Google Play will stop accepting new or updated apps using the standalone Google Mobile Ads SDKs v6.4.1 or lower.So Google Mobile Ads is now offered through Google Play services. This is the recommended way of enabling ads on your Android app.
Getting Started:
1.Sign up as an Admob Publisher here. Log in to your dashboard once you have your account approved.
2.Open the Monetize tab and create an ad unit for your application. You should be able to see your ad unit after selecting an app on your left panel.
3.Download the new Google Play Services Library using the Android SDK Manager in your Eclipse IDE.

4.Import Google Play Services Library into your Eclipse IDE. I’ve found mine in D:\Eclipse\sdk\extras\google\google_play_services\libproject . You will have to search the folder yourself.

5.Create a new project in Eclipse File > New > Android Application Project. Fill in the details and name your project AdmobTutorial.
Application Name : AdmobTutorial
Project Name : AdmobTutorial
Package Name : com.srinoid.admobtutorial
6.After created your project, You have to set Google Play Services Library as a reference project to your project.
7.Import Google Play Services Library into your App.

8.In your AndroidManifest.xml, we need to declare an activity for Google Play Services and permissions to allow the application to access to the Internet and check network status. Open your AndroidManifest.xml and paste the following code.
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.srinoid.admobtutorial"
    android:versionCode="1"
    android:versionName="1.0" >
     <uses-sdk
        android:minSdkVersion="9"
        android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
 <!--Google Play Service Meta-data Info -->
        <meta-data
            android:name="com.google.android.gms.version"
            android:value="@integer/google_play_services_version" />
 <!-- AdActivity Declaration-->
        <activity
            android:name="com.google.android.gms.ads.AdActivity"
 android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
    </application>
</manifest>
9.Next, create an XML graphical layout for your MainActivity. Go to res > layout > Right Click on layout > New > Android XML File
Name your new XML file activity_main.xml and paste the following code.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
 <!--Creating AdView in XML and loading an ad-->
    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        ads:adSize="BANNER"
        ads:adUnitId="Place adunitid here" />
</LinearLayout>

10.Open your MainActivity.java and paste the following code
package com.srinoid.admobtutorial;
//Importing Library Classes  
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.InterstitialAd;
 import android.os.Bundle;
import android.app.Activity;
 public class MainActivity extends Activity {
    private InterstitialAd interstitial;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // Get the view from activity_main.xml
        setContentView(R.layout.activity_main);
         // Prepare the Interstitial Ad
        interstitial = new InterstitialAd(MainActivity.this);
        // Insert the Ad Unit ID
        interstitial.setAdUnitId("Place your AdUnitId Here");
         //Locate the Banner Ad in activity_main.xml
        AdView adView = (AdView) this.findViewById(R.id.adView);
         // Request for Ads
        AdRequest adRequest = new AdRequest.Builder()
         // Add a test device to show Test Ads
         .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
         .addTestDevice("Place your test device id here")
                .build();
         // Load ads into Banner Ads
        adView.loadAd(adRequest);
         // Load ads into Interstitial Ads
        interstitial.loadAd(adRequest);
         // Prepare an Interstitial Ad Listener
        interstitial.setAdListener(new AdListener() {
            public void onAdLoaded() {
                // Call displayInterstitial() function
                displayInterstitial();
            }
        });
    }
    public void displayInterstitial() {
        // If Ads are loaded, show Interstitial else show nothing.
        if (interstitial.isLoaded()) {
            interstitial.show();
        }
    }
}
11. For More Information about Google Play Services Migration please go through the following  link


Android UI Design Guidelines

Android UI Design Guidelines

  • Android powers millions of phones, tablets, and other devices in a wide variety of screen sizes and form factors. By taking advantage of Android's flexible layout system, you can create apps that gracefully scale from large tablets to smaller phones.
  • Android runs on a variety of devices that offer different screen sizes and densities.
  • Android’s multiple devices and form factors make it feel like designing for it is an uphill battle.
  • Be flexible
      Stretch and compress your layouts to accommodate various heights and widths.
  • Optimize layouts
      On larger devices, take advantage of extra screen real estate. Create compound views that combine multiple views to reveal more content and ease navigation.
  • Assets for all
      Provide resources for different screen densities (DPI) to ensure that your app looks great on any device.
  • Devices vary not only in physical size, but also in screen density (DPI). To simplify the way you design for multiple screens, think of each device as falling into a particular size bucket and density bucket:
    • The size buckets are handset (smaller than 600dp) and tablet (larger than or equal 600dp).
    • The density buckets are LDPI, MDPI, HDPI, XHDPI, XXHDPI, and XXXHDPI.
  • To keep things simple, Android breaks down physical screen sizes (measured as the screen’s diagonal length from the top-left corner to bottom-right corner) into four general sizes: small, normal, large and xlarge.

  • Optimize your application's UI by designing alternative layouts for some of the different size buckets, and provide alternative bitmap images for different density buckets.

  • Notice: one dp (density-independent pixel) is one pixel on a 160 DPI screen.
  • Views dimensions and spacing
    • Touchable UI components are generally laid out along 48 dp units. Spacing between each UI element is 8 dp.

  • Text Size:
      The Android framework uses the following limited set of type sizes:
                                     Text size micro --------------------- 12sp
                                     Text Size Small ----------------------14sp
                                     Text Size Medium ------------------18sp
                                     Text Size Large ---------------------22sp
            Notice: one sp (scale-independent pixel) is one pixel on a 160 DPI screen if the user's global text scale is set to 100%.
  • Colors:
      Use color primarily for emphasis. Blue is the standard accent color in Android's color palette. Note that red and green may be indistinguishable to color-blind users.
              More Information refer following site:
                    http://developer.android.com/design/style/color.html
  • Iconography:
    • An icon is a graphic that takes up a small portion of screen real estate and provides a quick, intuitive representation of an action, a status, or an app.
    • When you design icons for your app, it's important to keep in mind that your app may be installed on a variety of devices that offer a range of pixel densities, as mentioned in Devices and Displays. But you can make your icons look great on all devices by providing each icon in multiple sizes.
    • When your app runs, Android checks the characteristics of the device screen and loads the appropriate density-specific assets for your app.

      Qualifier DPI Scaling factor Launcher icon Action bar, tab icon Notification icon (API 11) Notification icon (API 9) Notification icon (older)
      ldpi 120 0.75 36 x 36
      32 x 32
      24 x 24
      18 x 18
      18 x 18
      16 x 16
      12 x 19
      12 x 12
      19 x 19
      16 x 16
      mdpi 160
      48 x 48
      42 x 42
      32 x 32
      24 x 24
      24 x 24
      22 x 22
      16 x 25
      16 x 16
      25 x 25
      21 x 21
      hdpi 240 1.5 72 x 72
      64 x 64
      48 x 48
      36 x 36
      36 x 36
      33 x 33
      24 x 38
      24 x 24
      38 x 38
      32 x 32
      xhdpi 320 2.0 96 x 96
      84 x 84
      64 x 64
      48 x 48
      48 x 48
      44 x 44
      32 x 50
      32 x 32
      50 x 50
      42 x 42
      xxhdpi 480 3.0 144 x 144
      126 x 126
      96 x 96
      72 x 72
      72 x 72
      66 x 66
      48 x 75
      48 x 48
      75 x 75
      63 x 63


        • Notice: the first icon dimension in table cell is full asset size, the second icon dimension is optical square. Dimension values are in pixels.
        • Tip: creating ldpi assets is not really needed anymore. The devices are rare and the platform will just scale down mdpi.

        • So, to create an icon for different densities, you should follow the 2:3:4:6:8 scaling ratio between the five primary densities (medium, high, x-high, xx-high, and xxx-high respectively). For example, consider that the size for a launcher icon is specified to be 48x48 dp. This means the baseline (MDPI) asset is 48x48 px, and the high density (HDPI) asset should be 1.5x the baseline at 72x72 px, and the x-high density (XHDPI) asset should be 2x the baseline at 96x96 px, and so on.
        • For More Information refer following site:
          http://developer.android.com/design/style/iconography.html
      • Writing Styles:
      • Best Practices for User Interface

        • Android provides a flexible framework for UI design that allows your app to display different layouts for different devices, create custom UI widgets, and even control aspects of the system UI outside your app's window.
        • Designing for multiple Screens::
          • Android powers hundreds of device types with several different screen sizes, ranging from small phones to large TV sets. Therefore, it’s important that you design your application to be compatible with all screen sizes so it’s available to as many users as possible.

      • Naming conventions
      • Naming conventions for drawables

        • File names must contain only lowercase a-z, 0-9, or _.

        • Drawables for the specific views (ListView, TextView, EditText, ProgressBar, CheckBox etc.) should be named like this views keeping the naming rules, e.g. drawable for CheckBox should be named "checkbox_on_bg.png".

      Asset Type Prefix Example
      Action bar ab_ ab_stacked.9.png
      Button btn_ btn_send_pressed.9.png
      Dialog dialog_ dialog_top.9.png
      Divider divider_ divider_horizontal.9.png
      Icon ic_ ic_star.png
      Menu menu_ menu_submenu_bg.9.png
      Notification notification_ notification_bg.9.png
      Tabs tab_ tab_pressed.9.png
      • Naming conventions for icon assets

      Asset Type Prefix Example
      Icons ic_ ic_star.png
      Launcher icons ic_launcher ic_launcher_calendar.png
      Action bar icons ic_menu ic_menu_archive.png
      Status bar icons ic_stat_notify ic_stat_notify_msg.png
      Tab icons ic_tab ic_tab_recent.png
      Dialog icons ic_dialog ic_dialog_info.png
      • Naming conventions for selector states

      State
      Suffix Example
      Normal _normal btn_order_normal.9.png
      Pressed _pressed btn_order_pressed.9.png
      Focused _focused btn_order_focused.9.png
      Disabled _disabled btn_order_disabled.9.png
      Selected _selected btn_order_selected.9.png

      Android DP / PX converter

Copyright © Srinoid