Commit 8e95a880 authored by Administrator's avatar Administrator

设置页面

parent abef905b
...@@ -10,6 +10,7 @@ ...@@ -10,6 +10,7 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application <application
android:name=".EchoApplication"
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
......
package com.virjar.echo.adr;
import android.app.Application;
import com.virjar.echo.adr.repo.EchoConfig;
public class EchoApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
EchoConfig.init(this);
}
}
...@@ -11,13 +11,12 @@ import android.graphics.Color; ...@@ -11,13 +11,12 @@ import android.graphics.Color;
import android.os.Build; import android.os.Build;
import android.os.IBinder; import android.os.IBinder;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import com.virjar.echo.adr.repo.EchoConfig;
import com.virjar.echo.nat.client.EchoClient; import com.virjar.echo.nat.client.EchoClient;
import com.virjar.echo.nat.log.EchoLogger; import com.virjar.echo.nat.log.EchoLogger;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT; import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
...@@ -85,15 +84,11 @@ public class HttpProxyService extends Service { ...@@ -85,15 +84,11 @@ public class HttpProxyService extends Service {
notification.defaults = Notification.DEFAULT_SOUND; notification.defaults = Notification.DEFAULT_SOUND;
startForeground(110, notification); startForeground(110, notification);
//TODO 设备ID生成算法
String clientKey = UUID.randomUUID().toString();
EchoLogger.getLogger().info("start EchoProxy front service"); EchoLogger.getLogger().info("start EchoProxy front service");
//TODO 设置服务器信息
echoClient = new EchoClient( echoClient = new EchoClient(
"echo.virjar.com", 5698, EchoConfig.getEchoServer(), EchoConfig.getEchoServerPort(),
clientKey); EchoConfig.getClientId());
new Thread() { new Thread() {
@Override @Override
public void run() { public void run() {
......
package com.virjar.echo.adr.repo;
import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;
import com.virjar.echo.adr.R;
import java.util.UUID;
public class EchoConfig {
public static final String configFile = "echo_config";
public static SharedPreferences sharedPreferences;
private static String defaultServerHost;
private static int defaultServerPort;
public static void init(Context context) {
sharedPreferences = context.getSharedPreferences(configFile, Context.MODE_PRIVATE);
defaultServerHost = context.getString(R.string.default_server_host);
defaultServerPort = Integer.parseInt(context.getString(R.string.default_server_port));
getClientId();
}
public static String getEchoServer() {
return sharedPreferences.getString("server_host", defaultServerHost);
}
public static int getEchoServerPort() {
return sharedPreferences.getInt("server_port", defaultServerPort);
}
public static String getClientId() {
String echoClientId = sharedPreferences.getString("echo_clientId", "");
if (TextUtils.isEmpty(echoClientId)) {
echoClientId = System.currentTimeMillis() + "_" + UUID.randomUUID().toString();
sharedPreferences.edit().putString("echo_clientId", echoClientId).apply();
} else {
return echoClientId;
}
return getClientId();
}
}
package com.virjar.echo.adr.ui; package com.virjar.echo.adr.ui;
import android.os.Bundle; import android.os.Bundle;
import android.view.MenuItem;
import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.PreferenceFragmentCompat; import androidx.preference.PreferenceFragmentCompat;
import com.virjar.echo.adr.R; import com.virjar.echo.adr.R;
import com.virjar.echo.adr.repo.EchoConfig;
public class SettingsActivity extends AppCompatActivity { public class SettingsActivity extends AppCompatActivity {
...@@ -24,9 +26,22 @@ public class SettingsActivity extends AppCompatActivity { ...@@ -24,9 +26,22 @@ public class SettingsActivity extends AppCompatActivity {
} }
} }
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home:
finish();
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
public static class SettingsFragment extends PreferenceFragmentCompat { public static class SettingsFragment extends PreferenceFragmentCompat {
@Override @Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
getPreferenceManager().setSharedPreferencesName(EchoConfig.configFile);
setPreferencesFromResource(R.xml.root_preferences, rootKey); setPreferencesFromResource(R.xml.root_preferences, rootKey);
} }
} }
......
...@@ -164,7 +164,7 @@ ...@@ -164,7 +164,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:fontFamily="@font/calibri" android:fontFamily="@font/calibri"
android:text="powered by virjar@intiin.inc" android:text="powered by virjar@iinti.inc"
android:textAlignment="center" android:textAlignment="center"
android:textColor="#96ffffff" android:textColor="#96ffffff"
android:textSize="16sp" /> android:textSize="16sp" />
......
...@@ -3,11 +3,18 @@ ...@@ -3,11 +3,18 @@
<string name="title_activity_settings">SettingsActivity</string> <string name="title_activity_settings">SettingsActivity</string>
<!-- Preference Titles --> <!-- Preference Titles -->
<string name="messages_header">Messages</string> <string name="server_header">Server</string>
<string name="sync_header">Sync</string> <string name="client_header">Client</string>
<!-- Messages Preferences --> <!-- Messages Preferences -->
<string name="signature_title">Your signature</string> <string name="server_host_title">ServerHost</string>
<string name="default_server_host">echo.virjar.com</string>
<string name="server_port_title">ServerPort</string>
<string name="default_server_port">5698</string>
<string name="client_id_title">ClientId</string>
<string name="reply_title">Default reply action</string> <string name="reply_title">Default reply action</string>
<!-- Sync Preferences --> <!-- Sync Preferences -->
......
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"> <PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory app:title="@string/messages_header"> <PreferenceCategory app:title="@string/server_header">
<EditTextPreference <EditTextPreference
app:key="signature" app:defaultValue="@string/default_server_host"
app:title="@string/signature_title" app:key="server_host"
app:title="@string/server_host_title"
app:useSimpleSummaryProvider="true" /> app:useSimpleSummaryProvider="true" />
<ListPreference <EditTextPreference
app:defaultValue="reply" app:defaultValue="@string/default_server_port"
app:entries="@array/reply_entries" app:key="server_port"
app:entryValues="@array/reply_values" app:title="@string/server_port_title"
app:key="reply"
app:title="@string/reply_title"
app:useSimpleSummaryProvider="true" /> app:useSimpleSummaryProvider="true" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory app:title="@string/sync_header"> <PreferenceCategory app:title="@string/client_header">
<SwitchPreferenceCompat
app:key="sync"
app:title="@string/sync_title" />
<SwitchPreferenceCompat <EditTextPreference
app:dependency="sync" app:key="echo_clientId"
app:key="attachment" app:title="@string/client_id_title"
app:summaryOff="@string/attachment_summary_off" app:useSimpleSummaryProvider="true" />
app:summaryOn="@string/attachment_summary_on"
app:title="@string/attachment_title" />
</PreferenceCategory> </PreferenceCategory>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment