Skip to content

Commit

Permalink
Add translation
Browse files Browse the repository at this point in the history
Add AboutView
Change package Name
Optimize Codes
  • Loading branch information
liuyanyi committed Mar 15, 2018
1 parent ef4e442 commit cee35ae
Show file tree
Hide file tree
Showing 27 changed files with 572 additions and 66 deletions.
12 changes: 7 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ apply plugin: 'com.android.application'
android {
compileSdkVersion 26
defaultConfig {
applicationId "com.mogician.cardreader"
applicationId "com.wolfaonliu.cardreader"
minSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "1.2.5"
versionName "1.3.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
Expand All @@ -18,9 +18,10 @@ android {
}

android.applicationVariants.all {
variant -> variant.outputs.all {
outputFileName = "NCR_${variant.name}_v${variant.versionName}.apk"
}
variant ->
variant.outputs.all {
outputFileName = "NCR_${variant.name}_v${variant.versionName}.apk"
}
}
}

Expand All @@ -29,6 +30,7 @@ dependencies {
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:support-v4:26.1.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mogician.cardreader;
package com.wolfaonliu.cardreader;

import android.content.Context;
import android.support.test.InstrumentationRegistry;
Expand All @@ -7,7 +7,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;

import static org.junit.Assert.*;
import static org.junit.Assert.assertEquals;

/**
* Instrumented test, which will execute on an Android device.
Expand Down
5 changes: 3 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mogician.cardreader">
package="com.wolfaonliu.cardreader">

<uses-permission android:name="android.permission.NFC" />

Expand All @@ -12,7 +12,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme.NoActionBar">
<activity android:name=".MainActivity">
<activity android:name="com.wolfaonliu.cardreader.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down Expand Up @@ -55,6 +55,7 @@
android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/nfc_tech_filter" />
</activity>
<activity android:name="com.wolfaonliu.cardreader.AboutActivity" />
</application>

</manifest>
116 changes: 116 additions & 0 deletions app/src/main/java/com/wolfaonliu/cardreader/AboutActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package com.wolfaonliu.cardreader;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.Arrays;

public class AboutActivity extends AppCompatActivity implements AdapterView.OnItemClickListener {

Toolbar toolbar;


private ListView mView;

private AboutAdapter mAdapter;

private RecyclerView.LayoutManager mLayoutManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_about);

toolbar = findViewById(R.id.about_toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
initData();
initView();
}


private void initData() {
mAdapter = new AboutAdapter(getSet(), this);
}

private ArrayList<String[]> getSet() {
ArrayList<String[]> settings = new ArrayList<>();
String[][] s = new String[4][2];
s[0][0] = getString(R.string.version);
s[0][1] = Util.getVersion(this.getApplicationContext());
s[1][0] = getString(R.string.developer);
s[1][1] = "wolfaonliu";
s[2][0] = getString(R.string.contact);
s[2][1] = "[email protected]";
s[3][0] = getString(R.string.github);
s[3][1] = "https://github.com/liuyanyi/NewcapecCardReader";
settings.addAll(Arrays.asList(s));
return settings;
}

private void initView() {
mView = findViewById(R.id.set_list);
// 设置adapter
mView.setAdapter(mAdapter);
mView.setOnItemClickListener(this);
}

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Uri uri;
Intent intent;
switch (position) {
case 2:
// uri = Uri.parse("[email protected]");
// intent = new Intent(Intent.ACTION_SENDTO, uri);
//// intent.putExtra(Intent.EXTRA_SUBJECT, "Newcapec Card Reader Report");
// startActivity(intent);
showEmailDialog();
break;
case 3:
uri = Uri.parse("https://github.com/liuyanyi/NewcapecCardReader");
intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
break;
default:
break;
}
// Toast.makeText(this, "你点击了第" + position + "项", Toast.LENGTH_SHORT).show();
}


private void showEmailDialog() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.Report)
.setMessage(R.string.report_atten);
builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent email = new Intent(Intent.ACTION_SEND);
email.setType("message/rfc822");
email.putExtra(Intent.EXTRA_EMAIL, new String[]{"[email protected]"});
email.putExtra(Intent.EXTRA_SUBJECT, getString(R.string.app_name) + getString(R.string.report));
startActivity(Intent.createChooser(email, getString(R.string.email_clint)));
}
});
builder.setNegativeButton(R.string.no, null);

builder.show();
}
}
60 changes: 60 additions & 0 deletions app/src/main/java/com/wolfaonliu/cardreader/AboutAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package com.wolfaonliu.cardreader;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.ArrayList;

/**
* Created by Mogician on 2018/3/14.
*/

public class AboutAdapter extends BaseAdapter {

private ArrayList<String[]> mData;
private Activity activity;

private TextView setting;
private TextView settingsub;


public AboutAdapter(ArrayList<String[]> data, Activity activity) {
this.mData = data;
this.activity = activity;
}

@Override
public int getCount() {
return mData.size();
}

@Override
public Object getItem(int position) {
return null;
}

@Override
public long getItemId(int position) {
return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = LayoutInflater.from(activity).inflate(R.layout.about_item, parent, false);

setting = convertView.findViewById(R.id.setting);
settingsub = convertView.findViewById(R.id.settingsub);

//
setting.setText(mData.get(position)[0]);
settingsub.setText(mData.get(position)[1]);
return convertView;

}


}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mogician.cardreader;
package com.wolfaonliu.cardreader;

import android.app.Activity;
import android.graphics.Color;
Expand Down Expand Up @@ -95,7 +95,7 @@ public void setPersonId(String personId) {
public void setCardBalance(String cardBalance) {
if (cardBalance != null)
isNewcapecCard = true;
this.cardBalance = cardBalance + "元";
this.cardBalance = cardBalance + mainActivity.getString(R.string.yuan);
}

public void setStudentDept(String studentDept) {
Expand All @@ -114,13 +114,13 @@ public void onFinish(boolean isFull) {
pgBar.setVisibility(View.GONE);
if (!isFull) {
//未能复现……
atten.setText("警告,读取内容不全,请重新放置卡片");
atten.setText(mainActivity.getString(R.string.reading_alert));
pgI.setColorFilter(Color.parseColor("#259b24"));
} else if (isNewcapecCard) {
atten.setText("成功");
atten.setText(mainActivity.getString(R.string.success));
pgI.setColorFilter(Color.parseColor("#259b24"));
} else {
atten.setText("失败,非校园卡");
atten.setText(mainActivity.getString(R.string.failed));
pgI.setColorFilter(Color.parseColor("#e51c23"));
}
}
Expand All @@ -146,7 +146,7 @@ public void showInLog() {

public boolean show() {
if (isNewcapecCard) {
isCard.setText("校园卡");
isCard.setText(mainActivity.getString(R.string.isStuCard));

name.setText(studentName);

Expand All @@ -164,7 +164,7 @@ public boolean show() {

dealCard.setVisibility(View.VISIBLE);
// 设置adapter
mAdapter = new DealAdapter(getTradeList());
mAdapter = new DealAdapter(getTradeList(), mainActivity);
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.addItemDecoration(new ItemDivider(mainActivity, LinearLayoutManager.VERTICAL));
}
Expand All @@ -173,7 +173,7 @@ public boolean show() {
return false;

} else {
isCard.setText("非校园卡");
isCard.setText(mainActivity.getString(R.string.unsupport));

hardware.setText(hardwareId);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mogician.cardreader;
package com.wolfaonliu.cardreader;

import android.app.Activity;
import android.content.Intent;
Expand Down Expand Up @@ -49,7 +49,7 @@ public static CardInfo readCard(Activity activity, Intent intent) {
if (transceive != null && g.c(transceive)) {
transceive = isoDep.transceive(g.a(fInts.d));
if (transceive == null || !g.c(transceive)) {
Util.aToast("读卡失败!", activity);
Util.aToast(activity.getString(R.string.read_failed), activity);
} else {
byte[] a;

Expand Down Expand Up @@ -96,7 +96,7 @@ public static CardInfo readCard(Activity activity, Intent intent) {
a = g.a(transceive);
g.a(a, 0, transceive, 0, transceive.length - 2);
action = g.a(a, 0, a.length, "GB18030").trim();
Log.d("***", action);
// Log.d("***", action);
if (Util.d(action) || Util.a(action) || action.contains("000000")) {
// bVar.d(action);
// Log.d("学院******", action);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.mogician.cardreader;
package com.wolfaonliu.cardreader;

import android.app.Activity;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
Expand All @@ -15,9 +16,11 @@
public class DealAdapter extends RecyclerView.Adapter<DealAdapter.ViewHolder> {

private ArrayList<TradingRecordInfo> mData;
private Activity activity;

public DealAdapter(ArrayList<TradingRecordInfo> data) {
public DealAdapter(ArrayList<TradingRecordInfo> data, Activity activity) {
this.mData = data;
this.activity = activity;
}

public void updateData(ArrayList<TradingRecordInfo> data) {
Expand All @@ -37,10 +40,20 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
public void onBindViewHolder(ViewHolder holder, int position) {
// 绑定数据
String m = mData.get(position).getTradingMoney();
String t = mData.get(position).getTradingType();
int t = mData.get(position).getTradingType();
holder.time.setText(mData.get(position).getTradingDateTime());
holder.money.setText(m);
holder.type.setText(t);
switch (t) {
case 2:
holder.type.setText(activity.getString(R.string.recharge));
break;
case 6:
holder.type.setText(activity.getString(R.string.consumption));
break;
default:
holder.type.setText(t);
break;
}
}

@Override
Expand All @@ -56,9 +69,9 @@ public static class ViewHolder extends RecyclerView.ViewHolder {

public ViewHolder(View itemView) {
super(itemView);
type = (TextView) itemView.findViewById(R.id.type);
money = (TextView) itemView.findViewById(R.id.deal);
time = (TextView) itemView.findViewById(R.id.time);
type = itemView.findViewById(R.id.type);
money = itemView.findViewById(R.id.deal);
time = itemView.findViewById(R.id.time);
}
}
}
Loading

0 comments on commit cee35ae

Please sign in to comment.