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:android.view.SpringIndicator.java

private void addTabItems() {
    final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1.0f);
    tabs = new ArrayList<>();
    for (int i = 0; i < viewPager.getAdapter().getCount(); i++) {
        final TextView textView = new TextView(getContext());
        if (viewPager.getAdapter().getPageTitle(i) != null)
            textView.setText(viewPager.getAdapter().getPageTitle(i));
        textView.setGravity(Gravity.CENTER);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
        textView.setTextColor(getResources().getColor(textColorId));
        if (textBgResId != 0)
            textView.setBackgroundResource(textBgResId);
        textView.setLayoutParams(layoutParams);
        final int position = i;
        textView.setOnClickListener(new OnClickListener() {
            @Override/*w  w w .j  a  va  2s.c  o  m*/
            public void onClick(final View v) {
                if (tabClickListener == null || tabClickListener.onTabClick(position))
                    viewPager.setCurrentItem(position);
            }
        });
        tabs.add(textView);
        tabContainer.addView(textView);
    }
}

From source file:com.lucapernini.misapp.Registration.java

public void showToast(String msg) {
    Log.i(TAG, "Misa Registration, showToast: " + msg);

    Toast toast = Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT);
    toast.setGravity(Gravity.CENTER, toast.getXOffset() / 2, toast.getYOffset() / 2);
    toast.show();// w  w w.j a va 2  s .  c  o m

}

From source file:com.ayoview.sample.textview.badge.ViewsFragment.java

@Override
public void onClick(View v) {
    switch (v.getId()) {
    case R.id.counter: {
        counterBadge.incrementBadgeCount(1);
        break;/*from  www. j a  v  a  2 s .c o m*/
    }

    case R.id.gravity: {
        gravityBadge.incrementBadgeCount(1);
        Log.d(getClass().getName(), String.valueOf(gravityBadge.getBadgeCount() % 9));
        if (gravityBadge.getBadgeCount() % 9 == 0) {
            gravityBadge.setBadgeGravity(Gravity.LEFT | Gravity.TOP);
        } else if (gravityBadge.getBadgeCount() % 9 == 1) {
            gravityBadge.setBadgeGravity(Gravity.RIGHT | Gravity.BOTTOM);
        } else if (gravityBadge.getBadgeCount() % 9 == 2) {
            gravityBadge.setBadgeGravity(Gravity.LEFT | Gravity.BOTTOM);
        } else if (gravityBadge.getBadgeCount() % 9 == 3) {
            gravityBadge.setBadgeGravity(Gravity.RIGHT | Gravity.TOP);
        } else if (gravityBadge.getBadgeCount() % 9 == 4) {
            gravityBadge.setBadgeGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
        } else if (gravityBadge.getBadgeCount() % 9 == 5) {
            gravityBadge.setBadgeGravity(Gravity.RIGHT | Gravity.CENTER_VERTICAL);
        } else if (gravityBadge.getBadgeCount() % 9 == 6) {
            gravityBadge.setBadgeGravity(Gravity.CENTER);
        } else if (gravityBadge.getBadgeCount() % 9 == 7) {
            gravityBadge.setBadgeGravity(Gravity.CENTER_HORIZONTAL | Gravity.TOP);
        } else if (gravityBadge.getBadgeCount() % 9 == 8) {
            gravityBadge.setBadgeGravity(Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
        }
        break;
    }
    case R.id.visibility: {
        visibilityBadgeView
                .setVisibility(visibilityBadgeView.getVisibility() == View.GONE ? View.VISIBLE : View.GONE);
        break;
    }

    default:
        break;
    }

}

From source file:com.example.h156252.connected_cars.CarGrid.java

/** Called when the activity is first created. */
@Override//from w  ww .ja  v  a2s  .  c om
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.content_car_grid);
    try {
        Window window = getWindow();

        // clear FLAG_TRANSLUCENT_STATUS flag:
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

        // add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the window
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

        // finally change the color
        window.setStatusBarColor(Color.rgb(0, 0, 0));
        android.support.v7.app.ActionBar actionBar = getSupportActionBar();
        actionBar.setBackgroundDrawable(new ColorDrawable(Color.rgb(0, 0, 0)));
    } catch (Exception e) {
        // Toast.makeText(getApplicationContext(),"Exception in actionbar  "+e.getLocalizedMessage(),Toast.LENGTH_SHORT).show();
    }
    session = new SessionManagement(this);
    tts = new TextToSpeech(this, this);
    //Toast.makeText(getApplicationContext(),"Entering activity",Toast.LENGTH_SHORT).show();
    Intent intent = getIntent();
    String result = intent.getStringExtra(HomeScreen.EXTRA_MESSAGE);
    //Toast.makeText(getApplicationContext(),"obtaining result: " +result,Toast.LENGTH_SHORT).show();
    ArrayList<String> listdata = new ArrayList<String>();

    try {

        JSONArray jArray = new JSONArray(result);
        if (jArray != null) {
            for (int i = 0; i < jArray.length(); i++) {

                String jstr = jArray.get(i).toString();
                JSONObject jObj = new JSONObject(jstr);
                String id = jObj.getString("id");
                //String phone = jObj.getString("phone");
                String brand = jObj.getString("text");
                String text = jObj.getString("cartext");
                String carno = jObj.getString("carnum");
                String color = jObj.getString("color");
                //String isDone = jObj.getString("isDone");
                String result_combine = "CAR " + i + ":\nCar id : #" + id + "*\n" + "License No.   : " + carno
                        + "\n" + "Color   : " + color + "\n" + "Brand   : " + brand + "\n"
                        + "Text behind car   : " + text;
                String rr = "Success " + result_combine;
                //Toast.makeText(getApplicationContext(),rr,Toast.LENGTH_SHORT).show();
                String own_id = session.getID();
                if (!(id.equals(own_id)))
                    listdata.add(result_combine);
            }
        }
    } catch (Exception e) {
        //Toast.makeText(getApplicationContext(),e.getLocalizedMessage(),Toast.LENGTH_SHORT).show();
    }

    //Toast.makeText(getApplicationContext(),"out of json",Toast.LENGTH_SHORT).show();
    final GridView gridview = (GridView) findViewById(R.id.gridview);
    // final String[] items = new String[] { "Item1", "Item2", "Item3","Item4", "Item5", "Item6", "Item7", "Item8" };

    ArrayAdapter<String> ad = new ArrayAdapter<String>(getApplicationContext(),
            android.R.layout.simple_list_item_1, listdata);
    //Toast.makeText(getApplicationContext(),"setting array adapter",Toast.LENGTH_SHORT).show();
    //gridview.setBackgroundColor(Color.GRAY);

    gridview.setNumColumns(2);
    gridview.setGravity(Gravity.CENTER);
    gridview.setAdapter(ad);
    gridview.setBackgroundColor(Color.GRAY);
    //Toast.makeText(getApplicationContext(),"setting grid view",Toast.LENGTH_SHORT).show();
    gridview.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> arg0, View v, int position, long arg3) {
            // TODO Auto-generated method stub
            // Toast.makeText(getApplicationContext(), "" + arg2,Toast.LENGTH_SHORT).show();
            //Toast.makeText(getApplicationContext(),"Prompting speech",Toast.LENGTH_SHORT).show();

            try {
                String s = ((TextView) v).getText().toString();

                int start = 0; // '(' position in string
                int end = 0; // ')' position in string
                for (int i = 0; i < s.length(); i++) {
                    if (s.charAt(i) == '#') // Looking for '(' position in string
                        start = i;
                    else if (s.charAt(i) == '*') // Looking for ')' position in  string
                        end = i;
                }
                receiver_id = s.substring(start + 1, end);

                //Toast.makeText(getApplicationContext(), "ID: " + receiver_id, Toast.LENGTH_SHORT).show();
                //promptSpeechInput();

            } catch (Exception e) {
                // Toast.makeText(getApplicationContext(), e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
            }

            //receiver_id = grid_text.substring(grid_text.indexOf("#") + 1, grid_text.indexOf("#"));
            //Toast.makeText(getApplicationContext(),receiver_id,Toast.LENGTH_SHORT).show();

            try {
                promptSpeechInput();
            } catch (Exception e) {
                //Toast.makeText(getApplicationContext(), e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
            }

            try {
                Intent intent_rate = new Intent(getApplicationContext(), RateDriving.class);
                intent_rate.putExtra(EXTRA_MESSAGE, receiver_id);
                startActivity(intent_rate);

            } catch (Exception e) {
                //Toast.makeText(getApplicationContext(), e.getLocalizedMessage(), Toast.LENGTH_SHORT).show();
            }

            //new VoiceTask().execute("http://myfirst.au-syd.mybluemix.net/api/Items");
        }
    });

}

