From 0f3ea3351072240530c4d9887114a0fd4478ded5 Mon Sep 17 00:00:00 2001 From: plusCubed Date: Wed, 17 Jan 2018 22:22:23 -0800 Subject: [PATCH] Update dependencies, switch toast to notification --- README.md | 4 +-- .../velociraptor/cache/LimitCacheWay.java | 11 ++++-- .../velociraptor/limit/FloatingView.java | 2 -- .../velociraptor/limit/LimitService.java | 34 ++++++++++++------- .../settings/SettingsActivity.java | 18 ++++++++-- .../appselection/AppSelectionActivity.java | 4 +-- .../velociraptor/utils/NotificationUtils.java | 8 +++++ .../pluscubed/velociraptor/utils/Utils.java | 9 ----- .../layout/activity_settings_providers.xml | 4 +-- app/src/main/res/raw/changelog.html | 6 ++++ .../main/res/raw/third_party_license_metadata | 9 ++--- app/src/main/res/raw/third_party_licenses | 1 + app/src/main/res/values/strings.xml | 3 +- build.gradle | 2 +- 14 files changed, 73 insertions(+), 42 deletions(-) diff --git a/README.md b/README.md index 3595bf2..56d4df4 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/app/src/main/java/com/pluscubed/velociraptor/cache/LimitCacheWay.java b/app/src/main/java/com/pluscubed/velociraptor/cache/LimitCacheWay.java index f24ed8d..308f3b5 100644 --- a/app/src/main/java/com/pluscubed/velociraptor/cache/LimitCacheWay.java +++ b/app/src/main/java/com/pluscubed/velociraptor/cache/LimitCacheWay.java @@ -24,9 +24,14 @@ public static List 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; diff --git a/app/src/main/java/com/pluscubed/velociraptor/limit/FloatingView.java b/app/src/main/java/com/pluscubed/velociraptor/limit/FloatingView.java index 912a521..ec80131 100644 --- a/app/src/main/java/com/pluscubed/velociraptor/limit/FloatingView.java +++ b/app/src/main/java/com/pluscubed/velociraptor/limit/FloatingView.java @@ -83,7 +83,6 @@ private void inflateDebugging() { try { mWindowManager.addView(mDebuggingText, debuggingParams); } catch (Exception e) { - mService.showToast("Velociraptor error: " + e.getMessage()); } } @@ -122,7 +121,6 @@ private void inflateMonitor() { try { mWindowManager.addView(mFloatingView, params); } catch (Exception e) { - mService.showToast("Velociraptor error: " + e); } mFloatingView.setOnTouchListener(new FloatingOnTouchListener()); diff --git a/app/src/main/java/com/pluscubed/velociraptor/limit/LimitService.java b/app/src/main/java/com/pluscubed/velociraptor/limit/LimitService.java index d41b8c4..fe79061 100644 --- a/app/src/main/java/com/pluscubed/velociraptor/limit/LimitService.java +++ b/app/src/main/java/com/pluscubed/velociraptor/limit/LimitService.java @@ -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; @@ -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; @@ -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; @@ -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() { @@ -221,7 +218,7 @@ 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; @@ -229,21 +226,21 @@ private boolean prequisitesMet() { 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; } @@ -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 diff --git a/app/src/main/java/com/pluscubed/velociraptor/settings/SettingsActivity.java b/app/src/main/java/com/pluscubed/velociraptor/settings/SettingsActivity.java index 039af08..df1b937 100644 --- a/app/src/main/java/com/pluscubed/velociraptor/settings/SettingsActivity.java +++ b/app/src/main/java/com/pluscubed/velociraptor/settings/SettingsActivity.java @@ -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; @@ -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; @@ -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) @@ -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() { @@ -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); } } @@ -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)); diff --git a/app/src/main/java/com/pluscubed/velociraptor/settings/appselection/AppSelectionActivity.java b/app/src/main/java/com/pluscubed/velociraptor/settings/appselection/AppSelectionActivity.java index 3d9f898..f65cf75 100644 --- a/app/src/main/java/com/pluscubed/velociraptor/settings/appselection/AppSelectionActivity.java +++ b/app/src/main/java/com/pluscubed/velociraptor/settings/appselection/AppSelectionActivity.java @@ -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; @@ -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; @@ -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)); diff --git a/app/src/main/java/com/pluscubed/velociraptor/utils/NotificationUtils.java b/app/src/main/java/com/pluscubed/velociraptor/utils/NotificationUtils.java index 2c881aa..5c2b044 100644 --- a/app/src/main/java/com/pluscubed/velociraptor/utils/NotificationUtils.java +++ b/app/src/main/java/com/pluscubed/velociraptor/utils/NotificationUtils.java @@ -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) { @@ -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); } } diff --git a/app/src/main/java/com/pluscubed/velociraptor/utils/Utils.java b/app/src/main/java/com/pluscubed/velociraptor/utils/Utils.java index 14c7a5e..f7b85b9 100644 --- a/app/src/main/java/com/pluscubed/velociraptor/utils/Utils.java +++ b/app/src/main/java/com/pluscubed/velociraptor/utils/Utils.java @@ -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; @@ -51,12 +48,6 @@ public static boolean isAccessibilityServiceEnabled(Context context, Class= 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); } diff --git a/app/src/main/res/layout/activity_settings_providers.xml b/app/src/main/res/layout/activity_settings_providers.xml index 16129b5..52ab8c0 100644 --- a/app/src/main/res/layout/activity_settings_providers.xml +++ b/app/src/main/res/layout/activity_settings_providers.xml @@ -40,10 +40,10 @@ android:paddingTop="16dp"> +

v1.6.5 - 1/17/18

+
    +
  • Fix crashing on <5.0
  • +
+
+

v1.6.4 - 1/14/18

  • Fix mph speed limits from HERE & TomTom
  • diff --git a/app/src/main/res/raw/third_party_license_metadata b/app/src/main/res/raw/third_party_license_metadata index e9e9891..3e187fc 100644 --- a/app/src/main/res/raw/third_party_license_metadata +++ b/app/src/main/res/raw/third_party_license_metadata @@ -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 diff --git a/app/src/main/res/raw/third_party_licenses b/app/src/main/res/raw/third_party_licenses index 87d940e..85d3a1a 100644 --- a/app/src/main/res/raw/third_party_licenses +++ b/app/src/main/res/raw/third_party_licenses @@ -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 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 826292b..085b15e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -32,7 +32,7 @@ Grant permission Allow Velociraptor to access your location - Velociraptor doesn\'t have adequate permissions. Please open the app to grant them. + Velociraptor doesn\'t have location permissions. Please open the app to grant them. GPS is not turned on. Please enable for Velociraptor\'s speed limit monitor. Network is not connected. Velociraptor requires Internet connectivity to fetch the speed limit. @@ -182,5 +182,6 @@ Show/hide toggles + Warnings diff --git a/build.gradle b/build.gradle index 0743130..28fabbe 100644 --- a/build.gradle +++ b/build.gradle @@ -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()