public static boolean take_and_send() { try { Bitmap p = myTexture.getBitmap(); File outputDir = instance.getCacheDir(); // context being the Activity pointer File file = File.createTempFile("com.NXT", "file", outputDir); FileOutputStream fop = new FileOutputStream(file); p.compress(Bitmap.CompressFormat.JPEG, 40, fop); fop.flush(); fop.close(); // Ion.with(instance) // .load("http://172.16.128.219:5000/") // .setMultipartParameter("abc", "def") // .setMultipartFile("image", "image/jpeg", file) // .asJsonObject() // .setCallback(new FutureCallback<JsonObject>() { // @Override // public void onCompleted(Exception e, JsonObject result) { // if(e !=null) // e.printStackTrace(); // else // Log.e("OK", result.toString()); // } // }); // // // new And return true; } catch (IOException io) { Log.e("noo", "noo"); io.printStackTrace(); } return false; }
public KittenAdapter(final Activity activity, ImageLoader imageLoader) { KITTEN_URI = "file://" + activity.getCacheDir() + File.separator + IMAGE_FILE_NAME; mActivity = activity; mImageLoader = imageLoader; loadKittenToFile(); Point size = new Point(); mActivity.getWindowManager().getDefaultDisplay().getSize(size); mBounds = new Dimensions(size.x / 2, (int) ((size.x / 800f) * 200f)); mOptions = new Options(); mOptions.widthBounds = mBounds.width; mOptions.heightBounds = mBounds.height; mImagePrecacheAssistant = new AdapterImagesAssistant( mImageLoader, new PrecacheInformationProvider() { @Override public int getCount() { return KittenAdapter.this.getCount(); } @Override public List<String> getRequestsForDiskPrecache(int position) { List<String> list = new ArrayList<String>(); // if (position % 2 == 0) { list.add((String) getItem(position) + "1"); list.add((String) getItem(position) + "2"); // } else { // list.add((String) getItem(position)); // } return list; // return null; } @Override public List<PrecacheRequest> getRequestsForMemoryPrecache(int position) { List<PrecacheRequest> list = new ArrayList<PrecacheRequest>(); // if (position % 2 == 0) { list.add(new PrecacheRequest((String) getItem(position) + "1", mOptions)); list.add(new PrecacheRequest((String) getItem(position) + "2", mOptions)); // } else { // list.add(new PrecacheRequest((String) getItem(position), mOptions)); // } return list; // return null; } }); mImagePrecacheAssistant.setMemCacheRange(5); mImagePrecacheAssistant.setDiskCacheRange(10); }
public static String getCacheFileName() { if (temp_file == null) { Activity activity = null; if (handler != null) { if (handler instanceof Android2DHandler) { activity = ((Android2DHandler) handler).getLGameActivity(); } } if (activity != null) { temp_file = activity.getCacheDir().getAbsolutePath(); } } return temp_file; }
@Override public String call() throws IOException { AssetManager assMan = mParent.getResources().getAssets(); File cacheDir = mParent.getCacheDir(); String dataDirName = "tessdata"; File tessCacheDir = new File(cacheDir, dataDirName); boolean succeeded = false; for (int tries = 0; !succeeded; tries++) { InputStream istream = null; FileOutputStream ostream = null; try { if (!(tessCacheDir.mkdir() || tessCacheDir.isDirectory())) throw new IOException("Couldn't create tessCacheDir " + tessCacheDir.toString()); // List<String> cacheDirFiles = Arrays.asList(tessCacheDir.list(new // FilenameFilter() { // @Override public boolean accept(File dir, String filename) { return // filename.endsWith(".traineddata"); } // })); String[] tessDataFilenames = assMan.list(dataDirName); for (String dataFilename : tessDataFilenames) { // if (cacheDirFiles.contains(dataFilename)) // continue; istream = assMan.open(dataDirName + "/" + dataFilename, AssetManager.ACCESS_STREAMING); ostream = new FileOutputStream(new File(tessCacheDir, dataFilename)); byte[] buffer = new byte[0x80000]; int bytes_read; while ((bytes_read = istream.read(buffer)) != -1) ostream.write(buffer, 0, bytes_read); } succeeded = true; } catch (IOException ioe) { if (tries >= 3) throw ioe; try { Thread.sleep(1000); } catch (InterruptedException ie) { } } finally { if (istream != null) istream.close(); if (ostream != null) ostream.close(); } } return cacheDir.getAbsolutePath(); }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mContainer = container; setHasOptionsMenu(true); mActivity = getActivity(); mIsScreenLarge = !Utils.isPhone(mActivity); mResources = getResources(); mIsLandscape = mResources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; mTargetOffset = mIsLandscape && !mIsScreenLarge ? 2 : 0; mTargetInset = mResources.getDimensionPixelSize(com.android.internal.R.dimen.lockscreen_target_inset); mIconPicker = new IconPicker(mActivity, this); mPicker = new ShortcutPickHelper(mActivity, this); mImageTmp = new File(mActivity.getCacheDir() + "/target.tmp"); EMPTY_LABEL = mActivity.getResources().getString(R.string.lockscreen_target_empty); return inflater.inflate(R.layout.lockscreen_targets, container, false); }
@Test public void getDiskLruCacheDirectory_shouldReturnValidCacheDirectory() throws Exception { File file = CacheService.getDiskCacheDirectory(context); String expectedPath = context.getCacheDir().toString() + "/mopub-cache"; assertThat(file.getAbsolutePath()).isEqualTo(expectedPath); }
/** * Copies the file <code>kouchat-1600x1600.png</code> from assets to the cache directory of the * internal storage, if it's not already there. It will not be added to the media database. * * <p>The internal storage should be available even if the SD card is unmounted. * * @param instrumentation Test instrumentation. * @param activity The activity under test. */ public static void copyKouChatImageFromAssetsToInternalStorage( final Instrumentation instrumentation, final Activity activity) { final File cacheDir = activity.getCacheDir(); copyKouChatImageFromAssetsToStorage(instrumentation, activity, cacheDir, false); }
/** * Returns a representation of <code>kouchat-1600x1600.png</code> than can be used to get the * actual file on the internal storage. * * @param activity The activity under test. * @return <code>kouchat-1600x1600.png</code>. */ public static AndroidFile getKouChatImageFromInternalStorage(final Activity activity) { final File cacheDir = activity.getCacheDir(); final File image = new File(cacheDir, KOUCHAT_FILE); return new AndroidFile(image); }