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.sim2dial.dialer.StatusFragment.java

private void showZRTPDialog(final LinphoneCall call) {
    boolean authVerified = call.isAuthenticationTokenVerified();
    String format = getString(authVerified ? R.string.reset_sas_fmt : R.string.verify_sas_fmt);

    LayoutInflater inflater = LayoutInflater.from(getActivity());
    View layout = inflater.inflate(R.layout.zrtp_dialog,
            (ViewGroup) getActivity().findViewById(R.id.toastRoot));

    TextView toastText = (TextView) layout.findViewById(R.id.toastMessage);
    toastText.setText(String.format(format, call.getAuthenticationToken()));

    zrtpToast = new Toast(getActivity());
    zrtpToast.setGravity(Gravity.TOP | Gravity.RIGHT, 0, LinphoneUtils.pixelsToDpi(getResources(), 40));
    zrtpToast.setDuration(Toast.LENGTH_LONG);

    ImageView ok = (ImageView) layout.findViewById(R.id.toastOK);
    ok.setOnClickListener(new OnClickListener() {
        @Override/* ww w.j av a2 s. c  om*/
        public void onClick(View v) {
            if (call != null) {
                call.setAuthenticationTokenVerified(true);
            }
            if (encryption != null) {
                encryption.setImageResource(R.drawable.security_ok);
            }
            hideZRTPDialog();
        }
    });

    ImageView notOk = (ImageView) layout.findViewById(R.id.toastNotOK);
    notOk.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (call != null) {
                call.setAuthenticationTokenVerified(false);
            }
            if (encryption != null) {
                encryption.setImageResource(R.drawable.security_pending);
            }
            hideZRTPDialog();
        }
    });

    zrtpHack = new CountDownTimer(3000, 1000) {
        public void onTick(long millisUntilFinished) {
            if (!hideZrtpToast) {
                zrtpToast.show();
            }
        }

        public void onFinish() {
            if (!hideZrtpToast) {
                zrtpToast.show();
                zrtpHack.start();
            }
        }

    };

    zrtpToast.setView(layout);
    hideZrtpToast = false;
    zrtpToast.show();
    zrtpHack.start();
}

From source file:com.google.blockly.android.ToolboxFragment.java

/**
 * Updates the padding used to calculate the margins of the scrollable blocks, based on the size
 * and placement of the tabs./*from   w w w .  ja  v  a2s . c  om*/
 */
private void updateScrollablePadding() {
    int buttonHeight = mActionButton.getVisibility() == View.GONE ? 0 : mActionButton.getMeasuredHeight();
    int buttonWidth = mActionButton.getVisibility() == View.GONE ? 0 : mActionButton.getMeasuredWidth();
    int buttonVerticalPadding = 0, buttonHorizontalPadding = 0;
    if (mScrollOrientation == SCROLL_VERTICAL) {
        buttonVerticalPadding = buttonHeight;
    } else {
        buttonHorizontalPadding = buttonWidth;
    }
    int layoutDir = ViewCompat.getLayoutDirection(mRootView);
    int spacingForTabs;
    switch (GravityCompat.getAbsoluteGravity(mTabEdge, layoutDir)) {
    case Gravity.LEFT:
        spacingForTabs = hasTabs() ? mCategoryTabs.getMeasuredWidth() : 0; // Horizontal
        mScrollablePadding.set(spacingForTabs + buttonHorizontalPadding, buttonVerticalPadding, 0, 0);
        break;
    case Gravity.TOP:
        spacingForTabs = hasTabs() ? mCategoryTabs.getMeasuredHeight() : 0; // Vertical
        if (layoutDir == ViewCompat.LAYOUT_DIRECTION_LTR) {
            mScrollablePadding.set(buttonHorizontalPadding, spacingForTabs + buttonVerticalPadding, 0, 0);
        } else {
            mScrollablePadding.set(0, spacingForTabs + buttonVerticalPadding, buttonHorizontalPadding, 0);
        }
        break;
    case Gravity.RIGHT:
        spacingForTabs = hasTabs() ? mCategoryTabs.getMeasuredWidth() : 0; // Horizontal
        mScrollablePadding.set(0, buttonVerticalPadding, spacingForTabs + buttonHorizontalPadding, 0);
        break;
    case Gravity.BOTTOM:
        spacingForTabs = hasTabs() ? mCategoryTabs.getMeasuredHeight() : 0; // Vertical
        if (layoutDir == ViewCompat.LAYOUT_DIRECTION_LTR) {
            mScrollablePadding.set(buttonHorizontalPadding, 0, 0, spacingForTabs + buttonVerticalPadding);
        } else {
            mScrollablePadding.set(0, 0, buttonHorizontalPadding, spacingForTabs + buttonVerticalPadding);
        }
        break;
    }
}

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

