-
Notifications
You must be signed in to change notification settings - Fork 0
/
HomePage.java
executable file
·183 lines (146 loc) · 5.85 KB
/
HomePage.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
package com.example.shalini.stockapp;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.ListView;
import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import LibraryFiles.JSONParser;
public class HomePage extends AppCompatActivity {
/**/private List<LocalStorage> lstStrg = new ArrayList<LocalStorage>();
List<String> responseList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_page);
new JSONParse().execute();
populateListView();
}
public void bindAutoCompView()
{
final AutoCompleteTextView objAutoSymbols = (AutoCompleteTextView) findViewById(R.id.autoTxtVwStockSymbol);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.select_dialog_item, responseList);
objAutoSymbols.setThreshold(1);
objAutoSymbols.setAdapter(adapter);
objAutoSymbols.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick (AdapterView<?> parent, View view, int position, long id) {
String selectedText = (String)parent.getItemAtPosition(position);
selectedText = selectedText.substring(0,selectedText.indexOf("-"));
objAutoSymbols.setText(selectedText);
}
});
}
public void handleButtonClick(View view) {
Button button = (Button) findViewById(R.id.btnGetQuote);
startActivity(new Intent(this, StockDetails.class));
}
/* public class UserItemAdapter extends ArrayAdapter<LocalStorage> {
private ArrayList<LocalStorage> lstStorage;
public UserItemAdapter(Context context, int textViewResourceId, ArrayList<LocalStorage> storage) {
super(context, textViewResourceId, storage);
this.lstStorage = storage;
}
}*/
private void populateListView() {
String[] items = {"red", "blue", "green"};
ListView listView = (ListView) findViewById(R.id.listView);
listView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, items));
/*LocalStorage objStorage = new LocalStorage("yolanda","fdsfsfs");
lstStrg.add(0,objStorage);*/
}
private class JSONParse extends AsyncTask<String, String, JSONObject> {
public JSONParse() {
try {
Class.forName("android.os.AsyncTask");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
@Override
protected void onPreExecute() {
super.onPreExecute();
/* // pDialog.setMessage("Preparing to obtain data...");
pDialog.setIndeterminate(false);
pDialog.setCancelable(false);
pDialog.show();*/
}
@Override
protected JSONObject doInBackground(String... args) {
String url = "http://stockapplication-env.us-west-2.elasticbeanstalk.com/";
JSONParser objParser = new JSONParser();
JSONObject json = null;
try {
HashMap<String, String> params = new HashMap<>();
params.put("compName", "AAPL");
json = objParser.makeHttpRequest(
url, "GET", params);
if (json != null) {
Log.d("JSON result", json.toString());
}
} catch (Exception e) {
e.printStackTrace();
}
return json;
}
@Override
protected void onPostExecute(JSONObject json) {
responseList = new ArrayList<String>();
try {
JSONArray objArray = json.getJSONArray("total");
for(int i=0;i<objArray.length();i++)
{
String s = objArray.getString(i);
responseList.add(s);
}
bindAutoCompView();
} catch (JSONException e) {
e.printStackTrace();
}
// Getting JSON Array\
/*String jsonString = json.toString();
JSONArray jsonArr = null;
try {
jsonArr = new JSONArray(jsonString);
} catch (JSONException e) {
e.printStackTrace();
}
for (int i = 0; i < jsonArr.length(); i++) {
JSONObject objJson = null;
try {
e = jsonArr.getJSONObject(i);
} catch (JSONException e1) {
e1.printStackTrace();
}
String name = null;
try {
name = e.getString("total");
} catch (JSONException e1) {
e1.printStackTrace();
}
responseList.add(name);
}*/
// Storing JSON item in a Variable
}
}
}