Example usage for android.view View getResources

List of usage examples for android.view View getResources

Introduction

In this page you can find the example usage for android.view View getResources.

Prototype

public Resources getResources() 

Source Link

Document

Returns the resources associated with this view.

Usage

From source file:Main.java

public static final int getColor(View view, int id) {
    final int version = Build.VERSION.SDK_INT;
    if (version >= Build.VERSION_CODES.M) {
        return view.getResources().getColor(id, null);
    } else {//from w w  w .  j  av a2s  . c o m
        return view.getResources().getColor(id);
    }
}

From source file:com.bitants.wally.base.BaseFragment.java

public static void setInsets(Activity context, View view, boolean useStatusBarHeight, int extraHeight,
        int extraBottom) {
    int otherPadding = view.getResources().getDimensionPixelSize(R.dimen.gridview_other_padding);
    int bottomPadding = otherPadding + extraBottom;
    int statusbarHeight = 0;
    view.setPadding(otherPadding, statusbarHeight + extraHeight + otherPadding, otherPadding, bottomPadding);
}

From source file:Main.java

public static String getResourceId(View v) {
    // http://stackoverflow.com/a/17583380/198348
    int id = v.getId();
    String idString = "no id";
    if (id != View.NO_ID) {
        Resources res = v.getResources();
        if (res != null)
            idString = res.getResourceEntryName(id);
    }//  www .ja v  a  2  s  . c om
    return idString;
}

From source file:Main.java

@SuppressWarnings("deprecation")
public static android.graphics.drawable.Drawable getDrawableFromResource(final android.view.View view,
        final int resourceId) {
    if (VERSION.SDK_INT >= VERSION_CODES.LOLLIPOP) {
        return view.getContext().getDrawable(resourceId);
    }//from  w  ww . java  2  s  . c  o  m
    return view.getResources().getDrawable(resourceId);
}

From source file:Main.java

public static String getIDNameFromView(View v) {
    // -- get your View --
    int id = v.getId(); // get integer id of view
    String idString = "";
    if (id != View.NO_ID) { // make sure id is valid
        Resources res = v.getResources(); // get resources
        if (res != null)
            idString = res.getResourceEntryName(id); // get id string entry
    }/*  www  . ja  v  a 2 s .c o m*/
    return idString;
}

From source file:Main.java

public static boolean isKeyboardShown(View rootView) {
    // 128dp = 32dp * 4, minimum button height 32dp and generic 4 rows soft keyboard
    final int SOFT_KEYBOARD_HEIGHT_DP_THRESHOLD = 128;

    Rect r = new Rect();
    rootView.getWindowVisibleDisplayFrame(r);
    DisplayMetrics dm = rootView.getResources().getDisplayMetrics();
    // heightDiff = rootView height - status bar height (r.top) - visible frame height (r.bottom - r.top)
    int heightDiff = rootView.getBottom() - r.bottom;
    // Threshold size: dp to pixels, multiply with display density
    boolean isKeyboardShown = heightDiff > SOFT_KEYBOARD_HEIGHT_DP_THRESHOLD * dm.density;

    //        Log.d(TAG, "isKeyboardShown ? " + isKeyboardShown + ", heightDiff:" + heightDiff + ", density:" + dm.density
    //                + "root view height:" + rootView.getHeight() + ", rect:" + r);

    return isKeyboardShown;
}

From source file:com.yamin.kk.vlc.BitmapCache.java

public static Bitmap GetFromResource(View v, int resId) {
    BitmapCache cache = BitmapCache.getInstance();
    Bitmap bitmap = cache.getBitmapFromMemCache(resId);
    if (bitmap == null) {
        bitmap = BitmapFactory.decodeResource(v.getResources(), resId);
        cache.addBitmapToMemCache(resId, bitmap);
    }// w w w .  ja v a 2s  . co m
    return bitmap;
}

From source file:org.videolan.vlc.util.BitmapCache.java

public static Bitmap getFromResource(View v, int resId) {
    BitmapCache cache = BitmapCache.getInstance();
    Bitmap bitmap = cache.getBitmapFromMemCache(resId);
    if (bitmap == null) {
        bitmap = BitmapFactory.decodeResource(v.getResources(), resId);
        cache.addBitmapToMemCache(resId, bitmap);
    }/*from w  w w . java2 s .c om*/
    return bitmap;
}

From source file:org.xbmc.kore.testhelpers.action.ViewActions.java

public static ViewAction setCurrentViewPagerItem(final int pageTitleResourceId) {
    return new ViewAction() {

        @Override/*from   ww w  . j ava2  s . c  o m*/
        public Matcher<View> getConstraints() {
            return new TypeSafeMatcher<View>() {
                @Override
                protected boolean matchesSafely(View item) {
                    return item instanceof ViewPager;
                }

                @Override
                public void describeTo(Description description) {
                    description.appendText("is a SeekBar.");
                }
            };
        }

        @Override
        public String getDescription() {
            return null;
        }

        @Override
        public void perform(UiController uiController, View view) {
            ViewPager viewPager = (ViewPager) view;
            String expectedTitle = view.getResources().getString(pageTitleResourceId);
            PagerAdapter pagerAdapter = viewPager.getAdapter();
            for (int i = 0; i < pagerAdapter.getCount(); i++) {
                if (expectedTitle.contentEquals(pagerAdapter.getPageTitle(i))) {
                    viewPager.setCurrentItem(i);
                    return;
                }
            }
        }
    };
}

From source file:enterprayz.megatools.Tools.java

public static void showHintMessage(@NonNull View view, @StringRes int message) {
    showHintMessage(view, view.getResources().getString(message));
}