Skip to content

Commit

Permalink
Add Dark Theme
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdullahM0hamed authored and Leonid Pliushch committed Sep 28, 2020
1 parent c698354 commit 4b45656
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
34 changes: 34 additions & 0 deletions app/src/main/java/com/termux/api/DialogActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.speech.RecognitionListener;
import android.speech.RecognizerIntent;
import android.speech.SpeechRecognizer;
import android.util.Log;
import androidx.annotation.NonNull;
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
Expand Down Expand Up @@ -44,12 +45,17 @@
import com.termux.api.util.ResultReturner;
import com.termux.api.util.TermuxApiPermissionActivity;

import java.nio.charset.StandardCharsets;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Properties;

/**
* API that allows receiving user input interactively in a variety of different ways
Expand All @@ -58,6 +64,31 @@ public class DialogActivity extends AppCompatActivity {

private boolean resultReturned = false;

protected boolean getBlackUI() {
File propsFile = new File("/data/data/com.termux/files/home/.termux/termux.properties");

if (!propsFile.exists())
propsFile = new File("/data/data/com.termux/files/home/.config/termux.properties");

boolean mUseBlackUi = false;

if (propsFile.exists()) {
Properties props = new Properties();
try {
if (propsFile.isFile() && propsFile.canRead()) {
try (FileInputStream in = new FileInputStream(propsFile)) {
props.load(new InputStreamReader(in, StandardCharsets.UTF_8));
}
}
mUseBlackUi = props.getProperty("use-black-ui").equals("true");
} catch (Exception e) {
Log.e("termux-api", "Error loading props", e);
}
}

return mUseBlackUi;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -67,6 +98,9 @@ protected void onCreate(Bundle savedInstanceState) {

String methodType = intent.hasExtra("input_method") ? intent.getStringExtra("input_method") : "";

if (getBlackUI())
this.setTheme(R.style.DialogTheme_Dark);

InputMethod method = InputMethodFactory.get(methodType, this);
method.create(this, result -> {
postResult(context, result);
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
<item name="windowNoTitle">true</item>
</style>

<style name="DialogTheme.Dark" parent="Theme.AppCompat.Dialog.Alert">
<item name="windowNoTitle">true</item>
</style>

<style name="TransparentTheme" parent="@style/Theme.AppCompat.Light">

<item name="android:background">@android:color/transparent</item>
<item name="background">@android:color/transparent</item>

Expand All @@ -39,4 +41,4 @@
</style>

<style name="ButtonBarButton" />
</resources>
</resources>

0 comments on commit 4b45656

Please sign in to comment.