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.amitupadhyay.aboutexample.ui.widget.FabOverlapTextView.java

private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    paint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FabOverlapTextView);

    float defaultTextSize = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, DEFAULT_TEXT_SIZE_SP,
            getResources().getDisplayMetrics());

    setFabOverlapGravity(a.getInt(R.styleable.FabOverlapTextView_fabGravity, Gravity.BOTTOM | Gravity.RIGHT));
    setFabOverlapHeight(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_fabOverlayHeight, 0));
    setFabOverlapWidth(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_fabOverlayWidth, 0));

    if (a.hasValue(R.styleable.FabOverlapTextView_android_textAppearance)) {
        final int textAppearance = a.getResourceId(R.styleable.FabOverlapTextView_android_textAppearance,
                android.R.style.TextAppearance);
        TypedArray atp = getContext().obtainStyledAttributes(textAppearance, R.styleable.FontTextAppearance);
        paint.setColor(atp.getColor(R.styleable.FontTextAppearance_android_textColor, Color.BLACK));
        paint.setTextSize(atp.getDimensionPixelSize(R.styleable.FontTextAppearance_android_textSize,
                (int) defaultTextSize));
        if (atp.hasValue(R.styleable.FontTextAppearance_font)) {
            paint.setTypeface(FontUtil.get(getContext(), atp.getString(R.styleable.FontTextAppearance_font)));
        }//from   www.ja v  a2  s  . c  o m
        atp.recycle();
    }

    if (a.hasValue(R.styleable.FabOverlapTextView_font)) {
        setFont(a.getString(R.styleable.FabOverlapTextView_font));
    }

    if (a.hasValue(R.styleable.FabOverlapTextView_android_textColor)) {
        setTextColor(a.getColor(R.styleable.FabOverlapTextView_android_textColor, 0));
    }
    if (a.hasValue(R.styleable.FabOverlapTextView_android_textSize)) {
        setTextSize(a.getDimensionPixelSize(R.styleable.FabOverlapTextView_android_textSize,
                (int) defaultTextSize));
    }

    lineHeightHint = a.getDimensionPixelSize(R.styleable.FabOverlapTextView_lineHeightHint, 0);
    unalignedTopPadding = getPaddingTop();
    unalignedBottomPadding = getPaddingBottom();

    breakStrategy = a.getInt(R.styleable.FabOverlapTextView_android_breakStrategy,
            Layout.BREAK_STRATEGY_BALANCED);

    a.recycle();
}

From source file:am.project.x.business.drawables.cornerdrawable.CornerDrawableActivity.java

@SuppressLint("RtlHardcoded")
@Override/*from   w w w  . ja  va2 s  .c  om*/
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    switch (parent.getId()) {
    case R.id.cnd_sp_direction:
        switch (position) {
        default:
        case 0:
            drawable.setDirection(Gravity.TOP);
            break;
        case 1:
            drawable.setDirection(Gravity.LEFT);
            break;
        case 2:
            drawable.setDirection(Gravity.RIGHT);
            break;
        case 3:
            drawable.setDirection(Gravity.BOTTOM);
            break;
        }
        break;
    case R.id.cnd_sp_location:
        switch (position) {
        default:
        case 0:
            drawable.setLocation(Gravity.CENTER);
            break;
        case 1:
            drawable.setLocation(Gravity.LEFT);
            break;
        case 2:
            drawable.setLocation(Gravity.RIGHT);
            break;
        }
        break;
    }
}

From source file:com.example.android.supportv7.app.ToolbarDisplayOptions.java

@Override
public void onClick(View v) {
    final ActionBar bar = getSupportActionBar();
    int flags = 0;
    switch (v.getId()) {
    case R.id.toggle_home_as_up:
        flags = ActionBar.DISPLAY_HOME_AS_UP;
        break;/*  w  w  w  .  ja v  a 2  s .  com*/
    case R.id.toggle_show_home:
        flags = ActionBar.DISPLAY_SHOW_HOME;
        break;
    case R.id.toggle_use_logo:
        flags = ActionBar.DISPLAY_USE_LOGO;
        getSupportActionBar().setLogo(R.drawable.ic_media_play);
        break;
    case R.id.toggle_show_title:
        flags = ActionBar.DISPLAY_SHOW_TITLE;
        break;
    case R.id.toggle_show_custom:
        flags = ActionBar.DISPLAY_SHOW_CUSTOM;
        break;
    case R.id.cycle_custom_gravity: {
        ActionBar.LayoutParams lp = mCustomViewLayoutParams;
        int newGravity = 0;
        switch (lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.LEFT:
            newGravity = Gravity.CENTER_HORIZONTAL;
            break;
        case Gravity.CENTER_HORIZONTAL:
            newGravity = Gravity.RIGHT;
            break;
        case Gravity.RIGHT:
            newGravity = Gravity.LEFT;
            break;
        }
        lp.gravity = lp.gravity & ~Gravity.HORIZONTAL_GRAVITY_MASK | newGravity;
        bar.setCustomView(mCustomView, lp);
        return;
    }
    case R.id.toggle_visibility:
        if (bar.isShowing()) {
            bar.hide();
        } else {
            bar.show();
        }
        return;
    }

    int change = bar.getDisplayOptions() ^ flags;
    bar.setDisplayOptions(change, flags);
}

