Skip to content

Commit

Permalink
Optimize CustomRadioButton and CustomSeekBar code
Browse files Browse the repository at this point in the history
  • Loading branch information
frknkrc44 committed Jan 11, 2024
1 parent 2d25b24 commit 491b5f2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 12 deletions.
17 changes: 10 additions & 7 deletions app/src/main/java/org/blinksd/board/views/CustomRadioButton.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.blinksd.board.views;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.PorterDuff;
Expand All @@ -20,30 +21,32 @@ public CustomRadioButton(Context c) {
setPadding(i, 0, i, 0);
if (Build.VERSION.SDK_INT < 21) {
Drawable drw = getButtonDrawable();
if (drw != null) {
drw.setColorFilter(0xFFDEDEDE, PorterDuff.Mode.SRC_IN);

if (drw == null) {
return;
}

if (Build.VERSION.SDK_INT < 16) {
drw.setColorFilter(0xFFDEDEDE, PorterDuff.Mode.SRC_IN);

if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
setPadding(i + drw.getIntrinsicWidth(), 0, i, 0);
}
} else {
setPadding(i, 0, i, 0);
int color = 0xFFDEDEDE;
if (Build.VERSION.SDK_INT >= 31) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
color = getResources().getColor(android.R.color.system_accent1_200, c.getTheme());
}
setButtonTintList(ColorStateList.valueOf(color));
setButtonTintMode(PorterDuff.Mode.SRC_IN);

setBackground(null);
}

//setRadioButton();
}

@SuppressLint("DiscouragedPrivateApi")
public Drawable getButtonDrawable() {
if (Build.VERSION.SDK_INT >= 23) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
return super.getButtonDrawable();
}

Expand Down
9 changes: 5 additions & 4 deletions app/src/main/java/org/blinksd/board/views/CustomSeekBar.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.blinksd.board.views;

import android.annotation.SuppressLint;
import android.content.Context;
import android.content.res.ColorStateList;
import android.graphics.Bitmap;
Expand All @@ -25,7 +26,7 @@ class CustomSeekBar extends SeekBar {
setLayoutParams(new LinearLayout.LayoutParams(DensityUtils.mpInt(50), -2, 0));
int p = DensityUtils.dpInt(4);
setPadding(p * 4, p, p * 4, p);
if (Build.VERSION.SDK_INT >= 21)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
setSplitTrack(false);
drawSeekBar();
}
Expand Down Expand Up @@ -56,16 +57,16 @@ android.R.color.system_accent1_200, getContext().getTheme())
}
}

@SuppressLint("DiscouragedPrivateApi")
public Drawable getThumb() {
if (Build.VERSION.SDK_INT >= 16)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
return super.getThumb();

try {
Field thumb = AbsSeekBar.class.getDeclaredField("mThumb");
thumb.setAccessible(true);
return (Drawable) thumb.get(this);
} catch (Throwable t) {
}
} catch (Throwable ignored) {}

return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.PorterDuff;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
Expand Down

0 comments on commit 491b5f2

Please sign in to comment.