From source file:com.gokuai.yunkuandroidsdk.compat.v2.UrlTouchImageView.java

@SuppressWarnings("deprecation")
protected void init() {

    mImageView = new TouchImageView(mContext);

    LayoutParams params = new LayoutParams(android.view.ViewGroup.LayoutParams.FILL_PARENT,
            android.view.ViewGroup.LayoutParams.FILL_PARENT);
    mImageView.setLayoutParams(params);//  w  w w.  ja va 2 s  .  co m
    this.addView(mImageView);

    mImageView.setVisibility(GONE);

    mProgressBar = new ProgressBar(mContext, null, android.R.attr.progressBarStyleInverse);
    params = new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.CENTER_IN_PARENT);
    mProgressBar.setLayoutParams(params);
    mProgressBar.setIndeterminate(false);
    this.addView(mProgressBar);

    mTextView = new TextView(mContext);
    params = new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.CENTER_HORIZONTAL);
    params.addRule(RelativeLayout.CENTER_IN_PARENT);
    mTextView.setLayoutParams(params);
    int left = getResources().getDimensionPixelSize(R.dimen.gallery_percent_tv_padding_left);
    int top = getResources().getDimensionPixelSize(R.dimen.gallery_percent_tv_padding_top);
    int right = getResources().getDimensionPixelSize(R.dimen.gallery_percent_tv_padding_right);
    int bottom = getResources().getDimensionPixelSize(R.dimen.gallery_percent_tv_padding_bottom);
    mTextView.setPadding(left, top, right, bottom);
    mTextView.setGravity(Gravity.CENTER);
    mTextView.setTextColor(Color.WHITE);
    mTextView.setText(R.string.tip_is_preparing_for_data);
    mTextView.setVisibility(View.GONE);
    this.addView(mTextView);

    mButton = new Button(mContext);
    params = new LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT,
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    params.addRule(RelativeLayout.CENTER_IN_PARENT);
    mButton.setLayoutParams(params);
    mButton.setGravity(Gravity.CENTER);
    mButton.setText(R.string.tip_image_button);
    mButton.setTextColor(Color.WHITE);
    mButton.setBackgroundResource(R.drawable.btn_check_image);
    mButton.setVisibility(View.GONE);
    this.addView(mButton);

    mButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            mImageUrlTask = new AsyncTask<Void, Integer, Bitmap>() {

                @Override
                protected Bitmap doInBackground(Void... voids) {
                    if (mFileData != null) {
                        FileData fileData = FileDataManager.getInstance()
                                .getFileInfoSync(mFileData.getFullpath());

                        return getOriImage(fileData, new ParamsCallBack() {
                            @Override
                            public void callBack(Object obj) {
                                publishProgress((int) obj);
                            }
                        });

                    } else {
                        return null;
                    }

                }

                @Override
                protected void onProgressUpdate(Integer... values) {
                    super.onProgressUpdate(values);
                    mButton.setVisibility(GONE);
                    mTextView.setVisibility(VISIBLE);
                    mProgressBar.setVisibility(VISIBLE);
                    if (values[0] == -1) {
                        mTextView.setText(mContext.getString(R.string.tip_is_loading));
                    } else {
                        mTextView.setText(values[0] + " %");
                    }
                }

                @Override
                protected void onPostExecute(Bitmap bitmap) {
                    super.onPostExecute(bitmap);

                    if (mImageView != null && mProgressBar != null) {
                        if (bitmap != null) {
                            mButton.setVisibility(GONE);
                            mImageView.setScaleType(ScaleType.MATRIX);
                            mImageView.setImageBitmap(bitmap);

                            mTextView.setVisibility(View.GONE);
                            mImageView.setVisibility(VISIBLE);
                            mProgressBar.setVisibility(GONE);

                        } else {
                            mButton.setVisibility(GONE);
                            mTextView.setVisibility(VISIBLE);
                            mTextView.setText(R.string.tip_open_image_failed);
                            mProgressBar.setVisibility(View.VISIBLE);
                        }
                    }

                }
            }.execute();
        }
    });

}

From source file:android.support.design.internal.BottomNavigationItemView.java

@Override
public void setChecked(boolean checked) {
    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 {//from   ww w  . ja  va  2  s. co m
            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.aashir.gmote.player.widget.SlidingTabLayout.java

/**
 * Create a default view to be used for tabs. This is called if a custom tab view is not set via
 * {@link #setCustomTabView(int, int)}.//  w w  w  .  ja  v a  2 s.com
 */
protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    textView.setLayoutParams(new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.WRAP_CONTENT, 1f));

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    textView.setBackgroundResource(outValue.resourceId);
    textView.setAllCaps(true);

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}

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

@Override
public void onClick(View v) {
    Intent intent;//w  w w.j ava 2 s. c o  m
    switch (v.getId()) {
    case R.id.top_view_back:
        finish();
        break;
    case R.id.top_member_upate:
        String no = member_no.getText().toString().trim();
        String name = member_name.getText().toString();
        String phone = mobile_no.getText().toString();
        String nShopid = mShared.getString("shopid", "0");
        String nShopname = mShared.getString("shopname", "");

        if ("".equals(name)) {
            ToastView toast = new ToastView(F0_ProfileActivity.this, "????");
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            member_name.setText("");
            member_name.requestFocus();
        } else if ("".equals(no)) {
            ToastView toast = new ToastView(F0_ProfileActivity.this, "????");
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            member_no.requestFocus();
        } else if ("".equals(phone)) {
            ToastView toast = new ToastView(F0_ProfileActivity.this, "???");
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            mobile_no.requestFocus();
        } else {
            SIMPLE_MEMBER simple_member = new SIMPLE_MEMBER();
            simple_member.member_no = no;
            simple_member.member_name = name;
            simple_member.mobile_no = phone;
            simple_member.id = member.id;
            simple_member.shopid = nShopid;
            simple_member.shopname = nShopname;
            mMemberModel.update(simple_member);
            CloseKeyBoard();
        }
        break;

    case R.id.c0_del_button: {
        mAlertView.show();

        break;

    }
    }
}

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

@Override
public void onClick(View v) {
    String brief = mBrief.getText().toString().trim();
    switch (v.getId()) {
    case R.id.top_view_back:
        finish();// w ww.  j  a va 2 s .  com
        break;
    case R.id.btn_save:
        if ("".equals(brief)) {
            ToastView toast = new ToastView(C4_EditIntroActivity.this,
                    getString(R.string.brief_wrong_format_hint));
            toast.setGravity(Gravity.CENTER, 0, 0);
            toast.show();
            mBrief.setText("");
            mBrief.requestFocus();
            break;
        } else {
            mUserModel.changeBrief(brief);
        }
    }
}

From source file:it.redturtle.mobile.apparpav.MeteogramAdapter.java

/**
 * DOUBLE TITLE ROW//w w  w.  j  a  va2s  . c o m
 * @param att
 * @param linear
 * @return
 */
public LinearLayout getDoubleTitleRow(Map<String, String> att, LinearLayout linear) {
    LinearLayout container_layout = new LinearLayout(context);
    container_layout.setMinimumHeight(30);
    container_layout
            .setBackgroundDrawable(context.getResources().getDrawable(R.drawable.view_shape_meteo_blue));
    container_layout.setVerticalGravity(Gravity.CENTER);
    container_layout.setOrientation(LinearLayout.HORIZONTAL);

    LinearLayout.LayoutParams value_params = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.3f);
    TextView tx = new TextView(context);
    tx.setText("");
    tx.setTextColor(Color.rgb(66, 66, 66));
    container_layout.addView(tx, value_params);

    LinearLayout.LayoutParams ltext1 = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.35f);
    TextView t1 = new TextView(context);
    t1.setText(att.get("value1"));
    t1.setTextSize(11);
    t1.setGravity(Gravity.CENTER_HORIZONTAL);
    t1.setPadding(2, 0, 0, 2);
    t1.setTextColor(Color.rgb(255, 255, 255));
    container_layout.addView(t1, ltext1);

    LinearLayout.LayoutParams ltext2 = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.WRAP_CONTENT, 0.35f);
    TextView t2 = new TextView(context);
    t2.setText(att.get("value2"));
    t2.setTextSize(11);
    t2.setGravity(Gravity.CENTER_HORIZONTAL);
    t2.setPadding(2, 0, 0, 2);
    t2.setTextColor(Color.rgb(255, 255, 255));
    container_layout.addView(t2, ltext2);

    linear.addView(container_layout);
    return linear;
}