123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- package epson.common;
- import android.app.Application;
- import android.content.Context;
- import epson.print.C2135R;
- import java.io.IOException;
- import java.io.InputStream;
- import java.util.ArrayList;
- import org.apache.commons.lang.CharEncoding;
- import org.json.JSONArray;
- import org.json.JSONException;
- import org.json.JSONObject;
- public class InformationGuide extends Application {
- public static int GUIDE_VER;
- private static Context mContext;
- private String mJsonpath = "Guide/list.json";
- private ArrayList<String> mhtml = new ArrayList<>();
- public InformationGuide(Context context) {
- mContext = context;
- readGuideHtml();
- }
- public void readGuideHtml() {
- this.mhtml = new ArrayList<>();
- try {
- JSONObject jSONObject = new JSONObject(loadJSONFromAsset());
- GUIDE_VER = jSONObject.getJSONObject("Guide").getInt("Version");
- JSONArray jSONArray = jSONObject.getJSONObject("Guide").getJSONObject("Lang").getJSONArray(getGuideLaunguage());
- for (int i = 0; i < jSONArray.length(); i++) {
- ArrayList<String> arrayList = this.mhtml;
- arrayList.add("file:///android_asset/Guide/" + jSONArray.getString(i));
- }
- } catch (JSONException e) {
- e.printStackTrace();
- }
- }
- public String loadJSONFromAsset() {
- try {
- InputStream open = mContext.getAssets().open(this.mJsonpath);
- byte[] bArr = new byte[open.available()];
- open.read(bArr);
- open.close();
- return new String(bArr, CharEncoding.UTF_8);
- } catch (IOException e) {
- e.printStackTrace();
- return null;
- }
- }
- public String getGuideLaunguage() {
- return mContext.getString(R.string.guide_language);
- }
- public ArrayList<String> getHtmlPath() {
- return this.mhtml;
- }
- }
|