Example usage for android.view Gravity TOP

List of usage examples for android.view Gravity TOP

Introduction

In this page you can find the example usage for android.view Gravity TOP.

Prototype

int TOP

To view the source code for android.view Gravity TOP.

Click Source Link

Document

Push object to the top of its container, not changing its size.

Usage

From source file:com.klinker.deskclock.widget.multiwaveview.GlowPadView.java

public GlowPadView(Context context, AttributeSet attrs) {
    super(context, attrs);
    Resources res = context.getResources();

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GlowPadView);
    mInnerRadius = a.getDimension(R.styleable.GlowPadView_innerRadius, mInnerRadius);
    mOuterRadius = a.getDimension(R.styleable.GlowPadView_outerRadius, mOuterRadius);
    mSnapMargin = a.getDimension(R.styleable.GlowPadView_snapMargin, mSnapMargin);
    mVibrationDuration = a.getInt(R.styleable.GlowPadView_vibrationDuration, mVibrationDuration);
    mFeedbackCount = a.getInt(R.styleable.GlowPadView_feedbackCount, mFeedbackCount);
    TypedValue handle = a.peekValue(R.styleable.GlowPadView_handleDrawable);
    mHandleDrawable = new TargetDrawable(res, handle != null ? handle.resourceId : 0, 2);
    mHandleDrawable.setState(TargetDrawable.STATE_INACTIVE);
    mOuterRing = new TargetDrawable(res, getResourceId(a, R.styleable.GlowPadView_outerRingDrawable), 1);

    mAlwaysTrackFinger = a.getBoolean(R.styleable.GlowPadView_alwaysTrackFinger, false);

    int pointId = getResourceId(a, R.styleable.GlowPadView_pointDrawable);
    Drawable pointDrawable = pointId != 0 ? res.getDrawable(pointId) : null;
    mGlowRadius = a.getDimension(R.styleable.GlowPadView_glowRadius, 0.0f);

    TypedValue outValue = new TypedValue();

    // Read array of target drawables
    if (a.getValue(R.styleable.GlowPadView_targetDrawables, outValue)) {
        internalSetTargetResources(outValue.resourceId);
    }//  ww w.j  a  v  a 2 s  .com
    if (mTargetDrawables == null || mTargetDrawables.size() == 0) {
        throw new IllegalStateException("Must specify at least one target drawable");
    }

    // Read array of target descriptions
    if (a.getValue(R.styleable.GlowPadView_targetDescriptions, outValue)) {
        final int resourceId = outValue.resourceId;
        if (resourceId == 0) {
            throw new IllegalStateException("Must specify target descriptions");
        }
        setTargetDescriptionsResourceId(resourceId);
    }

    // Read array of direction descriptions
    if (a.getValue(R.styleable.GlowPadView_directionDescriptions, outValue)) {
        final int resourceId = outValue.resourceId;
        if (resourceId == 0) {
            throw new IllegalStateException("Must specify direction descriptions");
        }
        setDirectionDescriptionsResourceId(resourceId);
    }

    a.recycle();

    // Use gravity attribute from LinearLayout
    //a = context.obtainStyledAttributes(attrs, R.styleable.LinearLayout);
    mGravity = a.getInt(R.styleable.GlowPadView_android_gravity, Gravity.TOP);
    a.recycle();

    setVibrateEnabled(mVibrationDuration > 0);

    assignDefaultsIfNeeded();

    mPointCloud = new PointCloud(pointDrawable);
    mPointCloud.makePointCloud(mInnerRadius, mOuterRadius);
    mPointCloud.glowManager.setRadius(mGlowRadius);
}

From source file:org.sigimera.app.android.GCMIntentService.java

@Override
protected final void onUnregistered(final Context context, String regID) {
    final String HOST = Config.getInstance().getAPIHost() + "/gcm";
    HttpClient httpclient = new MyHttpClient(ApplicationController.getInstance().getApplicationContext());
    try {/*from   w  ww .  java2 s .co  m*/
        String authToken = SessionHandler.getInstance(null).getAuthenticationToken();
        final String toastMessage;
        if (regID != null && !regID.equals("")) {
            HttpDelete request = new HttpDelete(HOST + "/" + regID + "?auth_token=" + authToken);
            httpclient.execute(request);
            toastMessage = "Successfully unregistered!";
        } else {
            toastMessage = "You are not registered to receive push notifications.";
        }
        this.mainThreadHandler.post(new Runnable() {
            public void run() {
                Toast toast = Toast.makeText(getApplicationContext(), toastMessage, Toast.LENGTH_LONG);
                toast.setGravity(Gravity.TOP, 0, 0);
                toast.show();
            }
        });
    } catch (AuthenticationErrorException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        httpclient.getConnectionManager().shutdown();
    }
}

From source file:com.cloudexplorers.plugins.childBrowser.ChildBrowser.java

/**
 * Display a new browser with the specified URL.
 * //from w w  w.ja  va2s.  c  om
 * @param url
 *          The url to load.
 * @param jsonObject
 */
