Skip to content

Commit

Permalink
[refactor] Set Java version to 1.8 and cleanup code
Browse files Browse the repository at this point in the history
Signed-off-by: Iscle <albertiscle9@gmail.com>
  • Loading branch information
iscle committed Nov 2, 2020
1 parent 0256135 commit f42493a
Show file tree
Hide file tree
Showing 31 changed files with 157 additions and 281 deletions.
5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ android {
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private void initUI() {

//是否显示模式选项
if(mManager.getController() == null){
((LinearLayout)findViewById(R.id.input_customize_keyboard_dialog_layout_mode)).setVisibility(View.GONE);
findViewById(R.id.input_customize_keyboard_dialog_layout_mode).setVisibility(View.GONE);
}

}
Expand Down Expand Up @@ -246,12 +246,7 @@ public void updataUI() {
}

public void setButtonCounts(final int counts){
this.textButtonSum.post(new Runnable() {
@Override
public void run() {
textButtonSum.setText(String.valueOf(counts));
}
});
this.textButtonSum.post(() -> textButtonSum.setText(String.valueOf(counts)));
}

private Timer mTimer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private void initUI() {
seekbarAlpha.setMax(GameButton.MAX_ALPHA_SIZE_PT);
seekbarCornerSize.setMax(GameButton.MAX_CORNOR_SIZE_PT);
seekbarTextSize.setMax(GameButton.MAX_TEXT_SIZE_SP);
spinnerDesign.setAdapter(new ArrayAdapter<String>(mContext, android.R.layout.simple_spinner_item, Arrays.asList(CkbThemeMarker.DESIGNS)));
spinnerDesign.setAdapter(new ArrayAdapter<>(mContext, android.R.layout.simple_spinner_item, Arrays.asList(CkbThemeMarker.DESIGNS)));


//设定监听
Expand Down Expand Up @@ -347,7 +347,7 @@ public void runWhenPositive() {

if (v == textMap1 || v == textMap2 || v == textMap3 || v == textMap4) {
int i = 0;
String n = "";
String n;
if (v == textMap1) {
n = textMap1.getText().toString();
} else if (v == textMap2) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ public boolean setAlphaSize(int alphaPt){
public boolean setKeyName(String str){
if(str != null){
this.setText(str);
this.keyName = new String(str);
this.keyName = str;
return true;
}else{
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ public void recordData(GameButton gb){
System.arraycopy(gb.getKeyTypes(),0,this.keyTypes,0,GameButton.MAX_KEYMAP_SIZE);
this.designIndex = gb.getDesignIndex();
this.cornerRadius = gb.getCornerRadius();
this.textColor = new String(gb.getTextColorHex());
this.textColor = gb.getTextColorHex();
System.arraycopy(gb.getColorHexs(),0,this.themeColors,0,CkbThemeRecorder.COLOR_INDEX_LENGTH);
this.isKeep = gb.isKeep();
this.isHide = gb.isHide();
System.arraycopy(gb.getKeyPos(),0,this.keyPos,0, 2);
System.arraycopy(gb.getKeySize(),0,this.keySize,0, 2);
this.alphaSize = gb.getAlphaSize();
this.keyName = new String(gb.getKeyName());
this.keyName = gb.getKeyName();
this.isViewerFollow = gb.isViewerFollow();
this.show = gb.getShow();
this.textSize = gb.getTextProgress();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class GlfwKeyMap implements KeyMap {
private HashMap<String,Integer> glfwKeyMap;

public GlfwKeyMap(){
glfwKeyMap = new HashMap<String, Integer>();
glfwKeyMap = new HashMap<>();
init();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class LwjglKeyMap implements KeyMap {
private HashMap<String,Integer> lwjglMap;

public LwjglKeyMap(){
lwjglMap = new HashMap<String, Integer>();
lwjglMap = new HashMap<>();
init();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class XKeyMap implements KeyMap , AppEvent , MouseMap {
private HashMap<String,Integer> xKeyMap;

public XKeyMap(){
xKeyMap = new HashMap<String, Integer>();
xKeyMap = new HashMap<>();
init();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,11 +330,7 @@ public void runWhenPositive(){
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

if(buttonView instanceof SwitchCompat && bindingViews.containsKey(buttonView)){
if(isChecked){
(Objects.requireNonNull(bindingViews.get(buttonView))).setEnable(true);
}else{
(Objects.requireNonNull(bindingViews.get(buttonView))).setEnable(false);
}
(Objects.requireNonNull(bindingViews.get(buttonView))).setEnable(isChecked);
}
if(buttonView == checkboxLock){
if(isChecked){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ private void applyCrossKey(View v, MotionEvent e) {
* |7|8|9|
* --------
*/
int location = 0; //九宫格位置标志 失去焦点时为 0
int location; //九宫格位置标志 失去焦点时为 0
//自左向右,第一列
if (shiftPos[0] < buttonWidth && shiftPos[0] >= 0) {

Expand Down Expand Up @@ -339,7 +339,7 @@ private void uiUpdate(int location, MotionEvent e) {

private void makeKeyEvent(int location, MotionEvent e) {

String keyName = "";
String keyName;

switch (location) {
case 1:
Expand Down Expand Up @@ -466,7 +466,6 @@ public void setSize(int s) {
p.width = s / 2;
p.height = s / 2;
crossKeyBoardExtend.requestLayout();
;
crossKeyBoardExtend.invalidate();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
int p = progress + MIN_SHEEL_SPEED_PROGRESS;
textWheelSpeed.setText(String.valueOf(p));
//设置滚轮速度
((OnscreenMouse) mInput).setWheelSpeed((int) (OnscreenMouse.DEFAULT_WHEEL_SPEED / p));
((OnscreenMouse) mInput).setWheelSpeed(OnscreenMouse.DEFAULT_WHEEL_SPEED / p);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ public boolean fitSystemLang(){
public void switchLang(@NonNull String tag){
boolean included = false;
for(String str : LanguageUtils.LANG_TAGS){
if(str.equals(tag)){
if (str.equals(tag)) {
included = true;
break;
}
}
if(!included){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;

Expand All @@ -29,13 +27,10 @@ public LanguageDialog(Context context){

private void initUI(){
listLanguages = findViewById(R.id.dialog_listview_languages);
listLanguages.setAdapter(new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_1, Arrays.asList(LanguageUtils.LANG_TAGS)));
listLanguages.setOnItemClickListener(new ListView.OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
ChangeLauncherLanguage(listLanguages.getAdapter().getItem(pos).toString());
dismiss();
}
listLanguages.setAdapter(new ArrayAdapter<>(mContext, android.R.layout.simple_list_item_1, Arrays.asList(LanguageUtils.LANG_TAGS)));
listLanguages.setOnItemClickListener((adapterView, view, pos, l) -> {
ChangeLauncherLanguage(listLanguages.getAdapter().getItem(pos).toString());
dismiss();
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ private String getAuthlibInjectorArgs() {
SettingJson.Account account = UserManager.getSelectedAccount(mSetting);

if(account.getType().equals(SettingJson.USER_TYPE_EXTERNAL)) {
args.append("-javaagent:" + AppManifest.AUTHLIB_INJETOR_JAR + "=" + account.getApiUrl());
args.append(" -Dauthlibinjector.yggdrasil.prefetched=" + account.getApiMeta());
args.append("-javaagent:").append(AppManifest.AUTHLIB_INJETOR_JAR).append("=").append(account.getApiUrl());
args.append(" -Dauthlibinjector.yggdrasil.prefetched=").append(account.getApiMeta());
return args.toString();
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.aof.mcinabox.launcher.download.authlib.Request;
import com.aof.mcinabox.launcher.runtime.RuntimeManager;
import com.aof.mcinabox.launcher.tipper.TipperManager;
import com.aof.mcinabox.launcher.tipper.support.TipperRunable;
import com.aof.mcinabox.launcher.user.UserManager;
import com.aof.mcinabox.utils.FileTool;
import com.aof.mcinabox.utils.MemoryUtils;
Expand Down Expand Up @@ -47,72 +46,42 @@ public SettingChecker(Context context, SettingJson setting, TipperManager manage

public void checkIfChoseUser(){
if(UserManager.getSelectedAccount(mSetting) == null){
mTipperManager.addTip(TipperManager.createTipBean(mContext, TipperManager.TIPPER_LEVEL_WARN, mContext.getString(R.string.tips_not_selected_user), new TipperRunable() {
@Override
public void run() {
DialogUtils.createSingleChoiceDialog(mContext,mContext.getString(R.string.title_warn),mContext.getString(R.string.tips_not_create_user_please_do_it),mContext.getString(R.string.title_ok),null);
}
},CHECKER_ID_NOT_CHOOSE_USER));
mTipperManager.addTip(TipperManager.createTipBean(mContext, TipperManager.TIPPER_LEVEL_WARN, mContext.getString(R.string.tips_not_selected_user), () -> DialogUtils.createSingleChoiceDialog(mContext,mContext.getString(R.string.title_warn),mContext.getString(R.string.tips_not_create_user_please_do_it),mContext.getString(R.string.title_ok),null),CHECKER_ID_NOT_CHOOSE_USER));
}else{
mTipperManager.removeTip(CHECKER_ID_NOT_CHOOSE_USER);
}
}
public void checkIfInstallRuntime(){
if(RuntimeManager.getPackInfo() == null){
mTipperManager.addTip(TipperManager.createTipBean(mContext, TipperManager.TIPPER_LEVEL_WARN, mContext.getString(R.string.tips_not_install_runtime), new TipperRunable() {
@Override
public void run() {
DialogUtils.createSingleChoiceDialog(mContext,mContext.getString(R.string.title_warn),mContext.getString(R.string.tips_not_install_runtime_please_do_it),mContext.getString(R.string.title_ok),null);
}
},CHECKER_ID_NOT_INSTALL_RUNTIME));
mTipperManager.addTip(TipperManager.createTipBean(mContext, TipperManager.TIPPER_LEVEL_WARN, mContext.getString(R.string.tips_not_install_runtime), () -> DialogUtils.createSingleChoiceDialog(mContext,mContext.getString(R.string.title_warn),mContext.getString(R.string.tips_not_install_runtime_please_do_it),mContext.getString(R.string.title_ok),null),CHECKER_ID_NOT_INSTALL_RUNTIME));
}else{
mTipperManager.removeTip(CHECKER_ID_NOT_INSTALL_RUNTIME);
}
}
public void checkIfInstallGame(){
if(FileTool.listChildDirFromTargetDir(AppManifest.MINECRAFT_VERSIONS).size() == 0){
mTipperManager.addTip(TipperManager.createTipBean(mContext, TipperManager.TIPPER_LEVEL_WARN, mContext.getString(R.string.tips_not_select_version), new TipperRunable() {
@Override
public void run() {
DialogUtils.createSingleChoiceDialog(mContext,mContext.getString(R.string.title_warn),mContext.getString(R.string.tips_not_selected_version_please_do_it),mContext.getString(R.string.title_ok),null);
}
},CHECKER_ID_NOT_INSTALL_GAME));
mTipperManager.addTip(TipperManager.createTipBean(mContext, TipperManager.TIPPER_LEVEL_WARN, mContext.getString(R.string.tips_not_select_version), () -> DialogUtils.createSingleChoiceDialog(mContext,mContext.getString(R.string.title_warn),mContext.getString(R.string.tips_not_selected_version_please_do_it),mContext.getString(R.string.title_ok),null),CHECKER_ID_NOT_INSTALL_GAME));
}else{
mTipperManager.removeTip(CHECKER_ID_NOT_INSTALL_GAME);
}
}
public void checkMenmrySize(){
if(mSetting.getConfigurations().getMaxMemory() < 256){
mTipperManager.addTip(TipperManager.createTipBean(mContext, TipperManager.TIPPER_LEVEL_NOTE, mContext.getString(R.string.tips_available_memory_low), new TipperRunable() {
@Override
public void run() {
DialogUtils.createSingleChoiceDialog(mContext,mContext.getString(R.string.title_note),mContext.getString(R.string.tips_please_set_more_memory),mContext.getString(R.string.title_ok),null);
}
},CHECKER_ID_MEMORY_LOW));
mTipperManager.addTip(TipperManager.createTipBean(mContext, TipperManager.TIPPER_LEVEL_NOTE, mContext.getString(R.string.tips_available_memory_low), () -> DialogUtils.createSingleChoiceDialog(mContext,mContext.getString(R.string.title_note),mContext.getString(R.string.tips_please_set_more_memory),mContext.getString(R.string.title_ok),null),CHECKER_ID_MEMORY_LOW));
}else{
mTipperManager.removeTip(CHECKER_ID_MEMORY_LOW);
}

if(mSetting.getConfigurations().getMaxMemory() > MemoryUtils.getDynamicHeapSize(mContext) * 2 - 20 || mSetting.getConfigurations().getMaxMemory() > MemoryUtils.getTotalMemoryMB(mContext)){
mTipperManager.addTip(TipperManager.createTipBean(mContext, TipperManager.TIPPER_LEVEL_NOTE, mContext.getString(R.string.tips_available_memory_over), new TipperRunable() {
@Override
public void run() {
DialogUtils.createSingleChoiceDialog(mContext,mContext.getString(R.string.title_note),mContext.getString(R.string.tips_please_set_less_memory),mContext.getString(R.string.title_ok),null);
}
},CHECKER_ID_MEMORY_OVER));
mTipperManager.addTip(TipperManager.createTipBean(mContext, TipperManager.TIPPER_LEVEL_NOTE, mContext.getString(R.string.tips_available_memory_over), () -> DialogUtils.createSingleChoiceDialog(mContext,mContext.getString(R.string.title_note),mContext.getString(R.string.tips_please_set_less_memory),mContext.getString(R.string.title_ok),null),CHECKER_ID_MEMORY_OVER));
}else{
mTipperManager.removeTip(CHECKER_ID_MEMORY_OVER);
}
}

public void checkIfDisableFileCheck(){
if(mSetting.getConfigurations().isNotCheckGame()){
mTipperManager.addTip(TipperManager.createTipBean(mContext, TipperManager.TIPPER_LEVEL_NOTE, mContext.getString(R.string.title_not_check_minecraft), new TipperRunable() {
@Override
public void run() {
DialogUtils.createSingleChoiceDialog(mContext,mContext.getString(R.string.title_note),mContext.getString(R.string.tips_please_turn_on_minecraft_check),mContext.getString(R.string.title_ok),null);
}
},CHECKER_ID_NOT_CHECK_GAME));
mTipperManager.addTip(TipperManager.createTipBean(mContext, TipperManager.TIPPER_LEVEL_NOTE, mContext.getString(R.string.title_not_check_minecraft), () -> DialogUtils.createSingleChoiceDialog(mContext,mContext.getString(R.string.title_note),mContext.getString(R.string.tips_please_turn_on_minecraft_check),mContext.getString(R.string.title_ok),null),CHECKER_ID_NOT_CHECK_GAME));
}else{
mTipperManager.removeTip(CHECKER_ID_NOT_CHECK_GAME);
}
Expand All @@ -122,17 +91,12 @@ public void checkAuthlibInjector(){
SettingJson.Account account = UserManager.getSelectedAccount(mSetting);
File file = new File(AppManifest.AUTHLIB_INJETOR_JAR);
if(!file.exists() && account != null && account.type.equals(SettingJson.USER_TYPE_EXTERNAL)){
mTipperManager.addTip(TipperManager.createTipBean(mContext, TipperManager.TIPPER_LEVEL_ERROR, mContext.getString(R.string.title_missing_authlib), new TipperRunable() {
mTipperManager.addTip(TipperManager.createTipBean(mContext, TipperManager.TIPPER_LEVEL_ERROR, mContext.getString(R.string.title_missing_authlib), () -> DialogUtils.createBothChoicesDialog(mContext,mContext.getString(R.string.title_error),mContext.getString(R.string.tips_please_download_authlib_injector),mContext.getString(R.string.title_ok),mContext.getString(R.string.title_cancel),new DialogSupports(){
@Override
public void run() {
DialogUtils.createBothChoicesDialog(mContext,mContext.getString(R.string.title_error),mContext.getString(R.string.tips_please_download_authlib_injector),mContext.getString(R.string.title_ok),mContext.getString(R.string.title_cancel),new DialogSupports(){
@Override
public void runWhenPositive(){
new Request(mContext).requestLastestVersion();
}
});
public void runWhenPositive(){
new Request(mContext).requestLastestVersion();
}
},CHECKER_ID_MISSING_AUTHLIB));
}),CHECKER_ID_MISSING_AUTHLIB));
}else{
mTipperManager.removeTip(CHECKER_ID_MISSING_AUTHLIB);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,11 @@ public View getView(final int position, View convertView, ViewGroup parent) {

viewHolder.context = tipperList.get(position).getContext();
viewHolder.tip.setText(tipperList.get(position).getTipper_info());
viewHolder.help.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(tipperList.get(position).getTipper_runable() != null){
tipperList.get(position).getTipper_runable().run();
}
}});
viewHolder.help.setOnClickListener(v -> {
if(tipperList.get(position).getTipper_runable() != null){
tipperList.get(position).getTipper_runable().run();
}
});
return convertView;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public interface TipperRunable {

public void run();
void run();

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.content.Context;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
Expand Down Expand Up @@ -58,12 +57,9 @@ public void onCreate() {
buttonSnapshot = layout_installversion.findViewById(R.id.radiobutton_type_snapshot);
buttonOld = layout_installversion.findViewById(R.id.radiobutton_type_old);
listVersionsOnline = layout_installversion.findViewById(R.id.list_minecraft_manifest);
listVersionsOnline.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
selectedVersionPos = pos;
textSelectedVersion.setText(listVersionsOnline.getAdapter().getItem(pos).toString());
}
listVersionsOnline.setOnItemClickListener((adapterView, view, pos, l) -> {
selectedVersionPos = pos;
textSelectedVersion.setText(listVersionsOnline.getAdapter().getItem(pos).toString());
});

groupVersionType.setOnCheckedChangeListener(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public void onClick(View v) {
String[] files;
final String[] tmp2;
if(tmp.size() != 0){
files = tmp.toArray(new String[tmp.size()]);
files = tmp.toArray(new String[0]);
tmp2 = new String[Objects.requireNonNull(files).length + 1];
System.arraycopy(files,0,tmp2,1,files.length);
}else{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,7 @@ public static void clearLegalData(Context context){
public static void setAccountSelected(String username){
SettingJson.Account a = getAccountByUsername(MainActivity.Setting,username);
for(SettingJson.Account account : MainActivity.Setting.getAccounts()){
if(account == a){
account.setSelected(true);
}else{
account.setSelected(false);
}
account.setSelected(account == a);
}
}

Expand Down
Loading

0 comments on commit f42493a

Please sign in to comment.