Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.tencent.shadow.sample.host.lib;

/**
* @author zhukun on 2019-07-13.
*/
public interface Callback {

String call(String src);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.tencent.shadow.sample.host.lib;

import android.content.Context;
import android.util.Log;

/**
* @author zhukun on 2019-07-13.
*/
public class HostCallbackProvider {
private static HostCallbackProvider sInstance;
private Callback mCallback;

public static void init(Context mHostApplicationContext) {
sInstance = new HostCallbackProvider(mHostApplicationContext);
}

public static HostCallbackProvider getInstance() {
return sInstance;
}

final private Context mHostApplicationContext;

private HostCallbackProvider(Context mHostApplicationContext) {
this.mHostApplicationContext = mHostApplicationContext;
}


public void setCallback(Callback callback) {
this.mCallback = callback;
}

public Callback getCallback() {
return this.mCallback;
}

public void call() {
String result = this.mCallback.call("shadow");

Log.i("test", result);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.tencent.shadow.sample.host.lib;

import android.content.Context;
import android.util.Log;

/**
* @author zhukun on 2019-07-13.
*/
public class HostCallbackProvider2 {
private static HostCallbackProvider2 sInstance;
private Callback mCallback;

public static void init(Context mHostApplicationContext) {
sInstance = new HostCallbackProvider2(mHostApplicationContext);
}

public static HostCallbackProvider2 getInstance() {
return sInstance;
}

final private Context mHostApplicationContext;

private HostCallbackProvider2(Context mHostApplicationContext) {
this.mHostApplicationContext = mHostApplicationContext;
}


public void setCallback(Callback callback) {
this.mCallback = callback;
}

public Callback getCallback() {
return this.mCallback;
}

public void call() {
String result = this.mCallback.call("shadow");

Log.i("test", result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import com.tencent.shadow.core.common.LoggerFactory;
import com.tencent.shadow.dynamic.host.DynamicRuntime;
import com.tencent.shadow.dynamic.host.PluginManager;
import com.tencent.shadow.sample.host.lib.Callback;
import com.tencent.shadow.sample.host.lib.HostCallbackProvider;
import com.tencent.shadow.sample.host.lib.HostCallbackProvider2;
import com.tencent.shadow.sample.host.lib.HostUiLayerProvider;
import com.tencent.shadow.sample.host.manager.Shadow;

Expand Down Expand Up @@ -52,6 +55,16 @@ public void onCreate() {
PluginHelper.getInstance().init(this);

HostUiLayerProvider.init(this);
HostCallbackProvider.init(this);


HostCallbackProvider2.init(this);
HostCallbackProvider2.getInstance().setCallback(new Callback() {
@Override
public String call(String src) {
return "src:" + src;
}
});
}

private static void detectNonSdkApiUsageOnAndroidP() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;

import com.tencent.shadow.dynamic.host.EnterCallback;
import com.tencent.shadow.sample.constant.Constant;
import com.tencent.shadow.sample.host.lib.HostCallbackProvider;


public class PluginLoadActivity extends Activity {
Expand All @@ -43,6 +45,14 @@ protected void onCreate(Bundle savedInstanceState) {
mViewGroup = findViewById(R.id.container);

startPlugin();

new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Log.i("test", "start....");
HostCallbackProvider.getInstance().call();
}
}, 15000);
}


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

<activity android:name="com.tencent.shadow.sample.plugin.app.lib.usecases.context.ApplicationContextSubDirTestActivity" />
<activity android:name=".usecases.host_communication.PluginUseHostClassActivity" />
<activity android:name=".usecases.host_communication.HostUsePluginClassActivity" />

<provider
android:authorities="com.tencent.shadow.provider.test"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public class MainActivity extends Activity implements
private ExpandableListAdapter adapter;
private UseCaseSummaryFragment caseSummaryFragment;


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -84,7 +85,6 @@ public void onCreate(Bundle savedInstanceState) {

stickyLayout.setOnGiveUpTouchEventListener(this);
slidingMenu.showMenu();

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.tencent.shadow.sample.plugin.app.lib.usecases.dialog.TestDialogActivity;
import com.tencent.shadow.sample.plugin.app.lib.usecases.fragment.TestDynamicFragmentActivity;
import com.tencent.shadow.sample.plugin.app.lib.usecases.fragment.TestXmlFragmentActivity;
import com.tencent.shadow.sample.plugin.app.lib.usecases.host_communication.HostUsePluginClassActivity;
import com.tencent.shadow.sample.plugin.app.lib.usecases.host_communication.PluginUseHostClassActivity;
import com.tencent.shadow.sample.plugin.app.lib.usecases.packagemanager.TestPackageManagerActivity;
import com.tencent.shadow.sample.plugin.app.lib.usecases.provider.TestDBContentProviderActivity;
Expand Down Expand Up @@ -102,6 +103,7 @@ public static void initCase() {

UseCaseCategory communicationCategory = new UseCaseCategory("插件和宿主通信相关测试用例", new UseCase[]{
new PluginUseHostClassActivity.Case(),
new HostUsePluginClassActivity.Case(),
});
useCases.add(communicationCategory);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* Tencent is pleased to support the open source community by making Tencent Shadow available.
* Copyright (C) 2019 THL A29 Limited, a Tencent company. All rights reserved.
*
* Licensed under the BSD 3-Clause License (the "License"); you may not use
* this file except in compliance with the License. You may obtain a copy of
* the License at
*
* https://opensource.org/licenses/BSD-3-Clause
*
* 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.tencent.shadow.sample.plugin.app.lib.usecases.host_communication;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.LinearLayout;

import com.tencent.shadow.sample.host.lib.Callback;
import com.tencent.shadow.sample.host.lib.HostCallbackProvider;
import com.tencent.shadow.sample.host.lib.HostCallbackProvider2;
import com.tencent.shadow.sample.host.lib.HostUiLayerProvider;
import com.tencent.shadow.sample.plugin.app.lib.gallery.BaseActivity;
import com.tencent.shadow.sample.plugin.app.lib.gallery.cases.entity.UseCase;

public class HostUsePluginClassActivity extends BaseActivity {
public static class Case extends UseCase {
@Override
public String getName() {
return "宿主使用插件类测试";
}

@Override
public String getSummary() {
return "测试宿主使用插件类的方法";
}

@Override
public Class getPageClass() {
return HostUsePluginClassActivity.class;
}
}

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

LinearLayout linearLayout = new LinearLayout(this);

HostUiLayerProvider hostUiLayerProvider = HostUiLayerProvider.getInstance();
View hostUiLayer = hostUiLayerProvider.buildHostUiLayer();
linearLayout.addView(hostUiLayer);

setContentView(linearLayout);

HostCallbackProvider.getInstance().setCallback(new Callback() {
@Override
public String call(String s) {
return "Hi, " + s + ", byebye";
}
});


// HostCallbackProvider.getInstance().call();

HostCallbackProvider2.getInstance().call();
}
}