private Rect getRect(View view) { Rect rect = new Rect(); rect.top = view.getTop(); rect.left = view.getLeft(); rect.right = view.getRight(); rect.bottom = view.getBottom(); ViewParent viewParent = view.getParent(); if (viewParent != null) { if (viewParent instanceof ViewGroup) { Rect prect = getRect((ViewGroup) viewParent); rect.top += prect.top; rect.left += prect.left; rect.right += prect.left; rect.bottom += prect.top; } } return rect; }
/** * * @param remoteViews notification's old remoteViews * @param remoteview notification's old remoteViews view * @param oldRemoteView notification's new remoteViews view */ public void setPendIntent(RemoteViews remoteViews, View remoteview, View oldRemoteView) { if (findPendIntents() > 0) { Iterator<Map.Entry<Integer, PendingIntent>> set = clickIntents.entrySet().iterator(); List<RectInfo> list = new ArrayList<>(); int index = 0; VLog.v(TAG, "start find intent"); while (set.hasNext()) { Map.Entry<Integer, PendingIntent> e = set.next(); View view = oldRemoteView.findViewById(e.getKey()); if (view != null) { Rect rect = getRect(view); list.add(new RectInfo(rect, e.getValue(), index)); index++; } } VLog.v(TAG, "find:" + list); if (remoteview instanceof ViewGroup) { setIntentByViewGroup(remoteViews, (ViewGroup) remoteview, list); } } }
private void setIntentByViewGroup(RemoteViews remoteViews, ViewGroup viewGroup, List<RectInfo> list) { int count = viewGroup.getChildCount(); Rect p = new Rect(); viewGroup.getHitRect(p); for (int i = 0; i < count; i++) { View v = viewGroup.getChildAt(i); if (v instanceof ViewGroup) { // linearlayout setIntentByViewGroup(remoteViews, (ViewGroup) v, list); } else if (v instanceof TextView || v instanceof ImageView) { // textview Rect rect = getRect(v); RectInfo next = findIntent(rect, list); if (next != null) { // VLog.d(TAG, next.rect+":setPendIntent:"+i); // remoteViews.setImageViewBitmap(v.getId(), next.testBg); remoteViews.setOnClickPendingIntent(v.getId(), next.mPendingIntent); } } } }
private Rect getRect(View view) { Rect rect = new Rect(); rect.top = view.getTop(); rect.left = view.getLeft(); rect.right = view.getRight(); rect.bottom = view.getBottom(); ViewParent viewParent = view.getParent(); if (viewParent != null) { if (viewParent instanceof ViewGroup) { Rect prect = getRect((ViewGroup) viewParent); rect.top += prect.top; rect.left += prect.left; rect.right += prect.left; rect.bottom += prect.top; } } return rect; }
private Rect getRect(View view) { Rect rect = new Rect(); rect.top = view.getTop(); rect.left = view.getLeft(); rect.right = view.getRight(); rect.bottom = view.getBottom(); ViewParent viewParent = view.getParent(); if (viewParent != null) { if (viewParent instanceof ViewGroup) { Rect prect = getRect((ViewGroup) viewParent); rect.top += prect.top; rect.left += prect.left; rect.right += prect.left; rect.bottom += prect.top; } } return rect; }
/** * * @param remoteViews notification's old remoteViews * @param remoteview notification's old remoteViews view * @param oldRemoteView notification's new remoteViews view */ public void setPendIntent(RemoteViews remoteViews, View remoteview, View oldRemoteView) { if (findPendIntents() > 0) { Iterator<Map.Entry<Integer, PendingIntent>> set = clickIntents.entrySet().iterator(); List<RectInfo> list = new ArrayList<>(); int index = 0; VLog.v(TAG, "start find intent"); while (set.hasNext()) { Map.Entry<Integer, PendingIntent> e = set.next(); View view = oldRemoteView.findViewById(e.getKey()); if (view != null) { Rect rect = getRect(view); list.add(new RectInfo(rect, e.getValue(), index)); index++; } } VLog.v(TAG, "find:" + list); if (remoteview instanceof ViewGroup) { setIntentByViewGroup(remoteViews, (ViewGroup) remoteview, list); } } }
private void setIntentByViewGroup(RemoteViews remoteViews, ViewGroup viewGroup, List<RectInfo> list) { int count = viewGroup.getChildCount(); Rect p = new Rect(); viewGroup.getHitRect(p); for (int i = 0; i < count; i++) { View v = viewGroup.getChildAt(i); if (v instanceof ViewGroup) { // linearlayout setIntentByViewGroup(remoteViews, (ViewGroup) v, list); } else if (v instanceof TextView || v instanceof ImageView) { // textview Rect rect = getRect(v); RectInfo next = findIntent(rect, list); if (next != null) { // VLog.d(TAG, next.rect+":setPendIntent:"+i); // remoteViews.setImageViewBitmap(v.getId(), next.testBg); remoteViews.setOnClickPendingIntent(v.getId(), next.mPendingIntent); } } } }
/** * * @param remoteViews notification's old remoteViews * @param remoteview notification's old remoteViews view * @param oldRemoteView notification's new remoteViews view */ public void setPendIntent(RemoteViews remoteViews, View remoteview, View oldRemoteView) { if (findPendIntents() > 0) { Iterator<Map.Entry<Integer, PendingIntent>> set = clickIntents.entrySet().iterator(); List<RectInfo> list = new ArrayList<>(); int index = 0; VLog.v(TAG, "start find intent"); while (set.hasNext()) { Map.Entry<Integer, PendingIntent> e = set.next(); View view = oldRemoteView.findViewById(e.getKey()); if (view != null) { Rect rect = getRect(view); list.add(new RectInfo(rect, e.getValue(), index)); index++; } } VLog.v(TAG, "find:" + list); if (remoteview instanceof ViewGroup) { setIntentByViewGroup(remoteViews, (ViewGroup) remoteview, list); } } }
private void setIntentByViewGroup(RemoteViews remoteViews, ViewGroup viewGroup, List<RectInfo> list) { int count = viewGroup.getChildCount(); Rect p = new Rect(); viewGroup.getHitRect(p); for (int i = 0; i < count; i++) { View v = viewGroup.getChildAt(i); if (v instanceof ViewGroup) { // linearlayout setIntentByViewGroup(remoteViews, (ViewGroup) v, list); } else if (v instanceof TextView || v instanceof ImageView) { // textview Rect rect = getRect(v); RectInfo next = findIntent(rect, list); if (next != null) { // VLog.d(TAG, next.rect+":setPendIntent:"+i); // remoteViews.setImageViewBitmap(v.getId(), next.testBg); remoteViews.setOnClickPendingIntent(v.getId(), next.mPendingIntent); } } } }