Optimized language, attr, themes, colors.

Change the way to launch tool activity.
This commit is contained in:
2022-04-01 14:24:45 +08:00
parent ef235a86aa
commit 6c662f8389
47 changed files with 208 additions and 260 deletions

View File

@@ -1,13 +1,10 @@
package com.fatapp.oxygentoolbox;
import android.content.Intent;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager;
import android.graphics.drawable.Icon;
import android.os.Bundle;
import android.view.View;
import android.view.Menu;
import com.fatapp.oxygentoolbox.util.ResourceUtil;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.navigation.NavigationView;
@@ -20,7 +17,6 @@ import androidx.drawerlayout.widget.DrawerLayout;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;
import java.util.Collections;
import java.util.Objects;
public class MainActivity extends AppCompatActivity {
@@ -39,6 +35,7 @@ public class MainActivity extends AppCompatActivity {
drawer = findViewById(R.id.drawer_layout);
navigationView = findViewById(R.id.nav_view);
mainActivity = this;
ResourceUtil.init(getApplication());
}
@Override

View File

@@ -97,7 +97,7 @@ public class FoldLayout extends LinearLayout implements View.OnClickListener {
public void onAnimationStart(Animator animation) {
super.onAnimationStart(animation);
LinearLayout linearLayout = defaultView.findViewById(R.id.fold_layout_linear_layout);
linearLayout.setBackground(getResources().getDrawable(R.drawable.top_radius_background));
linearLayout.setBackground(getContext().getDrawable(R.drawable.top_radius_background));
}
});
@@ -114,7 +114,7 @@ public class FoldLayout extends LinearLayout implements View.OnClickListener {
super.onAnimationEnd(animation);
if (!isShow) {
LinearLayout linearLayout = defaultView.findViewById(R.id.fold_layout_linear_layout);
linearLayout.setBackground(getResources().getDrawable(R.drawable.top_bottom_radius_background));
linearLayout.setBackground(getContext().getDrawable(R.drawable.top_bottom_radius_background));
}
}
});
@@ -144,7 +144,7 @@ public class FoldLayout extends LinearLayout implements View.OnClickListener {
isShow = true;
showAnimator.start();
ImageView imageView = defaultView.findViewById(R.id.arrow_icon);
imageView.setImageDrawable(getResources().getDrawable(R.drawable.right_to_down_arrow));
imageView.setImageDrawable(getContext().getDrawable(R.drawable.right_to_down_arrow));
AnimatedVectorDrawable animatedVectorDrawable = (AnimatedVectorDrawable) imageView.getDrawable();
animatedVectorDrawable.start();
}
@@ -154,7 +154,7 @@ public class FoldLayout extends LinearLayout implements View.OnClickListener {
isShow = false;
hideAnimator.start();
ImageView imageView = defaultView.findViewById(R.id.arrow_icon);
imageView.setImageDrawable(getResources().getDrawable(R.drawable.down_to_right_arrow));
imageView.setImageDrawable(getContext().getDrawable(R.drawable.down_to_right_arrow));
AnimatedVectorDrawable animatedVectorDrawable = (AnimatedVectorDrawable) imageView.getDrawable();
animatedVectorDrawable.start();
}

View File

@@ -16,7 +16,7 @@ import androidx.lifecycle.ViewModelProvider;
import com.fatapp.oxygentoolbox.R;
import com.fatapp.oxygentoolbox.layout.FoldLayout;
import com.fatapp.oxygentoolbox.util.BasicToolsLauncher;
import com.fatapp.oxygentoolbox.util.ToolsLauncher;
import com.fatapp.oxygentoolbox.util.ToolsList;
import java.io.IOException;
@@ -66,10 +66,9 @@ public class HomeFragment extends Fragment {
for (ToolsList.Button button : tool.getButtonList()) {
View toolButtonLayout = getLayoutInflater().inflate(R.layout.tool_button, null);
Button toolButton = toolButtonLayout.findViewById(R.id.tool_button);
toolButton.setText(button.getText());
toolButton.setOnClickListener(v -> BasicToolsLauncher.launch(button.getActivity(), getContext()));
toolButton.setOnClickListener(v -> ToolsLauncher.launch(getContext(), button.getActivity()));
autoLinefeedLayout.addView(toolButtonLayout);
}
@@ -90,28 +89,29 @@ public class HomeFragment extends Fragment {
foldLayoutsLinearLayout.addView(foldLayoutHead);
}
/*for (int i = 0; i < 10; i++) {
/*
for (int i = 0; i < 10; i++) {
View toolButton = getLayoutInflater().inflate(R.layout.tool_button, null);
((Button) toolButton.findViewById(R.id.toolButton)).setText("Button");
toolButton.findViewById(R.id.toolButton).setOnClickListener(v -> {
((Button) toolButton.findViewById(R.id.tool_button)).setText("Button");
toolButton.findViewById(R.id.tool_button).setOnClickListener(v -> {
BasicToolsLauncher.launch(0, getContext());
});
View foldLayoutBody = getLayoutInflater().inflate(R.layout.fold_layout_body, null);
ViewGroup layout_item_AutoLinefeedLayout = foldLayoutBody.findViewById(R.id.layout_item_AutoLinefeedLayout);
ViewGroup layout_item_AutoLinefeedLayout = foldLayoutBody.findViewById(R.id.auto_linefeed_layout);
layout_item_AutoLinefeedLayout.addView(toolButton);
List<View> viewList = new ArrayList<>();
viewList.add(foldLayoutBody);
View foldLayoutHead = getLayoutInflater().inflate(R.layout.fold_layout, null);
FoldLayout foldLayout = foldLayoutHead.findViewById(R.id.foldLayout);
((TextView) foldLayout.findViewById(R.id.foldLayoutTextView)).setText("FoldLayout_" + i);
FoldLayout foldLayout = foldLayoutHead.findViewById(R.id.fold_layout);
((TextView) foldLayout.findViewById(R.id.fold_layout_text_view)).setText("FoldLayout_" + i);
foldLayout.addItemView(viewList);
foldLayoutsLinearLayout = root.findViewById(R.id.foldLayoutsLinearLayout);
foldLayoutsLinearLayout.addView(foldLayoutHead);
}*/
}
*/
}

View File

@@ -1,20 +0,0 @@
package com.fatapp.oxygentoolbox.util;
import static androidx.core.content.ContextCompat.startActivity;
import android.content.Context;
import android.content.Intent;
import com.fatapp.oxygentoolbox.tools.TimeScreenActivity;
public class BasicToolsLauncher {
public static void launch(int activity, Context context) {
switch (activity) {
case 0:
startActivity(context, new Intent(context, TimeScreenActivity.class), null);
break;
case 1:
break;
}
}
}

View File

@@ -0,0 +1,31 @@
package com.fatapp.oxygentoolbox.util;
import android.app.Application;
import android.content.res.Resources;
public final class ResourceUtil {
private static Application sApp;
private static Resources sRes;
public static void init(Application app) {
sApp = app;
sRes = app.getResources();
}
public static Application getApplication() {
return sApp;
}
public static Resources getResources() {
return sRes;
}
public static String getString(int resId) {
return sRes.getString(resId);
}
public static int getColor(int resId) {
return sRes.getColor(resId);
}
}

View File

@@ -166,7 +166,7 @@ public class ToolsJson {
@SerializedName("text")
private Text text;
@SerializedName("activity")
private Integer activity;
private String activity;
public Text getText() {
return text;
@@ -176,11 +176,11 @@ public class ToolsJson {
this.text = text;
}
public Integer getActivity() {
public String getActivity() {
return activity;
}
public void setActivity(Integer activity) {
public void setActivity(String activity) {
this.activity = activity;
}

View File

@@ -0,0 +1,20 @@
package com.fatapp.oxygentoolbox.util;
import static androidx.core.content.ContextCompat.startActivity;
import android.content.Context;
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) {
try {
startActivity(context, new Intent(context, Class.forName(activity)), null);
} catch (ClassNotFoundException e) {
Toast.makeText(context, R.string.activity_class_not_found, Toast.LENGTH_LONG).show();
}
}
}

View File

@@ -46,9 +46,9 @@ 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();
language = ResourceUtil.getResources().getConfiguration().getLocales().get(0).getLanguage();
} else {
language = MainActivity.mainActivity.getResources().getConfiguration().locale.getLanguage();
language = ResourceUtil.getResources().getConfiguration().locale.getLanguage();
}
if (language.equals("zh")) {
return strings.getCn();
@@ -105,7 +105,7 @@ public class ToolsList {
public static class Button {
private String text;
private Integer activity;
private String activity;
public String getText() {
return text;
@@ -115,11 +115,11 @@ public class ToolsList {
this.text = text;
}
public Integer getActivity() {
public String getActivity() {
return activity;
}
public void setActivity(Integer activity) {
public void setActivity(String activity) {
this.activity = activity;
}
}