Created
November 3, 2018 09:35
-
-
Save ajaypro/3209347ba8ab9acd23e932a3e4f3806e to your computer and use it in GitHub Desktop.
Activity from which I'm taking geopoint
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package io.github.project_travel_mate.destinations.description; | |
import android.arch.persistence.room.TypeConverter; | |
import android.arch.persistence.room.TypeConverters; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.support.annotation.Nullable; | |
import android.support.design.widget.FloatingActionButton; | |
import android.support.v7.app.AppCompatActivity; | |
import org.osmdroid.tileprovider.cachemanager.CacheManager; | |
import org.osmdroid.util.GeoPoint; | |
import org.osmdroid.views.MapView; | |
import java.util.ArrayList; | |
import javax.inject.Inject; | |
import butterknife.BindView; | |
import butterknife.ButterKnife; | |
import io.github.project_travel_mate.R; | |
import io.github.project_travel_mate.destinations.offlinedata.OfflineData; | |
import io.github.project_travel_mate.destinations.offlinedata.OfflineDataSource; | |
import objects.City; | |
import utils.GeopointsConverter; | |
import utils.Utils; | |
import static utils.Constants.EXTRA_MESSAGE_CITY_OBJECT; | |
public class CityMapActivity extends AppCompatActivity { | |
@BindView(R.id.mv_city_map) | |
MapView cityMap; | |
@BindView(R.id.fab_save_map) | |
FloatingActionButton saveMap; | |
@Inject | |
OfflineDataSource offlineDataSource; | |
public static Intent getStartIntent(Context context, City city) { | |
return new Intent(context, CityMapActivity.class) | |
.putExtra(EXTRA_MESSAGE_CITY_OBJECT, city); | |
} | |
@Override | |
protected void onCreate(@Nullable Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_city_map); | |
ButterKnife.bind(this); | |
final City mCity = (City) getIntent().getSerializableExtra(EXTRA_MESSAGE_CITY_OBJECT); | |
setTitle(mCity.mNickname); | |
cityMap.setBuiltInZoomControls(false); | |
cityMap.setMultiTouchControls(true); | |
cityMap.setTilesScaledToDpi(true); | |
cityMap.setMinZoomLevel(14.0); | |
cityMap.setMaxZoomLevel(29.0); | |
if (Utils.isNetworkConnected(this)) { | |
cityMap.setUseDataConnection(true); | |
} else { | |
cityMap.setUseDataConnection(false); | |
saveMap.hide(); | |
} | |
cityMap.getController().setZoom(14.0); | |
final double latitude = Double.parseDouble(mCity.getLatitude()); | |
final double longitude = Double.parseDouble(mCity.getLongitude()); | |
GeoPoint cityPoint = new GeoPoint(latitude, longitude); | |
cityMap.getController().setCenter(cityPoint); | |
final ArrayList<GeoPoint> points = new ArrayList<>(); | |
points.add(cityPoint); | |
saveMap.setOnClickListener(v -> { | |
CacheManager manager = new CacheManager(cityMap); | |
manager.downloadAreaAsync(this, points, 14, 29); | |
OfflineData offlineMaps = new OfflineData( this, cityPoint, 14, 29); | |
offlineDataSource.insertMap(offlineMaps); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment