package com.rey.material.util;

import android.content.Context;
import android.graphics.Typeface;

import java.util.HashMap;

/**
 * Created by Rey on 12/23/2014.
 */
public class TypefaceUtil {

    private static final HashMap<String, Typeface> sCachedFonts = new HashMap<String, Typeface>();
    private static final String PREFIX_ASSET = "asset:";

    private TypefaceUtil() {
    }

    /**
     * @param familyName if start with 'asset:' prefix, then load font from asset folder.
     * @return
     */
    public static Typeface load(Context context, String familyName, int style) {
        if(familyName != null && familyName.startsWith(PREFIX_ASSET))
            synchronized (sCachedFonts) {
                try {
                    if (!sCachedFonts.containsKey(familyName)) {
                        final Typeface typeface = Typeface.createFromAsset(context.getAssets(), familyName);
                        sCachedFonts.put(familyName, typeface);
                        return typeface;
                    }
                } catch (Exception e) {
                    return Typeface.DEFAULT;
                }

                return sCachedFonts.get(familyName);
            }

        return Typeface.create(familyName, style);
    }

    public static String getArNum(String number) {
        if (!LocaleUtil.getLocale().getLanguage().equalsIgnoreCase("ar")) {
            return number;
        }

        char[] arabicChars = {'٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'};
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < number.length(); i++) {
            if (Character.isDigit(number.charAt(i))) {
                builder.append(arabicChars[(int) (number.charAt(i)) - 48]);
            } else {
                builder.append(number.charAt(i));
            }
        }
        return builder.toString();
    }

    public static String getArNum(int numberText) {
        String number = String.valueOf(numberText);
        if (!LocaleUtil.getLocale().getLanguage().equalsIgnoreCase("ar")) {
            return number;
        }
        char[] arabicChars = {'٠', '١', '٢', '٣', '٤', '٥', '٦', '٧', '٨', '٩'};
        StringBuilder builder = new StringBuilder();
        for (int i = 0; i < number.length(); i++) {
            if (Character.isDigit(number.charAt(i))) {
                builder.append(arabicChars[(int) (number.charAt(i)) - 48]);
            } else {
                builder.append(number.charAt(i));
            }
        }
        return builder.toString();
    }
}

@@ -1487,32 +1487,50 @@
 '%D9%A7', '%D9%A8', '%D9%A9'%7D;%0A
+        try %7B%0A    
         StringBu
@@ -1566,32 +1566,36 @@
 lder();%0A        
+    
 for (int i = 0; 
@@ -1626,32 +1626,36 @@
 ) %7B%0A            
+ 
+   
 if (Character.is
@@ -1673,32 +1673,36 @@
 r.charAt(i))) %7B%0A
+    
                 
@@ -1765,32 +1765,36 @@
 %5D);%0A            
+    
 %7D else %7B%0A       
@@ -1778,32 +1778,36 @@
        %7D else %7B%0A
+    
                 
@@ -1848,34 +1848,41 @@
             
-%7D%0A
+    %7D%0A   
         
 %7D%0A        re
@@ -1861,34 +1861,39 @@
    %7D%0A           
+ 
 %7D%0A
+    
         return b
@@ -1907,24 +1907,94 @@
 toString();%0A
+        %7D catch (Exception e) %7B%0A%0A            return number;%0A        %7D%0A
     %7D%0A%0A    p
@@ -2466,35 +2466,27 @@
     
-builder.append(arabicChars%5B
+int arabicNumber = 
 (int
@@ -2502,35 +2502,231 @@
 .charAt(i)) - 48
-%5D);
+;%0A                if (arabicNumber %3C arabicChars.length) %7B%0A                    builder.append(arabicChars%5BarabicNumber%5D);%0A                %7D else %7B%0A                    return number;%0A                %7D
 %0A            %7D e

fix timePicker