Android Open Source - ExampleApp Report Activity






From Project

Back to project page ExampleApp.

License

The source code is released under:

Copyright (c) 2014, Altinn All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redis...

If you think the Android project ExampleApp 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.altinn.apps.fisher.ui.screen;
/**//from  w  ww .j av  a 2 s .  c om
 * This Screen represents list of saved/sent report items
 * If items are saved and user selects such item in that case ReportReceivedFishActivity screen brings in-front of user for editing and sending again.
 * If Sent item is selected in that send related information were shown by 'ReportSendDetialsActivity'
 * 
 */
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;

import android.content.Intent;
import android.os.AsyncTask;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.altinn.apps.fisher.R;
import com.altinn.apps.fisher.db.DataBaseHelper;
import com.altinn.apps.fisher.db.FormDBHelper;
import com.altinn.apps.fisher.models.InfoData;
import com.altinn.apps.fisher.models.ReportInfoData;
import com.altinn.apps.fisher.utils.Utils;
import com.altinn.apps.fisher.utils.Utils.Log;

public class ReportActivity extends BaseActivity  {
  private final String TAG = "ReportActivity";
  private ListView mListViewReports;
  private ReportAdapter mReportsAdapter;
  private RrefreshListTask mRefreshListTask;
  private ArrayList<InfoData> mReceivedListDraft;
  private ArrayList<InfoData> mReceivedListSent;
  private EditText mSearchInputView;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {    
    mLayOutId = R.layout.reports;
    super.onCreate(savedInstanceState);
    init();
  }
  
  private void init(){
    setTitle(R.string.context_menu_myreports, R.drawable.navigation_back);
    mSearchInputView = (EditText)findViewById(R.id.search_input);
    mListViewReports = (ListView)findViewById(R.id.list_reports);
    mListViewReports.setOnItemClickListener(new OnItemClickListener(){
      @Override
      public void onItemClick(AdapterView<?> adapter, View v, int position, long id) {
        ReportItem reportItem = mReportsAdapter.getItem(position);
        Log.d(TAG, "VIEW@@@@@@@@@@@: "+reportItem.id);
        Bundle bundle = new Bundle();
        //bundle.putBoolean("VIEW_MODE", mViewMode);
        bundle.putInt("FORM_ID", (int)reportItem.id);
        if(reportItem.isDraft)
          startActivity(ReportReceivedFishActivity.class,bundle);
        else{
          Intent intent = new Intent(ReportActivity.this,ReportSendDetailActivity.class);
          intent.putExtras(bundle);
          startActivity(intent);
        }
      }      
    });  
    
    mSearchInputView.addTextChangedListener(new TextWatcher() {      
      @Override
      public void onTextChanged(CharSequence s, int start, int before, int count) {        
      }
      
      @Override
      public void beforeTextChanged(CharSequence s, int start, int count, int after) {
      }
      
      @Override
      public void afterTextChanged(Editable s) {
        startFilterSearch();
      }
    });    
    startFilterSearch();    
  }
    
  private class ReportItem{
    String dateStr;
    String timeStr;
    int itemType;
    boolean isDraft;
    long id;
    String titleStr,subTitleLbl,subTitleValue;
    public ReportItem(InfoData infoData ){
      id = infoData.mId;
      itemType = infoData.mFormType;
      Calendar cal = Calendar.getInstance();      
      if(infoData.mSendId > 0){
        isDraft = false;
        cal.setTimeInMillis(infoData.mSendId);
      }else{
        isDraft = true;
        cal.setTimeInMillis(infoData.mCreateId);
      }
      SimpleDateFormat sdfDate = new SimpleDateFormat("MM.dd.yy");
      SimpleDateFormat sdfTime = new SimpleDateFormat("HH.mm");
      dateStr = sdfDate.format(cal.getTime());
      timeStr = sdfTime.format(cal.getTime());
      String timePreAppend = getString(R.string.lbl_time_short);
      timeStr = timePreAppend +" " +timeStr;
      if(itemType ==  HomeActivity.MENU_REPORT_RECEIVED){
        ReportInfoData rInfo = (ReportInfoData)infoData;
        titleStr = rInfo.mFirmName;
        //subTitleLbl = "MOTTAK AV";
        subTitleValue = rInfo.mFishName;
      }
    }
  }
  
  private class ReportAdapter extends BaseAdapter{
    private ArrayList<ReportItem> mReportList;
    private LayoutInflater mInflater;
    
    public ReportAdapter(ArrayList<ReportItem> menuList){
      mInflater = LayoutInflater.from(ReportActivity.this);
      if(menuList == null)
        mReportList = new ArrayList<ReportItem> ();
      else
        this.mReportList = menuList;
    }
    
