Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: mobile/android/thirdparty/org/adblockplus/browser/StartPane.java

Issue 29341330: Issue 3135 - Show the first run slide about the beta community to users that installed via Play and… (Closed)
Patch Set: Created May 12, 2016, 3:21 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details. 12 * GNU General Public License for more details.
13 * 13 *
14 * You should have received a copy of the GNU General Public License 14 * You should have received a copy of the GNU General Public License
15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
16 */ 16 */
17 17
18 package org.adblockplus.browser; 18 package org.adblockplus.browser;
19 19
20 import java.io.File; 20 import java.io.File;
21 import java.io.FileOutputStream; 21 import java.io.FileOutputStream;
22 import java.io.IOException; 22 import java.io.IOException;
23 import java.io.InputStream; 23 import java.io.InputStream;
24 import java.util.ArrayList; 24 import java.util.ArrayList;
25 import java.util.HashMap; 25 import java.util.HashMap;
26 import java.util.List; 26 import java.util.List;
27 import java.util.Map; 27 import java.util.Map;
28 28
29 import org.mozilla.gecko.AppConstants;
29 import org.mozilla.gecko.R; 30 import org.mozilla.gecko.R;
30 31
31 import android.content.Context; 32 import android.content.Context;
32 import android.content.DialogInterface; 33 import android.content.DialogInterface;
33 import android.content.DialogInterface.OnKeyListener; 34 import android.content.DialogInterface.OnKeyListener;
34 import android.graphics.Typeface; 35 import android.graphics.Typeface;
35 import android.os.Bundle; 36 import android.os.Bundle;
36 import android.support.v4.app.DialogFragment; 37 import android.support.v4.app.DialogFragment;
37 import android.util.Log; 38 import android.util.Log;
38 import android.view.KeyEvent; 39 import android.view.KeyEvent;
39 import android.view.LayoutInflater; 40 import android.view.LayoutInflater;
40 import android.view.View; 41 import android.view.View;
41 import android.view.View.OnClickListener; 42 import android.view.View.OnClickListener;
42 import android.view.ViewGroup; 43 import android.view.ViewGroup;
43 import android.view.ViewGroup.LayoutParams; 44 import android.view.ViewGroup.LayoutParams;
44 import android.view.Window; 45 import android.view.Window;
45 import android.widget.Button; 46 import android.widget.Button;
46 import android.widget.LinearLayout; 47 import android.widget.LinearLayout;
47 import android.widget.TextView; 48 import android.widget.TextView;
48 49
49 public class StartPane extends DialogFragment implements OnClickListener, OnKeyL istener 50 public class StartPane extends DialogFragment implements OnClickListener, OnKeyL istener
50 { 51 {
51 private static final String TAG = "AdblockBrowser.StartPane"; 52 private static final String TAG = "AdblockBrowser.StartPane";
52 private int currentStep = 0; 53 private int currentStep = 0;
53 // For now we disable the beta community page,
54 // see https://issues.adblockplus.org/ticket/2937 for a follow-up issue
55 // for detecting whether we are on the beta channel or not
56 private static final boolean SKIP_BETA_COMMUNITY_PAGE = true;
57 private static final HashMap<String, Integer> FONTS = new HashMap<String, Inte ger>(); 54 private static final HashMap<String, Integer> FONTS = new HashMap<String, Inte ger>();
58 private HashMap<String, Typeface> loadedFonts = new HashMap<String, Typeface>( ); 55 private HashMap<String, Typeface> loadedFonts = new HashMap<String, Typeface>( );
59 56
60 private static final int[] BETA_RESOURCE_LIST = 57 private static final int[] BETA_RESOURCE_LIST =
61 { 58 {
62 R.layout.abb_start_pane_step_1, R.string.abb_frp_button_1, 59 R.layout.abb_start_pane_step_1, R.string.abb_frp_button_1,
63 R.layout.abb_start_pane_step_2, R.string.abb_frp_button_2, 60 R.layout.abb_start_pane_step_2, R.string.abb_frp_button_2,
64 R.layout.abb_start_pane_step_3, R.string.abb_frp_button_3 61 R.layout.abb_start_pane_step_3, R.string.abb_frp_button_3
65 }; 62 };
66 63
67 private static final int[] RELEASE_RESOURCE_LIST = 64 private static final int[] RELEASE_RESOURCE_LIST =
68 { 65 {
69 R.layout.abb_start_pane_step_1, R.string.abb_frp_button_2, 66 R.layout.abb_start_pane_step_1, R.string.abb_frp_button_2,
70 R.layout.abb_start_pane_step_2, R.string.abb_frp_button_3 67 R.layout.abb_start_pane_step_2, R.string.abb_frp_button_3
71 }; 68 };
72 69
73 private static final int[] PAGES_RESOURCE_LIST = SKIP_BETA_COMMUNITY_PAGE ? 70 private int[] pagesResourceList;
74 RELEASE_RESOURCE_LIST : BETA_RESOURCE_LIST;
75 71
76 static 72 static
77 { 73 {
78 FONTS.put("ttf_opensans_light", R.raw.opensans_light); 74 FONTS.put("ttf_opensans_light", R.raw.opensans_light);
79 FONTS.put("ttf_opensans_semibold", R.raw.opensans_semibold); 75 FONTS.put("ttf_opensans_semibold", R.raw.opensans_semibold);
80 } 76 }
81 77
82 static Typeface typefaceFromResource(final Context context, final int resId) 78 static Typeface typefaceFromResource(final Context context, final int resId)
83 { 79 {
84 Typeface ret = null; 80 Typeface ret = null;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
117 for (Map.Entry<String, Integer> e : FONTS.entrySet()) 113 for (Map.Entry<String, Integer> e : FONTS.entrySet())
118 { 114 {
119 final Typeface t = typefaceFromResource(context, e.getValue().intValue()); 115 final Typeface t = typefaceFromResource(context, e.getValue().intValue());
120 if (t != null) 116 if (t != null)
121 { 117 {
122 this.loadedFonts.put(e.getKey(), t); 118 this.loadedFonts.put(e.getKey(), t);
123 } 119 }
124 } 120 }
125 } 121 }
126 122
123 private void loadPagesResources()
124 {
125 final boolean useBetaResourceList = !AppConstants.ABB_RELEASE_BUILD && Brows erAppUtils.wasInstalledFromPlayStore(getContext());
126 this.pagesResourceList = useBetaResourceList ? BETA_RESOURCE_LIST : RELEASE_ RESOURCE_LIST;
127 }
128
127 @Override 129 @Override
128 public void onCreate(Bundle savedInstanceState) 130 public void onCreate(Bundle savedInstanceState)
129 { 131 {
130 super.onCreate(savedInstanceState); 132 super.onCreate(savedInstanceState);
133
134 this.loadPagesResources();
131 this.setStyle(DialogFragment.STYLE_NO_TITLE, 0); 135 this.setStyle(DialogFragment.STYLE_NO_TITLE, 0);
132 this.loadTypefaces(); 136 this.loadTypefaces();
133 } 137 }
134 138
135 @Override 139 @Override
136 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) 140 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle)
137 { 141 {
138 final View view = inflater.inflate(R.layout.abb_start_pane, container, false ); 142 final View view = inflater.inflate(R.layout.abb_start_pane, container, false );
139 143
140 this.updateContents(view); 144 this.updateContents(view);
(...skipping 10 matching lines...) Expand all
151 super.onActivityCreated(savedInstanceState); 155 super.onActivityCreated(savedInstanceState);
152 final Window window = getDialog().getWindow(); 156 final Window window = getDialog().getWindow();
153 window.setBackgroundDrawable(null); 157 window.setBackgroundDrawable(null);
154 window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); 158 window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
155 } 159 }
156 160
157 @Override 161 @Override
158 public void onClick(View v) 162 public void onClick(View v)
159 { 163 {
160 final int nextStep = this.currentStep + 1; 164 final int nextStep = this.currentStep + 1;
161 if (nextStep * 2 < PAGES_RESOURCE_LIST.length) 165 if (nextStep * 2 < this.pagesResourceList.length)
162 { 166 {
163 this.currentStep = nextStep; 167 this.currentStep = nextStep;
164 this.updateContents(this.getView()); 168 this.updateContents(this.getView());
165 } 169 }
166 else 170 else
167 { 171 {
168 this.dismissAllowingStateLoss(); 172 this.dismissAllowingStateLoss();
169 } 173 }
170 } 174 }
171 175
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
205 } 209 }
206 } 210 }
207 211
208 private void updateContents(final View view) 212 private void updateContents(final View view)
209 { 213 {
210 final LinearLayout ll = (LinearLayout) view.findViewById(R.id.abb_main_conte nt); 214 final LinearLayout ll = (LinearLayout) view.findViewById(R.id.abb_main_conte nt);
211 ll.removeAllViews(); 215 ll.removeAllViews();
212 216
213 final LayoutInflater inflater = (LayoutInflater) this.getActivity() 217 final LayoutInflater inflater = (LayoutInflater) this.getActivity()
214 .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 218 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
215 inflater.inflate(PAGES_RESOURCE_LIST[this.currentStep * 2], ll, true); 219 inflater.inflate(this.pagesResourceList[this.currentStep * 2], ll, true);
216 this.setButtonText(view, R.id.abb_frp_button, PAGES_RESOURCE_LIST[this.curre ntStep * 2 + 1]); 220 this.setButtonText(view, R.id.abb_frp_button, this.pagesResourceList[this.cu rrentStep * 2 + 1]);
217 221
218 final List<View> views = listViews(view); 222 final List<View> views = listViews(view);
219 for (View v : views) 223 for (View v : views)
220 { 224 {
221 final Object tag = v.getTag(); 225 final Object tag = v.getTag();
222 if (tag != null) 226 if (tag != null)
223 { 227 {
224 Typeface t = this.loadedFonts.get(tag.toString()); 228 Typeface t = this.loadedFonts.get(tag.toString());
225 if (t != null) 229 if (t != null)
226 { 230 {
227 if (v instanceof TextView) 231 if (v instanceof TextView)
228 { 232 {
229 ((TextView) v).setTypeface(t); 233 ((TextView) v).setTypeface(t);
230 } 234 }
231 else if (v instanceof Button) 235 else if (v instanceof Button)
232 { 236 {
233 ((Button) v).setTypeface(t); 237 ((Button) v).setTypeface(t);
234 } 238 }
235 } 239 }
236 } 240 }
237 } 241 }
238 } 242 }
239 243
240 private void setButtonText(final View view, final int viewId, final int resId) 244 private void setButtonText(final View view, final int viewId, final int resId)
241 { 245 {
242 final Button button = (Button) view.findViewById(viewId); 246 final Button button = (Button) view.findViewById(viewId);
243 button.setText(this.getString(resId)); 247 button.setText(this.getString(resId));
244 } 248 }
245 } 249 }
OLDNEW

Powered by Google App Engine
This is Rietveld