Example usage for android.view Gravity CENTER_VERTICAL

List of usage examples for android.view Gravity CENTER_VERTICAL

Introduction

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

Prototype

int CENTER_VERTICAL

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

Click Source Link

Document

Place object in the vertical center of its container, not changing its size.

Usage

From source file:us.nineworlds.serenity.volley.YouTubeTrailerSearchResponseListener.java

@Override
public void onResponse(JSONObject response) {
    try {/*from  ww  w  .ja  v  a 2s .c  om*/
        JSONArray items = response.getJSONArray("items");
        View trailerIndicator = posterView.findViewById(R.id.trailerIndicator);
        View infoGraphicMeta = posterView.findViewById(R.id.infoGraphicMeta);

        JSONObject item = items.getJSONObject(0);
        JSONObject youtubeId = item.getJSONObject("id");

        String id = youtubeId.getString("videoId");

        createMetaData(id);
        if (trailerIndicator != null) {
            trailerIndicator.setVisibility(View.VISIBLE);
            infoGraphicMeta.setVisibility(View.VISIBLE);
        } else {
            Activity context = (Activity) posterView.getContext();
            LinearLayout infographicsView = (LinearLayout) context.findViewById(R.id.movieInfoGraphicLayout);
            ImageView ytImage = new ImageView(context);
            ytImage.setImageResource(R.drawable.yt_social_icon_red_128px);
            ytImage.setScaleType(ScaleType.FIT_XY);
            int w = ImageUtils.getDPI(45, context);
            int h = ImageUtils.getDPI(24, context);
            ytImage.setLayoutParams(new LinearLayout.LayoutParams(w, h));
            LinearLayout.LayoutParams p = (LinearLayout.LayoutParams) ytImage.getLayoutParams();
            p.leftMargin = 5;
            p.gravity = Gravity.CENTER_VERTICAL;
            infographicsView.addView(ytImage);
        }

        video.setTrailer(true);
        video.setTrailerId(id);
    } catch (JSONException e) {
        Log.d(getClass().getName(), e.getMessage(), e);
    }
}

From source file:com.grarak.rom.switcher.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);//from  w w w  . ja  v  a 2s . c o m

    progressBar = new ProgressBar(this);
    progressBar.getIndeterminateDrawable().setColorFilter(
            new LightingColorFilter(0xFF000000, getResources().getColor(android.R.color.white)));
    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.setCustomView(progressBar, new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT,
            ActionBar.LayoutParams.WRAP_CONTENT, Gravity.CENTER_VERTICAL | Gravity.END));

    new Task().execute();
}

From source file:com.vonglasow.michael.satstat.GpsSectionFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    mainActivity = (MainActivity) this.getContext();
    View rootView = inflater.inflate(R.layout.fragment_main_gps, container, false);

    // Initialize controls
    gpsRootLayout = (LinearLayout) rootView.findViewById(R.id.gpsRootLayout);
    gpsSnrView = (GpsSnrView) rootView.findViewById(R.id.gpsSnrView);
    gpsStatusView = new GpsStatusView(rootView.getContext());
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);//from   w ww. ja  v a2  s. c o  m
    params.gravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL;
    params.weight = 1;
    gpsRootLayout.addView(gpsStatusView, 0, params);
    gpsLatLayout = (LinearLayout) rootView.findViewById(R.id.gpsLatLayout);
    gpsLat = (TextView) rootView.findViewById(R.id.gpsLat);
    gpsLonLayout = (LinearLayout) rootView.findViewById(R.id.gpsLonLayout);
    gpsLon = (TextView) rootView.findViewById(R.id.gpsLon);
    gpsCoordLayout = (LinearLayout) rootView.findViewById(R.id.gpsCoordLayout);
    gpsCoord = (TextView) rootView.findViewById(R.id.gpsCoord);
    orDeclination = (TextView) rootView.findViewById(R.id.orDeclination);
    gpsSpeed = (TextView) rootView.findViewById(R.id.gpsSpeed);
    gpsSpeedUnit = (TextView) rootView.findViewById(R.id.gpsSpeedUnit);
    gpsAlt = (TextView) rootView.findViewById(R.id.gpsAlt);
    gpsAltUnit = (TextView) rootView.findViewById(R.id.gpsAltUnit);
    gpsTime = (TextView) rootView.findViewById(R.id.gpsTime);
    gpsBearing = (TextView) rootView.findViewById(R.id.gpsBearing);
    gpsAccuracy = (TextView) rootView.findViewById(R.id.gpsAccuracy);
    gpsAccuracyUnit = (TextView) rootView.findViewById(R.id.gpsAccuracyUnit);
    gpsOrientation = (TextView) rootView.findViewById(R.id.gpsOrientation);
    gpsSats = (TextView) rootView.findViewById(R.id.gpsSats);
    gpsTtff = (TextView) rootView.findViewById(R.id.gpsTtff);

    df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ROOT);

    mainActivity.gpsSectionFragment = this;

    return rootView;
}

