List of usage examples for java.io FileNotFoundException getStackTrace
public StackTraceElement[] getStackTrace()
From source file:com.phonegap.plugins.wsiCameraLauncher.WsiCameraLauncher.java
/** * Called when the camera view exits./* w ww. j av a2 s .c o m*/ * * @param requestCode * The request code originally supplied to * startActivityForResult(), allowing you to identify who this * result came from. * @param resultCode * The integer result code returned by the child activity through * its setResult(). * @param intent * An Intent, which can return result data to the caller (various * data can be attached to Intent "extras"). */ public void onActivityResult(int requestCode, int resultCode, Intent intent) { // Get src and dest types from request code int srcType = (requestCode / 16) - 1; int destType = (requestCode % 16) - 1; int rotate = 0; Log.d(LOG_TAG, "-z"); // If retrieving photo from library if ((srcType == PHOTOLIBRARY) || (srcType == SAVEDPHOTOALBUM)) { Log.d(LOG_TAG, "-y"); if (resultCode == Activity.RESULT_OK) { Log.d(LOG_TAG, "-x"); Uri uri = intent.getData(); Log.d(LOG_TAG, "-w"); // If you ask for video or all media type you will automatically // get back a file URI // and there will be no attempt to resize any returned data if (this.mediaType != PICTURE) { Log.d(LOG_TAG, "mediaType not PICTURE, so must be Video"); String metadataDateTime = ""; ExifInterface exif; try { exif = new ExifInterface(this.getRealPathFromURI(uri, this.cordova)); if (exif.getAttribute(ExifInterface.TAG_DATETIME) != null) { Log.d(LOG_TAG, "z4a"); metadataDateTime = exif.getAttribute(ExifInterface.TAG_DATETIME).toString(); metadataDateTime = metadataDateTime.replaceFirst(":", "-"); metadataDateTime = metadataDateTime.replaceFirst(":", "-"); } } catch (IOException e2) { // TODO Auto-generated catch block e2.printStackTrace(); } Log.d(LOG_TAG, "before create thumbnail"); Bitmap bitmap = ThumbnailUtils.createVideoThumbnail( (new File(this.getRealPathFromURI(uri, this.cordova))).getAbsolutePath(), MediaStore.Images.Thumbnails.MINI_KIND); Log.d(LOG_TAG, "after create thumbnail"); String mid = generateRandomMid(); try { String filePathMedium = this.getTempDirectoryPath(this.cordova.getActivity()) + "/medium_" + mid + ".jpg"; FileOutputStream foMedium = new FileOutputStream(filePathMedium); bitmap.compress(CompressFormat.JPEG, 100, foMedium); foMedium.flush(); foMedium.close(); bitmap.recycle(); System.gc(); JSONObject mediaFile = new JSONObject(); try { mediaFile.put("mid", mid); mediaFile.put("mediaType", "video"); mediaFile.put("filePath", filePathMedium); mediaFile.put("filePathMedium", filePathMedium); mediaFile.put("filePathThumb", filePathMedium); mediaFile.put("typeOfPluginResult", "initialRecordInformer"); String absolutePath = (new File(this.getRealPathFromURI(uri, this.cordova))) .getAbsolutePath(); mediaFile.put("fileExt", absolutePath.substring(absolutePath.lastIndexOf(".") + 1)); if (metadataDateTime != "") { mediaFile.put("metadataDateTime", metadataDateTime); } } catch (JSONException e) { Log.d(LOG_TAG, "error: " + e.getStackTrace().toString()); } Log.d(LOG_TAG, "mediafile at 638" + mediaFile.toString()); PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, (new JSONArray()).put(mediaFile)); pluginResult.setKeepCallback(true); this.callbackContext.sendPluginResult(pluginResult); new UploadVideoToS3Task().execute(new File(this.getRealPathFromURI(uri, this.cordova)), this.callbackContext, mid, mediaFile); } catch (FileNotFoundException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } } else { String imagePath = this.getRealPathFromURI(uri, this.cordova); String mimeType = FileUtils.getMimeType(imagePath); // If we don't have a valid image so quit. if (imagePath == null || mimeType == null || !(mimeType.equalsIgnoreCase("image/jpeg") || mimeType.equalsIgnoreCase("image/png"))) { Log.d(LOG_TAG, "I either have a null image path or bitmap"); this.failPicture("Unable to retrieve path to picture!"); return; } String mid = generateRandomMid(); Log.d(LOG_TAG, "a"); JSONObject mediaFile = new JSONObject(); Log.d(LOG_TAG, "b"); try { FileInputStream fi = new FileInputStream(imagePath); Bitmap bitmap = BitmapFactory.decodeStream(fi); fi.close(); Log.d(LOG_TAG, "z1"); // try to get exif data ExifInterface exif = new ExifInterface(imagePath); Log.d(LOG_TAG, "z2"); JSONObject metadataJson = new JSONObject(); Log.d(LOG_TAG, "z3"); /* JSONObject latlng = new JSONObject(); String lat = "0"; String lng = "0"; if (exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE) != null) { lat = exif.getAttribute(ExifInterface.TAG_GPS_LATITUDE); } if (exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE) != null) { lng = exif.getAttribute(ExifInterface.TAG_GPS_LONGITUDE); } latlng.put("lat", lat); latlng.put("lng", lng); Log.d(LOG_TAG, "z4"); metadataJson.put("locationData", latlng); */ String metadataDateTime = ""; if (exif.getAttribute(ExifInterface.TAG_DATETIME) != null) { Log.d(LOG_TAG, "z4a"); JSONObject exifWrapper = new JSONObject(); exifWrapper.put("DateTimeOriginal", exif.getAttribute(ExifInterface.TAG_DATETIME).toString()); exifWrapper.put("DateTimeDigitized", exif.getAttribute(ExifInterface.TAG_DATETIME).toString()); metadataDateTime = exif.getAttribute(ExifInterface.TAG_DATETIME).toString(); metadataDateTime = metadataDateTime.replaceFirst(":", "-"); metadataDateTime = metadataDateTime.replaceFirst(":", "-"); Log.d(LOG_TAG, "z5"); metadataJson.put("Exif", exifWrapper); } Log.d(LOG_TAG, "z6"); Log.d(LOG_TAG, "metadataJson: " + metadataJson.toString()); Log.d(LOG_TAG, "metadataDateTime: " + metadataDateTime.toString()); if (exif.getAttribute(ExifInterface.TAG_ORIENTATION) != null) { int o = Integer.parseInt(exif.getAttribute(ExifInterface.TAG_ORIENTATION)); Log.d(LOG_TAG, "z7"); if (o == ExifInterface.ORIENTATION_NORMAL) { rotate = 0; } else if (o == ExifInterface.ORIENTATION_ROTATE_90) { rotate = 90; } else if (o == ExifInterface.ORIENTATION_ROTATE_180) { rotate = 180; } else if (o == ExifInterface.ORIENTATION_ROTATE_270) { rotate = 270; } else { rotate = 0; } Log.d(LOG_TAG, "z8"); Log.d(LOG_TAG, "rotate: " + rotate); // try to correct orientation if (rotate != 0) { Matrix matrix = new Matrix(); Log.d(LOG_TAG, "z9"); matrix.setRotate(rotate); Log.d(LOG_TAG, "z10"); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); Log.d(LOG_TAG, "z11"); } } Log.d(LOG_TAG, "c"); String filePath = this.getTempDirectoryPath(this.cordova.getActivity()) + "/econ_" + mid + ".jpg"; FileOutputStream foEcon = new FileOutputStream(filePath); fitInsideSquare(bitmap, 850).compress(CompressFormat.JPEG, 45, foEcon); foEcon.flush(); foEcon.close(); Log.d(LOG_TAG, "d"); String filePathMedium = this.getTempDirectoryPath(this.cordova.getActivity()) + "/medium_" + mid + ".jpg"; FileOutputStream foMedium = new FileOutputStream(filePathMedium); makeInsideSquare(bitmap, 320).compress(CompressFormat.JPEG, 55, foMedium); foMedium.flush(); foMedium.close(); Log.d(LOG_TAG, "e"); String filePathThumb = this.getTempDirectoryPath(this.cordova.getActivity()) + "/thumb_" + mid + ".jpg"; FileOutputStream foThumb = new FileOutputStream(filePathThumb); makeInsideSquare(bitmap, 175).compress(CompressFormat.JPEG, 55, foThumb); foThumb.flush(); foThumb.close(); bitmap.recycle(); System.gc(); Log.d(LOG_TAG, "f"); mediaFile.put("mid", mid); mediaFile.put("mediaType", "photo"); mediaFile.put("filePath", filePath); mediaFile.put("filePathMedium", filePath); mediaFile.put("filePathThumb", filePath); mediaFile.put("typeOfPluginResult", "initialRecordInformer"); //mediaFile.put("metadataJson", metadataJson); if (metadataDateTime != "") { mediaFile.put("metadataDateTime", metadataDateTime); } PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, (new JSONArray()).put(mediaFile)); pluginResult.setKeepCallback(true); this.callbackContext.sendPluginResult(pluginResult); Log.d(LOG_TAG, "g"); Log.d(LOG_TAG, "mediaFile " + mediaFile.toString()); new UploadFilesToS3Task().execute(new File(filePath), new File(filePathMedium), new File(filePathThumb), this.callbackContext, mid, mediaFile); Log.d(LOG_TAG, "h"); } catch (FileNotFoundException e) { Log.d(LOG_TAG, "error: " + e.getStackTrace().toString()); } catch (IOException e1) { // TODO Auto-generated catch block Log.d(LOG_TAG, "error: " + e1.getStackTrace().toString()); } catch (JSONException e2) { // TODO Auto-generated catch block Log.d(LOG_TAG, "error: " + e2.getStackTrace().toString()); } /* if (this.correctOrientation) { String[] cols = { MediaStore.Images.Media.ORIENTATION }; Cursor cursor = this.cordova .getActivity() .getContentResolver() .query(intent.getData(), cols, null, null, null); if (cursor != null) { cursor.moveToPosition(0); rotate = cursor.getInt(0); cursor.close(); } if (rotate != 0) { Matrix matrix = new Matrix(); matrix.setRotate(rotate); bitmap = Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true); } } // Create an ExifHelper to save the exif // data that is lost during compression String resizePath = this .getTempDirectoryPath(this.cordova .getActivity()) + "/resize.jpg"; ExifHelper exif = new ExifHelper(); try { if (this.encodingType == JPEG) { exif.createInFile(resizePath); exif.readExifData(); rotate = exif.getOrientation(); } } catch (IOException e) { e.printStackTrace(); } OutputStream os = new FileOutputStream( resizePath); bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); os.close(); // Restore exif data to file if (this.encodingType == JPEG) { exif.createOutFile(this .getRealPathFromURI(uri, this.cordova)); exif.writeExifData(); } if (bitmap != null) { bitmap.recycle(); bitmap = null; } System.gc(); // The resized image is cached by the app in // order to get around this and not have to // delete your // application cache I'm adding the current // system time to the end of the file url. this.callbackContext.success("file://" + resizePath + "?" + System.currentTimeMillis()); */ } } else if (resultCode == Activity.RESULT_CANCELED) { this.failPicture("Selection cancelled."); } else { this.failPicture("Selection did not complete!"); } } }
From source file:com.xperia64.rompatcher.MainActivity.java
public void patch(final boolean c, final boolean d, final boolean r, final String ed) { final ProgressDialog myPd_ring = ProgressDialog.show(MainActivity.this, getResources().getString(R.string.wait), getResources().getString(R.string.wait_desc), true); myPd_ring.setCancelable(false);//from ww w .j a va2 s. c o m new Thread(new Runnable() { public void run() { if (new File(Globals.patchToApply).exists() && new File(Globals.fileToPatch).exists() && !Globals.fileToPatch.toLowerCase(Locale.US).endsWith(".ecm")) { String msg = getResources().getString(R.string.success); if (!new File(Globals.fileToPatch).canWrite()) { Globals.msg = msg = "Can not write to output file. If you are on KitKat or Lollipop, move the file to your internal storage."; return; } if (Globals.patchToApply.toLowerCase(Locale.US).endsWith(".ups")) { int e = upsPatchRom(Globals.fileToPatch, Globals.patchToApply, Globals.fileToPatch + ".new", r ? 1 : 0); if (e != 0) { msg = parseError(e, Globals.TYPE_UPS); } } else if (Globals.patchToApply.toLowerCase(Locale.US).endsWith(".xdelta") || Globals.patchToApply.toLowerCase(Locale.US).endsWith(".xdelta3") || Globals.patchToApply.toLowerCase(Locale.US).endsWith(".vcdiff")) { RandomAccessFile f = null; try { f = new RandomAccessFile(Globals.patchToApply, "r"); } catch (FileNotFoundException e1) { e1.printStackTrace(); Globals.msg = msg = getResources().getString(R.string.fnf); return; } StringBuilder s = new StringBuilder(); try { if (f.length() >= 9) { for (int i = 0; i < 8; i++) { s.append((char) f.readByte()); f.seek(i + 1); } } } catch (IOException e1) { e1.printStackTrace(); } try { f.close(); } catch (IOException e1) { e1.printStackTrace(); } // Header of xdelta patch determines version if (s.toString().equals("%XDELTA%") || s.toString().equals("%XDZ000%") || s.toString().equals("%XDZ001%") || s.toString().equals("%XDZ002%") || s.toString().equals("%XDZ003%") || s.toString().equals("%XDZ004%")) { int e = xdelta1PatchRom(Globals.fileToPatch, Globals.patchToApply, Globals.fileToPatch + ".new"); if (e != 0) { msg = parseError(e, Globals.TYPE_XDELTA1); } } else { int e = xdelta3PatchRom(Globals.fileToPatch, Globals.patchToApply, Globals.fileToPatch + ".new"); if (e != 0) { msg = parseError(e, Globals.TYPE_XDELTA3); } } } else if (Globals.patchToApply.toLowerCase(Locale.US).endsWith(".bps")) { int e = bpsPatchRom(Globals.fileToPatch, Globals.patchToApply, Globals.fileToPatch + ".new", r ? 1 : 0); if (e != 0) { msg = parseError(e, Globals.TYPE_BPS); } } else if (Globals.patchToApply.toLowerCase(Locale.US).endsWith(".dps")) { int e = dpsPatchRom(Globals.fileToPatch, Globals.patchToApply, Globals.fileToPatch + ".new"); if (e != 0) { msg = parseError(e, Globals.TYPE_DPS); } } else if (Globals.patchToApply.toLowerCase(Locale.US).endsWith(".bsdiff")) { int e = bsdiffPatchRom(Globals.fileToPatch, Globals.patchToApply, Globals.fileToPatch + ".new"); if (e != 0) { msg = parseError(e, Globals.TYPE_BSDIFF); } } else if (Globals.patchToApply.toLowerCase(Locale.US).endsWith(".aps")) { File f = new File(Globals.fileToPatch); File f2 = new File(Globals.fileToPatch + ".bak"); try { Files.copy(f, f2); } catch (IOException e) { e.printStackTrace(); } // Wow. byte[] gbaSig = { 0x41, 0x50, 0x53, 0x31, 0x00 }; byte[] n64Sig = { 0x41, 0x50, 0x53, 0x31, 0x30 }; byte[] realSig = new byte[5]; RandomAccessFile raf = null; System.out.println("APS Patch"); try { raf = new RandomAccessFile(Globals.patchToApply, "r"); } catch (FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); Globals.msg = msg = getResources().getString(R.string.fnf); return; } try { raf.read(realSig); raf.close(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } if (Arrays.equals(realSig, gbaSig)) { System.out.println("GBA APS"); APSGBAPatcher aa = new APSGBAPatcher(); aa.crcTableInit(); int e = 0; try { e = aa.ApplyPatch(Globals.patchToApply, Globals.fileToPatch, r); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); e = -5; } System.out.println("e: " + e); if (e != 0) { msg = parseError(e, Globals.TYPE_APSGBA); } } else if (Arrays.equals(realSig, n64Sig)) { System.out.println("N64 APS"); int e = apsN64PatchRom(Globals.fileToPatch, Globals.patchToApply); if (e != 0) { msg = parseError(e, Globals.TYPE_APSN64); } } else { msg = parseError(-131, -10000); } } else if (Globals.patchToApply.toLowerCase(Locale.US).endsWith(".ppf")) { File f = new File(Globals.fileToPatch); File f2 = new File(Globals.fileToPatch + ".bak"); try { Files.copy(f, f2); } catch (IOException e) { e.printStackTrace(); } int e = ppfPatchRom(Globals.fileToPatch, Globals.patchToApply, r ? 1 : 0); if (e != 0) { msg = parseError(e, Globals.TYPE_PPF); } } else if (Globals.patchToApply.toLowerCase(Locale.US).endsWith(".patch")) { int e = xdelta1PatchRom(Globals.fileToPatch, Globals.patchToApply, Globals.fileToPatch + ".new"); if (e != 0) { msg = parseError(e, Globals.TYPE_XDELTA1); } } else if (Globals.patchToApply.toLowerCase(Locale.US).endsWith(".asm")) { File f = new File(Globals.fileToPatch); File f2 = new File(Globals.fileToPatch + ".bak"); try { Files.copy(f, f2); } catch (IOException e) { e.printStackTrace(); } int e; if (Globals.asar) e = asarPatchRom(Globals.fileToPatch, Globals.patchToApply, r ? 1 : 0); else e = asmPatchRom(Globals.fileToPatch, Globals.patchToApply); if (e != 0) { msg = parseError(e, Globals.TYPE_ASM); } } else if (Globals.patchToApply.toLowerCase(Locale.US).endsWith(".dldi")) { File f = new File(Globals.fileToPatch); File f2 = new File(Globals.fileToPatch + ".bak"); try { Files.copy(f, f2); } catch (IOException e) { e.printStackTrace(); } int e = dldiPatchRom(Globals.fileToPatch, Globals.patchToApply); if (e != 0) { msg = parseError(e, Globals.TYPE_DLDI); } } else if (Globals.patchToApply.toLowerCase(Locale.US).endsWith(".xpc")) { int e = xpcPatchRom(Globals.fileToPatch, Globals.patchToApply, Globals.fileToPatch + ".new"); if (e != 0) { msg = parseError(e, Globals.TYPE_XPC); } } else if (Globals.patchToApply.toLowerCase(Locale.US).endsWith(".nmp")) { String drm = MainActivity.this.getPackageName(); System.out.println("Drm is: " + drm); if (drm.equals("com.xperia64.rompatcher.donation")) { if (c) { File f = new File(Globals.fileToPatch); File f2 = new File(Globals.fileToPatch + ".bak"); try { Files.copy(f, f2); } catch (IOException e) { e.printStackTrace(); } } NitroROMFilesystem fs; try { fs = new NitroROMFilesystem(Globals.fileToPatch); ROM.load(fs); RealPatch.patch(Globals.patchToApply, new Object()); ROM.close(); } catch (Exception e1) { // TODO Auto-generated catch block //e1.printStackTrace(); Globals.msg = msg = String.format(getResources().getString(R.string.nmpDefault), e1.getStackTrace()[0].getFileName(), e1.getStackTrace()[0].getLineNumber()); } if (c && d && !TextUtils.isEmpty(ed)) { File f = new File(Globals.fileToPatch); File f3 = new File(Globals.fileToPatch + ".bak"); File f2 = new File( Globals.fileToPatch.substring(0, Globals.fileToPatch.lastIndexOf('/') + 1) + ed); f.renameTo(f2); f3.renameTo(f); } } else { Globals.msg = msg = getResources().getString(R.string.drmwarning); MainActivity.this.runOnUiThread(new Runnable() { public void run() { AlertDialog.Builder b = new AlertDialog.Builder(MainActivity.this); b.setTitle(getResources().getString(R.string.drmwarning)); b.setIcon( ResourcesCompat.getDrawable(getResources(), R.drawable.icon_pro, null)); b.setMessage(getResources().getString(R.string.drmwarning_desc)); b.setCancelable(false); b.setNegativeButton(getResources().getString(android.R.string.cancel), new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { } }); b.setPositiveButton(getResources().getString(R.string.nagInfo), new OnClickListener() { @Override public void onClick(DialogInterface arg0, int arg1) { try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse( "market://details?id=com.xperia64.rompatcher.donation"))); } catch (android.content.ActivityNotFoundException anfe) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse( "http://play.google.com/store/apps/details?id=com.xperia64.rompatcher.donation"))); } } }); b.create().show(); } }); } } else { RandomAccessFile f = null; try { f = new RandomAccessFile(Globals.patchToApply, "r"); } catch (FileNotFoundException e1) { e1.printStackTrace(); Globals.msg = msg = getResources().getString(R.string.fnf); return; } StringBuilder s = new StringBuilder(); try { if (f.length() >= 6) { for (int i = 0; i < 5; i++) { s.append((char) f.readByte()); f.seek(i + 1); } } } catch (IOException e1) { e1.printStackTrace(); } try { f.close(); } catch (IOException e1) { e1.printStackTrace(); } int e; // Two variants of IPS, the normal PATCH type, then this weird one called IPS32 with messily hacked in 32 bit offsets if (s.toString().equals("IPS32")) { e = ips32PatchRom(Globals.fileToPatch, Globals.patchToApply); if (e != 0) { msg = parseError(e, Globals.TYPE_IPS); } } else { e = ipsPatchRom(Globals.fileToPatch, Globals.patchToApply); if (e != 0) { msg = parseError(e, Globals.TYPE_IPS); } } } if (Globals.patchToApply.toLowerCase(Locale.US).endsWith(".ups") || Globals.patchToApply.toLowerCase(Locale.US).endsWith(".xdelta") || Globals.patchToApply.toLowerCase(Locale.US).endsWith(".xdelta3") || Globals.patchToApply.toLowerCase(Locale.US).endsWith(".vcdiff") || Globals.patchToApply.toLowerCase(Locale.US).endsWith(".patch") || Globals.patchToApply.toLowerCase(Locale.US).endsWith(".bps") || Globals.patchToApply.toLowerCase(Locale.US).endsWith(".bsdiff") || Globals.patchToApply.toLowerCase(Locale.US).endsWith(".dps") || Globals.patchToApply.toLowerCase(Locale.US).endsWith(".xpc")) { File oldrom = new File(Globals.fileToPatch); File bkrom = new File(Globals.fileToPatch + ".bak"); oldrom.renameTo(bkrom); File newrom = new File(Globals.fileToPatch + ".new"); newrom.renameTo(oldrom); } if (!c) { File f = new File(Globals.fileToPatch + ".bak"); if (f.exists()) { f.delete(); } } else { if (d) { File one = new File(Globals.fileToPatch + ".bak"); File two = new File(Globals.fileToPatch); File three = new File( Globals.fileToPatch.substring(0, Globals.fileToPatch.lastIndexOf('/') + 1) + ed); two.renameTo(three); File four = new File(Globals.fileToPatch); one.renameTo(four); } } Globals.msg = msg; } else if (Globals.fileToPatch.toLowerCase(Locale.US).endsWith(".ecm")) { int e = 0; String msg = getResources().getString(R.string.success); if (c) { if (d) { e = ecmPatchRom(Globals.fileToPatch, Globals.fileToPatch.substring(0, Globals.fileToPatch.lastIndexOf('/')) + ed, 1); } else { //new File(Globals.fileToPatch).renameTo(new File(Globals.fileToPatch+".bak")); e = ecmPatchRom(Globals.fileToPatch, Globals.fileToPatch.substring(0, Globals.fileToPatch.lastIndexOf('.')), 1); } } else { e = ecmPatchRom(Globals.fileToPatch, "", 0); } if (e != 0) { msg = parseError(e, Globals.TYPE_ECM); } Globals.msg = msg; } else { Globals.msg = getResources().getString(R.string.fnf); } } }).start(); new Thread(new Runnable() { @Override public void run() { try { while (Globals.msg.equals("")) { Thread.sleep(25); } ; myPd_ring.dismiss(); runOnUiThread(new Runnable() { public void run() { Toast t = Toast.makeText(staticThis, Globals.msg, Toast.LENGTH_SHORT); t.show(); Globals.msg = ""; } }); if (Globals.msg.equals(getResources().getString(R.string.success))) // Don't annoy people who did something wrong even further { final SharedPreferences prefs = PreferenceManager .getDefaultSharedPreferences(MainActivity.this); int x = prefs.getInt("purchaseNag", 5); if (x != -1) { if ((isPackageInstalled("com.xperia64.timidityae", MainActivity.this) || isPackageInstalled("com.xperia64.rompatcher.donation", MainActivity.this))) { prefs.edit().putInt("purchaseNag", -1); } else { if (x >= 5) { prefs.edit().putInt("purchaseNag", 0).commit(); /*runOnUiThread(new Runnable() { public void run() { AlertDialog.Builder b = new AlertDialog.Builder(MainActivity.this); b.setTitle("Like ROM Patcher?"); b.setIcon(getResources().getDrawable(R.drawable.icon_pro)); b.setMessage(getResources().getString(R.string.nagMsg)); b.setCancelable(false); b.setNegativeButton(getResources().getString(android.R.string.cancel), new OnClickListener(){@Override public void onClick(DialogInterface arg0, int arg1) {}}); b.setPositiveButton(getResources().getString(R.string.nagInfo), new OnClickListener(){ @Override public void onClick(DialogInterface arg0, int arg1) { try { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.xperia64.rompatcher.donation"))); } catch (android.content.ActivityNotFoundException anfe) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=com.xperia64.rompatcher.donation"))); } } }); b.create().show(); } }); // end of UIThread*/ } else { prefs.edit().putInt("purchaseNag", x + 1).commit(); } } } } } catch (Exception e) { } } }).start(); }