Thursday, November 22, 2012

Resource Folder Content ?


Check this link http://developer.android.com/training/multiscreen/index.html
http://developer.android.com/guide/practices/screens_support.html
http://developer.android.com/guide/practices/ui_guidelines/icon_design.html
http://developer.android.com/guide/topics/resources/more-resources.html#Dimension
http://android-ui-utils.googlecode.com/hg/asset-studio/dist/index.html
http://android-developers.blogspot.in/2011/07/new-tools-for-managing-screen-sizes.html
http://jayxie.com/mirrors/android-sdk/resources/samples/MultiResolution/index.html
http://tools.android.com/recent/dealingwithdependenciesinandroidprojects
http://developer.android.com/about/dashboards/index.html

Taken from Here

In the /res folder you can have:

anim/ - XML files that define tween animations

color/ - XML files that define a state list of colors.

drawable/ - Bitmap files / Nine-Patches (re-sizable bitmaps) / State lists / Shapes / Animation drawables / Other drawables

layout/ - XML files that define a user interface layout.

menu/ - XML files that define application menus, such as an Options Menu, Context Menu, or Sub Menu.

raw/ - Arbitrary files to save in their raw form.

values/ - XML files that contain simple values, such as strings, integers, and colors.

arrays.xml for resource arrays (typed arrays).
colors.xml for color values
dimens.xml for dimension values.
strings.xml for string values.
styles.xml for styles.
xml/ - Arbitrary XML files

Also see Accessing Alternative Resources for more specific device configurations (locale, dpi, size, aspect, orientation, etc



Also We can have value folder like : -

res/values-ldpi/dimens.xml
res/values-mdpi/dimens.xml
res/values-hdpi/dimens.xml
res/values-sw720dp/dimens.xml

Drawable folders can be of : -

xhdpi: 720x1280
large-hdpi: 640x960
hdpi: 480x640
mdpi: 320x480
ldpi: 240x320

res/layout-sw600dp/main_activity.xml   # For 7” tablets (600dp wide and bigger)
res/layout-sw720dp/main_activity.xml   # For 10” tablets (720dp wide and bigger)



The size ratios should match the nominal pixel densities as Android defines them:

ldpi - 120 pixels/inch; dpi scale = .75 (4 dpi = 3 pixels)
mdpi - 160 pixels/inch; dpi scale = 1 (1 dpi = 1 pixel)
hdpi - 240 pixels/inch; dpi scale = 1.5 (2 dpi = 3 pixels)
xhdpi - 320 pixels/inch; dpi scale = 2 (1 dpi = 2 pixels)

So if you make your xhdpi images twice the size (in pixels) of the mdpi resources, they will be the same dpi, meaning they will be the same physical size on their respective screens.








Thursday, November 1, 2012

How to show dialog yes/No before leaving the app via Back button ?



private boolean isLastActivity() {
   final ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    final List<RunningTaskInfo> tasksInfo = am.getRunningTasks(1024);

    final String ourAppPackageName = getPackageName();
    RunningTaskInfo taskInfo;
    final int size = tasksInfo.size();
    for (int i = 0; i < size; i++) {
        taskInfo = tasksInfo.get(i);
        if (ourAppPackageName.equals(taskInfo.baseActivity.getPackageName())) {
            return taskInfo.numActivities == 1;
        }
    }

    return false;
}

You wil also require below permission in manifest....

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

Thus in your Activty you can just use the following:

public void onBackPressed() {
    if (isLastActivity()) {
         showDialog(DIALOG_EXIT_CONFIRMATION_ID);
    } else {
         super.onBackPressed(); // this will actually finish the Activity
    }
}