From source file:org.sizzlelab.contextlogger.android.MainActivity.java

private void initUI() {
    // Set up the action bar.
    mActionBar = getSupportActionBar();/*from  www .  j av  a  2 s  .c o m*/
    mActionBar.setDisplayShowTitleEnabled(true);
    mActionBar.setNavigationMode(ActionBar.DISPLAY_SHOW_CUSTOM);
    mActionBar.setHomeButtonEnabled(false);
    mActionBar.setDisplayShowCustomEnabled(true);

    mSwitcherView = getLayoutInflater().inflate(R.layout.logging_switcher, null);
    mSwitch = (Switch) mSwitcherView.findViewById(R.id.logger_switcher);
    mSwitch.setTextOn(getString(R.string.start));
    mSwitch.setTextOff(getString(R.string.stop));
    final ActionBar.LayoutParams lp = new ActionBar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT);
    lp.gravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;
    lp.setMargins(0, 0, 5, 0);
    mActionBar.setCustomView(mSwitcherView, lp);

    FragmentTransaction transaction = getSupportFragmentTransaction();
    LoggerPanelFragment lpf = new LoggerPanelFragment();
    mLoggerStatusChangeListener = (OnContextLoggerStatusChangeListener) lpf;
    mSwitch.setOnCheckedChangeListener((OnCheckedChangeListener) lpf);
    transaction.replace(R.id.screen_container, lpf, "loggerPanel");
    transaction.commit();
}

From source file:com.polyvi.xface.extension.inappbrowser.XInAppBrowser.java

/**
 * ButtonContainer//  w ww  .  jav a  2  s  . c  o  m
 * @return
 */
protected RelativeLayout buildActionButtonContainerLayout() {
    return createActionButtonContainer(BUTTON_CONTAINER_ID,
            new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT), Gravity.LEFT,
            Gravity.CENTER_VERTICAL);
}

From source file:mobisocial.musubi.objects.WebAppObj.java

@Override
public View createView(Context context, ViewGroup parent) {
    LinearLayout frame = new LinearLayout(context);
    frame.setLayoutParams(CommonLayouts.FULL_WIDTH);
    frame.setOrientation(LinearLayout.VERTICAL);

    LinearLayout appBar = new LinearLayout(context);
    appBar.setLayoutParams(CommonLayouts.FULL_WIDTH);
    appBar.setOrientation(LinearLayout.HORIZONTAL);
    frame.addView(appBar);//from  w ww. ja v a 2s . c om

    Drawable icon = context.getResources().getDrawable(R.drawable.ic_menu_globe);
    ImageView iv = new ImageView(context);
    iv.setImageDrawable(icon);
    iv.setAdjustViewBounds(true);
    iv.setMaxWidth(60);
    iv.setMaxHeight(60);
    iv.setLayoutParams(CommonLayouts.WRAPPED);
    appBar.addView(iv);

    TextView tv = new TextView(context);
    tv.setLayoutParams(CommonLayouts.WRAPPED);
    tv.setGravity(Gravity.CENTER_VERTICAL);
    appBar.addView(tv);

    LinearLayout actionBar = new LinearLayout(context);
    actionBar.setLayoutParams(CommonLayouts.WRAPPED);
    actionBar.setOrientation(LinearLayout.HORIZONTAL);
    frame.addView(actionBar);

    Button b = new Button(context);
    // required for listview long-press
    b.setLayoutParams(CommonLayouts.WRAPPED);
    b.setFocusable(false);
    b.setText("Run");
    b.setOnClickListener(getRunListener());
    actionBar.addView(b);

    b = new Button(context);
    // required for listview long-press
    b.setLayoutParams(CommonLayouts.WRAPPED);
    b.setFocusable(false);
    b.setOnClickListener(getAddListener());
    actionBar.addView(b);

    return frame;
}

From source file:com.brookmanholmes.bma.wizard.ui.StepPagerStrip.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (pageCount == 0) {
        return;//from  w  ww. ja v a 2s .com
    }

    float totalWidth = pageCount * (tabWidth + indicatorSpacing) - indicatorSpacing;
    float totalcx;
    float cy;
    boolean fillHorizontal = false;

    switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.CENTER_HORIZONTAL:
        totalcx = (getWidth() - totalWidth) / 2;
        break;
    case Gravity.RIGHT:
        totalcx = getWidth() - getPaddingRight() - totalWidth;
        break;
    case Gravity.FILL_HORIZONTAL:
        totalcx = getPaddingLeft();
        fillHorizontal = true;
        break;
    default:
        totalcx = getPaddingLeft();
    }

    switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.CENTER_VERTICAL:
        cy = (int) (getHeight() - tabHeight) / 2;
        break;
    case Gravity.BOTTOM:
        cy = getHeight() - getPaddingBottom() - tabHeight;
        break;
    default:
        cy = getPaddingTop();
    }

    float center = cy + tabHeight / 2;

    float tabWidth = this.tabWidth;
    if (fillHorizontal) {
        tabWidth = (getWidth() - getPaddingRight() - getPaddingLeft() - (pageCount - 1) * indicatorSpacing)
                / pageCount;
    }

    for (int i = 0; i < pageCount; i++) {
        float cx = totalcx + (i * (tabWidth + indicatorSpacing));

        Paint tempPaint;

        if (i < currentPage)
            tempPaint = prevTabPaint;
        else if (i > currentPage)
            tempPaint = nextTabPaint;
        else
            tempPaint = selectedTabPaint;

        canvas.drawCircle(cx, center, i == currentPage ? radius : nonCurrentRadius, tempPaint);
    }
}

From source file:com.xargsgrep.portknocker.asynctask.KnockerAsyncTask.java

private void showToast(String text) {
    Toast toast = Toast.makeText(activity, text, Toast.LENGTH_LONG);
    toast.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0);
    toast.show();
}

From source file:com.hyperkode.friendshare.fragment.LoginFragment.java

private void setupButtons() {
    // Login button handler
    loginButton = (Button) mThisActivity.findViewById(R.id.loginbutton_continue);
    loginButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            EditText usernameText = (EditText) mThisActivity.findViewById(R.id.login_username_textbox);
            String un = usernameText.getText().toString();

            if (cb != null && cb.isChecked()) {
                // do Twitter login
                authTwitter();//from ww w  .  ja  v  a2 s  .c om
                return;
            }

            if (un == null || un.length() == 0) {
                Toast toast = Toast.makeText(mThis, mThis.getString(R.string.enter_username),
                        Toast.LENGTH_LONG);
                toast.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL, 0, 0);
                toast.show();
                return;
            }

            //EditText passwordText = (EditText) findViewById(R.id.login_password_textbox);
            //String pw = passwordText.getText().toString();
            //Intent i = new Intent(mThis, LandingActivity.class);
            //mThis.startActivity(i);

            /*
            FragmentManager fm = LoginFragment.this.getActivity().getSupportFragmentManager();
            FragmentTransaction ft = fm.beginTransaction();
            ft.add(R.id.main_view_containter, LoginFragment.this);
            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
            ft.addToBackStack(null);
            ft.commit();
            */

        }
    });

    // Cancel button handler
    cancelButton = (Button) mThisActivity.findViewById(R.id.loginbutton_cancel);
    cancelButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // Exit screen
            mThis.finish();
        }
    });
}

From source file:id.co.datascrip.dtswarehousesystem.custom.StepPagerStrip.java

@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (mPageCount == 0) {
        return;/* w w w  .  ja v a 2s .  c o m*/
    }

    float totalWidth = mPageCount * (mTabWidth + mTabSpacing) - mTabSpacing;
    float totalLeft;
    boolean fillHorizontal = false;

    switch (mGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.CENTER_HORIZONTAL:
        totalLeft = (getWidth() - totalWidth) / 2;
        break;
    case Gravity.END:
        totalLeft = getWidth() - getPaddingRight() - totalWidth;
        break;
    case Gravity.FILL_HORIZONTAL:
        totalLeft = getPaddingLeft();
        fillHorizontal = true;
        break;
    default:
        totalLeft = getPaddingLeft();
    }

    switch (mGravity & Gravity.VERTICAL_GRAVITY_MASK) {
    case Gravity.CENTER_VERTICAL:
        mTempRectF.top = (int) (getHeight() - mTabHeight) / 2;
        break;
    case Gravity.BOTTOM:
        mTempRectF.top = getHeight() - getPaddingBottom() - mTabHeight;
        break;
    default:
        mTempRectF.top = getPaddingTop();
    }

    mTempRectF.bottom = mTempRectF.top + mTabHeight;

    float tabWidth = mTabWidth;
    if (fillHorizontal) {
        tabWidth = (getWidth() - getPaddingRight() - getPaddingLeft() - (mPageCount - 1) * mTabSpacing)
                / mPageCount;
    }

    for (int i = 0; i < mPageCount; i++) {
        mTempRectF.left = totalLeft + (i * (tabWidth + mTabSpacing));
        mTempRectF.right = mTempRectF.left + tabWidth;
        canvas.drawRect(mTempRectF,
                i < mCurrentPage ? mPrevTabPaint
                        : (i > mCurrentPage ? mNextTabPaint
                                : (i == mPageCount - 1 ? mSelectedLastTabPaint : mSelectedTabPaint)));
    }
}