10
10
import android .view .ViewGroup ;
11
11
import android .widget .Button ;
12
12
import android .widget .EditText ;
13
- import android .widget .TextView ;
14
13
15
14
import com .actionbarsherlock .app .SherlockFragment ;
16
15
17
16
import org .apache .commons .io .IOUtils ;
18
17
import org .opendroidphp .R ;
19
18
import org .opendroidphp .app .AppController ;
20
19
import org .opendroidphp .app .Constants ;
21
- import org .opendroidphp .app .common .utils .ShellOutputFormatter ;
22
20
23
21
import java .io .BufferedReader ;
24
22
import java .io .IOException ;
25
23
import java .io .InputStream ;
26
24
import java .io .InputStreamReader ;
27
25
import java .io .OutputStream ;
28
26
29
- public class SQLShellFragment extends SherlockFragment implements View .OnClickListener {
27
+ public class QueryFragment extends SherlockFragment implements View .OnClickListener {
30
28
31
29
private static InputStream stdout ;
32
30
private static OutputStream stdin ;
33
- private Button mRunCommand ;
34
- private TextView mResult ;
35
- private EditText mCommand ;
31
+ private Button mBtnQuery ;
32
+ private EditText mQuery ;
36
33
private Process process ;
37
34
38
35
@ Override
@@ -41,7 +38,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
41
38
View view = inflater .inflate (R .layout .fragment_mysql , container , false );
42
39
prepareView (view );
43
40
44
- SharedPreferences preferences = PreferenceManager .getDefaultSharedPreferences (getSherlockActivity ());
41
+ SharedPreferences preferences = PreferenceManager .
42
+ getDefaultSharedPreferences (getSherlockActivity ());
45
43
46
44
final String username = preferences .getString ("mysql_username" , "root" );
47
45
final String password = preferences .getString ("mysql_password" , "" );
@@ -52,18 +50,14 @@ public void run() {
52
50
initializeShell (username , password );
53
51
}
54
52
}).start ();
55
-
56
53
new AsyncCommandTask ().execute ();
57
-
58
54
return view ;
59
55
}
60
56
61
57
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 );
67
61
}
68
62
69
63
protected Process initializeShell (final String username , final String password ) {
@@ -80,15 +74,14 @@ protected Process initializeShell(final String username, final String password)
80
74
} catch (IOException e ) {
81
75
e .printStackTrace ();
82
76
AppController .toast (getSherlockActivity (), "Unable to run sql server" );
83
- // process.destroy();
84
77
}
85
78
return process ;
86
79
}
87
80
88
81
@ Override
89
82
public void onClick (View view ) {
90
83
if (stdin == null || process == null ) return ;
91
- String command = mCommand .getText ().toString ();
84
+ String command = mQuery .getText ().toString ();
92
85
try {
93
86
stdin .write ((command + "\r \n " ).getBytes ());
94
87
stdin .flush ();
@@ -97,16 +90,16 @@ public void onClick(View view) {
97
90
}
98
91
}
99
92
93
+
100
94
private class AsyncCommandTask extends AsyncTask <Void , String , Void > {
101
95
@ Override
102
96
protected Void doInBackground (Void ... params ) {
103
97
if (stdout == null || process == null ) return null ;
104
-
105
98
BufferedReader buff = new BufferedReader (
106
99
new InputStreamReader (stdout ));
107
100
try {
108
101
while (true ) {
109
- String stream = ShellOutputFormatter . toHTML ( buff .readLine () );
102
+ String stream = buff .readLine ();
110
103
if (stream == null ) break ;
111
104
publishProgress (stream );
112
105
}
@@ -121,7 +114,7 @@ protected Void doInBackground(Void... params) {
121
114
@ Override
122
115
protected void onProgressUpdate (String ... values ) {
123
116
super .onProgressUpdate (values );
124
- mResult .append (ShellOutputFormatter . toHTML ( values [0 ]) );
117
+ mQuery .append (values [0 ]);
125
118
}
126
119
}
127
120
}
0 commit comments