diff --git a/modules/mogo-module-share/src/main/AndroidManifest.xml b/modules/mogo-module-share/src/main/AndroidManifest.xml index 82aba71bd0..fb780d7be4 100644 --- a/modules/mogo-module-share/src/main/AndroidManifest.xml +++ b/modules/mogo-module-share/src/main/AndroidManifest.xml @@ -1,2 +1,4 @@ + package="com.mogo.module.share" > + + diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/ShareControl.java b/modules/mogo-module-share/src/main/java/com/mogo/module/share/ShareControl.java index d100a6e95b..4256364c5e 100644 --- a/modules/mogo-module-share/src/main/java/com/mogo/module/share/ShareControl.java +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/ShareControl.java @@ -45,12 +45,12 @@ public class ShareControl implements IShareControl { boolean isAdasShow = mogoServiceApis.getStatusManagerApi().isADASShow(); Logger.d("ShareControl", "showDialog 判断adas是否展示: " + isAdasShow); - if (isAdasShow) { - mogoServiceApis.getAdasControllerApi().closeADAS(); - } +// if (isAdasShow) { +// mogoServiceApis.getAdasControllerApi().closeADAS(); +// } mShareDialog = new LaucherShareDialog(mContext); - mShareDialog.setCanceledOnTouchOutside(true); +// mShareDialog.setCanceledOnTouchOutside(true); mShareDialog.show(); } diff --git a/modules/mogo-module-share/src/main/java/com/mogo/module/share/dialog/LaucherShareDialog.java b/modules/mogo-module-share/src/main/java/com/mogo/module/share/dialog/LaucherShareDialog.java index db5b2899af..fa9aa484db 100644 --- a/modules/mogo-module-share/src/main/java/com/mogo/module/share/dialog/LaucherShareDialog.java +++ b/modules/mogo-module-share/src/main/java/com/mogo/module/share/dialog/LaucherShareDialog.java @@ -1,11 +1,14 @@ package com.mogo.module.share.dialog; -import android.app.Dialog; import android.content.Context; import android.content.Intent; +import android.graphics.PixelFormat; import android.net.Uri; -import android.os.Bundle; +import android.os.Build; +import android.view.Gravity; +import android.view.LayoutInflater; import android.view.View; +import android.view.WindowManager; import android.widget.RelativeLayout; import android.widget.TextView; @@ -16,6 +19,7 @@ import com.mogo.module.share.R; import com.mogo.module.share.constant.ShareConstants; import com.mogo.service.MogoServicePaths; import com.mogo.service.analytics.IMogoAnalytics; +import com.mogo.utils.WindowUtils; import com.mogo.utils.logger.Logger; import java.util.HashMap; @@ -25,9 +29,15 @@ import java.util.Map; /** * @author lixiaopeng * @description 通用分享dialog + * + * 由于和左侧Adas冲突,改成了windowManager方式实现,这种实现方式的问题是,无法监测back键的事件 * @since 2020-01-10 */ -public class LaucherShareDialog extends Dialog implements View.OnClickListener { +public class LaucherShareDialog implements View.OnClickListener { + private static final String TAG = "LaucherShareDialog"; + + private boolean isShown = false; + private TextView txtOk; private RelativeLayout mBlockLayout; private RelativeLayout mOilPriceLayout; @@ -36,33 +46,29 @@ public class LaucherShareDialog extends Dialog implements View.OnClickListener { private Context mContext; private IMogoAnalytics mAnalytics; + private WindowManager windowManager; + private WindowManager.LayoutParams layoutParams; public LaucherShareDialog(@NonNull Context context) { - super(context, R.style.BottomDialog); this.mContext = context; - getWindow().setBackgroundDrawableResource(android.R.color.transparent); mAnalytics = (IMogoAnalytics) ARouter.getInstance().build(MogoServicePaths.PATH_UTILS_ANALYTICS).navigation(mContext); - - } - - public LaucherShareDialog(@NonNull Context context, int themeResId) { - super(context, R.style.BottomDialog); - } - - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - initView(); - initListener(); } + private View body; private void initView() { - setContentView(R.layout.launcher_dialog_share); - txtOk = findViewById(R.id.btn_share_title); - mBlockLayout = findViewById(R.id.btn_block_layout); - mOilPriceLayout = findViewById(R.id.oil_price_layout); - mTrafficCheckLayout = findViewById(R.id.traffic_check_layout); - mRoadClosureLayout = findViewById(R.id.road_closure_layout); + Logger.d(TAG, "test-------3"); + body = LayoutInflater.from(mContext).inflate(R.layout.launcher_dialog_share, null); + body.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + dismiss(); + } + }); + txtOk = body.findViewById(R.id.btn_share_title); + mBlockLayout = body.findViewById(R.id.btn_block_layout); + mOilPriceLayout = body.findViewById(R.id.oil_price_layout); + mTrafficCheckLayout = body.findViewById(R.id.traffic_check_layout); + mRoadClosureLayout = body.findViewById(R.id.road_closure_layout); } @@ -73,31 +79,34 @@ public class LaucherShareDialog extends Dialog implements View.OnClickListener { mRoadClosureLayout.setOnClickListener(this); } - @Override public void onClick(View view) { int id = view.getId(); + Logger.d(TAG, "onClick: " + id); if (id == R.id.btn_block_layout) { //拥堵 traceTanluData("1"); sendShareReceiver("1"); traceTypeData("1"); + dismiss(); } else if (id == R.id.oil_price_layout) { traceData("1"); Intent intent = new Intent(); intent.setData(Uri.parse("freshthing://com.zhidao.fresh.things/shareOilPrice")); mContext.startActivity(intent); traceTypeData("2"); + dismiss(); } else if (id == R.id.traffic_check_layout) { //交通检查 traceData("1"); sendShareReceiver("2"); traceTypeData("3"); + dismiss(); } else if (id == R.id.road_closure_layout) { //封路 traceData("1"); sendShareReceiver("3"); traceTypeData("4"); + dismiss(); } - dismiss(); } /** @@ -143,4 +152,39 @@ public class LaucherShareDialog extends Dialog implements View.OnClickListener { } + public void show(){ + Logger.d(TAG,"使用windowManager实现"); + if (!isShown) { + windowManager = (WindowManager) mContext.getApplicationContext().getSystemService(Context.WINDOW_SERVICE); + layoutParams = new WindowManager.LayoutParams(); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + layoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY; + } else { + layoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT; + } + layoutParams.format = PixelFormat.TRANSLUCENT; + layoutParams.gravity = Gravity.LEFT | Gravity.TOP; +// mWindowLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; + // FLAG_LAYOUT_IN_SCREEN:将window放置在整个屏幕之内,无视其他的装饰(比如状态栏); FLAG_NOT_TOUCH_MODAL:不阻塞事件传递到后面的窗口 + layoutParams.flags = WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE; + layoutParams.width = WindowUtils.getScreenWidth(mContext); + layoutParams.height = WindowUtils.getScreenHeight(mContext); + layoutParams.dimAmount = 0;//后面变暗区域透明... + layoutParams.x = 0; + layoutParams.y = 0; + initView(); + initListener(); + windowManager.addView(body, layoutParams); + isShown = true; + } + } + + public void dismiss(){ + if (isShown && windowManager != null && body != null) { + windowManager.removeViewImmediate(body); + windowManager = null; + isShown = false; + } + } + } diff --git a/modules/mogo-module-share/src/main/res/layout/launcher_dialog_share.xml b/modules/mogo-module-share/src/main/res/layout/launcher_dialog_share.xml index e38447d88a..3e9ca3ab44 100644 --- a/modules/mogo-module-share/src/main/res/layout/launcher_dialog_share.xml +++ b/modules/mogo-module-share/src/main/res/layout/launcher_dialog_share.xml @@ -1,146 +1,157 @@ - - - + android:layout_width="match_parent" + android:layout_height="match_parent" + android:clickable="true" + android:focusable="true" + android:background="#88000000"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:layout_width="@dimen/share_module_width" + android:layout_height="@dimen/share_module_height" + android:clickable="true" + android:focusable="true" + android:layout_gravity="center" + android:background="@drawable/shape_bg_222533_20px"> - - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file