mirror of
https://github.com/FatttSnake/OxygenToolbox.git
synced 2026-04-06 08:21:27 +08:00
Optimized language, themes, colors.
Added splashscreen, SplashActivity.
This commit is contained in:
@@ -7,14 +7,13 @@ import android.graphics.drawable.Icon;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.Menu;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.fatapp.oxygentoolbox.util.ToolsList;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.google.android.material.navigation.NavigationView;
|
||||
|
||||
import androidx.navigation.NavController;
|
||||
import androidx.navigation.Navigation;
|
||||
import androidx.navigation.fragment.NavHostFragment;
|
||||
import androidx.navigation.ui.AppBarConfiguration;
|
||||
import androidx.navigation.ui.NavigationUI;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
@@ -22,21 +21,24 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Objects;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
public static AppCompatActivity mainActivity;
|
||||
|
||||
private AppBarConfiguration mAppBarConfiguration;
|
||||
|
||||
private Toolbar toolbar;
|
||||
private FloatingActionButton fab;
|
||||
private DrawerLayout drawer;
|
||||
private NavigationView navigationView;
|
||||
|
||||
private void initView() {
|
||||
toolbar = findViewById(R.id.toolbar);
|
||||
fab = findViewById(R.id.fab);
|
||||
drawer = findViewById(R.id.drawer_layout);
|
||||
navigationView = findViewById(R.id.nav_view);
|
||||
mainActivity = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -48,7 +50,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
initView();
|
||||
initLayout();
|
||||
|
||||
shortCutCreateTest();
|
||||
// shortCutCreateTest();
|
||||
}
|
||||
|
||||
private void initLayout() {
|
||||
@@ -73,17 +75,18 @@ public class MainActivity extends AppCompatActivity {
|
||||
mAppBarConfiguration = new AppBarConfiguration.Builder(R.id.nav_home)
|
||||
.setOpenableLayout(drawer)
|
||||
.build();
|
||||
NavController navController = Navigation.findNavController(this, R.id.nav_host_fragment);
|
||||
NavController navController = ((NavHostFragment) Objects.requireNonNull(getSupportFragmentManager().findFragmentById(R.id.nav_host_fragment))).getNavController();
|
||||
NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);
|
||||
NavigationUI.setupWithNavController(navigationView, navController);
|
||||
}
|
||||
|
||||
/*
|
||||
private void shortCutCreateTest() {
|
||||
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N_MR1) {
|
||||
return;
|
||||
}
|
||||
Intent intent = new Intent();
|
||||
intent.setAction("android.intent.action.VIEW");
|
||||
intent.setAction("android.intent.action.MAIN");
|
||||
intent.setClassName("com.fatapp.oxygentoolbox",
|
||||
"com.fatapp.oxygentoolbox.MainActivity");
|
||||
ShortcutInfo.Builder builder;
|
||||
@@ -97,6 +100,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
|
||||
shortcutManager.addDynamicShortcuts(Collections.singletonList(builder.build()));
|
||||
}
|
||||
*/
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
|
||||
@@ -1,14 +1,24 @@
|
||||
package com.fatapp.oxygentoolbox;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.splashscreen.SplashScreen;
|
||||
|
||||
@SuppressLint("CustomSplashScreen")
|
||||
public class SplashActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
// Handle the splash screen transition.
|
||||
SplashScreen splashScreen = SplashScreen.installSplashScreen(this);
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_splash);
|
||||
|
||||
startActivity(new Intent(getApplicationContext(), MainActivity.class));
|
||||
finish();
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,6 @@ import com.fatapp.oxygentoolbox.util.ToolsList;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class HomeFragment extends Fragment {
|
||||
|
||||
@@ -57,7 +56,7 @@ public class HomeFragment extends Fragment {
|
||||
ToolsList.init(getResources().getAssets().open("json/BasicTools.json"));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
Toast.makeText(getContext(), "初始化工具集失败", Toast.LENGTH_LONG).show();
|
||||
Toast.makeText(getContext(), R.string.init_tools_failed, Toast.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -70,9 +69,7 @@ public class HomeFragment extends Fragment {
|
||||
|
||||
Button toolButton = toolButtonLayout.findViewById(R.id.tool_button);
|
||||
toolButton.setText(button.getText());
|
||||
toolButton.setOnClickListener(v -> {
|
||||
BasicToolsLauncher.launch(button.getActivity(), getContext());
|
||||
});
|
||||
toolButton.setOnClickListener(v -> BasicToolsLauncher.launch(button.getActivity(), getContext()));
|
||||
autoLinefeedLayout.addView(toolButtonLayout);
|
||||
}
|
||||
|
||||
@@ -84,7 +81,7 @@ public class HomeFragment extends Fragment {
|
||||
((TextView) foldLayout.findViewById(R.id.fold_layout_text_view)).setText(tool.getFoldLayoutTitle());
|
||||
|
||||
TextView foldLayoutIcon = foldLayout.findViewById(R.id.fold_layout_icon);
|
||||
foldLayoutIcon.setTypeface(Typeface.createFromAsset(Objects.requireNonNull(getContext()).getAssets(), tool.getFont()));
|
||||
foldLayoutIcon.setTypeface(Typeface.createFromAsset(requireContext().getAssets(), tool.getFont()));
|
||||
foldLayoutIcon.setText(tool.getIcon());
|
||||
|
||||
foldLayout.addItemView(viewList);
|
||||
|
||||
11
app/src/main/java/com/fatapp/oxygentoolbox/util/Locales.java
Normal file
11
app/src/main/java/com/fatapp/oxygentoolbox/util/Locales.java
Normal file
@@ -0,0 +1,11 @@
|
||||
package com.fatapp.oxygentoolbox.util;
|
||||
|
||||
public interface Locales {
|
||||
String getCn();
|
||||
|
||||
void setCn(String cn);
|
||||
|
||||
String getEn();
|
||||
|
||||
void setEn(String en);
|
||||
}
|
||||
@@ -108,67 +108,55 @@ public class ToolsJson {
|
||||
this.buttons = buttons;
|
||||
}
|
||||
|
||||
public static class Title {
|
||||
public static class Title implements Locales {
|
||||
@SerializedName("cn")
|
||||
private String cn;
|
||||
@SerializedName("tc")
|
||||
private String tc;
|
||||
@SerializedName("en")
|
||||
private String en;
|
||||
|
||||
@Override
|
||||
public String getCn() {
|
||||
return cn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCn(String cn) {
|
||||
this.cn = cn;
|
||||
}
|
||||
|
||||
public String getTc() {
|
||||
return tc;
|
||||
}
|
||||
|
||||
public void setTc(String tc) {
|
||||
this.tc = tc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEn() {
|
||||
return en;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEn(String en) {
|
||||
this.en = en;
|
||||
}
|
||||
}
|
||||
|
||||
public static class Desc {
|
||||
public static class Desc implements Locales {
|
||||
@SerializedName("cn")
|
||||
private String cn;
|
||||
@SerializedName("tc")
|
||||
private String tc;
|
||||
@SerializedName("en")
|
||||
private String en;
|
||||
|
||||
@Override
|
||||
public String getCn() {
|
||||
return cn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCn(String cn) {
|
||||
this.cn = cn;
|
||||
}
|
||||
|
||||
public String getTc() {
|
||||
return tc;
|
||||
}
|
||||
|
||||
public void setTc(String tc) {
|
||||
this.tc = tc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEn() {
|
||||
return en;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEn(String en) {
|
||||
this.en = en;
|
||||
}
|
||||
@@ -196,34 +184,28 @@ public class ToolsJson {
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
public static class Text {
|
||||
public static class Text implements Locales {
|
||||
@SerializedName("cn")
|
||||
private String cn;
|
||||
@SerializedName("tc")
|
||||
private String tc;
|
||||
@SerializedName("en")
|
||||
private String en;
|
||||
|
||||
@Override
|
||||
public String getCn() {
|
||||
return cn;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCn(String cn) {
|
||||
this.cn = cn;
|
||||
}
|
||||
|
||||
public String getTc() {
|
||||
return tc;
|
||||
}
|
||||
|
||||
public void setTc(String tc) {
|
||||
this.tc = tc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEn() {
|
||||
return en;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setEn(String en) {
|
||||
this.en = en;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
package com.fatapp.oxygentoolbox.util;
|
||||
|
||||
import android.os.Build;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.fatapp.oxygentoolbox.MainActivity;
|
||||
import com.fatapp.oxygentoolbox.ui.home.HomeFragment;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
@@ -7,6 +12,7 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class ToolsList {
|
||||
private static List<Tool> toolList = new ArrayList<>();
|
||||
@@ -19,16 +25,17 @@ public class ToolsList {
|
||||
jsonStringBuilder.append((char) i);
|
||||
}
|
||||
file.close();
|
||||
List<ToolsJson> toolsJsonList = new Gson().fromJson(jsonStringBuilder.toString(), new TypeToken<List<ToolsJson>>(){}.getType());
|
||||
List<ToolsJson> toolsJsonList = new Gson().fromJson(jsonStringBuilder.toString(), new TypeToken<List<ToolsJson>>() {
|
||||
}.getType());
|
||||
|
||||
for (ToolsJson toolsJson : toolsJsonList) {
|
||||
Tool tool = new Tool();
|
||||
tool.setFont(toolsJson.getContent().getFont());
|
||||
tool.setIcon(toolsJson.getContent().getIcon());
|
||||
tool.setFoldLayoutTitle(toolsJson.getContent().getTitle().getCn());
|
||||
tool.setFoldLayoutTitle(getLocale(toolsJson.getContent().getTitle()));
|
||||
for (ToolsJson.Content.Buttons cButton : toolsJson.getContent().getButtons()) {
|
||||
Button button = new Button();
|
||||
button.setText(cButton.getText().getCn());
|
||||
button.setText(getLocale(cButton.getText()));
|
||||
button.setActivity(cButton.getActivity());
|
||||
tool.buttonList.add(button);
|
||||
}
|
||||
@@ -36,6 +43,19 @@ public class ToolsList {
|
||||
}
|
||||
}
|
||||
|
||||
private static String getLocale(Locales strings) {
|
||||
String language;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
language = MainActivity.mainActivity.getResources().getConfiguration().getLocales().get(0).getLanguage();
|
||||
} else {
|
||||
language = MainActivity.mainActivity.getResources().getConfiguration().locale.getLanguage();
|
||||
}
|
||||
if (language.equals("zh")) {
|
||||
return strings.getCn();
|
||||
}
|
||||
return strings.getEn();
|
||||
}
|
||||
|
||||
public static List<Tool> getToolList() {
|
||||
return toolList;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user