Example usage for android.view Gravity END

List of usage examples for android.view Gravity END

Introduction

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

Prototype

int END

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

Click Source Link

Document

Push object to x-axis position at the end of its container, not changing its size.

Usage

From source file:com.alburivan.slickform.tooltip.SimpleTooltip.java

private PointF calculePopupLocation() {
    PointF location = new PointF();

    final RectF anchorRect = SimpleTooltipUtils.calculeRectInWindow(mAnchorView);
    final PointF anchorCenter = new PointF(anchorRect.centerX(), anchorRect.centerY());

    switch (mGravity) {
    case Gravity.START:
        location.x = anchorRect.left - mPopupWindow.getContentView().getWidth() - mMargin;
        location.y = anchorCenter.y - mPopupWindow.getContentView().getHeight() / 2f;
        break;//from w w  w . ja v a2s.c o  m
    case Gravity.END:
        location.x = anchorRect.right + mMargin;
        location.y = anchorCenter.y - mPopupWindow.getContentView().getHeight() / 2f;
        break;
    case Gravity.TOP:
        location.x = anchorCenter.x - mPopupWindow.getContentView().getWidth() / 2f;
        location.y = anchorRect.top - mPopupWindow.getContentView().getHeight() - mMargin;
        break;
    case Gravity.BOTTOM:
        location.x = anchorCenter.x - mPopupWindow.getContentView().getWidth() / 2f;
        location.y = anchorRect.bottom + mMargin;
        break;
    default:
        throw new IllegalArgumentException("Gravity must have be START, END, TOP or BOTTOM.");
    }

    return location;
}

From source file:ir.mohandesplus.examnight.views.SlidingTabLayout.java

private void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;//from   w  ww  .  j  a  va 2 s  . c  o m
        TextView tabTitleView = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }

        if (tabTitleView != null)
            tabTitleView.setText(adapter.getPageTitle(i));
        tabView.setOnClickListener(tabClickListener);
        String desc = mContentDescriptions.get(i, null);
        if (desc != null)
            tabView.setContentDescription(desc);

        mTabStrip.addView(tabView);
        if (i == mViewPager.getCurrentItem())
            tabView.setSelected(true);

        if (tabTitleView != null)
            tabTitleView.setTextColor(getResources().getColorStateList(R.color.selector));
        CalligraphyUtils.applyFontToTextView(getContext(), tabTitleView, "fonts/IranianSansLight.ttf");
        if (tabTitleView != null)
            tabTitleView.setTextSize(14);
    }

    if (!mDistributeEvenly) {
        mTabStrip.setGravity(Gravity.END);
        mTabStrip.setPadding(0, 0,
                getResources().getDimensionPixelSize(R.dimen.abc_action_bar_content_inset_material), 0);
    }
    mTabStrip.setLayoutDirection(LAYOUT_DIRECTION_LTR);

}

From source file:org.odk.collect.android.activities.AppListActivity.java

private void setupDrawerItems() {
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,
            sortingOptions) {//www  .  j a  v a2 s .c om
        @NonNull
        @Override
        public View getView(int position, View convertView, @NonNull ViewGroup parent) {
            TextView textView = (TextView) super.getView(position, convertView, parent);
            if (position == getSelectedSortingOrder()) {
                textView.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.light_blue));
            }
            textView.setPadding(50, 0, 0, 0);
            return textView;
        }
    };
    drawerList.setAdapter(adapter);
    drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            parent.getChildAt(selectedSortingOrder).setBackgroundColor(Color.TRANSPARENT);
            view.setBackgroundColor(ContextCompat.getColor(getBaseContext(), R.color.light_blue));
            performSelectedSearch(position);
            drawerLayout.closeDrawer(Gravity.END);
        }
    });
}

From source file:org.catrobat.paintroid.ui.BottomBar.java

private void showToolChangeToast() {
    if (mToolNameToast != null) {
        mToolNameToast.cancel();/*from   www .  ja v  a  2s. c o  m*/
    }

    mToolNameToast = Toast.makeText(mMainActivity, mMainActivity.getString(mCurrentToolType.getNameResource()),
            Toast.LENGTH_SHORT);
    mToolNameToast.setGravity(Gravity.TOP | Gravity.END, 0, SWITCH_TOOL_TOAST_Y_OFFSET);
    mToolNameToast.show();
}

From source file:edu.ptu.navpattern.tooltip.Tooltip.java

private View getContentView(final Builder builder) {
    GradientDrawable drawable = new GradientDrawable();
    drawable.setColor(builder.mBackgroundColor);
    drawable.setCornerRadius(builder.mCornerRadius);
    LinearLayout vgContent = new LinearLayout(builder.mContext);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        vgContent.setBackground(drawable);
    } else {// w  w w .j a  v  a 2  s  . c o m
        //noinspection deprecation
        vgContent.setBackgroundDrawable(drawable);
    }
    int padding = (int) builder.mPadding;
    vgContent.setPadding(padding, padding, padding, padding);
    vgContent.setOrientation(LinearLayout.VERTICAL);
    LinearLayout.LayoutParams textViewParams = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, 0);
    textViewParams.gravity = Gravity.CENTER;
    textViewParams.topMargin = 1;
    vgContent.setLayoutParams(textViewParams);
    vgContent.setDividerDrawable(vgContent.getResources().getDrawable(R.drawable.divider_line));
    vgContent.setShowDividers(LinearLayout.SHOW_DIVIDER_MIDDLE);

    if (builder.itemText != null && builder.itemText.length > 0) {
        for (int i = 0; i < builder.itemText.length; i++) {

            TextView textView = new TextView(builder.mContext);
            textView.setText(builder.itemText[i]);
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 44);
            textView.setTextColor(0xffffffff);
            textView.setGravity(Gravity.CENTER_VERTICAL);
            if (builder.itemLogo != null && builder.itemLogo.length > i) {
                Drawable drawableLeft = builder.mContext.getResources().getDrawable(builder.itemLogo[i]);
                /// ??,??.
                //                    drawableLeft.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
                //                    textView.setCompoundDrawables(drawableLeft, null, null, null);
                //                    textView.setCompoundDrawablePadding(4);
                //                    textView.setBackgroundDrawable(drawableLeft);
                LinearLayout linearLayout = new LinearLayout(builder.mContext);
                linearLayout.setMinimumHeight((int) dpToPx(44f));
                linearLayout.setOrientation(LinearLayout.HORIZONTAL);
                linearLayout.setGravity(Gravity.CENTER_VERTICAL);
                ImageView icon = new ImageView(builder.mContext);
                icon.setImageDrawable(drawableLeft);
                linearLayout.addView(icon);
                linearLayout.addView(textView);
                vgContent.addView(linearLayout);
                final int position = i;
                linearLayout.setClickable(false);
                linearLayout.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (builder.mOnItemClickListener != null) {
                            builder.mOnItemClickListener.onClick(position);
                        }
                        mTouchListener.onTouch(v,
                                MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(),
                                        MotionEvent.ACTION_UP, v.getLeft() + 5, v.getTop() + 5, 0));
                    }
                });
            } else {
                vgContent.addView(textView);
                final int position = i;
                textView.setClickable(false);
                textView.setMinimumHeight((int) dpToPx(44f));
                textView.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        if (builder.mOnItemClickListener != null) {
                            builder.mOnItemClickListener.onClick(position);
                        }
                        mTouchListener.onTouch(v, null);
                    }
                });
            }
        }

    }

    mArrowView = new ImageView(builder.mContext);
    mArrowView.setImageDrawable(builder.mArrowDrawable);

    LinearLayout.LayoutParams arrowLayoutParams;
    if (mGravity == Gravity.TOP || mGravity == Gravity.BOTTOM) {
        arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowWidth, (int) builder.mArrowHeight,
                0);
    } else {
        arrowLayoutParams = new LinearLayout.LayoutParams((int) builder.mArrowHeight, (int) builder.mArrowWidth,
                0);
    }
    arrowLayoutParams.gravity = Gravity.CENTER;
    mArrowView.setLayoutParams(arrowLayoutParams);

    mContentView = new LinearLayout(builder.mContext);
    mContentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    mContentView.setOrientation(mGravity == Gravity.START || mGravity == Gravity.END ? LinearLayout.HORIZONTAL
            : LinearLayout.VERTICAL);

    padding = (int) dpToPx(5);

    switch (mGravity) {
    case Gravity.START:
        mContentView.setPadding(0, 0, padding, 0);
        break;
    case Gravity.TOP:
    case Gravity.BOTTOM:
        mContentView.setPadding(padding, 0, padding, 0);
        break;
    case Gravity.END:
        mContentView.setPadding(padding, 0, 0, 0);
        break;
    }

    if (mGravity == Gravity.TOP || mGravity == Gravity.START) {
        mContentView.addView(vgContent);
        mContentView.addView(mArrowView);
    } else {
        mContentView.addView(mArrowView);
        mContentView.addView(vgContent);
    }

    if (builder.isCancelable || builder.isDismissOnClick) {
        mContentView.setOnTouchListener(mTouchListener);
    }
    return mContentView;
}

From source file:ti.modules.titanium.ui.widget.TiUIDrawerLayout.java

private void initRight() {
    if (rightFrame != null) {
        return;//from ww w  .  j a  va2s  .c  o  m
    }
    rightFrame = new FrameLayout(proxy.getActivity());

    LayoutParams frameLayout = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
    frameLayout.gravity = Gravity.END;
    rightFrame.setLayoutParams(frameLayout);

    layout.addView(rightFrame);
}

