org.androidannotations.api
Class ViewServer

java.lang.Object
  extended by org.androidannotations.api.ViewServer
All Implemented Interfaces:
Runnable

public class ViewServer
extends Object
implements Runnable

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

get

public static ViewServer get(android.content.Context context)
Returns a unique instance of the ViewServer. This method should only be called from the main thread of your application. The server will have the same lifetime as your process. If your application does not have the 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.

Parameters:
context - A Context used to check whether the application is debuggable, this can be the application context

start

public boolean start()
              throws IOException
Starts the server.

Returns:
True if the server was successfully created, or false if it already exists.
Throws:
IOException - If the server cannot be created.
See Also:
stop(), isRunning(), WindowManagerService#startViewServer(int)

stop

public boolean stop()
Stops the server.

Returns:
True if the server was stopped, false if an error occurred or if the server wasn't started.
See Also:
start(), isRunning(), WindowManagerService#stopViewServer()

isRunning

public boolean isRunning()
Indicates whether the server is currently running.

Returns:
True if the server is running, false otherwise.
See Also:
start(), stop(), WindowManagerService#isViewServerRunning()

addWindow

public void addWindow(android.app.Activity activity)
Invoke this method to register a new view hierarchy.

Parameters:
activity - The activity whose view hierarchy/window to register
See Also:
addWindow(View, String), removeWindow(Activity)

removeWindow

public void removeWindow(android.app.Activity activity)
Invoke this method to unregister a view hierarchy.

Parameters:
activity - The activity whose view hierarchy/window to unregister
See Also:
addWindow(Activity), removeWindow(View)

addWindow

public void addWindow(android.view.View view,
                      String name)
Invoke this method to register a new view hierarchy.

Parameters:
view - A view that belongs to the view hierarchy/window to register
See Also:
removeWindow(View)

removeWindow

public void removeWindow(android.view.View view)
Invoke this method to unregister a view hierarchy.

Parameters:
view - A view that belongs to the view hierarchy/window to unregister
See Also:
addWindow(View, String)

setFocusedWindow

public void setFocusedWindow(android.app.Activity activity)
Invoke this method to change the currently focused window.

Parameters:
activity - The activity whose view hierarchy/window hasfocus, or null to remove focus

setFocusedWindow

public void setFocusedWindow(android.view.View view)
Invoke this method to change the currently focused window.

Parameters:
view - A view that belongs to the view hierarchy/window that has focus, or null to remove focus

run

public void run()
Main server loop.

Specified by:
run in interface Runnable


Copyright © 2010-2014. All Rights Reserved.