[2/5] OmniGears: Moving events into OmniBrain
Change-Id: I3a1b2b846e7c25145d7ead68ead67ef9317238ec
diff --git a/res/drawable/bg_app_chooser.xml b/res/drawable/bg_app_chooser.xml
deleted file mode 100644
index a79d829..0000000
--- a/res/drawable/bg_app_chooser.xml
+++ /dev/null
@@ -1,32 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-
-<!-- Copyright (C) 2016 The OmniROM Project
-
- 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
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- -->
-
-<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
- <item>
- <shape android:shape="rectangle" >
- <solid android:color="?android:attr/colorBackgroundFloating" />
- <corners android:radius="10dp" />
- </shape>
- </item>
- <item>
- <shape android:shape="rectangle" >
- <stroke android:width="1dp" android:color="@android:color/black" />
- <corners android:radius="10dp" />
- </shape>
- </item>
-</layer-list>
diff --git a/res/drawable/ic_chevron_left.xml b/res/drawable/ic_chevron_left.xml
deleted file mode 100644
index 26c7932..0000000
--- a/res/drawable/ic_chevron_left.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="24dp"
- android:height="24dp"
- android:tint="?android:attr/colorAccent"
- android:viewportHeight="24.0"
- android:viewportWidth="24.0">
- <path
- android:fillColor="#fff"
- android:pathData="M15.41,7.41L14,6l-6,6 6,6 1.41,-1.41L10.83,12z" />
-</vector>
diff --git a/res/drawable/ic_chevron_right.xml b/res/drawable/ic_chevron_right.xml
deleted file mode 100644
index d48ea37..0000000
--- a/res/drawable/ic_chevron_right.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-<vector xmlns:android="http://schemas.android.com/apk/res/android"
- android:width="24dp"
- android:height="24dp"
- android:tint="?android:attr/colorAccent"
- android:viewportHeight="24.0"
- android:viewportWidth="24.0">
- <path
- android:fillColor="#fff"
- android:pathData="M10,6L8.59,7.41 13.17,12l-4.58,4.59L10,18l6,-6z" />
-</vector>
diff --git a/res/layout/layout_floating_widget.xml b/res/layout/layout_floating_widget.xml
deleted file mode 100644
index 0009761..0000000
--- a/res/layout/layout_floating_widget.xml
+++ /dev/null
@@ -1,49 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-
-<!-- Copyright (C) 2016 The OmniROM Project
-
- 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
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- -->
-
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" >
-
- <RelativeLayout
- android:id="@+id/root_container"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- tools:ignore="UselessParent">
-
- <ScrollView
- android:id="@+id/verticalScroll"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_centerHorizontal="true"
- android:layout_centerVertical="true"
- android:layout_marginBottom="8dip"
- android:layout_marginTop="8dip"
- android:scrollbars="none">
-
- <LinearLayout
- android:id="@+id/selected_apps"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@drawable/bg_app_chooser"
- android:orientation="vertical"
- android:padding="@dimen/floating_widget_view_padding" />
- </ScrollView>
- </RelativeLayout>
-</FrameLayout>
diff --git a/res/values/custom_arrays.xml b/res/values/custom_arrays.xml
index 077b14c..decf6f3 100644
--- a/res/values/custom_arrays.xml
+++ b/res/values/custom_arrays.xml
@@ -1,4 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
+
<!-- Copyright (C) 2013 The OmniROM Project
Parts Copyright (C) 2012-2013 The CyanogenMod Project
@@ -618,16 +619,6 @@
<item>3</item>
</string-array>
- <string-array name="app_chooser_position_entries" translatable="false">
- <item>@string/app_chooser_left</item>
- <item>@string/app_chooser_right</item>
- </string-array>
-
- <string-array name="app_chooser_position_values" translatable="false">
- <item>0</item>
- <item>1</item>
- </string-array>
-
<string-array name="lockscreen_clock_style_entries" translatable="false">
<item>@string/clock_style_digital</item>
<item>@string/clock_style_analog</item>
diff --git a/res/values/custom_dimens.xml b/res/values/custom_dimens.xml
index bf8196b..57af2c0 100755
--- a/res/values/custom_dimens.xml
+++ b/res/values/custom_dimens.xml
@@ -21,6 +21,4 @@
<dimen name="color_preference_height">18dip</dimen>
<dimen name="drag_grip_ridge_size">6dp</dimen>
<dimen name="drag_grip_ridge_gap">4dp</dimen>
- <dimen name="floating_widget_view_padding">10dp</dimen>
- <dimen name="floating_widget_window_padding">10dp</dimen>
</resources>
diff --git a/res/values/custom_strings.xml b/res/values/custom_strings.xml
index d82181c..ef89228 100644
--- a/res/values/custom_strings.xml
+++ b/res/values/custom_strings.xml
@@ -692,27 +692,6 @@
<string name="resolve_failed_summary">Resolving app failed</string>
<string name="disabled_entry">Disabled</string>
- <string name="event_service_settings_title">Events</string>
- <string name="category_media_player_title">Media player</string>
- <string name="bt_a2dp_connect_app_list_title">Bluetooth A2DP connect</string>
- <string name="headset_connect_app_list_title">Wired headset connect</string>
- <string name="event_service_enabled_title">Enable event service</string>
- <string name="event_service_running">Service is running</string>
- <string name="event_service_stopped">Service is not running</string>
- <string name="category_media_player_info_title">App selection</string>
- <string name="media_player_autostart_title">Send media play event after start</string>
- <string name="media_player_music_active_title">Do not start event on playback</string>
- <string name="autorun_single_app_title">Autorun single app</string>
- <string name="autorun_single_app_summary">Dont show app selection dialog</string>
- <string name="bt_a2dp_connect_app_list_summary">App(s) to be listed when an A2DP event is triggered, such as connecting a Bluetooth headset</string>
- <string name="headset_connect_app_list_summary">App(s) to be listed when a wired headset is connected</string>
- <string name="app_chooser_left">Left</string>
- <string name="app_chooser_right">Right</string>
- <string name="app_chooser_timeout_title">App chooser dialog timeout</string>
- <string name="app_chooser_position_title">App chooser dialog position</string>
- <string name="wired_events_threshold_title">Wired headset event threshold</string>
- <string name="wired_events_threshold_summary">Ignore headset events if they are within threshold time</string>
-
<!-- Quick Pulldown-->
<string name="quick_pulldown_title">Quick pulldown</string>
<string name="quick_pulldown_summary">%1$s edge of the status bar pulls down Quick Settings</string>
@@ -805,4 +784,6 @@
<string name="lockscreen_digital_clock_bold_hour_summary"></string>
<string name="digital_clock_settings_title">Digital clock</string>
<string name="digital_clock_settings_summary">Style settings</string>
+
+ <string name="event_service_settings_title">Events</string>
</resources>
diff --git a/res/xml/event_service_settings.xml b/res/xml/event_service_settings.xml
deleted file mode 100644
index eb4fb58..0000000
--- a/res/xml/event_service_settings.xml
+++ /dev/null
@@ -1,116 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-
-<!-- Copyright (C) 2018 The OmniROM Project
-
- 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
- the Free Software Foundation, either version 2 of the License, or
- (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- -->
-
-<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:settings="http://schemas.android.com/apk/res-auto"
- android:key="event_service_settings"
- android:title="@string/event_service_settings_title">
-
- <SwitchPreference
- android:key="event_service_enabled"
- android:persistent="false"
- android:title="@string/event_service_enabled_title" />
-
- <PreferenceCategory
- android:key="category_media_player"
- android:title="@string/category_media_player_title">
-
- <Preference
- android:dependency="event_service_enabled"
- android:icon="@drawable/ic_info_outline_24dp"
- android:key="category_media_player_info"
- android:persistent="false"
- android:summary="@string/category_media_player_info_title" />
-
- <org.omnirom.omnilib.preference.AppMultiSelectListPreference
- android:dependency="event_service_enabled"
- android:icon="@drawable/ic_settings_bluetooth"
- android:key="bt_a2dp_connect_app_string"
- android:persistent="false"
- android:summary="@string/bt_a2dp_connect_app_list_summary"
- android:title="@string/bt_a2dp_connect_app_list_title" />
-
- <org.omnirom.omnilib.preference.ScrollAppsViewPreference
- android:dependency="event_service_enabled"
- android:key="a2dp_app_list"
- android:persistent="false"
- android:selectable="false" />
-
- <org.omnirom.omnilib.preference.AppMultiSelectListPreference
- android:dependency="event_service_enabled"
- android:icon="@drawable/ic_headset_24dp"
- android:key="headset_connect_app_string"
- android:persistent="false"
- android:summary="@string/headset_connect_app_list_summary"
- android:title="@string/headset_connect_app_list_title" />
-
- <org.omnirom.omnilib.preference.ScrollAppsViewPreference
- android:dependency="event_service_enabled"
- android:key="headset_app_list"
- android:persistent="false"
- android:selectable="false" />
-
- <SwitchPreference
- android:defaultValue="true"
- android:dependency="event_service_enabled"
- android:key="autorun_single_app"
- android:persistent="false"
- android:summary="@string/autorun_single_app_summary"
- android:title="@string/autorun_single_app_title" />
-
- <SwitchPreference
- android:defaultValue="true"
- android:dependency="event_service_enabled"
- android:key="media_player_music_active"
- android:persistent="false"
- android:title="@string/media_player_music_active_title" />
-
- <SwitchPreference
- android:dependency="event_service_enabled"
- android:key="media_player_autostart"
- android:persistent="false"
- android:title="@string/media_player_autostart_title" />
-
- <org.omnirom.omnilib.preference.SeekBarPreference
- android:dependency="event_service_enabled"
- android:key="app_chooser_timeout"
- android:max="60"
- android:persistent="false"
- android:title="@string/app_chooser_timeout_title"
- settings:min="0"
- settings:unitsRight="@string/unit_sec" />
-
- <ListPreference
- android:dependency="event_service_enabled"
- android:entries="@array/app_chooser_position_entries"
- android:entryValues="@array/app_chooser_position_values"
- android:key="app_chooser_position"
- android:persistent="false"
- android:title="@string/app_chooser_position_title" />
-
- <org.omnirom.omnilib.preference.SeekBarPreference
- android:dependency="event_service_enabled"
- android:key="wired_events_threshold"
- android:max="6"
- android:persistent="false"
- android:summary="@string/wired_events_threshold_summary"
- android:title="@string/wired_events_threshold_title"
- settings:min="0"
- settings:unitsRight="@string/unit_sec" />
- </PreferenceCategory>
-</PreferenceScreen>
diff --git a/res/xml/omni_dashboard_fragment.xml b/res/xml/omni_dashboard_fragment.xml
index 8e8b310..9a9d4e5 100644
--- a/res/xml/omni_dashboard_fragment.xml
+++ b/res/xml/omni_dashboard_fragment.xml
@@ -65,8 +65,12 @@
<Preference
android:key="event_service_settings"
android:title="@string/event_service_settings_title"
- android:icon="@drawable/ic_settings_event_service"
- android:fragment="org.omnirom.omnigears.service.EventServiceSettings" />
+ android:icon="@drawable/ic_settings_event_service">
+ <intent
+ android:action="android.intent.action.MAIN"
+ android:targetPackage="org.omnirom.omnibrain"
+ android:targetClass="org.omnirom.omnibrain.OmniBrainActivity" />
+ </Preference>
<!--<Preference
android:key="weather_service_settings"
diff --git a/src/org/omnirom/omnigears/service/BootCompletedReceiver.java b/src/org/omnirom/omnigears/service/BootCompletedReceiver.java
deleted file mode 100644
index d5292e5..0000000
--- a/src/org/omnirom/omnigears/service/BootCompletedReceiver.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright (C) 2018 The OmniROM Project
- *
- * 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
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
-*/
-package org.omnirom.omnigears.service;
-
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.util.Log;
-
-public class BootCompletedReceiver extends BroadcastReceiver {
- private static final String TAG = "OmniEventService";
- private static final boolean DEBUG = true;
-
- private SharedPreferences getPrefs(Context context) {
- return context.getSharedPreferences(EventServiceSettings.EVENTS_PREFERENCES_NAME, Context.MODE_PRIVATE);
- }
-
- @Override
- public void onReceive(Context context, Intent intent) {
- if (getPrefs(context).getBoolean(EventServiceSettings.EVENT_SERVICE_ENABLED, false)) {
- if (DEBUG) Log.d(TAG, "onReceive " + intent.getAction());
- context.startService(new Intent(context, EventService.class));
- }
- }
-}
diff --git a/src/org/omnirom/omnigears/service/EventService.java b/src/org/omnirom/omnigears/service/EventService.java
deleted file mode 100644
index 9eba603..0000000
--- a/src/org/omnirom/omnigears/service/EventService.java
+++ /dev/null
@@ -1,452 +0,0 @@
-/*
- * Copyright (C) 2018 The OmniROM Project
- *
- * 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
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-package org.omnirom.omnigears.service;
-
-import android.app.ActivityManagerNative;
-import android.app.Service;
-import android.bluetooth.BluetoothA2dp;
-import android.bluetooth.BluetoothAdapter;
-import android.bluetooth.BluetoothDevice;
-import android.bluetooth.BluetoothProfile;
-import android.content.BroadcastReceiver;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.content.SharedPreferences;
-import android.content.pm.PackageManager;
-import android.content.res.Configuration;
-import android.graphics.PixelFormat;
-import android.graphics.drawable.Drawable;
-import android.media.AudioManager;
-import android.media.AudioSystem;
-import android.media.IAudioService;
-import android.media.session.MediaSessionLegacyHelper;
-import android.os.Binder;
-import android.os.Handler;
-import android.os.IBinder;
-import android.os.PowerManager;
-import android.os.ServiceManager;
-import android.os.SystemClock;
-import android.os.UserHandle;
-import android.text.TextUtils;
-import android.util.Log;
-import android.view.ContextThemeWrapper;
-import android.view.Gravity;
-import android.view.KeyEvent;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.WindowManager;
-import android.view.animation.Interpolator;
-import android.view.animation.PathInterpolator;
-import android.widget.ImageView;
-import android.widget.LinearLayout;
-
-import org.omnirom.omnigears.R;
-
-import java.util.ArrayList;
-import java.util.List;
-
-
-public class EventService extends Service {
- private static final String TAG = "OmniEventService";
- private static final boolean DEBUG = false;
- private PowerManager.WakeLock mWakeLock;
- private static boolean mIsRunning;
- private static boolean mWiredHeadsetConnected;
- private static boolean mA2DPConnected;
- private static final int ANIM_DURATION = 300;
- private static final int LEFT = 0;
- private static final int RIGHT = 1;
- private static final Interpolator FAST_OUT_SLOW_IN = new PathInterpolator(0.4f, 0f, 0.2f, 1f);
- private static boolean mOverlayShown;
- private static long mLastUnplugEventTimestamp;
-
- private WindowManager mWindowManager;
- private View mFloatingWidget = null;
- private List<String> appList = null;
- private Handler mHandler = new Handler();
- private PackageManager mPm;
- private int chooserPosition;
- private int mOverlayWidth;
- private boolean mRecalcOverlayWidth;
- private Runnable mCloseRunnable = new Runnable() {
- @Override
- public void run() {
- if (mOverlayShown) {
- slideAnimation(false);
- }
- }
- };
-
- private BroadcastReceiver mStateListener = new BroadcastReceiver() {
- @Override
- public void onReceive(Context context, Intent intent) {
- String action = intent.getAction();
- mWakeLock.acquire();
-
- try {
- if (DEBUG) Log.d(TAG, "onReceive " + action);
-
- boolean disableIfMusicActive = getPrefs(context).getBoolean(EventServiceSettings.EVENT_MUSIC_ACTIVE, true);
- boolean autoRun = getPrefs(context).getBoolean(EventServiceSettings.EVENT_AUTORUN_SINGLE, true);
-
- switch (action) {
- case BluetoothAdapter.ACTION_STATE_CHANGED:
- if (intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_OFF) {
- mA2DPConnected = false;
- }
- break;
- case BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED:
- int state = intent.getIntExtra(BluetoothProfile.EXTRA_STATE,
- BluetoothProfile.STATE_CONNECTED);
- if (state == BluetoothProfile.STATE_CONNECTED && !mA2DPConnected) {
- mA2DPConnected = true;
- if (DEBUG) Log.d(TAG, "BluetoothProfile.STATE_CONNECTED = true");
-
- if (!(disableIfMusicActive && isMusicActive())) {
- appList = getAvailableActionList(EventServiceSettings.EVENT_A2DP_CONNECT);
- if (appList.size() != 0) {
- if (autoRun && appList.size() == 1) {
- openApp(appList.iterator().next(), context);
- } else {
- openAppChooserDialog(context);
- }
- }
- }
- } else {
- mA2DPConnected = false;
- if (DEBUG) Log.d(TAG, "BluetoothProfile.STATE_CONNECTED = false");
- }
- break;
- case AudioManager.ACTION_HEADSET_PLUG:
- boolean useHeadset = intent.getIntExtra("state", 0) == 1;
- final int threshold = getPrefs(context).getInt(EventServiceSettings.WIRED_EVENTS_THRESHOLD, 0);
-
- if (useHeadset && !mWiredHeadsetConnected) {
- if (mLastUnplugEventTimestamp != 0) {
- final long eventDelta = System.currentTimeMillis() - mLastUnplugEventTimestamp;
- if (eventDelta < threshold * 1000) {
- if (DEBUG) Log.d(TAG, "Ignore AudioManager.ACTION_HEADSET_PLUG = " + useHeadset + " delta = " + eventDelta);
- return;
- }
- }
- mWiredHeadsetConnected = true;
- if (DEBUG) Log.d(TAG, "AudioManager.ACTION_HEADSET_PLUG = true");
-
- if (!(disableIfMusicActive && isMusicActive())) {
- appList = getAvailableActionList(EventServiceSettings.EVENT_WIRED_HEADSET_CONNECT);
- if (appList.size() != 0) {
- if (autoRun && appList.size() == 1) {
- openApp(appList.iterator().next(), context);
- } else {
- openAppChooserDialog(context);
- }
- }
- }
- } else {
- mWiredHeadsetConnected = false;
- if (DEBUG) Log.d(TAG, "AudioManager.ACTION_HEADSET_PLUG = false");
- mLastUnplugEventTimestamp = System.currentTimeMillis();
- }
- break;
- }
-
- } finally {
- mWakeLock.release();
- }
- }
- };
-
- public void openAppChooserDialog(final Context context) {
- if (!mOverlayShown) {
- if (mRecalcOverlayWidth) {
- mOverlayWidth = getOverlayWidth(context);
- mRecalcOverlayWidth = false;
- }
- // never enter again once this started
- mOverlayShown = true;
-
- final LayoutInflater inflater = LayoutInflater.from(new ContextThemeWrapper(
- context, android.R.style.Theme_DeviceDefault_Light_Dialog));
- mFloatingWidget = inflater.inflate(R.layout.layout_floating_widget, null);
-
- final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
- WindowManager.LayoutParams.WRAP_CONTENT,
- WindowManager.LayoutParams.WRAP_CONTENT,
- WindowManager.LayoutParams.TYPE_PHONE,
- WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
- PixelFormat.TRANSLUCENT);
-
- params.x = context.getResources().getDimensionPixelSize(R.dimen.floating_widget_window_padding);
-
- // Selected apps
- LinearLayout linearLayout = (LinearLayout) mFloatingWidget.findViewById(R.id.selected_apps);
- if (linearLayout.getChildCount() > 0) linearLayout.removeAllViews();
-
- for (final String value : appList) {
- try {
- View v = inflater.inflate(R.layout.app_grid_item, null);
- ComponentName componentName = ComponentName.unflattenFromString(value);
- Drawable icon = mPm.getActivityIcon(componentName);
- ((ImageView) v.findViewById(R.id.appIcon)).setImageDrawable(icon);
- v.setPadding(30, 15, 30, 15);
- v.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- mHandler.removeCallbacks(mCloseRunnable);
- mOverlayShown = false;
- try {
- mWindowManager.removeViewImmediate(mFloatingWidget);
- } catch (Exception e) {
- Log.e(TAG, "openApp ", e);
- }
- openApp(value, context);
- }
- });
- linearLayout.addView(v);
- } catch (PackageManager.NameNotFoundException e) {
- Log.e(TAG, "Set app icon", e);
- }
- }
-
- // Close button
- View close = inflater.inflate(R.layout.app_grid_item, null);
- close.setPadding(30, 15, 30, 15);
- close.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- mHandler.removeCallbacks(mCloseRunnable);
- slideAnimation(false);
- }
- });
-
- // Position and close icon
- chooserPosition = getPrefs(context).getInt(EventServiceSettings.APP_CHOOSER_POSITION, LEFT);
- if (chooserPosition == LEFT) {
- params.gravity = Gravity.CENTER_VERTICAL | Gravity.LEFT;
- ((ImageView) close.findViewById(R.id.appIcon)).setImageResource(R.drawable.ic_chevron_left);
- } else {
- params.gravity = Gravity.CENTER_VERTICAL | Gravity.RIGHT;
- ((ImageView) close.findViewById(R.id.appIcon)).setImageResource(R.drawable.ic_chevron_right);
- }
-
- linearLayout.addView(close);
-
- mWindowManager.addView(mFloatingWidget, params);
- slideAnimation(true);
-
- final int timeout = getPrefs(context).getInt(EventServiceSettings.APP_CHOOSER_TIMEOUT, 15);
- if (timeout > 0) {
- mHandler.postDelayed(mCloseRunnable, timeout * 1000);
- }
- }
- }
-
- private void openApp(String app_uri, Context context) {
- try {
- startActivityAsUser(createIntent(app_uri), UserHandle.CURRENT);
- if (getPrefs(context).getBoolean(EventServiceSettings.EVENT_MEDIA_PLAYER_START, false)) {
- mHandler.postDelayed(new Runnable() {
- @Override
- public void run() {
- dispatchMediaKeyToAudioService(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE);
- }
- }, 1000);
- }
- } catch (Exception e) {
- Log.e(TAG, "MultiAppSelector.EVENT_MEDIA_PLAYER_START", e);
- }
- }
-
- private void dispatchMediaKeyToAudioService(int keycode) {
- if (ActivityManagerNative.isSystemReady()) {
- IAudioService audioService = IAudioService.Stub
- .asInterface(ServiceManager.checkService(Context.AUDIO_SERVICE));
- if (audioService != null) {
- if (DEBUG) Log.d(TAG, "dispatchMediaKeyToAudioService " + keycode);
-
- KeyEvent event = new KeyEvent(SystemClock.uptimeMillis(),
- SystemClock.uptimeMillis(), KeyEvent.ACTION_DOWN,
- keycode, 0);
- MediaSessionLegacyHelper.getHelper(this).sendMediaButtonEvent(event, true);
- event = KeyEvent.changeAction(event, KeyEvent.ACTION_UP);
- MediaSessionLegacyHelper.getHelper(this).sendMediaButtonEvent(event, true);
- }
- }
- }
-
- private Intent createIntent(String value) {
- ComponentName componentName = ComponentName.unflattenFromString(value);
- Intent intent = new Intent(Intent.ACTION_MAIN);
- intent.addCategory(Intent.CATEGORY_LAUNCHER);
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK
- | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
- intent.setComponent(componentName);
- return intent;
- }
-
- private boolean isMusicActive() {
- if (AudioSystem.isStreamActive(AudioSystem.STREAM_MUSIC, 0)) {
- // local / wired / BT playback active
- if (DEBUG) Log.d(TAG, "isMusicActive(): local");
- return true;
- }
- if (AudioSystem.isStreamActiveRemotely(AudioSystem.STREAM_MUSIC, 0)) {
- // remote submix playback active
- if (DEBUG) Log.d(TAG, "isMusicActive(): remote submix");
- return true;
- }
- if (DEBUG) Log.d(TAG, "isMusicActive(): no");
- return false;
- }
-
- public class LocalBinder extends Binder {
- public EventService getService() {
- return EventService.this;
- }
- }
-
- private final LocalBinder mBinder = new LocalBinder();
-
- @Override
- public void onCreate() {
- super.onCreate();
- if (DEBUG) Log.d(TAG, "onCreate");
- PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
- mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
- mWakeLock.setReferenceCounted(true);
- mIsRunning = true;
- mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
- mPm = getPackageManager();
- registerListener();
- mOverlayWidth = getOverlayWidth(this);
- }
-
- @Override
- public void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- mRecalcOverlayWidth = true;
- }
-
- @Override
- public IBinder onBind(Intent intent) {
- return mBinder;
- }
-
- @Override
- public void onDestroy() {
- super.onDestroy();
- if (DEBUG) Log.d(TAG, "onDestroy");
- unregisterListener();
- mIsRunning = false;
- }
-
- private void registerListener() {
- if (DEBUG) Log.d(TAG, "registerListener");
- IntentFilter filter = new IntentFilter();
- filter.addAction(BluetoothDevice.ACTION_ACL_CONNECTED);
- filter.addAction(BluetoothDevice.ACTION_ACL_DISCONNECTED);
- filter.addAction(BluetoothAdapter.ACTION_STATE_CHANGED);
- filter.addAction(BluetoothA2dp.ACTION_CONNECTION_STATE_CHANGED);
- filter.addAction(AudioManager.ACTION_HEADSET_PLUG);
- this.registerReceiver(mStateListener, filter);
- }
-
- private void unregisterListener() {
- if (DEBUG) Log.d(TAG, "unregisterListener");
- try {
- this.unregisterReceiver(mStateListener);
- } catch (Exception e) {
- Log.e(TAG, "unregisterListener", e);
- }
- }
-
- public static boolean isRunning() {
- return mIsRunning;
- }
-
- private SharedPreferences getPrefs(Context context) {
- return context.getSharedPreferences(EventServiceSettings.EVENTS_PREFERENCES_NAME, Context.MODE_PRIVATE);
- }
-
- private int getOverlayWidth(Context context) {
- return (context.getResources().getDimensionPixelSize(R.dimen.floating_widget_view_padding) +
- context.getResources().getDimensionPixelSize(android.R.dimen.app_icon_size)) / 2;
- }
-
- private void slideAnimation(final boolean show) {
- if (show) {
- int startValue = 0;
- if (chooserPosition == RIGHT) {
- startValue = mOverlayWidth;
- } else {
- startValue = -mOverlayWidth;
- }
- mFloatingWidget.setTranslationX(startValue);
- mFloatingWidget.setAlpha(0);
- mFloatingWidget.animate()
- .alpha(1)
- .translationX(0)
- .setDuration(ANIM_DURATION)
- .setInterpolator(FAST_OUT_SLOW_IN)
- .start();
-
- } else {
- int endValue = 0;
- if (chooserPosition == RIGHT) {
- endValue = mOverlayWidth;
- } else {
- endValue = -mOverlayWidth;
- }
- mFloatingWidget.setTranslationX(0);
- mFloatingWidget.setAlpha(1);
- mFloatingWidget.animate()
- .alpha(0)
- .translationX(endValue)
- .setDuration(ANIM_DURATION)
- .setInterpolator(FAST_OUT_SLOW_IN)
- .withEndAction(() -> {
- mOverlayShown = false;
- try {
- mWindowManager.removeViewImmediate(mFloatingWidget);
- } catch (Exception e) {
- Log.e(TAG, "slideAnimation close ", e);
- }
- })
- .start();
- }
- }
-
- // filter out unresolvable (uninstalled) intents
- private List<String> getAvailableActionList(String key) {
- String value = getPrefs(this).getString(key, null);
- List<String> valueList = new ArrayList<String>();
- if (!TextUtils.isEmpty(value)) {
- for (String intentUri : value.split(":")){
- Intent intent = createIntent(intentUri);
- if (mPm.resolveActivity(intent, 0) != null) {
- valueList.add(intentUri);
- }
- }
- if (DEBUG) Log.d(TAG, "getActionList valueList = " + valueList);
- }
- return valueList;
- }
-}
-
diff --git a/src/org/omnirom/omnigears/service/EventServiceSettings.java b/src/org/omnirom/omnigears/service/EventServiceSettings.java
deleted file mode 100644
index 2dabdbf..0000000
--- a/src/org/omnirom/omnigears/service/EventServiceSettings.java
+++ /dev/null
@@ -1,293 +0,0 @@
-/*
- * Copyright (C) 2018 The OmniROM Project
- *
- * 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
- * the Free Software Foundation, either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-package org.omnirom.omnigears.service;
-
-import android.content.Context;
-import android.content.Intent;
-import android.content.SharedPreferences;
-import android.content.res.Resources;
-import android.os.Bundle;
-import android.os.Handler;
-import android.provider.SearchIndexableResource;
-import android.support.v14.preference.SwitchPreference;
-import android.support.v7.preference.ListPreference;
-import android.support.v7.preference.Preference;
-import android.support.v7.preference.Preference.OnPreferenceChangeListener;
-import android.text.TextUtils;
-
-import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
-import com.android.settings.R;
-import com.android.settings.SettingsPreferenceFragment;
-import com.android.settings.search.BaseSearchIndexProvider;
-import com.android.settings.search.Indexable;
-
-import org.omnirom.omnilib.preference.AppMultiSelectListPreference;
-import org.omnirom.omnilib.preference.ScrollAppsViewPreference;
-import org.omnirom.omnilib.preference.SeekBarPreference;
-
-import java.util.Arrays;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.Set;
-
-public class EventServiceSettings extends SettingsPreferenceFragment implements OnPreferenceChangeListener, Indexable {
- public static final String EVENTS_PREFERENCES_NAME = "event_service";
-
- public static final String EVENT_A2DP_CONNECT = "bt_a2dp_connect_app_string";
- public static final String EVENT_WIRED_HEADSET_CONNECT = "headset_connect_app_string";
- public static final String EVENT_SERVICE_ENABLED = "event_service_enabled";
- public static final String EVENT_MEDIA_PLAYER_START = "media_player_autostart";
- public static final String EVENT_MUSIC_ACTIVE = "media_player_music_active";
- public static final String EVENT_AUTORUN_SINGLE = "autorun_single_app";
- public static final String A2DP_APP_LIST = "a2dp_app_list";
- public static final String HEADSET_APP_LIST = "headset_app_list";
- public static final String APP_CHOOSER_TIMEOUT = "app_chooser_timeout";
- public static final String APP_CHOOSER_POSITION = "app_chooser_position";
- public static final String WIRED_EVENTS_THRESHOLD = "wired_events_threshold";
-
- // -- For backward compatibility
- public static final String OLD_EVENT_A2DP_CONNECT = "bt_a2dp_connect_app_list";
- public static final String OLD_EVENT_WIRED_HEADSET_CONNECT = "headset_connect_app_list";
- // -- End backward compatibility
-
- private AppMultiSelectListPreference mA2DPappSelect;
- private AppMultiSelectListPreference mWiredHeadsetAppSelect;
- private ScrollAppsViewPreference mA2DPApps;
- private ScrollAppsViewPreference mHeadsetApps;
- private SwitchPreference mEnable;
- private SwitchPreference mAutoStart;
- private SwitchPreference mMusicActive;
- private SwitchPreference mAutorun;
- private SeekBarPreference mChooserTimeout;
- private ListPreference mChooserPosition;
- private Handler mHandler = new Handler();
- private String mServiceRunning;
- private String mServiceStopped;
- private SeekBarPreference mWiredThresholdTimeout;
-
- @Override
- public int getMetricsCategory() {
- return MetricsEvent.OMNI_SETTINGS;
- }
-
- private SharedPreferences getPrefs() {
- return getActivity().getSharedPreferences(EVENTS_PREFERENCES_NAME, Context.MODE_PRIVATE);
- }
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.xml.event_service_settings);
-
- // -- For backward compatibility
- if (getPrefs().contains(OLD_EVENT_A2DP_CONNECT)) {
- Set<String> old_value = getPrefs().getStringSet(OLD_EVENT_A2DP_CONNECT, null);
- fixOldPreference(OLD_EVENT_A2DP_CONNECT, EVENT_A2DP_CONNECT, old_value);
- }
- if (getPrefs().contains(OLD_EVENT_WIRED_HEADSET_CONNECT)) {
- Set<String> old_value = getPrefs().getStringSet(OLD_EVENT_WIRED_HEADSET_CONNECT, null);
- fixOldPreference(OLD_EVENT_WIRED_HEADSET_CONNECT, EVENT_WIRED_HEADSET_CONNECT, old_value);
- }
- // -- End backward compatibility
-
- mEnable = (SwitchPreference) findPreference(EVENT_SERVICE_ENABLED);
- mEnable.setChecked(getPrefs().getBoolean(EventServiceSettings.EVENT_SERVICE_ENABLED, false));
- mEnable.setOnPreferenceChangeListener(this);
- mServiceRunning = getResources().getString(R.string.event_service_running);
- mServiceStopped = getResources().getString(R.string.event_service_stopped);
- mEnable.setSummary(isServiceRunning() ? mServiceRunning : mServiceStopped);
-
- mChooserPosition = (ListPreference) findPreference(APP_CHOOSER_POSITION);
- mChooserPosition.setOnPreferenceChangeListener(this);
- mChooserPosition.setValue(
- Integer.toString(getPrefs().getInt(EventServiceSettings.APP_CHOOSER_POSITION, 0)));
- mChooserPosition.setSummary(mChooserPosition.getEntry());
-
- mAutoStart = (SwitchPreference) findPreference(EVENT_MEDIA_PLAYER_START);
- mAutoStart.setChecked(getPrefs().getBoolean(EventServiceSettings.EVENT_MEDIA_PLAYER_START, false));
- mAutoStart.setOnPreferenceChangeListener(this);
-
- mMusicActive = (SwitchPreference) findPreference(EVENT_MUSIC_ACTIVE);
- mMusicActive.setChecked(getPrefs().getBoolean(EventServiceSettings.EVENT_MUSIC_ACTIVE, false));
- mMusicActive.setOnPreferenceChangeListener(this);
-
- mAutorun = (SwitchPreference) findPreference(EVENT_AUTORUN_SINGLE);
- mAutorun.setChecked(getPrefs().getBoolean(EventServiceSettings.EVENT_AUTORUN_SINGLE, true));
- mAutorun.setOnPreferenceChangeListener(this);
-
- mChooserTimeout = (SeekBarPreference) findPreference(APP_CHOOSER_TIMEOUT);
- mChooserTimeout.setValue(getPrefs().getInt(EventServiceSettings.APP_CHOOSER_TIMEOUT, 15));
- mChooserTimeout.setOnPreferenceChangeListener(this);
-
- mWiredThresholdTimeout = (SeekBarPreference) findPreference(WIRED_EVENTS_THRESHOLD);
- mWiredThresholdTimeout.setValue(getPrefs().getInt(EventServiceSettings.WIRED_EVENTS_THRESHOLD, 0));
- mWiredThresholdTimeout.setOnPreferenceChangeListener(this);
-
- mA2DPappSelect = (AppMultiSelectListPreference) findPreference(EVENT_A2DP_CONNECT);
- String value = getPrefs().getString(EVENT_A2DP_CONNECT, null);
- List<String> valueList = new ArrayList<String>();
- if (!TextUtils.isEmpty(value)) {
- valueList.addAll(Arrays.asList(value.split(":")));
- }
- mA2DPappSelect.setValues(valueList);
- mA2DPappSelect.setOnPreferenceChangeListener(this);
-
- mA2DPApps = (ScrollAppsViewPreference) findPreference(A2DP_APP_LIST);
- if (TextUtils.isEmpty(value)) {
- mA2DPApps.setVisible(false);
- } else {
- mA2DPApps.setVisible(true);
- mA2DPApps.setValues(valueList);
- }
-
- mWiredHeadsetAppSelect = (AppMultiSelectListPreference) findPreference(EVENT_WIRED_HEADSET_CONNECT);
- value = getPrefs().getString(EVENT_WIRED_HEADSET_CONNECT, null);
- valueList = new ArrayList<String>();
- if (!TextUtils.isEmpty(value)) {
- valueList.addAll(Arrays.asList(value.split(":")));
- }
- mWiredHeadsetAppSelect.setValues(valueList);
- mWiredHeadsetAppSelect.setOnPreferenceChangeListener(this);
-
- mHeadsetApps = (ScrollAppsViewPreference) findPreference(HEADSET_APP_LIST);
- if (TextUtils.isEmpty(value)) {
- mHeadsetApps.setVisible(false);
- } else {
- mHeadsetApps.setValues(valueList);
- mHeadsetApps.setVisible(true);
- }
- }
-
- private void fixOldPreference(String old_event, String new_event, Set<String> value) {
- getPrefs().edit().putString(new_event, TextUtils.join(":", value)).commit();
- getPrefs().edit().remove(old_event).commit();
- }
-
- @Override
- public boolean onPreferenceChange(Preference preference, Object newValue) {
- if (preference == mA2DPappSelect) {
- Collection<String> value = (Collection<String>) newValue;
-
- mA2DPApps.setVisible(false);
- if (value != null && !value.isEmpty()) {
- getPrefs().edit().putString(EVENT_A2DP_CONNECT, TextUtils.join(":", value)).commit();
- mA2DPApps.setValues(value);
- mA2DPApps.setVisible(true);
- } else {
- getPrefs().edit().putString(EVENT_A2DP_CONNECT, null).commit();
- }
-
- return true;
- } else if (preference == mWiredHeadsetAppSelect) {
- Collection<String> value = (Collection<String>) newValue;
-
- mHeadsetApps.setVisible(false);
- if (value != null && !value.isEmpty()) {
- getPrefs().edit().putString(EVENT_WIRED_HEADSET_CONNECT, TextUtils.join(":", value)).commit();
- mHeadsetApps.setValues(value);
- mHeadsetApps.setVisible(true);
- } else {
- getPrefs().edit().putString(EVENT_WIRED_HEADSET_CONNECT, null).commit();
- }
-
- return true;
- } else if (preference == mEnable) {
- boolean value = ((Boolean) newValue).booleanValue();
- if (value) {
- getActivity().startService(new Intent(getActivity(), EventService.class));
- } else {
- getActivity().stopService(new Intent(getActivity(), EventService.class));
- }
- getPrefs().edit().putBoolean(EVENT_SERVICE_ENABLED, value).commit();
- mHandler.postDelayed(new Runnable() {
- @Override
- public void run() {
- try {
- mEnable.setSummary(isServiceRunning() ? mServiceRunning : mServiceStopped);
- } catch (Exception e) {
- }
- }
- }, 1000);
- return true;
- } else if (preference == mAutoStart) {
- boolean value = ((Boolean) newValue).booleanValue();
- getPrefs().edit().putBoolean(EVENT_MEDIA_PLAYER_START, value).commit();
- return true;
- } else if (preference == mMusicActive) {
- boolean value = ((Boolean) newValue).booleanValue();
- getPrefs().edit().putBoolean(EVENT_MUSIC_ACTIVE, value).commit();
- return true;
- } else if (preference == mAutorun) {
- boolean value = ((Boolean) newValue).booleanValue();
- getPrefs().edit().putBoolean(EVENT_AUTORUN_SINGLE, value).commit();
- return true;
- } else if (preference == mChooserTimeout) {
- int value = ((int) newValue);
- getPrefs().edit().putInt(APP_CHOOSER_TIMEOUT, value).commit();
- return true;
- } else if (preference == mChooserPosition) {
- int value = Integer.valueOf((String) newValue);
- getPrefs().edit().putInt(APP_CHOOSER_POSITION, value).commit();
- updateChooserPositionSummary(value);
- return true;
- } else if (preference == mWiredThresholdTimeout) {
- int value = ((int) newValue);
- getPrefs().edit().putInt(WIRED_EVENTS_THRESHOLD, value).commit();
- return true;
- }
- return false;
- }
-
- private void updateChooserPositionSummary(int value) {
- Resources res = getResources();
- if (value == 0) {
- mChooserPosition.setSummary(res.getString(R.string.app_chooser_left));
- } else {
- mChooserPosition.setSummary(res.getString(R.string.app_chooser_right));
- }
- }
-
- private boolean isServiceRunning() {
- return EventService.isRunning();
- }
-
- public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
- new BaseSearchIndexProvider() {
- @Override
- public List<SearchIndexableResource> getXmlResourcesToIndex(Context context,
- boolean enabled) {
- ArrayList<SearchIndexableResource> result =
- new ArrayList<SearchIndexableResource>();
-
- SearchIndexableResource sir = new SearchIndexableResource(context);
- sir.xmlResId = R.xml.event_service_settings;
- result.add(sir);
-
- return result;
- }
-
- @Override
- public List<String> getNonIndexableKeys(Context context) {
- ArrayList<String> result = new ArrayList<String>();
- return result;
- }
- };
-}
-