android.view.Gravity Java Examples

The following examples show how to use android.view.Gravity. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SimpleHintContentHolder.java    From hintcase with Apache License 2.0 6 votes vote down vote up
@Override
public View getView(Context context, final HintCase hintCase, ViewGroup parent) {
    FrameLayout.LayoutParams frameLayoutParamsBlock = getParentLayoutParams(
            ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT,
            gravity, marginLeft, marginTop, marginRight, marginBottom);
    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setLayoutParams(frameLayoutParamsBlock);
    linearLayout.setGravity(Gravity.CENTER);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    if (contentTitle != null) {
        linearLayout.addView(getTextViewTitle(context));
    }
    if (existImage()) {
        linearLayout.addView(getImage(context, imageView, imageResourceId));
    }
    if (contentText != null) {
        linearLayout.addView(getTextViewDescription(context));
    }
    return linearLayout;
}
 
Example #2
Source File: DrawerLayout.java    From Dashchan with Apache License 2.0 6 votes vote down vote up
@Override
public void onViewReleased(View releasedChild, float xvel, float yvel) {
	// Offset is how open the drawer is, therefore left/right values
	// are reversed from one another.
	final float offset = getDrawerViewOffset(releasedChild);
	final int childWidth = releasedChild.getWidth();

	int left;
	if (checkDrawerViewAbsoluteGravity(releasedChild, Gravity.LEFT)) {
		left = xvel > 0 || xvel == 0 && offset > 0.5f ? 0 : -childWidth;
	} else {
		final int width = getWidth();
		left = xvel < 0 || xvel == 0 && offset > 0.5f ? width - childWidth : width;
	}

	mDragger.settleCapturedViewAt(left, releasedChild.getTop());
	invalidate();
}
 
Example #3
Source File: VideoChatHeadService.java    From VideoChatHeads with The Unlicense 6 votes vote down vote up
private void addCloseView() {

        liClose = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);

        // add close view ImageView centered on the bottom of the screen
        mCloseViewParams = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_PHONE,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                PixelFormat.TRANSLUCENT);

        mCloseViewParams.gravity = Gravity.BOTTOM | Gravity.CENTER;
        mCloseViewParams.height = 400;
        mCloseViewParams.width = WindowManager.LayoutParams.MATCH_PARENT;

        closeView = liClose.inflate(R.layout.view_layout_close, null);

        ivCloseView = (ImageView) closeView.findViewById(R.id.img_close);

        mCloseViewParams.x = 0;
        mCloseViewParams.y = 0;

        mWindowManager.addView(closeView, mCloseViewParams);
    }
 
Example #4
Source File: TextRoundCornerProgressBar.java    From UltimateAndroid with Apache License 2.0 6 votes vote down vote up
@SuppressLint("NewApi")
public TextRoundCornerProgressBar(Context context, AttributeSet attrs) {
	super(context, attrs);
	if (!isInEditMode()) {
		isProgressBarCreated = false;
		isProgressSetBeforeDraw = false;
		isMaxProgressSetBeforeDraw = false;
		isBackgroundColorSetBeforeDraw = false;
		isProgressColorSetBeforeDraw = false;
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		inflater.inflate(R.layout.round_corner_progress_bar_round_corner_with_text_layout, this);
		setup(context, attrs);
		isProgressBarCreated = true;
	} else {
		if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
			setBackground(new ColorDrawable(Color.parseColor("#CCCCCC")));
    	} else {
			setBackgroundColor(Color.parseColor("#CCCCCC"));
    	}
		setGravity(Gravity.CENTER);
           setPadding(0, (int)dp2px(5), 0, (int)dp2px(5));
		TextView tv = new TextView(context);
		tv.setText("TextRoundCornerProgressBar");
		addView(tv);
	}
}
 
Example #5
Source File: TranslucentDrawerLayout.java    From 920-text-editor-v2 with Apache License 2.0 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 #6
Source File: PacksAdapter.java    From actor-platform with GNU Affero General Public License v3.0 6 votes vote down vote up
public StickerViewHolder(Context context, FrameLayout fl) {
    super(fl);
    this.fl = fl;
    sv = new StickerView(context);
    int padding = Screen.dp(2);
    sv.setPadding(padding, padding, padding, padding);
    FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(packsSwitchContainer.getHeight(), packsSwitchContainer.getHeight(), Gravity.CENTER);
    fl.addView(sv, params);

    fl.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            int oldSelected = selectedPostion;
            selectedPostion = position;
            notifyItemChanged(oldSelected);
            notifyItemChanged(selectedPostion);
            stickersAdapter.scrollToSticker(s);
        }
    });
}
 
Example #7
Source File: ImageViewFromUrl.java    From zhangshangwuda with Apache License 2.0 6 votes vote down vote up
private void init(Context context) {
	mContext=context;
	// init layout params
	LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,
			LayoutParams.WRAP_CONTENT);
	params.gravity = Gravity.CENTER;
	// loading progress bar
	mLoading = new ProgressBar(context);
	mLoading.setLayoutParams(params);
	mLoading.setProgress(android.R.attr.progressBarStyleSmall);
	// image view to display the bitmap
	mImage = new ImageView(context);
	mImage.setLayoutParams(params);
	removeAllViews();
	addView(mLoading);
	addView(mImage);
}
 
Example #8
Source File: MessageRenderer.java    From Game-of-Thrones with Apache License 2.0 6 votes vote down vote up
private void renderMessageFromOthers(Message message) {
  User user = message.getUser();
  rootView.setGravity(Gravity.BOTTOM | Gravity.START);
  displayNameTextView.setVisibility(View.VISIBLE);
  avatarImageView.setVisibility(View.VISIBLE);

  imageLoader.builder()
      .load(user.getImageUrl())
      .placeHolder(AppCompatDrawableManager.get().getDrawable(avatarImageView.getContext(),
          R.drawable.ned_head_light))
      .into(avatarImageView)
      .circle()
      .show();

  displayNameTextView.setText(user.getName());
  displayPayLoad(message.getPayload());
  messageContainer.setBackgroundResource(R.drawable.background_message_from_others);
}
 
Example #9
Source File: CustomBanner.java    From WanAndroid with Apache License 2.0 6 votes vote down vote up
private CustomBanner setIndicatorGravity(int type) {
    switch (type) {
        case BannerConfig.LEFT:
            indicatorGravity = Gravity.LEFT | Gravity.CENTER_VERTICAL;
            break;

        case BannerConfig.CENTER:
            indicatorGravity = Gravity.CENTER;
            break;

        case BannerConfig.RIGHT:
            indicatorGravity = Gravity.RIGHT | Gravity.CENTER_VERTICAL;
            break;

        default:
            indicatorGravity = Gravity.CENTER;
    }
    return this;
}
 
Example #10
Source File: LoadingStatusAgent.java    From Shield with MIT License 6 votes vote down vote up
@Override
public View onCreateView(ViewGroup parent, int viewType) {
    LinearLayout rootView = new LinearLayout(mContext);
    rootView.setOrientation(LinearLayout.VERTICAL);
    rootView.setBackgroundColor(getContext().getResources().getColor(android.R.color.white));

    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
            LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    params.leftMargin = ViewUtils.dip2px(getContext(), 30);

    itemViewHolder = new ItemViewHolder();
    TextView textView = new TextView(mContext);
    textView.setHeight(ViewUtils.dip2px(getContext(), 50));
    textView.setGravity(Gravity.CENTER_VERTICAL);
    itemViewHolder.textView = textView;

    rootView.addView(textView, params);
    rootView.setTag(itemViewHolder);
    return rootView;
}
 
Example #11
Source File: InputMethodService.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override public void onCreate() {
    mTheme = Resources.selectSystemTheme(mTheme,
            getApplicationInfo().targetSdkVersion,
            android.R.style.Theme_InputMethod,
            android.R.style.Theme_Holo_InputMethod,
            android.R.style.Theme_DeviceDefault_InputMethod,
            android.R.style.Theme_DeviceDefault_InputMethod);
    super.setTheme(mTheme);
    super.onCreate();
    mImm = (InputMethodManager)getSystemService(INPUT_METHOD_SERVICE);
    mSettingsObserver = SettingsObserver.createAndRegister(this);
    // If the previous IME has occupied non-empty inset in the screen, we need to decide whether
    // we continue to use the same size of the inset or update it
    mShouldClearInsetOfPreviousIme = (mImm.getInputMethodWindowVisibleHeight() > 0);
    mInflater = (LayoutInflater)getSystemService(
            Context.LAYOUT_INFLATER_SERVICE);
    mWindow = new SoftInputWindow(this, "InputMethod", mTheme, null, null, mDispatcherState,
            WindowManager.LayoutParams.TYPE_INPUT_METHOD, Gravity.BOTTOM, false);
    // For ColorView in DecorView to work, FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS needs to be set
    // by default (but IME developers can opt this out later if they want a new behavior).
    mWindow.getWindow().setFlags(
            FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS, FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

    initViews();
    mWindow.getWindow().setLayout(MATCH_PARENT, WRAP_CONTENT);
}
 
Example #12
Source File: SampleTests.java    From android-SwipeRefreshMultipleViews with Apache License 2.0 6 votes vote down vote up
/**
 * Test that swiping on the empty view triggers a refresh.
 */
public void testSwipingEmptyView() {
    // Given a SwipeRefreshLayout which is displaying the empty view

    // When the swipe refresh layout is dragged
    TouchUtils.dragViewBy(this,
            mSwipeRefreshLayout,
            Gravity.CENTER,
            0,
            Math.round(mSwipeRefreshLayout.getHeight() * 0.4f));

    // Then the SwipeRefreshLayout should be refreshing
    getInstrumentation().runOnMainSync(new Runnable() {
        @Override
        public void run() {
            assertTrue(mSwipeRefreshLayout.isRefreshing());
        }
    });
}
 
Example #13
Source File: StatusBarKitkatImpl.java    From status-bar-compat with Apache License 2.0 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.KITKAT)
@Override
public void setStatusBarColor(Window window, int color) {
    window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

    ViewGroup decorViewGroup = (ViewGroup) window.getDecorView();
    View statusBarView = decorViewGroup.findViewWithTag(STATUS_BAR_VIEW_TAG);
    if (statusBarView == null) {
        statusBarView = new StatusBarView(window.getContext());
        statusBarView.setTag(STATUS_BAR_VIEW_TAG);
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        params.gravity = Gravity.TOP;
        statusBarView.setLayoutParams(params);
        decorViewGroup.addView(statusBarView);
    }
    statusBarView.setBackgroundColor(color);
    StatusBarCompat.internalSetFitsSystemWindows(window, true);
}
 
Example #14
Source File: ShowcaseViewBuilder.java    From ShowcaseView with Apache License 2.0 6 votes vote down vote up
public ShowcaseViewBuilder addCustomView(int layoutId, int gravity, float leftMargin, float topMargin, float rightMargin, float bottomMargin) {
    View view = LayoutInflater.from(mActivity).inflate(layoutId, null);
    LinearLayout linearLayout = new LinearLayout(mActivity);
    linearLayout.addView(view);
    linearLayout.setGravity(Gravity.CENTER);

    DisplayMetrics metrics = new DisplayMetrics();
    mActivity.getWindowManager().getDefaultDisplay().getMetrics(metrics);

    Rect rect = new Rect();
    rect.set(0, 0, metrics.widthPixels, metrics.heightPixels);

    int widthSpec = View.MeasureSpec.makeMeasureSpec(rect.width(), MeasureSpec.EXACTLY);
    int heightSpec = View.MeasureSpec.makeMeasureSpec(rect.height(), MeasureSpec.EXACTLY);

    linearLayout.measure(widthSpec, heightSpec);
    mCustomView.add(linearLayout);
    mCustomViewGravity.add(gravity);
    mCustomViewLeftMargins.add(leftMargin);
    mCustomViewTopMargins.add(topMargin);
    mCustomViewRightMargins.add(rightMargin);
    mCustomViewBottomMargins.add(bottomMargin);
    return this;
}
 
Example #15
Source File: BaseCircleIndicator.java    From CircleIndicator with Apache License 2.0 6 votes vote down vote up
public void initialize(Config config) {
    int miniSize = (int) (TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
            DEFAULT_INDICATOR_WIDTH, getResources().getDisplayMetrics()) + 0.5f);
    mIndicatorWidth = (config.width < 0) ? miniSize : config.width;
    mIndicatorHeight = (config.height < 0) ? miniSize : config.height;
    mIndicatorMargin = (config.margin < 0) ? miniSize : config.margin;

    mAnimatorOut = createAnimatorOut(config);
    mImmediateAnimatorOut = createAnimatorOut(config);
    mImmediateAnimatorOut.setDuration(0);

    mAnimatorIn = createAnimatorIn(config);
    mImmediateAnimatorIn = createAnimatorIn(config);
    mImmediateAnimatorIn.setDuration(0);

    mIndicatorBackgroundResId =
            (config.backgroundResId == 0) ? R.drawable.white_radius : config.backgroundResId;
    mIndicatorUnselectedBackgroundResId =
            (config.unselectedBackgroundId == 0) ? config.backgroundResId
                    : config.unselectedBackgroundId;

    setOrientation(config.orientation == VERTICAL ? VERTICAL : HORIZONTAL);
    setGravity(config.gravity >= 0 ? config.gravity : Gravity.CENTER);
}
 
Example #16
Source File: iOSVolumePanel.java    From Noyze with Apache License 2.0 6 votes vote down vote up
@Override public WindowManager.LayoutParams getWindowLayoutParams() {
    int flags = (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE		|
               WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH  |
               WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL      |
               WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR   |
               WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN		|
               WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED	    );
    WindowManager.LayoutParams WPARAMS = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, 0, 0,
            WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, flags, PixelFormat.TRANSLUCENT);
    WPARAMS.windowAnimations = android.R.style.Animation_Dialog;
    WPARAMS.packageName = getContext().getPackageName();
    WPARAMS.setTitle(TAG);
    WPARAMS.gravity = (Gravity.CENTER);
    WPARAMS.screenBrightness = WPARAMS.buttonBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
    return WPARAMS;
}
 
Example #17
Source File: MaterialBadgeTextView.java    From Android with MIT License 6 votes vote down vote up
private void init(Context context, AttributeSet attrs) {
    setGravity(Gravity.CENTER);
    density = getContext().getResources().getDisplayMetrics().density;
    mShadowRadius = (int) (density * SHADOW_RADIUS);
    shadowYOffset = (int) (density * Y_OFFSET);
    shadowXOffset = (int) (density * X_OFFSET);
    basePadding = (mShadowRadius * 2);
    float textHeight = getTextSize();
    float textWidth = textHeight / 4;
    diffWH = (int) (Math.abs(textHeight - textWidth) / 2);
    int horizontalPadding = basePadding + diffWH;
    setPadding(horizontalPadding, basePadding, horizontalPadding, basePadding);
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.MaterialBadgeTextView);
    backgroundColor = typedArray.getColor(R.styleable.MaterialBadgeTextView_android_background, Color.WHITE);
    borderColor = typedArray.getColor(R.styleable.MaterialBadgeTextView_mbtv_border_color, Color.TRANSPARENT);
    borderWidth = typedArray.getDimension(R.styleable.MaterialBadgeTextView_mbtv_border_width, 0);
    borderAlpha = typedArray.getFloat(R.styleable.MaterialBadgeTextView_mbtv_border_alpha, 1);
    ctType = typedArray.getInt(R.styleable.MaterialBadgeTextView_mbtv_type, DEFAULT_FILL_TYPE);
    typedArray.recycle();
}
 
Example #18
Source File: AspectRatioTextView.java    From PictureSelector with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
private void init(@NonNull TypedArray a) {
    setGravity(Gravity.CENTER_HORIZONTAL);

    mAspectRatioTitle = a.getString(R.styleable.ucrop_AspectRatioTextView_ucrop_artv_ratio_title);
    mAspectRatioX = a.getFloat(R.styleable.ucrop_AspectRatioTextView_ucrop_artv_ratio_x, CropImageView.SOURCE_IMAGE_ASPECT_RATIO);
    mAspectRatioY = a.getFloat(R.styleable.ucrop_AspectRatioTextView_ucrop_artv_ratio_y, CropImageView.SOURCE_IMAGE_ASPECT_RATIO);

    if (mAspectRatioX == CropImageView.SOURCE_IMAGE_ASPECT_RATIO || mAspectRatioY == CropImageView.SOURCE_IMAGE_ASPECT_RATIO) {
        mAspectRatio = CropImageView.SOURCE_IMAGE_ASPECT_RATIO;
    } else {
        mAspectRatio = mAspectRatioX / mAspectRatioY;
    }

    mDotSize = getContext().getResources().getDimensionPixelSize(R.dimen.ucrop_size_dot_scale_text_view);
    mDotPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mDotPaint.setStyle(Paint.Style.FILL);

    setTitle();

    int activeColor = getResources().getColor(R.color.ucrop_color_widget_active);
    applyActiveColor(activeColor);

    a.recycle();
}
 
Example #19
Source File: ChatAttachAlertContactsLayout.java    From Telegram with GNU General Public License v2.0 6 votes vote down vote up
public UserCell(Context context) {
    super(context);

    avatarDrawable = new AvatarDrawable();

    avatarImageView = new BackupImageView(context);
    avatarImageView.setRoundRadius(AndroidUtilities.dp(23));
    addView(avatarImageView, LayoutHelper.createFrame(46, 46, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 0 : 14, 9, LocaleController.isRTL ? 14 : 0, 0));

    nameTextView = new SimpleTextView(context);
    nameTextView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
    nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    nameTextView.setTextSize(16);
    nameTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
    addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 20, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 28 : 72, 12, LocaleController.isRTL ? 72 : 28, 0));

    statusTextView = new SimpleTextView(context);
    statusTextView.setTextSize(13);
    statusTextView.setTextColor(Theme.getColor(Theme.key_dialogTextGray2));
    statusTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
    addView(statusTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 20, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 28 : 72, 36, LocaleController.isRTL ? 72 : 28, 0));
}
 
Example #20
Source File: OptionsDialog.java    From Musicoco with Apache License 2.0 6 votes vote down vote up
public OptionsDialog(Activity activity) {
    this.activity = activity;
    this.mDialog = new Dialog(activity, R.style.BottomDialog);

    mDialog.getWindow().setGravity(Gravity.BOTTOM);
    mDialog.getWindow().setWindowAnimations(R.style.BottomDialog_Animation);
    mDialog.setCanceledOnTouchOutside(true);

    View view = LayoutInflater.from(activity).inflate(R.layout.options_container, null);
    listView = (ListView) view.findViewById(R.id.options_list);

    contentView = (LinearLayout) view.findViewById(R.id.options_container);

    titleText = (TextView) view.findViewById(R.id.options_title);
    divide = view.findViewById(R.id.options_divide);
    mDialog.setContentView(view);
    listView.post(new Runnable() {
        @Override
        public void run() {
            setDialogHeight();
        }
    });

    Utils.hideNavAndStatus(mDialog.getWindow().getDecorView());
}
 
Example #21
Source File: ChannelInfoActivity.java    From Applozic-Android-SDK with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
protected void onPostExecute(Long aLong) {
    super.onPostExecute(aLong);
    if (progressDialog != null && progressDialog.isShowing()) {
        progressDialog.dismiss();
    }
    if (!Utils.isInternetAvailable(context)) {
        Toast toast = Toast.makeText(context, getString(R.string.you_dont_have_any_network_access_info), Toast.LENGTH_SHORT);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }
    if (SUCCESS.equals(responseForRemove) && contactsAdapter != null) {
        if (channelUserMapperList != null && channelUserMapperList.size() > 0) {
            channelUserMapperList.remove(channelUserMapper);
            contactsAdapter.notifyDataSetChanged();
            Helper.getListViewSize(mainListView);
        }
    }
}
 
Example #22
Source File: FooterView.java    From CoreModule with Apache License 2.0 6 votes vote down vote up
public void init() {
    this.setOrientation(HORIZONTAL);
    this.setGravity(Gravity.CENTER);
    LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.CENTER;
    params.height = dip2px(23);
    this.setLayoutParams(params);

    progressBar.setIndeterminate(true);
    LayoutParams progressBarparams = new LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    progressBarparams.width = progressBarparams.height = dip2px(22);
    progressBar.setLayoutParams(progressBarparams);

    LayoutParams textViewparams = new LayoutParams(LayoutParams.WRAP_CONTENT, dip2px(20));
    textView.setTextColor(0xff666666);
    textView.setTextSize(16);
    textView.setLayoutParams(textViewparams);

    this.addView(progressBar);
    this.addView(textView);
}
 
Example #23
Source File: SimpleTextView.java    From Telegram-FOSS with GNU General Public License v2.0 6 votes vote down vote up
private void calcOffset(int width) {
    if (layout.getLineCount() > 0) {
        textWidth = (int) Math.ceil(layout.getLineWidth(0));
        textHeight = layout.getLineBottom(0);

        if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.CENTER_HORIZONTAL) {
            offsetX = (width - textWidth) / 2;
        } else if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.LEFT) {
            offsetX = -(int) layout.getLineLeft(0);
        } else if (layout.getLineLeft(0) == 0) {
            offsetX = width - textWidth;
        } else {
            offsetX = -AndroidUtilities.dp(8);
        }
        offsetX += getPaddingLeft();
        textDoesNotFit = textWidth > width;
    }
}
 
Example #24
Source File: VolumeBarPanel.java    From Noyze with Apache License 2.0 6 votes vote down vote up
@Override public WindowManager.LayoutParams getWindowLayoutParams() {
    int flags = (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE		|
            WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH  |
            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL      |
            WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR   |
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_OVERSCAN   |
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN		|
            WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED	    );
    WindowManager.LayoutParams WPARAMS = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT, 0, 0,
            WindowManager.LayoutParams.TYPE_SYSTEM_ERROR, flags, PixelFormat.TRANSLUCENT);
    WPARAMS.windowAnimations = android.R.style.Animation_Dialog;
    WPARAMS.packageName = getContext().getPackageName();
    WPARAMS.setTitle(TAG);
    WPARAMS.rotationAnimation = WindowManager.LayoutParams.ROTATION_ANIMATION_JUMPCUT;
    WPARAMS.gravity = (Gravity.FILL_HORIZONTAL | Gravity.TOP);
    WPARAMS.screenBrightness = WPARAMS.buttonBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
    return WPARAMS;
}
 
Example #25
Source File: MainActivity.java    From KA27 with Apache License 2.0 6 votes vote down vote up
/**
 * Dialog which asks the user to enter his password
 *
 * @param password current encoded password
 */
private void askPassword(final String password) {
    LinearLayout linearLayout = new LinearLayout(this);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setGravity(Gravity.CENTER);
    linearLayout.setPadding(30, 20, 30, 20);

    final AppCompatEditText mPassword = new AppCompatEditText(this);
    mPassword.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
    mPassword.setHint(getString(R.string.password));
    linearLayout.addView(mPassword);

    new AlertDialog.Builder(this).setView(linearLayout).setCancelable(false)
        .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                if (mPassword.getText().toString().equals(Utils.decodeString(password)))
                    new Task().execute();
                else {
                    Utils.toast(getString(R.string.password_wrong), MainActivity.this);
                    finish();
                }
            }
        }).show();
}
 
