Update memory/storage usage

pull/185/head
M66B 4 years ago
parent f9983ead6f
commit 73296979f4

@ -67,6 +67,8 @@ import javax.net.ssl.SSLSocketFactory;
import io.requery.android.database.sqlite.SQLiteDatabase; import io.requery.android.database.sqlite.SQLiteDatabase;
public class FragmentOptionsMisc extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener { public class FragmentOptionsMisc extends FragmentBase implements SharedPreferences.OnSharedPreferenceChangeListener {
private boolean resumed = false;
private SwitchCompat swExternalSearch; private SwitchCompat swExternalSearch;
private SwitchCompat swShortcuts; private SwitchCompat swShortcuts;
private SwitchCompat swFts; private SwitchCompat swFts;
@ -472,6 +474,27 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
return view; return view;
} }
@Override
public void onResume() {
super.onResume();
resumed = true;
View view = getView();
if (view != null)
view.post(new Runnable() {
@Override
public void run() {
updateUsage();
}
});
}
@Override
public void onPause() {
super.onPause();
resumed = false;
}
@Override @Override
public void onDestroyView() { public void onDestroyView() {
PreferenceManager.getDefaultSharedPreferences(getContext()).unregisterOnSharedPreferenceChangeListener(this); PreferenceManager.getDefaultSharedPreferences(getContext()).unregisterOnSharedPreferenceChangeListener(this);
@ -587,23 +610,42 @@ public class FragmentOptionsMisc extends FragmentBase implements SharedPreferenc
tvMemoryClass.setText(getString(R.string.title_advanced_memory_class, tvMemoryClass.setText(getString(R.string.title_advanced_memory_class,
class_mb + " MB", Helper.humanReadableByteCount(mi.totalMem))); class_mb + " MB", Helper.humanReadableByteCount(mi.totalMem)));
Runtime rt = Runtime.getRuntime();
long hused = rt.totalMemory() - rt.freeMemory();
long hmax = rt.maxMemory();
long nheap = Debug.getNativeHeapAllocatedSize();
tvMemoryUsage.setText(getString(R.string.title_advanced_memory_usage,
Helper.humanReadableByteCount(hused),
Helper.humanReadableByteCount(hmax),
Helper.humanReadableByteCount(nheap)));
tvStorageUsage.setText(getString(R.string.title_advanced_storage_usage,
Helper.humanReadableByteCount(Helper.getAvailableStorageSpace()),
Helper.humanReadableByteCount(Helper.getTotalStorageSpace())));
tvFingerprint.setText(Helper.getFingerprint(getContext())); tvFingerprint.setText(Helper.getFingerprint(getContext()));
grpDebug.setVisibility(swDebug.isChecked() || BuildConfig.DEBUG ? View.VISIBLE : View.GONE); grpDebug.setVisibility(swDebug.isChecked() || BuildConfig.DEBUG ? View.VISIBLE : View.GONE);
} }
private void updateUsage() {
if (!resumed)
return;
try {
Log.i("Update usage");
Runtime rt = Runtime.getRuntime();
long hused = rt.totalMemory() - rt.freeMemory();
long hmax = rt.maxMemory();
long nheap = Debug.getNativeHeapAllocatedSize();
tvMemoryUsage.setText(getString(R.string.title_advanced_memory_usage,
Helper.humanReadableByteCount(hused),
Helper.humanReadableByteCount(hmax),
Helper.humanReadableByteCount(nheap)));
tvStorageUsage.setText(getString(R.string.title_advanced_storage_usage,
Helper.humanReadableByteCount(Helper.getAvailableStorageSpace()),
Helper.humanReadableByteCount(Helper.getTotalStorageSpace())));
getView().postDelayed(new Runnable() {
@Override
public void run() {
updateUsage();
}
}, 2500);
} catch (Throwable ex) {
Log.e(ex);
}
}
private void setLastCleanup(long time) { private void setLastCleanup(long time) {
java.text.DateFormat DTF = Helper.getDateTimeInstance(getContext()); java.text.DateFormat DTF = Helper.getDateTimeInstance(getContext());
tvLastCleanup.setText( tvLastCleanup.setText(

Loading…
Cancel
Save