Repository navigation
Expand file tree
/
Copy pathResultActivity.java
More file actions
201 lines (160 loc) · 7.18 KB
/
Copy pathResultActivity.java
File metadata and controls
201 lines (160 loc) · 7.18 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
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
package com.example.majisha.ebayshopping;
import android.app.ListActivity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.AsyncTask;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.w3c.dom.Text;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Iterator;
public class ResultActivity extends ActionBarActivity {
private String url_search_php = "http://searchebay-env.elasticbeanstalk.com/my_index.php?";
private JSONObject json = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
TextView t_resultHeader = (TextView) findViewById(R.id.t_resultHeader);
t_resultHeader.setText("Results for '"+getIntent().getStringExtra("SEARCH_KEYWORD")+"'");
try {
json = new JSONObject(getIntent().getStringExtra("JSON_OBJECT"));
Iterator<?> jsonKeys = json.keys();
while(jsonKeys.hasNext()){
String key = (String) jsonKeys.next();
if(json.get(key) instanceof JSONObject){
if(key.toString().startsWith("item") && !key.toString().equals("itemCount")){
JSONObject item = json.getJSONObject(key);
JSONObject basicInfo = item.getJSONObject("basicInfo");
//Setting the title
int textid = getResources().getIdentifier("textView"+key.charAt(4), "id", "com.example.majisha.ebayshopping");
TextView t = (TextView)findViewById(textid);
t.setText(basicInfo.getString("title"));
//Set the image URL
int imgid = getResources().getIdentifier("imageView"+key.charAt(4), "id", "com.example.majisha.ebayshopping");
ImageView imgView = (ImageView)findViewById(imgid);
String imageUrl = basicInfo.getString("galleryURL");
new ImageLoader(imageUrl, imgView).execute();
//Set the pricing details
int priceid = getResources().getIdentifier("priceText"+key.charAt(4),"id","com.example.majisha.ebayshopping");
TextView pText = (TextView) findViewById(priceid);
if (basicInfo.getString("shippingServiceCost").isEmpty() || Float.parseFloat(basicInfo.getString("shippingServiceCost")) == 0.0){
String price_detail = "Price: $"+basicInfo.getString("convertedCurrentPrice")+"(FREE Shipping)";
pText.setText(price_detail);
}
else{
pText.setText("Price: $"+basicInfo.getString("convertedCurrentPrice")+"(+$"+basicInfo.getString("shippingServiceCost")+" for shipping)");
}
}
}
}
} catch (JSONException e) {
e.printStackTrace();
}
}
public void openDetails(View v) throws JSONException{
int id = v.getId();
String ID = "";
String title = "";
String price_shipping = "";
TextView title_text;
TextView price_text;
switch(id){
case R.id.textView0:
ID = "item0";
title_text = (TextView)findViewById(R.id.textView0);
title = title_text.getText().toString();
price_text = (TextView)findViewById(R.id.priceText0);
price_shipping = price_text.getText().toString();
break;
case R.id.textView1:
ID = "item1";
title_text = (TextView)findViewById(R.id.textView1);
title = title_text.getText().toString();
price_text = (TextView)findViewById(R.id.priceText1);
price_shipping = price_text.getText().toString();
break;
case R.id.textView2:
ID = "item2";
title_text = (TextView)findViewById(R.id.textView2);
title = title_text.getText().toString();
price_text = (TextView)findViewById(R.id.priceText2);
price_shipping = price_text.getText().toString();
break;
case R.id.textView3:
ID = "item3";
title_text = (TextView)findViewById(R.id.textView3);
title = title_text.getText().toString();
price_text = (TextView)findViewById(R.id.priceText3);
price_shipping = price_text.getText().toString();
break;
case R.id.textView4:
ID = "item4";
title_text = (TextView)findViewById(R.id.textView4);
title = title_text.getText().toString();
price_text = (TextView)findViewById(R.id.priceText4);
price_shipping = price_text.getText().toString();
break;
}
Intent intent = new Intent(ResultActivity.this, DetailsActivity.class);
intent.putExtra("ITEM_INFO", json.getJSONObject(ID).toString());
intent.putExtra("ITEM_TITLE",title);
intent.putExtra("ITEM_PRICE",price_shipping);
startActivity(intent);
}
public void openWebPage(View v) throws JSONException {
int id = v.getId();
String ID = "";
switch (id){
case R.id.imageView0:
ID = "item0";
break;
case R.id.imageView1:
ID = "item1";
break;
case R.id.imageView2:
ID = "item2";
break;
case R.id.imageView3:
ID = "item3";
break;
case R.id.imageView4:
ID = "item4";
break;
}
String url = json.getJSONObject(ID).getJSONObject("basicInfo").getString("viewItemURL");
Intent viewIntent = new Intent("android.intent.action.VIEW", Uri.parse(url));
startActivity(viewIntent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_result, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}