android.graphics.drawable.Drawable.createFromPath()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(471)

本文整理了Java中android.graphics.drawable.Drawable.createFromPath()方法的一些代码示例,展示了Drawable.createFromPath()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Drawable.createFromPath()方法的具体详情如下:
包路径:android.graphics.drawable.Drawable
类名称:Drawable
方法名:createFromPath

Drawable.createFromPath介绍

暂无

代码示例

代码示例来源:origin: ZieIony/Carbon

/**
 * Create a drawable from file path name.
 */
public static Drawable createFromPath(String pathName) {
  return Drawable.createFromPath(pathName);
}

代码示例来源:origin: ZieIony/Carbon

/**
 * Create a drawable from file path name.
 */
public Drawable createFromPath(String pathName) {
  return Drawable.createFromPath(pathName);
}

代码示例来源:origin: jaydenxiao2016/AndroidFire

@Nullable
private Drawable getDrawableFromDisk(File file) {
  Drawable drawable = Drawable.createFromPath(file.getAbsolutePath());
  if (drawable != null) {
    int picHeight = calculatePicHeight(drawable);
    drawable.setBounds(0, 0, mPicWidth, picHeight);
  }
  return drawable;
}

代码示例来源:origin: kaku2015/ColorfulNews

@Nullable
private Drawable getDrawableFromDisk(File file) {
  Drawable drawable = Drawable.createFromPath(file.getAbsolutePath());
  if (drawable != null) {
    int picHeight = calculatePicHeight(drawable);
    drawable.setBounds(0, 0, mPicWidth, picHeight);
  }
  return drawable;
}

代码示例来源:origin: DaxiaK/MyDiary

public Drawable getMemoBgDrawable(Context context, long topicId) {
  Drawable bgDrawable;
  FileManager memoFM = new FileManager(context, FileManager.MEMO_ROOT_DIR);
  File memoBg = new File(
      memoFM.getDirAbsolutePath()
          + "/" + topicId
          + "/" + CUSTOM_TOPIC_BG_FILENAME);
  if (memoBg.exists()) {
    bgDrawable = Drawable.createFromPath(memoBg.getAbsolutePath());
  } else {
    switch (currentTheme) {
      case TAKI:
        bgDrawable = new ColorDrawable(Color.WHITE);
        break;
      case MITSUHA:
        bgDrawable = new ColorDrawable(Color.WHITE);
        break;
      default:
        bgDrawable = new ColorDrawable(Color.WHITE);
        break;
    }
  }
  return bgDrawable;
}

代码示例来源:origin: DaxiaK/MyDiary

public Drawable getProfilePictureDrawable(Context context) {
  Drawable pictureDrawable;
  try {
    FileManager settingFM= new FileManager(context, FileManager.SETTING_DIR);
    File pictureFile = new File(settingFM.getDirAbsolutePath()
        + "/" + CUSTOM_PROFILE_PICTURE_FILENAME);
    if (pictureFile.exists()) {
      pictureDrawable = Drawable.createFromPath(pictureFile.getAbsolutePath());
    } else {
      pictureDrawable = ViewTools.getDrawable(context, R.drawable.ic_person_picture_default);
    }
  } catch (NullPointerException e) {
    pictureDrawable = ViewTools.getDrawable(context, R.drawable.ic_person_picture_default);
  }
  return pictureDrawable;
}

代码示例来源:origin: DaxiaK/MyDiary

public Drawable getProfileBgDrawable(Context context) {
  Drawable bgDrawable;
  switch (currentTheme) {
    case TAKI:
      bgDrawable = ViewTools.getDrawable(context, R.drawable.profile_theme_bg_taki);
      break;
    case MITSUHA:
      bgDrawable = ViewTools.getDrawable(context, R.drawable.profile_theme_bg_mitsuha);
      break;
    default:
      FileManager settingFM = new FileManager(context, FileManager.SETTING_DIR);
      File profileBgFile = new File(settingFM.getDirAbsolutePath()
          + "/" + CUSTOM_PROFILE_BANNER_BG_FILENAME);
      if (profileBgFile.exists()) {
        bgDrawable = Drawable.createFromPath(profileBgFile.getAbsolutePath());
      } else {
        bgDrawable = new ColorDrawable(getThemeMainColor(context));
      }
      break;
  }
  return bgDrawable;
}

代码示例来源:origin: DaxiaK/MyDiary

public Drawable getContactsBgDrawable(Context context, long topicId) {
  Drawable bgDrawable;
  FileManager contactsFM = new FileManager(context, FileManager.CONTACTS_ROOT_DIR);
  File contactsBg = new File(
      contactsFM.getDirAbsolutePath()
          + "/" + topicId
          + "/" + CUSTOM_TOPIC_BG_FILENAME);
  if (contactsBg.exists()) {
    bgDrawable = Drawable.createFromPath(contactsBg.getAbsolutePath());
  } else {
    switch (currentTheme) {
      case TAKI:
        bgDrawable = ViewTools.getDrawable(context, R.drawable.contacts_bg_taki);
        break;
      case MITSUHA:
        bgDrawable = ViewTools.getDrawable(context, R.drawable.contacts_bg_mitsuha);
        break;
      default:
        bgDrawable = new ColorDrawable(SPFManager.getMainColor(context));
        break;
    }
  }
  return bgDrawable;
}

代码示例来源:origin: DaxiaK/MyDiary

public Drawable getEntriesBgDrawable(Context context, long topicId) {
  Drawable bgDrawable;
  FileManager diaryFM = new FileManager(context, FileManager.DIARY_ROOT_DIR);
  File entriesBg = new File(
      diaryFM.getDirAbsolutePath()
          + "/" + topicId
          + "/" + CUSTOM_TOPIC_BG_FILENAME);
  if (entriesBg.exists()) {
    bgDrawable = Drawable.createFromPath(entriesBg.getAbsolutePath());
  } else {
    switch (currentTheme) {
      case TAKI:
        bgDrawable = ViewTools.getDrawable(context, R.drawable.theme_bg_taki);
        break;
      case MITSUHA:
        bgDrawable = ViewTools.getDrawable(context, R.drawable.theme_bg_mitsuha);
        break;
      default:
        bgDrawable = new ColorDrawable(SPFManager.getMainColor(context));
        break;
    }
  }
  return bgDrawable;
}

代码示例来源:origin: bitmovin/bitcodin-android-demo

@Override
 public void run() {
  thumbnailHolder.setImageDrawable(Drawable.createFromPath(thumbnail));
 }
});

代码示例来源:origin: bitmovin/bitcodin-android-demo

public Drawable get(String path) {
  if (this.mThumbnails != null && this.mThumbnails.containsKey(path)) {
   if (this.mThumbnails.get(path) == null) {
    this.mThumbnails.put(path, Drawable.createFromPath(path));
   }
   return this.mThumbnails.get(path);
  } else {
   return this.blankDrawable;
  }
 }
}

代码示例来源:origin: iZeroer/Daily

@Nullable
private Drawable getDrawableFromDisk(File file) {
  Drawable drawable = Drawable.createFromPath(file.getAbsolutePath());
  if (drawable != null) {
    int picHeight = calculatePicHeight(drawable);
    drawable.setBounds(0, 0, mPicWidth, picHeight);
  }
  return drawable;
}

代码示例来源:origin: LRH1993/LiveCircle

@Nullable
private Drawable getDrawableFromDisk(File file) {
  Drawable drawable = Drawable.createFromPath(file.getAbsolutePath());
  if (drawable != null) {
    int picHeight = calculatePicHeight(drawable);
    drawable.setBounds(0, 0, mPicWidth, picHeight);
  }
  return drawable;
}

代码示例来源:origin: suraj0208/WhatsappExtensions

@Override
  protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
    super.afterHookedMethod(param);
    Drawable drawable = Drawable.createFromPath(Environment.getExternalStorageDirectory() + ExtModule.WALLPAPER_DIR + contactNumber + ".jpg");
    if (drawable != null)
      param.args[0] = drawable;
  }
});

代码示例来源:origin: wirasetiawan29/Android

protected void onPostExecute(String file_url){
    dismissDialog(progress_bar_type);

    String imagePath = Environment.getExternalStorageDirectory().toString() + "/downloadedfile.jpg";
    my_image.setImageDrawable(Drawable.createFromPath(imagePath));
  }
}

代码示例来源:origin: Meiqia/MeiqiaSDK-Android

public static Drawable getDrawableFromFile(Context context, String url) {
  if (!isExternalStorageWritable()) {
    return null;
  }
  File cacheDir = context.getExternalCacheDir();
  if (cacheDir == null) {
    return null;
  }
  String md5 = stringToMD5(url);
  if (TextUtils.isEmpty(md5)) {
    return null;
  }
  File file = new File(cacheDir.getAbsolutePath() + "/" + md5);
  if (!file.exists()) {
    return null;
  }
  return Drawable.createFromPath(file.getAbsolutePath());
}

代码示例来源:origin: ckcz123/PKUHelper-Android

@SuppressWarnings("deprecation")
public static void realSetBackground(Intent data) {
  try {
    File file = MyFile.getFile(PKUHelper.pkuhelper, null, "bg_course_temp.jpg");
    if (file.exists()) {
      drawable = Drawable.createFromPath(file.getAbsolutePath());
      courseView.setBackgroundDrawable(drawable);
      File file2 = MyFile.getFile(PKUHelper.pkuhelper, null, "bg_course.jpg");
      file2.delete();
      file.renameTo(file2);
      PKUHelper.pkuhelper.sendBroadcast(
          new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
    }
  } catch (Exception | OutOfMemoryError e) {
    CustomToast.showErrorToast(PKUHelper.pkuhelper, "设置失败");
  }
}

代码示例来源:origin: ckcz123/PKUHelper-Android

@SuppressWarnings("deprecation")
public static void realSetBackground(Intent data) {
  try {
    File file = MyFile.getFile(PKUHelper.pkuhelper, null, "temp.jpg");
    if (file.exists()) {
      drawable = Drawable.createFromPath(file.getAbsolutePath());
      RelativeLayout relativeLayout = (RelativeLayout) PKUHelper.pkuhelper.findViewById(R.id.ipgw_view);
      relativeLayout.setBackgroundDrawable(drawable);
      File file2 = MyFile.getFile(PKUHelper.pkuhelper, null, "bg.jpg");
      file2.delete();
      file.renameTo(file2);
      PKUHelper.pkuhelper.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
    }
  } catch (Exception | OutOfMemoryError e) {
    CustomToast.showErrorToast(PKUHelper.pkuhelper, "设置失败");
  }
}

代码示例来源:origin: lltvcn/FreeText

@Override
public Drawable loadByName(String name) {
  Drawable drawable = drawableLruCache.get(name);
  if(drawable==null){
    drawable = Drawable.createFromPath(getLocalFileName(name));
    if(drawable!=null)
      drawableLruCache.put(name,drawable);
  }
  return drawable;
}

代码示例来源:origin: ckcz123/PKUHelper-Android

@Override
  public void run() {
    try {
      /*
      InputStream inputStream=WebConnection.connect(_url);
      Drawable drawable=Drawable.createFromStream(inputStream, _id+".png");
      */
      File file = MyFile.getCache(context, Util.getHash(_url));
      MyFile.urlToFile(_url, file, true);
      Drawable drawable = Drawable.createFromPath(file.getAbsolutePath());
      eventHandler.sendMessage(Message.obtain(
          eventHandler, Constants.MESSAGE_IMAGE_REQUEST_FINISHED, _type, _id, drawable));
    } catch (Exception e) {
      eventHandler.sendMessage(Message.obtain(
          eventHandler, Constants.MESSAGE_IMAGE_REQUEST_FAILED, _type, _id));
    }
  }
}).start();

相关文章