修改分享框实现方式,为了和adas左侧1/3共存,使用window manager的方式,这种方式无法响应back键

This commit is contained in:
tongchenfei
2020-03-27 18:21:28 +08:00
parent c28ddf9200
commit b745879476
4 changed files with 222 additions and 165 deletions

View File

@@ -1,2 +1,4 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mogo.module.share" />
package="com.mogo.module.share" >
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
</manifest>

View File

@@ -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();
}

View File

@@ -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;
}
}
}

View File

@@ -1,146 +1,157 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="@dimen/share_module_width"
android:layout_height="@dimen/share_module_height"
android:background="@drawable/shape_bg_222533_20px">
<TextView
android:id="@+id/btn_share_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginTop="@dimen/share_module_title_margin_top"
android:gravity="center"
android:text="一 我要分享 一"
android:textStyle="bold"
android:textColor="@color/white"
android:textSize="@dimen/share_module_title_content" />
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:background="#88000000">
<RelativeLayout
android:id="@+id/tu_block_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/btn_share_title"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/share_module_margin_top">
<RelativeLayout
android:id="@+id/btn_block_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/share_module_margin_left"
android:layout_toLeftOf="@+id/traffic_check_layout">
<ImageView
android:id="@+id/block_up_iv"
android:layout_width="@dimen/share_module_image_width"
android:layout_height="@dimen/share_module_image_width"
android:src="@drawable/share_block_up" />
<TextView
android:id="@+id/block_up_tv"
android:layout_width="@dimen/share_module_image_width"
android:layout_height="wrap_content"
android:layout_below="@+id/block_up_iv"
android:layout_marginTop="@dimen/share_module_tv_margin_top"
android:gravity="center"
android:text="上报拥堵"
android:textColor="@color/white"
android:textSize="@dimen/share_module_item"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/oil_price_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
android:layout_marginLeft="@dimen/share_module_margin_left"
android:layout_toRightOf="@+id/btn_block_layout">
<ImageView
android:id="@+id/oil_price_iv"
android:layout_width="@dimen/share_module_image_width"
android:layout_height="@dimen/share_module_image_width"
android:src="@drawable/share_oil_price" />
<TextView
android:id="@+id/oil_price_tv"
android:layout_width="@dimen/share_module_image_width"
android:layout_height="wrap_content"
android:layout_below="@+id/oil_price_iv"
android:layout_marginTop="@dimen/share_module_tv_margin_top"
android:gravity="center"
android:text="分享油价"
android:textColor="@color/white"
android:textSize="@dimen/share_module_item"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/traffic_check_layout"
android:layout_width="@dimen/share_module_image_width_second"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<ImageView
android:id="@+id/traffic_check_iv"
android:layout_width="@dimen/share_module_image_width"
android:layout_height="@dimen/share_module_image_width"
android:layout_centerHorizontal="true"
android:src="@drawable/share_traffic_check" />
<TextView
android:id="@+id/traffic_check_tv"
android:layout_width="@dimen/share_module_image_width_second"
android:layout_height="wrap_content"
android:layout_below="@+id/traffic_check_iv"
android:layout_marginTop="@dimen/share_module_tv_margin_top"
android:gravity="center"
android:text="上报交通检查"
android:textColor="@color/white"
android:textSize="@dimen/share_module_item"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/road_closure_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/share_module_margin_left"
android:layout_toRightOf="@+id/traffic_check_layout">
<ImageView
android:id="@+id/road_closure_iv"
android:layout_width="@dimen/share_module_image_width"
android:layout_height="@dimen/share_module_image_width"
android:src="@drawable/share_road_closure" />
<TextView
android:id="@+id/road_closure_tv"
android:layout_width="@dimen/share_module_image_width"
android:layout_height="wrap_content"
android:layout_below="@+id/road_closure_iv"
android:layout_marginTop="@dimen/share_module_tv_margin_top"
android:gravity="center"
android:text="上报封路"
android:textColor="@color/white"
android:textSize="@dimen/share_module_item"
android:textStyle="bold" />
</RelativeLayout>
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">
<TextView
android:id="@+id/btn_share_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_block_layout"
android:layout_marginTop="@dimen/share_module_bottom_margin_top"
android:layout_alignParentTop="true"
android:layout_marginTop="@dimen/share_module_title_margin_top"
android:gravity="center"
android:text="可以对小智说:上报拥堵、上报交通检查、上报封路"
android:textColor="@color/white_40"
android:textSize="@dimen/share_module_bottom_size"
android:text="一 我要分享 一"
android:textColor="@color/white"
android:textSize="@dimen/share_module_title_content"
android:textStyle="bold" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:id="@+id/tu_block_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/btn_share_title"
android:layout_centerHorizontal="true"
android:layout_marginTop="@dimen/share_module_margin_top">
<RelativeLayout
android:id="@+id/btn_block_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/share_module_margin_left"
android:layout_toLeftOf="@+id/traffic_check_layout">
<ImageView
android:id="@+id/block_up_iv"
android:layout_width="@dimen/share_module_image_width"
android:layout_height="@dimen/share_module_image_width"
android:src="@drawable/share_block_up" />
<TextView
android:id="@+id/block_up_tv"
android:layout_width="@dimen/share_module_image_width"
android:layout_height="wrap_content"
android:layout_below="@+id/block_up_iv"
android:layout_marginTop="@dimen/share_module_tv_margin_top"
android:gravity="center"
android:text="上报拥堵"
android:textColor="@color/white"
android:textSize="@dimen/share_module_item"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/oil_price_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/share_module_margin_left"
android:layout_toRightOf="@+id/btn_block_layout"
android:visibility="gone">
<ImageView
android:id="@+id/oil_price_iv"
android:layout_width="@dimen/share_module_image_width"
android:layout_height="@dimen/share_module_image_width"
android:src="@drawable/share_oil_price" />
<TextView
android:id="@+id/oil_price_tv"
android:layout_width="@dimen/share_module_image_width"
android:layout_height="wrap_content"
android:layout_below="@+id/oil_price_iv"
android:layout_marginTop="@dimen/share_module_tv_margin_top"
android:gravity="center"
android:text="分享油价"
android:textColor="@color/white"
android:textSize="@dimen/share_module_item"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/traffic_check_layout"
android:layout_width="@dimen/share_module_image_width_second"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true">
<ImageView
android:id="@+id/traffic_check_iv"
android:layout_width="@dimen/share_module_image_width"
android:layout_height="@dimen/share_module_image_width"
android:layout_centerHorizontal="true"
android:src="@drawable/share_traffic_check" />
<TextView
android:id="@+id/traffic_check_tv"
android:layout_width="@dimen/share_module_image_width_second"
android:layout_height="wrap_content"
android:layout_below="@+id/traffic_check_iv"
android:layout_marginTop="@dimen/share_module_tv_margin_top"
android:gravity="center"
android:text="上报交通检查"
android:textColor="@color/white"
android:textSize="@dimen/share_module_item"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="@+id/road_closure_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/share_module_margin_left"
android:layout_toRightOf="@+id/traffic_check_layout">
<ImageView
android:id="@+id/road_closure_iv"
android:layout_width="@dimen/share_module_image_width"
android:layout_height="@dimen/share_module_image_width"
android:src="@drawable/share_road_closure" />
<TextView
android:id="@+id/road_closure_tv"
android:layout_width="@dimen/share_module_image_width"
android:layout_height="wrap_content"
android:layout_below="@+id/road_closure_iv"
android:layout_marginTop="@dimen/share_module_tv_margin_top"
android:gravity="center"
android:text="上报封路"
android:textColor="@color/white"
android:textSize="@dimen/share_module_item"
android:textStyle="bold" />
</RelativeLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/btn_block_layout"
android:layout_marginTop="@dimen/share_module_bottom_margin_top"
android:gravity="center"
android:text="可以对小智说:上报拥堵、上报交通检查、上报封路"
android:textColor="@color/white_40"
android:textSize="@dimen/share_module_bottom_size"
android:textStyle="bold" />
</RelativeLayout>
</RelativeLayout>
</FrameLayout>