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:ch.pantas.billsplitter.ui.FixedTabsView.java

private void addTab(final int position, String title) {
    TextView tab = new TextView(getContext());
    tab.setText(title);/*  w ww . j  a va2 s.co m*/
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    tab.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1f));

    tab.setFocusable(true);
    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            viewPager.setCurrentItem(position);
        }
    });
    tabsContainer.addView(tab, position);
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.c16_feedback);
    mBack = (ImageView) findViewById(R.id.top_view_back);
    mTitle = (TextView) findViewById(R.id.top_view_title);
    mFeedBack = (EditText) findViewById(R.id.feedback_edittext);
    mFeedbackButton = (Button) findViewById(R.id.feedback_button);
    mBack.setOnClickListener(new View.OnClickListener() {

        @Override/*w w  w.j ava 2s .  co  m*/
        public void onClick(View v) {
            // TODO Auto-generated method stub
            finish();
        }
    });
    mTitle.setText(getString(R.string.feedback));

    mReportModel = new ReportModel(this);
    mReportModel.addResponseListener(this);

    mFeedbackButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            String str = mFeedBack.getText().toString();
            if (str.equals("")) {
                ToastView toast = new ToastView(C16_FeedbackActivity.this,
                        getString(R.string.please_input_feedback));
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            } else {
                mReportModel.feedback(str);
            }
        }
    });
}

From source file:com.android.purenexussettings.utils.SlidingTabLayout.java

protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP,
            getResources().getInteger(R.integer.slidetab_view_text_size_sp));
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    textView.setBackgroundResource(outValue.resourceId);
    textView.setAllCaps(true);/*from w w  w .  ja v  a2 s .c o m*/

    // some fudging around for padding of the tabs
    int paddingtb = (int) (getResources().getInteger(R.integer.slidetab_view_top_padding_dips)
            * getResources().getDisplayMetrics().density);
    int paddinglr = (int) (getResources().getInteger(R.integer.slidetab_view_padding_dips)
            * getResources().getDisplayMetrics().density);
    textView.setPadding(paddinglr, paddingtb, paddinglr, paddingtb);

    return textView;
}

From source file:com.aboveware.abovegame.expandable.ExpandableListFragment.java

