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.
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.app.ActionBar; import android.app.Activity; 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; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_displayarticle); // To get the icon on the back button in the top left corner ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); // 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); actionBar.setTitle(title); ImageView imageView = (ImageView) findViewById(R.id.imageView1); // This starts the asynchronous call for the image - TODO I already have the image (used it for the ListView I need to resuse! ) Picasso.with(this).load(url).placeholder(R.drawable.white).error(R.drawable.error).resize(320,200).into(imageView); new Retrivearticle(this).execute("http://www.motorindiaonline.in/mobapp/?a_id="+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(R.id.textView1); //t.setText(title); // the following just sets the article body with the empty string TextView b = (TextView)findViewById(R.id.textView2); b.setText(body); b.setMovementMethod(new ScrollingMovementMethod()); // to start the loading animation load = (WebView)findViewById(R.id.webView1); load.loadUrl("file:///android_asset/spiffygif.gif"); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.displayarticle, 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(); switch(id){ case R.id.action_settings: return true; case android.R.id.home: //made it such that we go the the category we were browsing before we opened the article onBackPressed(); return true; } if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } @Override public void onRequestCompleted(JSONObject result) { // stop loading GIF load.setVisibility(View.GONE); // 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 e.printStackTrace(); } // 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(R.id.textView1); t.setText(title); TextView b = (TextView)findViewById(R.id.textView2); b.setText(body); } }