blob: d77138b0a866d97f9e962e03a76c9cd10aa52a17 [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
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 Onoratoa5902522009-07-30 13:37:37 -070018package com.android.launcher2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080019
The Android Open Source Project31dd5032009-03-03 19:32:27 -080020import android.content.Context;
21import android.content.res.TypedArray;
22import android.util.AttributeSet;
Joe Onorato7bb17492009-09-24 17:51:01 -070023import android.view.MotionEvent;
Joe Onorato7bb17492009-09-24 17:51:01 -070024import android.view.View;
Michael Jurka4d596492012-01-16 06:43:49 -080025import android.widget.ImageView;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080026
Romain Guyedcce092010-03-04 13:03:17 -080027import com.android.launcher.R;
28
The Android Open Source Project31dd5032009-03-03 19:32:27 -080029public class HandleView extends ImageView {
30 private static final int ORIENTATION_HORIZONTAL = 1;
31
32 private Launcher mLauncher;
33 private int mOrientation = ORIENTATION_HORIZONTAL;
34
35 public HandleView(Context context) {
36 super(context);
37 }
38
39 public HandleView(Context context, AttributeSet attrs) {
40 this(context, attrs, 0);
41 }
42
43 public HandleView(Context context, AttributeSet attrs, int defStyle) {
44 super(context, attrs, defStyle);
45
46 TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.HandleView, defStyle, 0);
47 mOrientation = a.getInt(R.styleable.HandleView_direction, ORIENTATION_HORIZONTAL);
48 a.recycle();
Joe Onorato52a653f2009-11-11 14:52:11 -080049
50 setContentDescription(context.getString(R.string.all_apps_button_label));
The Android Open Source Project31dd5032009-03-03 19:32:27 -080051 }
52
53 @Override
54 public View focusSearch(int direction) {
55 View newFocus = super.focusSearch(direction);
Joe Onorato67886212009-09-14 19:05:05 -040056 if (newFocus == null && !mLauncher.isAllAppsVisible()) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080057 final Workspace workspace = mLauncher.getWorkspace();
58 workspace.dispatchUnhandledMove(null, direction);
59 return (mOrientation == ORIENTATION_HORIZONTAL && direction == FOCUS_DOWN) ?
60 this : workspace;
61 }
62 return newFocus;
63 }
64
65 @Override
Joe Onorato7bb17492009-09-24 17:51:01 -070066 public boolean onTouchEvent(MotionEvent ev) {
67 if (ev.getAction() == MotionEvent.ACTION_DOWN && mLauncher.isAllAppsVisible()) {
68 return false;
69 }
70 return super.onTouchEvent(ev);
71 }
72
The Android Open Source Project31dd5032009-03-03 19:32:27 -080073 void setLauncher(Launcher launcher) {
74 mLauncher = launcher;
75 }
76}