diff --git a/app/src/main/java/com/termux/app/ExtraKeysView.java b/app/src/main/java/com/termux/app/ExtraKeysView.java index e2f76dc3eb..703b952494 100644 --- a/app/src/main/java/com/termux/app/ExtraKeysView.java +++ b/app/src/main/java/com/termux/app/ExtraKeysView.java @@ -10,13 +10,18 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.Map; -import java.util.HashMap; -import java.util.Arrays; +import java.util.HashMap; +import java.io.File; +import java.util.Arrays; +import java.util.Properties; +import java.io.InputStream; +import java.io.FileInputStream; import android.view.HapticFeedbackConstants; import android.view.KeyEvent; import android.view.MotionEvent; -import android.view.View; +import android.view.View; +import android.graphics.Color; import android.widget.Button; import android.widget.GridLayout; import android.widget.PopupWindow; @@ -32,15 +37,53 @@ */ public final class ExtraKeysView extends GridLayout { - private static final int TEXT_COLOR = 0xFFFFFFFF; + private static int TEXT_COLOR; private static final int BUTTON_COLOR = 0x00000000; - private static final int INTERESTING_COLOR = 0xFF80DEEA; - private static final int BUTTON_PRESSED_COLOR = 0x7FFFFFFF; + private static int INTERESTING_COLOR; + private static int BUTTON_PRESSED_COLOR; public ExtraKeysView(Context context, AttributeSet attrs) { - super(context, attrs); + super(context, attrs); + setButtonColor(); } - + /* + * Get color values set by user in termux.properties. + * Set TEXT_COLOR, INTERESTING_COLOR, and BUTTON_PRESSED_COLOR based on user values, + * or fallback values, if not present. + */ + public void setButtonColor() { + InputStream fileInputStream; + boolean caught = false; + int color = Color.WHITE; + String[] keys = new String [] {"extra-key-color", "extra-key-checked-color", "extra-key-pressed-color"}; + for ( String key : keys) { + caught = false; + try { + String path = "/data/data/com.termux/files/home/.termux/termux.properties"; + File file = new File(path); + Properties properties = new Properties(); + fileInputStream = new FileInputStream(file); + properties.load(fileInputStream); + fileInputStream.close(); + color = Color.parseColor(properties.getProperty(key)); + } + catch (Throwable th) { + caught = true; + } + int position = Arrays.asList(keys).indexOf(key); + switch(position) { + case 0: + TEXT_COLOR = color; + break; + case 1: + INTERESTING_COLOR = caught ? 0xFF80DEEA : color; + break; + case 2: + BUTTON_PRESSED_COLOR = caught ? 0x7FFFFFFF : color; + break; + } + } + } /** * HashMap that implements Python dict.get(key, default) function. * Default java.util .get(key) is then the same as .get(key, null);