Commit 0e39dea0 authored by Ahad Birang's avatar Ahad Birang Committed by zooble

Android custome fontFamily (#301)

parent ceb20cbd
......@@ -25,6 +25,7 @@
|wheelFlex | array | [1, 1, 1] | iOS/Android | |
|pickerFontSize | number | 16 | iOS/Android | |
|pickerFontColor | array | [31, 31, 31, 1] | iOS/Android | |
|pickerFontFamily | string | | Android | |
|pickerRowHeight | number | 24 | iOS | |
|pickerData | array | | iOS/Android | |
|selectedValue | array | | iOS/Android | |
......
package com.beefe.picker;
import android.content.res.AssetManager;
import android.app.Activity;
import android.app.Dialog;
import android.graphics.Color;
import android.graphics.PixelFormat;
import android.graphics.Typeface;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.Gravity;
......@@ -75,6 +77,10 @@ import static android.graphics.Color.argb;
*/
public class PickerViewModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
private static final String FONTS = "fonts/";
private static final String OTF = ".otf";
private static final String TTF = ".ttf";
private static final String REACT_CLASS = "BEEPickerManager";
......@@ -104,6 +110,8 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life
private static final String PICKER_TEXT_SIZE = "pickerFontSize";
private static final String PICKER_TEXT_ELLIPSIS_LEN = "pickerTextEllipsisLen";
private static final String PICKER_FONT_FAMILY = "pickerFontFamily";
private static final String PICKER_EVENT_NAME = "pickerEvent";
private static final String EVENT_KEY_CONFIRM = "confirm";
private static final String EVENT_KEY_CANCEL = "cancel";
......@@ -340,6 +348,32 @@ public class PickerViewModule extends ReactContextBaseJavaModule implements Life
break;
}
if (options.hasKey(PICKER_FONT_FAMILY)) {
Typeface typeface = null;
AssetManager assetManager = activity.getApplicationContext().getAssets();
final String fontFamily = options.getString(PICKER_FONT_FAMILY);
try {
String path = FONTS + fontFamily + TTF;
typeface = Typeface.createFromAsset(assetManager, path);
} catch (Exception ignored) {
try {
String path = FONTS + fontFamily + OTF;
typeface = Typeface.createFromAsset(assetManager, path);
} catch (Exception ignored2) {
try {
typeface = Typeface.create(fontFamily, Typeface.NORMAL);
} catch (Exception ignored3) {
}
}
}
cancelTV.setTypeface(typeface);
titleTV.setTypeface(typeface);
confirmTV.setTypeface(typeface);
pickerViewAlone.setTypeface(typeface);
pickerViewLinkage.setTypeface(typeface);
}
if (options.hasKey(SELECTED_VALUE)) {
ReadableArray array = options.getArray(SELECTED_VALUE);
String[] selectedValue = getSelectedValue(array);
......
......@@ -203,6 +203,12 @@ public class LoopView extends View {
invalidate();
}
public void setTypeface(Typeface typeface){
paintOuterText.setTypeface(typeface);
paintCenterText.setTypeface(typeface);
invalidate();
}
public final void setNotLoop() {
isLoop = false;
}
......
package com.beefe.picker.view;
import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
......@@ -212,6 +213,17 @@ public class PickerViewAlone extends LinearLayout {
}
}
public void setTypeface(Typeface typeface){
int viewCount = pickerViewAloneLayout.getChildCount();
for (int i = 0; i < viewCount; i++) {
View view = pickerViewAloneLayout.getChildAt(i);
if (view instanceof LoopView) {
LoopView loopView = (LoopView) view;
loopView.setTypeface(typeface);
}
}
}
public void setTextEllipsisLen(int len){
int viewCount = pickerViewAloneLayout.getChildCount();
for (int i = 0; i < viewCount; i++) {
......
package com.beefe.picker.view;
import android.content.Context;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
......@@ -603,6 +604,20 @@ public class PickerViewLinkage extends LinearLayout {
}
}
public void setTypeface(Typeface typeface){
switch (curRow) {
case 2:
loopViewOne.setTypeface(typeface);
loopViewTwo.setTypeface(typeface);
break;
case 3:
loopViewOne.setTypeface(typeface);
loopViewTwo.setTypeface(typeface);
loopViewThree.setTypeface(typeface);
break;
}
}
public void setTextEllipsisLen(int len){
switch (curRow) {
case 2:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment