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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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   Source Code and License 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);
}
 
Example 41
Project: QSRefreshLayout   File: ElemeRefreshView.java   Source Code and License 5 votes vote down vote up
private void popFood() {

        ImageView iv = new ImageView(getContext());
        iv.setImageResource(foods[index]);
        FrameLayout.LayoutParams l = new LayoutParams((int) (30 * density), (int) (30 * density));
        l.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
        iv.setLayoutParams(l);
        popAnime(iv);
        eleme_content.addView(iv, 0);

        index++;
        if (index >= foods.length) index = 0;
    }
 
Example 42
Project: PlusGram   File: PhotoPaintView.java   Source Code and License 5 votes vote down vote up
private void openStickersView() {
    if (stickersView != null && stickersView.getVisibility() == VISIBLE) {
        return;
    }
    pickingSticker = true;

    if (stickersView == null) {
        stickersView = new StickerMasksView(getContext());
        stickersView.setListener(new StickerMasksView.Listener() {
            @Override
            public void onStickerSelected(TLRPC.Document sticker) {
                closeStickersView();
                createSticker(sticker);
            }

            @Override
            public void onTypeChanged() {
                updateStickersTitle();
            }
        });
        addView(stickersView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));
    }

    stickersView.setVisibility(VISIBLE);
    Animator a = ObjectAnimator.ofFloat(stickersView, "alpha", 0.0f, 1.0f);
    a.setDuration(200);
    a.start();

    undoItem.setVisibility(GONE);
    updateStickersTitle();
}
 
Example 43
Project: react-native-udesk   File: MessageAdatper.java   Source Code and License 5 votes vote down vote up
private void showStructBtn(Context context, StructModel structModel, LinearLayout structBtnLineayLayout) {
    try {
        if (structModel.getButtons() != null && structModel.getButtons().size() > 0) {
            structBtnLineayLayout.removeAllViews();
            structBtnLineayLayout.setVisibility(View.VISIBLE);
            List<StructModel.ButtonsBean> buttonsBeens = structModel.getButtons();
            for (int i = 0; i < buttonsBeens.size(); i++) {
                StructModel.ButtonsBean buttonsBean = buttonsBeens.get(i);
                TextView textView = new TextView(context);
                textView.setText(buttonsBean.getText());
                textView.setOnClickListener(new MyStructBtnOnClick(buttonsBean));
                textView.setTextColor(context.getResources().getColor(R.color.udesk_custom_dialog_sure_btn_color));
                textView.setGravity(Gravity.CENTER);
                textView.setPadding(5, 5, 5, 5);
                textView.setTextSize(18);
                LinearLayout.LayoutParams textviewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                        ViewGroup.LayoutParams.WRAP_CONTENT);

                View line = new View(context);
                line.setBackgroundColor(context.getResources().getColor(R.color.udesk_struct_bg_line_color));
                LinearLayout.LayoutParams lineParas = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.FILL_PARENT,
                        1);
                structBtnLineayLayout.addView(textView, textviewParams);
                structBtnLineayLayout.addView(line, lineParas);
            }

        } else {
            structBtnLineayLayout.setVisibility(View.GONE);
        }
    } catch (Resources.NotFoundException e) {
        e.printStackTrace();
    }
}
 
Example 44
Project: superglue   File: DebugDrawerLayout.java   Source Code and License 5 votes vote down vote up
/**
 * @param gravity the gravity of the child to return. If specified as a
 *            relative value, it will be resolved according to the current
 *            layout direction.
 * @return the drawer with the specified gravity
 */
View findDrawerWithGravity(int gravity) {
  final int absHorizGravity = GravityCompat.getAbsoluteGravity(
      gravity, ViewCompat.getLayoutDirection(this)) & Gravity.HORIZONTAL_GRAVITY_MASK;
  final int childCount = getChildCount();
  for (int i = 0; i < childCount; i++) {
    final View child = getChildAt(i);
    final int childAbsGravity = getDrawerViewAbsoluteGravity(child);
    if ((childAbsGravity & Gravity.HORIZONTAL_GRAVITY_MASK) == absHorizGravity) {
      return child;
    }
  }
  return null;
}
 
