mirror of
https://gitee.com/openharmony/applications_app_samples
synced 2024-11-23 08:30:06 +00:00
fix Flow task management service show device list
Signed-off-by: wangli325 <wangli325@huawei.com>
This commit is contained in:
parent
dafec89eaf
commit
d7eb994cd0
@ -15,8 +15,10 @@
|
||||
|
||||
package ohos.samples.distributedscheduler.slice;
|
||||
|
||||
import ohos.agp.window.dialog.IDialog;
|
||||
import ohos.agp.window.dialog.ListDialog;
|
||||
import ohos.aafwk.ability.continuation.ExtraParams;
|
||||
import ohos.aafwk.ability.continuation.IContinuationDeviceCallback;
|
||||
import ohos.aafwk.ability.continuation.IContinuationRegisterManager;
|
||||
import ohos.aafwk.ability.continuation.RequestCallback;
|
||||
import ohos.distributedschedule.interwork.IInitCallback;
|
||||
import ohos.samples.distributedscheduler.MainAbility;
|
||||
import ohos.samples.distributedscheduler.RemoteAgentProxy;
|
||||
@ -33,7 +35,6 @@ import ohos.agp.components.Text;
|
||||
import ohos.agp.window.dialog.ToastDialog;
|
||||
import ohos.app.Context;
|
||||
import ohos.bundle.ElementName;
|
||||
import ohos.distributedschedule.interwork.DeviceInfo;
|
||||
import ohos.distributedschedule.interwork.DeviceManager;
|
||||
import ohos.eventhandler.EventHandler;
|
||||
import ohos.eventhandler.EventRunner;
|
||||
@ -43,10 +44,6 @@ import ohos.hiviewdfx.HiLogLabel;
|
||||
import ohos.rpc.IRemoteObject;
|
||||
import ohos.rpc.RemoteException;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static ohos.agp.components.ComponentContainer.LayoutConfig.MATCH_CONTENT;
|
||||
|
||||
/**
|
||||
* MainAbilitySlice
|
||||
*/
|
||||
@ -66,13 +63,17 @@ public class MainAbilitySlice extends AbilitySlice implements IAbilityContinuati
|
||||
|
||||
private static final String REMOTE_SERVICE_FA = "ohos.samples.distributedscheduler.PageAbility";
|
||||
|
||||
private IContinuationRegisterManager continuationRegisterManager;
|
||||
|
||||
private int abilityToken;
|
||||
|
||||
private Text text;
|
||||
|
||||
private String param;
|
||||
|
||||
private String selectedDeviceId;
|
||||
private String selectedDeviceId;
|
||||
|
||||
private RemoteAgentProxy remoteAgentProxy = null;
|
||||
private RemoteAgentProxy remoteAgentProxy = null;
|
||||
|
||||
private EventHandler eventHandler = new EventHandler(EventRunner.current()) {
|
||||
@Override
|
||||
@ -94,9 +95,22 @@ public class MainAbilitySlice extends AbilitySlice implements IAbilityContinuati
|
||||
public void onStart(Intent intent) {
|
||||
super.onStart(intent);
|
||||
super.setUIContent(ohos.samples.distributedscheduler.ResourceTable.Layout_main_ability_slice);
|
||||
initContinuationRegisterManager();
|
||||
initComponents();
|
||||
}
|
||||
|
||||
private void initContinuationRegisterManager() {
|
||||
continuationRegisterManager = getContinuationRegisterManager();
|
||||
ExtraParams params = new ExtraParams();
|
||||
String[] devTypes = new String[]{ExtraParams.DEVICETYPE_SMART_PAD, ExtraParams.DEVICETYPE_SMART_PHONE};
|
||||
params.setDevType(devTypes);
|
||||
params.setTargetBundleName(REMOTE_BUNDLE);
|
||||
String jsonParams = "{\"filter\":{\"commonFilter\":{\"groupType\":\"1|256\"}}," +
|
||||
"\"isTurnOffRecommend\":true,\"transferScene\":0}";
|
||||
params.setJsonParams(jsonParams);
|
||||
continuationRegisterManager.register(REMOTE_BUNDLE, params, callback, requestCallback);
|
||||
}
|
||||
|
||||
private void initComponents() {
|
||||
Component choiceDeviceButton = findComponentById(ResourceTable.Id_choice_device);
|
||||
choiceDeviceButton.setClickedListener(component -> selectDevice());
|
||||
@ -140,33 +154,43 @@ public class MainAbilitySlice extends AbilitySlice implements IAbilityContinuati
|
||||
}
|
||||
|
||||
private void selectDevice() {
|
||||
List<DeviceInfo> infoList = DeviceManager.getDeviceList(DeviceInfo.FLAG_GET_ALL_DEVICE);
|
||||
if ((infoList == null) || (infoList.size() == 0)) {
|
||||
selectedDeviceId = null;
|
||||
}
|
||||
String[] items = new String[infoList.size()];
|
||||
int i = 0;
|
||||
for (DeviceInfo info : infoList) {
|
||||
items[i] = info.getDeviceType() + ", " + info.getDeviceName();
|
||||
i++;
|
||||
}
|
||||
ListDialog listDialog = new ListDialog(getContext());
|
||||
listDialog.setItems(items);
|
||||
listDialog.setTitleText("Choice a device");
|
||||
listDialog.setSize(DIALOG_WIDTH, MATCH_CONTENT);
|
||||
listDialog.setAutoClosable(true);
|
||||
listDialog.setOnSingleSelectListener((IDialog dailog, int position) -> {
|
||||
selectedDeviceId = infoList.get(position).getDeviceId();
|
||||
ExtraParams params = new ExtraParams();
|
||||
String[] devTypes = new String[]{ExtraParams.DEVICETYPE_SMART_PAD, ExtraParams.DEVICETYPE_SMART_PHONE};
|
||||
params.setDevType(devTypes);
|
||||
params.setTargetBundleName(REMOTE_BUNDLE);
|
||||
String jsonParams = "{\"filter\":{\"commonFilter\":{\"groupType\":\"1|256\"}}," +
|
||||
"\"isTurnOffRecommend\":true,\"transferScene\":0}";
|
||||
params.setJsonParams(jsonParams);
|
||||
continuationRegisterManager.showDeviceList(abilityToken, params, null);
|
||||
}
|
||||
|
||||
private IContinuationDeviceCallback callback = new IContinuationDeviceCallback() {
|
||||
@Override
|
||||
public void onDeviceConnectDone(String s, String s1) {
|
||||
selectedDeviceId = s;
|
||||
try {
|
||||
HiLog.info(LABEL_LOG, "initDistributedEnvironmentClick begin ");
|
||||
DeviceManager.initDistributedEnvironment(selectedDeviceId, iInitCallback);
|
||||
dailog.destroy();
|
||||
} catch (RemoteException e) {
|
||||
HiLog.info(LABEL_LOG, "RemoteException happen");
|
||||
}
|
||||
});
|
||||
listDialog.show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeviceDisconnectDone(String s) {
|
||||
try {
|
||||
DeviceManager.unInitDistributedEnvironment(selectedDeviceId, iInitCallback);
|
||||
} catch (RemoteException | IllegalArgumentException e) {
|
||||
HiLog.info(LABEL_LOG, e.getMessage());
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private RequestCallback requestCallback = new RequestCallback() {
|
||||
@Override
|
||||
public void onResult(int result) {
|
||||
abilityToken = result;
|
||||
}
|
||||
};
|
||||
|
||||
private IInitCallback iInitCallback = new IInitCallback() {
|
||||
@Override
|
||||
@ -284,5 +308,7 @@ public class MainAbilitySlice extends AbilitySlice implements IAbilityContinuati
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
remoteAgentProxy = null;
|
||||
continuationRegisterManager.unregister(abilityToken, null);
|
||||
continuationRegisterManager.disconnect();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user