[Android] ProgressDialog implem
Geoffrey Métais
git at videolan.org
Thu Feb 4 15:18:57 CET 2016
vlc-android | branch: dialog | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Feb 4 15:18:33 2016 +0100| [d18df5a7ba99c38c63a3ad42f230842b31c886ed] | committer: Geoffrey Métais
ProgressDialog implem
> https://code.videolan.org/videolan/vlc-android/commit/d18df5a7ba99c38c63a3ad42f230842b31c886ed
---
vlc-android/res/layout/vlc_progress_dialog.xml | 40 ++++++++++++
.../src/org/videolan/vlc/VLCApplication.java | 8 ++-
.../src/org/videolan/vlc/gui/DialogActivity.java | 10 +++
.../vlc/gui/dialogs/VlcProgressDialog.java | 72 ++++++++++++++++++++++
4 files changed, 128 insertions(+), 2 deletions(-)
diff --git a/vlc-android/res/layout/vlc_progress_dialog.xml b/vlc-android/res/layout/vlc_progress_dialog.xml
new file mode 100644
index 0000000..629da2a
--- /dev/null
+++ b/vlc-android/res/layout/vlc_progress_dialog.xml
@@ -0,0 +1,40 @@
+<?xml version="1.0" encoding="utf-8"?>
+<layout xmlns:android="http://schemas.android.com/apk/res/android"
+ xmlns:tools="http://schemas.android.com/tools" >
+ <data>
+ <import type="android.text.TextUtils" />
+ <import type="android.view.View" />
+ <variable name="dialog" type="org.videolan.libvlc.Dialog.ProgressDialog"/>
+ <variable name="handler" type="org.videolan.vlc.gui.dialogs.VlcProgressDialog"/>
+ </data>
+ <RelativeLayout
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:padding="10dp">
+
+ <TextView
+ android:id="@+id/text"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:layout_alignParentTop="true"
+ android:text="@{dialog.text}"
+ android:layout_margin="10dp" />
+ <android.support.v4.widget.ContentLoadingProgressBar
+ android:id="@+id/progress"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:max="100"
+ android:indeterminate="@{dialog.isIndeterminate()}"/>
+ <Button
+ android:id="@+id/cancel"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_below="@+id/progress"
+ android:text="@android:string/cancel"
+ android:layout_alignParentRight="true"
+ android:onClick="@{handler.onCancel}"
+ tools:targetApi="11"
+ style="?android:attr/borderlessButtonStyle"
+ android:visibility="@{TextUtils.isEmpty(dialog.cancelText) ? View.GONE : View.VISIBLE}"/>
+ </RelativeLayout>
+</layout>
diff --git a/vlc-android/src/org/videolan/vlc/VLCApplication.java b/vlc-android/src/org/videolan/vlc/VLCApplication.java
index c9d5176..51b1b10 100644
--- a/vlc-android/src/org/videolan/vlc/VLCApplication.java
+++ b/vlc-android/src/org/videolan/vlc/VLCApplication.java
@@ -27,11 +27,13 @@ import android.content.res.Configuration;
import android.content.res.Resources;
import android.preference.PreferenceManager;
import android.support.v4.app.DialogFragment;
+import android.support.v4.content.LocalBroadcastManager;
import android.support.v4.util.SimpleArrayMap;
import android.util.Log;
import org.videolan.libvlc.Dialog;
import org.videolan.vlc.gui.DialogActivity;
+import org.videolan.vlc.gui.dialogs.VlcProgressDialog;
import org.videolan.vlc.gui.helpers.AudioUtil;
import org.videolan.vlc.gui.helpers.BitmapCache;
import org.videolan.vlc.media.MediaDatabase;
@@ -63,6 +65,8 @@ public class VLCApplication extends Application {
new LinkedBlockingQueue<Runnable>());
private static int sDialogCounter = 0;
+ LocalBroadcastManager mLocalBroadcastManager;
+
@Override
public void onCreate() {
super.onCreate();
@@ -190,6 +194,7 @@ public class VLCApplication extends Application {
Log.d(TAG, "onDisplay ProgressDialog");
String key = DialogActivity.KEY_PROGRESS + sDialogCounter++;
fireDialog(dialog, key);
+ mLocalBroadcastManager = LocalBroadcastManager.getInstance(instance);
}
@Override
@@ -200,8 +205,7 @@ public class VLCApplication extends Application {
@Override
public void onProgressUpdate(Dialog.ProgressDialog dialog) {
- Log.d(TAG, "onProgressUpdate");
- //TODO
+ mLocalBroadcastManager.sendBroadcast(new Intent(VlcProgressDialog.ACTION_PROGRESS));
}
};
diff --git a/vlc-android/src/org/videolan/vlc/gui/DialogActivity.java b/vlc-android/src/org/videolan/vlc/gui/DialogActivity.java
index 7a5471f..dbda66d 100644
--- a/vlc-android/src/org/videolan/vlc/gui/DialogActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/DialogActivity.java
@@ -29,6 +29,7 @@ import android.support.v7.app.AppCompatActivity;
import org.videolan.vlc.gui.dialogs.VlcDialog;
import org.videolan.vlc.gui.dialogs.VlcLoginDialog;
+import org.videolan.vlc.gui.dialogs.VlcProgressDialog;
import org.videolan.vlc.gui.dialogs.VlcQuestionDialog;
public class DialogActivity extends AppCompatActivity {
@@ -45,6 +46,10 @@ public class DialogActivity extends AppCompatActivity {
setupLoginDialog(key);
else if (key.startsWith(KEY_QUESTION))
setupQuestionDialog(key);
+ else if (key.startsWith(KEY_PROGRESS))
+ setupProgressDialog(key);
+ else
+ finish();
}
private void setupLoginDialog(String key) {
@@ -57,6 +62,11 @@ public class DialogActivity extends AppCompatActivity {
startVlcDialog(key, dialog);
}
+ private void setupProgressDialog(String key) {
+ VlcProgressDialog dialog = new VlcProgressDialog();
+ startVlcDialog(key, dialog);
+ }
+
private void startVlcDialog(String key, VlcDialog dialog) {
dialog.init(key);
FragmentManager fm = getSupportFragmentManager();
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/VlcProgressDialog.java b/vlc-android/src/org/videolan/vlc/gui/dialogs/VlcProgressDialog.java
new file mode 100644
index 0000000..2a54508
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/VlcProgressDialog.java
@@ -0,0 +1,72 @@
+/*
+ * ************************************************************************
+ * VlcProgressDialog.java
+ * *************************************************************************
+ * Copyright © 2016 VLC authors and VideoLAN
+ * Author: Geoffrey Métais
+ *
+ * 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, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ *
+ * *************************************************************************
+ */
+
+package org.videolan.vlc.gui.dialogs;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.IntentFilter;
+import android.os.Bundle;
+import android.support.v4.content.LocalBroadcastManager;
+import android.text.TextUtils;
+import android.view.View;
+
+import org.videolan.libvlc.Dialog;
+import org.videolan.vlc.R;
+import org.videolan.vlc.databinding.VlcProgressDialogBinding;
+
+public class VlcProgressDialog extends VlcDialog<Dialog.ProgressDialog, VlcProgressDialogBinding> {
+
+ public static final String ACTION_PROGRESS = "vlc_progress";
+ LocalBroadcastManager mLocalBroadcastManager;
+
+ @Override
+ int getLayout() {
+ return R.layout.vlc_progress_dialog;
+ }
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ mLocalBroadcastManager = LocalBroadcastManager.getInstance(getContext());
+ mLocalBroadcastManager.registerReceiver(mProgressReceiver, new IntentFilter(ACTION_PROGRESS));
+ }
+
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+ mLocalBroadcastManager.unregisterReceiver(mProgressReceiver);
+ }
+
+ private final BroadcastReceiver mProgressReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ mBinding.progress.setProgress((int) (mVlcDialog.getPosition()*100));
+ mBinding.cancel.setText(mVlcDialog.getCancelText());
+ mBinding.cancel.setVisibility(
+ TextUtils.isEmpty(mVlcDialog.getCancelText()) ? View.GONE : View.VISIBLE);
+ }
+ };
+}
More information about the Android
mailing list