Android Open Source - disconnected-content-explorer-android Report List Fragment






From Project

Back to project page disconnected-content-explorer-android.

License

The source code is released under:

MIT License

If you think the Android project disconnected-content-explorer-android 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 mil.nga.dice.listview;
//from w ww.j ava2s . c  o  m
import android.app.Activity;
import android.app.ListFragment;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.support.v4.content.LocalBroadcastManager;
import android.view.View;
import android.widget.ListView;
import mil.nga.dice.report.Report;
import mil.nga.dice.report.ReportManager;

/**
 * Activities containing this fragment MUST implement the {@link Callbacks}
 * interface.
 */
public class ReportListFragment extends ListFragment {
  private CustomList mReportsAdapter;
  
  /**
   * The serialization (saved instance state) Bundle key representing the
   * activated item position. Only used on tablets.
   */
  private static final String STATE_ACTIVATED_POSITION = "activated_position";

  /**
   * The fragment's current callback object, which is notified of list item
   * clicks.
   */
  private Callbacks mCallbacks = reportCallbacks;

  /**
   * The current activated item position. Only used on tablets.
   */
  private int mActivatedPosition = ListView.INVALID_POSITION;

  /**
   * A callback interface that all activities containing this fragment must
   * implement. This mechanism allows activities to be notified of item
   * selections.
   */
  public interface Callbacks {
    /**
     * Callback for when an item has been selected.
     */
    public void onItemSelected(Report report);
  }

  
  private static Callbacks reportCallbacks = new Callbacks() {
    @Override
    public void onItemSelected(Report report) {
      System.out.println("List item selected");
    }
  };

  
  /**
   * Mandatory empty constructor for the fragment manager to instantiate the
   * fragment (e.g. upon screen orientation changes).
   */
  public ReportListFragment() {
  }

  
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    mReportsAdapter = new CustomList(getActivity(), ReportManager.getInstance().getReports());
    setListAdapter(mReportsAdapter);
    LocalBroadcastManager bm = LocalBroadcastManager.getInstance(getActivity().getApplicationContext());
    bm.registerReceiver(new BroadcastReceiver() {
      @Override
      public void onReceive(Context context, Intent intent) {
        mReportsAdapter.notifyDataSetChanged();
      }
    }, new IntentFilter(ReportManager.INTENT_UPDATE_REPORT_LIST));
  }


  @Override
  public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);

    // Restore the previously serialized activated item position.
    if (savedInstanceState != null
        && savedInstanceState.containsKey(STATE_ACTIVATED_POSITION)) {
      setActivatedPosition(savedInstanceState
          .getInt(STATE_ACTIVATED_POSITION));
    }
  }

  
  @Override
  public void onAttach(Activity activity) {
    super.onAttach(activity);

    // Activities containing this fragment must implement its callbacks.
    if (!(activity instanceof Callbacks)) {
      throw new IllegalStateException(
          "Activity must implement fragment's callbacks.");
    }

    mCallbacks = (Callbacks) activity;
  }


  @Override
  public void onDetach() {
    super.onDetach();
    mCallbacks = reportCallbacks;
  }

  
  @Override
  public void onListItemClick(ListView listView, View view, int position, long id) {
    super.onListItemClick(listView, view, position, id);
    // Notify the active callbacks interface (the activity, if the
    // fragment is attached to one) that an item has been selected.
    mCallbacks.onItemSelected((Report) mReportsAdapter.getItem(position));
  }

  
  @Override
  public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    if (mActivatedPosition != ListView.INVALID_POSITION) {
      // Serialize and persist the activated item position.
      outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition);
    }
  }


  private void setActivatedPosition(int position) {
    if (position == ListView.INVALID_POSITION) {
      getListView().setItemChecked(mActivatedPosition, false);
    }
    else {
      getListView().setItemChecked(position, true);
    }
    mActivatedPosition = position;
  }
}




Java Source Code List

mil.nga.dice.DICE.java
mil.nga.dice.gridview.CustomGrid.java
mil.nga.dice.gridview.ReportGridActivity.java
mil.nga.dice.gridview.ReportGridFragment.java
mil.nga.dice.jackson.deserializer.Deserializer.java
mil.nga.dice.jackson.deserializer.FeatureDeserializer.java
mil.nga.dice.jackson.deserializer.GeometryDeserializer.java
mil.nga.dice.listview.CustomList.java
mil.nga.dice.listview.ReportListActivity.java
mil.nga.dice.listview.ReportListFragment.java
mil.nga.dice.listview.ReportListItem.java
mil.nga.dice.map.BackgroundTileProvider.java
mil.nga.dice.map.OfflineMapLoader.java
mil.nga.dice.map.OfflineMap.java
mil.nga.dice.map.ReportMapActivity.java
mil.nga.dice.map.ReportMapFragment.java
mil.nga.dice.report.NoteActivity.java
mil.nga.dice.report.NoteFragment.java
mil.nga.dice.report.ReportDetailActivity.java
mil.nga.dice.report.ReportDetailFragment.java
mil.nga.dice.report.ReportDropbox.java
mil.nga.dice.report.ReportManager.java
mil.nga.dice.report.ReportUnzipRunnable.java
mil.nga.dice.report.Report.java