Android Open Source - RSSReader Suggested Feeds Activity






From Project

Back to project page RSSReader.

License

The source code is released under:

?????? ????? ?????? ?????? ?????????? ????????? 1.?????? ???????? ??????? ??????? ????? ?????? ????? ?????????...

If you think the Android project RSSReader 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.uyghurdev.avaroid.rssreader;
//w  w w . j a  va  2 s  .co  m
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;

import net.uyghurdev.avaroid.rssreader.data.FeedData;
import net.uyghurdev.avaroid.rssreader.operator.Feed;
import net.uyghurdev.avaroid.rssreader.operator.JSONManager;
import net.uyghurdev.avaroid.rssreader.operator.NetworkOperator;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.res.AssetManager;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.Gravity;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.Toast;
import android.widget.LinearLayout.LayoutParams;
import android.widget.ProgressBar;
import android.widget.TextView;

public class SuggestedFeedsActivity extends Activity {

  private TextView title;
//  private ListView lvFeeds;
  private LinearLayout list;
  private ProgressBar prog;
  private Button addSelected;
  private Button addAll;
  private NetworkOperator netOp;
  private JSONManager jman;
  private ArrayList<Feed> sugFeeds;
  boolean err;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sugfeeds);
    init();
    prepareList();
    
    addSelected.setOnClickListener(new Button.OnClickListener(){

      @Override
      public void onClick(View v) {
        // TODO Auto-generated method stub
        
        for(int position = 0; position < sugFeeds.size(); position++){
          if(((CheckBox) list.getChildAt(position)).isChecked()){
            FeedData data = new FeedData(SuggestedFeedsActivity.this);
//          Object cb = lvFeeds.getAdapter().getItem(position);
//          if(((View) lvFeeds.getAdapter().getItem(position)).isSelected())
          data.addFeed(sugFeeds.get(position).getTitle(), sugFeeds.get(position).getUrl());
          }
        }
        
        Intent intent = new Intent(SuggestedFeedsActivity.this,
            RSSReaderActivity.class);
        startActivity(intent);
//        overridePendingTransition(R.anim.enter_back, R.anim.exit_back);
        finish();
      }
      
    });
    
    addAll.setOnClickListener(new Button.OnClickListener(){

      @Override
      public void onClick(View v) {
        // TODO Auto-generated method stub
        for(Feed feed : sugFeeds){
          FeedData data = new FeedData(SuggestedFeedsActivity.this);
          data.addFeed(feed.getTitle(), feed.getUrl());
        }
        
        Intent intent = new Intent(SuggestedFeedsActivity.this,
            RSSReaderActivity.class);
        startActivity(intent);
//        overridePendingTransition(R.anim.enter_back, R.anim.exit_back);
        finish();
      }
      
    });
    
  }

  private void prepareList() {
    // TODO Auto-generated method stub
    err = false;
    
    final Handler handler = new Handler() {

      public void handleMessage(Message msg) {

        prog.setVisibility(View.GONE);
        if(err){
          errSiteMes();
        }else{
          setContent();
        }
      }

    };

    Thread checkUpdate = new Thread() {
      public void run() {

        try{
        String jStr = netOp.urlToString(Configs.SugFeedServer);
        if(jStr.length() == 0){
          err = true;
        }else{
          sugFeeds = jman.getSugFeeds(SuggestedFeedsActivity.this, jStr);
          if(sugFeeds == null){
            err = true;
          }
        }

        
        }catch(Exception e){
          err = true;
        }

        handler.sendEmptyMessage(0);
        
      }
    };

    checkUpdate.start();
  }
  
  public String ReadText() {
    AssetManager am = getAssets();
    String txt = "";
    try {

      
      InputStream fileIS = am.open("rssjson.txt");
      InputStreamReader reader = new InputStreamReader(fileIS, "UTF-8");
      StringBuffer sb = new StringBuffer();
      int start = 0;
      int count;
      char[] buf = new char[1024];
      while ((count = reader.read(buf)) != -1) {
        sb.append(buf, start, count);//sb.append(buf);//
      }
      txt = sb.toString();

    } catch (FileNotFoundException e) {

      e.printStackTrace();

    } catch (IOException e) {
      e.printStackTrace();

    }
    return txt;
  }

  private void setContent() {
    // TODO Auto-generated method stub
    
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
    
    for(int f = 0; f < sugFeeds.size(); f++){
      CheckBox cb = new CheckBox(this);
      cb.setId(f);

      cb.setTextColor(Color.BLACK);
      cb.setText(sugFeeds.get(f).title);
      list.addView(cb, lp);
    }
    
//    SuggestedFeedAdapter adapter = new SuggestedFeedAdapter(this, sugFeeds);
//    lvFeeds.setAdapter(adapter);
  }

  private void init() {
    // TODO Auto-generated method stub
    title = (TextView)findViewById(R.id.title);
    addSelected = (Button)findViewById(R.id.addSelected);
    addAll = (Button)findViewById(R.id.addAll);

    title.setText(getString(R.string.sug_feeds));
    addSelected.setText(getString(R.string.add_selected));
    addAll.setText(getString(R.string.add_all));
    list = (LinearLayout)findViewById(R.id.items);
//    lvFeeds = (ListView)findViewById(R.id.lvItems);
    prog = (ProgressBar)findViewById(R.id.progress);
    
    netOp = new NetworkOperator();
    jman = new JSONManager();
  }
  

  private void errSiteMes() {
    // TODO Auto-generated method stub
    LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = inflater.inflate(R.layout.toast, null);

    TextView text = (TextView) layout.findViewById(R.id.toast);

    text.setText(getString(R.string.can_not_conn));
    Toast toast = new Toast(this);
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(layout);
    toast.show();
  }

  
  public boolean onKeyDown(int keyCode, KeyEvent event) {

    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {


      Intent intent = new Intent(SuggestedFeedsActivity.this,
          RSSReaderActivity.class);
      startActivity(intent);
//      overridePendingTransition(R.anim.enter_back, R.anim.exit_back);
      finish();
    }
    return super.onKeyDown(keyCode, event);
  }

  
}




Java Source Code List

ca.laplanete.mobile.example.ExampleActivity.java
ca.laplanete.mobile.example.ExamplePagedDragDropGridAdapter.java
ca.laplanete.mobile.example.Item.java
ca.laplanete.mobile.example.Page.java
ca.laplanete.mobile.pageddragdropgrid.DeleteDropZoneView.java
ca.laplanete.mobile.pageddragdropgrid.DragDropGrid.java
ca.laplanete.mobile.pageddragdropgrid.ItemsSource.java
ca.laplanete.mobile.pageddragdropgrid.OnPageChangedListener.java
ca.laplanete.mobile.pageddragdropgrid.PagedContainer.java
ca.laplanete.mobile.pageddragdropgrid.PagedDragDropGridAdapter.java
ca.laplanete.mobile.pageddragdropgrid.PagedDragDropGrid.java
net.uyghurdev.avaroid.rssreader.About.java
net.uyghurdev.avaroid.rssreader.AddFeedActivity.java
net.uyghurdev.avaroid.rssreader.Configs.java
net.uyghurdev.avaroid.rssreader.ContentActivity.java
net.uyghurdev.avaroid.rssreader.CustomAlertDialog.java
net.uyghurdev.avaroid.rssreader.EditFeedActivity.java
net.uyghurdev.avaroid.rssreader.ImageLoader.java
net.uyghurdev.avaroid.rssreader.ItemAdapter.java
net.uyghurdev.avaroid.rssreader.ItemListActivity.java
net.uyghurdev.avaroid.rssreader.Item.java
net.uyghurdev.avaroid.rssreader.LItem.java
net.uyghurdev.avaroid.rssreader.RSSReaderActivity.java
net.uyghurdev.avaroid.rssreader.SettingsActivity.java
net.uyghurdev.avaroid.rssreader.SplashActivity.java
net.uyghurdev.avaroid.rssreader.SuggestedFeedsActivity.java
net.uyghurdev.avaroid.rssreader.data.DataHelper_.java
net.uyghurdev.avaroid.rssreader.data.FeedData.java
net.uyghurdev.avaroid.rssreader.data.OpenHelper.java
net.uyghurdev.avaroid.rssreader.operator.FeedParser.java
net.uyghurdev.avaroid.rssreader.operator.Feed.java
net.uyghurdev.avaroid.rssreader.operator.FeedsAdapter.java
net.uyghurdev.avaroid.rssreader.operator.JSONManager.java
net.uyghurdev.avaroid.rssreader.operator.NetworkOperator.java
net.uyghurdev.avaroid.rssreader.service.AlarmReceiver.java
net.uyghurdev.avaroid.rssreader.service.UpdateService.java
net.uyghurdev.avaroid.rssreader.tools.FileCache.java
net.uyghurdev.avaroid.rssreader.tools.Helper.java
net.uyghurdev.avaroid.rssreader.tools.MemoryCache.java
net.uyghurdev.avaroid.rssreader.tools.UIManager.java
net.uyghurdev.avaroid.rssreader.tools.Utils.java