mirror of
https://github.com/FatttSnake/OxygenToolbox.git
synced 2026-04-06 12:31:27 +08:00
Added launch page switch, LibrariesActivity, setting fragment to about fragment action.
This commit is contained in:
@@ -1,4 +0,0 @@
|
||||
package com.fatapp.oxygentoolbox.util;
|
||||
|
||||
public class Config {
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
package com.fatapp.oxygentoolbox.util;
|
||||
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.annotations.JsonAdapter;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.google.gson.stream.JsonReader;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
public class DependenciesJson {
|
||||
|
||||
@SerializedName("metadata")
|
||||
private MetadataDTO metadata;
|
||||
@SerializedName("libraries")
|
||||
private List<LibrariesDTO> libraries;
|
||||
@SerializedName("licenses")
|
||||
@JsonAdapter(RawStringJsonAdapter.class)
|
||||
private String licenses;
|
||||
|
||||
public MetadataDTO getMetadata() {
|
||||
return metadata;
|
||||
}
|
||||
|
||||
public List<LibrariesDTO> getLibraries() {
|
||||
return libraries;
|
||||
}
|
||||
|
||||
public String getLicenses() {
|
||||
return licenses;
|
||||
}
|
||||
|
||||
public static class MetadataDTO {
|
||||
@SerializedName("generated")
|
||||
private String generated;
|
||||
|
||||
public String getGenerated() {
|
||||
return generated;
|
||||
}
|
||||
}
|
||||
|
||||
public static class LibrariesDTO {
|
||||
@SerializedName("uniqueId")
|
||||
private String uniqueId;
|
||||
@SerializedName("funding")
|
||||
private List<?> funding;
|
||||
@SerializedName("developers")
|
||||
private List<DevelopersDTO> developers;
|
||||
@SerializedName("artifactVersion")
|
||||
private String artifactVersion;
|
||||
@SerializedName("description")
|
||||
private String description;
|
||||
@SerializedName("name")
|
||||
private String name;
|
||||
@SerializedName("licenses")
|
||||
private List<String> licenses;
|
||||
@SerializedName("scm")
|
||||
private ScmDTO scm;
|
||||
@SerializedName("website")
|
||||
private String website;
|
||||
|
||||
public String getUniqueId() {
|
||||
return uniqueId;
|
||||
}
|
||||
|
||||
public List<?> getFunding() {
|
||||
return funding;
|
||||
}
|
||||
|
||||
public List<DevelopersDTO> getDevelopers() {
|
||||
return developers;
|
||||
}
|
||||
|
||||
public String getDevelopersStr() {
|
||||
StringJoiner stringJoiner = new StringJoiner(", ");
|
||||
for (DevelopersDTO developer : getDevelopers()) {
|
||||
stringJoiner.add(developer.getName());
|
||||
}
|
||||
|
||||
return stringJoiner.toString();
|
||||
}
|
||||
|
||||
public String getArtifactVersion() {
|
||||
return artifactVersion;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public List<String> getLicenses() {
|
||||
return licenses;
|
||||
}
|
||||
|
||||
public ScmDTO getScm() {
|
||||
return scm;
|
||||
}
|
||||
|
||||
public String getWebsite() {
|
||||
return website;
|
||||
}
|
||||
|
||||
public static class ScmDTO {
|
||||
@SerializedName("connection")
|
||||
private String connection;
|
||||
@SerializedName("url")
|
||||
private String url;
|
||||
|
||||
public String getConnection() {
|
||||
return connection;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
}
|
||||
|
||||
public static class DevelopersDTO {
|
||||
@SerializedName("organisationUrl")
|
||||
private String organisationUrl;
|
||||
@SerializedName("name")
|
||||
private String name;
|
||||
|
||||
public String getOrganisationUrl() {
|
||||
return organisationUrl;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
public static class RawStringJsonAdapter extends TypeAdapter<String> {
|
||||
|
||||
@Override
|
||||
public void write(JsonWriter out, String value) throws IOException {
|
||||
out.jsonValue(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String read(JsonReader in) {
|
||||
return JsonParser.parseReader(in).toString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package com.fatapp.oxygentoolbox.util;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class LicenseJson {
|
||||
@SerializedName("content")
|
||||
private String content;
|
||||
@SerializedName("hash")
|
||||
private String hash;
|
||||
@SerializedName("internalHash")
|
||||
private String internalHash;
|
||||
@SerializedName("url")
|
||||
private String url;
|
||||
@SerializedName("spdxId")
|
||||
private String spdxId;
|
||||
@SerializedName("name")
|
||||
private String name;
|
||||
|
||||
public String getContent() {
|
||||
return content;
|
||||
}
|
||||
|
||||
public String getHash() {
|
||||
return hash;
|
||||
}
|
||||
|
||||
public String getInternalHash() {
|
||||
return internalHash;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public String getSpdxId() {
|
||||
return spdxId;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +1,25 @@
|
||||
package com.fatapp.oxygentoolbox.util;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.LocaleList;
|
||||
import android.text.TextUtils;
|
||||
import android.util.DisplayMetrics;
|
||||
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.appcompat.view.ContextThemeWrapper;
|
||||
import androidx.core.os.ConfigurationCompat;
|
||||
import androidx.core.os.LocaleListCompat;
|
||||
|
||||
import com.fatapp.oxygentoolbox.R;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
public class MultiLanguageUtils {
|
||||
|
||||
public static Context attachBaseContext(Context context) {
|
||||
String locale;
|
||||
if (SharedPreferencesUtils.isNull()) {
|
||||
locale = "default";
|
||||
} else {
|
||||
locale = SharedPreferencesUtils.getLocale();
|
||||
}
|
||||
String language;
|
||||
String country;
|
||||
if (!locale.equals("default")) {
|
||||
language = locale.substring(0, locale.indexOf("_"));
|
||||
country = locale.substring(locale.indexOf("_") + 1);
|
||||
} else {
|
||||
language = ResourceUtil.getSystemLocale().get(0).getLanguage();
|
||||
country = ResourceUtil.getSystemLocale().get(0).getCountry();
|
||||
}
|
||||
Locale locale = SharedPreferencesUtils.getLanguage();
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
|
||||
return createConfigurationContext(context, language, country);
|
||||
return createConfigurationContext(context, locale.getLanguage(), locale.getCountry());
|
||||
} else {
|
||||
return updateConfiguration(context, language, country);
|
||||
return updateConfiguration(context, locale.getLanguage(), locale.getCountry());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -109,4 +109,12 @@ public final class ResourceUtil {
|
||||
Configuration configuration = Resources.getSystem().getConfiguration();
|
||||
return ConfigurationCompat.getLocales(configuration);
|
||||
}
|
||||
|
||||
public static int dpToPx(float dp) {
|
||||
return (int) (dp * getDisplayMetrics().density + 0.5f);
|
||||
}
|
||||
|
||||
public static float pxToDp(int px) {
|
||||
return px / getDisplayMetrics().density + 0.5f;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,11 @@ import android.content.SharedPreferences;
|
||||
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import com.fatapp.oxygentoolbox.R;
|
||||
|
||||
import java.util.Locale;
|
||||
import java.util.Objects;
|
||||
|
||||
public class SharedPreferencesUtils {
|
||||
private static SharedPreferences preferences;
|
||||
|
||||
@@ -12,11 +17,31 @@ public class SharedPreferencesUtils {
|
||||
preferences = PreferenceManager.getDefaultSharedPreferences(app);
|
||||
}
|
||||
|
||||
public static String getLocale() {
|
||||
return preferences.getString("app_language", "default");
|
||||
public static Locale getLanguage() {
|
||||
String languagePreference;
|
||||
String language;
|
||||
String country;
|
||||
if (SharedPreferencesUtils.isNull() ||
|
||||
(languagePreference = preferences.getString(ResourceUtil.getString(R.string.setting_language_key), ResourceUtil.getString(R.string.setting_language_default_value))).equals(ResourceUtil.getString(R.string.setting_language_default_value))) {
|
||||
language = Objects.requireNonNull(ResourceUtil.getSystemLocale().get(0)).getLanguage();
|
||||
country = Objects.requireNonNull(ResourceUtil.getSystemLocale().get(0)).getCountry();
|
||||
} else {
|
||||
language = languagePreference.substring(0, languagePreference.indexOf("_"));
|
||||
country = languagePreference.substring(languagePreference.indexOf("_") + 1);
|
||||
}
|
||||
|
||||
return new Locale(language, country);
|
||||
}
|
||||
|
||||
public static boolean isNull() {
|
||||
return preferences == null;
|
||||
}
|
||||
|
||||
public static LaunchPage getLaunchPage() {
|
||||
return LaunchPage.valueOf(preferences.getString(ResourceUtil.getString(R.string.setting_launch_page_key), ResourceUtil.getString(R.string.setting_launch_page_default_value)));
|
||||
}
|
||||
|
||||
public enum LaunchPage {
|
||||
tools,favourites
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import android.content.Intent;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.fatapp.oxygentoolbox.R;
|
||||
import com.fatapp.oxygentoolbox.tools.TimeScreenActivity;
|
||||
|
||||
public class ToolsLauncher {
|
||||
public static void launch(Context context, String activity) {
|
||||
|
||||
@@ -1,28 +1,25 @@
|
||||
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;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
public class ToolsList {
|
||||
private static List<Tool> toolList = new ArrayList<>();
|
||||
|
||||
public static void init(InputStream file) throws IOException {
|
||||
int i;
|
||||
String str;
|
||||
StringBuilder jsonStringBuilder = new StringBuilder();
|
||||
|
||||
while ((i = file.read()) != -1) {
|
||||
jsonStringBuilder.append((char) i);
|
||||
InputStreamReader inputStreamReader = new InputStreamReader(file);
|
||||
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
|
||||
while ((str = bufferedReader.readLine()) != null) {
|
||||
jsonStringBuilder.append(str);
|
||||
}
|
||||
file.close();
|
||||
List<ToolsJson> toolsJsonList = new Gson().fromJson(jsonStringBuilder.toString(), new TypeToken<List<ToolsJson>>() {
|
||||
@@ -44,13 +41,7 @@ public class ToolsList {
|
||||
}
|
||||
|
||||
private static String getLocale(Locales strings) {
|
||||
String language;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
language = ResourceUtil.getResources().getConfiguration().getLocales().get(0).getLanguage();
|
||||
} else {
|
||||
language = ResourceUtil.getResources().getConfiguration().locale.getLanguage();
|
||||
}
|
||||
if (language.equals("zh")) {
|
||||
if (SharedPreferencesUtils.getLanguage().getLanguage().equals("zh")) {
|
||||
return strings.getCn();
|
||||
}
|
||||
return strings.getEn();
|
||||
|
||||
Reference in New Issue
Block a user