sk.baka.ambient.views
Class ViewUtils

java.lang.Object
  extended by sk.baka.ambient.views.ViewUtils

public final class ViewUtils
extends Object

Utility methods for views. Not thread safe.

Author:
Martin Vysny

Nested Class Summary
static interface ViewUtils.OnTextSubmit
          Fired when a text has been successfully entered.
 
Field Summary
static DialogInterface.OnClickListener CANCEL
          Cancels the dialog on invocation.
 Point measuredText
          The result of measureTextCache(Paint, String) is stored here.
 Point translated
          A result of translate* operations is stored here.
(package private)  int[] translatedPoint
          Here the temporary results of all translate* methods are stored.
 
Constructor Summary
ViewUtils()
           
 
Method Summary
static Point clone(Point point)
          Clones given point
static int getTextHeight(Paint paint, String text)
          Returns the text height.
static boolean isCancel(MotionEvent event)
          Checks if given event is a MotionEvent.ACTION_CANCEL event.
static boolean isPenUp(MotionEvent event)
          Checks if given event is a MotionEvent.ACTION_UP or MotionEvent.ACTION_CANCEL event.
static Point measureText(Paint paint, String text)
          Measures given text width/height and returns the result as a point.
static void measureText(Paint paint, String text, Point point)
          Measures given text width/height and sets them to the given point.
 void measureTextCache(Paint paint, String text)
          Measures given text width/height and sets them to the cached point.
static void recycleBitmaps(Collection<Bitmap> bitmaps)
          Recycles given collection of bitmap.
static Dialog showTextEditor(Context context, String submitButtonCaption, String cancelButtonCaption, String dialogCaption, String text, ViewUtils.OnTextSubmit listener)
          Creates new text dialog with a text enter capability.
static AlertDialog showYesNoDialog(Context context, int questionResId, DialogInterface.OnClickListener yesButtonListener)
          Shows a simple yes/no question dialog.
 void translateCoordinates(Point point, View view, View targetView)
          Translates given point into target view's coordinate system and stores the result into the translated point.
 void translateCoordinatesToRoot(Point point, View view)
          Translates given point into root view's coordinate system.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

translatedPoint

final int[] translatedPoint
Here the temporary results of all translate* methods are stored. This is just a cache, to prevent an array creation on each call.


translated

public final Point translated
A result of translate* operations is stored here.


measuredText

public final Point measuredText
The result of measureTextCache(Paint, String) is stored here.


CANCEL

public static final DialogInterface.OnClickListener CANCEL
Cancels the dialog on invocation.

Constructor Detail

ViewUtils

public ViewUtils()
Method Detail

clone

public static final Point clone(Point point)
Clones given point

Parameters:
point - the point to clone
Returns:
cloned point

recycleBitmaps

public static void recycleBitmaps(Collection<Bitmap> bitmaps)
Recycles given collection of bitmap. The collection is emptied afterwards.

Parameters:
bitmaps - bitmaps to recycle.

translateCoordinates

public void translateCoordinates(Point point,
                                 View view,
                                 View targetView)
Translates given point into target view's coordinate system and stores the result into the translated point.

Parameters:
point - the point to translate. Will not get modified. If null then the translated point data will be taken instead.
view - the point belongs to the coordinate system of this view. If null then the point is an absolute screen position.
targetView - translate the view to this view coordinate system. If null then the point will be returned as an absolute screen position.

translateCoordinatesToRoot

public void translateCoordinatesToRoot(Point point,
                                       View view)
Translates given point into root view's coordinate system. Does nothing if the supplied view is null.

Parameters:
point - the point to translate. Will not get modified.
view - the point belongs to the coordinate system of this view. If null then the point is an absolute screen position.

getTextHeight

public static int getTextHeight(Paint paint,
                                String text)
Returns the text height.

Parameters:
paint - the paint to use
text - the text to measure
Returns:
text height, in pixels.

measureText

public static void measureText(Paint paint,
                               String text,
                               Point point)
Measures given text width/height and sets them to the given point.

Parameters:
paint - the paint
text - text to measure
point - overwrites this point.

measureText

public static Point measureText(Paint paint,
                                String text)
Measures given text width/height and returns the result as a point.

Parameters:
paint - the paint
text - text to measure
Returns:
the text sizes

measureTextCache

public void measureTextCache(Paint paint,
                             String text)
Measures given text width/height and sets them to the cached point.

Parameters:
paint - the paint
text - text to measure

showTextEditor

public static Dialog showTextEditor(Context context,
                                    String submitButtonCaption,
                                    String cancelButtonCaption,
                                    String dialogCaption,
                                    String text,
                                    ViewUtils.OnTextSubmit listener)
Creates new text dialog with a text enter capability. When the dialog is submitted the text submit event is fired.

Parameters:
context - the context
submitButtonCaption - the submit button caption, if null then OK will be shown.
cancelButtonCaption - the cancel button caption, if null then Cancel will be shown.
dialogCaption - the dialog caption
text - the text to show in the dialog.
listener - fire events on this listener
Returns:
listener to be registered to the submit button.

showYesNoDialog

public static AlertDialog showYesNoDialog(Context context,
                                          int questionResId,
                                          DialogInterface.OnClickListener yesButtonListener)
Shows a simple yes/no question dialog.

Parameters:
context - the context.
questionResId - the question body.
yesButtonListener - invoked when user presses the 'Yes' button.
Returns:
the dialog instance.

isPenUp

public static boolean isPenUp(MotionEvent event)
Checks if given event is a MotionEvent.ACTION_UP or MotionEvent.ACTION_CANCEL event.

Parameters:
event - the event to check
Returns:
true if pen is up or the motion is canceled, false otherwise.

isCancel

public static boolean isCancel(MotionEvent event)
Checks if given event is a MotionEvent.ACTION_CANCEL event.

Parameters:
event - the event to check
Returns:
true if the motion is canceled, false otherwise.


Copyright © 2007-2008. All Rights Reserved.