Skip to content

Commit

Permalink
Merge pull request #3 from kevin-44/master
Browse files Browse the repository at this point in the history
v3.1
  • Loading branch information
QuantumLeaper authored Sep 5, 2019
2 parents 44c62e8 + 6552bf5 commit 226887e
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ android {
minSdkVersion 19
targetSdkVersion 26
versionCode 3
versionName "3.0"
versionName "3.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}
Expand Down
74 changes: 73 additions & 1 deletion app/src/main/java/upx/uplexa/androidminer/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
Expand Down Expand Up @@ -99,6 +100,7 @@ public class MainActivity extends AppCompatActivity implements OnItemSelectedLis
public static Context contextOfApplication;
public String wallet;
public String pref;
private float brightness = -1;

public static Context getContextOfApplication(){
return contextOfApplication;
Expand Down Expand Up @@ -170,6 +172,9 @@ protected void onCreate(Bundle savedInstanceState) {
}
edMaxCpu = findViewById(R.id.maxcpu);
cbUseWorkerId = findViewById(R.id.use_worker_id);
if(PreferenceHelper.getBlackModeState()) {
PreferenceHelper.setBlackModeState(false);
}

// check architecture
if (!Arrays.asList(SUPPORTED_ARCHITECTURES).contains(Build.CPU_ABI.toLowerCase())) {
Expand Down Expand Up @@ -284,6 +289,7 @@ public void onClick(View v) {

private void startMining(View view) {
if (binder == null) return;
PreferenceHelper.setBlackModeState(false);
Spinner edThreads = findViewById(R.id.threads);
Spinner edMaxCpu = findViewById(R.id.maxcpu);
TextView threader = (TextView)edThreads.getSelectedView();
Expand All @@ -297,6 +303,70 @@ private void stopMining(View view) {
binder.getService().stopMining();
}

private void toggleLog(View view) {
if (PreferenceHelper.getLogState()) {
PreferenceHelper.setLogState(false);
Toast.makeText(this, "log: off", Toast.LENGTH_SHORT).show();
}
else {
PreferenceHelper.setLogState(true);
Toast.makeText(this, "log: on", Toast.LENGTH_SHORT).show();
}
}

public void toggleBlackMode(View view) {
if (PreferenceHelper.getBlackModeState()) {
PreferenceHelper.setBlackModeState(false);
findViewById(R.id.black_mode_background).setVisibility(View.GONE);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
WindowManager.LayoutParams layout = getWindow().getAttributes();
layout.screenBrightness = brightness;
getWindow().setAttributes(layout);
setFullscreen(false);
Toast.makeText(this, "black mode: off", Toast.LENGTH_SHORT).show();
}
else {
PreferenceHelper.setBlackModeState(true);
findViewById(R.id.black_mode_background).setVisibility(View.VISIBLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
WindowManager.LayoutParams layout = getWindow().getAttributes();
brightness = layout.screenBrightness;
layout.screenBrightness = 0.00001f;
getWindow().setAttributes(layout);
setFullscreen(true);
Toast.makeText(this, "black mode: on", Toast.LENGTH_SHORT).show();
}
}

private void setFullscreen(boolean state) {
if (state) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
else {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
& View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
& View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
& View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
& View.SYSTEM_UI_FLAG_FULLSCREEN
& View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
}

@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (PreferenceHelper.getBlackModeState()) {
setFullscreen(true);
}
}

@Override
protected void onResume() {
super.onResume();
Expand All @@ -319,11 +389,13 @@ public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
enableButtons(true);
findViewById(R.id.start).setOnClickListener(MainActivity.this::startMining);
findViewById(R.id.stop).setOnClickListener(MainActivity.this::stopMining);
findViewById(R.id.log).setOnClickListener(MainActivity.this::toggleLog);
findViewById(R.id.black_mode).setOnClickListener(MainActivity.this::toggleBlackMode);
int cores = binder.getService().getAvailableCores();
// write suggested cores usage into editText
int suggested = cores / 2;
if (suggested == 0) suggested = 1;
((TextView) findViewById(R.id.cpus)).setText(String.format("(%d %s)", cores, getString(R.string.cpus)));
((TextView) findViewById(R.id.cpus)).setText(String.format("(%d)", cores));
}

}
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/java/upx/uplexa/androidminer/MiningService.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ public int getAccepted() {
}

public String getOutput() {
if (!PreferenceHelper.getLogState())
return "- LOG: OFF Tap the 'LOG' button to enable it";
if (outputHandler != null && outputHandler.getOutput() != null)
return outputHandler.getOutput().toString();
else return "";
Expand Down Expand Up @@ -224,7 +226,9 @@ public void run() {
reader = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = reader.readLine()) != null) {
output.append(line + System.lineSeparator());
if (PreferenceHelper.getLogState()) {
output.append(line).append(System.lineSeparator());
}
if (line.contains("accepted")) {
accepted++;
} else if (line.contains("speed")) {
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/upx/uplexa/androidminer/PreferenceHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ public class PreferenceHelper {
final public static String KEY_DEMO_NAME = "YOUR_UPX_ADDRESS_HERE"; // Rename this, lol.
final public static String MINPAY_STRING = "MINPAY"; // Rename this, lol.
final public static String WORKER_STRING = "WORKER"; // Rename this, lol.
final public static String LOG_STATE_STRING = "LOG_STATE"; // Rename this, lol.
final public static String BLACK_MODE_STATE_STRING = "BLACK_MODE_STATE"; // Rename this, lol.
public static void setName(String value) {
MainActivity.preferences.edit().putString(KEY_DEMO_NAME, value ).commit();
}
Expand Down Expand Up @@ -34,4 +36,18 @@ public static String getWorkerID() {
return MainActivity.preferences.getString(WORKER_STRING,"");
}

public static void setLogState(boolean state) {
MainActivity.preferences.edit().putBoolean(LOG_STATE_STRING, state).commit();
}
public static boolean getLogState() {
return MainActivity.preferences.getBoolean(LOG_STATE_STRING,true);
}

public static void setBlackModeState(boolean state) {
MainActivity.preferences.edit().putBoolean(BLACK_MODE_STATE_STRING, state).commit();
}
public static boolean getBlackModeState() {
return MainActivity.preferences.getBoolean(BLACK_MODE_STATE_STRING,false);
}

}
25 changes: 25 additions & 0 deletions app/src/main/res/drawable/button_selector_black.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item android:right="0dp" android:top="5dp">
<shape>
<corners android:radius="1dp" />

</shape>
</item>
<item android:bottom="5dp" android:left="0dp">
<shape>
<gradient android:angle="270"
android:endColor="#3A3A3A" android:startColor="#4F4F4F" />
<stroke android:width="1dp" android:color="#3A3A3A" />
<corners android:radius="4dp" />
<padding android:bottom="15dp" android:left="10dp"
android:right="10dp" android:top="10dp" />
</shape>
</item>
</layer-list>
</item>

</selector>
25 changes: 25 additions & 0 deletions app/src/main/res/drawable/button_selector_green.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item android:right="0dp" android:top="5dp">
<shape>
<corners android:radius="1dp" />

</shape>
</item>
<item android:bottom="5dp" android:left="0dp">
<shape>
<gradient android:angle="270"
android:endColor="#05A001" android:startColor="#06D501" />
<stroke android:width="1dp" android:color="#05A001" />
<corners android:radius="4dp" />
<padding android:bottom="15dp" android:left="10dp"
android:right="10dp" android:top="10dp" />
</shape>
</item>
</layer-list>
</item>

</selector>
58 changes: 55 additions & 3 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
android:id="@+id/pool"
android:layout_width="match_parent"
android:layout_height="1dp"
android:text=""
android:text="149.56.89.162:9194"
android:visibility="invisible" />


Expand All @@ -132,11 +132,13 @@
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="15dp"
android:paddingRight="15dp">
android:paddingRight="15dp"
android:gravity="center">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:text="@string/threads"
android:textColor="#fff" />

Expand All @@ -152,13 +154,15 @@
android:id="@+id/cpus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:text=""
android:textColor="#fff" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginBottom="2dp"
android:text="@string/max_cpu_usage"
android:textColor="#fff" />

Expand All @@ -172,6 +176,7 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="2dp"
android:text="@string/percent"
android:textColor="#fff" />

Expand Down Expand Up @@ -239,7 +244,7 @@
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="40dp"
android:paddingBottom="15dp"
android:paddingTop="7dp"
android:textColor="#fff">


Expand All @@ -266,9 +271,56 @@
app:layout_constraintEnd_toEndOf="parent" />


</android.support.constraint.ConstraintLayout>


<android.support.constraint.ConstraintLayout
android:id="@+id/linearLayout_custom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="40dp"
android:paddingTop="5dp"
android:paddingBottom="15dp"
android:textColor="#fff">


<Button
android:id="@+id/log"
android:layout_width="150dp"
android:layout_height="45dp"
android:layout_marginEnd="25dp"
android:background="@drawable/button_selector_green"
android:text="@string/log"
android:textColor="#ffffff"
app:layout_constraintBaseline_toBaselineOf="@+id/black_mode"
app:layout_constraintEnd_toStartOf="@+id/black_mode" />


<Button
android:id="@+id/black_mode"
android:layout_width="150dp"
android:layout_height="45dp"
android:background="@drawable/button_selector_black"
android:text="@string/black_mode"
android:textColor="#ffffff"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />


</android.support.constraint.ConstraintLayout>
</LinearLayout>

<LinearLayout
android:id="@+id/black_mode_background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black"
android:orientation="vertical"
android:fitsSystemWindows="true"
android:visibility="gone"
android:onClick="toggleBlackMode" />

<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="black">#000000</color>
</resources>
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
<string name="help">Help</string>
<string name="cmd">Cmd</string>
<string name="stop">Stop</string>
<string name="log">Log</string>
<string name="black_mode">Black Mode</string>
<string name="threads">Threads</string>
<string name="max_cpu_usage">Max CPU</string>
<string name="percent">%</string>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.5.0'


// NOTE: Do not place your application dependencies here; they belong
Expand Down

0 comments on commit 226887e

Please sign in to comment.