Commit 4a9ef3fe authored by zhang_z's avatar zhang_z

基本构建;

parent c1bfdd62
<component name="ProjectDictionaryState">
<dictionary name="Eurus">
<words>
<w>inputer</w>
</words>
</dictionary>
</component>
\ No newline at end of file
......@@ -2,6 +2,5 @@
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
<mapping directory="$PROJECT_DIR$/TangKuPos" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?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,29 +19,33 @@
android:configChanges="keyboard|orientation|screenSize|keyboardHidden"
android:label="@string/main_title"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustUnspecified|stateHidden"/>
android:windowSoftInputMode="adjustUnspecified|stateHidden" />
<activity
android:name=".ui.splash.SplashActivity"
android:configChanges="keyboard|orientation|screenSize|keyboardHidden"
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.login.LoginActivity"
android:configChanges="keyboard|orientation|screenSize|keyboardHidden"
android:windowSoftInputMode="adjustUnspecified|stateHidden"/>
android:windowSoftInputMode="adjustUnspecified|stateHidden" />
<activity
android:name=".ui.exception.ErrorDialogActivity"
android:configChanges="keyboard|orientation|screenSize|keyboardHidden"
android:theme="@style/Theme.AppCompat.Light.Dialog"/>
android:theme="@style/Theme.AppCompat.Light.Dialog" />
<activity
android:name=".ui.exception.ServerErrActivity"
android:configChanges="keyboard|orientation|screenSize|keyboardHidden"
android:theme="@style/Theme.AppCompat.Light.Dialog"/>
android:theme="@style/Theme.AppCompat.Light.Dialog" />
<activity
android:name=".ui.payment.PaymentActivity"
android:configChanges="keyboard|orientation|screenSize|keyboardHidden"
android:windowSoftInputMode="adjustUnspecified|stateHidden" />
</application>
</manifest>
\ No newline at end of file
package com.xingdata.zzdpos.ui.payment;
import com.xingdata.zzdpos.R;
import com.xingdata.zzdpos.base.BaseActivity;
import com.xingdata.zzdpos.databinding.ActivityPaymentBinding;
public class PaymentActivity extends BaseActivity<PaymentPresenter, ActivityPaymentBinding> implements PaymentContract.View {
@Override
public int getLayoutId() {
return R.layout.activity_payment;
}
@Override
public void initView() {
}
}
package com.xingdata.zzdpos.ui.payment;
import com.xingdata.zzdpos.base.BasePresenter;
import com.xingdata.zzdpos.base.BaseView;
interface PaymentContract {
interface View extends BaseView {
}
abstract class Presenter extends BasePresenter<PaymentContract.View> {
}
}
\ No newline at end of file
package com.xingdata.zzdpos.ui.payment;
public class PaymentPresenter extends PaymentContract.Presenter {
@Override
public void onAttached() {
}
}
//package com.xingdata.zzdpos.ui.payment.fragment;
//
//import com.xingdata.zzdpos.base.BaseFragment;
//import com.xingdata.zzdpos.ui.payment.PaymentPresenter;
//
///**
// * Created by Eurus on 2017/12/21.
// */
//
//public class CalculatorFragment extends BaseFragment<PaymentPresenter,> {
//}
package com.xingdata.zzdpos.ui.payment.view;
import android.view.View;
import com.xingdata.zzdpos.R;
import com.xingdata.zzdpos.base.BaseFragment;
import com.xingdata.zzdpos.databinding.ViewCalculatorBinding;
import com.xingdata.zzdpos.ui.payment.PaymentPresenter;
import com.xingdata.zzdpos.util.ConvertUtil;
import java.math.BigDecimal;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class CalculatorView extends BaseFragment<PaymentPresenter, ViewCalculatorBinding> {
private String mExp;
private OnResultChangeListener mOnResultChangeListener;
private onSettleClickListener mOnSettleClickListener;
public interface OnResultChangeListener {
void onResultChange(String exp, Long result);
}
public interface onSettleClickListener {
void onSettleClick(Long result);
}
@Override
public int getLayoutId() {
return R.layout.view_calculator;
}
@Override
public void initView() {
View.OnClickListener mOnClickListener = view -> {
switch (view.getId()) {
case R.id.btn_add:
break;
case R.id.btn_sub:
break;
case R.id.btn_mul:
break;
case R.id.btn_div:
break;
case R.id.btn_point:
break;
case R.id.btn_del:
delete();
break;
case R.id.btn_clear:
clear();
break;
case R.id.btn_settle:
settle();
break;
}
if (mOnResultChangeListener != null) {
mOnResultChangeListener.onResultChange(mExp, ConvertUtil.yuanToFen(parseExp(mExp)));
}
};
mViewBinding.setOnClick(mOnClickListener);
}
/**
* 删除
*/
private void delete() {
mExp = mExp.substring(0, mExp.length() - 1);
}
/**
* 结账
*/
private void settle() {
if (mOnSettleClickListener != null) {
mOnSettleClickListener.onSettleClick(ConvertUtil.yuanToFen(parseExp(mExp)));
}
}
/**
* 清空
*/
private void clear() {
mExp = "";
if (mOnResultChangeListener != null) {
mOnResultChangeListener.onResultChange(mExp, ConvertUtil.yuanToFen(parseExp(mExp)));
}
}
/**
* 解析计算四则运算表达式,例:2+((3+4)*2-22)/2*3
*
* @param exp 算式
* @return 结果
*/
public static String parseExp(String exp) {
exp = exp.replaceAll("\\s+", "")
.replaceAll("^\\((.+)\\)$", "$1")
.replaceAll("[\\s+-/*.]+$", "")
.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 + "]";
} else if (exp.matches("[0-9]+")) {
return exp;
} else if (exp.length() == 0) {
return "0";
}
String noParentheses = "^[^()]+$";
String priorOperatorExp = "(((\\d+(\\.\\d+)?)|(\\[-\\d+(\\.\\d+)?]))[*/]((\\d+(\\.\\d+)?)|(\\[-\\d+(\\.\\d+)?])))";
String operatorExp = "(((\\d+(\\.\\d+)?)|(\\[-\\d+(\\.\\d+)?]))[+\\-]((\\d+(\\.\\d+)?)|(\\[-\\d+(\\.\\d+)?])))";
if (exp.matches(noParentheses)) {
Pattern patt = Pattern.compile(priorOperatorExp);
Matcher mat = patt.matcher(exp);
if (mat.find()) {
String tempMinExp = mat.group();
exp = exp.replaceFirst(priorOperatorExp, parseExp(tempMinExp));
} else {
patt = Pattern.compile(operatorExp);
mat = patt.matcher(exp);
if (mat.find()) {
String tempMinExp = mat.group();
exp = exp.replaceFirst(operatorExp, parseExp(tempMinExp));
}
}
return parseExp(exp);
}
String minParentheses = "\\([^\\(\\)]+\\)";
Pattern patt = Pattern.compile(minParentheses);
Matcher mat = patt.matcher(exp);
if (mat.find()) {
String tempMinExp = mat.group();
exp = exp.replaceFirst(minParentheses, parseExp(tempMinExp));
}
System.out.println("expression" + exp);
return parseExp(exp);
}
/**
* 计算最小单位四则运算表达式(两个数字)
*
* @param exp 算式
* @return 结果
*/
public static String calculate(String exp) {
exp = exp.replaceAll("[\\[\\]]", "");
String number[] = exp.replaceFirst("(\\d)[+\\-*/]", "$1,").split(",");
BigDecimal number1 = new BigDecimal(number[0]);
BigDecimal number2 = new BigDecimal(number[1]);
BigDecimal result = null;
String operator = exp.replaceFirst("^.*\\d([+\\-*/]).+$", "$1");
if ("+".equals(operator)) {
result = number1.add(number2);
} else if ("-".equals(operator)) {
result = number1.subtract(number2);
} else if ("*".equals(operator)) {
result = number1.multiply(number2);
} else if ("/".equals(operator)) {
result = number1.divide(number2, 2, BigDecimal.ROUND_HALF_UP);
}
return result != null ? result.toString() : null;
}
public void setmOnResultChangeListener(OnResultChangeListener mOnResultChangeListener) {
this.mOnResultChangeListener = mOnResultChangeListener;
}
public void setmOnSettleClickListener(onSettleClickListener mOnSettleClickListener) {
this.mOnSettleClickListener = mOnSettleClickListener;
}
}
<?xml version="1.0" encoding="utf-8"?>
<layout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/store_product_bg"
android:title="收款"
android:titleTextColor="@color/white" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="3"
android:background="@color/store_product_bg"
android:orientation="vertical">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@color/white"
android:gravity="end|center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="小计:" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="40.00"
android:textColor="@color/deep_red" />
</LinearLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="7" />
</LinearLayout>
</layout>
\ No newline at end of file
This diff is collapsed.
......@@ -463,5 +463,25 @@
<string name="gift_add_confirm">马上换购</string>
<string name="gift_sku_price">原价</string>
<!--输入器-->
<string name="inputer_1">1</string>
<string name="inputer_2">2</string>
<string name="inputer_3">3</string>
<string name="inputer_4">4</string>
<string name="inputer_5">5</string>
<string name="inputer_6">6</string>
<string name="inputer_7">7</string>
<string name="inputer_8">8</string>
<string name="inputer_9">9</string>
<string name="inputer_0">0</string>
<string name="inputer_point">.</string>
<string name="inputer_del">删除</string>
<string name="inputer_clear">清空</string>
<string name="inputer_settle">收\n款</string>
<string name="inputer_add">+</string>
<string name="inputer_sub">-</string>
<string name="inputer_mul">×</string>
<string name="inputer_div">÷</string>
</resources>
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