List of usage examples for android.graphics.drawable BitmapDrawable BitmapDrawable
@Deprecated
public BitmapDrawable(java.io.InputStream is)
From source file:com.uzmap.pkg.uzmodules.UISearchBar.SearchBarActivity.java
@SuppressWarnings("deprecation") private void initData() { DisplayMetrics metric = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metric); mPref = getSharedPreferences("text", Context.MODE_PRIVATE); String text = mPref.getString("text", ""); if (!TextUtils.isEmpty(text)) { mEditText.setText(text);//from w ww . j a v a 2s . co m mEditText.setSelection(text.length()); } mNavigationLayout.setBackgroundColor(config.navBgColor); if (TextUtils.isEmpty(config.searchBoxBgImg)) { BitmapDrawable bitmapDrawable = new BitmapDrawable(BitmapFactory.decodeResource(getResources(), UZResourcesIDFinder.getResDrawableID("mo_searchbar_bg"))); mRelativeLayout.setBackgroundDrawable(bitmapDrawable); } else { BitmapDrawable bitmapDrawable = new BitmapDrawable(generateBitmap(config.searchBoxBgImg)); mRelativeLayout.setBackgroundDrawable(bitmapDrawable); } if (config.cancel_bg_bitmap != null) { mTextView.setBackgroundDrawable(new BitmapDrawable(config.cancel_bg_bitmap)); } else { mTextView.setBackgroundColor(config.cancel_bg_color); } mTextView.setTextSize(config.cancel_size); mTextView.setTextColor(config.cancal_color); LayoutParams params = new LayoutParams(UZUtility.dipToPix(config.searchBoxWidth), UZUtility.dipToPix(config.searchBoxHeight)); params.setMargins(UZUtility.dipToPix(10), 0, 0, 0); params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE); mEditText.setLayoutParams(params); WindowManager wm = this.getWindowManager(); int width = wm.getDefaultDisplay().getWidth(); double realWidth = width * 0.80; LayoutParams layoutParams = new LayoutParams((int) realWidth, UZUtility.dipToPix(config.searchBoxHeight)); layoutParams.setMargins(UZUtility.dipToPix(5), 0, 0, 0); layoutParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE); layoutParams.topMargin = UZUtility.dipToPix(8); layoutParams.bottomMargin = UZUtility.dipToPix(8); mRelativeLayout.setLayoutParams(layoutParams); double cancelRealWidth = width * 0.15; int space = (width - (int) realWidth - (int) cancelRealWidth - UZUtility.dipToPix(5)) / 2; LayoutParams cancalTxtParam = new LayoutParams((int) cancelRealWidth, UZUtility.dipToPix(config.searchBoxHeight)); cancalTxtParam.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); cancalTxtParam.addRule(RelativeLayout.CENTER_VERTICAL); cancalTxtParam.rightMargin = space; cancalTxtParam.leftMargin = space; mTextView.setLayoutParams(cancalTxtParam); mListView.setBackgroundColor(config.list_bg_color); listSize = config.list_size; mCleanTextColor = config.clear_font_color; mCleanTextSize = config.clear_font_size; recordCount = config.historyCount; /** * add clean list item */ int relativeLayoutCleanId = UZResourcesIDFinder.getResLayoutID("mo_searchbar_clean_item"); relativeLayoutClean = (LinearLayout) View.inflate(getApplicationContext(), relativeLayoutCleanId, null); int tv_cleanId = UZResourcesIDFinder.getResIdID("tv_clean"); mCleanTV = (TextView) relativeLayoutClean.findViewById(tv_cleanId); mCleanTV.setTextSize(mCleanTextSize); mCleanTV.setTextColor(mCleanTextColor); mCleanTV.setText(config.clearText); relativeLayoutClean .setBackgroundDrawable(addStateDrawable(config.clear_bg_color, config.clear_active_bg_color)); list.clear(); list.add(relativeLayoutClean); mPref = getSharedPreferences("history" + config.database, Context.MODE_PRIVATE); editor = mPref.edit(); trimHistroyList(config.historyCount); @SuppressWarnings("unchecked") Map<String, String> map = (Map<String, String>) mPref.getAll(); if (map != null) { if (map.size() != 0) { for (int i = 1; i <= map.size(); i++) { int listview_item = UZResourcesIDFinder.getResLayoutID("mo_searchbar_listview_item"); LinearLayout linearLayout = (LinearLayout) View.inflate(SearchBarActivity.this, listview_item, null); int tv_listId = UZResourcesIDFinder.getResIdID("tv_listview"); TextView tv = (TextView) linearLayout.findViewById(tv_listId); tv.setTextSize(listSize); tv.setTextColor(config.list_color); linearLayout.setBackgroundDrawable( addStateDrawable(config.list_bg_color, config.list_item_active_bg_color)); int itemBorderLineId = UZResourcesIDFinder.getResIdID("item_border_line"); linearLayout.findViewById(itemBorderLineId).setBackgroundColor(config.list_border_color); for (Entry<String, String> iterable_element : map.entrySet()) { String key = iterable_element.getKey(); if ((i + "").equals(key)) { tv.setText(iterable_element.getValue()); } } list.addFirst(linearLayout); } id = map.size(); } } adapter = new MyAdapter(); mListView.setAdapter(adapter); }
From source file:android.support.transition.ChangeBounds.java
@Override @Nullable//from ww w.jav a 2 s . c om public Animator createAnimator(@NonNull final ViewGroup sceneRoot, @Nullable TransitionValues startValues, @Nullable TransitionValues endValues) { if (startValues == null || endValues == null) { return null; } Map<String, Object> startParentVals = startValues.values; Map<String, Object> endParentVals = endValues.values; ViewGroup startParent = (ViewGroup) startParentVals.get(PROPNAME_PARENT); ViewGroup endParent = (ViewGroup) endParentVals.get(PROPNAME_PARENT); if (startParent == null || endParent == null) { return null; } final View view = endValues.view; if (parentMatches(startParent, endParent)) { Rect startBounds = (Rect) startValues.values.get(PROPNAME_BOUNDS); Rect endBounds = (Rect) endValues.values.get(PROPNAME_BOUNDS); final int startLeft = startBounds.left; final int endLeft = endBounds.left; final int startTop = startBounds.top; final int endTop = endBounds.top; final int startRight = startBounds.right; final int endRight = endBounds.right; final int startBottom = startBounds.bottom; final int endBottom = endBounds.bottom; final int startWidth = startRight - startLeft; final int startHeight = startBottom - startTop; final int endWidth = endRight - endLeft; final int endHeight = endBottom - endTop; Rect startClip = (Rect) startValues.values.get(PROPNAME_CLIP); Rect endClip = (Rect) endValues.values.get(PROPNAME_CLIP); int numChanges = 0; if ((startWidth != 0 && startHeight != 0) || (endWidth != 0 && endHeight != 0)) { if (startLeft != endLeft || startTop != endTop) ++numChanges; if (startRight != endRight || startBottom != endBottom) ++numChanges; } if ((startClip != null && !startClip.equals(endClip)) || (startClip == null && endClip != null)) { ++numChanges; } if (numChanges > 0) { Animator anim; if (!mResizeClip) { ViewUtils.setLeftTopRightBottom(view, startLeft, startTop, startRight, startBottom); if (numChanges == 2) { if (startWidth == endWidth && startHeight == endHeight) { Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft, endTop); anim = ObjectAnimatorUtils.ofPointF(view, POSITION_PROPERTY, topLeftPath); } else { final ViewBounds viewBounds = new ViewBounds(view); Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft, endTop); ObjectAnimator topLeftAnimator = ObjectAnimatorUtils.ofPointF(viewBounds, TOP_LEFT_PROPERTY, topLeftPath); Path bottomRightPath = getPathMotion().getPath(startRight, startBottom, endRight, endBottom); ObjectAnimator bottomRightAnimator = ObjectAnimatorUtils.ofPointF(viewBounds, BOTTOM_RIGHT_PROPERTY, bottomRightPath); AnimatorSet set = new AnimatorSet(); set.playTogether(topLeftAnimator, bottomRightAnimator); anim = set; set.addListener(new AnimatorListenerAdapter() { // We need a strong reference to viewBounds until the // animator ends (The ObjectAnimator holds only a weak reference). @SuppressWarnings("unused") private ViewBounds mViewBounds = viewBounds; }); } } else if (startLeft != endLeft || startTop != endTop) { Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft, endTop); anim = ObjectAnimatorUtils.ofPointF(view, TOP_LEFT_ONLY_PROPERTY, topLeftPath); } else { Path bottomRight = getPathMotion().getPath(startRight, startBottom, endRight, endBottom); anim = ObjectAnimatorUtils.ofPointF(view, BOTTOM_RIGHT_ONLY_PROPERTY, bottomRight); } } else { int maxWidth = Math.max(startWidth, endWidth); int maxHeight = Math.max(startHeight, endHeight); ViewUtils.setLeftTopRightBottom(view, startLeft, startTop, startLeft + maxWidth, startTop + maxHeight); ObjectAnimator positionAnimator = null; if (startLeft != endLeft || startTop != endTop) { Path topLeftPath = getPathMotion().getPath(startLeft, startTop, endLeft, endTop); positionAnimator = ObjectAnimatorUtils.ofPointF(view, POSITION_PROPERTY, topLeftPath); } final Rect finalClip = endClip; if (startClip == null) { startClip = new Rect(0, 0, startWidth, startHeight); } if (endClip == null) { endClip = new Rect(0, 0, endWidth, endHeight); } ObjectAnimator clipAnimator = null; if (!startClip.equals(endClip)) { ViewCompat.setClipBounds(view, startClip); clipAnimator = ObjectAnimator.ofObject(view, "clipBounds", sRectEvaluator, startClip, endClip); clipAnimator.addListener(new AnimatorListenerAdapter() { private boolean mIsCanceled; @Override public void onAnimationCancel(Animator animation) { mIsCanceled = true; } @Override public void onAnimationEnd(Animator animation) { if (!mIsCanceled) { ViewCompat.setClipBounds(view, finalClip); ViewUtils.setLeftTopRightBottom(view, endLeft, endTop, endRight, endBottom); } } }); } anim = TransitionUtils.mergeAnimators(positionAnimator, clipAnimator); } if (view.getParent() instanceof ViewGroup) { final ViewGroup parent = (ViewGroup) view.getParent(); ViewGroupUtils.suppressLayout(parent, true); TransitionListener transitionListener = new TransitionListenerAdapter() { boolean mCanceled = false; @Override public void onTransitionCancel(@NonNull Transition transition) { ViewGroupUtils.suppressLayout(parent, false); mCanceled = true; } @Override public void onTransitionEnd(@NonNull Transition transition) { if (!mCanceled) { ViewGroupUtils.suppressLayout(parent, false); } transition.removeListener(this); } @Override public void onTransitionPause(@NonNull Transition transition) { ViewGroupUtils.suppressLayout(parent, false); } @Override public void onTransitionResume(@NonNull Transition transition) { ViewGroupUtils.suppressLayout(parent, true); } }; addListener(transitionListener); } return anim; } } else { int startX = (Integer) startValues.values.get(PROPNAME_WINDOW_X); int startY = (Integer) startValues.values.get(PROPNAME_WINDOW_Y); int endX = (Integer) endValues.values.get(PROPNAME_WINDOW_X); int endY = (Integer) endValues.values.get(PROPNAME_WINDOW_Y); // TODO: also handle size changes: check bounds and animate size changes if (startX != endX || startY != endY) { sceneRoot.getLocationInWindow(mTempLocation); Bitmap bitmap = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); view.draw(canvas); @SuppressWarnings("deprecation") final BitmapDrawable drawable = new BitmapDrawable(bitmap); final float transitionAlpha = ViewUtils.getTransitionAlpha(view); ViewUtils.setTransitionAlpha(view, 0); ViewUtils.getOverlay(sceneRoot).add(drawable); Path topLeftPath = getPathMotion().getPath(startX - mTempLocation[0], startY - mTempLocation[1], endX - mTempLocation[0], endY - mTempLocation[1]); PropertyValuesHolder origin = PropertyValuesHolderUtils.ofPointF(DRAWABLE_ORIGIN_PROPERTY, topLeftPath); ObjectAnimator anim = ObjectAnimator.ofPropertyValuesHolder(drawable, origin); anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { ViewUtils.getOverlay(sceneRoot).remove(drawable); ViewUtils.setTransitionAlpha(view, transitionAlpha); } }); return anim; } } return null; }
From source file:de.madvertise.android.sdk.MadView.java
/** * Convenicence method for a shiny background for text ads * /* w w w. j ava 2 s. c om*/ * @param rect * @param backgroundColor * @param textColor * @return */ private BitmapDrawable generateBackgroundDrawable(Rect rect, int backgroundColor, int shineColor) { try { Bitmap bitmap = Bitmap.createBitmap(rect.width(), rect.height(), Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); drawTextBannerBackground(canvas, rect, backgroundColor, shineColor); return new BitmapDrawable(bitmap); } catch (Throwable t) { return null; } }
From source file:com.uzmap.pkg.uzmodules.UIListView.UIListView.java
@SuppressWarnings("deprecation") public void jsmethod_setRefreshFooter(UZModuleContext uzContext) { pullUpContext = uzContext;/*from w ww . j a v a2 s .c om*/ if (mRefreshableList != null) { mRefreshableList.setMode(mRefreshableList.getMode() != Mode.DISABLED ? mRefreshableList.getMode() == Mode.PULL_FROM_END ? Mode.PULL_FROM_END : Mode.BOTH : Mode.PULL_FROM_END); String textDown = uzContext.optString("textDown"); if (TextUtils.isEmpty(textDown)) { textDown = TEXT_DOWN; } String textUp = uzContext.optString("textUp"); if (TextUtils.isEmpty(textUp)) { textUp = TEXT_UP; } String loadingImg = uzContext.optString("loadingImg"); if (!uzContext.isNull("showTime")) { showFooterTime = uzContext.optBoolean("showTime"); } String bgColor = "#f5f5f5"; if (!uzContext.isNull("bgColor")) { bgColor = uzContext.optString("bgColor"); } String textColor = "#8e8e8e"; if (!uzContext.isNull("textColor")) { textColor = uzContext.optString("textColor"); } LoadingLayout loadingLayout = mRefreshableList.getFooterLayout(); loadingLayout.setPullLabel(textUp); loadingLayout.setReleaseLabel(textDown); loadingLayout.setRefreshingLabel(REFRESH_LABEL); BitmapDrawable bitmapDrawable = new BitmapDrawable(getBitmap(loadingImg)); bitmapDrawable.setTargetDensity(mContext.getResources().getDisplayMetrics().densityDpi); loadingLayout.setLoadingDrawable(bitmapDrawable); loadingLayout.setBackgroundColor(UZUtility.parseCssColor(bgColor)); loadingLayout.getHeaderText().setTextColor(UZUtility.parseCssColor(textColor)); loadingLayout.getSubHeaderText().setTextColor(UZUtility.parseCssColor(textColor)); if (refreshListener == null) { refreshListener = new OnRefreshListener(); mRefreshableList.setOnRefreshListener(refreshListener); } // callback(uzContext ,true); } }
From source file:com.lemon.lime.MainActivity.java
private void lilimode() { BitmapDrawable bg = new BitmapDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.tiger)); getSupportActionBar().setBackgroundDrawable(bg); mWebView.setBackgroundColor(Color.CYAN); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { window.setNavigationBarColor(Color.CYAN); window.setStatusBarColor(Color.parseColor("#C3721A")); }//from w w w . j ava 2s .com final View coordinatorLayoutView = findViewById(R.id.snackbarPosition); Snackbar snackbar = Snackbar.make(coordinatorLayoutView, R.string.lilimode, Snackbar.LENGTH_LONG) .setAction("?", new View.OnClickListener() { @Override public void onClick(View view) { AlertDialog.Builder alertadd = new AlertDialog.Builder(MainActivity.this); LayoutInflater factory = LayoutInflater.from(MainActivity.this); final View liliview = factory.inflate(R.layout.lili, null); alertadd.setView(liliview); alertadd.show(); } }); snackbar.getView().setBackgroundColor(Color.parseColor("#03c1c1")); snackbar.show(); }
From source file:com.flipzu.flipzu.Player.java
private Drawable scaleBitmap(Bitmap x, int width, int height) { Drawable d = null;//from ww w . j av a 2s . c o m debug.logV(TAG, "drawable_from_url layout" + width + "*" + height); if (x == null) debug.logV(TAG, "X IS NULL"); if (x == null) return null; d = new BitmapDrawable(x); if (width > 0 && height > 0 && x != null) { if (width > x.getWidth()) width = x.getWidth(); if (height > x.getHeight()) height = x.getHeight(); Bitmap cropped = Bitmap.createBitmap(x, 0, 0, width, height); d = new BitmapDrawable(cropped); } else { d = new BitmapDrawable(x); } // opacity d.setAlpha(122); return d; }
From source file:org.cryptsecure.Utility.java
/** * Sets the background tiled for a view element according to a given * resourceID./* w w w . j av a2 s. c o m*/ * * @param activity * the activity * @param view * the view * @param resourceID * the resource id */ @SuppressWarnings("deprecation") public static void setBackground(Context activity, View view, int resourceID) { // set dolphin background Bitmap bm2 = BitmapFactory.decodeResource(activity.getResources(), resourceID); BitmapDrawable background2 = new BitmapDrawable(bm2); background2.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT); view.setBackgroundDrawable(background2); }
From source file:com.example.alyshia.customsimplelauncher.MainActivity.java
protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) { super.onActivityResult(requestCode, resultCode, imageReturnedIntent); switch (requestCode) { case REQ_CODE_PICK_IMAGE: if (resultCode == RESULT_OK) { if (imageReturnedIntent != null) { System.out.println("path " + Uri.parse(filePath)); Bitmap selectedImage = BitmapFactory.decodeFile(filePath); screen.setBackground(new BitmapDrawable(selectedImage)); //if (tempFile.exists()) tempFile.delete(); }//from www . j a v a 2s . com } else { if (f.exists()) f.delete(); } } //enable back gallery if needed SharedPreferences knoxPref = getSharedPreferences(KnoxConstants.PREFS_KNOX, MODE_PRIVATE); Set<String> blacklist = knoxPref.getStringSet(KnoxConstants.BList, null); if (blacklist != null) { if (blacklist.contains(gallery)) { if (edm == null) { edm = (EnterpriseDeviceManager) getSystemService( EnterpriseDeviceManager.ENTERPRISE_POLICY_SERVICE); } ApplicationPolicy appPolicy = edm.getApplicationPolicy(); appPolicy.addPackagesToPreventStartBlackList(gallery); } } }
From source file:com.ibuildapp.romanblack.MultiContactsPlugin.MultiContactsPlugin.java
/** * Updates the page background after background image was downloaded and * decoded./*from ww w .j av a2 s . c om*/ */ private void updateBackground() { try { root.setBackgroundDrawable( new BitmapDrawable(BitmapFactory.decodeStream(new FileInputStream(cacheBackgroundFile)))); backgroundLoaded = true; handler.sendEmptyMessage(SHOW_DATA); } catch (FileNotFoundException fNFEx) { Log.e(TAG, fNFEx.getMessage()); fNFEx.printStackTrace(); } }
From source file:com.radicaldynamic.groupinform.activities.LauncherActivity.java
private void displaySplash() { // Don't show the splash screen if this app appears to be registered if (PreferenceManager.getDefaultSharedPreferences(getApplicationContext()) .getString(InformOnlineState.DEVICE_ID, null) instanceof String) { return;//from w w w.j av a2 s. co m } // Fetch the splash screen Drawable Drawable image = null; try { // Attempt to load the configured default splash screen // The following code only works in 1.6+ // BitmapDrawable bitImage = new BitmapDrawable(getResources(), FileUtils.SPLASH_SCREEN_FILE_PATH); BitmapDrawable bitImage = new BitmapDrawable( FileUtilsExtended.EXTERNAL_FILES + File.separator + FileUtilsExtended.SPLASH_SCREEN_FILE); if (bitImage.getBitmap() != null && bitImage.getIntrinsicHeight() > 0 && bitImage.getIntrinsicWidth() > 0) { image = bitImage; } } catch (Exception e) { // TODO: log exception for debugging? } // TODO: rework if (image == null) { // no splash provided... // if (FileUtils.storageReady() && !((new File(FileUtils.DEFAULT_CONFIG_PATH)).exists())) { // Show the built-in splash image if the config directory // does not exist. Otherwise, suppress the icon. image = getResources().getDrawable(R.drawable.gc_color); // } if (image == null) return; } // Create ImageView to hold the Drawable... ImageView view = new ImageView(getApplicationContext()); // Initialise it with Drawable and full-screen layout parameters view.setImageDrawable(image); int width = getWindowManager().getDefaultDisplay().getWidth(); int height = getWindowManager().getDefaultDisplay().getHeight(); FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(width, height, 0); view.setLayoutParams(lp); view.setScaleType(ScaleType.CENTER); view.setBackgroundColor(Color.WHITE); // And wrap the image view in a frame layout so that the full-screen layout parameters are honoured FrameLayout layout = new FrameLayout(getApplicationContext()); layout.addView(view); // Create the toast and set the view to be that of the FrameLayout mSplashToast = Toast.makeText(getApplicationContext(), "splash screen", Toast.LENGTH_LONG); mSplashToast.setView(layout); mSplashToast.setGravity(Gravity.CENTER, 0, 0); mSplashToast.show(); }