org.apache.catalina.Context.getResources()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(6.8k)|赞(0)|评价(0)|浏览(151)

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

Context.getResources介绍

[英]Return the Resources with which this Context is associated.
[中]返回与此上下文关联的资源。

代码示例

代码示例来源:origin: stackoverflow.com

public static final int getColor(Context context, int id) {
  final int version = Build.VERSION.SDK_INT;
  if (version >= 23) {
    return ContextCompatApi23.getColor(context, id);
  } else {
    return context.getResources().getColor(id);
  }
}

代码示例来源:origin: stackoverflow.com

public static float dpToPx(Context context, float valueInDp) {
  DisplayMetrics metrics = context.getResources().getDisplayMetrics();
  return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, valueInDp, metrics);
}

代码示例来源:origin: stackoverflow.com

public static boolean isTablet(Context context) {
  return (context.getResources().getConfiguration().screenLayout
      & Configuration.SCREENLAYOUT_SIZE_MASK)
      >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}

代码示例来源:origin: stackoverflow.com

public static float pixelsToSp(Context context, float px) {
  float scaledDensity = context.getResources().getDisplayMetrics().scaledDensity;
  return px/scaledDensity;
}

代码示例来源:origin: stackoverflow.com

public static float dipToPixels(Context context, float dipValue) {
  DisplayMetrics metrics = context.getResources().getDisplayMetrics();
  return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dipValue, metrics);
}

代码示例来源:origin: stackoverflow.com

public class RegularClass(){
  private Context context;

  public RegularClass(Context current){
    this.context = current;
  }

  public findResource(){
    context.getResources().getXml(R.xml.samplexml);
  }
}

代码示例来源:origin: stackoverflow.com

/**
 * Return a drawable object associated with a particular resource ID.
 * <p>
 * Starting in {@link android.os.Build.VERSION_CODES#LOLLIPOP}, the returned
 * drawable will be styled for the specified Context's theme.
 *
 * @param id The desired resource identifier, as generated by the aapt tool.
 *            This integer encodes the package, type, and resource entry.
 *            The value 0 is an invalid identifier.
 * @return Drawable An object that can be used to draw this resource.
 */
public static final Drawable getDrawable(Context context, int id) {
  final int version = Build.VERSION.SDK_INT;
  if (version >= 21) {
    return ContextCompatApi21.getDrawable(context, id);
  } else {
    return context.getResources().getDrawable(id);
  }
}

代码示例来源:origin: stackoverflow.com

public static int convertDip2Pixels(Context context, int dip) {
  return (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dip, context.getResources().getDisplayMetrics());
}

代码示例来源:origin: stackoverflow.com

public boolean isTablet(Context context) {
  boolean xlarge = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE);
  boolean large = ((context.getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE);
  return (xlarge || large);
}

代码示例来源:origin: stackoverflow.com

public static Uri resourceToUri(Context context, int resID) {
   return Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
       context.getResources().getResourcePackageName(resID) + '/' +
       context.getResources().getResourceTypeName(resID) + '/' +
       context.getResources().getResourceEntryName(resID) );
 }

代码示例来源:origin: stackoverflow.com

public static boolean isTablet(Context context) {
  return (context.getResources().getConfiguration().screenLayout
      & Configuration.SCREENLAYOUT_SIZE_MASK)
      >= Configuration.SCREENLAYOUT_SIZE_LARGE;
}

代码示例来源:origin: stackoverflow.com

public static Drawable getAssetImage(Context context, String filename) throws IOException {
  AssetManager assets = context.getResources().getAssets();
  InputStream buffer = new BufferedInputStream((assets.open("drawable/" + filename + ".png")));
  Bitmap bitmap = BitmapFactory.decodeStream(buffer);
  return new BitmapDrawable(context.getResources(), bitmap);
}

代码示例来源:origin: stackoverflow.com

public static Bitmap scaleDownBitmap(Bitmap photo, int newHeight, Context context) {
final float densityMultiplier = context.getResources().getDisplayMetrics().density;        
int h= (int) (newHeight*densityMultiplier);
int w= (int) (h * photo.getWidth()/((double) photo.getHeight()));
photo=Bitmap.createScaledBitmap(photo, w, h, true);
return photo;
}

代码示例来源:origin: stackoverflow.com

import android.content.Context;
import android.content.res.Resources;
import android.test.ActivityTestCase;

public class ActivityTestCaseTest extends ActivityTestCase {

  public void testFoo() {

    Context testContext = getInstrumentation().getContext();
    Resources testRes = testContext.getResources();

    assertNotNull(testRes);
    assertNotNull(testRes.getString(R.string.app_name));
  }
}

代码示例来源:origin: stackoverflow.com

public class Test extends ActivityTestCase {

  public void testFoo() {  

   // .. test project environment
   Context testContext = getInstrumentation().getContext();
   Resources testRes = testContext.getResources();
   InputStream ts = testRes.openRawResource(R.raw.your_res);

   assertNotNull(testRes);
  }    
}

代码示例来源:origin: stackoverflow.com

@NonNull Resources getLocalizedResources(Context context, Locale desiredLocale) {
  Configuration conf = context.getResources().getConfiguration();
  conf = new Configuration(conf);
  conf.setLocale(desiredLocale);
  Context localizedContext = context.createConfigurationContext(conf);
  return localizedContext.getResources();
}

代码示例来源:origin: stackoverflow.com

public class SimpleDividerItemDecoration extends RecyclerView.ItemDecoration {
  private Drawable mDivider;

  public SimpleDividerItemDecoration(Context context) {
    mDivider = context.getResources().getDrawable(R.drawable.line_divider);
  }

  @Override
  public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    int left = parent.getPaddingLeft();
    int right = parent.getWidth() - parent.getPaddingRight();

    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount; i++) {
      View child = parent.getChildAt(i);

      RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();

      int top = child.getBottom() + params.bottomMargin;
      int bottom = top + mDivider.getIntrinsicHeight();

      mDivider.setBounds(left, top, right, bottom);
      mDivider.draw(c);
    }
  }
}

代码示例来源:origin: stackoverflow.com

Context context = imageView.getContext();
int id = context.getResources().getIdentifier("picture0001", "drawable", context.getPackageName());
imageView.setImageResource(id);

代码示例来源:origin: stackoverflow.com

public static int isGooglePlayServicesAvailable(Context context) {
  PackageManager localPackageManager = context.getPackageManager();
  try {
    Resources localResources = context.getResources();
    localResources.getString(R.string.common_google_play_services_unknown_issue);
  } catch (Throwable localThrowable1) {
    Log.e("GooglePlayServicesUtil", "The Google Play services resources were not found. "
        + "Check your project configuration to ensure that the resources are included.");
  }
....

代码示例来源:origin: stackoverflow.com

public static Animator loadAnimator(Context context, @AnimatorRes int id)
    throws NotFoundException {
  return loadAnimator(context.getResources(), context.getTheme(), id);
}

相关文章

微信公众号

最新文章

更多

Context类方法