summaryrefslogtreecommitdiffstats
path: root/mobile/android/base/java/org/mozilla/gecko/firstrun/FirstrunPanel.java
blob: 4b27dbc734ec0c2a811a42e3014057f7402ff8a5 (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
79
80
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: nil; -*-
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

package org.mozilla.gecko.firstrun;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import org.mozilla.gecko.R;
import org.mozilla.gecko.Telemetry;
import org.mozilla.gecko.TelemetryContract;

/**
 * Base class for our first run pages. We call these FirstrunPanel for consistency
 * with HomePager/HomePanel.
 *
 * @see FirstrunPager for the containing pager.
 */
public class FirstrunPanel extends Fragment {

    public static final int TITLE_RES = -1;
    protected boolean showBrowserHint = true;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstance) {
        final ViewGroup root = (ViewGroup) inflater.inflate(R.layout.firstrun_basepanel_checkable_fragment, container, false);
        Bundle args = getArguments();
        if (args != null) {
            final int imageRes = args.getInt(FirstrunPagerConfig.KEY_IMAGE);
            final int textRes = args.getInt(FirstrunPagerConfig.KEY_TEXT);
            final int subtextRes = args.getInt(FirstrunPagerConfig.KEY_SUBTEXT);

            ((ImageView) root.findViewById(R.id.firstrun_image)).setImageResource(imageRes);
            ((TextView) root.findViewById(R.id.firstrun_text)).setText(textRes);
            ((TextView) root.findViewById(R.id.firstrun_subtext)).setText(subtextRes);
        }

        root.findViewById(R.id.firstrun_link).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.BUTTON, "firstrun-next");
                pagerNavigation.next();
            }
        });

        return root;
    }

    public interface PagerNavigation {
        void next();
        void finish();
    }
    protected PagerNavigation pagerNavigation;

    public void setPagerNavigation(PagerNavigation listener) {
        this.pagerNavigation = listener;
    }

    protected void next() {
        if (pagerNavigation != null) {
            pagerNavigation.next();
        }
    }

    protected void close() {
        if (pagerNavigation != null) {
            pagerNavigation.finish();
        }
    }

    protected boolean shouldShowBrowserHint() {
        return showBrowserHint;
    }
}