From b6677c087219d10635fcf351d775ebdd0d6a7325 Mon Sep 17 00:00:00 2001 From: Qutayba-Khader Date: Mon, 30 Apr 2018 16:22:15 +0300 Subject: [PATCH 1/2] - fix for untouchable bubble issue. - add options to show and hide dialog controls. - add new (slim dialog) option. --- .idea/caches/build_file_checksums.ser | Bin 534 -> 509 bytes app/build.gradle | 64 ++++-- .../services/FloatingVolumeService.java | 45 +++- .../mycax/floatingvolume/utils/Constants.java | 12 ++ app/src/main/res/layout/activity_main.xml | 15 +- .../main/res/layout/floating_layout_slim.xml | 201 ++++++++++++++++++ app/src/main/res/values/strings.xml | 10 + app/src/main/res/values/styles.xml | 12 ++ app/src/main/res/xml/pref_main.xml | 34 ++- 9 files changed, 369 insertions(+), 24 deletions(-) create mode 100644 app/src/main/java/com/android/mycax/floatingvolume/utils/Constants.java create mode 100644 app/src/main/res/layout/floating_layout_slim.xml diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index dbd31c079fe5f795b7abb07dc2f7efceccf54480..f83b099ad65970917d56fb1602a33ffb4824f2ad 100644 GIT binary patch delta 200 zcmbQn@|StS3>LAR_@aq(e9~D<7z7dv3SyESf}T{k)8U1ay%}ZAZH0La-pS~i6o?c)HC!KESHfWGY!wq)oLW>I6H=6zoE@H6 ql&b5SpOl%Cs%sbnH8f^&KclDM=U(PjdlHuVZL&=>es)$MsR96CnMa=h delta 229 zcmey%JdI_-3>H2$o!1lR_$0HHFz^?rmXu`Xr5Ed^7bT|Tq?Q&jFhx79`7Hi}jU(g% z69Yp<0Rsbr!18}mhbLxkeX0=^7o4WADqX_BlT@0SlLFIK$WX_?22$v&+Iq|Vfo*Tz zq4(EQ4U%0a`!mX_OH|n1aVhrQyxwBL6C3%X93>2@`WgATsrtE<$%z&EP($=5Uu2Y? zypK`OPGEOg!1=eDKP*-`94z>hq+h}ykXTTlkKM-K%<8sGlb$7NML0@w%=mPn0ssz} BQx^aL diff --git a/app/build.gradle b/app/build.gradle index d27faeb..b84f669 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -1,13 +1,53 @@ //noinspection GradleCompatible apply plugin: 'com.android.application' +def compile_sdk_version = 27 +def min_sdk_version = 21 +def support_library_version = "27.1.1" +def build_tools_version = "27.0.3" +def play_services_version = "15.0.0" +def firebase_version = "15.0.0" +def support_test_version = "1.0.1" +def gson_version = "2.8.2" +def glide_version = "3.8.0" + + + +configurations.all { + resolutionStrategy.eachDependency { DependencyResolveDetails details -> + // Skip multidex because it follows a different versioning pattern. + if (!details.requested.name.startsWith("multidex")) { + switch (details.requested.group) { + case 'com.android.support': + details.useVersion "$support_library_version" + break; + case 'com.google.android.gms': + details.useVersion "$play_services_version" + break; + case 'com.google.firebase': + details.useVersion "$firebase_version" + break; + case 'com.android.support.test': + details.useVersion "$support_test_version" + break; + case 'com.google.code.gson': + details.useVersion "$gson_version" + break; + case 'com.github.bumptech.glide': + details.useVersion "$glide_version" + break; + } + } + } +} + android { - compileSdkVersion 27 - buildToolsVersion '27.0.3' + compileSdkVersion compile_sdk_version + buildToolsVersion build_tools_version defaultConfig { applicationId "com.android.mycax.floatingvolume" - minSdkVersion 21 - targetSdkVersion 27 + minSdkVersion min_sdk_version + targetSdkVersion compile_sdk_version versionCode 6 versionName "1.0.5 beta" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" @@ -22,13 +62,13 @@ android { dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) - implementation 'com.android.support:appcompat-v7:27.1.1' - implementation 'com.android.support.constraint:constraint-layout:1.1.0' - implementation 'com.android.support:cardview-v7:27.1.1' - implementation 'com.android.support:support-v4:27.1.1' - testImplementation 'junit:junit:4.12' - androidTestImplementation 'com.android.support.test:runner:1.0.2' + implementation "com.android.support:appcompat-v7:${support_library_version}" + implementation "com.android.support.constraint:constraint-layout:1.1.0" + implementation "com.android.support:cardview-v7:${support_library_version}" + implementation "com.android.support:support-v4:${support_library_version}" + androidTestImplementation 'junit:junit:4.12' + androidTestImplementation "com.android.support.test:runner:${support_test_version}" androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2' - compile 'com.github.BaselHorany:DualButton:1.1.1' - compile 'com.github.recruit-lifestyle:FloatingView:2.3.1' + implementation 'com.github.BaselHorany:DualButton:1.1.1' + implementation 'com.github.recruit-lifestyle:FloatingView:2.3.1' } diff --git a/app/src/main/java/com/android/mycax/floatingvolume/services/FloatingVolumeService.java b/app/src/main/java/com/android/mycax/floatingvolume/services/FloatingVolumeService.java index 382580e..cea3b09 100644 --- a/app/src/main/java/com/android/mycax/floatingvolume/services/FloatingVolumeService.java +++ b/app/src/main/java/com/android/mycax/floatingvolume/services/FloatingVolumeService.java @@ -10,6 +10,8 @@ import android.content.res.Configuration; import android.graphics.PixelFormat; import android.graphics.Point; +import android.media.AudioManager; +import android.media.MediaPlayer; import android.os.Build; import android.os.CountDownTimer; import android.os.IBinder; @@ -27,13 +29,14 @@ import android.view.animation.AnimationUtils; import android.widget.ImageView; import android.widget.LinearLayout; +import android.widget.MediaController; import android.widget.SeekBar; import android.widget.TextView; -import android.media.AudioManager; import com.android.mycax.floatingvolume.R; import com.android.mycax.floatingvolume.audio.AudioVolumeObserver; import com.android.mycax.floatingvolume.audio.OnAudioVolumeChangedListener; +import com.android.mycax.floatingvolume.utils.Constants; import java.util.Objects; @@ -157,6 +160,8 @@ private void expandView(LayoutInflater inflater, DisplayMetrics displayMetrics) implementVolumeFeatures(); + checkBarsSettings(); + mAudioVolumeObserverRinger = new AudioVolumeObserver(this); mAudioVolumeObserverRinger.register(AudioManager.STREAM_RING, this); @@ -176,7 +181,7 @@ private void expandView(LayoutInflater inflater, DisplayMetrics displayMetrics) @SuppressLint("InflateParams") private void addFloatingWidgetView(LayoutInflater inflater, DisplayMetrics displayMetrics) { getWindowManagerDefaultDisplay(); - mFloatingWidgetView = inflater.inflate(R.layout.floating_layout, null, false); + mFloatingWidgetView = inflater.inflate(getDialogLayout(), null, false); final WindowManager.LayoutParams params = new WindowManager.LayoutParams( WindowManager.LayoutParams.WRAP_CONTENT, @@ -418,6 +423,8 @@ private FloatingViewManager.Options loadOptions(DisplayMetrics metrics) { options.floatingViewY = height - (height / 2); } + options.moveDirection=FloatingViewManager.MOVE_DIRECTION_NONE; + return options; } @@ -567,4 +574,38 @@ public void onConfigurationChanged(Configuration newConfig) { private void getWindowManagerDefaultDisplay() { mWindowManager.getDefaultDisplay().getSize(szWindow); } + + private void checkBarsSettings() { + try { + /**/ + mFloatingWidgetView.findViewById(R.id.textViewMedia).setVisibility(PreferenceManager.getDefaultSharedPreferences(this).getBoolean(Constants.SHOW_MEDIA_BAR, true) ? View.VISIBLE : View.GONE); + mFloatingWidgetView.findViewById(R.id.linearLayoutMedia).setVisibility(PreferenceManager.getDefaultSharedPreferences(this).getBoolean(Constants.SHOW_MEDIA_BAR, true) ? View.VISIBLE : View.GONE); + /**/ + /**/ + mFloatingWidgetView.findViewById(R.id.textViewAlarm).setVisibility(PreferenceManager.getDefaultSharedPreferences(this).getBoolean(Constants.SHOW_ALARM_BAR, true) ? View.VISIBLE : View.GONE); + mFloatingWidgetView.findViewById(R.id.linearLayoutAlarm).setVisibility(PreferenceManager.getDefaultSharedPreferences(this).getBoolean(Constants.SHOW_ALARM_BAR, true) ? View.VISIBLE : View.GONE); + /**/ + /**/ + mFloatingWidgetView.findViewById(R.id.textViewRinger).setVisibility(PreferenceManager.getDefaultSharedPreferences(this).getBoolean(Constants.SHOW_RINGER_BAR, true) ? View.VISIBLE : View.GONE); + mFloatingWidgetView.findViewById(R.id.linearLayoutRinger).setVisibility(PreferenceManager.getDefaultSharedPreferences(this).getBoolean(Constants.SHOW_RINGER_BAR, true) ? View.VISIBLE : View.GONE); + /**/ + } catch (Exception e) { + e.printStackTrace(); + + } + } + + private int getDialogLayout() { + try { + if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(Constants.USE_SLIM_DIALOG, false)) + return R.layout.floating_layout_slim; + } catch (Exception e) { + e.printStackTrace(); + + } + return R.layout.floating_layout; + } + + + } \ No newline at end of file diff --git a/app/src/main/java/com/android/mycax/floatingvolume/utils/Constants.java b/app/src/main/java/com/android/mycax/floatingvolume/utils/Constants.java new file mode 100644 index 0000000..ddb4803 --- /dev/null +++ b/app/src/main/java/com/android/mycax/floatingvolume/utils/Constants.java @@ -0,0 +1,12 @@ +package com.android.mycax.floatingvolume.utils; + +public interface Constants { + + + // Preference Keys + public static final String SHOW_MEDIA_BAR = "show_media_bar"; + public static final String SHOW_RINGER_BAR = "show_ringer_bar"; + public static final String SHOW_ALARM_BAR = "show_alarm_bar"; + public static final String USE_SLIM_DIALOG = "use_slim_dialog"; + // +} diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index e34723a..3094822 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,17 +1,17 @@ - - \ No newline at end of file + \ No newline at end of file diff --git a/app/src/main/res/layout/floating_layout_slim.xml b/app/src/main/res/layout/floating_layout_slim.xml new file mode 100644 index 0000000..a675121 --- /dev/null +++ b/app/src/main/res/layout/floating_layout_slim.xml @@ -0,0 +1,201 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7cb2a7a..4232d6c 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -15,4 +15,14 @@ Enable to make volume control interface movable Enable window bounce effect Volume control interface will bounce off the edge when dropped + Show Media Bar + Show Ringer Bar + Show Alarm Bar + Floating Dialog Settings + Show media bar in floating dialog + Show ringer bar in floating dialog + Show alarm bar in floating dialog + Use slim dialog + Use slim dialog with small icons nested of the default dialog + diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 559292e..c11b7e3 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -33,4 +33,16 @@ @drawable/ic_touch_app_white_24dp @drawable/ic_bounce_white_24dp + + + + + + diff --git a/app/src/main/res/xml/pref_main.xml b/app/src/main/res/xml/pref_main.xml index 45d2938..8a36388 100644 --- a/app/src/main/res/xml/pref_main.xml +++ b/app/src/main/res/xml/pref_main.xml @@ -8,16 +8,44 @@ android:icon="?attr/save_icon_color" android:key="settings_save_last_position" android:summary="@string/settings_summary_save_position" - android:title="@string/settings_title_save_position"/> + android:title="@string/settings_title_save_position" /> + android:summary="@string/pref_disable_fixed_ui_summary" + android:title="@string/pref_disable_fixed_ui" /> + + + + + + + + + From 1102f898bd1d2b9c55497a5340189c76d3a4058e Mon Sep 17 00:00:00 2001 From: Adam Myczkowski Date: Mon, 30 Apr 2018 23:23:41 +0100 Subject: [PATCH 2/2] Fixes and changes: * Use multislectlistpreference for showing different seekbars * If seekbars are not to be shown don't register broadcast * Optimise layout * Fix bug on rotation Signed-off-by: Adam Myczkowski --- .idea/assetWizardSettings.xml | 4 +- .idea/caches/build_file_checksums.ser | Bin 509 -> 534 bytes app/build.gradle | 12 +- .../mycax/floatingvolume/MainActivity.java | 28 ++- .../services/FloatingVolumeService.java | 174 +++++++++--------- .../mycax/floatingvolume/utils/Constants.java | 18 +- .../drawable/ic_slim_dialog_black_24dp.xml | 9 + .../drawable/ic_slim_dialog_white_24dp.xml | 9 + app/src/main/res/layout/floating_layout.xml | 6 +- .../main/res/layout/floating_layout_slim.xml | 44 ++--- app/src/main/res/values/arrays.xml | 21 +++ app/src/main/res/values/attrs.xml | 1 + app/src/main/res/values/strings.xml | 6 +- app/src/main/res/values/styles.xml | 2 + app/src/main/res/xml/pref_main.xml | 65 +++---- .../mycax/floatingvolume/ExampleUnitTest.java | 17 -- 16 files changed, 207 insertions(+), 209 deletions(-) create mode 100644 app/src/main/res/drawable/ic_slim_dialog_black_24dp.xml create mode 100644 app/src/main/res/drawable/ic_slim_dialog_white_24dp.xml create mode 100644 app/src/main/res/values/arrays.xml delete mode 100644 app/src/test/java/com/android/mycax/floatingvolume/ExampleUnitTest.java diff --git a/.idea/assetWizardSettings.xml b/.idea/assetWizardSettings.xml index 41e03fc..fbbd448 100644 --- a/.idea/assetWizardSettings.xml +++ b/.idea/assetWizardSettings.xml @@ -18,7 +18,7 @@ @@ -28,7 +28,7 @@ diff --git a/.idea/caches/build_file_checksums.ser b/.idea/caches/build_file_checksums.ser index f83b099ad65970917d56fb1602a33ffb4824f2ad..db8b17b7953091d370cfe0697e3fbcc67b2bda0e 100644 GIT binary patch delta 229 zcmey%JdI_-3>JyGU$;-3d%8@`f>;!g~1)P7Y`NLwB!@+`2N%|!W0*M6$`q*tWsyunU_p1WW@!r+4!U|_@R{#Jy CD^>^q delta 200 zcmbQn@|StS3>LAR_@aq(e9~D<7z7dv3SyESf}T{k)8U1ay%}ZAZH0La-pS~i6o?c)HC!KESHfWGY!wq)oLW>I6H=6zoE@H6 ql&b5SpOl%Cs%sbnH8f^&KclDM=U(PjdlHuVZL&=>es)$MsR96CnMa=h diff --git a/app/build.gradle b/app/build.gradle index b84f669..73cf1c4 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -20,22 +20,22 @@ configurations.all { switch (details.requested.group) { case 'com.android.support': details.useVersion "$support_library_version" - break; + break case 'com.google.android.gms': details.useVersion "$play_services_version" - break; + break case 'com.google.firebase': details.useVersion "$firebase_version" - break; + break case 'com.android.support.test': details.useVersion "$support_test_version" - break; + break case 'com.google.code.gson': details.useVersion "$gson_version" - break; + break case 'com.github.bumptech.glide': details.useVersion "$glide_version" - break; + break } } } diff --git a/app/src/main/java/com/android/mycax/floatingvolume/MainActivity.java b/app/src/main/java/com/android/mycax/floatingvolume/MainActivity.java index 7a32fd9..f7233c3 100644 --- a/app/src/main/java/com/android/mycax/floatingvolume/MainActivity.java +++ b/app/src/main/java/com/android/mycax/floatingvolume/MainActivity.java @@ -15,6 +15,7 @@ import android.widget.Toast; import com.android.mycax.floatingvolume.utils.AppUtils; +import com.android.mycax.floatingvolume.utils.Constants; import com.basel.DualButton.DualButton; import java.util.Objects; @@ -23,18 +24,13 @@ public class MainActivity extends AppCompatPreferenceActivity implements SwitchPreference.OnPreferenceChangeListener, DualButton.OnDualClickListener { private DualButton FloatingService; private SwitchPreference bounceEffect; - private static final String PREF_ENABLE_DARK_MODE = "enable_dark_mode_switch"; - private static final String PREF_ENABLE_BOUNCE = "enable_bounce_effect"; - private static final String PREF_DISABLE_FIXED_UI = "disable_fixed_ui"; - private static final int OVERLAY_PERMISSION_REQUEST = 1; - private static final int NOTIFICATION_POLICY_PERMISSION_REQUEST = 2; private AppUtils utils; private NotificationManager notificationManager; @Override protected void onCreate(Bundle savedInstanceState) { setTheme(PreferenceManager.getDefaultSharedPreferences(this) - .getBoolean(PREF_ENABLE_DARK_MODE, false) ? R.style.AppTheme_Dark : R.style.AppTheme); + .getBoolean(Constants.PREF_ENABLE_DARK_MODE, false) ? R.style.AppTheme_Dark : R.style.AppTheme); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); utils = new AppUtils(this); @@ -51,14 +47,14 @@ protected void onCreate(Bundle savedInstanceState) { protected void onPostCreate(Bundle savedInstanceState) { super.onPostCreate(savedInstanceState); addPreferencesFromResource(R.xml.pref_main); - SwitchPreference darkMode = (SwitchPreference) findPreference(PREF_ENABLE_DARK_MODE); + SwitchPreference darkMode = (SwitchPreference) findPreference(Constants.PREF_ENABLE_DARK_MODE); darkMode.setOnPreferenceChangeListener(this); - bounceEffect = (SwitchPreference) findPreference(PREF_ENABLE_BOUNCE); + bounceEffect = (SwitchPreference) findPreference(Constants.PREF_ENABLE_BOUNCE); if (!PreferenceManager.getDefaultSharedPreferences(this) - .getBoolean(PREF_DISABLE_FIXED_UI, false)) { + .getBoolean(Constants.PREF_DISABLE_FIXED_UI, false)) { bounceEffect.setEnabled(false); } - SwitchPreference disableFixedUI = (SwitchPreference) findPreference(PREF_DISABLE_FIXED_UI); + SwitchPreference disableFixedUI = (SwitchPreference) findPreference(Constants.PREF_DISABLE_FIXED_UI); disableFixedUI.setOnPreferenceChangeListener(this); } @@ -78,14 +74,14 @@ public void onClickSecond(Button btn) { @Override public boolean onPreferenceChange(Preference preference, Object object) { - if (preference == findPreference(PREF_ENABLE_DARK_MODE)) { + if (preference == findPreference(Constants.PREF_ENABLE_DARK_MODE)) { finish(); final Intent intent = getIntent(); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); - } else if (preference == findPreference(PREF_DISABLE_FIXED_UI)) { + } else if (preference == findPreference(Constants.PREF_DISABLE_FIXED_UI)) { bounceEffect.setEnabled(!PreferenceManager.getDefaultSharedPreferences(this) - .getBoolean(PREF_DISABLE_FIXED_UI, false)); + .getBoolean(Constants.PREF_DISABLE_FIXED_UI, false)); } return true; } @@ -99,14 +95,14 @@ private void checkPermissions() { if (!Settings.canDrawOverlays(this)) { Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION, Uri.parse("package:" + getPackageName())); - startActivityForResult(intent, OVERLAY_PERMISSION_REQUEST); + startActivityForResult(intent, Constants.OVERLAY_PERMISSION_REQUEST); } if (!Objects.requireNonNull(notificationManager).isNotificationPolicyAccessGranted()) { Intent intent = new Intent( android.provider.Settings .ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS); - startActivityForResult(intent, NOTIFICATION_POLICY_PERMISSION_REQUEST); + startActivityForResult(intent, Constants.NOTIFICATION_POLICY_PERMISSION_REQUEST); } } } @@ -114,7 +110,7 @@ private void checkPermissions() { @TargetApi(Build.VERSION_CODES.M) @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { - if (requestCode == OVERLAY_PERMISSION_REQUEST || requestCode == NOTIFICATION_POLICY_PERMISSION_REQUEST) { + if (requestCode == Constants.OVERLAY_PERMISSION_REQUEST || requestCode == Constants.NOTIFICATION_POLICY_PERMISSION_REQUEST) { if (Settings.canDrawOverlays(this) && Objects.requireNonNull(notificationManager).isNotificationPolicyAccessGranted()) { initializeView(); } else { diff --git a/app/src/main/java/com/android/mycax/floatingvolume/services/FloatingVolumeService.java b/app/src/main/java/com/android/mycax/floatingvolume/services/FloatingVolumeService.java index cea3b09..8c31471 100644 --- a/app/src/main/java/com/android/mycax/floatingvolume/services/FloatingVolumeService.java +++ b/app/src/main/java/com/android/mycax/floatingvolume/services/FloatingVolumeService.java @@ -11,7 +11,6 @@ import android.graphics.PixelFormat; import android.graphics.Point; import android.media.AudioManager; -import android.media.MediaPlayer; import android.os.Build; import android.os.CountDownTimer; import android.os.IBinder; @@ -28,8 +27,6 @@ import android.view.animation.Animation; import android.view.animation.AnimationUtils; import android.widget.ImageView; -import android.widget.LinearLayout; -import android.widget.MediaController; import android.widget.SeekBar; import android.widget.TextView; @@ -39,6 +36,7 @@ import com.android.mycax.floatingvolume.utils.Constants; import java.util.Objects; +import java.util.Set; import jp.co.recruit_lifestyle.android.floatingview.FloatingViewListener; import jp.co.recruit_lifestyle.android.floatingview.FloatingViewManager; @@ -51,16 +49,13 @@ public class FloatingVolumeService extends Service implements FloatingViewListen private FloatingViewManager mFloatingViewManager; private AudioVolumeObserver mAudioVolumeObserverMedia, mAudioVolumeObserverVoiceCall, mAudioVolumeObserverRinger, mAudioVolumeObserverAlarm; private SeekBar mediaControl, ringerControl, alarmControl, voiceCallControl; - private static final String PREF_KEY_LAST_POSITION_X = "last_position_x"; - private static final String PREF_KEY_LAST_POSITION_Y = "last_position_y"; - private static final String PREF_KEY_LAST_POSITION_X_EXPANDED = "last_position_x_expanded"; - private static final String PREF_KEY_LAST_POSITION_Y_EXPANDED = "last_position_y_expanded"; private BroadcastReceiver RingerModeReceiver; private boolean isDarkThemeEnabled, isDisableStaticUiEnabled, isUseLastPosition, isBounceEnabled; private int x_init_cord, y_init_cord, x_init_margin, y_init_margin; private final Point szWindow = new Point(); private SharedPreferences.Editor editor; private SharedPreferences sharedPref; + private Set seekbarSelections; private static int OVERLAY_TYPE; static { @@ -123,6 +118,7 @@ private void expandView(LayoutInflater inflater, DisplayMetrics displayMetrics) isDisableStaticUiEnabled = sharedPref.getBoolean("disable_fixed_ui", false); isUseLastPosition = sharedPref.getBoolean("settings_save_last_position", false); isBounceEnabled = sharedPref.getBoolean("enable_bounce_effect", false); + seekbarSelections = sharedPref.getStringSet("items_to_show_in_dialog_pref", null); addFloatingWidgetView(inflater, displayMetrics); if (isDisableStaticUiEnabled) implementTouchListenerToFloatingWidgetView(this); @@ -160,20 +156,6 @@ private void expandView(LayoutInflater inflater, DisplayMetrics displayMetrics) implementVolumeFeatures(); - checkBarsSettings(); - - mAudioVolumeObserverRinger = new AudioVolumeObserver(this); - mAudioVolumeObserverRinger.register(AudioManager.STREAM_RING, this); - - mAudioVolumeObserverMedia = new AudioVolumeObserver(this); - mAudioVolumeObserverMedia.register(AudioManager.STREAM_MUSIC, this); - - mAudioVolumeObserverVoiceCall = new AudioVolumeObserver(this); - mAudioVolumeObserverVoiceCall.register(AudioManager.STREAM_VOICE_CALL, this); - - mAudioVolumeObserverAlarm = new AudioVolumeObserver(this); - mAudioVolumeObserverAlarm.register(AudioManager.STREAM_ALARM, this); - mFloatingWidgetView.findViewById(R.id.close_expanded_view).setOnClickListener(this); iconView.setVisibility(View.GONE); } @@ -192,8 +174,8 @@ private void addFloatingWidgetView(LayoutInflater inflater, DisplayMetrics displ if (isDisableStaticUiEnabled) { params.gravity = Gravity.TOP | Gravity.START; if (isUseLastPosition) { - params.x = sharedPref.getInt(PREF_KEY_LAST_POSITION_X_EXPANDED, 0); - params.y = sharedPref.getInt(PREF_KEY_LAST_POSITION_Y_EXPANDED, 0); + params.x = sharedPref.getInt(Constants.PREF_KEY_LAST_POSITION_X_EXPANDED, 0); + params.y = sharedPref.getInt(Constants.PREF_KEY_LAST_POSITION_Y_EXPANDED, 0); } else { int height = displayMetrics.heightPixels; params.x = displayMetrics.widthPixels - mFloatingWidgetView.getWidth(); @@ -210,33 +192,56 @@ private void addFloatingWidgetView(LayoutInflater inflater, DisplayMetrics displ } private void implementVolumeFeatures() { - mediaControl = mFloatingWidgetView.findViewById(R.id.SeekBarMedia); - mediaControl.setMax(Objects.requireNonNull(audioManager).getStreamMaxVolume(AudioManager.STREAM_MUSIC)); - mediaControl.setProgress(audioManager.getStreamVolume(AudioManager.STREAM_MUSIC)); - mediaControl.setOnSeekBarChangeListener(this); - - ringerControl = mFloatingWidgetView.findViewById(R.id.SeekBarRinger); - ringerControl.setMax(audioManager.getStreamMaxVolume(AudioManager.STREAM_RING)); - ringerControl.setProgress(audioManager.getStreamVolume(AudioManager.STREAM_RING)); - ringerControl.setOnSeekBarChangeListener(this); - - alarmControl = mFloatingWidgetView.findViewById(R.id.SeekBarAlarm); - alarmControl.setMax(audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM)); - alarmControl.setProgress(audioManager.getStreamVolume(AudioManager.STREAM_ALARM)); - alarmControl.setOnSeekBarChangeListener(this); - - LinearLayout linearLayoutInCall = mFloatingWidgetView.findViewById(R.id.linearLayoutVoiceCall); - TextView textViewInCall = mFloatingWidgetView.findViewById(R.id.textViewVoiceCall); - if (audioManager.getMode() == AudioManager.MODE_IN_CALL) { - linearLayoutInCall.setVisibility(View.VISIBLE); - textViewInCall.setVisibility(View.VISIBLE); - voiceCallControl = mFloatingWidgetView.findViewById(R.id.SeekBarVoiceCall); - voiceCallControl.setMax(audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL)); - voiceCallControl.setProgress(audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL)); - voiceCallControl.setOnSeekBarChangeListener(this); + if (seekbarSelections.contains("1")) { + mediaControl = mFloatingWidgetView.findViewById(R.id.SeekBarMedia); + mediaControl.setMax(Objects.requireNonNull(audioManager).getStreamMaxVolume(AudioManager.STREAM_MUSIC)); + mediaControl.setProgress(audioManager.getStreamVolume(AudioManager.STREAM_MUSIC)); + mediaControl.setOnSeekBarChangeListener(this); + mAudioVolumeObserverMedia = new AudioVolumeObserver(this); + mAudioVolumeObserverMedia.register(AudioManager.STREAM_MUSIC, this); + } else { + mFloatingWidgetView.findViewById(R.id.textViewMedia).setVisibility(View.GONE); + mFloatingWidgetView.findViewById(R.id.linearLayoutMedia).setVisibility(View.GONE); + } + + if (seekbarSelections.contains("2")) { + ringerControl = mFloatingWidgetView.findViewById(R.id.SeekBarRinger); + ringerControl.setMax(audioManager.getStreamMaxVolume(AudioManager.STREAM_RING)); + ringerControl.setProgress(audioManager.getStreamVolume(AudioManager.STREAM_RING)); + ringerControl.setOnSeekBarChangeListener(this); + mAudioVolumeObserverRinger = new AudioVolumeObserver(this); + mAudioVolumeObserverRinger.register(AudioManager.STREAM_RING, this); } else { - linearLayoutInCall.setVisibility(View.GONE); - textViewInCall.setVisibility(View.GONE); + mFloatingWidgetView.findViewById(R.id.textViewRinger).setVisibility(View.GONE); + mFloatingWidgetView.findViewById(R.id.linearLayoutRinger).setVisibility(View.GONE); + } + + if (seekbarSelections.contains("3")) { + alarmControl = mFloatingWidgetView.findViewById(R.id.SeekBarAlarm); + alarmControl.setMax(audioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM)); + alarmControl.setProgress(audioManager.getStreamVolume(AudioManager.STREAM_ALARM)); + alarmControl.setOnSeekBarChangeListener(this); + mAudioVolumeObserverAlarm = new AudioVolumeObserver(this); + mAudioVolumeObserverAlarm.register(AudioManager.STREAM_ALARM, this); + } else { + mFloatingWidgetView.findViewById(R.id.textViewAlarm).setVisibility(View.GONE); + mFloatingWidgetView.findViewById(R.id.linearLayoutAlarm).setVisibility(View.GONE); + } + + if (seekbarSelections.contains("4")) { + mAudioVolumeObserverVoiceCall = new AudioVolumeObserver(this); + mAudioVolumeObserverVoiceCall.register(AudioManager.STREAM_VOICE_CALL, this); + if (audioManager.getMode() == AudioManager.MODE_IN_CALL) { + mFloatingWidgetView.findViewById(R.id.linearLayoutVoiceCall).setVisibility(View.VISIBLE); + mFloatingWidgetView.findViewById(R.id.textViewVoiceCall).setVisibility(View.VISIBLE); + voiceCallControl = mFloatingWidgetView.findViewById(R.id.SeekBarVoiceCall); + voiceCallControl.setMax(audioManager.getStreamMaxVolume(AudioManager.STREAM_VOICE_CALL)); + voiceCallControl.setProgress(audioManager.getStreamVolume(AudioManager.STREAM_VOICE_CALL)); + voiceCallControl.setOnSeekBarChangeListener(this); + } else { + mFloatingWidgetView.findViewById(R.id.linearLayoutVoiceCall).setVisibility(View.GONE); + mFloatingWidgetView.findViewById(R.id.textViewVoiceCall).setVisibility(View.GONE); + } } change_ringer_mode = mFloatingWidgetView.findViewById(R.id.imageViewModeSwitch); @@ -352,10 +357,18 @@ public void onClick(View v) { case R.id.close_expanded_view: removeExpandedView(); iconView.setVisibility(View.VISIBLE); - mAudioVolumeObserverRinger.unregister(); - mAudioVolumeObserverMedia.unregister(); - mAudioVolumeObserverVoiceCall.unregister(); - mAudioVolumeObserverAlarm.unregister(); + if (seekbarSelections.contains("1")) { + mAudioVolumeObserverMedia.unregister(); + } + if (seekbarSelections.contains("2")) { + mAudioVolumeObserverRinger.unregister(); + } + if (seekbarSelections.contains("3")) { + mAudioVolumeObserverAlarm.unregister(); + } + if (seekbarSelections.contains("4")) { + mAudioVolumeObserverVoiceCall.unregister(); + } unregisterReceiver(RingerModeReceiver); break; case R.id.imageViewModeSwitch: @@ -373,8 +386,8 @@ public void onFinishFloatingView() { public void onTouchFinished(boolean isFinishing, int x, int y) { if (!isFinishing) { editor = PreferenceManager.getDefaultSharedPreferences(this).edit(); - editor.putInt(PREF_KEY_LAST_POSITION_X, x); - editor.putInt(PREF_KEY_LAST_POSITION_Y, y); + editor.putInt(Constants.PREF_KEY_LAST_POSITION_X, x); + editor.putInt(Constants.PREF_KEY_LAST_POSITION_Y, y); editor.apply(); } } @@ -415,8 +428,8 @@ private FloatingViewManager.Options loadOptions(DisplayMetrics metrics) { if (isUseLastPosition) { final int defaultX = options.floatingViewX; final int defaultY = options.floatingViewY; - options.floatingViewX = sharedPref.getInt(PREF_KEY_LAST_POSITION_X, defaultX); - options.floatingViewY = sharedPref.getInt(PREF_KEY_LAST_POSITION_Y, defaultY); + options.floatingViewX = sharedPref.getInt(Constants.PREF_KEY_LAST_POSITION_X, defaultX); + options.floatingViewY = sharedPref.getInt(Constants.PREF_KEY_LAST_POSITION_Y, defaultY); } else { int height = metrics.heightPixels; options.floatingViewX = metrics.widthPixels; @@ -482,8 +495,8 @@ else if (y_cord_Destination + (mFloatingWidgetView.getHeight() + barHeight) > sz mWindowManager.updateViewLayout(mFloatingWidgetView, layoutParams); editor = PreferenceManager.getDefaultSharedPreferences(context).edit(); - editor.putInt(PREF_KEY_LAST_POSITION_X_EXPANDED, layoutParams.x); - editor.putInt(PREF_KEY_LAST_POSITION_Y_EXPANDED, layoutParams.y); + editor.putInt(Constants.PREF_KEY_LAST_POSITION_X_EXPANDED, layoutParams.x); + editor.putInt(Constants.PREF_KEY_LAST_POSITION_Y_EXPANDED, layoutParams.y); editor.apply(); return true; } @@ -556,18 +569,20 @@ private double bounceValue(long step, long scale) { public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); - getWindowManagerDefaultDisplay(); + if (mFloatingWidgetView != null) { + getWindowManagerDefaultDisplay(); - WindowManager.LayoutParams layoutParams = (WindowManager.LayoutParams) mFloatingWidgetView.getLayoutParams(); + WindowManager.LayoutParams layoutParams = (WindowManager.LayoutParams) mFloatingWidgetView.getLayoutParams(); - if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { - if (layoutParams.y + (mFloatingWidgetView.getHeight() + getStatusBarHeight()) > szWindow.y) { - layoutParams.y = szWindow.y - (mFloatingWidgetView.getHeight() + getStatusBarHeight()); - mWindowManager.updateViewLayout(mFloatingWidgetView, layoutParams); + if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { + if (layoutParams.y + (mFloatingWidgetView.getHeight() + getStatusBarHeight()) > szWindow.y) { + layoutParams.y = szWindow.y - (mFloatingWidgetView.getHeight() + getStatusBarHeight()); + mWindowManager.updateViewLayout(mFloatingWidgetView, layoutParams); + } + if (layoutParams.x != 0 && layoutParams.x < szWindow.x) resetPosition(szWindow.x); + } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { + if (layoutParams.x > szWindow.x) resetPosition(szWindow.x); } - if (layoutParams.x != 0 && layoutParams.x < szWindow.x) resetPosition(szWindow.x); - } else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) { - if (layoutParams.x > szWindow.x) resetPosition(szWindow.x); } } @@ -575,26 +590,6 @@ private void getWindowManagerDefaultDisplay() { mWindowManager.getDefaultDisplay().getSize(szWindow); } - private void checkBarsSettings() { - try { - /**/ - mFloatingWidgetView.findViewById(R.id.textViewMedia).setVisibility(PreferenceManager.getDefaultSharedPreferences(this).getBoolean(Constants.SHOW_MEDIA_BAR, true) ? View.VISIBLE : View.GONE); - mFloatingWidgetView.findViewById(R.id.linearLayoutMedia).setVisibility(PreferenceManager.getDefaultSharedPreferences(this).getBoolean(Constants.SHOW_MEDIA_BAR, true) ? View.VISIBLE : View.GONE); - /**/ - /**/ - mFloatingWidgetView.findViewById(R.id.textViewAlarm).setVisibility(PreferenceManager.getDefaultSharedPreferences(this).getBoolean(Constants.SHOW_ALARM_BAR, true) ? View.VISIBLE : View.GONE); - mFloatingWidgetView.findViewById(R.id.linearLayoutAlarm).setVisibility(PreferenceManager.getDefaultSharedPreferences(this).getBoolean(Constants.SHOW_ALARM_BAR, true) ? View.VISIBLE : View.GONE); - /**/ - /**/ - mFloatingWidgetView.findViewById(R.id.textViewRinger).setVisibility(PreferenceManager.getDefaultSharedPreferences(this).getBoolean(Constants.SHOW_RINGER_BAR, true) ? View.VISIBLE : View.GONE); - mFloatingWidgetView.findViewById(R.id.linearLayoutRinger).setVisibility(PreferenceManager.getDefaultSharedPreferences(this).getBoolean(Constants.SHOW_RINGER_BAR, true) ? View.VISIBLE : View.GONE); - /**/ - } catch (Exception e) { - e.printStackTrace(); - - } - } - private int getDialogLayout() { try { if (PreferenceManager.getDefaultSharedPreferences(this).getBoolean(Constants.USE_SLIM_DIALOG, false)) @@ -605,7 +600,4 @@ private int getDialogLayout() { } return R.layout.floating_layout; } - - - } \ No newline at end of file diff --git a/app/src/main/java/com/android/mycax/floatingvolume/utils/Constants.java b/app/src/main/java/com/android/mycax/floatingvolume/utils/Constants.java index ddb4803..eed28a6 100644 --- a/app/src/main/java/com/android/mycax/floatingvolume/utils/Constants.java +++ b/app/src/main/java/com/android/mycax/floatingvolume/utils/Constants.java @@ -1,12 +1,14 @@ package com.android.mycax.floatingvolume.utils; public interface Constants { - - - // Preference Keys - public static final String SHOW_MEDIA_BAR = "show_media_bar"; - public static final String SHOW_RINGER_BAR = "show_ringer_bar"; - public static final String SHOW_ALARM_BAR = "show_alarm_bar"; - public static final String USE_SLIM_DIALOG = "use_slim_dialog"; - // + String PREF_KEY_LAST_POSITION_X = "last_position_x"; + String PREF_KEY_LAST_POSITION_Y = "last_position_y"; + String PREF_KEY_LAST_POSITION_X_EXPANDED = "last_position_x_expanded"; + String PREF_KEY_LAST_POSITION_Y_EXPANDED = "last_position_y_expanded"; + String USE_SLIM_DIALOG = "use_slim_dialog"; + String PREF_ENABLE_DARK_MODE = "enable_dark_mode_switch"; + String PREF_ENABLE_BOUNCE = "enable_bounce_effect"; + String PREF_DISABLE_FIXED_UI = "disable_fixed_ui"; + int OVERLAY_PERMISSION_REQUEST = 1; + int NOTIFICATION_POLICY_PERMISSION_REQUEST = 2; } diff --git a/app/src/main/res/drawable/ic_slim_dialog_black_24dp.xml b/app/src/main/res/drawable/ic_slim_dialog_black_24dp.xml new file mode 100644 index 0000000..380e4b3 --- /dev/null +++ b/app/src/main/res/drawable/ic_slim_dialog_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_slim_dialog_white_24dp.xml b/app/src/main/res/drawable/ic_slim_dialog_white_24dp.xml new file mode 100644 index 0000000..ce0abd2 --- /dev/null +++ b/app/src/main/res/drawable/ic_slim_dialog_white_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/floating_layout.xml b/app/src/main/res/layout/floating_layout.xml index fe174f2..eee29cd 100644 --- a/app/src/main/res/layout/floating_layout.xml +++ b/app/src/main/res/layout/floating_layout.xml @@ -179,7 +179,8 @@ app:layout_constraintStart_toEndOf="@+id/imageViewModeSwitch" app:layout_constraintTop_toTopOf="@+id/linearLayoutAlarm" card_view:layout_constraintBottom_toBottomOf="parent" - tools:ignore="ContentDescription" /> + tools:ignore="ContentDescription" + tools:padding="4dp" /> + tools:ignore="ContentDescription" + tools:padding="4dp" /> \ No newline at end of file diff --git a/app/src/main/res/layout/floating_layout_slim.xml b/app/src/main/res/layout/floating_layout_slim.xml index a675121..9acc8d4 100644 --- a/app/src/main/res/layout/floating_layout_slim.xml +++ b/app/src/main/res/layout/floating_layout_slim.xml @@ -6,7 +6,6 @@ android:id="@+id/root_container" android:layout_width="wrap_content" android:layout_height="wrap_content" - tools:background="@color/colorPrimaryP" tools:ignore="UselessParent"> @@ -38,8 +37,7 @@ app:layout_constraintRight_toRightOf="parent" app:layout_constraintTop_toTopOf="parent" app:layout_constraintVertical_bias="0.0" - tools:ignore="ContentDescription" - tools:src="@drawable/ic_close_black_24dp" /> + tools:ignore="ContentDescription" /> + tools:ignore="ContentDescription" /> + android:layout_height="wrap_content" + android:padding="4dp" + tools:ignore="ContentDescription" /> + android:layout_height="wrap_content" + android:padding="4dp" + tools:ignore="ContentDescription" /> @@ -184,10 +181,9 @@ + android:layout_height="wrap_content" + android:padding="4dp" + tools:ignore="ContentDescription" /> + + + @string/show_media_bar + @string/show_ringer_bar + @string/show_alarm_bar + @string/show_voicecall_bar + + + 1 + 2 + 3 + 4 + + + 1 + 2 + 3 + 4 + + \ No newline at end of file diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index c363235..400237c 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -12,5 +12,6 @@ + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 4232d6c..857dac1 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -18,10 +18,10 @@ Show Media Bar Show Ringer Bar Show Alarm Bar + Show Voice Call Bar + Items to show in floating dialog + Select which seek bars to show in the floating dialog Floating Dialog Settings - Show media bar in floating dialog - Show ringer bar in floating dialog - Show alarm bar in floating dialog Use slim dialog Use slim dialog with small icons nested of the default dialog diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index c11b7e3..34ce5b7 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -14,6 +14,7 @@ @drawable/ic_save_black_24dp @drawable/ic_touch_app_black_24dp @drawable/ic_bounce_black_24dp + @drawable/ic_slim_dialog_black_24dp