We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
MaterialsConsole
SamplesCaaS EngineScreen Sharing

Screen Sharing

Code Structure

Expand

Module

File

Description

CaaSEngineDemo

CaasKitHelper.java

Encapsulation class of the CaaS Engine APIs.

CaasKitApplication.java

Global application.

CaasKitDemoActivity.java

Global activity layout file.

Demo of Screen Sharing

CaasKitHelper.java

/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
 */
 
package com.huawei.caaskitdemo.caaskit;
 
import android.content.Context;
import android.util.Log;
 
import com.huawei.caas.caasservice.HwCaasHandler;
import com.huawei.caas.caasservice.HwCaasServiceCallBack;
import com.huawei.caas.caasservice.HwCaasServiceManager;
import com.huawei.caas.caasservice.HwCaasUtils;
import com.huawei.caas.caasservice.HwCallStateCallBack;
import com.huawei.caaskitdemo.CaasKitApplication;
 
/**
 * CaasKit Helper.
 *
 * @since 2019-10-21
 */
public class CaasKitHelper {
    private static final String TAG = "CaasKitHelper";
 
    private static final int VIEWHEIGHT = 248;
 
    private static final int VIEWWIDTH = 256;
 
    private static final int LOCATION_X = 102;
 
    private static final int LOCATION_Y = 140;
 
    private static CaasKitHelper sCaasKitHelper;
 
    private HwCaasServiceManager mHwCaasServiceManager;
 
    private HwCaasHandler mHwCaasHandler;
 
    private Context mContext;
 
    private boolean mIsSendShowFail;
 
    private boolean mIsCaasKitInit;
 
    private boolean mIsHasCaaSContacts = false;
 
    private HwCallStateCallBack mCallStateCallBack = new HwCallStateCallBack() {
        @Override
        public void notifyCallState(HwCaasUtils.CallState state) {
            Log.d(TAG, "callState: " + state);
        }
    };
 
    private HwCaasServiceCallBack mCallBack = new HwCaasServiceCallBack() {
        @Override
        public void initSuccess(HwCaasHandler handler) {
            // callback after successful initialization of HwCaasHandler.
            mHwCaasHandler = handler;
            if (mHwCaasHandler != null) {
                // Display the app name of the caller party. This is mandatory, otherwise, the MeeTime entry cannot be displayed.
                mHwCaasHandler.setCallerAppName("Application");
                // Select the style of the contacts view, which can be floating window or full screen style (similar to system Contacts screen).
                mHwCaasHandler.setContactViewStyle(HwCaasUtils.ContactsViewStyle.FULL_SCREEN);
 
                // Set the size and initial position of the floating window. If full screen style is selected, skip this step.
//                mHwCaasHandler.setContactViewStyle(HwCaasUtils.ContactsViewStyle.FLOAT_VIEW);
//                mHwCaasHandler.setContactViewSize(VIEWWIDTH, VIEWHEIGHT);
//                mHwCaasHandler.setFloatViewLocation(HwCaasUtils.STARTVIEW,
//                        HwCaasUtils.POINT_RIGHTANDDOWN, LOCATION_X, LOCATION_Y);
//                mHwCaasHandler.setFloatViewLocation(HwCaasUtils.CONTACTVIEW, HwCaasUtils.POINT_RIGHTANDDOWN, LOCATION_X, LOCATION_Y);
 
                // Listen to the call status, including dialing, calling, and not calling. Skip this step if not required.
                mHwCaasHandler.setCallStateCallBack(mCallStateCallBack);
                // Check whether there are contacts that meet the requirements. ContactsType.NORMAL_CONTACTS - Normal MeeTime contacts; ContactsType.SCREEN_SHARING_CONTACTS - Contacts supporting screen sharing.
                mIsHasCaaSContacts = mHwCaasHandler.hasCaaSContacts(HwCaasUtils.ContactsType.SCREEN_SHARING_CONTACTS);
                if (mIsSendShowFail) {
                    sendShow();
                    mIsSendShowFail = false;
                }
            }
        }
 
        @Override
        public void initFail(int retCode) {
            // callback if init Handler fail.
            Log.i(TAG, "retCode: " + retCode);
        }
 
        @Override
        public void releaseSuccess() {
            // callback after successful release of mHwCaasServiceManager.
            mHwCaasHandler = null;
            mIsSendShowFail = false;
        }
    };
 
    private CaasKitHelper() {
        mContext = CaasKitApplication.getContext();
    }
 
    public synchronized static CaasKitHelper getInstance() {
        if (sCaasKitHelper == null) {
            sCaasKitHelper = new CaasKitHelper();
        }
        return sCaasKitHelper;
    }
 
    public void caasKitInit() {
        Log.d(TAG, "caasKitInit.");
        if (!mIsCaasKitInit) {
            // Initialize the mHwCaasServiceManager instance.
            mHwCaasServiceManager = HwCaasServiceManager.init();
            // Initialize the HwCaasHandler instance through handlerType.
            mHwCaasServiceManager.initHandler(mContext, HwCaasUtils.SCREEN_SHARING_TYPE, mCallBack);
            mIsCaasKitInit = true;
        }
    }
 
