Java Code Examples for android.view.View.getResources()

The following are Jave code examples for showing how to use getResources() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: sample-code-posts   File: RecyclerTypeSafeMatcher.java   View Source Code Vote up 7 votes
@Override
protected boolean matchesSafely(final View itemView) {
    resources = itemView.getResources();
    if (childItemView == null) {
        final RecyclerView recyclerView = (RecyclerView) itemView.getRootView().findViewById(recyclerViewId);
        if (recyclerView != null && recyclerView.getId() == recyclerViewId) {
            childItemView = recyclerView.findViewHolderForAdapterPosition(position).itemView;
        } else {
            return false;
        }
    }

    if (targetViewId == -1) {
        return itemView == childItemView;
    } else {
        final View targetView = childItemView.findViewById(targetViewId);
        return itemView == targetView;
    }
}
 
Example 2
Project: GitHub   File: BlurTask.java   View Source Code Vote up 6 votes
public BlurTask(View target, BlurFactor factor, Callback callback) {
  target.setDrawingCacheEnabled(true);
  this.res = target.getResources();
  this.factor = factor;
  this.callback = callback;

  target.destroyDrawingCache();
  target.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW);
  capture = target.getDrawingCache();
  contextWeakRef = new WeakReference<>(target.getContext());
}
 
Example 3
Project: Slide-RSS   File: DragSortRecycler.java   View Source Code Vote up 6 votes
private BitmapDrawable createFloatingBitmap(View v) {
    floatingItemStatingBounds = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
    floatingItemBounds = new Rect(floatingItemStatingBounds);

    Bitmap bitmap = Bitmap.createBitmap(floatingItemStatingBounds.width(),
            floatingItemStatingBounds.height(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    v.draw(canvas);

    BitmapDrawable retDrawable = new BitmapDrawable(v.getResources(), bitmap);
    retDrawable.setBounds(floatingItemBounds);

    return retDrawable;
}
 
Example 4
Project: file.io-app   File: MaterialIn.java   View Source Code Vote up 6 votes
public static void startAnimators(final View view, int startOffsetX, int startOffsetY, long delay) {
    if (view.getVisibility() == View.VISIBLE && view.getAlpha() != 0f) {
        view.clearAnimation();
        view.animate().cancel();
        final Resources res = view.getResources();
        final float endAlpha = view.getAlpha();
        final float endTranslateX = view.getTranslationX();
        final float endTranslateY = view.getTranslationY();
        view.setAlpha(0);
        final Animator fade = ObjectAnimator.ofFloat(view, View.ALPHA, endAlpha);
        fade.setDuration(res.getInteger(R.integer.material_in_fade_anim_duration));
        fade.setInterpolator(new AccelerateInterpolator());
        fade.setStartDelay(delay);
        fade.start();
        ViewPropertyAnimator slide = view.animate();
        if (startOffsetY != 0) {
            view.setTranslationY(startOffsetY);
            slide.translationY(endTranslateY);
        } else {
            view.setTranslationX(startOffsetX);
            slide.translationX(endTranslateX);
        }
        slide.setInterpolator(new DecelerateInterpolator(2));
        slide.setDuration(res.getInteger(R.integer.material_in_slide_anim_duration));
        slide.setStartDelay(delay);
        slide.setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationCancel(Animator animation) {
                if (fade.isStarted()) {
                    fade.cancel();
                }
                view.setAlpha(endAlpha);
                view.setTranslationX(endTranslateX);
                view.setTranslationY(endTranslateY);
            }
        });
        slide.start();
    }
}
 
Example 5
Project: MiPushFramework   File: Utils.java   View Source Code Vote up 6 votes
public static void forceCustomPadding(View view, boolean additive) {
    final Resources res = view.getResources();
    final int paddingSide = res.getDimensionPixelSize(R.dimen.settings_side_margin);

    final int paddingStart = paddingSide + (additive ? view.getPaddingStart() : 0);
    final int paddingEnd = paddingSide + (additive ? view.getPaddingEnd() : 0);
    final int paddingBottom = res.getDimensionPixelSize(
            R.dimen.preference_fragment_padding_bottom);

    view.setPaddingRelative(paddingStart, 0, paddingEnd, paddingBottom);
}
 
Example 6
Project: Hello-Music-droid   File: DragSortRecycler.java   View Source Code Vote up 6 votes
private BitmapDrawable createFloatingBitmap(View v) {
    floatingItemStatingBounds = new Rect(v.getLeft(), v.getTop(), v.getRight(), v.getBottom());
    floatingItemBounds = new Rect(floatingItemStatingBounds);

    Bitmap bitmap = Bitmap.createBitmap(floatingItemStatingBounds.width(),
            floatingItemStatingBounds.height(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    v.draw(canvas);

    BitmapDrawable retDrawable = new BitmapDrawable(v.getResources(), bitmap);
    retDrawable.setBounds(floatingItemBounds);

    return retDrawable;
}
 
Example 7
Project: guanggoo-android   File: MyHtmlHttpImageGetter.java   View Source Code Vote up 6 votes
public ImageGetterAsyncTask(UrlDrawable d, MyHtmlHttpImageGetter imageGetter, View container,
                            boolean matchParentWidth, boolean compressImage, int qualityImage) {
    this.drawableReference = new WeakReference<>(d);
    this.imageGetterReference = new WeakReference<>(imageGetter);
    this.containerReference = new WeakReference<>(container);
    this.resources = new WeakReference<>(container.getResources());
    this.matchParentWidth = matchParentWidth;
    this.compressImage = compressImage;
    this.qualityImage = qualityImage;
}
 
Example 8
Project: AOSP-Kayboard-7.1.2   File: SetupWizardActivity.java   View Source Code Vote up 6 votes
public SetupStep(final int stepNo, final String applicationName, final TextView bulletView,
        final View stepView, final int title, final int instruction,
        final int finishedInstruction, final int actionIcon, final int actionLabel) {
    mStepNo = stepNo;
    mStepView = stepView;
    mBulletView = bulletView;
    final Resources res = stepView.getResources();
    mActivatedColor = res.getColor(R.color.setup_text_action);
    mDeactivatedColor = res.getColor(R.color.setup_text_dark);

    final TextView titleView = (TextView)mStepView.findViewById(R.id.setup_step_title);
    titleView.setText(res.getString(title, applicationName));
    mInstruction = (instruction == 0) ? null
            : res.getString(instruction, applicationName);
    mFinishedInstruction = (finishedInstruction == 0) ? null
            : res.getString(finishedInstruction, applicationName);

    mActionLabel = (TextView)mStepView.findViewById(R.id.setup_step_action_label);
    mActionLabel.setText(res.getString(actionLabel));
    if (actionIcon == 0) {
        final int paddingEnd = ViewCompatUtils.getPaddingEnd(mActionLabel);
        ViewCompatUtils.setPaddingRelative(mActionLabel, paddingEnd, 0, paddingEnd, 0);
    } else {
        TextViewCompatUtils.setCompoundDrawablesRelativeWithIntrinsicBounds(
                mActionLabel, res.getDrawable(actionIcon), null, null, null);
    }
}
 
Example 9
Project: Ristretto   File: RistrettoViewMatchers.java   View Source Code Vote up 6 votes
@Override
public boolean matchesSafely(View view) {
    if (resources == null) {
        resources = view.getResources();
        String typeName = resources.getResourceTypeName(resourceId);
        if ("string".matches(typeName)) {
            matcher = withText(resourceId);
        } else if ("id".equals(typeName)) {
            matcher = withId(resourceId);
        } else {
            throw new Resources.NotFoundException("Type not supported, only id & string are supported!");
        }
    }
    return matcher.matches(view);
}
 
Example 10
Project: BBSSDK-for-Android   File: BlurTask.java   View Source Code Vote up 6 votes
public BlurTask(View target, BlurFactor factor, Callback callback) {
	this.res = target.getResources();
	this.factor = factor;
	this.callback = callback;
	this.contextWeakRef = new WeakReference<Context>(target.getContext());

	target.setDrawingCacheEnabled(true);
	target.destroyDrawingCache();
	target.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW);
	bitmap = target.getDrawingCache();
}
 
Example 11
Project: PSNine   File: HtmlHttpImageGetter.java   View Source Code Vote up 6 votes
public ImageGetterAsyncTask(UrlDrawable d, HtmlHttpImageGetter imageGetter, View container,
                            boolean matchParentWidth, boolean compressImage, int qualityImage) {
    this.drawableReference = new WeakReference<>(d);
    this.imageGetterReference = new WeakReference<>(imageGetter);
    this.containerReference = new WeakReference<>(container);
    this.resources = new WeakReference<>(container.getResources());
    this.matchParentWidth = matchParentWidth;
    this.compressImage = compressImage;
    this.qualityImage = qualityImage;
}
 
Example 12
Project: javaide   File: DynamicLayoutInflator.java   View Source Code Vote up 6 votes
public static int parseColor(View view, String text) {
    if (text.startsWith("@color/")) {
        Resources resources = view.getResources();
        return resources.getColor(resources.getIdentifier(text.substring("@color/".length()), "color", view.getContext().getPackageName()));
    }
    if (text.length() == 4 && text.startsWith("#")) {
        text = "#" + text.charAt(1) + text.charAt(1) + text.charAt(2) + text.charAt(2) + text.charAt(3) + text.charAt(3);
    }
    return Color.parseColor(text);
}
 
Example 13
Project: AcademApp   File: MaterialIn.java   View Source Code Vote up 6 votes
public static void startAnimators(final View view, int startOffsetX, int startOffsetY, long delay) {
    if (view.getVisibility() == View.VISIBLE && view.getAlpha() != 0f) {
        view.clearAnimation();
        view.animate().cancel();
        final Resources res = view.getResources();
        final float endAlpha = view.getAlpha();
        final float endTranslateX = view.getTranslationX();
        final float endTranslateY = view.getTranslationY();
        view.setAlpha(0);
        final Animator fade = ObjectAnimator.ofFloat(view, View.ALPHA, endAlpha);
        fade.setDuration(res.getInteger(R.integer.material_in_fade_anim_duration));
        fade.setInterpolator(new AccelerateInterpolator());
        fade.setStartDelay(delay);
        fade.start();
        ViewPropertyAnimator slide = view.animate();
        if (startOffsetY != 0) {
            view.setTranslationY(startOffsetY);
            slide.translationY(endTranslateY);
        } else {
            view.setTranslationX(startOffsetX);
            slide.translationX(endTranslateX);
        }
        slide.setInterpolator(new DecelerateInterpolator(2));
        slide.setDuration(res.getInteger(R.integer.material_in_slide_anim_duration));
        slide.setStartDelay(delay);
        slide.setListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationCancel(Animator animation) {
                if (fade.isStarted()) {
                    fade.cancel();
                }
                view.setAlpha(endAlpha);
                view.setTranslationX(endTranslateX);
                view.setTranslationY(endTranslateY);
            }
        });
        slide.start();
    }
}
 
Example 14
Project: WeatherPlus   File: DayDetailsListAdapter.java   View Source Code Vote up 6 votes
@Override
public DayDetailsListHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext())
            .inflate(R.layout.day_details_list_item, parent, false);

    res = view.getResources();

    return new DayDetailsListHolder(view);
}
 
Example 15
Project: QiangHongBao   File: BlurTask.java   View Source Code Vote up 6 votes
public BlurTask(View target, BlurFactor factor, Callback callback) {
  this.res = target.getResources();
  this.factor = factor;
  this.callback = callback;
  this.contextWeakRef = new WeakReference<>(target.getContext());

  target.setDrawingCacheEnabled(true);
  target.destroyDrawingCache();
  target.setDrawingCacheQuality(View.DRAWING_CACHE_QUALITY_LOW);
  bitmap = target.getDrawingCache();
}
 
Example 16
Project: file.io-app   File: MaterialIn.java   View Source Code Vote up 5 votes
private static void initAnimation(View view, int offsetX, int offsetY, int delayDir, int slideDir) {
    if (offsetX < 0) {
        offsetX = 0;
    }
    if (offsetY < 0) {
        offsetY = 0;
    }
    if (view instanceof ViewGroup && ((ViewGroup) view).getChildCount() > 0 &&
            !MATERIAL_IN_BLOCK.equals(view.getTag()) &&
            !MATERIAL_IN_BLOCK_WITHOUT_SLIDE.equals(view.getTag())) {
        ViewGroup viewGroup = (ViewGroup) view;
        int viewHeight = viewGroup.getHeight();
        for (int i = 0; i < viewGroup.getChildCount(); i++) {
            View child = viewGroup.getChildAt(i);
            int nextOffsetX = offsetX + ((delayDir == Gravity.RIGHT) ? child.getLeft() :
                    (delayDir == Gravity.LEFT ? viewHeight - child.getRight() : 0));
            int nextOffsetY = offsetY + ((delayDir == Gravity.BOTTOM) ? child.getTop() :
                    (delayDir == Gravity.TOP ? viewHeight - child.getBottom() : 0));
            initAnimation(child, nextOffsetX, nextOffsetY, delayDir, slideDir);
        }
    } else {
        final Resources res = view.getResources();
        int slideTranslation = res.getDimensionPixelSize(R.dimen.material_in_anim_slide_offset);
        if (MATERIAL_IN_BLOCK_WITHOUT_SLIDE.equals(view.getTag())) {
            slideTranslation = 0;
        }
        int multY = 0;
        if (slideDir == Gravity.TOP) {
            multY = 1;
        } else if (slideDir == Gravity.BOTTOM) {
            multY = -1;
        }
        int multX = 0;
        if (slideDir == Gravity.LEFT) {
            multX = 1;
        } else if (slideDir == Gravity.RIGHT) {
            multX = -1;
        }
        int delayOffset = delayDir == Gravity.TOP || delayDir == Gravity.BOTTOM ? offsetY : offsetX;
        float delayDenominator = res.getDimension(R.dimen.material_in_delay_denominator);
        long delay = (long) (delayOffset / delayDenominator);
        startAnimators(view, slideTranslation * multX, slideTranslation * multY, delay);
    }
}
 
Example 17
Project: DroidTelescope   File: ViewUtils.java   View Source Code Vote up 5 votes
/**
 * 获取View的签名
 *
 * @param view
 * @return
 */
public static String getViewSign(View view) {
    StringBuilder sign = new StringBuilder(128);
    sign.append(view.getClass().getName());
    sign.append('{');
    sign.append(Integer.toHexString(System.identityHashCode(view)));
    sign.append(' ');
    sign.append(view.getLeft());
    sign.append(',');
    sign.append(view.getTop());
    sign.append('-');
    sign.append(view.getRight());
    sign.append(',');
    sign.append(view.getBottom());
    final int id = view.getId();
    if (id != View.NO_ID) {
        sign.append(" #");
        sign.append(Integer.toHexString(id));
        final Resources r = view.getResources();
        if (id > 0 && resourceHasPackage(id) && r != null) {
            try {
                String pkgname;
                switch (id & 0xff000000) {
                    case 0x7f000000:
                        pkgname = "app";
                        break;
                    case 0x01000000:
                        pkgname = "android";
                        break;
                    default:
                        pkgname = r.getResourcePackageName(id);
                        break;
                }
                String typename = r.getResourceTypeName(id);
                String entryname = r.getResourceEntryName(id);
                sign.append(" ");
                sign.append(pkgname);
                sign.append(":");
                sign.append(typename);
                sign.append("/");
                sign.append(entryname);
                if ("android".equals(pkgname) && "id".equals(typename) && "content".equals(entryname)) {
                    //找到android:id/content的父View,认为是根View了,不再查找
                    isRootParent = true;
                }
            } catch (Resources.NotFoundException e) {
            }
        }
    }
    sign.append('}');
    return sign.toString();
}
 
Example 18
Project: android-architecture-components   File: RecyclerViewMatcher.java   View Source Code Vote up 5 votes
public Matcher<View> atPositionOnView(final int position, final int targetViewId) {

        return new TypeSafeMatcher<View>() {
            Resources resources = null;
            View childView;

            public void describeTo(Description description) {
                String idDescription = Integer.toString(recyclerViewId);
                if (this.resources != null) {
                    try {
                        idDescription = this.resources.getResourceName(recyclerViewId);
                    } catch (Resources.NotFoundException var4) {
                        idDescription = String.format("%s (resource name not found)", recyclerViewId);
                    }
                }

                description.appendText("RecyclerView with id: " + idDescription + " at position: " + position);
            }

            public boolean matchesSafely(View view) {

                this.resources = view.getResources();

                if (childView == null) {
                    RecyclerView recyclerView = view.getRootView().findViewById(recyclerViewId);
                    if (recyclerView != null && recyclerView.getId() == recyclerViewId) {
                        RecyclerView.ViewHolder viewHolder = recyclerView.findViewHolderForAdapterPosition(position);
                        if (viewHolder != null) {
                            childView = viewHolder.itemView;
                        }
                    }
                    else {
                        return false;
                    }
                }

                if (targetViewId == -1) {
                    return view == childView;
                } else {
                    View targetView = childView.findViewById(targetViewId);
                    return view == targetView;
                }
            }
        };
    }
 
Example 19
Project: mvvm-template   File: FeedsViewHolder.java   View Source Code Vote up 5 votes
public FeedsViewHolder(@NonNull View itemView, NavigatorHelper navigatorHelper) {
    super(itemView);
    this.navigatorHelper = navigatorHelper;
    this.resources = itemView.getResources();
    avatarLoader = new AvatarLoader(itemView.getContext());
}
 
Example 20
Project: Android-CleanArchitecture-Java   File: RecyclerViewMatcher.java   View Source Code Vote up 5 votes
public Matcher<View> atPositionOnView(final int position, final int targetViewId) {

        return new TypeSafeMatcher<View>() {
            Resources resources = null;
            View childView;

            public void describeTo(Description description) {
                String idDescription = Integer.toString(recyclerViewId);
                if (this.resources != null) {
                    try {
                        idDescription = this.resources.getResourceName(recyclerViewId);
                    } catch (Resources.NotFoundException var4) {
                        idDescription = String.format("%s (resource name not found)", recyclerViewId);
                    }
                }

                description.appendText("RecyclerView with id: " + idDescription + " at position: " + position);
            }

            public boolean matchesSafely(View view) {

                this.resources = view.getResources();

                if (childView == null) {
                    RecyclerView recyclerView =
                            (RecyclerView) view.getRootView().findViewById(recyclerViewId);
                    if (recyclerView != null && recyclerView.getId() == recyclerViewId) {
                        RecyclerView.ViewHolder viewHolder = recyclerView.findViewHolderForAdapterPosition(position);
                        if (viewHolder != null) {
                            childView = viewHolder.itemView;
                        }
                    }
                    else {
                        return false;
                    }
                }

                if (targetViewId == -1) {
                    return view == childView;
                } else {
                    View targetView = childView.findViewById(targetViewId);
                    return view == targetView;
                }
            }
        };
    }