Skip to content

Commit

Permalink
[SSDK-1731]Kitchen Sink for Screen Sharing [Android]
Browse files Browse the repository at this point in the history
  • Loading branch information
DengQiming committed Mar 13, 2018
1 parent 2e9e8cb commit bd1dc96
Show file tree
Hide file tree
Showing 6 changed files with 169 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.REORDER_TASKS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.GET_TASKS" />

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

package com.cisco.sparksdk.kitchensink.actions;

import com.cisco.sparksdk.kitchensink.actions.events.OnCallMembershipEvent;
import com.cisco.sparksdk.kitchensink.actions.events.OnConnectEvent;
import com.cisco.sparksdk.kitchensink.actions.events.OnDisconnectEvent;
import com.cisco.sparksdk.kitchensink.actions.events.OnMediaChangeEvent;
Expand Down Expand Up @@ -60,7 +61,7 @@ public void onMediaChanged(MediaChangedEvent mediaChangedEvent) {

@Override
public void onCallMembershipChanged(CallMembershipChangedEvent event) {

postEvent(new OnCallMembershipEvent(event));
}

private void postEvent(Object event) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.cisco.sparksdk.kitchensink.actions.events;

import com.ciscospark.androidsdk.phone.CallObserver;

/**
* Created by qimdeng on 3/13/18.
*/

public class OnCallMembershipEvent {
public CallObserver.CallMembershipChangedEvent callEvent;

public OnCallMembershipEvent(CallObserver.CallMembershipChangedEvent event) {
this.callEvent = event;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,34 @@
package com.cisco.sparksdk.kitchensink.launcher;

import android.app.Activity;
import android.app.ActivityManager;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Switch;
import android.widget.Toast;

import com.cisco.sparksdk.kitchensink.R;
import com.cisco.sparksdk.kitchensink.actions.commands.RequirePermissionAction;
import com.cisco.sparksdk.kitchensink.actions.events.OnCallMembershipEvent;
import com.cisco.sparksdk.kitchensink.actions.events.OnMediaChangeEvent;
import com.cisco.sparksdk.kitchensink.launcher.fragments.LauncherFragment;
import com.cisco.sparksdk.kitchensink.ui.BaseFragment;
import com.ciscospark.androidsdk.phone.CallObserver;
import com.github.benoitdion.ln.Ln;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import java.util.List;

public class LauncherActivity extends Activity {

Expand All @@ -42,6 +61,13 @@ protected void onCreate(Bundle savedInstanceState) {
setContentView(R.layout.activity_launcher);
BaseFragment fragment = new LauncherFragment();
replace(fragment);
EventBus.getDefault().register(this);
}

@Override
public void onDestroy() {
super.onDestroy();
EventBus.getDefault().unregister(this);
}

@Override
Expand Down Expand Up @@ -75,4 +101,50 @@ public Fragment getFragment() {
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
RequirePermissionAction.PermissionsRequired(requestCode, grantResults);
}

@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(OnMediaChangeEvent event) {
if (event.callEvent instanceof CallObserver.SendingSharingEvent) {
Ln.d("Activity SendingSharingEvent: " + ((CallObserver.SendingSharingEvent)event.callEvent).isSending());
if (!((CallObserver.SendingSharingEvent)event.callEvent).isSending()){
cancelNotication();
moveToFront();
updateSharingSwitch(false);
Toast.makeText(this, "Stop to share content", Toast.LENGTH_SHORT).show();
}
}
}

@SuppressWarnings("unused")
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(OnCallMembershipEvent event) {
if (event.callEvent instanceof CallObserver.MembershipSendingSharingEvent) {
Ln.d("Activity CallMembership email: " + event.callEvent.getCallMembership().getEmail() +
" isSendingSharing: " + event.callEvent.getCallMembership().isSendingSharing());
}
}

protected void moveToFront() {
final ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
final List<ActivityManager.RunningTaskInfo> recentTasks = activityManager.getRunningTasks(Integer.MAX_VALUE);

for (int i = 0; i < recentTasks.size(); i++) {
// bring to front
if (recentTasks.get(i).baseActivity.toShortString().indexOf("com.cisco.sparksdk.kitchensink") > -1) {
activityManager.moveTaskToFront(recentTasks.get(i).id, ActivityManager.MOVE_TASK_WITH_HOME);
}
}
}

private void cancelNotication(){
NotificationManager notifyManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
notifyManager.cancel(1);
}

private void updateSharingSwitch(boolean flag){
Switch shareSwitch = (Switch) findViewById(R.id.switchShareContent);
if (shareSwitch != null && shareSwitch.isChecked())
shareSwitch.setChecked(flag);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,15 @@
package com.cisco.sparksdk.kitchensink.launcher.fragments;


import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.constraint.ConstraintLayout;
import android.support.v4.app.NotificationCompat;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
Expand All @@ -49,6 +55,8 @@
import com.cisco.sparksdk.kitchensink.launcher.LauncherActivity;
import com.cisco.sparksdk.kitchensink.ui.BaseFragment;
import com.cisco.sparksdk.kitchensink.ui.FullScreenSwitcher;
import com.ciscospark.androidsdk.phone.CallObserver;
import com.github.benoitdion.ln.Ln;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
Expand All @@ -58,11 +66,12 @@
import butterknife.OnClick;

import static com.ciscospark.androidsdk.phone.CallObserver.RemoteSendingSharingEvent;

import static com.ciscospark.androidsdk.phone.CallObserver.SendingSharingEvent;
/**
* A simple {@link BaseFragment} subclass.
*/
public class CallFragment extends BaseFragment {
protected static final int MEDIA_PROJECTION_REQUEST = 2;
private static final String CALLEE = "callee";
private static final String INCOMING_CALL = "incoming";
private SparkAgent agent;
Expand Down Expand Up @@ -108,6 +117,9 @@ public class CallFragment extends BaseFragment {
@BindView(R.id.call_layout)
ConstraintLayout layout;

@BindView(R.id.switchShareContent)
Switch switchShareContent;

// Required empty public constructor
public CallFragment() {
}
Expand Down Expand Up @@ -206,7 +218,7 @@ public void onRemoteViewClicked() {
}

@OnCheckedChanged({R.id.switchSendVideo, R.id.switchSendAudio,
R.id.switchReceiveVideo, R.id.switchReceiveAudio})
R.id.switchReceiveVideo, R.id.switchReceiveAudio, R.id.switchShareContent})
public void onSwitchCallAbility(Switch s) {
switch (s.getId()) {
case R.id.switchSendVideo:
Expand All @@ -220,13 +232,19 @@ public void onSwitchCallAbility(Switch s) {
break;
case R.id.switchSendAudio:
agent.sendAudio(s.isChecked());
break;
case R.id.switchReceiveVideo:
agent.receiveVideo(s.isChecked());
break;
case R.id.switchReceiveAudio:
agent.receiveAudio(s.isChecked());
break;
case R.id.switchShareContent:
if (s.isChecked())
agent.getActiveCall().startSharing(r -> {Ln.d("startSharing result: " + r);});
else
agent.getActiveCall().stopSharing(r -> {Ln.d("stopSharing result: " + r);});
break;

}
}

Expand Down Expand Up @@ -327,7 +345,14 @@ public void onEventMainThread(OnDisconnectEvent event) {
@Subscribe(threadMode = ThreadMode.MAIN)
public void onEventMainThread(OnMediaChangeEvent event) {
if (event.callEvent instanceof RemoteSendingSharingEvent) {
Ln.d("RemoteSendingSharingEvent: " + ((RemoteSendingSharingEvent)event.callEvent).isSending());
updateScreenShareView();
} else if (event.callEvent instanceof SendingSharingEvent) {
Ln.d("SendingSharingEvent: " + ((SendingSharingEvent)event.callEvent).isSending());
if (((SendingSharingEvent)event.callEvent).isSending()){
sendNotification();
backToHome();
}
}
}

Expand All @@ -336,4 +361,26 @@ public void onEventMainThread(OnMediaChangeEvent event) {
public void onEventMainThread(PermissionAcquiredEvent event) {
makeCall();
}

private void backToHome() {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
this.startActivity(intent);
}

private void sendNotification(){
Intent appIntent = new Intent(getActivity(), LauncherActivity.class);
appIntent.setAction(Intent.ACTION_MAIN);
appIntent.addCategory(Intent.CATEGORY_LAUNCHER);
appIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
PendingIntent contentIntent = PendingIntent.getActivity(getActivity(), 0,appIntent,PendingIntent.FLAG_UPDATE_CURRENT);

NotificationManager notifyManager = (NotificationManager) getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder builder = new NotificationCompat.Builder(getActivity())
.setSmallIcon(R.mipmap.ic_launcher)
.setContentTitle("Cisco Kichensink")
.setContentText("I'm sharing content")
.setContentIntent(contentIntent);
notifyManager.notify(1, builder.build());
}
}
30 changes: 29 additions & 1 deletion app/src/main/res/layout/fragment_call.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/switchLoudSpeaker"
app:layout_constraintTop_toBottomOf="@+id/textReceiveAudio" />
app:layout_constraintTop_toBottomOf="@+id/TextShareContent" />

<Switch
android:id="@+id/switchSendAudio"
Expand Down Expand Up @@ -284,6 +284,34 @@
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/switchReceiveVideo"
app:layout_constraintTop_toBottomOf="@+id/textSendAudio" />


<TextView
android:id="@+id/TextShareContent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:text="Sharing Content"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/switchLoudSpeaker"
app:layout_constraintTop_toBottomOf="@+id/textReceiveAudio" />

<Switch
android:id="@+id/switchShareContent"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginRight="16dp"
android:checked="false"
app:layout_constraintBottom_toBottomOf="@+id/TextShareContent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@+id/TextShareContent"
tools:checked="false" />
</android.support.constraint.ConstraintLayout>
</ScrollView>

Expand Down

0 comments on commit bd1dc96

Please sign in to comment.