Android examples for User Interface:View Property
get Decoration Views
/* Athrun - Android automation testing Framework. Copyright (C) 2010-2012 TaoBao UI AutoMan Team This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., HuaXing road, Hangzhou,China. Email:taichan@taobao.com,shidun@taobao.com,bingyang.djj@taobao.com *//*from ww w.j ava 2 s . c o m*/ //package com.java2s; import java.lang.reflect.Field; import android.view.View; public class Main { private static Class<?> windowManager; private static String windowManagerString; public static View[] getDecorViews() { Object wmi; try { Field views = windowManager.getDeclaredField("mViews"); views.setAccessible(true); Field instanceField = windowManager .getDeclaredField(getWindowManagerString()); instanceField.setAccessible(true); wmi = instanceField.get(null); synchronized (wmi) { return ((View[]) views.get(wmi)).clone(); } } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (SecurityException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); // } catch (InvocationTargetException e) { // e.printStackTrace(); // } catch (NoSuchMethodException e) { // e.printStackTrace(); } catch (NoSuchFieldException e) { e.printStackTrace(); } throw new RuntimeException("getWindowDecorViews() return null."); } private static String getWindowManagerString() { if (windowManagerString == null) { if (android.os.Build.VERSION.SDK_INT >= 17) { windowManagerString = "sDefaultWindowManager"; } else if (android.os.Build.VERSION.SDK_INT >= 13) { windowManagerString = "sWindowManager"; } else { windowManagerString = "mWindowManager"; } } return windowManagerString; } }