org.solovyev.android
Class AndroidUtils

java.lang.Object
  extended by org.solovyev.android.AndroidUtils

public final class AndroidUtils
extends Object

This class contains static methods for working with some android classes


Nested Class Summary
static class AndroidUtils.PhoneModel
           
static interface AndroidUtils.ViewProcessor<V>
          Interface to process view.
 
Method Summary
static void addTab(android.content.Context context, android.widget.TabHost tabHost, String tabId, int tabCaptionId, Class<? extends android.app.Activity> activityClass)
          Method adds tab to the tabHost element
static void centerAndWrapTabsFor(android.widget.TabHost tabHost)
          Method center the tabs' contents on specified tabHost elements.
static int getAppVersionCode(android.content.Context context, String appPackageName)
          Method returns version of current application.
static int getScreenOrientation(android.app.Activity activity)
           
static boolean isDebuggable(android.content.Context context)
           
static boolean isLayoutSizeAtLeast(int size, android.content.res.Configuration configuration)
           
static boolean isPhoneModel(AndroidUtils.PhoneModel phoneModel)
           
static void processViews(android.view.View view, AndroidUtils.ViewProcessor<android.view.View> viewProcessor)
          Method runs through view and all it's children recursively and process them via viewProcessor
static
<T> void
processViewsOfType(android.view.View view, Class<T> viewClass, AndroidUtils.ViewProcessor<T> viewProcessor)
          Method runs through view and all it's children recursively and process all instances of viewClass via viewProcessor
static void restartActivity(android.app.Activity activity)
          Method restarts activity
static int toPixels(android.util.DisplayMetrics dm, int dps)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

centerAndWrapTabsFor

public static void centerAndWrapTabsFor(@NotNull
                                        android.widget.TabHost tabHost)
Method center the tabs' contents on specified tabHost elements. This method should be invoked only for tabs with only text on them (and no image) This method checks some known devices/android versions/builds which don't support tab centering and do nothing for them NOTE: be aware that this method doesn't cover all unsupported cases, for sure don't use this method

Parameters:
tabHost - tabHost element

addTab

public static void addTab(@NotNull
                          android.content.Context context,
                          @NotNull
                          android.widget.TabHost tabHost,
                          @NotNull
                          String tabId,
                          int tabCaptionId,
                          @NotNull
                          Class<? extends android.app.Activity> activityClass)
Method adds tab to the tabHost element

Parameters:
context - activity which users tabHost
tabHost - tabHost element
tabId - id of tab to be added
tabCaptionId - string id of tab to be added
activityClass - activity class to be invoked if the tab is pressed

getAppVersionCode

public static int getAppVersionCode(@NotNull
                                    android.content.Context context,
                                    @NotNull
                                    String appPackageName)
Method returns version of current application.

Parameters:
context - context
appPackageName - full name of the package of an app, 'com.example.app' for example.
Returns:
version number we are currently in, if for some reason package info was not found and thus versionCode could not be found -1 is returned

processViewsOfType

public static <T> void processViewsOfType(@NotNull
                                          android.view.View view,
                                          @NotNull
                                          Class<T> viewClass,
                                          @NotNull
                                          AndroidUtils.ViewProcessor<T> viewProcessor)
Method runs through view and all it's children recursively and process all instances of viewClass via viewProcessor

Parameters:
view - parent view to be processed, if view is ViewGroup then all it's children will be processed
viewClass - only instances of specified class will be processed
viewProcessor - object which processes views

processViews

public static void processViews(@NotNull
                                android.view.View view,
                                @NotNull
                                AndroidUtils.ViewProcessor<android.view.View> viewProcessor)
Method runs through view and all it's children recursively and process them via viewProcessor

Parameters:
view - parent view to be processed, if view is ViewGroup then all it's children will be processed
viewProcessor - object which processes views

restartActivity

public static void restartActivity(@NotNull
                                   android.app.Activity activity)
Method restarts activity

Parameters:
activity - to be restarted activity

toPixels

public static int toPixels(@NotNull
                           android.util.DisplayMetrics dm,
                           int dps)

isPhoneModel

public static boolean isPhoneModel(@NotNull
                                   AndroidUtils.PhoneModel phoneModel)

getScreenOrientation

public static int getScreenOrientation(@NotNull
                                       android.app.Activity activity)

isLayoutSizeAtLeast

public static boolean isLayoutSizeAtLeast(int size,
                                          @NotNull
                                          android.content.res.Configuration configuration)

isDebuggable

public static boolean isDebuggable(@NotNull
                                   android.content.Context context)


Copyright © 2012. All Rights Reserved.