Java Code Examples for org.telegram.messenger.AndroidUtilities#density()
The following examples show how to use
org.telegram.messenger.AndroidUtilities#density() .
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: DrawerLayoutContainer.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
public DrawerLayoutContainer(Context context) { super(context); minDrawerMargin = (int) (MIN_DRAWER_MARGIN * AndroidUtilities.density + 0.5f); setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); setFocusableInTouchMode(true); if (Build.VERSION.SDK_INT >= 21) { setFitsSystemWindows(true); setOnApplyWindowInsetsListener((v, insets) -> { final DrawerLayoutContainer drawerLayout = (DrawerLayoutContainer) v; AndroidUtilities.statusBarHeight = insets.getSystemWindowInsetTop(); lastInsets = insets; drawerLayout.setWillNotDraw(insets.getSystemWindowInsetTop() <= 0 && getBackground() == null); drawerLayout.requestLayout(); return insets.consumeSystemWindowInsets(); }); setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); } shadowLeft = getResources().getDrawable(R.drawable.menu_shadow); }
Example 2
Source File: PeopleNearbyActivity.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
public HintInnerCell(Context context) { super(context); int top = (int) ((ActionBar.getCurrentActionBarHeight() + (actionBar.getOccupyStatusBar() ? AndroidUtilities.statusBarHeight : 0)) / AndroidUtilities.density) - 44; imageView = new ImageView(context); imageView.setBackgroundDrawable(Theme.createCircleDrawable(AndroidUtilities.dp(74), Theme.getColor(Theme.key_chats_archiveBackground))); imageView.setImageDrawable(new ShareLocationDrawable(context, 2)); imageView.setScaleType(ImageView.ScaleType.CENTER); addView(imageView, LayoutHelper.createFrame(74, 74, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, top + 27, 0, 0)); titleTextView = new TextView(context); titleTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText)); titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 24); titleTextView.setGravity(Gravity.CENTER); titleTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("PeopleNearby", R.string.PeopleNearby))); addView(titleTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 52, top + 120, 52, 27)); messageTextView = new TextView(context); messageTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText)); messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15); messageTextView.setGravity(Gravity.CENTER); messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("PeopleNearbyInfo2", R.string.PeopleNearbyInfo2))); addView(messageTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 40, top + 161, 40, 27)); }
Example 3
Source File: StickersAlert.java From TelePlus-Android with GNU General Public License v2.0 | 6 votes |
private void updateSendButton() { int size = (int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) / 2 / AndroidUtilities.density); if (delegate != null && (stickerSet == null || !stickerSet.set.masks)) { previewSendButton.setText(LocaleController.getString("SendSticker", R.string.SendSticker).toUpperCase()); stickerImageView.setLayoutParams(LayoutHelper.createFrame(size, size, Gravity.CENTER, 0, 0, 0, 30)); stickerEmojiTextView.setLayoutParams(LayoutHelper.createFrame(size, size, Gravity.CENTER, 0, 0, 0, 30)); previewSendButton.setVisibility(View.VISIBLE); previewFavButton.setVisibility(View.VISIBLE); previewSendButtonShadow.setVisibility(View.VISIBLE); } else { previewSendButton.setText(LocaleController.getString("Close", R.string.Close).toUpperCase()); stickerImageView.setLayoutParams(LayoutHelper.createFrame(size, size, Gravity.CENTER)); stickerEmojiTextView.setLayoutParams(LayoutHelper.createFrame(size, size, Gravity.CENTER)); previewSendButton.setVisibility(View.GONE); previewFavButton.setVisibility(View.GONE); previewSendButtonShadow.setVisibility(View.GONE); } }
Example 4
Source File: StickersAlert.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
private void updateSendButton() { int size = (int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) / 2 / AndroidUtilities.density); if (delegate != null && (stickerSet == null || !stickerSet.set.masks)) { previewSendButton.setText(LocaleController.getString("SendSticker", R.string.SendSticker).toUpperCase()); stickerImageView.setLayoutParams(LayoutHelper.createFrame(size, size, Gravity.CENTER, 0, 0, 0, 30)); stickerEmojiTextView.setLayoutParams(LayoutHelper.createFrame(size, size, Gravity.CENTER, 0, 0, 0, 30)); previewSendButton.setVisibility(View.VISIBLE); previewSendButtonShadow.setVisibility(View.VISIBLE); } else { previewSendButton.setText(LocaleController.getString("Close", R.string.Close).toUpperCase()); stickerImageView.setLayoutParams(LayoutHelper.createFrame(size, size, Gravity.CENTER)); stickerEmojiTextView.setLayoutParams(LayoutHelper.createFrame(size, size, Gravity.CENTER)); previewSendButton.setVisibility(View.GONE); previewSendButtonShadow.setVisibility(View.GONE); } }
Example 5
Source File: PeopleNearbyActivity.java From Telegram with GNU General Public License v2.0 | 6 votes |
public HintInnerCell(Context context) { super(context); int top = (int) ((ActionBar.getCurrentActionBarHeight() + (actionBar.getOccupyStatusBar() ? AndroidUtilities.statusBarHeight : 0)) / AndroidUtilities.density) - 44; imageView = new ImageView(context); imageView.setBackgroundDrawable(Theme.createCircleDrawable(AndroidUtilities.dp(74), Theme.getColor(Theme.key_chats_archiveBackground))); imageView.setImageDrawable(new ShareLocationDrawable(context, 2)); imageView.setScaleType(ImageView.ScaleType.CENTER); addView(imageView, LayoutHelper.createFrame(74, 74, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, top + 27, 0, 0)); titleTextView = new TextView(context); titleTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText)); titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 24); titleTextView.setGravity(Gravity.CENTER); titleTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("PeopleNearby", R.string.PeopleNearby))); addView(titleTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 52, top + 120, 52, 27)); messageTextView = new TextView(context); messageTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText)); messageTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15); messageTextView.setGravity(Gravity.CENTER); messageTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("PeopleNearbyInfo2", R.string.PeopleNearbyInfo2))); addView(messageTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.LEFT, 40, top + 161, 40, 27)); }
Example 6
Source File: PullForegroundDrawable.java From Telegram with GNU General Public License v2.0 | 5 votes |
private void updatePath() { int h = AndroidUtilities.dp(18); path.reset(); path.moveTo(h >> 1, AndroidUtilities.dpf2(4.98f)); path.lineTo(AndroidUtilities.dpf2(4.95f), AndroidUtilities.dpf2(9f)); path.lineTo(h - AndroidUtilities.dpf2(4.95f), AndroidUtilities.dpf2(9f)); path.lineTo(h >> 1, AndroidUtilities.dpf2(4.98f)); paint.setStyle(Paint.Style.FILL_AND_STROKE); paint.setStrokeJoin(Paint.Join.ROUND); paint.setStrokeWidth(AndroidUtilities.dpf2(1f)); lastDensity = AndroidUtilities.density; }
Example 7
Source File: PullForegroundDrawable.java From Telegram with GNU General Public License v2.0 | 5 votes |
@Override public void draw(@NonNull Canvas canvas) { if (lastDensity != AndroidUtilities.density) { updatePath(); } canvas.save(); canvas.translate(getBounds().left, getBounds().top); canvas.drawPath(path, paint); int h = AndroidUtilities.dp(18); canvas.drawRect(AndroidUtilities.dpf2(7.56f), AndroidUtilities.dpf2(8f), h - AndroidUtilities.dpf2(7.56f), AndroidUtilities.dpf2(11.1f), paint); canvas.restore(); }
Example 8
Source File: ThemePreviewActivity.java From Telegram with GNU General Public License v2.0 | 5 votes |
@Override public boolean onFragmentCreate() { NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.emojiDidLoad); if (screenType == SCREEN_TYPE_ACCENT_COLOR) { NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.didSetNewWallpapper); } if (screenType != SCREEN_TYPE_PREVIEW || accent != null) { if (SharedConfig.getDevicePerfomanceClass() == SharedConfig.PERFORMANCE_CLASS_LOW) { int w = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y); int h = Math.max(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y); imageFilter = (int) (w / AndroidUtilities.density) + "_" + (int) (h / AndroidUtilities.density) + "_f"; } else { imageFilter = (int) (1080 / AndroidUtilities.density) + "_" + (int) (1920 / AndroidUtilities.density) + "_f"; } maxWallpaperSize = Math.min(1920, Math.max(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y)); NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.wallpapersNeedReload); NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.wallpapersDidLoad); TAG = DownloadController.getInstance(currentAccount).generateObserverTag(); if (patterns == null) { patterns = new ArrayList<>(); MessagesStorage.getInstance(currentAccount).getWallpapers(); } } else { isMotion = Theme.isWallpaperMotion(); } return super.onFragmentCreate(); }
Example 9
Source File: PhotoFilterBlurControl.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
private void handlePinch(int state, MotionEvent event) { switch (state) { case GestureStateBegan: { startPointerDistance = getDistance(event); pointerScale = 1; activeControl = BlurViewActiveControl.BlurViewActiveControlWholeArea; setSelected(true, true); } case GestureStateChanged: { float newDistance = getDistance(event); pointerScale += (newDistance - startPointerDistance) / AndroidUtilities.density * 0.01f; falloff = Math.max(BlurMinimumFalloff, falloff * pointerScale); size = Math.max(falloff + BlurMinimumDifference, size * pointerScale); pointerScale = 1; startPointerDistance = newDistance; invalidate(); if (delegate != null) { delegate.valueChanged(centerPoint, falloff, size, degreesToRadians(angle) + (float) Math.PI / 2.0f); } } break; case GestureStateEnded: case GestureStateCancelled: case GestureStateFailed: { activeControl = BlurViewActiveControl.BlurViewActiveControlNone; setSelected(false, true); } break; default: break; } }
Example 10
Source File: PhonebookShareActivity.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
private void needLayout() { FrameLayout.LayoutParams layoutParams; int newTop = (actionBar.getOccupyStatusBar() ? AndroidUtilities.statusBarHeight : 0) + ActionBar.getCurrentActionBarHeight(); if (listView != null) { layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams(); if (layoutParams.topMargin != newTop) { layoutParams.topMargin = newTop; listView.setLayoutParams(layoutParams); extraHeightView.setTranslationY(newTop); } } if (avatarImage != null) { float diff = extraHeight / (float) AndroidUtilities.dp(88); extraHeightView.setScaleY(diff); shadowView.setTranslationY(newTop + extraHeight); avatarImage.setScaleX((42 + 18 * diff) / 42.0f); avatarImage.setScaleY((42 + 18 * diff) / 42.0f); float avatarY = (actionBar.getOccupyStatusBar() ? AndroidUtilities.statusBarHeight : 0) + ActionBar.getCurrentActionBarHeight() / 2.0f * (1.0f + diff) - 21 * AndroidUtilities.density + 27 * AndroidUtilities.density * diff; avatarImage.setTranslationX(-AndroidUtilities.dp(47) * diff); avatarImage.setTranslationY((float) Math.ceil(avatarY)); nameTextView.setTranslationX(-21 * AndroidUtilities.density * diff); nameTextView.setTranslationY((float) Math.floor(avatarY) - (float) Math.ceil(AndroidUtilities.density) + (float) Math.floor(7 * AndroidUtilities.density * diff)); nameTextView.setScaleX(1.0f + 0.12f * diff); nameTextView.setScaleY(1.0f + 0.12f * diff); } }
Example 11
Source File: TimerDrawable.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
@Override public void draw(Canvas canvas) { int width = getIntrinsicWidth(); int height = getIntrinsicHeight(); if (time == 0) { paint.setColor(Theme.getColor(Theme.key_chat_secretTimerBackground)); linePaint.setColor(Theme.getColor(Theme.key_chat_secretTimerText)); canvas.drawCircle(AndroidUtilities.dpf2(9), AndroidUtilities.dpf2(9), AndroidUtilities.dpf2(7.5f), paint); canvas.drawCircle(AndroidUtilities.dpf2(9), AndroidUtilities.dpf2(9), AndroidUtilities.dpf2(8), linePaint); paint.setColor(Theme.getColor(Theme.key_chat_secretTimerText)); canvas.drawLine(AndroidUtilities.dp(9), AndroidUtilities.dp(9), AndroidUtilities.dp(13), AndroidUtilities.dp(9), linePaint); canvas.drawLine(AndroidUtilities.dp(9), AndroidUtilities.dp(5), AndroidUtilities.dp(9), AndroidUtilities.dp(9.5f), linePaint); canvas.drawRect(AndroidUtilities.dpf2(7), AndroidUtilities.dpf2(0), AndroidUtilities.dpf2(11), AndroidUtilities.dpf2(1.5f), paint); } else { paint.setColor(Theme.getColor(Theme.key_chat_secretTimerBackground)); timePaint.setColor(Theme.getColor(Theme.key_chat_secretTimerText)); canvas.drawCircle(AndroidUtilities.dp(9.5f), AndroidUtilities.dp(9.5f), AndroidUtilities.dp(9.5f), paint); } if (time != 0 && timeLayout != null) { int xOffxet = 0; if (AndroidUtilities.density == 3) { xOffxet = -1; } canvas.translate((int)(width / 2 - Math.ceil(timeWidth / 2)) + xOffxet, (height - timeHeight) / 2); timeLayout.draw(canvas); } }
Example 12
Source File: Switch.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
public Switch(Context context) { super(context); mThumbDrawable = context.getResources().getDrawable(R.drawable.switch_thumb); if (mThumbDrawable != null) mThumbDrawable.setCallback(this); mTrackDrawable = context.getResources().getDrawable(R.drawable.switch_track); if (mTrackDrawable != null) mTrackDrawable.setCallback(this); if (AndroidUtilities.density < 1) mSwitchMinWidth = AndroidUtilities.dp(30); else mSwitchMinWidth = 0; mSwitchPadding = 0; mSplitTrack = false; final ViewConfiguration config = ViewConfiguration.get(context); mTouchSlop = config.getScaledTouchSlop(); mMinFlingVelocity = config.getScaledMinimumFlingVelocity(); refreshDrawableState(); setChecked(isChecked()); }
Example 13
Source File: CropRotationWheel.java From Telegram with GNU General Public License v2.0 | 5 votes |
@Override public boolean onTouchEvent(MotionEvent ev) { int action = ev.getActionMasked(); float x = ev.getX(); if (action == MotionEvent.ACTION_DOWN) { prevX = x; if (rotationListener != null) rotationListener.onStart(); } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { if (rotationListener != null) rotationListener.onEnd(this.rotation); AndroidUtilities.makeAccessibilityAnnouncement(String.format("%.1f°", this.rotation)); } else if (action == MotionEvent.ACTION_MOVE) { float delta = prevX - x; float newAngle = this.rotation + (float)(delta / AndroidUtilities.density / Math.PI / 1.65f); newAngle = Math.max(-MAX_ANGLE, Math.min(MAX_ANGLE, newAngle)); if (Math.abs(newAngle - this.rotation) > 0.001) { if (Math.abs(newAngle) < 0.05) newAngle = 0; setRotation(newAngle, false); if (rotationListener != null) rotationListener.onChange(this.rotation); prevX = x; } } return true; }
Example 14
Source File: TimerDrawable.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
@Override public void draw(Canvas canvas) { int width = getIntrinsicWidth(); int height = getIntrinsicHeight(); if (time == 0) { paint.setColor(Theme.getColor(Theme.key_chat_secretTimerBackground)); linePaint.setColor(Theme.getColor(Theme.key_chat_secretTimerText)); canvas.drawCircle(AndroidUtilities.dpf2(9), AndroidUtilities.dpf2(9), AndroidUtilities.dpf2(7.5f), paint); canvas.drawCircle(AndroidUtilities.dpf2(9), AndroidUtilities.dpf2(9), AndroidUtilities.dpf2(8), linePaint); paint.setColor(Theme.getColor(Theme.key_chat_secretTimerText)); canvas.drawLine(AndroidUtilities.dp(9), AndroidUtilities.dp(9), AndroidUtilities.dp(13), AndroidUtilities.dp(9), linePaint); canvas.drawLine(AndroidUtilities.dp(9), AndroidUtilities.dp(5), AndroidUtilities.dp(9), AndroidUtilities.dp(9.5f), linePaint); canvas.drawRect(AndroidUtilities.dpf2(7), AndroidUtilities.dpf2(0), AndroidUtilities.dpf2(11), AndroidUtilities.dpf2(1.5f), paint); } else { paint.setColor(Theme.getColor(Theme.key_chat_secretTimerBackground)); timePaint.setColor(Theme.getColor(Theme.key_chat_secretTimerText)); canvas.drawCircle(AndroidUtilities.dp(9.5f), AndroidUtilities.dp(9.5f), AndroidUtilities.dp(9.5f), paint); } if (time != 0 && timeLayout != null) { int xOffxet = 0; if (AndroidUtilities.density == 3) { xOffxet = -1; } canvas.translate((int)(width / 2 - Math.ceil(timeWidth / 2)) + xOffxet, (height - timeHeight) / 2); timeLayout.draw(canvas); } }
Example 15
Source File: PullForegroundDrawable.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
private void updatePath() { int h = AndroidUtilities.dp(18); path.reset(); path.moveTo(h >> 1, AndroidUtilities.dpf2(4.98f)); path.lineTo(AndroidUtilities.dpf2(4.95f), AndroidUtilities.dpf2(9f)); path.lineTo(h - AndroidUtilities.dpf2(4.95f), AndroidUtilities.dpf2(9f)); path.lineTo(h >> 1, AndroidUtilities.dpf2(4.98f)); paint.setStyle(Paint.Style.FILL_AND_STROKE); paint.setStrokeJoin(Paint.Join.ROUND); paint.setStrokeWidth(AndroidUtilities.dpf2(1f)); lastDensity = AndroidUtilities.density; }
Example 16
Source File: PhotoFilterBlurControl.java From TelePlus-Android with GNU General Public License v2.0 | 5 votes |
private void handlePinch(int state, MotionEvent event) { switch (state) { case GestureStateBegan: { startPointerDistance = getDistance(event); pointerScale = 1; activeControl = BlurViewActiveControl.BlurViewActiveControlWholeArea; setSelected(true, true); } case GestureStateChanged: { float newDistance = getDistance(event); pointerScale += (newDistance - startPointerDistance) / AndroidUtilities.density * 0.01f; falloff = Math.max(BlurMinimumFalloff, falloff * pointerScale); size = Math.max(falloff + BlurMinimumDifference, size * pointerScale); pointerScale = 1; startPointerDistance = newDistance; invalidate(); if (delegate != null) { delegate.valueChanged(centerPoint, falloff, size, degreesToRadians(angle) + (float) Math.PI / 2.0f); } } break; case GestureStateEnded: case GestureStateCancelled: case GestureStateFailed: { activeControl = BlurViewActiveControl.BlurViewActiveControlNone; setSelected(false, true); } break; default: break; } }
Example 17
Source File: DrawerLayoutContainer.java From Telegram with GNU General Public License v2.0 | 5 votes |
public DrawerLayoutContainer(Context context) { super(context); adjustPanLayoutHelper = new AdjustPanLayoutHelper(this); minDrawerMargin = (int) (MIN_DRAWER_MARGIN * AndroidUtilities.density + 0.5f); setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); setFocusableInTouchMode(true); if (Build.VERSION.SDK_INT >= 21) { setFitsSystemWindows(true); setOnApplyWindowInsetsListener((v, insets) -> { final DrawerLayoutContainer drawerLayout = (DrawerLayoutContainer) v; if (AndroidUtilities.statusBarHeight != insets.getSystemWindowInsetTop()) { drawerLayout.requestLayout(); } AndroidUtilities.statusBarHeight = insets.getSystemWindowInsetTop(); lastInsets = insets; drawerLayout.setWillNotDraw(insets.getSystemWindowInsetTop() <= 0 && getBackground() == null); if (Build.VERSION.SDK_INT >= 28) { DisplayCutout cutout = insets.getDisplayCutout(); hasCutout = cutout != null && cutout.getBoundingRects().size() != 0; } invalidate(); return insets.consumeSystemWindowInsets(); }); setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); } shadowLeft = getResources().getDrawable(R.drawable.menu_shadow); }
Example 18
Source File: DrawerLayoutContainer.java From Telegram-FOSS with GNU General Public License v2.0 | 5 votes |
public DrawerLayoutContainer(Context context) { super(context); adjustPanLayoutHelper = new AdjustPanLayoutHelper(this); minDrawerMargin = (int) (MIN_DRAWER_MARGIN * AndroidUtilities.density + 0.5f); setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); setFocusableInTouchMode(true); if (Build.VERSION.SDK_INT >= 21) { setFitsSystemWindows(true); setOnApplyWindowInsetsListener((v, insets) -> { final DrawerLayoutContainer drawerLayout = (DrawerLayoutContainer) v; if (AndroidUtilities.statusBarHeight != insets.getSystemWindowInsetTop()) { drawerLayout.requestLayout(); } AndroidUtilities.statusBarHeight = insets.getSystemWindowInsetTop(); lastInsets = insets; drawerLayout.setWillNotDraw(insets.getSystemWindowInsetTop() <= 0 && getBackground() == null); if (Build.VERSION.SDK_INT >= 28) { DisplayCutout cutout = insets.getDisplayCutout(); hasCutout = cutout != null && cutout.getBoundingRects().size() != 0; } invalidate(); return insets.consumeSystemWindowInsets(); }); setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); } shadowLeft = getResources().getDrawable(R.drawable.menu_shadow); }
Example 19
Source File: Switch.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
@Override public void draw(Canvas c) { final Rect padding = mTempRect; final int switchLeft = mSwitchLeft; final int switchTop = mSwitchTop; final int switchRight = mSwitchRight; final int switchBottom = mSwitchBottom; int thumbInitialLeft = switchLeft + getThumbOffset(); final Insets thumbInsets; if (mThumbDrawable != null) { thumbInsets = Insets.NONE; } else { thumbInsets = Insets.NONE; } if (mTrackDrawable != null) { mTrackDrawable.getPadding(padding); thumbInitialLeft += padding.left; int trackLeft = switchLeft; int trackTop = switchTop; int trackRight = switchRight; int trackBottom = switchBottom; if (thumbInsets != Insets.NONE) { if (thumbInsets.left > padding.left) { trackLeft += thumbInsets.left - padding.left; } if (thumbInsets.top > padding.top) { trackTop += thumbInsets.top - padding.top; } if (thumbInsets.right > padding.right) { trackRight -= thumbInsets.right - padding.right; } if (thumbInsets.bottom > padding.bottom) { trackBottom -= thumbInsets.bottom - padding.bottom; } } mTrackDrawable.setBounds(trackLeft, trackTop, trackRight, trackBottom); } if (mThumbDrawable != null) { mThumbDrawable.getPadding(padding); final int thumbLeft = thumbInitialLeft - padding.left; final int thumbRight = thumbInitialLeft + mThumbWidth + padding.right; int offset = (AndroidUtilities.density == 1.5f ? AndroidUtilities.dp(1) : 0); mThumbDrawable.setBounds(thumbLeft, switchTop + offset, thumbRight, switchBottom + offset); final Drawable background = getBackground(); if (background != null && Build.VERSION.SDK_INT >= 21) { background.setHotspotBounds(thumbLeft, switchTop, thumbRight, switchBottom); } } super.draw(c); }
Example 20
Source File: RadioButton.java From Telegram-FOSS with GNU General Public License v2.0 | 4 votes |
@Override protected void onDraw(Canvas canvas) { if (bitmap == null || bitmap.getWidth() != getMeasuredWidth()) { if (bitmap != null) { bitmap.recycle(); bitmap = null; } try { bitmap = Bitmap.createBitmap(getMeasuredWidth(), getMeasuredHeight(), Bitmap.Config.ARGB_8888); bitmapCanvas = new Canvas(bitmap); } catch (Throwable e) { FileLog.e(e); } } float circleProgress; float innerRad; if (progress <= 0.5f) { paint.setColor(color); checkedPaint.setColor(color); circleProgress = progress / 0.5f; } else { circleProgress = 2.0f - progress / 0.5f; int r1 = Color.red(color); int rD = (int) ((Color.red(checkedColor) - r1) * (1.0f - circleProgress)); int g1 = Color.green(color); int gD = (int) ((Color.green(checkedColor) - g1) * (1.0f - circleProgress)); int b1 = Color.blue(color); int bD = (int) ((Color.blue(checkedColor) - b1) * (1.0f - circleProgress)); int c = Color.rgb(r1 + rD, g1 + gD, b1 + bD); paint.setColor(c); checkedPaint.setColor(c); } if (bitmap != null) { bitmap.eraseColor(0); float rad = size / 2 - (1 + circleProgress) * AndroidUtilities.density; bitmapCanvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, rad, paint); if (progress <= 0.5f) { bitmapCanvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, (rad - AndroidUtilities.dp(1)), checkedPaint); bitmapCanvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, (rad - AndroidUtilities.dp(1)) * (1.0f - circleProgress), eraser); } else { bitmapCanvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, size / 4 + (rad - AndroidUtilities.dp(1) - size / 4) * circleProgress, checkedPaint); } canvas.drawBitmap(bitmap, 0, 0, null); } }