List of usage examples for android.view Gravity CENTER_HORIZONTAL
int CENTER_HORIZONTAL
To view the source code for android.view Gravity CENTER_HORIZONTAL.
Click Source Link
From source file:pl.bcichecki.rms.client.android.dialogs.RemindPasswordDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { context = getActivity();// w w w .j a v a2 s. c o m AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(getString(R.string.dialog_remind_password_title)); builder.setMessage(getString(R.string.dialog_remind_password_message)); final LinearLayout layout = new LinearLayout(getActivity()); layout.setOrientation(LinearLayout.VERTICAL); layout.setGravity(Gravity.CENTER_HORIZONTAL); int space = (int) AppUtils.convertDpToPixel(getActivity(), 16); layout.setPadding(space, 0, space, 0); final EditText usernameEditText = new EditText(getActivity()); usernameEditText.setHint(getString(R.string.dialog_remind_password_enter_username_hint)); usernameEditText.setMaxLines(1); usernameEditText.setSingleLine(); usernameEditText.setImeOptions(EditorInfo.IME_ACTION_DONE); usernameEditText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { usernameEditText.setError(null); } }); layout.addView(usernameEditText); builder.setView(layout); builder.setPositiveButton(getString(R.string.dialog_remind_password_ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int whichButton) { return; } }); builder.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { return; } }); builder.setCancelable(false); final AlertDialog dialog = builder.create(); dialog.setOnShowListener(new DialogInterface.OnShowListener() { @Override public void onShow(DialogInterface dialogInterface) { utilitiesRestClient = new UtilitiesRestClient(getActivity(), SharedPreferencesWrapper.getServerAddress(), SharedPreferencesWrapper.getServerPort(), SharedPreferencesWrapper.getWebserviceContextPath()); final Button positiveButton = dialog.getButton(DialogInterface.BUTTON_POSITIVE); positiveButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!AppUtils.checkInternetConnection(getActivity())) { Log.d(TAG, "There is NO network connected!"); return; } usernameEditText.setError(null); if (StringUtils.isBlank(usernameEditText.getText().toString())) { usernameEditText.setError(getString(R.string.dialog_remind_password_field_required)); return; } final String username = usernameEditText.getText().toString(); utilitiesRestClient.forgotPassword(username, new AsyncHttpResponseHandler() { @Override public void onFailure(Throwable error, String content) { Log.d(TAG, "Reminding password failed. [error=" + error + ", content=" + content + "]"); AppUtils.showCenteredToast(context, getString(R.string.dialog_remind_password_recovery_failed), Toast.LENGTH_LONG); } @Override public void onFinish() { positiveButton.setEnabled(true); } @Override public void onStart() { Log.d(TAG, "Reminding password for user: " + username); AppUtils.showCenteredToast(context, getString(R.string.dialog_remind_password_recovery_in_progress), Toast.LENGTH_SHORT); positiveButton.setEnabled(false); } @Override public void onSuccess(int statusCode, String content) { Log.d(TAG, "Reminding password success."); AppUtils.showCenteredToast(context, getString(R.string.dialog_remind_password_recovery_successful), Toast.LENGTH_SHORT); dialog.dismiss(); } }); } }); final Button negativeButton = dialog.getButton(DialogInterface.BUTTON_NEGATIVE); negativeButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { cancelRequests(); dialog.dismiss(); } }); } }); return dialog; }
From source file:de.vanita5.twittnuker.view.ProfileImageBannerLayout.java
public ProfileImageBannerLayout(final Context context, final AttributeSet attrs, final int defStyle) { super(context, attrs, defStyle); mBorderWidth = (int) (getResources().getDisplayMetrics().density * 2); mProfileBannerImageView = new ProfileBannerImageView(context); mProfileBannerImageView.setId(VIEW_ID_PROFILE_BANNER); addView(mProfileBannerImageView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); mProfileImageView = new ProfileImageViewInternal(context, mBorderWidth); mProfileImageView.setId(VIEW_ID_PROFILE_IMAGE); addView(mProfileImageView,// w w w.java2 s . com new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL)); }
From source file:am.project.x.business.drawables.combinationdrawable.CombinationDrawableActivity.java
@SuppressLint("RtlHardcoded") @Override/* w w w .j a v a 2 s . c om*/ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { switch (position) { default: case 0: drawable.setGravity(Gravity.CENTER); break; case 1: drawable.setGravity(Gravity.LEFT); break; case 2: drawable.setGravity(Gravity.CENTER_HORIZONTAL); break; case 3: drawable.setGravity(Gravity.RIGHT); break; case 4: drawable.setGravity(Gravity.CENTER_VERTICAL); break; case 5: drawable.setGravity(Gravity.CENTER_VERTICAL | Gravity.RIGHT); break; case 6: drawable.setGravity(Gravity.BOTTOM); break; case 7: drawable.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL); break; case 8: drawable.setGravity(Gravity.BOTTOM | Gravity.RIGHT); break; } }
From source file:com.example.android.swiperefreshlistfragment.tests.SampleTests.java
/** * Test that swiping on the populated list triggers a refresh. */// w w w . j av a 2s . co m public void testSwipingListView() { // Given a SwipeRefreshLayout which is displaying a populated list // When the swipe refresh layout is dragged TouchUtils.dragViewBy(this, mSwipeRefreshLayout, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, Math.round(mSwipeRefreshLayout.getHeight() * 0.4f)); // Then the SwipeRefreshLayout should be refreshing // We need to use runOnMainSync here as fake dragging uses waitForIdleSync() getInstrumentation().runOnMainSync(new Runnable() { @Override public void run() { assertTrue(mSwipeRefreshLayout.isRefreshing()); } }); }
From source file:com.bt.download.android.gui.util.UIUtils.java
public static void showToastMessage(Context context, String message, int duration, int gravity, int xOffset, int yOffset) { if (context != null && message != null) { Toast toast = Toast.makeText(context, message, duration); if (gravity != (Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM)) { toast.setGravity(gravity, xOffset, yOffset); }//from w ww .j av a2s.co m toast.show(); } }
From source file:am.project.x.business.drawables.linedrawable.LineDrawableActivity.java
@SuppressLint("RtlHardcoded") @Override/*from ww w . j av a 2 s . c om*/ public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { switch (position) { default: case 0: drawable.setGravity(Gravity.BOTTOM); break; case 1: drawable.setGravity(Gravity.LEFT); break; case 2: drawable.setGravity(Gravity.TOP); break; case 3: drawable.setGravity(Gravity.RIGHT); break; case 4: drawable.setGravity(Gravity.CENTER_HORIZONTAL); break; case 5: drawable.setGravity(Gravity.CENTER_VERTICAL); break; case 6: drawable.setGravity(Gravity.TOP | Gravity.BOTTOM); break; case 7: drawable.setGravity(Gravity.LEFT | Gravity.RIGHT); break; } }
From source file:com.iwork.ui.view.SlidingTabLayout.java
public SlidingTabLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // Disable the Scroll Bar setHorizontalScrollBarEnabled(false); // Make sure that the Tab Strips fills this View setFillViewport(true);/* w ww . j a v a 2 s. c o m*/ mTitleOffset = (int) (TITLE_OFFSET_DIPS * getResources().getDisplayMetrics().density); mTabStrip = new SlidingTabStrip(context); mTabStrip.setGravity(Gravity.CENTER_HORIZONTAL); addView(mTabStrip, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); }
From source file:com.google.android.apps.dashclock.configuration.ConfigureAppearanceFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime); final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getActivity()); ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_configure_appearance, container, false); mCurrentStyleNames.put(AppearanceConfig.PREF_STYLE_TIME, sp.getString(AppearanceConfig.PREF_STYLE_TIME, AppearanceConfig.TIME_STYLE_NAMES[0])); configureStylePager((ViewPager) rootView.findViewById(R.id.pager_time_style), (PagerPositionStrip) rootView.findViewById(R.id.pager_time_position_strip), AppearanceConfig.TIME_STYLE_NAMES, AppearanceConfig.COMPONENT_TIME, Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, AppearanceConfig.PREF_STYLE_TIME); mCurrentStyleNames.put(AppearanceConfig.PREF_STYLE_DATE, sp.getString(AppearanceConfig.PREF_STYLE_DATE, AppearanceConfig.DATE_STYLE_NAMES[0])); configureStylePager((ViewPager) rootView.findViewById(R.id.pager_date_style), (PagerPositionStrip) rootView.findViewById(R.id.pager_date_position_strip), AppearanceConfig.DATE_STYLE_NAMES, AppearanceConfig.COMPONENT_DATE, Gravity.CENTER_HORIZONTAL | Gravity.TOP, AppearanceConfig.PREF_STYLE_DATE); ((ConfigurationActivity) getActivity()).showWallpaper(); mAppearanceContainerView = rootView.findViewById(R.id.appearance_container); if (savedInstanceState == null) { getChildFragmentManager().beginTransaction() .add(R.id.appearance_more_container, new ConfigureAppearanceMoreFragment()).commit(); }//from w w w.ja va2s.c om return rootView; }
From source file:com.tiancaicc.springfloatingactionmenu.MenuItemView.java
private void init(Context context, boolean hasMargin) { Resources resources = getResources(); int diameterPX = Utils.dpToPx(mMenuItem.getDiameter(), resources); this.mDiameter = diameterPX; mBtn = new ImageButton(context); mBtn.setScaleType(ImageView.ScaleType.FIT_CENTER); if (hasMargin) { int p = Util.dpToPx(12, getResources()); mBtn.setPadding(p, p, p, p);//ww w . j a v a 2s . c om } LayoutParams btnLp = new LayoutParams(diameterPX, diameterPX); btnLp.gravity = Gravity.CENTER_HORIZONTAL; btnLp.bottomMargin = Util.dpToPx(mGapSize, resources); mBtn.setLayoutParams(btnLp); OvalShape ovalShape = new OvalShape(); ShapeDrawable shapeDrawable = new ShapeDrawable(ovalShape); shapeDrawable.getPaint().setColor(resources.getColor(mMenuItem.getBgColor())); mBtn.setBackgroundDrawable(shapeDrawable); if (TextUtils.isEmpty(mMenuItem.getIconFilePath())) { mBtn.setImageResource(mMenuItem.getIcon()); } else { mBtn.setImageURI(Uri.fromFile(new File(mMenuItem.getIconFilePath()))); } mBtn.setClickable(false); addView(mBtn); mLabel = (com.github.omadahealth.typefaceview.TypefaceTextView) View.inflate(getContext(), R.layout.c_text_view, null); mLabel.setPaintFlags(mLabel.getPaintFlags() | Paint.UNDERLINE_TEXT_FLAG); mLabel.setTextIsSelectable(false); LayoutParams labelLp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); labelLp.gravity = Gravity.CENTER_HORIZONTAL; mLabel.setLayoutParams(labelLp); if (!TextUtils.isEmpty(mMenuItem.getLabel())) { mLabel.setPadding(0, Util.dpToPx(70, getResources()), 0, 0); Drawable bottomArrow = ContextCompat.getDrawable(getContext(), R.drawable.ic_arrow); mLabel.setCompoundDrawablesWithIntrinsicBounds(null, null, null, bottomArrow); } mLabel.setText(mMenuItem.getLabel()); mLabel.setTextColor(resources.getColor(mMenuItem.getTextColor())); // mLabel.setTextSize(TypedValue.COMPLEX_UNIT_SP, mTextSize); addView(mLabel); setOrientation(LinearLayout.VERTICAL); if (mAlphaAnimation) { setAlpha(0); } getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { getViewTreeObserver().removeGlobalOnLayoutListener(this); applyPressAnimation(); ViewGroup parent = (ViewGroup) getParent(); parent.setClipChildren(false); parent.setClipToPadding(false); setClipChildren(false); setClipToPadding(false); } }); }
From source file:se.johan.wendler.ui.view.DragGripView.java
@Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); float drawWidth = HORIZ_RIDGES * (mRidgeSize + mRidgeGap) - mRidgeGap; float drawLeft; switch (Gravity.getAbsoluteGravity(mGravity, ViewCompat.getLayoutDirection(this)) & Gravity.HORIZONTAL_GRAVITY_MASK) { case Gravity.CENTER_HORIZONTAL: drawLeft = getPaddingLeft() + ((mWidth - getPaddingLeft() - getPaddingRight()) - drawWidth) / 2; break;//w w w . ja v a2 s. c om case GravityCompat.END: drawLeft = getWidth() - getPaddingRight() - drawWidth; break; default: drawLeft = getPaddingLeft(); } int vertRidges = (int) ((mHeight - getPaddingTop() - getPaddingBottom() + mRidgeGap) / (mRidgeSize + mRidgeGap)); float drawHeight = vertRidges * (mRidgeSize + mRidgeGap) - mRidgeGap; float drawTop = getPaddingTop() + ((mHeight - getPaddingTop() - getPaddingBottom()) - drawHeight) / 2; for (int y = 0; y < vertRidges; y++) { for (int x = 0; x < HORIZ_RIDGES; x++) { canvas.drawRect(drawLeft + x * (mRidgeSize + mRidgeGap), drawTop + y * (mRidgeSize + mRidgeGap), drawLeft + x * (mRidgeSize + mRidgeGap) + mRidgeSize, drawTop + y * (mRidgeSize + mRidgeGap) + mRidgeSize, mRidgePaint); } } }