|
1 |
| -package com.wanjian.sak.layer; |
2 |
| - |
3 |
| -import android.content.Context; |
4 |
| -import android.graphics.Canvas; |
5 |
| -import android.graphics.drawable.Drawable; |
6 |
| -import android.view.View; |
7 |
| -import android.view.ViewGroup; |
8 |
| -import android.view.WindowManager; |
9 |
| -import android.widget.FrameLayout; |
10 |
| - |
11 |
| -import com.wanjian.sak.config.Config; |
12 |
| -import com.wanjian.sak.converter.ISizeConverter; |
13 |
| -import com.wanjian.sak.filter.ViewFilter; |
14 |
| - |
15 |
| -/** |
16 |
| - * Created by wanjian on 2017/3/9. |
17 |
| - */ |
18 |
| - |
19 |
| -public abstract class AbsLayer extends FrameLayout { |
20 |
| - private boolean mEnable; |
21 |
| - private Config config; |
22 |
| - |
23 |
| - public AbsLayer(Context context) { |
24 |
| - super(context); |
25 |
| - } |
26 |
| - |
27 |
| - public void attachConfig(Config config) { |
28 |
| - this.config = config; |
29 |
| - } |
30 |
| - |
31 |
| - public String description(){ |
32 |
| - return null; |
33 |
| - } |
34 |
| - |
35 |
| - public Drawable icon(){ |
36 |
| - return null; |
37 |
| - } |
38 |
| - |
39 |
| - public final void enable(boolean enable) { |
40 |
| - this.mEnable = enable; |
41 |
| - onStateChange(enable); |
42 |
| - } |
43 |
| - |
44 |
| - protected void onStateChange(boolean isEnable) { |
45 |
| - |
46 |
| - } |
47 |
| - |
48 |
| - protected Config getConfig() { |
49 |
| - return config; |
50 |
| - } |
51 |
| - |
52 |
| - public final boolean isEnable() { |
53 |
| - return mEnable; |
54 |
| - } |
55 |
| - |
56 |
| - protected boolean isClipDraw() { |
57 |
| - return config.isClipDraw(); |
58 |
| - } |
59 |
| - |
60 |
| - protected int getStartRange() { |
61 |
| - return config.getStartRange(); |
62 |
| - } |
63 |
| - |
64 |
| - protected int getEndRange() { |
65 |
| - return config.getEndRange(); |
66 |
| - } |
67 |
| - |
68 |
| - public final void uiUpdate(Canvas canvas, View view) { |
69 |
| - if (!isEnable()) { |
70 |
| - return; |
71 |
| - } |
72 |
| - int count = canvas.save(); |
73 |
| - onUiUpdate(canvas, view); |
74 |
| - canvas.restoreToCount(count); |
75 |
| - } |
76 |
| - |
77 |
| - protected void onUiUpdate(Canvas canvas, View rootView) { |
78 |
| - |
79 |
| - } |
80 |
| - |
81 |
| - @Override |
82 |
| - protected final void onAttachedToWindow() { |
83 |
| - super.onAttachedToWindow(); |
84 |
| - onAttached(getRootView()); |
85 |
| - } |
86 |
| - |
87 |
| - protected void onAttached(View rootView) { |
88 |
| - } |
89 |
| - |
90 |
| - @Override |
91 |
| - protected final void onDetachedFromWindow() { |
92 |
| - onDetached(getRootView()); |
93 |
| - super.onDetachedFromWindow(); |
94 |
| - } |
95 |
| - |
96 |
| - protected void onDetached(View rootView) { |
97 |
| - } |
98 |
| - |
99 |
| - /** |
100 |
| - * @param view view |
101 |
| - * @return x, y, width,height |
102 |
| - */ |
103 |
| - protected int[] getLocationAndSize(View view) { |
104 |
| - int[] locations = new int[2]; |
105 |
| - view.getLocationInWindow(locations); |
106 |
| - View decorView = view.getRootView();// dialog 内边距 |
107 |
| - return new int[]{locations[0] - decorView.getPaddingLeft(), locations[1] - decorView.getPaddingTop(), view.getWidth(), view.getHeight()}; |
108 |
| - } |
109 |
| - |
110 |
| - protected int dp2px(int dip) { |
111 |
| - float density = getRootView().getResources().getDisplayMetrics().density; |
112 |
| - return (int) (dip * density + 0.5); |
113 |
| - } |
114 |
| - |
115 |
| - protected int px2dp(float pxValue) { |
116 |
| - final float scale = getRootView().getResources().getDisplayMetrics().density; |
117 |
| - return (int) (pxValue / scale + 0.5f); |
118 |
| - } |
119 |
| - |
120 |
| - protected ISizeConverter getSizeConverter() { |
121 |
| - return ISizeConverter.CONVERTER; |
122 |
| - } |
123 |
| - |
124 |
| - protected ViewFilter getViewFilter() { |
125 |
| - return ViewFilter.FILTER; |
126 |
| - } |
127 |
| - |
128 |
| - protected void showWindow(View view, WindowManager.LayoutParams params) { |
129 |
| - WindowManager manager = (WindowManager) getRootView().getContext().getSystemService(Context.WINDOW_SERVICE); |
130 |
| - manager.addView(view, params); |
131 |
| - } |
132 |
| - |
133 |
| - protected void updateWindow(View view, WindowManager.LayoutParams params) { |
134 |
| - WindowManager manager = (WindowManager) getRootView().getContext().getSystemService(Context.WINDOW_SERVICE); |
135 |
| - manager.updateViewLayout(view, params); |
136 |
| - } |
137 |
| - |
138 |
| - protected void removeWindow(View view) { |
139 |
| - WindowManager manager = (WindowManager) getRootView().getContext().getSystemService(Context.WINDOW_SERVICE); |
140 |
| - manager.removeViewImmediate(view); |
141 |
| - } |
142 |
| - |
143 |
| - public ViewGroup.LayoutParams getLayoutParams(FrameLayout.LayoutParams params) { |
144 |
| - return params; |
145 |
| - } |
146 |
| - |
147 |
| -} |
| 1 | +//package com.wanjian.sak.layer; |
| 2 | +// |
| 3 | +//import android.content.Context; |
| 4 | +//import android.graphics.Canvas; |
| 5 | +//import android.graphics.drawable.Drawable; |
| 6 | +//import android.view.View; |
| 7 | +//import android.view.ViewGroup; |
| 8 | +//import android.view.WindowManager; |
| 9 | +//import android.widget.FrameLayout; |
| 10 | +// |
| 11 | +//import com.wanjian.sak.config.Config; |
| 12 | +//import com.wanjian.sak.converter.ISizeConverter; |
| 13 | +//import com.wanjian.sak.filter.ViewFilter; |
| 14 | +// |
| 15 | +///** |
| 16 | +// * Created by wanjian on 2017/3/9. |
| 17 | +// */ |
| 18 | +// |
| 19 | +//public abstract class AbsLayer extends FrameLayout { |
| 20 | +// private boolean mEnable; |
| 21 | +// private Config config; |
| 22 | +// |
| 23 | +// public AbsLayer(Context context) { |
| 24 | +// super(context); |
| 25 | +// } |
| 26 | +// |
| 27 | +// public void attachConfig(Config config) { |
| 28 | +// this.config = config; |
| 29 | +// } |
| 30 | +// |
| 31 | +// public String description(){ |
| 32 | +// return null; |
| 33 | +// } |
| 34 | +// |
| 35 | +// public Drawable icon(){ |
| 36 | +// return null; |
| 37 | +// } |
| 38 | +// |
| 39 | +// public final void enable(boolean enable) { |
| 40 | +// this.mEnable = enable; |
| 41 | +// onStateChange(enable); |
| 42 | +// } |
| 43 | +// |
| 44 | +// protected void onStateChange(boolean isEnable) { |
| 45 | +// |
| 46 | +// } |
| 47 | +// |
| 48 | +// protected Config getConfig() { |
| 49 | +// return config; |
| 50 | +// } |
| 51 | +// |
| 52 | +// public final boolean isEnable() { |
| 53 | +// return mEnable; |
| 54 | +// } |
| 55 | +// |
| 56 | +// protected boolean isClipDraw() { |
| 57 | +// return config.isClipDraw(); |
| 58 | +// } |
| 59 | +// |
| 60 | +// protected int getStartRange() { |
| 61 | +// return config.getStartRange(); |
| 62 | +// } |
| 63 | +// |
| 64 | +// protected int getEndRange() { |
| 65 | +// return config.getEndRange(); |
| 66 | +// } |
| 67 | +// |
| 68 | +// public final void uiUpdate(Canvas canvas, View view) { |
| 69 | +// if (!isEnable()) { |
| 70 | +// return; |
| 71 | +// } |
| 72 | +// int count = canvas.save(); |
| 73 | +// onUiUpdate(canvas, view); |
| 74 | +// canvas.restoreToCount(count); |
| 75 | +// } |
| 76 | +// |
| 77 | +// protected void onUiUpdate(Canvas canvas, View rootView) { |
| 78 | +// |
| 79 | +// } |
| 80 | +// |
| 81 | +// @Override |
| 82 | +// protected final void onAttachedToWindow() { |
| 83 | +// super.onAttachedToWindow(); |
| 84 | +// onAttached(getRootView()); |
| 85 | +// } |
| 86 | +// |
| 87 | +// protected void onAttached(View rootView) { |
| 88 | +// } |
| 89 | +// |
| 90 | +// @Override |
| 91 | +// protected final void onDetachedFromWindow() { |
| 92 | +// onDetached(getRootView()); |
| 93 | +// super.onDetachedFromWindow(); |
| 94 | +// } |
| 95 | +// |
| 96 | +// protected void onDetached(View rootView) { |
| 97 | +// } |
| 98 | +// |
| 99 | +// /** |
| 100 | +// * @param view view |
| 101 | +// * @return x, y, width,height |
| 102 | +// */ |
| 103 | +// protected int[] getLocationAndSize(View view) { |
| 104 | +// int[] locations = new int[2]; |
| 105 | +// view.getLocationInWindow(locations); |
| 106 | +// View decorView = view.getRootView();// dialog 内边距 |
| 107 | +// return new int[]{locations[0] - decorView.getPaddingLeft(), locations[1] - decorView.getPaddingTop(), view.getWidth(), view.getHeight()}; |
| 108 | +// } |
| 109 | +// |
| 110 | +// protected int dp2px(int dip) { |
| 111 | +// float density = getRootView().getResources().getDisplayMetrics().density; |
| 112 | +// return (int) (dip * density + 0.5); |
| 113 | +// } |
| 114 | +// |
| 115 | +// protected int px2dp(float pxValue) { |
| 116 | +// final float scale = getRootView().getResources().getDisplayMetrics().density; |
| 117 | +// return (int) (pxValue / scale + 0.5f); |
| 118 | +// } |
| 119 | +// |
| 120 | +// protected ISizeConverter getSizeConverter() { |
| 121 | +// return ISizeConverter.CONVERTER; |
| 122 | +// } |
| 123 | +// |
| 124 | +// protected ViewFilter getViewFilter() { |
| 125 | +// return ViewFilter.FILTER; |
| 126 | +// } |
| 127 | +// |
| 128 | +// protected void showWindow(View view, WindowManager.LayoutParams params) { |
| 129 | +// WindowManager manager = (WindowManager) getRootView().getContext().getSystemService(Context.WINDOW_SERVICE); |
| 130 | +// manager.addView(view, params); |
| 131 | +// } |
| 132 | +// |
| 133 | +// protected void updateWindow(View view, WindowManager.LayoutParams params) { |
| 134 | +// WindowManager manager = (WindowManager) getRootView().getContext().getSystemService(Context.WINDOW_SERVICE); |
| 135 | +// manager.updateViewLayout(view, params); |
| 136 | +// } |
| 137 | +// |
| 138 | +// protected void removeWindow(View view) { |
| 139 | +// WindowManager manager = (WindowManager) getRootView().getContext().getSystemService(Context.WINDOW_SERVICE); |
| 140 | +// manager.removeViewImmediate(view); |
| 141 | +// } |
| 142 | +// |
| 143 | +// public ViewGroup.LayoutParams getLayoutParams(FrameLayout.LayoutParams params) { |
| 144 | +// return params; |
| 145 | +// } |
| 146 | +// |
| 147 | +//} |
0 commit comments