Example #26
Source File: DrawerLayout.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
boolean isDrawerView(View child) {
	final int gravity = ((LayoutParams) child.getLayoutParams()).gravity;
	final int absGravity = Gravity.getAbsoluteGravity(gravity, getLayoutDirection(child));
	if ((absGravity & Gravity.LEFT) != 0) {
		// This child is a left-edge drawer
		return true;
	}
	if ((absGravity & Gravity.RIGHT) != 0) {
		// This child is a right-edge drawer
		return true;
	}
	return false;
}
 
Example #27
Source File: ContentWrapperView.java    From android-chromium with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Constructs a ContentWrapperView object.
 * @param context The context to create this View with.
 */
public ContentWrapperView(Context context, InfoBar infoBar, int backgroundType, View panel,
        boolean infoBarsFromTop) {
    // Set up this ViewGroup.
    super(context);
    mInfoBar = infoBar;
    mGravity = infoBarsFromTop ? Gravity.BOTTOM : Gravity.TOP;
    mInfoBarsFromTop = infoBarsFromTop;

    // Pull out resources we need for the backgrounds.  Defaults to the INFO type.
    int separatorBackground = R.color.infobar_info_background_separator;
    int layoutBackground = R.drawable.infobar_info_background;
    if (backgroundType == InfoBar.BACKGROUND_TYPE_WARNING) {
        layoutBackground = R.drawable.infobar_warning_background;
        separatorBackground = R.color.infobar_warning_background_separator;
    }

    // Set up this view.
    Resources resources = context.getResources();
    LayoutParams wrapParams = new LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    setLayoutParams(wrapParams);
    ApiCompatibilityUtils.setBackgroundForView(this, resources.getDrawable(layoutBackground));

    // Add a separator line that delineates different InfoBars.
    View separator = new View(context);
    separator.setBackgroundColor(resources.getColor(separatorBackground));
    addView(separator, new LayoutParams(LayoutParams.MATCH_PARENT, getBoundaryHeight(context),
            mGravity));

    // Add the InfoBar content.
    addChildView(panel);
}
 
Example #28
Source File: IcsSpinner.java    From zen4android with MIT License 5 votes vote down vote up
/**
 * Describes how the selected item view is positioned. Currently only the horizontal component
 * is used. The default is determined by the current theme.
 *
 * @param gravity See {@link android.view.Gravity}
 *
 * @attr ref android.R.styleable#Spinner_gravity
 */
public void setGravity(int gravity) {
    if (mGravity != gravity) {
        if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == 0) {
            gravity |= Gravity.LEFT;
        }
        mGravity = gravity;
        requestLayout();
    }
}
 
Example #29
Source File: ViewGroupExample.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private CustomViewGroup(Context context) {
    super(context);

    this.setOrientation(VERTICAL);

    this.textView = new TextView(context);
    this.imageView = new ImageView(context);
    this.button = new Button(context);

    LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    this.textView.setLayoutParams(layoutParams);
    this.imageView.setLayoutParams(layoutParams);
    this.button.setLayoutParams(layoutParams);

    this.textView.setGravity(Gravity.CENTER);

    this.imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    this.imageView.setAdjustViewBounds(true);

    this.button.setText("Goto GitHub");
    this.button.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://davidschreiber.github.com/FancyCoverFlow"));
            view.getContext().startActivity(i);
        }
    });

    this.addView(this.textView);
    this.addView(this.imageView);
    this.addView(this.button);
}
 
Example #30
Source File: PlacesSearchNoneReviewFragment.java    From Place-Search-Service with MIT License 5 votes vote down vote up
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    TextView text = new TextView(inflater.getContext());
    text.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    text.setText("No reviews");
    text.setTextSize(15);
    text.setTextColor(getResources().getColor(android.R.color.darker_gray));
    text.setGravity(Gravity.CENTER);
    return text;
}