List of usage examples for android.support.v4.content.res ResourcesCompat getDrawable
public static Drawable getDrawable(Resources resources, int i, Theme theme) throws NotFoundException
From source file:com.nttec.everychan.ui.presentation.HtmlParser.java
private static void startImg(SpannableStringBuilder text, Attributes attributes, HtmlParser.ImageGetter img) { String src = attributes.getValue("", "src"); Drawable d = null;/* w ww .j a v a 2s.c o m*/ if (img != null) { d = img.getDrawable(src); } if (d == null) { d = ResourcesCompat.getDrawable(Resources.getSystem(), android.R.drawable.ic_menu_report_image, null); d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); } int len = text.length(); text.append("\uFFFC"); text.setSpan(new ImageSpan(d, src), len, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); }
From source file:supertoast.utils.SuperActivityToast.java
/** * Modify various attributes of the SuperActivityToast before being shown. */// www.ja va 2 s. c o m @Override protected void onPrepareShow() { super.onPrepareShow(); // This will take care of many modifications final FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(this.mStyle.width, this.mStyle.height); // Make some type specific tweaks switch (this.mStyle.type) { case Style.TYPE_STANDARD: break; case Style.TYPE_BUTTON: // If NOT Lollipop frame, give padding on each side if (this.mStyle.frame != Style.FRAME_LOLLIPOP) { this.mStyle.width = FrameLayout.LayoutParams.MATCH_PARENT; this.mStyle.xOffset = BackgroundUtils.convertToDIP(24); this.mStyle.yOffset = BackgroundUtils.convertToDIP(24); } // On a big screen device, show the SuperActivityToast on the bottom left if ((this.mContext.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE) { this.mStyle.width = BackgroundUtils.convertToDIP(568); this.mStyle.gravity = Gravity.BOTTOM | Gravity.START; } // Set up the Button attributes final Button button = (Button) this.mView.findViewById(R.id.button); button.setBackgroundResource(BackgroundUtils.getButtonBackgroundResource(this.mStyle.frame)); button.setText(this.mStyle.buttonText != null ? this.mStyle.buttonText.toUpperCase() : ""); button.setTypeface(button.getTypeface(), this.mStyle.buttonTypefaceStyle); button.setTextColor(this.mStyle.buttonTextColor); button.setTextSize(this.mStyle.buttonTextSize); if (this.mStyle.frame != Style.FRAME_LOLLIPOP) { this.mView.findViewById(R.id.divider).setBackgroundColor(this.mStyle.buttonDividerColor); // Set an icon resource if desired if (this.mStyle.buttonIconResource > 0) { button.setCompoundDrawablesWithIntrinsicBounds( ResourcesCompat.getDrawable(mContext.getResources(), this.mStyle.buttonIconResource, mContext.getTheme()), null, null, null); } } if (this.mOnButtonClickListener != null) { button.setOnClickListener(new View.OnClickListener() { short clicked = 0; @Override public void onClick(View view) { // Prevent button spamming if (clicked > 0) return; clicked++; mOnButtonClickListener.onClick(view, getButtonToken()); SuperActivityToast.this.dismiss(); } }); } break; case Style.TYPE_PROGRESS_CIRCLE: if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { this.mProgressBar.setIndeterminateTintMode(PorterDuff.Mode.SRC_IN); this.mProgressBar.setIndeterminateTintList(ColorStateList.valueOf(this.mStyle.progressBarColor)); } break; case Style.TYPE_PROGRESS_BAR: if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { this.mProgressBar.setIndeterminateTintMode(PorterDuff.Mode.SRC_IN); this.mProgressBar.setIndeterminateTintList(ColorStateList.valueOf(this.mStyle.progressBarColor)); this.mProgressBar.setProgressTintMode(PorterDuff.Mode.SRC_IN); this.mProgressBar.setProgressTintList(ColorStateList.valueOf(this.mStyle.progressBarColor)); } this.mProgressBar.setProgress(this.mStyle.progress); this.mProgressBar.setMax(this.mStyle.progressMax); this.mProgressBar.setIndeterminate(this.mStyle.progressIndeterminate); break; } layoutParams.width = this.mStyle.width; layoutParams.height = this.mStyle.height; layoutParams.gravity = this.mStyle.gravity; layoutParams.bottomMargin = this.mStyle.yOffset; layoutParams.topMargin = this.mStyle.yOffset; layoutParams.leftMargin = this.mStyle.xOffset; layoutParams.rightMargin = this.mStyle.xOffset; this.mView.setLayoutParams(layoutParams); // Set up touch to dismiss if (this.mStyle.touchToDismiss) { mView.setOnTouchListener(new View.OnTouchListener() { int timesTouched; @Override public boolean onTouch(View v, MotionEvent motionEvent) { // Prevent repetitive touch events if (timesTouched == 0 && motionEvent.getAction() == MotionEvent.ACTION_DOWN) dismiss(); timesTouched++; return false; // Do not consume the event in case a Button listener is set } }); } else { // Make sure no listener is set mView.setOnTouchListener(null); } }
From source file:com.github.johnpersano.supertoasts.library.SuperActivityToast.java
/** * Modify various attributes of the SuperActivityToast before being shown. *//* w w w. j a va 2 s . c o m*/ @Override protected void onPrepareShow() { super.onPrepareShow(); // This will take care of many modifications final FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(this.mStyle.width, this.mStyle.height); // Make some type specific tweaks switch (this.mStyle.type) { case Style.TYPE_STANDARD: break; case Style.TYPE_BUTTON: // If NOT Lollipop frame, give padding on each side if (this.mStyle.frame != Style.FRAME_LOLLIPOP) { this.mStyle.width = FrameLayout.LayoutParams.MATCH_PARENT; this.mStyle.xOffset = BackgroundUtils.convertToDIP(24); this.mStyle.yOffset = BackgroundUtils.convertToDIP(24); } // On a big screen device, show the SuperActivityToast on the bottom left if ((this.mContext.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE) { this.mStyle.width = BackgroundUtils.convertToDIP(568); this.mStyle.gravity = Gravity.BOTTOM | Gravity.START; } // Set up the Button attributes final Button button = (Button) this.mView.findViewById(R.id.button); button.setBackgroundResource(BackgroundUtils.getButtonBackgroundResource(this.mStyle.frame)); button.setText(this.mStyle.buttonText != null ? this.mStyle.buttonText.toUpperCase() : ""); button.setTypeface(button.getTypeface(), this.mStyle.buttonTypefaceStyle); button.setTextColor(this.mStyle.buttonTextColor); button.setTextSize(this.mStyle.buttonTextSize); if (this.mStyle.frame != Style.FRAME_LOLLIPOP) { this.mView.findViewById(R.id.divider).setBackgroundColor(this.mStyle.buttonDividerColor); // Set an icon resource if desired if (this.mStyle.buttonIconResource > 0) { button.setCompoundDrawablesWithIntrinsicBounds( ResourcesCompat.getDrawable(mContext.getResources(), this.mStyle.buttonIconResource, mContext.getTheme()), null, null, null); } } if (this.mOnButtonClickListener != null) { button.setOnClickListener(new View.OnClickListener() { short clicked = 0; @Override public void onClick(View view) { // Prevent button spamming if (clicked > 0) return; clicked++; mOnButtonClickListener.onClick(view, getButtonToken()); SuperActivityToast.this.dismiss(); } }); } break; case Style.TYPE_PROGRESS_CIRCLE: if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { this.mProgressBar.setIndeterminateTintMode(PorterDuff.Mode.SRC_IN); this.mProgressBar.setIndeterminateTintList(ColorStateList.valueOf(this.mStyle.progressBarColor)); } break; case Style.TYPE_PROGRESS_BAR: if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { this.mProgressBar.setIndeterminateTintMode(PorterDuff.Mode.SRC_IN); this.mProgressBar.setIndeterminateTintList(ColorStateList.valueOf(this.mStyle.progressBarColor)); this.mProgressBar.setProgressTintMode(PorterDuff.Mode.SRC_IN); this.mProgressBar.setProgressTintList(ColorStateList.valueOf(this.mStyle.progressBarColor)); } this.mProgressBar.setProgress(this.mStyle.progress); this.mProgressBar.setMax(this.mStyle.progressMax); this.mProgressBar.setIndeterminate(this.mStyle.progressIndeterminate); break; } layoutParams.width = this.mStyle.width; layoutParams.height = this.mStyle.height; layoutParams.gravity = this.mStyle.gravity; layoutParams.bottomMargin = this.mStyle.yOffset; layoutParams.topMargin = this.mStyle.yOffset; layoutParams.leftMargin = this.mStyle.xOffset; layoutParams.rightMargin = this.mStyle.xOffset; this.mView.setLayoutParams(layoutParams); // Set up touch to dismiss if (this.mStyle.touchToDismiss) { mView.setOnTouchListener(new View.OnTouchListener() { int timesTouched; @Override public boolean onTouch(View v, MotionEvent motionEvent) { // Prevent repetitive touch events if (timesTouched == 0 && motionEvent.getAction() == MotionEvent.ACTION_DOWN) dismiss(); timesTouched++; return false; // Do not consume the event in case a Button listener is set } }); } else { // Make sure no listener is set mView.setOnTouchListener(null); } }
From source file:com.mukesh.OtpView.java
/** * Set the item background to a given resource. The resource should refer to * a Drawable object or 0 to remove the item background. * * @param resId The identifier of the resource. * @attr ref R.styleable#OtpView_android_itemBackground *///from ww w .j ava2s .c o m public void setItemBackgroundResources(@DrawableRes int resId) { if (resId != 0 && itemBackgroundResource != resId) { return; } itemBackground = ResourcesCompat.getDrawable(getResources(), resId, getContext().getTheme()); setItemBackground(itemBackground); itemBackgroundResource = resId; }
From source file:com.google.android.apps.muzei.settings.ChooseSourceFragment.java
private void prepareGenerateSourceImages() { mImageFillPaint.setColor(Color.WHITE); mImageFillPaint.setAntiAlias(true);/*ww w .j a v a 2s .c o m*/ mAlphaPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.DST_OUT)); mSelectedSourceImage = new BitmapDrawable(getResources(), generateSourceImage( ResourcesCompat.getDrawable(getResources(), R.drawable.ic_source_selected, null))); }
From source file:com.luke.lukef.lukeapp.tools.LukeNetUtils.java
/** * Method for asynchronously fetching an image from the internet and setting it into an imageView. * Allows bigger image download to not pause the app. * @param imageViewToSet ImageView where the image will be set * @param url Url of the image as a String * @param defaultImageId Default image id, in case the online image is unavailable * @param activity Activity that can run setting the imageView on a UiThread *///from w w w .jav a2 s .c om public static void imageSetupTask(ImageView imageViewToSet, String url, final int defaultImageId, Activity activity) { class LoadImageTask extends AsyncTask<Void, Void, Void> { private ImageView imageView; private String urlString; private Activity activity; private Bitmap bitmap = null; int defaultId; LoadImageTask(ImageView imageView, String urlString, Activity activity, int defaultId) { this.activity = activity; this.urlString = urlString; this.imageView = imageView; this.defaultId = defaultId; } @Override protected Void doInBackground(Void... params) { if (this.urlString != null) { LukeNetUtils lukeNetUtils = new LukeNetUtils(this.activity); try { this.bitmap = lukeNetUtils.getBitmapFromURL(urlString); } catch (ExecutionException | InterruptedException e) { Log.e("ImageAsyncTask", "doInBackground: ", e); } } else { this.bitmap = null; } return null; } @Override protected void onPostExecute(Void aVoid) { this.activity.runOnUiThread(new Runnable() { @Override public void run() { if (LoadImageTask.this.bitmap == null) { LoadImageTask.this.imageView.setImageDrawable( ResourcesCompat.getDrawable(activity.getResources(), defaultImageId, null)); } else { LoadImageTask.this.imageView.setImageBitmap(LoadImageTask.this.bitmap); } } }); super.onPostExecute(aVoid); } } LoadImageTask bitmapTask = new LoadImageTask(imageViewToSet, url, activity, defaultImageId); bitmapTask.execute(); }
From source file:com.forrestguice.suntimeswidget.SuntimesUtils.java
/** * @param context context used to get resources * @param resourceID drawable resource ID to a GradientDrawable * @param fillColor fill color to apply to drawable * @param strokeColor stroke color to apply to drawable * @param strokePx width of stroke/* w w w . j a va 2s . c o m*/ * @return a Bitmap of the drawable */ public static Bitmap gradientDrawableToBitmap(Context context, int resourceID, int fillColor, int strokeColor, int strokePx) { Drawable drawable = ResourcesCompat.getDrawable(context.getResources(), resourceID, null); GradientDrawable gradient = (GradientDrawable) drawable; int w = 1, h = 1; if (gradient != null) { w = gradient.getIntrinsicWidth(); h = gradient.getIntrinsicHeight(); } Drawable tinted = tintDrawable(gradient, fillColor, strokeColor, strokePx); return drawableToBitmap(context, tinted, w, h, true); }
From source file:com.forrestguice.suntimeswidget.SuntimesUtils.java
/** * @param context context used to get resources * @param resourceID drawable resource ID to an InsetDrawable * @param fillColor fill color to apply to drawable * @param strokeColor stroke color to apply to drawable * @param strokePx width of stroke/* w w w . ja v a 2s .c o m*/ * @return a Bitmap of the drawable */ public static Bitmap insetDrawableToBitmap(Context context, int resourceID, int fillColor, int strokeColor, int strokePx) { Drawable drawable = ResourcesCompat.getDrawable(context.getResources(), resourceID, null); InsetDrawable inset = (InsetDrawable) drawable; int w = 1, h = 1; if (inset != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { Drawable wrapped = inset.getDrawable(); if (wrapped != null) { w = wrapped.getIntrinsicWidth(); h = wrapped.getIntrinsicHeight(); } } else { w = inset.getIntrinsicWidth(); h = inset.getIntrinsicHeight(); } } Drawable tinted = tintDrawable(inset, fillColor, strokeColor, strokePx); return drawableToBitmap(context, tinted, w, h, true); }
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 w w w .j a v a 2s . co 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(); }
From source file:org.miaowo.miaowo.util.Html.java
private static void startImg(Editable text, Attributes attributes, Html.ImageGetter img, Context context) { String src = attributes.getValue("", "src"); Drawable d = null;/*from w w w . ja v a 2 s . c o m*/ if (img != null) { d = img.getDrawable(src); } if (d == null) { d = ResourcesCompat.getDrawable(context.getResources(), R.drawable.unknown_image, null); d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight()); } int len = text.length(); text.append("\uFFFC"); text.setSpan(new ImageSpan(d, src), len, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); }