FileDocCategorySizeDatePackage
OnScreenHint.javaAPI DocAndroid 1.5 API9758Wed May 06 22:42:42 BST 2009com.android.camera

OnScreenHint

public class OnScreenHint extends Object
A on-screen hint is a view containing a little message for the user and will be shown on the screen continuously. This class helps you create and show those.

When the view is shown to the user, appears as a floating view over the application.

The easiest way to use this class is to call one of the static methods that constructs everything you need and returns a new OnScreenHint object.

Fields Summary
static final String
TAG
static final boolean
localLOGV
final android.content.Context
mContext
int
mGravity
int
mX
int
mY
float
mHorizontalMargin
float
mVerticalMargin
android.view.View
mView
android.view.View
mNextView
private final WindowManager.LayoutParams
mParams
private android.view.WindowManager
mWM
private final android.os.Handler
mHandler
private Runnable
mShow
private Runnable
mHide
Constructors Summary
public OnScreenHint(android.content.Context context)
Construct an empty OnScreenHint object. You must call {@link #setView} before you can call {@link #show}.

param
context The context to use. Usually your {@link android.app.Application} or {@link android.app.Activity} object.


                                                          
       
        mContext = context;
        mWM = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
        mY = context.getResources().getDimensionPixelSize(R.dimen.hint_y_offset);

        mParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
        mParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
        mParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
        mParams.format = PixelFormat.TRANSLUCENT;
        mParams.windowAnimations = R.style.Animation_OnScreenHint;
        mParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
        mParams.setTitle("OnScreenHint");
    
Methods Summary
public voidcancel()
Close the view if it's showing.

        if (localLOGV) Log.v(TAG, "HIDE: " + this);
        mHandler.post(mHide);
    
public intgetGravity()
Get the location at which the notification should appear on the screen.

see
android.view.Gravity
see
#getGravity

        return mGravity;
    
public floatgetHorizontalMargin()
Return the horizontal margin.

        return mHorizontalMargin;
    
public floatgetVerticalMargin()
Return the vertical margin.

        return mVerticalMargin;
    
public android.view.ViewgetView()
Return the view.

see
#setView

        return mNextView;
    
public intgetXOffset()
Return the X offset in pixels to apply to the gravity's location.

        return mX;
    
public intgetYOffset()
Return the Y offset in pixels to apply to the gravity's location.

        return mY;
    
private synchronized voidhandleHide()

        if (localLOGV) Log.v(TAG, "HANDLE HIDE: " + this + " mView=" + mView);
        if (mView != null) {
            // note: checking parent() just to make sure the view has
            // been added...  i have seen cases where we get here when
            // the view isn't yet added, so let's try not to crash.
            if (mView.getParent() != null) {
                if (localLOGV) Log.v(
                        TAG, "REMOVE! " + mView + " in " + this);
                mWM.removeView(mView);
            }
            mView = null;
        }
    
private synchronized voidhandleShow()

        if (localLOGV) Log.v(TAG, "HANDLE SHOW: " + this + " mView=" + mView
                + " mNextView=" + mNextView);
        if (mView != mNextView) {
            // remove the old view if necessary
            handleHide();
            mView = mNextView;
            final int gravity = mGravity;
            mParams.gravity = gravity;
            if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.FILL_HORIZONTAL) {
                mParams.horizontalWeight = 1.0f;
            }
            if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.FILL_VERTICAL) {
                mParams.verticalWeight = 1.0f;
            }
            mParams.x = mX;
            mParams.y = mY;
            mParams.verticalMargin = mVerticalMargin;
            mParams.horizontalMargin = mHorizontalMargin;
            if (mView.getParent() != null) {
                if (localLOGV) Log.v(
                        TAG, "REMOVE! " + mView + " in " + this);
                mWM.removeView(mView);
            }
            if (localLOGV) Log.v(TAG, "ADD! " + mView + " in " + this);
            mWM.addView(mView, mParams);
        }
    
public static com.android.camera.OnScreenHintmakeText(android.content.Context context, java.lang.CharSequence text)
Make a standard hint that just contains a text view.

param
context The context to use. Usually your {@link android.app.Application} or {@link android.app.Activity} object.
param
text The text to show. Can be formatted text.

        OnScreenHint result = new OnScreenHint(context);

        LayoutInflater inflate = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = inflate.inflate(R.layout.on_screen_hint, null);
        TextView tv = (TextView)v.findViewById(R.id.message);
        tv.setText(text);

        result.mNextView = v;

        return result;
    
public static com.android.camera.OnScreenHintmakeText(android.content.Context context, int resId)
Make a standard hint that just contains a text view with the text from a resource.

param
context The context to use. Usually your {@link android.app.Application} or {@link android.app.Activity} object.
param
resId The resource id of the string resource to use. Can be formatted text.
throws
Resources.NotFoundException if the resource can't be found.

        return makeText(context, context.getResources().getText(resId));
    
public voidsetGravity(int gravity, int xOffset, int yOffset)
Set the location at which the notification should appear on the screen.

see
android.view.Gravity
see
#getGravity

        mGravity = gravity;
        mX = xOffset;
        mY = yOffset;
    
public voidsetMargin(float horizontalMargin, float verticalMargin)
Set the margins of the view.

param
horizontalMargin The horizontal margin, in percentage of the container width, between the container's edges and the notification
param
verticalMargin The vertical margin, in percentage of the container height, between the container's edges and the notification

        mHorizontalMargin = horizontalMargin;
        mVerticalMargin = verticalMargin;
    
public voidsetText(int resId)
Update the text in a OnScreenHint that was previously created using one of the makeText() methods.

param
resId The new text for the OnScreenHint.

        setText(mContext.getText(resId));
    
public voidsetText(java.lang.CharSequence s)
Update the text in a OnScreenHint that was previously created using one of the makeText() methods.

param
s The new text for the OnScreenHint.

        if (mNextView == null) {
            throw new RuntimeException("This OnScreenHint was not created with OnScreenHint.makeText()");
        }
        TextView tv = (TextView) mNextView.findViewById(R.id.message);
        if (tv == null) {
            throw new RuntimeException("This OnScreenHint was not created with OnScreenHint.makeText()");
        }
        tv.setText(s);
    
public voidsetView(android.view.View view)
Set the view to show.

see
#getView

        mNextView = view;
    
public voidshow()
Show the view on the screen.

        if (mNextView == null) {
            throw new RuntimeException("setView must have been called");
        }
        if (localLOGV) Log.v(TAG, "SHOW: " + this);
        mHandler.post(mShow);