BaseIWindow.java revision 15a4d2ffd04dc6c70f2cd17dae12ac6bc14c69ab
1/*
2 * Copyright (C) 2009 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.internal.view;
18
19import android.content.res.Configuration;
20import android.graphics.Rect;
21import android.os.Bundle;
22import android.os.ParcelFileDescriptor;
23import android.os.RemoteException;
24import android.view.IWindow;
25import android.view.IWindowSession;
26import android.view.KeyEvent;
27import android.view.MotionEvent;
28
29public class BaseIWindow extends IWindow.Stub {
30    private IWindowSession mSession;
31
32    public void setSession(IWindowSession session) {
33        mSession = session;
34    }
35
36    public void resized(int w, int h, Rect coveredInsets,
37            Rect visibleInsets, boolean reportDraw, Configuration newConfig) {
38        if (reportDraw) {
39            try {
40                mSession.finishDrawing(this);
41            } catch (RemoteException e) {
42            }
43        }
44    }
45
46    public void dispatchKey(KeyEvent event) {
47        try {
48            mSession.finishKey(this);
49        } catch (RemoteException ex) {
50        }
51    }
52
53    public boolean onDispatchPointer(MotionEvent event, long eventTime,
54            boolean callWhenDone) {
55        event.recycle();
56        return false;
57    }
58
59    public void dispatchPointer(MotionEvent event, long eventTime,
60            boolean callWhenDone) {
61        try {
62            if (event == null) {
63                event = mSession.getPendingPointerMove(this);
64                onDispatchPointer(event, eventTime, false);
65            } else if (callWhenDone) {
66                if (!onDispatchPointer(event, eventTime, true)) {
67                    mSession.finishKey(this);
68                }
69            } else {
70                onDispatchPointer(event, eventTime, false);
71            }
72        } catch (RemoteException ex) {
73        }
74    }
75
76    public boolean onDispatchTrackball(MotionEvent event, long eventTime,
77            boolean callWhenDone) {
78        event.recycle();
79        return false;
80    }
81
82    public void dispatchTrackball(MotionEvent event, long eventTime,
83            boolean callWhenDone) {
84        try {
85            if (event == null) {
86                event = mSession.getPendingTrackballMove(this);
87                onDispatchTrackball(event, eventTime, false);
88            } else if (callWhenDone) {
89                if (!onDispatchTrackball(event, eventTime, true)) {
90                    mSession.finishKey(this);
91                }
92            } else {
93                onDispatchTrackball(event, eventTime, false);
94            }
95        } catch (RemoteException ex) {
96        }
97    }
98
99    public void dispatchAppVisibility(boolean visible) {
100    }
101
102    public void dispatchGetNewSurface() {
103    }
104
105    public void windowFocusChanged(boolean hasFocus, boolean touchEnabled) {
106    }
107
108    public void executeCommand(String command, String parameters, ParcelFileDescriptor out) {
109    }
110
111    public void closeSystemDialogs(String reason) {
112    }
113
114    public void dispatchWallpaperOffsets(float x, float y, float xStep, float yStep, boolean sync) {
115        if (sync) {
116            try {
117                mSession.wallpaperOffsetsComplete(asBinder());
118            } catch (RemoteException e) {
119            }
120        }
121    }
122
123    public void dispatchWallpaperCommand(String action, int x, int y,
124            int z, Bundle extras, boolean sync) {
125        if (sync) {
126            try {
127                mSession.wallpaperCommandComplete(asBinder(), null);
128            } catch (RemoteException e) {
129            }
130        }
131    }
132}
133