- Optimized GPU overdraw caused by minebuttons by replacing their background with nine patch files.

This commit is contained in:
SerpentSpirale 2021-01-29 23:15:50 +01:00
parent 2d2fd909ce
commit 4eb7ba7445
6 changed files with 16 additions and 72 deletions

View File

@ -9,39 +9,8 @@ import android.widget.*;
import android.view.View.*;
import net.kdt.pojavlaunch.*;
public class MineButton extends Button
public class MineButton extends androidx.appcompat.widget.AppCompatButton
{
private ColorDrawable left = new ColorDrawable(Color.parseColor("#80000000"));
private ColorDrawable top = new ColorDrawable(Color.parseColor("#64FC20"));
private ColorDrawable right = new ColorDrawable(Color.parseColor("#40000000"));
private ColorDrawable bottom = new ColorDrawable(Color.parseColor("#80000000"));
private ColorDrawable bgNormal = new ColorDrawable(Color.parseColor("#36b030"));
private ColorDrawable leftFocus = new ColorDrawable(Color.parseColor("#C2000000"));
private ColorDrawable topFocus = new ColorDrawable(Color.parseColor("#80313131"));
private ColorDrawable rightFocus = new ColorDrawable(Color.parseColor("#C2000000"));
private ColorDrawable bottomFocus = new ColorDrawable(Color.parseColor("#C2000000"));
private ColorDrawable bgFocus = new ColorDrawable(Color.parseColor("#313131"));
private boolean isUp = true;
private Drawable[] DrawableArray = new Drawable[]{
top,
left,
right,
bottom,
bgNormal
};
private Drawable[] DrawableArrayFocus = new Drawable[]{
topFocus,
leftFocus,
rightFocus,
bottomFocus,
bgFocus
};
private LayerDrawable layerdrawable, layerdrawablefocus;
public MineButton(Context ctx) {
this(ctx, null);
@ -56,23 +25,8 @@ public class MineButton extends Button
getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
layerdrawable = new LayerDrawable(DrawableArray);
layerdrawable.setLayerInset(0, 0, 0, 0, 0); // top
layerdrawable.setLayerInset(1, 0, 8, getWidth() - 8,0); // left
layerdrawable.setLayerInset(2, getWidth() - 8, 8, 0, 0); // right
layerdrawable.setLayerInset(3, 0, getHeight() - 8, 0, 0); // bottom
layerdrawable.setLayerInset(4, 8, 8, 8, 8); // bg
layerdrawablefocus = new LayerDrawable(DrawableArrayFocus);
layerdrawablefocus.setLayerInset(0, 0, 0, 0, 0); // top
layerdrawablefocus.setLayerInset(1, 0, 8, getWidth() - 8,0); // left
layerdrawablefocus.setLayerInset(2, getWidth() - 8, 8, 0, 0); // right
layerdrawablefocus.setLayerInset(3, 0, getHeight() - 8, 0, 0); // bottom
layerdrawablefocus.setLayerInset(4, 8, 8, 8, 8); // bg
setBackgroundDrawable(layerdrawable);
setTextColor(Color.WHITE);
setPadding(10, 10, 10, 10);
setPadding(10,10,10,10);
//setOnTouchListener(null);
}
@ -80,24 +34,4 @@ public class MineButton extends Button
setTypeface(Typeface.createFromAsset(getContext().getAssets(), "font/NotoSans-Bold.ttf"));
}
@Override
public void setEnabled(boolean enabled)
{
super.setEnabled(enabled);
setBackgroundDrawable(enabled ? layerdrawable : layerdrawablefocus);
}
@Override
public boolean onTouchEvent(MotionEvent event)
{
if ((event.getAction() == event.ACTION_UP) && !isUp && isEnabled()) {
setBackgroundDrawable(layerdrawable);
isUp = true;
} else if (event.getAction() == event.ACTION_DOWN && isUp) {
setBackgroundDrawable(layerdrawablefocus);
isUp = false;
}
return super.onTouchEvent(event);
}
}

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/mine_button_focused" />
<item android:state_enabled="false" android:drawable="@drawable/mine_button_focused" />
<item android:drawable="@drawable/mine_button_unfocused" />
</selector>

Binary file not shown.

After

Width:  |  Height:  |  Size: 116 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 B

View File

@ -95,7 +95,8 @@
android:layout_height="match_parent"
android:text="@string/login_online_login_label"
android:onClick="loginMC"
android:gravity="center"/>
android:gravity="center"
android:background="@drawable/mine_button_background"/>
<ProgressBar
android:layout_width="match_parent"
@ -111,7 +112,8 @@
android:layout_width="210dip"
android:layout_height="match_parent"
android:text="@string/login_select_account"
android:onClick="loginSavedAcc"/>
android:onClick="loginSavedAcc"
android:background="@drawable/mine_button_background"/>
</LinearLayout>
@ -119,7 +121,8 @@
android:layout_height="42dp"
android:layout_width="match_parent"
android:text="@string/login_microsoft"
android:onClick="loginMicrosoft"/>
android:onClick="loginMicrosoft"
android:background="@drawable/mine_button_background"/>
</LinearLayout>

View File

@ -252,7 +252,8 @@
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/guidelineLeft"
app:layout_constraintTop_toTopOf="@+id/guidelineBottom" />
app:layout_constraintTop_toTopOf="@+id/guidelineBottom"
android:background="@drawable/mine_button_background"/>
<TextView
android:id="@+id/launchermain_text_welcome"