123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300 |
- package com.edufound.reader.popwindow;
- import android.app.Activity;
- import android.content.Context;
- import android.view.Gravity;
- import android.view.KeyEvent;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.widget.FrameLayout;
- import android.widget.ImageView;
- import android.widget.PopupWindow;
- import com.edufound.reader.R;
- import com.edufound.reader.application.EApplication;
- import com.edufound.reader.bean.RecordResultBean;
- import com.edufound.reader.bean.UserRecordBean;
- import com.edufound.reader.cusview.GridRadioGroup;
- import com.edufound.reader.listener.PopUtilClickListener;
- import com.edufound.reader.listener.PopupRecordStatusListener;
- import com.edufound.reader.presenter.PopWindowPresneter;
- import com.edufound.reader.util.GlideUtils;
- import com.jakewharton.rxbinding4.view.RxView;
- import com.orhanobut.logger.Logger;
- import java.util.concurrent.TimeUnit;
- import io.reactivex.rxjava3.functions.Consumer;
- public class PopWindowUtil {
- private static PopWindowPresneter mPresenter;
- private static PopupWindow mPopupWindow;
- private static void initPresenter() {
- if (mPresenter == null) {
- mPresenter = new PopWindowPresneter();
- }
- }
- private static boolean checkWindowShoing() {
- if (mPopupWindow == null) {
- return false;
- }
- return mPopupWindow.isShowing();
- }
- public static void hidePopupWindow() {
- if (mPopupWindow.isShowing()) {
- mPopupWindow.dismiss();
- }
- }
- public static void showExitAppWindow(Context context, View parent) {
- initPresenter();
- if (checkWindowShoing()) {
- return;
- }
- View dialog_view = LayoutInflater.from(context).inflate(R.layout.popupwindow_exit_app, null);
- dialog_view.setFocusable(true);
- ImageView image = dialog_view.findViewById(R.id.popupwindow_exit_app_image);
- GlideUtils.loadImageSizeKipMemoryCache(context, "http://reader-apk.ai160.com/reader-apk/res/exit_app.png", image);
- FrameLayout exit = dialog_view.findViewById(R.id.popupwindow_exit_app_ok);
- FrameLayout cancel = dialog_view.findViewById(R.id.popupwindow_exit_app_cancel);
- setClickListener(exit, o -> {
- EApplication.killAppProcess(context);
- });
- setClickListener(cancel, o -> {
- mPopupWindow.dismiss();
- });
- mPopupWindow = new PopupWindow(dialog_view, FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
- mPopupWindow.setFocusable(true);
- mPopupWindow.showAtLocation(parent, Gravity.CENTER, 0, 0);
- }
- public static void showSelectGradeWindow(Context context, View parent, int checked, PopUtilClickListener listener) {
- initPresenter();
- if (checkWindowShoing()) {
- return;
- }
- View dialog_view = LayoutInflater.from(context).inflate(R.layout.popupwindow_select_grade, null);
- dialog_view.setFocusable(true);
- FrameLayout btn_ok = dialog_view.findViewById(R.id.popupwindow_select_ok);
- GridRadioGroup gridRadioGroup = dialog_view.findViewById(R.id.popupwindow_select_grade_gridgroup);
- int id = 0;
- final String[] checkText = {String.valueOf(id)};
- switch (checked) {
- case 0:
- id = R.id.popupwindow_select_grade_one;
- checkText[0] = "一年级";
- break;
- case 1:
- id = R.id.popupwindow_select_grade_two;
- checkText[0] = "二年级";
- break;
- case 2:
- id = R.id.popupwindow_select_grade_three;
- checkText[0] = "三年级";
- break;
- case 3:
- id = R.id.popupwindow_select_grade_four;
- checkText[0] = "四年级";
- break;
- case 4:
- id = R.id.popupwindow_select_grade_pre;
- checkText[0] = "学前";
- break;
- }
- gridRadioGroup.setOnCheckedChangeListener(new GridRadioGroup.OnCheckedChangeListener() {
- @Override
- public void onCheckedChanged(GridRadioGroup group, int checkedId) {
- Logger.e("checkedId:" + checkedId);
- group.check(checkedId);
- switch (checkedId) {
- case R.id.popupwindow_select_grade_one:
- //一年级
- checkText[0] = "一年级";
- break;
- case R.id.popupwindow_select_grade_two:
- checkText[0] = "二年级";
- //二年级
- break;
- case R.id.popupwindow_select_grade_three:
- checkText[0] = "三年级";
- //三年级
- break;
- case R.id.popupwindow_select_grade_four:
- checkText[0] = "四年级";
- //四年级
- break;
- case R.id.popupwindow_select_grade_pre:
- //学前
- checkText[0] = "学前";
- break;
- }
- }
- });
- gridRadioGroup.check(id);
- setClickListener(btn_ok, o -> {
- mPopupWindow.dismiss();
- listener.clickSubmit(checkText[0]);
- });
- mPopupWindow = new PopupWindow(dialog_view, FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
- mPopupWindow.setFocusable(true);
- mPopupWindow.showAtLocation(parent, Gravity.CENTER, 0, 0);
- }
- public static void showExitLoginWindow(Context context, View parent, PopUtilClickListener listener) {
- initPresenter();
- if (checkWindowShoing()) {
- return;
- }
- View dialog_view = LayoutInflater.from(context).inflate(R.layout.popupwindow_exit_login, null);
- dialog_view.setFocusable(true);
- ImageView image = dialog_view.findViewById(R.id.popupwindow_exit_login_image);
- GlideUtils.loadImageSizeKipMemoryCache(context, "http://reader-apk.ai160.com/reader-apk/res/exit_login.png", image);
- FrameLayout exit = dialog_view.findViewById(R.id.popupwindow_exit_login_ok);
- FrameLayout cancel = dialog_view.findViewById(R.id.popupwindow_exit_login_cancel);
- setClickListener(exit, o -> {
- listener.clickSubmit(null);
- });
- setClickListener(cancel, o -> {
- mPopupWindow.dismiss();
- listener.clickCancel();
- });
- mPopupWindow = new PopupWindow(dialog_view, FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
- mPopupWindow.setFocusable(true);
- mPopupWindow.showAtLocation(parent, Gravity.CENTER, 0, 0);
- }
- public static void showCancellationAccountWindow(Context context, View parent, PopUtilClickListener listener) {
- initPresenter();
- if (checkWindowShoing()) {
- return;
- }
- View dialog_view = LayoutInflater.from(context).inflate(R.layout.popupwindow_cancellation_account, null);
- dialog_view.setFocusable(true);
- FrameLayout exit = dialog_view.findViewById(R.id.popupwindow_cancellation_account_ok);
- FrameLayout cancel = dialog_view.findViewById(R.id.popupwindow_cancellation_account_cancel);
- setClickListener(exit, o -> {
- listener.clickSubmit(null);
- });
- setClickListener(cancel, o -> {
- mPopupWindow.dismiss();
- listener.clickCancel();
- });
- mPopupWindow = new PopupWindow(dialog_view, FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
- mPopupWindow.setFocusable(true);
- mPopupWindow.showAtLocation(parent, Gravity.CENTER, 0, 0);
- }
- public static void showBindWeChatWindow(Activity context, View parent, PopUtilClickListener listener) {
- initPresenter();
- if (checkWindowShoing()) {
- return;
- }
- View dialog_view = LayoutInflater.from(context).inflate(R.layout.popupwindow_bind_wechat, null);
- dialog_view.setFocusable(true);
- ImageView back = dialog_view.findViewById(R.id.popupwindow_bindwechat_back);
- ImageView image = dialog_view.findViewById(R.id.popupwindow_bind_wechat_image);
- setClickListener(back, o -> {
- mPopupWindow.dismiss();
- listener.clickCancel();
- });
- mPresenter.getBindWeChatPath(context, image);
- mPopupWindow = new PopupWindow(dialog_view, FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
- mPopupWindow.setFocusable(true);
- mPopupWindow.showAtLocation(parent, Gravity.CENTER, 0, 0);
- }
- public static void showRecordStatusWindow(Activity context, View parent, RecordResultBean bean, UserRecordBean.UserRead userread, PopupRecordStatusListener listener) {
- initPresenter();
- if (checkWindowShoing()) {
- return;
- }
- View dialog_view = LayoutInflater.from(context).inflate(R.layout.popupwindow_record_status, null);
- dialog_view.setFocusable(true);
- dialog_view.setOnKeyListener(new View.OnKeyListener() {
- @Override
- public boolean onKey(View v, int keyCode, KeyEvent event) {
- if (keyCode == KeyEvent.KEYCODE_BACK) {
- return true;
- }
- return false;
- }
- });
- ImageView back = dialog_view.findViewById(R.id.popupwindow_record_status_close);
- setClickListener(back, o -> {
- mPopupWindow.dismiss();
- });
- mPresenter.initRecordStatusWindow(context, dialog_view, bean, userread, listener);
- mPopupWindow = new PopupWindow(dialog_view, FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
- mPopupWindow.setFocusable(false);
- mPopupWindow.showAtLocation(parent, Gravity.CENTER, 0, 0);
- }
- public static void showMyOrderWindow(Context context, View parent) {
- initPresenter();
- if (checkWindowShoing()) {
- return;
- }
- View dialog_view = LayoutInflater.from(context).inflate(R.layout.popupwindow_myorder, null);
- dialog_view.setFocusable(true);
- dialog_view.setOnKeyListener(new View.OnKeyListener() {
- @Override
- public boolean onKey(View v, int keyCode, KeyEvent event) {
- if (keyCode == KeyEvent.KEYCODE_BACK) {
- return true;
- }
- return false;
- }
- });
- ImageView back = dialog_view.findViewById(R.id.popupwindow_myorder_back);
- setClickListener(back, o -> {
- mPopupWindow.dismiss();
- });
- mPresenter.myOrderWindowInit(context, dialog_view);
- mPopupWindow = new PopupWindow(dialog_view, FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
- mPopupWindow.setFocusable(false);
- mPopupWindow.showAtLocation(parent, Gravity.CENTER, 0, 0);
- }
- public static void showRecordRemovedWindow(Context context, View parent, PopUtilClickListener listener) {
- initPresenter();
- if (checkWindowShoing()) {
- return;
- }
- View dialog_view = LayoutInflater.from(context).inflate(R.layout.popupwindow_record_remove, null);
- dialog_view.setFocusable(true);
- FrameLayout ok = dialog_view.findViewById(R.id.popupwindow_record_remove_ok);
- FrameLayout cancel = dialog_view.findViewById(R.id.popupwindow_record_remove_cancel);
- setClickListener(ok, o -> {
- mPopupWindow.dismiss();
- listener.clickSubmit(null);
- });
- setClickListener(cancel, o -> {
- mPopupWindow.dismiss();
- listener.clickCancel();
- });
- mPopupWindow = new PopupWindow(dialog_view, FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);
- mPopupWindow.setFocusable(true);
- mPopupWindow.showAtLocation(parent, Gravity.CENTER, 0, 0);
- }
- private static void setClickListener(View view, Consumer onNext) {
- RxView.clicks(view).throttleFirst(2, TimeUnit.SECONDS).subscribe(onNext);
- }
- }
|