Commit 8e95a880 authored by Administrator's avatar Administrator

设置页面

parent abef905b
......@@ -10,6 +10,7 @@
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:name=".EchoApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
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;
import android.os.Build;
import android.os.IBinder;
import androidx.annotation.Nullable;
import com.virjar.echo.adr.repo.EchoConfig;
import com.virjar.echo.nat.client.EchoClient;
import com.virjar.echo.nat.log.EchoLogger;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import static android.app.PendingIntent.FLAG_UPDATE_CURRENT;
......@@ -85,15 +84,11 @@ public class HttpProxyService extends Service {
notification.defaults = Notification.DEFAULT_SOUND;
startForeground(110, notification);
//TODO 设备ID生成算法
String clientKey = UUID.randomUUID().toString();
EchoLogger.getLogger().info("start EchoProxy front service");
//TODO 设置服务器信息
echoClient = new EchoClient(
"echo.virjar.com", 5698,
clientKey);
EchoConfig.getEchoServer(), EchoConfig.getEchoServerPort(),
EchoConfig.getClientId());
new Thread() {
@Override
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;
import android.os.Bundle;
import android.view.MenuItem;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.PreferenceFragmentCompat;
import com.virjar.echo.adr.R;
import com.virjar.echo.adr.repo.EchoConfig;
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 {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
getPreferenceManager().setSharedPreferencesName(EchoConfig.configFile);
setPreferencesFromResource(R.xml.root_preferences, rootKey);
}
}
......
......@@ -164,7 +164,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:fontFamily="@font/calibri"
android:text="powered by virjar@intiin.inc"
android:text="powered by virjar@iinti.inc"
android:textAlignment="center"
android:textColor="#96ffffff"
android:textSize="16sp" />
......
......@@ -3,11 +3,18 @@
<string name="title_activity_settings">SettingsActivity</string>
<!-- Preference Titles -->
<string name="messages_header">Messages</string>
<string name="sync_header">Sync</string>
<string name="server_header">Server</string>
<string name="client_header">Client</string>
<!-- 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>
<!-- Sync Preferences -->
......
<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory app:title="@string/messages_header">
<PreferenceCategory app:title="@string/server_header">
<EditTextPreference
app:key="signature"
app:title="@string/signature_title"
app:defaultValue="@string/default_server_host"
app:key="server_host"
app:title="@string/server_host_title"
app:useSimpleSummaryProvider="true" />
<ListPreference
app:defaultValue="reply"
app:entries="@array/reply_entries"
app:entryValues="@array/reply_values"
app:key="reply"
app:title="@string/reply_title"
<EditTextPreference
app:defaultValue="@string/default_server_port"
app:key="server_port"
app:title="@string/server_port_title"
app:useSimpleSummaryProvider="true" />
</PreferenceCategory>
<PreferenceCategory app:title="@string/sync_header">
<SwitchPreferenceCompat
app:key="sync"
app:title="@string/sync_title" />
<PreferenceCategory app:title="@string/client_header">
<SwitchPreferenceCompat
app:dependency="sync"
app:key="attachment"
app:summaryOff="@string/attachment_summary_off"
app:summaryOn="@string/attachment_summary_on"
app:title="@string/attachment_title" />
<EditTextPreference
app:key="echo_clientId"
app:title="@string/client_id_title"
app:useSimpleSummaryProvider="true" />
</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