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

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

Issue 6296160390086656: Issue 2491 - Fix design elements in onboarding slides (Closed)
Patch Set: Created May 21, 2015, 1:38 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
« no previous file with comments | « mobile/android/base/strings.xml.in ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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;
21 import java.io.FileOutputStream;
22 import java.io.IOException;
23 import java.io.InputStream;
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.List;
27 import java.util.Map;
28
20 import org.mozilla.gecko.R; 29 import org.mozilla.gecko.R;
21 30
22 import android.content.Context; 31 import android.content.Context;
23 import android.content.DialogInterface; 32 import android.content.DialogInterface;
24 import android.content.DialogInterface.OnKeyListener; 33 import android.content.DialogInterface.OnKeyListener;
34 import android.graphics.Typeface;
25 import android.os.Bundle; 35 import android.os.Bundle;
26 import android.support.v4.app.DialogFragment; 36 import android.support.v4.app.DialogFragment;
27 import android.text.Html; 37 import android.text.Html;
38 import android.util.Log;
28 import android.view.KeyEvent; 39 import android.view.KeyEvent;
29 import android.view.LayoutInflater; 40 import android.view.LayoutInflater;
30 import android.view.View; 41 import android.view.View;
31 import android.view.View.OnClickListener; 42 import android.view.View.OnClickListener;
32 import android.view.ViewGroup; 43 import android.view.ViewGroup;
33 import android.view.ViewGroup.LayoutParams; 44 import android.view.ViewGroup.LayoutParams;
34 import android.view.Window; 45 import android.view.Window;
35 import android.widget.Button; 46 import android.widget.Button;
36 import android.widget.LinearLayout; 47 import android.widget.LinearLayout;
37 import android.widget.TextView; 48 import android.widget.TextView;
38 49
39 public class StartPane extends DialogFragment implements OnClickListener, OnKeyL istener 50 public class StartPane extends DialogFragment implements OnClickListener, OnKeyL istener
40 { 51 {
41 private static final String TAG = "AdblockBrowser.StartPane"; 52 private static final String TAG = "AdblockBrowser.StartPane";
42 private int currentStep = 1; 53 private int currentStep = 1;
43 private static final int NUMBER_OF_STEPS = 3; 54 private static final int NUMBER_OF_STEPS = 3;
55 private static final HashMap<String, Integer> FONTS = new HashMap<String, Inte ger>();
56 private HashMap<String, Typeface> loadedFonts = new HashMap<String, Typeface>( );
57
58 static
59 {
60 FONTS.put("ttf_opensans_light", R.raw.opensans_light);
61 FONTS.put("ttf_opensans_semibold", R.raw.opensans_semibold);
62 }
63
64 static Typeface typefaceFromResource(final Context context, final int resId)
65 {
66 Typeface ret = null;
67 try
68 {
69 context.getCacheDir().mkdir();
70 final File output = File.createTempFile("abb_font", ".ttf");
71 final byte[] buffer = new byte[4096];
72 final InputStream in = context.getResources().openRawResource(resId);
73 final FileOutputStream out = new FileOutputStream(output);
74 for (;;)
75 {
76 final int read = in.read(buffer);
77 if (read < 0)
78 {
79 break;
80 }
81 out.write(buffer, 0, read);
82 }
83 in.close();
84 out.close();
85 ret = Typeface.createFromFile(output);
86 output.delete();
87 }
88 catch (IOException e)
89 {
90 Log.e(TAG, "Failed to load typeface: " + e.getMessage(), e);
91 }
92 return ret;
93 }
94
95 private void loadTypefaces()
96 {
97 final Context context = this.getActivity();
98 this.loadedFonts.clear();
99 for (Map.Entry<String, Integer> e : FONTS.entrySet())
100 {
101 final Typeface t = typefaceFromResource(context, e.getValue().intValue());
102 if (t != null)
103 {
104 this.loadedFonts.put(e.getKey(), t);
105 }
106 }
107 }
44 108
45 @Override 109 @Override
46 public void onCreate(Bundle savedInstanceState) 110 public void onCreate(Bundle savedInstanceState)
47 { 111 {
48 super.onCreate(savedInstanceState); 112 super.onCreate(savedInstanceState);
49 this.setStyle(DialogFragment.STYLE_NO_TITLE, 0); 113 this.setStyle(DialogFragment.STYLE_NO_TITLE, 0);
114 this.loadTypefaces();
50 } 115 }
51 116
52 @Override 117 @Override
53 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) 118 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle)
54 { 119 {
55 final View view = inflater.inflate(R.layout.abb_start_pane, container, false ); 120 final View view = inflater.inflate(R.layout.abb_start_pane, container, false );
56 121
57 this.setTextViewTextHtml(view, R.id.abb_app_title, "Adblock <b>Browser</b>") ;
58 this.updateContents(view); 122 this.updateContents(view);
59 123
60 this.getDialog().setOnKeyListener(this); 124 this.getDialog().setOnKeyListener(this);
61 ((Button) view.findViewById(R.id.abb_frp_button)).setOnClickListener(this); 125 ((Button) view.findViewById(R.id.abb_frp_button)).setOnClickListener(this);
62 126
63 return view; 127 return view;
64 } 128 }
65 129
66 @Override 130 @Override
67 public void onActivityCreated(Bundle savedInstanceState) 131 public void onActivityCreated(Bundle savedInstanceState)
(...skipping 26 matching lines...) Expand all
94 if (event.getAction() == KeyEvent.ACTION_DOWN && this.currentStep > 1) 158 if (event.getAction() == KeyEvent.ACTION_DOWN && this.currentStep > 1)
95 { 159 {
96 this.currentStep--; 160 this.currentStep--;
97 this.updateContents(this.getView()); 161 this.updateContents(this.getView());
98 } 162 }
99 return true; 163 return true;
100 } 164 }
101 return false; 165 return false;
102 } 166 }
103 167
168 private static List<View> listViews(final View parent)
169 {
170 final List<View> views = new ArrayList<View>();
171 listViews(parent, views);
172 return views;
173 }
174
175 private static void listViews(final View parent, final List<View> views)
176 {
177 views.add(parent);
178 if (parent instanceof ViewGroup)
179 {
180 final ViewGroup vg = (ViewGroup) parent;
181 final int childCount = vg.getChildCount();
182 for (int i = 0; i < childCount; i++)
183 {
184 listViews(vg.getChildAt(i), views);
185 }
186 }
187 }
188
104 private void updateContents(final View view) 189 private void updateContents(final View view)
105 { 190 {
106 final LinearLayout ll = (LinearLayout) view.findViewById(R.id.abb_main_conte nt); 191 final LinearLayout ll = (LinearLayout) view.findViewById(R.id.abb_main_conte nt);
107 ll.removeAllViews(); 192 ll.removeAllViews();
108 193
109 final LayoutInflater inflater = (LayoutInflater) this.getActivity() 194 final LayoutInflater inflater = (LayoutInflater) this.getActivity()
110 .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 195 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
111 inflater.inflate( 196 inflater.inflate(
112 this.getResources().getIdentifier("abb_start_pane_step_" + this.currentS tep, 197 this.getResources().getIdentifier("abb_start_pane_step_" + this.currentS tep,
113 "layout", 198 "layout",
114 this.getActivity().getPackageName()), ll, true); 199 this.getActivity().getPackageName()), ll, true);
115 200
116 this.setButtonText(view, R.id.abb_frp_button, 201 this.setButtonText(view, R.id.abb_frp_button,
117 this.getResources().getIdentifier("abb_frp_button_" + this.currentStep, 202 this.getResources().getIdentifier("abb_frp_button_" + this.currentStep,
118 "string", 203 "string",
119 this.getActivity().getPackageName())); 204 this.getActivity().getPackageName()));
120 }
121 205
122 private void setTextViewTextHtml(final View view, final int viewId, final Stri ng text) 206 final List<View> views = listViews(view);
123 { 207 for (View v : views)
124 final TextView tv = (TextView) view.findViewById(viewId); 208 {
125 tv.setText(Html.fromHtml(text)); 209 final Object tag = v.getTag();
210 if (tag != null)
211 {
212 Typeface t = this.loadedFonts.get(tag.toString());
213 if (t != null)
214 {
215 if (v instanceof TextView)
216 {
217 ((TextView) v).setTypeface(t);
218 }
219 else if (v instanceof Button)
220 {
221 ((Button) v).setTypeface(t);
222 }
223 }
224 }
225 }
126 } 226 }
127 227
128 private void setButtonText(final View view, final int viewId, final int resId) 228 private void setButtonText(final View view, final int viewId, final int resId)
129 { 229 {
130 final Button button = (Button) view.findViewById(viewId); 230 final Button button = (Button) view.findViewById(viewId);
131 button.setText(this.getString(resId)); 231 button.setText(this.getString(resId));
132 } 232 }
133 } 233 }
OLDNEW
« no previous file with comments | « mobile/android/base/strings.xml.in ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld