From c59754499f0cc3cb5ec660c5d6004e3b762ed16e Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Sun, 20 Sep 2015 13:19:28 +0200 Subject: [PATCH] new app icon & made player fullscreen work better --- .idea/misc.xml | 2 +- .../org/schabi/newpipe/PlayVideoActivity.java | 124 ++++++++++-- .../newpipe/VideoItemDetailActivity.java | 6 +- .../newpipe/VideoItemDetailFragment.java | 1 + .../schabi/newpipe/VideoItemListActivity.java | 4 + .../schabi/newpipe/VideoItemListFragment.java | 1 + .../main/res/layout/activity_play_video.xml | 9 +- .../res/layout/activity_videoitem_list.xml | 4 +- app/src/main/res/mipmap-hdpi/ic_launcher.png | Bin 4720 -> 2406 bytes app/src/main/res/mipmap-mdpi/ic_launcher.png | Bin 2570 -> 1432 bytes app/src/main/res/mipmap-xhdpi/ic_launcher.png | Bin 6056 -> 3116 bytes .../main/res/mipmap-xxhdpi/ic_launcher.png | Bin 8979 -> 4728 bytes app/src/main/res/values-v21/styles.xml | 2 + app/src/main/res/values/styles.xml | 1 + assets/new_newpipe_icon.svg | 188 ++++++++++++++++++ 15 files changed, 320 insertions(+), 22 deletions(-) create mode 100644 assets/new_newpipe_icon.svg diff --git a/.idea/misc.xml b/.idea/misc.xml index fbb68289f..5d1998103 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -37,7 +37,7 @@ - + diff --git a/app/src/main/java/org/schabi/newpipe/PlayVideoActivity.java b/app/src/main/java/org/schabi/newpipe/PlayVideoActivity.java index db7d09691..4ec9afbd6 100644 --- a/app/src/main/java/org/schabi/newpipe/PlayVideoActivity.java +++ b/app/src/main/java/org/schabi/newpipe/PlayVideoActivity.java @@ -2,12 +2,16 @@ package org.schabi.newpipe; import android.content.Intent; import android.content.pm.ActivityInfo; +import android.content.res.Configuration; +import android.content.res.Resources; import android.media.MediaPlayer; import android.net.Uri; +import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; +import android.util.DisplayMetrics; import android.util.Log; import android.view.Display; import android.view.Menu; @@ -17,8 +21,11 @@ import android.view.Surface; import android.view.View; import android.view.WindowManager; import android.widget.Button; +import android.widget.FrameLayout; +import android.widget.LinearLayout; import android.widget.MediaController; import android.widget.ProgressBar; +import android.widget.SeekBar; import android.widget.VideoView; /** @@ -50,6 +57,7 @@ public class PlayVideoActivity extends AppCompatActivity { private static final String POSITION = "position"; private static final long HIDING_DELAY = 3000; + private static final long TAB_HIDING_DELAY = 100; private String videoUrl = ""; @@ -61,6 +69,8 @@ public class PlayVideoActivity extends AppCompatActivity { private View decorView; private boolean uiIsHidden = false; private static long lastUiShowTime = 0; + private boolean isLandscape = true; + private boolean hasSoftKeys = false; @Override protected void onCreate(Bundle savedInstanceState) { @@ -68,6 +78,9 @@ public class PlayVideoActivity extends AppCompatActivity { setContentView(R.layout.activity_play_video); + isLandscape = checkIfLandscape(); + hasSoftKeys = checkIfhasSoftKeys(); + actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); Intent intent = getIntent(); @@ -91,6 +104,7 @@ public class PlayVideoActivity extends AppCompatActivity { videoView.seekTo(position); if (position == 0) { videoView.start(); + showUi(); } else { videoView.pause(); } @@ -113,16 +127,21 @@ public class PlayVideoActivity extends AppCompatActivity { decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { @Override public void onSystemUiVisibilityChange(int visibility) { - if((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) { - uiIsHidden = false; + if (visibility == View.VISIBLE && uiIsHidden) { showUi(); - } else { - uiIsHidden = true; - hideUi(); } } }); - showUi(); + + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); + } + + @Override + protected void onPostCreate(Bundle savedInstanceState) { + super.onPostCreate(savedInstanceState); + } @Override @@ -166,8 +185,16 @@ public class PlayVideoActivity extends AppCompatActivity { } @Override - protected void onPostCreate(Bundle savedInstanceState) { - super.onPostCreate(savedInstanceState); + public void onConfigurationChanged(Configuration config) { + super.onConfigurationChanged(config); + + if (config.orientation == Configuration.ORIENTATION_LANDSCAPE) { + isLandscape = true; + adjustMediaControllMetrics(); + } else if (config.orientation == Configuration.ORIENTATION_PORTRAIT){ + isLandscape = false; + adjustMediaControllMetrics(); + } } @Override @@ -187,15 +214,15 @@ public class PlayVideoActivity extends AppCompatActivity { private void showUi() { try { uiIsHidden = false; - mediaController.show(); + mediaController.show(100000); actionBar.show(); - //decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); - //| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); + adjustMediaControllMetrics(); + getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { - if ((System.currentTimeMillis() - lastUiShowTime) > HIDING_DELAY) { + if ((System.currentTimeMillis() - lastUiShowTime) >= HIDING_DELAY) { hideUi(); } } @@ -210,8 +237,75 @@ public class PlayVideoActivity extends AppCompatActivity { uiIsHidden = true; actionBar.hide(); mediaController.hide(); - getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); - //decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN); - //| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); + decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN + | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_FULLSCREEN + | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION + | View.SYSTEM_UI_FLAG_LAYOUT_STABLE); + getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, + WindowManager.LayoutParams.FLAG_FULLSCREEN); + } + + private void adjustMediaControllMetrics() { + MediaController.LayoutParams mediaControllerLayout + = new MediaController.LayoutParams(MediaController.LayoutParams.MATCH_PARENT, + MediaController.LayoutParams.WRAP_CONTENT); + + if(!hasSoftKeys) { + mediaControllerLayout.setMargins(20, 0, 20, 20); + } else { + int width = getNavigationBarWidth(); + int height = getNavigationBarHeight(); + mediaControllerLayout.setMargins(width + 20, 0, width + 20, height + 20); + } + mediaController.setLayoutParams(mediaControllerLayout); + } + + private boolean checkIfhasSoftKeys(){ + if(Build.VERSION.SDK_INT >= 17) { + return getNavigationBarHeight() != 0 || getNavigationBarWidth() != 0; + } else { + return true; + } + } + + private int getNavigationBarHeight() { + if(Build.VERSION.SDK_INT >= 17) { + Display d = getWindowManager().getDefaultDisplay(); + + DisplayMetrics realDisplayMetrics = new DisplayMetrics(); + d.getRealMetrics(realDisplayMetrics); + DisplayMetrics displayMetrics = new DisplayMetrics(); + d.getMetrics(displayMetrics); + + int realHeight = realDisplayMetrics.heightPixels; + int displayHeight = displayMetrics.heightPixels; + return (realHeight - displayHeight); + } else { + return 50; + } + } + + private int getNavigationBarWidth() { + if(Build.VERSION.SDK_INT >= 17) { + Display d = getWindowManager().getDefaultDisplay(); + + DisplayMetrics realDisplayMetrics = new DisplayMetrics(); + d.getRealMetrics(realDisplayMetrics); + DisplayMetrics displayMetrics = new DisplayMetrics(); + d.getMetrics(displayMetrics); + + int realWidth = realDisplayMetrics.widthPixels; + int displayWidth = displayMetrics.widthPixels; + return (realWidth - displayWidth); + } else { + return 50; + } + } + + public boolean checkIfLandscape() { + DisplayMetrics displayMetrics = new DisplayMetrics(); + getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); + return displayMetrics.heightPixels < displayMetrics.widthPixels; } } diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemDetailActivity.java b/app/src/main/java/org/schabi/newpipe/VideoItemDetailActivity.java index cc9287796..cc0c95edf 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoItemDetailActivity.java +++ b/app/src/main/java/org/schabi/newpipe/VideoItemDetailActivity.java @@ -1,16 +1,20 @@ package org.schabi.newpipe; import android.content.ContentProviderOperation; +import android.content.res.Configuration; +import android.os.Build; import android.preference.PreferenceManager; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.content.Intent; import android.os.Bundle; import android.support.v4.app.NavUtils; +import android.util.DisplayMetrics; import android.util.Log; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; +import android.view.WindowManager; import org.schabi.newpipe.youtube.YoutubeExtractor; @@ -39,12 +43,12 @@ public class VideoItemDetailActivity extends AppCompatActivity { private String videoUrl; private int currentStreamingService = -1; + private boolean isLandscape; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_videoitem_detail); - // Show the Up button in the action bar. getSupportActionBar().setDisplayHomeAsUpEnabled(true); ActionBarHandler.getHandler().setupNavMenu(this); diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java b/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java index 23ca053f8..9b2afe39d 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java +++ b/app/src/main/java/org/schabi/newpipe/VideoItemDetailFragment.java @@ -15,6 +15,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.ImageView; +import android.widget.ListView; import android.widget.ProgressBar; import android.widget.TextView; diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemListActivity.java b/app/src/main/java/org/schabi/newpipe/VideoItemListActivity.java index 827f5e8e1..0a46ac10e 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoItemListActivity.java +++ b/app/src/main/java/org/schabi/newpipe/VideoItemListActivity.java @@ -2,15 +2,19 @@ package org.schabi.newpipe; import android.content.Context; import android.content.Intent; +import android.content.res.Configuration; +import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.preference.PreferenceManager; import android.support.v7.app.AppCompatActivity; +import android.util.DisplayMetrics; import android.util.Log; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; +import android.view.WindowManager; import android.view.inputmethod.InputMethodManager; import android.support.v7.widget.SearchView; import android.widget.ImageView; diff --git a/app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java b/app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java index c3f7b46f6..c924aa227 100644 --- a/app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java +++ b/app/src/main/java/org/schabi/newpipe/VideoItemListFragment.java @@ -13,6 +13,7 @@ import android.widget.ListView; import android.widget.Toast; import java.net.URL; +import java.util.List; import java.util.Vector; diff --git a/app/src/main/res/layout/activity_play_video.xml b/app/src/main/res/layout/activity_play_video.xml index b2721fd07..433930f71 100644 --- a/app/src/main/res/layout/activity_play_video.xml +++ b/app/src/main/res/layout/activity_play_video.xml @@ -9,17 +9,20 @@ + android:layout_gravity="center" + android:focusable="false"/>