diff options
Diffstat (limited to 'hierarchyviewer2/app/src/com/android')
3 files changed, 124 insertions, 1 deletions
diff --git a/hierarchyviewer2/app/src/com/android/hierarchyviewer/HierarchyViewerApplication.java b/hierarchyviewer2/app/src/com/android/hierarchyviewer/HierarchyViewerApplication.java index acc79b7..427add4 100644 --- a/hierarchyviewer2/app/src/com/android/hierarchyviewer/HierarchyViewerApplication.java +++ b/hierarchyviewer2/app/src/com/android/hierarchyviewer/HierarchyViewerApplication.java @@ -16,8 +16,23 @@ package com.android.hierarchyviewer; +import com.android.hierarchyviewerlib.ComponentRegistry; +import com.android.hierarchyviewerlib.HierarchyViewerDirector; +import com.android.hierarchyviewerlib.models.DeviceSelectionModel; + public class HierarchyViewerApplication { public static void main(String[] args) { - System.out.println("TEST"); + HierarchyViewerDirector director = new HierarchyViewerApplicationDirector(); + ComponentRegistry.setDirector(director); + director.initDebugBridge(); + ComponentRegistry.setDeviceSelectionModel(new DeviceSelectionModel()); + director.startListenForDevices(); + director.populateDeviceSelectionModel(); + + UIThread.runUI(); + + director.stopListenForDevices(); + director.stopDebugBridge(); + director.terminate(); } } diff --git a/hierarchyviewer2/app/src/com/android/hierarchyviewer/HierarchyViewerApplicationDirector.java b/hierarchyviewer2/app/src/com/android/hierarchyviewer/HierarchyViewerApplicationDirector.java new file mode 100644 index 0000000..5321ce7 --- /dev/null +++ b/hierarchyviewer2/app/src/com/android/hierarchyviewer/HierarchyViewerApplicationDirector.java @@ -0,0 +1,66 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.hierarchyviewer; + +import com.android.hierarchyviewerlib.HierarchyViewerDirector; +import com.android.sdklib.SdkConstants; + +import java.io.File; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + +/** + * This is the application version of the director. + */ +public class HierarchyViewerApplicationDirector extends HierarchyViewerDirector { + + private final ExecutorService executor = Executors.newSingleThreadExecutor(); + + @Override + public void terminate() { + super.terminate(); + executor.shutdown(); + } + + /* + * Gets the location of adb. The script that runs the hierarchy viewer + * defines com.android.hierarchyviewer.bindir. + */ + @Override + public String getAdbLocation() { + String hvParentLocation = System.getProperty("com.android.hierarchyviewer.bindir"); + if (hvParentLocation != null && hvParentLocation.length() != 0) { + return hvParentLocation + File.separator + SdkConstants.FN_ADB; + } + return SdkConstants.FN_ADB; + } + + /* + * In the application, we handle background tasks using a single thread, + * just to get rid of possible race conditions that can occur. We update the + * progress bar to show that we are doing something in the background. + */ + @Override + public void executeInBackground(final Runnable task) { + executor.execute(new Runnable() { + public void run() { + task.run(); + } + }); + } + +} diff --git a/hierarchyviewer2/app/src/com/android/hierarchyviewer/UIThread.java b/hierarchyviewer2/app/src/com/android/hierarchyviewer/UIThread.java new file mode 100644 index 0000000..f59f6c4 --- /dev/null +++ b/hierarchyviewer2/app/src/com/android/hierarchyviewer/UIThread.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2010 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.hierarchyviewer; + +import com.android.ddmuilib.ImageLoader; +import com.android.hierarchyvieweruilib.DeviceSelector; + +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Shell; + +public class UIThread { + public static void runUI() { + Display display = new Display(); + Shell shell = new Shell(display); + shell.setLayout(new FillLayout()); + DeviceSelector deviceSelector = new DeviceSelector(shell); + shell.open(); + while (!shell.isDisposed()) { + if (!display.readAndDispatch()) { + display.sleep(); + } + } + deviceSelector.terminate(); + ImageLoader.dispose(); + display.dispose(); + } +} |