Android Open Source - BBC-News-Reader Category Chooser Fragment






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

package com.digitallizard.bbcnewsreader.fragments;
/*  w  ww. java  2  s  . com*/
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.actionbarsherlock.app.SherlockFragment;
import com.digitallizard.bbcnewsreader.CategoryChooserAdapter;
import com.digitallizard.bbcnewsreader.R;
import com.digitallizard.bbcnewsreader.data.DatabaseHandler;
import com.mobeta.android.dslv.DragSortListView;

public class CategoryChooserFragment extends SherlockFragment {
  
  /* constants */

  /* variables */
  private DatabaseHandler database;
  private CategoryChooserAdapter adapter;
  private DragSortListView listView;
  

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    // load the categories from the database
    database = new DatabaseHandler(getActivity());
    String[] enabledCategories = database.getEnabledCategories()[1];
    String[] disabledCategories = database.getDisabledCategories()[1];
    
    // create the list adapter
    adapter = new CategoryChooserAdapter(getActivity(), 
        enabledCategories, disabledCategories);
  }

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    // inflate the layout
    View view = inflater.inflate(R.layout.category_chooser, container, false);
    
    // connect the listview to the adapter and set dragging stuff
    listView = (DragSortListView) view.findViewById(R.id.categoryChooserListView);
    listView.setAdapter(adapter);
    listView.setDropListener(dropListener);
        
    return view;
  }
  
  private DragSortListView.DropListener dropListener = new DragSortListView.DropListener() {
    @Override
    public void drop(int from, int to) {
      // remove the item from the old position and insert it at the new one
      if(from != to) {
        String item = adapter.getItem(from);
        adapter.move(item, from, to);
      }
    }
  };
  
  public void saveCategories() {
    database.setCategoryStates(adapter.getEnabledCategories(), adapter.getDisabledCategories());
  }
}




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