From source file:com.dwdesign.tweetings.adapter.DirectMessagesConversationAdapter.java

@Override
public void bindView(final View view, final Context context, final Cursor cursor) {
    final int position = cursor.getPosition();
    final DirectMessageConversationViewHolder holder = (DirectMessageConversationViewHolder) view.getTag();

    final long account_id = cursor.getLong(mIndices.account_id);
    final long message_timestamp = cursor.getLong(mIndices.message_timestamp);
    final long sender_id = cursor.getLong(mIndices.sender_id);

    final boolean is_outgoing = account_id == sender_id;

    final String name = mDisplayName ? cursor.getString(mIndices.sender_name)
            : cursor.getString(mIndices.sender_screen_name);

    holder.setTextSize(mTextSize);/*from w  ww . j  a v  a2  s  . c o  m*/
    final TwidereLinkify linkify = new TwidereLinkify(holder.text);
    linkify.setOnLinkClickListener(new OnLinkClickHandler(context, account_id));
    linkify.addAllLinks();
    holder.text.setMovementMethod(null);
    holder.name.setText(name);
    holder.name.setGravity(is_outgoing ? Gravity.LEFT : Gravity.RIGHT);
    holder.text.setText(cursor.getString(mIndices.text));
    holder.text.setGravity(is_outgoing ? Gravity.LEFT : Gravity.RIGHT);
    holder.time.setText(formatToLongTimeString(mContext, message_timestamp));
    holder.time.setGravity(is_outgoing ? Gravity.RIGHT : Gravity.LEFT);
    holder.profile_image_left.setVisibility(mDisplayProfileImage && is_outgoing ? View.VISIBLE : View.GONE);
    holder.profile_image_right.setVisibility(mDisplayProfileImage && !is_outgoing ? View.VISIBLE : View.GONE);
    if (mDisplayProfileImage) {
        final String sender_profile_image_url_string = cursor.getString(mIndices.sender_profile_image_url);
        final URL sender_profile_image_url = parseURL(
                mDisplayHiResProfileImage ? getBiggerTwitterProfileImage(sender_profile_image_url_string)
                        : sender_profile_image_url_string);

        mImageLoader.displayProfileImage(holder.profile_image_left, String.valueOf(sender_profile_image_url));
        mImageLoader.displayProfileImage(holder.profile_image_right, String.valueOf(sender_profile_image_url));
        holder.profile_image_left.setTag(position);
        holder.profile_image_right.setTag(position);
    }

    super.bindView(view, context, cursor);
}

From source file:com.example.android.navigationdrawerexample.RightDrawerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_right_drawer);

    mTitle = mDrawerTitle = getTitle();//from   w w w. j  a v a 2 s. com
    mPlanetTitles = getResources().getStringArray(R.array.planets_array);
    mHorizonDrawerLayout = (HorizonDrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.right_drawer);

    // set a custom shadow that overlays the main content when the drawer opens
    mHorizonDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.LEFT);
    // set up the drawer's list view with items and click listener
    mDrawerList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mPlanetTitles));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    // enable ActionBar app icon to behave as action to toggle nav drawer
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mHorizonDrawerToggle = new ActionBarHorizonDrawerToggle(this, /* host Activity */
            getSupportActionBar(), /* ActionBar of the hosting Activity */
            mHorizonDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            getSupportActionBar().setTitle(mTitle);
            supportInvalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            getSupportActionBar().setTitle(mDrawerTitle);
            supportInvalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };
    mHorizonDrawerToggle.setGravity(Gravity.RIGHT);
    mHorizonDrawerLayout.setDrawerListener(mHorizonDrawerToggle);

    if (savedInstanceState == null) {
        selectItem(0);
    }
}

