forked from pu20720/2019
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDynamicList.java
357 lines (278 loc) · 9.17 KB
/
DynamicList.java
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
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
package andbas.Ch11TabHost2;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import org.xml.sax.InputSource;
import org.xml.sax.XMLReader;
import com.xml.LoginXMLHandler;
import com.xml.LoginXMLStruct;
import com.xml.MessageHandler;
import com.xml.MessageHandler2;
import com.xml.MessageStruct;
import com.xml.MessageStruct2;
import com.xml.UserGroupHandler;
import com.xml.UserGroupStruct;
import andbas.Ch11TabHost2.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.os.StrictMode;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;
import android.widget.SimpleAdapter.ViewBinder;
import android.widget.TextView;
public class DynamicList extends Activity
{
TextView textView1;
TextView textView2;
ListView lv;
ImageView iv;
String title, context= "", img, pnum, article_id, phone;
int type;
String IPAddress="";
Button account, chatroom, attend, saleinfo;
private ArrayList<UserGroupStruct> query_data= new ArrayList<UserGroupStruct>();
LoginXMLStruct data;
String user;
int private_recieve_type;
int cop = 0;
private ArrayList<MessageStruct2> mydata;
String address;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.dynamiclist);
IPAddress = (String) this.getResources().getText(R.string.url);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
user = telephonyManager.getDeviceId();
Bundle bData = this.getIntent().getExtras();
title = bData.getString( "title" );
context = bData.getString( "content" );
img = bData.getString( "img" );
pnum = bData.getString( "pnum" );
article_id = bData.getString( "article_id" );
phone = bData.getString( "phone" );
address = bData.getString( "address" );
buildViews(); //user define
}
private void buildViews()
{
int idx1, idx2, idx3;
textView1 = (TextView)findViewById(R.id.textView1);
textView2 = (TextView)findViewById(R.id.textView2);
iv = (ImageView)findViewById(R.id.imageView1);
//account = (Button) findViewById(R.id.button2);
chatroom = (Button) findViewById(R.id.button1);
attend = (Button) findViewById(R.id.button3);
saleinfo = (Button) findViewById(R.id.button2);
textView1.setText(title);
//Log.i("TAG", context);
idx1 = 0;
textView2.setText(context);
//textView3.setText(context.substring((context.length()/3) + 1, 2 * (context.length()/3)));
//textView4.setText(context.substring((2 * (context.length()/3) + 1), context.length()));
//String imgs[] = img.split(",");
//for (int i=0; i<imgs.length; i++)
{
String str = IPAddress + "upload/" + img;
Log.i("TAG", str);
try {
URL url = new URL(str);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inSampleSize = 2;
Bitmap myBitmap = BitmapFactory.decodeStream(input, null, opts);
iv.setImageBitmap(myBitmap);
} catch (Exception e) {
e.printStackTrace();
}
}
chatroom.setEnabled(false);
reload();
chatroom.setOnClickListener(listener);
attend.setOnClickListener(listener);
saleinfo.setOnClickListener(listener);
}
private Button.OnClickListener listener = new Button.OnClickListener(){
@Override
public void onClick(View v) {
switch(v.getId()){
case R.id.button2:
//phone22
Uri gmmIntentUri = Uri.parse("geo:0,0?q=" + address);
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);
break;
case R.id.button1:
Intent app = new Intent(DynamicList.this, DiscussList.class);
Bundle rdata = new Bundle();
rdata.putString("title", title);
rdata.putString("pnum", pnum);
rdata.putString("article_id", article_id);
app.putExtras(rdata);
startActivity(app);
break;
case R.id.button3:
senddata();
break;
}
}
};
void reload()
{
int attend_num;
getusergroup();
attend_num = query_data.size();
if (attend_num == 0) attend_num = 1;
//textView3.setText("" + attend_num + "/" + pnum);
}
void getusergroup()
{
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
String uriAPI ="";
try
{
//String s = URLEncoder.encode(k, "utf-8");
uriAPI = IPAddress + "getgroupuser.php?aid=" + article_id;
Log.i("TAG", uriAPI);
}
catch (Exception e)
{
e.printStackTrace();
}
Log.i("TAG", uriAPI);
URL url = null;
try{
url = new URL(uriAPI);
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
//Using login handler for xml
UserGroupHandler myHandler = new UserGroupHandler();
xr.setContentHandler(myHandler);
//open connection
xr.parse(new InputSource(url.openStream()));
//verify OK
query_data = myHandler.getContainer().getListItems();
}
catch (Exception e)
{
e.printStackTrace();
}
for (int i = 0; i<query_data.size(); i++)
{
if (query_data.get(i).user.equals(user))
{
attend.setEnabled(false);
chatroom.setEnabled(true);
break;
}
}
}
void senddata()
{
try
{
String uriAPI = IPAddress + "sendattendgroup.php?aid=" + article_id + "&user=" + user;
Log.i("TAG", uriAPI);
URL url = null;
try{
url = new URL(uriAPI);
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
//Using login handler for xml
LoginXMLHandler myHandler = new LoginXMLHandler();
xr.setContentHandler(myHandler);
//open connection
xr.parse(new InputSource(url.openStream()));
//verify OK
data = myHandler.getParsedData();
}
catch(Exception e){
e.printStackTrace();
return;
}
}
catch (Exception e)
{
e.printStackTrace();
}
reload();
}
public void openOptionsDialog(String title, String info)
{
new AlertDialog.Builder(this)
.setTitle(title)
.setMessage(info)
.setPositiveButton("OK",
new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialoginterface, int i)
{
}
}
)
.show();
}
public int toweb(String uriAPI) {
int error = 0;
HttpGet httpRequest = new HttpGet(uriAPI);
try {
HttpResponse httpResponse = new DefaultHttpClient()
.execute(httpRequest);
if (httpResponse.getStatusLine().getStatusCode() == 200) {
String strResult = EntityUtils.toString(httpResponse
.getEntity());
} else {
// mTextView1.setText("Error Response: "+httpResponse.getStatusLine().toString());
}
} catch (ClientProtocolException e) {
// mTextView1.setText(e.getMessage().toString());
e.printStackTrace();
error = 1;
} catch (IOException e) {
// mTextView1.setText(e.getMessage().toString());
e.printStackTrace();
error = 1;
} catch (Exception e) {
// mTextView1.setText(e.getMessage().toString());
e.printStackTrace();
error = 1;
}
return error;
}
}