Design: UI more like Minecraft Launcher, change how font replaced

This commit is contained in:
khanhduytran0 2020-08-03 14:07:11 +07:00
parent efffa26f2f
commit 3d0264923d
7 changed files with 33 additions and 57 deletions

View File

@ -11,8 +11,6 @@ import net.kdt.pojavlaunch.*;
public class MineButton extends Button public class MineButton extends Button
{ {
private static FontChanger fontChangerMinecraftTen;
private ColorDrawable left = new ColorDrawable(Color.parseColor("#80000000")); private ColorDrawable left = new ColorDrawable(Color.parseColor("#80000000"));
private ColorDrawable top = new ColorDrawable(Color.parseColor("#64FC20")); private ColorDrawable top = new ColorDrawable(Color.parseColor("#64FC20"));
private ColorDrawable right = new ColorDrawable(Color.parseColor("#40000000")); private ColorDrawable right = new ColorDrawable(Color.parseColor("#40000000"));
@ -54,10 +52,7 @@ public class MineButton extends Button
init(); init();
} }
public void init() public void init() {
{
if (fontChangerMinecraftTen == null) fontChangerMinecraftTen = new FontChanger(getContext().getAssets(), "font/minecraft-ten.ttf");
fontChangerMinecraftTen.replaceFont(this);
getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override @Override
public void onGlobalLayout() { public void onGlobalLayout() {

View File

@ -8,37 +8,18 @@ import android.widget.*;
import net.kdt.pojavlaunch.*; import net.kdt.pojavlaunch.*;
import java.util.*; import java.util.*;
import android.content.*; import android.content.*;
import com.kdt.mcgui.*;
public class MineActivity extends AppCompatActivity implements View.OnClickListener public class MineActivity extends AppCompatActivity implements View.OnClickListener
{ {
private int topId = 150001; private int topId = 150001;
private boolean showBeforeView = true; private boolean showBeforeView = true;
private static FontChanger fontChanger;
private ImageButton menu; private ImageButton menu;
private LinearLayout content, undertop; private LinearLayout content, undertop;
private LayoutInflater li; private LayoutInflater li;
public static ViewGroup replaceFonts(Context ctx, ViewGroup viewTree) {
if (fontChanger == null) fontChanger = new FontChanger(ctx.getAssets(), "font/NotoSans-Bold.ttf");
return fontChanger.replaceFonts(viewTree);
}
public static View replaceFont(Context ctx, TextView view) {
if (fontChanger == null) fontChanger = new FontChanger(ctx.getAssets(), "font/NotoSans-Bold.ttf");
return fontChanger.replaceFont(view);
}
public ViewGroup replaceFonts(ViewGroup viewTree) {
return replaceFonts(this, viewTree);
}
public View replaceFont(TextView view) {
return replaceFont(this, view);
}
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
this.onCreate(savedInstanceState, true); this.onCreate(savedInstanceState, true);
@ -65,7 +46,7 @@ public class MineActivity extends AppCompatActivity implements View.OnClickListe
li.inflate(R.layout.top_bar, top, true); li.inflate(R.layout.top_bar, top, true);
li.inflate(R.layout.bottom_bar, btm, true); li.inflate(R.layout.bottom_bar, btm, true);
replaceFonts(btm); FontChanger.changeFonts(btm);
// replaceFont((TextView) top.findViewById(R.id.topbar_navmenu_changelang)); // replaceFont((TextView) top.findViewById(R.id.topbar_navmenu_changelang));
Spinner changeLangSpinner = ((Spinner) top.findViewById(R.id.topbar_navmenu_changelang)); Spinner changeLangSpinner = ((Spinner) top.findViewById(R.id.topbar_navmenu_changelang));
@ -107,7 +88,7 @@ public class MineActivity extends AppCompatActivity implements View.OnClickListe
} }
li.inflate(resource, content, true); li.inflate(resource, content, true);
replaceFonts(content); FontChanger.changeFonts(content);
} }
@Override @Override
@ -119,7 +100,7 @@ public class MineActivity extends AppCompatActivity implements View.OnClickListe
content.addView(view); content.addView(view);
if (view instanceof ViewGroup) { if (view instanceof ViewGroup) {
replaceFonts((ViewGroup) view); FontChanger.changeFonts((ViewGroup) view);
} }
} }

View File

