Skip to content

Commit

Permalink
v1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
by-syk committed Dec 6, 2016
1 parent c16848c commit ae539aa
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v1.1.1 2016-12-06
- Long press to switch window priority.

v1.1.0 2016-11-15
- Fix: TRIPLE TAP causes DOUBLE TAP to execute.
- Fix: Position of window changes.
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.by_syk.netupdown"
minSdkVersion 8
targetSdkVersion 25
versionCode 161115000
versionName "1.1.0"
versionCode 161206000
versionName "1.1.1"

vectorDrawables.generatedDensities = ['mdpi', 'hdpi', 'xhdpi', 'xxhdpi']
}
Expand Down
37 changes: 36 additions & 1 deletion app/src/main/java/com/by_syk/netupdown/PrefActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,28 @@

package com.by_syk.netupdown;

import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.view.WindowManager;

import com.by_syk.lib.storage.SP;
import com.by_syk.netupdown.service.NetTrafficService;

/**
* Created by By_syk on 2016-11-08.
*/

public class PrefActivity extends PreferenceActivity implements Preference.OnPreferenceChangeListener {
private SP sp;

private CheckBoxPreference checkBoxPreference;

private ServiceReceiver serviceReceiver;
Expand All @@ -45,6 +51,8 @@ protected void onCreate(Bundle savedInstanceState) {
checkBoxPreference.setOnPreferenceChangeListener(this);

serviceReceiver = new ServiceReceiver();

sp = new SP(this, false);
}

@Override
Expand Down Expand Up @@ -87,7 +95,11 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
case "run":
boolean isChecked = (Boolean) newValue;
if (isChecked) {
runService();
if (!sp.getBoolean("priorityHint")) {
hintPriorityDialog();
} else {
runService();
}
} else {
stopService();
}
Expand All @@ -97,6 +109,29 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
}
}

private void hintPriorityDialog() {
AlertDialog alertDialog = new AlertDialog.Builder(this)
.setMessage(R.string.priority_desc)
.setPositiveButton(R.string.dia_bt_high_priority, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
sp.put("window", WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)
.put("priorityHint", true).save();
runService();
}
})
.setNegativeButton(R.string.dia_bt_low_priority, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
sp.put("window", WindowManager.LayoutParams.TYPE_SYSTEM_ALERT)
.put("priorityHint", true).save();
runService();
}
})
.create();
alertDialog.show();
}

class ServiceReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package com.by_syk.netupdown.fragment;

import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
Expand All @@ -28,7 +30,9 @@
import android.preference.PreferenceFragment;
import android.preference.SwitchPreference;
import android.provider.Settings;
import android.view.WindowManager;

import com.by_syk.lib.storage.SP;
import com.by_syk.netupdown.R;
import com.by_syk.netupdown.service.NetTrafficService;
import com.by_syk.netupdown.util.C;
Expand All @@ -39,6 +43,8 @@

@TargetApi(11)
public class PrefFragment extends PreferenceFragment implements Preference.OnPreferenceChangeListener {
private SP sp;

private SwitchPreference switchPreference;
private CheckBoxPreference checkBoxPreference;

Expand Down Expand Up @@ -66,6 +72,8 @@ public void onCreate(Bundle savedInstanceState) {
findPreference("run").setOnPreferenceChangeListener(this);

serviceReceiver = new ServiceReceiver();

sp = new SP(getActivity(), false);
}

@Override
Expand Down Expand Up @@ -99,7 +107,11 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
if (isChecked) {
if (!NetTrafficService.isRunning) {
if (canDrawOverlays()) {
runService();
if (!sp.getBoolean("priorityHint")) {
hintPriorityDialog();
} else {
runService();
}
} else { // No permission
requestDrawOverLays();
}
Expand Down Expand Up @@ -155,6 +167,29 @@ public void requestDrawOverLays() {
startActivityForResult(intent, OVERLAY_PERMISSION_REQ_CODE);
}

private void hintPriorityDialog() {
AlertDialog alertDialog = new AlertDialog.Builder(getActivity())
.setMessage(R.string.priority_desc)
.setPositiveButton(R.string.dia_bt_high_priority, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
sp.put("window", WindowManager.LayoutParams.TYPE_SYSTEM_ERROR)
.put("priorityHint", true).save();
runService();
}
})
.setNegativeButton(R.string.dia_bt_low_priority, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
sp.put("window", WindowManager.LayoutParams.TYPE_SYSTEM_ALERT)
.put("priorityHint", true).save();
runService();
}
})
.create();
alertDialog.show();
}

