Android Open Source - irma_android_verifier Verification List Fragment






From Project

Back to project page irma_android_verifier.

License

The source code is released under:

GNU General Public License

If you think the Android project irma_android_verifier 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 org.irmacard.androidverifier;
//from ww w.java  2 s . c o  m
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.support.v4.app.LoaderManager.LoaderCallbacks;
import android.support.v4.content.CursorLoader;
import android.support.v4.content.Loader;
import android.util.Log;
import android.view.View;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;

public class VerificationListFragment extends ListFragment implements LoaderCallbacks<Cursor> {
  public static final String TAG = "VerificationListFragment";
    private static final String STATE_ACTIVATED_POSITION = "activated_position";

    private Callbacks mCallbacks = sVerificationCallbacks;
    private int mActivatedPosition = ListView.INVALID_POSITION;
    SimpleCursorAdapter mAdapter;

    public interface Callbacks {

        public void onItemSelected(long id);
    }

    private static Callbacks sVerificationCallbacks = new Callbacks() {
        @Override
        public void onItemSelected(long id) {
        }
    };

    public VerificationListFragment() {
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }
    
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
      super.onActivityCreated(savedInstanceState);
        // Give some text to display if there is no data.  
        setEmptyText("No verifications");        

        mAdapter = new VerificationCursorAdapter(getActivity(), null);
        setListAdapter(mAdapter);
        // Start out with a progress indicator.
        setListShown(false);
        // Prepare the loader.  Either re-connect with an existing one,
        // or start a new one.
        getLoaderManager().initLoader(0, null, this);
    }

    @Override
    public void onViewCreated(View view, Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        if (savedInstanceState != null && savedInstanceState
                .containsKey(STATE_ACTIVATED_POSITION)) {
            setActivatedPosition(savedInstanceState.getInt(STATE_ACTIVATED_POSITION));
        }
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        if (!(activity instanceof Callbacks)) {
            throw new IllegalStateException("Activity must implement fragment's callbacks.");
        }
        
        mCallbacks = (Callbacks) activity;
    }

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

    @Override
    public void onListItemClick(ListView listView, View view, int position, long id) {
        super.onListItemClick(listView, view, position, id);
        
        mCallbacks.onItemSelected(listView.getItemIdAtPosition(position));
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        if (mActivatedPosition != ListView.INVALID_POSITION) {
            outState.putInt(STATE_ACTIVATED_POSITION, mActivatedPosition);
        }
    }

    public void setActivateOnItemClick(boolean activateOnItemClick) {
        getListView().setChoiceMode(activateOnItemClick
                ? ListView.CHOICE_MODE_SINGLE
                : ListView.CHOICE_MODE_NONE);
    }

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

        mActivatedPosition = position;
    }

  @Override
  public Loader<Cursor> onCreateLoader(int id, Bundle args) {
    return new CursorLoader(getActivity(),
        VerificationData.Verifications.CONTENT_URI, 
        null, null, null, null);
  }

  @Override
  public void onLoadFinished(Loader<Cursor> loader, Cursor data) {
    // Swap the new cursor in.  (The framework will take care of closing the
        // old cursor once we return.)
        mAdapter.swapCursor(data);
        Log.i(TAG, "Count: "+data.getCount());
        // The list should now be shown.
        if (isResumed()) {
            setListShown(true);
        } else {
            setListShownNoAnimation(true);
        }        
    
  }

  @Override
  public void onLoaderReset(Loader<Cursor> arg0) {
        // This is called when the last Cursor provided to onLoadFinished()
        // above is about to be closed.  We need to make sure we are no
        // longer using it.
        mAdapter.swapCursor(null);
  }
}




Java Source Code List

org.irmacard.androidverifier.AnimatedArrow.java
org.irmacard.androidverifier.AnonCredCheckActivity.java
org.irmacard.androidverifier.SettingsActivity.java
org.irmacard.androidverifier.StatsActivity.java
org.irmacard.androidverifier.VerificationCursorAdapter.java
org.irmacard.androidverifier.VerificationData.java
org.irmacard.androidverifier.VerificationDetailActivity.java
org.irmacard.androidverifier.VerificationDetailFragment.java
org.irmacard.androidverifier.VerificationListActivity.java
org.irmacard.androidverifier.VerificationListFragment.java
org.irmacard.androidverifier.Verification.java
org.irmacard.androidverifier.VerificationsProvider.java