Commit 48a3a245 authored by zhang_z's avatar zhang_z

计算器基本完成;

parent 1708d114
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.xingdata.zzdpos">
package="com.xingdata.zzdpos">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.SEND_SMS" />
<application
android:name=".App"
......@@ -19,18 +19,15 @@
android:configChanges="keyboard|orientation|screenSize|keyboardHidden"
android:label="@string/main_title"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustUnspecified|stateHidden" >
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
android:windowSoftInputMode="adjustUnspecified|stateHidden">
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity
android:name=".ui.splash.SplashActivity"
android:configChanges="keyboard|orientation|screenSize|keyboardHidden"
android:theme="@style/AppTheme">
</activity>
<activity
......@@ -49,7 +46,13 @@
<activity
android:name=".ui.payment.PaymentActivity"
android:configChanges="keyboard|orientation|screenSize|keyboardHidden"
android:windowSoftInputMode="adjustUnspecified|stateHidden" />
android:windowSoftInputMode="adjustUnspecified|stateHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
\ No newline at end of file
......@@ -23,6 +23,8 @@ public class PaymentFragment extends BaseFragment<PaymentPresenter, FragmentPaym
mCalculatorView.setmOnResultChangeListener((exp, result) -> {
LogUtils.e(exp + "\n" + result);
mViewBinding.tvExp.setText(exp);
mViewBinding.tvResult.setText(ConvertUtil.fenToYuan(result));
});
mCalculatorView.setmOnSettleClickListener(result -> {
LogUtils.e(ConvertUtil.fenToYuan(result));
......
......@@ -4,6 +4,7 @@ package com.xingdata.zzdpos.ui.payment.view;
import android.view.View;
import android.widget.TextView;
import com.blankj.utilcode.util.LogUtils;
import com.xingdata.zzdpos.R;
import com.xingdata.zzdpos.base.BaseFragment;
import com.xingdata.zzdpos.databinding.ViewCalculatorBinding;
......@@ -18,6 +19,7 @@ public class CalculatorView extends BaseFragment<PaymentPresenter, ViewCalculato
private String mExp;
private String mValue;
private String mLast;
private OnResultChangeListener mOnResultChangeListener;
private onSettleClickListener mOnSettleClickListener;
......@@ -26,6 +28,7 @@ public class CalculatorView extends BaseFragment<PaymentPresenter, ViewCalculato
public CalculatorView() {
mExp = "";
mValue = "";
mLast = "";
}
public interface OnResultChangeListener {
......@@ -55,24 +58,28 @@ public class CalculatorView extends BaseFragment<PaymentPresenter, ViewCalculato
settle();
break;
default:
LogUtils.e("mExp : " + mExp + "\nmValue : " + mValue + "\nmLast" + mLast);
if (view instanceof TextView) {
String str = ((TextView) view).getText().toString();
if (mExp.length() == 0 && str.matches("[+\\-*/]")) return;
if (mExp.length() == 0 && str.equals(".")) mExp += "0";
if (mValue.length() > 0 && str.matches("[+\\-*/]")) {
String[] mExps = mExp.split("[+\\-×÷]");
if (mExps.length > 1) mValue = mExps[mExps.length - 1];
else mValue = mExp;
if (mLast.matches("[+\\-×÷.]") && str.matches("[+\\-×÷.]")) return;
if (mValue.length() > 0 && str.matches("[+\\-×÷]")) {
mValue = "";
} else {
if (mValue.contains(".") && str.matches("[.]")) return;
mValue += str;
String[] _values = mValue.split("[.]");
if (_values.length > 1) {
if (_values[1].length() > 2) return;
}
if (mValue.length() == 0 && str.matches("[+\\-×÷]")) return;
if (mValue.contains(".") && str.matches("[+\\-×÷.]")) return;
if (mValue.split("[.]").length > 1 && mValue.split("[.]")[1].length() > 2)
return;
if (mValue.length() == 0 && str.equals(".")) mExp += "0";
}
mLast = str;
mExp += str;
}
break;
......@@ -88,7 +95,10 @@ public class CalculatorView extends BaseFragment<PaymentPresenter, ViewCalculato
* 删除
*/
private void delete() {
mExp = mExp.substring(0, mExp.length() - 1);
if (mExp.length() > 0) {
mExp = mExp.substring(0, mExp.length() - 1);
mLast = mExp.substring(mExp.length() - 1, mExp.length());
}
}
/**
......@@ -124,12 +134,11 @@ public class CalculatorView extends BaseFragment<PaymentPresenter, ViewCalculato
.replaceAll("×", "*").replaceAll("÷", "/");
String minExp = "^((\\d+(\\.\\d+)?)|(\\[-\\d+(\\.\\d+)?]))[+\\-*/]((\\d+(\\.\\d+)?)|(\\[-\\d+(\\.\\d+)?]))$";
if (exp.matches(minExp)) {
String result = calculate(exp);
return Double.parseDouble(result) >= 0 ? result : "[" + result + "]";
return calculate(exp);
} else if (exp.matches("[0-9.]+")) {
return exp;
} else if (exp.length() == 0) {
return "0";
return "0.0";
}
String noParentheses = "^[^()]+$";
String priorOperatorExp = "(((\\d+(\\.\\d+)?)|(\\[-\\d+(\\.\\d+)?]))[*/]((\\d+(\\.\\d+)?)|(\\[-\\d+(\\.\\d+)?])))";
......@@ -143,7 +152,6 @@ public class CalculatorView extends BaseFragment<PaymentPresenter, ViewCalculato
} else {
patt = Pattern.compile(operatorExp);
mat = patt.matcher(exp);
if (mat.find()) {
String tempMinExp = mat.group();
exp = exp.replaceFirst(operatorExp, parseExp(tempMinExp));
......
......@@ -6,6 +6,7 @@
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
......@@ -13,6 +14,20 @@
android:background="@color/store_product_bg"
android:orientation="vertical">
<TextView
android:id="@+id/tv_exp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end|center_vertical"
android:textColor="@color/white_caocao" />
<TextView
android:id="@+id/tv_result"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end|center_vertical"
android:textColor="@color/white_caocao" />
</LinearLayout>
<LinearLayout
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment