Skip to content

Commit

Permalink
v1.3 - added a tile config activity
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Wolfsohn committed Oct 5, 2019
1 parent 8388905 commit d20bcbe
Show file tree
Hide file tree
Showing 15 changed files with 413 additions and 104 deletions.
109 changes: 109 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ android {
applicationId "com.jpwolfso.privdnsqt"
minSdkVersion 28
targetSdkVersion 28
versionCode 3
versionName '1.2'
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
versionCode 4
versionName '1.3'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
minifyEnabled true
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
Expand All @@ -21,4 +21,5 @@ android {
}

dependencies {
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
}
2 changes: 1 addition & 1 deletion app/release/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":3,"versionName":"1.2","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":4,"versionName":"1.3","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
38 changes: 19 additions & 19 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:toolsNs="http://schemas.android.com/tools"
package="com.jpwolfso.privdnsqt">

<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" toolsNs:ignore="ProtectedPermissions"/>
<uses-permission
android:name="android.permission.WRITE_SECURE_SETTINGS"
toolsNs:ignore="ProtectedPermissions" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@android:style/Theme.Translucent.NoTitleBar">

<service
android:name=".PrivateDnsTileService"
android:enabled="true"
android:exported="true"
android:icon="@drawable/ic_dnsauto"
android:label="@string/qt_default"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
</service>
android:theme="@android:style/Theme.DeviceDefault.Dialog">

<activity
android:name=".HelperActivity"
android:name=".PrivateDnsConfigActivity"
android:excludeFromRecents="true"
android:noHistory="true">
android:label="Private DNS Quick Tile Modes">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE_PREFERENCES" />
</intent-filter>
</activity>


<service
android:name=".PrivateDnsTileService"
android:enabled="true"
android:exported="true"
android:icon="@drawable/ic_dnsauto"
android:label="@string/qt_default"
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
<intent-filter>
<action android:name="android.service.quicksettings.action.QS_TILE" />
</intent-filter>
</service>

</application>

</manifest>

</manifest>
19 changes: 0 additions & 19 deletions app/src/main/java/com/jpwolfso/privdnsqt/HelperActivity.java

This file was deleted.

118 changes: 118 additions & 0 deletions app/src/main/java/com/jpwolfso/privdnsqt/PrivateDnsConfigActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package com.jpwolfso.privdnsqt;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.Toast;

public class PrivateDnsConfigActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_private_dns_config);

final SharedPreferences togglestates = getSharedPreferences("togglestates", Context.MODE_PRIVATE);
final SharedPreferences.Editor editor = togglestates.edit();

final CheckBox checkoff = findViewById(R.id.check_off);
final CheckBox checkauto = findViewById(R.id.check_auto);
final CheckBox checkon = findViewById(R.id.check_on);

final EditText texthostname = findViewById(R.id.text_hostname);

final Button okbutton = findViewById(R.id.button_ok);

if (togglestates.getBoolean("toggle_off", true)) {
checkoff.setChecked(true);
}

if (togglestates.getBoolean("toggle_auto", true)) {
checkauto.setChecked(true);
}

if (togglestates.getBoolean("toggle_on", true)) {
checkon.setChecked(true);
texthostname.setEnabled(true);
} else {
texthostname.setEnabled(false);

}

String dnsprovider = Settings.Global.getString(getContentResolver(), "private_dns_specifier");
if (dnsprovider != null) {
texthostname.setText(dnsprovider);
}

checkoff.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (checkoff.isChecked()) {
editor.putBoolean("toggle_off", true);
} else {
editor.putBoolean("toggle_off", false);
}
}
});

checkauto.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (checkauto.isChecked()) {
editor.putBoolean("toggle_auto", true);
} else {
editor.putBoolean("toggle_auto", false);
}
}
});

checkon.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (checkon.isChecked()) {
editor.putBoolean("toggle_on", true);
texthostname.setEnabled(true);
} else {
editor.putBoolean("toggle_on", false);
texthostname.setEnabled(false);
}
}
});

okbutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (hasPermission()) {
if (checkon.isChecked()) {
if (texthostname.getText().toString().isEmpty()) {
Toast.makeText(PrivateDnsConfigActivity.this, "DNS provider not configured", Toast.LENGTH_SHORT).show();
return;
} else {
Settings.Global.putString(getContentResolver(), "private_dns_specifier", texthostname.getText().toString());
}
}
editor.commit();
finish();
} else {
Toast.makeText(PrivateDnsConfigActivity.this, getString(R.string.toast_permission), Toast.LENGTH_SHORT).show();
return;
}
}
});


}

public boolean hasPermission() {
return checkCallingOrSelfPermission("android.permission.WRITE_SECURE_SETTINGS") != PackageManager.PERMISSION_DENIED;
}

}
Loading

0 comments on commit d20bcbe

Please sign in to comment.