Advertisement
Guest User

Untitled

a guest
Mar 20th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.92 KB | None | 0 0
  1. package com.tuber.tuber;
  2.  
  3. import android.annotation.TargetApi;
  4. import android.content.Context;
  5. import android.content.Intent;
  6. import android.os.Build;
  7. import android.os.Bundle;
  8. import android.support.design.widget.FloatingActionButton;
  9. import android.support.design.widget.Snackbar;
  10. import android.support.v7.app.AppCompatActivity;
  11. import android.support.v7.widget.Toolbar;
  12. import android.view.View;
  13. import android.widget.Button;
  14. import android.view.View;
  15. import android.view.Menu;
  16. import android.view.MenuItem;
  17. import android.widget.ListView;
  18. import java.util.ArrayList;
  19. import java.util.GregorianCalendar;
  20. import java.util.List;
  21.  
  22. import android.widget.TextView;
  23. import android.widget.Toast;
  24.  
  25.  
  26. import android.animation.Animator;
  27. import android.animation.AnimatorListenerAdapter;
  28. import android.annotation.TargetApi;
  29. import android.content.Intent;
  30. import android.content.pm.PackageManager;
  31. import android.support.annotation.NonNull;
  32. import android.support.design.widget.Snackbar;
  33. import android.support.v7.app.AppCompatActivity;
  34. import android.app.LoaderManager.LoaderCallbacks;
  35. import android.util.Log;
  36. import android.widget.Toast;
  37. import android.content.CursorLoader;
  38. import android.content.Loader;
  39. import android.database.Cursor;
  40. import android.net.Uri;
  41. import android.os.AsyncTask;
  42.  
  43. import com.android.volley.AuthFailureError;
  44. import com.android.volley.Cache;
  45. import com.android.volley.Request;
  46. import com.android.volley.RequestQueue;
  47. import com.android.volley.Response;
  48. import com.android.volley.VolleyError;
  49. import com.android.volley.toolbox.JsonArrayRequest;
  50. import com.android.volley.toolbox.JsonObjectRequest;
  51. import com.android.volley.toolbox.StringRequest;
  52. import com.android.volley.toolbox.Volley;
  53. import com.google.gson.JsonArray;
  54.  
  55. import android.os.Build;
  56. import android.os.Bundle;
  57. import android.provider.ContactsContract;
  58. import android.text.TextUtils;
  59. import android.view.KeyEvent;
  60. import android.view.View;
  61. import android.view.View.OnClickListener;
  62. import android.view.inputmethod.EditorInfo;
  63. import android.widget.ArrayAdapter;
  64. import android.widget.AutoCompleteTextView;
  65. import android.widget.Button;
  66. import android.widget.EditText;
  67. import android.widget.TextView;
  68.  
  69. import java.util.ArrayList;
  70. import java.util.List;
  71.  
  72. import android.*;
  73.  
  74. import org.json.JSONArray;
  75. import org.json.JSONException;
  76. import org.json.JSONObject;
  77.  
  78. import java.util.Collection;
  79. import java.util.HashMap;
  80. import java.util.Map;
  81. import java.util.Set;
  82.  
  83.  
  84. public class MainActivity extends AppCompatActivity {
  85.  
  86. private Button find_tutor_button;
  87. private String token;
  88. private String username;
  89.  
  90. private List<Entry> entries = new ArrayList<Entry>();
  91.  
  92.  
  93. @Override
  94. protected void onCreate(Bundle savedInstanceState) {
  95. super.onCreate(savedInstanceState);
  96. setContentView(R.layout.content_main);
  97.  
  98. Toolbar myToolbar = (Toolbar) findViewById(R.id.my_toolbar);
  99. setSupportActionBar(myToolbar);
  100.  
  101. token = getIntent().getStringExtra("token");
  102. username = getIntent().getStringExtra("username");
  103.  
  104. final ListView EntryListView = (ListView) findViewById(R.id.list);
  105. final EntryAdapter EntryAdapter = new EntryAdapter(this, R.layout.list_item);
  106. EntryListView.setAdapter(EntryAdapter);
  107.  
  108. // Populate the list, through the adapter
  109. for(final Entry entry : getEntries()) {
  110. EntryAdapter.add(entry);
  111. }
  112.  
  113. }
  114.  
  115. private List<Entry> getEntries() {
  116.  
  117. // Let's setup some test data.
  118. // Normally this would come from some asynchronous fetch into a data source
  119. // such as a sqlite database, or an HTTP request
  120. // Creates the Volley request queue
  121. RequestQueue requestQueue = Volley.newRequestQueue(this);
  122.  
  123.  
  124. // Creating the JsonArrayRequest class called arrayreq, passing the required parameters
  125. //JsonURL is the URL to be fetched from
  126. JsonArrayRequest arrayreq = new JsonArrayRequest("https://cs.utm.utoronto.ca/~csc301app0/index.php/listings",
  127. // The second parameter Listener overrides the method onResponse() and passes
  128. //JSONArray as a parameter
  129. new Response.Listener<JSONArray>() {
  130.  
  131. // Takes the response from the JSON request
  132. @Override
  133. public void onResponse(JSONArray response) {
  134. try {
  135. // Retrieves first JSON object in outer array
  136. JSONObject listing = new JSONObject();
  137.  
  138. for(int i = 0; i < response.length(); i++) {
  139. Log.i("JsonObject: ", response.getJSONObject(i).toString());
  140. listing = response.getJSONObject(i);
  141.  
  142. entries.add(
  143. new Entry(
  144. (String) listing.get("firstname"),
  145. "5/5",
  146. (String)listing.get("location"),
  147. R.drawable.arjun
  148. )
  149. );
  150. }
  151.  
  152.  
  153. }
  154. // Try and catch are included to handle any errors due to JSON
  155. catch (JSONException e) {
  156. // If an error occurs, this prints the error to the log
  157. e.printStackTrace();
  158. }
  159. }
  160. },
  161. // The final parameter overrides the method onErrorResponse() and passes VolleyError
  162. //as a parameter
  163. new Response.ErrorListener() {
  164. @Override
  165. // Handles errors that occur due to Volley
  166. public void onErrorResponse(VolleyError error) {
  167. Log.e("Volley", "Error");
  168. }
  169. }
  170. );
  171.  
  172. requestQueue.add(arrayreq);
  173.  
  174. return entries;
  175. }
  176.  
  177. /*
  178. query = something like "CSC3**" or "CSC384" or "CSC***".
  179. Should change the list contents to only tutors who are down to tutor that subject
  180. - to change, need to clear
  181. - then (like in getEntries) create entries
  182. - then add all these entries
  183. */
  184. public void doSearch(String query){
  185.  
  186. }
  187.  
  188. @Override
  189. public boolean onCreateOptionsMenu(Menu menu) {
  190. // Inflate the menu; this adds items to the action bar if it is present.
  191. getMenuInflater().inflate(R.menu.menu_main, menu);
  192. return true;
  193. }
  194.  
  195. @Override
  196. public boolean onOptionsItemSelected(MenuItem item) {
  197. switch (item.getItemId()) {
  198. case R.id.profile:
  199. // User chose the "Settings" item, show the app settings UI...
  200. Intent intent = new Intent(this, Tutor_Main_Page.class);
  201. intent.putExtra("token", token);
  202. intent.putExtra("username", username);
  203. this.startActivity(intent);
  204. return true;
  205.  
  206. case R.id.signout:
  207. // User chose the "Favorite" action, mark the current item
  208. // as a favorite...
  209. this.startActivity(new Intent(this,LoginActivity.class));
  210. return true;
  211.  
  212. case R.id.changepass:
  213. // User chose the "Favorite" action, mark the current item
  214. // as a favorite...
  215. this.startActivity(new Intent(this,ChangePassword.class));
  216. return true;
  217.  
  218. default:
  219. // If we got here, the user's action was not recognized.
  220. // Invoke the superclass to handle it.
  221. return super.onOptionsItemSelected(item);
  222.  
  223. }
  224. }
  225.  
  226. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement