Android Open Source - spring-for-android-starter-book Main Activity






From Project

Back to project page spring-for-android-starter-book.

License

The source code is released under:

Apache License

If you think the Android project spring-for-android-starter-book 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 net.dahanne.spring.android.ch3.message.converters.feedreader;
import java.util.Collections;
/*from   w  ww .j av  a 2s .c  o m*/
import org.springframework.http.MediaType;
import org.springframework.http.converter.feed.RssChannelHttpMessageConverter;
import org.springframework.web.client.RestTemplate;

import android.app.Activity;
import android.os.AsyncTask;
import android.os.Bundle;
import android.view.Menu;
import android.webkit.WebView;

import com.google.code.rome.android.repackaged.com.sun.syndication.feed.rss.Channel;
import com.google.code.rome.android.repackaged.com.sun.syndication.feed.rss.Item;

public class MainActivity extends Activity {

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final WebView resultTextView = (WebView) findViewById(R.id.result_text);

    AsyncTask<String, Void, Channel> simpleGetTask =  new AsyncTask<String, Void, Channel>() {
      @Override
      protected Channel doInBackground(String... params) {
        RestTemplate restTemplate = new RestTemplate();
        // Configure the RSS message converter.
                RssChannelHttpMessageConverter rssChannelConverter = new RssChannelHttpMessageConverter();
                rssChannelConverter.setSupportedMediaTypes(Collections.singletonList(MediaType.TEXT_XML));

                // Add the RSS message converter to the RestTemplate instance
                restTemplate.getMessageConverters().add(rssChannelConverter);
        
        // Make the HTTP GET request on the url (params[0]), marshaling the response to a String
        return restTemplate.getForObject(params[0], Channel.class);
      }
      
      @Override
      protected void onPostExecute(Channel result) {
        //get the latest article from the blog
        Item item = (Item) result.getItems().get(1);
        
        // load the content of the article into the WebView
        resultTextView.loadData(item.getContent().getValue(), "text/html", "UTF-8");
      }
      
    };
    
    String url = "http://blog.dahanne.net/feed/";
    // triggers the task; it will update the resultTextView once it is done
    simpleGetTask.execute(url);
  }

}




Java Source Code List

net.dahanne.android.google.client.AbstractAsyncActivity.java
net.dahanne.android.google.client.AbstractAsyncListActivity.java
net.dahanne.android.google.client.AbstractWebViewActivity.java
net.dahanne.android.google.client.AsyncActivity.java
net.dahanne.android.google.client.GoogleActivity.java
net.dahanne.android.google.client.GoogleProfileActivity.java
net.dahanne.android.google.client.GoogleProfileListAdapter.java
net.dahanne.android.google.client.GoogleWebOAuthActivity.java
net.dahanne.android.google.client.MainApplication.java
net.dahanne.spring.android.ch3.gzip.IfConfigMeJson.java
net.dahanne.spring.android.ch3.gzip.MainActivity.java
net.dahanne.spring.android.ch3.http.basic.authentication.MainActivity.java
net.dahanne.spring.android.ch3.message.converters.feedreader.MainActivity.java
net.dahanne.spring.android.ch3.message.converters.jackson.IfConfigMeJson.java
net.dahanne.spring.android.ch3.message.converters.jackson.IfConfigMeJson.java
net.dahanne.spring.android.ch3.message.converters.jackson.IfConfigMeRestClient.java
net.dahanne.spring.android.ch3.message.converters.jackson.IfConfigMeRestClient_.java
net.dahanne.spring.android.ch3.message.converters.jackson.MainActivity.java
net.dahanne.spring.android.ch3.message.converters.jackson.MainActivity.java
net.dahanne.spring.android.ch3.message.converters.jackson.MainActivity_.java
net.dahanne.spring.android.ch3.message.converters.simplexml.IfConfigMeXml.java
net.dahanne.spring.android.ch3.message.converters.simplexml.MainActivity.java
net.dahanne.spring.android.ch3.restful.example.recipeapp.DishType.java
net.dahanne.spring.android.ch3.restful.example.recipeapp.RecipeAbstractAsyncTask.java
net.dahanne.spring.android.ch3.restful.example.recipeapp.RecipeEditor.java
net.dahanne.spring.android.ch3.restful.example.recipeapp.Recipe.java
net.dahanne.spring.android.ch3.restful.example.recipeapp.RecipesList.java
net.dahanne.spring.android.firstexample.MainActivity.java
net.dahanne.spring.android.firstexample.MainActivity.java