latLngs, AMap aMap) {
98 | Boolean flag = false;
99 | try {
100 |
101 | for (int i = 0; i < latLngs.size() - 2; i++) {
102 | Point point1, point2, point3, point4;
103 |
104 | point1 = aMap.getProjection().toScreenLocation(latLngs.get(i).getLatLng());
105 | point2 = aMap.getProjection().toScreenLocation(latLngs.get(i + 1).getLatLng());
106 |
107 | for (int j = i + 2; j < latLngs.size(); j++) {
108 |
109 | if (i == 0 && j == latLngs.size() - 1) {
110 | break;
111 |
112 | } else if (j == latLngs.size() - 1) {
113 | point3 = aMap.getProjection().toScreenLocation(latLngs.get(j).getLatLng());
114 | point4 = aMap.getProjection().toScreenLocation(latLngs.get(0).getLatLng());
115 | flag = intersection(point1, point2, point3, point4);
116 |
117 | } else {
118 | point3 = aMap.getProjection().toScreenLocation(latLngs.get(j).getLatLng());
119 | point4 = aMap.getProjection().toScreenLocation(latLngs.get(j + 1).getLatLng());
120 | flag = intersection(point1, point2, point3, point4);
121 | }
122 |
123 | if (flag) {
124 | return flag;
125 | }
126 | }
127 | }
128 |
129 | } catch (Exception e) {
130 | }
131 |
132 |
133 | return flag;
134 | }
135 |
136 |
137 | public static boolean intersection(Point point1, Point point2, Point point3, Point point4) {
138 | double l1x1 = point1.x;
139 | double l1y1 = point1.y;
140 | double l1x2 = point2.x;
141 | double l1y2 = point2.y;
142 | double l2x1 = point3.x;
143 | double l2y1 = point3.y;
144 | double l2x2 = point4.x;
145 | double l2y2 = point4.y;
146 |
147 |
148 | // 快速排斥实验 首先判断两条线段在 x 以及 y 坐标的投影是否有重合。 有一个为真,则代表两线段必不可交。
149 | if (Math.max(l1x1, l1x2) < Math.min(l2x1, l2x2)
150 | || Math.max(l1y1, l1y2) < Math.min(l2y1, l2y2)
151 | || Math.max(l2x1, l2x2) < Math.min(l1x1, l1x2)
152 | || Math.max(l2y1, l2y2) < Math.min(l1y1, l1y2)) {
153 | return false;
154 | }
155 | // 跨立实验 如果相交则矢量叉积异号或为零,大于零则不相交
156 | if ((((l1x1 - l2x1) * (l2y2 - l2y1) - (l1y1 - l2y1) * (l2x2 - l2x1))
157 | * ((l1x2 - l2x1) * (l2y2 - l2y1) - (l1y2 - l2y1) * (l2x2 - l2x1))) > 0
158 | || (((l2x1 - l1x1) * (l1y2 - l1y1) - (l2y1 - l1y1) * (l1x2 - l1x1))
159 | * ((l2x2 - l1x1) * (l1y2 - l1y1) - (l2y2 - l1y1) * (l1x2 - l1x1))) > 0) {
160 | return false;
161 | }
162 | return true;
163 | }
164 |
165 | /**
166 | * 计算平均值
167 | *
168 | * @param a
169 | * @param b
170 | * @return
171 | */
172 | public static int avg(int a, int b) {
173 |
174 | return ((a & b) + ((a ^ b) >> 1));
175 |
176 | }
177 | }
178 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xuezhy/drawmap/utils/GoogleMapUtil.java:
--------------------------------------------------------------------------------
1 | package com.xuezhy.drawmap.utils;
2 |
3 | import com.amap.api.maps.model.TileOverlayOptions;
4 | import com.amap.api.maps.model.TileProvider;
5 | import com.amap.api.maps.model.UrlTileProvider;
6 |
7 | import java.net.MalformedURLException;
8 | import java.net.URL;
9 |
10 | /**
11 | * 类功能描述: 高德地图切换到有的地方没有卫星图片,此处使用谷歌地图的卫星切片替换
12 | * 作者: zhongyangxue
13 | * 创建时间: 2019/10/16 上午12:40
14 | * 邮箱 1366411749@qq.com
15 | * 版本: 1.0
16 | */
17 | public class GoogleMapUtil {
18 | // final static String url = "http://mt2.google.cn/vt/lyrs=y@167000000&hl=zh-CN&gl=cn&x=%d&y=%d&z=%d&s=Galil";
19 | // final static String url = "http://mt0.google.cn/vt/lyrs=y@198&hl=zh-CN&gl=cn&src=app&x=%d&y=%d&z=%d&s=";
20 | final static String url = "http://mt3.google.cn/maps/vt?lyrs=y@194&hl=zh-CN&gl=cn&x=%d&y=%d&z=%d";
21 |
22 |
23 | public static TileOverlayOptions getGooleMapTileOverlayOptions() {
24 |
25 | TileProvider tileProvider = new UrlTileProvider(256, 256) {
26 | public URL getTileUrl(int x, int y, int zoom) {
27 | try {
28 | return new URL(String.format(url, x, y, zoom));
29 | } catch (MalformedURLException e) {
30 | e.printStackTrace();
31 | }
32 | return null;
33 | }
34 | };
35 |
36 | return new TileOverlayOptions()
37 | .tileProvider(tileProvider)
38 | .diskCacheEnabled(true)
39 | .diskCacheSize(50000)
40 | .diskCacheDir("/storage/emulated/0/amap/OMCcache")
41 | .memoryCacheEnabled(false)
42 | .memCacheSize(10000)
43 | .zIndex(-9999);
44 | }
45 |
46 | }
47 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xuezhy/drawmap/utils/GpsManager.java:
--------------------------------------------------------------------------------
1 | package com.xuezhy.drawmap.utils;
2 |
3 | import android.app.Activity;
4 | import android.content.Intent;
5 | import android.location.LocationManager;
6 | import android.provider.Settings;
7 | import com.amap.api.location.AMapLocation;
8 | import com.amap.api.location.AMapLocationClient;
9 | import com.amap.api.location.AMapLocationClientOption;
10 | import com.amap.api.location.AMapLocationListener;
11 | import com.xuezhy.drawmap.bean.LocationEvent;
12 | import com.xuezhy.drawmap.EventCode;
13 | import com.xuezhy.drawmap.bean.LatlngBean;
14 |
15 | import org.greenrobot.eventbus.EventBus;
16 |
17 | import static android.content.Context.LOCATION_SERVICE;
18 |
19 | /**
20 | * 类功能描述:
21 | * 作者: zhongyangxue
22 | * 创建时间: 2020-03-30 14:18
23 | * 邮箱 1366411749@qq.com
24 | * 版本: 1.0
25 | */
26 | public class GpsManager {
27 | private AMapLocationClient locationClient = null;
28 | private LocationManager mLocationManager;
29 | private static final GpsManager checkGpsManager = new GpsManager();
30 |
31 | private GpsManager() {
32 | }
33 |
34 |
35 | public static GpsManager getInstance() {
36 | return checkGpsManager;
37 | }
38 |
39 | public void init(Activity context) throws Exception {
40 | if (mLocationManager == null) {
41 | mLocationManager = (LocationManager) context.getSystemService(LOCATION_SERVICE);
42 | }
43 | if (locationClient == null) {
44 | //初始化client
45 | locationClient = new AMapLocationClient(context);
46 | //设置定位参数
47 | locationClient.setLocationOption(getDefaultOption());
48 | // 设置定位监听
49 | locationClient.setLocationListener(locationListener);
50 | // 启动定位
51 | // locationClient.startLocation();
52 | }
53 | }
54 |
55 | public void startLocation() {
56 | if (locationClient != null) {
57 | //先暂停
58 | locationClient.stopLocation();
59 | // 启动定位
60 | locationClient.startLocation();
61 | }
62 | }
63 |
64 | /**
65 | * 默认的定位参数
66 | *
67 | * @author hongming.wang
68 | * @since 2.8.0
69 | */
70 | private AMapLocationClientOption getDefaultOption() {
71 | AMapLocationClientOption mOption = new AMapLocationClientOption();
72 | mOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);//可选,设置定位模式,可选的模式有高精度、仅设备、仅网络。默认为高精度模式
73 | mOption.setGpsFirst(true);//可选,设置是否gps优先,只在高精度模式下有效。默认关闭
74 | mOption.setHttpTimeOut(30 * 000);//可选,设置网络请求超时时间。默认为30秒。在仅设备模式下无效
75 | mOption.setInterval(50 * 1000);//可选,设置定位间隔。
76 | mOption.setNeedAddress(true);//可选,设置是否返回逆地理地址信息。默认是true
77 | mOption.setOnceLocation(false);//可选,设置是否单次定位。默认是false
78 | mOption.setWifiScan(true); //可选,设置是否开启wifi扫描。默认为true,如果设置为false会同时停止主动刷新,停止以后完全依赖于系统刷新,定位位置可能存在误差
79 | mOption.setLocationCacheEnable(true); //可选,设置是否使用缓存定位,默认为true
80 | mOption.setMockEnable(false); ////设置是否允许模拟位置,默认为false,不允许模拟位置
81 | return mOption;
82 | }
83 |
84 | /**
85 | * 判断是否打开定位
86 | *
87 | * @return
88 | */
89 | public Boolean checkGps() {
90 | //判断gps是否打开
91 | return mLocationManager
92 | .isProviderEnabled(LocationManager.GPS_PROVIDER);
93 | }
94 |
95 | /**
96 | * 跳转到设置页面
97 | *
98 | * @param context
99 | * @param GPS_REQUEST_CODE
100 | */
101 | public void goToSetting(Activity context, int GPS_REQUEST_CODE) {
102 | PopWindowUtil.buildNoTitleEnsureDialog(context, "请在设置中打开定位", "取消", "去设置", new PopWindowUtil.EnsureListener() {
103 | @Override
104 | public void sure(Object obj) {
105 | Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
106 | context.startActivityForResult(intent, GPS_REQUEST_CODE);
107 | }
108 |
109 | @Override
110 | public void cancel() {
111 |
112 | }
113 | });
114 |
115 | }
116 |
117 |
118 | /**
119 | * 定位监听
120 | */
121 | AMapLocationListener locationListener = new AMapLocationListener() {
122 | @Override
123 | public void onLocationChanged(AMapLocation loc) {
124 | if (null == loc) {
125 | return;
126 | }
127 | try {
128 | if (loc.getLatitude() != 0 &&loc.getLongitude() != 0) {
129 | EventBus.getDefault().post(new LocationEvent(EventCode.LOCATION_CODE,new LatlngBean(loc.getLatitude(),loc.getLongitude())));
130 | }
131 |
132 | } catch (Exception e) {
133 |
134 | }
135 |
136 | }
137 | };
138 |
139 |
140 | }
141 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xuezhy/drawmap/utils/PopWindowUtil.java:
--------------------------------------------------------------------------------
1 | package com.xuezhy.drawmap.utils;
2 |
3 | import android.app.Activity;
4 | import android.app.AlertDialog;
5 | import android.content.Context;
6 | import android.os.Build;
7 | import android.text.TextUtils;
8 | import android.view.LayoutInflater;
9 | import android.view.View;
10 | import android.view.WindowManager;
11 | import android.widget.TextView;
12 |
13 | import com.xuezhy.drawmap.R;
14 |
15 |
16 | /**
17 | * 类功能描述:
18 | * 作者: zhongyangxue
19 | * 创建时间: 2020-01-12 17:05
20 | * 邮箱 1366411749@qq.com
21 | * 版本: 1.0
22 | */
23 | public class PopWindowUtil {
24 |
25 | public static final AlertDialog buildNoTitleEnsureDialog(Context context, String content, String cancel, String sure, final EnsureListener listener) {
26 | if (context instanceof Activity) {
27 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
28 | if (((Activity) context).isDestroyed())
29 | return null;
30 | }
31 | }
32 |
33 | final AlertDialog dialog;
34 | AlertDialog.Builder builder = new AlertDialog.Builder(context);
35 | builder.setCancelable(false);
36 | dialog = builder.create();
37 |
38 | dialog.show();
39 | View baseView = LayoutInflater.from(context).inflate(R.layout.layout_ensure_notitle_dialog, null);
40 | ((TextView) baseView.findViewById(R.id.dialog_cancel_btn)).setText(cancel);
41 | ((TextView) baseView.findViewById(R.id.dialog_sure_btn)).setText(sure);
42 | if (!TextUtils.isEmpty(content)) {
43 | ((TextView) baseView.findViewById(R.id.dialog_content)).setText(content);
44 | } else {
45 | baseView.findViewById(R.id.dialog_content).setVisibility(View.GONE);
46 | }
47 | baseView.findViewById(R.id.dialog_sure_btn).setOnClickListener(new View.OnClickListener() {
48 |
49 | @Override
50 | public void onClick(View v) {
51 | if (listener != null)
52 | listener.sure(null);
53 | dialog.dismiss();
54 | }
55 | });
56 |
57 | baseView.findViewById(R.id.dialog_cancel_btn).setOnClickListener(new View.OnClickListener() {
58 |
59 | @Override
60 | public void onClick(View v) {
61 | if (listener != null)
62 | listener.cancel();
63 | dialog.dismiss();
64 | }
65 | });
66 | WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
67 | lp.width = ScreenUtil.getPxByDp(context,320);//定义宽度
68 | lp.height = WindowManager.LayoutParams.WRAP_CONTENT;//定义高度
69 | dialog.getWindow().setAttributes(lp);
70 | dialog.setContentView(baseView);
71 | dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
72 | return dialog;
73 | }
74 |
75 | public interface EnsureListener {
76 | void sure(Object obj);
77 |
78 | void cancel();
79 | }
80 |
81 |
82 | }
83 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xuezhy/drawmap/utils/ScreenUtil.java:
--------------------------------------------------------------------------------
1 | package com.xuezhy.drawmap.utils;
2 |
3 | import android.content.Context;
4 | import android.content.res.Configuration;
5 | import android.content.res.Resources;
6 | import android.graphics.Point;
7 | import android.graphics.Rect;
8 | import android.support.annotation.NonNull;
9 | import android.util.DisplayMetrics;
10 | import android.view.Display;
11 | import android.view.View;
12 | import android.view.Window;
13 | import android.view.WindowManager;
14 | import java.lang.reflect.Method;
15 |
16 |
17 | public class ScreenUtil {
18 |
19 | private static final String TAG = ScreenUtil.class.getSimpleName();
20 |
21 | private static int navigationBarHeight = 0;
22 | private static int SOFT_INPUT_HEIGHT = 0;
23 |
24 | public static boolean checkNavigationBarShow(@NonNull Context context, @NonNull Window window) {
25 | boolean show;
26 | Display display = window.getWindowManager().getDefaultDisplay();
27 | Point point = new Point();
28 | display.getRealSize(point);
29 |
30 | View decorView = window.getDecorView();
31 | Configuration conf = context.getResources().getConfiguration();
32 | if (Configuration.ORIENTATION_LANDSCAPE == conf.orientation) {
33 | View contentView = decorView.findViewById(android.R.id.content);
34 | show = (point.x != contentView.getWidth());
35 | } else {
36 | Rect rect = new Rect();
37 | decorView.getWindowVisibleDisplayFrame(rect);
38 | show = (rect.bottom != point.y);
39 | }
40 | return show;
41 | }
42 |
43 | public static int getNavigationBarHeight(Context context) {
44 | if (navigationBarHeight != 0)
45 | return navigationBarHeight;
46 | Resources resources =context.getResources();
47 | int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
48 | int height = resources.getDimensionPixelSize(resourceId);
49 | navigationBarHeight = height;
50 | return height;
51 | }
52 |
53 | public static int[] getScreenSize(Context context) {
54 | int size[] = new int[2];
55 | DisplayMetrics dm = context.getResources().getDisplayMetrics();
56 | size[0] = dm.widthPixels;
57 | size[1] = dm.heightPixels;
58 | return size;
59 | }
60 |
61 | public static int getStatusBarHeight(Context context) {
62 | int result = 0;
63 | int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
64 | if (resourceId > 0) {
65 | result = context.getResources().getDimensionPixelSize(resourceId);
66 | }
67 | return result;
68 | }
69 |
70 | public static int getScreenHeight(Context context) {
71 | DisplayMetrics metric = new DisplayMetrics();
72 | WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
73 | wm.getDefaultDisplay().getMetrics(metric);
74 | return metric.heightPixels;
75 | }
76 |
77 | public static int getScreenWidth(Context context) {
78 | DisplayMetrics metric = new DisplayMetrics();
79 | WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
80 | wm.getDefaultDisplay().getMetrics(metric);
81 | return metric.widthPixels;
82 | }
83 |
84 | public static int getPxByDp(Context context,float dp) {
85 | float scale = context.getResources().getDisplayMetrics().density;
86 | return (int) (dp * scale + 0.5f);
87 | }
88 |
89 | public static int getDpi(Context context) {
90 | int dpi = 0;
91 | WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
92 | Display display = windowManager.getDefaultDisplay();
93 | DisplayMetrics displayMetrics = new DisplayMetrics();
94 | @SuppressWarnings("rawtypes")
95 | Class c;
96 | try {
97 | c = Class.forName("android.view.Display");
98 | @SuppressWarnings("unchecked")
99 | Method method = c.getMethod("getRealMetrics", DisplayMetrics.class);
100 | method.invoke(display, displayMetrics);
101 | dpi = displayMetrics.heightPixels;
102 | } catch (Exception e) {
103 | e.printStackTrace();
104 | }
105 | return dpi;
106 | }
107 |
108 | /**
109 | * 获取 虚拟按键的高度
110 | *
111 | * @param context
112 | * @return
113 | */
114 | public static int getBottomStatusHeight(Context context) {
115 | if (SOFT_INPUT_HEIGHT > 0)
116 | return SOFT_INPUT_HEIGHT;
117 | int totalHeight = getDpi(context);
118 | int contentHeight = getScreenHeight(context);
119 | SOFT_INPUT_HEIGHT = totalHeight - contentHeight;
120 | return SOFT_INPUT_HEIGHT;
121 | }
122 |
123 | public static int[] scaledSize(int containerWidth, int containerHeight, int realWidth, int realHeight) {
124 |
125 | float deviceRate = (float) containerWidth / (float) containerHeight;
126 | float rate = (float) realWidth / (float) realHeight;
127 | int width = 0;
128 | int height = 0;
129 | if (rate < deviceRate) {
130 | height = containerHeight;
131 | width = (int) (containerHeight * rate);
132 | } else {
133 | width = containerWidth;
134 | height = (int) (containerWidth / rate);
135 | }
136 | return new int[]{width, height};
137 | }
138 | }
139 |
--------------------------------------------------------------------------------
/app/src/main/java/com/xuezhy/drawmap/utils/StatusBarUtil.java:
--------------------------------------------------------------------------------
1 | package com.xuezhy.drawmap.utils;
2 |
3 | import android.annotation.TargetApi;
4 | import android.app.Activity;
5 | import android.content.Context;
6 | import android.graphics.Color;
7 | import android.os.Build;
8 | import android.support.annotation.ColorInt;
9 | import android.support.annotation.IntDef;
10 | import android.support.annotation.IntRange;
11 | import android.support.annotation.NonNull;
12 | import android.support.design.widget.CoordinatorLayout;
13 | import android.support.v4.widget.DrawerLayout;
14 | import android.view.View;
15 | import android.view.ViewGroup;
16 | import android.view.Window;
17 | import android.view.WindowManager;
18 | import android.widget.LinearLayout;
19 |
20 | import com.xuezhy.drawmap.R;
21 |
22 | import java.lang.annotation.Retention;
23 | import java.lang.annotation.RetentionPolicy;
24 | import java.lang.reflect.Field;
25 | import java.lang.reflect.Method;
26 |
27 |
28 | public class StatusBarUtil {
29 |
30 | public static final int DEFAULT_STATUS_BAR_ALPHA = 112;
31 | private static final int FAKE_STATUS_BAR_VIEW_ID = R.id.statusbarutil_fake_status_bar_view;
32 | private static final int FAKE_TRANSLUCENT_VIEW_ID = R.id.statusbarutil_translucent_view;
33 | private static final int TAG_KEY_HAVE_SET_OFFSET = -123;
34 |
35 | public final static int TYPE_MIUI = 0;
36 | public final static int TYPE_FLYME = 1;
37 | public final static int TYPE_M = 3;//6.0
38 |
39 | @IntDef({TYPE_MIUI,
40 | TYPE_FLYME,
41 | TYPE_M})
42 | @Retention(RetentionPolicy.SOURCE)
43 | @interface ViewType {
44 | }
45 |
46 | /**
47 | * 设置状态栏颜色
48 | *
49 | * @param activity 需要设置的 activity
50 | * @param color 状态栏颜色值
51 | */
52 | public static void setColor(Activity activity, @ColorInt int color) {
53 | setColor(activity, color, DEFAULT_STATUS_BAR_ALPHA);
54 | }
55 |
56 | /**
57 | * 设置状态栏颜色
58 | *
59 | * @param activity 需要设置的activity
60 | * @param color 状态栏颜色值
61 | * @param statusBarAlpha 状态栏透明度
62 | */
63 |
64 | public static void setColor(Activity activity, @ColorInt int color, @IntRange(from = 0, to = 255) int statusBarAlpha) {
65 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
66 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
67 | activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
68 | activity.getWindow().setStatusBarColor(calculateStatusColor(color, statusBarAlpha));
69 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
70 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
71 | ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
72 | View fakeStatusBarView = decorView.findViewById(FAKE_STATUS_BAR_VIEW_ID);
73 | if (fakeStatusBarView != null) {
74 | if (fakeStatusBarView.getVisibility() == View.GONE) {
75 | fakeStatusBarView.setVisibility(View.VISIBLE);
76 | }
77 | fakeStatusBarView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
78 | } else {
79 | decorView.addView(createStatusBarView(activity, color, statusBarAlpha));
80 | }
81 | setRootView(activity);
82 | }
83 | }
84 |
85 | /**
86 | * 为滑动返回界面设置状态栏颜色
87 | *
88 | * @param activity 需要设置的activity
89 | * @param color 状态栏颜色值
90 | */
91 | public static void setColorForSwipeBack(Activity activity, int color) {
92 | setColorForSwipeBack(activity, color, DEFAULT_STATUS_BAR_ALPHA);
93 | }
94 |
95 | /**
96 | * 为滑动返回界面设置状态栏颜色
97 | *
98 | * @param activity 需要设置的activity
99 | * @param color 状态栏颜色值
100 | * @param statusBarAlpha 状态栏透明度
101 | */
102 | public static void setColorForSwipeBack(Activity activity, @ColorInt int color,
103 | @IntRange(from = 0, to = 255) int statusBarAlpha) {
104 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
105 |
106 | ViewGroup contentView = ((ViewGroup) activity.findViewById(android.R.id.content));
107 | View rootView = contentView.getChildAt(0);
108 | int statusBarHeight = getStatusBarHeight(activity);
109 | if (rootView != null && rootView instanceof CoordinatorLayout) {
110 | final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) rootView;
111 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
112 | coordinatorLayout.setFitsSystemWindows(false);
113 | contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
114 | boolean isNeedRequestLayout = contentView.getPaddingTop() < statusBarHeight;
115 | if (isNeedRequestLayout) {
116 | contentView.setPadding(0, statusBarHeight, 0, 0);
117 | coordinatorLayout.post(new Runnable() {
118 | @Override
119 | public void run() {
120 | coordinatorLayout.requestLayout();
121 | }
122 | });
123 | }
124 | } else {
125 | coordinatorLayout.setStatusBarBackgroundColor(calculateStatusColor(color, statusBarAlpha));
126 | }
127 | } else {
128 | contentView.setPadding(0, statusBarHeight, 0, 0);
129 | contentView.setBackgroundColor(calculateStatusColor(color, statusBarAlpha));
130 | }
131 | setTransparentForWindow(activity);
132 | }
133 | }
134 |
135 | /**
136 | * 设置状态栏纯色 不加半透明效果
137 | *
138 | * @param activity 需要设置的 activity
139 | * @param color 状态栏颜色值
140 | */
141 | public static void setColorNoTranslucent(Activity activity, @ColorInt int color) {
142 | setColor(activity, color, 0);
143 | }
144 |
145 | /**
146 | * 设置状态栏颜色(5.0以下无半透明效果,不建议使用)
147 | *
148 | * @param activity 需要设置的 activity
149 | * @param color 状态栏颜色值
150 | */
151 | @Deprecated
152 | public static void setColorDiff(Activity activity, @ColorInt int color) {
153 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
154 | return;
155 | }
156 | transparentStatusBar(activity);
157 | ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
158 | // 移除半透明矩形,以免叠加
159 | View fakeStatusBarView = contentView.findViewById(FAKE_STATUS_BAR_VIEW_ID);
160 | if (fakeStatusBarView != null) {
161 | if (fakeStatusBarView.getVisibility() == View.GONE) {
162 | fakeStatusBarView.setVisibility(View.VISIBLE);
163 | }
164 | fakeStatusBarView.setBackgroundColor(color);
165 | } else {
166 | contentView.addView(createStatusBarView(activity, color));
167 | }
168 | setRootView(activity);
169 | }
170 |
171 | /**
172 | * 使状态栏半透明
173 | *
174 | * 适用于图片作为背景的界面,此时需要图片填充到状态栏
175 | *
176 | * @param activity 需要设置的activity
177 | */
178 | public static void setTranslucent(Activity activity) {
179 | setTranslucent(activity, DEFAULT_STATUS_BAR_ALPHA);
180 | }
181 |
182 | /**
183 | * 使状态栏半透明
184 | *
185 | * 适用于图片作为背景的界面,此时需要图片填充到状态栏
186 | *
187 | * @param activity 需要设置的activity
188 | * @param statusBarAlpha 状态栏透明度
189 | */
190 | public static void setTranslucent(Activity activity, @IntRange(from = 0, to = 255) int statusBarAlpha) {
191 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
192 | return;
193 | }
194 | setTransparent(activity);
195 | addTranslucentView(activity, statusBarAlpha);
196 | }
197 |
198 | /**
199 | * 针对根布局是 CoordinatorLayout, 使状态栏半透明
200 | *
201 | * 适用于图片作为背景的界面,此时需要图片填充到状态栏
202 | *
203 | * @param activity 需要设置的activity
204 | * @param statusBarAlpha 状态栏透明度
205 | */
206 | public static void setTranslucentForCoordinatorLayout(Activity activity, @IntRange(from = 0, to = 255) int statusBarAlpha) {
207 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
208 | return;
209 | }
210 | transparentStatusBar(activity);
211 | addTranslucentView(activity, statusBarAlpha);
212 | }
213 |
214 | /**
215 | * 设置状态栏全透明
216 | *
217 | * @param activity 需要设置的activity
218 | */
219 | public static void setTransparent(Activity activity) {
220 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
221 | return;
222 | }
223 | transparentStatusBar(activity);
224 | setRootView(activity);
225 | }
226 |
227 | /**
228 | * 使状态栏透明(5.0以上半透明效果,不建议使用)
229 | *
230 | * 适用于图片作为背景的界面,此时需要图片填充到状态栏
231 | *
232 | * @param activity 需要设置的activity
233 | */
234 | @Deprecated
235 | public static void setTranslucentDiff(Activity activity) {
236 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
237 | // 设置状态栏透明
238 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
239 | setRootView(activity);
240 | }
241 | }
242 |
243 | /**
244 | * 为DrawerLayout 布局设置状态栏变色
245 | *
246 | * @param activity 需要设置的activity
247 | * @param drawerLayout DrawerLayout
248 | * @param color 状态栏颜色值
249 | */
250 | public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, @ColorInt int color) {
251 | setColorForDrawerLayout(activity, drawerLayout, color, DEFAULT_STATUS_BAR_ALPHA);
252 | }
253 |
254 | /**
255 | * 为DrawerLayout 布局设置状态栏颜色,纯色
256 | *
257 | * @param activity 需要设置的activity
258 | * @param drawerLayout DrawerLayout
259 | * @param color 状态栏颜色值
260 | */
261 | public static void setColorNoTranslucentForDrawerLayout(Activity activity, DrawerLayout drawerLayout, @ColorInt int color) {
262 | setColorForDrawerLayout(activity, drawerLayout, color, 0);
263 | }
264 |
265 | /**
266 | * 为DrawerLayout 布局设置状态栏变色
267 | *
268 | * @param activity 需要设置的activity
269 | * @param drawerLayout DrawerLayout
270 | * @param color 状态栏颜色值
271 | * @param statusBarAlpha 状态栏透明度
272 | */
273 | public static void setColorForDrawerLayout(Activity activity, DrawerLayout drawerLayout, @ColorInt int color,
274 | @IntRange(from = 0, to = 255) int statusBarAlpha) {
275 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
276 | return;
277 | }
278 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
279 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
280 | activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
281 | activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
282 | } else {
283 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
284 | }
285 | // 生成一个状态栏大小的矩形
286 | // 添加 statusBarView 到布局中
287 | ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
288 | View fakeStatusBarView = contentLayout.findViewById(FAKE_STATUS_BAR_VIEW_ID);
289 | if (fakeStatusBarView != null) {
290 | if (fakeStatusBarView.getVisibility() == View.GONE) {
291 | fakeStatusBarView.setVisibility(View.VISIBLE);
292 | }
293 | fakeStatusBarView.setBackgroundColor(color);
294 | } else {
295 | contentLayout.addView(createStatusBarView(activity, color), 0);
296 | }
297 | // 内容布局不是 LinearLayout 时,设置padding top
298 | if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
299 | contentLayout.getChildAt(1)
300 | .setPadding(contentLayout.getPaddingLeft(), getStatusBarHeight(activity) + contentLayout.getPaddingTop(),
301 | contentLayout.getPaddingRight(), contentLayout.getPaddingBottom());
302 | }
303 | // 设置属性
304 | setDrawerLayoutProperty(drawerLayout, contentLayout);
305 | addTranslucentView(activity, statusBarAlpha);
306 | }
307 |
308 | /**
309 | * 设置 DrawerLayout 属性
310 | *
311 | * @param drawerLayout DrawerLayout
312 | * @param drawerLayoutContentLayout DrawerLayout 的内容布局
313 | */
314 | private static void setDrawerLayoutProperty(DrawerLayout drawerLayout, ViewGroup drawerLayoutContentLayout) {
315 | ViewGroup drawer = (ViewGroup) drawerLayout.getChildAt(1);
316 | drawerLayout.setFitsSystemWindows(false);
317 | drawerLayoutContentLayout.setFitsSystemWindows(false);
318 | drawerLayoutContentLayout.setClipToPadding(true);
319 | drawer.setFitsSystemWindows(false);
320 | }
321 |
322 | /**
323 | * 为DrawerLayout 布局设置状态栏变色(5.0以下无半透明效果,不建议使用)
324 | *
325 | * @param activity 需要设置的activity
326 | * @param drawerLayout DrawerLayout
327 | * @param color 状态栏颜色值
328 | */
329 | @Deprecated
330 | public static void setColorForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout, @ColorInt int color) {
331 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
332 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
333 | // 生成一个状态栏大小的矩形
334 | ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
335 | View fakeStatusBarView = contentLayout.findViewById(FAKE_STATUS_BAR_VIEW_ID);
336 | if (fakeStatusBarView != null) {
337 | if (fakeStatusBarView.getVisibility() == View.GONE) {
338 | fakeStatusBarView.setVisibility(View.VISIBLE);
339 | }
340 | fakeStatusBarView.setBackgroundColor(calculateStatusColor(color, DEFAULT_STATUS_BAR_ALPHA));
341 | } else {
342 | // 添加 statusBarView 到布局中
343 | contentLayout.addView(createStatusBarView(activity, color), 0);
344 | }
345 | // 内容布局不是 LinearLayout 时,设置padding top
346 | if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
347 | contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
348 | }
349 | // 设置属性
350 | setDrawerLayoutProperty(drawerLayout, contentLayout);
351 | }
352 | }
353 |
354 | /**
355 | * 为 DrawerLayout 布局设置状态栏透明
356 | *
357 | * @param activity 需要设置的activity
358 | * @param drawerLayout DrawerLayout
359 | */
360 | public static void setTranslucentForDrawerLayout(Activity activity, DrawerLayout drawerLayout) {
361 | setTranslucentForDrawerLayout(activity, drawerLayout, DEFAULT_STATUS_BAR_ALPHA);
362 | }
363 |
364 | /**
365 | * 为 DrawerLayout 布局设置状态栏透明
366 | *
367 | * @param activity 需要设置的activity
368 | * @param drawerLayout DrawerLayout
369 | */
370 | public static void setTranslucentForDrawerLayout(Activity activity, DrawerLayout drawerLayout,
371 | @IntRange(from = 0, to = 255) int statusBarAlpha) {
372 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
373 | return;
374 | }
375 | setTransparentForDrawerLayout(activity, drawerLayout);
376 | addTranslucentView(activity, statusBarAlpha);
377 | }
378 |
379 | /**
380 | * 为 DrawerLayout 布局设置状态栏透明
381 | *
382 | * @param activity 需要设置的activity
383 | * @param drawerLayout DrawerLayout
384 | */
385 | public static void setTransparentForDrawerLayout(Activity activity, DrawerLayout drawerLayout) {
386 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
387 | return;
388 | }
389 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
390 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
391 | activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
392 | activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
393 | } else {
394 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
395 | }
396 |
397 | ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
398 | // 内容布局不是 LinearLayout 时,设置padding top
399 | if (!(contentLayout instanceof LinearLayout) && contentLayout.getChildAt(1) != null) {
400 | contentLayout.getChildAt(1).setPadding(0, getStatusBarHeight(activity), 0, 0);
401 | }
402 |
403 | // 设置属性
404 | setDrawerLayoutProperty(drawerLayout, contentLayout);
405 | }
406 |
407 | /**
408 | * 为 DrawerLayout 布局设置状态栏透明(5.0以上半透明效果,不建议使用)
409 | *
410 | * @param activity 需要设置的activity
411 | * @param drawerLayout DrawerLayout
412 | */
413 | @Deprecated
414 | public static void setTranslucentForDrawerLayoutDiff(Activity activity, DrawerLayout drawerLayout) {
415 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
416 | // 设置状态栏透明
417 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
418 | // 设置内容布局属性
419 | ViewGroup contentLayout = (ViewGroup) drawerLayout.getChildAt(0);
420 | contentLayout.setFitsSystemWindows(true);
421 | contentLayout.setClipToPadding(true);
422 | // 设置抽屉布局属性
423 | ViewGroup vg = (ViewGroup) drawerLayout.getChildAt(1);
424 | vg.setFitsSystemWindows(false);
425 | // 设置 DrawerLayout 属性
426 | drawerLayout.setFitsSystemWindows(false);
427 | }
428 | }
429 |
430 | /**
431 | * 为头部是 ImageView 的界面设置状态栏全透明
432 | *
433 | * @param activity 需要设置的activity
434 | * @param needOffsetView 需要向下偏移的 View
435 | */
436 | public static void setTransparentForImageView(Activity activity, View needOffsetView) {
437 | setTranslucentForImageView(activity, 0, needOffsetView);
438 | }
439 |
440 | /**
441 | * 为头部是 ImageView 的界面设置状态栏透明(使用默认透明度)
442 | *
443 | * @param activity 需要设置的activity
444 | * @param needOffsetView 需要向下偏移的 View
445 | */
446 | public static void setTranslucentForImageView(Activity activity, View needOffsetView) {
447 | setTranslucentForImageView(activity, DEFAULT_STATUS_BAR_ALPHA, needOffsetView);
448 | }
449 |
450 | /**
451 | * 为头部是 ImageView 的界面设置状态栏透明
452 | *
453 | * @param activity 需要设置的activity
454 | * @param statusBarAlpha 状态栏透明度
455 | * @param needOffsetView 需要向下偏移的 View
456 | */
457 | public static void setTranslucentForImageView(Activity activity, @IntRange(from = 0, to = 255) int statusBarAlpha,
458 | View needOffsetView) {
459 | if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
460 | return;
461 | }
462 | setTransparentForWindow(activity);
463 | addTranslucentView(activity, statusBarAlpha);
464 | if (needOffsetView != null) {
465 | Object haveSetOffset = needOffsetView.getTag(TAG_KEY_HAVE_SET_OFFSET);
466 | if (haveSetOffset != null && (Boolean) haveSetOffset) {
467 | return;
468 | }
469 | ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) needOffsetView.getLayoutParams();
470 | layoutParams.setMargins(layoutParams.leftMargin, layoutParams.topMargin + getStatusBarHeight(activity),
471 | layoutParams.rightMargin, layoutParams.bottomMargin);
472 | needOffsetView.setTag(TAG_KEY_HAVE_SET_OFFSET, true);
473 | }
474 | }
475 |
476 | /**
477 | * 为 fragment 头部是 ImageView 的设置状态栏透明
478 | *
479 | * @param activity fragment 对应的 activity
480 | * @param needOffsetView 需要向下偏移的 View
481 | */
482 | public static void setTranslucentForImageViewInFragment(Activity activity, View needOffsetView) {
483 | setTranslucentForImageViewInFragment(activity, DEFAULT_STATUS_BAR_ALPHA, needOffsetView);
484 | }
485 |
486 | /**
487 | * 为 fragment 头部是 ImageView 的设置状态栏透明
488 | *
489 | * @param activity fragment 对应的 activity
490 | * @param needOffsetView 需要向下偏移的 View
491 | */
492 | public static void setTransparentForImageViewInFragment(Activity activity, View needOffsetView) {
493 | setTranslucentForImageViewInFragment(activity, 0, needOffsetView);
494 | }
495 |
496 | /**
497 | * 为 fragment 头部是 ImageView 的设置状态栏透明
498 | *
499 | * @param activity fragment 对应的 activity
500 | * @param statusBarAlpha 状态栏透明度
501 | * @param needOffsetView 需要向下偏移的 View
502 | */
503 | public static void setTranslucentForImageViewInFragment(Activity activity, @IntRange(from = 0, to = 255) int statusBarAlpha,
504 | View needOffsetView) {
505 | setTranslucentForImageView(activity, statusBarAlpha, needOffsetView);
506 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
507 | clearPreviousSetting(activity);
508 | }
509 | }
510 |
511 | /**
512 | * 隐藏伪状态栏 View
513 | *
514 | * @param activity 调用的 Activity
515 | */
516 | public static void hideFakeStatusBarView(Activity activity) {
517 | ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
518 | View fakeStatusBarView = decorView.findViewById(FAKE_STATUS_BAR_VIEW_ID);
519 | if (fakeStatusBarView != null) {
520 | fakeStatusBarView.setVisibility(View.GONE);
521 | }
522 | View fakeTranslucentView = decorView.findViewById(FAKE_TRANSLUCENT_VIEW_ID);
523 | if (fakeTranslucentView != null) {
524 | fakeTranslucentView.setVisibility(View.GONE);
525 | }
526 | }
527 |
528 | @TargetApi(Build.VERSION_CODES.M)
529 | public static void setLightMode(Activity activity) {
530 | setMIUIStatusBarDarkIcon(activity, true);
531 | setMeizuStatusBarDarkIcon(activity, true);
532 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
533 | activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
534 | }
535 | }
536 |
537 | @TargetApi(Build.VERSION_CODES.M)
538 | public static void setDarkMode(Activity activity) {
539 | setMIUIStatusBarDarkIcon(activity, false);
540 | setMeizuStatusBarDarkIcon(activity, false);
541 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
542 | activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
543 | }
544 | }
545 |
546 | /**
547 | * 修改 MIUI V6 以上状态栏颜色
548 | */
549 | private static void setMIUIStatusBarDarkIcon(@NonNull Activity activity, boolean darkIcon) {
550 | Class extends Window> clazz = activity.getWindow().getClass();
551 | try {
552 | Class> layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
553 | Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
554 | int darkModeFlag = field.getInt(layoutParams);
555 | Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
556 | extraFlagField.invoke(activity.getWindow(), darkIcon ? darkModeFlag : 0, darkModeFlag);
557 | } catch (Exception e) {
558 | //e.printStackTrace();
559 | }
560 | }
561 |
562 | /**
563 | * 修改魅族状态栏字体颜色 Flyme 4.0
564 | */
565 | private static void setMeizuStatusBarDarkIcon(@NonNull Activity activity, boolean darkIcon) {
566 | try {
567 | WindowManager.LayoutParams lp = activity.getWindow().getAttributes();
568 | Field darkFlag = WindowManager.LayoutParams.class.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
569 | Field meizuFlags = WindowManager.LayoutParams.class.getDeclaredField("meizuFlags");
570 | darkFlag.setAccessible(true);
571 | meizuFlags.setAccessible(true);
572 | int bit = darkFlag.getInt(null);
573 | int value = meizuFlags.getInt(lp);
574 | if (darkIcon) {
575 | value |= bit;
576 | } else {
577 | value &= ~bit;
578 | }
579 | meizuFlags.setInt(lp, value);
580 | activity.getWindow().setAttributes(lp);
581 | } catch (Exception e) {
582 | //e.printStackTrace();
583 | }
584 | }
585 |
586 | ///////////////////////////////////////////////////////////////////////////////////
587 |
588 | @TargetApi(Build.VERSION_CODES.KITKAT)
589 | private static void clearPreviousSetting(Activity activity) {
590 | ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
591 | View fakeStatusBarView = decorView.findViewById(FAKE_STATUS_BAR_VIEW_ID);
592 | if (fakeStatusBarView != null) {
593 | decorView.removeView(fakeStatusBarView);
594 | ViewGroup rootView = (ViewGroup) ((ViewGroup) activity.findViewById(android.R.id.content)).getChildAt(0);
595 | rootView.setPadding(0, 0, 0, 0);
596 | }
597 | }
598 |
599 | /**
600 | * 添加半透明矩形条
601 | *
602 | * @param activity 需要设置的 activity
603 | * @param statusBarAlpha 透明值
604 | */
605 | private static void addTranslucentView(Activity activity, @IntRange(from = 0, to = 255) int statusBarAlpha) {
606 | ViewGroup contentView = (ViewGroup) activity.findViewById(android.R.id.content);
607 | View fakeTranslucentView = contentView.findViewById(FAKE_TRANSLUCENT_VIEW_ID);
608 | if (fakeTranslucentView != null) {
609 | if (fakeTranslucentView.getVisibility() == View.GONE) {
610 | fakeTranslucentView.setVisibility(View.VISIBLE);
611 | }
612 | fakeTranslucentView.setBackgroundColor(Color.argb(statusBarAlpha, 255, 255, 255));
613 | } else {
614 | contentView.addView(createTranslucentStatusBarView(activity, statusBarAlpha));
615 | }
616 | }
617 |
618 | /**
619 | * 生成一个和状态栏大小相同的彩色矩形条
620 | *
621 | * @param activity 需要设置的 activity
622 | * @param color 状态栏颜色值
623 | * @return 状态栏矩形条
624 | */
625 | private static View createStatusBarView(Activity activity, @ColorInt int color) {
626 | return createStatusBarView(activity, color, 0);
627 | }
628 |
629 | /**
630 | * 生成一个和状态栏大小相同的半透明矩形条
631 | *
632 | * @param activity 需要设置的activity
633 | * @param color 状态栏颜色值
634 | * @param alpha 透明值
635 | * @return 状态栏矩形条
636 | */
637 | private static View createStatusBarView(Activity activity, @ColorInt int color, int alpha) {
638 | // 绘制一个和状态栏一样高的矩形
639 | View statusBarView = new View(activity);
640 | LinearLayout.LayoutParams params =
641 | new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(activity));
642 | statusBarView.setLayoutParams(params);
643 | statusBarView.setBackgroundColor(calculateStatusColor(color, alpha));
644 | statusBarView.setId(FAKE_STATUS_BAR_VIEW_ID);
645 | return statusBarView;
646 | }
647 |
648 | /**
649 | * 设置根布局参数
650 | */
651 | private static void setRootView(Activity activity) {
652 | ViewGroup parent = (ViewGroup) activity.findViewById(android.R.id.content);
653 | for (int i = 0, count = parent.getChildCount(); i < count; i++) {
654 | View childView = parent.getChildAt(i);
655 | if (childView instanceof ViewGroup) {
656 | childView.setFitsSystemWindows(true);
657 | ((ViewGroup) childView).setClipToPadding(true);
658 | }
659 | }
660 | }
661 |
662 | /**
663 | * 设置透明
664 | */
665 | private static void setTransparentForWindow(Activity activity) {
666 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
667 | activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
668 | activity.getWindow()
669 | .getDecorView()
670 | .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
671 | } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
672 | activity.getWindow()
673 | .setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
674 | }
675 | }
676 |
677 | /**
678 | * 使状态栏透明
679 | */
680 | @TargetApi(Build.VERSION_CODES.KITKAT)
681 | private static void transparentStatusBar(Activity activity) {
682 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
683 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
684 | activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
685 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
686 | activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
687 | } else {
688 | activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
689 | }
690 | }
691 |
692 | /**
693 | * 创建半透明矩形 View
694 | *
695 | * @param alpha 透明值
696 | * @return 半透明 View
697 | */
698 | private static View createTranslucentStatusBarView(Activity activity, int alpha) {
699 | // 绘制一个和状态栏一样高的矩形
700 | View statusBarView = new View(activity);
701 | LinearLayout.LayoutParams params =
702 | new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight(activity));
703 | statusBarView.setLayoutParams(params);
704 | statusBarView.setBackgroundColor(Color.argb(alpha, 0, 0, 0));
705 | statusBarView.setId(FAKE_TRANSLUCENT_VIEW_ID);
706 | return statusBarView;
707 | }
708 |
709 | /**
710 | * 获取状态栏高度
711 | *
712 | * @param context context
713 | * @return 状态栏高度
714 | */
715 | public static int getStatusBarHeight(Context context) {
716 | // 获得状态栏高度
717 | int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
718 | return context.getResources().getDimensionPixelSize(resourceId);
719 | }
720 |
721 | /**
722 | * 计算状态栏颜色
723 | *
724 | * @param color color值
725 | * @param alpha alpha值
726 | * @return 最终的状态栏颜色
727 | */
728 | private static int calculateStatusColor(@ColorInt int color, int alpha) {
729 | if (alpha == 0) {
730 | return color;
731 | }
732 | float a = 1 - alpha / 255f;
733 | int red = color >> 16 & 0xff;
734 | int green = color >> 8 & 0xff;
735 | int blue = color & 0xff;
736 | red = (int) (red * a + 0.5);
737 | green = (int) (green * a + 0.5);
738 | blue = (int) (blue * a + 0.5);
739 | return 0xff << 24 | red << 16 | green << 8 | blue;
740 | }
741 |
742 | /**
743 | * 设置文字颜色
744 | */
745 | public static void setStatusBarFontIconDark(Activity activity,@ViewType int type) {
746 | switch (type) {
747 | case TYPE_MIUI:
748 | setMiuiUI(activity,true);
749 | break;
750 | case TYPE_M:
751 | setCommonUI(activity);
752 | break;
753 | case TYPE_FLYME:
754 | setFlymeUI(activity,true);
755 | break;
756 | }
757 | }
758 |
759 | //设置6.0的字体
760 | public static void setCommonUI(Activity activity) {
761 | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
762 | activity.getWindow().getDecorView().setSystemUiVisibility(
763 | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
764 | | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
765 | }
766 | }
767 |
768 | //设置Flyme的字体
769 | public static void setFlymeUI(Activity activity,boolean dark) {
770 | try {
771 | Window window = activity.getWindow();
772 | WindowManager.LayoutParams lp = window.getAttributes();
773 | Field darkFlag = WindowManager.LayoutParams.class.getDeclaredField("MEIZU_FLAG_DARK_STATUS_BAR_ICON");
774 | Field meizuFlags = WindowManager.LayoutParams.class.getDeclaredField("meizuFlags");
775 | darkFlag.setAccessible(true);
776 | meizuFlags.setAccessible(true);
777 | int bit = darkFlag.getInt(null);
778 | int value = meizuFlags.getInt(lp);
779 | if (dark) {
780 | value |= bit;
781 | } else {
782 | value &= ~bit;
783 | }
784 | meizuFlags.setInt(lp, value);
785 | window.setAttributes(lp);
786 | } catch (Exception e) {
787 | e.printStackTrace();
788 | }
789 | }
790 |
791 | //设置MIUI字体
792 | public static void setMiuiUI(Activity activity,boolean dark) {
793 | try {
794 | Window window = activity.getWindow();
795 | Class clazz = activity.getWindow().getClass();
796 | Class layoutParams = Class.forName("android.view.MiuiWindowManager$LayoutParams");
797 | Field field = layoutParams.getField("EXTRA_FLAG_STATUS_BAR_DARK_MODE");
798 | int darkModeFlag = field.getInt(layoutParams);
799 | Method extraFlagField = clazz.getMethod("setExtraFlags", int.class, int.class);
800 | if (dark) { //状态栏亮色且黑色字体
801 | extraFlagField.invoke(window, darkModeFlag, darkModeFlag);
802 | } else {
803 | extraFlagField.invoke(window, 0, darkModeFlag);
804 | }
805 | } catch (Exception e) {
806 | e.printStackTrace();
807 | }
808 | }
809 |
810 | }
811 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/ic_launcher_background.xml:
--------------------------------------------------------------------------------
1 |
2 |
7 |
10 |
15 |
20 |
25 |
30 |
35 |
40 |
45 |
50 |
55 |
60 |
65 |
70 |
75 |
80 |
85 |
90 |
95 |
100 |
105 |
110 |
115 |
120 |
125 |
130 |
135 |
140 |
145 |
150 |
155 |
160 |
165 |
170 |
171 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/my_cursor.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/popu_dialog_bg.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/shape_input_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
--------------------------------------------------------------------------------
/app/src/main/res/drawable/shape_map_draw_point_white.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/act_first.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/act_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
10 |
11 |
12 |
18 |
19 |
30 |
31 |
36 |
37 |
45 |
46 |
54 |
55 |
56 |
57 |
69 |
70 |
71 |
72 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_dialog_notice.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
17 |
31 |
32 |
33 |
38 |
39 |
44 |
45 |
56 |
57 |
61 |
62 |
73 |
74 |
75 |
76 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/layout_ensure_notitle_dialog.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
15 |
16 |
17 |
25 |
26 |
27 |
32 |
33 |
38 |
39 |
48 |
49 |
53 |
54 |
63 |
64 |
65 |
66 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/map_draw_marker.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
11 |
12 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/map_draw_marker_big_white.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
11 |
12 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/layout/map_draw_marker_small_white.xml:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 |
11 |
12 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuezhongyang/MapDrawDemo/018d9f2ece6a4bea8f5466a96cbaf0db922b7d89/app/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuezhongyang/MapDrawDemo/018d9f2ece6a4bea8f5466a96cbaf0db922b7d89/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuezhongyang/MapDrawDemo/018d9f2ece6a4bea8f5466a96cbaf0db922b7d89/app/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuezhongyang/MapDrawDemo/018d9f2ece6a4bea8f5466a96cbaf0db922b7d89/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/arrow_back.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuezhongyang/MapDrawDemo/018d9f2ece6a4bea8f5466a96cbaf0db922b7d89/app/src/main/res/mipmap-xhdpi/arrow_back.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/arrow_next_white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuezhongyang/MapDrawDemo/018d9f2ece6a4bea8f5466a96cbaf0db922b7d89/app/src/main/res/mipmap-xhdpi/arrow_next_white.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuezhongyang/MapDrawDemo/018d9f2ece6a4bea8f5466a96cbaf0db922b7d89/app/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuezhongyang/MapDrawDemo/018d9f2ece6a4bea8f5466a96cbaf0db922b7d89/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/iv_cancel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuezhongyang/MapDrawDemo/018d9f2ece6a4bea8f5466a96cbaf0db922b7d89/app/src/main/res/mipmap-xhdpi/iv_cancel.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/iv_delete.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuezhongyang/MapDrawDemo/018d9f2ece6a4bea8f5466a96cbaf0db922b7d89/app/src/main/res/mipmap-xhdpi/iv_delete.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/map_handle.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuezhongyang/MapDrawDemo/018d9f2ece6a4bea8f5466a96cbaf0db922b7d89/app/src/main/res/mipmap-xhdpi/map_handle.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xhdpi/map_positioning.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuezhongyang/MapDrawDemo/018d9f2ece6a4bea8f5466a96cbaf0db922b7d89/app/src/main/res/mipmap-xhdpi/map_positioning.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuezhongyang/MapDrawDemo/018d9f2ece6a4bea8f5466a96cbaf0db922b7d89/app/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuezhongyang/MapDrawDemo/018d9f2ece6a4bea8f5466a96cbaf0db922b7d89/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuezhongyang/MapDrawDemo/018d9f2ece6a4bea8f5466a96cbaf0db922b7d89/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuezhongyang/MapDrawDemo/018d9f2ece6a4bea8f5466a96cbaf0db922b7d89/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/app/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #008577
4 | #00574B
5 | #D81B60
6 |
7 | #333333
8 | #70C160
9 | #DDDDDD
10 | #ffffff
11 | #80FF0000
12 | #80269A3F
13 | #80000000
14 | #1A000000
15 | #33000000
16 | #40000000
17 | #4D000000
18 | #66000000
19 |
20 |
--------------------------------------------------------------------------------
/app/src/main/res/values/ids.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/app/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | MapDrawDemo
3 | 应用需要定位权限和存储读写权限
4 | 同意
5 | 取消
6 |
7 |
--------------------------------------------------------------------------------
/app/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/build.gradle:
--------------------------------------------------------------------------------
1 | // Top-level build file where you can add configuration options common to all sub-projects/modules.
2 |
3 | buildscript {
4 | repositories {
5 | google()
6 | jcenter()
7 | }
8 | dependencies {
9 | classpath 'com.android.tools.build:gradle:3.5.2'
10 |
11 | // NOTE: Do not place your application dependencies here; they belong
12 | // in the individual module build.gradle files
13 | }
14 | }
15 |
16 | allprojects {
17 | repositories {
18 | google()
19 | jcenter()
20 | }
21 | }
22 |
23 | task clean(type: Delete) {
24 | delete rootProject.buildDir
25 | }
26 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | # Project-wide Gradle settings.
2 | # IDE (e.g. Android Studio) users:
3 | # Gradle settings configured through the IDE *will override*
4 | # any settings specified in this file.
5 | # For more details on how to configure your build environment visit
6 | # http://www.gradle.org/docs/current/userguide/build_environment.html
7 | # Specifies the JVM arguments used for the daemon process.
8 | # The setting is particularly useful for tweaking memory settings.
9 | org.gradle.jvmargs=-Xmx1536m
10 | # When configured, Gradle will run in incubating parallel mode.
11 | # This option should only be used with decoupled projects. More details, visit
12 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
13 | # org.gradle.parallel=true
14 | # AndroidX package structure to make it clearer which packages are bundled with the
15 | # Android operating system, and which are packaged with your app's APK
16 | # https://developer.android.com/topic/libraries/support-library/androidx-rn
17 | #android.useAndroidX=true
18 | # Automatically convert third-party libraries to use AndroidX
19 | #android.enableJetifier=true
20 |
21 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/xuezhongyang/MapDrawDemo/018d9f2ece6a4bea8f5466a96cbaf0db922b7d89/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Jul 23 16:44:47 CST 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
7 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Attempt to set APP_HOME
10 | # Resolve links: $0 may be a link
11 | PRG="$0"
12 | # Need this for relative symlinks.
13 | while [ -h "$PRG" ] ; do
14 | ls=`ls -ld "$PRG"`
15 | link=`expr "$ls" : '.*-> \(.*\)$'`
16 | if expr "$link" : '/.*' > /dev/null; then
17 | PRG="$link"
18 | else
19 | PRG=`dirname "$PRG"`"/$link"
20 | fi
21 | done
22 | SAVED="`pwd`"
23 | cd "`dirname \"$PRG\"`/" >/dev/null
24 | APP_HOME="`pwd -P`"
25 | cd "$SAVED" >/dev/null
26 |
27 | APP_NAME="Gradle"
28 | APP_BASE_NAME=`basename "$0"`
29 |
30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
31 | DEFAULT_JVM_OPTS=""
32 |
33 | # Use the maximum available, or set MAX_FD != -1 to use that value.
34 | MAX_FD="maximum"
35 |
36 | warn () {
37 | echo "$*"
38 | }
39 |
40 | die () {
41 | echo
42 | echo "$*"
43 | echo
44 | exit 1
45 | }
46 |
47 | # OS specific support (must be 'true' or 'false').
48 | cygwin=false
49 | msys=false
50 | darwin=false
51 | nonstop=false
52 | case "`uname`" in
53 | CYGWIN* )
54 | cygwin=true
55 | ;;
56 | Darwin* )
57 | darwin=true
58 | ;;
59 | MINGW* )
60 | msys=true
61 | ;;
62 | NONSTOP* )
63 | nonstop=true
64 | ;;
65 | esac
66 |
67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
68 |
69 | # Determine the Java command to use to start the JVM.
70 | if [ -n "$JAVA_HOME" ] ; then
71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
72 | # IBM's JDK on AIX uses strange locations for the executables
73 | JAVACMD="$JAVA_HOME/jre/sh/java"
74 | else
75 | JAVACMD="$JAVA_HOME/bin/java"
76 | fi
77 | if [ ! -x "$JAVACMD" ] ; then
78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
79 |
80 | Please set the JAVA_HOME variable in your environment to match the
81 | location of your Java installation."
82 | fi
83 | else
84 | JAVACMD="java"
85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
86 |
87 | Please set the JAVA_HOME variable in your environment to match the
88 | location of your Java installation."
89 | fi
90 |
91 | # Increase the maximum file descriptors if we can.
92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
93 | MAX_FD_LIMIT=`ulimit -H -n`
94 | if [ $? -eq 0 ] ; then
95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
96 | MAX_FD="$MAX_FD_LIMIT"
97 | fi
98 | ulimit -n $MAX_FD
99 | if [ $? -ne 0 ] ; then
100 | warn "Could not set maximum file descriptor limit: $MAX_FD"
101 | fi
102 | else
103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
104 | fi
105 | fi
106 |
107 | # For Darwin, add options to specify how the application appears in the dock
108 | if $darwin; then
109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
110 | fi
111 |
112 | # For Cygwin, switch paths to Windows format before running java
113 | if $cygwin ; then
114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
116 | JAVACMD=`cygpath --unix "$JAVACMD"`
117 |
118 | # We build the pattern for arguments to be converted via cygpath
119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
120 | SEP=""
121 | for dir in $ROOTDIRSRAW ; do
122 | ROOTDIRS="$ROOTDIRS$SEP$dir"
123 | SEP="|"
124 | done
125 | OURCYGPATTERN="(^($ROOTDIRS))"
126 | # Add a user-defined pattern to the cygpath arguments
127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
129 | fi
130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
131 | i=0
132 | for arg in "$@" ; do
133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
135 |
136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
138 | else
139 | eval `echo args$i`="\"$arg\""
140 | fi
141 | i=$((i+1))
142 | done
143 | case $i in
144 | (0) set -- ;;
145 | (1) set -- "$args0" ;;
146 | (2) set -- "$args0" "$args1" ;;
147 | (3) set -- "$args0" "$args1" "$args2" ;;
148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
154 | esac
155 | fi
156 |
157 | # Escape application args
158 | save () {
159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
160 | echo " "
161 | }
162 | APP_ARGS=$(save "$@")
163 |
164 | # Collect all arguments for the java command, following the shell quoting and substitution rules
165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
166 |
167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong
168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then
169 | cd "$(dirname "$0")"
170 | fi
171 |
172 | exec "$JAVACMD" "$@"
173 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | set DIRNAME=%~dp0
12 | if "%DIRNAME%" == "" set DIRNAME=.
13 | set APP_BASE_NAME=%~n0
14 | set APP_HOME=%DIRNAME%
15 |
16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
17 | set DEFAULT_JVM_OPTS=
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windows variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 |
53 | :win9xME_args
54 | @rem Slurp the command line arguments.
55 | set CMD_LINE_ARGS=
56 | set _SKIP=2
57 |
58 | :win9xME_args_slurp
59 | if "x%~1" == "x" goto execute
60 |
61 | set CMD_LINE_ARGS=%*
62 |
63 | :execute
64 | @rem Setup the command line
65 |
66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
67 |
68 | @rem Execute Gradle
69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
70 |
71 | :end
72 | @rem End local scope for the variables with windows NT shell
73 | if "%ERRORLEVEL%"=="0" goto mainEnd
74 |
75 | :fail
76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
77 | rem the _cmd.exe /c_ return code!
78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
79 | exit /b 1
80 |
81 | :mainEnd
82 | if "%OS%"=="Windows_NT" endlocal
83 |
84 | :omega
85 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 | rootProject.name='MapDrawDemo'
3 |
--------------------------------------------------------------------------------