import FIREFOX_52_6_0esr_RELEASE from mozilla-esr52 hg repo

This commit is contained in:
Roy Tam 2018-01-19 03:59:58 +08:00
commit dcd9973243
150858 changed files with 23884658 additions and 0 deletions

View file

@ -0,0 +1,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;
}
}

View file

@ -0,0 +1,94 @@
/* -*- 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.content.Context;
import android.support.v4.app.FragmentManager;
import android.util.AttributeSet;
import android.view.View;
import android.widget.LinearLayout;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import org.mozilla.gecko.R;
import org.mozilla.gecko.Telemetry;
import org.mozilla.gecko.TelemetryContract;
import org.mozilla.gecko.Experiments;
/**
* A container for the pager and the entire first run experience.
* This is used for animation purposes.
*/
public class FirstrunAnimationContainer extends LinearLayout {
public static final String PREF_FIRSTRUN_ENABLED = "startpane_enabled";
public static interface OnFinishListener {
public void onFinish();
}
private FirstrunPager pager;
private boolean visible;
private OnFinishListener onFinishListener;
public FirstrunAnimationContainer(Context context) {
this(context, null);
}
public FirstrunAnimationContainer(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void load(Context appContext, FragmentManager fm) {
visible = true;
pager = (FirstrunPager) findViewById(R.id.firstrun_pager);
pager.load(appContext, fm, new OnFinishListener() {
@Override
public void onFinish() {
hide();
}
});
}
public boolean isVisible() {
return visible;
}
public void hide() {
visible = false;
if (onFinishListener != null) {
onFinishListener.onFinish();
}
animateHide();
// Stop all versions of firstrun A/B sessions.
Telemetry.stopUISession(TelemetryContract.Session.EXPERIMENT, Experiments.ONBOARDING3_B);
Telemetry.stopUISession(TelemetryContract.Session.EXPERIMENT, Experiments.ONBOARDING3_C);
}
private void animateHide() {
final Animator alphaAnimator = ObjectAnimator.ofFloat(this, "alpha", 0);
alphaAnimator.setDuration(150);
alphaAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
FirstrunAnimationContainer.this.setVisibility(View.GONE);
}
});
alphaAnimator.start();
}
public boolean showBrowserHint() {
final int currentPage = pager.getCurrentItem();
FirstrunPanel currentPanel = (FirstrunPanel) ((FirstrunPager.ViewPagerAdapter) pager.getAdapter()).getItem(currentPage);
pager.cleanup();
return currentPanel.shouldShowBrowserHint();
}
public void registerOnFinishListener(OnFinishListener listener) {
this.onFinishListener = listener;
}
}

View file

