Android Open Source - MotorIndia Displayarticle

From Project

Back to project page MotorIndia.


The source code is released under:

GNU General Public License

If you think the Android project MotorIndia listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package spider.motorindia;
/*  w w w.  ja  v a 2  s. co  m*/
import org.json.JSONException;
import org.json.JSONObject;

import com.squareup.picasso.Picasso;

import spider.motorindia.Retrivearticle.MyCallbackInterface;
import android.content.Intent;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

public class Displayarticle extends Activity implements MyCallbackInterface {
  String title = "";
  String body = "";
  WebView load;
  protected void onCreate(Bundle savedInstanceState) {
    // To get the icon on the back button in the top left corner
    ActionBar actionBar = getActionBar();
    // handle the incoming INTENT
    Intent intent = getIntent();
    int message = intent.getIntExtra(Home.EXTRA_MESSAGE,26479);
    String url = intent.getStringExtra(Home.EXTRA_URL);
    // We already have the title corresponding to the article in the ListView, use that and set the actionBar title
    title = intent.getStringExtra(Home.EXTRA_TITLE);
    ImageView imageView = (ImageView) findViewById(;
    // This starts the asynchronous call for the image - TODO I already have the image (used it for the ListView I need to resuse! )
    new Retrivearticle(this).execute(""+Integer.toString(message));
    // This sets the Title of the article just after the Image.
    // the actual content is set after the callback is done. for reasons given there.
    //TextView t = (TextView)findViewById(;
    // the following just sets the article body with the empty string
    TextView b = (TextView)findViewById(;
    b.setMovementMethod(new ScrollingMovementMethod());
    // to start the loading animation
    load = (WebView)findViewById(;

  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(, menu);
    return true;

  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();

      return true;
      //made it such that we go the the category we were browsing before we opened the article
      return true;
    if (id == {
      return true;
    return super.onOptionsItemSelected(item);

  public void onRequestCompleted(JSONObject result) {
    // stop loading GIF
    // SO here we get the JSON object = result
    try {
      // change the uncoded text the server sends to UTF-8 such that android recognizes it.
      // DUE to the server sending a empty string 
      //we comment this out
      //title = org.apache.commons.lang3.StringEscapeUtils.unescapeJava(result.getString("title"));
      body = org.apache.commons.lang3.StringEscapeUtils.unescapeJava(result.getString("content"));
    } catch (JSONException e) {
      // Auto-generated catch block

    // I set the title here even when I have the title during OnCreate as it looks better if both title and body were set at the same time
    // And the loading animation being superimposed on the title doesn't look good
    TextView t = (TextView)findViewById(;
    TextView b = (TextView)findViewById(;

Java Source Code List