Example usage for android.view Gravity RIGHT

List of usage examples for android.view Gravity RIGHT

Introduction

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

Prototype

int RIGHT

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

Click Source Link

Document

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

Usage

From source file:com.ubergeek42.WeechatAndroid.ChatLinesAdapter.java

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;/*from  ww  w .j a va 2  s.com*/

    // If we don't have the view, or we were using a filteredView, inflate a new one
    if (convertView == null) {
        convertView = inflater.inflate(R.layout.chatview_line, null);
        holder = new ViewHolder();
        holder.timestamp = (TextView) convertView.findViewById(R.id.chatline_timestamp);
        holder.prefix = (TextView) convertView.findViewById(R.id.chatline_prefix);
        holder.message = (TextView) convertView.findViewById(R.id.chatline_message);

        convertView.setTag(holder);

    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    // Change the font sizes
    holder.timestamp.setTextSize(textSize);
    holder.prefix.setTextSize(textSize);
    holder.message.setTextSize(textSize);

    BufferLine chatLine = (BufferLine) getItem(position);

    // Render the timestamp
    if (enableTimestamp) {
        holder.timestamp.setText(timestampFormat.format(chatLine.getTimestamp()));
        holder.timestamp.setPadding(holder.timestamp.getPaddingLeft(), holder.timestamp.getPaddingTop(), 5,
                holder.timestamp.getPaddingBottom());
    } else {
        holder.timestamp.setText("");
        holder.timestamp.setPadding(holder.timestamp.getPaddingLeft(), holder.timestamp.getPaddingTop(), 0,
                holder.timestamp.getPaddingBottom());
    }

    // Recalculate the prefix width based on the size of one character(fixed width font)
    if (prefixWidth == 0) {
        holder.prefix.setMinimumWidth(0);
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < maxPrefix; i++) {
            sb.append("m");
        }
        holder.prefix.setText(sb.toString());
        holder.prefix.measure(convertView.getWidth(), convertView.getHeight());
        prefixWidth = holder.prefix.getMeasuredWidth();
    }

    // Render the prefix
    if (chatLine.getHighlight()) {
        String prefixStr = chatLine.getPrefix();
        Spannable highlightText = new SpannableString(prefixStr);
        highlightText.setSpan(new ForegroundColorSpan(Color.YELLOW), 0, prefixStr.length(),
                Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        highlightText.setSpan(new BackgroundColorSpan(Color.MAGENTA), 0, prefixStr.length(),
                Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        holder.prefix.setText(highlightText);
    } else {
        if (enableColor) {
            holder.prefix.setText(Html.fromHtml(chatLine.getPrefixHTML()), TextView.BufferType.SPANNABLE);
        } else {
            holder.prefix.setText(chatLine.getPrefix());
        }
    }
    if (prefix_align.equals("right")) {
        holder.prefix.setGravity(Gravity.RIGHT);
        holder.prefix.setMinimumWidth(prefixWidth);
    } else if (prefix_align.equals("left")) {
        holder.prefix.setGravity(Gravity.LEFT);
        holder.prefix.setMinimumWidth(prefixWidth);
    } else {
        holder.prefix.setGravity(Gravity.LEFT);
        holder.prefix.setMinimumWidth(0);
    }

    // Render the message

    if (enableColor) {
        holder.message.setText(Html.fromHtml(chatLine.getMessageHTML()), TextView.BufferType.SPANNABLE);
    } else {
        holder.message.setText(chatLine.getMessage());
    }

    return convertView;
}

From source file:android.support.transition.SidePropagation.java

private int getMaxDistance(ViewGroup sceneRoot) {
    switch (mSide) {
    case Gravity.LEFT:
    case Gravity.RIGHT:
    case Gravity.START:
    case Gravity.END:
        return sceneRoot.getWidth();
    default:/*from  ww w.  ja  v a2s  . c om*/
        return sceneRoot.getHeight();
    }
}

From source file:com.brookmanholmes.bma.wizard.ui.StepPagerStrip.java

private int hitTest(float x) {
    if (pageCount == 0) {
        return -1;
    }//from  w  w w.j  a va  2 s .  co m

    float totalWidth = pageCount * (tabWidth + indicatorSpacing) - indicatorSpacing;
    float totalLeft;
    boolean fillHorizontal = false;

    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.CENTER_HORIZONTAL:
        totalLeft = (getWidth() - totalWidth) / 2;
        break;
    case Gravity.RIGHT:
        totalLeft = getWidth() - getPaddingRight() - totalWidth;
        break;
    case Gravity.FILL_HORIZONTAL:
        totalLeft = getPaddingLeft();
        fillHorizontal = true;
        break;
    default:
        totalLeft = getPaddingLeft();
    }

    float tabWidth = this.tabWidth;
    if (fillHorizontal) {
        tabWidth = (getWidth() - getPaddingRight() - getPaddingLeft() - (pageCount - 1) * indicatorSpacing)
                / pageCount;
    }

    float totalRight = totalLeft + (pageCount * (tabWidth + indicatorSpacing));
    if (x >= totalLeft && x <= totalRight && totalRight > totalLeft) {
        return (int) (((x - totalLeft) / (totalRight - totalLeft)) * pageCount);
    } else {
        return -1;
    }
}

From source file:com.gh4a.BaseActivity.java

protected boolean closeDrawers() {
    boolean result = false;
    if (mDrawerLayout.isDrawerOpen(Gravity.LEFT)) {
        mDrawerLayout.closeDrawer(Gravity.LEFT);
        result = true;/* w  w  w .  j  a  va2 s  .c om*/
    }
    if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT)) {
        mDrawerLayout.closeDrawer(Gravity.RIGHT);
        result = true;
    }
    return result;
}

From source file:com.tmall.wireless.tangram3.view.BannerView.java

public void setIndicatorGravity(int gravity) {
    switch (gravity) {
    case GRAVITY_LEFT:
        if (mIndicator != null) {
            mIndicator.setGravity(Gravity.LEFT);
        }/*from ww  w.  j  a va 2s.  c  o  m*/
        break;
    case GRAVITY_CENTER:
        if (mIndicator != null) {
            mIndicator.setGravity(Gravity.CENTER_HORIZONTAL);
        }
        break;
    case GRAVITY_RIGHT:
        if (mIndicator != null) {
            mIndicator.setGravity(Gravity.RIGHT);
        }
        break;
    default:
        break;
    }
}

From source file:com.sonvp.tooltip.Tooltip.java

private Tooltip(Builder builder) {
    this.builder = builder;
    this.anchorView = builder.anchorView;
    this.gravity = builder.tooltipGravity;

    if (builder.dismissOutsideTouch) {

        rootView = (ViewGroup) anchorView.getRootView();
        overlay = new View(builder.context);
        overlay.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        //        overlay.setBackgroundColor(builder.context.getResources().getColor(android.R.color.holo_green_light));
        overlay.setOnTouchListener(this);
        rootView.addView(overlay);/*from  ww w . j av a 2s  .  co  m*/
    }

    // TODO container should NOT capture all events
    container = new LinearLayout(builder.context);
    container.setOnClickListener(this);

    int backgroundColor = builder.backgroundColor;

    viewTooltip = getViewTooltip(builder, backgroundColor);

    rectAnchorView = getRectView(anchorView);
    changeGravityToolTip();
    if (builder.arrowDrawable == null) {
        builder.arrowDrawable = new ArrowDrawable(backgroundColor, gravity);
    }

    arrow = new ImageView(builder.context);
    // TODO supports Gravity.NO_GRAVITY
    switch (gravity) {
    case Gravity.LEFT:
        container.setOrientation(LinearLayout.HORIZONTAL);
        container.addView(viewTooltip, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        arrow.setImageDrawable(builder.arrowDrawable);
        container.addView(arrow,
                new LinearLayout.LayoutParams((int) builder.arrowWidth, (int) builder.arrowHeight));
        break;
    case Gravity.RIGHT:
        container.setOrientation(LinearLayout.HORIZONTAL);
        arrow.setImageDrawable(builder.arrowDrawable);
        container.addView(arrow,
                new LinearLayout.LayoutParams((int) builder.arrowWidth, (int) builder.arrowHeight));
        container.addView(viewTooltip, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        break;
    case Gravity.TOP:
        container.setOrientation(LinearLayout.VERTICAL);
        container.addView(viewTooltip, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        arrow.setImageDrawable(builder.arrowDrawable);
        container.addView(arrow,
                new LinearLayout.LayoutParams((int) builder.arrowWidth, (int) builder.arrowHeight));
        break;
    case Gravity.BOTTOM:
        container.setOrientation(LinearLayout.VERTICAL);
        arrow.setImageDrawable(builder.arrowDrawable);
        container.addView(arrow,
                new LinearLayout.LayoutParams((int) builder.arrowWidth, (int) builder.arrowHeight));
        container.addView(viewTooltip, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));
        break;
    }

    popupWindow = new PopupWindow(container, ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    popupWindow.setOnDismissListener(this);
    popupWindow.setClippingEnabled(false);
    popupWindow.setAnimationStyle(android.R.style.Animation);
    //        popupWindow.setBackgroundDrawable(builder.context.getResources().getDrawable(android.R.color.holo_blue_bright));

}

From source file:biz.mosil.demo.navigationdrawer.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (mDrawerToggle.onOptionsItemSelected(item)) {
        //  DrawerLayout  Drawer 
        if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT)) {
            //  DrawerLayout ? Drawer
            mDrawerLayout.closeDrawer(Gravity.RIGHT);
        }/*w  ww. j  ava 2  s .  c  o m*/
        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.gh4a.BaseActivity.java

protected void toggleRightSideDrawer() {
    if (mDrawerLayout.isDrawerOpen(Gravity.RIGHT)) {
        mDrawerLayout.closeDrawer(Gravity.RIGHT);
    } else {//from   w w w  .j a v  a 2s  . co m
        mDrawerLayout.openDrawer(Gravity.RIGHT);
    }
}

From source file:org.lol.reddit.activities.CaptchaActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    PrefsUtility.applyTheme(this);
    getSupportActionBar().setTitle(R.string.post_captcha_title);

    super.onCreate(savedInstanceState);

    final LoadingView loadingView = new LoadingView(this, R.string.download_waiting, true, true);
    setContentView(loadingView);/*from   w w w  .  j a va2  s  . c  o m*/

    final RedditAccount selectedAccount = RedditAccountManager.getInstance(this)
            .getAccount(getIntent().getStringExtra("username"));

    final CacheManager cm = CacheManager.getInstance(this);

    RedditAPI.newCaptcha(cm, new APIResponseHandler.NewCaptchaResponseHandler(this) {
        @Override
        protected void onSuccess(final String captchaId) {

            final URI captchaUrl = Constants.Reddit.getUri("/captcha/" + captchaId);

            cm.makeRequest(new CacheRequest(captchaUrl, RedditAccountManager.getAnon(), null,
                    Constants.Priority.CAPTCHA, 0, CacheRequest.DownloadType.FORCE, Constants.FileType.CAPTCHA,
                    false, false, true, CaptchaActivity.this) {
                @Override
                protected void onCallbackException(Throwable t) {
                    BugReportActivity.handleGlobalError(CaptchaActivity.this, t);
                }

                @Override
                protected void onDownloadNecessary() {
                }

                @Override
                protected void onDownloadStarted() {
                    loadingView.setIndeterminate(R.string.download_downloading);
                }

                @Override
                protected void onFailure(RequestFailureType type, Throwable t, StatusLine status,
                        String readableMessage) {
                    final RRError error = General.getGeneralErrorForFailure(CaptchaActivity.this, type, t,
                            status, url.toString());
                    General.showResultDialog(CaptchaActivity.this, error);
                    finish();
                }

                @Override
                protected void onProgress(long bytesRead, long totalBytes) {
                    loadingView.setProgress(R.string.download_downloading,
                            (float) ((double) bytesRead / (double) totalBytes));
                }

                @Override
                protected void onSuccess(final CacheManager.ReadableCacheFile cacheFile, long timestamp,
                        UUID session, boolean fromCache, String mimetype) {

                    final Bitmap image;
                    try {
                        image = BitmapFactory.decodeStream(cacheFile.getInputStream());
                    } catch (IOException e) {
                        BugReportActivity.handleGlobalError(CaptchaActivity.this, e);
                        return;
                    }

                    General.UI_THREAD_HANDLER.post(new Runnable() {
                        public void run() {

                            final LinearLayout ll = new LinearLayout(CaptchaActivity.this);
                            ll.setOrientation(LinearLayout.VERTICAL);

                            final ImageView captchaImg = new ImageView(CaptchaActivity.this);
                            ll.addView(captchaImg);
                            final LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) captchaImg
                                    .getLayoutParams();
                            layoutParams.setMargins(20, 20, 20, 20);
                            layoutParams.height = General.dpToPixels(context, 100);
                            captchaImg.setScaleType(ImageView.ScaleType.FIT_CENTER);

                            final EditText captchaText = new EditText(CaptchaActivity.this);
                            ll.addView(captchaText);
                            ((LinearLayout.LayoutParams) captchaText.getLayoutParams()).setMargins(20, 0, 20,
                                    20);
                            captchaText.setInputType(android.text.InputType.TYPE_CLASS_TEXT
                                    | android.text.InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
                                    | InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);

                            captchaImg.setImageBitmap(image);

                            final Button submitButton = new Button(CaptchaActivity.this);
                            submitButton.setText(R.string.post_captcha_submit_button);
                            ll.addView(submitButton);
                            ((LinearLayout.LayoutParams) submitButton.getLayoutParams()).setMargins(20, 0, 20,
                                    20);
                            ((LinearLayout.LayoutParams) submitButton
                                    .getLayoutParams()).gravity = Gravity.RIGHT;
                            ((LinearLayout.LayoutParams) submitButton
                                    .getLayoutParams()).width = LinearLayout.LayoutParams.WRAP_CONTENT;

                            submitButton.setOnClickListener(new View.OnClickListener() {
                                public void onClick(View v) {
                                    final Intent result = new Intent();
                                    result.putExtra("captchaId", captchaId);
                                    result.putExtra("captchaText", captchaText.getText().toString());
                                    setResult(RESULT_OK, result);
                                    finish();
                                }
                            });

                            final ScrollView sv = new ScrollView(CaptchaActivity.this);
                            sv.addView(ll);
                            setContentView(sv);
                        }
                    });

                }
            });
        }

        @Override
        protected void onCallbackException(Throwable t) {
            BugReportActivity.handleGlobalError(CaptchaActivity.this, t);
        }

        @Override
        protected void onFailure(RequestFailureType type, Throwable t, StatusLine status,
                String readableMessage) {
            final RRError error = General.getGeneralErrorForFailure(CaptchaActivity.this, type, t, status,
                    null);
            General.showResultDialog(CaptchaActivity.this, error);
            finish();
        }

        @Override
        protected void onFailure(APIFailureType type) {
            final RRError error = General.getGeneralErrorForFailure(CaptchaActivity.this, type);
            General.showResultDialog(CaptchaActivity.this, error);
            finish();
        }
    }, selectedAccount, this);
}

