Android Open Source - AndroidWeatherBuoyDemo Buoy Listing Fragment






From Project

Back to project page AndroidWeatherBuoyDemo.

License

The source code is released under:

Apache License

If you think the Android project AndroidWeatherBuoyDemo 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.kevinrschultz.weatherbuoy.ui;
/*ww w .ja va2 s . c o m*/
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Spinner;

import com.google.common.collect.Lists;
import com.kevinrschultz.weatherbuoy.R;
import com.kevinrschultz.weatherbuoy.model.BuoyDescription;
import com.kevinrschultz.weatherbuoy.model.Region;

import java.util.List;

/**
 * A placeholder fragment containing a simple view.
 */
public class BuoyListingFragment extends Fragment implements BuoyListingView, AdapterView.OnItemClickListener, AdapterView.OnItemSelectedListener {

    private BuoyListingPresenter presenter;

    private BuoyDescriptionAdapter buoyAdapter;

    private ArrayAdapter<Region> regionAdapter;

    private ListView buoyListView;

    private Spinner regionSpinner;

    public static BuoyListingFragment makeBuoyListingFragment() {
        return new BuoyListingFragment();
    }

    public BuoyListingFragment() {
        presenter = new BuoyListingPresenter();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = inflater.inflate(R.layout.fragment_buoy_listing, container, false);
        buoyListView = ListView.class.cast(v.findViewById(android.R.id.list));
        regionSpinner = Spinner.class.cast(v.findViewById(R.id.buoy_listing_region_spinner));
        return v;
    }

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        buoyAdapter = new BuoyDescriptionAdapter(getActivity());
        buoyListView.setAdapter(buoyAdapter);
        buoyListView.setOnItemClickListener(this);
        regionAdapter = makeRegionAdapter();
        regionSpinner.setAdapter(regionAdapter);
        regionSpinner.setOnItemSelectedListener(this);
    }

    @Override
    public void onStart() {
        super.onStart();
        presenter.setView(this);
    }

    @Override
    public void onStop() {
        super.onStop();
        presenter.clearView();
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        if (parent == buoyListView) {
            BuoyDescription description = buoyAdapter.getItem(position);
            Intent intent = BuoyDetailActivity.makeBuoyDetailIntent(getActivity(), description.getId());
            startActivity(intent);
        }
    }

    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        if (parent == regionSpinner) {
            presenter.selectRegion(regionAdapter.getItem(position));
        }
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {
        if (parent == regionSpinner) {
            presenter.selectRegion(null);
        }
    }

    @Override
    public void updateList(List<BuoyDescription> descriptionList) {
        buoyAdapter.clear();
        buoyAdapter.addAll(descriptionList);
    }

    private ArrayAdapter<Region> makeRegionAdapter() {
        ArrayAdapter<Region> adapter = new ArrayAdapter<Region>(getActivity(), android.R.layout.simple_expandable_list_item_1, Region.values());
        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        return adapter;
    }

}




Java Source Code List

com.kevinrschultz.weatherbuoy.Constants.java
com.kevinrschultz.weatherbuoy.customviews.compass.CompassViewTest.java
com.kevinrschultz.weatherbuoy.customviews.compass.CompassView.java
com.kevinrschultz.weatherbuoy.customviews.compass.Compass.java
com.kevinrschultz.weatherbuoy.data.FakeBuoyListingGenerator.java
com.kevinrschultz.weatherbuoy.json.GsonSingleton.java
com.kevinrschultz.weatherbuoy.model.Advisory.java
com.kevinrschultz.weatherbuoy.model.BuoyDescription.java
com.kevinrschultz.weatherbuoy.model.Region.java
com.kevinrschultz.weatherbuoy.model.UnitSystem.java
com.kevinrschultz.weatherbuoy.model.WaveCondition.java
com.kevinrschultz.weatherbuoy.model.WindCondition.java
com.kevinrschultz.weatherbuoy.preferences.WeatherBuoyPreferences.java
com.kevinrschultz.weatherbuoy.sandbox.ActivityLaunchingListItem.java
com.kevinrschultz.weatherbuoy.sandbox.CompassViewActivity.java
com.kevinrschultz.weatherbuoy.sandbox.MainActivity.java
com.kevinrschultz.weatherbuoy.ui.BaseActivity.java
com.kevinrschultz.weatherbuoy.ui.BaseArrayAdapter.java
com.kevinrschultz.weatherbuoy.ui.BuoyDescriptionAdapter.java
com.kevinrschultz.weatherbuoy.ui.BuoyDetailActivity.java
com.kevinrschultz.weatherbuoy.ui.BuoyDetailFragment.java
com.kevinrschultz.weatherbuoy.ui.BuoyDetailViewModel.java
com.kevinrschultz.weatherbuoy.ui.BuoyListingActivity.java
com.kevinrschultz.weatherbuoy.ui.BuoyListingFragment.java
com.kevinrschultz.weatherbuoy.ui.BuoyListingPresenter.java
com.kevinrschultz.weatherbuoy.ui.BuoyListingView.java
com.kevinrschultz.weatherbuoy.ui.SettingsActivity.java
com.kevinrschultz.weatherbuoy.ui.SettingsFragment.java
com.kevinrschultz.weatherbuoy.util.UnitConverter.java
com.kevinrschultz.weatherbuoy.views.AdvisoryBannerView.java
com.kevinrschultz.weatherbuoy.views.InstrumentView.java
com.kevinrschultz.weatherbuoy.views.Instrument.java
com.kevinrschultz.weatherbuoy.views.OptionalTextView.java