    public void sendShow() {
        Log.d(TAG, "sendShow.");
        if (mHwCaasHandler != null) {
            Log.d(TAG, "isHasCaaSContacts: " + mIsHasCaaSContacts);
            if (mIsHasCaaSContacts) {
                // The user touches the entry, and the contact list is displayed.
                boolean ret = mHwCaasHandler.sendEventToCaasService(HwCaasUtils.SHOW_CONTACTS);
                // The app displays a floating ball. After the user touches the dock, the contact list is displayed.
//                boolean ret = mHwCaasHandler.sendEventToCaasService(HwCaasUtils.SHOW);
                Log.d(TAG, "ret: " + ret);
            }
        } else {
            mIsSendShowFail = true;
            Log.e(TAG, "sendShow fail.");
        }
    }
 
    public boolean sendHide() {
        Log.d(TAG, "sendHide.");
        if (mHwCaasHandler != null) {
            // Use the method for hiding contact list together with HwCaasUtils.SHOW_CONTACTS.
            boolean ret = mHwCaasHandler.sendEventToCaasService(HwCaasUtils.HIDE_CONTACTS);
            // Use the method for hiding floating dock with HwCaasUtils.SHOW.
//            boolean isSendoK = mHwCaasHandler.sendEventToCaasService(HwCaasUtils.HIDE);
            Log.d(TAG, "ret: " + ret);
            return ret;
        }
        Log.e(TAG, "sendHide fail.");
        return false;
    }
 
    public void pauseShare() {
        Log.d(TAG, "pauseShare.");
        if (mHwCaasHandler != null) {
            boolean isSendoK = mHwCaasHandler.sendEventToCaasService(HwCaasUtils.SCREEN_SHARING_PAUSE);
            Log.d(TAG, "isSendoK: " + isSendoK);
        }
    }
 
    public void resumeShare() {
        Log.d(TAG, "resumeShare.");
        if (mHwCaasHandler != null) {
            boolean isSendoK = mHwCaasHandler.sendEventToCaasService(HwCaasUtils.SCREEN_SHARING_RESUME);
            Log.d(TAG, "isSendoK: " + isSendoK);
        }
    }
 
    public void caasKitRelease() {
        Log.d(TAG, "caasKitRelease.");
        if (mIsCaasKitInit) {
            if (mHwCaasServiceManager != null) {
                // Release resources.
                mHwCaasServiceManager.release();
                mHwCaasServiceManager = null;
            }
            mIsCaasKitInit = false;
        }
    }
}

CaasKitApplication.java

/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
 */
 
package com.huawei.caaskitdemo;
 
import android.app.Application;
import android.content.Context;
import android.util.Log;
 
/**
 * Main application.
 *
 * @since 2019-10-21
 */
public class CaasKitApplication extends Application {
    private static final String TAG = "CaasKitApplication";
 
    private static CaasKitApplication sApplication;
 
    @Override
    public void onCreate() {
        Log.i(TAG, "onCreate.");
        super.onCreate();
        setApp(this);
    }
 
    public static CaasKitApplication getInstance() {
        return sApplication;
    }
 
    public static Context getContext() {
        return sApplication.getApplicationContext();
    }
 
    private static synchronized void setApp(CaasKitApplication app) {
        sApplication = app;
    }
}

CaasKitDemoActivity.java

/*
 * Copyright (c) Huawei Technologies Co., Ltd. 2020-2020. All rights reserved.
 */
 
package com.huawei.caaskitdemo;
 
import android.content.Context;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
 
import com.huawei.caaskitdemo.caaskit.CaasKitHelper;
 
public class CaasKitDemoActivity extends AppCompatActivity {
    private static final String TAG = "CaaSKitDemoActivity";
 
    private Button mCallShow;
 
    private Button mCallHide;
 
    private Button mSharePause;
 
    private Button mShareResume;
 
    private TextView mPasswordView;
 
    private ImageView mBackgroundView;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.activity_caaskitdemo);
        CaasKitHelper.getInstance().caasKitInit();
        mCallShow = findViewById(R.id.call_show);
        mCallHide = findViewById(R.id.call_hide);
        mCallShow.setOnClickListener(v ->{
            CaasKitHelper.getInstance().sendShow();
        });
        mCallHide.setOnClickListener(v ->{
            CaasKitHelper.getInstance().sendHide();
        });
        mSharePause = findViewById(R.id.share_pause);
        mShareResume = findViewById(R.id.share_resume);
        mSharePause.setOnClickListener(v ->{
            CaasKitHelper.getInstance().pauseShare();
        });
        mShareResume.setOnClickListener(v ->{
            CaasKitHelper.getInstance().resumeShare();
        });
        mPasswordView = findViewById(R.id.paasword_view);
        mPasswordView.setOnFocusChangeListener(new android.view.View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                Log.d(TAG, "onFocusChange:" + hasFocus);
                if (hasFocus) {
                    CaasKitHelper.getInstance().pauseShare();
                } else {
                    InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
                    CaasKitHelper.getInstance().resumeShare();
                }
            }
        });
        mBackgroundView = findViewById(R.id.back_ground);
        mBackgroundView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View var1, MotionEvent var2) {
                if (mPasswordView != null) {
                    mPasswordView.clearFocus();
                }
                return true;
            }
        });
    }
 
    @Override
    protected void onPause() {
        Log.d(TAG, "onPause.");
        CaasKitHelper.getInstance().pauseShare();
        super.onPause();
    }
 
    @Override
    protected void onStop() {
        super.onStop();
        Log.d(TAG, "onStop.");
    }
 
    @Override
    protected void onResume() {
        super.onResume();
        Log.d(TAG, "onResume.");
        CaasKitHelper.getInstance().resumeShare();
    }
 
    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d(TAG, "onDestroy.");
        CaasKitHelper.getInstance().caasKitRelease();
    }
}
Search
Enter a keyword.