Commit 01f694af authored by Administrator's avatar Administrator

1.支持选择是否自动重播 2.设置重播时间间隔 3. 设置页面展示summary

parent 7c364648
......@@ -9,8 +9,8 @@ android {
minSdkVersion 19
//noinspection ExpiredTargetSdkVersion
targetSdkVersion 23
versionCode 4
versionName "1.4"
versionCode 5
versionName "1.5"
archivesBaseName = "Majora_${versionName}".replace(' ', '_')
}
......
......@@ -10,16 +10,43 @@ import com.virjar.majora.adr.utils.PermissionUtils;
import com.virjar.majora.client.sdk.client.MajoraClient;
import com.virjar.majora.client.sdk.log.MajoraLogger;
import java.util.Timer;
import java.util.TimerTask;
import eu.chainfire.libsuperuser.Shell;
public class MajoraClientService {
private static boolean started = false;
private static MajoraClient majoraClient;
// 重播任务定时器
private static final Timer timer = new Timer("reDial");
private static class RedialThread extends Thread {
private static final RedialThread mInstance = new RedialThread();
@Override
public void run() {
while (Thread.currentThread().isAlive()) {
SharedPreferences spf = PreferenceManager.getDefaultSharedPreferences(TheApp.getApplication());
boolean autoRedial = spf.getBoolean("auto_redial", true);
int sleepMinutes = spf.getInt("auto_redial_duration", 5);
if (sleepMinutes < 1) {
sleepMinutes = 1;
}
if (sleepMinutes > 600) {
sleepMinutes = 600;
}
if (!autoRedial) {
sleepMinutes = 5;
}
try {
Thread.sleep(sleepMinutes * 60 * 1000);
} catch (InterruptedException e) {
//ignore
return;
}
if (autoRedial) {
reDial();
}
}
}
}
public static void startup() {
......@@ -32,12 +59,10 @@ public class MajoraClientService {
}
startProxyService();
timer.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
reDial();
RedialThread redialThread = RedialThread.mInstance;
if (!redialThread.isAlive()) {
redialThread.start();
}
}, 5 * 60 * 1000, 5 * 60 * 1000);
started = true;
}
......
......@@ -3,6 +3,7 @@ package com.virjar.majora.adr.ui;
import android.app.Fragment;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.Nullable;
......@@ -10,6 +11,7 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.SeekBar;
import android.widget.TextView;
import android.widget.Toast;
......@@ -22,6 +24,17 @@ import com.virjar.majora.adr.utils.CommonUtils;
import eu.chainfire.libsuperuser.Shell;
public class MainPanelFragment extends Fragment {
private View autoRedialPanel;
@Override
public void onResume() {
super.onResume();
SharedPreferences spf = PreferenceManager.getDefaultSharedPreferences(TheApp.getApplication());
boolean autoRedial = spf.getBoolean("auto_redial", true)
&& Shell.SU.available();
autoRedialPanel.setVisibility(autoRedial ? View.VISIBLE : View.GONE);
}
@Nullable
@Override
......@@ -65,6 +78,30 @@ public class MainPanelFragment extends Fragment {
}
});
TextView reDialConfigTextView = view.findViewById(R.id.tv_redial_view);
autoRedialPanel = view.findViewById(R.id.auto_redial_panel);
SeekBar seekBar = view.findViewById(R.id.reDialSeekBar);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
seekBar.setMin(1);
}
seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
reDialConfigTextView.setText(String.valueOf(progress));
SharedPreferences spf = PreferenceManager.getDefaultSharedPreferences(TheApp.getApplication());
spf.edit().putInt("auto_redial_duration", progress).apply();
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
return view;
}
......
package com.virjar.majora.adr.ui.widget;
import android.content.Context;
import android.os.Build;
import android.preference.EditTextPreference;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
public class EditSummaryPreference extends EditTextPreference {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public EditSummaryPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
public EditSummaryPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public EditSummaryPreference(Context context, AttributeSet attrs) {
super(context, attrs);
}
public EditSummaryPreference(Context context) {
super(context);
}
@Override
public CharSequence getSummary() {
return getText();
}
}
......@@ -214,6 +214,39 @@
</LinearLayout>
<LinearLayout
android:id="@+id/auto_redial_panel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:orientation="horizontal">
<TextView
android:padding="5dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="重播间隔(分钟): " />
<TextView
android:padding="5dp"
android:minWidth="5dp"
android:id="@+id/tv_redial_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="0" />
<SeekBar
android:id="@+id/reDialSeekBar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:max="60" />
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
......
......@@ -15,7 +15,6 @@
<string name="nav_item_about">关于</string>
<string name="settings_group_app">应用</string>
<string name="settings_group_user">用户</string>
<string name="phone_identifier">结算账户</string>
<string name="support_framework_label">框架/安装支持</string>
......@@ -66,5 +65,7 @@
<string name="client_id">clientId</string>
<string name="server_config">服务器配置</string>
<string name="binding_account">结算账号</string>
<string name="settings_group_local">本地配置</string>
<string name="auto_redial">自动重播</string>
</resources>
......@@ -3,17 +3,23 @@
xmlns:app="http://schemas.android.com/apk/res-auto">
<PreferenceCategory android:title="@string/server">
<EditTextPreference
<com.virjar.majora.adr.ui.widget.EditSummaryPreference
android:defaultValue="@string/default_server_host"
android:key="server_host"
android:persistent="true"
android:title="@string/server_host" />
<EditTextPreference
<com.virjar.majora.adr.ui.widget.EditSummaryPreference
android:defaultValue="@string/default_server_port"
android:digits="0123456789"
android:inputType="numberDecimal"
android:key="server_port"
android:title="@string/port" />
<com.virjar.majora.adr.ui.widget.EditSummaryPreference
android:defaultValue=""
android:key="account_identifier"
android:title="@string/phone_identifier">
</com.virjar.majora.adr.ui.widget.EditSummaryPreference>
</PreferenceCategory>
<PreferenceCategory
......@@ -44,14 +50,14 @@
<PreferenceCategory
android:key="group_user"
android:title="@string/settings_group_user">
android:key="group_local"
android:title="@string/settings_group_local">
<EditTextPreference
android:defaultValue=""
android:key="account_identifier"
android:title="@string/phone_identifier">
<SwitchPreference
android:title="@string/auto_redial"
android:key="auto_redial"
android:defaultValue="true"
/>
</EditTextPreference>
</PreferenceCategory>
</PreferenceScreen>
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