Android Open Source - anti-piracy-android-app Asam List Fragment






From Project

Back to project page anti-piracy-android-app.

License

The source code is released under:

Apache License

If you think the Android project anti-piracy-android-app 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.giat.asam;
//from  w  ww  .  jav a  2s .c o m
import java.util.List;

import mil.nga.giat.asam.model.AsamBean;
import mil.nga.giat.asam.util.AsamConstants;
import mil.nga.giat.asam.util.AsamListContainer;
import mil.nga.giat.asam.util.AsamLog;
import mil.nga.giat.asam.widget.AsamArrayAdapter;
import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.TextView;


public class AsamListFragment extends Fragment implements AdapterView.OnItemClickListener {

    public interface OnAsamSelectedListener {
        public void onAsamSelected(AsamBean asam);
    }

    private int mSortDirection;
    private int mSortPopupSpinnerSelection;
    private List<AsamBean> mAsams;
    private ListView mAsamListViewUI;
    private AsamArrayAdapter mAsamArrayAdapter;
    private OnAsamSelectedListener mOnAsamSelectedListener;
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        AsamLog.i(AsamListFragment.class.getName() + ":onCreate");
        setHasOptionsMenu(true);
    }
    
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.asam_list_fragment, container, false);
        return view;
    }
    
    @Override
    public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
        inflater.inflate(R.menu.asam_list_fragment_menu, menu);
        super.onCreateOptionsMenu(menu, inflater);
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int itemId = item.getItemId();
        if (itemId == R.id.asam_list_fragment_menu_sort_ui) {
            DialogFragment dialogFragment = SortAsamListDialogFragment.newInstance(mSortDirection, mSortPopupSpinnerSelection);
            dialogFragment.show(getActivity().getSupportFragmentManager(), "dialog");
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        AsamLog.i(AsamListFragment.class.getName() + ":onActivityCreated");
        mAsamListViewUI = (ListView)getActivity().findViewById(R.id.asam_list_tablet_list_view_ui);
        
        TextView emptyListViewUI = new TextView(getActivity());
        emptyListViewUI.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
        emptyListViewUI.setText(getResources().getString(R.string.asam_list_empty_list_text));
        emptyListViewUI.setVisibility(View.GONE);
        mAsamListViewUI.setEmptyView(emptyListViewUI);
        
        mAsams = AsamListContainer.mAsams;
        mAsamArrayAdapter = new AsamArrayAdapter(getActivity(), R.layout.asam_list_row, mAsams);
        mSortDirection = AsamConstants.SORT_DESCENDING;
        mSortPopupSpinnerSelection = AsamConstants.OCURRENCE_DATE_SORT;
        mAsamArrayAdapter.sort(new AsamBean.DescendingOccurrenceDateComparator());
        mAsamListViewUI.setAdapter(mAsamArrayAdapter);
        mAsamListViewUI.setOnItemClickListener(this);
    }
    
    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        AsamLog.i(AsamListFragment.class.getName() + ":onAttach");
        try {
            mOnAsamSelectedListener = (OnAsamSelectedListener)activity;
        }
        catch (ClassCastException caught) {
            throw new ClassCastException(activity.toString() + " must implement OnAsamSelectedListener");
        }
    }
        
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        mOnAsamSelectedListener.onAsamSelected(mAsams.get(position));
    }
    
    public void onSortAsamList(int sortDirection, int sortPopupSpinnerSelection) {
        mSortDirection = sortDirection;
        mSortPopupSpinnerSelection = sortPopupSpinnerSelection;
        switch (mSortPopupSpinnerSelection) {
            case AsamConstants.AGGRESSOR_SORT:
                if (mSortDirection == AsamConstants.SORT_ASCENDING) {
                    mAsamArrayAdapter.sort(new AsamBean.AscendingAggressorComparator());
                }
                else {
                    mAsamArrayAdapter.sort(new AsamBean.DescendingAggressorComparator());
                }
                break;
                
            case AsamConstants.OCURRENCE_DATE_SORT:
                if (mSortDirection == AsamConstants.SORT_ASCENDING) {
                    mAsamArrayAdapter.sort(new AsamBean.AscendingOccurrenceDateComparator());
                }
                else {
                    mAsamArrayAdapter.sort(new AsamBean.DescendingOccurrenceDateComparator());
                }
                break;
                
            case AsamConstants.REFERENCE_NUMBER_SORT:
                if (mSortDirection == AsamConstants.SORT_ASCENDING) {
                    mAsamArrayAdapter.sort(new AsamBean.AscendingReferenceNumberComparator());
                }
                else {
                    mAsamArrayAdapter.sort(new AsamBean.DescendingReferenceNumberComparator());
                }
                break;
                
            case AsamConstants.SUBREGION_SORT:
                if (mSortDirection == AsamConstants.SORT_ASCENDING) {
                    mAsamArrayAdapter.sort(new AsamBean.AscendingSubregionComparator());
                }
                else {
                    mAsamArrayAdapter.sort(new AsamBean.DescendingSubregionComparator());
                }
                break;
                
            case AsamConstants.VICTIM_SORT:
                if (mSortDirection == AsamConstants.SORT_ASCENDING) {
                    mAsamArrayAdapter.sort(new AsamBean.AscendingVictimComparator());
                }
                else {
                    mAsamArrayAdapter.sort(new AsamBean.DescendingVictimComparator());
                }
                break;
        }
    }
}




Java Source Code List

mil.nga.giat.asam.AsamListActivity.java
mil.nga.giat.asam.AsamListFragment.java
mil.nga.giat.asam.AsamListReportTabletActivity.java
mil.nga.giat.asam.AsamReportActivity.java
mil.nga.giat.asam.AsamReportFragment.java
mil.nga.giat.asam.Asam.java
mil.nga.giat.asam.DisclaimerActivity.java
mil.nga.giat.asam.DisclaimerDialogFragment.java
mil.nga.giat.asam.InfoActivity.java
mil.nga.giat.asam.InfoDialogFragment.java
mil.nga.giat.asam.InfoFragment.java
mil.nga.giat.asam.LaunchScreenActivity.java
mil.nga.giat.asam.LegalActivity.java
mil.nga.giat.asam.LegalDetailsActivity.java
mil.nga.giat.asam.LegalDetailsFragment.java
mil.nga.giat.asam.LegalFragment.java
mil.nga.giat.asam.LegalTabletActivity.java
mil.nga.giat.asam.MainActivity.java
mil.nga.giat.asam.PreferencesActivity.java
mil.nga.giat.asam.PreferencesDialogFragment.java
mil.nga.giat.asam.SortAsamListDialogFragment.java
mil.nga.giat.asam.TextQueryActivity.java
mil.nga.giat.asam.TextQueryDialogFragment.java
mil.nga.giat.asam.connectivity.NetworkChangeReceiver.java
mil.nga.giat.asam.connectivity.OfflineBannerFragment.java
mil.nga.giat.asam.db.AsamDbHelper.java
mil.nga.giat.asam.jackson.deserializer.Deserializer.java
mil.nga.giat.asam.jackson.deserializer.FeatureDeserializer.java
mil.nga.giat.asam.jackson.deserializer.GeometryDeserializer.java
mil.nga.giat.asam.map.AllAsamsMapActivity.java
mil.nga.giat.asam.map.AllAsamsMapTabletActivity.java
mil.nga.giat.asam.map.BackgroundTileProvider.java
mil.nga.giat.asam.map.OfflineMap.java
mil.nga.giat.asam.map.SingleAsamMapActivity.java
mil.nga.giat.asam.map.SubregionMapActivity.java
mil.nga.giat.asam.model.AsamBean.java
mil.nga.giat.asam.model.AsamJsonParser.java
mil.nga.giat.asam.model.AsamMapClusterBean.java
mil.nga.giat.asam.model.LegalBean.java
mil.nga.giat.asam.model.SubregionBean.java
mil.nga.giat.asam.model.SubregionTextParser.java
mil.nga.giat.asam.model.TextQueryParametersBean.java
mil.nga.giat.asam.net.AsamWebService.java
mil.nga.giat.asam.util.AsamConstants.java
mil.nga.giat.asam.util.AsamListContainer.java
mil.nga.giat.asam.util.AsamLog.java
mil.nga.giat.asam.util.AsamUtils.java
mil.nga.giat.asam.util.CurrentSubregionHelper.java
mil.nga.giat.asam.util.ManifestMetaData.java
mil.nga.giat.asam.util.SyncTime.java
mil.nga.giat.asam.widget.AsamArrayAdapter.java