@TargetApi(23)
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ public void onUpdate(long netSpeed, long netSpeedUp, long netSpeedDown, long use
// Log.d(C.LOG_TAG, "NetTrafficSpider.Callback onUpdate: " + readableNetSpeed);
if (mode == MODE_SPEED) {
text = readableNetSpeed;
// text = "σ" + (int) variance + " " + readableNetSpeed;
// text = readableNetSpeedUp + " | " + readableNetSpeedDown;
} else {
text = readableUsedBytes;
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/java/com/by_syk/netupdown/util/NetTrafficSpider.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ public class NetTrafficSpider {
private int netSpeedUp = 0;
private int netSpeedDown = 0;

// private int[] recentBytes = new int[16];
// private int recentIndex = 0;

private int refreshPeriod = 1000;

private Thread thread = null;
Expand Down Expand Up @@ -170,6 +173,7 @@ public void run() {

total = lastTotalTxBytes + lastTotalRxBytes;
netSpeed = (int) ((total - lastTotalBytes) * 1000 / refreshPeriod);
// recentBytes[(++recentIndex) % recentBytes.length] = (int) (total - lastTotalBytes);
lastTotalBytes = total;

usedBytes = lastTotalBytes - startTotalBytes;
Expand All @@ -185,6 +189,20 @@ public void run() {
}
}

// private float getStandardDeviation(int[] arr) {
// float sum = 0; // byte
// for (int a : arr) {
// sum += a;
// }
// float average = sum / arr.length;
// sum = 0; // kb
// for (int a : arr) {
// sum += (a - average) * (a - average) / (1024 * 1024);
// }
// average = (float) Math.sqrt(sum / arr.length);
// return average;
// }

public interface Callback {
void beforeStart();
void onUpdate(long netSpeed, long netSpeedUp, long netSpeedDown, long usedBytes,
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,14 @@
<!--<string name="preference_summary_special">为 @ 定制</string>-->
<!--<string name="preference_title_copyright">版权所有</string>-->

<string name="dia_bt_high_priority">需要</string>
<string name="dia_bt_low_priority">不需要</string>

<string name="run_shortcut_short_label">网速悬浮窗</string>
<string name="run_shortcut_long_label">显示网速悬浮窗</string>
<string name="priority_desc">
"是否需要采用高优先级模式以允许悬浮窗能被拖动到状态栏?
\n提示:允许拖动到状态栏可能带来一些问题,比如造成某些视频播放器无法调节亮度。不过您也可以随时长按悬浮窗来切换这一设置。"</string>

<string name="tile_run">网速悬浮窗</string>

Expand Down
7 changes: 7 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,15 @@
<!--<string name="preference_summary_special">For @</string>-->
<!--<string name="preference_title_copyright">Copyright</string>-->

<string name="dia_bt_high_priority">Yes</string>
<string name="dia_bt_low_priority">No</string>

<string name="run_shortcut_short_label">Run Upstream</string>
<string name="run_shortcut_long_label">Run Upstream</string>
<string name="priority_desc">
"Do you need the floating window to be dragged to the status bar?
\nTIPS: If yes, high priority will be granted to the floating window. It may cause some video players unable to adjust brightness.
Well, you could also toggle the option at any time by pressing and holding the floating window."</string>

<string name="tile_run">Run Upstream</string>

Expand Down

0 comments on commit ae539aa

Please sign in to comment.