Back to project page Vispin.
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.
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); } }