Plugin lib: AndroidX的Activity使用PluginResource

This commit is contained in:
raotao 2022-03-25 17:47:24 +08:00
parent e44e8b0524
commit dcb8bdec24
2 changed files with 26 additions and 2 deletions

View File

@ -18,6 +18,7 @@ package com.qihoo360.replugin.loader.a;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
@ -26,6 +27,7 @@ import androidx.fragment.app.Fragment;
import com.qihoo360.replugin.RePluginInternal;
import com.qihoo360.replugin.helper.LogRelease;
import com.qihoo360.replugin.loader.PluginResource;
import java.lang.reflect.Field;
@ -34,15 +36,25 @@ import java.lang.reflect.Field;
*/
public abstract class PluginAppCompatXActivity extends AppCompatActivity {
private PluginResource pluginResource;
@Override
protected void attachBaseContext(Context newBase) {
newBase = RePluginInternal.createActivityContext(this, newBase);
pluginResource = new PluginResource(newBase);
super.attachBaseContext(newBase);
}
@Override
public Context getBaseContext() {
public Resources getResources() {
if (pluginResource != null){
return pluginResource;
}
return super.getResources();
}
@Override
public Context getBaseContext() {
return super.getBaseContext();
}

View File

@ -18,6 +18,7 @@ package com.qihoo360.replugin.loader.a;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;
@ -26,6 +27,7 @@ import androidx.fragment.app.FragmentActivity;
import com.qihoo360.replugin.RePluginInternal;
import com.qihoo360.replugin.helper.LogRelease;
import com.qihoo360.replugin.loader.PluginResource;
import java.lang.reflect.Field;
@ -34,15 +36,25 @@ import java.lang.reflect.Field;
*/
public abstract class PluginFragmentXActivity extends FragmentActivity {
private PluginResource pluginResource;
@Override
protected void attachBaseContext(Context newBase) {
newBase = RePluginInternal.createActivityContext(this, newBase);
pluginResource = new PluginResource(newBase);
super.attachBaseContext(newBase);
}
@Override
public Context getBaseContext() {
public Resources getResources() {
if (pluginResource != null){
return pluginResource;
}
return super.getResources();
}
@Override
public Context getBaseContext() {
return super.getBaseContext();
}