From source file:com.kyo.fitssystemwindows.FitsSystemWindowsFrameLayout.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final boolean applyInsets = lastInsets != null && ViewCompat.getFitsSystemWindows(this);
    final int layoutDirection = ViewCompat.getLayoutDirection(this);
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);

        if (child.getVisibility() == GONE) {
            continue;
        }//from   w w w  .j  a  va 2  s  .  c o  m

        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        if (lp.gravity == -1) {
            lp.gravity = DEFAULT_CHILD_GRAVITY;
        }

        if (applyInsets) {
            int cgrav = GravityCompat.getAbsoluteGravity(lp.gravity, layoutDirection);

            if (cgrav == -1) {
                cgrav = DEFAULT_CHILD_GRAVITY;
            } else {
                if ((cgrav & Gravity.VERTICAL_GRAVITY_MASK) == 0) {
                    cgrav = cgrav | Gravity.TOP;
                }
                if ((cgrav & Gravity.HORIZONTAL_GRAVITY_MASK) == 0) {
                    cgrav = cgrav | (layoutDirection == LAYOUT_DIRECTION_LTR ? Gravity.LEFT : Gravity.RIGHT);
                }
            }

            if (ViewCompat.getFitsSystemWindows(child)) {
                final int l = child.getPaddingLeft();
                final int t = child.getPaddingTop();
                final int r = child.getPaddingRight();
                final int b = child.getPaddingBottom();
                IMPL.dispatchChildInsets(child, lp, cgrav, lastInsets);
                child.setPadding(l, t, r, b);
            } else {
                IMPL.applyMarginInsets(lp, cgrav, lastInsets);
                lp.leftMargin += lp.leftMargin2;
                lp.topMargin += lp.topMargin2;
                lp.rightMargin += lp.rightMargin2;
                lp.bottomMargin += lp.bottomMargin2;
            }
        }
    }
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() == GONE || ViewCompat.getFitsSystemWindows(child)) {
            continue;
        }
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        lp.leftMargin -= lp.leftMargin2;
        lp.topMargin -= lp.topMargin2;
        lp.rightMargin -= lp.rightMargin2;
        lp.bottomMargin -= lp.bottomMargin2;
    }
}