Skip to content

Commit

Permalink
current location update button added
Browse files Browse the repository at this point in the history
  • Loading branch information
Arjun committed Oct 20, 2017
1 parent 6a56156 commit ea8ffb7
Show file tree
Hide file tree
Showing 11 changed files with 53 additions and 58 deletions.
8 changes: 1 addition & 7 deletions app/src/main/java/in/arjsna/mapsalarm/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public class MainActivity extends AppCompatActivity
private GoogleMap mMap;
private boolean mPermissionDenied = false;
private LocationManager locationManager;
private FrameLayout mMapHolderLayout;

@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -45,16 +44,11 @@ public class MainActivity extends AppCompatActivity
(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
supportMapFragment.getMapAsync(this);
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
mMapHolderLayout = findViewById(R.id.map_holder_layout);
bindEvents();
}

private void bindEvents() {
mMapHolderLayout.setOnTouchListener(new View.OnTouchListener() {
@Override public boolean onTouch(View v, MotionEvent event) {
return false;
}
});
// TODO: 20/10/17 bindevents
}

private void getPermissionAndEnableLocation() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.location.Location;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.AlertDialog;
import android.view.LayoutInflater;
Expand Down Expand Up @@ -36,8 +37,8 @@
import javax.inject.Inject;

public class LocationAlarmActivity extends BaseActivity
implements OnMapReadyCallback, GoogleMap.OnMyLocationButtonClickListener,
GoogleMap.OnMyLocationClickListener, LocationAlarmMVPContract.ILocationAlarmView {
implements OnMapReadyCallback,
LocationAlarmMVPContract.ILocationAlarmView {
private static final int LOCATION_PERMISSION_REQUEST_CODE = 1;
private static final int REQUEST_CHECK_SETTINGS = 2;

Expand All @@ -48,8 +49,11 @@ public class LocationAlarmActivity extends BaseActivity
@Inject
public LocationAlarmMVPContract.ILocationPresenter<LocationAlarmMVPContract.ILocationAlarmView>
locationPresenter;
@Inject @ActivityContext public Context context;
@Inject
@ActivityContext
public Context context;
private Location currentLocation;
private FloatingActionButton currentLocationBtn;

@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -65,6 +69,7 @@ private void initView() {
//Toolbar toolbar = findViewById(R.id.toolbar);
//setSupportActionBar(toolbar);
locationPin = findViewById(R.id.location_pin);
currentLocationBtn = findViewById(R.id.my_location_btn);
SupportMapFragment supportMapFragment =
(SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);
supportMapFragment.getMapAsync(this);
Expand All @@ -73,6 +78,7 @@ private void initView() {

private void bindEvents() {
locationPin.setOnClickListener(v -> locationPresenter.onLocationPinClicked());
currentLocationBtn.setOnClickListener(v -> locationPresenter.onMyLocationBtnClicked());
}

@Override public void showAddCheckPointDialog() {
Expand Down Expand Up @@ -136,28 +142,17 @@ private void getPermissionAndEnableLocation() {
PermissionUtils.requestPermission(this, LOCATION_PERMISSION_REQUEST_CODE,
Manifest.permission.ACCESS_FINE_LOCATION, true);
} else if (mMap != null) {
mMap.setMyLocationEnabled(true);
locationPresenter.onLocationPermissionGranted();
}
}

@Override public boolean onMyLocationButtonClick() {
return false;
}

@Override public void onMyLocationClick(@NonNull Location location) {
Toast.makeText(this, "Current location:\n" + location, Toast.LENGTH_LONG).show();
}

@Override public void onMapReady(GoogleMap googleMap) {
initialiseMap(googleMap);
getPermissionAndEnableLocation();
}

private void initialiseMap(GoogleMap googleMap) {
mMap = googleMap;
mMap.setOnMyLocationButtonClickListener(this);
mMap.setOnMyLocationClickListener(this);
}

@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,7 @@ interface ILocationPresenter<V extends ILocationAlarmView> extends IMVPPresenter
void onLocationPinClicked();

void onSetCheckPoint(String checkpointName, double latitude, double longitude);

void onMyLocationBtnClicked();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class LocationAlarmPresenter<V extends LocationAlarmMVPContract.ILocation
}

@Override public void onLocationPermissionGranted() {
locationProvider.getLastLocation(location -> getView().updateCurrentLocation(location));
updateCurrentLocation();
addCheckPointMarkers();
}

Expand Down Expand Up @@ -77,6 +77,14 @@ private void addCheckPointMarkers() {
});
}

@Override public void onMyLocationBtnClicked() {
updateCurrentLocation();
}

private void updateCurrentLocation() {
locationProvider.getLastLocation(location -> getView().updateCurrentLocation(location));
}

private void insertCheckPoint(CheckPoint checkPoint) {
getCheckPointDataSource().insertNewCheckPoint(checkPoint)
.subscribeOn(Schedulers.io())
Expand Down
Binary file added app/src/main/res/drawable-hdpi/center.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/center.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/center.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxhdpi/center.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xxxhdpi/center.9.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
66 changes: 31 additions & 35 deletions app/src/main/res/layout/activity_location_alarm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,45 @@
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="in.arjsna.mapsalarm.locationalarm.LocationAlarmActivity"
>

<!--<android.support.design.widget.AppBarLayout-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="wrap_content"-->
<!--android:theme="@style/AppTheme.AppBarOverlay"-->
<!--&gt;-->

<!--<android.support.v7.widget.Toolbar-->
<!--android:id="@+id/toolbar"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="?attr/actionBarSize"-->
<!--android:background="?attr/colorPrimary"-->
<!--app:popupTheme="@style/AppTheme.PopupOverlay"-->
<!--/>-->

<!--</android.support.design.widget.AppBarLayout>-->
<FrameLayout
android:id="@+id/map_holder_layout"
<fragment
class="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/map"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
/>
<ImageView
android:id="@+id/location_pin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="15dp"
android:src="@drawable/map_pin"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
tools:context="in.arjsna.mapsalarm.locationalarm.LocationAlarmActivity"
>
<fragment
class="com.google.android.gms.maps.SupportMapFragment"
android:id="@+id/map"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<ImageView
android:id="@+id/location_pin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="15dp"
android:src="@drawable/map_pin"
/>
</FrameLayout>
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/my_location_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/center"
app:fabSize="mini"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintVertical_bias="0.9"
app:layout_constraintHorizontal_bias="0.9"
/>
</android.support.constraint.ConstraintLayout>
2 changes: 1 addition & 1 deletion app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="colorAccent">#FFFFFF</color>
<color name="grey">#AEAEAE</color>
<color name="white">#FFFFFF</color>
</resources>

0 comments on commit ea8ffb7

Please sign in to comment.