Example 45
Project: leoapp-sources   File: NumberPickerPreference.java   Source Code and License 5 votes vote down vote up
@Override
protected View onCreateDialogView() {
    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParams.gravity = Gravity.CENTER;
    picker = new NumberPicker(getContext());
    picker.setLayoutParams(layoutParams);
    FrameLayout dialogView = new FrameLayout(getContext());
    dialogView.addView(picker);
    return dialogView;
}
 
Example 46
Project: GCSApp   File: ClearEditText.java   Source Code and License 5 votes vote down vote up
/**
 * 当ClearEditText焦点发生变化的时候,判断里面字符串长度设置清除图标的显示与隐藏
 */
@Override
public void onFocusChange(View v, boolean hasFocus) {
    if (hasFocus) {
        setClearIconVisible(getText().length() > 0);
        this.setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
    } else {
        setClearIconVisible(false);
    }
}
 
Example 47
Project: mvvm-template   File: FontTextView.java   Source Code and License 5 votes vote down vote up
public void setEventsIcon(@DrawableRes int drawableRes) {
    Drawable drawable = ContextCompat.getDrawable(getContext(), drawableRes);
    int width = drawable.getIntrinsicWidth();
    int height = drawable.getIntrinsicHeight();
    drawable.setBounds(0, 0, width / 2, height / 2);
    ScaleDrawable sd = new ScaleDrawable(drawable, Gravity.CENTER, 0.6f, 0.6f);
    sd.setLevel(8000);
    ViewHelper.tintDrawable(drawable, ViewHelper.getTertiaryTextColor(getContext()));
    setCompoundDrawablesWithIntrinsicBounds(sd, null, null, null);
}
 
Example 48
Project: calendarview2   File: WeekDayView.java   Source Code and License 5 votes vote down vote up
public WeekDayView(Context context, int dayOfWeek) {
    super(context);

    setGravity(Gravity.CENTER);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        setTextAlignment(TEXT_ALIGNMENT_CENTER);
    }

    setDayOfWeek(dayOfWeek);
}
 
Example 49
Project: Multi-ColorPicker   File: MultiColorPickerView.java   Source Code and License 5 votes vote down vote up
public Selector addSelector(Drawable drawable, ColorListener colorListener) {
    if(drawable == null || colorListener == null) return null;

    final ImageView selectorImage = new ImageView(getContext());
    selectorImage.setImageDrawable(drawable);

    final Selector selector = new Selector(selectorImage, colorListener);
    LayoutParams thumbParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    thumbParams.gravity = Gravity.CENTER;

    selectorImage.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            switch (motionEvent.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    swapAlpha(selector);
                    mainSelector = selector;

                    Matrix invertMatrix = new Matrix();
                    palette.getImageMatrix().invert(invertMatrix);

                    float[] mappedPoints = new float[]{motionEvent.getX(), motionEvent.getY()};
                    invertMatrix.mapPoints(mappedPoints);

                    MotionEvent event = MotionEvent.obtain(0, 0, MotionEvent.ACTION_DOWN, motionEvent.getX(), motionEvent.getY(), 0);
                    dispatchTouchEvent(event);
                    break;
            }
            return false;
        }
    });

    addView(selector.getSelector(), thumbParams);
    swapAlpha(selector);
    selector.setSelectorListener(selectorListener);
    selector.onMoveCenter();
    selectorList.add(selector);
    mainSelector = selector;
    return selector;
}
 
Example 50
Project: decoy   File: AbstractWheelTextAdapter.java   Source Code and License 5 votes vote down vote up
/**
     * Configures text view. Is called for the TEXT_VIEW_ITEM_RESOURCE views.
     * @param view the text view to be configured
     */
    protected void configureTextView(TextView view) {
        view.setTextColor(textColor);
        view.setGravity(Gravity.CENTER);
        view.setTextSize(textSize);
        view.setEllipsize(TextUtils.TruncateAt.END);
        view.setLines(1);
//        view.setCompoundDrawablePadding(20);
//        view.setTypeface(Typeface.SANS_SERIF, Typeface.BOLD);
    }
 
