Improved activated notification
This commit is contained in:
parent
5f693fc47a
commit
a1895726c1
@ -9,9 +9,8 @@ android {
|
|||||||
applicationId "org.itxtech.daedalus"
|
applicationId "org.itxtech.daedalus"
|
||||||
minSdkVersion 21
|
minSdkVersion 21
|
||||||
targetSdkVersion 25
|
targetSdkVersion 25
|
||||||
versionCode 1
|
versionCode 2
|
||||||
versionName "1.0.0"
|
versionName "1.0.1"
|
||||||
|
|
||||||
|
|
||||||
buildConfigField "String", "BUILD_TIME", "\"${System.currentTimeMillis()}\""
|
buildConfigField "String", "BUILD_TIME", "\"${System.currentTimeMillis()}\""
|
||||||
buildConfigField "String", "GIT_COMMIT", "\"${gitCommit}\""
|
buildConfigField "String", "GIT_COMMIT", "\"${gitCommit}\""
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
<uses-permission android:name="android.permission.INTERNET"/>
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
|
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
|
||||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||||
|
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
@ -28,6 +29,13 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</receiver>
|
</receiver>
|
||||||
|
|
||||||
|
<receiver android:name=".StatusBarBroadcastReceiver">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="org.itxtech.daedalus.StatusBarBroadcastReceiver.STATUS_BAR_BTN_DEACTIVATE_CLICK_ACTION"/>
|
||||||
|
<action android:name="org.itxtech.daedalus.StatusBarBroadcastReceiver.STATUS_BAR_BTN_SETTINGS_CLICK_ACTION"/>
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name"
|
||||||
|
@ -33,6 +33,13 @@
|
|||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<div style="font-size: 12px; color: gray;">
|
<div style="font-size: 12px; color: gray;">
|
||||||
|
Users must comply with local laws and regulations.<br>
|
||||||
|
Welcome to CuteDNS! QQ Group: 625385297.<br>
|
||||||
|
Open the menu to explore more features.
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<div style="font-size: 8px; color: gray;">
|
||||||
This program is free software: you can redistribute it and/or modify<br>
|
This program is free software: you can redistribute it and/or modify<br>
|
||||||
it under the terms of the GNU General Public License as published by<br>
|
it under the terms of the GNU General Public License as published by<br>
|
||||||
the Free Software Foundation, either version 3 of the License, or<br>
|
the Free Software Foundation, either version 3 of the License, or<br>
|
||||||
@ -46,12 +53,5 @@
|
|||||||
You should have received a copy of the GNU General Public License<br>
|
You should have received a copy of the GNU General Public License<br>
|
||||||
along with this program. If not, see http://www.gnu.org/licenses/.<br>
|
along with this program. If not, see http://www.gnu.org/licenses/.<br>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
|
||||||
<br>
|
|
||||||
<div style="font-size: 12px; color: gray;">
|
|
||||||
Users must comply with local laws and regulations.<br>
|
|
||||||
Welcome to CuteDNS! QQ Group: 625385297.<br>
|
|
||||||
Open the menu to explore more features.
|
|
||||||
</div>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -30,9 +30,17 @@
|
|||||||
<br>
|
<br>
|
||||||
<img width="185" height="55" src="cutedns_logo.png">
|
<img width="185" height="55" src="cutedns_logo.png">
|
||||||
<div style="font-size: 25px;">CuteDNS!</div>
|
<div style="font-size: 25px;">CuteDNS!</div>
|
||||||
|
|
||||||
<br>
|
<br>
|
||||||
<br>
|
<br>
|
||||||
<div style="font-size: 12px; color: gray;">
|
<div style="font-size: 12px; color: gray;">
|
||||||
|
使用者必须遵守当地法律法规。<br>
|
||||||
|
欢迎加入 CuteDNS! QQ群:625385297 。<br>
|
||||||
|
打开菜单探索更多功能。
|
||||||
|
</div>
|
||||||
|
<br>
|
||||||
|
<br>
|
||||||
|
<div style="font-size: 8px; color: gray;">
|
||||||
This program is free software: you can redistribute it and/or modify<br>
|
This program is free software: you can redistribute it and/or modify<br>
|
||||||
it under the terms of the GNU General Public License as published by<br>
|
it under the terms of the GNU General Public License as published by<br>
|
||||||
the Free Software Foundation, either version 3 of the License, or<br>
|
the Free Software Foundation, either version 3 of the License, or<br>
|
||||||
@ -46,12 +54,5 @@
|
|||||||
You should have received a copy of the GNU General Public License<br>
|
You should have received a copy of the GNU General Public License<br>
|
||||||
along with this program. If not, see http://www.gnu.org/licenses/.<br>
|
along with this program. If not, see http://www.gnu.org/licenses/.<br>
|
||||||
</div>
|
</div>
|
||||||
<br>
|
|
||||||
<br>
|
|
||||||
<div style="font-size: 12px; color: gray;">
|
|
||||||
使用者必须遵守当地法律法规。<br>
|
|
||||||
欢迎加入 CuteDNS! QQ群:625385297 。<br>
|
|
||||||
打开菜单探索更多功能。
|
|
||||||
</div>
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
@ -7,6 +7,7 @@ import android.content.Context;
|
|||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.VpnService;
|
import android.net.VpnService;
|
||||||
import android.os.ParcelFileDescriptor;
|
import android.os.ParcelFileDescriptor;
|
||||||
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v7.app.NotificationCompat;
|
import android.support.v7.app.NotificationCompat;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
@ -21,15 +22,16 @@ import android.util.Log;
|
|||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*/
|
*/
|
||||||
public class DaedalusVpnService extends VpnService implements Runnable {
|
public class DaedalusVpnService extends VpnService implements Runnable {
|
||||||
public static final String ACTION_ACTIVATE = "org.itxtech.daedalus.DaedalusVpnServer.ACTIVATE";
|
static final String ACTION_ACTIVATE = "org.itxtech.daedalus.DaedalusVpnService.ACTION_ACTIVATE";
|
||||||
public static final String ACTION_DEACTIVATE = "org.itxtech.daedalus.DaedalusVpnServer.DEACTIVATE";
|
static final String ACTION_DEACTIVATE = "org.itxtech.daedalus.DaedalusVpnService.ACTION_DEACTIVATE";
|
||||||
|
|
||||||
public static String primaryServer;
|
static String primaryServer;
|
||||||
public static String secondaryServer;
|
static String secondaryServer;
|
||||||
|
|
||||||
private Thread mThread = null;
|
private Thread mThread = null;
|
||||||
private static int ip = 0;
|
private static int ip = 0;
|
||||||
private ParcelFileDescriptor descriptor;
|
private ParcelFileDescriptor descriptor;
|
||||||
|
private boolean running = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
@ -41,6 +43,7 @@ public class DaedalusVpnService extends VpnService implements Runnable {
|
|||||||
if (intent != null) {
|
if (intent != null) {
|
||||||
switch (intent.getAction()) {
|
switch (intent.getAction()) {
|
||||||
case ACTION_ACTIVATE:
|
case ACTION_ACTIVATE:
|
||||||
|
if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean("settings_notification", true)) {
|
||||||
|
|
||||||
NotificationManager manager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
|
NotificationManager manager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
|
|
||||||
@ -53,15 +56,19 @@ public class DaedalusVpnService extends VpnService implements Runnable {
|
|||||||
.setSmallIcon(R.mipmap.ic_launcher)
|
.setSmallIcon(R.mipmap.ic_launcher)
|
||||||
.setAutoCancel(true)
|
.setAutoCancel(true)
|
||||||
.setOngoing(true)
|
.setOngoing(true)
|
||||||
.setContentIntent(pIntent);
|
.setContentIntent(pIntent)
|
||||||
|
.addAction(R.mipmap.ic_launcher, getResources().getString(R.string.button_text_deactivate), PendingIntent.getBroadcast(this, 0, new Intent(StatusBarBroadcastReceiver.STATUS_BAR_BTN_DEACTIVATE_CLICK_ACTION), 0))
|
||||||
|
.addAction(R.mipmap.ic_launcher, getResources().getString(R.string.action_settings), PendingIntent.getBroadcast(this, 0, new Intent(StatusBarBroadcastReceiver.STATUS_BAR_BTN_SETTINGS_CLICK_ACTION), 0));
|
||||||
|
|
||||||
Notification notification = builder.build();
|
Notification notification = builder.build();
|
||||||
notification.flags = Notification.FLAG_NO_CLEAR;
|
notification.flags = Notification.FLAG_NO_CLEAR;
|
||||||
|
|
||||||
manager.notify(0, notification);
|
manager.notify(0, notification);
|
||||||
|
}
|
||||||
|
|
||||||
if (this.mThread == null) {
|
if (this.mThread == null) {
|
||||||
this.mThread = new Thread(this, "DaedalusVpn");
|
this.mThread = new Thread(this, "DaedalusVpn");
|
||||||
|
this.running = true;
|
||||||
this.mThread.start();
|
this.mThread.start();
|
||||||
}
|
}
|
||||||
return START_STICKY;
|
return START_STICKY;
|
||||||
@ -88,6 +95,10 @@ public class DaedalusVpnService extends VpnService implements Runnable {
|
|||||||
this.descriptor.close();
|
this.descriptor.close();
|
||||||
this.descriptor = null;
|
this.descriptor = null;
|
||||||
}
|
}
|
||||||
|
if (this.mThread != null) {
|
||||||
|
this.running = false;
|
||||||
|
this.mThread = null;
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.d("DVpn", e.toString());
|
Log.d("DVpn", e.toString());
|
||||||
}
|
}
|
||||||
@ -122,8 +133,8 @@ public class DaedalusVpnService extends VpnService implements Runnable {
|
|||||||
builder.addDnsServer(primaryServer).addDnsServer(secondaryServer);
|
builder.addDnsServer(primaryServer).addDnsServer(secondaryServer);
|
||||||
this.descriptor = builder.setSession("DVpn").establish();
|
this.descriptor = builder.setSession("DVpn").establish();
|
||||||
|
|
||||||
while (true) {
|
while (running) {
|
||||||
Thread.sleep(8000);
|
Thread.sleep(1000);
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.d("DVpn", e.toString());
|
Log.d("DVpn", e.toString());
|
||||||
|
@ -10,8 +10,8 @@ package org.itxtech.daedalus;
|
|||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*/
|
*/
|
||||||
public class DnsServers {
|
class DnsServers {
|
||||||
public static String getDnsServerAddress(String id) {
|
static String getDnsServerAddress(String id) {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case "0":
|
case "0":
|
||||||
return "113.107.249.56";
|
return "113.107.249.56";
|
||||||
|
@ -27,12 +27,19 @@ import android.widget.Button;
|
|||||||
* the Free Software Foundation, version 3.
|
* the Free Software Foundation, version 3.
|
||||||
*/
|
*/
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
private static MainActivity instance = null;
|
||||||
private SharedPreferences prefs;
|
private SharedPreferences prefs;
|
||||||
|
|
||||||
|
static MainActivity getInstance() {
|
||||||
|
return instance;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
instance = this;
|
||||||
|
|
||||||
initConfig();
|
initConfig();
|
||||||
|
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
|
@ -0,0 +1,49 @@
|
|||||||
|
package org.itxtech.daedalus;
|
||||||
|
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.widget.Button;
|
||||||
|
|
||||||
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Daedalus Project
|
||||||
|
*
|
||||||
|
* @author iTXTech
|
||||||
|
* @link https://itxtech.org
|
||||||
|
* <p>
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*/
|
||||||
|
public class StatusBarBroadcastReceiver extends BroadcastReceiver {
|
||||||
|
static String STATUS_BAR_BTN_DEACTIVATE_CLICK_ACTION = "org.itxtech.daedalus.StatusBarBroadcastReceiver.STATUS_BAR_BTN_DEACTIVATE_CLICK_ACTION";
|
||||||
|
static String STATUS_BAR_BTN_SETTINGS_CLICK_ACTION = "org.itxtech.daedalus.StatusBarBroadcastReceiver.STATUS_BAR_BTN_SETTINGS_CLICK_ACTION";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
if (intent.getAction().equals(STATUS_BAR_BTN_DEACTIVATE_CLICK_ACTION)) {
|
||||||
|
Intent serviceIntent = new Intent(context, DaedalusVpnService.class);
|
||||||
|
context.startService(serviceIntent.setAction(DaedalusVpnService.ACTION_DEACTIVATE));
|
||||||
|
context.stopService(serviceIntent);
|
||||||
|
if (MainActivity.getInstance() != null) {
|
||||||
|
((Button) MainActivity.getInstance().findViewById(R.id.button_activate)).setText(R.string.button_text_activate);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (intent.getAction().equals(STATUS_BAR_BTN_SETTINGS_CLICK_ACTION)) {
|
||||||
|
Intent settingsIntent = new Intent(context, SettingsActivity.class);
|
||||||
|
settingsIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||||
|
context.startActivity(settingsIntent);
|
||||||
|
try {
|
||||||
|
Object statusBarManager = context.getSystemService("statusbar");
|
||||||
|
Method collapse = statusBarManager.getClass().getMethod("collapsePanels");
|
||||||
|
collapse.invoke(statusBarManager);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.d("DVpn", e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,7 +6,7 @@
|
|||||||
<string name="button_text_activate">启用</string>
|
<string name="button_text_activate">启用</string>
|
||||||
<string name="button_text_deactivate">停用</string>
|
<string name="button_text_deactivate">停用</string>
|
||||||
<string name="action_about">关于</string>
|
<string name="action_about">关于</string>
|
||||||
<string name="notification_activated">点击回到 Daedalus</string>
|
<string name="notification_activated">已启用 iTXTech Daedalus。</string>
|
||||||
<string name="settings_system">系统设置</string>
|
<string name="settings_system">系统设置</string>
|
||||||
<string name="settings_boot">开机自动启用</string>
|
<string name="settings_boot">开机自动启用</string>
|
||||||
<string name="settings_server">服务器设置</string>
|
<string name="settings_server">服务器设置</string>
|
||||||
@ -29,4 +29,5 @@
|
|||||||
<string name="action_visit_itxtech">访问 iTXTech</string>
|
<string name="action_visit_itxtech">访问 iTXTech</string>
|
||||||
<string name="action_join_qqgroup">加入 CuteDNS! QQ群</string>
|
<string name="action_join_qqgroup">加入 CuteDNS! QQ群</string>
|
||||||
<string name="notice_join_group_failed">未安装手Q或当前版本不支持此操作。</string>
|
<string name="notice_join_group_failed">未安装手Q或当前版本不支持此操作。</string>
|
||||||
|
<string name="settings_notification">启用时在状态栏显示通知</string>
|
||||||
</resources>
|
</resources>
|
@ -1,11 +1,11 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">Daedalus</string>
|
<string name="app_name">Daedalus</string>
|
||||||
<string name="action_settings">Settings</string>
|
<string name="action_settings">Settings</string>
|
||||||
<string name="notice_main">Through CuteDNS! to see the world outside.</string>
|
<string name="notice_main">See the world outside through CuteDNS!</string>
|
||||||
<string name="button_text_activate">Activate</string>
|
<string name="button_text_activate">Activate</string>
|
||||||
<string name="button_text_deactivate">Deactivate</string>
|
<string name="button_text_deactivate">Deactivate</string>
|
||||||
<string name="action_about">About</string>
|
<string name="action_about">About</string>
|
||||||
<string name="notification_activated">Click to back to Daedalus</string>
|
<string name="notification_activated">iTXTech Daedalus is activated.</string>
|
||||||
<string name="settings_system">System settings</string>
|
<string name="settings_system">System settings</string>
|
||||||
<string name="settings_boot">Auto activate on boot</string>
|
<string name="settings_boot">Auto activate on boot</string>
|
||||||
<string name="settings_server">Server settings</string>
|
<string name="settings_server">Server settings</string>
|
||||||
@ -29,4 +29,5 @@
|
|||||||
<string name="action_join_qqgroup">Join QQ group</string>
|
<string name="action_join_qqgroup">Join QQ group</string>
|
||||||
<string name="notice_join_group_failed">QQ is not installed or this version of QQ does not support this operation.
|
<string name="notice_join_group_failed">QQ is not installed or this version of QQ does not support this operation.
|
||||||
</string>
|
</string>
|
||||||
|
<string name="settings_notification">Display notification in status bar when activated</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -8,6 +8,10 @@
|
|||||||
android:key="settings_boot"
|
android:key="settings_boot"
|
||||||
android:title="@string/settings_boot"
|
android:title="@string/settings_boot"
|
||||||
android:defaultValue="false"/>
|
android:defaultValue="false"/>
|
||||||
|
<SwitchPreference
|
||||||
|
android:key="settings_notification"
|
||||||
|
android:title="@string/settings_notification"
|
||||||
|
android:defaultValue="true"/>
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
|
Loading…
x
Reference in New Issue
Block a user