    @Override
    public int getCount() {
      // TODO Auto-generated method stub
      return mReportList.size();
    }

    @Override
    public ReportItem getItem(int index) {
      
      return mReportList.get(index);
    }

    @Override
    public long getItemId(int index) {
      // TODO Auto-generated method stub
      return index;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {      
      final ReportItem reportItem = mReportList.get(position);
      ViewHolder holder = null;
      if(convertView == null){
        convertView = mInflater.inflate(R.layout.report_item_new, null);
        holder = new ViewHolder();
        holder.lbl_time = (TextView)convertView.findViewById(R.id.time_item);
        holder.lbl_date = (TextView)convertView.findViewById(R.id.date_item);
        holder.lbl_subtitle = (TextView)convertView.findViewById(R.id.label_item);
        holder.lbl_subtitle_value = (TextView)convertView.findViewById(R.id.label_value);
        holder.lbl_title = (TextView)convertView.findViewById(R.id.title_item);
        holder.indicator = (ImageView)convertView.findViewById(R.id.send_icon);
        convertView.setTag(holder);
      }else{
        holder = (ViewHolder)convertView.getTag();
      }
      
      holder.lbl_date.setText(reportItem.dateStr);
      holder.lbl_time.setText(reportItem.timeStr);
      holder.lbl_title.setText(reportItem.titleStr);
      //holder.lbl_subtitle.setText(reportItem.subTitleLbl);
      holder.lbl_subtitle_value.setText(reportItem.subTitleValue);
      if(reportItem.isDraft){
        holder.indicator.setImageResource(R.drawable.content_save_b);
      }else{
        holder.indicator.setImageResource(R.drawable.social_send_now_b);
      }      
      return convertView;
    }    
  }
  
  private static class ViewHolder{
    TextView lbl_date, lbl_time, lbl_title, lbl_subtitle,lbl_subtitle_value;
    ImageView indicator;
  }
  private void startFilterSearch(){  
    if(mRefreshListTask != null){
      mRefreshListTask.cancel(true);
    }    
    mRefreshListTask = new RrefreshListTask();
    mRefreshListTask.execute(mSearchInputView.getText().toString());    
  }
  
  private class RrefreshListTask extends AsyncTask{

    @Override
    protected Object doInBackground(Object... arg0) {
      String searchText = (String)arg0[0];
      FormDBHelper formDbHelper = (FormDBHelper)DataBaseHelper.getInstance().getDBHelper(DataBaseHelper.TABLE_HEPLER_FORM);
      if(mReceivedListDraft == null)
        mReceivedListDraft =  formDbHelper.getFormList(HomeActivity.MENU_REPORT_RECEIVED,true);
      if(mReceivedListSent == null)
        mReceivedListSent =  formDbHelper.getFormList(HomeActivity.MENU_REPORT_RECEIVED,false);
      
      
      ArrayList<ReportItem> listAll = new ArrayList<ReportItem>();
      
      boolean isFilterEnabled = false;
      if(!Utils.isNullorEmpty(searchText) && searchText.trim().length() > 0){
        isFilterEnabled = true;
        searchText = searchText.toLowerCase();
      }
      
      if(mReceivedListDraft != null){
        for(InfoData infodata:mReceivedListDraft){
          ReportItem reportItem = new ReportItem(infodata);
          if(!isFilterEnabled)
            listAll.add(reportItem);
          else{
            String searchInText = (reportItem.titleStr + " "+reportItem.subTitleValue ).toLowerCase();
            if(searchInText.indexOf(searchText) != -1){
              listAll.add(reportItem);
            }
          }
        }
      }
      if(mReceivedListSent != null){
        for(InfoData infodata:mReceivedListSent){
          ReportItem reportItem = new ReportItem(infodata);
          if(!isFilterEnabled)
            listAll.add(reportItem);
          else{
            String searchInText = (reportItem.titleStr + " "+reportItem.subTitleValue).toLowerCase();
            if(searchInText.indexOf(searchText) != -1){
              listAll.add(reportItem);
            }
          }
        }
      }
      
      mReportsAdapter = new ReportAdapter(listAll);
      return null;
    }
    
