1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.hierarchyviewerlib.device;
18
19import com.android.ddmlib.IDevice;
20
21/**
22 * Used for storing a window from the window manager service on the device.
23 * These are the windows that the device selector shows.
24 */
25public class Window {
26
27    private String mTitle;
28
29    private int mHashCode;
30
31    private IDevice mDevice;
32
33    public Window(IDevice device, String title, int hashCode) {
34        this.mDevice = device;
35        this.mTitle = title;
36        this.mHashCode = hashCode;
37    }
38
39    public String getTitle() {
40        return mTitle;
41    }
42
43    public int getHashCode() {
44        return mHashCode;
45    }
46
47    public String encode() {
48        return Integer.toHexString(mHashCode);
49    }
50
51    @Override
52    public String toString() {
53        return mTitle;
54    }
55
56    public IDevice getDevice() {
57        return mDevice;
58    }
59
60    public static Window getFocusedWindow(IDevice device) {
61        return new Window(device, "<Focused Window>", -1);
62    }
63
64    /*
65     * After each refresh of the windows in the device selector, the windows are
66     * different instances and automatically reselecting the same window doesn't
67     * work in the device selector unless the equals method is defined here.
68     */
69    @Override
70    public boolean equals(Object other) {
71        if (other instanceof Window) {
72            return mHashCode == ((Window) other).mHashCode
73                    && mDevice.getSerialNumber().equals(((Window) other).mDevice.getSerialNumber());
74        }
75        return false;
76    }
77}
78