From source file:com.example.android.navigationdrawerexample.ContentDrawerActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_content_drawer);

    mTitle = mDrawerTitle = getTitle();//  w  ww.  j ava  2s .  c  o m
    mPlanetTitles = getResources().getStringArray(R.array.planets_array);
    mContentDrawerLayout = (ContentDrawerLayout) findViewById(R.id.drawer_layout);
    mDrawerList = (ListView) findViewById(R.id.content_drawer);

    // set a custom shadow that overlays the main content when the drawer opens
    mContentDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.LEFT);
    // set up the drawer's list view with items and click listener
    mDrawerList.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, mPlanetTitles));
    mDrawerList.setOnItemClickListener(new DrawerItemClickListener());

    // enable ActionBar app icon to behave as action to toggle nav drawer
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);

    // ActionBarDrawerToggle ties together the the proper interactions
    // between the sliding drawer and the action bar app icon
    mContentDrawerToggle = new ActionBarContentDrawerToggle(this, /* host Activity */
            getSupportActionBar(), /* ActionBar of the hosting Activity */
            mContentDrawerLayout, /* DrawerLayout object */
            R.drawable.ic_drawer, /* nav drawer image to replace 'Up' caret */
            R.string.drawer_open, /* "open drawer" description for accessibility */
            R.string.drawer_close /* "close drawer" description for accessibility */
    ) {
        public void onDrawerClosed(View view) {
            getSupportActionBar().setTitle(mTitle);
            supportInvalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }

        public void onDrawerOpened(View drawerView) {
            getSupportActionBar().setTitle(mDrawerTitle);
            supportInvalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
        }
    };
    mContentDrawerToggle.setGravity(Gravity.RIGHT);
    mContentDrawerLayout.setDrawerListener(mContentDrawerToggle);

    if (savedInstanceState == null) {
        selectItem(0);
    }
}

From source file:com.photocitygame.android.ImageActivity.java

private void addScoreRow(TableLayout scoreTable, String team, int score) {
    TableRow row = new TableRow(this);
    TextView tv = new TextView(this);
    tv.setText(team);//from  ww  w.  ja  v  a 2 s  .  c o m
    row.addView(tv);
    TextView scoreView = new TextView(this);
    scoreView.setText(Integer.toString(score));
    scoreView.setGravity(Gravity.RIGHT);
    row.addView(scoreView);
    scoreTable.addView(row);
}

From source file:com.example.android.supportv7.app.ActionBarDisplayOptions.java

@Override
public void onClick(View v) {
    final ActionBar bar = getSupportActionBar();
    int flags = 0;
    switch (v.getId()) {
    case R.id.toggle_home_as_up:
        flags = ActionBar.DISPLAY_HOME_AS_UP;
        break;/*w ww  .jav  a2 s  .  c o m*/
    case R.id.toggle_show_home:
        flags = ActionBar.DISPLAY_SHOW_HOME;
        break;
    case R.id.toggle_use_logo:
        flags = ActionBar.DISPLAY_USE_LOGO;
        break;
    case R.id.toggle_show_title:
        flags = ActionBar.DISPLAY_SHOW_TITLE;
        break;
    case R.id.toggle_show_custom:
        flags = ActionBar.DISPLAY_SHOW_CUSTOM;
        break;
    case R.id.toggle_navigation:
        bar.setNavigationMode(
                bar.getNavigationMode() == ActionBar.NAVIGATION_MODE_STANDARD ? ActionBar.NAVIGATION_MODE_TABS
                        : ActionBar.NAVIGATION_MODE_STANDARD);
        return;
    case R.id.cycle_custom_gravity: {
        ActionBar.LayoutParams lp = mCustomViewLayoutParams;
        int newGravity = 0;
        switch (lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.LEFT:
            newGravity = Gravity.CENTER_HORIZONTAL;
            break;
        case Gravity.CENTER_HORIZONTAL:
            newGravity = Gravity.RIGHT;
            break;
        case Gravity.RIGHT:
            newGravity = Gravity.LEFT;
            break;
        }
        lp.gravity = lp.gravity & ~Gravity.HORIZONTAL_GRAVITY_MASK | newGravity;
        bar.setCustomView(mCustomView, lp);
        return;
    }
    case R.id.toggle_visibility:
        if (bar.isShowing()) {
            bar.hide();
        } else {
            bar.show();
        }
        return;
    }

    int change = bar.getDisplayOptions() ^ flags;
    bar.setDisplayOptions(change, flags);
}

From source file:cn.djangoogle.pull2load.internal.LoadingLayout.java

