0

I have downloaded a word meaning Android sqlite.db dictionary file. By fetching SQL query I got

enslishWord="plausible";
hindiMeaning="lR;kHkklh]diViw.kZ]";

By using Hindi Typeface in TextView I got proper Hindi meaning. If I try to print by System.out.println(hindiMeaning); it prints lR;kHkklh]diViw.kZ]

I am confused about the problem and looking for a solution. Please, check the raw Android sqlite.db Github link in comment sections.

Prokash Sarkar
  • 11,723
  • 1
  • 37
  • 50
  • https://github.com/shahidul2k9/english-to-hindi-dictionary/blob/f818bef83663b3d3e815440a9414658f9bb845c6/app/src/main/assets/english-hindi.sqlite – Mahadi Hasan Sunny Jul 28 '21 at 06:18
  • how are storing hindi ? . is it in UTF8 and unicode – Rahat Shovo Jul 28 '21 at 07:29
  • english-hindi.sqlite is ANSI encoding. If I convert it into UTF-8 the englsih-hindi.sqlite doesn't work. The SqliteLog errors E/SQLiteLog: (11) database corruption at line 65059 of [b2325a6e1c] E/SQLiteLog: (11) database corruption at line 65209 of [b2325a6e1c] E/SQLiteLog: (11) statement aborts at 3: [] database disk image is malformed ) 2021-07-29 12:22:56.283 E/SQLiteDatabase: Database corruption detected in open() – Mahadi Hasan Sunny Jul 29 '21 at 08:03

2 Answers2

0

add this class

public class typeface extends TypefaceSpan {
    Typeface typeface;

    public typeface(String family, Typeface typeface) {
        super(family);
        this.typeface = typeface;
    }

    @Override
    public void updateDrawState(TextPaint ds) {
        ds.setTypeface(typeface);
    }

    @Override
    public void updateMeasureState(TextPaint ds) {
        ds.setTypeface(typeface);
    }

}`

Add this method to you activity

 public SpannableString spannableString(String string, String your_working_hindi_font_name , Context context) {

    SpannableString span = new SpannableString(string);
    span.setSpan(new typeface("", Typeface.createFromAsset(context.getAssets(),
            "" + your_working_hindi_font_name + ".ttf")), 0, span.length(), span.SPAN_EXCLUSIVE_EXCLUSIVE);

    return span;

}
public void spannableToast(SpannableString text, Context context) {
    Toast.makeText(context, text, Toast.LENGTH_SHORT).show();
}

call method to show toast

spannableToast(spannableString(normal, "hindi" , getContext()) , getContext());

to set text

 phoneTv.setText( spannableString(normal, "hindi" , getContext()));
Rahat Shovo
  • 66
  • 2
  • 5
  • In System.out.println(text); and clipData = ClipData.newPlainText("Facebook Post", text); clipboard.setPrimaryClip(clipData); it gives lR;kHkklh]diViw.kZ] .. but it works in toast message. – Mahadi Hasan Sunny Jul 28 '21 at 16:52
  • To copy or get it to in your clip data set the text to a text view 1st then get a text from the textview. – Rahat Shovo Jul 29 '21 at 06:28
0

If I try to print by System.out.println(hindiMeaning); it prints lR;kHkklh]diViw.kZ].

Are you trying to print the non-English characters in Console?

android.graphics.Typeface is an Android-specific class whereas System.out.println is a Java-specific function. You can't expect the Java console to print out the non-English characters by default.

In Android Studio the default encoding can be set in the studio64.exe.vmoptions file as an ordinary VM parameter. This file is located inside the root folder of your Android Studio installation and contains a set of JVM parameters. Add -Dfile.encoding=UTF-8 there to set encoding in UTF-8.

Alternatively, you can change the option via the settings.

Reference: IntelliJ IDEA incorrect encoding in console output

Android Studio Settings

Prokash Sarkar
  • 11,723
  • 1
  • 37
  • 50
  • english-hindi.sqlite is ANSI encoding. If I convert it into UTF-8 the englsih-hindi.sqlite doesn't work. The SqliteLog errors E/SQLiteLog: (11) database corruption at line 65059 of [b2325a6e1c] E/SQLiteLog: (11) database corruption at line 65209 of [b2325a6e1c] E/SQLiteLog: (11) statement aborts at 3: [] database disk image is malformed ) E/SQLiteDatabase: Database corruption detected in open() – Mahadi Hasan Sunny Jul 29 '21 at 08:17