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:pl.bcichecki.rms.client.android.activities.LoginActivity.java

protected void performLogin() {
    Log.d(TAG, "Performing login... [username=" + username + ", password=" + password + "]");
    profileRestClient = new ProfileRestClient(CONTEXT, username, password,
            SharedPreferencesWrapper.getServerRealm(), SharedPreferencesWrapper.getServerAddress(),
            SharedPreferencesWrapper.getServerPort(), SharedPreferencesWrapper.getWebserviceContextPath());
    profileRestClient.getProfile(new GsonHttpResponseHandler<User>(new TypeToken<User>() {
    }.getType(), true) {/*from w  w w . j  a  v  a2s. c  o  m*/

        @Override
        public void onFailure(Throwable error, String content) {
            Log.d(TAG, "Getting profile failed! [error=" + error + ", content=" + content + "]");
            AlertDialog.Builder errorDialog = new AlertDialog.Builder(CONTEXT);
            errorDialog.setIcon(android.R.drawable.ic_dialog_alert);
            if (error instanceof HttpResponseException) {
                if (((HttpResponseException) error).getStatusCode() == HttpStatus.SC_UNAUTHORIZED) {
                    errorDialog.setTitle(R.string.activity_login_unsuccessful_login_message_title);
                    errorDialog.setMessage(R.string.activity_login_unsuccessful_login_message_content);
                } else {
                    errorDialog.setTitle(R.string.general_unknown_error_message_title);
                    errorDialog
                            .setMessage(String.format(getString(R.string.general_unknown_error_message_content),
                                    (HttpResponseException) error));
                }
            } else {
                errorDialog.setTitle(R.string.general_unknown_error_message_title);
                errorDialog.setMessage(
                        String.format(getString(R.string.general_unknown_error_message_content), error));
            }
            errorDialog.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
            AlertDialog dialog = errorDialog.show();
            TextView messageText = (TextView) dialog.findViewById(android.R.id.message);
            messageText.setGravity(Gravity.CENTER);
        }

        @Override
        public void onFinish() {
            showProgress(false);
            Log.d(TAG, "Getting profile finished.");
        }

        @Override
        public void onStart() {
            Log.d(TAG, "Getting profile started.");
            showProgress(true);
        }

        @Override
        public void onSuccess(int statusCode, User user) {
            Log.d(TAG, "Success [statusCode=" + statusCode + ", jsonObject=" + user.toString() + "]");
            UserProfileHolder.setUserProfile(user);
            UserProfileHolder.setUsername(username);
            UserProfileHolder.setPassword(password);
            AppUtils.showCenteredToast(CONTEXT, R.string.activity_login_login_successful, Toast.LENGTH_SHORT);
            Intent mainActivityIntent = new Intent(CONTEXT, MainActivity.class);
            startActivity(mainActivityIntent);
        }
    });
}

From source file:cn.com.zzwfang.view.indicator.PagerSlidingTabStrip.java

private void addTextTab(final int position, String title) {

    TextView tab = new TextView(getContext());
    tab.setLayoutParams(getLayoutParams());
    tab.setText(title);/*from  w w  w .  j av  a 2 s .  co m*/
    tab.setFocusable(true);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();

    tab.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            pager.setCurrentItem(position);
        }
    });

    tabsContainer.addView(tab);

}

From source file:brostore.maquillage.custom.PagerSlidingTabStrip.java

private void addCustomTextTab(final int position, String title) {
    LinearLayout conteneur = new LinearLayout(getContext());
    LinearLayout.LayoutParams param = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT);
    conteneur.setOrientation(LinearLayout.HORIZONTAL);
    conteneur.setGravity(Gravity.CENTER);
    TextView tab = new TextView(getContext());
    TextView tabCust = new TextView(getContext());
    //tabCust.setBackgroundResource(R.drawable.live_nombre);
    tabCust.setGravity(Gravity.CENTER);//from   www  . j  a  v a  2 s .co m
    tabCust.setTextColor(Color.WHITE);
    tabCust.setTypeface(tabTypeface);
    tabCust.setTextSize(11);
    tabCust.setVisibility(View.GONE);
    int fiveDip = Utils.convertDpToPixel(5, getResources());
    tabCust.setPadding(fiveDip, 0, fiveDip, 0);
    tabCust.setText("0");
    tab.setText(title);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();

    conteneur.addView(tab, param);
    param.leftMargin = Utils.convertDpToPixel(10, getResources());
    conteneur.addView(tabCust, param);
    addTab(position, conteneur);
}

From source file:com.hybris.mobile.lib.ui.view.Alert.java

/**
 * Show the alert/*  w  ww.  jav  a 2s.co m*/
 *
 * @param context                 application-specific resources
 * @param configuration           describes all device configuration information
 * @param text                    message to be displayed
 * @param forceClearPreviousAlert true will clear previous alert else keep it
 */
@SuppressLint("NewApi")
private static void showAlertOnScreen(final Activity context, final Configuration configuration,
        final String text, boolean forceClearPreviousAlert) {

    final ViewGroup mainView = ((ViewGroup) context.findViewById(android.R.id.content));
    boolean currentlyDisplayed = false;
    int viewId = R.id.alert_view_top;
    final TextView textView;
    boolean alertAlreadyExists = false;

    if (configuration.getOrientation().equals(Configuration.Orientation.BOTTOM)) {
        viewId = R.id.alert_view_bottom;
    }

    // Retrieving the view
    RelativeLayout relativeLayout = (RelativeLayout) mainView.findViewById(viewId);

    if (forceClearPreviousAlert) {
        mainView.removeView(relativeLayout);
        relativeLayout = null;
    }

    // Creating the view
    if (relativeLayout == null) {

        // Main layout
        relativeLayout = new RelativeLayout(context);
        relativeLayout.setId(viewId);
        relativeLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, configuration.getHeight()));
        relativeLayout.setGravity(Gravity.CENTER);

        // Textview
        textView = new TextView(context);
        textView.setId(R.id.alert_view_text);
        textView.setGravity(Gravity.CENTER);
        textView.setLayoutParams(
                new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
        relativeLayout.addView(textView);

        setIcon(context, configuration, relativeLayout, textView);

        if (configuration.getOrientation().equals(Configuration.Orientation.TOP)) {
            relativeLayout.setY(-configuration.getHeight());
        } else {
            relativeLayout.setY(mainView.getHeight());
        }

        // Adding the view to the global layout
        mainView.addView(relativeLayout, 0);
        relativeLayout.bringToFront();
        relativeLayout.requestLayout();
        relativeLayout.invalidate();
    }
    // View already exists
    else {
        alertAlreadyExists = true;
        textView = (TextView) relativeLayout.findViewById(R.id.alert_view_text);

        if (configuration.getOrientation().equals(Configuration.Orientation.TOP)) {
            if (relativeLayout.getY() == 0) {
                currentlyDisplayed = true;
            }
        } else {
            if (relativeLayout.getY() < mainView.getHeight()) {
                currentlyDisplayed = true;
            }
        }

        // The view is currently shown to the user
        if (currentlyDisplayed) {

            // If the message is not the same, we hide the current message and display the new one
            if (!StringUtils.equals(text, textView.getText())) {
                // Anim out the current message
                ViewPropertyAnimator viewPropertyAnimator = animOut(configuration, mainView, relativeLayout);

                final RelativeLayout relativeLayoutFinal = relativeLayout;

                if (viewPropertyAnimator != null) {
                    // Anim in the new message after the animation out has finished
                    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
                        viewPropertyAnimator.setListener(new AnimatorListenerAdapter() {
                            @Override
                            public void onAnimationEnd(Animator animation) {
                                setIcon(context, configuration, relativeLayoutFinal, textView);
                                animIn(configuration, relativeLayoutFinal, textView, mainView, text);
                            }
                        });
                    } else {
                        viewPropertyAnimator.withEndAction(new Runnable() {
                            @Override
                            public void run() {
                                setIcon(context, configuration, relativeLayoutFinal, textView);
                                animIn(configuration, relativeLayoutFinal, textView, mainView, text);
                            }
                        });
                    }
                } else {
                    setIcon(context, configuration, relativeLayoutFinal, textView);
                    animIn(configuration, relativeLayoutFinal, textView, mainView, text);
                }
            }
        }
    }

    final RelativeLayout relativeLayoutFinal = relativeLayout;

    // Close the alert by clicking the layout
    if (configuration.isCloseable()) {
        relativeLayout.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                animOut(configuration, mainView, relativeLayoutFinal);
                v.performClick();
                return true;
            }
        });
    }

    if (!currentlyDisplayed) {
        // Set the icon in case the alert already exists but it's not currently displayed
        if (alertAlreadyExists) {
            setIcon(context, configuration, relativeLayoutFinal, textView);
        }

        // We anim in the alert
        animIn(configuration, relativeLayoutFinal, textView, mainView, text);
    }
}

From source file:cn.org.eshow.framwork.view.sliding.AbSlidingSmoothFixTabView.java

/**
 * ??tab.// w ww. j a  v a2 s.co m
 *
 * @param tabText the tab text
 * @param fragment the fragment
 */
public void addItemView(String tabText, Fragment fragment) {

    tabItemTextList.add(tabText);
    pagerItemList.add(fragment);

    tabItemList.clear();
    mTabLayout.removeAllViews();

    for (int i = 0; i < tabItemTextList.size(); i++) {
        final int index = i;
        String text = tabItemTextList.get(i);
        TextView tv = new TextView(this.context);
        tv.setTextColor(tabColor);
        tv.setTextSize(tabTextSize);
        tv.setText(text);
        tv.setGravity(Gravity.CENTER);
        tv.setLayoutParams(new LayoutParams(0, LayoutParams.FILL_PARENT, 1));
        tv.setPadding(12, 5, 12, 5);
        tv.setFocusable(false);
        tabItemList.add(tv);
        mTabLayout.addView(tv);
        tv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                mViewPager.setCurrentItem(index);
            }
        });
    }

    //?
    AbLogUtil.d(AbSlidingSmoothFixTabView.class, "addItemView finish");
    mFragmentPagerAdapter.notifyDataSetChanged();
    mViewPager.setCurrentItem(0);
    computeTabImg(0);
}

From source file:com.bangqu.eshow.view.sliding.ESSlidingSmoothFixTabView.java

/**
 * ??tab.// ww w  . ja v  a 2s.  co m
 *
 * @param tabText the tab text
 * @param fragment the fragment
 */
public void addItemView(String tabText, Fragment fragment) {

    tabItemTextList.add(tabText);
    pagerItemList.add(fragment);

    tabItemList.clear();
    mTabLayout.removeAllViews();

    for (int i = 0; i < tabItemTextList.size(); i++) {
        final int index = i;
        String text = tabItemTextList.get(i);
        TextView tv = new TextView(this.context);
        tv.setTextColor(tabColor);
        tv.setTextSize(tabTextSize);
        tv.setText(text);
        tv.setGravity(Gravity.CENTER);
        tv.setLayoutParams(new LayoutParams(0, LayoutParams.FILL_PARENT, 1));
        tv.setPadding(12, 5, 12, 5);
        tv.setFocusable(false);
        tabItemList.add(tv);
        mTabLayout.addView(tv);
        tv.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View arg0) {
                mViewPager.setCurrentItem(index);
            }
        });
    }

    //?
    ESLogUtil.d(ESSlidingSmoothFixTabView.class, "addItemView finish");
    mFragmentPagerAdapter.notifyDataSetChanged();
    mViewPager.setCurrentItem(0);
    computeTabImg(0);
}

From source file:fr.univsavoie.ltp.client.map.Popup.java

/**
 * Afficher une boite au milieu de la carte si aucun utilisateur est connects
 * pour proposer a l'invit, de se connecter ou s'incrire aupres du service LTP.
 *///from w ww .j  av a2s  . c o  m
