Skip to content

Commit d12a8c9

Browse files
author
Shushant
committed
Improved Mysql shell UI
1 parent 0538955 commit d12a8c9

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

Diff for: src/org/opendroidphp/app/ui/SQLShellFragment.java renamed to src/org/opendroidphp/app/ui/QueryFragment.java

+12-19
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,26 @@
1010
import android.view.ViewGroup;
1111
import android.widget.Button;
1212
import android.widget.EditText;
13-
import android.widget.TextView;
1413

1514
import com.actionbarsherlock.app.SherlockFragment;
1615

1716
import org.apache.commons.io.IOUtils;
1817
import org.opendroidphp.R;
1918
import org.opendroidphp.app.AppController;
2019
import org.opendroidphp.app.Constants;
21-
import org.opendroidphp.app.common.utils.ShellOutputFormatter;
2220

2321
import java.io.BufferedReader;
2422
import java.io.IOException;
2523
import java.io.InputStream;
2624
import java.io.InputStreamReader;
2725
import java.io.OutputStream;
2826

29-
public class SQLShellFragment extends SherlockFragment implements View.OnClickListener {
27+
public class QueryFragment extends SherlockFragment implements View.OnClickListener {
3028

3129
private static InputStream stdout;
3230
private static OutputStream stdin;
33-
private Button mRunCommand;
34-
private TextView mResult;
35-
private EditText mCommand;
31+
private Button mBtnQuery;
32+
private EditText mQuery;
3633
private Process process;
3734

3835
@Override
@@ -41,7 +38,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
4138
View view = inflater.inflate(R.layout.fragment_mysql, container, false);
4239
prepareView(view);
4340

44-
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getSherlockActivity());
41+
SharedPreferences preferences = PreferenceManager.
42+
getDefaultSharedPreferences(getSherlockActivity());
4543

4644
final String username = preferences.getString("mysql_username", "root");
4745
final String password = preferences.getString("mysql_password", "");
@@ -52,18 +50,14 @@ public void run() {
5250
initializeShell(username, password);
5351
}
5452
}).start();
55-
5653
new AsyncCommandTask().execute();
57-
5854
return view;
5955
}
6056

6157
protected void prepareView(View view) {
62-
mRunCommand = (Button) view.findViewById(R.id.run_cmd);
63-
mResult = (TextView) view.findViewById(R.id.shell_result);
64-
mCommand = (EditText) view.findViewById(R.id.command);
65-
66-
mRunCommand.setOnClickListener(this);
58+
mQuery = (EditText) view.findViewById(R.id.create_mysql_query);
59+
mBtnQuery = (Button) view.findViewById(R.id.btn_execute_query);
60+
mBtnQuery.setOnClickListener(this);
6761
}
6862

6963
protected Process initializeShell(final String username, final String password) {
@@ -80,15 +74,14 @@ protected Process initializeShell(final String username, final String password)
8074
} catch (IOException e) {
8175
e.printStackTrace();
8276
AppController.toast(getSherlockActivity(), "Unable to run sql server");
83-
// process.destroy();
8477
}
8578
return process;
8679
}
8780

8881
@Override
8982
public void onClick(View view) {
9083
if (stdin == null || process == null) return;
91-
String command = mCommand.getText().toString();
84+
String command = mQuery.getText().toString();
9285
try {
9386
stdin.write((command + "\r\n").getBytes());
9487
stdin.flush();
@@ -97,16 +90,16 @@ public void onClick(View view) {
9790
}
9891
}
9992

93+
10094
private class AsyncCommandTask extends AsyncTask<Void, String, Void> {
10195
@Override
10296
protected Void doInBackground(Void... params) {
10397
if (stdout == null || process == null) return null;
104-
10598
BufferedReader buff = new BufferedReader(
10699
new InputStreamReader(stdout));
107100
try {
108101
while (true) {
109-
String stream = ShellOutputFormatter.toHTML(buff.readLine());
102+
String stream = buff.readLine();
110103
if (stream == null) break;
111104
publishProgress(stream);
112105
}
@@ -121,7 +114,7 @@ protected Void doInBackground(Void... params) {
121114
@Override
122115
protected void onProgressUpdate(String... values) {
123116
super.onProgressUpdate(values);
124-
mResult.append(ShellOutputFormatter.toHTML(values[0]));
117+
mQuery.append(values[0]);
125118
}
126119
}
127120
}

0 commit comments

Comments
 (0)