42
42
import android .graphics .Bitmap ;
43
43
import android .graphics .BitmapFactory ;
44
44
import android .graphics .Point ;
45
+ import android .graphics .PorterDuff ;
46
+ import android .graphics .Rect ;
45
47
import android .graphics .drawable .Drawable ;
46
48
import android .net .Uri ;
47
49
import android .os .BatteryManager ;
66
68
import android .widget .LinearLayout ;
67
69
import android .widget .ProgressBar ;
68
70
import android .widget .SeekBar ;
69
- import android .widget .Space ;
70
71
import android .widget .TextView ;
71
72
import android .widget .Toast ;
72
73
import android .text .Spannable ;
94
95
import com .android .volley .VolleyError ;
95
96
import com .android .volley .toolbox .StringRequest ;
96
97
import com .android .volley .toolbox .Volley ;
97
- import com .github .anastr .speedviewlib .DeluxeSpeedView ;
98
+ import com .github .anastr .speedviewlib .SpeedView ;
98
99
import com .github .anastr .speedviewlib .TubeSpeedometer ;
99
100
import com .github .anastr .speedviewlib .components .Section ;
100
101
import com .google .android .material .bottomnavigation .BottomNavigationView ;
@@ -135,6 +136,8 @@ public class MainActivity extends BaseActivity
135
136
private boolean bPayoutDataReceived = false ;
136
137
137
138
private boolean bIgnoreCPUCoresEvent = false ;
139
+ private boolean bIsRestartEvent = false ;
140
+ private boolean bIsRestartDialogShown = false ;
138
141
139
142
// Settings
140
143
private boolean bDisableTemperatureControl = false ;
@@ -290,20 +293,34 @@ protected void onCreate(Bundle savedInstanceState) {
290
293
meterCores = findViewById (R .id .meter_cores );
291
294
meterCores .makeSections (1 , getResources ().getColor (R .color .c_yellow ), Section .Style .SQUARE );
292
295
meterCores .setMaxSpeed (nNbMaxCores );
293
- meterCores .speedTo (nCores );
296
+ meterCores .speedTo (nCores , 0 );
294
297
295
298
tvNbCores = findViewById (R .id .nbcores );
296
299
297
300
// Hashrate
298
301
meterHashrate = findViewById (R .id .meter_hashrate );
299
302
meterHashrate .makeSections (1 , getResources ().getColor (R .color .c_blue ), Section .Style .SQUARE );
303
+ /*ImageIndicator imageIndicatorHs = new ImageIndicator(getApplicationContext(), getResources().getDrawable(R.drawable.indicator_speed));
304
+ meterHashrate.setIndicator(imageIndicatorHs);*/
300
305
301
306
meterHashrate_avg = findViewById (R .id .meter_hashrate_avg );
302
307
meterHashrate_avg .makeSections (1 , getResources ().getColor (android .R .color .transparent ), Section .Style .SQUARE );
303
308
309
+ // Scale drawable
310
+ /*Bitmap bitmapAvg = Utils.getBitmapFromVectorDrawable(contextOfApplication, R.drawable.indicator_avg);
311
+ Drawable dAvg = new BitmapDrawable(getResources(), Bitmap.createScaledBitmap(bitmapAvg, 12, 6, true));
312
+ ImageIndicator imageIndicatorAvg = new ImageIndicator(getApplicationContext(), dAvg);
313
+ meterHashrate_avg.setIndicator(imageIndicatorAvg);*/
314
+
304
315
meterHashrate_max = findViewById (R .id .meter_hashrate_max );
305
316
meterHashrate_max .makeSections (1 , getResources ().getColor (android .R .color .transparent ), Section .Style .SQUARE );
306
317
318
+ // Scale drawable
319
+ /*Bitmap bitmapMax = Utils.getBitmapFromVectorDrawable(contextOfApplication, R.drawable.indicator_max);
320
+ Drawable dMax = new BitmapDrawable(getResources(), Bitmap.createScaledBitmap(bitmapMax, 12, 6, true));
321
+ ImageIndicator imageIndicatorMax = new ImageIndicator(getApplicationContext(), dMax);
322
+ meterHashrate_max.setIndicator(imageIndicatorMax);*/
323
+
307
324
tvHashrate = findViewById (R .id .hashrate );
308
325
tvStatus = findViewById (R .id .miner_status );
309
326
@@ -339,6 +356,9 @@ public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
339
356
return ;
340
357
341
358
if (isDeviceMining ()) {
359
+ if (bIsRestartDialogShown )
360
+ return ;
361
+
342
362
final Dialog dialog = new Dialog (MainActivity .this );
343
363
dialog .setContentView (R .layout .stop_mining );
344
364
dialog .setCancelable (false );
@@ -350,6 +370,8 @@ public void onClick(View v) {
350
370
nCores = sbCores .getProgress ();
351
371
Config .write ("cores" , Integer .toString (nCores ));
352
372
373
+ bIsRestartEvent = true ;
374
+
353
375
MainActivity .this .stopMining (); // Stop mining
354
376
355
377
// Start miner with small delay
@@ -363,6 +385,7 @@ public void run() {
363
385
updateCores ();
364
386
365
387
dialog .dismiss ();
388
+ bIsRestartDialogShown = false ;
366
389
}
367
390
});
368
391
@@ -379,10 +402,12 @@ public void run() {
379
402
});
380
403
381
404
dialog .dismiss ();
405
+ bIsRestartDialogShown = false ;
382
406
}
383
407
});
384
408
385
409
dialog .show ();
410
+ bIsRestartDialogShown = true ;
386
411
}
387
412
else {
388
413
nCores = sbCores .getProgress ();
@@ -702,7 +727,7 @@ private void updateCores() {
702
727
String sCores = nCores + "/" + nNbMaxCores ;
703
728
tvNbCores .setText (sCores );
704
729
705
- meterCores .speedTo (nCores );
730
+ meterCores .speedTo (nCores , 0 );
706
731
}
707
732
708
733
@ Override
@@ -922,6 +947,9 @@ private void toggleMiningState() {
922
947
}
923
948
924
949
private void setMiningButtonState (Boolean state ) {
950
+ if (bIsRestartEvent )
951
+ return ;
952
+
925
953
Drawable buttonDrawableStart = btnStart .getBackground ();
926
954
buttonDrawableStart = DrawableCompat .wrap (buttonDrawableStart );
927
955
@@ -945,6 +973,24 @@ private void setMiningButtonState(Boolean state) {
945
973
}
946
974
}
947
975
976
+ private void enableSliderCores (boolean enable ) {
977
+ if (bIsRestartEvent )
978
+ return ;
979
+
980
+ Rect bounds = sbCores .getProgressDrawable ().getBounds ();
981
+
982
+ if (enable ) {
983
+ sbCores .setProgressDrawable (getResources ().getDrawable (R .drawable .seekbar_ruler_yellow ));
984
+ sbCores .getThumb ().setColorFilter (getResources ().getColor (R .color .c_white ), PorterDuff .Mode .SRC_IN );
985
+ }
986
+ else {
987
+ sbCores .setProgressDrawable (getResources ().getDrawable (R .drawable .seekbar_ruler_inactive ));
988
+ sbCores .getThumb ().setColorFilter (getResources ().getColor (R .color .c_light_grey ), PorterDuff .Mode .SRC_IN );
989
+ }
990
+
991
+ sbCores .getProgressDrawable ().setBounds (bounds );
992
+ }
993
+
948
994
private void setMinerStatus (Integer status ) {
949
995
if (status == STATE_STOPPED ) {
950
996
llStatus .setVisibility (View .GONE );
@@ -962,6 +1008,7 @@ private void setMinerStatus(Integer status) {
962
1008
963
1009
stopTimerStatusHashrate ();
964
1010
resetHashrateTicks ();
1011
+ enableSliderCores (true );
965
1012
}
966
1013
else if (status == STATE_MINING ) {
967
1014
if (tvHashrate .getText ().equals ("0" )) {
@@ -979,6 +1026,8 @@ else if(status == STATE_MINING) {
979
1026
View v = findViewById (R .id .main_navigation );
980
1027
v .setKeepScreenOn (true );
981
1028
}
1029
+
1030
+ enableSliderCores (false );
982
1031
}
983
1032
else {
984
1033
llStatus .setVisibility (View .VISIBLE );
@@ -1042,7 +1091,7 @@ public void stopTimerStatusHashrate() {
1042
1091
}
1043
1092
1044
1093
private void resetHashrateTicks () {
1045
- DeluxeSpeedView meterTicks = findViewById (R .id .meter_hashrate_ticks );
1094
+ SpeedView meterTicks = findViewById (R .id .meter_hashrate_ticks );
1046
1095
meterTicks .setMaxSpeed (500 );
1047
1096
meterTicks .setTickNumber (0 );
1048
1097
meterTicks .setTextColor (getResources ().getColor (android .R .color .transparent ));
@@ -1053,9 +1102,13 @@ private void resetHashrateTicks() {
1053
1102
}
1054
1103
1055
1104
private void updateHashrateTicks (float fMax ) {
1056
- DeluxeSpeedView meterTicks = findViewById (R .id .meter_hashrate_ticks );
1105
+ SpeedView meterTicks = findViewById (R .id .meter_hashrate_ticks );
1057
1106
if (meterTicks .getTickNumber () == 0 && fMax > 0 ) {
1058
- float hrMax = nNbMaxCores * fMax / nCores * 1.05f ;
1107
+ float hrMax = nNbMaxCores * fMax / nCores ;
1108
+ if (!nCores .equals (nNbMaxCores )) {
1109
+ hrMax = hrMax * 1.05f ;
1110
+ }
1111
+
1059
1112
meterTicks .setMaxSpeed (hrMax );
1060
1113
meterTicks .setTickNumber (10 );
1061
1114
meterTicks .setTextColor (getResources ().getColor (R .color .txt_main ));
@@ -1091,7 +1144,7 @@ private void updateHashrate(float fSpeed, float fMax) {
1091
1144
if (!isDeviceMining () || fSpeed < 0.0f )
1092
1145
return ;
1093
1146
1094
- DeluxeSpeedView meterTicks = findViewById (R .id .meter_hashrate_ticks );
1147
+ SpeedView meterTicks = findViewById (R .id .meter_hashrate_ticks );
1095
1148
if (meterTicks .getTickNumber () == 0 ) {
1096
1149
updateHashrateTicks (fMax );
1097
1150
@@ -1453,6 +1506,8 @@ public void onStateChange(Boolean state) {
1453
1506
1454
1507
setStatusText ("Miner Stopped" );
1455
1508
}
1509
+
1510
+ bIsRestartEvent = false ;
1456
1511
});
1457
1512
}
1458
1513
@@ -1470,9 +1525,9 @@ public void onStatusChange(String status, float speed, float max, Integer accept
1470
1525
}
1471
1526
1472
1527
if (accepted == 1 ) {
1473
- tvAcceptedShares .setTextColor (getResources ().getColor (R .color .txt_main ));
1474
- tvDifficulty .setTextColor (getResources ().getColor (R .color .txt_main ));
1475
- tvConnection .setTextColor (getResources ().getColor (R .color .txt_main ));
1528
+ tvAcceptedShares .setTextColor (getResources ().getColor (R .color .c_white ));
1529
+ tvDifficulty .setTextColor (getResources ().getColor (R .color .c_white ));
1530
+ tvConnection .setTextColor (getResources ().getColor (R .color .c_white ));
1476
1531
}
1477
1532
1478
1533
updateHashrate (speed , max );
@@ -1674,9 +1729,9 @@ private void enableStartBtn(boolean enabled) {
1674
1729
btnStart .setBackground (buttonDrawable );
1675
1730
btnStart .setTextColor (getResources ().getColor (R .color .c_white ));
1676
1731
} else {
1677
- DrawableCompat .setTint (buttonDrawable , getResources ().getColor (R .color .c_black ));
1732
+ DrawableCompat .setTint (buttonDrawable , getResources ().getColor (R .color .c_inactive ));
1678
1733
btnStart .setBackground (buttonDrawable );
1679
- btnStart .setTextColor (getResources ().getColor (R .color .c_black ));
1734
+ btnStart .setTextColor (getResources ().getColor (R .color .c_inactive ));
1680
1735
}
1681
1736
1682
1737
btnStart .setEnabled (enabled );
0 commit comments