Skip to content

Commit

Permalink
Use TypedValueCompat
Browse files Browse the repository at this point in the history
  • Loading branch information
Isira-Seneviratne committed Nov 29, 2023
1 parent 545f9ae commit bbbb90e
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 16 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ plugins {
}

android {
compileSdk 33
compileSdk 34
namespace 'org.schabi.newpipe'

defaultConfig {
Expand Down Expand Up @@ -211,7 +211,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.core:core-ktx:1.10.0'
implementation 'androidx.core:core-ktx:1.12.0'
implementation 'androidx.documentfile:documentfile:1.0.1'
implementation 'androidx.fragment:fragment-ktx:1.4.1'
implementation "androidx.lifecycle:lifecycle-livedata-ktx:${androidxLifecycleVersion}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import android.provider.Settings;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
Expand All @@ -54,6 +53,7 @@
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.content.ContextCompat;
import androidx.core.util.TypedValueCompat;
import androidx.fragment.app.Fragment;
import androidx.preference.PreferenceManager;

Expand Down Expand Up @@ -111,12 +111,12 @@
import org.schabi.newpipe.util.Localization;
import org.schabi.newpipe.util.NavigationHelper;
import org.schabi.newpipe.util.PermissionHelper;
import org.schabi.newpipe.util.image.PicassoHelper;
import org.schabi.newpipe.util.PlayButtonHelper;
import org.schabi.newpipe.util.StreamTypeUtil;
import org.schabi.newpipe.util.ThemeHelper;
import org.schabi.newpipe.util.external_communication.KoreUtils;
import org.schabi.newpipe.util.external_communication.ShareUtils;
import org.schabi.newpipe.util.PlayButtonHelper;
import org.schabi.newpipe.util.image.PicassoHelper;

import java.util.ArrayList;
import java.util.Iterator;
Expand Down Expand Up @@ -990,8 +990,8 @@ public void updateTabLayoutVisibility() {
final int height = DeviceUtils.getWindowHeight(activity.getWindowManager());
final int viewPagerVisibleHeight = height - pagerHitRect.top;
// see TabLayout.DEFAULT_HEIGHT, which is equal to 48dp
final float tabLayoutHeight = TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP, 48, getResources().getDisplayMetrics());
final float tabLayoutHeight = TypedValueCompat.dpToPx(48,
getResources().getDisplayMetrics());

if (viewPagerVisibleHeight > tabLayoutHeight * 2) {
// no translation at all when viewPagerVisibleHeight > tabLayout.height * 3
Expand Down
12 changes: 3 additions & 9 deletions app/src/main/java/org/schabi/newpipe/util/DeviceUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import android.os.BatteryManager;
import android.os.Build;
import android.provider.Settings;
import android.util.TypedValue;
import android.view.InputDevice;
import android.view.KeyEvent;
import android.view.WindowInsets;
Expand All @@ -22,6 +21,7 @@
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import androidx.core.util.TypedValueCompat;
import androidx.preference.PreferenceManager;

import org.schabi.newpipe.App;
Expand Down Expand Up @@ -266,18 +266,12 @@ public static boolean isConfirmKey(final int keyCode) {

public static int dpToPx(@Dimension(unit = Dimension.DP) final int dp,
@NonNull final Context context) {
return (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_DIP,
dp,
context.getResources().getDisplayMetrics());
return (int) TypedValueCompat.dpToPx(dp, context.getResources().getDisplayMetrics());
}

public static int spToPx(@Dimension(unit = Dimension.SP) final int sp,
@NonNull final Context context) {
return (int) TypedValue.applyDimension(
TypedValue.COMPLEX_UNIT_SP,
sp,
context.getResources().getDisplayMetrics());
return (int) TypedValueCompat.spToPx(sp, context.getResources().getDisplayMetrics());
}

public static boolean isLandscape(final Context context) {
Expand Down

0 comments on commit bbbb90e

Please sign in to comment.