-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNewProductActivity.java
More file actions
166 lines (129 loc) · 5.32 KB
/
NewProductActivity.java
File metadata and controls
166 lines (129 loc) · 5.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
package com.zamer.zamer;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.zamer.parser.JSONParser;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public class NewProductActivity extends Activity {
private ProgressDialog pDialog;
SessionManager session;
JSONParser jsonParser = new JSONParser();
TextView txtName;
TextView txtPrice;
TextView txtDesc;
TextView txtMan;
EditText txtMetka;
TextView txtFloor;
TextView txtTelz;
TextView txtImena;
TextView txtDen;
EditText txtTim;
EditText txtCompany;
TextView txtOderstates;
EditText txtPaystates;
EditText txtIP;
EditText txtUrl;
Button b;
String mn;
private static String url_create_product = "http://zamer.com.ua/phpapi/api";
private static final String TAG_SUCCESS = "success";
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.add_product);
Intent i = getIntent();
mn = i.getStringExtra("man");
txtName = (EditText) findViewById(R.id.txtName);
txtImena = (EditText) findViewById(R.id.txtImena);
txtDesc = (EditText) findViewById(R.id.txtDesc);
txtTelz = (EditText) findViewById(R.id.txtTelz);
//txtDen = (EditText) findViewById(R.id.txtDen);
//txtTim = (EditText) findViewById(R.id.txtTim);
txtFloor = (EditText) findViewById(R.id.txtFloor);
txtMetka = (EditText) findViewById(R.id.txtMetka);
Button btnCreateProduct = (Button) findViewById(R.id.btnCreateProduct);
btnCreateProduct.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new CreateNewProduct().execute();
}
});
}
/**
* Фоновый Async Task создания нового продукта
**/
class CreateNewProduct extends AsyncTask<String, String, String> {
/**
* Перед согданием в фоновом потоке показываем прогресс диалог
**/
@Override
protected void onPreExecute() {
super.onPreExecute();
pDialog = new ProgressDialog(NewProductActivity.this);
pDialog.setMessage("Создание заявки...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(true);
pDialog.show();
}
/**
* Создание продукта
**/
protected String doInBackground(String... args) {
// получаем обновленные данные с EditTexts
String name = txtName.getText().toString();
//String tim = txtTim.getText().toString();
String description = txtDesc.getText().toString();
String ime= txtImena.getText().toString();
String tel = txtTelz.getText().toString();
String floor = txtFloor.getText().toString();
//String den = txtDen.getText().toString();
String me = txtMetka.getText().toString();
// String mn="slon";
// формируем параметры
List<NameValuePair> params = new ArrayList<NameValuePair>();
//params.add(new BasicNameValuePair(TAG_TIM, tim));
params.add(new BasicNameValuePair("description", description));
params.add(new BasicNameValuePair("ime", ime));
params.add(new BasicNameValuePair("floor", floor));
params.add(new BasicNameValuePair("name", name));
params.add(new BasicNameValuePair("tel", tel));
params.add(new BasicNameValuePair("description", description));
params.add(new BasicNameValuePair("metka", me));
params.add(new BasicNameValuePair("mn", mn));
// получаем JSON объект
JSONObject json = jsonParser.makeHttpRequest(url_create_product, "POST", params);
Log.d("Create Response", json.toString());
try {
int success = json.getInt(TAG_SUCCESS);
if (success == 1) {
// продукт удачно создан
Intent i = new Intent(getApplicationContext(), AllProductsActivity.class);
startActivity(i);
// закрываем это окно
finish();
}
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
/**
* После оконачния скрываем прогресс диалог
**/
protected void onPostExecute(String file_url) {
pDialog.dismiss();
}
}
}