Android Open Source - Vispin Pins Dialog Fragment






From Project

Back to project page Vispin.

License

The source code is released under:

Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. ...

If you think the Android project Vispin 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.jpardogo.vispin.ui.dialogs;
/*from   w  w w. j  av a 2 s .  c  o  m*/
import android.app.Activity;
import android.app.DialogFragment;
import android.location.Address;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;

import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.jpardogo.vispin.R;
import com.jpardogo.vispin.adapters.PinsAdapter;
import com.jpardogo.vispin.models.PinInfo;

import java.util.Arrays;

import butterknife.ButterKnife;
import butterknife.InjectView;

public class PinsDialogFragment extends DialogFragment implements AdapterView.OnItemClickListener {

    private static final String ADDRESS = "Address";
    @InjectView(R.id.grid)
    GridView mListView;
    private OnPinsDialogListener mActivityCallback;
    private PinsAdapter mAdapter;
    private Address mAddress;


    private enum PinStatus {
        TOVISIT("Pending visit..."),
        VISITED("Place visited");

        private String text;
        PinStatus(String text) {
            this.text=text;
        }

        @Override
        public String toString() {
            return text;
        }
    }

    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        try {
            mActivityCallback = (OnPinsDialogListener) activity;
        } catch (ClassCastException e) {
            throw new ClassCastException(activity.toString()
                    + " must implement " + OnPinsDialogListener.class.getSimpleName());
        }
    }

    public static PinsDialogFragment newInstance(Address address) {
        PinsDialogFragment pinsDialogFragment = new PinsDialogFragment();
        Bundle bundle = new Bundle();
        bundle.putParcelable(ADDRESS, address);
        pinsDialogFragment.setArguments(bundle);
        return pinsDialogFragment;
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Bundle args = getArguments();
        if (args != null) {
            mAddress = args.getParcelable(ADDRESS);
        }
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_dialog_pins, container, false);
        ButterKnife.inject(this, rootView);
        mListView.setOnItemClickListener(this);
        mAdapter = new PinsAdapter(getActivity(),R.layout.item_grid_address);
        mAdapter.setItems(Arrays.asList(PinStatus.VISITED.toString(), PinStatus.TOVISIT.toString()));
        mListView.setAdapter(mAdapter);
        getDialog().setTitle("set "+mAddress.getCountryName()+" as...");
        return rootView;
    }

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) {
        mActivityCallback.pinCreated(createPin(mAdapter.getItem(position).getItem()));
    }

    private MarkerOptions createPin(String status) {
        MarkerOptions markerOptions =createMarkerOptions(status);
        markerOptions.position(new LatLng(mAddress.getLatitude(), mAddress.getLongitude()));
        return markerOptions;
    }

    private MarkerOptions createMarkerOptions(String status) {
        MarkerOptions markerOptions = new MarkerOptions();
        float hue = BitmapDescriptorFactory.HUE_RED;
        if(status.equals(PinStatus.VISITED.toString())) {
            hue = BitmapDescriptorFactory.HUE_GREEN;
        }else if(status.equals(PinStatus.TOVISIT.toString())){
            hue = BitmapDescriptorFactory.HUE_RED;
        }

        markerOptions.icon(BitmapDescriptorFactory.defaultMarker(hue));
        markerOptions.snippet(new PinInfo(mAddress.getCountryName(), status).toString());
        return markerOptions;
    }

    public interface OnPinsDialogListener {
        void pinCreated(MarkerOptions markerOptions);
    }
}




Java Source Code List

com.jpardogo.vispin.ApplicationTest.java
com.jpardogo.vispin.MainActivity.java
com.jpardogo.vispin.VispinApp.java
com.jpardogo.vispin.adapters.BaseAllAdapters.java
com.jpardogo.vispin.adapters.PinInfoWindowAdapter.java
com.jpardogo.vispin.adapters.PinsAdapter.java
com.jpardogo.vispin.adapters.delegates.BaseDelegateAdapter.java
com.jpardogo.vispin.adapters.delegates.DelegateAdapter.java
com.jpardogo.vispin.models.ListItem.java
com.jpardogo.vispin.models.PinInfo.java
com.jpardogo.vispin.ui.MainActivity.java
com.jpardogo.vispin.ui.PinsMapFragment.java
com.jpardogo.vispin.ui.custom.DrawInsetsFrameLayout.java
com.jpardogo.vispin.ui.dialogs.PinsDialogFragment.java
com.jpardogo.vispin.utils.Utils.java