Skip to content
Snippets Groups Projects
Commit af05ddc2 authored by Francesco Andreuzzi's avatar Francesco Andreuzzi
Browse files

5.3e

parent 359267bc
Branches
Tags
No related merge requests found
...@@ -15,6 +15,7 @@ import ohi.andre.consolelauncher.commands.CommandTuils; ...@@ -15,6 +15,7 @@ import ohi.andre.consolelauncher.commands.CommandTuils;
import ohi.andre.consolelauncher.commands.specific.ParamCommand; import ohi.andre.consolelauncher.commands.specific.ParamCommand;
import ohi.andre.consolelauncher.commands.specific.PermanentSuggestionCommand; import ohi.andre.consolelauncher.commands.specific.PermanentSuggestionCommand;
import ohi.andre.consolelauncher.commands.main.MainPack; import ohi.andre.consolelauncher.commands.main.MainPack;
import ohi.andre.consolelauncher.managers.AliasManager;
import ohi.andre.consolelauncher.managers.AppsManager; import ohi.andre.consolelauncher.managers.AppsManager;
import ohi.andre.consolelauncher.managers.ContactManager; import ohi.andre.consolelauncher.managers.ContactManager;
import ohi.andre.consolelauncher.managers.FileManager; import ohi.andre.consolelauncher.managers.FileManager;
...@@ -67,11 +68,13 @@ public class SuggestionsManager { ...@@ -67,11 +68,13 @@ public class SuggestionsManager {
float rate = 1f / shift; float rate = 1f / shift;
suggestionList.add(new Suggestion(before, apps[count], true, (int) Math.ceil(rate), Suggestion.TYPE_APP)); suggestionList.add(new Suggestion(before, apps[count], true, (int) Math.ceil(rate), Suggestion.TYPE_APP));
} }
}
suggestAlias(info.aliasManager, suggestionList, lastWord);
return suggestionList.toArray(new Suggestion[suggestionList.size()]); return suggestionList.toArray(new Suggestion[suggestionList.size()]);
} }
} // lastword == 0 && before > 0
// lastword = 0 && before > 0
else { else {
// check if this is a command // check if this is a command
Command cmd = null; Command cmd = null;
...@@ -98,7 +101,7 @@ public class SuggestionsManager { ...@@ -98,7 +101,7 @@ public class SuggestionsManager {
// suggestArgs(info, cmd.cmd instanceof ParamCommand ? ((ParamCommand) cmd.cmd).argsForParam((String) cmd.mArgs[0])[cmd.nArgs - 1] : cmd.cmd.argType()[cmd.nArgs], suggestionList, lastWord, before); // suggestArgs(info, cmd.cmd instanceof ParamCommand ? ((ParamCommand) cmd.cmd).argsForParam((String) cmd.mArgs[0])[cmd.nArgs - 1] : cmd.cmd.argType()[cmd.nArgs], suggestionList, lastWord, before);
// } // }
if(cmd.cmd instanceof ParamCommand && (cmd.mArgs == null || cmd.mArgs.length == 0)) suggestParams(suggestionList, (ParamCommand) cmd.cmd, before); if(cmd.cmd instanceof ParamCommand && (cmd.mArgs == null || cmd.mArgs.length == 0)) suggestParams(suggestionList, (ParamCommand) cmd.cmd, before, null);
else suggestArgs(info, cmd.nextArg(), suggestionList, before); else suggestArgs(info, cmd.nextArg(), suggestionList, before);
} else { } else {
...@@ -129,7 +132,9 @@ public class SuggestionsManager { ...@@ -129,7 +132,9 @@ public class SuggestionsManager {
lastWord = before.substring(index) + lastWord; lastWord = before.substring(index) + lastWord;
} }
suggestArgs(info, cmd.nextArg(), suggestionList, lastWord, before); if(cmd.cmd instanceof ParamCommand && (cmd.mArgs == null || cmd.mArgs.length == 0)) {
suggestParams(suggestionList, (ParamCommand) cmd.cmd, before, lastWord);
} else suggestArgs(info, cmd.nextArg(), suggestionList, lastWord, before);
} else { } else {
// not a command // not a command
// ==> app // ==> app
...@@ -138,6 +143,7 @@ public class SuggestionsManager { ...@@ -138,6 +143,7 @@ public class SuggestionsManager {
} else { } else {
// lastword > 0 && before = 0 // lastword > 0 && before = 0
suggestCommand(info, suggestionList, lastWord); suggestCommand(info, suggestionList, lastWord);
suggestAlias(info.aliasManager, suggestionList, lastWord);
suggestApp(info, suggestionList, lastWord, Tuils.EMPTYSTRING); suggestApp(info, suggestionList, lastWord, Tuils.EMPTYSTRING);
} }
} }
...@@ -154,16 +160,20 @@ public class SuggestionsManager { ...@@ -154,16 +160,20 @@ public class SuggestionsManager {
} }
} }
private void suggestParams(List<Suggestion> suggestions, ParamCommand cmd, String before) { private void suggestAlias(AliasManager aliasManager, List<Suggestion> suggestions, String lastWord) {
if(lastWord.length() == 0) for(String s : aliasManager.getAliases()) suggestions.add(new Suggestion(Tuils.EMPTYSTRING, s, true, NO_RATE, Suggestion.TYPE_ALIAS));
else for(String s : aliasManager.getAliases()) if(s.startsWith(lastWord)) suggestions.add(new Suggestion(Tuils.EMPTYSTRING, s, true, NO_RATE, Suggestion.TYPE_ALIAS));
}
private void suggestParams(List<Suggestion> suggestions, ParamCommand cmd, String before, String lastWord) {
String[] params = cmd.params(); String[] params = cmd.params();
if (params == null) { if (params == null) {
return; return;
} }
boolean exec = false; boolean exec = false;
for (String s : cmd.params()) { if(lastWord == null || lastWord.length() == 0) for (String s : cmd.params()) suggestions.add(new Suggestion(before, s, exec, NO_RATE, 0));
suggestions.add(new Suggestion(before, s, exec, NO_RATE, 0)); else for (String s : cmd.params()) if (s.startsWith(lastWord)) suggestions.add(new Suggestion(before, s, exec, NO_RATE, 0));
}
} }
private void suggestArgs(MainPack info, int type, List<Suggestion> suggestions, String prev, String before) { private void suggestArgs(MainPack info, int type, List<Suggestion> suggestions, String prev, String before) {
...@@ -198,6 +208,7 @@ public class SuggestionsManager { ...@@ -198,6 +208,7 @@ public class SuggestionsManager {
break; break;
case CommandAbstraction.CONFIG_FILE: case CommandAbstraction.CONFIG_FILE:
suggestConfigFile(suggestions, prev, before); suggestConfigFile(suggestions, prev, before);
break;
} }
} }
...@@ -453,7 +464,6 @@ public class SuggestionsManager { ...@@ -453,7 +464,6 @@ public class SuggestionsManager {
xmlPrefsFiles.add(AppsManager.PATH); xmlPrefsFiles.add(AppsManager.PATH);
xmlPrefsFiles.add(NotificationManager.PATH); xmlPrefsFiles.add(NotificationManager.PATH);
} }
Log.e("andre", xmlPrefsFiles.toString());
if(prev == null || prev.length() == 0) { if(prev == null || prev.length() == 0) {
for(String s : xmlPrefsFiles) { for(String s : xmlPrefsFiles) {
......
...@@ -6,6 +6,7 @@ import java.io.BufferedReader; ...@@ -6,6 +6,7 @@ import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.InterruptedIOException;
import ohi.andre.consolelauncher.tuils.interfaces.Outputable; import ohi.andre.consolelauncher.tuils.interfaces.Outputable;
...@@ -63,43 +64,20 @@ public class ShellUtils { ...@@ -63,43 +64,20 @@ public class ShellUtils {
// return new CommandResult(0, e.toString()); // return new CommandResult(0, e.toString());
// } // }
if(cmds.length > 1) return null; if(cmds.length > 1 || cmds.length == 0) return null;
int result = -1; int result = -1;
if (cmds == null || cmds.length == 0) {
return null;
}
BufferedReader errorResult = null; BufferedReader errorResult = null;
StringBuilder errorMsg = null; StringBuilder errorMsg = null;
final StringBuilder output = new StringBuilder(); final StringBuilder output = new StringBuilder();
// DataOutputStream os = null;
try { try {
// process = Runtime.getRuntime().exec(root ? "su" : "sh");
// os = new DataOutputStream(process.getOutputStream());
//
// if (path != null) {
// String cdCommand = "cd " + path;
// os.write(cdCommand.getBytes());
// os.writeBytes(Tuils.NEWLINE);
// os.flush();
// }
// for (String command : cmds) {
// if (command == null) {
// continue;
// }
//
// os.write(command.getBytes());
// os.writeBytes(Tuils.NEWLINE);
// }
// os.flush();
final Process process = Runtime.getRuntime().exec((root ? "su -c " : "") + cmds[0], null, path != null ? new File(path) : null); final Process process = Runtime.getRuntime().exec((root ? "su -c " : "") + cmds[0], null, path != null ? new File(path) : null);
final Thread externalThread = Thread.currentThread(); final Thread externalThread = Thread.currentThread();
Thread thread = new StoppableThread() { Thread readerThread = new StoppableThread() {
@Override @Override
public void run() { public void run() {
...@@ -111,43 +89,39 @@ public class ShellUtils { ...@@ -111,43 +89,39 @@ public class ShellUtils {
String s; String s;
try { try {
while ((s = successResult.readLine()) != null) { while ((s = successResult.readLine()) != null) {
if(Thread.currentThread().isInterrupted() || externalThread.isInterrupted()) return; if (Thread.currentThread().isInterrupted() || externalThread.isInterrupted())
return;
if (outputable != null) outputable.onOutput(Tuils.NEWLINE + s); if (outputable != null) outputable.onOutput(Tuils.NEWLINE + s);
else {
output.append(Tuils.NEWLINE); output.append(Tuils.NEWLINE);
output.append(s); output.append(s);
} }
} catch (IOException e) {
Log.e("andre", "", e);
} }
sleep(25);
} catch (StackOverflowError | Exception e) {
if(outputable != null && ! (e instanceof InterruptedException)) outputable.onOutput(e.toString());
try { try {
sleep(50); successResult.close();
} catch (InterruptedException e) { } catch (IOException e1) {}
Log.e("andre", "", e);
return; return;
} }
run();
} }
}; };
thread.start(); readerThread.start();
result = process.waitFor(); result = process.waitFor();
thread.interrupt(); readerThread.interrupt();
if(output.length() == 0) { if(output.length() == 0) {
errorMsg = new StringBuilder(); errorMsg = new StringBuilder();
// successResult = new BufferedReader(new InputStreamReader(process.getInputStream()));
errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream())); errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream()));
String s; String s;
// while ((s = successResult.readLine()) != null) {
// successMsg.append(Tuils.NEWLINE);
// successMsg.append(s);
// }
while ((s = errorResult.readLine()) != null) { while ((s = errorResult.readLine()) != null) {
if(errorMsg.length() > 0) errorMsg.append(Tuils.NEWLINE); if(errorMsg.length() > 0) errorMsg.append(Tuils.NEWLINE);
errorMsg.append(s); errorMsg.append(s);
...@@ -159,18 +133,10 @@ public class ShellUtils { ...@@ -159,18 +133,10 @@ public class ShellUtils {
catch (Exception e) {} catch (Exception e) {}
finally { finally {
try { try {
// if (os != null) {
// os.close();
// }
// if (successResult != null) {
// successResult.close();
// }
if (errorResult != null) { if (errorResult != null) {
errorResult.close(); errorResult.close();
} }
} catch (IOException e) { } catch (IOException e) {}
Log.e("andre", "", e);
}
} }
if(output.length() > 0) { if(output.length() > 0) {
......
package ohi.andre.consolelauncher.tuils; package ohi.andre.consolelauncher.tuils;
import android.util.Log;
/** /**
* Created by francescoandreuzzi on 27/04/2017. * Created by francescoandreuzzi on 27/04/2017.
*/ */
...@@ -12,11 +14,17 @@ public class StoppableThread extends Thread { ...@@ -12,11 +14,17 @@ public class StoppableThread extends Thread {
public void interrupt() { public void interrupt() {
super.interrupt(); super.interrupt();
synchronized (this) {
stopped = true; stopped = true;
} }
}
@Override @Override
public boolean isInterrupted() { public boolean isInterrupted() {
return stopped || super.isInterrupted(); boolean b;
synchronized (this) {
b = stopped;
}
return b || super.isInterrupted();
} }
} }
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
<!-- busy --> <!-- busy -->
<string name="busy">T-UI is busy, wait until the execution finishes or use the command \"ctrlc\"</string> <string name="busy">T-UI is busy, wait until the execution finishes or use the command \"ctrlc\"</string>
<string name="busy_hint">type "ctrlc" to stop</string> <string name="busy_hint">type \"ctrlc\" to stop</string>
<string name="rate_donate_text">\nDo you like my work? Rate on Play Store (command: >>rate) or offer me a coffee (command: >>donate). Thank you for using T-UI.\n\nYou can disable this message in >>tuisettings</string> <string name="rate_donate_text">\nDo you like my work? Rate on Play Store (command: >>rate) or offer me a coffee (command: >>donate). Thank you for using T-UI.\n\nYou can disable this message in >>tuisettings</string>
...@@ -39,6 +39,8 @@ ...@@ -39,6 +39,8 @@
<string name="output_problemcamera">There was a problem while connecting to your device camera</string> <string name="output_problemcamera">There was a problem while connecting to your device camera</string>
<string name="output_numberformat">Wrong number format</string> <string name="output_numberformat">Wrong number format</string>
<string name="output_invalidarg">Invalid argument</string> <string name="output_invalidarg">Invalid argument</string>
<string name="output_lessarg">Less arguments than expected</string>
<string name="output_aliasnotfound">Alias not found:</string>
<!-- tuixt --> <!-- tuixt -->
<string name="help_tuixt_help">Print the list of commands, or info about a command <string name="help_tuixt_help">Print the list of commands, or info about a command
...@@ -116,8 +118,15 @@ ...@@ -116,8 +118,15 @@
<string name="help_airplane">Toggle Airplane Mode</string> <string name="help_airplane">Toggle Airplane Mode</string>
<string name="help_aliases">Print alias that are currently saved in \"sdcard\"/t-ui/alias.txt</string> <string name="help_aliases">Manager your aliases
<string name="help_aliasfile">Open alias.txt</string> \n\nUsage:
\n-add -> add a new alias
\n-rm -> remove an existing alias
\n-ls -> list your aliases
\n-file -> open alias.xml
\n\nExample:
\n>>alias -add bip echo beeeeeep
\n>>alias -rm bip</string>
<string name="help_apps">Manage your apps <string name="help_apps">Manage your apps
\n\nUsage: \n\nUsage:
\n>>apps [option] [app name] \n>>apps [option] [app name]
...@@ -127,20 +136,11 @@ ...@@ -127,20 +136,11 @@
\n-ps -> show Google Play Store page for this app \n-ps -> show Google Play Store page for this app
\n-st -> show Settings details for this app \n-st -> show Settings details for this app
\n-frc -> force t-ui to open this app \n-frc -> force t-ui to open this app
\n-file -> open apps.xml
\nno option -> list your apps \nno option -> list your apps
\n\nExample: \n\nExample:
\n>>apps -st T-UI \n>>apps -st T-UI
</string> </string>
<string name="help_appshide">Hide an app
\n\nUsage:
\n>>apps_hide [app]
\n\nExample:
\n>>apps_hide Settings</string>
<string name="help_appsunhide">Unhide an hidden app
\n\nUsage:
\n>>apps_unhide [app]
\n\nExample:
\n>>apps_unhide Settings</string>
<string name="help_bluetooth">Toggle Bluetooth</string> <string name="help_bluetooth">Toggle Bluetooth</string>
<string name="help_clear">Clear the screen</string> <string name="help_clear">Clear the screen</string>
<string name="help_calc" formatted="false">Perform basic operations (+ - * / % ^ sqrt) <string name="help_calc" formatted="false">Perform basic operations (+ - * / % ^ sqrt)
...@@ -262,6 +262,7 @@ ...@@ -262,6 +262,7 @@
\n\n-inc -> include an application \n\n-inc -> include an application
\n-exc -> exclude an appliation \n-exc -> exclude an appliation
\n-clr -> set the color to be used for the application \n-clr -> set the color to be used for the application
\n-file -> open notifications.xml
\n\nExample: \n\nExample:
\n\nnotifications -inc Clock \n\nnotifications -inc Clock
\nnotifications -clr Settings #FF0000</string> \nnotifications -clr Settings #FF0000</string>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment