private boolean copyAssetsToFilesystem(String assetsSrc, String des) {
   if (SQLiteDebug.isDebug) {
     Log.i(TAG, "Copy " + assetsSrc + " to " + des);
   }
   InputStream istream = null;
   OutputStream ostream = null;
   try {
     AssetManager am = context.getAssets();
     istream = am.open(assetsSrc);
     ostream = new FileOutputStream(des);
     byte[] buffer = new byte[1024 * 64];
     int length;
     while ((length = istream.read(buffer)) > 0) {
       ostream.write(buffer, 0, length);
     }
     istream.close();
     ostream.close();
   } catch (Exception e) {
     e.printStackTrace();
     try {
       if (istream != null) istream.close();
       if (ostream != null) ostream.close();
     } catch (Exception ee) {
       ee.printStackTrace();
     }
     return false;
   }
   return true;
 }
Exemplo n.º 2
0
  private void processAssets() {
    AssetManager am = getApplicationContext().getAssets();
    final String BDAY_TUNE = "Chipmunks - Happy Birthday to You!!!.mp4.mp3";

    try {
      // InputStream ist = am.open(BDAY_TUNE);
      // AssetFileDescriptor fd = am.openFd(BDAY_TUNE);
      InputStream ist = am.open("test.txt");

      InputStreamReader is = new InputStreamReader(ist);
      StringBuilder sb = new StringBuilder();
      BufferedReader br = new BufferedReader(is);
      String read = br.readLine();

      while (read != null) {
        System.out.println(read);
        sb.append(read);
        read = br.readLine();
      }

      // return sb.toString();

    } catch (Exception e) {
      e.printStackTrace();
    }
    ;
  }
Exemplo n.º 3
0
  private static void writeStaticAssets(AssetManager assets, ZipOutputStream out, String path) {
    try {
      for (String item : assets.list(path)) {
        try {
          InputStream fileIn = assets.open(path + "/" + item);

          ByteArrayOutputStream baos = new ByteArrayOutputStream();
          BufferedInputStream bin = new BufferedInputStream(fileIn);

          byte[] buffer = new byte[8192];
          int read = 0;

          while ((read = bin.read(buffer, 0, buffer.length)) != -1) {
            baos.write(buffer, 0, read);
          }

          bin.close();
          baos.close();

          ZipEntry entry = new ZipEntry(path + "/" + item);
          out.putNextEntry(entry);
          out.write(baos.toByteArray());
          out.closeEntry();
        } catch (IOException e) {
          BootstrapSiteExporter.writeStaticAssets(assets, out, path + "/" + item);
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 4
0
  public static @NonNull LinkedList<ThemeInfo> enumerateThemes(@NonNull Context context) {
    LinkedList<ThemeInfo> themes = new LinkedList<>();
    AssetManager manager = context.getAssets();

    // load themes from assets
    try {
      String[] builtin_themes = manager.list("");
      for (String theme : builtin_themes) {
        if (!theme.toLowerCase().endsWith("theme.properties")) continue;
        Properties p = loadColorScheme(theme, manager);
        if (p != null) themes.add(new ThemeInfo(p.getProperty("NAME", theme), theme));
      }
    } catch (IOException e) {
      e.printStackTrace();
    }

    // load themes from disk
    File dir = new File(SEARCH_DIR);
    if (dir.exists()) {
      File[] files = dir.listFiles();
      if (files != null) {
        for (File file : files) {
          if (!file.getName().toLowerCase().endsWith("theme.properties")) continue;
          Properties p = loadColorScheme(file.getAbsolutePath(), null);
          if (p != null)
            themes.add(
                new ThemeInfo(p.getProperty("NAME", file.getName()), file.getAbsolutePath()));
        }
      }
    }
    return themes;
  }
Exemplo n.º 5
0
  private void CopyAssets() {

    AssetManager assetManager = getAssets();

    InputStream in = null;
    OutputStream out = null;
    File file = new File(getFilesDir(), fileName);
    try {
      in = assetManager.open(fileName);
      out = openFileOutput(file.getName(), Context.MODE_WORLD_READABLE);

      copyFile(in, out);
      in.close();
      in = null;
      out.flush();
      out.close();
      out = null;
    } catch (Exception e) {
      Log.e("tag", e.getMessage());
    }

    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setDataAndType(Uri.parse("file://" + getFilesDir() + "/" + fileName), "application/pdf");

    startActivity(intent);
  }
Exemplo n.º 6
0
  private void resetQuiz() {
    AssetManager assets = getAssets();
    filenameList.clear();
    try {
      Set<String> regions = regionsMap.keySet();
      for (String region : regions) {
        if (regionsMap.get(region)) {
          String[] paths = assets.list(region);
          for (String path : paths) {
            filenameList.add(path.replace(".png", ""));
          }
        }
      }
    } catch (IOException e) {
      Log.e(TAG, "Error loading image file names", e);
    }
    correctAnswers = 0;
    totalGuesses = 0;

    quizCountriesList.clear();
    int flagCounter = 1;
    int numberOfFlags = filenameList.size();

    while (flagCounter <= 10) {
      int randomIndex = random.nextInt(numberOfFlags);
      String fileName = filenameList.get(randomIndex);
      if (!quizCountriesList.contains(fileName)) {
        quizCountriesList.add(fileName);
        ++flagCounter;
      }
    }
    loadNextFlag();
  }
Exemplo n.º 7
0
  /**
   * 从assets文件夹拷贝文件到/data/data/[应用包名]/files目录下。
   *
   * @param context 当前上下文。
   * @param fileName 库的名称。
   * @param outPath 输出路径。
   * @return 返回库路径。
   * @throws IOException
   */
  public static void copyFormAssets(Context context, String fileName, String outPath)
      throws IOException {
    InputStream is = null;
    OutputStream os = null;
    AssetManager am = context.getAssets();
    try {
      is = am.open(fileName);
      os = new FileOutputStream(outPath);

      byte[] buffer = new byte[1024];
      int length;
      while ((length = is.read(buffer)) > 0) {
        os.write(buffer, 0, length);
      }
    } finally {
      try {
        if (is != null) {
          is.close();
        }
      } catch (IOException e) {
        e.printStackTrace();
      }

      try {
        if (os != null) {
          os.close();
        }
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
Exemplo n.º 8
0
  @SuppressWarnings("nls")
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.about);

    Bundle extras = getIntent().getExtras();
    String packageName = null;
    if (extras != null) {
      packageName = extras.getString(LibraryConstants.PREFS_KEY_TEXT);
    }

    try {
      AssetManager assetManager = this.getAssets();
      InputStream inputStream = assetManager.open("about.html");
      String htmlText = new Scanner(inputStream).useDelimiter("\\A").next();

      if (packageName != null) {
        String version = "";
        try {
          PackageInfo pInfo =
              getPackageManager().getPackageInfo(packageName, PackageManager.GET_META_DATA);
          version = pInfo.versionName;
        } catch (NameNotFoundException e) {
          e.printStackTrace();
        }

        htmlText = htmlText.replaceFirst("VERSION", version);
      }

      WebView aboutView = (WebView) findViewById(R.id.aboutview);
      aboutView.loadData(htmlText, "text/html", "utf-8");
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 9
0
 /** svg image on sdcard */
 public static void unpackOnSdCard(AssetManager assetManager) throws IOException {
   if (Environment.getExternalStorageState().compareTo(Environment.MEDIA_MOUNTED) == 0) {
     File sdcard = Environment.getExternalStorageDirectory();
     String irrlichtPath = sdcard.getAbsoluteFile() + "/Irrlicht/";
     File irrlichtDir = new File(irrlichtPath);
     if (irrlichtDir.exists() && !irrlichtDir.isDirectory()) {
       throw new IOException("Irrlicht exists and is not a directory on SD Card");
     } else if (!irrlichtDir.exists()) {
       irrlichtDir.mkdirs();
     }
     // Note: /sdcard/irrlicht dir exists
     String[] filenames = assetManager.list("data");
     for (String filename : filenames) {
       InputStream inputStream = assetManager.open("data/" + filename);
       OutputStream outputStream = new FileOutputStream(irrlichtPath + "/" + filename);
       // copy
       byte[] buffer = new byte[4096];
       int length;
       while ((length = inputStream.read(buffer)) > 0) {
         outputStream.write(buffer, 0, length);
       }
       outputStream.flush();
       outputStream.close();
       inputStream.close();
     }
   } else {
     throw new IOException("SD Card not available");
   }
 }
Exemplo n.º 10
0
  private void CopyAssets() {
    AssetManager assetManager = getAssets();
    String[] files = null;
    try {
      if (Build.VERSION.SDK_INT >= 21) files = assetManager.list("api-16");
      else files = assetManager.list("");
    } catch (IOException e) {
      Log.e(TAG, e.getMessage());
    }
    if (files != null) {
      for (String file : files) {
        InputStream in = null;
        OutputStream out = null;
        try {

          if (Build.VERSION.SDK_INT >= 21) in = assetManager.open("api-16/" + file);
          else in = assetManager.open(file);
          out = new FileOutputStream("/data/data/org.proxydroid/" + file);
          copyFile(in, out);
          in.close();
          in = null;
          out.flush();
          out.close();
          out = null;
        } catch (Exception e) {
          Log.e(TAG, e.getMessage());
        }
      }
    }
  }
Exemplo n.º 11
0
 public static void assetsCopy(Context c, String assetsPath, String dirPath) throws IOException {
   AssetManager manager = c.getAssets();
   String[] list = manager.list(assetsPath);
   if (list.length == 0) { // 文件
     InputStream in = manager.open(assetsPath);
     File file = new File(dirPath);
     file.getParentFile().mkdirs();
     file.createNewFile();
     FileOutputStream fout = new FileOutputStream(file);
     /* 复制 */
     byte[] buf = new byte[1024];
     int count;
     while ((count = in.read(buf)) != -1) {
       fout.write(buf, 0, count);
       fout.flush();
     }
     /* 关闭 */
     in.close();
     fout.close();
   } else { // 目录
     for (String path : list) {
       assetsCopy(c, assetsPath + "/" + path, dirPath + "/" + path);
     }
   }
 }
Exemplo n.º 12
0
  private void startServer() {

    if (server == null) {
      AssetManager am =
          (AssetManager)
              AndroidServiceLocator.GetInstance()
                  .GetService(AndroidServiceLocator.SERVICE_ANDROID_ASSET_MANAGER);
      if (serverProperties == null) {
        serverProperties = new Properties();
        try {
          serverProperties.load(am.open(SERVER_PROPERTIES));
        } catch (IOException ex) {
          LOG.Log(Module.GUI, ex.toString());
        }
      }
      LOG.Log(
          Module.GUI,
          "The Port is: " + serverProperties.getProperty(SERVER_PORT_PROPERTY, "Missing"));
      try {
        serverPort = Integer.parseInt(serverProperties.getProperty(SERVER_PORT_PROPERTY));
        server = new HttpServer(serverPort, this, this.appView);
        server.start();
      } catch (Exception ex) {
        LOG.Log(Module.GUI, ex.toString());
      }
      LOG.Log(Module.GUI, "Server started.");
    }
  }
Exemplo n.º 13
0
  public static void firstTimeServerSetup(final Context context) {
    final AssetManager assetManager = context.getAssets();
    final String[] files;
    try {
      files = assetManager.list("");
      for (String filename : files) {
        if (filename.endsWith(".xml")) {
          final InputStream in = assetManager.open(filename);
          final File outFile = new File(getSharedPreferencesPath(context));
          if (outFile.exists() || outFile.mkdir()) {
            final File file = new File(getSharedPreferencesPath(context), filename);
            final FileOutputStream out = new FileOutputStream(file);

            byte[] buffer = new byte[2048];
            int read;
            while ((read = in.read(buffer)) != -1) {
              out.write(buffer, 0, read);
            }

            in.close();
            out.flush();
            out.close();
          }
        }
      }
    } catch (final IOException e) {
      e.printStackTrace();
    }
  }
Exemplo n.º 14
0
  public List getContent() {
    AssetManager am = this.getAssets();
    String json = "";
    try {
      InputStream is = am.open(fileDir);
      InputStreamReader isr = new InputStreamReader(is, "UTF-8");
      BufferedReader br = new BufferedReader(isr);

      for (String s = br.readLine(); s != null; s = br.readLine()) {
        json += s;
      }
    } catch (IOException e) {
      e.printStackTrace();
    }

    List<Soal> content = new LinkedList<>();
    try {
      JSONArray soals = new JSONArray(json);
      for (int i = 0; i < soals.length(); ++i) {
        content.add(new Soal(soals.getJSONObject(i)));
      }
    } catch (JSONException e) {
      e.printStackTrace();
    }

    return content;
  }
  /**
   * Read a file from assets
   *
   * @param fileName The file name to read
   * @return A string value of the file contents, may be empty
   * @throws IOException If the the read is not possible or some other errors.
   * @deprecated Marked as deprecated until the a gradle related bug will be fixed in robolectric
   */
  @NonNull
  @Deprecated
  @SuppressWarnings("unused")
  protected String readFileFromAssets(@NonNull Context context, @NonNull final String fileName)
      throws IOException {
    StringBuilder json = new StringBuilder();

    BufferedReader reader = null;
    try {

      // Prepare the assets reader
      AssetManager assets = context.getAssets();
      InputStreamReader isr = new InputStreamReader(assets.open(fileName), "UTF-8");
      reader = new BufferedReader(isr);

      // Read the assets file line by line
      String line = reader.readLine();
      while (line != null) {
        json.append(line);
        line = reader.readLine();
      }

    } finally {
      // We need to close the reader even if an exception was thrown
      if (reader != null) {
        reader.close();
      }
    }

    return json.toString();
  }
Exemplo n.º 16
0
  private void qaulCopyFileOrDir(String path) {
    AssetManager assetManager = this.getAssets();
    String assets[] = null;
    try {
      Log.i(MSG_TAG, "copyFileOrDir() " + path);
      assets = assetManager.list(path);
      if (assets.length == 0) {
        qaulCopyFile(path);
      } else {
        String fullPath = dataPathString + "/" + path;
        Log.i(MSG_TAG, "path=" + fullPath);
        File dir = new File(fullPath);
        if (!dir.exists()
            && !path.startsWith("images")
            && !path.startsWith("sounds")
            && !path.startsWith("webkit")) if (!dir.mkdirs()) ;
        Log.i(MSG_TAG, "could not create dir " + fullPath);
        for (int i = 0; i < assets.length; ++i) {
          String p;
          if (path.equals("")) p = "";
          else p = path + "/";

          if (!path.startsWith("images")
              && !path.startsWith("sounds")
              && !path.startsWith("webkit")) qaulCopyFileOrDir(p + assets[i]);
        }
      }
    } catch (IOException ex) {
      Log.e(MSG_TAG, "I/O Exception", ex);
    }
  }
Exemplo n.º 17
0
  private void qaulCopyFile(String filename) {
    AssetManager assetManager = this.getAssets();

    InputStream in = null;
    OutputStream out = null;
    String newFileName = null;
    try {
      Log.i(MSG_TAG, "copyFile() " + filename);
      in = assetManager.open(filename);
      if (filename.endsWith(".jpg")) // extension was added to avoid compression on APK file
      newFileName = dataPathString + "/" + filename.substring(0, filename.length() - 4);
      else newFileName = dataPathString + "/" + filename;
      out = new FileOutputStream(newFileName);

      byte[] buffer = new byte[1024];
      int read;
      while ((read = in.read(buffer)) != -1) {
        out.write(buffer, 0, read);
      }
      in.close();
      in = null;
      out.flush();
      out.close();
      out = null;
    } catch (Exception e) {
      Log.e(MSG_TAG, "Exception in copyFile() of " + newFileName);
      Log.e(MSG_TAG, "Exception in copyFile() " + e.toString());
    }
  }
Exemplo n.º 18
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    super.onCreate(savedInstanceState);
    TextView textView = new TextView(this);
    setContentView(textView);

    AssetManager assetManager = getAssets();
    InputStream inputStream = null;
    try {
      inputStream = assetManager.open("texts/myawesometext.txt");
      String text = loadTextFile(inputStream);
      textView.setText(text);
    } catch (IOException e) {
      textView.setText("Couldn't load file");
    } finally {
      if (inputStream != null) {
        try {
          inputStream.close();
        } catch (IOException e) {
          textView.setText("Couldn't close file");
        }
      }
    }
  }
  public SwitchButton(Context context) {
    super(context); // Si richiama il costruttore della superclasse
    onOffBound =
        new RectF(); // Creo il bound per il pulsante on/off,che è un oggetto di classe "RectF"
    try {
      AssetManager assetManager =
          context
              .getAssets(); // Creo un oggetto di classe AssetManager necessario per prelevare le
                            // risorse di tipo Assets

      InputStream inputStream =
          assetManager.open(
              "onbutton.png"); // Leggo e memorizzo nell'oggetto inputStream, la risorsa
                               // "onbutton.png" presente nella cartella Assets
      onButton =
          BitmapFactory.decodeStream(
              inputStream); // Decodifico l'inputStream,cioè l'immagine, in un oggetto Bitmap, e
                            // viene memorizzatio nell'oggetto "onButton"

      inputStream =
          assetManager.open(
              "offbutton.png"); // Leggo e memorizzo nell'oggetto inputStream, la risorsa
                                // "offbutton.png" presente nella cartella Assets
      offButton =
          BitmapFactory.decodeStream(
              inputStream); // Decodifico l'inputStream,cioè l'immagine, in un oggetto Bitmap, e
                            // viene memorizzatio nell'oggetto "offButton"

      inputStream
          .close(); // Chiude il flusso di input e rilascia tutte le risorse di sistema associate al
                    // flusso.
    } catch (IOException e) {
    }
  }
Exemplo n.º 20
0
  /**
   * Loads the achievements placed in the text file in the folder.
   *
   * @param textFile name of achievements text file.
   * @param context of the application.
   */
  public void loadAchievements(String textFile, Context context) {

    AssetManager assetManager = context.getAssets();

    Scanner scanner = null;
    try {
      scanner = new Scanner(assetManager.open(textFile + ".txt"));

      scanner = scanner.useDelimiter(";");
      while (scanner.hasNext()) {
        String name = scanner.next();
        String goal = scanner.next();
        String postName = scanner.next();
        String caption = scanner.next();
        String description = scanner.next();
        String link = scanner.next();
        boolean postOK = Boolean.parseBoolean(scanner.next());
        addAchievement(name, goal, postName, caption, description, link, postOK);
        scanner.nextLine();
      }
      scanner.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
  public static void get_assetsScript(String fn, Context c, String prefix, String postfix) {
    byte[] buffer;
    final AssetManager assetManager = c.getAssets();
    try {
      InputStream f = assetManager.open(fn);
      buffer = new byte[f.available()];
      f.read(buffer);
      f.close();
      final String s = new String(buffer);
      final StringBuffer sb = new StringBuffer(s);
      if (!postfix.equals("")) {
        sb.append("\n\n" + postfix);
      }
      if (!prefix.equals("")) {
        sb.insert(0, prefix + "\n");
      }
      sb.insert(0, "#!" + Helpers.binExist("sh") + "\n\n");
      try {
        FileOutputStream fos;
        fos = c.openFileOutput(fn, Context.MODE_PRIVATE);
        fos.write(sb.toString().getBytes());
        fos.close();

      } catch (IOException e) {
        Log.d(TAG, "error write " + fn + " file");
        e.printStackTrace();
      }

    } catch (IOException e) {
      Log.d(TAG, "error read " + fn + " file");
      e.printStackTrace();
    }
  }
  // 處理讀取Asset資料夾內的模型
  private Object3D loadModel(String filename, float scale) {
    Resources res = this.resource;
    AssetManager asManager = res.getAssets();
    Object3D obj3D = new Object3D(0);
    Object3D objTemp = null;

    try {
      Object3D[] model =
          Loader.load3DS(asManager.open(filename, AssetManager.ACCESS_UNKNOWN), scale);

      for (int i = 0; i < model.length; i++) {
        objTemp = model[i];
        objTemp.setCenter(SimpleVector.ORIGIN);
        objTemp.rotateX((float) (-0.5f * Math.PI));
        objTemp.rotateMesh();
        objTemp.setRotationMatrix(new Matrix());
        obj3D = Object3D.mergeObjects(obj3D, objTemp);
        obj3D.compile();
      }
      return obj3D;

    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return null;
  }
 /*
  * This method loads the data from the appropriate xml file
  */
 public void prepareData() {
   AssetManager manager = getAssets();
   InputStream is = null;
   int[] selectedIntValues =
       new int[] {
         categorySpinner.getSelectedItemPosition(), subcategorySpinner.getSelectedItemPosition()
       };
   String[] selectedStringValues = new String[selectedIntValues.length];
   for (int i = 0; i < selectedIntValues.length; i++) {
     if (selectedIntValues[i] < 10) {
       selectedStringValues[i] = "0" + selectedIntValues[i];
     } else {
       selectedStringValues[i] = "" + selectedIntValues[i];
     }
   }
   try {
     is =
         manager.open(
             "Category_"
                 + selectedStringValues[0]
                 + "/Shoplist_"
                 + selectedStringValues[1]
                 + ".xml");
   } catch (Exception e) {
     try {
       is = manager.open("empty_shoplist.xml");
     } catch (Exception e1) {
       // handle later
     }
   }
   handler = new MyXMLHandler(is);
 }
Exemplo n.º 24
0
  public void buildData() {

    try {
      _files = _assMan.list("files");
    } catch (IOException e) {
      e.printStackTrace();
    }

    for (int i = 0; i < _files.length; ++i) {
      Scanner scan;
      HashMap<String, Integer> hash;
      try {
        scan = new Scanner(_assMan.open(_files[i]));
        hash = new HashMap<String, Integer>();

        while (scan.hasNext()) {
          String[] current = scan.nextLine().split(" ");
          hash.put(current[0], Integer.valueOf(current[1]));
        }
        _map.put(_files[i].split(".")[0], hash);
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
Exemplo n.º 25
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_assets_test);

    // Show the Up button in the action bar.
    setupActionBar();

    display = (TextView) findViewById(R.id.display);

    AssetManager am = getAssets();
    InputStream is = null;

    try {
      is = am.open("songs/fly.txt");
      String text = loadFile(is);
      display.setText(text);
    } catch (IOException e) {
      display.setText("Error al abrir el archivo !!!");
    } finally {
      if (is != null) {
        try {
          is.close();
        } catch (IOException e) {
          display.setText("No se pudo cerrar el archivo");
        }
      }
    }
  }
Exemplo n.º 26
0
  public boolean parsePackage() {
    AssetManager assmgr = null;
    boolean assetError = true;
    try {
      assmgr = ReflectAccelerator.newAssetManager();
      if (assmgr == null) return false;

      int cookie = ReflectAccelerator.addAssetPath(assmgr, mArchiveSourcePath);
      if (cookie != 0) {
        parser = assmgr.openXmlResourceParser(cookie, "AndroidManifest.xml");
        assetError = false;
      } else {
        Log.w(TAG, "Failed adding asset path:" + mArchiveSourcePath);
      }
    } catch (Exception e) {
      Log.w(TAG, "Unable to read AndroidManifest.xml of " + mArchiveSourcePath, e);
    }
    if (assetError) {
      if (assmgr != null) assmgr.close();
      return false;
    }

    res = new Resources(assmgr, Small.getContext().getResources().getDisplayMetrics(), null);
    return parsePackage(res, parser);
  }
 public void loadConfig() {
   AssetManager am = mApp.getAssets();
   BufferedReader br = null;
   StringBuilder sb = new StringBuilder();
   try {
     br = new BufferedReader(new InputStreamReader(am.open("news_config.xml")));
     String line;
     while ((line = br.readLine()) != null) {
       sb.append(line);
     }
   } catch (IOException e) {
     e.printStackTrace();
   } finally {
     try {
       if (br != null) br.close();
     } catch (IOException e) {
       e.printStackTrace();
     }
   }
   JSONParser parser = new JSONParser();
   JSONObject jobj;
   try {
     jobj = (JSONObject) parser.parse(sb.toString());
     for (Object key : jobj.keySet()) {
       mProp.put(key, jobj.get(key));
     }
   } catch (ParseException e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 28
0
  public static String read(Instrumentation instrumentation, String fileName) {
    String data = "";

    try {
      BufferedReader bufferedReader = null;
      try {
        AssetManager assetManager = instrumentation.getContext().getAssets();
        InputStream inputStream = assetManager.open(fileName);
        bufferedReader = new BufferedReader(new InputStreamReader(inputStream));

        StringBuilder stringBuilder = new StringBuilder();
        String line;
        while ((line = bufferedReader.readLine()) != null) {
          stringBuilder.append(line);
        }

        data = stringBuilder.toString();
      } finally {
        if (bufferedReader != null) {
          bufferedReader.close();
        }
      }
    } catch (IOException e) {
      e.printStackTrace();
    }

    return data;
  }
Exemplo n.º 29
0
  private String loadData(Context context) {
    AssetManager assetManager = context.getResources().getAssets();
    byte[] buffer = null;

    InputStream inputStream = null;
    try {
      inputStream = assetManager.open(DATA_FILE_NAME);
      int size = inputStream.available();
      buffer = new byte[size];
      int n = -1;
      int bytesOffset = 0;
      byte[] tempBuffer = new byte[ADBlockUtils.BUFFER_TO_READ];
      while ((n = inputStream.read(tempBuffer)) != -1) {
        System.arraycopy(tempBuffer, 0, buffer, bytesOffset, n);
        bytesOffset += n;
      }
      inputStream.close();
    } catch (IOException e) {
      e.printStackTrace();
    }
    if (null == buffer) {
      return "";
    }

    return new String(buffer);
  }
 private void setNotificationLargeIcon(
     Bundle extras, String packageName, Resources resources, NotificationCompat.Builder mBuilder) {
   String gcmLargeIcon = extras.getString(IMAGE); // from gcm
   if (gcmLargeIcon != null && !"".equals(gcmLargeIcon)) {
     if (gcmLargeIcon.startsWith("http://") || gcmLargeIcon.startsWith("https://")) {
       mBuilder.setLargeIcon(getBitmapFromURL(gcmLargeIcon));
       Log.d(LOG_TAG, "using remote large-icon from gcm");
     } else {
       AssetManager assetManager = getAssets();
       InputStream istr;
       try {
         istr = assetManager.open(gcmLargeIcon);
         Bitmap bitmap = BitmapFactory.decodeStream(istr);
         mBuilder.setLargeIcon(bitmap);
         Log.d(LOG_TAG, "using assets large-icon from gcm");
       } catch (IOException e) {
         int largeIconId = 0;
         largeIconId = resources.getIdentifier(gcmLargeIcon, DRAWABLE, packageName);
         if (largeIconId != 0) {
           Bitmap largeIconBitmap = BitmapFactory.decodeResource(resources, largeIconId);
           mBuilder.setLargeIcon(largeIconBitmap);
           Log.d(LOG_TAG, "using resources large-icon from gcm");
         } else {
           Log.d(LOG_TAG, "Not setting large icon");
         }
       }
     }
   }
 }