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; |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 24 | import android.view.MotionEvent; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 25 | import android.view.KeyEvent; |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 26 | import android.view.View; |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 27 | |
Romain Guy | edcce09 | 2010-03-04 13:03:17 -0800 | [diff] [blame] | 28 | import com.android.launcher.R; |
| 29 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 30 | public class HandleView extends ImageView { |
| 31 | private static final int ORIENTATION_HORIZONTAL = 1; |
| 32 | |
| 33 | private Launcher mLauncher; |
| 34 | private int mOrientation = ORIENTATION_HORIZONTAL; |
| 35 | |
| 36 | public HandleView(Context context) { |
| 37 | super(context); |
| 38 | } |
| 39 | |
| 40 | public HandleView(Context context, AttributeSet attrs) { |
| 41 | this(context, attrs, 0); |
| 42 | } |
| 43 | |
| 44 | public HandleView(Context context, AttributeSet attrs, int defStyle) { |
| 45 | super(context, attrs, defStyle); |
| 46 | |
| 47 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.HandleView, defStyle, 0); |
| 48 | mOrientation = a.getInt(R.styleable.HandleView_direction, ORIENTATION_HORIZONTAL); |
| 49 | a.recycle(); |
Joe Onorato | 52a653f | 2009-11-11 14:52:11 -0800 | [diff] [blame] | 50 | |
| 51 | setContentDescription(context.getString(R.string.all_apps_button_label)); |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public View focusSearch(int direction) { |
| 56 | View newFocus = super.focusSearch(direction); |
Joe Onorato | 6788621 | 2009-09-14 19:05:05 -0400 | [diff] [blame] | 57 | if (newFocus == null && !mLauncher.isAllAppsVisible()) { |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 58 | final Workspace workspace = mLauncher.getWorkspace(); |
| 59 | workspace.dispatchUnhandledMove(null, direction); |
| 60 | return (mOrientation == ORIENTATION_HORIZONTAL && direction == FOCUS_DOWN) ? |
| 61 | this : workspace; |
| 62 | } |
| 63 | return newFocus; |
| 64 | } |
| 65 | |
| 66 | @Override |
Joe Onorato | 7bb1749 | 2009-09-24 17:51:01 -0700 | [diff] [blame] | 67 | public boolean onTouchEvent(MotionEvent ev) { |
| 68 | if (ev.getAction() == MotionEvent.ACTION_DOWN && mLauncher.isAllAppsVisible()) { |
| 69 | return false; |
| 70 | } |
| 71 | return super.onTouchEvent(ev); |
| 72 | } |
| 73 | |
The Android Open Source Project | 31dd503 | 2009-03-03 19:32:27 -0800 | [diff] [blame] | 74 | private static boolean isDirectionKey(int keyCode) { |
| 75 | return keyCode == KeyEvent.KEYCODE_DPAD_DOWN || keyCode == KeyEvent.KEYCODE_DPAD_LEFT || |
| 76 | keyCode == KeyEvent.KEYCODE_DPAD_RIGHT || keyCode == KeyEvent.KEYCODE_DPAD_UP; |
| 77 | } |
| 78 | |
| 79 | void setLauncher(Launcher launcher) { |
| 80 | mLauncher = launcher; |
| 81 | } |
| 82 | } |