Skip to content

Commit

Permalink
Update v7.3
Browse files Browse the repository at this point in the history
  • Loading branch information
YangDai2003 committed Jan 20, 2025
1 parent ed29680 commit 3b4c0c2
Show file tree
Hide file tree
Showing 47 changed files with 486 additions and 140 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,9 @@ It integrates multiple practical functions to provide you with all calculation a
13. Mathematical statistics:
- Given multiple values entered, the greatest common divisor, least common multiple, arithmetic mean, geometric mean, harmonic mean, square mean, variance, standard deviation, and sum are given.

14. Ruler:
- Measure small objects using on-screen scales, supports both inch and centimeter units.

*** Also provides a variety of widgets for simple calculations without opening the software.

*** Also provides floating window function.
Expand Down
5 changes: 4 additions & 1 deletion README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,14 @@
- 轻松求解线性方程和一元二次方程。

12. 购物助手:
- 快速计算折扣和单价。
- 快速计算折扣和单价。

13. 数学统计:
- 根据输入的多个数值,给出最大公约数、最小公倍数、算术平均数、几何平均数、调和平均数、平方平均数、方差、标准差和总和。

14. 刻度尺:
- 通过屏幕上的刻度,测量小物件的长度,支持英寸和厘米两种单位。

*** 还提供多种桌面小部件,无需打开软件即可进行简单运算。

*** 同时提供了悬浮窗功能,在任意位置进行计算。
Expand Down
9 changes: 6 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ android {
applicationId "com.yangdai.calc"
minSdk 28
targetSdk 35
versionCode 62
versionName '7.2'
resourceConfigurations += ["en", "zh", "de"]
versionCode 63
versionName '7.3'
}

androidResources {
generateLocaleConfig true
}

buildTypes {
Expand Down
9 changes: 6 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
<uses-permission android:name="android.permission.SYSTEM_OVERLAY_WINDOW" />
<!-- 适配android 11无法唤起第三方apk -->
<uses-permission android:name="android.permission.SYSTEM_OVERLAY_WINDOW" /> <!-- 适配android 11无法唤起第三方apk -->
<uses-permission android:name="com.google.android.gms.permission.AD_ID" />

<queries>
Expand All @@ -34,12 +33,16 @@
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:localeConfig="@xml/locales_config"
android:resizeableActivity="true"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme"
tools:targetApi="tiramisu">
<activity
android:name=".main.toolbox.functions.ruler.RulerActivity"
android:exported="false"
android:label="@string/ruler"
android:parentActivityName=".main.MainActivity" />
<activity
android:name=".main.toolbox.functions.programmer.ProgrammerActivity"
android:exported="false"
Expand Down
11 changes: 10 additions & 1 deletion app/src/main/java/com/yangdai/calc/main/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,14 @@
import android.widget.ImageView;
import android.widget.Toast;

import androidx.activity.EdgeToEdge;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.fragment.app.Fragment;
import androidx.preference.PreferenceManager;
import androidx.recyclerview.widget.RecyclerView;
Expand Down Expand Up @@ -142,8 +146,13 @@ private void requestOverlayDisplayPermission() {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setStatusBarColor(SurfaceColors.SURFACE_0.getColor(this));
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
return insets;
});

defaultSharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
defaultSharedPrefs.registerOnSharedPreferenceChangeListener(this);
Expand Down
142 changes: 76 additions & 66 deletions app/src/main/java/com/yangdai/calc/main/toolbox/ToolBoxFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.yangdai.calc.main.toolbox.functions.bmi.BMIActivity;
import com.yangdai.calc.main.toolbox.functions.chinese.ChineseNumberConversionActivity;
import com.yangdai.calc.main.toolbox.functions.programmer.ProgrammerActivity;
import com.yangdai.calc.main.toolbox.functions.ruler.RulerActivity;
import com.yangdai.calc.main.toolbox.functions.shopping.ShoppingActivity;
import com.yangdai.calc.main.toolbox.functions.algebra.StatisticsActivity;
import com.yangdai.calc.R;
Expand All @@ -48,22 +49,7 @@ public class ToolBoxFragment extends Fragment {
ToolBoxAdapter adapter;
private List<ToolBoxItem> newData;
private List<ToolBoxItem> data;
private static final String ORDER = "0/1/2/3/4/5/6/7/8/9/10/11/12/13";
boolean isGrid;
private static final int UNIT_ACTIVITY_ID = 0;
private static final int DATE_RANGE_ACTIVITY_ID = 1;
private static final int FINANCE_ACTIVITY_ID = 2;
private static final int COMPASS_ACTIVITY_ID = 3;
private static final int BMI_ACTIVITY_ID = 4;
private static final int SHOPPING_ACTIVITY_ID = 5;
private static final int CURRENCY_ACTIVITY_ID = 6;
private static final int CHINESE_NUMBER_CONVERSION_ACTIVITY_ID = 7;
private static final int RELATIONSHIP_ACTIVITY_ID = 8;
private static final int RANDOM_ACTIVITY_ID = 9;
private static final int FUNCTION_ACTIVITY_ID = 10;
private static final int STATISTICS_ACTIVITY_ID = 11;
private static final int FRACTION_ACTIVITY_ID = 12;
private static final int PROGRAMMER_ACTIVITY_ID = 13;

public ToolBoxFragment() {
}
Expand All @@ -77,20 +63,21 @@ public void onCreate(@Nullable Bundle savedInstanceState) {
@SuppressLint("UseCompatLoadingForDrawables")
private List<ToolBoxItem> createToolBoxItems() {
List<ToolBoxItem> items = new ArrayList<>();
items.add(new ToolBoxItem(UNIT_ACTIVITY_ID, getString(R.string.UnitsActivity), getResources().getDrawable(R.drawable.unit_icon, requireContext().getTheme())));
items.add(new ToolBoxItem(DATE_RANGE_ACTIVITY_ID, getString(R.string.dateActivity), getResources().getDrawable(R.drawable.date_range_icon, requireContext().getTheme())));
items.add(new ToolBoxItem(FINANCE_ACTIVITY_ID, getString(R.string.financeActivity), getResources().getDrawable(R.drawable.finance_icon, requireContext().getTheme())));
items.add(new ToolBoxItem(COMPASS_ACTIVITY_ID, getString(R.string.compassActivity), getResources().getDrawable(R.drawable.compass_icon, requireContext().getTheme())));
items.add(new ToolBoxItem(BMI_ACTIVITY_ID, getString(R.string.bmiActivity), getResources().getDrawable(R.drawable.bmi_icon, requireContext().getTheme())));
items.add(new ToolBoxItem(SHOPPING_ACTIVITY_ID, getString(R.string.shoppingActivity), getResources().getDrawable(R.drawable.shopping_icon, requireContext().getTheme())));
items.add(new ToolBoxItem(CURRENCY_ACTIVITY_ID, getString(R.string.exchangeActivity), getResources().getDrawable(R.drawable.currency_exchange_icon, requireContext().getTheme())));
items.add(new ToolBoxItem(CHINESE_NUMBER_CONVERSION_ACTIVITY_ID, getString(R.string.chineseNumberConverter), getResources().getDrawable(R.drawable.chinese_number_icon, requireContext().getTheme())));
items.add(new ToolBoxItem(RELATIONSHIP_ACTIVITY_ID, getString(R.string.relationshipActivity), getResources().getDrawable(R.drawable.relation_icon, requireContext().getTheme())));
items.add(new ToolBoxItem(RANDOM_ACTIVITY_ID, getString(R.string.randomActivity), getResources().getDrawable(R.drawable.random_number_icon, requireContext().getTheme())));
items.add(new ToolBoxItem(FUNCTION_ACTIVITY_ID, getString(R.string.EquationActivity), getResources().getDrawable(R.drawable.functions_icon, requireContext().getTheme())));
items.add(new ToolBoxItem(STATISTICS_ACTIVITY_ID, getString(R.string.statisticActivity), getResources().getDrawable(R.drawable.statistics_icon, requireContext().getTheme())));
items.add(new ToolBoxItem(FRACTION_ACTIVITY_ID, getString(R.string.numberConvert), getResources().getDrawable(R.drawable.fraction, requireContext().getTheme())));
items.add(new ToolBoxItem(PROGRAMMER_ACTIVITY_ID, getString(R.string.programmer), getResources().getDrawable(R.drawable.binary_icon, requireContext().getTheme())));
items.add(new ToolBoxItem(Constants.UNIT_ACTIVITY_ID, getString(R.string.UnitsActivity), getResources().getDrawable(R.drawable.unit_icon, requireContext().getTheme())));
items.add(new ToolBoxItem(Constants.DATE_RANGE_ACTIVITY_ID, getString(R.string.dateActivity), getResources().getDrawable(R.drawable.date_range_icon, requireContext().getTheme())));
items.add(new ToolBoxItem(Constants.FINANCE_ACTIVITY_ID, getString(R.string.financeActivity), getResources().getDrawable(R.drawable.finance_icon, requireContext().getTheme())));
items.add(new ToolBoxItem(Constants.COMPASS_ACTIVITY_ID, getString(R.string.compassActivity), getResources().getDrawable(R.drawable.compass_icon, requireContext().getTheme())));
items.add(new ToolBoxItem(Constants.BMI_ACTIVITY_ID, getString(R.string.bmiActivity), getResources().getDrawable(R.drawable.bmi_icon, requireContext().getTheme())));
items.add(new ToolBoxItem(Constants.SHOPPING_ACTIVITY_ID, getString(R.string.shoppingActivity), getResources().getDrawable(R.drawable.shopping_icon, requireContext().getTheme())));
items.add(new ToolBoxItem(Constants.CURRENCY_ACTIVITY_ID, getString(R.string.exchangeActivity), getResources().getDrawable(R.drawable.currency_exchange_icon, requireContext().getTheme())));
items.add(new ToolBoxItem(Constants.CHINESE_NUMBER_CONVERSION_ACTIVITY_ID, getString(R.string.chineseNumberConverter), getResources().getDrawable(R.drawable.chinese_number_icon, requireContext().getTheme())));
items.add(new ToolBoxItem(Constants.RELATIONSHIP_ACTIVITY_ID, getString(R.string.relationshipActivity), getResources().getDrawable(R.drawable.relation_icon, requireContext().getTheme())));
items.add(new ToolBoxItem(Constants.RANDOM_ACTIVITY_ID, getString(R.string.randomActivity), getResources().getDrawable(R.drawable.random_number_icon, requireContext().getTheme())));
items.add(new ToolBoxItem(Constants.FUNCTION_ACTIVITY_ID, getString(R.string.EquationActivity), getResources().getDrawable(R.drawable.functions_icon, requireContext().getTheme())));
items.add(new ToolBoxItem(Constants.STATISTICS_ACTIVITY_ID, getString(R.string.statisticActivity), getResources().getDrawable(R.drawable.statistics_icon, requireContext().getTheme())));
items.add(new ToolBoxItem(Constants.FRACTION_ACTIVITY_ID, getString(R.string.numberConvert), getResources().getDrawable(R.drawable.fraction, requireContext().getTheme())));
items.add(new ToolBoxItem(Constants.PROGRAMMER_ACTIVITY_ID, getString(R.string.programmer), getResources().getDrawable(R.drawable.binary_icon, requireContext().getTheme())));
items.add(new ToolBoxItem(Constants.RULER_ACTIVITY_ID, getString(R.string.ruler), getResources().getDrawable(R.drawable.ruler_icon, requireContext().getTheme())));
return items;
}

Expand All @@ -114,7 +101,7 @@ public void onViewCreated(@NonNull View notes, @Nullable Bundle savedInstanceSta
isGrid = bundle.getBoolean("GridLayout", true);
updateRecycleView(isGrid);
});
String order = sharedPreferences.getString("order", ORDER);
String order = sharedPreferences.getString("order", Constants.ORDER);
List<String> orderList = new ArrayList<>(Arrays.asList(order.split("/")));
if (orderList.size() < data.size()) {
int oLength = orderList.size();
Expand All @@ -126,9 +113,9 @@ public void onViewCreated(@NonNull View notes, @Nullable Bundle savedInstanceSta
editor.putString("order", orderString);
editor.apply();
} else if (orderList.size() > data.size()) {
orderList = new ArrayList<>(Arrays.asList(ORDER.split("/")));
orderList = new ArrayList<>(Arrays.asList(Constants.ORDER.split("/")));
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString("order", ORDER);
editor.putString("order", Constants.ORDER);
editor.apply();
}

Expand Down Expand Up @@ -181,42 +168,65 @@ public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction)
};
}


private void updateRecycleView(boolean isGrid) {
adapter = new ToolBoxAdapter(newData, isGrid, (item) -> {
int itemId = item.id();
switch (itemId) {
case UNIT_ACTIVITY_ID ->
startActivity(new Intent(getContext(), UnitActivity.class));
case DATE_RANGE_ACTIVITY_ID ->
startActivity(new Intent(getContext(), DateRangeActivity.class));
case FINANCE_ACTIVITY_ID ->
startActivity(new Intent(getContext(), FinanceActivity.class));
case COMPASS_ACTIVITY_ID -> startActivity(new Intent(getContext(), Compass.class));
case BMI_ACTIVITY_ID -> startActivity(new Intent(getContext(), BMIActivity.class));
case SHOPPING_ACTIVITY_ID ->
startActivity(new Intent(getContext(), ShoppingActivity.class));
case CURRENCY_ACTIVITY_ID ->
startActivity(new Intent(getContext(), CurrencyActivity.class));
case CHINESE_NUMBER_CONVERSION_ACTIVITY_ID ->
startActivity(new Intent(getContext(), ChineseNumberConversionActivity.class));
case RELATIONSHIP_ACTIVITY_ID ->
startActivity(new Intent(getContext(), RelationshipActivity.class));
case RANDOM_ACTIVITY_ID ->
startActivity(new Intent(getContext(), RandomNumberActivity.class));
case FUNCTION_ACTIVITY_ID ->
startActivity(new Intent(getContext(), EquationActivity.class));
case STATISTICS_ACTIVITY_ID ->
startActivity(new Intent(getContext(), StatisticsActivity.class));
case FRACTION_ACTIVITY_ID ->
startActivity(new Intent(getContext(), FractionActivity.class));
case PROGRAMMER_ACTIVITY_ID ->
startActivity(new Intent(getContext(), ProgrammerActivity.class));
default -> {
}
}
});
adapter = new ToolBoxAdapter(newData, isGrid, this::startActivityById);
recyclerView.setLayoutManager(isGrid ? new GridLayoutManager(getContext(), 3) : new LinearLayoutManager(getContext()));
recyclerView.setAdapter(adapter);
}

private void startActivityById(ToolBoxItem item) {
Intent intent = null;
switch (item.id()) {
case Constants.UNIT_ACTIVITY_ID ->
intent = new Intent(getContext(), UnitActivity.class);
case Constants.DATE_RANGE_ACTIVITY_ID ->
intent = new Intent(getContext(), DateRangeActivity.class);
case Constants.FINANCE_ACTIVITY_ID ->
intent = new Intent(getContext(), FinanceActivity.class);
case Constants.COMPASS_ACTIVITY_ID -> intent = new Intent(getContext(), Compass.class);
case Constants.BMI_ACTIVITY_ID -> intent = new Intent(getContext(), BMIActivity.class);
case Constants.SHOPPING_ACTIVITY_ID ->
intent = new Intent(getContext(), ShoppingActivity.class);
case Constants.CURRENCY_ACTIVITY_ID ->
intent = new Intent(getContext(), CurrencyActivity.class);
case Constants.CHINESE_NUMBER_CONVERSION_ACTIVITY_ID ->
intent = new Intent(getContext(), ChineseNumberConversionActivity.class);
case Constants.RELATIONSHIP_ACTIVITY_ID ->
intent = new Intent(getContext(), RelationshipActivity.class);
case Constants.RANDOM_ACTIVITY_ID ->
intent = new Intent(getContext(), RandomNumberActivity.class);
case Constants.FUNCTION_ACTIVITY_ID ->
intent = new Intent(getContext(), EquationActivity.class);
case Constants.STATISTICS_ACTIVITY_ID ->
intent = new Intent(getContext(), StatisticsActivity.class);
case Constants.FRACTION_ACTIVITY_ID ->
intent = new Intent(getContext(), FractionActivity.class);
case Constants.PROGRAMMER_ACTIVITY_ID ->
intent = new Intent(getContext(), ProgrammerActivity.class);
case Constants.RULER_ACTIVITY_ID ->
intent = new Intent(getContext(), RulerActivity.class);
}
if (intent != null) {
startActivity(intent);
}
}

private static class Constants {
public static final String ORDER = "0/1/2/3/4/5/6/7/8/9/10/11/12/13/14";
public static final int UNIT_ACTIVITY_ID = 0;
public static final int DATE_RANGE_ACTIVITY_ID = 1;
public static final int FINANCE_ACTIVITY_ID = 2;
public static final int COMPASS_ACTIVITY_ID = 3;
public static final int BMI_ACTIVITY_ID = 4;
public static final int SHOPPING_ACTIVITY_ID = 5;
public static final int CURRENCY_ACTIVITY_ID = 6;
public static final int CHINESE_NUMBER_CONVERSION_ACTIVITY_ID = 7;
public static final int RELATIONSHIP_ACTIVITY_ID = 8;
public static final int RANDOM_ACTIVITY_ID = 9;
public static final int FUNCTION_ACTIVITY_ID = 10;
public static final int STATISTICS_ACTIVITY_ID = 11;
public static final int FRACTION_ACTIVITY_ID = 12;
public static final int PROGRAMMER_ACTIVITY_ID = 13;
public static final int RULER_ACTIVITY_ID = 14;
}
}
Loading

0 comments on commit 3b4c0c2

Please sign in to comment.