Skip to content

Commit

Permalink
Plugin lib: AndroidX的Activity使用PluginResource
Browse files Browse the repository at this point in the history
  • Loading branch information
raotao committed Mar 25, 2022
1 parent e44e8b0 commit dcb8bde
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;

Expand All @@ -26,6 +27,7 @@

import com.qihoo360.replugin.RePluginInternal;
import com.qihoo360.replugin.helper.LogRelease;
import com.qihoo360.replugin.loader.PluginResource;

import java.lang.reflect.Field;

Expand All @@ -34,15 +36,25 @@
*/
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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.os.Build;
import android.os.Bundle;

Expand All @@ -26,6 +27,7 @@

import com.qihoo360.replugin.RePluginInternal;
import com.qihoo360.replugin.helper.LogRelease;
import com.qihoo360.replugin.loader.PluginResource;

import java.lang.reflect.Field;

Expand All @@ -34,15 +36,25 @@
*/
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();
}

Expand Down

0 comments on commit dcb8bde

Please sign in to comment.