Commit 66e692f6 authored by Sébastien Toque's avatar Sébastien Toque

UI: replace speed/sleep/jump menu & dialog by a new alertdialog

parent c418d47c
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/adv_func"
android:layout_width="450dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="5dp" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:weightSum="7" >
<TextView
android:id="@+id/adv_func_speed_text"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:gravity="center|left"
android:text="@string/playback_speed"
android:textSize="22sp" />
<TextView
android:id="@+id/adv_func_speed_info"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="center_horizontal|center_vertical"
android:text="@string/speed_placeholder"
android:textColor="@color/orange"
android:textSize="22sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="right" >
<ImageButton
android:id="@+id/adv_func_speed"
android:layout_width="50dp"
android:layout_height="50dp"
android:background="@drawable/ic_forward" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:weightSum="7" >
<TextView
android:id="@+id/adv_func_sleep_title"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:gravity="center|left"
android:text="@string/sleep_title"
android:textSize="22sp" />
<!-- Sleep Info TextView for future function -->
<TextView
android:id="@+id/adv_func_sleep_info"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="center_horizontal|center_vertical"
android:text="test"
android:textColor="@color/orange"
android:textSize="22sp"
android:textStyle="bold"
android:visibility="invisible" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="right" >
<!-- Sleep Cancel button for future function -->
<ImageButton
android:id="@+id/adv_func_sleep_cancel"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:background="@drawable/sleep_cancel"
android:visibility="gone" />
<ImageButton
android:id="@+id/adv_func_sleep"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="10dp"
android:background="@drawable/sleep" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="300dp"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</ScrollView>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/playback_speed"
android:title="@string/playback_speed" />
<item
android:id="@+id/sleep_timer"
android:title="@string/sleep_title" />
<item
android:id="@+id/go_to_time"
android:title="@string/jump_to_time" />
</menu>
\ No newline at end of file
......@@ -18,4 +18,14 @@
<item name="android:background">@drawable/actionbar_background</item>
<item name="background">@drawable/actionbar_background</item>
</style>
<style name="Theme.VLC.AlertMenu" parent="android:Theme.Dialog">
<item name="android:windowBackground">@null</item>
<item name="android:windowFrame">@null</item>
<item name="windowContentOverlay">@null</item>
<item name="android:windowAnimationStyle">@null</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowNoTitle">true</item>
</style>
</resources>
/*****************************************************************************
* AdvFuncDialog.java
*****************************************************************************
* Copyright © 2012 VLC authors and VideoLAN
*
* 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 java.util.Calendar;
import org.videolan.vlc.LibVLC;
import org.videolan.vlc.R;
import org.videolan.vlc.Util;
import org.videolan.vlc.gui.SpeedSelectorDialog;
import org.videolan.vlc.gui.TimeSleepDialog;
import android.app.Activity;
import android.app.Dialog;
import android.content.DialogInterface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.TextView;
public class AdvFuncDialog extends Dialog {
public final static String TAG = "VLC/AdvFuncPopupWindow";
private static View mAdvFuncView;
private ImageButton mSleep;
private TimeSleepDialog mTimeSleepDialog;
private ImageButton mSpeed;
private TextView mSpeedInfo;
private SpeedSelectorDialog mSpeedSelectorDialog;
/**
* Put all advance functionality here
*/
public AdvFuncDialog(Activity activity) {
super(activity);
setOwnerActivity(activity);
LayoutInflater inflater = LayoutInflater.from(getOwnerActivity());
mAdvFuncView = inflater.inflate(R.layout.advance_function,
(ViewGroup) findViewById(R.id.adv_func));
setContentView(mAdvFuncView);
setTitle(getOwnerActivity().getString(R.string.tools));
setCanceledOnTouchOutside(true);
// Init Sleep function
mSleep = (ImageButton) mAdvFuncView.findViewById(R.id.adv_func_sleep);
mSleep.setOnClickListener(mSleepListener);
// Init Speed function
mSpeed = (ImageButton) mAdvFuncView.findViewById(R.id.adv_func_speed);
mSpeed.setOnClickListener(mSpeedLabelListener);
mSpeedInfo = (TextView) mAdvFuncView.findViewById(R.id.adv_func_speed_info);
mSpeedInfo.setText(getSpeedInfo());
}
private final View.OnClickListener mSleepListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
mTimeSleepDialog = new TimeSleepDialog(getOwnerActivity(), hour, minute);
};
};
private final View.OnClickListener mSpeedLabelListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
mSpeedSelectorDialog = new SpeedSelectorDialog(getOwnerActivity());
mSpeedSelectorDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
mSpeedInfo.setText(getSpeedInfo());
}
});
mSpeedSelectorDialog.show();
}
};
/**
* Return play speed
*/
private String getSpeedInfo() {
LibVLC libVLC = LibVLC.getExistingInstance();
if (libVLC != null)
return Util.formatRateString(libVLC.getRate());
else
return "";
}
public void destroyAdvFuncDialog() {
// Dismiss secondary window
if(mTimeSleepDialog != null) {
if(mTimeSleepDialog.isShowing()) {
mTimeSleepDialog.dismiss();
}
}
if(mSpeedSelectorDialog != null) {
if (mSpeedSelectorDialog.isShowing()) {
mSpeedSelectorDialog.dismiss();
}
}
// Dismiss main window
if(isShowing())
dismiss();
}
}
......@@ -25,11 +25,18 @@ import java.net.URI;
import java.net.URISyntaxException;
import org.videolan.vlc.R;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.VlcRunnable;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.view.ContextThemeWrapper;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager.LayoutParams;
public class CommonDialogs {
public final static String TAG = "VLC/CommonDialogs";
......@@ -61,4 +68,31 @@ public class CommonDialogs {
return alertDialog;
}
public static void advancedOptions(final Context context, View v) {
LayoutInflater inflater = LayoutInflater.from(VLCApplication.getAppContext());
View view = inflater.inflate(R.layout.advanced_options, null);
Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(context, R.style.Theme_VLC_AlertMenu))
.setView(view);
AlertDialog dialog = builder.create();
dialog.setCanceledOnTouchOutside(true);
dialog.show();
// force size
float density = context.getResources().getDisplayMetrics().density;
LayoutParams lp = dialog.getWindow().getAttributes();
lp.width = (int) (density * 300 + 0.5f); // 300dp
// force location
if (v != null) {
lp.gravity = Gravity.TOP | Gravity.LEFT;
int[] location = new int[2];
v.getLocationInWindow(location);
lp.x = location[0] - lp.width;
lp.y = location[1] - (int) (density * 50 + 0.5f); // -50dp to compensate alertdialog margins
}
dialog.getWindow().setAttributes(lp);
}
}
......@@ -20,41 +20,28 @@
package org.videolan.vlc.gui.audio;
import java.util.Calendar;
import org.videolan.vlc.AudioService;
import org.videolan.vlc.AudioServiceController;
import org.videolan.vlc.R;
import org.videolan.vlc.RepeatType;
import org.videolan.vlc.Util;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.gui.AdvFuncDialog;
import org.videolan.vlc.gui.JumpToTimeDialog;
import org.videolan.vlc.gui.CommonDialogs;
import org.videolan.vlc.gui.MainActivity;
import org.videolan.vlc.gui.SpeedSelectorDialog;
import org.videolan.vlc.gui.TimeSleepDialog;
import org.videolan.vlc.interfaces.IAudioPlayer;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.media.AudioManager;
import android.os.Build;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.KeyEvent;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.PopupMenu;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
......@@ -81,9 +68,6 @@ public class AudioPlayerActivity extends Activity implements IAudioPlayer {
private boolean mShowRemainingTime = false;
private String lastTitle;
// Advance Function
private AdvFuncDialog mAdvFuncDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
......@@ -151,8 +135,6 @@ public class AudioPlayerActivity extends Activity implements IAudioPlayer {
@Override
protected void onStop() {
super.onStop();
if (mAdvFuncDialog != null)
mAdvFuncDialog.destroyAdvFuncDialog();
}
public static void start(Context context) {
......@@ -339,55 +321,7 @@ public class AudioPlayerActivity extends Activity implements IAudioPlayer {
return super.onKeyDown(keyCode, event);
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void showAdvanceFunction(View v) {
if(!Util.isHoneycombOrLater()) { // show the 2.3-style menu
registerForContextMenu(v);
openContextMenu(v);
return;
}
// Inherit native app context to get the new style
// If we use this (Activity) context we get the ugly white style
PopupMenu popupMenu = new PopupMenu(VLCApplication.getAppContext(), v);
popupMenu.getMenuInflater().inflate(R.menu.player_overflow, popupMenu.getMenu());
popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
return handleContextItemSelected(item);
}
});
popupMenu.show();
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.player_overflow, menu);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
return handleContextItemSelected(item);
}
private boolean handleContextItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.playback_speed:
new SpeedSelectorDialog(this).show();
return true;
case R.id.sleep_timer:
final Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
new TimeSleepDialog(this, hour, minute);
return true;
case R.id.go_to_time:
new JumpToTimeDialog(this, AudioServiceController.getInstance().getTime()).show();
return true;
}
return false;
CommonDialogs.advancedOptions(this, v);
}
}
......@@ -36,7 +36,7 @@ import org.videolan.vlc.R;
import org.videolan.vlc.Util;
import org.videolan.vlc.VLCApplication;
import org.videolan.vlc.WeakHandler;
import org.videolan.vlc.gui.AdvFuncDialog;
import org.videolan.vlc.gui.CommonDialogs;
import org.videolan.vlc.gui.PreferencesActivity;
import org.videolan.vlc.gui.audio.AudioPlayerActivity;
import org.videolan.vlc.interfaces.IPlayerControl;
......@@ -175,9 +175,6 @@ public class VideoPlayerActivity extends Activity {
private Map<Integer,String> mAudioTracksList;
private Map<Integer,String> mSubtitleTracksList;
// Advance Function
private AdvFuncDialog mAdvFuncDialog;
@Override
@TargetApi(11)
protected void onCreate(Bundle savedInstanceState) {
......@@ -385,8 +382,6 @@ public class VideoPlayerActivity extends Activity {
@Override
protected void onStop() {
super.onStop();
if (mAdvFuncDialog != null)
mAdvFuncDialog.destroyAdvFuncDialog();
}
@Override
......@@ -1485,8 +1480,6 @@ public class VideoPlayerActivity extends Activity {
}
public void showAdvanceFunction(View v) {
if (mAdvFuncDialog == null)
mAdvFuncDialog = new AdvFuncDialog(this);
mAdvFuncDialog.show();
CommonDialogs.advancedOptions(this, v);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment