fixed build error
This commit is contained in:
parent
7c4c509b3d
commit
69cc81a741
|
@ -1,149 +0,0 @@
|
|||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.mariotaku.twidere.fragment;
|
||||
|
||||
import android.graphics.Point;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.content.res.ResourcesCompat;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import org.mariotaku.twidere.Constants;
|
||||
import org.mariotaku.twidere.R;
|
||||
import org.osmdroid.ResourceProxy;
|
||||
import org.osmdroid.api.IMapController;
|
||||
import org.osmdroid.api.IMapView;
|
||||
import org.osmdroid.util.GeoPoint;
|
||||
import org.osmdroid.views.MapView;
|
||||
import org.osmdroid.views.overlay.ItemizedOverlay;
|
||||
import org.osmdroid.views.overlay.Overlay;
|
||||
import org.osmdroid.views.overlay.OverlayItem;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class OpenStreetMapViewerFragment extends BaseSupportFragment implements Constants {
|
||||
|
||||
private MapView mMapView;
|
||||
private double mLatitude, mLongitude;
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(final Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
setHasOptionsMenu(true);
|
||||
final Bundle args = getArguments();
|
||||
final double latitude = args.getDouble(EXTRA_LATITUDE, Double.NaN);
|
||||
final double longitude = args.getDouble(EXTRA_LONGITUDE, Double.NaN);
|
||||
if (Double.isNaN(latitude) || Double.isNaN(longitude)) {
|
||||
getActivity().finish();
|
||||
return;
|
||||
}
|
||||
mLatitude = latitude;
|
||||
mLongitude = longitude;
|
||||
mMapView.setMultiTouchControls(true);
|
||||
mMapView.setBuiltInZoomControls(true);
|
||||
mMapView.setTilesScaledToDpi(true);
|
||||
final List<Overlay> overlays = mMapView.getOverlays();
|
||||
final GeoPoint gp = new GeoPoint((int) (latitude * 1E6), (int) (longitude * 1E6));
|
||||
final Drawable d = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_map_marker, null);
|
||||
final Itemization markers = new Itemization(d, mMapView.getResourceProxy());
|
||||
final OverlayItem overlayitem = new OverlayItem("", "", gp);
|
||||
markers.addOverlay(overlayitem);
|
||||
overlays.add(markers);
|
||||
final IMapController mc = mMapView.getController();
|
||||
mc.setZoom(12);
|
||||
mc.setCenter(gp);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return inflater.inflate(R.layout.activity_osm_viewer, container, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
mMapView = (MapView) view.findViewById(R.id.map_view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
inflater.inflate(R.menu.menu_osm_viewer, menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(final MenuItem item) {
|
||||
switch (item.getItemId()) {
|
||||
case R.id.center: {
|
||||
moveToCenter(mLatitude, mLongitude);
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void moveToCenter(double lat, double lng) {
|
||||
final GeoPoint gp = new GeoPoint((int) (lat * 1E6), (int) (lng * 1E6));
|
||||
final IMapController mc = mMapView.getController();
|
||||
mc.animateTo(gp);
|
||||
}
|
||||
|
||||
static class Itemization extends ItemizedOverlay<OverlayItem> {
|
||||
|
||||
private final ArrayList<OverlayItem> mOverlays = new ArrayList<>();
|
||||
|
||||
public Itemization(final Drawable defaultMarker, final ResourceProxy proxy) {
|
||||
super(boundCenterBottom(defaultMarker), proxy);
|
||||
}
|
||||
|
||||
public void addOverlay(final OverlayItem overlay) {
|
||||
mOverlays.add(overlay);
|
||||
populate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onSnapToItem(final int x, final int y, final Point snapPoint, final IMapView mapView) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int size() {
|
||||
return mOverlays.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected OverlayItem createItem(final int i) {
|
||||
return mOverlays.get(i);
|
||||
}
|
||||
|
||||
protected static Drawable boundCenterBottom(final Drawable d) {
|
||||
d.setBounds(-d.getIntrinsicWidth() / 2, -d.getIntrinsicHeight(), d.getIntrinsicWidth() / 2, 0);
|
||||
return d;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,123 @@
|
|||
/*
|
||||
* Twidere - Twitter client for Android
|
||||
*
|
||||
* Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.mariotaku.twidere.fragment
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Point
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Bundle
|
||||
import android.support.v4.content.res.ResourcesCompat
|
||||
import android.view.*
|
||||
import kotlinx.android.synthetic.fdroid.activity_osm_viewer.*
|
||||
import org.mariotaku.twidere.Constants
|
||||
import org.mariotaku.twidere.R
|
||||
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_LATITUDE
|
||||
import org.mariotaku.twidere.constant.IntentConstants.EXTRA_LONGITUDE
|
||||
import org.osmdroid.api.IMapView
|
||||
import org.osmdroid.util.GeoPoint
|
||||
import org.osmdroid.views.overlay.ItemizedOverlay
|
||||
import org.osmdroid.views.overlay.OverlayItem
|
||||
import java.util.*
|
||||
|
||||
class OpenStreetMapViewerFragment : BaseSupportFragment(), Constants {
|
||||
|
||||
private var latitude: Double = 0.0
|
||||
private var longitude: Double = 0.0
|
||||
|
||||
override fun onActivityCreated(savedInstanceState: Bundle?) {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
setHasOptionsMenu(true)
|
||||
val args = arguments
|
||||
val latitude = args.getDouble(EXTRA_LATITUDE, Double.NaN)
|
||||
val longitude = args.getDouble(EXTRA_LONGITUDE, Double.NaN)
|
||||
if (latitude.isNaN() || longitude.isNaN()) {
|
||||
activity.finish()
|
||||
return
|
||||
}
|
||||
this.latitude = latitude
|
||||
this.longitude = longitude
|
||||
mapView.setMultiTouchControls(true)
|
||||
mapView.setBuiltInZoomControls(true)
|
||||
mapView.isTilesScaledToDpi = true
|
||||
val gp = GeoPoint(latitude, longitude)
|
||||
val d = ResourcesCompat.getDrawable(resources, R.drawable.ic_map_marker, null)!!
|
||||
val markers = Itemization(context, d)
|
||||
val overlayItem = OverlayItem("", "", gp)
|
||||
markers.addOverlay(overlayItem)
|
||||
mapView.overlays.add(markers)
|
||||
val mc = mapView.controller
|
||||
mc.setZoom(12)
|
||||
mc.setCenter(gp)
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
return inflater.inflate(R.layout.activity_osm_viewer, container, false)
|
||||
}
|
||||
|
||||
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
|
||||
inflater.inflate(R.menu.menu_osm_viewer, menu)
|
||||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.center -> {
|
||||
moveToCenter(latitude, longitude)
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
private fun moveToCenter(lat: Double, lng: Double) {
|
||||
val gp = GeoPoint(lat, lng)
|
||||
val mc = mapView.controller
|
||||
mc.animateTo(gp)
|
||||
}
|
||||
|
||||
internal class Itemization(context: Context, defaultMarker: Drawable) : ItemizedOverlay<OverlayItem>(context, OpenStreetMapViewerFragment.Itemization.boundCenterBottom(defaultMarker)) {
|
||||
|
||||
private val overlays = ArrayList<OverlayItem>()
|
||||
|
||||
fun addOverlay(overlay: OverlayItem) {
|
||||
overlays.add(overlay)
|
||||
populate()
|
||||
}
|
||||
|
||||
override fun onSnapToItem(x: Int, y: Int, snapPoint: Point, mapView: IMapView): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun size(): Int {
|
||||
return overlays.size
|
||||
}
|
||||
|
||||
override fun createItem(i: Int): OverlayItem {
|
||||
return overlays[i]
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
private fun boundCenterBottom(d: Drawable): Drawable {
|
||||
d.setBounds(-d.intrinsicWidth / 2, -d.intrinsicHeight, d.intrinsicWidth / 2, 0)
|
||||
return d
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -16,13 +16,14 @@
|
|||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<org.osmdroid.views.MapView
|
||||
android:id="@+id/map_view"
|
||||
android:id="@+id/mapView"
|
||||
tilesource="Mapnik"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tilesource="Mapnik" />
|
||||
android:layout_height="match_parent"/>
|
||||
</FrameLayout>
|
Loading…
Reference in New Issue