Merged PR 9967: Update sdksample for RC 0.13
Updating sdksample for the API changes in RC from https://microsoft.visualstudio.com/DefaultCollection/OS/_packaging?feed=CDP-Nightly&_a=package&package=com.microsoft.connecteddevices%3Aconnecteddevices-sdk&version=0.13.0-rc.4&protocolType=maven
This commit is contained in:
Родитель
0de3489793
Коммит
7e218617e3
|
@ -11,6 +11,7 @@ import com.microsoft.connecteddevices.base.EventListener;
|
||||||
import com.microsoft.connecteddevices.commanding.AppServiceConnection;
|
import com.microsoft.connecteddevices.commanding.AppServiceConnection;
|
||||||
import com.microsoft.connecteddevices.commanding.AppServiceRequestReceivedEventArgs;
|
import com.microsoft.connecteddevices.commanding.AppServiceRequestReceivedEventArgs;
|
||||||
import com.microsoft.connecteddevices.discovery.AppServiceDescription;
|
import com.microsoft.connecteddevices.discovery.AppServiceDescription;
|
||||||
|
import com.microsoft.connecteddevices.hosting.AppServiceConnectionOpenedEventArgs;
|
||||||
import com.microsoft.connecteddevices.hosting.AppServiceProvider;
|
import com.microsoft.connecteddevices.hosting.AppServiceProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -40,7 +41,8 @@ public abstract class BaseService implements AppServiceProvider, EventListener<A
|
||||||
* Receive incoming connections and listen for subsequent requests.
|
* Receive incoming connections and listen for subsequent requests.
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onConnectionOpened(final @NonNull AppServiceConnection connection) {
|
public void onConnectionOpened(final @NonNull AppServiceConnectionOpenedEventArgs args) {
|
||||||
|
AppServiceConnection connection = args.getAppServiceConnection();
|
||||||
Log.i(TAG, "Opened incoming connection to app service " + connection.getAppServiceDescription().getPackageId() + "/" +
|
Log.i(TAG, "Opened incoming connection to app service " + connection.getAppServiceDescription().getPackageId() + "/" +
|
||||||
connection.getAppServiceDescription().getName());
|
connection.getAppServiceDescription().getName());
|
||||||
connection.addRequestReceivedListener(this);
|
connection.addRequestReceivedListener(this);
|
||||||
|
|
|
@ -129,6 +129,15 @@ public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
// Initialize the Rome platform
|
// Initialize the Rome platform
|
||||||
initializePlatform();
|
initializePlatform();
|
||||||
|
|
||||||
|
// Initialize the UserActivity Feed
|
||||||
|
// Execute in background thread to avoid a known sdk issue
|
||||||
|
new Thread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run () {
|
||||||
|
getUserActivityFragment().initializeUserActivityFeed();
|
||||||
|
}
|
||||||
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -168,9 +177,6 @@ public class MainActivity extends AppCompatActivity {
|
||||||
case SUCCEEDED:
|
case SUCCEEDED:
|
||||||
raiseToast("Completed Rome registration");
|
raiseToast("Completed Rome registration");
|
||||||
|
|
||||||
// When the CDP platform has finished registering, initialize the UserActivity Feed
|
|
||||||
getUserActivityFragment().initializeUserActivityFeed();
|
|
||||||
|
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
|
@ -18,8 +18,6 @@ import com.microsoft.connecteddevices.core.UserAccountProvider;
|
||||||
import com.microsoft.connecteddevices.hosting.AppServiceProvider;
|
import com.microsoft.connecteddevices.hosting.AppServiceProvider;
|
||||||
import com.microsoft.connecteddevices.hosting.LaunchUriProvider;
|
import com.microsoft.connecteddevices.hosting.LaunchUriProvider;
|
||||||
import com.microsoft.connecteddevices.hosting.RemoteSystemApplicationRegistrationBuilder;
|
import com.microsoft.connecteddevices.hosting.RemoteSystemApplicationRegistrationBuilder;
|
||||||
import com.microsoft.connecteddevices.userdata.SyncScope;
|
|
||||||
import com.microsoft.connecteddevices.userdata.UserDataFeed;
|
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
|
@ -22,10 +22,9 @@ import com.microsoft.connecteddevices.useractivities.UserActivity;
|
||||||
import com.microsoft.connecteddevices.useractivities.UserActivityChannel;
|
import com.microsoft.connecteddevices.useractivities.UserActivityChannel;
|
||||||
import com.microsoft.connecteddevices.useractivities.UserActivitySession;
|
import com.microsoft.connecteddevices.useractivities.UserActivitySession;
|
||||||
import com.microsoft.connecteddevices.useractivities.UserActivitySessionHistoryItem;
|
import com.microsoft.connecteddevices.useractivities.UserActivitySessionHistoryItem;
|
||||||
import com.microsoft.connecteddevices.userdata.SyncScope;
|
|
||||||
import com.microsoft.connecteddevices.userdata.UserDataFeed;
|
import com.microsoft.connecteddevices.userdata.UserDataFeed;
|
||||||
import com.microsoft.connecteddevices.userdata.UserDataSyncStatus;
|
import com.microsoft.connecteddevices.userdata.UserDataFeedSyncScope;
|
||||||
import com.microsoft.connecteddevices.usernotifications.UserNotificationChannel;
|
import com.microsoft.connecteddevices.userdata.UserDataFeedSyncStatus;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
@ -83,16 +82,48 @@ public class UserActivityFragment extends BaseFragment implements View.OnClickLi
|
||||||
private UserDataFeed mUserDataFeed;
|
private UserDataFeed mUserDataFeed;
|
||||||
private String mStatusText;
|
private String mStatusText;
|
||||||
|
|
||||||
@Nullable
|
private UserDataFeed getUserDataFeed(UserAccount account, UserDataFeedSyncScope[] scopes, EventListener<UserDataFeed, Void> listener) {
|
||||||
private UserActivityChannel getUserActivityChannel() {
|
UserDataFeed feed = UserDataFeed.getForAccount(account, PlatformBroker.getPlatform(), Secrets.APP_HOST_NAME);
|
||||||
mStatusText = getStringValue(R.string.status_activities_get_channel);
|
feed.addSyncStatusChangedListener(listener);
|
||||||
|
feed.addSyncScopes(scopes);
|
||||||
|
feed.startSync();
|
||||||
|
return feed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void initializeUserActivityFeed() {
|
||||||
|
mStatusText = getStringValue(R.string.status_activities_initialize);
|
||||||
Log.d(TAG, mStatusText);
|
Log.d(TAG, mStatusText);
|
||||||
|
|
||||||
UserActivityChannel channel = null;
|
|
||||||
try {
|
try {
|
||||||
|
UserAccount[] accounts = AccountProviderBroker.getSignInHelper().getUserAccounts();
|
||||||
|
if (accounts.length <= 0) {
|
||||||
|
mStatusText = getStringValue(R.string.status_activities_signin_required);
|
||||||
|
Log.e(TAG, mStatusText);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Step #1
|
// Step #1
|
||||||
// create a UserActivityChannel for the signed in account
|
// get the UserDataFeed for the signed in account
|
||||||
channel = new UserActivityChannel(mUserDataFeed);
|
UserDataFeedSyncScope[] scopes = { UserActivityChannel.getSyncScope() };
|
||||||
|
mUserDataFeed = getUserDataFeed(accounts[0], scopes, new EventListener<UserDataFeed, Void>() {
|
||||||
|
@Override
|
||||||
|
public void onEvent(UserDataFeed userDataFeed, Void aVoid) {
|
||||||
|
if (userDataFeed.getSyncStatus() == UserDataFeedSyncStatus.SYNCHRONIZED) {
|
||||||
|
mStatusText = getStringValue(R.string.status_activities_initialize_complete);
|
||||||
|
Log.e(TAG, mStatusText);
|
||||||
|
} else {
|
||||||
|
mStatusText = getStringValue(R.string.status_activities_initialize_failed);
|
||||||
|
Log.e(TAG, mStatusText);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
mStatusText = getStringValue(R.string.status_activities_get_channel);
|
||||||
|
Log.d(TAG, mStatusText);
|
||||||
|
|
||||||
|
// Step #2
|
||||||
|
// create a UserActivityChannel on the UserDataFeed
|
||||||
|
mActivityChannel = new UserActivityChannel(mUserDataFeed);
|
||||||
|
|
||||||
mStatusText = getStringValue(R.string.status_activities_get_channel_success);
|
mStatusText = getStringValue(R.string.status_activities_get_channel_success);
|
||||||
Log.d(TAG, mStatusText);
|
Log.d(TAG, mStatusText);
|
||||||
|
@ -101,34 +132,13 @@ public class UserActivityFragment extends BaseFragment implements View.OnClickLi
|
||||||
mStatusText = getStringValue(R.string.status_activities_get_channel_failed);
|
mStatusText = getStringValue(R.string.status_activities_get_channel_failed);
|
||||||
Log.e(TAG, mStatusText);
|
Log.e(TAG, mStatusText);
|
||||||
}
|
}
|
||||||
return channel;
|
|
||||||
}
|
|
||||||
|
|
||||||
private UserDataFeed getUserDataFeed(SyncScope[] scopes, EventListener<UserDataFeed, Void> listener) {
|
|
||||||
UserAccount[] accounts = AccountProviderBroker.getSignInHelper().getUserAccounts();
|
|
||||||
if (accounts.length <= 0) {
|
|
||||||
mStatusText = getStringValue(R.string.status_activities_signin_required);
|
|
||||||
Log.e(TAG, mStatusText);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
UserDataFeed feed = UserDataFeed.getForAccount(accounts[0], PlatformBroker.getPlatform(), Secrets.APP_HOST_NAME);
|
|
||||||
feed.addSyncStatusChangedListener(listener);
|
|
||||||
feed.addSyncScopes(scopes);
|
|
||||||
feed.startSync();
|
|
||||||
return feed;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String createActivityId() {
|
|
||||||
return UUID.randomUUID().toString();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private UserActivity createUserActivity(UserActivityChannel channel, String activityId) {
|
private UserActivity createUserActivity(UserActivityChannel channel, String activityId) {
|
||||||
UserActivity activity = null;
|
UserActivity activity = null;
|
||||||
AsyncOperation<UserActivity> activityOperation = channel.getOrCreateUserActivityAsync(activityId);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
AsyncOperation<UserActivity> activityOperation = channel.getOrCreateUserActivityAsync(activityId);
|
||||||
activity = activityOperation.get();
|
activity = activityOperation.get();
|
||||||
mStatusText = getStringValue(R.string.status_activities_create_activity_success);
|
mStatusText = getStringValue(R.string.status_activities_create_activity_success);
|
||||||
Log.d(TAG, mStatusText);
|
Log.d(TAG, mStatusText);
|
||||||
|
@ -140,30 +150,6 @@ public class UserActivityFragment extends BaseFragment implements View.OnClickLi
|
||||||
return activity;
|
return activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Initializes the UserActivityFeed.
|
|
||||||
*/
|
|
||||||
public void initializeUserActivityFeed() {
|
|
||||||
mStatusText = getStringValue(R.string.status_activities_initialize);
|
|
||||||
Log.d(TAG, mStatusText);
|
|
||||||
|
|
||||||
SyncScope[] scopes = { UserActivityChannel.getSyncScope(), UserNotificationChannel.getSyncScope() };
|
|
||||||
mUserDataFeed = getUserDataFeed(scopes, new EventListener<UserDataFeed, Void>() {
|
|
||||||
@Override
|
|
||||||
public void onEvent(UserDataFeed userDataFeed, Void aVoid) {
|
|
||||||
if (userDataFeed.getSyncStatus() == UserDataSyncStatus.SYNCHRONIZED) {
|
|
||||||
mStatusText = getStringValue(R.string.status_activities_initialize_complete);
|
|
||||||
Log.d(TAG, mStatusText);
|
|
||||||
} else {
|
|
||||||
mStatusText = getStringValue(R.string.status_activities_initialize_failed);
|
|
||||||
Log.e(TAG, mStatusText);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mActivityChannel = getUserActivityChannel();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
View rootView = inflater.inflate(R.layout.fragment_useractivity, container, false);
|
View rootView = inflater.inflate(R.layout.fragment_useractivity, container, false);
|
||||||
|
@ -184,8 +170,8 @@ public class UserActivityFragment extends BaseFragment implements View.OnClickLi
|
||||||
mReadButton = rootView.findViewById(R.id.activityReadButton);
|
mReadButton = rootView.findViewById(R.id.activityReadButton);
|
||||||
mReadButton.setOnClickListener(this);
|
mReadButton.setOnClickListener(this);
|
||||||
|
|
||||||
mHistoryItems = new ArrayList<>();
|
|
||||||
mListView = rootView.findViewById(R.id.activityListView);
|
mListView = rootView.findViewById(R.id.activityListView);
|
||||||
|
mHistoryItems = new ArrayList<>();
|
||||||
mListAdapter = new UserActivityListAdapter(getContext(), mHistoryItems);
|
mListAdapter = new UserActivityListAdapter(getContext(), mHistoryItems);
|
||||||
mListView.setAdapter(mListAdapter);
|
mListView.setAdapter(mListAdapter);
|
||||||
|
|
||||||
|
@ -196,18 +182,19 @@ public class UserActivityFragment extends BaseFragment implements View.OnClickLi
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
// New activity button clicked
|
// Create New activity button clicked
|
||||||
/*
|
// Clicking it will generate default values for the activity, create the activity and publish it.
|
||||||
Clicking the New button will generate default properties for the activity, create the activity,
|
|
||||||
and publish it.
|
|
||||||
*/
|
|
||||||
if (mNewButton.equals(v)) {
|
if (mNewButton.equals(v)) {
|
||||||
|
setStatus(R.string.status_activities_create_activity);
|
||||||
|
|
||||||
mActivity = null;
|
mActivity = null;
|
||||||
final String newId = createActivityId();
|
mActivitySession = null;
|
||||||
|
|
||||||
|
final String newActivityId = UUID.randomUUID().toString();
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
mActivityId.setText(newId);
|
mActivityId.setText(newActivityId);
|
||||||
mDisplayText.setText(R.string.default_activity_display_text);
|
mDisplayText.setText(R.string.default_activity_display_text);
|
||||||
mActivationUri.setText(R.string.default_activity_uri);
|
mActivationUri.setText(R.string.default_activity_uri);
|
||||||
mActivityIconUri.setText(R.string.default_activity_icon_uri);
|
mActivityIconUri.setText(R.string.default_activity_icon_uri);
|
||||||
|
@ -215,8 +202,6 @@ public class UserActivityFragment extends BaseFragment implements View.OnClickLi
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
setStatus(R.string.status_activities_create_activity);
|
|
||||||
|
|
||||||
// ActivityChannel has not been initialized
|
// ActivityChannel has not been initialized
|
||||||
if (mActivityChannel == null) {
|
if (mActivityChannel == null) {
|
||||||
setStatus(R.string.status_activities_channel_null);
|
setStatus(R.string.status_activities_channel_null);
|
||||||
|
@ -263,7 +248,7 @@ public class UserActivityFragment extends BaseFragment implements View.OnClickLi
|
||||||
|
|
||||||
setStatus(R.string.status_activities_session_start);
|
setStatus(R.string.status_activities_session_start);
|
||||||
} else {
|
} else {
|
||||||
mActivitySession.close();
|
mActivitySession.stop();
|
||||||
mActivitySession = null;
|
mActivitySession = null;
|
||||||
getActivity().runOnUiThread(new Runnable() {
|
getActivity().runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -82,7 +82,7 @@
|
||||||
<string name="status_activities_save_activity_failed">Failed to save UserActivity!</string>
|
<string name="status_activities_save_activity_failed">Failed to save UserActivity!</string>
|
||||||
<string name="status_activities_read_activity_success">Read UserActivity successfully</string>
|
<string name="status_activities_read_activity_success">Read UserActivity successfully</string>
|
||||||
<string name="status_activities_read_activity_failed">Failed to read UserActivity!</string>
|
<string name="status_activities_read_activity_failed">Failed to read UserActivity!</string>
|
||||||
<string name="status_activities_channel_null">ActivityChannel is null (is platform initialization complete?)</string>
|
<string name="status_activities_channel_null">UserActivityChannel is not available yet (is platform initialization complete?)</string>
|
||||||
<string name="status_activities_read_activity">Reading UserActivities…</string>
|
<string name="status_activities_read_activity">Reading UserActivities…</string>
|
||||||
<string name="status_activities_session_activity_required">Must create UserActivity before starting session!</string>
|
<string name="status_activities_session_activity_required">Must create UserActivity before starting session!</string>
|
||||||
<string name="status_activities_session_start">UserActivitySession started</string>
|
<string name="status_activities_session_start">UserActivitySession started</string>
|
||||||
|
|
Загрузка…
Ссылка в новой задаче