Skip to content

Commit

Permalink
支持Stackmat
Browse files Browse the repository at this point in the history
  • Loading branch information
MeigenChou committed Mar 11, 2021
1 parent 882dbf1 commit d4b4e7d
Show file tree
Hide file tree
Showing 37 changed files with 722 additions and 103 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "com.dctimer"
minSdkVersion 14
targetSdkVersion 28
versionCode 40
versionName "1.2.1"
versionCode 41
versionName "1.2.2"
}
buildTypes {
release {
Expand Down
29 changes: 18 additions & 11 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION" />
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />

<uses-feature android:name="android.hardware.bluetooth_le" android:required="false"/>
<uses-feature
android:name="android.hardware.bluetooth_le"
android:required="false" />

<application
android:name=".APP"
Expand All @@ -24,7 +27,8 @@
android:supportsRtl="true"
android:theme="@style/AppTheme.NoActionBar"
android:usesCleartextTraffic="true">
<activity android:name=".activity.MainActivity"
<activity
android:name=".activity.MainActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"
android:windowSoftInputMode="adjustPan">
Expand All @@ -34,20 +38,24 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity android:name=".activity.SessionActivity"
<activity
android:name=".activity.SessionActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/title_activity_session" />

<activity android:name=".activity.DetailActivity"
<activity
android:name=".activity.DetailActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/title_activity_detail" />

<activity android:name=".activity.WebActivity"
<activity
android:name=".activity.WebActivity"
android:configChanges="orientation|keyboardHidden|screenSize" />

<activity android:name=".activity.GraphActivity"
<activity
android:name=".activity.GraphActivity"
android:configChanges="orientation|keyboardHidden|screenSize" />
<activity
android:name=".activity.TestActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/action_stackmat" />

<provider
android:name="android.support.v4.content.FileProvider"
Expand All @@ -58,7 +66,6 @@
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths" />
</provider>

</application>

</manifest>
10 changes: 10 additions & 0 deletions app/src/main/java/com/dctimer/APP.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.ActivityInfo;
import android.media.AudioFormat;
import android.util.DisplayMetrics;

import com.dctimer.database.DBHelper;
Expand Down Expand Up @@ -91,6 +92,8 @@ public class APP extends Application {
public static boolean dropToStop;
public static double sensitivity;
public static boolean darkList;
public static int samplingRate;
public static int dataFormat;

@Override
public void onCreate() {
Expand Down Expand Up @@ -210,6 +213,8 @@ public void readPref(SharedPreferences sp) { //读取配置 TODO
vibrateTime = sp.getInt("vibtime", 2); // 震动时长
screenOri = sp.getInt("screenori", 0); // 屏幕方向
savePath = sp.getString("scrpath", defaultPath);
samplingRate = sp.getInt("srate", 44100);
dataFormat = sp.getInt("dform", AudioFormat.ENCODING_PCM_8BIT);
}

public static void resetPref() {
Expand All @@ -228,5 +233,10 @@ public static void resetPref() {
colors[0] = 0xff2196F3; colors[1] = 0xffffffff; colors[2] = 0xffff00ff;
colors[3] = 0xffff0000; colors[4] = 0xff009900;
for (int i = 0; i < 4; i++) swipeType[i] = i + 1;
samplingRate = 44100; dataFormat = AudioFormat.ENCODING_PCM_8BIT;
}

public static int getPixel(int dp) {
return (int) (dpi * dp);
}
}
7 changes: 3 additions & 4 deletions app/src/main/java/com/dctimer/activity/GraphActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ public void onClick(View view) {
String[] items = getResources().getStringArray(R.array.item_date_range);
weekText = getResources().getStringArray(R.array.item_week);
monthText = getResources().getStringArray(R.array.item_month);
Log.w("dct", "month " + Arrays.toString(monthText));
for (int i = 0; i < items.length; i++) {
tabLayout.addTab(tabLayout.newTab().setText(items[i]));
}
Expand Down Expand Up @@ -429,7 +428,7 @@ private void refresh(int width, int height) {
canvas.drawRect(0, 0, width, height, p);
p.setColor(0xffdddddd);
p.setStrokeWidth(APP.dpi);
int fontSize = (int) (APP.dpi * 15);
int fontSize = APP.getPixel(15);
canvas.drawLine(0, height - fontSize, width, height - fontSize, p);
for (int i=0; i<bins; i++) {
float x = (float) i * width / bins;
Expand Down Expand Up @@ -457,12 +456,12 @@ private void refresh(int width, int height) {
p.setTextSize(fontSize);
for (int i=0; i<bins; i++) {
float x = (float) i * width / bins;
canvas.drawText(getDateText(i), x + APP.dpi, height - APP.dpi * 2, p);
canvas.drawText(getDateText(i), x + APP.dpi, height - APP.getPixel(2), p);
}
if (select >= 0 && data[select] > 0) {
p.setTextAlign(Paint.Align.CENTER);
int h = rectHeight * data[select] / maxValue;
canvas.drawText(String.valueOf(data[select]), (select + 0.5f) * width / bins, height - fontSize - h - APP.dpi * 2, p);
canvas.drawText(String.valueOf(data[select]), (select + 0.5f) * width / bins, height - fontSize - h - APP.getPixel(2), p);
}

graph.invalidate();
Expand Down
72 changes: 59 additions & 13 deletions app/src/main/java/com/dctimer/activity/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,11 @@ protected void onResume() {
if (sensorManager != null && sensor != null) {
sensorManager.registerListener(mSensorEventListener, sensor, SensorManager.SENSOR_DELAY_NORMAL);
}
if (stackmat != null) {
stackmat.setSamplingRate(samplingRate);
stackmat.setDataFormat(dataFormat);
stackmat.start();
}
}

@Override
Expand All @@ -420,6 +425,10 @@ protected void onPause() {
if (sensorManager != null && sensor != null) {
sensorManager.unregisterListener(mSensorEventListener, sensor);
}
if (stackmat != null) {
stackmat.stop();
//stackmat = null;
}
}

@Override
Expand Down Expand Up @@ -675,11 +684,23 @@ public boolean onNavigationItemSelected(MenuItem item) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(context, PERMISSIONS[0]) == PackageManager.PERMISSION_GRANTED) {
new ImportExportDialog().newInstance().show(getSupportFragmentManager(), "ImportExport");
} else ActivityCompat.requestPermissions(MainActivity.this, PERMISSIONS, 3);
} else ActivityCompat.requestPermissions(this, PERMISSIONS, 3);
} else new ImportExportDialog().newInstance().show(getSupportFragmentManager(), "ImportExport");
break;
case R.id.nav_stackmat:
if (Build.VERSION.SDK_INT > 22) {
if (ContextCompat.checkSelfPermission(context, Manifest.permission.RECORD_AUDIO)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.RECORD_AUDIO },
8);
break;
}
}
Intent intent = new Intent(context, TestActivity.class);
startActivity(intent);
break;
case R.id.nav_algorithm: //公式库
Intent intent = new Intent(context, WebActivity.class);
intent = new Intent(context, WebActivity.class);
String web = "http://algdb.net";
intent.putExtra("web", web);
intent.putExtra("title", "AlgDb.net");
Expand All @@ -692,6 +713,20 @@ public boolean onNavigationItemSelected(MenuItem item) {
intent.putExtra("title", "alg.cubing.net");
startActivity(intent);
break;
case R.id.nav_wca:
intent = new Intent(context, WebActivity.class);
web = "https://www.worldcubeassociation.org/";
intent.putExtra("web", web);
intent.putExtra("title", "World Cube Association");
startActivity(intent);
break;
case R.id.nav_cubing:
intent = new Intent(context, WebActivity.class);
web = "https://cubingchina.com/";
intent.putExtra("web", web);
intent.putExtra("title", getString(R.string.menu_cubing));
startActivity(intent);
break;
case R.id.nav_test:
//随机生成成绩
result.insert(10000, 12000, 4000000, currentScramble.getScramble());
Expand Down Expand Up @@ -796,13 +831,16 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
scanDevice();
} else if (requestCode == 7) { //Stackmat
startStackmat();
} else if (requestCode == 8) {
Intent intent = new Intent(this, TestActivity.class);
startActivity(intent);
}
}
}

private void startStackmat() {
if (stackmat == null) {
stackmat = new Stackmat(this);
stackmat = new Stackmat(this, samplingRate, dataFormat);
}
setTimerText("---");
stackmat.start();
Expand Down Expand Up @@ -1265,7 +1303,10 @@ public void onClick(DialogInterface dialogInterface, int i) {
stAdapter.setText(position, itemStr[0][i]);
if (i < 2) {
bluetoothTools.disconnect();
if (stackmat != null) stackmat.stop();
if (stackmat != null) {
stackmat.stop();
stackmat = null;
}
if (i == 0)
setTimerText("0" + (decimalMark == 0 ? "." : ",") + (timerAccuracy == 0 ? "00" : "000"));
else setTimerText("IMPORT");
Expand Down Expand Up @@ -1604,11 +1645,11 @@ public void run() {
case 33: //n阶
int[] cs = {sp.getInt("csn1", Color.YELLOW), sp.getInt("csn2", Color.BLUE), sp.getInt("csn3", Color.RED),
sp.getInt("csn4", Color.WHITE), sp.getInt("csn5", 0xff009900), sp.getInt("csn6", 0xffff9900)};
colorSchemeView = new ColorSchemeView(this, (int) (dpi * 290), cs, 1);
colorSchemeView = new ColorSchemeView(this, APP.getPixel(290), cs, 1);
AlertDialog dialog = new AlertDialog.Builder(context).setTitle(getString(R.string.scheme_cube)).setView(colorSchemeView)
.setNegativeButton(R.string.btn_close, null).setNeutralButton(R.string.scheme_reset, null).show();
WindowManager.LayoutParams params = dialog.getWindow().getAttributes();
params.width = (int) (dpi * 320);
params.width = APP.getPixel(320);
dialog.getWindow().setAttributes(params);
dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setTextColor(0xffff0000);
dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener(new View.OnClickListener() {
Expand All @@ -1630,7 +1671,7 @@ public void onClick(View view) { //配色复位
dialog = new AlertDialog.Builder(context).setTitle(getString(R.string.scheme_pyrm)).setView(colorSchemeView)
.setNegativeButton(R.string.btn_close, null).setNeutralButton(R.string.scheme_reset, null).show();
params = dialog.getWindow().getAttributes();
params.width = (int) (dpi * 320);
params.width = APP.getPixel(320);
dialog.getWindow().setAttributes(params);
dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setTextColor(0xffff0000);
dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener(new View.OnClickListener() {
Expand All @@ -1650,7 +1691,7 @@ public void onClick(View view) {
dialog = new AlertDialog.Builder(context).setTitle(getString(R.string.scheme_sq)).setView(colorSchemeView)
.setNegativeButton(R.string.btn_close, null).setNeutralButton(R.string.scheme_reset, null).show();
params = dialog.getWindow().getAttributes();
params.width = (int) (dpi * 320);
params.width = APP.getPixel(320);
dialog.getWindow().setAttributes(params);
dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setTextColor(0xffff0000);
dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener(new View.OnClickListener() {
Expand All @@ -1670,7 +1711,7 @@ public void onClick(View view) {
dialog = new AlertDialog.Builder(context).setTitle(getString(R.string.scheme_skewb)).setView(colorSchemeView)
.setNegativeButton(R.string.btn_close, null).setNeutralButton(R.string.scheme_reset, null).show();
params = dialog.getWindow().getAttributes();
params.width = (int) (dpi * 320);
params.width = APP.getPixel(320);
dialog.getWindow().setAttributes(params);
dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setTextColor(0xffff0000);
dialog.getButton(AlertDialog.BUTTON_NEUTRAL).setOnClickListener(new View.OnClickListener() {
Expand Down Expand Up @@ -2257,7 +2298,7 @@ private void removePref() { //移除配置
edit.remove("multp"); edit.remove("minxc"); edit.remove("simss");
edit.remove("l1len"); edit.remove("l2len"); edit.remove("sside");
edit.remove("pside"); edit.remove("rside"); edit.remove("group");
edit.remove("decim");
edit.remove("decim"); edit.remove("dform");
edit.remove("hidscr"); edit.remove("ttsize"); edit.remove("stsize");
edit.remove("cube2l"); edit.remove("scrgry"); edit.remove("selses");
edit.remove("ismulp"); edit.remove("svsize");
Expand Down Expand Up @@ -2327,9 +2368,10 @@ else if (enterTime == 2 || enterTime == 3) { //TODO SS计时器

private void setStatsLabel() {
StringBuilder sb = new StringBuilder();
sb.append(result.getSolved()).append('/').append(result.length()).append('\n');
sb.append(result.getSolved()).append('/').append(result.length()).append("\n");
sb.append("best: ").append(result.getBestTime()).append("\n");
sb.append(avg1Type == 0 ? "ao" : "mo").append(avg1len).append(": ");
sb.append(result.getRollingAvg1(result.length() - 1)).append('\n');
sb.append(result.getRollingAvg1(result.length() - 1)).append("\n");
sb.append(avg2Type == 0 ? "ao" : "mo").append(avg2len).append(": ");
sb.append(result.getRollingAvg2(result.length() - 1));
tvStat.setText(sb.toString());
Expand Down Expand Up @@ -2453,6 +2495,7 @@ public void setImageSize() { //设置打乱图大小
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams((int) (imageSize * dpi), (int) (imageSize * 3 * dpi) / 4);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
params.setMargins(0, 0, 0, APP.getPixel(5));
scrambleView.setLayoutParams(params);
}

Expand Down Expand Up @@ -2979,6 +3022,8 @@ public void showDetail(int pos) {
String date = result.getString(5);
String comment = result.getString(6);
String solution = result.getString(13);
int id = result.getId(p);
Log.w("dct", "id: "+id);
if (date == null) date = "";
if (multiPhase > 0) { //TODO 显示各分段成绩

Expand Down Expand Up @@ -3087,7 +3132,8 @@ public void onClick(DialogInterface dialogInterface, int i) {
}

private void delete(int num) {
result.delete(num);
int res = result.delete(num);
if (res != 0) Toast.makeText(context, R.string.delete_fail, Toast.LENGTH_SHORT).show();
btnSessionMean.setText(getString(R.string.session_mean, result.getSessionMean()));
result.calcAvg();
if (multiPhase > 0) result.calcMpMean();
Expand Down
Loading

0 comments on commit d4b4e7d

Please sign in to comment.