/**
 * Check the lock mode of the drawer with the given gravity.
 * //from ww w . j  a v a  2s. com
 * @param edgeGravity
 *            Gravity of the drawer to check
 * @return one of {@link #LOCK_MODE_UNLOCKED},
 *         {@link #LOCK_MODE_LOCKED_CLOSED} or
 *         {@link #LOCK_MODE_LOCKED_OPEN}.
 */
public int getDrawerLockMode(int edgeGravity) {
    final int absGravity = GravityCompat.getAbsoluteGravity(edgeGravity, ViewCompat.getLayoutDirection(this));
    if (absGravity == Gravity.TOP) {
        return mLockModeTop;
    } else if (absGravity == Gravity.BOTTOM) {
        return mLockModeBottom;
    }
    return LOCK_MODE_UNLOCKED;
}

From source file:com.doubleTwist.drawerlib.ADrawerLayout.java

protected void layoutView(View v, int l, int t, int r, int b) {
    LayoutParams params = (LayoutParams) v.getLayoutParams();

    Rect bounds = new Rect();
    Rect boundsWithoutPeek = new Rect();
    int gravity = params.gravity;
    switch (gravity) {
    case Gravity.RIGHT:
        if (DEBUG)
            Log.d(TAG, "gravity: right");
        bounds.left = r - v.getMeasuredWidth() - mPeekSize.right;
        bounds.top = t;/*ww w . ja va2 s .c o m*/
        bounds.right = r - mPeekSize.right;
        bounds.bottom = t + v.getMeasuredHeight();
        v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom);
        boundsWithoutPeek = new Rect(bounds);
        boundsWithoutPeek.offset(mPeekSize.right, 0);
        mMinScrollX = -bounds.width();
        break;
    case Gravity.TOP:
        if (DEBUG)
            Log.d(TAG, "gravity: top");
        bounds.left = l;
        bounds.top = t + mPeekSize.top;
        bounds.right = v.getMeasuredWidth();
        bounds.bottom = t + v.getMeasuredHeight() + mPeekSize.top;
        v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom);
        boundsWithoutPeek = new Rect(bounds);
        boundsWithoutPeek.offset(0, -mPeekSize.top);
        mMaxScrollY = bounds.height();
        break;
    case Gravity.BOTTOM:
        if (DEBUG)
            Log.d(TAG, "gravity: bottom");
        bounds.left = l;
        bounds.top = b - v.getMeasuredHeight() - mPeekSize.bottom;
        bounds.right = l + v.getMeasuredWidth();
        bounds.bottom = b - mPeekSize.bottom;
        v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom);
        boundsWithoutPeek = new Rect(bounds);
        boundsWithoutPeek.offset(0, mPeekSize.bottom);
        mMinScrollY = -bounds.height();
        break;
    case Gravity.LEFT:
        if (DEBUG)
            Log.d(TAG, "gravity: left");
        bounds.left = l + mPeekSize.left;
        bounds.top = t;
        bounds.right = l + v.getMeasuredWidth() + mPeekSize.left;
        bounds.bottom = t + v.getMeasuredHeight();
        v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom);
        mMaxScrollX = bounds.width();
        boundsWithoutPeek = new Rect(bounds);
        boundsWithoutPeek.offset(-mPeekSize.left, 0);
        break;
    default:
        if (DEBUG)
            Log.d(TAG, "gravity: default");
        bounds.left = l;
        bounds.top = t;
        bounds.right = l + v.getMeasuredWidth();
        bounds.bottom = t + v.getMeasuredHeight();
        v.layout(bounds.left, bounds.top, bounds.right, bounds.bottom);
        boundsWithoutPeek = new Rect(bounds);
        break;
    }

    if (DEBUG) {
        Log.d(TAG, " == VIEW LAYOUT == " + v.toString());
        Log.d(TAG, "bounds: " + bounds.left + "," + bounds.top + "," + bounds.right + "," + bounds.bottom);
    }

    if (mLayoutBounds.containsKey(v))
        mLayoutBounds.remove(v);
    mLayoutBounds.put(v, bounds);
    if (mLayoutBoundsWithoutPeek.containsKey(v))
        mLayoutBoundsWithoutPeek.remove(v);
    mLayoutBoundsWithoutPeek.put(v, boundsWithoutPeek);
}

From source file:android.support.wear.widget.drawer.WearableDrawerLayout.java

/**
 * Peek the drawer./*from w  w w. java 2  s . com*/
 *
 * @param gravity {@link Gravity#TOP} to peek the top drawer or {@link Gravity#BOTTOM} to peek
 * the bottom drawer.
 */
void peekDrawer(final int gravity) {
    if (!isLaidOut()) {
        // If this view is not laid out yet, postpone the peek until onLayout is called.
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "WearableDrawerLayout not laid out yet. Postponing peek.");
        }
        switch (gravity) {
        case Gravity.TOP:
            mShouldPeekTopDrawerAfterLayout = true;
            break;
        case Gravity.BOTTOM:
            mShouldPeekBottomDrawerAfterLayout = true;
            break;
        default: // fall out
        }
        return;
    }
    final WearableDrawerView drawerView = findDrawerWithGravity(gravity);
    maybePeekDrawer(drawerView);
}

From source file:com.esri.android.mapsapp.MapFragment.java

/**
 * Takes a MapView that has already been instantiated to show a WebMap,
 * completes its setup by setting various listeners and attributes, and sets
 * it as the activity's content view./*from ww  w .  j  av a2s . c o m*/
 * 
 * @param mapView
 */
private void setMapView(final MapView mapView) {

    mMapView = mapView;
    mMapView.setEsriLogoVisible(true);
    mMapView.enableWrapAround(true);
    mapView.setAllowRotationByPinch(true);

    // Creating an inflater
    mInflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    // Setting up the layout params for the searchview and searchresult
    // layout
    mlayoutParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT,
            Gravity.LEFT | Gravity.TOP);
    int LEFT_MARGIN_SEARCH = 15;
    int RIGHT_MARGIN_SEARCH = 15;
    int BOTTOM_MARGIN_SEARCH = 0;
    mlayoutParams.setMargins(LEFT_MARGIN_SEARCH, TOP_MARGIN_SEARCH, RIGHT_MARGIN_SEARCH, BOTTOM_MARGIN_SEARCH);

    // Add the map to the layout
    mMapContainer.addView(mMapView, 0);

    // Set up floating action button
    setClickListenerForFloatingActionButton();

    // Displaying the searchbox layout
    showSearchBoxLayout();

    mMapView.setOnPinchListener(new OnPinchListener() {

        /**
         * Default value
         */
        private static final long serialVersionUID = 1L;

        @Override
        public void postPointersDown(float x1, float y1, float x2, float y2, double factor) {
        }

        @Override
        public void postPointersMove(float x1, float y1, float x2, float y2, double factor) {
        }

        @Override
        public void postPointersUp(float x1, float y1, float x2, float y2, double factor) {
        }

        @Override
        public void prePointersDown(float x1, float y1, float x2, float y2, double factor) {
        }

        @Override
        public void prePointersMove(float x1, float y1, float x2, float y2, double factor) {
            if (mMapView.getRotationAngle() > 5 || mMapView.getRotationAngle() < -5) {
                mCompass.setVisibility(View.VISIBLE);
                mCompass.sensorManager.unregisterListener(mCompass.sensorEventListener);
                mCompass.setRotationAngle(mMapView.getRotationAngle());
            }
        }

        @Override
        public void prePointersUp(float x1, float y1, float x2, float y2, double factor) {
        }

    });

    // Setup listener for map initialized
    mMapView.setOnStatusChangedListener(new OnStatusChangedListener() {

        private static final long serialVersionUID = 1L;

        @Override
        public void onStatusChanged(Object source, STATUS status) {

            if (source == mMapView && status == STATUS.INITIALIZED) {

                mapSpatialReference = mMapView.getSpatialReference();

                if (mMapViewState == null) {
                    // Starting location tracking will cause zoom to My
                    // Location
                    startLocationTracking();
                } else {
                    mMapView.restoreState(mMapViewState);
                }
                // add search and routing layers
                addGraphicLayers();
            }
        }
    });

    // Setup use of magnifier on a long press on the map
    mMapView.setShowMagnifierOnLongPress(true);
    mLongPressEvent = null;

    // Setup OnTouchListener to detect and act on long-press
    mMapView.setOnTouchListener(new MapOnTouchListener(getActivity(), mMapView) {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
                // Start of a new gesture. Make sure mLongPressEvent is
                // cleared.
                mLongPressEvent = null;
            }
            return super.onTouch(v, event);
        }

        @Override
        public void onLongPress(MotionEvent point) {
            // Set mLongPressEvent to indicate we are processing a
            // long-press
            mLongPressEvent = point;
            super.onLongPress(point);

        }

        @Override
        public boolean onDragPointerUp(MotionEvent from, final MotionEvent to) {
            if (mLongPressEvent != null) {
                // This is the end of a long-press that will have displayed
                // the
                // magnifier.
                // Perform reverse-geocoding of the point that was pressed
                Point mapPoint = mMapView.toMapPoint(to.getX(), to.getY());
                ReverseGeocodingAsyncTask reverseGeocodeTask = new ReverseGeocodingAsyncTask();
                reverseGeocodeTask.execute(mapPoint);
                mPendingTask = reverseGeocodeTask;

                mLongPressEvent = null;
                // Remove any previous graphics
                resetGraphicsLayers();
            }
            return super.onDragPointerUp(from, to);
        }

    });

}

From source file:com.pressurelabs.flowopensource.TheHubActivity.java

/**
 * Generates a Popup Menu with Two Actions Edit and Delete.
 *
 * Deleting the Flow removes the single card from the UI and also notifiers the AppDataManager to
 * delete from file//from w  w w. j  a va  2  s  .c o  m
 *
 * Editing launches a renaming process
 *
* @param longClickedFlow Flow represented by cardview longclicked
  * @param cardPosition position of cardview in adapter
 * @param cardViewClicked the cardview view object clicked
 * @return
 */
private boolean showLongClickPopUpMenu(final Flow longClickedFlow, final int cardPosition,
        final View cardViewClicked) {
    LayoutInflater layoutInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = layoutInflater.inflate(R.layout.popup_window_longclick, null);

    LinearLayout viewGroup = (LinearLayout) layout.findViewById(R.id.popup_longclick);

    // Creating the PopupWindow
    final PopupWindow popup = new PopupWindow(layout, RecyclerView.LayoutParams.WRAP_CONTENT,
            RecyclerView.LayoutParams.WRAP_CONTENT);

    int dividerMargin = viewGroup.getDividerPadding(); // Top bottom
    int popupPadding = layout.getPaddingBottom();
    int popupDisplayHeight = -(cardViewClicked.getHeight() - dividerMargin - popupPadding);

    // Prevents border

    popup.setBackgroundDrawable(new ColorDrawable());
    popup.setFocusable(true);

    // Getting a reference to Close button, and close the popup when clicked.
    ImageView delete = (ImageView) layout.findViewById(R.id.popup_delete_item);

    delete.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            /* Deletes current Flow from file and UI */
            rvContent.remove(cardPosition);
            manager.delete(longClickedFlow.getUuid());
            adapter.notifyItemRemoved(cardPosition);
            adapter.notifyItemRangeChanged(cardPosition, adapter.getItemCount());

            popup.dismiss();

            Snackbar bar = Snackbar.make(cardViewClicked, R.string.snackbar_hub_msg, Snackbar.LENGTH_LONG)
                    .setAction("NO!!!", new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            rvContent.add(cardPosition, longClickedFlow);
                            manager.save(longClickedFlow.getUuid(), longClickedFlow);
                            adapter.notifyItemInserted(cardPosition);
                        }
                    });

            bar.show();
        }
    });

    ImageView edit = (ImageView) layout.findViewById(R.id.popup_edit_item);

    edit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            popup.dismiss();
            renameFlow(cardPosition, cardViewClicked);

        }
    });

    // Displaying the popup at the specified location, + offsets.
    popup.showAsDropDown(cardViewClicked, cardViewClicked.getMeasuredWidth(), popupDisplayHeight, Gravity.TOP);
    longClickPopup = popup;
    return true;
}

From source file:info.semanticsoftware.semassist.android.activity.SemanticAssistantsActivity.java

/** Presents additional information about a specific assistant.
 * @return a dynamically generated linear layout
 *///w w w. j a v a 2  s .  c  o m
private LinearLayout getServiceDescLayout() {
    final LinearLayout output = new LinearLayout(this);
    final RelativeLayout topButtonsLayout = new RelativeLayout(this);
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

    final Button btnBack = new Button(this);
    btnBack.setText(R.string.btnAllServices);
    btnBack.setId(5);
    btnBack.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            output.setVisibility(View.GONE);
            getListView().setVisibility(View.VISIBLE);
            lblAvAssist.setVisibility(View.VISIBLE);
        }
    });

    topButtonsLayout.addView(btnBack);

    final Button btnInvoke = new Button(this);
    btnInvoke.setText(R.string.btnInvokeLabel);
    btnInvoke.setId(6);

    btnInvoke.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            new InvocationTask().execute();
        }
    });

    layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, btnInvoke.getId());
    btnInvoke.setLayoutParams(layoutParams);
    topButtonsLayout.addView(btnInvoke);

    output.addView(topButtonsLayout);

    TableLayout serviceInfoTbl = new TableLayout(this);
    output.addView(serviceInfoTbl);

    serviceInfoTbl.setColumnShrinkable(1, true);

    /* FIRST ROW */
    TableRow rowServiceName = new TableRow(this);

    TextView lblServiceName = new TextView(this);
    lblServiceName.setText(R.string.lblServiceName);
    lblServiceName.setTextAppearance(getApplicationContext(), R.style.titleText);

    TextView txtServiceName = new TextView(this);
    txtServiceName.setText(selectedService);
    txtServiceName.setTextAppearance(getApplicationContext(), R.style.normalText);
    txtServiceName.setPadding(10, 0, 0, 0);

    rowServiceName.addView(lblServiceName);
    rowServiceName.addView(txtServiceName);

    /* SECOND ROW */
    TableRow rowServiceDesc = new TableRow(this);

    TextView lblServiceDesc = new TextView(this);
    lblServiceDesc.setText(R.string.lblServiceDesc);
    lblServiceDesc.setTextAppearance(getApplicationContext(), R.style.titleText);

    TextView txtServiceDesc = new TextView(this);
    txtServiceDesc.setTextAppearance(getApplicationContext(), R.style.normalText);
    txtServiceDesc.setPadding(10, 0, 0, 0);
    List<GateRuntimeParameter> params = null;
    ServiceInfoForClientArray list = getServices();
    for (int i = 0; i < list.getItem().size(); i++) {
        if (list.getItem().get(i).getServiceName().equals(selectedService)) {
            txtServiceDesc.setText(list.getItem().get(i).getServiceDescription());
            params = list.getItem().get(i).getParams();
            break;
        }
    }

    TextView lblParams = new TextView(this);
    lblParams.setText(R.string.lblServiceParams);
    lblParams.setTextAppearance(getApplicationContext(), R.style.titleText);
    output.addView(lblParams);

    LayoutParams txtParamsAttrbs = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
    LinearLayout paramsLayout = new LinearLayout(this);
    paramsLayout.setId(0);

    if (params.size() > 0) {
        ScrollView scroll = new ScrollView(this);
        scroll.setLayoutParams(txtParamsAttrbs);
        paramsLayout.setOrientation(LinearLayout.VERTICAL);
        scroll.addView(paramsLayout);
        for (int j = 0; j < params.size(); j++) {
            TextView lblParamName = new TextView(this);
            lblParamName.setText(params.get(j).getParamName());
            EditText tview = new EditText(this);
            tview.setId(1);
            tview.setText(params.get(j).getDefaultValueString());
            LayoutParams txtViewLayoutParams = new LayoutParams(LayoutParams.FILL_PARENT,
                    LayoutParams.WRAP_CONTENT);
            tview.setLayoutParams(txtViewLayoutParams);
            paramsLayout.addView(lblParamName);
            paramsLayout.addView(tview);
        }
        output.addView(scroll);
    } else {
        TextView lblParamName = new TextView(this);
        lblParamName.setText(R.string.lblRTParams);
        output.addView(lblParamName);
    }

    rowServiceDesc.addView(lblServiceDesc);
    rowServiceDesc.addView(txtServiceDesc);

    serviceInfoTbl.addView(rowServiceName);
    serviceInfoTbl.addView(rowServiceDesc);

    output.setOrientation(LinearLayout.VERTICAL);
    output.setGravity(Gravity.TOP);

    return output;
}

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