@ -4,35 +4,31 @@ import android.content.res.*;
import android.graphics.*; import android.graphics.*;
import android.view.*; import android.view.*;
import android.widget.*; import android.widget.*;
import android.content.*;
import com.kdt.mcgui.*;
public class FontChanger public class FontChanger
{ {
private Typeface typeface; private static Typeface fNotoSans, fMinecraftTen;
public FontChanger(Typeface typeface) { public static void initFonts(Context ctx) {
this.typeface = typeface; fNotoSans = Typeface.createFromAsset(ctx.getAssets(), "font/NotoSans-Bold.ttf");
} fMinecraftTen = Typeface.createFromAsset(ctx.getAssets(), "font/minecraft-ten.ttf");
}
public FontChanger(AssetManager assets, String assetsFontFileName) {
typeface = Typeface.createFromAsset(assets, assetsFontFileName); public static void changeFonts(ViewGroup viewTree) {
} View child;
public ViewGroup replaceFonts(ViewGroup viewTree)
{
View child;
for(int i = 0; i < viewTree.getChildCount(); ++i) { for(int i = 0; i < viewTree.getChildCount(); ++i) {
child = viewTree.getChildAt(i); child = viewTree.getChildAt(i);
if (child instanceof ViewGroup) { if (child instanceof ViewGroup) {
replaceFonts((ViewGroup) child); changeFonts((ViewGroup) child);
} else if (child instanceof TextView) { } else if (child instanceof TextView) {
replaceFont((TextView) child); changeFont((TextView) child);
} }
} }
return viewTree; }
}
public View replaceFont(TextView view) { public static void changeFont(TextView view) {
view.setTypeface(typeface); view.setTypeface(view instanceof MineButton ? fMinecraftTen : fNotoSans);
return view;
} }
} }

View File

@ -37,6 +37,8 @@ public class PojavApplication extends Application
specialButtons[2].name = getString(R.string.control_primary); specialButtons[2].name = getString(R.string.control_primary);
specialButtons[3].name = getString(R.string.control_secondary); specialButtons[3].name = getString(R.string.control_secondary);
specialButtons[4].name = getString(R.string.control_mouse); specialButtons[4].name = getString(R.string.control_mouse);
FontChanger.initFonts(this);
} catch (Throwable th) { } catch (Throwable th) {
Intent ferrorIntent = new Intent(this, FatalErrorActivity.class); Intent ferrorIntent = new Intent(this, FatalErrorActivity.class);
ferrorIntent.putExtra("throwable", th); ferrorIntent.putExtra("throwable", th);

View File

@ -133,7 +133,7 @@ public class PojavLoginActivity extends AppCompatActivity
LinearLayout startScr = new LinearLayout(PojavLoginActivity.this); LinearLayout startScr = new LinearLayout(PojavLoginActivity.this);
LayoutInflater.from(PojavLoginActivity.this).inflate(R.layout.start_screen, startScr); LayoutInflater.from(PojavLoginActivity.this).inflate(R.layout.start_screen, startScr);
MineActivity.replaceFonts(PojavLoginActivity.this, startScr); FontChanger.changeFonts(startScr);
progress = (ProgressBar) startScr.findViewById(R.id.startscreenProgress); progress = (ProgressBar) startScr.findViewById(R.id.startscreenProgress);
//startScr.addView(progress); //startScr.addView(progress);

View File

@ -49,20 +49,20 @@
android:inputType="textPassword" android:inputType="textPassword"
android:layout_marginBottom="5dp"/> android:layout_marginBottom="5dp"/>
<Switch <CheckBox
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:text="@string/login_online_remember" android:layout_gravity="left"
android:layout_gravity="right" android:text="@string/login_online_check_keeplogin"
android:id="@+id/login_switch_remember"/> android:id="@+id/login_switch_remember"/>
<Switch <CheckBox
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_gravity="right" android:layout_gravity="left"
android:text="@string/login_offline_switch" android:text="@string/login_offline_label"
android:id="@+id/login_switch_offline"/> android:id="@+id/login_switch_offline"/>
<LinearLayout <LinearLayout
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@ -20,10 +20,12 @@
<string name="login_online_password_hint">Password</string> <string name="login_online_password_hint">Password</string>
<string name="login_online_password_question">Forgot password?</string> <string name="login_online_password_question">Forgot password?</string>
<string name="login_online_remember">Remember me?</string> <string name="login_online_remember">Remember me?</string>
<string name="login_online_check_keeplogin">Keep me logged in</string>
<string name="login_online_login_label">Login</string> <string name="login_online_login_label">Login</string>
<string name="login_online_create_account">(Create new account?)</string> <string name="login_online_create_account">(Create new account?)</string>
<string name="login_offline_switch">Offline account?</string> <string name="login_offline_switch">Offline account?</string>
<string name="login_offline_label">Login as offline account</string>
<string name="login_offline_alert_skip">Skip</string> <string name="login_offline_alert_skip">Skip</string>
<string name="login_error_short_username">Username must be at least 3 characters</string> <string name="login_error_short_username">Username must be at least 3 characters</string>