Android Open Source - BBC-News-Reader Category Activity






From Project

Back to project page BBC-News-Reader.

License

The source code is released under:

Copyright (c) 2011, 2012, Digital Lizard (Oscar Key, Thomas Boby) All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the...

If you think the Android project BBC-News-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

/*******************************************************************************
 * BBC News Reader//from   w  ww. j a  va  2 s . c o m
 * Released under the BSD License. See README or LICENSE.
 * Copyright (c) 2011, Digital Lizard (Oscar Key, Thomas Boby)
 * All rights reserved.
 ******************************************************************************/
package com.digitallizard.bbcnewsreader;

import java.util.ArrayList;

import android.content.Intent;
import android.os.Bundle;
import android.os.Messenger;
import android.support.v4.view.ViewPager;
import android.widget.ListView;

import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.actionbarsherlock.view.MenuItem;
import com.digitallizard.bbcnewsreader.data.DatabaseHandler;
import com.digitallizard.bbcnewsreader.fragments.FrontpageFragment.FrontPageClickHandler;
import com.viewpagerindicator.TitlePageIndicator;

public class CategoryActivity extends SherlockFragmentActivity implements FrontPageClickHandler {
  public static final String EXTRA_CATEGORY_TITLE = "categoryTitle";
  
  private static final int DISPLAY_MODE_HANDSET = 0;
  private static final int DISPLAY_MODE_TABLET_LANDSCAPE = 1;
  
  ListView listView;
  DatabaseHandler database;
  ArrayList<Item> items;
  Messenger resourceMessenger;
  boolean resourceServiceBound;
  
  private int currentDisplayMode;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.setContentView(R.layout.category_activity);
    
    // determine which display mode is currently active
    if (getResources().getBoolean(R.bool.screen_xlarge)) {
      currentDisplayMode = DISPLAY_MODE_TABLET_LANDSCAPE;
    }
    else {
      currentDisplayMode = DISPLAY_MODE_HANDSET;
    }
    
    // do specific configuration for various screen sizes
    /*if (currentDisplayMode == DISPLAY_MODE_TABLET_LANDSCAPE) {
      // force landscape
      setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
      // display the correct category
      CategoryFragment fragment = (CategoryFragment) getSupportFragmentManager().findFragmentById(R.id.categoryFragment);
      fragment.displayCategory(getIntent().getStringExtra(EXTRA_CATEGORY_TITLE));
    }*/
    
    if (currentDisplayMode == DISPLAY_MODE_HANDSET) {
      // load the pager
      CategoryPagerAdapter adapter = new CategoryPagerAdapter(this, getSupportFragmentManager());
          ViewPager pager = (ViewPager)findViewById(R.id.categoryPager);
          pager.setAdapter(adapter);
          
          // bind the pager indicator
          TitlePageIndicator pagerIndicator = (TitlePageIndicator) findViewById(R.id.categoryPagerIndicator);
          pagerIndicator.setViewPager(pager);
          
          // set the pager position to the selected category
          pager.setCurrentItem(adapter.getPositionOfTitle(getIntent().getStringExtra(EXTRA_CATEGORY_TITLE)), false); // no smooth scroll
    }
  }
  
  public void onItemClick(int id) {
    // launch the article activity
    Intent intent = new Intent(this, ArticleActivity.class);
    intent.putExtra(ArticleActivity.EXTRA_KEY_ITEM_ID, id);
    startActivity(intent);
  }
  
  public void onCategoryClick(String title) {
    // this should never be called in this case
  }
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == android.R.id.home) {
      this.finish();
      return true;
    }
    else {
      return super.onOptionsItemSelected(item);
    }
  }
}




Java Source Code List

com.digitallizard.bbcnewsreader.ArticleActivity.java
com.digitallizard.bbcnewsreader.CategoryActivity.java
com.digitallizard.bbcnewsreader.CategoryChooserActivity.java
com.digitallizard.bbcnewsreader.CategoryChooserAdapter.java
com.digitallizard.bbcnewsreader.CategoryPagerAdapter.java
com.digitallizard.bbcnewsreader.Eula.java
com.digitallizard.bbcnewsreader.ItemAdapter.java
com.digitallizard.bbcnewsreader.ItemLayout.java
com.digitallizard.bbcnewsreader.Item.java
com.digitallizard.bbcnewsreader.RSSManager.java
com.digitallizard.bbcnewsreader.ReaderActivity.java
com.digitallizard.bbcnewsreader.ResourceInterface.java
com.digitallizard.bbcnewsreader.ResourceService.java
com.digitallizard.bbcnewsreader.ServiceManager.java
com.digitallizard.bbcnewsreader.SettingsActivity.java
com.digitallizard.bbcnewsreader.data.DatabaseHandler.java
com.digitallizard.bbcnewsreader.data.DatabaseHelper.java
com.digitallizard.bbcnewsreader.data.DatabaseProvider.java
com.digitallizard.bbcnewsreader.data.ItemClearer.java
com.digitallizard.bbcnewsreader.data.WrapBackwards.java
com.digitallizard.bbcnewsreader.fragments.ArticleFragment.java
com.digitallizard.bbcnewsreader.fragments.CategoryChooserFragment.java
com.digitallizard.bbcnewsreader.fragments.CategoryFragment.java
com.digitallizard.bbcnewsreader.fragments.FrontpageFragment.java
com.digitallizard.bbcnewsreader.resource.web.HtmlParser.java
com.digitallizard.bbcnewsreader.resource.web.ImageDownloader.java
com.digitallizard.bbcnewsreader.resource.web.QueueItem.java
com.digitallizard.bbcnewsreader.resource.web.WebManager.java
com.digitallizard.bbcnewsreader.widget.ReaderWidget.java
com.digitallizard.bbcnewsreader.widget.WidgetConfigActivity.java
com.hlidskialf.android.preference.SeekBarPreference.java