InformationGuide.java 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package epson.common;
  2. import android.app.Application;
  3. import android.content.Context;
  4. import epson.print.C2135R;
  5. import java.io.IOException;
  6. import java.io.InputStream;
  7. import java.util.ArrayList;
  8. import org.apache.commons.lang.CharEncoding;
  9. import org.json.JSONArray;
  10. import org.json.JSONException;
  11. import org.json.JSONObject;
  12. public class InformationGuide extends Application {
  13. public static int GUIDE_VER;
  14. private static Context mContext;
  15. private String mJsonpath = "Guide/list.json";
  16. private ArrayList<String> mhtml = new ArrayList<>();
  17. public InformationGuide(Context context) {
  18. mContext = context;
  19. readGuideHtml();
  20. }
  21. public void readGuideHtml() {
  22. this.mhtml = new ArrayList<>();
  23. try {
  24. JSONObject jSONObject = new JSONObject(loadJSONFromAsset());
  25. GUIDE_VER = jSONObject.getJSONObject("Guide").getInt("Version");
  26. JSONArray jSONArray = jSONObject.getJSONObject("Guide").getJSONObject("Lang").getJSONArray(getGuideLaunguage());
  27. for (int i = 0; i < jSONArray.length(); i++) {
  28. ArrayList<String> arrayList = this.mhtml;
  29. arrayList.add("file:///android_asset/Guide/" + jSONArray.getString(i));
  30. }
  31. } catch (JSONException e) {
  32. e.printStackTrace();
  33. }
  34. }
  35. public String loadJSONFromAsset() {
  36. try {
  37. InputStream open = mContext.getAssets().open(this.mJsonpath);
  38. byte[] bArr = new byte[open.available()];
  39. open.read(bArr);
  40. open.close();
  41. return new String(bArr, CharEncoding.UTF_8);
  42. } catch (IOException e) {
  43. e.printStackTrace();
  44. return null;
  45. }
  46. }
  47. public String getGuideLaunguage() {
  48. return mContext.getString(R.string.guide_language);
  49. }
  50. public ArrayList<String> getHtmlPath() {
  51. return this.mhtml;
  52. }
  53. }