Skip to content

Commit

Permalink
Merge pull request #5198 from bijupmb/TIMOB-14007-ImplementFontProper…
Browse files Browse the repository at this point in the history
…tyForPickerAndPickerColmn

[TIMOB-14007] set font property
  • Loading branch information
hieupham007 committed Apr 29, 2014
2 parents ff900e6 + c58c380 commit 6d75d2b
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
import android.widget.TimePicker;

@Kroll.proxy(creatableInModule=UIModule.class, propertyAccessors={
"locale", "visibleItems", "value", TiC.PROPERTY_CALENDAR_VIEW_SHOWN
"locale", "visibleItems", "value", TiC.PROPERTY_CALENDAR_VIEW_SHOWN, TiC.PROPERTY_FONT
})
public class PickerProxy extends TiViewProxy implements PickerColumnListener
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,22 @@
import java.text.ParsePosition;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Locale;

import kankan.wheel.widget.WheelView;

import org.appcelerator.kroll.KrollDict;
import org.appcelerator.kroll.KrollProxy;
import org.appcelerator.kroll.common.Log;
import org.appcelerator.titanium.TiC;
import org.appcelerator.titanium.proxy.TiViewProxy;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiUIHelper;
import org.appcelerator.titanium.view.TiUIView;

import android.app.Activity;
import android.graphics.Typeface;
import android.view.ViewGroup.LayoutParams;
import android.widget.LinearLayout;

Expand Down Expand Up @@ -146,7 +149,11 @@ public void processProperties(KrollDict d) {
if (d.containsKey("numericMonths")) {
numericMonths = TiConvert.toBoolean(d, "numericMonths");
}


if (d.containsKey(TiC.PROPERTY_FONT)) {
setFontProperties();
}

if (maxDate.before(minDate)) {
maxDate.setTime(minDate.getTime());
}
Expand All @@ -169,16 +176,77 @@ public void processProperties(KrollDict d) {
@Override
public void propertyChanged(String key, Object oldValue, Object newValue, KrollProxy proxy)
{
if ("value".equals(key)) {
Date date = (Date)newValue;
if (TiC.PROPERTY_FONT.equals(key)) {
setFontProperties();

} else if (TiC.PROPERTY_VALUE.equals(key)) {
Date date = (Date) newValue;
setValue(date.getTime());
} else if ("locale".equals(key)) {
setLocale(TiConvert.toString(newValue));
}
super.propertyChanged(key, oldValue, newValue, proxy);
}


private void setFontProperties()
{

String fontFamily = null;
Float fontSize = null;
String fontWeight = null;
Typeface typeface = null;
KrollDict d = proxy.getProperties();
if (d.containsKey(TiC.PROPERTY_FONT) && d.get(TiC.PROPERTY_FONT) instanceof HashMap) {
KrollDict font = d.getKrollDict(TiC.PROPERTY_FONT);
if (font.containsKey(TiC.PROPERTY_FONTSIZE)) {
String sFontSize = TiConvert.toString(font, TiC.PROPERTY_FONTSIZE);
fontSize = new Float(TiUIHelper.getSize(sFontSize));
}
if (font.containsKey(TiC.PROPERTY_FONTFAMILY)) {
fontFamily = TiConvert.toString(font, TiC.PROPERTY_FONTFAMILY);
}
if (font.containsKey(TiC.PROPERTY_FONTWEIGHT)) {
fontWeight = TiConvert.toString(font, TiC.PROPERTY_FONTWEIGHT);
}
}
if (d.containsKeyAndNotNull(TiC.PROPERTY_FONT_FAMILY)) {
fontFamily = TiConvert.toString(d, TiC.PROPERTY_FONT_FAMILY);
}
if (d.containsKeyAndNotNull(TiC.PROPERTY_FONT_SIZE)) {
String sFontSize = TiConvert.toString(d, TiC.PROPERTY_FONT_SIZE);
fontSize = new Float(TiUIHelper.getSize(sFontSize));
}
if (d.containsKeyAndNotNull(TiC.PROPERTY_FONT_WEIGHT)) {
fontWeight = TiConvert.toString(d, TiC.PROPERTY_FONT_WEIGHT);
}
if (fontFamily != null) {
typeface = TiUIHelper.toTypeface(fontFamily);
}
Integer typefaceWeight = null;
if (fontWeight != null) {
typefaceWeight = new Integer(TiUIHelper.toTypefaceStyle(fontWeight, null));
}

if (typeface != null) {
dayWheel.setTypeface(typeface);
monthWheel.setTypeface(typeface);
yearWheel.setTypeface(typeface);
}
if (typefaceWeight != null) {
dayWheel.setTypefaceWeight(typefaceWeight);
monthWheel.setTypefaceWeight(typefaceWeight);
yearWheel.setTypefaceWeight(typefaceWeight);
}
if (fontSize != null) {
dayWheel.setTextSize(fontSize.intValue());
monthWheel.setTextSize(fontSize.intValue());
yearWheel.setTextSize(fontSize.intValue());
}
dayWheel.invalidate();
monthWheel.invalidate();
yearWheel.invalidate();
}

private void setAdapters()
{
setYearAdapter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ private void setFontProperties()
Float fontSize = null;
String fontWeight = null;
Typeface typeface = null;
// TODO KrollDict d = proxy.getProperties();
KrollDict d = new KrollDict();
KrollDict d = proxy.getProperties();
if (d.containsKey(TiC.PROPERTY_FONT) && d.get(TiC.PROPERTY_FONT) instanceof HashMap) {
KrollDict font = d.getKrollDict(TiC.PROPERTY_FONT);
if (font.containsKey("fontSize")) {
Expand Down
15 changes: 15 additions & 0 deletions android/titanium/src/java/org/appcelerator/titanium/TiC.java
Original file line number Diff line number Diff line change
Expand Up @@ -1179,6 +1179,21 @@ public class TiC
*/
public static final String PROPERTY_FONT = "font";

/**
* @module.api
*/
public static final String PROPERTY_FONTFAMILY = "fontFamily";

/**
* @module.api
*/
public static final String PROPERTY_FONTWEIGHT = "fontWeight";

/**
* @module.api
*/
public static final String PROPERTY_FONTSIZE = "fontSize";

/**
* @module.api
*/
Expand Down
5 changes: 5 additions & 0 deletions apidoc/Titanium/UI/Picker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,11 @@ properties:
type: Boolean
default: false
platforms: [android]

- name: font
summary: Font to use for text.
type: Font

examples:
- title: Multi-Column Picker using Alloy XML Markup
example: |
Expand Down
4 changes: 4 additions & 0 deletions apidoc/Titanium/UI/PickerColumn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ properties:
summary: The selected row in this column.
type: Titanium.UI.PickerRow
platforms: [mobileweb, tizen]

- name: font
summary: Font to use for text.
type: Font

examples:
- title: Multi-Column Picker
Expand Down

0 comments on commit 6d75d2b

Please sign in to comment.