diff --git a/replugin-sample-extra/README.md b/replugin-sample-extra/README.md new file mode 100644 index 00000000..e67e6cb6 --- /dev/null +++ b/replugin-sample-extra/README.md @@ -0,0 +1,5 @@ +# replugin-sample-extra 中是一些更高级的示例 + +其中,replugin-sample-extra/fresco 是对 Fresco 的使用,实现了宿主和插件公用一份Fresco代码。 + +FrescoHost是宿主代码,FrescoPlugin是插件代码。 diff --git a/replugin-sample-extra/fresco/FrescoHost/.gitignore b/replugin-sample-extra/fresco/FrescoHost/.gitignore new file mode 100644 index 00000000..39fb081a --- /dev/null +++ b/replugin-sample-extra/fresco/FrescoHost/.gitignore @@ -0,0 +1,9 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/replugin-sample-extra/fresco/FrescoHost/app/.gitignore b/replugin-sample-extra/fresco/FrescoHost/app/.gitignore new file mode 100644 index 00000000..796b96d1 --- /dev/null +++ b/replugin-sample-extra/fresco/FrescoHost/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/replugin-sample-extra/fresco/FrescoHost/app/build.gradle b/replugin-sample-extra/fresco/FrescoHost/app/build.gradle new file mode 100644 index 00000000..87387be3 --- /dev/null +++ b/replugin-sample-extra/fresco/FrescoHost/app/build.gradle @@ -0,0 +1,76 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 26 + buildToolsVersion "26.0.2" + + defaultConfig { + applicationId "com.qihoo360.replugin.fresco.host" + minSdkVersion 14 + targetSdkVersion 26 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } + + sourceSets { + main { + jniLibs.srcDirs = ['libs'] + } + } +} + +/* + * Copyright (C) 2005-2017 Qihoo 360 Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed To in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +// ATTENTION!!! Must be PLACED AFTER "android{}" to read the applicationId +apply plugin: 'replugin-host-gradle' + +/** + * 配置项均为可选配置,默认无需添加 + * 更多可选配置项参见replugin-host-gradle的RepluginConfig类 + * 可更改配置项参见 自动生成RePluginHostConfig.java + */ +repluginHostConfig { + + /** + * 是否使用 AppCompat 库 + * 不需要个性化配置时,无需添加 + */ + useAppCompat = true +} + +dependencies { + compile 'com.qihoo360.replugin:replugin-host-lib:2.2.1' + + compile fileTree(dir: 'libs', include: ['*.jar']) + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + + compile 'com.android.support:appcompat-v7:26.0.0-alpha1' + testCompile 'junit:junit:4.12' + + // fresco依赖bolts-android + compile "com.parse.bolts:bolts-android:1.4.0" +} diff --git a/replugin-sample-extra/fresco/FrescoHost/app/libs/armeabi/libimagepipeline.so b/replugin-sample-extra/fresco/FrescoHost/app/libs/armeabi/libimagepipeline.so new file mode 100644 index 00000000..cff4884f Binary files /dev/null and b/replugin-sample-extra/fresco/FrescoHost/app/libs/armeabi/libimagepipeline.so differ diff --git a/replugin-sample-extra/fresco/FrescoHost/app/libs/drawee-modified-1.7.1.jar b/replugin-sample-extra/fresco/FrescoHost/app/libs/drawee-modified-1.7.1.jar new file mode 100644 index 00000000..b514d339 Binary files /dev/null and b/replugin-sample-extra/fresco/FrescoHost/app/libs/drawee-modified-1.7.1.jar differ diff --git a/replugin-sample-extra/fresco/FrescoHost/app/libs/fbcore-1.7.1.jar b/replugin-sample-extra/fresco/FrescoHost/app/libs/fbcore-1.7.1.jar new file mode 100644 index 00000000..ce0053ff Binary files /dev/null and b/replugin-sample-extra/fresco/FrescoHost/app/libs/fbcore-1.7.1.jar differ diff --git a/replugin-sample-extra/fresco/FrescoHost/app/libs/fresco-1.7.1.jar b/replugin-sample-extra/fresco/FrescoHost/app/libs/fresco-1.7.1.jar new file mode 100644 index 00000000..7190ef51 Binary files /dev/null and b/replugin-sample-extra/fresco/FrescoHost/app/libs/fresco-1.7.1.jar differ diff --git a/replugin-sample-extra/fresco/FrescoHost/app/libs/imagepipeline-1.7.1.jar b/replugin-sample-extra/fresco/FrescoHost/app/libs/imagepipeline-1.7.1.jar new file mode 100644 index 00000000..51e2b542 Binary files /dev/null and b/replugin-sample-extra/fresco/FrescoHost/app/libs/imagepipeline-1.7.1.jar differ diff --git a/replugin-sample-extra/fresco/FrescoHost/app/libs/imagepipeline-base-1.7.1.jar b/replugin-sample-extra/fresco/FrescoHost/app/libs/imagepipeline-base-1.7.1.jar new file mode 100644 index 00000000..d48eff6e Binary files /dev/null and b/replugin-sample-extra/fresco/FrescoHost/app/libs/imagepipeline-base-1.7.1.jar differ diff --git a/replugin-sample-extra/fresco/FrescoHost/app/proguard-rules.pro b/replugin-sample-extra/fresco/FrescoHost/app/proguard-rules.pro new file mode 100644 index 00000000..d14c450f --- /dev/null +++ b/replugin-sample-extra/fresco/FrescoHost/app/proguard-rules.pro @@ -0,0 +1,25 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in D:\Android\android-sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/replugin-sample-extra/fresco/FrescoHost/app/src/main/AndroidManifest.xml b/replugin-sample-extra/fresco/FrescoHost/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..d716e32a --- /dev/null +++ b/replugin-sample-extra/fresco/FrescoHost/app/src/main/AndroidManifest.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/replugin-sample-extra/fresco/FrescoHost/app/src/main/assets/plugins/plugin1.jar b/replugin-sample-extra/fresco/FrescoHost/app/src/main/assets/plugins/plugin1.jar new file mode 100644 index 00000000..e41d11b0 Binary files /dev/null and b/replugin-sample-extra/fresco/FrescoHost/app/src/main/assets/plugins/plugin1.jar differ diff --git a/replugin-sample-extra/fresco/FrescoHost/app/src/main/java/com/facebook/fresco/patch/DraweeStyleableCallbackImpl.java b/replugin-sample-extra/fresco/FrescoHost/app/src/main/java/com/facebook/fresco/patch/DraweeStyleableCallbackImpl.java new file mode 100644 index 00000000..5cae30e5 --- /dev/null +++ b/replugin-sample-extra/fresco/FrescoHost/app/src/main/java/com/facebook/fresco/patch/DraweeStyleableCallbackImpl.java @@ -0,0 +1,293 @@ +/* + * Copyright (C) 2005-2017 Qihoo 360 Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed To in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.facebook.fresco.patch; + +import android.content.Context; + +import com.facebook.drawee.generic.DraweeStyleableCallback; + +import java.lang.reflect.Field; + +/** + * DraweeStyleableCallbackImpl + * + * 自定义属性回调接口 + * + * @author RePlugin Team + */ +public class DraweeStyleableCallbackImpl implements DraweeStyleableCallback { + + private Context mContext; + + DraweeStyleableCallbackImpl(Context context) { + this.mContext = context; + } + + /** + * 反射得到样式表数组,如:R.styleable.SimpleDraweeView + * + * @param context + * @param name + * @return + */ + private static int[] getStyleableArray(Context context, String name) { + try { + String className = context.getPackageName() + ".R$styleable"; + Field[] fields = Class.forName(className).getFields(); + for (Field field : fields) { + if (field.getName().equals(name)) { + return (int[]) field.get(null); + } + } + } catch (Exception e) { + e.printStackTrace(); + } + + return null; + } + + /** + * 反射得到样式表数组下的具体资源,如:R.styleable.GenericDraweeHierarchy_placeholderImage + * + * @param context + * @param styleableName + * @param styleableFieldName + * @return + */ + private static int getStyleableFieldId(Context context, String styleableName, String styleableFieldName) { + String className = context.getPackageName() + ".R"; + String type = "styleable"; + String name = styleableName + "_" + styleableFieldName; + + try { + Class cla = Class.forName(className); + for (Class childClass : cla.getClasses()) { + String simpleName = childClass.getSimpleName(); + if (simpleName.equals(type)) { + for (Field field : childClass.getFields()) { + String fieldName = field.getName(); + if (fieldName.equals(name)) { + return (int) field.get(null); + } + } + } + } + } catch (Exception e) { + e.printStackTrace(); + } + + return 0; + } + + @Override + public int[] getSimpleDraweeView() { + // 替代 R.styleable.SimpleDraweeView; + return getStyleableArray(mContext, "SimpleDraweeView"); + } + + @Override + public int[] getGenericDraweeHierarchy() { + // 替代 R.styleable.GenericDraweeHierarchy; + return getStyleableArray(mContext, "GenericDraweeHierarchy"); + } + + @Override + public int getActualImageScaleType() { + // 替代 R.styleable.GenericDraweeHierarchy_actualImageScaleType; + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "actualImageScaleType"); + } + + @Override + public int getPlaceholderImage() { + // 替代:R.styleable.GenericDraweeHierarchy_placeholderImage + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "placeholderImage"); + } + + @Override + public int getPressedStateOverlayImage() { + // 替代:R.styleable.GenericDraweeHierarchy_pressedStateOverlayImage + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "pressedStateOverlayImage"); + } + + @Override + public int getProgressBarImage() { + // R.styleable.GenericDraweeHierarchy_progressBarImage; + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "progressBarImage"); + } + + @Override + public int getFadeDuration() { + // R.styleable.GenericDraweeHierarchy_fadeDuration; + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "fadeDuration"); + } + + @Override + public int getViewAspectRatio() { + // R.styleable.GenericDraweeHierarchy_viewAspectRatio; + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "viewAspectRatio"); + } + + @Override + public int getPlaceholderImageScaleType() { + // R.styleable.GenericDraweeHierarchy_placeholderImageScaleType; + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "placeholderImageScaleType"); + } + + @Override + public int getRetryImage() { + // R.styleable.GenericDraweeHierarchy_retryImage; + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "retryImage"); + } + + @Override + public int getRetryImageScaleType() { + // R.styleable.GenericDraweeHierarchy_retryImageScaleType; + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "retryImageScaleType"); + } + + @Override + public int getFailureImage() { + // return R.styleable.GenericDraweeHierarchy_failureImage; + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "failureImage"); + } + + @Override + public int getFailureImageScaleType() { + // R.styleable.GenericDraweeHierarchy_failureImageScaleType; + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "failureImageScaleType"); + } + + @Override + public int getProgressBarImageScaleType() { + // R.styleable.GenericDraweeHierarchy_progressBarImageScaleType; + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "progressBarImageScaleType"); + } + + @Override + public int getProgressBarAutoRotateInterval() { + // R.styleable.GenericDraweeHierarchy_progressBarAutoRotateInterval; + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "progressBarAutoRotateInterval"); + } + + @Override + public int getBackgroundImage() { + // R.styleable.GenericDraweeHierarchy_backgroundImage; + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "backgroundImage"); + } + + @Override + public int getOverlayImage() { + // R.styleable.GenericDraweeHierarchy_overlayImage; + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "overlayImage"); + } + + @Override + public int getRoundAsCircle() { + // R.styleable.GenericDraweeHierarchy_roundAsCircle; + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "roundAsCircle"); + } + + @Override + public int getRoundedCornerRadius() { + // R.styleable.GenericDraweeHierarchy_roundedCornerRadius; + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "roundedCornerRadius"); + } + + @Override + public int getRoundTopLeft() { + // R.styleable.GenericDraweeHierarchy_roundTopLeft; + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "roundTopLeft"); + } + + @Override + public int getRoundTopRight() { + // R.styleable.GenericDraweeHierarchy_roundTopRight; + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "roundTopRight"); + } + + @Override + public int getRoundBottomLeft() { + // R.styleable.GenericDraweeHierarchy_roundBottomLeft; + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "roundBottomLeft"); + } + + @Override + public int getRoundBottomRight() { + // R.styleable.GenericDraweeHierarchy_roundBottomRight; + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "roundBottomRight"); + } + + @Override + public int getRoundTopStart() { + // R.styleable.GenericDraweeHierarchy_roundTopStart; + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "roundTopStart"); + } + + @Override + public int getRoundTopEnd() { + // R.styleable.GenericDraweeHierarchy_roundTopEnd; + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "roundTopEnd"); + } + + @Override + public int getRoundBottomStart() { + // R.styleable.GenericDraweeHierarchy_roundBottomStart; + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "roundBottomStart"); + } + + @Override + public int getRoundBottomEnd() { + // R.styleable.GenericDraweeHierarchy_roundBottomEnd; + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "roundBottomEnd"); + } + + @Override + public int getRoundWithOverlayColor() { + // R.styleable.GenericDraweeHierarchy_roundWithOverlayColor; + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "roundWithOverlayColor"); + } + + @Override + public int getRoundingBorderWidth() { + // R.styleable.GenericDraweeHierarchy_roundingBorderWidth; + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "roundingBorderWidth"); + } + + @Override + public int getRoundingBorderColor() { + // R.styleable.GenericDraweeHierarchy_roundingBorderColor; + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "roundingBorderColor"); + } + + @Override + public int getRoundingBorderPadding() { + // R.styleable.GenericDraweeHierarchy_roundingBorderPadding; + return getStyleableFieldId(mContext, "GenericDraweeHierarchy", "roundingBorderPadding"); + } + + @Override + public int getActualImageUri() { + // R.styleable.SimpleDraweeView_actualImageUri; + return getStyleableFieldId(mContext, "SimpleDraweeView", "actualImageUri"); + } + + @Override + public int getActualImageResource() { + // R.styleable.SimpleDraweeView_actualImageResource; + return getStyleableFieldId(mContext, "SimpleDraweeView", "actualImageResource"); + } +} \ No newline at end of file diff --git a/replugin-sample-extra/fresco/FrescoHost/app/src/main/java/com/facebook/fresco/patch/FrescoPatch.java b/replugin-sample-extra/fresco/FrescoHost/app/src/main/java/com/facebook/fresco/patch/FrescoPatch.java new file mode 100644 index 00000000..c295a790 --- /dev/null +++ b/replugin-sample-extra/fresco/FrescoHost/app/src/main/java/com/facebook/fresco/patch/FrescoPatch.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2005-2017 Qihoo 360 Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed To in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.facebook.fresco.patch; + +import android.content.Context; + +import com.facebook.drawee.generic.GenericDraweeHierarchyInflater; +import com.facebook.drawee.view.SimpleDraweeView; + +/** + * 为 “自己编译好的fresco drawee 模块(对应drawee-modified-1.7.1.jar)” 设置回调接口 + * + * @author RePlugin Team + */ +public class FrescoPatch { + + /** + * 初始化 + *

