The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 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 | |
| 17 | |
Joe Onorato | a590252 | 2009-07-30 13:37:37 -0700 | [diff] [blame] | 18 | package com.android.launcher2; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 19 | |
| 20 | import android.widget.ImageView; |
| 21 | import android.content.Context; |
| 22 | import android.content.res.TypedArray; |
| 23 | import android.util.AttributeSet; |
| 24 | import android.view.View; |
| 25 | import android.view.KeyEvent; |
| 26 | |
| 27 | public class HandleView extends ImageView { |
| 28 | private static final int ORIENTATION_HORIZONTAL = 1; |
| 29 | |
| 30 | private Launcher mLauncher; |
| 31 | private int mOrientation = ORIENTATION_HORIZONTAL; |
| 32 | |
| 33 | public HandleView(Context context) { |
| 34 | super(context); |
| 35 | } |
| 36 | |
| 37 | public HandleView(Context context, AttributeSet attrs) { |
| 38 | this(context, attrs, 0); |
| 39 | } |
| 40 | |
| 41 | public HandleView(Context context, AttributeSet attrs, int defStyle) { |
| 42 | super(context, attrs, defStyle); |
| 43 | |
| 44 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.HandleView, defStyle, 0); |
| 45 | mOrientation = a.getInt(R.styleable.HandleView_direction, ORIENTATION_HORIZONTAL); |
| 46 | a.recycle(); |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public View focusSearch(int direction) { |
| 51 | View newFocus = super.focusSearch(direction); |
Joe Onorato | 6788621 | 2009-09-14 19:05:05 -0400 | [diff] [blame] | 52 | if (newFocus == null && !mLauncher.isAllAppsVisible()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 53 | final Workspace workspace = mLauncher.getWorkspace(); |
| 54 | workspace.dispatchUnhandledMove(null, direction); |
| 55 | return (mOrientation == ORIENTATION_HORIZONTAL && direction == FOCUS_DOWN) ? |
| 56 | this : workspace; |
| 57 | } |
| 58 | return newFocus; |
| 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public boolean onKeyDown(int keyCode, KeyEvent event) { |
| 63 | final boolean handled = super.onKeyDown(keyCode, event); |
| 64 | |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 65 | /* TODO |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 66 | if (!handled && !mLauncher.isDrawerDown() && !isDirectionKey(keyCode)) { |
| 67 | return mLauncher.getApplicationsGrid().onKeyDown(keyCode, event); |
| 68 | } |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 69 | */ |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 70 | |
| 71 | return handled; |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public boolean onKeyUp(int keyCode, KeyEvent event) { |
| 76 | final boolean handled = super.onKeyUp(keyCode, event); |
| 77 | |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 78 | /* TODO |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 79 | if (!handled && !mLauncher.isDrawerDown() && !isDirectionKey(keyCode)) { |
| 80 | return mLauncher.getApplicationsGrid().onKeyUp(keyCode, event); |
| 81 | } |
Joe Onorato | 7404ee4 | 2009-07-31 11:54:44 -0700 | [diff] [blame] | 82 | */ |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 83 | |
| 84 | return handled; |
| 85 | } |
| 86 | |
| 87 | private static boolean isDirectionKey(int keyCode) { |
| 88 | return keyCode == KeyEvent.KEYCODE_DPAD_DOWN || keyCode == KeyEvent.KEYCODE_DPAD_LEFT || |
| 89 | keyCode == KeyEvent.KEYCODE_DPAD_RIGHT || keyCode == KeyEvent.KEYCODE_DPAD_UP; |
| 90 | } |
| 91 | |
| 92 | void setLauncher(Launcher launcher) { |
| 93 | mLauncher = launcher; |
| 94 | } |
| 95 | } |