Java Code Examples for android.view.Gravity

The following are top voted examples for showing how to use android.view.Gravity. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: Matrix-Calculator-for-Android   File: ChangeLogActivity.java   View source code 8 votes vote down vote up
private void SetNewContents(int key) {
    if (!Changes(key).equals("null")) {
        CardView.LayoutParams param = new CardView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        CardView card = new CardView(this);
        if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("DARK_THEME_KEY", false))
            card.setCardBackgroundColor(ContextCompat.getColor(this, R.color.DarkcolorPrimary));
        card.setCardElevation(5);
        card.setLayoutParams(param);
        card.setPadding(ConvertTopx(15), ConvertTopx(15), ConvertTopx(15), ConvertTopx(15));
        card.setUseCompatPadding(true);
        TextView changes = new TextView(this);
        changes.setGravity(Gravity.CENTER);
        changes.setPadding(ConvertTopx(5), ConvertTopx(5), ConvertTopx(5), ConvertTopx(5));
        changes.setText(Changes(key));
        changes.setTypeface(Typeface.MONOSPACE);
        if (firebaseRemoteConfig.getBoolean("mark_red") && key == 0)
            changes.setTextColor(Color.RED);
        card.addView(changes);
        layout.addView(card);
    }
    bar.setVisibility(View.GONE);
}
 
Example 2
Project: godlibrary   File: DialogDate.java   View source code 7 votes vote down vote up
public AlertDialog show(Context context) {
    dialog = new AlertDialog.Builder(context).create();
    dialog.show();
    Window window = dialog.getWindow();
    window.setContentView(R.layout.dialog_date_time);
    window.setGravity(Gravity.CENTER);// 此处可以设置dialog显示的位置
    //window.setWindowAnimations(R.style.in_left_out_right_style);
    window.setBackgroundDrawableResource(R.color.transparent);

    datePicker = (DatePicker) window
            .findViewById(R.id.date_time_datePicker1);
    datePicker.setCalendarViewShown(false);
    timePicker = (TimePicker) window.findViewById(R.id.date_time_timePicker);
    but_ok = (Button) window.findViewById(R.id.date_time_but_ok);
    but_ok.setOnClickListener(this);
    return dialog;
}
 
Example 3
Project: AndroidOpen   File: SharedElementFragment1.java   View source code 6 votes vote down vote up
private void addNextFragment(Sample sample, ImageView squareBlue, boolean overlap) {
    SharedElementFragment2 sharedElementFragment2 = SharedElementFragment2.newInstance(sample);

    Slide slideTransition = new Slide(Gravity.RIGHT);
    slideTransition.setDuration(getResources().getInteger(R.integer.anim_duration_medium));

    ChangeBounds changeBoundsTransition = new ChangeBounds();
    changeBoundsTransition.setDuration(getResources().getInteger(R.integer.anim_duration_medium));

    sharedElementFragment2.setEnterTransition(slideTransition);
    sharedElementFragment2.setAllowEnterTransitionOverlap(overlap);
    sharedElementFragment2.setAllowReturnTransitionOverlap(overlap);
    sharedElementFragment2.setSharedElementEnterTransition(changeBoundsTransition);

    getFragmentManager().beginTransaction()
            .replace(R.id.sample2_content, sharedElementFragment2)
            .addToBackStack(null)
            .addSharedElement(squareBlue, getString(R.string.square_blue_name))
            .commit();
}
 
Example 4
Project: cordova-plugin-unswipable-android-status-bar   File: StatusBarOverlay.java   View source code 6 votes vote down vote up
public static void add(Activity activity) {
    WindowManager manager = ((WindowManager) activity
            .getApplicationContext()
            .getSystemService(Context.WINDOW_SERVICE));

    WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
    localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
    localLayoutParams.gravity = Gravity.TOP;
    localLayoutParams.flags =
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
            // Enable the notification to receive touch events
            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
            // Draw over status bar
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;

    localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
    localLayoutParams.height = (int) (50 * activity.getResources().getDisplayMetrics().scaledDensity);
    localLayoutParams.format = PixelFormat.TRANSPARENT;

    StatusBarOverlay view = new StatusBarOverlay(activity);

    manager.addView(view, localLayoutParams);
}
 
Example 5
Project: BannerView   File: BannerView.java   View source code 6 votes vote down vote up
private void handleTypedArray(Context context, AttributeSet attrs) {
    if (attrs == null) {
        return;
    }
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.BannerStyle);
    mIndicatorMargin = typedArray.getDimensionPixelSize(R.styleable.BannerStyle_banner_indicatorMargin, 5);
    mIndicatorSelectedResId = typedArray.getResourceId(R.styleable.BannerStyle_banner_indicatorSelected, R.drawable.indicator_oval_selected);
    mIndicatorUnselectedResId = typedArray.getResourceId(R.styleable.BannerStyle_banner_indicatorUnselected, R.drawable.indicator_oval_unselected);
    mScaleType = typedArray.getInt(R.styleable.BannerStyle_banner_scaleType, mScaleType);
    mDelayTime = typedArray.getInt(R.styleable.BannerStyle_banner_delayTime, 3000);
    mScrollTime = typedArray.getInt(R.styleable.BannerStyle_banner_scrollTime, 800);
    isAutoPlay = typedArray.getBoolean(R.styleable.BannerStyle_banner_isAutoPlay, true);
    mTitleBackground = typedArray.getColor(R.styleable.BannerStyle_banner_titleBackground, -1);
    mTitleHeight = typedArray.getDimensionPixelSize(R.styleable.BannerStyle_banner_titleHeight, -1);
    mTitleTextColor = typedArray.getColor(R.styleable.BannerStyle_banner_titleTextColor, -1);
    mTitleTextSize = typedArray.getDimensionPixelSize(R.styleable.BannerStyle_banner_titleTextSize, -1);
    mLayoutResId = typedArray.getResourceId(R.styleable.BannerStyle_banner_layoutId, mLayoutResId);
    mGravity = typedArray.getInt(R.styleable.BannerStyle_banner_indicatorGravity, Gravity.CENTER);

    mBannerStyle = typedArray.getInt(R.styleable.BannerStyle_banner_indicatorType, BannerStyle.CIRCLE_INDICATOR);
    typedArray.recycle();
}
 
Example 6
Project: SmartRefreshLayout   File: FalsifyHeader.java   View source code 6 votes vote down vote up
@Override
@SuppressLint({"DrawAllocation", "SetTextI18n"})
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (isInEditMode()) {//这段代码在运行时不会执行,只会在Studio编辑预览时运行,不用在意性能问题
        int d = DensityUtil.dp2px(5);

        Paint paint = new Paint();
        paint.setStyle(Paint.Style.STROKE);
        paint.setColor(0x44ffffff);
        paint.setStrokeWidth(DensityUtil.dp2px(1));
        paint.setPathEffect(new DashPathEffect(new float[]{d, d, d, d}, 1));
        canvas.drawRect(d, d, getWidth() - d, getBottom() - d, paint);

        TextView textView = new TextView(getContext());
        textView.setText(getClass().getSimpleName()+" 虚假区域\n运行时代表下拉Header的高度【" + DensityUtil.px2dp(getHeight()) + "dp】\n而不会显示任何东西");
        textView.setTextColor(0x44ffffff);
        textView.setGravity(Gravity.CENTER);
        textView.measure(makeMeasureSpec(getWidth(), EXACTLY), makeMeasureSpec(getHeight(), EXACTLY));
        textView.layout(0, 0, getWidth(), getHeight());
        textView.draw(canvas);
    }
}
 
Example 7
Project: GitHub   File: GravityDelegate.java   View source code 6 votes vote down vote up
public int[] calculateDistanceToFinalSnap(@NonNull RecyclerView.LayoutManager layoutManager,
                                          @NonNull View targetView) {
    int[] out = new int[2];

    if (layoutManager.canScrollHorizontally()) {
        if (gravity == Gravity.START) {
            out[0] = distanceToStart(targetView, getHorizontalHelper(layoutManager), false);
        } else { // END
            out[0] = distanceToEnd(targetView, getHorizontalHelper(layoutManager), false);
        }
    } else {
        out[0] = 0;
    }

    if (layoutManager.canScrollVertically()) {
        if (gravity == Gravity.TOP) {
            out[1] = distanceToStart(targetView, getVerticalHelper(layoutManager), false);
        } else { // BOTTOM
            out[1] = distanceToEnd(targetView, getVerticalHelper(layoutManager), false);
        }
    } else {
        out[1] = 0;
    }

    return out;
}
 
Example 8
Project: QiangHongBao   File: BottomBarTab.java   View source code 6 votes vote down vote up
void prepareLayout() {
    int layoutResource;

    layoutResource = getLayoutResource();

    inflate(getContext(), layoutResource, this);
    setOrientation(VERTICAL);
    setGravity(Gravity.CENTER_HORIZONTAL);
    setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

    iconView = (AppCompatImageView) findViewById(R.id.bb_bottom_bar_icon);
    iconView.setImageResource(iconResId);

    if (type != Type.TABLET) {
        titleView = (TextView) findViewById(R.id.bb_bottom_bar_title);
        titleView.setText(title);
    }

    updateCustomTextAppearance();
    updateCustomTypeface();
}
 
Example 9
Project: Coder   File: ImmersionBar.java   View source code 6 votes vote down vote up
/**
 * 设置一个可以自定义颜色的状态栏
 */
private void setupStatusBarView() {
    if (mBarParams.statusBarView == null) {
        mBarParams.statusBarView = new View(mActivity);
    }
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, getStatusBarHeight(mActivity));
    params.gravity = Gravity.TOP;
    if (!isNavigationAtBottom(mActivity)) {
        params.rightMargin = getNavigationBarWidth(mActivity);
    }
    mBarParams.statusBarView.setLayoutParams(params);
    mBarParams.statusBarView.setBackgroundColor(ColorUtils.blendARGB(mBarParams.statusBarColor,
            mBarParams.statusBarColorTransform, mBarParams.statusBarAlpha));
    mBarParams.statusBarView.setVisibility(View.VISIBLE);
    ViewGroup viewGroup = (ViewGroup) mBarParams.statusBarView.getParent();
    if (viewGroup != null)
        viewGroup.removeView(mBarParams.statusBarView);
    mViewGroup.addView(mBarParams.statusBarView);
}
 
Example 10
Project: AnimationWrapLayout   File: MainActivity.java   View source code 6 votes vote down vote up
private TextView inflateTextView() {
    GradientDrawable shape = new GradientDrawable();
    shape.setCornerRadius(8);
    shape.setColor(0xff000000 | mRandom.nextInt(0x00ffffff));
    TextView textView = new TextView(this);
    textView.setGravity(Gravity.CENTER);
    textView.setTextColor(Color.WHITE);
    textView.setWidth(150 + mRandom.nextInt(3) * 50);
    textView.setHeight(150 + mRandom.nextInt(3) * 50);
    textView.setTextSize(32);
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
        textView.setBackgroundDrawable(shape);
    } else {
        textView.setBackground(shape);
    }
    textView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View view) {
            mList.removeViewWithAnimation(view);
        }
    });
    textView.setText(String.format(Locale.JAPAN, "%1$02d", mCounter++));
    return textView;
}
 
Example 11
Project: MedicationReminder   File: SwipeMenuView.java   View source code 6 votes vote down vote up
private void addItem(SwipeMenuItem item, int id) {
	LayoutParams params = new LayoutParams(item.getWidth(),
			LayoutParams.MATCH_PARENT);
	LinearLayout parent = new LinearLayout(getContext());
	parent.setId(id);
	parent.setGravity(Gravity.CENTER);
	parent.setOrientation(LinearLayout.VERTICAL);
	parent.setLayoutParams(params);
	parent.setBackgroundDrawable(item.getBackground());
	parent.setOnClickListener(this);
	addView(parent);

	if (item.getIcon() != null) {
		parent.addView(createIcon(item));
	}
	if (!TextUtils.isEmpty(item.getTitle())) {
		parent.addView(createTitle(item));
	}

}
 
Example 12
Project: superglue   File: DebugDrawerLayout.java   View source code 6 votes vote down vote up
@Override
public void onViewPositionChanged(View changedView, int left, int top, int dx, int dy) {
  float offset;
  final int childWidth = changedView.getWidth();

  // This reverses the positioning shown in onLayout.
  if (checkDrawerViewAbsoluteGravity(changedView, Gravity.LEFT)) {
    offset = (float) (childWidth + left) / childWidth;
  } else {
    final int width = getWidth();
    offset = (float) (width - left) / childWidth;
  }
  setDrawerViewOffset(changedView, offset);
  changedView.setVisibility(offset == 0 ? INVISIBLE : VISIBLE);
  invalidate();
}
 
Example 13
Project: go-jay   File: ToastProgress.java   View source code 6 votes vote down vote up
public ToastProgress(android.content.Context context) {
	super(context);
	this.ctx=context;
	this.h=new Handler();
	this.h2=new Handler();
	root = new LinearLayout(ctx);
	root.setPadding((int)dp2px(ctx, 20), (int)dp2px(ctx, 10), (int)dp2px(ctx, 20), (int)dp2px(ctx, 10));
	root.setOrientation(LinearLayout.HORIZONTAL);
	prog=new ProgressBar(ctx);
	prog.setLayoutParams(new LinearLayout.LayoutParams((int)dp2px(ctx, 20), (int)dp2px(ctx, 20)));
	root.addView(prog);
	clt=new TextView(ctx);
	clt.setTextSize(14);
	clt.setTextColor(Color.WHITE);
	LinearLayout.LayoutParams tlp=new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
	tlp.gravity=Gravity.CENTER_VERTICAL;
	tlp.setMargins((int)dp2px(ctx,10),0,0,0);
	clt.setLayoutParams(tlp);
	root.addView(clt);
	shape = new GradientDrawable();
	shape.setShape(GradientDrawable.RECTANGLE);
}
 
Example 14
Project: LaunchEnr   File: NotificationFooterLayout.java   View source code 6 votes vote down vote up
public NotificationFooterLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    Resources res = getResources();
    mRtl = Utilities.isRtl(res);

    int iconSize = res.getDimensionPixelSize(R.dimen.notification_footer_icon_size);
    mIconLayoutParams = new LayoutParams(iconSize, iconSize);
    mIconLayoutParams.gravity = Gravity.CENTER_VERTICAL;
    // Compute margin start for each icon such that the icons between the first one
    // and the ellipsis are evenly spaced out.
    int paddingEnd = res.getDimensionPixelSize(R.dimen.notification_footer_icon_row_padding);
    int ellipsisSpace = res.getDimensionPixelSize(R.dimen.horizontal_ellipsis_offset)
            + res.getDimensionPixelSize(R.dimen.horizontal_ellipsis_size);
    int footerWidth = res.getDimensionPixelSize(R.dimen.bg_popup_item_width);
    int availableIconRowSpace = footerWidth - paddingEnd - ellipsisSpace
            - iconSize * MAX_FOOTER_NOTIFICATIONS;
    mIconLayoutParams.setMarginStart(availableIconRowSpace / MAX_FOOTER_NOTIFICATIONS);
}
 
Example 15
Project: decoy   File: MsgViewHolderAudio.java   View source code 6 votes vote down vote up
private void layoutByDirection() {
    if (isReceivedMessage()) {
        setGravity(animationView, Gravity.LEFT | Gravity.CENTER_VERTICAL);
        setGravity(durationLabel, Gravity.RIGHT | Gravity.CENTER_VERTICAL);

        containerView.setBackgroundResource(R.drawable.nim_message_item_left_selector);
        containerView.setPadding(ScreenUtil.dip2px(15), ScreenUtil.dip2px(8), ScreenUtil.dip2px(10), ScreenUtil.dip2px(8));
        animationView.setBackgroundResource(R.drawable.nim_audio_animation_list_left);
        durationLabel.setTextColor(Color.BLACK);

    } else {
        setGravity(animationView, Gravity.RIGHT | Gravity.CENTER_VERTICAL);
        setGravity(durationLabel, Gravity.LEFT | Gravity.CENTER_VERTICAL);
        unreadIndicator.setVisibility(View.GONE);

        containerView.setBackgroundResource(R.drawable.nim_message_item_right_selector);
        containerView.setPadding(ScreenUtil.dip2px(10), ScreenUtil.dip2px(8), ScreenUtil.dip2px(15), ScreenUtil.dip2px(8));
        animationView.setBackgroundResource(R.drawable.nim_audio_animation_list_right);
        durationLabel.setTextColor(Color.WHITE);
    }
}
 
Example 16
Project: FlickLauncher   File: Utilities.java   View source code 6 votes vote down vote up
public static void aboutAlertDialog(Context context)
{
    AlertDialog builder =
            new AlertDialog.Builder(context, R.style.AlertDialogCustom).setTitle(context.getResources().getString(R.string.app_name))
                    .setCancelable(false)
                    .setIcon(R.mipmap.ic_launcher_home)
                    .setMessage(R.string.disclaimer_dialog_message)
                    .setPositiveButton(context.getResources().getString(R.string.ok), new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int id) {
                            dialog.dismiss();
                        }
                    }).create();
    builder.show();
    ((TextView)builder.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
    ((TextView)builder.findViewById(android.R.id.message)).setGravity(Gravity.CENTER_VERTICAL);
    builder.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
}
 
Example 17
Project: SearchLayout   File: FlowSearchLayout.java   View source code 6 votes vote down vote up
private void initHistoryData(List<String> allNames) {
    int padding = (int) (DensityUtil.dip2px(10f) * DensityUtil.getBaseScale(getContext()));
    TagAdapter adapter = new TagAdapter<String>(allNames) {
        @Override
        public View getView(FlowLayout parent, int position, String s) {
            TextView textView = new TextView(getContext());
            textView.setLayoutParams(new RadioGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            textView.setWidth((int) (DensityUtil.dip2px(80f) * DensityUtil.getBaseScale(getContext())));
            textView.setLines(1);
            textView.setGravity(Gravity.CENTER);
            textView.setEllipsize(TextUtils.TruncateAt.END);
            textView.setPadding(padding, padding, padding, padding);
            textView.setText(s);
            return textView;
        }
    };
    mBinding.flowLayoutHistory.setAdapter(adapter);
    mBinding.flowLayoutHistory.setOnTagClickListener((view, position, parent) -> {
        String item = (String) adapter.getItem(position);
        return false;
    });
}
 
Example 18
Project: airgram   File: ChatAttachAlert.java   View source code 6 votes vote down vote up
public AttachButton(Context context) {
    super(context);

    imageView = new ImageView(context);
    imageView.setScaleType(ImageView.ScaleType.CENTER);
    addView(imageView, LayoutHelper.createFrame(64, 64, Gravity.CENTER_HORIZONTAL | Gravity.TOP));

    textView = new TextView(context);
    textView.setTypeface(FontManager.instance().getTypeface());
    textView.setLines(1);
    textView.setSingleLine(true);
    textView.setGravity(Gravity.CENTER_HORIZONTAL);
    textView.setEllipsize(TextUtils.TruncateAt.END);
    textView.setTextColor(Theme.ATTACH_SHEET_TEXT_COLOR);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
    addView(textView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 0, 64, 0, 0));
}
 
Example 19
Project: FastTextView   File: TextViewAttrsHelper.java   View source code 6 votes vote down vote up
private static Layout.Alignment getAlignmentByGravity(int gravity) {
  switch (gravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) {
    case Gravity.START:
      return Layout.Alignment.ALIGN_NORMAL;
    case Gravity.END:
      return Layout.Alignment.ALIGN_OPPOSITE;
    case Gravity.LEFT:
      return Layout.Alignment.ALIGN_LEFT;
    case Gravity.RIGHT:
      return Layout.Alignment.ALIGN_RIGHT;
    case Gravity.CENTER_HORIZONTAL:
      return Layout.Alignment.ALIGN_CENTER;
    default:
      return Layout.Alignment.ALIGN_NORMAL;
  }
}
 
Example 20
Project: RFID-Attendance   File: MainActivity.java   View source code 6 votes vote down vote up
/**
 * Display a checkmark toast to notify the user of a successful scan
 */
private void showCheckmarkToast(){
    // Inflate the toast layout
    LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.toast_checkmark,
            (ViewGroup) findViewById(R.id.toast_layout_root));
    TextView text = (TextView) layout.findViewById(R.id.toast_text);
    text.setText(R.string.scan_successful);

    // Create the toast
    Toast toast = new Toast(getApplicationContext());
    toast.setGravity(Gravity.CENTER_HORIZONTAL, 0, 0);
    toast.setDuration(Toast.LENGTH_SHORT);
    toast.setView(layout);
    toast.show();
}
 
Example 21
Project: android-stepsview   File: StepsView.java   View source code 6 votes vote down vote up
private void drawLabels() {
    List<Float> indicatorPosition = mStepsViewIndicator.getThumbContainerXPosition();

    if (mLabels != null) {
        for (int i = 0; i < mLabels.length; i++) {
            TextView textView = new TextView(getContext());
            textView.setText(mLabels[i]);
            textView.setTextColor(mLabelColorIndicator);
            textView.setTextSize(mLabelTextSize);
            textView.setGravity(Gravity.CENTER);
            textView.setLayoutParams(
                    new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                            ViewGroup.LayoutParams.WRAP_CONTENT));
            textView.measure(0, 0);
            float textWidth = textView.getMeasuredWidth();
            textView.setX(indicatorPosition.get(i) - (textWidth / 2));

            mLabelsLayout.addView(textView);
        }
    }
}
 
Example 22
Project: sctalk   File: YayaEmoGridView.java   View source code 6 votes vote down vote up
private void initViewPage() {
    setOrientation(VERTICAL);
    _viewPager = new ViewPager(_context);
    _llDot = new LinearLayout(_context);

    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,
            CommonUtil.getDefaultPannelHeight(_context));
    params.gravity=Gravity.BOTTOM;
    _viewPager.setLayoutParams(params);
    _llDot.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT));
    _llDot.setGravity(Gravity.CENTER);
    _llDot.setOrientation(HORIZONTAL);
    addView(_viewPager);
    addView(_llDot);
}
 
Example 23
Project: SmartButler   File: UserFragment.java   View source code 6 votes vote down vote up
private void showDialogForAvatarOrDismiss(boolean showOrNotShow)
{
    if (showOrNotShow)
    {
        avatarClickDialog = new Dialog(getActivity(), R.style.Theme_Light_Dialog);
        dialogView = LayoutInflater.from(getActivity()).inflate(R.layout.layout_dialog,null);
        //获得dialog的window窗口
        Window window = avatarClickDialog.getWindow();
        //设置dialog在屏幕底部
        window.setGravity(Gravity.BOTTOM);
        //设置dialog弹出时的动画效果,从屏幕底部向上弹出
        window.setWindowAnimations(R.style.dialogStyle);
        window.getDecorView().setPadding(0, 0, 0, 0);
        //获得window窗口的属性
        android.view.WindowManager.LayoutParams lp = window.getAttributes();
        //设置窗口宽度为充满全屏
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        //设置窗口高度为包裹内容
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        //将设置好的属性set回去
        window.setAttributes(lp);
        //将自定义布局加载到dialog上
        avatarClickDialog.setContentView(dialogView);
        //初始化Button
        btn_camera= (Button) dialogView.findViewById(R.id.btn_camera);
        btn_album= (Button) dialogView.findViewById(R.id.btn_album);
        btn_cancel= (Button) dialogView.findViewById(R.id.btn_cancel);
        //监听Button
        btn_camera.setOnClickListener(this);
        btn_album.setOnClickListener(this);
        btn_cancel.setOnClickListener(this);
        avatarClickDialog.show();
    }
    else
    {
        avatarClickDialog.dismiss();
    }
}
 
Example 24
Project: Remindy   File: PlaceActivity.java   View source code 6 votes vote down vote up
private void setAliasAndAddress(String alias, String address) {
    //Save alias and address
    mPlace.setAlias(alias);
    mPlace.setAddress(address);

    if(!mAliasAddressAlreadySet) {
        TransitionManager.beginDelayedTransition(mMapContainer, new Slide(Gravity.BOTTOM));
        mAlias.setText(alias);
        mAddress.setText(address);
        mAliasAddressContainer.setVisibility(View.VISIBLE);
        mAliasAddressAlreadySet = true;

    } else {
        //TransitionManager.beginDelayedTransition(mMapContainer, new ChangeText().setChangeBehavior(ChangeText.CHANGE_BEHAVIOR_OUT_IN));
        mAlias.setText(alias);
        mAddress.setText(address);
    }
}
 
Example 25
Project: qmui   File: QMUITopBar.java   View source code 6 votes vote down vote up
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    super.onLayout(changed, l, t, r, b);
    if (mTitleContainerView != null) {
        int titleContainerViewWidth = mTitleContainerView.getMeasuredWidth();
        int titleContainerViewHeight = mTitleContainerView.getMeasuredHeight();
        int titleContainerViewTop = (b - t - mTitleContainerView.getMeasuredHeight()) / 2;
        int titleContainerViewLeft = getPaddingLeft();
        if ((mTitleGravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.CENTER_HORIZONTAL) {
            // 标题水平居中
            titleContainerViewLeft = (r - l - mTitleContainerView.getMeasuredWidth()) / 2;
        } else {
            // 标题非水平居中
            // 计算左侧 View 的总宽度
            for (int leftViewIndex = 0; leftViewIndex < mLeftViewList.size(); leftViewIndex++) {
                View view = mLeftViewList.get(leftViewIndex);
                if (view.getVisibility() != GONE) {
                    titleContainerViewLeft += view.getMeasuredWidth();
                }
            }
        }
        mTitleContainerView.layout(titleContainerViewLeft, titleContainerViewTop, titleContainerViewLeft + titleContainerViewWidth, titleContainerViewTop + titleContainerViewHeight);
    }
}
 
Example 26
Project: QSVideoPlayer   File: DemoQSVideoView.java   View source code 6 votes vote down vote up
@Override
protected boolean showVolumeDialog(int nowVolume, int maxVolume) {

    if (mVolumeDialog == null) {
        View localView = LayoutInflater.from(getContext()).inflate(R.layout.jc_dialog_volume, null);
        mDialogVolumeImageView = ((ImageView) localView.findViewById(R.id.volume_image_tip));
        mDialogVolumeTextView = ((TextView) localView.findViewById(R.id.tv_volume));
        mDialogVolumeProgressBar = ((ProgressBar) localView.findViewById(R.id.volume_progressbar));
        mDialogVolumeProgressBar.setMax(maxVolume);
        mVolumeDialog = getPopupWindow(localView);
    }
    if (!mVolumeDialog.isShowing())
        mVolumeDialog.showAtLocation(this, Gravity.TOP, 0, Util.dp2px(getContext(), 50));

    mDialogVolumeTextView.setText(nowVolume + "");
    mDialogVolumeProgressBar.setProgress(nowVolume);
    return true;
}
 
Example 27
Project: OSchina_resources_android   File: KJDragGridView.java   View source code 6 votes vote down vote up
/**
 * 创建拖动的镜像
 *
 * @param bitmap
 * @param downX  按下的点相对父控件的X坐标
 * @param downY  按下的点相对父控件的X坐标
 */
private void createDragImage(Bitmap bitmap, int downX, int downY) {
    mWindowLayoutParams = new WindowManager.LayoutParams();
    mWindowLayoutParams.format = PixelFormat.TRANSLUCENT; // 图片之外的其他地方透明

    mWindowLayoutParams.gravity = Gravity.TOP | Gravity.LEFT;
    mWindowLayoutParams.x = downX - mPoint2ItemLeft + mOffset2Left;
    mWindowLayoutParams.y = downY - mPoint2ItemTop + mOffset2Top
            - mStatusHeight;
    mWindowLayoutParams.alpha = 0.55f; // 透明度

    mWindowLayoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
    mWindowLayoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
    mWindowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
            | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;

    mDragImageView = new ImageView(getContext());
    mDragImageView.setImageBitmap(bitmap);
    mWindowManager.addView(mDragImageView, mWindowLayoutParams);
}
 
Example 28
Project: EpubReaderAndroid   File: MainActivity.java   View source code 6 votes vote down vote up
private void initToolbar() {
    binding.toolbar.inflateMenu(R.menu.menu);

    binding.toolbar.setOnMenuItemClickListener(item -> {
        switch (item.getItemId()) {
            case R.id.menu_settings:
                if (binding.settings.getVisibility() == View.VISIBLE) {
                    binding.settings.setVisibility(View.GONE);
                } else {
                    binding.settings.setVisibility(View.VISIBLE);
                }
                return true;
            default:
                return false;
        }
    });

    binding.toolbar.setNavigationOnClickListener(v -> {
        binding.drawerLayout.openDrawer(Gravity.START);
    });
}
 
Example 29
Project: GalleryCycleImageView   File: GalleryCycleImageView.java   View source code 6 votes vote down vote up
public void setCount(int count) {
    mCount = count;
    setIndicatorFocusColor(indicatorFocusColor);
    setIndicatorNormalColor(indicatorNormalColor);
    mLinearLayout = new LinearLayout(mContext);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(indicatorSize, indicatorSize);
    layoutParams.gravity = Gravity.CENTER;
    layoutParams.setMargins(densityUtil.dip2px(mContext, 2), densityUtil.dip2px(mContext, 0),
            densityUtil.dip2px(mContext, 2), densityUtil.dip2px(mContext, 0));
    mLinearLayout.setGravity(Gravity.CENTER);
    LayoutParams params = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    params.topMargin = densityUtil.dip2px(mContext, 10);
    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, TRUE);
    params.addRule(RelativeLayout.CENTER_HORIZONTAL, TRUE);
    addView(mLinearLayout, params);

    //动态添加小圆点指示器
    for (int i = 0; i < mCount; i++) {
        //创建一个ImageView用于存放一个小圆点
        ImageView indicatorImage = new ImageView(mContext);
        if (i == 0) {
            //为了兼容,使用setBackgroundDrawable
            indicatorImage.setBackgroundDrawable(indicatorFocus);
        } else {
            indicatorImage.setBackgroundDrawable(indicatorNormal);
        }
        mLinearLayout.addView(indicatorImage, layoutParams);
    }

    ViewPagerAdapter adapter = new ViewPagerAdapter();
    mViewPager.setAdapter(adapter);
    mViewPager.setOffscreenPageLimit(mCount);
    int targetItemPosition = Integer.MAX_VALUE / 2 - Integer.MAX_VALUE / 2 % count;
    mViewPager.setCurrentItem(targetItemPosition);
}
 
Example 30
Project: TK_1701   File: RaderActivity.java   View source code 6 votes vote down vote up
@Override
protected void onRestart() {
    super.onRestart();

    if ( button_AR.isChecked() == true ) {
        // ARを強制終了
        RADER_VALUES.switchARMode( false );
        // カメラ開放
        mCamera.close();
        mCamera = null;
        // 背景差し替え(imageView表示)
        backgroundImageView.setVisibility( backgroundImageView.VISIBLE );
        // AR用メッセージ非表示
        linearLayout_ARMessages.setVisibility( View.GONE );
        // レーダー用メッセージ表示
        linearLayout_raderMessages.setVisibility( View.VISIBLE );

        button_AR.setChecked( false );

        // Toast表示
        Toast toast = Toast.makeText( getApplicationContext(),
                "バックグラウンドから復帰。\nARモードを終了しました。", Toast.LENGTH_SHORT );
        toast.setGravity( Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0 );
        toast.show();
    }
}
 
Example 31
Project: Farmacias   File: SlideInItemAnimator.java   View source code 6 votes vote down vote up
@Override
public boolean animateAdd(RecyclerView.ViewHolder holder) {
    holder.itemView.setAlpha(0f);
    switch (slideFromEdge) {
        case Gravity.LEFT:
            holder.itemView.setTranslationX(-holder.itemView.getWidth() / 3);
            break;
        case Gravity.TOP:
            holder.itemView.setTranslationY(-holder.itemView.getHeight() / 3);
            break;
        case Gravity.RIGHT:
            holder.itemView.setTranslationX(holder.itemView.getWidth() / 3);
            break;
        default: // Gravity.BOTTOM
            holder.itemView.setTranslationY(holder.itemView.getHeight() / 3);
    }
    pendingAdds.add(holder);
    return true;
}
 
Example 32
Project: FreeStreams-TVLauncher   File: AllApp.java   View source code 6 votes vote down vote up
public void managerAppInit()
	{
		View v = LayoutInflater.from(mContext).inflate(R.layout.item_pager_layout, null);
		LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
		params.gravity = Gravity.CENTER;
        int itemCount = -1;
		if(mPagerIndex < mPagerCount - 1)
		{
			itemCount = 15;
		}else
		{
			itemCount = (mAppList.size() - (mPagerCount-1)*15);
		}
		for(int i = 0; i < itemCount; i++)
		{
			appIcons[i] = (ImageView) v.findViewById(iconIds[i]);
			appNames[i] = (TextView)v.findViewById(nameIds[i]);
			appIcons[i].setImageDrawable(mAppList.get(mPagerIndex*15 + i).getIcon());
            appItems[i] = (LinearLayout)v.findViewById(itemIds[i]);
            appNames[i].setText(mAppList.get(mPagerIndex * 15 + i).getName());
            appItems[i].setVisibility(View.VISIBLE);
            appItems[i].setOnClickListener(this);
//            appItems[i].setOnFocusChangeListener(focusChangeListener);
        }
		addView(v);
	}
 
Example 33
Project: Watermark   File: CircleView.java   View source code 6 votes vote down vote up
public void showHint(int color) {
    final int[] screenPos = new int[2];
    final Rect displayFrame = new Rect();
    getLocationOnScreen(screenPos);
    getWindowVisibleDisplayFrame(displayFrame);
    final Context context = getContext();
    final int width = getWidth();
    final int height = getHeight();
    final int midy = screenPos[1] + height / 2;
    int referenceX = screenPos[0] + width / 2;
    if (ViewCompat.getLayoutDirection(this) == ViewCompat.LAYOUT_DIRECTION_LTR) {
        final int screenWidth = context.getResources().getDisplayMetrics().widthPixels;
        referenceX = screenWidth - referenceX; // mirror
    }
    Toast cheatSheet =
            Toast.makeText(context, String.format("#%06X", 0xFFFFFF & color), Toast.LENGTH_SHORT);
    if (midy < displayFrame.height()) {
        // Show along the top; follow action buttons
        cheatSheet.setGravity(
                Gravity.TOP | GravityCompat.END, referenceX, screenPos[1] + height - displayFrame.top);
    } else {
        // Show along the bottom center
        cheatSheet.setGravity(Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, height);
    }
    cheatSheet.show();
}
 
Example 34
Project: QSVideoPlayer   File: DemoQSVideoView.java   View source code 6 votes vote down vote up
@Override
protected boolean showBrightnessDialog(int brightnessPercent, int max) {
    if (mBrightnessDialog == null) {
        View localView = LayoutInflater.from(getContext()).inflate(R.layout.jc_dialog_brightness, null);
        mDialogBrightnessTextView = ((TextView) localView.findViewById(R.id.tv_brightness));
        mDialogBrightnessProgressBar = ((ProgressBar) localView.findViewById(R.id.brightness_progressbar));
        mDialogBrightnessProgressBar.setMax(max);
        //mBrightnessDialog = getDialog(Gravity.TOP, 0, Util.dp2px(getContext(), 50));
        //mBrightnessDialog.setContentView(localView);

        mBrightnessDialog = getPopupWindow(localView);
    }
    if (!mBrightnessDialog.isShowing())
        mBrightnessDialog.showAtLocation(this, Gravity.TOP, 0, Util.dp2px(getContext(), 50));

    mDialogBrightnessTextView.setText(brightnessPercent + "");
    mDialogBrightnessProgressBar.setProgress(brightnessPercent);
    return true;
}
 
Example 35
Project: xlight_android_native   File: DialogTimeActivity.java   View source code 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_dialog);
    getWindow().setGravity(Gravity.BOTTOM);
    getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
    initData();
    initViews();
}
 
Example 36
Project: GitHub   File: Utils.java   View source code 5 votes vote down vote up
public static void showDialog(Context context){
        SelectDialog selectDialog = new SelectDialog(context, R.style.dialog);//创建Dialog并设置样式主题
        Window win = selectDialog.getWindow();
        WindowManager.LayoutParams params = new WindowManager.LayoutParams();
//        params.x = -80;//设置x坐标
//        params.y = -60;//设置y坐标
        params.gravity = Gravity.CENTER;
        win.setAttributes(params);
        selectDialog.setCanceledOnTouchOutside(true);//设置点击Dialog外部任意区域关闭Dialog
        selectDialog.show();

    }
 
Example 37
Project: GitHub   File: PagerSlidingTabStrip.java   View source code 5 votes vote down vote up
private void addTextTab(final int position, String title) {

		TextView tab = new TextView(getContext());
		tab.setText(title);
		tab.setGravity(Gravity.CENTER);
		tab.setSingleLine();

		addTab(position, tab);
	}
 
Example 38
Project: qmui   File: QMUIDialogAction.java   View source code 5 votes vote down vote up
/**
 * 生成适用于对话框的按钮
 */
public static Button generateSpanActionButton(Context context, String text, int iconRes, boolean hasLeftMargin) {
	Button button = new Button(context);
	LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
			ViewGroup.LayoutParams.WRAP_CONTENT,
			QMUIResHelper.getAttrDimen(context, R.attr.qmui_dialog_action_button_height));
	if(hasLeftMargin){
		lp.leftMargin = QMUIResHelper.getAttrDimen(context, R.attr.qmui_dialog_action_button_margin_left);
	}
	button.setLayoutParams(lp);
	button.setMinHeight(QMUIResHelper.getAttrDimen(context, R.attr.qmui_dialog_action_button_height));
	button.setMinWidth(QMUIResHelper.getAttrDimen(context, R.attr.qmui_dialog_action_button_min_width));
	button.setMinimumWidth(QMUIResHelper.getAttrDimen(context, R.attr.qmui_dialog_action_button_min_width));
	button.setMinimumHeight(QMUIResHelper.getAttrDimen(context, R.attr.qmui_dialog_action_button_height));
	button.setText(text);
	if (iconRes != 0) {
		Drawable drawable = context.getResources().getDrawable(iconRes);
		if (drawable != null) {
			drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
			button.setCompoundDrawables(drawable, null, null, null);
			button.setCompoundDrawablePadding(QMUIResHelper.getAttrDimen(context, R.attr.qmui_dialog_action_drawable_padding));
		}

	}
	button.setGravity(Gravity.CENTER);
	button.setClickable(true);
	button.setTextSize(TypedValue.COMPLEX_UNIT_PX, QMUIResHelper.getAttrDimen(context, R.attr.qmui_dialog_action_button_text_size));
	button.setTextColor(QMUIResHelper.getAttrColorStateList(context, R.attr.qmui_dialog_action_text_color));
	button.setBackground(QMUIResHelper.getAttrDrawable(context, R.attr.qmui_dialog_action_btn_bg));
	final int paddingHor = QMUIResHelper.getAttrDimen(context, R.attr.qmui_dialog_action_button_padding_horizontal);
	button.setPadding(paddingHor, 0, paddingHor, 0);
	return button;
}
 
Example 39
Project: BlackList   File: SMSConversationCursorAdapter.java   View source code 5 votes vote down vote up
public SMSConversationCursorAdapter(Context context) {
    super(context, null, 0);
    paddingStart = new Padding(context, Gravity.START, 5, 50);
    paddingEnd = new Padding(context, Gravity.END, 5, 50);

    calendar.setTimeInMillis(System.currentTimeMillis());
    currentYear = calendar.get(Calendar.YEAR);
    currentDay = calendar.get(Calendar.DAY_OF_YEAR);
}
 
Example 40
Project: cniao5   File: PRTHeader.java   View source code 5 votes vote down vote up
public PRTHeader(Context context) {
	super(context);
	int[] size = ResHelper.getScreenSize(context);
	float screenWidth = size[0] < size[1] ? size[0] : size[1];
	float ratio = screenWidth / DESIGN_SCREEN_WIDTH;

	setOrientation(VERTICAL);

	LinearLayout llInner = new LinearLayout(context);
	LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	lp.gravity = Gravity.CENTER_HORIZONTAL;
	addView(llInner, lp);

	ivArrow = new RotateImageView(context);
	int resId = ResHelper.getBitmapRes(context, "ssdk_oks_ptr_ptr");
	if (resId > 0) {
		ivArrow.setImageResource(resId);
	}
	int avatarWidth = (int) (ratio * DESIGN_AVATAR_WIDTH);
	lp = new LayoutParams(avatarWidth, avatarWidth);
	lp.gravity = Gravity.CENTER_VERTICAL;
	int avataPadding = (int) (ratio * DESIGN_AVATAR_PADDING);
	lp.topMargin = lp.bottomMargin = avataPadding;
	llInner.addView(ivArrow, lp);

	pbRefreshing = new ProgressBar(context);
	resId = ResHelper.getBitmapRes(context, "ssdk_oks_classic_progressbar");
	Drawable pbdrawable = context.getResources().getDrawable(resId);
	pbRefreshing.setIndeterminateDrawable(pbdrawable);
	llInner.addView(pbRefreshing, lp);
	pbRefreshing.setVisibility(View.GONE);

	tvHeader = new TextView(getContext());
	tvHeader.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
	tvHeader.setPadding(avataPadding, 0, avataPadding, 0);
	tvHeader.setTextColor(0xff09bb07);
	lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	lp.gravity = Gravity.CENTER_VERTICAL;
	llInner.addView(tvHeader, lp);
}