+ * 为SimpleDraweeView设置回调 + * 为GenericDraweeHierarchyInflater设置回调 + */ + public static void initialize(Context context) { + DraweeStyleableCallbackImpl draweeStyleableCallback = new DraweeStyleableCallbackImpl(context); + SimpleDraweeView.setDraweeStyleableCallback(draweeStyleableCallback); + GenericDraweeHierarchyInflater.setDraweeStyleableCallback(draweeStyleableCallback); + } +} \ No newline at end of file diff --git a/replugin-sample-extra/fresco/FrescoHost/app/src/main/java/com/qihoo360/replugin/fresco/host/HostApp.java b/replugin-sample-extra/fresco/FrescoHost/app/src/main/java/com/qihoo360/replugin/fresco/host/HostApp.java new file mode 100644 index 00000000..b18b24dd --- /dev/null +++ b/replugin-sample-extra/fresco/FrescoHost/app/src/main/java/com/qihoo360/replugin/fresco/host/HostApp.java @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2005-2017 Qihoo 360 Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed To in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.qihoo360.replugin.fresco.host; + +import com.facebook.drawee.backends.pipeline.Fresco; +import com.facebook.fresco.patch.FrescoPatch; +import com.qihoo360.replugin.RePluginApplication; +import com.qihoo360.replugin.RePluginConfig; + +/** + * HostApp + * + * @author RePlugin Team + */ +public class HostApp extends RePluginApplication { + + @Override + public void onCreate() { + super.onCreate(); + + // 初始化Fresco + Fresco.initialize(this); + + // 初始化FrescoPath + FrescoPatch.initialize(this); + } + + /** + * RePlugin允许提供各种“自定义”的行为,让您“无需修改源代码”,即可实现相应的功能 + */ + @Override + protected RePluginConfig createConfig() { + RePluginConfig c = new RePluginConfig(); + + // 允许“插件使用宿主类” + // 打开这个开关之后,当插件ClassLoader找不到类时,会去看宿主是否有这个类 + // 从而,实现插件复用宿主中的Java类 + c.setUseHostClassIfNotFound(true); + + return c; + } +} \ No newline at end of file diff --git a/replugin-sample-extra/fresco/FrescoHost/app/src/main/java/com/qihoo360/replugin/fresco/host/HostFrescoActivity.java b/replugin-sample-extra/fresco/FrescoHost/app/src/main/java/com/qihoo360/replugin/fresco/host/HostFrescoActivity.java new file mode 100644 index 00000000..74cbaae5 --- /dev/null +++ b/replugin-sample-extra/fresco/FrescoHost/app/src/main/java/com/qihoo360/replugin/fresco/host/HostFrescoActivity.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2005-2017 Qihoo 360 Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed To in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.qihoo360.replugin.fresco.host; + +import android.net.Uri; +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; + +import com.facebook.drawee.view.SimpleDraweeView; + +/** + * 宿主中使用fresco + * + * @author RePlugin Team + */ +public class HostFrescoActivity extends AppCompatActivity { + + private static final String IMAGE_URL = "https://img1.doubanio.com/view/photo/large/public/p2504463708.jpg"; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_host_fresco); + + SimpleDraweeView draweeView = (SimpleDraweeView) findViewById(R.id.image); + draweeView.setImageURI(Uri.parse(IMAGE_URL)); + } +} \ No newline at end of file diff --git a/replugin-sample-extra/fresco/FrescoHost/app/src/main/java/com/qihoo360/replugin/fresco/host/MainActivity.java b/replugin-sample-extra/fresco/FrescoHost/app/src/main/java/com/qihoo360/replugin/fresco/host/MainActivity.java new file mode 100644 index 00000000..177d0703 --- /dev/null +++ b/replugin-sample-extra/fresco/FrescoHost/app/src/main/java/com/qihoo360/replugin/fresco/host/MainActivity.java @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2005-2017 Qihoo 360 Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed To in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ + +package com.qihoo360.replugin.fresco.host; + +import android.content.Intent; +import android.os.Bundle; +import android.os.Handler; +import android.os.Looper; +import android.os.Message; +import android.support.v7.app.AppCompatActivity; +import android.util.Log; +import android.view.View; +import android.widget.Button; + +import com.qihoo360.replugin.RePlugin; + +/** + * @author RePlugin Team + */ +public class MainActivity extends AppCompatActivity { + + private Button mButton1; + private Button mButton2; + + Handler mHandler = new Handler(Looper.getMainLooper()) { + + @Override + public void handleMessage(Message msg) { + super.handleMessage(msg); + RePlugin.startActivity(MainActivity.this, new Intent(), "plugin1", "com.qihoo360.replugin.fresco.plugin.MainActivity"); + } + }; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + mButton1 = (Button) findViewById(R.id.button1); + mButton2 = (Button) findViewById(R.id.button2); + + mButton1.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View view) { + startActivity(new Intent(MainActivity.this, HostFrescoActivity.class)); + } + }); + + mButton2.setOnClickListener(new View.OnClickListener() { + + @Override + public void onClick(View view) { + + new Thread() { + @Override + public void run() { + super.run(); + + long begin = System.currentTimeMillis(); + RePlugin.preload("plugin1"); + Log.d("FrescoHost", "preload use:" + (System.currentTimeMillis() - begin)); + + mHandler.sendEmptyMessage(-1); + } + }.start(); + } + }); + } +} \ No newline at end of file diff --git a/replugin-sample-extra/fresco/FrescoHost/app/src/main/res/layout/activity_host_fresco.xml b/replugin-sample-extra/fresco/FrescoHost/app/src/main/res/layout/activity_host_fresco.xml new file mode 100644 index 00000000..4bceeaef --- /dev/null +++ b/replugin-sample-extra/fresco/FrescoHost/app/src/main/res/layout/activity_host_fresco.xml @@ -0,0 +1,14 @@ + + + + + + \ No newline at end of file diff --git a/replugin-sample-extra/fresco/FrescoHost/app/src/main/res/layout/activity_main.xml b/replugin-sample-extra/fresco/FrescoHost/app/src/main/res/layout/activity_main.xml new file mode 100644 index 00000000..bdd222cb --- /dev/null +++ b/replugin-sample-extra/fresco/FrescoHost/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,27 @@ + + + + + +