<span style=
"color: #0000ff;"
>package</span><span style=
"color: #000000;"
> com.android.up;
</span><span style=
"color: #0000ff;"
>import</span><span style=
"color: #000000;"
> java.util.ArrayList;
</span><span style=
"color: #0000ff;"
>import</span><span style=
"color: #000000;"
> java.util.List;
</span><span style=
"color: #0000ff;"
>import</span><span style=
"color: #000000;"
> org.apache.http.HttpResponse;
</span><span style=
"color: #0000ff;"
>import</span><span style=
"color: #000000;"
> org.apache.http.NameValuePair;
</span><span style=
"color: #0000ff;"
>import</span><span style=
"color: #000000;"
> org.apache.http.client.ClientProtocolException;
</span><span style=
"color: #0000ff;"
>import</span><span style=
"color: #000000;"
> org.apache.http.message.BasicNameValuePair;
</span><span style=
"color: #0000ff;"
>import</span><span style=
"color: #000000;"
> org.json.JSONObject;
</span><span style=
"color: #0000ff;"
>import</span><span style=
"color: #000000;"
> com.android.MainActivity;
</span><span style=
"color: #0000ff;"
>import</span><span style=
"color: #000000;"
> com.android.R;
</span><span style=
"color: #0000ff;"
>import</span><span style=
"color: #000000;"
> com.anroid.net.DialogUtil;
</span><span style=
"color: #0000ff;"
>import</span><span style=
"color: #000000;"
> android.app.Activity;
</span><span style=
"color: #0000ff;"
>import</span><span style=
"color: #000000;"
> android.app.ProgressDialog;
</span><span style=
"color: #0000ff;"
>import</span><span style=
"color: #000000;"
> android.content.Intent;
</span><span style=
"color: #0000ff;"
>import</span><span style=
"color: #000000;"
> android.os.AsyncTask;
</span><span style=
"color: #0000ff;"
>import</span><span style=
"color: #000000;"
> android.os.Bundle;
</span><span style=
"color: #0000ff;"
>import</span><span style=
"color: #000000;"
> android.view.View;
</span><span style=
"color: #0000ff;"
>import</span><span style=
"color: #000000;"
> android.view.View.OnClickListener;
</span><span style=
"color: #0000ff;"
>import</span><span style=
"color: #000000;"
> android.widget.Button;
</span><span style=
"color: #0000ff;"
>import</span><span style=
"color: #000000;"
> android.widget.EditText;
</span><span style=
"color: #0000ff;"
>import</span><span style=
"color: #000000;"
> android.widget.TextView;
</span><span style=
"color: #0000ff;"
>
public
</span> <span style=
"color: #0000ff;"
>
class
</span> up <span style=
"color: #0000ff;"
>
extends
</span><span style=
"color: #000000;"
> Activity {
</span><span style=
"color: #008000;"
>
<span style=
"color: #0000ff;"
>
private
</span><span style=
"color: #000000;"
> ProgressDialog pDialog;
</span><span style=
"color: #0000ff;"
>
private
</span><span style=
"color: #000000;"
> TextView tv_head;
JSONParser jsonParser </span>= <span style=
"color: #0000ff;"
>
new
</span><span style=
"color: #000000;"
> JSONParser();
EditText inputName;
EditText inputEmail;
EditText inputDesc;
Button upback;
</span><span style=
"color: #008000;"
>
<span style=
"color: #0000ff;"
>
private
</span> <span style=
"color: #0000ff;"
>
static
</span> String url_up =
"http://10.0.2.2/up/up.php"
;<span style=
"color: #008000;"
><br>
private
static
final
String TAG_MESSAGE =
"message"
;<br></span>
<span style=
"color: #000000;"
> @Override
</span><span style=
"color: #0000ff;"
>
public
</span> <span style=
"color: #0000ff;"
>void</span><span style=
"color: #000000;"
> onCreate(Bundle savedInstanceState) {
</span><span style=
"color: #0000ff;"
>super</span><span style=
"color: #000000;"
>.onCreate(savedInstanceState);
setContentView(R.layout.up);
tv_head </span>=<span style=
"color: #000000;"
> (TextView)findViewById(R.id.tv_head);
tv_head.setText(</span>
"建议"
<span style=
"color: #000000;"
>);
</span><span style=
"color: #008000;"
>
inputName =<span style=
"color: #000000;"
> (EditText) findViewById(R.id.inputName);
inputEmail </span>=<span style=
"color: #000000;"
> (EditText) findViewById(R.id.inputEmail);
inputDesc </span>=<span style=
"color: #000000;"
> (EditText) findViewById(R.id.inputDesc);
upback </span>=<span style=
"color: #000000;"
> (Button)findViewById(R.id.upback);
upback.setOnClickListener(</span><span style=
"color: #0000ff;"
>
new
</span><span style=
"color: #000000;"
> OnClickListener() {
@Override
</span><span style=
"color: #0000ff;"
>
public
</span> <span style=
"color: #0000ff;"
>void</span><span style=
"color: #000000;"
> onClick(View arg0) {
</span><span style=
"color: #008000;"
>
Intent back = <span style=
"color: #0000ff;"
>
new
</span> Intent(up.<span style=
"color: #0000ff;"
>this</span>,MainActivity.<span style=
"color: #0000ff;"
>
class
</span><span style=
"color: #000000;"
>);
back.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(back);
up.</span><span style=
"color: #0000ff;"
>this</span><span style=
"color: #000000;"
>.finish();
}
});
</span><span style=
"color: #008000;"
>
Button btnCreateProduct =<span style=
"color: #000000;"
> (Button) findViewById(R.id.btnCreateProduct);
</span><span style=
"color: #008000;"
>
btnCreateProduct.setOnClickListener(<span style=
"color: #0000ff;"
>
new
</span><span style=
"color: #000000;"
> View.OnClickListener() {
</span><span style=
"color: #0000ff;"
>
public
</span> <span style=
"color: #0000ff;"
>void</span><span style=
"color: #000000;"
> onClick(View view) {
</span><span style=
"color: #008000;"
>
<span style=
"color: #0000ff;"
>
if
</span><span style=
"color: #000000;"
>(validate()){
</span><span style=
"color: #0000ff;"
>
new
</span><span style=
"color: #000000;"
> Up().execute();
}
}
});
}
</span><span style=
"color: #0000ff;"
>
private
</span> <span style=
"color: #0000ff;"
>boolean</span><span style=
"color: #000000;"
> validate()
{
String description </span>=<span style=
"color: #000000;"
> inputDesc.
getText
().toString().trim();
</span><span style=
"color: #0000ff;"
>
if
</span> (description.equals(
""
<span style=
"color: #000000;"
>))
{
DialogUtil.showDialog(</span><span style=
"color: #0000ff;"
>this</span>,
"您还没有填写建议"
, <span style=
"color: #0000ff;"
>false</span><span style=
"color: #000000;"
>);
</span><span style=
"color: #0000ff;"
>
return
</span> <span style=
"color: #0000ff;"
>false</span><span style=
"color: #000000;"
>;
}
</span><span style=
"color: #0000ff;"
>
return
</span> <span style=
"color: #0000ff;"
>true</span><span style=
"color: #000000;"
>;
}
</span><span style=
"color: #008000;"
>
</span>
<span style=
"color: #0000ff;"
>
class
</span> Up <span style=
"color: #0000ff;"
>
extends
</span> AsyncTask<string string><span style=
"color: #000000;"
> {
</span><span style=
"color: #008000;"
>
</span><span style=
"color: #000000;"
>
@Override
</span><span style=
"color: #0000ff;"
>
protected
</span> <span style=
"color: #0000ff;"
>void</span><span style=
"color: #000000;"
> onPreExecute() {
</span><span style=
"color: #0000ff;"
>super</span><span style=
"color: #000000;"
>.onPreExecute();
pDialog </span>= <span style=
"color: #0000ff;"
>
new
</span> ProgressDialog(up.<span style=
"color: #0000ff;"
>this</span><span style=
"color: #000000;"
>);
pDialog.setMessage(</span>
"正在上传.."
<span style=
"color: #000000;"
>);
pDialog.setIndeterminate(</span><span style=
"color: #0000ff;"
>false</span><span style=
"color: #000000;"
>);
pDialog.setCancelable(</span><span style=
"color: #0000ff;"
>true</span><span style=
"color: #000000;"
>);
pDialog.show();
}
</span><span style=
"color: #008000;"
>
</span>
<span style=
"color: #0000ff;"
>
protected
</span><span style=
"color: #000000;"
> String doInBackground(String... args) {
String name </span>=<span style=
"color: #000000;"
> inputName.
getText
().toString();
String email </span>=<span style=
"color: #000000;"
> inputEmail.
getText
().toString();
String description </span>=<span style=
"color: #000000;"
> inputDesc.
getText
().toString();
</span><span style=
"color: #008000;"
>
List<namevaluepair> params = <span style=
"color: #0000ff;"
>
new
</span> ArrayList<namevaluepair><span style=
"color: #000000;"
>();
params.add(</span><span style=
"color: #0000ff;"
>
new
</span> BasicNameValuePair(
"name"
<span style=
"color: #000000;"
>, name));
params.add(</span><span style=
"color: #0000ff;"
>
new
</span> BasicNameValuePair(
"email"
<span style=
"color: #000000;"
>, email));
params.add(</span><span style=
"color: #0000ff;"
>
new
</span> BasicNameValuePair(
"description"
<span style=
"color: #000000;"
>, description));
</span><span style=
"color: #008000;"
>
</span><span style=
"color: #008000;"
>
<span style=
"color: #0000ff;"
>
try
</span><span style=
"color: #000000;"
>{
JSONObject json </span>=<span style=
"color: #000000;"
> jsonParser.makeHttpRequest(url_up,
</span>
"POST"
<span style=
"color: #000000;"
>, params);<br> String message = json.getString(TAG_MESSAGE);<br>
return
message;
}</span><span style=
"color: #0000ff;"
>
catch
</span><span style=
"color: #000000;"
>(Exception e){</span><span style=
"color: #000000;"
>
e.printStackTrace(); <br>
return
""
;
}
</span><span style=
"color: #008000;"
>
<span style=
"color: #000000;"
>
}
</span><span style=
"color: #008000;"
>
</span>
<span style=
"color: #0000ff;"
>
protected
</span> <span style=
"color: #0000ff;"
>void</span><span style=
"color: #000000;"
> onPostExecute(String message) { </span><span style=
"color: #000000;"
>
pDialog.dismiss();<br>
}
}
}</span></namevaluepair></namevaluepair></string>