Improved activated notification

This commit is contained in:
PeratX 2017-04-08 23:18:28 +08:00
parent 5f693fc47a
commit a1895726c1
11 changed files with 122 additions and 41 deletions

View File

@ -9,9 +9,8 @@ android {
applicationId "org.itxtech.daedalus"
minSdkVersion 21
targetSdkVersion 25
versionCode 1
versionName "1.0.0"
versionCode 2
versionName "1.0.1"
buildConfigField "String", "BUILD_TIME", "\"${System.currentTimeMillis()}\""
buildConfigField "String", "GIT_COMMIT", "\"${gitCommit}\""

View File

@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.EXPAND_STATUS_BAR"/>
<application
android:allowBackup="true"
@ -28,6 +29,13 @@
</intent-filter>
</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
android:name=".MainActivity"
android:label="@string/app_name"

View File

@ -33,6 +33,13 @@
<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>
<br>
<br>
<div style="font-size: 8px; color: gray;">
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>
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>
along with this program. If not, see http://www.gnu.org/licenses/.<br>
</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>
</html>

View File

@ -30,9 +30,17 @@
<br>
<img width="185" height="55" src="cutedns_logo.png">
<div style="font-size: 25px;">CuteDNS!</div>
<br>
<br>
<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>
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>
@ -46,12 +54,5 @@
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>
</div>
<br>
<br>
<div style="font-size: 12px; color: gray;">
使用者必须遵守当地法律法规。<br>
欢迎加入 CuteDNS! QQ群625385297 。<br>
打开菜单探索更多功能。
</div>
</body>
</html>

View File

@ -7,6 +7,7 @@ import android.content.Context;
import android.content.Intent;
import android.net.VpnService;
import android.os.ParcelFileDescriptor;
import android.preference.PreferenceManager;
import android.support.v7.app.NotificationCompat;
import android.util.Log;
@ -21,15 +22,16 @@ import android.util.Log;
* the Free Software Foundation, version 3.
*/
public class DaedalusVpnService extends VpnService implements Runnable {
public static final String ACTION_ACTIVATE = "org.itxtech.daedalus.DaedalusVpnServer.ACTIVATE";
public static final String ACTION_DEACTIVATE = "org.itxtech.daedalus.DaedalusVpnServer.DEACTIVATE";
static final String ACTION_ACTIVATE = "org.itxtech.daedalus.DaedalusVpnService.ACTION_ACTIVATE";
static final String ACTION_DEACTIVATE = "org.itxtech.daedalus.DaedalusVpnService.ACTION_DEACTIVATE";
public static String primaryServer;
public static String secondaryServer;
static String primaryServer;
static String secondaryServer;
private Thread mThread = null;
private static int ip = 0;
private ParcelFileDescriptor descriptor;
private boolean running = false;
@Override
public void onCreate() {
@ -41,27 +43,32 @@ public class DaedalusVpnService extends VpnService implements Runnable {
if (intent != null) {
switch (intent.getAction()) {
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);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
Intent nIntent = new Intent(this, MainActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, nIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentTitle(getResources().getString(R.string.notification_activated))
.setDefaults(NotificationCompat.DEFAULT_LIGHTS)
.setSmallIcon(R.mipmap.ic_launcher)
.setAutoCancel(true)
.setOngoing(true)
.setContentIntent(pIntent);
Intent nIntent = new Intent(this, MainActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, 0, nIntent, PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentTitle(getResources().getString(R.string.notification_activated))
.setDefaults(NotificationCompat.DEFAULT_LIGHTS)
.setSmallIcon(R.mipmap.ic_launcher)
.setAutoCancel(true)
.setOngoing(true)
.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.flags = Notification.FLAG_NO_CLEAR;
Notification notification = builder.build();
notification.flags = Notification.FLAG_NO_CLEAR;
manager.notify(0, notification);
manager.notify(0, notification);
}
if (this.mThread == null) {
this.mThread = new Thread(this, "DaedalusVpn");
this.running = true;
this.mThread.start();
}
return START_STICKY;
@ -88,6 +95,10 @@ public class DaedalusVpnService extends VpnService implements Runnable {
this.descriptor.close();
this.descriptor = null;
}
if (this.mThread != null) {
this.running = false;
this.mThread = null;
}
} catch (Exception e) {
Log.d("DVpn", e.toString());
}
@ -122,8 +133,8 @@ public class DaedalusVpnService extends VpnService implements Runnable {
builder.addDnsServer(primaryServer).addDnsServer(secondaryServer);
this.descriptor = builder.setSession("DVpn").establish();
while (true) {
Thread.sleep(8000);
while (running) {
Thread.sleep(1000);
}
} catch (Exception e) {
Log.d("DVpn", e.toString());

View File

@ -10,8 +10,8 @@ package org.itxtech.daedalus;
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, version 3.
*/
public class DnsServers {
public static String getDnsServerAddress(String id) {
class DnsServers {
static String getDnsServerAddress(String id) {
switch (id) {
case "0":
return "113.107.249.56";

View File

@ -27,12 +27,19 @@ import android.widget.Button;
* the Free Software Foundation, version 3.
*/
public class MainActivity extends AppCompatActivity {
private static MainActivity instance = null;
private SharedPreferences prefs;
static MainActivity getInstance() {
return instance;
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
instance = this;
initConfig();
setContentView(R.layout.activity_main);

View File

@ -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());
}
}
}
}

View File

@ -6,7 +6,7 @@
<string name="button_text_activate">启用</string>
<string name="button_text_deactivate">停用</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_boot">开机自动启用</string>
<string name="settings_server">服务器设置</string>
@ -29,4 +29,5 @@
<string name="action_visit_itxtech">访问 iTXTech</string>
<string name="action_join_qqgroup">加入 CuteDNS! QQ群</string>
<string name="notice_join_group_failed">未安装手Q或当前版本不支持此操作。</string>
<string name="settings_notification">启用时在状态栏显示通知</string>
</resources>

View File

@ -1,11 +1,11 @@
<resources>
<string name="app_name">Daedalus</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_deactivate">Deactivate</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_boot">Auto activate on boot</string>
<string name="settings_server">Server settings</string>
@ -29,4 +29,5 @@
<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>
<string name="settings_notification">Display notification in status bar when activated</string>
</resources>

View File

@ -8,6 +8,10 @@
android:key="settings_boot"
android:title="@string/settings_boot"
android:defaultValue="false"/>
<SwitchPreference
android:key="settings_notification"
android:title="@string/settings_notification"
android:defaultValue="true"/>
</PreferenceCategory>
<PreferenceCategory