Skip to content

Commit 09da0c9

Browse files
committed
Utils
1 parent cce1599 commit 09da0c9

File tree

1 file changed

+7
-100
lines changed
  • MPChartLib/src/main/java/com/github/mikephil/charting/utils

1 file changed

+7
-100
lines changed

MPChartLib/src/main/java/com/github/mikephil/charting/utils/Utils.java

Lines changed: 7 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import com.github.mikephil.charting.formatter.DefaultValueFormatter;
2222
import com.github.mikephil.charting.formatter.IValueFormatter;
2323

24-
import java.util.List;
24+
import androidx.annotation.NonNull;
2525

2626
/**
2727
* Utilities class that has some helper methods. Needs to be initialized by
@@ -50,41 +50,13 @@ public abstract class Utils {
5050
* initialize method, called inside the Chart.init() method.
5151
*/
5252
@SuppressWarnings("deprecation")
53-
public static void init(Context context) {
54-
55-
if (context == null) {
56-
// noinspection deprecation
57-
mMinimumFlingVelocity = ViewConfiguration.getMinimumFlingVelocity();
58-
// noinspection deprecation
59-
mMaximumFlingVelocity = ViewConfiguration.getMaximumFlingVelocity();
60-
61-
Log.e("chartLib-Utils", "Utils.init(...) PROVIDED CONTEXT OBJECT IS NULL");
62-
63-
} else {
64-
ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
65-
mMinimumFlingVelocity = viewConfiguration.getScaledMinimumFlingVelocity();
66-
mMaximumFlingVelocity = viewConfiguration.getScaledMaximumFlingVelocity();
67-
68-
Resources res = context.getResources();
69-
mMetrics = res.getDisplayMetrics();
70-
}
71-
}
72-
73-
/**
74-
* initialize method, called inside the Chart.init() method. backwards
75-
* compatibility - to not break existing code
76-
*
77-
* @param res
78-
*/
79-
@Deprecated
80-
public static void init(Resources res) {
53+
public static void init(@NonNull Context context) {
54+
ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
55+
mMinimumFlingVelocity = viewConfiguration.getScaledMinimumFlingVelocity();
56+
mMaximumFlingVelocity = viewConfiguration.getScaledMaximumFlingVelocity();
8157

58+
Resources res = context.getResources();
8259
mMetrics = res.getDisplayMetrics();
83-
84-
// noinspection deprecation
85-
mMinimumFlingVelocity = ViewConfiguration.getMinimumFlingVelocity();
86-
// noinspection deprecation
87-
mMaximumFlingVelocity = ViewConfiguration.getMaximumFlingVelocity();
8860
}
8961

9062
/**
@@ -97,40 +69,14 @@ public static void init(Resources res) {
9769
* device density
9870
*/
9971
public static float convertDpToPixel(float dp) {
100-
10172
if (mMetrics == null) {
102-
103-
Log.e("chartLib-Utils",
104-
"Utils NOT INITIALIZED. You need to call Utils.init(...) at least once before" +
105-
" calling Utils.convertDpToPixel(...). Otherwise conversion does not " +
106-
"take place.");
73+
Log.e("chartLib-Utils", "Utils NOT INITIALIZED. You need to call Utils.init(...) at least once before calling Utils.convertDpToPixel(...). Otherwise conversion does not take place.");
10774
return dp;
10875
}
10976

11077
return dp * mMetrics.density;
11178
}
11279

113-
/**
114-
* This method converts device specific pixels to density independent
115-
* pixels. NEEDS UTILS TO BE INITIALIZED BEFORE USAGE.
116-
*
117-
* @param px A value in px (pixels) unit. Which we need to convert into db
118-
* @return A float value to represent dp equivalent to px value
119-
*/
120-
public static float convertPixelsToDp(float px) {
121-
122-
if (mMetrics == null) {
123-
124-
Log.e("chartLib-Utils",
125-
"Utils NOT INITIALIZED. You need to call Utils.init(...) at least once before" +
126-
" calling Utils.convertPixelsToDp(...). Otherwise conversion does not" +
127-
" take place.");
128-
return px;
129-
}
130-
131-
return px / mMetrics.density;
132-
}
133-
13480
/**
13581
* calculates the approximate width of a text, depending on a demo text
13682
* avoid repeated calls (e.g. inside drawing methods)
@@ -376,45 +322,6 @@ public static int getDecimals(float number) {
376322
return (int) Math.ceil(-Math.log10(i)) + 2;
377323
}
378324

379-
/**
380-
* Converts the provided Integer List to an int array.
381-
*
382-
* @param integers
383-
* @return
384-
*/
385-
public static int[] convertIntegers(List<Integer> integers) {
386-
387-
int[] ret = new int[integers.size()];
388-
389-
copyIntegers(integers, ret);
390-
391-
return ret;
392-
}
393-
394-
public static void copyIntegers(List<Integer> from, int[] to) {
395-
int count = Math.min(to.length, from.size());
396-
for (int i = 0; i < count; i++) {
397-
to[i] = from.get(i);
398-
}
399-
}
400-
401-
/**
402-
* Converts the provided String List to a String array.
403-
*
404-
* @param strings
405-
* @return
406-
*/
407-
public static String[] convertStrings(List<String> strings) {
408-
409-
String[] ret = new String[strings.size()];
410-
411-
for (int i = 0; i < ret.length; i++) {
412-
ret[i] = strings.get(i);
413-
}
414-
415-
return ret;
416-
}
417-
418325
/**
419326
* Replacement for the Math.nextUp(...) method that is only available in
420327
* HONEYCOMB and higher.

0 commit comments

Comments
 (0)