Java Code Examples for android.graphics.drawable.Drawable#createFromPath()
The following examples show how to use
android.graphics.drawable.Drawable#createFromPath() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AppsListFragment.java From J2ME-Loader with Apache License 2.0 | 6 votes |
private void showStartDialog(AppItem app) { AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity()); StringBuilder text = new StringBuilder() .append(getString(R.string.author)).append(' ') .append(app.getAuthor()).append('\n') .append(getString(R.string.version)).append(' ') .append(app.getVersion()).append('\n'); dialog.setMessage(text); dialog.setTitle(app.getTitle()); Drawable drawable = Drawable.createFromPath(app.getImagePathExt()); if (drawable != null) dialog.setIcon(drawable); dialog.setPositiveButton(R.string.START_CMD, (d, w) -> { Config.startApp(getActivity(), app.getPath(), false); }); dialog.setNegativeButton(R.string.close, null); dialog.show(); }
Example 2
Source File: AdapterUnifiedNativeAdMapper.java From googleads-mobile-android-mediation with Apache License 2.0 | 6 votes |
private AdapterNativeMappedImage parseImageComponent(final JSONObject jsonObject) { if (jsonObject != null) { try { JSONObject dataObject = jsonObject.getJSONObject("data"); Uri url = Uri.parse(dataObject.optString("url")); String assetPath = dataObject.optString("asset"); Drawable drawable; if (TextUtils.isEmpty(assetPath)) { drawable = drawableFromUrl(url.toString()); } else { drawable = Drawable.createFromPath(assetPath); } return new AdapterNativeMappedImage(drawable, url, VerizonMediationAdapter.VAS_IMAGE_SCALE); } catch (Exception e) { Log.e(TAG, "Unable to parse data object.", e); } } return null; }
Example 3
Source File: WaitPDPActivity.java From DroidForce with GNU Lesser General Public License v2.1 | 6 votes |
/** * Load background image from the assets directory. * @return Drawable object representing the background image. */ private Drawable loadBackground() { Resources r = getResources(); Log.d("DroidForce", "resources: "+ r); String[] files = null; try { files = r.getAssets().list(""); } catch (IOException e) { Log.e("DroidForce", "exception "+ e); e.printStackTrace(); } Log.d("DroidForce", "number of files in assets: "+ files.length); for (String s: files) { Log.d("DroidForce", "file in asset: "+ s); if (s.endsWith("protect.png")) { File file = copyFileFromAssetsToInternalStorage(s, true); String path = file.getAbsolutePath(); Log.d("DroidForce", "Path to file is '"+ path +"'"); return Drawable.createFromPath(path); } } throw new RuntimeException("error: drawable not found."); }
Example 4
Source File: DrawableUtil.java From VideoOS-Android-SDK with GNU General Public License v3.0 | 5 votes |
/** * get drawable by path * * @param filePath * @return */ public static Drawable getByPath(String filePath) { Drawable drawable = WeakCache.getCache(TAG).get(filePath); if (drawable == null) { try { drawable = Drawable.createFromPath(filePath); WeakCache.getCache(TAG).put(filePath, drawable); } catch (Throwable e) { } } return drawable; }
Example 5
Source File: CreateFromQMSLayerDialog.java From android_maplibui with GNU Lesser General Public License v3.0 | 5 votes |
private void setIcon(TextView view, String path) { Drawable icon = Drawable.createFromPath(path); Drawable checkbox = view.getCompoundDrawables()[2]; if (icon != null) icon.setBounds(0, 0, checkbox.getIntrinsicWidth(), checkbox.getIntrinsicHeight()); view.setCompoundDrawables(icon, null, checkbox, null); }
Example 6
Source File: DrawableCache.java From DistroHopper with GNU General Public License v3.0 | 5 votes |
@Override public synchronized Drawable get(Object key) { if (!this.containsKey(key)) { return null; } return Drawable.createFromPath(this.getPath(key.toString())); }
Example 7
Source File: ChatBackgroundView.java From actor-platform with GNU Affero General Public License v3.0 | 5 votes |
public void bind() { if (background == null) { shp = getContext().getSharedPreferences("wallpaper", Context.MODE_PRIVATE); if (shp.getInt("wallpaper", 0) == ActorSDK.sharedActor().style.getDefaultBackgrouds().length) { background = Drawable.createFromPath(BaseActorSettingsFragment.getWallpaperFile()); } else { background = getResources().getDrawable(BackgroundPreviewView.getBackground(BackgroundPreviewView.getBackgroundIdByUri(messenger().getSelectedWallpaper(), getContext(), shp.getInt("wallpaper", 0)))); } } }
Example 8
Source File: LabelManagerPackageActivity.java From talkback with Apache License 2.0 | 5 votes |
@Override protected Drawable doInBackground(Void... params) { final String screenshotPath = label.getScreenshotPath(); LogUtils.v(TAG, "Spawning new LoadScreenshotTask(%d) for %s.", hashCode(), screenshotPath); return Drawable.createFromPath(screenshotPath); }
Example 9
Source File: AppLovinNativeAdMapper.java From googleads-mobile-android-mediation with Apache License 2.0 | 5 votes |
AppLovinNativeAdMapper(AppLovinNativeAd nativeAd, Context context) { mNativeAd = nativeAd; setHeadline(nativeAd.getTitle()); setBody(nativeAd.getDescriptionText()); setCallToAction(nativeAd.getCtaText()); ImageView mediaView = new ImageView(context); ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); mediaView.setLayoutParams(layoutParams); ArrayList<NativeAd.Image> images = new ArrayList<>(1); Uri imageUri = Uri.parse(nativeAd.getImageUrl()); Drawable imageDrawable = Drawable.createFromPath(imageUri.getPath()); Uri iconUri = Uri.parse(nativeAd.getIconUrl()); Drawable iconDrawable = Drawable.createFromPath(iconUri.getPath()); AppLovinNativeAdImage image = new AppLovinNativeAdImage(imageUri, imageDrawable); AppLovinNativeAdImage icon = new AppLovinNativeAdImage(iconUri, iconDrawable); images.add(image); setImages(images); setIcon(icon); mediaView.setImageDrawable(imageDrawable); setMediaView(mediaView); setStarRating(nativeAd.getStarRating()); Bundle extraAssets = new Bundle(); extraAssets.putLong(AppLovinNativeAdapter.KEY_EXTRA_AD_ID, nativeAd.getAdId()); extraAssets.putString(AppLovinNativeAdapter.KEY_EXTRA_CAPTION_TEXT, nativeAd.getCaptionText()); setExtras(extraAssets); setOverrideClickHandling(false); setOverrideImpressionRecording(false); }
Example 10
Source File: IconStyleData.java From Status with Apache License 2.0 | 5 votes |
/** * Get a drawable of the style at a particular index. * * @param context The current application context. * @param value The index to obtain. * @return A created Drawable, or null if * something has gone horribly wrong. */ @Nullable public Drawable getDrawable(Context context, int value) { if (value < 0 || value >= getSize()) return null; switch (type) { case TYPE_VECTOR: return VectorDrawableCompat.create(context.getResources(), resource[value], context.getTheme()); case TYPE_IMAGE: return ContextCompat.getDrawable(context, resource[value]); case TYPE_FILE: String[] permissions = new String[]{Manifest.permission.READ_EXTERNAL_STORAGE, Manifest.permission.WRITE_EXTERNAL_STORAGE}; if (!StaticUtils.isPermissionsGranted(context, permissions)) { if (context instanceof Activity) StaticUtils.requestPermissions((Activity) context, permissions); return null; } else { try { return Drawable.createFromPath(path[value]); } catch (OutOfMemoryError e) { e.printStackTrace(); return null; } } default: return null; } }
Example 11
Source File: StoryArrayAdapter.java From scanvine-android with MIT License | 5 votes |
@Override public void handleMessage(Message msg) { ImageView imageView = wrImageView.get(); if (imageView != null) { Drawable d = Drawable.createFromPath(""+msg.obj); imageView.setImageDrawable(d); } }
Example 12
Source File: ZipSDCardLoader.java From Android-skin-support with MIT License | 5 votes |
@Override public Drawable getDrawable(Context context, String skinName, int resId) { String resName = context.getResources().getResourceEntryName(resId); String resType = context.getResources().getResourceTypeName(resId); if ("drawable".equalsIgnoreCase(resType) && "zip_background".equalsIgnoreCase(resName)) { String dir = SkinFileUtils.getSkinDir(context); File zipBackground = new File(dir, "zip_background.png"); if (zipBackground.exists()) { return Drawable.createFromPath(zipBackground.getAbsolutePath()); } return null; } return super.getDrawable(context, skinName, resId); }
Example 13
Source File: ZipSDCardLoader.java From Android-skin-support with MIT License | 5 votes |
@Override public Drawable getDrawable(Context context, String skinName, int resId) { String resName = context.getResources().getResourceEntryName(resId); String resType = context.getResources().getResourceTypeName(resId); if ("drawable".equalsIgnoreCase(resType) && "zip_background".equalsIgnoreCase(resName)) { String dir = SkinFileUtils.getSkinDir(context); File zipBackground = new File(dir, "zip_background.png"); if (zipBackground.exists()) { return Drawable.createFromPath(zipBackground.getAbsolutePath()); } return null; } return super.getDrawable(context, skinName, resId); }
Example 14
Source File: VMFile.java From VMLibrary with Apache License 2.0 | 5 votes |
/** * 读取文件到drawable * * @param filepath 文件路径 * @return 返回Drawable资源 */ public static Drawable fileToDrawable(String filepath) { if (VMStr.isEmpty(filepath)) { return null; } File file = new File(filepath); if (file.exists()) { Drawable drawable = Drawable.createFromPath(filepath); return drawable; } return null; }
Example 15
Source File: LegacyGlobalActions.java From android_9.0.0_r45 with Apache License 2.0 | 5 votes |
private void addUsersToMenu(ArrayList<Action> items) { UserManager um = (UserManager) mContext.getSystemService(Context.USER_SERVICE); if (um.isUserSwitcherEnabled()) { List<UserInfo> users = um.getUsers(); UserInfo currentUser = getCurrentUser(); for (final UserInfo user : users) { if (user.supportsSwitchToByUser()) { boolean isCurrentUser = currentUser == null ? user.id == 0 : (currentUser.id == user.id); Drawable icon = user.iconPath != null ? Drawable.createFromPath(user.iconPath) : null; SinglePressAction switchToUser = new SinglePressAction( com.android.internal.R.drawable.ic_menu_cc, icon, (user.name != null ? user.name : "Primary") + (isCurrentUser ? " \u2714" : "")) { @Override public void onPress() { try { ActivityManager.getService().switchUser(user.id); } catch (RemoteException re) { Log.e(TAG, "Couldn't switch user " + re); } } @Override public boolean showDuringKeyguard() { return true; } @Override public boolean showBeforeProvisioning() { return false; } }; items.add(switchToUser); } } } }
Example 16
Source File: ChatBackgroundActivity.java From deltachat-android with GNU General Public License v3.0 | 4 votes |
private void setLayoutBackgroundImage(String backgroundImagePath) { Drawable image = Drawable.createFromPath(backgroundImagePath); preview.setImageDrawable(image); }
Example 17
Source File: LollipopDrawablesCompat.java From RippleDrawable with MIT License | 4 votes |
/** * Create a drawable from file path name. */ public static Drawable createFromPath(String pathName) { return Drawable.createFromPath(pathName); }
Example 18
Source File: AppLovinUnifiedNativeAdMapper.java From googleads-mobile-android-mediation with Apache License 2.0 | 4 votes |
public AppLovinUnifiedNativeAdMapper(Context context, AppLovinNativeAd nativeAd) { mNativeAd = nativeAd; setHeadline(mNativeAd.getTitle()); setBody(mNativeAd.getDescriptionText()); setCallToAction(mNativeAd.getCtaText()); final ImageView mediaView = new ImageView(context); ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); mediaView.setLayoutParams(layoutParams); ArrayList<NativeAd.Image> images = new ArrayList<>(1); Uri imageUri = Uri.parse(mNativeAd.getImageUrl()); Drawable imageDrawable = Drawable.createFromPath(imageUri.getPath()); Uri iconUri = Uri.parse(mNativeAd.getIconUrl()); Drawable iconDrawable = Drawable.createFromPath(iconUri.getPath()); AppLovinNativeAdImage image = new AppLovinNativeAdImage(imageUri, imageDrawable); AppLovinNativeAdImage icon = new AppLovinNativeAdImage(iconUri, iconDrawable); images.add(image); setImages(images); setIcon(icon); mediaView.setImageDrawable(imageDrawable); setMediaView(mediaView); int imageHeight = imageDrawable.getIntrinsicHeight(); if (imageHeight > 0) { setMediaContentAspectRatio(imageDrawable.getIntrinsicWidth() / imageHeight); } setStarRating((double) mNativeAd.getStarRating()); Bundle extraAssets = new Bundle(); extraAssets.putLong(AppLovinNativeAdapter.KEY_EXTRA_AD_ID, mNativeAd.getAdId()); extraAssets.putString(AppLovinNativeAdapter.KEY_EXTRA_CAPTION_TEXT, mNativeAd.getCaptionText()); setExtras(extraAssets); setOverrideClickHandling(false); setOverrideImpressionRecording(false); }
Example 19
Source File: MessagesFragment.java From actor-platform with GNU Affero General Public License v3.0 | 4 votes |
@Override public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { // // Loading arguments // try { peer = Peer.fromBytes(getArguments().getByteArray("EXTRA_PEER")); conversationVM = messenger().getConversationVM(peer); } catch (IOException e) { throw new RuntimeException(e); } // // Display List // BindedDisplayList<Message> displayList = onCreateDisplayList(); if (isPrimaryMode) { displayList.setLinearLayoutCallback(b -> { if (layoutManager != null) { layoutManager.setStackFromEnd(b); } }); } // // Main View // View res = inflate(inflater, container, R.layout.fragment_messages, displayList); progressView = (CircularProgressBar) res.findViewById(R.id.loadingProgress); progressView.setIndeterminate(true); progressView.setVisibility(View.INVISIBLE); // // Loading background // Drawable background; int[] backgrounds = ActorSDK.sharedActor().style.getDefaultBackgrouds(); String selectedWallpaper = messenger().getSelectedWallpaper(); if (selectedWallpaper != null) { background = getResources().getDrawable(backgrounds[0]); if (selectedWallpaper.startsWith("local:")) { for (int i = 1; i < backgrounds.length; i++) { if (getResources().getResourceEntryName(backgrounds[i]).equals(selectedWallpaper.replaceAll("local:", ""))) { background = getResources().getDrawable(backgrounds[i]); } } } else { background = Drawable.createFromPath(BaseActorSettingsFragment.getWallpaperFile()); } } else { background = getResources().getDrawable(backgrounds[0]); } ((ImageView) res.findViewById(R.id.chatBackgroundView)).setImageDrawable(background); // // List Padding // View footer = new View(getActivity()); footer.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(8))); addHeaderView(footer); // Add Footer as Header because of reverse layout View header = new View(getActivity()); header.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, Screen.dp(64))); addFooterView(header); // Add Header as Footer because of reverse layout // // Init unread message index if available // recalculateUnreadMessageIfNeeded(); return res; }
Example 20
Source File: ImageUtils.java From TapUnlock with Apache License 2.0 | 4 votes |
public static Drawable retrieveWallpaperDrawable() { if (isExternalStorageReadable()) return Drawable.createFromPath(Environment.getExternalStorageDirectory() + "/TapUnlock/blurredWallpaper.png"); return null; }