Skip to content

Commit

Permalink
✨finished development^Cf campus card consumption
Browse files Browse the repository at this point in the history
  • Loading branch information
genshen committed Oct 12, 2017
1 parent 2850fee commit 856923a
Show file tree
Hide file tree
Showing 22 changed files with 196 additions and 35 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ android {
targetSdkVersion 26
versionCode 112
versionName "2.1.0"
buildConfigField "String", "APP_BUILD_TIME", "\"Mon, 09 October. 2017 \"" // build time
buildConfigField "String", "APP_BUILD_TIME", "\"Fri, 13 October. 2017 \"" // build time
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
externalNativeBuild {
cmake {
Expand Down
1 change: 1 addition & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public static java.lang.String TABLENAME;
-dontwarn okhttp3.**
-dontwarn okio.**
-dontwarn javax.annotation.**
-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase #addtionally added to solve campus card consumption bug

### https://github.com/Yalantis/uCrop
-dontwarn com.yalantis.ucrop**
Expand Down
12 changes: 9 additions & 3 deletions app/src/main/java/me/gensh/fragments/CampusNetworkFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.RandomAccessFile;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;

import me.gensh.helloustb.R;
Expand Down Expand Up @@ -143,8 +144,12 @@ private String[] getWeekAxis(Calendar calendar_now) {
return new_week;
}

private static float[] calcVariance(Calendar calendar_now, float today_flow) {
private float[] calcVariance(Calendar calendar_now, float today_flow) {
float[] data = M(calendar_now, today_flow);

System.out.println("<<<<<<<<<<<<<" + today_flow);
System.out.println(Arrays.toString(data));

float[] variance = new float[DATA_LENGTH - 1];
int day_counter = calendar_now.get(Calendar.DAY_OF_MONTH) - 1;
for (int i = DATA_LENGTH - 2; i >= 0; i--) {
Expand All @@ -158,9 +163,10 @@ private static float[] calcVariance(Calendar calendar_now, float today_flow) {
return variance;
}

public static float[] M(Calendar calendar_now, float todayFlow) {
public float[] M(Calendar calendar_now, float todayFlow) {
float[] flowData = new float[]{0, 0, 0, 0, 0, 0, 0, 0};
File file = new File(FILE_PATH);

File file = new File(getActivity().getFilesDir(), FILE_PATH);
if (file.exists() && file.length() == 38) {
try {
RandomAccessFile random_f = new RandomAccessFile(file, "rw");
Expand Down
24 changes: 22 additions & 2 deletions app/src/main/java/me/gensh/helloustb/About.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import java.util.Random;

import me.gensh.network.VersionCheckerTask;
import me.gensh.service.ApkDownloadIntentService;
import permissions.dispatcher.NeedsPermission;
Expand All @@ -34,7 +37,6 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_about);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
setVersion();
}

Expand Down Expand Up @@ -80,7 +82,7 @@ public void onAttemptToDownload(long packageSize, int newVersionCode, String new
@NeedsPermission({Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE})
public void startDownload(long packageSize, int newVersionCode, String newVersionName) {
Toast.makeText(this, R.string.update_downloading, Toast.LENGTH_SHORT).show();
ApkDownloadIntentService.startActionDownloadApk(this, packageSize, newVersionCode,newVersionName);
ApkDownloadIntentService.startActionDownloadApk(this, packageSize, newVersionCode, newVersionName);
}

@OnShowRationale({Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE})
Expand Down Expand Up @@ -118,9 +120,27 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
AboutPermissionsDispatcher.onRequestPermissionsResult(this, requestCode, grantResults);
}

final static private short TURN = 4;
final static private short ICON_COUNT = 8;
final static private int[] icons = {R.drawable.play_1, R.drawable.play_2, R.drawable.play_3,
R.drawable.play_4, R.drawable.play_5, R.drawable.play_6, R.drawable.play_7, R.drawable.play_8};
private short iconClickCounter = 0;
Random random = new Random();

public void clickHandle(View view) {
int id = view.getId();
switch (id) {
case R.id.about_header_container:
iconClickCounter++;
if (iconClickCounter == TURN) {
ImageView appIcon = findViewById(R.id.app_icon);
int index = random.nextInt(ICON_COUNT); //ic_launcher is also needed ?
appIcon.setImageResource(icons[index]); // 0 to ICON_COUNT-1
iconClickCounter = 0;
} /*else { //1,2,3,TURN-1
Snackbar.make(view, getString(R.string.about_play_snack, TURN - iconClickCounter), Snackbar.LENGTH_SHORT).show();
}*/
break;
case R.id.check_update:
checker = new VersionCheckerTask(getString(R.string.UpdateAddress), this, false);
checker.execute();
Expand Down
21 changes: 16 additions & 5 deletions app/src/main/java/me/gensh/helloustb/CampusCardConsumption.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ protected void onCreate(Bundle savedInstanceState) {
mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
mAdapter = new CampusCardAdapter(campusCardDataList);
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.setEmptyView(R.layout.list_empty_view, (ViewGroup) findViewById(R.id.recycle_view_container), true);

fab.setOnClickListener(new View.OnClickListener() {
@Override
Expand Down Expand Up @@ -107,21 +106,28 @@ public void onOk(int what, @NonNull ArrayList<String> data) {
attemptHttpRequest(HttpClients.HTTP_GET, getString(R.string.campus_card_query_link), Tags.E, 0x102, Tags.GET.ID_E_CAMPUS_CARD, HttpClients.CHARSET_BTF8, null, false);
} else if (what == 0x102) {
dismissProgressDialog();
/** todo bugs at:{@link HttpClients#newInstance }*/
// if (campusCardDataList != null) {
// campusCardDataList.clear();
// }

int size = data.size() / 4;
for (int i = 0; i < size; i++) {
if (data.get(4 * i).isEmpty() || data.get(4 * i + 1).isEmpty() ||
data.get(4 * i + 2).isEmpty() || data.get(4 * i + 3).isEmpty()) {
//filter empty content.
continue;
}
System.out.println(data.get(4 * i));
SparseArray<String> stringSparseArray = new SparseArray<>();
stringSparseArray.put(CAMPUS_CARD_CONSUME_TAG_TIME, data.get(4 * i));
stringSparseArray.put(CAMPUS_CARD_CONSUME_TAG_PLACE, data.get(4 * i + 1));
stringSparseArray.put(CAMPUS_CARD_CONSUME_TAG_MONEY, data.get(4 * i + 2));
stringSparseArray.put(CAMPUS_CARD_CONSUME_TAG_LEFT, data.get(4 * i + 3));
campusCardDataList.add(stringSparseArray);
}
if (!mRecyclerView.hasEmptyView()) {
mRecyclerView.setEmptyView(R.layout.list_empty_view, (ViewGroup) findViewById(R.id.recycle_view_container), false);
}
mAdapter.notifyDataSetChanged();
}
}
Expand All @@ -130,15 +136,20 @@ public void onOk(int what, @NonNull ArrayList<String> data) {
public void onPasswordError() {
dismissProgressDialog();
Snackbar.make(fab, R.string.error_password, Snackbar.LENGTH_LONG).setAction("Action", null).show();
if (!mRecyclerView.hasEmptyView()) {
mRecyclerView.setEmptyView(R.layout.list_empty_view, (ViewGroup) findViewById(R.id.recycle_view_container), false);
}
}

@Override
public void onTimeoutError() {
dismissProgressDialog();
Snackbar.make(fab, R.string.connection_timeout, Snackbar.LENGTH_LONG).setAction("Action", null).show();
if (!mRecyclerView.hasEmptyView()) {
mRecyclerView.setEmptyView(R.layout.list_empty_view, (ViewGroup) findViewById(R.id.recycle_view_container), false);
}
}

//
private class CampusCardAdapter extends RecyclerViewWithEmptySupport.Adapter<CampusCardAdapter.ViewHolder> {
List<SparseArray<String>> data;

Expand All @@ -156,9 +167,9 @@ public CampusCardAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int vie
public void onBindViewHolder(CampusCardAdapter.ViewHolder holder, int position) {
SparseArray<String> item = data.get(position);
holder.consumePlace.setText(item.get(CAMPUS_CARD_CONSUME_TAG_PLACE));
holder.consumeMoney.setText(getString(R.string.campus_card_consum_moey, item.get(CAMPUS_CARD_CONSUME_TAG_MONEY)));
holder.consumeLeft.setText(getString(R.string.campus_card_consum_left, item.get(CAMPUS_CARD_CONSUME_TAG_LEFT)));
holder.consumeTime.setText(item.get(CAMPUS_CARD_CONSUME_TAG_TIME));
holder.consumeMoney.setText(item.get(CAMPUS_CARD_CONSUME_TAG_MONEY));
holder.consumeLeft.setText(item.get(CAMPUS_CARD_CONSUME_TAG_LEFT));
holder.tagImage.setImageResource(StringUtils.getConsumptionTypeResourceByPlace(item.get(CAMPUS_CARD_CONSUME_TAG_PLACE)));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,8 @@ public void setEmptyView(@LayoutRes int emptyViewLayout, ViewGroup parent, boole
this.emptyView = view;
checkIfEmpty();
}

public boolean hasEmptyView() {
return emptyView != null;
}
}
Binary file added app/src/main/res/drawable-xxhdpi/play_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/play_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/play_3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/play_4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/play_5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/play_6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/play_7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/play_8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
81 changes: 81 additions & 0 deletions app/src/main/res/drawable/ic_nodata_common.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?xml version="1.0" encoding="utf-8"?>
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="1024dp"
android:height="1024dp"
android:viewportWidth="1024"
android:viewportHeight="1024">

<path
android:fillColor="#DDDDDD"
android:pathData="M519.261867 813.3376c-100.932267 0-201.873067
0.008533-302.813867-0.017067-25.506133
0-26.146133-0.682667-26.154667-27.076266-0.034133-72.669867-0.341333-145.348267
0.3072-218.001067 0.110933-11.8016 2.525867-24.456533 7.210667-35.2256
31.8464-73.198933 64.878933-145.877333 96.785067-219.0592 6.016-13.7984
14.045867-18.8416 28.928-18.773333 132.974933 0.477867 265.941333 0.503467
398.907733-0.017067 15.249067-0.068267 22.647467 5.7856 28.245333 19.541333
29.9264 73.3696 60.817067 146.3296 90.820267 219.656534 3.8144 9.3184 6.178133
19.950933 6.2464 29.994666 0.512 75.101867 0.3328 150.2208 0.256
225.3312-0.017067 22.126933-1.553067 23.6032-24.1152 23.6288-101.538133
0.042667-203.076267 0.017067-304.622933 0.017067z m-0.6144-11.886933c99.114667 0
198.212267-0.196267 297.326933 0.2304 14.045867 0.0512 20.736-3.114667
20.565333-19.157334-0.682667-67.7632-0.571733-135.543467-0.0512-203.3152
0.110933-14.225067-4.5056-19.3024-18.773333-19.0976-46.523733 0.6656-93.090133
1.220267-139.579733-0.256-19.566933-0.622933-26.8544 5.2736-30.208
25.173334-11.630933 69.1712-78.592 115.703467-147.0464
104.285866-56.277333-9.378133-98.0992-50.1248-107.374934-106.837333-2.816-17.211733-9.275733-23.057067-26.88-22.587733-47.701333
1.28-95.488 1.032533-143.2064 0.128-16.520533-0.3072-21.9136 5.0176-21.7088
21.845333 0.7936 65.314133 0.896 130.6624-0.0512 195.968-0.256 18.141867
4.642133 24.209067 23.296 24.0384 97.902933-0.8704 195.797333-0.401067
293.691734-0.418133zM292.266667 548.471467c32.2048 0 58.6752 0.7936
85.077333-0.2816 17.5616-0.708267 24.132267 4.8128 25.002667 23.662933 2.756267
60.3648 56.1664 108.4928 117.956266 108.586667 63.061333 0.085333
116.727467-47.872 119.304534-109.056 0.827733-19.490133 8.490667-23.765333
25.472-23.159467 26.3168 0.938667 52.701867 0.256 83.370666
0.256-8.823467-28.219733-15.889067-52.608-24.490666-76.4416-1.322667-3.6608-9.728-6.673067-14.8736-6.690133-125.047467-0.366933-250.112-0.392533-375.159467
0.059733-5.4528 0.017067-14.114133 3.874133-15.7952 8.132267-9.045333
23.005867-16.349867 46.711467-25.856 74.922666z m228.087466-95.3856c61.678933 0
123.383467-0.221867 185.0624 0.187733 12.680533 0.085333 18.816-3.208533
18.551467-17.4336-0.6912-37.256533-0.5888-74.538667-0.0512-111.803733
0.187733-12.9536-5.0688-16.8448-17.237333-16.810667-123.989333 0.256-247.970133
0.2816-371.950934-0.017067-12.791467-0.034133-16.827733 5.060267-16.674133
17.390934 0.469333 36.0448 0.861867 72.123733-0.1792 108.142933-0.477867
16.469333 5.5552 20.829867 21.0432 20.650667 60.4672-0.708267
120.951467-0.290133 181.435733-0.3072z m316.245334 95.086933L741.256533
318.72l-4.650666 0.938667c-0.3584 5.76-1.006933 11.537067-1.024 17.3056-0.119467
26.8288 1.4848 53.76-0.426667 80.452266-2.850133 39.944533 5.8624 77.5168
19.003733 114.372267 2.2528 6.314667 8.738133 15.189333 13.8752 15.633067
20.804267 1.792 41.838933 0.750933 68.5568 0.750933z m-634.914134
0.256c24.789333 0 43.963733-0.785067 63.0528 0.273067 13.533867 0.750933
19.029333-5.4272 23.082667-17.476267 12.706133-37.751467 21.8624-75.7248
18.9184-116.232533-1.723733-23.645867-0.2304-47.530667-0.392533-71.3216-0.042667-5.034667-0.981333-10.043733-1.5104-15.069867l-4.8896-1.0752L201.6768
548.437333zM564.138667 890.1632c29.764267 2.3296 57.890133 6.698667 85.870933
5.9392 18.056533-0.4864 36.6336-6.690133 53.589333-13.738667 11.4688-4.778667
16.008533-4.010667 23.005867 6.434134 12.4416 18.577067 25.8048 37.009067
41.489067 52.7616 24.430933 24.541867 54.9888 37.034667 90.4704
37.4528-30.788267 15.9232-63.291733 25.403733-97.3568 27.886933-6.664533
0.477867-15.9488-6.212267-20.522667-12.270933-7.6288-10.112-15.547733-11.1616-26.6496-8.3968-12.834133
3.2-26.001067 5.717333-39.159467 6.613333-6.6816
0.4608-14.267733-2.0736-20.3776-5.2992-41.173333-21.751467-68.642133-56.5504-90.359466-97.3824z
m250.231466
97.152c-3.968-4.8896-4.778667-6.8864-6.1952-7.492267-38.203733-16.2816-65.399467-44.714667-87.765333-79.104-2.6112-4.010667-12.629333-6.971733-17.211733-5.188266-29.969067
11.6736-60.305067 16.4864-92.151467
10.5216-7.3216-1.3824-14.916267-1.28-23.7824-1.962667 24.635733 44.740267
64.571733 93.508267 127.377067 71.9872 13.218133-4.539733 22.468267-1.186133
31.863466 9.4464 5.060267 5.717333 15.0784 9.9584 22.698667 9.710933
14.1056-0.452267 28.1088-4.6848 45.166933-7.918933zM925.5168 8.541867c23.688533
70.852267 23.150933 175.505067-77.602133 208.213333 0-1.8176-0.622933-3.7888
0.085333-4.744533 30.702933-40.9088 39.253333-88.226133
38.161067-137.915734-0.2816-13.1584 2.030933-22.510933 12.586666-31.616
10.1888-8.772267 17.152-21.393067 26.769067-33.937066z m-50.082133
179.413333c47.232-11.861333 64.366933-110.429867 42.24-151.927467-7.816533
11.281067-20.608 21.290667-20.804267 31.530667-0.750933 40.516267-4.8384
80-21.435733 120.405333zM163.669333 382.011733c-3.805867 10.7776-8.1664
23.150933-12.484266
35.447467-31.573333-6.510933-54.613333-31.624533-65.5104-72.004267 12.373333
9.4976 22.766933 20.437333 35.456 26.410667 12.501333 5.888 27.332267 6.7584
42.538666 10.146133zM733.098667 161.3824c12.714667 23.125333 6.058667
56.32-16.1792 81.834667-1.450667-9.019733-4.548267-15.906133-3.0208-21.504
2.696533-9.856 9.070933-18.628267 12.3136-28.3904 3.157333-9.454933
4.3264-19.584 6.894933-31.940267z" />
</vector>
19 changes: 8 additions & 11 deletions app/src/main/res/layout/content_about.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,17 @@
android:layout_height="match_parent"
android:orientation="vertical">

<Space
android:layout_width="match_parent"
android:layout_height="20sp" />

<RelativeLayout
android:id="@+id/about_header_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:onClick="clickHandle"
android:clickable="true"
android:paddingTop="20dp"
android:paddingBottom="20dp">

<ImageView
android:id="@+id/logo"
android:id="@+id/app_icon"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerHorizontal="true"
Expand All @@ -33,7 +34,7 @@
android:id="@+id/this_version"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/logo"
android:layout_below="@id/app_icon"
android:layout_marginTop="15dp"
android:gravity="center_horizontal"
android:textColor="@color/black"
Expand All @@ -50,10 +51,6 @@
android:textSize="16sp" />
</RelativeLayout>

<Space
android:layout_width="match_parent"
android:layout_height="20sp" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
26 changes: 19 additions & 7 deletions app/src/main/res/layout/list_empty_view.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">

<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:id="@+id/empty_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World" />
</LinearLayout>
android:layout_centerInParent="true"
android:text="@string/empty_common_no_data"/>

<android.support.v7.widget.AppCompatImageView
android:id="@+id/empty_image"
android:layout_width="@dimen/empty_image_width"
android:layout_height="@dimen/empty_image_height"
android:layout_above="@id/empty_text"
android:layout_centerHorizontal="true"
app:srcCompat="@drawable/ic_nodata_common"/>

</RelativeLayout>
13 changes: 7 additions & 6 deletions app/src/main/res/layout/recycle_view_campus_card.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,23 @@
android:layout_height="wrap_content" />

<android.support.v7.widget.AppCompatTextView
android:id="@+id/campus_card_consume_time"
android:id="@+id/campus_card_consume_money"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/campus_card_consume_place" />
android:layout_below="@+id/campus_card_consume_place" />

<android.support.v7.widget.AppCompatTextView
android:id="@+id/campus_card_consume_money"
android:id="@+id/campus_card_consume_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/campus_card_consume_time" />
android:layout_below="@+id/campus_card_consume_money" />


<android.support.v7.widget.AppCompatTextView
android:id="@+id/campus_card_consume_left"
android:id="@+id/campus_card_consume_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/campus_card_consume_money" />
android:layout_below="@+id/campus_card_consume_left" />
</RelativeLayout>

</LinearLayout>
Loading

0 comments on commit 856923a

Please sign in to comment.