public void updateAll() {
    Cursor c = sourceDB.findAll();
    ManagedCursor mc = new ManagedCursor(c);
    final SourceCache sourceCache = SourceCache.getInstance(indexActivity);
    final List<CachedArticleSource> cachedArticleSources = new ArrayList<CachedArticleSource>();
    mc.each(
        new EachCursor() {
          public void call(Cursor c, int index) {
            String sourceType = c.getString(c.getColumnIndex(Source.KEY_SOURCE_TYPE));
            String sourceContentUrl = c.getString(c.getColumnIndex(Source.KEY_CONTENT_URL));
            String sourceName = c.getString(c.getColumnIndex(Source.KEY_SOURCE_NAME));
            String sourceImage = c.getString(c.getColumnIndex(Source.KEY_IMAGE_URL));
            String sourceID = c.getString(c.getColumnIndex(Source.KEY_SOURCE_ID));

            //                adapter.getItem()
            CachedArticleSource cachedArticleSource = null;
            if (sourceType.equals(Constants.TYPE_RSS)) {
              FeaturedArticleSource featuredArticleSource =
                  new FeaturedArticleSource(
                      indexActivity, sourceContentUrl, sourceName, sourceImage);
              cachedArticleSource =
                  new CachedArticleSource(
                      featuredArticleSource, indexActivity, indexActivity, sourceCache);
            }

            if (cachedArticleSource != null) {
              cachedArticleSources.add(cachedArticleSource);
            }
          }
        });
    this.sourceDB.close();
    //        sourceCache.close();
    for (int i = 0; i < cachedArticleSources.size(); i++) {
      CachedArticleSource cachedArticleSource = cachedArticleSources.get(i);
      cachedArticleSource.loadSourceFromCache();
      cachedArticleSource.checkUpdate();
    }
  }
Example #2
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    this.deviceInfo = getDeviceInfoFromApplicationContext();

    StopWatch sw = new StopWatch();
    sw.start("create activity");

    createAnimation();
    buildFadeInPageViewAnimation();
    buildFadeOutPageViewAnimation();

    setProgressBarIndeterminateVisibility(false);
    System.out.println("debug on create");

    executor =
        new ThreadPoolExecutor(
            0, Integer.MAX_VALUE, 10L, TimeUnit.SECONDS, new SynchronousQueue<Runnable>());
    sourceDB = new SourceDB(this);
    alarmSender = new AlarmSender(this);

    //        sm = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
    //        acceleromererSensor = sm.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
    //        createShakeListener();

    Cursor sourceCursor = sourceDB.findAll();

    startManagingCursor(sourceCursor);

    sourceAdapter =
        new SourceItemArrayAdapter<SourceItem>(this, R.layout.source_item, sourceDB, deviceInfo);

    TelephonyManager tManager = (TelephonyManager) this.getSystemService(Context.TELEPHONY_SERVICE);
    deviceId = tManager.getDeviceId();
    inflater = LayoutInflater.from(this);
    accountType = (String) getIntent().getExtras().get("type");
    sourceId = (String) getIntent().getExtras().get("sourceId");
    sourceImageURL = (String) getIntent().getExtras().get("sourceImage");
    sourceName = (String) getIntent().getExtras().get("sourceName");
    contentUrl = (String) getIntent().getExtras().get("contentUrl");

    //// System.out.println("sourceImageURL:" + sourceImageURL);
    setContentView(R.layout.main);
    container = (ViewGroup) findViewById(R.id.pageContainer);
    pageIndexView = (PageIndexView) findViewById(R.id.pageIndex);
    ViewSwitcher headerSwitcher = (ViewSwitcher) findViewById(R.id.flipper);
    header = (HeaderView) findViewById(R.id.header);
    contentImageButton = (ImageButton) findViewById(R.id.content);
    contentImageButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View view) {
            overridePendingTransition(android.R.anim.slide_in_left, R.anim.fade);
            PageActivity.this.finish();
          }
        });
    //        pageInfo = (TextView)header.findViewById(R.id.pageInfo);
    headerText = (TextView) findViewById(R.id.headerText);
    headerImageView = (WebImageView) findViewById(R.id.headerImage);

    pageViewFactory = new WeiboPageViewFactory();

    preferences = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    this.browseMode = getBrowseMode();
    //        this.animationMode = getAnimationMode();
    refreshingSemaphore = new Semaphore(1, true);
    Log.v("accountType", accountType);
    reload();
  }