]> Git Repo - Android-Verus.git/blame - app/src/main/java/com/verus/miner/MainActivity.java
now sets the stop button if it errors
[Android-Verus.git] / app / src / main / java / com / verus / miner / MainActivity.java
CommitLineData
9899aa46 1package com.verus.miner;
ebd9203a 2
3import androidx.appcompat.app.AppCompatActivity;
4import androidx.core.app.ActivityCompat;
5
6import android.content.Context;
7import android.content.pm.PackageManager;
d4b6bfef 8import android.text.method.ScrollingMovementMethod;
ebd9203a 9import android.util.Log;
10import android.view.View;
11import android.widget.*;
12import android.os.*;
13import java.io.*;
14
9899aa46 15import com.verus.miner.VerusMiner;
ebd9203a 16
d4b6bfef 17/*
18how long will it run b4 i have to much data in the logall variable
19bench mark doesnt work idk y
20 */
ebd9203a 21import android.os.Bundle;
22
23public class MainActivity extends AppCompatActivity {
24 VerusMiner miner;
25 Handler handler = new Handler();
26 boolean mining = false;
27 String LOGAll = "";
28
29 @Override
30 protected void onCreate(Bundle savedInstanceState) {
31 super.onCreate(savedInstanceState);
32 setContentView(R.layout.activity_main);
33 File homePath = MainActivity.this.getFilesDir();
c0230718 34 Log.e("test",homePath.getAbsolutePath());
35
d4b6bfef 36 miner = new VerusMiner(homePath,this);
ebd9203a 37 int PERMISSION_ALL = 1;
38 String[] PERMISSIONS = {
39 android.Manifest.permission.ACCESS_NETWORK_STATE,
ebd9203a 40 android.Manifest.permission.INTERNET,
41 };
42
43 if (!hasPermissions(this, PERMISSIONS)) {
44 ActivityCompat.requestPermissions(this, PERMISSIONS, PERMISSION_ALL);
45 }
46 EditText threads = (EditText) findViewById(R.id.threads);
47 EditText worker = (EditText) findViewById(R.id.worker);
48 EditText address = (EditText) findViewById(R.id.address);
49 EditText pool = (EditText) findViewById(R.id.pool);
50 EditText pass = (EditText) findViewById(R.id.pass);
51
52 if(readSettings(this) == null)
53 saveSettings(threads.getText().toString() + '\n' + worker.getText().toString() + '\n' + pool.getText().toString() + '\n' + pass.getText().toString() + '\n' + address.getText().toString(), this);
54
55 String settings = readSettings(this);
56 threads.setText(settings.split("\n")[1]);
57 worker.setText(settings.split("\n")[2]);
58 pool.setText(settings.split("\n")[3]);
59 pass.setText(settings.split("\n")[4]);
60 address.setText(settings.split("\n")[5]);
61
d4b6bfef 62 TextView text = (TextView)findViewById(R.id.LOG);
ebd9203a 63
d4b6bfef 64 text.setMovementMethod(new ScrollingMovementMethod());
ebd9203a 65
66
67 }
68 public void mine(View view){
69 TextView text = (TextView)findViewById(R.id.LOG);
aea96504 70 Button button = (Button)findViewById(R.id.button);
ebd9203a 71 if(mining){
72 handler.removeCallbacks(textView);
73 miner.stop();
74 mining = false;
75 text.setText("");
d4b6bfef 76 text.scrollTo(0, 0);
ebd9203a 77 LOGAll = "";
aea96504 78 button.setText("Start");
ebd9203a 79 }else {
80 EditText threads = (EditText)findViewById(R.id.threads);
81 EditText worker = (EditText)findViewById(R.id.worker);
82 EditText pool = (EditText)findViewById(R.id.pool);
83 EditText pass = (EditText)findViewById(R.id.pass);
84 EditText address = (EditText) findViewById(R.id.address);
85
86
87 saveSettings(threads.getText().toString() + '\n' + worker.getText().toString() + '\n' + pool.getText().toString() + '\n' + pass.getText().toString() + '\n' + address.getText().toString(),this);
88
89 CheckBox bench = (CheckBox)findViewById(R.id.bench);
51ff76d1 90 miner.mine(threads.getText().toString(),pass.getText().toString(),pool.getText().toString(),worker.getText().toString(),address.getText().toString(),bench.isChecked());
ebd9203a 91 handler.postDelayed(textView, 200);
92 mining = true;
aea96504 93 button.setText("Stop");
ebd9203a 94 }
95
96 }
97 // Define the code block to be executed
98 private Runnable textView = new Runnable() {
99 @Override
100 public void run() {
7bbfebb4 101 Button button = (Button)findViewById(R.id.button);
ebd9203a 102 TextView text = (TextView)findViewById(R.id.LOG);
103 String LOG = "";
328fdec5 104 if(LOGAll.split("\n").length > 100) {
105 LOGAll = LOGAll.substring(LOGAll.indexOf('\n') + (LOGAll.split("\n").length - 100));
106 }
ebd9203a 107 if (miner.errors != null) {
b90ab169 108 LOG += miner.errors + miner.error() + miner.output();
ebd9203a 109 miner.stop();
328fdec5 110 if(text.getScrollY() == text.getLayout().getLineTop(text.getLineCount()) - text.getHeight()){
111 text.setText(LOG);
112 text.scrollTo(0, text.getLayout().getLineTop(text.getLineCount()) - text.getHeight());
113 } else {
5e974867 114 text.setText(LOG);
328fdec5 115 }
7bbfebb4 116 mining = false;
117 button.setText("Start");
ebd9203a 118 Log.e("test",LOG);
7bbfebb4 119 handler.removeCallbacks(textView);
120
b90ab169 121 }
122 if (!miner.error().isEmpty()) {
123 LOG += miner.error() + miner.output();
ebd9203a 124 miner.stop();
328fdec5 125 if(text.getScrollY() == text.getLayout().getLineTop(text.getLineCount()) - text.getHeight()){
126 text.setText(LOG);
127 text.scrollTo(0, text.getLayout().getLineTop(text.getLineCount()) - text.getHeight());
128 } else {
129 text.setText(LOG);
328fdec5 130 }
7bbfebb4 131 mining = false;
132 button.setText("Start");
ebd9203a 133 Log.e("test",LOG);
7bbfebb4 134 handler.removeCallbacks(textView);
ebd9203a 135 } else {
136 LOG += miner.output();
137 LOGAll += LOG;
138 Log.e("test",LOG);
328fdec5 139 if(text.getScrollY() >= (text.getLayout().getLineTop(text.getLineCount()) - text.getHeight())-2){
140 text.setText(LOGAll);
141 text.scrollTo(0, text.getLayout().getLineTop(text.getLineCount()) - text.getHeight());
142 } else {
143 text.setText(LOGAll);
144
145 }
ebd9203a 146 handler.postDelayed(this, 200);
147 }
148 }
149 };
150 private static boolean hasPermissions(Context context, String... permissions) {
151 if (context != null && permissions != null) {
152 for (String permission : permissions) {
153 if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {
154 return false;
155 }
156 }
157 }
158 return true;
159 }
160 private void saveSettings(String data,Context context) {
161 try {
162 OutputStreamWriter outputStreamWriter = new OutputStreamWriter(context.openFileOutput("config.txt", Context.MODE_PRIVATE));
163 outputStreamWriter.write(data);
164 outputStreamWriter.close();
165 }
166 catch (IOException e) {
167 Log.e("Exception", "File write failed: " + e.toString());
168 }
169 }
170 private String readSettings(Context context) {
171
172 String ret = "";
173
174 try {
175 InputStream inputStream = context.openFileInput("config.txt");
176
177 if ( inputStream != null ) {
178 InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
179 BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
180 String receiveString = "";
181 StringBuilder stringBuilder = new StringBuilder();
182
183 while ( (receiveString = bufferedReader.readLine()) != null ) {
184 stringBuilder.append("\n").append(receiveString);
185 }
186
187 inputStream.close();
188 ret = stringBuilder.toString();
189 }
190 }
191 catch (FileNotFoundException e) {
192 Log.e("login activity", "File not found: " + e.toString());
193 return null;
194 } catch (IOException e) {
195 Log.e("login activity", "Can not read file: " + e.toString());
196 }
197
198 return ret;
199 }
200}
This page took 0.047622 seconds and 4 git commands to generate.