diff options
author | Tony Tam <engineer.tonytam@pm.me> | 2020-07-16 00:06:01 -0700 |
---|---|---|
committer | Tony Tam <engineer.tonytam@pm.me> | 2020-07-16 00:06:01 -0700 |
commit | dba3aee7b0152805384f9f944cac38c8abada5d5 (patch) | |
tree | 01b2fe13aa193b3e121d5078de5c980a812d3b11 /app/src/main | |
parent | 0cad3bce6840069261b64fe5dc7e474df2b57315 (diff) | |
download | AntennaPod-dba3aee7b0152805384f9f944cac38c8abada5d5.zip |
finally fixed
Diffstat (limited to 'app/src/main')
-rw-r--r-- | app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java | 29 | ||||
-rw-r--r-- | app/src/main/res/layout/cover_fragment.xml | 8 |
2 files changed, 25 insertions, 12 deletions
diff --git a/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java b/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java index 708385e31..ef0b87d00 100644 --- a/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java +++ b/app/src/main/java/de/danoeh/antennapod/fragment/CoverFragment.java @@ -1,9 +1,11 @@ package de.danoeh.antennapod.fragment; +import android.content.Context; import android.content.res.Configuration; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.text.TextUtils; +import android.util.DisplayMetrics; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -69,7 +71,7 @@ public class CoverFragment extends Fragment { @Override public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { - configureForOrientation(getResources().getConfiguration().orientation); + configureForOrientation(getResources().getConfiguration().orientation, getResources().getConfiguration()); } private void loadMediaInfo() { @@ -106,6 +108,7 @@ public class CoverFragment extends Fragment { root = null; } + @Override public void onStart() { super.onStart(); @@ -172,34 +175,44 @@ public class CoverFragment extends Fragment { } } - @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); if (orientation != newConfig.orientation) { orientation = newConfig.orientation; - configureForOrientation(orientation); } + configureForOrientation(orientation, newConfig); + } + + public float convertDpToPixel(float dp) { + Context context = this.getActivity().getApplicationContext(); + return dp * ((float) context.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT); } - private void configureForOrientation(int orientation) { + private void configureForOrientation(int orientation, Configuration newConfig) { View textContainer = getView().findViewById(R.id.cover_fragment_text_container); LinearLayout mainContainer = getView().findViewById(R.id.cover_fragment); - LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) textContainer.getLayoutParams(); if (orientation == Configuration.ORIENTATION_PORTRAIT) { mainContainer.setOrientation(LinearLayout.VERTICAL); - params.weight = 0; + if (newConfig.screenWidthDp > 0) { + imgvCover.getLayoutParams().width = (int) (convertDpToPixel(newConfig.screenWidthDp) * .80); + imgvCover.getLayoutParams().height = imgvCover.getLayoutParams().width; + } } else { mainContainer.setOrientation(LinearLayout.HORIZONTAL); - params.weight = 1; + if (newConfig.screenHeightDp > 0) { + imgvCover.getLayoutParams().height = (int) (convertDpToPixel(newConfig.screenHeightDp) * .40); + imgvCover.getLayoutParams().width = imgvCover.getLayoutParams().height; + } } if (_position > -1) { displayCoverImage(_position); } - textContainer.setLayoutParams(params); + imgvCover.requestLayout(); } + @Override public void onDestroyView() { super.onDestroyView(); diff --git a/app/src/main/res/layout/cover_fragment.xml b/app/src/main/res/layout/cover_fragment.xml index 738fba027..03b11fbcb 100644 --- a/app/src/main/res/layout/cover_fragment.xml +++ b/app/src/main/res/layout/cover_fragment.xml @@ -12,10 +12,10 @@ <de.danoeh.antennapod.view.SquareImageView android:id="@+id/imgvCover" - android:layout_width="0dp" - android:layout_height="match_parent" - android:layout_marginLeft="32dp" - android:layout_marginRight="32dp" + android:layout_width="200dp" + android:layout_height="200dp" + android:layout_marginLeft="8dp" + android:layout_marginRight="8dp" android:layout_weight="0" android:foreground="?attr/selectableItemBackgroundBorderless" android:importantForAccessibility="no" |