Example 51
Project: GitHub   File: TestViewPropertiesCase.java   Source Code and License 5 votes vote down vote up
public void testTextGravity() {
    View view = DynamicView.createView(
        context,
        dummyJsonObj
            .addProperty(new DynamicPropertyJsonBuilder().setName(NAME.GRAVITY).setType(TYPE.INTEGER).setValue(17).build())
            .build());
    assertEquals(((TextView)view).getGravity(), 17);

    view = DynamicView.createView(
        context,
        dummyJsonObj
            .addProperty(new DynamicPropertyJsonBuilder().setName(NAME.GRAVITY).setType(TYPE.STRING).setValue("CENTER").build())
            .build());
    assertEquals(((TextView)view).getGravity(), Gravity.CENTER);
}
 
Example 52
Project: decoy   File: PagerSlidingTabStrip.java   Source Code and License 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 53
Project: GitHub   File: BaseQuickAdapter.java   Source Code and License 5 votes vote down vote up
/**
 * 创建进度条 显示在view的结尾
 * @param convertView
 * @param parent
 * @return
 */
private View createIndeterminateProgressView(View convertView, ViewGroup parent) {
    if (convertView == null) {
        FrameLayout container = new FrameLayout(context);
        container.setForegroundGravity(Gravity.CENTER);
        ProgressBar progress = new ProgressBar(context);
        container.addView(progress);
        convertView = container;
    }
    return convertView;
}
 
Example 54
Project: ht-viewpagerwithindicator   File: SlidingTabStrip.java   Source Code and License 5 votes vote down vote up
@Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
//        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        if (mMaxVisibleViewCount <= -1 || mParentWidth < 0) {
            setGravity(Gravity.CENTER);
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            return;
        }
        // 初始化界面时,mMaxVisibleViewCount标示允许可见的tabView的最大数量
        //mMaxVisibleViewCount=-1,tabView宽度为原始宽度;mMaxVisibleViewCount=0,平分屏幕宽度;mMaxVisibleViewCount>0,屏幕宽度N等份;
        final int childCount = getChildCount();
        int measureWidth = 0;//测量的总宽度
        int measureHeight = 0;//测量的最大高度
        if (childCount > 0) {
            if (mMaxVisibleViewCount == 0) {
                mMaxVisibleViewCount = childCount;
            } else if (mMaxVisibleViewCount > 0) {
                mMaxVisibleViewCount = Math.min(mMaxVisibleViewCount, childCount);
            }
            int childWith = mParentWidth / mMaxVisibleViewCount;
            for (int i = 0; i < childCount; i++) {
                View child = getChildAt(i);
                LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) child.getLayoutParams();
                if (child.getVisibility() == GONE) {
                    continue;
                }
                int childWidthMeasureSpec = MeasureSpec.makeMeasureSpec(childWith, MeasureSpec.EXACTLY);
                child.measure(childWidthMeasureSpec, heightMeasureSpec);
                measureWidth += child.getMeasuredWidth() + lp.leftMargin + lp.rightMargin;
                measureHeight = Math.max(measureHeight, child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin);
            }
        }
        setMeasuredDimension(resolveSize(measureWidth, widthMeasureSpec), resolveSize(measureHeight, heightMeasureSpec));
    }
 
Example 55
Project: superglue   File: DebugDrawerLayout.java   Source Code and License 5 votes vote down vote up
@Override
protected void onRestoreInstanceState(Parcelable state) {
  final SavedState ss = (SavedState) state;
  super.onRestoreInstanceState(ss.getSuperState());

  if (ss.openDrawerGravity != Gravity.NO_GRAVITY) {
    final View toOpen = findDrawerWithGravity(ss.openDrawerGravity);
    if (toOpen != null) {
      openDrawer(toOpen);
    }
  }

  setDrawerLockMode(ss.lockModeLeft, Gravity.LEFT);
  setDrawerLockMode(ss.lockModeRight, Gravity.RIGHT);
}
 
Example 56
Project: CustomListView   File: PullToRefreshAdapterViewBase.java   Source Code and License 5 votes vote down vote up
private static FrameLayout.LayoutParams convertEmptyViewLayoutParams(ViewGroup.LayoutParams lp) {
	FrameLayout.LayoutParams newLp = null;

	if (null != lp) {
		newLp = new FrameLayout.LayoutParams(lp);

		if (lp instanceof LinearLayout.LayoutParams) {
			newLp.gravity = ((LinearLayout.LayoutParams) lp).gravity;
		} else {
			newLp.gravity = Gravity.CENTER;
		}
	}

	return newLp;
}
 
