ndt-dev - [ndt-dev] [ndt] r525 committed - Add mixin to clean repetitive code.
Subject: NDT-DEV email list created
List archive
- From:
- To:
- Subject: [ndt-dev] [ndt] r525 committed - Add mixin to clean repetitive code.
- Date: Wed, 24 Aug 2011 16:03:15 +0000
Revision: 525
Author:
Date: Wed Aug 24 09:02:56 2011
Log: Add mixin to clean repetitive code.
http://code.google.com/p/ndt/source/detail?r=525
Added:
/branches/android/Android/src/net/measurementlab/ndt/NdtSupport.java
=======================================
--- /dev/null
+++ /branches/android/Android/src/net/measurementlab/ndt/NdtSupport.java Wed Aug 24 09:02:56 2011
@@ -0,0 +1,58 @@
+package net.measurementlab.ndt;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import android.app.Activity;
+import android.graphics.Typeface;
+import android.widget.TextView;
+
+/**
+ * Mixin to share code useful across all parts of the app.
+ *
+ * @author
+ *
+ */
+class NdtSupport {
+ static final String DEFAULT_TYPEFACE = "fonts/League_Gothic.otf";
+
+ private static Map<String, Typeface> typefaces = new HashMap<String, Typeface>();
+
+ /**
+ * Convenience that assumes a specific default font should be
uniformaly
+ * applied.
+ *
+ * @see NdtSupport#applyFont(Activity, String, int...)
+ */
+ static void applyFont(Activity activity, int... textFieldIds) {
+ applyFont(activity, DEFAULT_TYPEFACE, textFieldIds);
+ }
+
+ /**
+ * Convenience for setting a whole array of text fields to the same
+ * typeface.
+ *
+ * @param activity
+ * used to find the fields to alter
+ * @param typefaceResource
+ * the resource path to the typeface of interest
+ * @param textFieldIds
+ * vararg of ids to look up and change
+ */
+ static void applyFont(Activity activity, String typefaceResource,
+ int... textFieldIds) {
+ Typeface typeface = null;
+ if (typefaces.containsKey(typefaceResource)) {
+ typeface = typefaces.get(typefaceResource);
+ } else {
+ typeface =
Typeface.createFromAsset(activity.getAssets(),
+
+ "fonts/League_Gothic.otf");
+ typefaces.put(typefaceResource, typeface);
+ }
+ for (int textFieldId : textFieldIds) {
+ TextView textView = (TextView)
activity.findViewById(textFieldId);
+ textView.setTypeface(typeface);
+ }
+ }
+}
- [ndt-dev] [ndt] r525 committed - Add mixin to clean repetitive code., ndt, 08/24/2011
Archive powered by MHonArc 2.6.16.