diff options
author | Joey <joey@lineageos.org> | 2018-05-19 17:14:02 +0200 |
---|---|---|
committer | Joey <joey@lineageos.org> | 2018-05-21 14:42:21 +0200 |
commit | 4e987baa75d9fa05d38f2a14c9792f384608dd8e (patch) | |
tree | 087198918ad86eef473b142a8c366b6b2f638050 /src/com/android/launcher3/Utilities.java | |
parent | 04d024e27af8f820ceca1d70962fcc60a2de2902 (diff) | |
download | android_packages_apps_Trebuchet-4e987baa75d9fa05d38f2a14c9792f384608dd8e.tar.gz android_packages_apps_Trebuchet-4e987baa75d9fa05d38f2a14c9792f384608dd8e.tar.bz2 android_packages_apps_Trebuchet-4e987baa75d9fa05d38f2a14c9792f384608dd8e.zip |
Trebuchet: improve predictive apps
- Store data in a sql db
- Categorize app launch between
- Day
- Night
- Headphones
The suggestions will change on the go basing on
whether an headset is plugged in or it's day or night
Change-Id: Ic9d8dd4dafbb1a56157140119df71efd6fb4349a
Signed-off-by: Joey <joey@lineageos.org>
Diffstat (limited to 'src/com/android/launcher3/Utilities.java')
-rw-r--r-- | src/com/android/launcher3/Utilities.java | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index e0ef90c3f..453b466d2 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -32,6 +32,8 @@ import android.graphics.Color; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Rect; +import android.media.AudioDeviceInfo; +import android.media.AudioManager; import android.os.Build; import android.os.Bundle; import android.os.DeadObjectException; @@ -58,6 +60,7 @@ import java.io.Closeable; import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.Calendar; import java.util.Collection; import java.util.HashSet; import java.util.Locale; @@ -132,6 +135,9 @@ public final class Utilities { private static final int GRID_ROW_VALUE_DEFAULT = 4; private static final int GRID_COLUMN_VALUE_DEFAULT = 5; + private static final int SUGGESTIONS_DAY_START = 5; + private static final int SUGGESTIONS_DAY_END = 21; + public static boolean isPropertyEnabled(String propertyName) { return Log.isLoggable(propertyName, Log.VERBOSE); } @@ -710,4 +716,30 @@ public final class Utilities { SharedPreferences prefs = getPrefs(context.getApplicationContext()); return prefs.getBoolean(SettingsActivity.KEY_WORKSPACE_EDIT, true); } + + public static boolean hasHeadset(Context context) { + AudioManager manager = context.getSystemService(AudioManager.class); + if (manager == null) { + return false; + } + + AudioDeviceInfo[] devices = manager.getDevices(AudioManager.GET_DEVICES_OUTPUTS); + for (AudioDeviceInfo device : devices) { + switch (device.getType()) { + case AudioDeviceInfo.TYPE_BLUETOOTH_A2DP: + case AudioDeviceInfo.TYPE_USB_HEADSET: + case AudioDeviceInfo.TYPE_WIRED_HEADPHONES: + case AudioDeviceInfo.TYPE_WIRED_HEADSET: + return true; + } + } + + return false; + } + + public static boolean isDayTime() { + Calendar calendar = Calendar.getInstance(); + int hours = calendar.get(Calendar.HOUR_OF_DAY); + return hours > SUGGESTIONS_DAY_START && hours < SUGGESTIONS_DAY_END; + } } |