public String showWebPage(final String url, JSONObject options) {
    // Determine if we should hide the location bar.
    if (options != null) {
        showLocationBar = options.optBoolean("showLocationBar", true);
    }

    // Create dialog in new thread
    Runnable runnable = new Runnable() {
        /**
         * Convert our DIP units to Pixels
         * 
         * @return int
         */
        private int dpToPixels(int dipValue) {
            int value = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (float) dipValue,
                    cordova.getActivity().getResources().getDisplayMetrics());

            return value;
        }

        public void run() {
            // Let's create the main dialog
            dialog = new Dialog(cordova.getActivity(), android.R.style.Theme_NoTitleBar);
            dialog.getWindow().getAttributes().windowAnimations = android.R.style.Animation_Dialog;
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setCancelable(true);
            dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                public void onDismiss(DialogInterface dialog) {
                    try {
                        JSONObject obj = new JSONObject();
                        obj.put("type", CLOSE_EVENT);

                        sendUpdate(obj, false);
                    } catch (JSONException e) {
                        Log.d(LOG_TAG, "Should never happen");
                    }
                }
            });

            // Main container layout
            LinearLayout main = new LinearLayout(cordova.getActivity());
            main.setOrientation(LinearLayout.VERTICAL);

            // Toolbar layout
            RelativeLayout toolbar = new RelativeLayout(cordova.getActivity());
            toolbar.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, this.dpToPixels(44)));
            toolbar.setPadding(this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2), this.dpToPixels(2));
            toolbar.setHorizontalGravity(Gravity.LEFT);
            toolbar.setVerticalGravity(Gravity.TOP);

            // Action Button Container layout
            RelativeLayout actionButtonContainer = new RelativeLayout(cordova.getActivity());
            actionButtonContainer.setLayoutParams(
                    new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            actionButtonContainer.setHorizontalGravity(Gravity.LEFT);
            actionButtonContainer.setVerticalGravity(Gravity.CENTER_VERTICAL);
            actionButtonContainer.setId(1);

            // Back button
            ImageButton back = new ImageButton(cordova.getActivity());
            RelativeLayout.LayoutParams backLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
            backLayoutParams.addRule(RelativeLayout.ALIGN_LEFT);
            back.setLayoutParams(backLayoutParams);
            back.setContentDescription("Back Button");
            back.setId(2);
            try {
                back.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_left.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            back.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goBack();
                }
            });

            // Forward button
            ImageButton forward = new ImageButton(cordova.getActivity());
            RelativeLayout.LayoutParams forwardLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
            forwardLayoutParams.addRule(RelativeLayout.RIGHT_OF, 2);
            forward.setLayoutParams(forwardLayoutParams);
            forward.setContentDescription("Forward Button");
            forward.setId(3);
            try {
                forward.setImageBitmap(loadDrawable("www/childbrowser/icon_arrow_right.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            forward.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    goForward();
                }
            });

            // Edit Text Box
            edittext = new EditText(cordova.getActivity());
            RelativeLayout.LayoutParams textLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
            textLayoutParams.addRule(RelativeLayout.RIGHT_OF, 1);
            textLayoutParams.addRule(RelativeLayout.LEFT_OF, 5);
            edittext.setLayoutParams(textLayoutParams);
            edittext.setId(4);
            edittext.setSingleLine(true);
            edittext.setText(url);
            edittext.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
            edittext.setImeOptions(EditorInfo.IME_ACTION_GO);
            edittext.setInputType(InputType.TYPE_NULL); // Will not except input...
                                                        // Makes the text
                                                        // NON-EDITABLE
            edittext.setOnKeyListener(new View.OnKeyListener() {
                public boolean onKey(View v, int keyCode, KeyEvent event) {
                    // If the event is a key-down event on the "enter" button
                    if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                        navigate(edittext.getText().toString());
                        return true;
                    }
                    return false;
                }
            });

            // Close button
            ImageButton close = new ImageButton(cordova.getActivity());
            RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
            closeLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
            close.setLayoutParams(closeLayoutParams);
            forward.setContentDescription("Close Button");
            close.setId(5);
            try {
                close.setImageBitmap(loadDrawable("www/childbrowser/icon_close.png"));
            } catch (IOException e) {
                Log.e(LOG_TAG, e.getMessage(), e);
            }
            close.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    closeDialog();
                }
            });

            // WebView
            webview = new WebView(cordova.getActivity());
            webview.setLayoutParams(
                    new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
            webview.setWebChromeClient(new WebChromeClient());
            WebViewClient client = new ChildBrowserClient(edittext);
            webview.setWebViewClient(client);
            WebSettings settings = webview.getSettings();
            settings.setJavaScriptEnabled(true);
            settings.setJavaScriptCanOpenWindowsAutomatically(true);
            settings.setBuiltInZoomControls(true);
            settings.setPluginsEnabled(true);
            settings.setDomStorageEnabled(true);

            webview.loadUrl(url);
            webview.setId(6);
            webview.getSettings().setLoadWithOverviewMode(true);
            webview.getSettings().setUseWideViewPort(true);
            webview.getSettings().setJavaScriptEnabled(true);
            webview.getSettings().setPluginsEnabled(true);

            webview.requestFocus();
            webview.requestFocusFromTouch();

            // Add the back and forward buttons to our action button container
            // layout
            actionButtonContainer.addView(back);
            actionButtonContainer.addView(forward);

            // Add the views to our toolbar
            toolbar.addView(actionButtonContainer);
            toolbar.addView(edittext);
            toolbar.addView(close);

            // Don't add the toolbar if its been disabled
            if (getShowLocationBar()) {
                // Add our toolbar to our main view/layout
                main.addView(toolbar);
            }

            // Add our webview to our main view/layout
            main.addView(webview);

            WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
            lp.copyFrom(dialog.getWindow().getAttributes());
            lp.width = WindowManager.LayoutParams.FILL_PARENT;
            lp.height = WindowManager.LayoutParams.FILL_PARENT;

            dialog.setContentView(main);
            dialog.show();
            dialog.getWindow().setAttributes(lp);
        }

        private Bitmap loadDrawable(String filename) throws java.io.IOException {
            InputStream input = cordova.getActivity().getAssets().open(filename);
            return BitmapFactory.decodeStream(input);
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
    return "";
}

From source file:android.support.v7.app.MediaRouteButton.java

@Override
public boolean performLongClick() {
    if (super.performLongClick()) {
        return true;
    }/* w  w w .  j  ava  2  s .c o  m*/

    if (!mCheatSheetEnabled) {
        return false;
    }

    final CharSequence contentDesc = getContentDescription();
    if (TextUtils.isEmpty(contentDesc)) {
        // Don't show the cheat sheet if we have no description
        return false;
    }

    final int[] screenPos = new int[2];
    final Rect displayFrame = new Rect();
    getLocationOnScreen(screenPos);
    getWindowVisibleDisplayFrame(displayFrame);

    final Context context = getContext();
    final int width = getWidth();
    final int height = getHeight();
    final int midy = screenPos[1] + height / 2;
    final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;

    Toast cheatSheet = Toast.makeText(context, contentDesc, Toast.LENGTH_SHORT);
    if (midy < displayFrame.height()) {
        // Show along the top; follow action buttons
        cheatSheet.setGravity(Gravity.TOP | GravityCompat.END, screenWidth - screenPos[0] - width / 2, height);
    } else {
        // Show along the bottom center
        cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height);
    }
    cheatSheet.show();
    performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
    return true;
}

From source file:com.example.verticaldrawerlayout.VerticalDrawerLayout.java

/**
 * Set a simple drawable used for the left or right shadow.
 * The drawable provided must have a nonzero intrinsic width.
 * //from  w w  w. j  av  a2 s.c  o  m
 * @param shadowDrawable
 *            Shadow drawable to use at the edge of a drawer
 * @param gravity
 *            Which drawer the shadow should apply to
 */
public void setDrawerShadow(Drawable shadowDrawable, int gravity) {
    /*
     * TODO Someone someday might want to set more complex drawables here.
     * They're probably nuts, but we might want to consider registering
     * callbacks,
     * setting states, etc. properly.
     */

    final int absGravity = GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(this));
    if ((absGravity & Gravity.TOP) == Gravity.TOP) {
        mShadowTop = shadowDrawable;
        invalidate();
    }
    if ((absGravity & Gravity.BOTTOM) == Gravity.BOTTOM) {
        mShadowBottom = shadowDrawable;
        invalidate();
    }
}

From source file:com.linkbubble.ui.BubbleFlowDraggable.java

@Override
void configure(int width, int itemWidth, int itemHeight) {
    mBubbleFlowWidth = Config.mScreenWidth;

    super.configure(width, itemWidth, itemHeight);

    if (mDraggableHelper != null && mDraggableHelper.getWindowManagerParams() != null) {
        WindowManager.LayoutParams windowManagerParams = mDraggableHelper.getWindowManagerParams();
        windowManagerParams.width = width;
        windowManagerParams.x = 0;/*  w  ww .ja v  a2  s .  c  o  m*/
        windowManagerParams.y = 0;
        windowManagerParams.gravity = Gravity.TOP | Gravity.LEFT;

        setExactPos(0, 0);
    }
}

From source file:com.htc.dotdesign.ToolBoxService.java

private void setToolPanelVisibility(boolean bShow) {
    if (mCurrExtend != null) {
        mWindowManager.removeView(mCurrExtend);
        mCurrExtend = null;// w w w.  j av a 2 s  .  c om
    }

    if (bShow) {
        mIsToolBarExtend = true;
        if (mCurrFun == FunType.Fun_Palette) {
            Resources res = getResources();
            WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
                    WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                    PixelFormat.TRANSLUCENT);
            params.gravity = Gravity.START;
            if (mDragButtonParams.y < mScreenHeight / 2) {
                params.gravity = Gravity.TOP | params.gravity;
                params.y = mDragButtonParams.y + mDragButtonHeight;
                View top_arrow = mPalette.findViewById(R.id.top_arrow);
                top_arrow.setVisibility(View.VISIBLE);
                View bottom_arrow = mPalette.findViewById(R.id.bottom_arrow);
                bottom_arrow.setVisibility(View.GONE);
            } else {
                params.gravity = Gravity.BOTTOM | params.gravity;
                params.y = mScreenHeight - mDragButtonParams.y;
                View top_arrow = mPalette.findViewById(R.id.top_arrow);
                top_arrow.setVisibility(View.GONE);
                View bottom_arrow = mPalette.findViewById(R.id.bottom_arrow);
                bottom_arrow.setVisibility(View.VISIBLE);
            }
            int[] locations = new int[2];
            mBtnPalette.getLocationOnScreen(locations);
            int x = locations[0];
            params.x = (x + mBtnPalette.getWidth() / 2)
                    - (mArrowWidth / 2 + res.getDimensionPixelSize(R.dimen.h02));

            mPalette.setVisibility(View.VISIBLE);
            mWindowManager.addView(mPalette, params);
            mCurrExtend = mPalette;
            initBrushSize();
        } else if (mCurrFun == FunType.Fun_Eraser) {
            Resources res = getResources();
            WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
                    WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                    PixelFormat.TRANSLUCENT);
            params.gravity = Gravity.START;
            if (mDragButtonParams.y < mScreenHeight / 2) {
                params.gravity = Gravity.TOP | params.gravity;
                params.y = mDragButtonParams.y + mDragButtonHeight;
                View top_arrow = mEraser.findViewById(R.id.top_arrow);
                top_arrow.setVisibility(View.VISIBLE);
                View bottom_arrow = mEraser.findViewById(R.id.bottom_arrow);
                bottom_arrow.setVisibility(View.GONE);
            } else {
                params.gravity = Gravity.BOTTOM | params.gravity;
                params.y = mScreenHeight - mDragButtonParams.y;
                View top_arrow = mEraser.findViewById(R.id.top_arrow);
                top_arrow.setVisibility(View.GONE);
                View bottom_arrow = mEraser.findViewById(R.id.bottom_arrow);
                bottom_arrow.setVisibility(View.VISIBLE);
            }
            int[] locations = new int[2];
            mBtnEraser.getLocationOnScreen(locations);
            int x = locations[0];
            params.x = (x + mBtnEraser.getWidth() / 2)
                    - (mArrowWidth / 2 + res.getDimensionPixelSize(R.dimen.h02));

            mEraser.setVisibility(View.VISIBLE);
            mWindowManager.addView(mEraser, params);
            mCurrExtend = mEraser;
            initBrushSize();
        } else if (mCurrFun == FunType.Fun_VirtualDot) {

        } else if (mCurrFun == FunType.Fun_Menu) {
            Resources res = getResources();
            WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                    WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
                    WindowManager.LayoutParams.TYPE_PHONE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                    PixelFormat.TRANSLUCENT);
            params.gravity = Gravity.END;
            if (mDragButtonParams.y < mScreenHeight / 2) {
                params.gravity = Gravity.TOP | params.gravity;
                params.y = mDragButtonParams.y + mDragButtonHeight;
                // Set top_arrow to visible and align to parent right.
                View top_arrow = mMenu.findViewById(R.id.top_arrow);
                top_arrow.setVisibility(View.VISIBLE);
                LinearLayout.LayoutParams arrowParams = (LinearLayout.LayoutParams) top_arrow.getLayoutParams();
                arrowParams.setMarginEnd(res.getDimensionPixelSize(R.dimen.h02));
                arrowParams.gravity = Gravity.END;
                top_arrow.setLayoutParams(arrowParams);
                // Set bottom_arrow to gone
                View bottom_arrow = mMenu.findViewById(R.id.bottom_arrow);
                bottom_arrow.setVisibility(View.GONE);
            } else {
                params.gravity = Gravity.BOTTOM | params.gravity;
                params.y = mScreenHeight - mDragButtonParams.y;
                // Set top_arrow to gone
                View top_arrow = mMenu.findViewById(R.id.top_arrow);
                top_arrow.setVisibility(View.GONE);
                // Set bottom_arrow to visible and align to parent right.
                View bottom_arrow = mMenu.findViewById(R.id.bottom_arrow);
                LinearLayout.LayoutParams arrowParams = (LinearLayout.LayoutParams) bottom_arrow
                        .getLayoutParams();
                arrowParams.setMarginEnd(res.getDimensionPixelSize(R.dimen.h02));
                arrowParams.gravity = Gravity.END;
                bottom_arrow.setLayoutParams(arrowParams);
                bottom_arrow.setVisibility(View.VISIBLE);
            }
            int[] locations = new int[2];
            mBtnMenu.getLocationOnScreen(locations);
            int x = locations[0];
            //params.x = (x + mBtnMenu.getWidth()/2) - (mArrowWidth/2 + res.getDimensionPixelSize(R.dimen.h02));
            params.x = mScreenWidth - (x + mBtnMenu.getWidth() / 2)
                    - (mArrowWidth / 2 + res.getDimensionPixelSize(R.dimen.h02));

            mMenu.setVisibility(View.VISIBLE);
            mWindowManager.addView(mMenu, params);
            mCurrExtend = mMenu;
        }
    } else {
        mIsToolBarExtend = false;
    }

    updateToolBarFunIconColor();
}

