1/*
2 * Copyright (C) 2015 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.systemui.recents;
18
19import android.appwidget.AppWidgetHostView;
20import android.content.Context;
21import android.view.View;
22import android.widget.RemoteViews;
23
24public class RecentsAppWidgetHostView extends AppWidgetHostView {
25
26    private Context mContext;
27    private int mPreviousOrientation;
28
29    public RecentsAppWidgetHostView(Context context) {
30        super(context);
31        mContext = context;
32    }
33
34    @Override
35    public void updateAppWidget(RemoteViews remoteViews) {
36        // Store the orientation in which the widget was inflated
37        updateLastInflationOrientation();
38        super.updateAppWidget(remoteViews);
39    }
40
41    @Override
42    protected View getErrorView() {
43        // Just return an empty view as the error view when failing to inflate the Recents search
44        // bar widget (this is mainly to catch the case where we try and inflate the widget view
45        // while the search provider is updating)
46        return new View(mContext);
47    }
48
49    /**
50     * Updates the last orientation that this widget was inflated.
51     */
52    private void updateLastInflationOrientation() {
53        mPreviousOrientation = mContext.getResources().getConfiguration().orientation;
54    }
55
56    /**
57     * @return whether the search widget was updated while Recents was in a different orientation
58     *         in the background.
59     */
60    public boolean isReinflateRequired() {
61        // Re-inflate is required if the orientation has changed since last inflated.
62        int orientation = mContext.getResources().getConfiguration().orientation;
63        if (mPreviousOrientation != orientation) {
64            return true;
65        }
66        return false;
67    }
68}
69