@ -0,0 +1,174 @@
/* -*- 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.content.Context;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.animation.Animator;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import org.mozilla.gecko.Telemetry;
import org.mozilla.gecko.TelemetryContract;
import org.mozilla.gecko.home.HomePager.Decor;
import org.mozilla.gecko.home.TabMenuStrip;
import org.mozilla.gecko.restrictions.Restrictions;
import java.util.List;
/**
* ViewPager containing for our first run pages.
*
* @see FirstrunPanel for the first run pages that are used in this pager.
*/
public class FirstrunPager extends ViewPager {
private Context context;
protected FirstrunPanel.PagerNavigation pagerNavigation;
private Decor mDecor;
public FirstrunPager(Context context) {
this(context, null);
}
public FirstrunPager(Context context, AttributeSet attrs) {
super(context, attrs);
this.context = context;
}
@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
if (child instanceof Decor) {
((ViewPager.LayoutParams) params).isDecor = true;
mDecor = (Decor) child;
mDecor.setOnTitleClickListener(new TabMenuStrip.OnTitleClickListener() {
@Override
public void onTitleClicked(int index) {
setCurrentItem(index, true);
}
});
}
super.addView(child, index, params);
}
public void load(Context appContext, FragmentManager fm, final FirstrunAnimationContainer.OnFinishListener onFinishListener) {
final List<FirstrunPagerConfig.FirstrunPanelConfig> panels;
if (Restrictions.isRestrictedProfile(context)) {
panels = FirstrunPagerConfig.getRestricted();
} else {
panels = FirstrunPagerConfig.getDefault(appContext);
}
setAdapter(new ViewPagerAdapter(fm, panels));
this.pagerNavigation = new FirstrunPanel.PagerNavigation() {
@Override
public void next() {
final int currentPage = FirstrunPager.this.getCurrentItem();
if (currentPage < FirstrunPager.this.getAdapter().getCount() - 1) {
FirstrunPager.this.setCurrentItem(currentPage + 1);
}
}
@Override
public void finish() {
if (onFinishListener != null) {
onFinishListener.onFinish();
}
}
};
addOnPageChangeListener(new OnPageChangeListener() {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
mDecor.onPageScrolled(position, positionOffset, positionOffsetPixels);
}
@Override
public void onPageSelected(int i) {
mDecor.onPageSelected(i);
Telemetry.sendUIEvent(TelemetryContract.Event.SHOW, TelemetryContract.Method.PANEL, "onboarding." + i);
}
@Override
public void onPageScrollStateChanged(int i) {}
});
animateLoad();
// Record telemetry for first onboarding panel, for baseline.
Telemetry.sendUIEvent(TelemetryContract.Event.SHOW, TelemetryContract.Method.PANEL, "onboarding.0");
}
public void cleanup() {
setAdapter(null);
}
private void animateLoad() {
setTranslationY(500);
setAlpha(0);
final Animator translateAnimator = ObjectAnimator.ofFloat(this, "translationY", 0);
translateAnimator.setDuration(400);
final Animator alphaAnimator = ObjectAnimator.ofFloat(this, "alpha", 1);
alphaAnimator.setStartDelay(200);
alphaAnimator.setDuration(600);
final AnimatorSet set = new AnimatorSet();
set.playTogether(alphaAnimator, translateAnimator);
set.setStartDelay(400);
set.start();
}
protected class ViewPagerAdapter extends FragmentPagerAdapter {
private final List<FirstrunPagerConfig.FirstrunPanelConfig> panels;
private final Fragment[] fragments;
public ViewPagerAdapter(FragmentManager fm, List<FirstrunPagerConfig.FirstrunPanelConfig> panels) {
super(fm);
this.panels = panels;
this.fragments = new Fragment[panels.size()];
for (FirstrunPagerConfig.FirstrunPanelConfig panel : panels) {
mDecor.onAddPagerView(context.getString(panel.getTitleRes()));
}
if (panels.size() > 0) {
mDecor.onPageSelected(0);
}
}
@Override
public Fragment getItem(int i) {
Fragment fragment = this.fragments[i];
if (fragment == null) {
FirstrunPagerConfig.FirstrunPanelConfig panelConfig = panels.get(i);
fragment = Fragment.instantiate(context, panelConfig.getClassname(), panelConfig.getArgs());
((FirstrunPanel) fragment).setPagerNavigation(pagerNavigation);
fragments[i] = fragment;
}
return fragment;
}
@Override
public int getCount() {
return panels.size();
}
@Override
public CharSequence getPageTitle(int i) {
// Unused now that we use TabMenuStrip.
return context.getString(panels.get(i).getTitleRes()).toUpperCase();
}
}
}

View file

@ -0,0 +1,107 @@
/* -*- 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.content.Context;
import android.os.Bundle;
import android.util.Log;
import org.mozilla.gecko.GeckoSharedPrefs;
import org.mozilla.gecko.R;
import org.mozilla.gecko.Telemetry;
import org.mozilla.gecko.TelemetryContract;
import org.mozilla.gecko.Experiments;
import java.util.LinkedList;
import java.util.List;
public class FirstrunPagerConfig {
public static final String LOGTAG = "FirstrunPagerConfig";
public static final String KEY_IMAGE = "imageRes";
public static final String KEY_TEXT = "textRes";
public static final String KEY_SUBTEXT = "subtextRes";
public static List<FirstrunPanelConfig> getDefault(Context context) {
final List<FirstrunPanelConfig> panels = new LinkedList<>();
if (Experiments.isInExperimentLocal(context, Experiments.ONBOARDING3_B)) {
panels.add(SimplePanelConfigs.urlbarPanelConfig);
panels.add(SimplePanelConfigs.bookmarksPanelConfig);
panels.add(SimplePanelConfigs.dataPanelConfig);
panels.add(SimplePanelConfigs.syncPanelConfig);
panels.add(SimplePanelConfigs.signInPanelConfig);
Telemetry.startUISession(TelemetryContract.Session.EXPERIMENT, Experiments.ONBOARDING3_B);
GeckoSharedPrefs.forProfile(context).edit().putString(Experiments.PREF_ONBOARDING_VERSION, Experiments.ONBOARDING3_B).apply();
} else if (Experiments.isInExperimentLocal(context, Experiments.ONBOARDING3_C)) {
panels.add(SimplePanelConfigs.tabqueuePanelConfig);
panels.add(SimplePanelConfigs.readerviewPanelConfig);
panels.add(SimplePanelConfigs.accountPanelConfig);
Telemetry.startUISession(TelemetryContract.Session.EXPERIMENT, Experiments.ONBOARDING3_C);
GeckoSharedPrefs.forProfile(context).edit().putString(Experiments.PREF_ONBOARDING_VERSION, Experiments.ONBOARDING3_C).apply();
} else {
Log.e(LOGTAG, "Not in an experiment!");
panels.add(SimplePanelConfigs.signInPanelConfig);
}
return panels;
}
public static List<FirstrunPanelConfig> getRestricted() {
final List<FirstrunPanelConfig> panels = new LinkedList<>();
panels.add(new FirstrunPanelConfig(RestrictedWelcomePanel.class.getName(), RestrictedWelcomePanel.TITLE_RES));
return panels;
}
public static class FirstrunPanelConfig {
private String classname;
private int titleRes;
private Bundle args;
public FirstrunPanelConfig(String resource, int titleRes) {
this(resource, titleRes, -1, -1, -1, true);
}
public FirstrunPanelConfig(String classname, int titleRes, int imageRes, int textRes, int subtextRes) {
this(classname, titleRes, imageRes, textRes, subtextRes, false);
}
private FirstrunPanelConfig(String classname, int titleRes, int imageRes, int textRes, int subtextRes, boolean isCustom) {
this.classname = classname;
this.titleRes = titleRes;
if (!isCustom) {
this.args = new Bundle();
this.args.putInt(KEY_IMAGE, imageRes);
this.args.putInt(KEY_TEXT, textRes);
this.args.putInt(KEY_SUBTEXT, subtextRes);
}
}
public String getClassname() {
return this.classname;
}
public int getTitleRes() {
return this.titleRes;
}
public Bundle getArgs() {
return args;
}
}
private static class SimplePanelConfigs {
public static final FirstrunPanelConfig urlbarPanelConfig = new FirstrunPanelConfig(FirstrunPanel.class.getName(), R.string.firstrun_panel_title_welcome, R.drawable.firstrun_urlbar, R.string.firstrun_urlbar_message, R.string.firstrun_urlbar_subtext);
public static final FirstrunPanelConfig bookmarksPanelConfig = new FirstrunPanelConfig(FirstrunPanel.class.getName(), R.string.firstrun_bookmarks_title, R.drawable.firstrun_bookmarks, R.string.firstrun_bookmarks_message, R.string.firstrun_bookmarks_subtext);
public static final FirstrunPanelConfig dataPanelConfig = new FirstrunPanelConfig(DataPanel.class.getName(), R.string.firstrun_data_title, R.drawable.firstrun_data_off, R.string.firstrun_data_message, R.string.firstrun_data_subtext);
public static final FirstrunPanelConfig syncPanelConfig = new FirstrunPanelConfig(FirstrunPanel.class.getName(), R.string.firstrun_sync_title, R.drawable.firstrun_sync, R.string.firstrun_sync_message, R.string.firstrun_sync_subtext);
public static final FirstrunPanelConfig signInPanelConfig = new FirstrunPanelConfig(SyncPanel.class.getName(), R.string.pref_sync, R.drawable.firstrun_signin, R.string.firstrun_signin_message, R.string.firstrun_welcome_button_browser);
public static final FirstrunPanelConfig tabqueuePanelConfig = new FirstrunPanelConfig(TabQueuePanel.class.getName(), R.string.firstrun_tabqueue_title, R.drawable.firstrun_tabqueue_off, R.string.firstrun_tabqueue_message_off, R.string.firstrun_tabqueue_subtext_off);
public static final FirstrunPanelConfig readerviewPanelConfig = new FirstrunPanelConfig(FirstrunPanel.class.getName(), R.string.firstrun_readerview_title, R.drawable.firstrun_readerview, R.string.firstrun_readerview_message, R.string.firstrun_readerview_subtext);
public static final FirstrunPanelConfig accountPanelConfig = new FirstrunPanelConfig(SyncPanel.class.getName(), R.string.firstrun_account_title, R.drawable.firstrun_account, R.string.firstrun_account_message, R.string.firstrun_button_notnow);
}
}

View file

@ -0,0 +1,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;
}
}

View file

@ -0,0 +1,61 @@
/* -*- 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 org.mozilla.gecko.R;
import org.mozilla.gecko.Telemetry;
import org.mozilla.gecko.TelemetryContract;
import org.mozilla.gecko.home.HomePager;
import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import java.util.EnumSet;
public class RestrictedWelcomePanel extends FirstrunPanel {
public static final int TITLE_RES = R.string.firstrun_panel_title_welcome;
private static final String LEARN_MORE_URL = "https://support.mozilla.org/kb/controlledaccess";
private HomePager.OnUrlOpenListener onUrlOpenListener;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
try {
onUrlOpenListener = (HomePager.OnUrlOpenListener) activity;
} catch (ClassCastException e) {
throw new ClassCastException(activity.toString() + " must implement HomePager.OnUrlOpenListener");
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstance) {
final ViewGroup root = (ViewGroup) inflater.inflate(R.layout.restricted_firstrun_welcome_fragment, container, false);
root.findViewById(R.id.welcome_browse).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
close();
}
});
root.findViewById(R.id.learn_more_link).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onUrlOpenListener.onUrlOpen(LEARN_MORE_URL, EnumSet.of(HomePager.OnUrlOpenListener.Flags.ALLOW_SWITCH_TO_TAB));
close();
}
});
return root;
}
}

View file

@ -0,0 +1,61 @@
/* -*- 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.content.Intent;
import android.os.Bundle;
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;
import org.mozilla.gecko.fxa.FxAccountConstants;
import org.mozilla.gecko.fxa.activities.FxAccountWebFlowActivity;
public class SyncPanel extends FirstrunPanel {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstance) {
final ViewGroup root = (ViewGroup) inflater.inflate(R.layout.firstrun_sync_fragment, container, false);
final 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.welcome_browse)).setText(subtextRes);
}
root.findViewById(R.id.welcome_account).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.BUTTON, "firstrun-sync");
showBrowserHint = false;
final Intent intent = new Intent(FxAccountConstants.ACTION_FXA_GET_STARTED);
intent.putExtra(FxAccountWebFlowActivity.EXTRA_ENDPOINT, FxAccountConstants.ENDPOINT_FIRSTRUN);
intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
startActivity(intent);
close();
}
});
root.findViewById(R.id.welcome_browse).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.BUTTON, "firstrun-browser");
close();
}
});
return root;
}
}

View file

@ -0,0 +1,92 @@
/* -*- 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.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.SwitchCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.TextView;
import org.mozilla.gecko.GeckoSharedPrefs;
import org.mozilla.gecko.R;
import org.mozilla.gecko.Telemetry;
import org.mozilla.gecko.TelemetryContract;
import org.mozilla.gecko.preferences.GeckoPreferences;
import org.mozilla.gecko.tabqueue.TabQueueHelper;
import org.mozilla.gecko.tabqueue.TabQueuePrompt;
public class TabQueuePanel extends FirstrunPanel {
private static final int REQUEST_CODE_TAB_QUEUE = 1;
private SwitchCompat toggleSwitch;
private ImageView imageView;
private TextView messageTextView;
private TextView subtextTextView;
private Context context;
@Override
public View onCreateView(LayoutInflater inflater, final ViewGroup container, Bundle savedInstance) {
context = getContext();
final View root = super.onCreateView(inflater, container, savedInstance);
imageView = (ImageView) root.findViewById(R.id.firstrun_image);
messageTextView = (TextView) root.findViewById(R.id.firstrun_text);
subtextTextView = (TextView) root.findViewById(R.id.firstrun_subtext);
toggleSwitch = (SwitchCompat) root.findViewById(R.id.firstrun_switch);
toggleSwitch.setVisibility(View.VISIBLE);
toggleSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.DIALOG, "firstrun_tabqueue-permissions");
if (b && !TabQueueHelper.canDrawOverlays(context)) {
Intent promptIntent = new Intent(context, TabQueuePrompt.class);
startActivityForResult(promptIntent, REQUEST_CODE_TAB_QUEUE);
return;
}
Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.BUTTON, "firstrun-tabqueue-" + b);
final SharedPreferences prefs = GeckoSharedPrefs.forApp(context);
final SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(GeckoPreferences.PREFS_TAB_QUEUE, b).apply();
// Set image, text, and typeface changes.
imageView.setImageResource(b ? R.drawable.firstrun_tabqueue_on : R.drawable.firstrun_tabqueue_off);
messageTextView.setText(b ? R.string.firstrun_tabqueue_message_on : R.string.firstrun_tabqueue_message_off);
messageTextView.setTypeface(b ? Typeface.DEFAULT_BOLD : Typeface.DEFAULT);
subtextTextView.setText(b ? R.string.firstrun_tabqueue_subtext_on : R.string.firstrun_tabqueue_subtext_off);
subtextTextView.setTypeface(b ? Typeface.defaultFromStyle(Typeface.ITALIC) : Typeface.DEFAULT);
subtextTextView.setTextColor(b ? ContextCompat.getColor(context, R.color.fennec_ui_orange) : ContextCompat.getColor(context, R.color.placeholder_grey));
}
});
return root;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
case REQUEST_CODE_TAB_QUEUE:
final boolean accepted = TabQueueHelper.processTabQueuePromptResponse(resultCode, context);
if (accepted) {
Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.DIALOG, "firstrun_tabqueue-permissions-yes");
toggleSwitch.setChecked(true);
Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.BUTTON, "firstrun-tabqueue-true");
}
Telemetry.sendUIEvent(TelemetryContract.Event.ACTION, TelemetryContract.Method.DIALOG, "firstrun_tabqueue-permissions-" + (accepted ? "accepted" : "rejected"));
break;
}
}
}