Android Open Source - Android-Counter-Application Counter History Fragment






From Project

Back to project page Android-Counter-Application.

License

The source code is released under:

GNU General Public License

If you think the Android project Android-Counter-Application 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 ca.ualberta.cs.artem_counter;
/*  w  w  w .j  av a  2s. c  o m*/
import java.util.ArrayList;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

// This is a class that serves as a fragment in the CounterHistoryActivity,
// depending on the selected tab in the dropdown menu, it inflates the required history list.
public class CounterHistoryFragment extends Fragment {

  public static final String ARG_SECTION_NUMBER = "section_number";
  public static final String counterIndex = "counter_index";
  ArrayList<String> hourly;
  ArrayList<String> daily;
  ArrayList<String> weekly;
  ArrayList<String> monthly;

  Counter counter;

  public CounterHistoryFragment() {
  }

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    counter = CounterList.getSpecificCounter(getArguments().getInt(counterIndex));

    View rootView = inflater.inflate(R.layout.fragment_counter_info, container, false);
    TextView textView = (TextView) rootView.findViewById(R.id.section_label);
    ListView listView = (ListView) rootView.findViewById(R.id.listView1);

    if(getArguments().getInt(ARG_SECTION_NUMBER)==1){
      ArrayList<String> history = new CounterHistory(counter).hourlyStats();
      final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getActivity(),android.R.layout.simple_list_item_1, history);
      listView.setAdapter(adapter);
    }
    if(getArguments().getInt(ARG_SECTION_NUMBER)==2){
      ArrayList<String> history = new CounterHistory(counter).dailyStats();
      final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getActivity(),android.R.layout.simple_list_item_1, history);
      listView.setAdapter(adapter);
    }
    if(getArguments().getInt(ARG_SECTION_NUMBER)==3){
      ArrayList<String> history = new CounterHistory(counter).weeklyStats();
      final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getActivity(),android.R.layout.simple_list_item_1, history);
      listView.setAdapter(adapter);
    }
    if(getArguments().getInt(ARG_SECTION_NUMBER)==4){
      ArrayList<String> history = new CounterHistory(counter).monthlyStats();
      final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this.getActivity(),android.R.layout.simple_list_item_1, history);
      listView.setAdapter(adapter);
    }

    textView.setText(counter.getName());
    return rootView;
  }
}




Java Source Code List

ca.ualberta.cs.artem_counter.CounterAdapter.java
ca.ualberta.cs.artem_counter.CounterHistoryActivity.java
ca.ualberta.cs.artem_counter.CounterHistoryFragment.java
ca.ualberta.cs.artem_counter.CounterHistory.java
ca.ualberta.cs.artem_counter.CounterListActivity.java
ca.ualberta.cs.artem_counter.CounterList.java
ca.ualberta.cs.artem_counter.Counter.java