Android Open Source - foxail_reader News Activity






From Project

Back to project page foxail_reader.

License

The source code is released under:

GNU General Public License

If you think the Android project foxail_reader 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 org.foxail.android.reader.activity;
/* w  ww  .  j a v a 2 s  .  co m*/
import org.foxail.android.common.volley.HtmlRequest;
import org.foxail.android.reader.BuildConfig;
import org.foxail.android.reader.R;
import org.foxail.android.reader.client.Client;
import org.foxail.android.reader.model.News;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebView;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.Volley;

@SuppressLint("NewApi")
public class NewsActivity extends BaseActivity {
  
  private final static String TAG = "NewsActivity";
  
  private News news;
  private WebView newsWeb;
  private RequestQueue mQueue;
  private Client client;

  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_news);
    
    mQueue = Volley.newRequestQueue(this);
    client = clientFactory.getClient("cnbeta");
    
    //??ActionBar????????
    getActionBar().setDisplayHomeAsUpEnabled(true);
    
    newsWeb = (WebView) findViewById(R.id.news_web);
    //???????
    newsWeb.getSettings().setSupportZoom(true);
    newsWeb.getSettings().setBuiltInZoomControls(true);
    newsWeb.getSettings().setDisplayZoomControls(false);
    
    Intent intent = getIntent();
    Bundle newsBundle = intent.getExtras();
    news = (News) newsBundle.get("news");
    
    setTitle(news.getTitle());
    showNewsContent(news);
  }

  @Override
  public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.news, menu);
    return true;
  }
    
    //?????????????? 
  @Override  
    public boolean onOptionsItemSelected(MenuItem item) {
      switch (item.getItemId()) {
        case android.R.id.home: {
          finish();
          break;
        }
        case R.id.news_menu_share: {
          share(news);
          break;
        }
        case R.id.news_menu_refresh: {
          //??????
          showNewsContent(news);
          break;
        }
        default:
          break;
    }
      return true;
    }
  
  private void showNewsContent(News news) {
    if (BuildConfig.DEBUG) {
      Log.d(TAG, "get news content starting. news.id=" + news.getId());
    }
    
    Bundle bundle = new Bundle();
    bundle.putString("msg", getString(R.string.msg_loading));
    showDialog(DIALOG_PROGRESS_COMMON, bundle);
    
    try {
      //html = client.getNewsContent(news.getId());
      HtmlRequest request = new HtmlRequest(client.getContentUrl(news.getId()),  
              new Response.Listener<String>() {  
                  @Override  
                  public void onResponse(String response) {  
                      //Log.d("TAG", response);
                  
                    String html = client.getNewsContent(response);
                
                //??????????????
                newsWeb.loadDataWithBaseURL("about:blank", 
                    html, "text/html", "utf-8", null);
                closePDialog();
                  }
              }, new Response.ErrorListener() {  
                  @Override  
                  public void onErrorResponse(VolleyError error) {  
                      //Log.e("TAG", error.getMessage(), error);  
                  }
              });
      mQueue.add(request);
    } catch(Exception e) {
      closePDialog();
      showToast(getString(R.string.msg_connectServerFailed));
      return;
    }
  }

}




Java Source Code List

org.foxail.android.common.CommonUtil.java
org.foxail.android.common.http.ConnectionManager.java
org.foxail.android.common.http.HttpConnection.java
org.foxail.android.common.volley.HtmlRequest.java
org.foxail.android.reader.activity.BaseActivity.java
org.foxail.android.reader.activity.FavoritesActivity.java
org.foxail.android.reader.activity.MainActivity.java
org.foxail.android.reader.activity.NewsActivity.java
org.foxail.android.reader.client.ClientFactory.java
org.foxail.android.reader.client.Client.java
org.foxail.android.reader.client.CnBetaClient.java
org.foxail.android.reader.model.News.java