/**
 * Provide default implementation to return a simple list view. Subclasses can
 * override to replace with their own layout. If doing so, the returned view
 * hierarchy <em>must</em> have a ListView whose id is
 * {@link android.R.id#list android.R.id.list} and can optionally have a
 * sibling view id {@link android.R.id#empty android.R.id.empty} that is to be
 * shown when the list is empty./*ww w.  j  a  v a 2 s  . co  m*/
 * <p/>
 * <p>
 * If you are overriding this method with your own custom content, consider
 * including the standard layout {@link android.R.layout#list_content} in your
 * layout file, so that you continue to retain all of the standard behavior of
 * AbsListFragment. In particular, this is currently the only way to have the
 * built-in indeterminant progress state be shown.
 */
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    FrameLayout root = new FrameLayout(getActivity());

    FrameLayout lframe = new FrameLayout(getActivity());
    lframe.setId(INTERNAL_LIST_CONTAINER_ID);

    TextView tv = new TextView(getActivity());
    tv.setId(INTERNAL_EMPTY_ID);
    tv.setGravity(Gravity.CENTER);
    lframe.addView(tv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    ExpandableListView lv = new ExpandableListView(getActivity());
    lv.setId(android.R.id.list);
    lv.setDrawSelectorOnTop(false);
    lframe.addView(lv, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    root.addView(lframe, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    ListView.LayoutParams lp = new ListView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    root.setLayoutParams(lp);

    return root;
}

From source file:com.adithyaupadhya.uimodule.roundcornerprogressbar.BaseRoundCornerProgressBar.java

private void previewLayout(Context context) {
    setGravity(Gravity.CENTER);
    TextView tv = new TextView(context);
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT);
    tv.setLayoutParams(params);/*from  w  w w .ja v a2 s.  c o  m*/
    tv.setGravity(Gravity.CENTER);
    tv.setText(getClass().getSimpleName());
    tv.setTextColor(Color.WHITE);
    tv.setBackgroundColor(Color.GRAY);
    addView(tv);
}

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

/**
 * ?/*from w w w. ja  v  a2 s.  co  m*/
 * @param view
 * @param onCancelListener
 * @return
 */
public static ESSampleDialogFragment showDialog(View view, DialogInterface.OnCancelListener onCancelListener) {
    return showDialog(view, Gravity.CENTER, defaultStyle, onCancelListener);
}

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

/**
 * ?/*from  www.  j  av a  2s  .c o m*/
 * @param view
 * @param onCancelListener
 * @return
 */
public static AbSampleDialogFragment showDialog(View view, DialogInterface.OnCancelListener onCancelListener) {
    return showDialog(view, Gravity.CENTER, defaultStyle, onCancelListener);
}

From source file:com.firesoft.member.Activity.B2_SignupActivity.java

@Override
public void onClick(View v) {
    String nickname = mNickname.getText().toString().trim();
    String password = mPassword.getText().toString();
    String password_again = mPasswordAgain.getText().toString();
    switch (v.getId()) {
    case R.id.btn_signup_complete:
        if ("".equals(nickname)) {
            ToastView toast = new ToastView(B2_SignupActivity.this, getString(R.string.please_input_nickname));
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();//from   w  w  w.j a va2  s . c  om
            mNickname.setText("");
            mNickname.requestFocus();
        } else if (nickname.length() < 1 || nickname.length() > 16) {
            ToastView toast = new ToastView(B2_SignupActivity.this,
                    getString(R.string.nickname_wrong_format_hint));
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            mNickname.requestFocus();
        } else if ("".equals(password)) {
            ToastView toast = new ToastView(B2_SignupActivity.this, getString(R.string.please_input_password));
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            mPassword.requestFocus();
        } else if (password.length() < 6 || password.length() > 20) {
            ToastView toast = new ToastView(B2_SignupActivity.this,
                    getString(R.string.password_wrong_format_hint));
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            mPassword.requestFocus();
        } else if (!password.equals(password_again)) {
            ToastView toast = new ToastView(B2_SignupActivity.this,
                    getString(R.string.two_passwords_differ_hint));
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            mPasswordAgain.requestFocus();
        } else {
            mUserModel.signup(mMobile, password, nickname);
            CloseKeyBoard();
        }
        break;
    }

}

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

@Override
public void OnMessageResponse(String url, JSONObject jo, AjaxStatus status) throws JSONException {
    if (url.endsWith(ApiInterface.USER_CHANGE_PASSWORD)) {
        userchange_passwordResponse response = new userchange_passwordResponse();
        response.fromJson(jo);//from ww w  .ja v  a 2s  .  c om
        if (response.succeed == 1) {
            ToastView toast = new ToastView(C13_EditPasswordActivity.this,
                    getString(R.string.change_password_success));
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            finish();
        } else {
            if (response.error_code == APIErrorCode.ERROR_PASSWORD) {
                mNowPassword.requestFocus();
            }
        }

    }
}

From source file:com.insthub.BeeFramework.model.BaseModel.java

public void callback(String url, JSONObject jo, AjaxStatus status) {
    if (null == jo) {
        //            ToastView toast = new ToastView(mContext,"");
        //            toast.setGravity(Gravity.CENTER, 0, 0);
        //            toast.show();
        return;/*from  www. j a  v a  2 s.  c o  m*/
    }
    try {
        STATUS responseStatus = new STATUS();
        responseStatus.fromJson(jo.optJSONObject("status"));
        if (responseStatus.succeed != ErrorCodeConst.ResponseSucceed) {
            if (responseStatus.error_code == ErrorCodeConst.InvalidSession) {
                ToastView toast = new ToastView(mContext, mContext.getString(R.string.session_expires_tips));
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
                E0_ProfileFragment.isRefresh = true;
                Intent intent = new Intent(mContext, A0_SigninActivity.class);
                mContext.startActivity(intent);

                shared = mContext.getSharedPreferences("userInfo", 0);
                editor = shared.edit();

                editor.putString("uid", "");
                editor.putString("sid", "");
                editor.commit();
                SESSION.getInstance().uid = shared.getString("uid", "");
                SESSION.getInstance().sid = shared.getString("sid", "");

            }

        }

        Resources resource = mContext.getResources();
        String way = resource.getString(R.string.delivery);
        String col = resource.getString(R.string.collected);
        String und = resource.getString(R.string.understock);
        String been = resource.getString(R.string.been_used);
        String sub = resource.getString(R.string.submit_the_parameter_error);
        String fai = resource.getString(R.string.failed);
        String pur = resource.getString(R.string.error_10008);
        String noi = resource.getString(R.string.no_shipping_information);
        String error = resource.getString(R.string.username_or_password_error);
        if (responseStatus.error_code == ErrorCodeConst.SelectedDeliverMethod) {
            ToastView toast = new ToastView(mContext, way);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }

        if (responseStatus.error_code == ErrorCodeConst.AlreadyCollected) {
            //Toast.makeText(mContext, "??", Toast.LENGTH_SHORT).show();
            ToastView toast = new ToastView(mContext, col);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }

        if (responseStatus.error_code == ErrorCodeConst.InventoryShortage) {
            ToastView toast = new ToastView(mContext, und);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }

        if (responseStatus.error_code == ErrorCodeConst.UserOrEmailExist) {
            ToastView toast = new ToastView(mContext, been);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }

        if (responseStatus.error_code == ErrorCodeConst.InvalidParameter) {
            ToastView toast = new ToastView(mContext, sub);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }

        if (responseStatus.error_code == ErrorCodeConst.ProcessFailed) {
            ToastView toast = new ToastView(mContext, fai);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }

        if (responseStatus.error_code == ErrorCodeConst.BuyFailed) {
            ToastView toast = new ToastView(mContext, pur);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }

        if (responseStatus.error_code == ErrorCodeConst.NoShippingInformation) {
            ToastView toast = new ToastView(mContext, noi);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }
        if (responseStatus.error_code == ErrorCodeConst.InvalidUsernameOrPassword) {
            ToastView toast = new ToastView(mContext, error);
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }
        if (responseStatus.error_code == ErrorCodeConst.UserOrEmailExist) {
            ToastView toast = new ToastView(mContext, resource.getString(R.string.been_used));
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
        }
    } catch (JSONException e) {

    }

}