From 6a8ecfea7468d0e742f4aa2147fd69180896cd30 Mon Sep 17 00:00:00 2001 From: Tanguy Herbron Date: Tue, 29 May 2018 14:38:16 +0200 Subject: [PATCH] Fix pixel sized layouts - Move dp to px converter to moodlbox - Fix details activity icon size generation --- .../nauk/moodl/Activities/CurrencyDetailsActivity.java | 8 +++++++- .../Activities/DetailsActivityFragments/Home.java | 10 +++------- .../DataManagers/CurrencyData/CurrencyCardview.java | 10 +++------- app/src/main/java/com/nauk/moodl/MoodlBox.java | 5 +++++ 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/nauk/moodl/Activities/CurrencyDetailsActivity.java b/app/src/main/java/com/nauk/moodl/Activities/CurrencyDetailsActivity.java index ed880ee..32d8cef 100644 --- a/app/src/main/java/com/nauk/moodl/Activities/CurrencyDetailsActivity.java +++ b/app/src/main/java/com/nauk/moodl/Activities/CurrencyDetailsActivity.java @@ -60,6 +60,7 @@ import com.nauk.moodl.DataManagers.PreferencesManager; import com.nauk.moodl.DetailsActivityPagerAdapter; import com.nauk.moodl.LayoutManagers.TradeListAdapter; import com.nauk.moodl.LayoutManagers.TransactionListAdapter; +import com.nauk.moodl.MoodlBox; import com.nauk.moodl.PlaceholderManager; import com.nauk.moodl.R; @@ -188,7 +189,12 @@ public class CurrencyDetailsActivity extends AppCompatActivity { canvas.drawCircle(result.getHeight()/2, result.getWidth()/2, 75, paint); canvas.drawBitmap(Bitmap.createScaledBitmap(currency.getIcon(), 100, 100, false), result.getHeight()/2 - 50, result.getWidth()/2 - 50, null); - getSupportActionBar().setIcon(new BitmapDrawable(getResources(), Bitmap.createScaledBitmap(result, 120, 120, false))); + getSupportActionBar() + .setIcon(new BitmapDrawable(getResources(), + Bitmap.createScaledBitmap(result + , (int) MoodlBox.convertDpToPx(25, getResources()) + , (int) MoodlBox.convertDpToPx(25, getResources()) + , false))); } } /*for(int i = 0; i < dataChartList.size(); i++) diff --git a/app/src/main/java/com/nauk/moodl/Activities/DetailsActivityFragments/Home.java b/app/src/main/java/com/nauk/moodl/Activities/DetailsActivityFragments/Home.java index 0ed39c8..43b5d2a 100644 --- a/app/src/main/java/com/nauk/moodl/Activities/DetailsActivityFragments/Home.java +++ b/app/src/main/java/com/nauk/moodl/Activities/DetailsActivityFragments/Home.java @@ -34,6 +34,7 @@ import com.nauk.moodl.DataManagers.CurrencyData.Currency; import com.nauk.moodl.DataManagers.CurrencyData.CurrencyDataChart; import com.nauk.moodl.DataManagers.PreferencesManager; import com.nauk.moodl.LayoutManagers.CustomViewPager; +import com.nauk.moodl.MoodlBox; import com.nauk.moodl.PlaceholderManager; import com.nauk.moodl.R; @@ -170,7 +171,7 @@ public class Home extends Fragment { private void buttonEvent(View v) { v.setEnabled(false); - v.setElevation(convertDpToPx(8)); + v.setElevation(MoodlBox.convertDpToPx(8, getResources())); LinearLayout buttonLayout = (LinearLayout) v.getParent(); @@ -181,7 +182,7 @@ public class Home extends Fragment { if(button != v) { button.setEnabled(true); - button.setElevation(convertDpToPx(2)); + button.setElevation(MoodlBox.convertDpToPx(2, getResources())); } } @@ -319,11 +320,6 @@ public class Home extends Fragment { } } - private float convertDpToPx(float dp) - { - return dp * this.getResources().getDisplayMetrics().density; - } - private void updateChartTab(int timeUnit, int amount) { updateChartsData(timeUnit, amount); diff --git a/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyCardview.java b/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyCardview.java index 3fa7b55..fbc23c3 100644 --- a/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyCardview.java +++ b/app/src/main/java/com/nauk/moodl/DataManagers/CurrencyData/CurrencyCardview.java @@ -28,6 +28,7 @@ import com.nauk.moodl.Activities.CurrencyDetailsActivity; import com.nauk.moodl.Activities.HomeActivityFragments.Summary; import com.nauk.moodl.DataManagers.DatabaseManager; import com.nauk.moodl.DataManagers.PreferencesManager; +import com.nauk.moodl.MoodlBox; import com.nauk.moodl.PlaceholderManager; import com.nauk.moodl.R; @@ -125,11 +126,6 @@ public class CurrencyCardview extends CardView { updateColor(currency); } - private float convertDpToPx(float dp) - { - return dp * this.getResources().getDisplayMetrics().density; - } - public CurrencyCardview(@NonNull final Context context, final Currency currency, float totalValue, boolean isBalanceHidden) { super(context); @@ -198,11 +194,11 @@ public class CurrencyCardview extends CardView { private void setupCardView(Context context) { ViewGroup.MarginLayoutParams layoutParams = new ViewGroup.MarginLayoutParams(ViewGroup.MarginLayoutParams.MATCH_PARENT, ViewGroup.MarginLayoutParams.WRAP_CONTENT); - layoutParams.setMargins((int) convertDpToPx(10), 0, (int) convertDpToPx(10), (int) convertDpToPx(10)); + layoutParams.setMargins((int) MoodlBox.convertDpToPx(10, getResources()), 0, (int) MoodlBox.convertDpToPx(10, getResources()), (int) MoodlBox.convertDpToPx(10, getResources())); setLayoutParams(layoutParams); - setRadius(convertDpToPx(2)); + setRadius(MoodlBox.convertDpToPx(2, getResources())); setClickable(false); setFocusable(false); diff --git a/app/src/main/java/com/nauk/moodl/MoodlBox.java b/app/src/main/java/com/nauk/moodl/MoodlBox.java index ab86531..8dd8d5e 100644 --- a/app/src/main/java/com/nauk/moodl/MoodlBox.java +++ b/app/src/main/java/com/nauk/moodl/MoodlBox.java @@ -247,6 +247,11 @@ public class MoodlBox { return getIconUrl(symbol, 50, currencyDetailsList); } + public static float convertDpToPx(float dp, Resources resources) + { + return dp * resources.getDisplayMetrics().density; + } + public static String getIconUrl(String symbol, int size, CurrencyDetailsList currencyDetailsList) { String url;