From source file:com.android.incallui.widget.multiwaveview.GlowPadView.java

public GlowPadView(Context context, AttributeSet attrs) {
    super(context, attrs);
    Resources res = context.getResources();

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.GlowPadView);
    mInnerRadius = a.getDimension(R.styleable.GlowPadView_innerRadius, mInnerRadius);
    mOuterRadius = a.getDimension(R.styleable.GlowPadView_outerRadius, mOuterRadius);
    mSnapMargin = a.getDimension(R.styleable.GlowPadView_snapMargin, mSnapMargin);
    mVibrationDuration = a.getInt(R.styleable.GlowPadView_vibrationDuration, mVibrationDuration);
    mFeedbackCount = a.getInt(R.styleable.GlowPadView_feedbackCount, mFeedbackCount);
    mAllowScaling = a.getBoolean(R.styleable.GlowPadView_allowScaling, false);
    TypedValue handle = a.peekValue(R.styleable.GlowPadView_handleDrawable);
    setHandleDrawable(handle != null ? handle.resourceId : R.drawable.ic_incall_audio_handle);
    mOuterRing = new TargetDrawable(res, getResourceId(a, R.styleable.GlowPadView_outerRingDrawable), 1);

    mAlwaysTrackFinger = a.getBoolean(R.styleable.GlowPadView_alwaysTrackFinger, false);

    int pointId = getResourceId(a, R.styleable.GlowPadView_pointDrawable);
    Drawable pointDrawable = pointId != 0 ? res.getDrawable(pointId) : null;
    mGlowRadius = a.getDimension(R.styleable.GlowPadView_glowRadius, 0.0f);

    TypedValue outValue = new TypedValue();

    // Read array of target drawables
    if (a.getValue(R.styleable.GlowPadView_targetDrawables, outValue)) {
        internalSetTargetResources(outValue.resourceId);
    }//from   w ww  .j a  v  a  2 s .  c om
    if (mTargetDrawables == null || mTargetDrawables.size() == 0) {
        throw new IllegalStateException("Must specify at least one target drawable");
    }

    // Read array of target descriptions
    if (a.getValue(R.styleable.GlowPadView_targetDescriptions, outValue)) {
        final int resourceId = outValue.resourceId;
        if (resourceId == 0) {
            throw new IllegalStateException("Must specify target descriptions");
        }
        setTargetDescriptionsResourceId(resourceId);
    }

    // Read array of direction descriptions
    if (a.getValue(R.styleable.GlowPadView_directionDescriptions, outValue)) {
        final int resourceId = outValue.resourceId;
        if (resourceId == 0) {
            throw new IllegalStateException("Must specify direction descriptions");
        }
        setDirectionDescriptionsResourceId(resourceId);
    }

    // Use gravity attribute from LinearLayout
    //a = context.obtainStyledAttributes(attrs, R.styleable.LinearLayout);
    mGravity = a.getInt(R.styleable.GlowPadView_android_gravity, Gravity.TOP);
    a.recycle();

    setVibrateEnabled(mVibrationDuration > 0);

    assignDefaultsIfNeeded();

    mPointCloud = new PointCloud(pointDrawable);
    mPointCloud.makePointCloud(mInnerRadius, mOuterRadius);
    mPointCloud.glowManager.setRadius(mGlowRadius);

    mExploreByTouchHelper = new GlowpadExploreByTouchHelper(this);
    ViewCompat.setAccessibilityDelegate(this, mExploreByTouchHelper);
}

From source file:android.support.designox.widget.CollapsingTextHelper.java

private void calculateBaseOffsets() {
    final float currentTextSize = mCurrentTextSize;

    // We then calculate the collapsed text size, using the same logic
    calculateUsingTextSize(mCollapsedTextSize);
    float width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0;
    final int collapsedAbsGravity = GravityCompat.getAbsoluteGravity(mCollapsedTextGravity,
            mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR);
    switch (collapsedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.BOTTOM:
        mCollapsedDrawY = mCollapsedBounds.bottom;
        break;/*  w  w w  .  j av a  2 s. c  o m*/
    case Gravity.TOP:
        mCollapsedDrawY = mCollapsedBounds.top - mTextPaint.ascent();
        break;
    case Gravity.CENTER_VERTICAL:
    default:
        float textHeight = mTextPaint.descent() - mTextPaint.ascent();
        float textOffset = (textHeight / 2) - mTextPaint.descent();
        mCollapsedDrawY = mCollapsedBounds.centerY() + textOffset;
        break;
    }
    switch (collapsedAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.CENTER_HORIZONTAL:
        mCollapsedDrawX = mCollapsedBounds.centerX() - (width / 2);
        break;
    case Gravity.RIGHT:
        mCollapsedDrawX = mCollapsedBounds.right - width;
        break;
    case Gravity.LEFT:
    default:
        mCollapsedDrawX = mCollapsedBounds.left;
        break;
    }

    calculateUsingTextSize(mExpandedTextSize);
    width = mTextToDraw != null ? mTextPaint.measureText(mTextToDraw, 0, mTextToDraw.length()) : 0;
    final int expandedAbsGravity = GravityCompat.getAbsoluteGravity(mExpandedTextGravity,
            mIsRtl ? ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR);
    switch (expandedAbsGravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.BOTTOM:
        mExpandedDrawY = mExpandedBounds.bottom;
        break;
    case Gravity.TOP:
        mExpandedDrawY = mExpandedBounds.top - mTextPaint.ascent();
        break;
    case Gravity.CENTER_VERTICAL:
    default:
        float textHeight = mTextPaint.descent() - mTextPaint.ascent();
        float textOffset = (textHeight / 2) - mTextPaint.descent();
        mExpandedDrawY = mExpandedBounds.centerY() + textOffset;
        break;
    }
    switch (expandedAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.CENTER_HORIZONTAL:
        mExpandedDrawX = mExpandedBounds.centerX() - (width / 2);
        break;
    case Gravity.RIGHT:
        mExpandedDrawX = mExpandedBounds.right - width;
        break;
    case Gravity.LEFT:
    default:
        mExpandedDrawX = mExpandedBounds.left;
        break;
    }

    // The bounds have changed so we need to clear the texture
    clearTexture();
    // Now reset the text size back to the original
    setInterpolatedTextSize(currentTextSize);
}

From source file:co.codecrunch.musicplayerlite.slidinguppanelhelper.SlidingUpPanelLayout.java

public void setGravity(int gravity) {
    if (gravity != Gravity.TOP && gravity != Gravity.BOTTOM) {
        throw new IllegalArgumentException("gravity must be set to either top or bottom");
    }//from  w  ww .j av a 2  s.  co  m
    mIsSlidingUp = gravity == Gravity.BOTTOM;
    if (!mFirstLayout) {
        requestLayout();
    }
}