This repository has been archived on 2026-04-04. You can view files and clone it, but you cannot make any changes to its state, such as pushing and creating new issues, pull requests or comments.
mbcp-helper/app/src/main/java/toolkit/coderstory/SettingsActivity.java
2021-04-12 19:22:11 +08:00

61 lines
2.4 KiB
Java

package toolkit.coderstory;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.os.Bundle;
import android.preference.PreferenceFragment;
import android.view.View;
import com.coderstory.toolkit.R;
public class SettingsActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
checkEdXposed();
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.fragment_container, new SettingsFragment()).commit();
}
}
@SuppressLint("WorldReadableFiles")
private void checkEdXposed() {
try {
// getSharedPreferences will hooked by LSPosed and change xml file path to /data/misc/edxp**
// will not throw SecurityException
//noinspection deprecation
getSharedPreferences("conf", Context.MODE_WORLD_READABLE);
} catch (SecurityException exception) {
new AlertDialog.Builder(this)
.setMessage(getString(R.string.not_supported))
.setPositiveButton(android.R.string.ok, (dialog12, which) -> finish())
.setNegativeButton(R.string.ignore, null)
.show();
}
}
public static class SettingsFragment extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getPreferenceManager().setSharedPreferencesName("conf");
addPreferencesFromResource(R.xml.prefs);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
view.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
View list = view.findViewById(android.R.id.list);
list.setOnApplyWindowInsetsListener((v, insets) -> {
list.setPadding(insets.getSystemWindowInsetLeft(), insets.getSystemWindowInsetTop(), insets.getSystemWindowInsetRight(), insets.getStableInsetBottom());
return insets.consumeSystemWindowInsets();
});
super.onViewCreated(view, savedInstanceState);
}
}
}