Myanmar font on Android devices - whole app

I found this answer which is perfect for my question. But that doesn't work for me. I do not know why. Maybe I am doing something wrong.

I copied exactly the code from the answer. So my package com.example.printhelper has Application.java files FontsOverride.java. In res / assets / fonts, I have the font Zawgyi_One.ttf. And I have this line:

<item name="android:typeface">serif</item>

      

in the subject .xml.

Some Myanmar words are stored in my database (UTF-8) and I get them via json over http get.

But I still saw (ñöõ)½ºýüþºû±ý(ôð)þ±à èºî

on EditText

instead of the letters Myanmar.

Am I doing something wrong? I am using Android Studio editor.

CODE: Application.java

package com.example.printhelper;

public final class Application extends android.app.Application {
    @Override
    public void onCreate() {
        super.onCreate();
        FontsOverride.setDefaultFont(this, "DEFAULT", "Zawgyi_One.ttf");
        FontsOverride.setDefaultFont(this, "DEFAULT_BOLD", "Zawgyi_One.ttf");
        FontsOverride.setDefaultFont(this, "MONOSPACE", "Zawgyi_One.ttf");
        FontsOverride.setDefaultFont(this, "SERIF", "Zawgyi_One.ttf");
        FontsOverride.setDefaultFont(this, "SANS_SERIF", "Zawgyi_One.ttf");
    }
}

      

FontsOverride.java

public final class FontsOverride {

    public static void setDefaultFont(Context context, String staticTypefaceFieldName, String fontAssetName) {
        final Typeface regular = Typeface.createFromAsset(context.getAssets(), fontAssetName);
        replaceFont(staticTypefaceFieldName, regular);
    }

    protected static void replaceFont(String staticTypefaceFieldName, final Typeface newTypeface) {
        try {
            final Field staticField = Typeface.class.getDeclaredField(staticTypefaceFieldName);
            staticField.setAccessible(true);
            staticField.set(null, newTypeface);
        } catch (NoSuchFieldException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}

      

NOTE. I want to override all TextView and EditText

There is still no answer. I think there is something in my application that is blocking the font, but I have no idea what or why. I have several themes in my application that the user can select. All styles in styles.xml and themes.xml. All topics are derived from the same parent. Is it possible to declare a parent-only font style, right?

EDIT: Cathing the json - I am using AsyncTask

DefaultHttpClient httpclient = new DefaultHttpClient();
HttpGet httpget = new HttpGet(url);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = httpclient.execute(httpget,responseHandler);

      

EDIT 2: Converting strings

I am converting the answer to hex

HttpGet httpget = new HttpGet(url);
httpget.setHeader("Content-type", "application/json; charset=utf-8");;
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = httpclient.execute(httpget,responseHandler);
byte[] array = httpclient.execute(httpget,responseHandler).getBytes();
StringBuffer hexString = new StringBuffer();
for (byte b : array) {
    int intVal = b & 0xff;
    if (intVal < 0x10)
        hexString.append("0");
    hexString.append(Integer.toHexString(intVal));
}
System.out.println(hexString);

      

and this is what he throws away

7b22766965776572735f6964223a33352c22766965776572735f66697273746e616d65223a224b41222c22766965776572735f6c6173746e616d65223a22204b412053455420333528437573746f6d657220c382c2bdc383c2a2c382c2b6c383c2bdc382c2a6c383c2a0c383c2a8c383c2adc382c2b6c383c2a0c382c2a5c383c2bdc383c2bcc382c2bcc383c28cc383c2bd29222c22766965776572735f7374726565746e616d65223a22c383c282c382c2bac383c2bbc382c2b1c383c2bd20c383c2b4c383c2b3c383c2bec382c2bfc383c2a3c382c2bcc383c2a2c382c2bac382c2a3c3a2c280c29cc382c2bdc383c2a020c382c2bdc382c2bac383c2bdc383c2bcc382c2bfc383c2aec382c2bbc383c2bd20c383c2b2222c22766965776572735f686f7573656e756d223a6e756c6c2c22766965776572735f63697479223a6e756c6c2c22766965776572735f706f7374636f6465223a6e756c6c2c22766965776572735f6372656174696f6e5f74696d65223a7b2264617465223a22323031322d31312d31382031373a30313a30362e303030303030222c2274696d657a6f6e655f74797065223a332c2274696d657a6f6e65223a22417369612f52616e676f6f6e227d2c22766965776572735f69735f616374697665223a312c22766965776572735f6e6f7465223a6e756c6c2c22766965776572735f736d617274636172645f6964223a313435303030303033332c22766965776572735f736574746f70626f785f6964223a6e756c6c2c22766965776572735f636f6e74726163745f6e756d626572223a22222c22766965776572735f656d61696c223a6e756c6c2c22766965776572735f70686f6e656e756d223a3231313535342c22766965776572735f68705f6e756d626572223a6e756c6c2c22766965776572735f6d61726974616c5f737461747573223a2273696e676c65222c22766965776572735f646174655f6f665f61637469766174696f6e223a6e756c6c2c22766965776572735f616765223a302c22766965776572735f6f636375706174696f6e223a6e756c6c2c22766965776572735f6e69665f63696e223a6e756c6c2c22766965776572735f7a6f6e65223a6e756c6c2c22766965776572735f67656e646572223a226d616c65222c22766965776572735f70686f6e656e756d32223a6e756c6c2c22766965776572735f637265617465645f75736572735f6964223a6e756c6c2c22766965776572735f6163746976617465645f75736572735f6964223a6e756c6c2c22766965776572735f656469746564223a6e756c6c2c22766965776572735f6469766973696f6e735f6964223a6e756c6c2c22766965776572735f746f776e73686970735f6964223a6e756c6c2c22766965776572735f6465616c6572735f6964223a6e756c6c2c22766965776572735f626f75717565745f6578706972655f64617465223a7b2264617465223a22323031312d31312d31312030303a30303a30302e303030303030222c2274696d657a6f6e655f74797065223a332c2274696d657a6f6e65223a22417369612f52616e676f6f6e227d2c22766965776572735f6f70656e65645f7469636b6574223a302c22766965776572735f736574746f70626f785f726570616972223a302c22766965776572735f656469745f74696d65223a6e756c6c2c22766965776572735f656469745f75736572735f6964223a6e756c6c2c22766965776572735f73656c6663617265223a7b2264617465223a222d303030312d31312d33302030303a30303a30302e303030303030222c2274696d657a6f6e655f74797065223a332c2274696d657a6f6e65223a22417369612f52616e676f6f6e227d2c22766965776572735f6269727468646179223a6e756c6c7d

      

Here you can convert hex to string.

Does this mean that the problem is on the server?

+3


source to share


1 answer


I have already fixed this with application/json; charset=utf-8

. I was looking for the problem in my android app but it was on the submit side.

I'm using the Nette Framework, so it wasn't as clear as it sounds. Exactly what needed to be updated was:

JsonResponse($data, 'application/json; charset=utf-8'));

      



Yes, from the comment

that's not a font problem, an encoding problem

... Thanks @ njzk2 for the help.

0


source







All Articles