Example usage for android.view Gravity CENTER

List of usage examples for android.view Gravity CENTER

Introduction

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

Prototype

int CENTER

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

Click Source Link

Document

Place the object in the center of its container in both the vertical and horizontal axis, not changing its size.

Usage

From source file:com.asc_ii.bangnote.bigbang.BigBangLayout.java

public void addTextItem(String text) {
    TextView view = new TextView(getContext());
    view.setText(text);//from   ww w . ja  va 2 s .c o  m
    view.setBackgroundResource(R.drawable.item_background);
    view.setTextColor(ContextCompat.getColorStateList(getContext(), R.color.bigbang_item_text));
    view.setGravity(Gravity.CENTER);
    if (mItemTextSize > 0)
        view.setTextSize(TypedValue.COMPLEX_UNIT_PX, mItemTextSize);
    addView(view);
}

From source file:com.bangqu.eshow.util.ESDialogUtil.java

/**
 * //from  w w w  .  j  av a 2s .  c o  m
 * ???.
 * @param view
 * @param animEnter
 * @param animExit
 * @param animPopEnter
 * @param animPopExit
 * @param onCancelListener
 * @return
 */
public static ESSampleDialogFragment showDialog(View view, int animEnter, int animExit, int animPopEnter,
        int animPopExit, DialogInterface.OnCancelListener onCancelListener) {
    return showDialog(view, animEnter, animExit, animPopEnter, animPopExit, Gravity.CENTER, defaultStyle,
            onCancelListener);
}

From source file:com.insthub.O2OMobile.Activity.C12_EditSignatureActivity.java

@Override
public void onClick(View v) {
    String signture = mSignture.getText().toString().trim();
    switch (v.getId()) {
    case R.id.top_view_back:
        finish();//from   w ww  .  j a v  a  2 s . c o  m
        break;
    case R.id.btn_save:
        if ("".equals(signture)) {
            ToastView toast = new ToastView(C12_EditSignatureActivity.this,
                    getString(R.string.signature_not_null));
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            mSignture.setText("");
            mSignture.requestFocus();
            break;
        } else {
            mUserModel.changeSignature(signture);
        }
    }
}

From source file:cn.org.eshow.framwork.util.AbDialogUtil.java

/**
 * /*from   www .ja va  2  s .  com*/
 * ???.
 * @param view
 * @param animEnter
 * @param animExit
 * @param animPopEnter
 * @param animPopExit
 * @param onCancelListener
 * @return
 */
public static AbSampleDialogFragment showDialog(View view, int animEnter, int animExit, int animPopEnter,
        int animPopExit, DialogInterface.OnCancelListener onCancelListener) {
    return showDialog(view, animEnter, animExit, animPopEnter, animPopExit, Gravity.CENTER, defaultStyle,
            onCancelListener);
}

From source file:com.android.messaging.ui.ViewPagerTabs.java

private void addTab(CharSequence tabTitle, final int position) {
    final TextView textView = new TextView(getContext());
    textView.setText(tabTitle);/*from  www  .j  a v  a2 s.  c  o  m*/
    textView.setBackgroundResource(R.drawable.contact_picker_tab_background_selector);
    textView.setGravity(Gravity.CENTER);
    textView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mPager.setCurrentItem(getRtlPosition(position));
        }
    });

    // Assign various text appearance related attributes to child views.
    if (mTextStyle > 0) {
        textView.setTypeface(textView.getTypeface(), mTextStyle);
    }
    if (mTextSize > 0) {
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, mTextSize);
    }
    if (mTextColor != null) {
        textView.setTextColor(mTextColor);
    }
    textView.setAllCaps(mTextAllCaps);
    textView.setPadding(mSidePadding, 0, mSidePadding, 0);
    mTabStrip.addView(textView,
            new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1));
    // Default to the first child being selected
    if (position == 0) {
        mPrevSelected = 0;
        textView.setSelected(true);
    }
}

From source file:biz.incomsystems.fwknop2.ConfigDetailFragment.java

public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.detail_help) {
        Intent detailIntent = new Intent(getActivity(), HelpActivity.class);
        startActivity(detailIntent);//ww  w .  j av a 2s  .  c om
    } else if (id == R.id.qr_code) {
        try {
            Intent intent = new Intent("com.google.zxing.client.android.SCAN");
            intent.putExtra("SCAN_MODE", "QR_CODE_MODE"); // "PRODUCT_MODE for bar codes
            startActivityForResult(intent, 0);
        } catch (Exception e) { // This is where the play store is called if the app is not installed
            Uri marketUri = Uri.parse("market://details?id=com.google.zxing.client.android");
            Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri);
            startActivity(marketIntent);
        }
    } else if (id == R.id.save) {
        InetAddressValidator ipValidate = new InetAddressValidator();
        Context context = getActivity(); // We know we will use a toast, so set it up now
        int duration = Toast.LENGTH_LONG;
        CharSequence text = "Saving config";
        Toast toast = Toast.makeText(context, text, duration);
        toast.setGravity(Gravity.CENTER, 0, 0);
        LinearLayout toastLayout = (LinearLayout) toast.getView();
        TextView toastTV = (TextView) toastLayout.getChildAt(0);
        toastTV.setTextSize(30);

        //The following is all input validation

        try {
            if ((Integer.parseInt(txt_server_port.getText().toString()) > 0)
                    && (Integer.parseInt(txt_server_port.getText().toString()) < 65535)) { // check for valid port
                txt_server_port.setText(String.valueOf(Integer.parseInt(txt_server_port.getText().toString())));
            } else {
                txt_server_port.setText(String.valueOf(62201));
            }
        } catch (NumberFormatException ex) {
            txt_server_port.setText(String.valueOf(62201));
        }
        if (txt_NickName.getText().toString().equalsIgnoreCase("")) { // Need to create a new Nick
            toast.setText("You Must choose a unique Nickname."); // choosing a used nick will just overwrite it. So really
            toast.show();
        } else if (chkb64hmac.isChecked() && txt_HMAC.getText().toString().length() % 4 != 0) { // base64 must have a multiple of 4 length
            toast.setText("Hmac is not a valid Base64, not a multiple of 4.");
            toast.show();
        } else if (chkb64hmac.isChecked()
                && !(txt_HMAC.getText().toString().matches("^[A-Za-z0-9+/]+={0,2}$"))) { // looks for disallowed b64 characters
            toast.setText("Hmac is not a valid Base64, Contains disallowed characters.");
            toast.show();
        } else if (chkb64key.isChecked() && txt_KEY.getText().toString().length() % 4 != 0) {
            toast.setText("Key is not a valid Base64, not a multiple of 4.");
            toast.show();
        } else if (chkb64key.isChecked() && !(txt_KEY.getText().toString().matches("^[A-Za-z0-9+/]+={0,2}$"))) { // looks for disallowed b64 characters
            toast.setText("Key is not a valid Base64, Contains disallowed characters.");
            toast.show();
        } else if (!(txt_ports.getText().toString().matches("tcp/\\d.*")
                || txt_ports.getText().toString().matches("udp/\\d.*"))) {
            toast.setText("Access ports must be in the form of 'tcp/22'");
            toast.show();
        } else if (spn_allowip.getSelectedItem().toString().equalsIgnoreCase("Allow IP")
                && (!ipValidate.isValid(txt_allowIP.getText().toString()))) { //Have to have a valid ip to allow, if using allow ip
            toast.setText("You Must supply a valid IP address to 'Allow IP'.");
            toast.show();
        } else if (!ipValidate.isValid(txt_server_ip.getText().toString())
                && !DomainValidator.getInstance().isValid(txt_server_ip.getText().toString())) { // check server entry. Must be a valid url or ip.
            toast.setText("You Must supply a valid server address.");
            toast.show();
        } else if (txt_KEY.getText().toString().equalsIgnoreCase("")) {
            toast.setText("You Must supply a Rijndael key.");
            toast.show();
        } else if (spn_ssh.getSelectedItem().toString().equalsIgnoreCase("Juicessh")
                && juice_adapt.getConnectionName(spn_juice.getSelectedItemPosition()) == null) {
            toast.setText("A connection must be saved in Juicessh before being used here.");
            toast.show();
            //            //end input validation, actual saving below
        } else {
            toast.show();
            if (configtype.equalsIgnoreCase("Open Port")) {
                config.PORTS = txt_ports.getText().toString();
                config.SERVER_TIMEOUT = txt_server_time.getText().toString();
            } else {
                config.PORTS = "";
                config.SERVER_TIMEOUT = "";
            }
            if (configtype.equalsIgnoreCase("Nat Access")) {
                config.NAT_IP = txt_nat_ip.getText().toString();
                config.NAT_PORT = txt_nat_port.getText().toString();
                config.PORTS = txt_ports.getText().toString();
                config.SERVER_TIMEOUT = txt_server_time.getText().toString();
            } else {
                config.NAT_IP = "";
                config.NAT_PORT = "";
            }
            if (configtype.equalsIgnoreCase("Server Command")) {
                config.SERVER_CMD = txt_server_cmd.getText().toString();
            } else {
                config.SERVER_CMD = "";
            }
            if (spn_allowip.getSelectedItem().toString().equalsIgnoreCase("Resolve IP")) {
                config.ACCESS_IP = spn_allowip.getSelectedItem().toString();
            } else if (spn_allowip.getSelectedItem().toString().equalsIgnoreCase("Source IP")) {
                config.ACCESS_IP = "0.0.0.0";
            } else {
                config.ACCESS_IP = txt_allowIP.getText().toString();
            }
            config.NICK_NAME = txt_NickName.getText().toString();
            config.SERVER_IP = txt_server_ip.getText().toString();
            config.SERVER_PORT = txt_server_port.getText().toString();
            config.SSH_CMD = "";
            if (spn_ssh.getSelectedItem().toString().equalsIgnoreCase("SSH Uri")) {
                config.SSH_CMD = txt_ssh_cmd.getText().toString();
                config.juice_uuid = UUID.fromString("00000000-0000-0000-0000-000000000000");
            } else if (spn_ssh.getSelectedItem().toString().equalsIgnoreCase("Juicessh")) {
                config.SSH_CMD = "juice:" + juice_adapt.getConnectionName(spn_juice.getSelectedItemPosition());
                config.juice_uuid = juice_adapt.getConnectionId(spn_juice.getSelectedItemPosition());
            } else {
                config.juice_uuid = UUID.fromString("00000000-0000-0000-0000-000000000000");
                config.SSH_CMD = "";
            }
            config.KEY = txt_KEY.getText().toString(); //key
            config.KEY_BASE64 = chkb64key.isChecked(); //is key b64
            config.HMAC = txt_HMAC.getText().toString(); // hmac key
            config.HMAC_BASE64 = chkb64hmac.isChecked(); //is hmac base64
            mydb.updateConfig(context, config);

            //this updates the list for one panel mode
            Activity activity = getActivity();
            if (activity instanceof ConfigListActivity) {
                ConfigListActivity myactivity = (ConfigListActivity) activity;
                myactivity.onItemSaved();

            } else {
                ConfigDetailActivity myactivity = (ConfigDetailActivity) activity;
                myactivity.onBackPressed();
            }
        }
    } else {
        return false;
    }
    return super.onOptionsItemSelected(item);
}

From source file:cn.ibona.commonutil.indicator.TabPageIndicator.java

private void addTab(int index, CharSequence text, int iconResId) {
    final TabView tabView = new TabView(getContext());
    tabView.mIndex = index;/*from www  .  j  ava 2 s . co  m*/
    tabView.setFocusable(true);
    tabView.setOnClickListener(mTabClickListener);
    tabView.setText(text);
    //
    tabView.setGravity(Gravity.CENTER);

    if (iconResId != 0) {
        tabView.setCompoundDrawablesWithIntrinsicBounds(iconResId, 0, 0, 0);
    }

    mTabLayout.addView(tabView, new LinearLayout.LayoutParams(0, MATCH_PARENT, 1));
}

From source file:cn.jay.widget.BottomNavigationItemView.java

@Override
public void setChecked(boolean checked) {
    mItemData.setChecked(checked);//from w  w w .  ja v a 2  s  .c om

    if (mUseStandardDesign) {
        ViewCompat.setPivotX(mLargeLabel, mLargeLabel.getWidth() / 2);
        ViewCompat.setPivotY(mLargeLabel, mLargeLabel.getBaseline());
        ViewCompat.setPivotX(mSmallLabel, mSmallLabel.getWidth() / 2);
        ViewCompat.setPivotY(mSmallLabel, mSmallLabel.getBaseline());
        if (mShiftingMode) {
            if (checked) {
                LayoutParams iconParams = (LayoutParams) mIcon.getLayoutParams();
                iconParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
                iconParams.topMargin = mDefaultMargin;
                mIcon.setLayoutParams(iconParams);
                mLargeLabel.setVisibility(VISIBLE);
                ViewCompat.setScaleX(mLargeLabel, 1f);
                ViewCompat.setScaleY(mLargeLabel, 1f);
            } else {
                LayoutParams iconParams = (LayoutParams) mIcon.getLayoutParams();
                iconParams.gravity = Gravity.CENTER;
                iconParams.topMargin = mDefaultMargin;
                mIcon.setLayoutParams(iconParams);
                mLargeLabel.setVisibility(INVISIBLE);
                ViewCompat.setScaleX(mLargeLabel, 0.5f);
                ViewCompat.setScaleY(mLargeLabel, 0.5f);
            }
            mSmallLabel.setVisibility(INVISIBLE);
        } else {
            if (checked) {
                LayoutParams iconParams = (LayoutParams) mIcon.getLayoutParams();
                iconParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
                iconParams.topMargin = mDefaultMargin + mShiftAmount;
                mIcon.setLayoutParams(iconParams);
                mLargeLabel.setVisibility(VISIBLE);
                mSmallLabel.setVisibility(INVISIBLE);

                ViewCompat.setScaleX(mLargeLabel, 1f);
                ViewCompat.setScaleY(mLargeLabel, 1f);
                ViewCompat.setScaleX(mSmallLabel, mScaleUpFactor);
                ViewCompat.setScaleY(mSmallLabel, mScaleUpFactor);
            } else {
                LayoutParams iconParams = (LayoutParams) mIcon.getLayoutParams();
                iconParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
                iconParams.topMargin = mDefaultMargin;
                mIcon.setLayoutParams(iconParams);
                mLargeLabel.setVisibility(INVISIBLE);
                mSmallLabel.setVisibility(VISIBLE);

                ViewCompat.setScaleX(mLargeLabel, mScaleDownFactor);
                ViewCompat.setScaleY(mLargeLabel, mScaleDownFactor);
                ViewCompat.setScaleX(mSmallLabel, 1f);
                ViewCompat.setScaleY(mSmallLabel, 1f);
            }
        }
    }

    refreshDrawableState();
}

From source file:com.example.activity.ShotListActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // TODO Auto-generated method stub
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        if (isExit == false) {
            isExit = true;//from  w  ww .jav a 2 s .c om
            ToastView toast = new ToastView(getApplicationContext(), "?BeeExample");
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            Handler mHandler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    super.handleMessage(msg);
                    isExit = false;
                }
            };
            mHandler.sendEmptyMessageDelayed(0, 3000);
            return true;
        } else {
            finish();
            return false;
        }
    }
    return true;
}

From source file:ab.util.AbDialogUtil.java

/**
 * ?()/*from www.j a va2s. c om*/
 * 
 * @param view
 * @param animEnter
 * @param animExit
 * @param animPopEnter
 * @param animPopExit
 * @return
 */
public static AbSampleDialogFragment showDialog(View view, int animEnter, int animExit, int animPopEnter,
        int animPopExit) {
    return showDialog(view, animEnter, animExit, animPopEnter, animPopExit, Gravity.CENTER);
}