Skip to content

Commit

Permalink
Open main activity on alarm dismiss
Browse files Browse the repository at this point in the history
  • Loading branch information
Arjun committed Oct 20, 2017
1 parent 7e8a1d4 commit 6a56156
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 29 deletions.
5 changes: 3 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
package="in.arjsna.mapsalarm">

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.VIBRATE"/>

<application
Expand All @@ -28,7 +28,8 @@
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key"/>

<activity android:name=".locationalarm.LocationAlarmActivity">
<activity android:name=".locationalarm.LocationAlarmActivity"
android:launchMode="singleTop">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>

Expand Down
37 changes: 33 additions & 4 deletions app/src/main/java/in/arjsna/mapsalarm/alarm/AlarmActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,27 @@

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.os.PowerManager;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.TextView;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.CircleOptions;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.jakewharton.rxbinding2.view.RxView;
import in.arjsna.mapsalarm.R;
import in.arjsna.mapsalarm.bgservice.LocationAwareService;
import in.arjsna.mapsalarm.db.CheckPoint;
import in.arjsna.mapsalarm.locationalarm.LocationAlarmActivity;
import in.arjsna.mapsalarm.mvpbase.BaseActivity;
import javax.inject.Inject;

Expand All @@ -29,6 +35,7 @@ public class AlarmActivity extends BaseActivity implements AlarmMVPContract.IAla
private View dismissButton;

private GoogleMap googleMap;
private TextView checkPointName;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -39,6 +46,14 @@ protected void onCreate(Bundle savedInstanceState) {
mWakeLock.acquire(2 * 60 * 1000L);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
window.setStatusBarColor(Color.TRANSPARENT);
}

setContentView(R.layout.activity_alarm);
if (getActivityComponent() != null) {
getActivityComponent().inject(this);
Expand All @@ -65,8 +80,7 @@ private void bindEvents() {

private void initViews() {
dismissButton = findViewById(R.id.dismiss_btn);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
checkPointName = findViewById(R.id.check_point_name_tv);
alarmPresenter.onViewInitialised();
}

Expand All @@ -80,6 +94,10 @@ public void loadMap() {
@Override public void stopRinging() {
Intent stopIntent = new Intent(AlarmActivity.this, LocationAwareService.class);
stopService(stopIntent);
Intent locationAlarmIntent = new Intent(AlarmActivity.this, LocationAlarmActivity.class);
locationAlarmIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(locationAlarmIntent);
finish();
}

@Override protected void onDestroy() {
Expand All @@ -95,10 +113,21 @@ public void loadMap() {
@Override
public void setMarkerOnMap(CheckPoint checkPoint) {
if (googleMap != null) {
LatLng latLng = new LatLng(checkPoint.getLatitude(), checkPoint.getLongitude());
googleMap.addMarker(new MarkerOptions().position(
new LatLng(checkPoint.getLatitude(), checkPoint.getLongitude()))
latLng)
.draggable(false)
.icon(BitmapDescriptorFactory.fromResource(R.drawable.flag)));
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latLng, 15), 10, null);
googleMap.addCircle(new CircleOptions().center(latLng)
.strokeWidth(5)
.strokeColor(getResources().getColor(R.color.cardview_dark_background))
.radius(500));
}
}

@Override
public void setCheckPointName(String name) {
checkPointName.setText(name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ interface IAlarmView extends IMVPView {
void loadMap();

void setMarkerOnMap(CheckPoint checkPoint);

void setCheckPointName(String name);
}

interface IAlarmPresenter<V extends IAlarmView> extends IMVPPresenter<V> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ public AlarmPresenter(@ActivityContext Context context,

@Override public void onMapReady() {
getView().setMarkerOnMap(checkPoint);
getView().setCheckPointName(checkPoint.getName());
}
}
39 changes: 16 additions & 23 deletions app/src/main/res/layout/activity_alarm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,6 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="in.arjsna.mapsalarm.alarm.AlarmActivity">

<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_height="wrap_content"
android:layout_width="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
android:theme="@style/AppTheme.AppBarOverlay">

<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>
<android.support.v7.widget.CardView
android:id="@+id/alarm_view_layout"
android:layout_width="0dp"
Expand All @@ -40,15 +22,27 @@
android:layout_height="wrap_content"
>
<TextView
android:id="@+id/alarm_label"
android:id="@+id/check_point_name_tv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="0dp"
android:gravity="center"
android:textSize="18sp"
android:textSize="16sp"
android:textColor="@color/white"
android:text="@string/location_reached"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/alarm_label"
app:layout_constraintRight_toLeftOf="@+id/vertical_divider"/>
<TextView
android:id="@+id/alarm_label"
android:layout_width="0dp"
android:layout_height="0dp"
android:gravity="center"
android:textSize="16sp"
android:textColor="@color/white"
android:text="@string/location_reached"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@+id/check_point_name_tv"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintRight_toLeftOf="@+id/vertical_divider"/>
<View
Expand Down Expand Up @@ -83,6 +77,5 @@
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/app_bar_layout"
app:liteMode="true"/>
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>

0 comments on commit 6a56156

Please sign in to comment.