Skip to content

Commit

Permalink
Release 0.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
RainbowC0 committed Sep 16, 2024
1 parent 5f2feff commit d36f555
Show file tree
Hide file tree
Showing 24 changed files with 241 additions and 285 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "cn.rbc.termuc"
minSdkVersion 21
targetSdkVersion 30
versionCode 3
versionName "0.1.2"
versionCode 4
versionName "0.1.3"
}

buildTypes {
Expand Down
23 changes: 1 addition & 22 deletions app/src/main/assets/init
Original file line number Diff line number Diff line change
@@ -1,22 +1 @@
echo 设置存储 Setup storage
termux-setup-storage
DATA=package:com.termux
echo -n 设置悬浮窗权限 Setup draw over apps \(请按回车 Press Enter\);read _
am start -a android.settings.action.MANAGE_OVERLAY_PERMISSION -d $DATA>/dev/null
echo -n 设置禁用电池优化 Setup ignore battery optimizations \(请按回车 Press Enter\);read _
am start -a android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS>/dev/null
echo -n 设置关联启动与后台弹出权限 Setup Startup \& Background pop-ups permissions \(请按回车 Press Enter\);read _
am start -a android.settings.APPLICATION_DETAILS_SETTINGS -d $DATA>/dev/null
echo 设置allow-external-app为\`true' Setup allow-external-app to \`true\'
fl=/data/data/com.termux/files/home/.termux/termux.properties
if [ -f $fl ];then
awk '/^#/{print;next }/^\s*allow-external-apps/{gsub(/allow-external-apps.*/,"allow-external-apps=true");found=1}{print $0}END{if(!found)print "allow-external-apps=true"}' $fl>$TMPDIR/a.tmp && mv $TMPDIR/a.tmp $fl
else
mkdir -p `dirname $fl`
echo 'allow-external-apps=true'>$fl
fi
echo 安装Clang Install Clang
pkg i clang -y
apt autoremove --purge
apt clean
echo ok
echo 设置存储 Setup storage;termux-setup-storage;DATA=package:com.termux;echo -n 设置悬浮窗权限 Setup draw over apps \(请按回车 Press Enter\);read i;am start -a android.settings.action.MANAGE_OVERLAY_PERMISSION -d $DATA>/dev/null;echo -n 设置禁用电池优化 Setup ignore battery optimizations \(请按回车 Press Enter\);read i;am start -a android.settings.IGNORE_BATTERY_OPTIMIZATION_SETTINGS>/dev/null;echo -n 设置关联启动与后台弹出权限 Setup Startup \& Background pop-ups permissions \(请按回车 Press Enter\);read i;am start -a android.settings.APPLICATION_DETAILS_SETTINGS -d $DATA>/dev/null;echo 设置allow-external-app Setup allow-external-app;fl=/data/data/com.termux/files/home/.termux/termux.properties;if [ -f $fl ];then awk '/^#/{print;next }/^\s*allow-external-apps/{gsub(/allow-external-apps.*/,"allow-external-apps=true");found=1}{print $0}END{if(!found)print "allow-external-apps=true"}' $fl>$TMPDIR/a.tmp && mv $TMPDIR/a.tmp $fl;else mkdir -p `dirname $fl`;echo 'allow-external-apps=true'>$fl;fi;echo 安装Clang Install Clang;pkg i clang -y;apt autoremove --purge;apt clean;echo ok
2 changes: 1 addition & 1 deletion app/src/main/java/cn/rbc/termuc/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Application extends android.app.Application
KEY_DARKMODE = "darkmode",
KEY_WORDWRAP = "wordwrap",
KEY_WHITESPACE = "whitespace",
KEY_TEXTSIZE = "textsize",
KEY_TEXTSIZE = "fontsize",
KEY_SHOW_HIDDEN = "showhidden",
KEY_CHECKAPP = "checkapp",
KEY_INITAPP = "initapp",
Expand Down
40 changes: 16 additions & 24 deletions app/src/main/java/cn/rbc/termuc/EditFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.content.res.*;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import android.app.AlertDialog.Builder;

public class EditFragment extends Fragment
implements OnTextChangeListener, DialogInterface.OnClickListener, Formatter
Expand Down Expand Up @@ -71,14 +72,17 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
editor.setLanguage(LanguageNonProg.getInstance());
}
ma.setEditor(editor);
if (tp != TYPE_OTHER)
if (tp != TYPE_OTHER && "s".equals(Application.completion))
MainActivity.lsp.didOpen(fl, tp==TYPE_CPP?"cpp":"c", s);
} catch(IOException fnf) {
fnf.printStackTrace();
HelperUtils.show(Toast.makeText(ma, R.string.open_failed, Toast.LENGTH_SHORT));
}
if ((type&TYPE_MASK)!=TYPE_OTHER && "s".equals(Application.completion))
editor.setFormatter(this);
if ((type&TYPE_MASK)!=TYPE_OTHER) {
if ("s".equals(Application.completion))
editor.setFormatter(this);
editor.setAutoComplete("l".equals(Application.completion));
}
lastModified = fl.lastModified();
return editor;
}
Expand All @@ -89,7 +93,7 @@ public String getC() {

@Override
public int createAutoIndent(CharSequence text) {
return 0;
return 4;
}

@Override
Expand Down Expand Up @@ -119,7 +123,6 @@ public CharSequence format(CharSequence txt, int width) {
}

private int mVer;
//private long mSendTime;

public void onChanged(CharSequence c, int start, int ver, boolean ins, boolean typ) {
TextEditor editor = ed;
Expand Down Expand Up @@ -151,38 +154,27 @@ public void onChanged(CharSequence c, int start, int ver, boolean ins, boolean t
}
range.msg = (String)c;
changes.add(range);
//HelperUtils.show(Toast.makeText(getContext()), text.isBatchEdit(),
//if (text.isBatchEdit())
Lsp lsp = MainActivity.lsp;
lsp.didChange(fl, ver, changes);
// when inserting text and typing, call for completion
if (ins && typ && c.length()==1)
lsp.completionTry(fl, range.enl, range.enc+1, c.charAt(0));
changes.clear();
mVer = ver;
//mSendTime = System.currentTimeMillis();
//editor.postDelayed(this, 1000L);
}
/*
public void run() {
Lsp lsp = MainActivity.lsp;
if (lsp.lastReceivedTime()<mSendTime) {
lsp.didChange(fl, mVer, ed.getText().toString());
}
}
*/

@Override
public void onResume() {
super.onResume();
long mLast = fl.lastModified();
if (mLast>lastModified) {
lastModified = mLast;
new AlertDialog.Builder(getContext())
.setTitle(fl.getName())
.setMessage(getString(R.string.file_modified, fl.getName()))
.setPositiveButton(android.R.string.ok, this)
.setNegativeButton(android.R.string.cancel, null)
.create().show();
Builder bd = new Builder(getContext());
bd.setTitle(fl.getName());
bd.setMessage(getString(R.string.file_modified, fl.getName()));
bd.setPositiveButton(android.R.string.ok, this);
bd.setNegativeButton(android.R.string.cancel, null);
bd.create().show();
}
}

Expand Down Expand Up @@ -243,7 +235,7 @@ public String load() throws IOException {
fr.close();
String s = sb.toString();
ed.setText(s);
if ((type&TYPE_MASK)!=TYPE_OTHER)
if ((type&TYPE_MASK)!=TYPE_OTHER && "s".equals(Application.completion))
ed.getText().setOnTextChangeListener(this);
return s;
}
Expand Down
28 changes: 20 additions & 8 deletions app/src/main/java/cn/rbc/termuc/Lsp.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.widget.*;
import android.util.JsonReader;
import java.util.concurrent.*;
import java.util.concurrent.locks.*;

public class Lsp implements Runnable {
final static int INITIALIZE = 0, INITIALIZED = 1,
Expand All @@ -28,14 +29,24 @@ public class Lsp implements Runnable {
private long mLastReceivedTime;
private Handler mRead;

public void start(final Context mC, Handler read) {
public void start(Context mC, Handler read) {
Utils.run(mC, "/system/bin/toybox", new String[]{"nc", "-l", "-s", Application.lsp_host, "-p", Integer.toString(Application.lsp_port), "clangd", "--header-insertion-decorators=0"}, Utils.ROOT.getAbsolutePath(), true);
mExecutor = Executors.newSingleThreadExecutor();
sk = new Socket();
mRead = read;
new Thread(this).start();
}

public void end() {
try {
sk.close();
} catch(IOException ioe) {}
}

public boolean isEnded() {
return sk.isClosed();
}

public void run() {
try{
int i = 0;
Expand All @@ -49,6 +60,7 @@ public void run() {
} while (i<=20 && !sk.isConnected());
if (i>20)
throw new IOException("Connection failed");
initialize();
InputStream is = sk.getInputStream();
byte[] b = new byte[16];
OUTER: while (true) {
Expand All @@ -59,6 +71,8 @@ public void run() {
b[i] = (byte)t;
}
if (Arrays.equals(b, CONTENTLEN)) {
Message msg = new Message();
msg.what = tp;
int len = 0;
while (Character.isDigit(i = is.read()))
len = len * 10 + i - 48;
Expand All @@ -69,11 +83,8 @@ public void run() {
strb[i] = (byte)is.read();
InputStream r = new ByteArrayInputStream(strb);
JsonReader limitInput = new JsonReader(new InputStreamReader(r, StandardCharsets.UTF_8));
Message msg = new Message();
msg.what = tp;
msg.obj = limitInput;
mRead.sendMessage(msg);
//tp = NOTI;
}
}
is.close();
Expand All @@ -99,7 +110,7 @@ private static String wrap(String m, Object p, boolean req) {
return s.toString();
}

public void initialize() {
private void initialize() {
tp = INITIALIZE;
StringBuilder sb = new StringBuilder("{\"processId\":");
sb.append(android.os.Process.myPid());
Expand Down Expand Up @@ -141,15 +152,15 @@ public void didOpen(File f, String lang, String ct) {
m.append("\",\"version\":0,\"text\":");
m.append(JSONObject.quote(ct));
m.append("}}");
//tp = OPEN;
tp = OPEN;
mExecutor.execute(new Send("textDocument/didOpen", m.toString(), false));
}

public void didSave(File f) {
StringBuilder s = new StringBuilder("{\"textDocument\":{\"uri\":");
s.append(JSONObject.quote(Uri.fromFile(f).toString()));
s.append("}}");
//tp = SAVE;
tp = SAVE;
mExecutor.execute(new Send("textDocument/didSave", s.toString(), false));
}

Expand All @@ -161,6 +172,7 @@ public synchronized void didChange(File f, int version, String text) {
sb.append("},\"contentChanges\":[{\"text\":");
sb.append(JSONObject.quote(text));
sb.append("}]}").toString();
tp = CHANGE;
mExecutor.execute(new Send("textDocument/didChange", sb.toString(), false));
}

Expand All @@ -186,7 +198,7 @@ public synchronized void didChange(File f, int version, List<Range> chs) {
}
sb.setCharAt(sb.length()-1, ']');
sb.append('}');
//tp = CHANGE;
tp = CHANGE;
mExecutor.execute(new Send("textDocument/didChange", sb.toString(), false));
}

Expand Down
24 changes: 15 additions & 9 deletions app/src/main/java/cn/rbc/termuc/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class MainActivity extends Activity implements
private ArrayAdapter<String> hda;
private FileAdapter adp;
private EditFragment lastFrag = null;
private boolean byhand = true, inited = false, transZ;
private boolean byhand = true, transZ;
private View keys, showlist;
private File pwd;
private TextView pwdpth, msgEmpty, transTxV;
Expand Down Expand Up @@ -120,7 +120,7 @@ protected void onCreate(Bundle savedInstanceState) {
}, PackageManager.PERMISSION_GRANTED);
if (pref.getBoolean(TESTAPP, true))
Utils.testApp(this, false);
if (pref.getBoolean(INITAPP, true))
else if (pref.getBoolean(INITAPP, true))
Utils.initBack(this, false);
}

Expand Down Expand Up @@ -185,10 +185,6 @@ else if (!Utils.isBlob(pwd))
else
_i = -1;
if (_tp != -1) {
if (!inited) {
lsp.initialize();
inited = true;
}
EditFragment ef = new EditFragment(pwd.getPath(), _tp);
FragmentTransaction mts = getFragmentManager().beginTransaction()
.add(R.id.editFrag, ef, _it);
Expand Down Expand Up @@ -348,15 +344,16 @@ public boolean onKeyUp(int i, KeyEvent keyEvent) {
protected void onRestoreInstanceState(Bundle bundle) {
super.onRestoreInstanceState(bundle);
pwd = new File(bundle.getString(PWD));
int i = 0, j = 0;
int i = 0, j = 0, _tp = 0;
List<String> files = bundle.getStringArrayList(FILES);
if (files != null) {
FragmentManager fm = getFragmentManager();
for (String s:bundle.getStringArrayList(FILES)) {
hda.add(s);
Fragment f = fm.findFragmentByTag(s);
EditFragment f = (EditFragment)fm.findFragmentByTag(s);
if (!f.isHidden()) {
j = i;
_tp = f.type;
codeEditor = (TextEditor)f.getView();
}
i++;
Expand All @@ -370,6 +367,7 @@ protected void onRestoreInstanceState(Bundle bundle) {
byhand = false;
ab.setSelectedNavigationItem(j);
byhand = true;
setFileRunnable((_tp & EditFragment.TYPE_HEADER) == 0);
}
}
if (subc != null)
Expand Down Expand Up @@ -422,14 +420,22 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case SETTING:
if (resultCode == RESULT_OK) {
boolean s = "s".equals(Application.completion);
FragmentManager fm = getFragmentManager();
for (int i=getActionBar().getNavigationItemCount() - 1;i >= 0;i--) {
Fragment f = fm.findFragmentByTag(hda.getItem(i));
TextEditor ed = (TextEditor)f.getView();
ed.setFormatter("s".equals(Application.completion) ?(EditFragment)f: null);
ed.setFormatter(s?(EditFragment)f: null);
ed.setAutoComplete("l".equals(Application.completion));
ed.setWordWrap(Application.wordwrap);
ed.setShowNonPrinting(Application.whitespace);
}
if (s) {
if (lsp.isEnded())
lsp.start(this, hand);
} else if (!lsp.isEnded()) {
lsp.end();
}
} else if (resultCode == RESULT_FIRST_USER) {
recreate();
}
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/cn/rbc/termuc/MainHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,14 @@ public void handleMessage(Message msg) {
sb.append(jr.nextString());
jr.close();
ma.lsp.setCompTrigs(sb.toString().toCharArray());
// what == Lsp.INITIALIZE
FragmentManager fm = ma.getFragmentManager();
for (int i=ma.getActionBar().getNavigationItemCount()-1;i>=0;i--) {
EditFragment ef = (EditFragment)fm.findFragmentByTag(ma.getTag(i));
int tp = ef.type;
if (tp != EditFragment.TYPE_OTHER)
ma.lsp.didOpen(ef.getFile(), tp==EditFragment.TYPE_CPP?"cpp":"c", ((TextEditor)ef.getView()).getText().toString());
}
return;
case RNG:
jr.beginObject();
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/java/cn/rbc/termuc/SettingsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ protected void onCreate(Bundle savedInstanceState) {
mPort = (EditTextPreference)findPreference(Application.KEY_LSP_PORT);
findPreference(Application.KEY_CHECKAPP).setOnPreferenceClickListener(this);
findPreference(Application.KEY_INITAPP).setOnPreferenceClickListener(this);
onPreferenceChange(mEngine, mEngine.getValue());

mDark = Application.dark_mode;
mWrap = Application.wordwrap;
Expand Down Expand Up @@ -69,8 +70,6 @@ public boolean onPreferenceChange(Preference p1, Object p2) {
boolean enable = "s".equals(p2);
mHost.setEnabled(enable);
mPort.setEnabled(enable);
if (!enable)
HelperUtils.show(Toast.makeText(this, "敬请期待\nComing soon", Toast.LENGTH_SHORT));
}
return true;
}
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/cn/rbc/termuc/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ public void onClick(DialogInterface d, int p) {
}

public static void initBack(Activity ctx, boolean manually) {
try {
ctx.getPackageManager().getPackageInfo("com.termux", PackageManager.GET_GIDS);
Builder bd = new Builder(ctx);
bd.setTitle(R.string.init_termux);
bd.setMessage(R.string.init_inform);
Expand All @@ -150,6 +152,10 @@ public static void initBack(Activity ctx, boolean manually) {
if (!manually)
bd.setNeutralButton(R.string.initialized, it);
bd.create().show();
} catch (PackageManager.NameNotFoundException nne) {
if (manually)
HelperUtils.show(Toast.makeText(ctx, R.string.no_install, Toast.LENGTH_SHORT));
}
}

public static void copyJump(Context ctx) {
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<string name="textsize">默认字号</string>
<string name="check_app">检测&amp;安装 Termux</string>
<string name="installed">已安装</string>
<string name="no_install">未安装</string>
<string name="install_app">安装 Termux</string>
<string name="confirm_install">未检测到 Termux,是否现在安装?</string>
<string name="no_remind">不再提醒</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<string name="textsize">Default font size</string>
<string name="check_app">Check &amp; install Termux</string>
<string name="installed">Installed</string>
<string name="no_install">Not installed</string>
<string name="install_app">Install Termux</string>
<string name="confirm_install">Termux is not detected. Do you want install it now?</string>
<string name="no_remind">Never remind</string>
Expand Down
Loading

0 comments on commit d36f555

Please sign in to comment.