Closed zezung27 closed 2 years ago
snapHelper.attachToRecyclerView(miniNotiLayout); // inflating the view mini type = 3 (media) miniMediaLayout = (RelativeLayout) layoutInflater.inflate(R.layout.media_mini_noti, null); miniMediaLayout.setVisibility(GONE); txtNameMediaMini = (TextView) miniMediaLayout.findViewById(R.id.nameMedia); imgIconMediaMini = (ImageView) miniMediaLayout.findViewById(R.id.imgNotiMedia); lottieMiniMedia = (LottieAnimationView)miniMediaLayout.findViewById(R.id.animationViewMedia); miniMediaLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(Contanst.MINI_TO_EXPAND_MEDIA_LOCAL_BROADCAST); LocalBroadcastManager.getInstance(context).sendBroadcast(intent); isExpandMedia = true; mFakeView.setVisibility(GONE); expandMediaLayout(); } }); mParentView.addView(miniMediaLayout); //inflating the view type2 expandType2layout = (LinearLayout) layoutInflater.inflate(R.layout.expand_type_2_layout, null); listActionsLayoutType2 = (LinearLayout) expandType2layout.findViewById(R.id.listActionsType2); imgCollapseType2 =(ImageView) expandType2layout.findViewById(R.id.imgRightType2); imgCollapseType2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { collapseType2(); } }); expandType2layout.setVisibility(GONE); mParentView.addView(expandType2layout); // inflating the view expand media type = 3 (media) expandMediaLayout = (LinearLayout) layoutInflater.inflate(R.layout.expand_media_layout, null); expandMediaLayout.setVisibility(GONE); appNameExpandMedia = (TextView) expandMediaLayout.findViewById(R.id.appNameExpandMedia); imgExpandClose = (ImageView) expandMediaLayout.findViewById(R.id.imgClearMediaLayout); titleExpandMedia = (TextView) expandMediaLayout.findViewById(R.id.titleMediaExpand); imgExpandCollapse = (ImageView) expandMediaLayout.findViewById(R.id.imgCollapseMedia); listActionsLayout = (LinearLayout) expandMediaLayout.findViewById(R.id.listActionExpandMedia); progressBarExpandMedia = (ProgressBar) expandMediaLayout.findViewById(R.id.progressBarMediaExpand); txtCurrentTime = (TextView) expandMediaLayout.findViewById(R.id.currentTimeSeekBarMeida); txtMaxTime = (TextView) expandMediaLayout.findViewById(R.id.maxTimeSeekBarMeida); mParentView.addView(expandMediaLayout); imgExpandCollapse.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { collapseMedia(); } }); imgExpandClose.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { NotificationManager manager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE); manager.cancel(Integer.parseInt(currentMediaNoti.getId())); Intent intent = new Intent(Contanst.EXPAND_TO_MINI_MEDIA_LOCAL_BROADCAST); LocalBroadcastManager.getInstance(context).sendBroadcast(intent); isExpandMedia = false; mFakeView.setVisibility(GONE); setCurrentProrityMode(0); setCurrentMediaNoti(null); int newWidth = Utils.getWidthPopupWindow(Contanst.TYPE_IDLE, context); int newHeight = Utils.getHeightPopupWindow(Contanst.TYPE_IDLE, context); fadeInOutAnim(newWidth, newHeight, 5, null); } }); // inflating the view phone type = 4 (phone) miniPhoneLayout = (RelativeLayout) layoutInflater.inflate(R.layout.mini_call_layout, null); lottiePhoneAccept = (LottieAnimationView) miniPhoneLayout.findViewById(R.id.phone_accept); lottiePhoneReject = (LottieAnimationView) miniPhoneLayout.findViewById(R.id.phone_reject); imgMiniPhoneAvatar = (ImageView) miniPhoneLayout.findViewById(R.id.imgLeftCallMini); txtNamePhoneMini = (TextView) miniPhoneLayout.findViewById(R.id.nameMiniCall); txtNumberPhoneMini = (TextView) miniPhoneLayout.findViewById(R.id.phoneMiniCall); listActionsMiniCall = (LinearLayout)miniPhoneLayout.findViewById(R.id.listActionsMiniCall); miniPhoneLayout.setVisibility(GONE); mParentView.addView(miniPhoneLayout); // inflating the view phone type = 5 (phone) phoneActive = (RelativeLayout) layoutInflater.inflate(R.layout.handle_call_active_layout, null); lottiePhoneActive = (LottieAnimationView) phoneActive.findViewById(R.id.phone_active); chronometerCall = (Chronometer) phoneActive.findViewById(R.id.chronometerCall); phoneActive.setVisibility(GONE); mParentView.addView(phoneActive); // init root params mParams.gravity = Gravity.TOP | Gravity.CENTER; mParams.y = 10; // init offset mParams.width = Utils.getWidthPopupWindow(Contanst.TYPE_IDLE, context); mParams.height = Utils.getHeightPopupWindow(Contanst.TYPE_IDLE, context); mWindowManager = (WindowManager) context.getSystemService(WINDOW_SERVICE); mWindowManager.addView(mFakeView, mParamsFake); mWindowManager.addView(mParentView, mParams); }
private void collapseMedia() {
Intent intent = new Intent(Contanst.EXPAND_TO_MINI_MEDIA_LOCAL_BROADCAST);
LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
isExpandMedia = false;
mFakeView.setVisibility(GONE);
expandToMiniMedia();
}
private void collapseType2() {
isExpandType2 = false;
mFakeView.setVisibility(GONE);
int newWidth = Utils.getWidthPopupWindow(Contanst.TYPE_MINI_NOTI, context);
int newHeight = Utils.getHeightPopupWindow(Contanst.TYPE_MINI_NOTI, context);
fadeInOutAnim(newWidth, newHeight, 4, null);
}
private void testNewAnim() {
isExpandType2 = false;
mFakeView.setVisibility(GONE);
expandType2layout.setVisibility(GONE);
miniNotiLayout.setVisibility(GONE);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
mParams.width = Utils.getWidthPopupWindow(Contanst.TYPE_IDLE, context);
mParams.height = Utils.getHeightPopupWindow(Contanst.TYPE_IDLE, context);
mParentView.setLayoutParams(mParams);
mWindowManager.updateViewLayout(mParentView, mParams);
}
}, 500);
}
public static WindowPopup getInstance(Context context) {
if (single_instance == null)
single_instance = new WindowPopup(context);
return single_instance;
}
public void open() {
try {
if(mParentView.getWindowToken()==null) {
if(mParentView.getParent()==null) {
mWindowManager.addView(mParentView, mParams);
}
}
} catch (Exception e) {
Log.d("Error1", e.toString());
}
}
public void close() {
try {
((WindowManager) context.getSystemService(WINDOW_SERVICE)).removeView(mParentView);
// invalidate the view
mParentView.invalidate();
// remove all views
((ViewGroup) mParentView.getParent()).removeAllViews();
// the above steps are necessary when you are adding and removing
// the view simultaneously, it might give some exceptions
} catch (Exception e) {
Log.d("Error2", e.toString());
}
}
private void scaleMiniCallToIdle(boolean isAccept) { int rootWidth = mParentView.getLayoutParams().width; int rootHeight = mParentView.getLayoutParams().height; int newWidth = context.getResources().getDimensionPixelSize(isAccept ? R.dimen.window_width_call_active : R.dimen.window_width_idle); int newHeight = context.getResources().getDimensionPixelSize(R.dimen.window_height_idle); scaleAnim(rootWidth, rootHeight, newWidth, newHeight, 5, null); } private void addViewToCallActionContainer(NotificationModal notification) { acceptIndex = 1; declineIndex = 0; int n; int n2; if (notification.getActions() == null || notification.getActions().size() == 0) { return; } boolean bl = notification.getPackageName().equalsIgnoreCase("com.skype.raider"); int n3 = 1; if (!bl) { declineIndex = 0; acceptIndex = n3; } else { declineIndex = n3; acceptIndex = 0; } if (notification.getActions().size() == 2) { n = 0; n2 = 0; for (int i = 0; i < notification.getActions().size(); ++i) { if (i == 0) { //linearLayout.findViewById(2131361853).setVisibility(0); lottiePhoneReject.setVisibility(View.VISIBLE); lottiePhoneReject.playAnimation(); lottiePhoneReject.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { try { scaleMiniCallToIdle(false); notification.getActions().get(declineIndex).pendingIntent.send(); } catch (PendingIntent.CanceledException e) { e.printStackTrace(); } } }); n = n3; } if (i != n3) continue; //linearLayout.findViewById(2131361845).setVisibility(0); lottiePhoneAccept.setVisibility(View.VISIBLE); lottiePhoneAccept.playAnimation(); lottiePhoneAccept.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { try { scaleMiniCallToIdle(true); notification.getActions().get(acceptIndex).pendingIntent.send(); } catch (PendingIntent.CanceledException e) { e.printStackTrace(); } } }); n2 = n3; } } else { n = 0; n2 = 0; } if (notification.getActions().size() == n3) { //linearLayout.findViewById(2131361853).setVisibility(0); lottiePhoneReject.setVisibility(GONE); lottiePhoneReject.playAnimation(); lottiePhoneReject.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { try { scaleMiniCallToIdle(false); notification.getActions().get(declineIndex).pendingIntent.send(); } catch (PendingIntent.CanceledException e) { e.printStackTrace(); } } }); } else { n3 = n; } if (n3 == 0) { //linearLayout.findViewById(2131361853).setVisibility(8); lottiePhoneReject.setVisibility(GONE); } if (n2 == 0) { //linearLayout.findViewById(2131361845).setVisibility(8); lottiePhoneAccept.setVisibility(GONE); } }
// start anim
public void scaleAnim(int rootWidth, int rootHeight, int newWidth, int newHeight, int type, NotificationModal notificationModal) {
// type: 1 idleToMini, 2: miniToIdle, type 3: miniMedia, type 4: mini phone, type 5: mini call to idle, type: 6 remove all noti call
PropertyValuesHolder propertyW = PropertyValuesHolder.ofInt("WIDTH_PROPERTY", rootWidth, newWidth);
PropertyValuesHolder propertyH = PropertyValuesHolder.ofInt("HEIGHT_PROPERTY", rootHeight, newHeight);
ValueAnimator animator = new ValueAnimator();
animator.setValues(propertyW, propertyH);
animator.setDuration(200);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animation) {
int width = (int) animation.getAnimatedValue("WIDTH_PROPERTY");
int height = (int) animation.getAnimatedValue("HEIGHT_PROPERTY");
mParams.height = height;
mParams.width = width;
mParentView.setPivotX(0.5f);
mParentView.setPivotY(0.5f);
mParentView.setLayoutParams(mParams);
mWindowManager.updateViewLayout(mParentView, mParams);
}
});
animator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
if(type == 4) {
addViewToCallActionContainer(notificationModal);
}
if(type == 5) {
miniPhoneLayout.setVisibility(GONE);
}
if(type == 6) {
miniPhoneLayout.setVisibility(GONE);
phoneActive.setVisibility(GONE);
}
}
@Override
public void onAnimationEnd(Animator animator) {
if(type == 1) {
miniNotiLayout.setVisibility(View.VISIBLE);
}
if(type == 2) {
miniNotiLayout.setVisibility(GONE);
}
if(type == 3) {
miniMediaLayout.setVisibility(View.VISIBLE);
txtNameMediaMini.setText(notificationModal.getTitle() != null ? notificationModal.getTitle().toString() : "");
Bitmap bitmap = BitmapFactory.decodeByteArray(notificationModal.getIcon(), 0, notificationModal.getIcon().length);
if (bitmap != null) {
imgIconMediaMini.setImageBitmap(bitmap);
} else {
imgIconMediaMini.setImageResource(R.drawable.ic_display);
}
lottieMiniMedia.playAnimation();
}
if(type == 4) { miniPhoneLayout.setVisibility(View.VISIBLE); txtNumberPhoneMini.setText(notificationModal.getTitle()+""); txtNamePhoneMini.setText(notificationModal.getText()+""); Bitmap bitmap = BitmapFactory.decodeByteArray(notificationModal.getLargeIcon(), 0, notificationModal.getLargeIcon().length); if (bitmap != null) { imgMiniPhoneAvatar.setImageBitmap(bitmap); } else { imgMiniPhoneAvatar.setImageResource(R.mipmap.ic_launcher); } } }
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
animator.setInterpolator(new LinearInterpolator());
animator.start();
}
public void handleIdleToMiniAnim() {
int rootWidth = mParentView.getLayoutParams().width;
int rootHeight = mParentView.getLayoutParams().height;
int newWidth = context.getResources().getDimensionPixelSize(R.dimen.window_width_noti_mini);
int newHeight = context.getResources().getDimensionPixelSize(R.dimen.window_height_noti_mini);
scaleAnim(rootWidth, rootHeight, newWidth, newHeight, 1, null);
}
public void animMiniToIdle() {
int rootWidth = mParentView.getLayoutParams().width;
int rootHeight = mParentView.getLayoutParams().height;
int newWidth = context.getResources().getDimensionPixelSize(R.dimen.window_width_idle);
int newHeight = context.getResources().getDimensionPixelSize(R.dimen.window_height_idle);
scaleAnim(rootWidth, rootHeight, newWidth, newHeight, 2, null);
}
// display setting
public void changeLeft() {
mParams.gravity = Gravity.TOP | Gravity.START;
mWindowManager.updateViewLayout(mParentView, mParams);
setCurrentPosition("LEFT");
}
public void changeRight() {
mParams.gravity = Gravity.TOP | Gravity.END;
mWindowManager.updateViewLayout(mParentView, mParams);
setCurrentPosition("RIGHT");
}
public void changeCenter() {
mParams.gravity = Gravity.TOP | Gravity.CENTER;
mWindowManager.updateViewLayout(mParentView, mParams);
setCurrentPosition("CENTER");
}
public String getCurrentPosition() {
return currentPosition;
}
public void setCurrentPosition(String currentPosition) {
this.currentPosition = currentPosition;
}
public int getCurrentYPos() {
return mParams.y;
}
public void changeY(int y) {
mParams.y = y;
mWindowManager.updateViewLayout(mParentView, mParams);
}
public int getCurrentXPos() {
return mParams.x;
}
public int getCurrentWidth() {
return mParams.width;
}
public int getCurrentHeight() {
return mParams.height;
}
public void changeWidth(int w) {
mParams.width = w;
mWindowManager.updateViewLayout(mParentView, mParams);
}
public void changeHeight(int h) {
mParams.height = h;
mWindowManager.updateViewLayout(mParentView, mParams);
}
public void changeX(int x) {
mParams.x = x;
mWindowManager.updateViewLayout(mParentView, mParams);
}
public void updateList(NotificationModal notificationModal, int priorityMode) {
if(miniMediaLayout.getVisibility() == View.VISIBLE) {
miniMediaLayout.setVisibility(GONE);
}
modalArrayList.add(0, notificationModal);
miniNotiRecyclerAdapter.notifyDataSetChanged();
}
public void setCurrentProrityMode(int value) {
currentPriorityMode = value;
}
public int getCurrentPriorityMode() {
return currentPriorityMode;
}
public void setUpMediaNoti(NotificationModal notificationModal) {
startAnimationIdleToMiniMedia(notificationModal);
}
public NotificationModal getCurrentMediaNoti() {
return currentMediaNoti;
}
public void setCurrentMediaNoti(NotificationModal currentMediaNoti) {
this.currentMediaNoti = currentMediaNoti;
}
public boolean isExpandMedia() {
return isExpandMedia;
}
// Animation
public void expandType2(NotificationModal notificationModal) {
//test
isExpandType2 = true;
mFakeView.setVisibility(View.VISIBLE);
int newWidth = Utils.getWidthPopupWindow(Contanst.TYPE_EXPAND_TYPE2, context);
int newHeight = Utils.getHeightPopupWindow(Contanst.TYPE_EXPAND_TYPE2, context);
// fade out in
fadeInOutAnim(newWidth, newHeight, 3, notificationModal);
}
public void startAnimationIdleToMiniMedia(NotificationModal notificationModal) { int rootWidth = mParentView.getLayoutParams().width; int rootHeight = mParentView.getLayoutParams().height; int newWidth = context.getResources().getDimensionPixelSize(R.dimen.window_width_noti_mini); int newHeight = context.getResources().getDimensionPixelSize(R.dimen.window_height_noti_mini); scaleAnim(rootWidth, rootHeight, newWidth, newHeight, 3, notificationModal); }
public void fadeInOutAnim(int newWidth, int newHeight, int type, NotificationModal notificationModal) {
// type: 1 - miniToexpandmedia, type2: expandToMiniMedia, type3: miniTOexpandType2Action
// type4: expandType2 -> miniType2
// type 5: close expand media
// type 6: close delete expand type2
ObjectAnimator fadeOut = ObjectAnimator.ofFloat(mParentView, "alpha", 1f, 0f);
fadeOut.setDuration(300);
fadeOut.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
float alphaMini = (float) valueAnimator.getAnimatedValue();
mParentView.setAlpha(alphaMini);
mWindowManager.updateViewLayout(mParentView, mParams);
}
});
fadeOut.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
}
@Override
public void onAnimationEnd(Animator animator) {
if(type == 1) {
miniMediaLayout.setVisibility(GONE);
addViewActionsToLayout(listActionsLayout, getCurrentMediaNoti(), true);
appNameExpandMedia.setText(currentMediaNoti.getAppName());
titleExpandMedia.setText(currentMediaNoti.getTitle());
}
if (type == 2) {
miniMediaLayout.setVisibility(View.VISIBLE);
expandMediaLayout.setVisibility(GONE);
}
if(type == 3) {
miniNotiLayout.setVisibility(GONE);
addViewActionsToLayout(listActionsLayoutType2, notificationModal, false);
ImageView imgIcon = (ImageView) expandType2layout.findViewById(R.id.imgLeftType2);
TextView txtAppName = (TextView)expandType2layout.findViewById(R.id.appnameType2);
TextView txtTitleName = (TextView)expandType2layout.findViewById(R.id.titleType2);
txtAppName.setText(notificationModal.getAppName()+"");
txtTitleName.setText(notificationModal.getText()+"");
Bitmap bitmap = BitmapFactory.decodeByteArray(notificationModal.getIcon(), 0, notificationModal.getIcon().length);
if (bitmap != null) {
imgIcon.setImageBitmap(bitmap);
} else {
imgIcon.setImageResource(R.drawable.ic_display);
}
}
if(type == 4) {
miniNotiLayout.setVisibility(View.VISIBLE);
expandType2layout.setVisibility(GONE);
}
if(type == 5) {
miniMediaLayout.setVisibility(GONE);
expandMediaLayout.setVisibility(GONE);
miniNotiLayout.setVisibility(View.VISIBLE);
}
if(type == 6) {
expandType2layout.setVisibility(GONE);
}
mParams.height = newHeight;
mParams.width = newWidth;
mParentView.setAlpha(0f);
mWindowManager.updateViewLayout(mParentView, mParams);
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
ObjectAnimator fadeIn = ObjectAnimator.ofFloat(mParentView, "alpha", 0f, 1f);
fadeIn.setDuration(300);
fadeIn.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
float alphaExpand = (float) valueAnimator.getAnimatedValue();
mParentView.setAlpha(alphaExpand);
mParentView.setPivotX(0.5f);
mParentView.setPivotY(0f);
mWindowManager.updateViewLayout(mParentView, mParams);
}
});
fadeIn.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
if(type == 1) {
expandMediaLayout.setVisibility(View.VISIBLE);
}
if(type == 3) {
expandType2layout.setVisibility(View.VISIBLE);
}
mWindowManager.updateViewLayout(mParentView, mParams);
}
@Override
public void onAnimationEnd(Animator animator) {
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
AnimatorSet animatorSet = new AnimatorSet();
animatorSet.play(fadeOut).before(fadeIn);
animatorSet.setInterpolator(new LinearInterpolator());
animatorSet.start();
};
public void expandMediaLayout() {
int newWidth = Utils.getWidthPopupWindow(Contanst.TYPE_EXPAND_NOTI, context);
int newHeight = Utils.getHeightPopupWindow(Contanst.TYPE_EXPAND_NOTI, context);
// fade out/in anim
fadeInOutAnim(newWidth, newHeight, 1, getCurrentMediaNoti());
}
private void expandToMiniMedia() {
int newWidth = Utils.getWidthPopupWindow(Contanst.TYPE_MINI_NOTI, context);
int newHeight = Utils.getHeightPopupWindow(Contanst.TYPE_MINI_NOTI, context);
fadeInOutAnim(newWidth, newHeight, 2, getCurrentMediaNoti());
}
public void updateMediaProgress(NotificationModal notificationModal) {
progressBarExpandMedia.setProgress(notificationModal.getProgress());
progressBarExpandMedia.setMax(notificationModal.getProgressMax());
txtCurrentTime.setText(Utils.getFormattedTime(notificationModal.getPosition()));
txtMaxTime.setText(Utils.getFormattedTime(notificationModal.getDuration()));
}
public LinearLayout getLayoutListActionMedia() { return listActionsLayout; } private void sendRemoteInput(PendingIntent pendingIntent, RemoteInput[] arrremoteInput, RemoteInput remoteInput, String string2) { Bundle bundle = new Bundle(); bundle.putString(remoteInput.getResultKey(), string2); Intent intent = new Intent().addFlags(Intent.FLAG_RECEIVER_FOREGROUND); RemoteInput.addResultsToIntent(arrremoteInput, intent, bundle); // if (Build.VERSION.SDK_INT >= 28) { // if (remoteInput.getAllowFreeFormInput()) { // RemoteInput.setResultsSource((Intent)intent, RemoteInput.SOURCE_FREE_FORM_INPUT); // } else { // RemoteInput.setResultsSource((Intent)intent, RemoteInput.SOURCE_CHOICE); // } // } try { pendingIntent.send(context, 0, intent); return; } catch (PendingIntent.CanceledException canceledException) { canceledException.printStackTrace(); return; } }
public void removeNotiType2(NotificationModal notificationModal) {
// mParams.flags |= WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
if(modalArrayList.size() > 0) {
int index = -1;
for (int i = 0; i < modalArrayList.size(); i++) {
if(modalArrayList.get(i).getPackageName().equals(notificationModal.getPackageName())) {
index = i;
break;
}
}
if(index != -1) {
modalArrayList.remove(index);
miniNotiRecyclerAdapter.notifyDataSetChanged();
}
}
isExpandType2 = false;
mFakeView.setVisibility(GONE);
int newWidth = Utils.getWidthPopupWindow(modalArrayList.size() > 0 ? Contanst.TYPE_MINI_NOTI: Contanst.TYPE_IDLE, context);
int newHeight = Utils.getHeightPopupWindow(modalArrayList.size() > 0 ? Contanst.TYPE_MINI_NOTI: Contanst.TYPE_IDLE, context);
fadeInOutAnim(newWidth, newHeight, 6, null);
}
public void addRemoteInput(NotificationModal notificationModal, LinearLayout layout, PendingIntent pendingIntent, RemoteInput[] arrremoteInput) {
layout.removeAllViews();
RelativeLayout remoteInput = (RelativeLayout)LayoutInflater.from(context).inflate(R.layout.remote_input_message, null);
layout.addView(remoteInput);
EditText editText = (EditText) remoteInput.findViewById(R.id.editTextRemoteInput);
ImageView imgSend = (ImageView) remoteInput.findViewById(R.id.imgSendRemote);
editText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
if(charSequence.toString().trim().length() > 0) {
imgSend.setAlpha(1f);
imgSend.setClickable(true);
} else {
imgSend.setAlpha(0.3f);
imgSend.setClickable(false);
}
}
@Override
public void afterTextChanged(Editable editable) {
}
});
imgSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(editText.getText().toString().trim().length() > 0) {
sendRemoteInput(pendingIntent, arrremoteInput, arrremoteInput[0], editText.getText().toString());
removeNotiType2(notificationModal);
}
}
});
}
public void addViewActionsToLayout(LinearLayout listActionsLayout, NotificationModal notificationModal, boolean isMedia) {
listActionsLayout.removeAllViews();
for (int i = 0; i < notificationModal.getActions().size(); ++i) {
final int posCurrent = i;
TextView textView = (TextView)LayoutInflater.from(context).inflate(R.layout.notice_actions_layout, null);
Drawable drawable2 = ResourcesCompat.getDrawable((Resources)context.getResources(), R.drawable.ic_display, null);
try {
drawable2 = ContextCompat.getDrawable(context.createPackageContext(notificationModal.getPackageName(), 0), (int)((ActionParsable)getCurrentMediaNoti().getActions().get((int)i)).actionIcon);
}
catch (Exception exception) {
exception.printStackTrace();
}
textView.setText(((ActionParsable)notificationModal.getActions().get((int)i)).charSequence);
textView.setTextColor(context.getResources().getColor(R.color.white));
if (notificationModal.getTemplate().equals((Object)"MediaStyle")) {
drawable2.setTint(context.getResources().getColor(R.color.white));
textView.setCompoundDrawablesWithIntrinsicBounds(drawable2, null, null, null);
textView.setText((CharSequence)"");
}
if (i > 0) {
textView.setPadding(50, 5, 5, 5);
}
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
notificationModal.getActions().get(posCurrent).pendingIntent.send();
if(!isMedia) {
if(notificationModal.getActions().get(posCurrent).remoteInputs != null) {
sendRemoteInput(notificationModal.getPendingIntent(), notificationModal.getActions().get(posCurrent).remoteInputs,notificationModal.getActions().get(posCurrent).remoteInputs[0], "");
}
//delete noti -> mini (if size > 0) or not -> idle
removeNotiType2(notificationModal);
}
} catch (PendingIntent.CanceledException e) {
e.printStackTrace();
}
}
});
listActionsLayout.addView((View)textView);
}
}
public void showChronometerCall(NotificationModal notificationModal) {
phoneActive.setVisibility(View.VISIBLE);
long elapsedRealtime = SystemClock.elapsedRealtime();
chronometerCall.setBase(elapsedRealtime);
chronometerCall.start();
lottiePhoneActive.playAnimation();
}
public void handleShowMiniCall(NotificationModal notificationModal) {
//hide all current view
miniNotiLayout.setVisibility(GONE);
miniMediaLayout.setVisibility(GONE);
expandMediaLayout.setVisibility(GONE);
expandType2layout.setVisibility(GONE);
int rootWidth = mParentView.getLayoutParams().width;
int rootHeight = mParentView.getLayoutParams().height;
int newWidth = context.getResources().getDimensionPixelSize(R.dimen.window_width_mini_phone);
int newHeight = context.getResources().getDimensionPixelSize(R.dimen.window_height_mini_phone);
scaleAnim(rootWidth, rootHeight, newWidth, newHeight, 4, notificationModal);
}
@Override public void onMiniClick(boolean closeMini, boolean isOpenNoti, NotificationModal notificationModal) { if(closeMini) { modalArrayList.clear(); miniNotiRecyclerAdapter.notifyDataSetChanged(); miniNotiLayout.setVisibility(GONE); if(currentMediaNoti != null) { miniMediaLayout.setVisibility(View.VISIBLE); } else { animMiniToIdle(); } } if(isOpenNoti) { //expand animation if(notificationModal.getActions() != null && notificationModal.getActions().size() > 0) { //expand type2 expandType2(notificationModal); } else if(notificationModal.pendingIntent != null) { miniNotiLayout.setVisibility(View.GONE); if(currentMediaNoti != null) { miniMediaLayout.setVisibility(View.VISIBLE); } else { animMiniToIdle(); } try { notificationModal.pendingIntent.send(); } catch (PendingIntent.CanceledException e) { e.printStackTrace(); } } } }
public void removeCallNoti() {
int rootWidth = mParentView.getLayoutParams().width;
int rootHeight = mParentView.getLayoutParams().height;
int newWidth = context.getResources().getDimensionPixelSize(R.dimen.window_width_idle);
int newHeight = context.getResources().getDimensionPixelSize(R.dimen.window_height_idle);
setCurrentProrityMode(0);
scaleAnim(rootWidth, rootHeight, newWidth, newHeight, 6, null);
}
}
package com.matcos.dynamicislandlight.core.service;
import static android.content.Context.NOTIFICATION_SERVICE; import static android.content.Context.WINDOW_SERVICE; import static android.view.View.GONE;
import android.animation.Animator; import android.animation.AnimatorSet; import android.animation.ObjectAnimator; import android.animation.PropertyValuesHolder; import android.animation.ValueAnimator; import android.annotation.SuppressLint; import android.app.Notification; import android.app.NotificationManager; import android.app.PendingIntent; import android.app.RemoteInput; import android.content.Context; import android.content.Intent; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.PixelFormat; import android.graphics.drawable.Drawable; import android.os.Build; import android.os.Bundle; import android.os.Handler; import android.os.SystemClock; import android.text.Editable; import android.text.TextWatcher; import android.util.Log; import android.view.Gravity; import android.view.LayoutInflater; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; import android.view.animation.LinearInterpolator; import android.widget.Chronometer; import android.widget.EditText; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ProgressBar; import android.widget.RelativeLayout; import android.widget.TextView; import android.widget.Toast;
import androidx.core.content.ContextCompat; import androidx.core.content.res.ResourcesCompat; import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.PagerSnapHelper; import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.SnapHelper;
import com.airbnb.lottie.LottieAnimationView; import com.matcos.dynamicislandlight.R; import com.matcos.dynamicislandlight.core.service.modal.ActionParsable; import com.matcos.dynamicislandlight.core.service.modal.NotificationModal; import com.matcos.dynamicislandlight.utils.Contanst; import com.matcos.dynamicislandlight.utils.Utils;
import java.util.ArrayList;
public class WindowPopup implements IMiniOnlistener{ private Context context; private ViewGroup mParentView, mFakeView; private RecyclerView miniNotiLayout; private RelativeLayout miniMediaLayout, miniPhoneLayout, phoneActive; private LottieAnimationView lottieMiniMedia,lottiePhoneAccept, lottiePhoneReject, lottiePhoneActive; private LinearLayout expandMediaLayout, listActionsLayout, expandType2layout, listActionsLayoutType2, listActionsMiniCall; private TextView txtNameMediaMini, appNameExpandMedia, titleExpandMedia, txtCurrentTime, txtMaxTime, txtNamePhoneMini, txtNumberPhoneMini; private ImageView imgExpandClose, imgExpandCollapse,imgIconMediaMini, imgCollapseType2, imgMiniPhoneAvatar; private ProgressBar progressBarExpandMedia; private Chronometer chronometerCall; // private ViewGroup mParentView; private WindowManager.LayoutParams mParams, mParamsFake; private WindowManager mWindowManager; private LayoutInflater layoutInflater; // of type Singleton private static WindowPopup single_instance = null; private boolean isMiniNoti = false; private boolean isExpandMedia = false; private boolean isExpandType2 = false; private boolean idleMode = false; // new private MiniNotiRecyclerAdapter miniNotiRecyclerAdapter; private ArrayList modalArrayList;
private String currentPosition = "CENTER";
private int currentPriorityMode = 1;
private NotificationModal currentMediaNoti;
int acceptIndex = 1;
int declineIndex = 0;