mirror of
https://github.com/M66B/NetGuard.git
synced 2025-02-23 14:51:06 +00:00
parent
5e8661b1e9
commit
c9196eb75a
3 changed files with 82 additions and 12 deletions
|
@ -77,6 +77,7 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
private MenuItem menuSearch = null;
|
||||
private IInAppBillingService IABService = null;
|
||||
private AlertDialog dialogFirst = null;
|
||||
private AlertDialog dialogVpn = null;
|
||||
private AlertDialog dialogAbout = null;
|
||||
|
||||
private static final int REQUEST_VPN = 1;
|
||||
|
@ -120,19 +121,40 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
if (isChecked) {
|
||||
Log.i(TAG, "Switch on");
|
||||
Intent prepare = VpnService.prepare(ActivityMain.this);
|
||||
final Intent prepare = VpnService.prepare(ActivityMain.this);
|
||||
if (prepare == null) {
|
||||
Log.e(TAG, "Prepare done");
|
||||
onActivityResult(REQUEST_VPN, RESULT_OK, null);
|
||||
} else {
|
||||
Log.i(TAG, "Start intent=" + prepare);
|
||||
try {
|
||||
startActivityForResult(prepare, REQUEST_VPN);
|
||||
} catch (Throwable ex) {
|
||||
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
||||
onActivityResult(REQUEST_VPN, RESULT_CANCELED, null);
|
||||
Toast.makeText(ActivityMain.this, ex.toString(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
// Show dialog
|
||||
LayoutInflater inflater = LayoutInflater.from(ActivityMain.this);
|
||||
View view = inflater.inflate(R.layout.vpn, null);
|
||||
dialogVpn = new AlertDialog.Builder(ActivityMain.this)
|
||||
.setView(view)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
if (running) {
|
||||
Log.i(TAG, "Start intent=" + prepare);
|
||||
try {
|
||||
startActivityForResult(prepare, REQUEST_VPN);
|
||||
} catch (Throwable ex) {
|
||||
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
|
||||
onActivityResult(REQUEST_VPN, RESULT_CANCELED, null);
|
||||
Toast.makeText(ActivityMain.this, ex.toString(), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialogInterface) {
|
||||
dialogVpn = null;
|
||||
}
|
||||
})
|
||||
.create();
|
||||
dialogVpn.show();
|
||||
}
|
||||
} else {
|
||||
Log.i(TAG, "Switch off");
|
||||
|
@ -242,13 +264,23 @@ public class ActivityMain extends AppCompatActivity implements SharedPreferences
|
|||
unregisterReceiver(connectivityChangedReceiver);
|
||||
unregisterReceiver(packageChangedReceiver);
|
||||
|
||||
if (IABService != null)
|
||||
if (IABService != null) {
|
||||
unbindService(IABConnection);
|
||||
IABService = null;
|
||||
}
|
||||
|
||||
if (dialogFirst != null)
|
||||
if (dialogFirst != null) {
|
||||
dialogFirst.dismiss();
|
||||
if (dialogAbout != null)
|
||||
dialogFirst = null;
|
||||
}
|
||||
if (dialogVpn != null) {
|
||||
dialogVpn.dismiss();
|
||||
dialogVpn = null;
|
||||
}
|
||||
if (dialogAbout != null) {
|
||||
dialogAbout.dismiss();
|
||||
dialogAbout = null;
|
||||
}
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
|
37
app/src/main/res/layout/vpn.xml
Normal file
37
app/src/main/res/layout/vpn.xml
Normal file
|
@ -0,0 +1,37 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="20dp"
|
||||
android:paddingEnd="20dp"
|
||||
android:paddingStart="20dp"
|
||||
android:paddingTop="20dp">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:src="@mipmap/ic_launcher" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:layout_marginStart="8dp"
|
||||
android:text="@string/app_name"
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Large"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/msg_vpn"
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Medium" />
|
||||
</LinearLayout>
|
|
@ -24,6 +24,7 @@ This is caused by bugs in Android, or in the software provided by the manufactur
|
|||
<string name="msg_disabled">NetGuard is disabled, use the switch above to enable NetGuard</string>
|
||||
<string name="msg_revoked">NetGuard has been disabled</string>
|
||||
<string name="msg_completed">Action completed</string>
|
||||
<string name="msg_vpn">NetGuard uses a local VPN as a sinkhole for blocked traffic, for this reason you should allow a VPN connection in the next dialog</string>
|
||||
|
||||
<string name="title_using">Allow when device in use</string>
|
||||
<string name="title_roaming">Block when roaming</string>
|
||||
|
|
Loading…
Reference in a new issue