public final void popupGuest() {
    DisplayMetrics dm = new DisplayMetrics();
    this.activity.getWindowManager().getDefaultDisplay().getMetrics(dm);

    //final int height = dm.heightPixels;
    final int width = dm.widthPixels;
    //final int height = dm.heightPixels;

    int popupWidth = (int) (width * 0.75);
    //int popupHeight = height / 2;

    // Inflate the popup_layout.xml
    LinearLayout viewGroup = (LinearLayout) this.activity.findViewById(R.id.popupGuest);
    LayoutInflater layoutInflater = (LayoutInflater) this.activity
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    final View layout = layoutInflater.inflate(R.layout.popup_guest, viewGroup);
    layout.setBackgroundResource(R.drawable.popup_gradient);

    // Crer le PopupWindow
    final PopupWindow popupGuest = new PopupWindow(layout, popupWidth, LayoutParams.WRAP_CONTENT, true);
    popupGuest.setBackgroundDrawable(new BitmapDrawable());
    popupGuest.setOutsideTouchable(true);

    // Some offset to align the popup a bit to the right, and a bit down, relative to button's position.
    final int OFFSET_X = 0;
    final int OFFSET_Y = 0;

    // Displaying the popup at the specified location, + offsets.
    this.activity.findViewById(R.id.layoutMain).post(new Runnable() {
        public void run() {
            popupGuest.showAtLocation(layout, Gravity.CENTER, OFFSET_X, OFFSET_Y);
        }
    });

    /*
     * Evenements composants du PopupWindow
     */

    // Ecouteur d'vnement sur le bouton des paramtres
    Button btLogin = (Button) layout.findViewById(R.id.btnPopupLogin);
    btLogin.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            // La constante CODE_MON_ACTIVITE reprsente lidentifiant de la requte
            // (requestCode) qui sera utilis plus tard pour identifier lactivit
            // renvoyant la valeur de retour.
            Intent i = new Intent(activity, LoginActivity.class);
            activity.startActivityForResult(i, 1);

            popupGuest.dismiss();
        }
    });

    // Ecouteur d'vnement sur le bouton des paramtres
    Button btSignup = (Button) layout.findViewById(R.id.btnPopupSignup);
    btSignup.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
            // La constante CODE_MON_ACTIVITE reprsente lidentifiant de la requte
            // (requestCode) qui sera utilis plus tard pour identifier lactivit
            // renvoyant la valeur de retour.
            Intent i = new Intent(activity, SignupActivity.class);
            activity.startActivityForResult(i, 3);

            popupGuest.dismiss();
        }
    });

    // Ecouteur d'vnement sur le bouton pour fermer l'application
    Button close = (Button) layout.findViewById(R.id.btnPopupClose);
    close.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            popupGuest.dismiss();
        }
    });
}

From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java

@Override
public void onCreate() {
    mRecordingTimeView = new TextView(ApplicationScreen.getMainContext());
    mRecordingTimeView.setTextSize(12);/* ww  w. j a  v a  2s  .  co  m*/
    mRecordingTimeView.setBackgroundResource(R.drawable.thumbnail_background);
    mRecordingTimeView.setVisibility(View.GONE);
    mRecordingTimeView.setGravity(Gravity.CENTER);
    mRecordingTimeView.setText("00:00");

    this.createModeSwitcher();

    if (VERSION.SDK_INT < VERSION_CODES.JELLY_BEAN_MR2) {
        this.modeSwitcher.setVisibility(View.GONE);
    }
}

From source file:net.oschina.app.ui.MainActivity.java

private void initTabs() {
    MainTab[] tabs = MainTab.values();/*from w ww  .j  a v a 2s .  c  o  m*/
    final int size = tabs.length;
    for (int i = 0; i < size; i++) {
        MainTab mainTab = tabs[i];
        TabSpec tab = mTabHost.newTabSpec(getString(mainTab.getResName()));
        View indicator = LayoutInflater.from(getApplicationContext()).inflate(R.layout.tab_indicator, null);
        TextView title = (TextView) indicator.findViewById(R.id.tab_title);
        Drawable drawable = this.getResources().getDrawable(mainTab.getResIcon());
        title.setCompoundDrawablesWithIntrinsicBounds(null, drawable, null, null);
        if (i == 2) {
            indicator.setVisibility(View.INVISIBLE);
            mTabHost.setNoTabChangedTag(getString(mainTab.getResName()));
        }
        title.setText(getString(mainTab.getResName()));
        tab.setIndicator(indicator);
        tab.setContent(new TabContentFactory() {

            @Override
            public View createTabContent(String tag) {
                return new View(MainActivity.this);
            }
        });
        mTabHost.addTab(tab, mainTab.getClz(), null);

        if (mainTab.equals(MainTab.ME)) {
            View cn = indicator.findViewById(R.id.tab_mes);
            mBvNotice = new BadgeView(MainActivity.this, cn);
            mBvNotice.setBadgePosition(BadgeView.POSITION_TOP_RIGHT);
            mBvNotice.setTextSize(TypedValue.COMPLEX_UNIT_SP, 10);
            mBvNotice.setBackgroundResource(R.drawable.notification_bg);
            mBvNotice.setGravity(Gravity.CENTER);
        }
        mTabHost.getTabWidget().getChildAt(i).setOnTouchListener(this);
    }
}

From source file:ab.util.AbDialogUtil.java

/**
 * ?()
 * 
 * @param view
 */
public static AbSampleDialogFragment showPanel(View view) {
    return showPanel(view, Gravity.CENTER);
}