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