// common utility - return intent to launch reader by reader name and full file name. Null if not // found public Intent launchReader(String name, String file) { String re[] = name.split(":"); if (re.length == 2 && re[0].equals("Intent")) { Intent i = new Intent(); i.setAction(Intent.ACTION_VIEW); i.setDataAndType(Uri.parse("file://" + file), re[1]); addToList("lastOpened", file, false); if (!history.containsKey(file) || history.get(file) == FINISHED) history.put(file, READING); return i; } else { Intent i = getIntentByLabel(name); if (i == null) // Toast.makeText(this, "Activity \"" + name + "\" not found!", Toast.LENGTH_SHORT).show(); Toast.makeText( this, getResources().getString(R.string.jv_rla_activity) + " \"" + name + "\" " + getResources().getString(R.string.jv_rla_not_found), Toast.LENGTH_SHORT) .show(); else { i.setAction(Intent.ACTION_VIEW); i.setData(Uri.parse("file://" + file)); addToList("lastOpened", file, false); if (!history.containsKey(file) || history.get(file) == FINISHED) history.put(file, READING); return i; } } return null; }
public boolean readFile(String listName, String fileName, String delimiter) { FileInputStream fis = null; try { fis = openFileInput(fileName); } catch (FileNotFoundException e) { } if (fis == null) return false; else { InputStreamReader insr = null; try { insr = new InputStreamReader(fis, "utf8"); } catch (UnsupportedEncodingException e) { return false; } BufferedReader bufr = new BufferedReader(insr, FileBufferSize); String l = new String(); while (true) { try { l = bufr.readLine(); } catch (IOException e) { return false; } if (l == null) break; if (!l.equals("")) { // Log.d(TAG, "ADD (last) \"" + l + "\""); addToList(listName, l, true, delimiter); } } try { bufr.close(); insr.close(); fis.close(); } catch (IOException e) { } } return true; }
public void addToList(String listName, String fullName, Boolean addToEnd) { addToList(listName, fullName, addToEnd, "/"); }