Example 57
Project: RunMap   File: ReviewActivity.java   Source Code and License 5 votes vote down vote up
@Override
public void showEmptyView() {
    TextView textView = new TextView(ReviewActivity.this);
    textView.setText(R.string.string_empty_tips);
    textView.setTextSize(30);
    textView.setBackgroundColor(Color.WHITE);
    textView.setGravity(Gravity.CENTER);
    ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    textView.setLayoutParams(lp);
    ((ViewGroup)(findViewById(android.R.id.content))).addView(textView);
}
 
Example 58
Project: QMUI_Android   File: QMUIBottomSheet.java   Source Code and License 5 votes vote down vote up
private void setItemWidth(View itemView, int itemWidth) {
    LinearLayout.LayoutParams itemLp;
    if (itemView.getLayoutParams() != null) {
        itemLp = (LinearLayout.LayoutParams) itemView.getLayoutParams();
        itemLp.width = itemWidth;
    } else {
        itemLp = new LinearLayout.LayoutParams(itemWidth, ViewGroup.LayoutParams.WRAP_CONTENT);
        itemView.setLayoutParams(itemLp);
    }
    itemLp.gravity = Gravity.TOP;
}
 
Example 59
Project: CSipSimple   File: SlidingTab.java   Source Code and License 5 votes vote down vote up
/**
 * Layout the given widgets within the parent.
 * 
 * @param l
 *            the parent's left border
 * @param t
 *            the parent's top border
 * @param r
 *            the parent's right border
 * @param b
 *            the parent's bottom border
 * @param alignment
 *            which side to align the widget to
 */
private void layout(int l, int t, int r, int b, int alignment) {
	final int handleWidth = tab.getBackground().getIntrinsicWidth();
	final int handleHeight = tab.getBackground().getIntrinsicHeight();
	final int targetWidth = target.getDrawable().getIntrinsicWidth();
	final int targetHeight = target.getDrawable().getIntrinsicHeight();
	final int parentWidth = r - l;
	final int parentHeight = b - t;

	final int leftTarget = (int) (TARGET_ZONE * parentWidth) - targetWidth + handleWidth / 2;
	final int rightTarget = (int) ((1.0f - TARGET_ZONE) * parentWidth) - handleWidth / 2;

	final int targetTop = (parentHeight - targetHeight) / 2;
	final int targetBottom = targetTop + targetHeight;
	final int top = (parentHeight - handleHeight) / 2;
	final int bottom = (parentHeight + handleHeight) / 2;
	if (alignment == ALIGN_LEFT) {
		tab.layout(0, top, handleWidth, bottom);
		text.layout(0 - parentWidth, top, 0, bottom);
		text.setGravity(Gravity.RIGHT);
		target.layout(leftTarget, targetTop, leftTarget + targetWidth, targetBottom);
	} else {
		tab.layout(parentWidth - handleWidth, top, parentWidth, bottom);
		text.layout(parentWidth, top, parentWidth + parentWidth, bottom);
		target.layout(rightTarget, targetTop, rightTarget + targetWidth, targetBottom);
		text.setGravity(Gravity.TOP);
	}
	
}
 
Example 60
Project: BizareChat   File: UserInfoFragment.java   Source Code and License 5 votes vote down vote up
@Override
public void showNetworkError() {
    if (connProblemSnack == null) {
        connProblemSnack = TSnackbar.make(websiteTextView,
                R.string.main_connection_problem, TSnackbar.LENGTH_SHORT);
        connProblemSnack.getView().setBackgroundColor(getResources()
                .getColor(R.color.main_screen_connection_problem_background));
        TextView message = (TextView) connProblemSnack.getView()
                .findViewById(com.androidadvance.topsnackbar.R.id.snackbar_text);
        message.setTextColor(getResources().getColor(R.color.main_screen_connection_problem_text));
        message.setGravity(Gravity.CENTER);
    }
    connProblemSnack.show();
}