From 4261a2eed3f501d3820e4dc35ef62084d83fa93c Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Tue, 5 Dec 2017 12:51:23 +0100 Subject: [PATCH 1/4] remember last screen orientation --- .../newpipe/player/MainVideoPlayer.java | 32 ++++++++++++++++++- app/src/main/res/values/settings_keys.xml | 2 ++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java index 73e4d87ac..e68f56edb 100644 --- a/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java +++ b/app/src/main/java/org/schabi/newpipe/player/MainVideoPlayer.java @@ -22,12 +22,15 @@ package org.schabi.newpipe.player; import android.app.Activity; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.content.pm.ActivityInfo; import android.content.res.Configuration; import android.graphics.Color; import android.media.AudioManager; import android.os.Build; import android.os.Bundle; +import android.preference.PreferenceManager; +import android.provider.Settings; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v7.widget.RecyclerView; @@ -81,6 +84,8 @@ public final class MainVideoPlayer extends Activity { private boolean activityPaused; private VideoPlayerImpl playerImpl; + private SharedPreferences defaultPreferences; + /*////////////////////////////////////////////////////////////////////////// // Activity LifeCycle //////////////////////////////////////////////////////////////////////////*/ @@ -89,6 +94,7 @@ public final class MainVideoPlayer extends Activity { protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (DEBUG) Log.d(TAG, "onCreate() called with: savedInstanceState = [" + savedInstanceState + "]"); + defaultPreferences = PreferenceManager.getDefaultSharedPreferences(this); ThemeHelper.setTheme(this); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) getWindow().setStatusBarColor(Color.BLACK); setVolumeControlStream(AudioManager.STREAM_MUSIC); @@ -99,6 +105,8 @@ public final class MainVideoPlayer extends Activity { return; } + + showSystemUi(); setContentView(R.layout.activity_main_player); playerImpl = new VideoPlayerImpl(this); @@ -146,6 +154,11 @@ public final class MainVideoPlayer extends Activity { activityPaused = false; } + if(globalScreenOrientationLocked()) { + boolean lastOrientationWasLandscape + = defaultPreferences.getBoolean(getString(R.string.last_orientation_landscape_key), false); + setLandScape(lastOrientationWasLandscape); + } } @Override @@ -198,11 +211,28 @@ public final class MainVideoPlayer extends Activity { } private void toggleOrientation() { - setRequestedOrientation(getResources().getDisplayMetrics().heightPixels > getResources().getDisplayMetrics().widthPixels + setLandScape(!isLandScape()); + defaultPreferences.edit() + .putBoolean(getString(R.string.last_orientation_landscape_key), !isLandScape()) + .apply(); + } + + private boolean isLandScape() { + return getResources().getDisplayMetrics().heightPixels < getResources().getDisplayMetrics().widthPixels; + } + + private void setLandScape(boolean v) { + setRequestedOrientation(v ? ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE : ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT); } + private boolean globalScreenOrientationLocked() { + // 1: Screen orientation changes using acelerometer + // 0: Screen orientatino is locked + return !(android.provider.Settings.System.getInt(getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 0) == 1); + } + protected void setRepeatModeButton(final ImageButton imageButton, final int repeatMode) { switch (repeatMode) { case Player.REPEAT_MODE_OFF: diff --git a/app/src/main/res/values/settings_keys.xml b/app/src/main/res/values/settings_keys.xml index 5eee12c6c..0b8a6e0f6 100644 --- a/app/src/main/res/values/settings_keys.xml +++ b/app/src/main/res/values/settings_keys.xml @@ -75,6 +75,8 @@ @string/audio_webm_key + last_orientation_landscape_key + theme light_theme From 26ed6299e363f4c4b9cea886731c255afddb269f Mon Sep 17 00:00:00 2001 From: TobiGr Date: Tue, 5 Dec 2017 17:07:31 +0100 Subject: [PATCH 2/4] - add donation hint and website to about activity - move NewPipe's license to license tab --- .../schabi/newpipe/about/AboutActivity.java | 25 +++++++++++--- .../schabi/newpipe/about/LicenseFragment.java | 10 ++++++ app/src/main/res/layout/fragment_about.xml | 34 +++++++++++++++---- app/src/main/res/layout/fragment_licenses.xml | 30 +++++++++++++++- app/src/main/res/values/strings.xml | 18 +++++++--- 5 files changed, 99 insertions(+), 18 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java b/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java index a2fe35894..a64ed7ff4 100644 --- a/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java +++ b/app/src/main/java/org/schabi/newpipe/about/AboutActivity.java @@ -135,8 +135,12 @@ public class AboutActivity extends AppCompatActivity { View githubLink = rootView.findViewById(R.id.github_link); githubLink.setOnClickListener(new OnGithubLinkClickListener()); - View licenseLink = rootView.findViewById(R.id.app_read_license); - licenseLink.setOnClickListener(new OnReadFullLicenseClickListener()); + View donationLink = rootView.findViewById(R.id.donation_link); + donationLink.setOnClickListener(new OnDonationLinkClickListener()); + + View websiteLink = rootView.findViewById(R.id.website_link); + websiteLink.setOnClickListener(new OnWebsiteLinkClickListener()); + return rootView; } @@ -149,10 +153,21 @@ public class AboutActivity extends AppCompatActivity { } } - private static class OnReadFullLicenseClickListener implements View.OnClickListener { + private static class OnDonationLinkClickListener implements View.OnClickListener { @Override - public void onClick(View v) { - LicenseFragment.showLicense(v.getContext(), StandardLicenses.GPL3); + public void onClick(final View view) { + final Context context = view.getContext(); + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(context.getString(R.string.donation_url))); + context.startActivity(intent); + } + } + + private static class OnWebsiteLinkClickListener implements View.OnClickListener { + @Override + public void onClick(final View view) { + final Context context = view.getContext(); + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(context.getString(R.string.website_url))); + context.startActivity(intent); } } } diff --git a/app/src/main/java/org/schabi/newpipe/about/LicenseFragment.java b/app/src/main/java/org/schabi/newpipe/about/LicenseFragment.java index 4400cac53..272e27240 100644 --- a/app/src/main/java/org/schabi/newpipe/about/LicenseFragment.java +++ b/app/src/main/java/org/schabi/newpipe/about/LicenseFragment.java @@ -62,6 +62,9 @@ public class LicenseFragment extends Fragment { View rootView = inflater.inflate(R.layout.fragment_licenses, container, false); ViewGroup softwareComponentsView = rootView.findViewById(R.id.software_components); + View licenseLink = rootView.findViewById(R.id.app_read_license); + licenseLink.setOnClickListener(new OnReadFullLicenseClickListener()); + for (final SoftwareComponent component : softwareComponents) { View componentView = inflater.inflate(R.layout.item_software_component, container, false); TextView softwareName = componentView.findViewById(R.id.name); @@ -119,4 +122,11 @@ public class LicenseFragment extends Fragment { Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(componentLink)); startActivity(browserIntent); } + + private static class OnReadFullLicenseClickListener implements View.OnClickListener { + @Override + public void onClick(View v) { + LicenseFragment.showLicense(v.getContext(), StandardLicenses.GPL3); + } + } } diff --git a/app/src/main/res/layout/fragment_about.xml b/app/src/main/res/layout/fragment_about.xml index aa154072a..6e1db563a 100644 --- a/app/src/main/res/layout/fragment_about.xml +++ b/app/src/main/res/layout/fragment_about.xml @@ -45,6 +45,7 @@ android:id="@+id/app_description" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:paddingBottom="5dp" android:text="@string/app_description" /> -