summaryrefslogtreecommitdiffstats
path: root/mobile/android/base/java/org/mozilla/gecko/firstrun/DataPanel.java
blob: d5940d7581fbf52dd37525a1b95bee13286a1c5c (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
/* -*- 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.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import org.mozilla.gecko.GeckoSharedPrefs;
import org.mozilla.gecko.PrefsHelper;
import org.mozilla.gecko.R;
import org.mozilla.gecko.Telemetry;
import org.mozilla.gecko.TelemetryContract;

public class DataPanel extends FirstrunPanel {
    private boolean isEnabled = false;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstance) {
        final View root = super.onCreateView(inflater, container, savedInstance);
        final ImageView clickableImage = (ImageView) root.findViewById(R.id.firstrun_image);
        clickableImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                // Set new state.
                isEnabled = !isEnabled;
                int newResource = isEnabled ? R.drawable.firstrun_data_on : R.drawable.firstrun_data_off;
                ((ImageView) view).setImageResource(newResource);
                if (isEnabled) {
                    // Always block images.
                    PrefsHelper.setPref("browser.image_blocking", 0);
                } else {
                    // Default: always load images.
                    PrefsHelper.setPref("browser.image_blocking", 1);
                }
                Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.BUTTON, "firstrun-datasaving-" + isEnabled);
            }
        });

        return root;
    }
}