Search in sources :

Example 1 with TextImageView

use of net.iGap.module.customView.TextImageView in project iGap-Android by KianIranian-STDG.

the class CallActivity method createRootView.

private View createRootView() {
    if (CallService.getInstance() == null)
        finish();
    FrameLayout rootView = new FrameLayout(this);
    rootView.setBackgroundColor(0);
    rootView.setFitsSystemWindows(true);
    rootView.setClipToPadding(false);
    if (isVideoCall()) {
        surfaceRemote = new SurfaceViewRenderer(this);
        surfaceRemote.setVisibility(isIncomingCallAndAnswered ? View.VISIBLE : View.GONE);
        surfaceRemote.setOnClickListener(v -> hideIcons());
        rootView.addView(surfaceRemote, LayoutCreator.createFrame(LayoutCreator.MATCH_PARENT, LayoutCreator.MATCH_PARENT, Gravity.CENTER));
        surfaceLocal = new SurfaceViewRenderer(this);
        surfaceLocal.setVisibility(View.VISIBLE);
        rootView.addView(surfaceLocal, LayoutCreator.createFrame(100, 140, Gravity.TOP | (isRtl ? Gravity.LEFT : Gravity.RIGHT), 8, 8, 8, 8));
        try {
            surfaceLocal.init(WebRTC.getInstance().getEglBaseContext(), null);
        } catch (Exception e) {
            // for android version 4 on huawei device
            e.printStackTrace();
            HelperLog.getInstance().setErrorLog(e);
            Toast.makeText(this, getResources().getString(R.string.not_success), Toast.LENGTH_SHORT).show();
            CallManager.getInstance().endCall();
        }
        surfaceLocal.setEnableHardwareScaler(true);
        surfaceLocal.setMirror(isFrontCamera);
        surfaceLocal.setZOrderMediaOverlay(true);
        surfaceLocal.setZOrderOnTop(true);
        try {
            surfaceRemote.init(WebRTC.getInstance().getEglBaseContext(), null);
        } catch (Exception e) {
            // for android version 4 on huawei device
            e.printStackTrace();
            HelperLog.getInstance().setErrorLog(e);
            Toast.makeText(this, getResources().getString(R.string.not_success), Toast.LENGTH_SHORT).show();
            CallManager.getInstance().endCall();
        }
        surfaceRemote.setEnableHardwareScaler(true);
        surfaceRemote.setMirror(false);
        WebRTC.getInstance().setFrameListener(new WebRTC.VideoFrameListener() {

            @Override
            public void onLocalFrame(VideoFrame frame) {
                if (surfaceLocal != null)
                    surfaceLocal.onFrame(frame);
            }

            @Override
            public void onRemoteFrame(VideoFrame frame) {
                if (surfaceRemote != null)
                    surfaceRemote.onFrame(frame);
            }
        });
    }
    userImageView = new AppCompatImageView(this) {

        private Drawable topGradient = getResources().getDrawable(R.drawable.gradient_top);

        private Drawable bottomGradient = getResources().getDrawable(R.drawable.gradient_bottom);

        private Paint paint = new Paint();

        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);
            paint.setColor(0x4C000000);
            canvas.drawRect(0, 0, getWidth(), getHeight(), paint);
            topGradient.setBounds(0, 0, getWidth(), LayoutCreator.dp(170));
            topGradient.setAlpha(130);
            topGradient.draw(canvas);
            bottomGradient.setBounds(0, getHeight() - LayoutCreator.dp(220), getWidth(), getHeight());
            bottomGradient.setAlpha(180);
            bottomGradient.draw(canvas);
        }
    };
    userImageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
    if (isVideoCall())
        userImageView.setVisibility(isIncomingCallAndAnswered ? View.GONE : View.VISIBLE);
    rootView.addView(userImageView, LayoutCreator.createFrame(LayoutCreator.MATCH_PARENT, LayoutCreator.MATCH_PARENT));
    callTypeTextView = new TextView(this);
    callTypeTextView.setText(isVideoCall() ? R.string.video_calls : R.string.voice_calls);
    callTypeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
    callTypeTextView.setTextColor(getResources().getColor(R.color.white));
    callTypeTextView.setTypeface(ResourcesCompat.getFont(this, R.font.main_font));
    callTypeTextView.setLines(1);
    callTypeTextView.setMaxLines(1);
    callTypeTextView.setSingleLine(true);
    callTypeTextView.setEllipsize(TextUtils.TruncateAt.END);
    callTypeTextView.setGravity(isRtl ? Gravity.RIGHT : Gravity.LEFT);
    rootView.addView(callTypeTextView, LayoutCreator.createFrame(LayoutCreator.MATCH_PARENT, LayoutCreator.WRAP_CONTENT, Gravity.TOP, 16, 24, 16, 0));
    statusTextView = new AppCompatTextView(this);
    statusTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    statusTextView.setTextColor(getResources().getColor(R.color.white));
    statusTextView.setTypeface(ResourcesCompat.getFont(this, R.font.main_font_bold));
    statusTextView.setLines(1);
    statusTextView.setMaxLines(1);
    statusTextView.setSingleLine(true);
    statusTextView.setEllipsize(TextUtils.TruncateAt.END);
    statusTextView.setGravity(isRtl ? Gravity.RIGHT : Gravity.LEFT);
    if (isIncoming && CallManager.getInstance().getCurrentSate() == CallState.CONNECTED) {
        statusTextView.setText(R.string.connected);
    } else if (isIncoming) {
        statusTextView.setText(R.string.incoming_call);
    } else {
        statusTextView.setText(R.string.connecting);
    }
    rootView.addView(statusTextView, LayoutCreator.createFrame(LayoutCreator.MATCH_PARENT, LayoutCreator.WRAP_CONTENT, Gravity.TOP, 16, 46, 16, 0));
    durationTextView = new AppCompatTextView(this);
    durationTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    durationTextView.setTextColor(getResources().getColor(R.color.white));
    durationTextView.setTypeface(ResourcesCompat.getFont(this, R.font.main_font));
    durationTextView.setLines(1);
    durationTextView.setMaxLines(1);
    durationTextView.setSingleLine(true);
    durationTextView.setEllipsize(TextUtils.TruncateAt.END);
    durationTextView.setGravity(isRtl ? Gravity.RIGHT : Gravity.LEFT);
    rootView.addView(durationTextView, LayoutCreator.createFrame(LayoutCreator.MATCH_PARENT, LayoutCreator.WRAP_CONTENT, Gravity.TOP, 16, 72, 16, 0));
    nameTextView = new TextView(this);
    nameTextView.setTextColor(getResources().getColor(R.color.white));
    nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 40);
    nameTextView.setTypeface(ResourcesCompat.getFont(this, R.font.main_font));
    nameTextView.setLines(1);
    nameTextView.setMaxLines(1);
    nameTextView.setSingleLine(true);
    nameTextView.setEllipsize(TextUtils.TruncateAt.END);
    nameTextView.setGravity(Gravity.CENTER);
    rootView.addView(nameTextView, LayoutCreator.createFrame(LayoutCreator.MATCH_PARENT, LayoutCreator.WRAP_CONTENT, Gravity.TOP, 16, isVideoCall() ? 172 : 92, 16, 0));
    if (isIncoming && isIncomingCallAndNotAnswered) {
        answerRippleView = new CallRippleView(this);
        answerRippleView.setImageResource(R.drawable.ic_call_answer);
        answerRippleView.startAnimation();
        answerRippleView.setDelegate(this::answerCall);
        answerRippleView.setOnClickListener(v -> answerCall());
        rootView.addView(answerRippleView, LayoutCreator.createFrame(150, 150, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 36));
        declineRippleView = new CallRippleView(this);
        declineRippleView.setImageResource(R.drawable.ic_call_decline);
        declineRippleView.startAnimation();
        declineRippleView.setDelegate(this::declineCall);
        declineRippleView.setOnClickListener(v -> {
            declineCall();
        });
        rootView.addView(declineRippleView, LayoutCreator.createFrame(150, 150, Gravity.BOTTOM | Gravity.RIGHT, 0, 0, 0, 36));
        quickDeclineView = new LinearLayout(this);
        quickDeclineView.setOrientation(LinearLayout.VERTICAL);
        quickDeclineView.setOnClickListener(v -> onQuickDeclineClick());
        View view = new View(this);
        view.setBackground(getResources().getDrawable(R.drawable.shape_call_decline));
        view.setAlpha(0.3f);
        quickDeclineView.addView(view, LayoutCreator.createLinear(100, 3, Gravity.CENTER));
        TextView declineText = new AppCompatTextView(this);
        declineText.setText(R.string.send_text);
        declineText.setTextColor(Theme.getInstance().getDividerColor(this));
        declineText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
        quickDeclineView.addView(declineText, LayoutCreator.createLinear(LayoutCreator.WRAP_CONTENT, LayoutCreator.WRAP_CONTENT, Gravity.CENTER, 0, 1, 0, 8));
        rootView.addView(quickDeclineView, LayoutCreator.createFrame(LayoutCreator.MATCH_PARENT, LayoutCreator.WRAP_CONTENT, Gravity.BOTTOM));
    } else {
        ImageView cancelImageView = new AppCompatImageView(this);
        cancelImageView.setImageResource(R.drawable.ic_call_cancel);
        cancelImageView.setVisibility(View.GONE);
        cancelImageView.setOnClickListener(v -> finish());
        // rootView.addView(cancelImageView, LayoutCreator.createFrame(64, 64, Gravity.BOTTOM, 62, 0, 0, 62));
        ImageView callAgainImageView = new AppCompatImageView(this);
        callAgainImageView.setImageResource(R.drawable.ic_call_answer);
        callAgainImageView.setVisibility(View.GONE);
        callAgainImageView.setOnClickListener(v -> {
            CallManager.getInstance().startCall(caller.getUserId(), callType);
        });
    // rootView.addView(callAgainImageView, LayoutCreator.createFrame(64, 64, Gravity.BOTTOM | Gravity.RIGHT, 0, 0, 62, 62));
    }
    buttonsGridView = new LinearLayout(this);
    buttonsGridView.setOrientation(LinearLayout.VERTICAL);
    if (isIncoming && isIncomingCallAndNotAnswered)
        hideButtonsGridView();
    else if (CallManager.getInstance().isWaitForEndCall())
        fadeButtonsGridView();
    else
        showButtonsGridView();
    LinearLayout row1 = new LinearLayout(this);
    row1.setOrientation(LinearLayout.HORIZONTAL);
    buttonsGridView.addView(row1, LayoutCreator.createFrame(LayoutCreator.MATCH_PARENT, LayoutCreator.WRAP_CONTENT, Gravity.CENTER, 0, 16, 0, 0));
    if (isVideoCall()) {
        cameraView = new TextImageView(this);
        cameraView.setText(R.string.camera);
        cameraView.setTextColor(getResources().getColor(R.color.white));
        cameraView.setOnClickListener(v -> toggleCamera());
        cameraView.setImageResource(R.drawable.ic_call_camera);
        row1.addView(cameraView, LayoutCreator.createLinear(52, LayoutCreator.WRAP_CONTENT, 1f));
    }
    holdView = new TextImageView(this);
    holdView.setText(R.string.hold);
    holdView.setViewColor(CallManager.getInstance().isCallInHold() ? Theme.getInstance().getPrimaryDarkColor(this) : getResources().getColor(R.color.white));
    holdView.setOnClickListener(v -> holdCall());
    holdView.setImageResource(R.drawable.ic_call_hold);
    holdView.setViewColor(CallManager.getInstance().isCallAlive() ? CallManager.getInstance().isCallInHold() ? Theme.getInstance().getPrimaryDarkColor(this) : getResources().getColor(R.color.white) : getResources().getColor(R.color.gray_9d));
    row1.addView(holdView, LayoutCreator.createLinear(52, LayoutCreator.WRAP_CONTENT, 1f));
    if (CallManager.getInstance().isCallAlive()) {
        if (CallManager.getInstance().isCallInHold()) {
            holdView.setViewColor(Theme.getInstance().getPrimaryDarkColor(this));
        } else {
            holdView.setViewColor(getResources().getColor(R.color.white));
        }
    } else {
        holdView.setViewColor(getResources().getColor(R.color.gray_4c));
    }
    directView = new TextImageView(this);
    directView.setText(R.string.message);
    directView.setTextColor(getResources().getColor(R.color.white));
    directView.setOnClickListener(v -> toggleCamera());
    directView.setImageResource(R.drawable.ic_call_chat);
    directView.setOnClickListener(v -> goToChat());
    row1.addView(directView, LayoutCreator.createLinear(52, LayoutCreator.WRAP_CONTENT, 1f));
    LinearLayout row2 = new LinearLayout(this);
    row2.setOrientation(LinearLayout.HORIZONTAL);
    buttonsGridView.addView(row2, LayoutCreator.createFrame(LayoutCreator.MATCH_PARENT, LayoutCreator.WRAP_CONTENT, Gravity.CENTER, 0, 16, 0, 0));
    micView = new TextImageView(this);
    micView.setImageResource(R.drawable.ic_call_mic);
    micView.setText(R.string.mic);
    if (!CallManager.getInstance().isMicEnable()) {
        toggleMic();
    }
    micView.setViewColor(CallManager.getInstance().isMicEnable() ? getResources().getColor(R.color.white) : Theme.getInstance().getPrimaryDarkColor(this));
    micView.setOnClickListener(v -> toggleMic());
    row2.addView(micView, LayoutCreator.createLinear(52, LayoutCreator.WRAP_CONTENT, 1f));
    speakerView = new TextImageView(this);
    speakerView.setImageResource(R.drawable.ic_call_speaker);
    speakerView.setText(R.string.speacker);
    speakerView.setViewColor(isSpeakerEnable() ? Theme.getInstance().getPrimaryDarkColor(this) : getResources().getColor(R.color.white));
    speakerView.setOnClickListener(v -> toggleSpeaker());
    row2.addView(speakerView, LayoutCreator.createLinear(52, LayoutCreator.WRAP_CONTENT, 1f));
    bluetoothView = new TextImageView(this);
    bluetoothView.setImageResource(R.drawable.ic_call_bluetooth);
    bluetoothView.setText(R.string.bluetooth);
    bluetoothView.setViewColor(CallManager.getInstance().getActiveAudioDevice() == CallAudioManager.AudioDevice.BLUETOOTH ? Theme.getInstance().getPrimaryDarkColor(this) : getResources().getColor(R.color.white));
    bluetoothView.setOnClickListener(v -> bluetoothClick());
    row2.addView(bluetoothView, LayoutCreator.createLinear(52, LayoutCreator.WRAP_CONTENT, 1f));
    declineImageView = new AppCompatImageView(this);
    declineImageView.setImageResource(R.drawable.ic_call_decline);
    declineImageView.setOnClickListener(v -> {
        endCall();
    });
    buttonsGridView.addView(declineImageView, LayoutCreator.createLinear(64, 64, Gravity.CENTER, 0, 48, 0, 0));
    rootView.addView(buttonsGridView, LayoutCreator.createFrame(LayoutCreator.MATCH_PARENT, LayoutCreator.WRAP_CONTENT, Gravity.BOTTOM, 32, 0, 32, 62));
    if (caller != null) {
        nameTextView.setText(caller.getName());
        try {
            avatarHandler.getAvatar(new ParamWithInitBitmap(userImageView, caller.getUserId()).initBitmap(null).showMain().onInitSet(() -> {
                if (caller.color != null && caller.color.length() > 0)
                    userImageView.setBackgroundColor(Color.parseColor(caller.color));
            }));
        } catch (Exception e) {
            // must be refactor avatar handler
            e.printStackTrace();
        }
    }
    return rootView;
}
Also used : CallRippleView(net.iGap.module.customView.CallRippleView) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) AppCompatTextView(androidx.appcompat.widget.AppCompatTextView) Paint(android.graphics.Paint) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) AppCompatTextView(androidx.appcompat.widget.AppCompatTextView) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) ImageView(android.widget.ImageView) View(android.view.View) CallRippleView(net.iGap.module.customView.CallRippleView) TextImageView(net.iGap.module.customView.TextImageView) TextView(android.widget.TextView) VideoFrame(org.webrtc.VideoFrame) SurfaceViewRenderer(org.webrtc.SurfaceViewRenderer) FrameLayout(android.widget.FrameLayout) ParamWithInitBitmap(net.iGap.helper.avatar.ParamWithInitBitmap) TextImageView(net.iGap.module.customView.TextImageView) AppCompatTextView(androidx.appcompat.widget.AppCompatTextView) TextView(android.widget.TextView) AppCompatImageView(androidx.appcompat.widget.AppCompatImageView) ImageView(android.widget.ImageView) TextImageView(net.iGap.module.customView.TextImageView) LinearLayout(android.widget.LinearLayout) WebRTC(net.iGap.module.webrtc.WebRTC)

Aggregations

Canvas (android.graphics.Canvas)1 Paint (android.graphics.Paint)1 Drawable (android.graphics.drawable.Drawable)1 View (android.view.View)1 FrameLayout (android.widget.FrameLayout)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 AppCompatImageView (androidx.appcompat.widget.AppCompatImageView)1 AppCompatTextView (androidx.appcompat.widget.AppCompatTextView)1 ParamWithInitBitmap (net.iGap.helper.avatar.ParamWithInitBitmap)1 CallRippleView (net.iGap.module.customView.CallRippleView)1 TextImageView (net.iGap.module.customView.TextImageView)1 WebRTC (net.iGap.module.webrtc.WebRTC)1 SurfaceViewRenderer (org.webrtc.SurfaceViewRenderer)1 VideoFrame (org.webrtc.VideoFrame)1