From 9d4ace97bf0a391c6ef44040dc4daec51d02ad8e Mon Sep 17 00:00:00 2001 From: Pierfrancesco Soffritti Date: Mon, 13 Nov 2017 21:33:30 +0100 Subject: [PATCH 1/2] added menu icon --- .../src/main/res/drawable/ic_menu_24dp.xml | 9 +++++++ .../src/main/res/layout/player_controls.xml | 25 ++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 YouTubePlayer/src/main/res/drawable/ic_menu_24dp.xml diff --git a/YouTubePlayer/src/main/res/drawable/ic_menu_24dp.xml b/YouTubePlayer/src/main/res/drawable/ic_menu_24dp.xml new file mode 100644 index 00000000..87e46d1a --- /dev/null +++ b/YouTubePlayer/src/main/res/drawable/ic_menu_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/YouTubePlayer/src/main/res/layout/player_controls.xml b/YouTubePlayer/src/main/res/layout/player_controls.xml index 0e5ce1fd..cd94801e 100644 --- a/YouTubePlayer/src/main/res/layout/player_controls.xml +++ b/YouTubePlayer/src/main/res/layout/player_controls.xml @@ -9,6 +9,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:clickable="true" + android:focusable="true" android:background="@android:color/black" /> + android:layout_alignParentStart="true" + android:layout_toStartOf="@id/menu_button" /> + + Date: Mon, 13 Nov 2017 22:51:58 +0100 Subject: [PATCH 2/2] PopupWindow implementation --- .../player/YouTubePlayerView.java | 26 +++++++++++++++++++ .../ui/DefaultPlayerUIController.java | 11 ++++++++ .../youtubeplayer/ui/PlayerUIController.java | 1 + .../main/res/drawable/ic_settings_24dp.xml | 9 +++++++ .../res/drawable/shape_rounded_corners.xml | 4 +++ .../src/main/res/layout/mylayout.xml | 16 ++++++++++++ YouTubePlayer/src/main/res/values/dimens.xml | 4 +++ YouTubePlayer/src/main/res/values/strings.xml | 1 + 8 files changed, 72 insertions(+) create mode 100644 YouTubePlayer/src/main/res/drawable/ic_settings_24dp.xml create mode 100644 YouTubePlayer/src/main/res/drawable/shape_rounded_corners.xml create mode 100644 YouTubePlayer/src/main/res/layout/mylayout.xml create mode 100644 YouTubePlayer/src/main/res/values/dimens.xml diff --git a/YouTubePlayer/src/main/java/com/pierfrancescosoffritti/youtubeplayer/player/YouTubePlayerView.java b/YouTubePlayer/src/main/java/com/pierfrancescosoffritti/youtubeplayer/player/YouTubePlayerView.java index 0afe3281..9bbf958f 100644 --- a/YouTubePlayer/src/main/java/com/pierfrancescosoffritti/youtubeplayer/player/YouTubePlayerView.java +++ b/YouTubePlayer/src/main/java/com/pierfrancescosoffritti/youtubeplayer/player/YouTubePlayerView.java @@ -6,10 +6,13 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.util.AttributeSet; +import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.WindowManager; import android.webkit.WebView; import android.widget.FrameLayout; +import android.widget.PopupWindow; import com.pierfrancescosoffritti.youtubeplayer.R; import com.pierfrancescosoffritti.youtubeplayer.utils.NetworkReceiver; @@ -143,6 +146,29 @@ public boolean removeFullScreenListener(@NonNull YouTubePlayerFullScreenListener return fullScreenHelper.removeFullScreenListener(fullScreenListener); } + public void showMenu(View anchorView) { + PopupWindow window = createPopupDisplay(); + window.showAsDropDown(anchorView, - getResources().getDimensionPixelSize(R.dimen._8dp) * 3, - getResources().getDimensionPixelSize(R.dimen._8dp) * 4); + } + + public PopupWindow createPopupDisplay() { + final PopupWindow popupWindow = new PopupWindow(this); + + LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); + + if(inflater == null) + return null; + + View view = inflater.inflate(R.layout.mylayout, null); + + popupWindow.setFocusable(true); + popupWindow.setWidth(WindowManager.LayoutParams.WRAP_CONTENT); + popupWindow.setHeight(WindowManager.LayoutParams.WRAP_CONTENT); + popupWindow.setContentView(view); + + return popupWindow; + } + private void addYouTubePlayerInternalListeners(YouTubePlayer youTubePlayer) { youTubePlayer.addListener(playerUIControls); youTubePlayer.addListener(playbackResumer); diff --git a/YouTubePlayer/src/main/java/com/pierfrancescosoffritti/youtubeplayer/ui/DefaultPlayerUIController.java b/YouTubePlayer/src/main/java/com/pierfrancescosoffritti/youtubeplayer/ui/DefaultPlayerUIController.java index 8213761b..abe58388 100644 --- a/YouTubePlayer/src/main/java/com/pierfrancescosoffritti/youtubeplayer/ui/DefaultPlayerUIController.java +++ b/YouTubePlayer/src/main/java/com/pierfrancescosoffritti/youtubeplayer/ui/DefaultPlayerUIController.java @@ -38,6 +38,7 @@ public class DefaultPlayerUIController implements PlayerUIController, View.OnCli @NonNull private final TextView liveVideoIndicator; @NonNull private final ProgressBar progressBar; + @NonNull private final ImageView menuButton; @NonNull private final ImageView playButton; @NonNull private final ImageView youTubeButton; @NonNull private final ImageView fullScreenButton; @@ -70,6 +71,7 @@ public DefaultPlayerUIController(@NonNull YouTubePlayerView youTubePlayerView, @ liveVideoIndicator = controlsView.findViewById(R.id.live_video_indicator); progressBar = controlsView.findViewById(R.id.progress); + menuButton = controlsView.findViewById(R.id.menu_button); playButton = controlsView.findViewById(R.id.play_button); youTubeButton = controlsView.findViewById(R.id.youtube_button); fullScreenButton = controlsView.findViewById(R.id.fullscreen_button); @@ -82,6 +84,7 @@ public DefaultPlayerUIController(@NonNull YouTubePlayerView youTubePlayerView, @ seekBar.setOnSeekBarChangeListener(this); panel.setOnClickListener(this); playButton.setOnClickListener(this); + menuButton.setOnClickListener(this); fullScreenButton.setOnClickListener(this); } @@ -141,6 +144,12 @@ public void showCustomAction2(boolean show) { customActionRight.setVisibility(visibility); } + @Override + public void showMenuButton(boolean show) { + int visibility = show ? View.VISIBLE : View.INVISIBLE; + menuButton.setVisibility(visibility); + } + @Override public void showFullscreenButton(boolean show) { int visibility = show ? View.VISIBLE : View.INVISIBLE; @@ -160,6 +169,8 @@ else if(view == playButton) onPlayButtonPressed(); else if(view == fullScreenButton) onFullScreenPressed(); + else if(view == menuButton) + youTubePlayerView.showMenu(menuButton); } private void onFullScreenPressed() { diff --git a/YouTubePlayer/src/main/java/com/pierfrancescosoffritti/youtubeplayer/ui/PlayerUIController.java b/YouTubePlayer/src/main/java/com/pierfrancescosoffritti/youtubeplayer/ui/PlayerUIController.java index e92efd64..cbd18175 100644 --- a/YouTubePlayer/src/main/java/com/pierfrancescosoffritti/youtubeplayer/ui/PlayerUIController.java +++ b/YouTubePlayer/src/main/java/com/pierfrancescosoffritti/youtubeplayer/ui/PlayerUIController.java @@ -14,5 +14,6 @@ public interface PlayerUIController { void showCustomAction2(boolean show); void showFullscreenButton(boolean show); + void showMenuButton(boolean show); void setCustomFullScreenButtonListener(View.OnClickListener customFullScreenButtonListener); } diff --git a/YouTubePlayer/src/main/res/drawable/ic_settings_24dp.xml b/YouTubePlayer/src/main/res/drawable/ic_settings_24dp.xml new file mode 100644 index 00000000..ace746c4 --- /dev/null +++ b/YouTubePlayer/src/main/res/drawable/ic_settings_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/YouTubePlayer/src/main/res/drawable/shape_rounded_corners.xml b/YouTubePlayer/src/main/res/drawable/shape_rounded_corners.xml new file mode 100644 index 00000000..c4f69a14 --- /dev/null +++ b/YouTubePlayer/src/main/res/drawable/shape_rounded_corners.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/YouTubePlayer/src/main/res/layout/mylayout.xml b/YouTubePlayer/src/main/res/layout/mylayout.xml new file mode 100644 index 00000000..a5b0b44c --- /dev/null +++ b/YouTubePlayer/src/main/res/layout/mylayout.xml @@ -0,0 +1,16 @@ + + + + + + \ No newline at end of file diff --git a/YouTubePlayer/src/main/res/values/dimens.xml b/YouTubePlayer/src/main/res/values/dimens.xml new file mode 100644 index 00000000..1f395eee --- /dev/null +++ b/YouTubePlayer/src/main/res/values/dimens.xml @@ -0,0 +1,4 @@ + + + 8dp + \ No newline at end of file diff --git a/YouTubePlayer/src/main/res/values/strings.xml b/YouTubePlayer/src/main/res/values/strings.xml index a7629f7a..c4ae5e53 100644 --- a/YouTubePlayer/src/main/res/values/strings.xml +++ b/YouTubePlayer/src/main/res/values/strings.xml @@ -5,4 +5,5 @@ Open video in YouTube Full screen button LIVE + Quality