Search in sources :

Example 1 with OnClickAddressListener

use of com.junjunguo.pocketmaps.model.listeners.OnClickAddressListener in project PocketMaps by junjunguo.

the class MapActions method initSearchLocationHandler.

private void initSearchLocationHandler(final boolean isStartP, final boolean fromFavourite) {
    int viewID = R.id.map_nav_settings_to_search;
    if (isStartP) {
        viewID = R.id.map_nav_settings_from_search;
    }
    if (fromFavourite) {
        viewID = R.id.map_nav_settings_to_favorite;
        if (isStartP) {
            viewID = R.id.map_nav_settings_from_favorite;
        }
    }
    final ViewGroup pointItem = (ViewGroup) activity.findViewById(viewID);
    pointItem.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch(event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    setBgColor(pointItem, R.color.my_primary_light);
                    return true;
                case MotionEvent.ACTION_UP:
                    setBgColor(pointItem, R.color.my_primary);
                    Intent intent = new Intent(activity, GeocodeActivity.class);
                    OnClickAddressListener callbackListener = new OnClickAddressListener() {

                        @Override
                        public void onClick(Address addr) {
                            GeoPoint newPos = new GeoPoint(addr.getLatitude(), addr.getLongitude());
                            if (isStartP) {
                                Destination.getDestination().setStartPoint(newPos);
                                fromLocalET.setText(Destination.getDestination().getStartPointToString());
                                addFromMarker(Destination.getDestination().getStartPoint());
                                navSettingsFromVP.setVisibility(View.INVISIBLE);
                            } else {
                                Destination.getDestination().setEndPoint(newPos);
                                toLocalET.setText(Destination.getDestination().getEndPointToString());
                                addToMarker(Destination.getDestination().getEndPoint());
                                navSettingsToVP.setVisibility(View.INVISIBLE);
                            }
                            boolean showingNavigator = activeNavigator();
                            if (!showingNavigator) {
                                navSettingsVP.setVisibility(View.VISIBLE);
                            }
                            MapHandler.getMapHandler().centerPointOnMap(newPos, 0, 0, 0);
                        }
                    };
                    GeoPoint[] points = null;
                    if (fromFavourite) {
                        points = new GeoPoint[3];
                        points[0] = Destination.getDestination().getStartPoint();
                        points[1] = Destination.getDestination().getEndPoint();
                        Location curLoc = MapActivity.getmCurrentLocation();
                        if (curLoc != null) {
                            points[2] = new GeoPoint(curLoc.getLatitude(), curLoc.getLongitude());
                        }
                    }
                    GeocodeActivity.setPre(callbackListener, points);
                    activity.startActivity(intent);
                    return true;
            }
            return false;
        }
    });
}
Also used : GeoPoint(org.oscim.core.GeoPoint) Address(android.location.Address) ViewGroup(android.view.ViewGroup) OnClickAddressListener(com.junjunguo.pocketmaps.model.listeners.OnClickAddressListener) Intent(android.content.Intent) MapView(org.oscim.android.MapView) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) GeoPoint(org.oscim.core.GeoPoint) MotionEvent(android.view.MotionEvent) Location(android.location.Location)

Example 2 with OnClickAddressListener

use of com.junjunguo.pocketmaps.model.listeners.OnClickAddressListener in project PocketMaps by junjunguo.

the class GeocodeActivity method showAddresses.

private RecyclerView showAddresses(List<Address> list) {
    setContentView(R.layout.activity_addresses);
    OnClickAddressListener l = new OnClickAddressListener() {

        @Override
        public void onClick(Address addr) {
            log("Address selected: " + addr);
            GeocodeActivity.this.finish();
            if (callbackListener != null) {
                callbackListener.onClick(addr);
            }
        }
    };
    MyAddressAdapter adapter = new MyAddressAdapter(list, l);
    RecyclerView listView = (RecyclerView) findViewById(R.id.my_addr_recycler_view);
    listView.setHasFixedSize(true);
    // use a linear layout manager
    LinearLayoutManager layoutManager = new LinearLayoutManager(this.getApplicationContext());
    layoutManager.setOrientation(LinearLayout.VERTICAL);
    listView.setLayoutManager(layoutManager);
    listView.setItemAnimator(new DefaultItemAnimator());
    listView.setAdapter(adapter);
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.my_addr_add_fab);
    if (locations == null) {
        fab.setVisibility(View.INVISIBLE);
    } else {
        fab.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                log("Plus selected!");
                showFavAdd();
            }
        });
    }
    return listView;
}
Also used : Address(android.location.Address) MyAddressAdapter(com.junjunguo.pocketmaps.fragments.MyAddressAdapter) OnClickAddressListener(com.junjunguo.pocketmaps.model.listeners.OnClickAddressListener) FloatingActionButton(android.support.design.widget.FloatingActionButton) RecyclerView(android.support.v7.widget.RecyclerView) OnClickListener(android.view.View.OnClickListener) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) View(android.view.View) AdapterView(android.widget.AdapterView) RecyclerView(android.support.v7.widget.RecyclerView) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator)

Aggregations

Address (android.location.Address)2 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 OnClickAddressListener (com.junjunguo.pocketmaps.model.listeners.OnClickAddressListener)2 Intent (android.content.Intent)1 Location (android.location.Location)1 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 DefaultItemAnimator (android.support.v7.widget.DefaultItemAnimator)1 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)1 MotionEvent (android.view.MotionEvent)1 OnClickListener (android.view.View.OnClickListener)1 ViewGroup (android.view.ViewGroup)1 TextView (android.widget.TextView)1 MyAddressAdapter (com.junjunguo.pocketmaps.fragments.MyAddressAdapter)1 MapView (org.oscim.android.MapView)1 GeoPoint (org.oscim.core.GeoPoint)1