From source file:com.zte.permissioncontrol.ui.PermissionControlPageActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.permission_control_pages);
    mEmptyView = (FrameLayout) findViewById(R.id.empty_view);
    mSavedInstanceState = savedInstanceState;
    // add the switch on Action bar
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mSwitch = (Switch) inflater.inflate(R.layout.imageswitch_layout, null);
    final int padding = getResources().getDimensionPixelSize(R.dimen.action_bar_switch_padding);
    mSwitch.setPadding(0, 0, padding, 0);
    getActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM);
    getActionBar().setCustomView(mSwitch, new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
            ActionBar.LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.END));
    mSwitch.setOnCheckedChangeListener(this);

    // hide fragment firstly , then update it in onResume() according to switch status
    final FragmentManager fragmentManager = getFragmentManager();
    FragmentTransaction transaction = fragmentManager.beginTransaction();

    mPermissionsFragment = (PermissionsFragment) fragmentManager.findFragmentByTag(mPermissionsTag);
    mAppsFragment = (AppsFragment) fragmentManager.findFragmentByTag(mAppsTag);

    if (mPermissionsFragment == null) {
        mPermissionsFragment = new PermissionsFragment();
        mAppsFragment = new AppsFragment();
        transaction.add(R.id.tab_pager, mPermissionsFragment, mPermissionsTag);
        transaction.add(R.id.tab_pager, mAppsFragment, mAppsTag);
    }/*from   w  w  w .ja va  2  s . c  o  m*/

    transaction.hide(mPermissionsFragment);
    transaction.hide(mAppsFragment);
    transaction.commit();
    fragmentManager.executePendingTransactions();

    // set page adapter
    mTabPager = (ViewPager) findViewById(R.id.tab_pager);
    mTabPagerAdapter = new TabPagerAdapter();
    mTabPager.setAdapter(mTabPagerAdapter);
    mTabPager.setOnPageChangeListener(mTabPagerListener);

    // Configure action bar
    mActionBarAdapter = new ActionBarAdapter(this, this, getActionBar());

    boolean isShow = PermControlUtils.isPermControlOn(this);
    Log.d(TAG, "oncreate(), isShow " + isShow);

}

From source file:com.tooltip.Tooltip.java

private PointF calculateLocation() {
    PointF location = new PointF();

    final RectF anchorRect = Util.calculateRectInWindow(mAnchorView);
    final PointF anchorCenter = new PointF(anchorRect.centerX(), anchorRect.centerY());

    switch (mGravity) {
    case Gravity.START:
        location.x = anchorRect.left - mContentView.getWidth() - mMargin;
        location.y = anchorCenter.y - mContentView.getHeight() / 2f;
        break;/*from   w  ww  . jav  a  2  s.co m*/
    case Gravity.END:
        location.x = anchorRect.right + mMargin;
        location.y = anchorCenter.y - mContentView.getHeight() / 2f;
        break;
    case Gravity.TOP:
        location.x = anchorCenter.x - mContentView.getWidth() / 2f;
        location.y = anchorRect.top - mContentView.getHeight() - mMargin;
        break;
    case Gravity.BOTTOM:
        location.x = anchorCenter.x - mContentView.getWidth() / 2f;
        location.y = anchorRect.bottom + mMargin;
        break;
    }

    return location;
}

From source file:us.shandian.blacklight.ui.statuses.NewPostActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.isCheckable() && item.isEnabled()) {
        item.setChecked(!item.isChecked());
    }/*  w  w  w . jav a 2s. c  o m*/

    int id = item.getItemId();
    if (id == android.R.id.home) {
        finish();
        return true;
    } else if (id == R.id.post_send) {
        try {
            if (!TextUtils.isEmpty(mText.getText().toString())) {
                new Uploader().execute();
            } else {
                Toast.makeText(this, R.string.empty_weibo, Toast.LENGTH_SHORT).show();
            }
        } catch (Exception e) {

        }
        return true;
    } else if (id == R.id.post_pic) {
        if (mBitmap == null) {
            showPicturePicker();
        } else {
            setPicture(null);
        }
        return true;
    } else if (id == R.id.post_emoticon) {
        if (mDrawer.isDrawerOpen(Gravity.END)) {
            mDrawer.closeDrawer(Gravity.END);
        } else {
            mDrawer.openDrawer(Gravity.END);
        }
        return true;
    } else if (id == R.id.post_at) {
        AtUserSuggestDialog diag = new AtUserSuggestDialog(this);
        diag.setListener(new AtUserSuggestDialog.AtUserListener() {
            @Override
            public void onChooseUser(String name) {
                mText.getText().insert(mText.getSelectionStart(), " @" + name + " ");
            }
        });
        diag.show();
        return true;
    } else {
        return super.onOptionsItemSelected(item);
    }
}

From source file:io.github.minime89.passbeam.activities.KeyboardLayoutActivity.java

private void setupKeyboardLayoutMenu() {
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        ProgressBar progressBar = new ProgressBar(this);
        progressBar.setVisibility(View.GONE);
        progressBar.setIndeterminate(true);

        ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
                ActionBar.LayoutParams.WRAP_CONTENT, Gravity.END | Gravity.CENTER_VERTICAL);
        progressBar.setLayoutParams(layoutParams);

        actionBar.setDisplayShowCustomEnabled(true);
        actionBar.setCustomView(progressBar);
    }/*from  w ww.j  a v a2  s .  c o m*/
}