[Android] Begining of download dialog

Geoffrey Métais git at videolan.org
Mon Dec 21 17:22:05 CET 2015


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Fri Dec 18 18:09:32 2015 +0100| [bfedb9837528236e64363d74456bb304c2bc24b7] | committer: Geoffrey Métais

Begining of download dialog

> https://code.videolan.org/videolan/vlc-android/commit/bfedb9837528236e64363d74456bb304c2bc24b7
---

 vlc-android/res/layout/dialog_download.xml         | 25 +++++++
 vlc-android/res/menu/extension_context_menu.xml    |  3 +-
 .../vlc/gui/dialogs/DownloaderDialogFragment.java  | 87 ++++++++++++++++++++++
 3 files changed, 114 insertions(+), 1 deletion(-)

diff --git a/vlc-android/res/layout/dialog_download.xml b/vlc-android/res/layout/dialog_download.xml
new file mode 100644
index 0000000..f6a09a4
--- /dev/null
+++ b/vlc-android/res/layout/dialog_download.xml
@@ -0,0 +1,25 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:layout_width="match_parent" android:layout_height="match_parent">
+
+    <ProgressBar
+        android:id="@+id/download_progress"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:indeterminate="false"
+        android:max="100"
+        android:progress="0"/>
+    <TextView
+        android:id="@+id/download_text"
+        android:layout_width="match_parent"
+        android:layout_height="wrap_content"
+        android:layout_below="@+id/download_progress"/>
+    <Button
+        android:id="@+id/download_cancel"
+        android:layout_width="wrap_content"
+        android:layout_height="wrap_content"
+        android:layout_below="@+id/download_text"
+        android:layout_alignParentRight="true"
+        android:layout_alignParentBottom="true"/>
+
+</RelativeLayout>
\ No newline at end of file
diff --git a/vlc-android/res/menu/extension_context_menu.xml b/vlc-android/res/menu/extension_context_menu.xml
index 4c40cc4..241612f 100644
--- a/vlc-android/res/menu/extension_context_menu.xml
+++ b/vlc-android/res/menu/extension_context_menu.xml
@@ -11,5 +11,6 @@
         android:title="@string/play_as_audio" />
     <item
         android:id="@+id/extension_item_download"
-        android:title="@string/download_on_device" />
+        android:title="@string/download_on_device"
+        android:visible="false"/>
 </menu>
\ No newline at end of file
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/DownloaderDialogFragment.java b/vlc-android/src/org/videolan/vlc/gui/dialogs/DownloaderDialogFragment.java
new file mode 100644
index 0000000..f6232a0
--- /dev/null
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/DownloaderDialogFragment.java
@@ -0,0 +1,87 @@
+package org.videolan.vlc.gui.dialogs;
+
+import android.app.Dialog;
+import android.os.Bundle;
+import android.os.Handler;
+import android.os.Message;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
+import android.support.v4.app.DialogFragment;
+import android.support.v7.app.AppCompatDialog;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import android.widget.ProgressBar;
+import android.widget.TextView;
+
+import org.videolan.vlc.R;
+
+public class DownloaderDialogFragment extends DialogFragment implements View.OnClickListener {
+
+    private static final int DOWNLOAD_PROGRESS = 40;
+    private static final int DOWNLOAD_INDETERMINATE = 41;
+
+    public static final String KEY_URL = "url";
+    public static final String KEY_TITLE = "title";
+
+    ProgressBar mProgress;
+    TextView mText;
+    Button mCancelButton;
+
+    private  String mUrl, mtitle;
+
+    public DownloaderDialogFragment() {
+        startDownload();
+    }
+
+    @NonNull
+    @Override
+    public Dialog onCreateDialog(Bundle savedInstanceState) {
+
+        return new AppCompatDialog(getActivity(), getTheme());
+
+    }
+
+    @Override
+    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
+        Bundle args = getArguments();
+        mtitle = args.getString(KEY_TITLE);
+        mUrl = args.getString(KEY_URL);
+        View view = inflater.inflate(R.layout.dialog_download, container);
+
+        mProgress = (ProgressBar) view.findViewById(R.id.download_progress);
+        mText = (TextView) view.findViewById(R.id.download_text);
+        mCancelButton = (Button) view.findViewById(R.id.download_cancel);
+        mCancelButton.setOnClickListener(this);
+
+        mText.setText("Downloading " + mtitle);
+        return view;
+    }
+
+    private void startDownload() {
+        //TODO
+    }
+
+    Handler mHandler = new Handler() {
+        @Override
+        public void handleMessage(Message msg) {
+            switch (msg.what) {
+                case DOWNLOAD_PROGRESS:
+                    mProgress.setProgress(msg.arg1);
+                    break;
+                case DOWNLOAD_INDETERMINATE:
+                    mProgress.setIndeterminate(true);
+                    break;
+            }
+        }
+    };
+
+    @Override
+    public void onClick(View v) {
+        switch (v.getId()) {
+            case R.id.download_cancel:
+                //TODO
+        }
+    }
+}



More information about the Android mailing list