List of usage examples for android.content Context openFileInput
public abstract FileInputStream openFileInput(String name) throws FileNotFoundException;
From source file:net.phase.wallet.Currency.java
public static Wallet[] getStoredWallets(Context context, WalletActivity activity) throws IOException { ArrayList<Wallet> walletsArray = new ArrayList<Wallet>(); String[] files = context.fileList(); if (files.length == 0) return null; for (String filename : files) { BufferedReader in = new BufferedReader(new InputStreamReader(context.openFileInput(filename))); try {/*from www.j av a2 s . co m*/ walletsArray.add(new Wallet(in, activity)); } catch (NumberFormatException e) { } in.close(); } Wallet[] wallets = new Wallet[walletsArray.size()]; walletsArray.toArray(wallets); return wallets; }
From source file:com.mocap.MocapFragment.java
public void Read_File(Context context) { FileInputStream fIn = null;/* w ww . j a v a 2 s.c o m*/ InputStreamReader isr = null; char[] inputBuffer = new char[255]; String data = null; JSONObject json = null; try { fIn = context.openFileInput("objet_1.obj"); isr = new InputStreamReader(fIn); isr.read(inputBuffer); data = new String(inputBuffer); //affiche le contenu de mon fichier dans un popup surgissant //Log.i(TAG, "Data: " + data); //Toast.makeText(context, "data: " + data, Toast.LENGTH_SHORT).show(); //json=new JSONObject(data); } catch (Exception e) { Toast.makeText(context, "Objet not read", Toast.LENGTH_SHORT).show(); } /*finally { try { isr.close(); fIn.close(); } catch (IOException e) { Toast.makeText(context, "Settings not read",Toast.LENGTH_SHORT).show(); } } */ //return json; }
From source file:org.jraf.android.hellomundo.app.saveshare.SaveShareHelper.java
@Background(Type.DISK) private WebcamInfo saveAndInsertImage(Context context, int appwidgetId) throws Exception { long webcamId; if (appwidgetId == WALLPAPER) { webcamId = getCurrentWallpaperWebcamId(context); } else {/*from ww w . j av a 2 s .c o m*/ webcamId = AppwidgetManager.get().getCurrentWebcamId(context, appwidgetId); if (webcamId == Constants.WEBCAM_ID_NONE) throw new Exception("Could not get webcamId for appwidgetId=" + appwidgetId); } // 2.1 equivalent of File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File picturesPath = new File(Environment.getExternalStorageDirectory(), "Pictures"); File path = new File(picturesPath, "HelloMundo"); WebcamInfo webcamInfo = getWebcamInfo(context, webcamId); if (webcamInfo == null) { throw new Exception("Could not get webcam info"); } String fileName = webcamInfo.getFileName(context); File file = new File(path, fileName); path.mkdirs(); String imageFile; if (appwidgetId == WALLPAPER) { imageFile = Constants.FILE_IMAGE_WALLPAPER; } else { imageFile = AppwidgetManager.get().getFileName(appwidgetId); } InputStream inputStream = context.openFileInput(imageFile); OutputStream outputStream = new FileOutputStream(file); try { IoUtil.copy(inputStream, outputStream); } finally { IoUtil.closeSilently(inputStream, outputStream); } // Scan it final AtomicReference<Uri> scannedImageUri = new AtomicReference<Uri>(); MediaScannerUtil.scanFile(context, new String[] { file.getPath() }, null, new OnScanCompletedListener() { @Override public void onScanCompleted(String p, Uri uri) { Log.d("path=" + p + " uri=" + uri); scannedImageUri.set(uri); } }); // Wait until the media scanner has found our file long start = System.currentTimeMillis(); while (scannedImageUri.get() == null) { Log.d("Waiting 250ms for media scanner..."); SystemClock.sleep(250); if (System.currentTimeMillis() - start > 5000) { throw new Exception("MediaScanner did not scan the file " + file + " after 5000ms"); } } webcamInfo.localBitmapUriStr = scannedImageUri.get().toString(); return webcamInfo; }
From source file:com.thoughtmetric.tl.TLLib.java
public static Object[] parseEditText(HtmlCleaner cleaner, URL url, TLHandler handler, Context context) throws IOException { // Although probably not THE worst hack I've written, this function ranks near the top. // TODO: rework this routine get rid of code duplication. DefaultHttpClient httpclient = new DefaultHttpClient(); httpclient.setCookieStore(cookieStore); HttpGet httpGet = new HttpGet(url.toExternalForm()); HttpResponse response = httpclient.execute(httpGet); handler.sendEmptyMessage(PROGRESS_DOWNLOADING); InputStream is = response.getEntity().getContent(); InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); FileOutputStream fos = context.openFileOutput(TEMP_FILE_NAME, Context.MODE_PRIVATE); BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos)); String line;/* www.j av a 2 s .c o m*/ String formStart = "<form action=\"/forum/edit.php"; while ((line = br.readLine()) != null) { if (line.startsWith(formStart)) { Log.d(TAG, line); bw.write(line); break; } } String start = "\t\t<textarea"; String end = "\t\t<p>"; StringBuffer sb = new StringBuffer(); while ((line = br.readLine()) != null) { if (line.startsWith(start)) { bw.write("</form>"); int i = line.lastIndexOf('>'); sb.append(Html.fromHtml(line.substring(i + 1)).toString()); sb.append("\n"); break; } else { bw.write(line); } } while ((line = br.readLine()) != null) { if (line.startsWith(end)) { break; } sb.append(Html.fromHtml(line).toString()); sb.append("\n"); } bw.flush(); bw.close(); if (handler != null) handler.sendEmptyMessage(PROGRESS_PARSING); Object[] ret = new Object[2]; ret[0] = sb.toString(); ret[1] = cleaner.clean(context.openFileInput(TEMP_FILE_NAME)); return ret; }
From source file:org.dharmaseed.android.TalkCursorAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { // Set talk title and teacher name TextView title = (TextView) view.findViewById(R.id.item_view_title); TextView teacher = (TextView) view.findViewById(R.id.item_view_detail1); TextView center = (TextView) view.findViewById(R.id.item_view_detail2); title.setText(getString(cursor, DBManager.C.Talk.TABLE_NAME + "." + DBManager.C.Talk.TITLE)); teacher.setText(getString(cursor, DBManager.C.Teacher.TABLE_NAME + "." + DBManager.C.Teacher.NAME)); center.setText(getString(cursor, DBManager.C.Center.TABLE_NAME + "." + DBManager.C.Teacher.NAME)); // Set date/*from www . j a v a 2 s.c om*/ TextView date = (TextView) view.findViewById(R.id.item_view_detail3); String recDate = getString(cursor, DBManager.C.Talk.TABLE_NAME + "." + DBManager.C.Talk.RECORDING_DATE); try { date.setText(DateFormat.getDateInstance().format(parser.parse(recDate))); } catch (ParseException e) { date.setText(""); } // Set the talk duration final TextView durationView = (TextView) view.findViewById(R.id.item_view_detail4); double duration = cursor.getDouble(cursor.getColumnIndexOrThrow( DBManager.getAlias(DBManager.C.Talk.TABLE_NAME + "." + DBManager.C.Talk.DURATION_IN_MINUTES))); String durationStr = DateUtils.formatElapsedTime((long) (duration * 60)); durationView.setText(durationStr); // Set teacher photo String photoFilename = DBManager.getTeacherPhotoFilename(cursor.getInt(cursor.getColumnIndexOrThrow( DBManager.getAlias(DBManager.C.Talk.TABLE_NAME + "." + DBManager.C.Talk.TEACHER_ID)))); ImageView photoView = (ImageView) view.findViewById(R.id.item_view_photo); try { FileInputStream photo = context.openFileInput(photoFilename); photoView.setImageBitmap(BitmapFactory.decodeStream(photo)); } catch (FileNotFoundException e) { Drawable icon = ContextCompat.getDrawable(context, R.drawable.dharmaseed_icon); photoView.setImageDrawable(icon); } // Set talk stars handleStars(view, cursor.getInt(cursor.getColumnIndexOrThrow(DBManager.C.Talk.ID))); }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Checks if a file exists in the application internal private data folder. * // ww w .j a va 2 s .c o m * @param context * @param fileName * @return */ public static boolean storage_checkIfFileExistsInInternalStorage(Context context, String fileName) { try { context.openFileInput(fileName); return true; } catch (FileNotFoundException e) { return false; } }
From source file:com.android.leanlauncher.LauncherTransitionable.java
private static void readConfiguration(Context context, LocaleConfiguration configuration) { DataInputStream in = null;//from ww w . ja va 2 s .co m try { in = new DataInputStream(context.openFileInput(LauncherFiles.LAUNCHER_PREFERENCES)); configuration.locale = in.readUTF(); configuration.mcc = in.readInt(); configuration.mnc = in.readInt(); } catch (FileNotFoundException e) { // Ignore } catch (IOException e) { // Ignore } finally { if (in != null) { try { in.close(); } catch (IOException e) { // Ignore } } } }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Loads a Bitmap image form the internal storage. * /* w ww . ja v a 2 s . co m*/ * @param context * @param fileName * @return * @throws Exception */ public static Bitmap media_loadBitmapFromInternalStorage(Context context, String fileName) throws Exception { try { FileInputStream is = context.openFileInput(fileName); Bitmap b = BitmapFactory.decodeStream(is); return b; } catch (Exception e) { throw new Exception("Error reading data '" + fileName + "' (internal storage) : " + e.getMessage(), e); } }
From source file:es.javocsoft.android.lib.toolbox.ToolBox.java
/** * Reads data from the application internal storage data folder. * /*from w ww .j a v a2 s . c om*/ * @param context * @param fileName * @return * @throws Exception */ public static byte[] storage_readDataFromInternalStorage(Context context, String fileName) throws Exception { FileInputStream fIn; try { fIn = context.openFileInput(fileName); byte[] buffer = new byte[fIn.available()]; fIn.read(buffer); fIn.close(); return buffer; } catch (Exception e) { throw new Exception("Error reading data '" + fileName + "' (internal storage) : " + e.getMessage(), e); } }
From source file:com.android.launcher2.Launcher.java
private static void readConfiguration(Context context, LocaleConfiguration configuration) { DataInputStream in = null;/*from w w w . j ava 2s . c om*/ try { in = new DataInputStream(context.openFileInput(PREFERENCES)); configuration.locale = in.readUTF(); configuration.mcc = in.readInt(); configuration.mnc = in.readInt(); } catch (FileNotFoundException e) { // Ignore } catch (IOException e) { // Ignore } finally { if (in != null) { try { in.close(); } catch (IOException e) { // Ignore } } } }