summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/PendingAppWidgetHostView.java
blob: 048e9f8c39b0779500ec8acb031580e56fb274a5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package com.android.launcher3;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;

public class PendingAppWidgetHostView extends LauncherAppWidgetHostView implements OnClickListener {

    int mRestoreStatus;

    private TextView mDefaultView;
    private OnClickListener mClickListener;

    public PendingAppWidgetHostView(Context context, int restoreStatus) {
        super(context);
        mRestoreStatus = restoreStatus;
    }

    @Override
    public void updateAppWidgetSize(Bundle newOptions, int minWidth, int minHeight, int maxWidth,
            int maxHeight) {
        // No-op
    }

    @Override
    protected View getDefaultView() {
        if (mDefaultView == null) {
            mDefaultView = (TextView) mInflater.inflate(R.layout.appwidget_not_ready, this, false);
            mDefaultView.setOnClickListener(this);
            applyState();
        }
        return mDefaultView;
    }

    @Override
    public void setOnClickListener(OnClickListener l) {
        mClickListener = l;
    }

    public void setStatus(int status) {
        if (mRestoreStatus != status) {
            mRestoreStatus = status;
            applyState();
        }
    }

    @Override
    public boolean isReinflateRequired() {
        // Re inflate is required if the the widget is restored.
        return mRestoreStatus == LauncherAppWidgetInfo.RESTORE_COMPLETED;
    }

    private void applyState() {
        if (mDefaultView != null) {
            if (isReadyForClickSetup()) {
                mDefaultView.setText(R.string.gadget_setup_text);
            } else {
                mDefaultView.setText(R.string.gadget_pending_text);
            }
        }
    }

    @Override
    public void onClick(View v) {
        // AppWidgetHostView blocks all click events on the root view. Instead handle click events
        // on the content and pass it along.
        if (mClickListener != null) {
            mClickListener.onClick(this);
        }
    }

    public boolean isReadyForClickSetup() {
        return (mRestoreStatus & LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY) == 0
                && (mRestoreStatus & LauncherAppWidgetInfo.FLAG_UI_NOT_READY) != 0;
    }
}