Skip to content
Snippets Groups Projects
Commit 10737125 authored by Geoffrey Métais's avatar Geoffrey Métais Committed by Thomas Guillem
Browse files

VLC Dialogs implementation


Signed-off-by: default avatarThomas Guillem <thomas@gllm.fr>
parent b6ace7a2
No related branches found
No related tags found
No related merge requests found
Showing
with 557 additions and 2 deletions
......@@ -455,8 +455,11 @@
<activity
android:name=".gui.video.VideoPlayerActivity"
android:configChanges="orientation|screenSize"
android:theme="@style/Theme.VLC.Player" >
</activity>
android:theme="@style/Theme.VLC.Player" />
<activity
android:name=".gui.DialogActivity"
android:theme="@style/TransparentTheme" />
<service android:name=".extensions.ExtensionManagerService" />
<service android:name=".PlaybackService" />
......
<?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.view.View" />
<variable name="dialog" type="org.videolan.libvlc.Dialog.LoginDialog"/>
<variable name="handler" type="org.videolan.vlc.gui.dialogs.VlcLoginDialog"/>
</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:layout_margin="10dp"
android:text="@{dialog.text}"/>
<android.support.design.widget.TextInputLayout
android:id="@+id/login_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/text"
android:layout_margin="10dp" >
<EditText
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minWidth="200dp"
android:hint="@string/login"
android:inputType="textNoSuggestions"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/password_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/login_container"
android:layout_margin="10dp" >
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minWidth="200dp"
android:hint="@string/password"
android:inputType="textPassword"
android:singleLine="true" />
</android.support.design.widget.TextInputLayout>
<CheckBox
android:id="@+id/store"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/password_container"
android:text="store"
android:layout_alignParentLeft="true"
android:layout_margin="5dp"
android:visibility="@{dialog.asksStore() ? View.VISIBLE : View.GONE}"/>
<Button
android:id="@+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/store"
android:layout_toLeftOf="@+id/action"
android:text="@android:string/cancel"
android:onClick="@{handler.onCancel}"
tools:targetApi="11"
style="?android:attr/borderlessButtonStyle" />
<Button
android:id="@+id/action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/store"
android:text="@android:string/ok"
android:onClick="@{handler.onLogin}"
tools:targetApi="11"
style="?android:attr/borderlessButtonStyle" />
</RelativeLayout>
</layout>
<?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>
<?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.QuestionDialog"/>
<variable name="handler" type="org.videolan.vlc.gui.dialogs.VlcQuestionDialog"/>
</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" />
<Button
android:id="@+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/store"
android:text="@android:string/cancel"
android:layout_toLeftOf="@+id/action1"
android:onClick="@{handler.onCancel}"
tools:targetApi="11"
style="?android:attr/borderlessButtonStyle" />
<Button
android:id="@+id/action1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="@+id/action2"
android:layout_below="@+id/store"
android:text="@{dialog.action1Text}"
android:visibility="@{TextUtils.isEmpty(dialog.action1Text) ? View.GONE : View.VISIBLE}"
android:onClick="@{handler.onAction1}"
tools:targetApi="11"
style="?android:attr/borderlessButtonStyle" />
<Button
android:id="@+id/action2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/store"
android:text="@{dialog.action2Text}"
android:visibility="@{TextUtils.isEmpty(dialog.action2Text) ? View.GONE : View.VISIBLE}"
android:onClick="@{handler.onAction2}"
tools:targetApi="11"
style="?android:attr/borderlessButtonStyle" />
</RelativeLayout>
</layout>
......@@ -159,6 +159,8 @@
<string name="server_username_hint">Username</string>
<string name="server_servername_hint">Server name, for conveniency</string>
<string name="server_port">Port: </string>
<string name="login">Login</string>
<string name="password">Password</string>
<string name="search_results">Search results</string>
<string name="favorites_add">Add to favorites</string>
......
......@@ -21,18 +21,25 @@ package org.videolan.vlc;
import android.app.Application;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
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;
import org.videolan.vlc.util.AndroidDevices;
import org.videolan.vlc.util.Strings;
import org.videolan.vlc.util.VLCInstance;
import java.util.Calendar;
import java.util.Locale;
......@@ -56,6 +63,10 @@ public class VLCApplication extends Application {
/* Up to 2 threads maximum, inactive threads are killed after 2 seconds */
private ThreadPoolExecutor mThreadPool = new ThreadPoolExecutor(0, 2, 2, TimeUnit.SECONDS,
new LinkedBlockingQueue<Runnable>());
private static int sDialogCounter = 0;
LocalBroadcastManager mLocalBroadcastManager;
@Override
public void onCreate() {
super.onCreate();
......@@ -99,6 +110,8 @@ public class VLCApplication extends Application {
AudioUtil.prepareCacheFolder(this);
sTV = AndroidDevices.isAndroidTv() || !AndroidDevices.hasTsp();
Dialog.setCallbacks(VLCInstance.get(), mDialogCallbacks);
}
/**
......@@ -155,4 +168,46 @@ public class VLCApplication extends Application {
public static Object getData(String key) {
return sDataMap.remove(key);
}
Dialog.Callbacks mDialogCallbacks = new Dialog.Callbacks() {
@Override
public void onDisplay(Dialog.ErrorMessage dialog) {
Log.w(TAG, "ErrorMessage "+dialog.getText());
}
@Override
public void onDisplay(Dialog.LoginDialog dialog) {
String key = DialogActivity.KEY_LOGIN + sDialogCounter++;
fireDialog(dialog, key);
}
@Override
public void onDisplay(Dialog.QuestionDialog dialog) {
String key = DialogActivity.KEY_QUESTION + sDialogCounter++;
fireDialog(dialog, key);
}
@Override
public void onDisplay(Dialog.ProgressDialog dialog) {
String key = DialogActivity.KEY_PROGRESS + sDialogCounter++;
fireDialog(dialog, key);
mLocalBroadcastManager = LocalBroadcastManager.getInstance(instance);
}
@Override
public void onCanceled(Dialog dialog) {
((DialogFragment)dialog.getContext()).dismiss();
}
@Override
public void onProgressUpdate(Dialog.ProgressDialog dialog) {
mLocalBroadcastManager.sendBroadcast(new Intent(VlcProgressDialog.ACTION_PROGRESS));
}
};
private void fireDialog(Dialog dialog, String key) {
storeData(key, dialog);
startActivity(new Intent(instance, DialogActivity.class).setAction(key)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
}
/*
* ***************************************************************************
* DialogActivity.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;
import android.os.Bundle;
import android.support.v4.app.FragmentManager;
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 {
public static final String KEY_LOGIN = "LoginDialog";
public static final String KEY_QUESTION = "QuestionDialog";
public static final String KEY_PROGRESS = "ProgressDialog";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String key = getIntent().getAction();
if (key.startsWith(KEY_LOGIN))
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) {
VlcLoginDialog dialog = new VlcLoginDialog();
startVlcDialog(key, dialog);
}
private void setupQuestionDialog(String key) {
VlcQuestionDialog dialog = new VlcQuestionDialog();
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();
dialog.show(fm, key);
}
}
// *************************************************************************
// VlcDialog.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.databinding.DataBindingUtil;
import android.os.Bundle;
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 org.videolan.libvlc.Dialog;
import org.videolan.vlc.BR;
import org.videolan.vlc.VLCApplication;
public abstract class VlcDialog<T extends Dialog, B extends android.databinding.ViewDataBinding> extends DialogFragment {
T mVlcDialog;
B mBinding;
abstract int getLayout();
public void init(String key) {
mVlcDialog = (T) VLCApplication.getData(key);
}
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
mBinding = DataBindingUtil.inflate(inflater, getLayout(), container, false);
mBinding.setVariable(BR.dialog, mVlcDialog);
mBinding.setVariable(BR.handler, this);
return mBinding.getRoot();
}
@NonNull
@Override
public android.app.Dialog onCreateDialog(Bundle savedInstanceState) {
mVlcDialog.setContext(this);
AppCompatDialog dialog = new AppCompatDialog(getActivity(), getTheme());
dialog.setTitle(mVlcDialog.getTitle());
dialog.setCancelable(true);
dialog.setCanceledOnTouchOutside(true);
return dialog;
}
@Override
public void onDestroy() {
super.onDestroy();
mVlcDialog.dismiss();
getActivity().finish();
}
public void onCancel(View v) {
dismiss();
}
}
/*
* ************************************************************************
* NetworkLoginDialog.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.view.View;
import org.videolan.libvlc.Dialog;
import org.videolan.vlc.R;
import org.videolan.vlc.databinding.VlcLoginDialogBinding;
public class VlcLoginDialog extends VlcDialog<Dialog.LoginDialog, VlcLoginDialogBinding> {
@Override
int getLayout() {
return R.layout.vlc_login_dialog;
}
public void onLogin(View v) {
mVlcDialog.postLogin(mBinding.login.getText().toString().trim(),
mBinding.password.getText().toString().trim(), mBinding.store.isChecked());
dismiss();
}
}
/*
* ************************************************************************
* 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);
}
};
}
/*
* ***************************************************************************
* VlcQuestionDialog.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.view.View;
import org.videolan.libvlc.Dialog;
import org.videolan.vlc.R;
import org.videolan.vlc.databinding.VlcQuestionDialogBinding;
public class VlcQuestionDialog extends VlcDialog<Dialog.QuestionDialog, VlcQuestionDialogBinding> {
@Override
int getLayout() {
return R.layout.vlc_question_dialog;
}
public void onAction1(View v) {
mVlcDialog.postAction(1);
}
public void onAction2(View v) {
mVlcDialog.postAction(2);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment