mirror of
https://github.com/PurpleI2P/i2pd-android.git
synced 2024-12-06 19:27:28 +01:00
rework main ui, change theme, remove unused code
Signed-off-by: R4SAS <r4sas@i2pmail.org>
This commit is contained in:
@@ -85,13 +85,12 @@ public class DaemonWrapper {
|
||||
}
|
||||
|
||||
public int getTransitTunnelsCount() {
|
||||
return I2PD_JNI.GetTransitTunnelsCount();
|
||||
return I2PD_JNI.getTransitTunnelsCount();
|
||||
}
|
||||
|
||||
public enum State {
|
||||
uninitialized(R.string.uninitialized),
|
||||
starting(R.string.starting),
|
||||
jniLibraryLoaded(R.string.jniLibraryLoaded),
|
||||
startedOkay(R.string.startedOkay),
|
||||
startFailed(R.string.startFailed),
|
||||
gracefulShutdownInProgress(R.string.gracefulShutdownInProgress),
|
||||
@@ -168,7 +167,6 @@ public class DaemonWrapper {
|
||||
} catch (Throwable tr) {
|
||||
Log.e(TAG, "", tr);
|
||||
}
|
||||
|
||||
setState(State.stopped);
|
||||
}
|
||||
}
|
||||
@@ -178,7 +176,6 @@ public class DaemonWrapper {
|
||||
try {
|
||||
processAssets();
|
||||
I2PD_JNI.loadLibraries();
|
||||
setState(State.jniLibraryLoaded);
|
||||
//registerNetworkCallback();
|
||||
} catch (Throwable tr) {
|
||||
lastThrowable = tr;
|
||||
|
||||
@@ -27,8 +27,7 @@ import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
@@ -37,19 +36,20 @@ import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import static android.provider.Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS;
|
||||
import static org.purplei2p.i2pd.DaemonWrapper.State.startedOkay;
|
||||
import static org.purplei2p.i2pd.DaemonWrapper.State.starting;
|
||||
import static org.purplei2p.i2pd.DaemonWrapper.State.stopped;
|
||||
|
||||
public class I2PDActivity extends Activity {
|
||||
private static final String TAG = "i2pdActvt";
|
||||
private static final int MY_PERMISSION_REQUEST_WRITE_EXTERNAL_STORAGE = 1;
|
||||
public static final int GRACEFUL_DELAY_MILLIS = 10 * 60 * 1000;
|
||||
public static final String PACKAGE_URI_SCHEME = "package:";
|
||||
private Button enableButton;
|
||||
private Button disableButton;
|
||||
|
||||
private TextView textView;
|
||||
private CheckBox HTTPProxyState;
|
||||
private CheckBox SOCKSProxyState;
|
||||
private CheckBox BOBState;
|
||||
private CheckBox SAMState;
|
||||
private CheckBox I2CPState;
|
||||
|
||||
|
||||
private static volatile DaemonWrapper daemon;
|
||||
|
||||
@@ -65,15 +65,23 @@ public class I2PDActivity extends Activity {
|
||||
try {
|
||||
if (textView == null)
|
||||
return;
|
||||
|
||||
Throwable tr = daemon.getLastThrowable();
|
||||
if (tr != null) {
|
||||
textView.setText(throwableToString(tr));
|
||||
return;
|
||||
}
|
||||
|
||||
DaemonWrapper.State state = daemon.getState();
|
||||
if(state == startedOkay){
|
||||
disableButton.setVisibility(View.VISIBLE);
|
||||
|
||||
if (daemon.isStartedOkay()) {
|
||||
HTTPProxyState.setChecked(I2PD_JNI.getHTTPProxyState());
|
||||
SOCKSProxyState.setChecked(I2PD_JNI.getSOCKSProxyState());
|
||||
BOBState.setChecked(I2PD_JNI.getBOBState());
|
||||
SAMState.setChecked(I2PD_JNI.getSAMState());
|
||||
I2CPState.setChecked(I2PD_JNI.getI2CPState());
|
||||
}
|
||||
|
||||
String startResultStr = DaemonWrapper.State.startFailed.equals(state) ? String.format(": %s", daemon.getDaemonStartResult()) : "";
|
||||
String graceStr = DaemonWrapper.State.gracefulShutdownInProgress.equals(state) ? String.format(": %s %s", formatGraceTimeRemaining(), getText(R.string.remaining)) : "";
|
||||
textView.setText(String.format("%s%s%s", getText(state.getStatusStringResourceId()), startResultStr, graceStr));
|
||||
@@ -102,9 +110,14 @@ public class I2PDActivity extends Activity {
|
||||
Log.i(TAG, "onCreate");
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
enableButton = findViewById(R.id.enableButton);
|
||||
disableButton = findViewById(R.id.disableButton);
|
||||
|
||||
textView = (TextView) findViewById(R.id.appStatusText);
|
||||
HTTPProxyState = (CheckBox) findViewById(R.id.service_httpproxy_box);
|
||||
SOCKSProxyState = (CheckBox) findViewById(R.id.service_socksproxy_box);
|
||||
BOBState = (CheckBox) findViewById(R.id.service_bob_box);
|
||||
SAMState = (CheckBox) findViewById(R.id.service_sam_box);
|
||||
I2CPState = (CheckBox) findViewById(R.id.service_i2cp_box);
|
||||
|
||||
if (daemon == null) {
|
||||
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
daemon = new DaemonWrapper(getAssets(), connectivityManager);
|
||||
@@ -113,25 +126,6 @@ public class I2PDActivity extends Activity {
|
||||
|
||||
daemon.addStateChangeListener(daemonStateUpdatedListener);
|
||||
daemonStateUpdatedListener.daemonStateUpdate(DaemonWrapper.State.uninitialized, daemon.getState());
|
||||
enableButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if( daemon.getState() != startedOkay && daemon.getState() != starting ){
|
||||
daemon.stopDaemon();
|
||||
daemon.startDaemon();
|
||||
disableButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
});
|
||||
disableButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if( daemon.getState() != stopped ){
|
||||
daemon.stopDaemon();
|
||||
disableButton.setVisibility(View.INVISIBLE);
|
||||
}
|
||||
}
|
||||
});
|
||||
// request permissions
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
@@ -299,7 +293,7 @@ public class I2PDActivity extends Activity {
|
||||
return true;
|
||||
|
||||
case R.id.action_start_webview:
|
||||
if( daemon.getState() == startedOkay)
|
||||
if(daemon.isStartedOkay())
|
||||
startActivity(new Intent(getApplicationContext(), WebConsoleActivity.class));
|
||||
else
|
||||
Toast.makeText(this,"I2Pd not was started!", Toast.LENGTH_SHORT).show();
|
||||
@@ -334,11 +328,12 @@ public class I2PDActivity extends Activity {
|
||||
new Thread(() -> {
|
||||
Log.d(TAG, "stopping");
|
||||
try {
|
||||
textView.setText(getText(R.string.stopping));
|
||||
daemon.stopDaemon();
|
||||
} catch (Throwable tr) {
|
||||
Log.e(TAG, "", tr);
|
||||
}
|
||||
quit(); //TODO make menu items for starting i2pd. On my Android, I need to reboot the OS to restart i2pd.
|
||||
quit();
|
||||
}, "stop").start();
|
||||
}
|
||||
|
||||
|
||||
@@ -3,35 +3,33 @@ package org.purplei2p.i2pd;
|
||||
public class I2PD_JNI {
|
||||
public static native String getABICompiledWith();
|
||||
|
||||
public static void loadLibraries() {
|
||||
System.loadLibrary("i2pd");
|
||||
}
|
||||
|
||||
/**
|
||||
* returns error info if failed
|
||||
* returns "ok" if daemon initialized and started okay
|
||||
*/
|
||||
public static native String startDaemon();
|
||||
|
||||
//should only be called after startDaemon() success
|
||||
public static native void stopDaemon();
|
||||
|
||||
public static native void stopAcceptingTunnels();
|
||||
|
||||
public static native void startAcceptingTunnels();
|
||||
|
||||
public static native void stopAcceptingTunnels();
|
||||
public static native void reloadTunnelsConfigs();
|
||||
|
||||
public static native void onNetworkStateChanged(boolean isConnected);
|
||||
|
||||
public static native void setDataDir(String jdataDir);
|
||||
|
||||
public static native int GetTransitTunnelsCount();
|
||||
|
||||
public static native String getWebConsAddr();
|
||||
|
||||
public static native void setLanguage(String jlanguage);
|
||||
|
||||
public static void loadLibraries() {
|
||||
//System.loadLibrary("c++_shared");
|
||||
System.loadLibrary("i2pd");
|
||||
}
|
||||
|
||||
public static native int getTransitTunnelsCount();
|
||||
public static native String getWebConsAddr();
|
||||
public static native String getDataDir();
|
||||
|
||||
public static native boolean getHTTPProxyState();
|
||||
public static native boolean getSOCKSProxyState();
|
||||
public static native boolean getBOBState();
|
||||
public static native boolean getSAMState();
|
||||
public static native boolean getI2CPState();
|
||||
|
||||
public static native void onNetworkStateChanged(boolean isConnected);
|
||||
}
|
||||
|
||||
@@ -10,14 +10,16 @@ import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.Settings;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.MenuItem;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.Switch;
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
import org.purplei2p.i2pd.iniedotr.IniEditor;
|
||||
|
||||
public class SettingsActivity extends Activity {
|
||||
protected IniEditor iniedit = new IniEditor();
|
||||
private String dataDir = DaemonWrapper.getDataDir();//for inieditor
|
||||
@@ -62,6 +64,7 @@ public class SettingsActivity extends Activity {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//@Override
|
||||
private void requestPermission() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
@@ -76,11 +79,15 @@ public class SettingsActivity extends Activity {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
Log.i(TAG, "onCreate");
|
||||
super.onCreate(savedInstanceState);
|
||||
cacheDir = getApplicationContext().getCacheDir();
|
||||
setContentView(R.layout.activity_settings);
|
||||
|
||||
Objects.requireNonNull(getActionBar()).setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
cacheDir = getApplicationContext().getCacheDir();
|
||||
Switch autostart_switch = findViewById(R.id.autostart_enable);
|
||||
File onBoot = new File(cacheDir.getAbsolutePath() + onBootFileName);
|
||||
autostart_switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||
@@ -107,4 +114,14 @@ public class SettingsActivity extends Activity {
|
||||
if(onBoot.exists())
|
||||
autostart_switch.setChecked(true);
|
||||
}
|
||||
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
|
||||
if (id == android.R.id.home) {
|
||||
finish();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class WebConsoleActivity extends Activity {
|
||||
@@ -22,7 +21,7 @@ public class WebConsoleActivity extends Activity {
|
||||
|
||||
Objects.requireNonNull(getActionBar()).setDisplayHomeAsUpEnabled(true);
|
||||
|
||||
webView = (WebView) findViewById(R.id.webview1);
|
||||
webView = (WebView) findViewById(R.id.webconsole);
|
||||
webView.setWebViewClient(new WebViewClient());
|
||||
|
||||
final WebSettings webSettings = webView.getSettings();
|
||||
|
||||
Reference in New Issue
Block a user