public LoadingLayout(Context context, final Mode mode, final Orientation scrollDirection, TypedArray attrs) {
    super(context);
    mMode = mode;/*from w  w  w  .  j a  va  2  s . co m*/
    mScrollDirection = scrollDirection;

    switch (scrollDirection) {
    case HORIZONTAL:
        LayoutInflater.from(context).inflate(R.layout.pull2load_header_horizontal, this);
        break;
    case VERTICAL:
    default:
        LayoutInflater.from(context).inflate(R.layout.pull2load_header_vertical, this);
        break;
    }

    mInnerLayout = (FrameLayout) findViewById(R.id.fl_inner);
    mHeaderText = (TextView) mInnerLayout.findViewById(R.id.pull_to_refresh_text);
    mHeaderProgressWheel = (ProgressWheel) mInnerLayout.findViewById(R.id.pull_to_refresh_progress_wheel);
    mSubHeaderText = (TextView) mInnerLayout.findViewById(R.id.pull_to_refresh_sub_text);
    mHeaderImage = (ImageView) mInnerLayout.findViewById(R.id.pull_to_refresh_image);

    LayoutParams lp = (LayoutParams) mInnerLayout.getLayoutParams();

    switch (mode) {
    case PULL_FROM_END:
        lp.gravity = scrollDirection == Orientation.VERTICAL ? Gravity.TOP : Gravity.LEFT;

        // Load in labels
        mPullLabel = context.getString(R.string.pull_to_refresh_from_bottom_pull_label);
        mRefreshingLabel = context.getString(R.string.pull_to_refresh_from_bottom_refreshing_label);
        mReleaseLabel = context.getString(R.string.pull_to_refresh_from_bottom_release_label);
        break;

    case PULL_FROM_START:
    default:
        lp.gravity = scrollDirection == Orientation.VERTICAL ? Gravity.BOTTOM : Gravity.RIGHT;

        // Load in labels
        mPullLabel = context.getString(R.string.pull_to_refresh_pull_label);
        mRefreshingLabel = context.getString(R.string.pull_to_refresh_refreshing_label);
        mReleaseLabel = context.getString(R.string.pull_to_refresh_release_label);
        break;
    }

    if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderBackground)) {
        Drawable background = attrs.getDrawable(R.styleable.PullToRefresh_ptrHeaderBackground);
        if (null != background) {
            ViewCompat.setBackground(this, background);
        }
    }

    if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderTextAppearance)) {
        TypedValue styleID = new TypedValue();
        attrs.getValue(R.styleable.PullToRefresh_ptrHeaderTextAppearance, styleID);
        setTextAppearance(styleID.data);
    }
    if (attrs.hasValue(R.styleable.PullToRefresh_ptrSubHeaderTextAppearance)) {
        TypedValue styleID = new TypedValue();
        attrs.getValue(R.styleable.PullToRefresh_ptrSubHeaderTextAppearance, styleID);
        setSubTextAppearance(styleID.data);
    }

    // Text Color attrs need to be set after TextAppearance attrs
    if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderTextColor)) {
        ColorStateList colors = attrs.getColorStateList(R.styleable.PullToRefresh_ptrHeaderTextColor);
        if (null != colors) {
            setTextColor(colors);
        }
    }
    if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderSubTextColor)) {
        ColorStateList colors = attrs.getColorStateList(R.styleable.PullToRefresh_ptrHeaderSubTextColor);
        if (null != colors) {
            setSubTextColor(colors);
        }
    }

    // Try and get defined drawable from Attrs
    Drawable imageDrawable = null;
    if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawable)) {
        imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawable);
    }

    // Check Specific Drawable from Attrs, these overrite the generic
    // drawable attr above
    switch (mode) {
    case PULL_FROM_START:
    default:
        if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableStart)) {
            imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableStart);
        } else if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableTop)) {
            Pull2LoadCommonUtil.warnDeprecation("ptrDrawableTop", "ptrDrawableStart");
            imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableTop);
        }
        break;

    case PULL_FROM_END:
        if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableEnd)) {
            imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableEnd);
        } else if (attrs.hasValue(R.styleable.PullToRefresh_ptrDrawableBottom)) {
            Pull2LoadCommonUtil.warnDeprecation("ptrDrawableBottom", "ptrDrawableEnd");
            imageDrawable = attrs.getDrawable(R.styleable.PullToRefresh_ptrDrawableBottom);
        }
        break;
    }

    // If we don't have a user defined drawable, load the default
    if (null == imageDrawable) {
        imageDrawable = ContextCompat.getDrawable(context, getDefaultDrawableResId());
    }

    // Set Drawable, and save width/height
    setLoadingDrawable(imageDrawable);

    reset();
}

From source file:android.support.v7ox.widget.ButtonBarLayout.java

private void setStacked(boolean stacked) {
    setOrientation(stacked ? LinearLayout.VERTICAL : LinearLayout.HORIZONTAL);
    setGravity(stacked ? Gravity.RIGHT : Gravity.BOTTOM);
    final View spacer = findViewById(R.id.spacer);
    if (spacer != null) {
        spacer.setVisibility(stacked ? View.GONE : View.INVISIBLE);
    }/*  w w  w  .  ja  va 2s  .co  m*/
    // Reverse the child order. This is specific to the Material button
    // bar's layout XML and will probably not generalize.
    final int childCount = getChildCount();
    for (int i = childCount - 2; i >= 0; i--) {
        bringChildToFront(getChildAt(i));
    }
}