Advertisement
Guest User

Untitled

a guest
May 28th, 2015
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.17 KB | None | 0 0
  1. package twitterapp.hummingbird.nl.hummingbird;
  2.  
  3. import android.app.AlertDialog;
  4. import android.app.Dialog;
  5. import android.app.SearchManager;
  6. import android.content.Context;
  7. import android.content.Intent;
  8. import android.support.v4.app.DialogFragment;
  9. import android.support.v4.widget.SwipeRefreshLayout;
  10. import android.support.v7.app.ActionBarActivity;
  11. import android.os.Bundle;
  12. import android.support.v7.widget.SearchView;
  13. import android.util.Log;
  14. import android.view.LayoutInflater;
  15. import android.view.Menu;
  16. import android.view.MenuItem;
  17. import android.view.View;
  18. import android.widget.AdapterView;
  19. import android.widget.Button;
  20. import android.widget.ListView;
  21. import android.widget.TextView;
  22. import android.widget.Toast;
  23.  
  24. import com.melnykov.fab.FloatingActionButton;
  25. import com.sothree.slidinguppanel.SlidingUpPanelLayout;
  26.  
  27. import org.json.JSONArray;
  28. import org.json.JSONException;
  29. import org.json.JSONObject;
  30.  
  31. import java.util.ArrayList;
  32. import java.util.Observable;
  33. import java.util.Observer;
  34.  
  35. import twitterapp.hummingbird.nl.hummingbird.model.Model;
  36. import twitterapp.hummingbird.nl.hummingbird.model.Tweet;
  37. import twitterapp.hummingbird.nl.hummingbird.view.TweetListAdapter;
  38.  
  39.  
  40. public class MainActivity extends ActionBarActivity implements Observer {
  41.  
  42.     HummingbirdApplication app;
  43.     Model model;
  44.     TweetListAdapter tweetListAdapter;
  45.  
  46.     @Override
  47.     protected void onCreate(Bundle savedInstanceState) {
  48.         super.onCreate(savedInstanceState);
  49.         setContentView(R.layout.activity_main);
  50.         app = (HummingbirdApplication) getApplicationContext();
  51.         model = app.getModel();
  52.  
  53.         try {
  54.             JSONObject json = new JSONObject(app.getJsonText());
  55.             model.addTweets(json);
  56.         } catch (JSONException e) {
  57.             //ToDo: Error netjes afhandelen
  58.             e.printStackTrace();
  59.         }
  60.  
  61.         tweetListAdapter = new TweetListAdapter(this,R.layout.tweet_list_item, model.getTweets());
  62.         ListView tweetsList = (ListView) findViewById(R.id.lvTweetsOverview);
  63.         tweetsList.setAdapter(tweetListAdapter);
  64.  
  65.         FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
  66.         fab.attachToListView(tweetsList);
  67.  
  68.         // Handle clicking on fab
  69.         fab.setOnClickListener(new View.OnClickListener() {
  70.             @Override
  71.             public void onClick(View view) {
  72.                 Toast.makeText(app, "TODO: Toon Tweet maken dialog.", Toast.LENGTH_SHORT).show();
  73.             }
  74.  
  75.         });
  76.  
  77.         // Handle clicking on tweets
  78.         tweetsList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  79.             @Override
  80.             public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
  81.                 Intent intent = new Intent(app, TweetDetailActivity.class);
  82.                 intent.putExtra("tweetIndex", i);
  83.                 startActivity(intent);
  84.             }
  85.         });
  86.  
  87.         // Handle swipe to refresh
  88.         final SwipeRefreshLayout swipeLayout = (SwipeRefreshLayout) findViewById(R.id.swipeToRefresh);
  89.         swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
  90.             @Override
  91.             public void onRefresh() {
  92.                 Toast.makeText(app, "TODO: Refreshen van tweets.", Toast.LENGTH_SHORT).show();
  93.                 if (swipeLayout.isRefreshing()) {
  94.                     swipeLayout.setRefreshing(false);
  95.                 }
  96.             }
  97.         });
  98.     }
  99.  
  100.  
  101.     @Override
  102.     public boolean onCreateOptionsMenu(Menu menu) {
  103.         getMenuInflater().inflate(R.menu.menu_main, menu);
  104.  
  105.         SearchView searchView = (SearchView) menu.findItem(R.id.action_search).getActionView();
  106.         searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
  107.  
  108.             @Override
  109.             public boolean onQueryTextSubmit(String s) {
  110.                 Log.d("searchtest", "onQueryTextSubmit ");
  111.                 return false;
  112.             }
  113.  
  114.             @Override
  115.             public boolean onQueryTextChange(String s) {
  116.                 Log.d("searchtest", "onQueryTextChange ");
  117.                 return false;
  118.             }
  119.         });
  120.  
  121.         return true;
  122.     }
  123.  
  124.     @Override
  125.     public boolean onOptionsItemSelected(MenuItem item) {
  126.         // Handle action bar item clicks here. The action bar will
  127.         // automatically handle clicks on the Home/Up button, so long
  128.         // as you specify a parent activity in AndroidManifest.xml.
  129.         int id = item.getItemId();
  130.  
  131.         //noinspection SimplifiableIfStatement
  132. //        if (id == R.id.action_settings) {
  133. //            return true;
  134. //        }
  135.  
  136.         return super.onOptionsItemSelected(item);
  137.     }
  138.  
  139.  
  140.     /**
  141.      * This method is called if the specified {@code Observable} object's
  142.      * {@code notifyObservers} method is called (because the {@code Observable}
  143.      * object has been updated.
  144.      *
  145.      * @param observable the {@link Observable} object.
  146.      * @param data       the data passed to {@link Observable#notifyObservers(Object)}.
  147.      */
  148.     @Override
  149.     public void update(Observable observable, Object data) {
  150.         tweetListAdapter.notifyDataSetChanged();
  151.     }
  152.  
  153. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement