|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.androidannotations.api.ViewServer
public class ViewServer
This class can be used to enable the use of HierarchyViewer inside an application. HierarchyViewer is an Android SDK tool that can be used to inspect and debug the user interface of running applications. For security reasons, HierarchyViewer does not work on production builds (for instance phones bought in store.) By using this class, you can make HierarchyViewer work on any device. You must be very careful however to only enable HierarchyViewer when debugging your application.
To use this view server, your application must require the INTERNET permission.
The recommended way to use this API is to register activities when they are created, and to unregister them when they get destroyed:
public class MyActivity extends Activity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Set content view, etc. ViewServer.get(this).addWindow(this); } public void onDestroy() { super.onDestroy(); ViewServer.get(this).removeWindow(this); } public void onResume() { super.onResume(); ViewServer.get(this).setFocusedWindow(this); } }
In a similar fashion, you can use this API with an InputMethodService:
public class MyInputMethodService extends InputMethodService { public void onCreate() { super.onCreate(); View decorView = getWindow().getWindow().getDecorView(); String name = "MyInputMethodService"; ViewServer.get(this).addWindow(decorView, name); } public void onDestroy() { super.onDestroy(); View decorView = getWindow().getWindow().getDecorView(); ViewServer.get(this).removeWindow(decorView); } public void onStartInput(EditorInfo attribute, boolean restarting) { super.onStartInput(attribute, restarting); View decorView = getWindow().getWindow().getDecorView(); ViewServer.get(this).setFocusedWindow(decorView); } }
Method Summary | |
---|---|
void |
addWindow(android.app.Activity activity)
Invoke this method to register a new view hierarchy. |
void |
addWindow(android.view.View view,
String name)
Invoke this method to register a new view hierarchy. |
static ViewServer |
get(android.content.Context context)
Returns a unique instance of the ViewServer. |
boolean |
isRunning()
Indicates whether the server is currently running. |
void |
removeWindow(android.app.Activity activity)
Invoke this method to unregister a view hierarchy. |
void |
removeWindow(android.view.View view)
Invoke this method to unregister a view hierarchy. |
void |
run()
Main server loop. |
void |
setFocusedWindow(android.app.Activity activity)
Invoke this method to change the currently focused window. |
void |
setFocusedWindow(android.view.View view)
Invoke this method to change the currently focused window. |
boolean |
start()
Starts the server. |
boolean |
stop()
Stops the server. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static ViewServer get(android.content.Context context)
android:debuggable
flag set in its manifest, the server returned by this method will be a
dummy object that does not do anything. This allows you to use the same
code in debug and release versions of your application.
context
- A Context used to check whether the application is debuggable,
this can be the application contextpublic boolean start() throws IOException
IOException
- If the server cannot be created.stop()
,
isRunning()
,
WindowManagerService#startViewServer(int)
public boolean stop()
start()
,
isRunning()
,
WindowManagerService#stopViewServer()
public boolean isRunning()
start()
,
stop()
,
WindowManagerService#isViewServerRunning()
public void addWindow(android.app.Activity activity)
activity
- The activity whose view hierarchy/window to registeraddWindow(View, String)
,
removeWindow(Activity)
public void removeWindow(android.app.Activity activity)
activity
- The activity whose view hierarchy/window to unregisteraddWindow(Activity)
,
removeWindow(View)
public void addWindow(android.view.View view, String name)
view
- A view that belongs to the view hierarchy/window to registerremoveWindow(View)
public void removeWindow(android.view.View view)
view
- A view that belongs to the view hierarchy/window to unregisteraddWindow(View, String)
public void setFocusedWindow(android.app.Activity activity)
activity
- The activity whose view hierarchy/window hasfocus, or null to
remove focuspublic void setFocusedWindow(android.view.View view)
view
- A view that belongs to the view hierarchy/window that has
focus, or null to remove focuspublic void run()
run
in interface Runnable
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |