Skip to content

Commit

Permalink
fix(preferences): memory allocation by increments of 8MB
Browse files Browse the repository at this point in the history
  • Loading branch information
Mathias-Boulay committed Jan 19, 2025
1 parent 315352a commit 171f955
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public class CustomSeekBarPreference extends SeekBarPreference {
private int mMin;
/** The textview associated by default to the preference */
private TextView mTextView;
/** Seekbar increment in case the max gets set */
private final int mIncrement;


@SuppressLint("PrivateResource")
Expand All @@ -31,6 +33,7 @@ public CustomSeekBarPreference(Context context, AttributeSet attrs, int defStyle
try (TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.SeekBarPreference, defStyleAttr, defStyleRes)) {
mMin = a.getInt(R.styleable.SeekBarPreference_min, 0);
mIncrement = a.getInt(R.styleable.SeekBarPreference_seekBarIncrement, 0);
}
}

Expand Down Expand Up @@ -111,7 +114,12 @@ public void setSuffix(String suffix) {
*/
public void setRange(int min, int max){
setMin(min);
setMax(max);
setMaxKeepIncrement(max);
}

public void setMaxKeepIncrement(int max) {
super.setMax(max);
setSeekBarIncrement(mIncrement);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ public static void loadPreferences(Context ctx) {
*/
private static int findBestRAMAllocation(Context ctx){
int deviceRam = Tools.getTotalDeviceMemory(ctx);
if (deviceRam < 1024) return 300;
if (deviceRam < 1536) return 450;
if (deviceRam < 2048) return 600;
if (deviceRam < 1024) return 296;
if (deviceRam < 1536) return 448;
if (deviceRam < 2048) return 656;
// Limit the max for 32 bits devices more harshly
if (is32BitsDevice()) return 700;
if (is32BitsDevice()) return 696;

if (deviceRam < 3064) return 936;
if (deviceRam < 4096) return 1148;
if (deviceRam < 4096) return 1144;
if (deviceRam < 6144) return 1536;
return 2048; //Default RAM allocation for 64 bits
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void onCreatePreferences(Bundle b, String str) {
if(is32BitsDevice() || deviceRam < 2048) maxRAM = Math.min(1024, deviceRam);
else maxRAM = deviceRam - (deviceRam < 3064 ? 800 : 1024); //To have a minimum for the device to breathe

memorySeekbar.setMax(maxRAM);
memorySeekbar.setMaxKeepIncrement(maxRAM);
memorySeekbar.setValue(ramAllocation);
memorySeekbar.setSuffix(" MB");

Expand Down

0 comments on commit 171f955

Please sign in to comment.