List of usage examples for android.view View getContext
@ViewDebug.CapturedViewProperty public final Context getContext()
From source file:com.apptentive.android.sdk.util.Util.java
/** * helper method to set the background depending on the android version * * @param v//from w w w.ja v a 2 s. c o m * @param drawableRes */ public static void setBackground(View v, int drawableRes) { setBackground(v, getCompatDrawable(v.getContext(), drawableRes)); }
From source file:android.support.design.testutils.TestUtilsActions.java
/** * Replaces an existing {@link TabLayout} with a new one inflated from the specified * layout resource./* www . j a va2 s . c om*/ */ public static ViewAction replaceTabLayout(final @LayoutRes int tabLayoutResId) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return isDisplayingAtLeast(90); } @Override public String getDescription() { return "Replace TabLayout"; } @Override public void perform(UiController uiController, View view) { uiController.loopMainThreadUntilIdle(); final ViewGroup viewGroup = (ViewGroup) view; final int childCount = viewGroup.getChildCount(); // Iterate over children and find TabLayout for (int i = 0; i < childCount; i++) { View child = viewGroup.getChildAt(i); if (child instanceof TabLayout) { // Remove the existing TabLayout viewGroup.removeView(child); // Create a new one final LayoutInflater layoutInflater = LayoutInflater.from(view.getContext()); final TabLayout newTabLayout = (TabLayout) layoutInflater.inflate(tabLayoutResId, viewGroup, false); // Make sure we're adding the new TabLayout at the same index viewGroup.addView(newTabLayout, i); break; } } uiController.loopMainThreadUntilIdle(); } }; }
From source file:Main.java
public static void collapse(final View v, boolean isHalf) { final int initialHeight = v.getMeasuredHeight(); remainHeigt = 0;/* ww w. java 2 s. co m*/ if (isHalf) { remainHeigt = initialHeight / 2; } else { remainHeigt = initialHeight; } Animation a = new Animation() { @Override protected void applyTransformation(float interpolatedTime, Transformation t) { if (interpolatedTime == 1) { v.setVisibility(View.GONE); } else { v.getLayoutParams().height = initialHeight - (int) (remainHeigt * interpolatedTime); v.requestLayout(); } } @Override public boolean willChangeBounds() { return true; } }; // 1dp/ms a.setDuration((int) (initialHeight / v.getContext().getResources().getDisplayMetrics().density)); v.startAnimation(a); }
From source file:Main.java
public static void expand(final View v) { v.measure(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); final int targetHeight = v.getMeasuredHeight(); // Older versions of android (pre API 21) cancel animations for views with a height of 0. v.getLayoutParams().height = 1;//from w w w . j a v a 2 s . com v.setVisibility(View.VISIBLE); Animation a = new Animation() { @Override protected void applyTransformation(float interpolatedTime, Transformation t) { v.getLayoutParams().height = interpolatedTime == 1 ? RelativeLayout.LayoutParams.WRAP_CONTENT : (int) (targetHeight * interpolatedTime); v.requestLayout(); } @Override public boolean willChangeBounds() { return true; } }; // 1dp/ms a.setDuration((int) (targetHeight / v.getContext().getResources().getDisplayMetrics().density) * 2); v.startAnimation(a); }
From source file:com.facebook.react.uimanager.AccessibilityDelegateUtil.java
public static void setDelegate(final View view) { // if a view already has an accessibility delegate, replacing it could cause problems, // so leave it alone. if (!ViewCompat.hasAccessibilityDelegate(view)) { ViewCompat.setAccessibilityDelegate(view, new AccessibilityDelegateCompat() { @Override//from ww w.j ava 2 s. c o m public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) { super.onInitializeAccessibilityNodeInfo(host, info); String accessibilityHint = (String) view.getTag(R.id.accessibility_hint); AccessibilityRole accessibilityRole = (AccessibilityRole) view.getTag(R.id.accessibility_role); if (accessibilityRole == null) { accessibilityRole = AccessibilityRole.NONE; } setRole(info, accessibilityRole, view.getContext()); if (!(accessibilityHint == null)) { String contentDescription = (String) info.getContentDescription(); if (contentDescription != null) { contentDescription = contentDescription + ", " + accessibilityHint; info.setContentDescription(contentDescription); } else { info.setContentDescription(accessibilityHint); } } } }); } }
From source file:Main.java
public static void expand(final View v, Activity activity) { v.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); Resources r = activity.getResources(); final float px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 200, r.getDisplayMetrics()); final int targtetHeight = (int) px;//200;//v.getMeasuredHeight(); v.getLayoutParams().height = 0;//from w w w . ja va2 s .co m v.setVisibility(View.VISIBLE); Animation a = new Animation() { @Override protected void applyTransformation(float interpolatedTime, Transformation t) { v.getLayoutParams().height = interpolatedTime == 1 ? ((int) px)//200//ViewGroup.LayoutParams.WRAP_CONTENT : (int) (targtetHeight * interpolatedTime); v.requestLayout(); } @Override public boolean willChangeBounds() { return true; } }; a.setDuration((int) (targtetHeight / v.getContext().getResources().getDisplayMetrics().density)); v.startAnimation(a); }
From source file:Main.java
public static void expand(final View v, boolean isHalf) { v.measure(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); targetHeight = v.getMeasuredHeight(); if (isHalf) { targetHeight = targetHeight / 2; }//from w w w.j ava 2s . c o m // Older versions of android (pre API 21) cancel animations for views with a height of 0. v.getLayoutParams().height = 1; v.setVisibility(View.VISIBLE); Animation a = new Animation() { @Override protected void applyTransformation(float interpolatedTime, Transformation t) { v.getLayoutParams().height = interpolatedTime == 1 ? RelativeLayout.LayoutParams.WRAP_CONTENT : (int) (targetHeight * interpolatedTime); v.requestLayout(); } @Override public boolean willChangeBounds() { return true; } }; // 1dp/ms a.setDuration((int) (targetHeight / v.getContext().getResources().getDisplayMetrics().density)); v.startAnimation(a); }
From source file:com.desno365.mods.DesnoUtils.java
public static Snackbar getDefaultSnackbar(View parent, int text, int duration) { Snackbar snack = Snackbar.make(parent, text, duration); // make text white View view = snack.getView();/*from ww w.j a v a2s . com*/ @SuppressLint("PrivateResource") TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text); tv.setTextColor(Color.WHITE); // set background and action colors TypedArray a = parent.getContext().getTheme() .obtainStyledAttributes(new int[] { R.attr.color_primary_dark, R.attr.color_accent }); int color1 = a.getColor(0, 0); int color2 = a.getColor(1, 0); a.recycle(); view.setBackgroundColor(color1); snack.setActionTextColor(color2); return snack; }
From source file:com.erevacation.challenge.injection.modules.ViewHolderModule.java
public ViewHolderModule(View itemView) { activity = (AppCompatActivity) itemView.getContext(); }
From source file:com.nickandjerry.dynamiclayoutinflator.DynamicLayoutInflator.java
public static Drawable getDrawableByName(View view, String name) { Resources resources = view.getResources(); return resources.getDrawable(resources.getIdentifier(name, "drawable", view.getContext().getPackageName())); }