Skip to content

Commit

Permalink
Automatically follow night/dark mode on Android 10+
Browse files Browse the repository at this point in the history
Fixes #358
  • Loading branch information
julian-klode committed Feb 28, 2020
1 parent ceb49c3 commit c4080db
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions app/src/main/java/org/jak_linux/dns66/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,20 @@
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.tabs.TabLayout;

import androidx.fragment.app.Fragment;
import androidx.localbroadcastmanager.content.LocalBroadcastManager;
import androidx.viewpager.widget.ViewPager;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.app.AppCompatDelegate;
import androidx.appcompat.widget.Toolbar;

import android.text.Html;
import android.util.Log;
import android.view.Menu;
Expand Down Expand Up @@ -78,7 +82,9 @@ protected void onCreate(Bundle savedInstanceState) {
config = FileHelper.loadCurrentSettings(this);
}

if (config.nightMode) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
} else if (config.nightMode) {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
} else {
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
Expand Down Expand Up @@ -127,8 +133,11 @@ public boolean onCreateOptionsMenu(Menu menu) {
menu.findItem(R.id.setting_show_notification).setChecked(config.showNotification);
menu.findItem(R.id.setting_night_mode).setChecked(config.nightMode);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
menu.findItem(R.id.setting_night_mode).setVisible(false);
}
// On Android O, require users to configure notifications via notification channels.
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
menu.findItem(R.id.setting_show_notification).setVisible(false);
}
return true;
Expand Down Expand Up @@ -224,7 +233,7 @@ private void sendLogcat() {

Intent eMailIntent = new Intent(Intent.ACTION_SEND);
eMailIntent.setType("text/plain");
eMailIntent.putExtra(Intent.EXTRA_EMAIL, new String[] {"jak@jak-linux.org"});
eMailIntent.putExtra(Intent.EXTRA_EMAIL, new String[]{"jak@jak-linux.org"});
eMailIntent.putExtra(Intent.EXTRA_SUBJECT, "DNS66 Logcat");
eMailIntent.putExtra(Intent.EXTRA_TEXT, logcat.toString());
eMailIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Expand Down

0 comments on commit c4080db

Please sign in to comment.