Skip to content

Commit

Permalink
Update dependencies, switch toast to notification
Browse files Browse the repository at this point in the history
  • Loading branch information
pluscubed committed Jan 18, 2018
1 parent b69af55 commit 0f3ea33
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 42 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
![Icon](./app/src/main/res/mipmap-mdpi/ic_launcher.png) Velociraptor
=========
Floating speed limit monitor for Android, using OpenStreetMap and HERE Maps APIs.
Floating speed limit monitor for Android with speedometer and warning features.

[![Get it on Google Play](http://i.imgur.com/PeDVOwW.png)](https://play.google.com/store/apps/details?id=com.pluscubed.velociraptor)

Copyright (C) 2016 Daniel Ciao
Copyright (C) 2018 Daniel Ciao

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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,14 @@ public static List<LimitCacheWay> fromResponse(LimitResponse response) {
double clat = (coord1.lat + coord2.lat) / 2;
double clon = (coord1.lon + coord2.lon) / 2;

LimitCacheWay way = new AutoValue_LimitCacheWay(clat, clon,
(long) response.speedLimit(), response.timestamp(),
coord1.lat, coord1.lon, coord2.lat, coord2.lon, response.roadName(), (long) response.origin());
LimitCacheWay way = new AutoValue_LimitCacheWay(
clat, clon,
(long) response.speedLimit(),
response.timestamp(),
coord1.lat, coord1.lon, coord2.lat, coord2.lon,
response.roadName(),
(long) response.origin()
);
ways.add(way);
}
return ways;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ private void inflateDebugging() {
try {
mWindowManager.addView(mDebuggingText, debuggingParams);
} catch (Exception e) {
mService.showToast("Velociraptor error: " + e.getMessage());
}
}

Expand Down Expand Up @@ -122,7 +121,6 @@ private void inflateMonitor() {
try {
mWindowManager.addView(mFloatingView, params);
} catch (Exception e) {
mService.showToast("Velociraptor error: " + e);
}
mFloatingView.setOnTouchListener(new FloatingOnTouchListener());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.annotation.SuppressLint;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Context;
Expand All @@ -12,13 +13,11 @@
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Build;
import android.os.Handler;
import android.os.IBinder;
import android.os.Looper;
import android.provider.Settings;
import android.support.annotation.Nullable;
import android.support.v4.app.NotificationCompat;
import android.widget.Toast;

import com.android.billingclient.api.Purchase;
import com.google.android.gms.location.FusedLocationProviderClient;
Expand Down Expand Up @@ -60,9 +59,8 @@ public class LimitService extends Service {
public static final int VIEW_FLOATING = 0;

public static final String EXTRA_HIDE_LIMIT = "com.pluscubed.velociraptor.HIDE_LIMIT";

public static final int NOTIFICATION_WARNING = 192;
private static final int NOTIFICATION_FOREGROUND = 303;

private int speedLimitViewType = -1;
private LimitView speedLimitView;

Expand Down Expand Up @@ -160,7 +158,6 @@ public void onLocationResult(LocationResult locationResult) {
try {
fusedLocationClient.requestLocationUpdates(locationRequest, locationCallback, Looper.myLooper());
} catch (SecurityException unlikely) {
showToast("Velociraptor cannot obtain location");
}

billingManager = new BillingManager(this, new BillingManager.BillingUpdatesListener() {
Expand Down Expand Up @@ -221,29 +218,29 @@ private void startNotification() {
private boolean prequisitesMet() {
if (!PrefUtils.isTermsAccepted(this)) {
if (BuildConfig.VERSION_CODE > PrefUtils.getVersionCode(this)) {
showToast(getString(R.string.terms_warning));
showWarningNotification(getString(R.string.terms_warning));
}
stopSelf();
return false;
}

if (!Utils.isLocationPermissionGranted(LimitService.this)
|| (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(this))) {
showToast(getString(R.string.permissions_warning));
showWarningNotification(getString(R.string.permissions_warning));
stopSelf();
return false;
}

LocationManager manager = (LocationManager) getSystemService(LOCATION_SERVICE);
if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
showToast(getString(R.string.location_settings_warning));
showWarningNotification(getString(R.string.location_settings_warning));
}

ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting();
if (!isConnected) {
showToast(getString(R.string.network_warning));
showWarningNotification(getString(R.string.network_warning));
}
return true;
}
Expand Down Expand Up @@ -390,9 +387,22 @@ private int convertToUiSpeed(int kmhSpeed) {
return speed;
}

void showToast(final String string) {
Handler handler = new Handler(Looper.getMainLooper());
handler.post(() -> Toast.makeText(LimitService.this.getApplicationContext(), string, Toast.LENGTH_LONG).show());
void showWarningNotification(final String string) {
Intent notificationIntent = new Intent(this, SettingsActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, PENDING_SETTINGS, notificationIntent, PendingIntent.FLAG_CANCEL_CURRENT);

NotificationUtils.initChannels(this);
Notification notification = new NotificationCompat.Builder(this, NotificationUtils.CHANNEL_WARNINGS)
.setContentTitle(getString(R.string.grant_permission))
.setContentText(string)
.setPriority(Notification.PRIORITY_MIN)
.setSmallIcon(R.drawable.ic_speedometer_notif)
.setContentIntent(pendingIntent)
.setStyle(new NotificationCompat.BigTextStyle().bigText(string))
.build();

NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(NOTIFICATION_WARNING, notification);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.location.Location;
import android.net.Uri;
import android.os.Build;
Expand All @@ -18,6 +19,7 @@
import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.content.res.AppCompatResources;
import android.support.v7.widget.SwitchCompat;
import android.support.v7.widget.Toolbar;
import android.text.Html;
Expand Down Expand Up @@ -148,6 +150,8 @@ public class SettingsActivity extends AppCompatActivity {
@BindView(R.id.tomtom_editdata)
Button tomtomEditDataButton;

@BindView(R.id.osm_title)
TextView osmTitle;
@BindView(R.id.osm_editdata)
Button osmEditDataButton;
@BindView(R.id.osm_donate)
Expand Down Expand Up @@ -436,6 +440,12 @@ public void onNothingSelected(AdapterView<?> parent) {
showTermsDialog();
}

Drawable checkIcon = AppCompatResources.getDrawable(this, R.drawable.ic_done_green_20dp);
Drawable crossIcon = AppCompatResources.getDrawable(this, R.drawable.ic_cross_red_20dp);
osmTitle.setCompoundDrawablesWithIntrinsicBounds(null, null, checkIcon, null);
hereTitle.setCompoundDrawablesWithIntrinsicBounds(null, null, crossIcon, null);
tomtomTitle.setCompoundDrawablesWithIntrinsicBounds(null, null, crossIcon, null);

billingManager = new BillingManager(this, new BillingManager.BillingUpdatesListener() {
@Override
public void onBillingClientSetupFinished() {
Expand Down Expand Up @@ -490,11 +500,13 @@ private void setSubscriptionState(Button button, TextView title, boolean subscri
if (subscribed) {
button.setEnabled(false);
button.setText(R.string.subscribed);
title.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_done_green_20dp, 0);
Drawable checkIcon = AppCompatResources.getDrawable(this, R.drawable.ic_done_green_20dp);
title.setCompoundDrawablesWithIntrinsicBounds(null, null, checkIcon, null);
} else {
button.setEnabled(true);
button.setText(R.string.subscribe);
title.setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_cross_red_20dp, 0);
Drawable crossIcon = AppCompatResources.getDrawable(this, R.drawable.ic_cross_red_20dp);
title.setCompoundDrawablesWithIntrinsicBounds(null, null, crossIcon, null);
}
}

Expand Down Expand Up @@ -548,7 +560,7 @@ public void showSupportDialog() {
String content = getString(R.string.support_dev_dialog);

MaterialDialog.Builder builder = new MaterialDialog.Builder(this)
.icon(Utils.getVectorDrawableCompat(this, R.drawable.ic_favorite_black_24dp))
.icon(AppCompatResources.getDrawable(this, R.drawable.ic_favorite_black_24dp))
.title(R.string.support_development)
.content(Html.fromHtml(content));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import android.support.v4.graphics.drawable.DrawableCompat;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.content.res.AppCompatResources;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
Expand All @@ -25,7 +26,6 @@
import com.pluscubed.velociraptor.R;
import com.pluscubed.velociraptor.detection.AppDetectionService;
import com.pluscubed.velociraptor.utils.PrefUtils;
import com.pluscubed.velociraptor.utils.Utils;

import java.util.ArrayList;
import java.util.HashSet;
Expand Down Expand Up @@ -187,7 +187,7 @@ protected void onDestroy() {
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_app_selection, menu);
MenuItem item = menu.findItem(R.id.menu_app_selection_maps);
Drawable drawable = Utils.getVectorDrawableCompat(this, R.drawable.ic_map_white_24dp).mutate();
Drawable drawable = AppCompatResources.getDrawable(this, R.drawable.ic_map_white_24dp).mutate();
drawable = DrawableCompat.wrap(drawable);
if (mMapsOnly) {
DrawableCompat.setTint(drawable, ContextCompat.getColor(this, R.color.colorAccent));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class NotificationUtils {

public static final String CHANNEL_TOGGLES = "toggles";
public static final String CHANNEL_RUNNING = "running";
public static final String CHANNEL_WARNINGS = "warnings";

public static void initChannels(Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
Expand All @@ -31,5 +32,12 @@ public static void initChannels(Context context) {
NotificationManager.IMPORTANCE_LOW
);
notificationManager.createNotificationChannel(channel);

channel = new NotificationChannel(
CHANNEL_WARNINGS,
context.getString(R.string.channel_warnings),
NotificationManager.IMPORTANCE_LOW
);
notificationManager.createNotificationChannel(channel);
}
}
9 changes: 0 additions & 9 deletions app/src/main/java/com/pluscubed/velociraptor/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,11 @@
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.drawable.Drawable;
import android.media.AudioManager;
import android.media.ToneGenerator;
import android.os.Build;
import android.os.Handler;
import android.provider.Settings;
import android.support.annotation.DrawableRes;
import android.support.graphics.drawable.VectorDrawableCompat;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;

Expand Down Expand Up @@ -51,12 +48,6 @@ public static boolean isAccessibilityServiceEnabled(Context context, Class<? ext
return false;
}

public static Drawable getVectorDrawableCompat(Context context, @DrawableRes int drawable) {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ?
ContextCompat.getDrawable(context, drawable) :
VectorDrawableCompat.create(context.getResources(), drawable, context.getTheme());
}

public static int convertDpToPx(Context context, float dp) {
return (int) (dp * context.getResources().getDisplayMetrics().density + 0.5f);
}
Expand Down
4 changes: 1 addition & 3 deletions app/src/main/res/layout/activity_settings_providers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
android:paddingTop="16dp">

<TextView
android:id="@+id/osm_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="8dp"
android:drawableRight="@drawable/ic_done_green_20dp"
android:paddingEnd="8dp"
android:paddingRight="8dp"
android:text="@string/openstreetmap"
Expand Down Expand Up @@ -131,7 +131,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="8dp"
android:drawableRight="@drawable/ic_cross_red_20dp"
android:paddingEnd="8dp"
android:paddingRight="8dp"
android:text="@string/tomtom_provider"
Expand Down Expand Up @@ -212,7 +211,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="8dp"
android:drawableRight="@drawable/ic_cross_red_20dp"
android:paddingEnd="8dp"
android:paddingRight="8dp"
android:text="@string/here_provider"
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/raw/changelog.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
</style>
</head>
<body>
<h4>v1.6.5 - 1/17/18</h4>
<ul>
<li>Fix crashing on <5.0</li>
</ul>
<br />

<h4>v1.6.4 - 1/14/18</h4>
<ul>
<li>Fix mph speed limits from HERE & TomTom</li>
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/res/raw/third_party_license_metadata
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@
70269:46 leakcanary-analyzer
70317:46 haha
70365:46 leakcanary-watcher
70413:46 kotlin-annotation-processing-gradle
70461:46 kotlin-compiler-embeddable
70509:46 kotlin-reflect
70557:46 kotlin-script-runtime
70413:46 leakcanary-android-no-op
70461:46 kotlin-annotation-processing-gradle
70509:46 kotlin-compiler-embeddable
70557:46 kotlin-reflect
70605:46 kotlin-script-runtime
1 change: 1 addition & 0 deletions app/src/main/res/raw/third_party_licenses
Original file line number Diff line number Diff line change
Expand Up @@ -1347,3 +1347,4 @@ http://www.apache.org/licenses/LICENSE-2.0.txt
http://www.apache.org/licenses/LICENSE-2.0.txt
http://www.apache.org/licenses/LICENSE-2.0.txt
http://www.apache.org/licenses/LICENSE-2.0.txt
http://www.apache.org/licenses/LICENSE-2.0.txt
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<string name="grant_permission">Grant permission</string>
<string name="enable_location_desc">Allow Velociraptor to access your location</string>

<string name="permissions_warning">Velociraptor doesn\'t have adequate permissions. Please open the app to grant them.</string>
<string name="permissions_warning">Velociraptor doesn\'t have location permissions. Please open the app to grant them.</string>
<string name="location_settings_warning">GPS is not turned on. Please enable for Velociraptor\'s speed limit monitor.</string>
<string name="network_warning">Network is not connected. Velociraptor requires Internet connectivity to fetch the speed limit.</string>

Expand Down Expand Up @@ -182,5 +182,6 @@

<!--Notification Channels-->
<string name="channel_toggles">Show/hide toggles</string>
<string name="channel_warnings">Warnings</string>

</resources>
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apply plugin: 'com.github.ben-manes.versions'

buildscript {
ext.kotlin_version = '1.2.10'
ext.kotlin_version = '1.2.20'
repositories {
jcenter()
google()
Expand Down

0 comments on commit 0f3ea33

Please sign in to comment.