    @Override
    protected void onPostExecute(Object obj) {
      mListViewReports.setAdapter(mReportsAdapter);
    }
    
  }

  

  
}




Java Source Code List

com.altinn.apps.fisher.AppContext.java
com.altinn.apps.fisher.CacheManager.java
com.altinn.apps.fisher.common.AppConstants.java
com.altinn.apps.fisher.common.IStatusMessage.java
com.altinn.apps.fisher.common.MenuItem.java
com.altinn.apps.fisher.common.StatusMessage.java
com.altinn.apps.fisher.db.DataBaseHelper.java
com.altinn.apps.fisher.db.FactoryDBHelper.java
com.altinn.apps.fisher.db.FishCategoryDBHelper.java
com.altinn.apps.fisher.db.FormDBHelper.java
com.altinn.apps.fisher.db.IDBHelper.java
com.altinn.apps.fisher.db.RegsDBHelper.java
com.altinn.apps.fisher.db.VesselDBHelper.java
com.altinn.apps.fisher.gps.CLocationProvider.java
com.altinn.apps.fisher.gps.ILocationUpdateListner.java
com.altinn.apps.fisher.models.CaughtInfoData.java
com.altinn.apps.fisher.models.InfoData.java
com.altinn.apps.fisher.models.ReportInfoData.java
com.altinn.apps.fisher.models.UserProfile.java
com.altinn.apps.fisher.net.AbstractWorkerTask.java
com.altinn.apps.fisher.net.CookieHelper.java
com.altinn.apps.fisher.net.IParser.java
com.altinn.apps.fisher.net.JSParser.java
com.altinn.apps.fisher.net.ParseManager.java
com.altinn.apps.fisher.net.TaskNotifier.java
com.altinn.apps.fisher.net.jsobj.AttachmentObj.java
com.altinn.apps.fisher.net.jsobj.FormObj.java
com.altinn.apps.fisher.net.jsobj.JSConstants.java
com.altinn.apps.fisher.net.jsobj.JsonObj.java
com.altinn.apps.fisher.net.jsobj.LinkItemObj.java
com.altinn.apps.fisher.net.jsobj.LinkObj.java
com.altinn.apps.fisher.net.jsobj.MessageObj.java
com.altinn.apps.fisher.net.jsobj.MessagesEmbedded.java
com.altinn.apps.fisher.net.jsobj.OrganisationObj.java
com.altinn.apps.fisher.net.tasks.LoginTask.java
com.altinn.apps.fisher.net.tasks.RefreshTokenTask.java
com.altinn.apps.fisher.net.tasks.SendReportTask.java
com.altinn.apps.fisher.net.tasks.UserProfileTask.java
com.altinn.apps.fisher.settings.FactoryDetails.java
com.altinn.apps.fisher.settings.FishDetails.java
com.altinn.apps.fisher.settings.SettingItem.java
com.altinn.apps.fisher.settings.VesselsDetails.java
com.altinn.apps.fisher.ui.component.DurationTimePickDialog.java
com.altinn.apps.fisher.ui.component.RAutoCompleteTextView.java
com.altinn.apps.fisher.ui.component.RButton.java
com.altinn.apps.fisher.ui.component.REditText.java
com.altinn.apps.fisher.ui.component.RTextView.java
com.altinn.apps.fisher.ui.screen.BaseActivity.java
com.altinn.apps.fisher.ui.screen.BrowserActivity.java
com.altinn.apps.fisher.ui.screen.FactoryDetailsActivity.java
com.altinn.apps.fisher.ui.screen.HomeActivity.java
com.altinn.apps.fisher.ui.screen.InformationActivity.java
com.altinn.apps.fisher.ui.screen.MenuNavigationActivity.java
com.altinn.apps.fisher.ui.screen.ReportActivity.java
com.altinn.apps.fisher.ui.screen.ReportReceivedFishActivity.java
com.altinn.apps.fisher.ui.screen.ReportSendDetailActivity.java
com.altinn.apps.fisher.ui.screen.SplashActivity.java
com.altinn.apps.fisher.ui.screen.UserProfileActivity.java
com.altinn.apps.fisher.utils.PreferenceUtils.java
com.altinn.apps.fisher.utils.Utils.java
net.simonvt.menudrawer.BuildLayerFrameLayout.java
net.simonvt.menudrawer.ColorDrawable.java
net.simonvt.menudrawer.DraggableDrawer.java
net.simonvt.menudrawer.FloatScroller.java
net.simonvt.menudrawer.MenuDrawer.java
net.simonvt.menudrawer.NoClickThroughFrameLayout.java
net.simonvt.menudrawer.OverlayDrawer.java
net.simonvt.menudrawer.PeekInterpolator.java
net.simonvt.menudrawer.Position.java
net.simonvt.menudrawer.Scroller.java
net.simonvt.menudrawer.SinusoidalInterpolator.java
net.simonvt.menudrawer.SlideDrawable.java
net.simonvt.menudrawer.SlidingDrawer.java
net.simonvt.menudrawer.SmoothInterpolator.java
net.simonvt.menudrawer.StaticDrawer.java
net.simonvt.menudrawer.ViewHelper.java
net.simonvt.menudrawer.compat.ActionBarHelperCompat.java
net.simonvt.menudrawer.compat.ActionBarHelperNative.java
net.simonvt.menudrawer.compat.ActionBarHelper.java