修改分享框实现方式,为了和adas左侧1/3共存,使用window manager的方式,这种方式无法响应back键
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user