blob: 9970c767586190e5aacd0ce0d6318056fa0a4969 [file] [log] [blame]
The Android Open Source Project31dd5032009-03-03 19:32:27 -08001/*
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
Joe Onoratoa5902522009-07-30 13:37:37 -070017package com.android.launcher2;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080018
The Android Open Source Project7376fae2009-03-11 12:11:58 -070019import android.appwidget.AppWidgetHostView;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080020import android.content.Context;
Adam Cohen06dff352012-06-01 17:17:08 -070021import android.content.res.Configuration;
22import android.os.Bundle;
23import android.os.Parcel;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080024import android.view.LayoutInflater;
25import android.view.MotionEvent;
26import android.view.View;
Winson Chung97d85d22011-04-13 11:27:36 -070027import android.view.ViewGroup;
Adam Cohen06dff352012-06-01 17:17:08 -070028import android.widget.RemoteViews;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080029
Romain Guyedcce092010-03-04 13:03:17 -080030import com.android.launcher.R;
31
The Android Open Source Project31dd5032009-03-03 19:32:27 -080032/**
33 * {@inheritDoc}
34 */
Michael Jurka08ee7702011-08-11 16:53:35 -070035public class LauncherAppWidgetHostView extends AppWidgetHostView {
Winson Chung88f33452012-02-23 15:23:44 -080036 private CheckLongPressHelper mLongPressHelper;
The Android Open Source Project31dd5032009-03-03 19:32:27 -080037 private LayoutInflater mInflater;
Adam Cohen06dff352012-06-01 17:17:08 -070038 private Context mContext;
39 private int mPreviousOrientation;
Michael Jurka99b6a5b2011-01-07 15:37:17 -080040
The Android Open Source Project7376fae2009-03-11 12:11:58 -070041 public LauncherAppWidgetHostView(Context context) {
The Android Open Source Project31dd5032009-03-03 19:32:27 -080042 super(context);
Adam Cohen06dff352012-06-01 17:17:08 -070043 mContext = context;
Winson Chung88f33452012-02-23 15:23:44 -080044 mLongPressHelper = new CheckLongPressHelper(this);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080045 mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
46 }
Adam Cohen41d5d6d2011-05-31 15:52:28 -070047
The Android Open Source Project31dd5032009-03-03 19:32:27 -080048 @Override
49 protected View getErrorView() {
The Android Open Source Project7376fae2009-03-11 12:11:58 -070050 return mInflater.inflate(R.layout.appwidget_error, this, false);
The Android Open Source Project31dd5032009-03-03 19:32:27 -080051 }
52
Adam Cohen06dff352012-06-01 17:17:08 -070053 @Override
54 public void updateAppWidget(RemoteViews remoteViews) {
55 // Store the orientation in which the widget was inflated
56 mPreviousOrientation = mContext.getResources().getConfiguration().orientation;
57 super.updateAppWidget(remoteViews);
58 }
59
60 public boolean orientationChangedSincedInflation() {
61 int orientation = mContext.getResources().getConfiguration().orientation;
62 if (mPreviousOrientation != orientation) {
63 return true;
64 }
65 return false;
66 }
67
The Android Open Source Project31dd5032009-03-03 19:32:27 -080068 public boolean onInterceptTouchEvent(MotionEvent ev) {
69 // Consume any touch events for ourselves after longpress is triggered
Winson Chung88f33452012-02-23 15:23:44 -080070 if (mLongPressHelper.hasPerformedLongPress()) {
71 mLongPressHelper.cancelLongPress();
The Android Open Source Project31dd5032009-03-03 19:32:27 -080072 return true;
73 }
Adam Cohen19072da2011-05-31 14:30:45 -070074
The Android Open Source Project31dd5032009-03-03 19:32:27 -080075 // Watch for longpress events at this level to make sure
The Android Open Source Project7376fae2009-03-11 12:11:58 -070076 // users can always pick up this widget
The Android Open Source Project31dd5032009-03-03 19:32:27 -080077 switch (ev.getAction()) {
78 case MotionEvent.ACTION_DOWN: {
Winson Chung88f33452012-02-23 15:23:44 -080079 mLongPressHelper.postCheckForLongPress();
The Android Open Source Project31dd5032009-03-03 19:32:27 -080080 break;
81 }
Adam Cohen19072da2011-05-31 14:30:45 -070082
The Android Open Source Project31dd5032009-03-03 19:32:27 -080083 case MotionEvent.ACTION_UP:
84 case MotionEvent.ACTION_CANCEL:
Winson Chung88f33452012-02-23 15:23:44 -080085 mLongPressHelper.cancelLongPress();
The Android Open Source Project31dd5032009-03-03 19:32:27 -080086 break;
87 }
Adam Cohen19072da2011-05-31 14:30:45 -070088
The Android Open Source Project31dd5032009-03-03 19:32:27 -080089 // Otherwise continue letting touch events fall through to children
90 return false;
91 }
Adam Cohend4844c32011-02-18 19:25:06 -080092
Jeff Sharkey83f111d2009-04-20 21:03:13 -070093 @Override
94 public void cancelLongPress() {
95 super.cancelLongPress();
96
Winson Chung88f33452012-02-23 15:23:44 -080097 mLongPressHelper.cancelLongPress();
Jeff Sharkey83f111d2009-04-20 21:03:13 -070098 }
Michael Jurka99b6a5b2011-01-07 15:37:17 -080099
Winson Chung97d85d22011-04-13 11:27:36 -0700100 @Override
101 public int getDescendantFocusability() {
102 return ViewGroup.FOCUS_BLOCK_DESCENDANTS;
103 }
The Android Open Source Project31dd5032009-03-03 19:32:27 -0800104}