这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 51 additions & 8 deletions app/src/main/java/com/termux/app/ExtraKeysView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down