/**
 * Check the lock mode of the given drawer view.
 * //ww  w . jav a2 s.  co m
 * @param drawerView
 *            Drawer view to check lock mode
 * @return one of {@link #LOCK_MODE_UNLOCKED},
 *         {@link #LOCK_MODE_LOCKED_CLOSED} or
 *         {@link #LOCK_MODE_LOCKED_OPEN}.
 */
public int getDrawerLockMode(View drawerView) {
    final int absGravity = getDrawerViewAbsoluteGravity(drawerView);
    if (absGravity == Gravity.TOP) {
        return mLockModeTop;
    } else if (absGravity == Gravity.BOTTOM) {
        return mLockModeBottom;
    }
    return LOCK_MODE_UNLOCKED;
}

From source file:com.github.topbottomsnackbar.TBSnackbar.java

/**
 * Show the {@link TBSnackbar}.// w w  w .  ja va 2  s .  c om
 */
public void show() {
    if (mStyle == STYLE_SHOW_BOTTOM) {
        changeLayoutParams(Gravity.BOTTOM);

    } else {
        changeLayoutParams(Gravity.TOP);
        if (mStyle == STYLE_SHOW_TOP_FITSYSTEMWINDOW) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
                mView.setPadding(0, getStatusBarHeight(mContext), 0, 0);
        }
    }
    TBSnackbarManager.getInstance().show(mDuration, mManagerCallback);
}