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

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

Issue 6296160390086656: Issue 2491 - Fix design elements in onboarding slides (Closed)
Patch Set: Renamed button background. Created May 22, 2015, 12:04 p.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mobile/android/base/strings.xml.in ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mobile/android/thirdparty/org/adblockplus/browser/StartPane.java
diff --git a/mobile/android/thirdparty/org/adblockplus/browser/StartPane.java b/mobile/android/thirdparty/org/adblockplus/browser/StartPane.java
index b8fafcfe204dc68c1ae8d47697a464936f032492..fcd689c084f3a6fd73e9580655db1c591b41d1dd 100644
--- a/mobile/android/thirdparty/org/adblockplus/browser/StartPane.java
+++ b/mobile/android/thirdparty/org/adblockplus/browser/StartPane.java
@@ -17,14 +17,24 @@
package org.adblockplus.browser;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
import org.mozilla.gecko.R;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnKeyListener;
+import android.graphics.Typeface;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
-import android.text.Html;
+import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
@@ -41,12 +51,66 @@ public class StartPane extends DialogFragment implements OnClickListener, OnKeyL
private static final String TAG = "AdblockBrowser.StartPane";
private int currentStep = 1;
private static final int NUMBER_OF_STEPS = 3;
+ private static final HashMap<String, Integer> FONTS = new HashMap<String, Integer>();
+ private HashMap<String, Typeface> loadedFonts = new HashMap<String, Typeface>();
+
+ static
+ {
+ FONTS.put("ttf_opensans_light", R.raw.opensans_light);
+ FONTS.put("ttf_opensans_semibold", R.raw.opensans_semibold);
+ }
+
+ static Typeface typefaceFromResource(final Context context, final int resId)
+ {
+ Typeface ret = null;
+ try
+ {
+ context.getCacheDir().mkdir();
+ final File output = File.createTempFile("abb_font", ".ttf");
+ final byte[] buffer = new byte[4096];
+ final InputStream in = context.getResources().openRawResource(resId);
+ final FileOutputStream out = new FileOutputStream(output);
+ for (;;)
+ {
+ final int read = in.read(buffer);
+ if (read < 0)
+ {
+ break;
+ }
+ out.write(buffer, 0, read);
+ }
+ in.close();
+ out.close();
+ ret = Typeface.createFromFile(output);
+ output.delete();
+ }
+ catch (IOException e)
+ {
+ Log.e(TAG, "Failed to load typeface: " + e.getMessage(), e);
+ }
+ return ret;
+ }
+
+ private void loadTypefaces()
+ {
+ final Context context = this.getActivity();
+ this.loadedFonts.clear();
+ for (Map.Entry<String, Integer> e : FONTS.entrySet())
+ {
+ final Typeface t = typefaceFromResource(context, e.getValue().intValue());
+ if (t != null)
+ {
+ this.loadedFonts.put(e.getKey(), t);
+ }
+ }
+ }
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.setStyle(DialogFragment.STYLE_NO_TITLE, 0);
+ this.loadTypefaces();
}
@Override
@@ -54,7 +118,6 @@ public class StartPane extends DialogFragment implements OnClickListener, OnKeyL
{
final View view = inflater.inflate(R.layout.abb_start_pane, container, false);
- this.setTextViewTextHtml(view, R.id.abb_app_title, "Adblock <b>Browser</b>");
this.updateContents(view);
this.getDialog().setOnKeyListener(this);
@@ -101,6 +164,27 @@ public class StartPane extends DialogFragment implements OnClickListener, OnKeyL
return false;
}
+ private static List<View> listViews(final View parent)
+ {
+ final List<View> views = new ArrayList<View>();
+ listViews(parent, views);
+ return views;
+ }
+
+ private static void listViews(final View parent, final List<View> views)
+ {
+ views.add(parent);
+ if (parent instanceof ViewGroup)
+ {
+ final ViewGroup vg = (ViewGroup) parent;
+ final int childCount = vg.getChildCount();
+ for (int i = 0; i < childCount; i++)
+ {
+ listViews(vg.getChildAt(i), views);
+ }
+ }
+ }
+
private void updateContents(final View view)
{
final LinearLayout ll = (LinearLayout) view.findViewById(R.id.abb_main_content);
@@ -117,12 +201,27 @@ public class StartPane extends DialogFragment implements OnClickListener, OnKeyL
this.getResources().getIdentifier("abb_frp_button_" + this.currentStep,
"string",
this.getActivity().getPackageName()));
- }
- private void setTextViewTextHtml(final View view, final int viewId, final String text)
- {
- final TextView tv = (TextView) view.findViewById(viewId);
- tv.setText(Html.fromHtml(text));
+ final List<View> views = listViews(view);
+ for (View v : views)
+ {
+ final Object tag = v.getTag();
+ if (tag != null)
+ {
+ Typeface t = this.loadedFonts.get(tag.toString());
+ if (t != null)
+ {
+ if (v instanceof TextView)
+ {
+ ((TextView) v).setTypeface(t);
+ }
+ else if (v instanceof Button)
+ {
+ ((Button) v).setTypeface(t);
+ }
+ }
+ }
+ }
}
private void setButtonText(final View view, final int viewId, final int resId)
« 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