[Android] Confirm app exit in multiwindow mode
Geoffrey Métais
git at videolan.org
Tue Aug 29 12:15:23 CEST 2017
vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Tue Aug 29 12:14:43 2017 +0200| [e56b14e864de274187ed092f62d9084b4858630a] | committer: Geoffrey Métais
Confirm app exit in multiwindow mode
> https://code.videolan.org/videolan/vlc-android/commit/e56b14e864de274187ed092f62d9084b4858630a
---
vlc-android/res/values/strings.xml | 1 +
.../src/org/videolan/vlc/gui/MainActivity.java | 7 ++-
.../src/org/videolan/vlc/gui/helpers/UiTools.java | 58 ++++++++++++++--------
3 files changed, 45 insertions(+), 21 deletions(-)
diff --git a/vlc-android/res/values/strings.xml b/vlc-android/res/values/strings.xml
index 5a0732565..6a452f28d 100644
--- a/vlc-android/res/values/strings.xml
+++ b/vlc-android/res/values/strings.xml
@@ -489,6 +489,7 @@
<string name="allow_sdraw_overlays_description">VLC needs you to grant this permission display your video in a popup over other applications.</string>
<string name="permission_ask_again">Grant permission</string>
<string name="exit_app">Close VLC</string>
+ <string name="exit_app_msg">Are you sur you want to quit VLC?</string>
<!-- fast scroller -->
<string name="fastscroller_track">FastScroller track</string>
diff --git a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
index 3866677cc..ae793dc4c 100644
--- a/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/MainActivity.java
@@ -51,6 +51,7 @@ import android.view.View;
import android.view.ViewGroup;
import android.widget.FilterQueryProvider;
+import org.videolan.libvlc.util.AndroidUtil;
import org.videolan.medialibrary.Medialibrary;
import org.videolan.vlc.BuildConfig;
import org.videolan.vlc.MediaParsingService;
@@ -349,7 +350,7 @@ public class MainActivity extends ContentActivity implements FilterQueryProvider
@Override
public void onBackPressed() {
/* Close the menu first */
- if(mDrawerLayout.isDrawerOpen(mNavigationView)) {
+ if (mDrawerLayout.isDrawerOpen(mNavigationView)) {
mDrawerLayout.closeDrawer(mNavigationView);
return;
}
@@ -367,6 +368,10 @@ public class MainActivity extends ContentActivity implements FilterQueryProvider
((ExtensionBrowser) fragment).goBack();
return;
}
+ if (AndroidUtil.isNougatOrLater && isInMultiWindowMode()) {
+ UiTools.confirmExit(this);
+ return;
+ }
finish();
}
diff --git a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
index 96790e648..07e6fdce9 100644
--- a/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
+++ b/vlc-android/src/org/videolan/vlc/gui/helpers/UiTools.java
@@ -26,6 +26,7 @@ package org.videolan.vlc.gui.helpers;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
+import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.content.res.TypedArray;
import android.databinding.BindingAdapter;
@@ -46,6 +47,7 @@ import android.support.annotation.RequiresApi;
import android.support.design.widget.Snackbar;
import android.support.v4.app.FragmentActivity;
import android.support.v4.content.ContextCompat;
+import android.support.v7.app.AlertDialog;
import android.text.Html;
import android.text.TextUtils;
import android.util.DisplayMetrics;
@@ -301,35 +303,35 @@ public class UiTools {
if (bitmap == null || bitmap.getConfig() == null)
return null;
- //Let's create an empty bitmap with the same size of the bitmap we want to blur
- Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
+ //Let's create an empty bitmap with the same size of the bitmap we want to blur
+ Bitmap outBitmap = Bitmap.createBitmap(bitmap.getWidth(), bitmap.getHeight(), Bitmap.Config.ARGB_8888);
- //Instantiate a new Renderscript
- RenderScript rs = RenderScript.create(VLCApplication.getAppContext());
+ //Instantiate a new Renderscript
+ RenderScript rs = RenderScript.create(VLCApplication.getAppContext());
- //Create an Intrinsic Blur Script using the Renderscript
- ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
+ //Create an Intrinsic Blur Script using the Renderscript
+ ScriptIntrinsicBlur blurScript = ScriptIntrinsicBlur.create(rs, Element.U8_4(rs));
- //Create the Allocations (in/out) with the Renderscript and the in/out bitmaps
- Allocation allIn = Allocation.createFromBitmap(rs, bitmap);
- Allocation allOut = Allocation.createFromBitmap(rs, outBitmap);
+ //Create the Allocations (in/out) with the Renderscript and the in/out bitmaps
+ Allocation allIn = Allocation.createFromBitmap(rs, bitmap);
+ Allocation allOut = Allocation.createFromBitmap(rs, outBitmap);
- //Set the radius of the blur
- blurScript.setRadius(radius);
+ //Set the radius of the blur
+ blurScript.setRadius(radius);
- //Perform the Renderscript
- blurScript.setInput(allIn);
- blurScript.forEach(allOut);
+ //Perform the Renderscript
+ blurScript.setInput(allIn);
+ blurScript.forEach(allOut);
- //Copy the final bitmap created by the out Allocation to the outBitmap
- allOut.copyTo(outBitmap);
+ //Copy the final bitmap created by the out Allocation to the outBitmap
+ allOut.copyTo(outBitmap);
- //After finishing everything, we destroy the Renderscript.
- rs.destroy();
+ //After finishing everything, we destroy the Renderscript.
+ rs.destroy();
- return outBitmap;
- }
+ return outBitmap;
+ }
public static void updateSortTitles(SortableFragment sortable, Menu menu) {
MenuItem item = menu.findItem(R.id.ml_menu_sortby_name);
@@ -395,4 +397,20 @@ public class UiTools {
item.setTitle(R.string.sortby_number);
}
}
+
+ public static void confirmExit(final Activity activity) {
+ new AlertDialog.Builder(activity)
+ .setMessage(R.string.exit_app_msg)
+ .setTitle(R.string.exit_app)
+ .setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ activity.finish();
+ }
+ })
+ .setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
+ public void onClick(DialogInterface dialog, int id) {
+ dialog.dismiss();
+ }
+ }).create().show();
+ }
}
More information about the Android
mailing list