mirror of
https://github.com/topjohnwu/Magisk.git
synced 2025-03-28 16:32:14 +00:00
103 lines
3.2 KiB
Java
103 lines
3.2 KiB
Java
package com.topjohnwu.magisk.components;
|
|
|
|
import android.content.pm.PackageManager;
|
|
import android.content.res.AssetManager;
|
|
import android.content.res.Configuration;
|
|
import android.content.res.Resources;
|
|
import android.os.Bundle;
|
|
import android.support.annotation.Keep;
|
|
import android.support.annotation.NonNull;
|
|
import android.support.annotation.Nullable;
|
|
import android.support.v7.app.AppCompatActivity;
|
|
import android.view.WindowManager;
|
|
|
|
import com.topjohnwu.magisk.MagiskManager;
|
|
import com.topjohnwu.magisk.R;
|
|
import com.topjohnwu.magisk.utils.Topic;
|
|
import com.topjohnwu.magisk.utils.Utils;
|
|
|
|
public class Activity extends AppCompatActivity {
|
|
|
|
private AssetManager mAssetManager = null;
|
|
private Resources mResources = null;
|
|
|
|
public Activity() {
|
|
super();
|
|
Configuration configuration = new Configuration();
|
|
configuration.setLocale(MagiskManager.locale);
|
|
applyOverrideConfiguration(configuration);
|
|
}
|
|
|
|
@Override
|
|
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
|
super.onCreate(savedInstanceState);
|
|
if (this instanceof Topic.Subscriber) {
|
|
((Topic.Subscriber) this).subscribeTopics();
|
|
}
|
|
}
|
|
|
|
@Override
|
|
protected void onDestroy() {
|
|
if (this instanceof Topic.Subscriber) {
|
|
((Topic.Subscriber) this).unsubscribeTopics();
|
|
}
|
|
super.onDestroy();
|
|
}
|
|
|
|
@Override
|
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
|
MagiskManager mm = getMagiskManager();
|
|
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
if (mm.permissionGrantCallback != null) {
|
|
mm.permissionGrantCallback.run();
|
|
}
|
|
}
|
|
mm.permissionGrantCallback = null;
|
|
}
|
|
|
|
@Override
|
|
public AssetManager getAssets() {
|
|
return mAssetManager == null ? super.getAssets() : mAssetManager;
|
|
}
|
|
|
|
@Override
|
|
public Resources getResources() {
|
|
return mResources == null ? super.getResources() : mResources;
|
|
}
|
|
|
|
public MagiskManager getMagiskManager() {
|
|
return (MagiskManager) super.getApplicationContext();
|
|
}
|
|
|
|
protected void setFloating() {
|
|
boolean isTablet = getResources().getBoolean(R.bool.isTablet);
|
|
if (isTablet) {
|
|
WindowManager.LayoutParams params = getWindow().getAttributes();
|
|
params.height = getResources().getDimensionPixelSize(R.dimen.floating_height);
|
|
params.width = getResources().getDimensionPixelSize(R.dimen.floating_width);
|
|
params.alpha = 1.0f;
|
|
params.dimAmount = 0.6f;
|
|
params.flags |= 2;
|
|
getWindow().setAttributes(params);
|
|
setFinishOnTouchOutside(true);
|
|
}
|
|
}
|
|
|
|
@Keep
|
|
public void swapResources(String dexPath) {
|
|
mAssetManager = Utils.getAssets(dexPath);
|
|
if (mAssetManager == null)
|
|
return;
|
|
Resources res = super.getResources();
|
|
mResources = new Resources(mAssetManager, res.getDisplayMetrics(), res.getConfiguration());
|
|
mResources.newTheme().setTo(super.getTheme());
|
|
}
|
|
|
|
@Keep
|
|
public void restoreResources() {
|
|
mAssetManager = null;
|
|
mResources = null;
|
|
}
|
|
|
|
}
|