Android Open Source - SurgeTracker Surge List Fragment






From Project

Back to project page SurgeTracker.

License

The source code is released under:

MIT License

If you think the Android project SurgeTracker 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.bklimt.surgetracker.view;
/*from   ww w  .j a v a 2 s.co m*/
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ListView;

import com.bklimt.surgetracker.R;
import com.bklimt.surgetracker.backbone.ModelListener;
import com.bklimt.surgetracker.model.RootViewModel;

import java.lang.ref.WeakReference;

import bolts.Capture;

/**
 * A placeholder fragment containing a simple view.
 */
public class SurgeListFragment extends Fragment {
    /**
     * Returns a new instance of this fragment for the given section
     * number.
     */
    public static SurgeListFragment newInstance() {
        SurgeListFragment fragment = new SurgeListFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    public SurgeListFragment() {
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
        final View rootView = inflater.inflate(R.layout.fragment_main, container, false);

        final RootViewModel root = RootViewModel.get();

        final SurgeListAdapter surgeListAdapter = new SurgeListAdapter(getActivity(), this);
        final ListView surgeListView = (ListView) rootView.findViewById(R.id.surge_list);
        surgeListView.setAdapter(surgeListAdapter);
        root.getSurges().bindToArrayAdapter(surgeListAdapter);

        Button startButton = (Button) rootView.findViewById(R.id.start_button);
        final WeakReference<Button> weakStartButton = new WeakReference<Button>(startButton);
        final Capture<ModelListener<RootViewModel>> weakListener = new Capture<ModelListener<RootViewModel>>();
        weakListener.set(new ModelListener<RootViewModel>() {
            @Override
            public void onChanged(RootViewModel model, String key, Object oldValue, Object newValue) {
                Button startButton = weakStartButton.get();
                if (startButton == null) {
                    root.removeListener(weakListener.get());
                    return;
                }

                if (key.equals("currentSurge")) {
                    if (newValue == null) {
                        startButton.setText(R.string.start);
                    } else {
                        startButton.setText(R.string.stop);
                    }
                }
            }
        });
        root.addListener(weakListener.get());

        startButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (root.getCurrentSurge() == null) {
                    root.startSurge();
                } else {
                    root.stopSurge();
                }
            }
        });

        return rootView;
    }
}




Java Source Code List

com.bklimt.surgetracker.ApplicationTest.java
com.bklimt.surgetracker.SurgeTrackerApplication.java
com.bklimt.surgetracker.TimerThread.java
com.bklimt.surgetracker.backbone.CollectionListener.java
com.bklimt.surgetracker.backbone.Collection.java
com.bklimt.surgetracker.backbone.ModelListener.java
com.bklimt.surgetracker.backbone.Model.java
com.bklimt.surgetracker.backbone.Visitor.java
com.bklimt.surgetracker.model.AggregateCollection.java
com.bklimt.surgetracker.model.Aggregate.java
com.bklimt.surgetracker.model.RootViewModel.java
com.bklimt.surgetracker.model.SurgeCollection.java
com.bklimt.surgetracker.model.SurgeParseObject.java
com.bklimt.surgetracker.model.Surge.java
com.bklimt.surgetracker.view.AggregateListAdapter.java
com.bklimt.surgetracker.view.AggregateListFragment.java
com.bklimt.surgetracker.view.MainActivity.java
com.bklimt.surgetracker.view.SurgeDeletionDialogFragment.java
com.bklimt.surgetracker.view.SurgeDurationDialogFragment.java
com.bklimt.surgetracker.view.SurgeGraphFragment.java
com.bklimt.surgetracker.view.SurgeListAdapter.java
com.bklimt.surgetracker.view.SurgeListFragment.java
com.bklimt.surgetracker.view.SurgeStartDialogFragment.java