Java Code Examples for android.view.View#getBackground()

The following examples show how to use android.view.View#getBackground() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WXViewUtils.java    From ucar-weex-core with Apache License 2.0 6 votes vote down vote up
/**
 * Due limitation in Android platform, the linear gradient in the following page will not be
 * rounded if {@link Canvas#clipPath(Path)} of the parent view invoked when API level is lower
 * than 21.
 * http://dotwe.org/weex/963c9ade129f86757cecdd85651cd30e
 * @param targetView
 * @param borderDrawable
 * @return
 */
private static boolean clipCanvasIfBackgroundImageExist(@NonNull View targetView,
                                                        @NonNull BorderDrawable borderDrawable) {
  if (targetView instanceof ViewGroup) {
    View child;
    ViewGroup parent = ((ViewGroup) targetView);
    int count = parent.getChildCount();
    for (int i = 0; i < count; i++) {
      child = parent.getChildAt(i);
      if (child.getBackground() instanceof BorderDrawable &&
          ((BorderDrawable) child.getBackground()).hasImage() &&
          Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        return false;
      }
    }
  }
  return true;
}
 
Example 2
Source File: UserSettingsFragment.java    From aws-mobile-self-paced-labs-samples with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.com_facebook_usersettingsfragment, container, false);
    loginButton = (LoginButton) view.findViewById(R.id.com_facebook_usersettingsfragment_login_button);
    loginButton.setProperties(loginButtonProperties);
    loginButton.setFragment(this);
    Session session = getSession();
    if (session != null && !session.equals(Session.getActiveSession())) {
        loginButton.setSession(session);
    }
    connectedStateLabel = (TextView) view.findViewById(R.id.com_facebook_usersettingsfragment_profile_name);
    
    // if no background is set for some reason, then default to Facebook blue
    if (view.getBackground() == null) {
        view.setBackgroundColor(getResources().getColor(R.color.com_facebook_blue));
    } else {
        view.getBackground().setDither(true);
    }
    return view;
}
 
Example 3
Source File: Utils.java    From Noyze with Apache License 2.0 6 votes vote down vote up
public static void unbindDrawables(View view) {
    if (null == view) return;
    if (view.getBackground() != null) {
        view.getBackground().setCallback(null);
        view.setBackground(null);
    }
    if (view instanceof ViewGroup) {
        ViewGroup container = (ViewGroup) view;
        for (int i = 0, e = container.getChildCount(); i < e; i++) {
            unbindDrawables(container.getChildAt(i));
        }
        container.removeAllViews();
    } else if (view instanceof ImageView) {
        ImageView image = (ImageView) view;
        Drawable d = image.getDrawable();
        if (d instanceof BitmapDrawable) {
            Bitmap bmp = ((BitmapDrawable) d).getBitmap();
            if (null != bmp) {
                bmp.recycle();
            }
        }
        image.setImageDrawable(null);
    }
}
 
Example 4
Source File: MainActivity.java    From android-art-res with Apache License 2.0 6 votes vote down vote up
@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);
    if (hasFocus) {
        // test transition
        View v = findViewById(R.id.test_transition);
        TransitionDrawable drawable = (TransitionDrawable) v.getBackground();
        drawable.startTransition(1000);

        // test scale
        View testScale = findViewById(R.id.test_scale);
        ScaleDrawable testScaleDrawable = (ScaleDrawable) testScale.getBackground();
        testScaleDrawable.setLevel(10);

        // test clip
        ImageView testClip = (ImageView) findViewById(R.id.test_clip);
        ClipDrawable testClipDrawable = (ClipDrawable) testClip.getDrawable();
        testClipDrawable.setLevel(8000);
        
        // test custom drawable
        View testCustomDrawable = findViewById(R.id.test_custom_drawable);
        CustomDrawable customDrawable = new CustomDrawable(Color.parseColor("#0ac39e"));
        testCustomDrawable.setBackgroundDrawable(customDrawable);
    }
}
 
Example 5
Source File: UserSettingsFragment.java    From KlyphMessenger with MIT License 6 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.com_facebook_usersettingsfragment, container, false);
    loginButton = (LoginButton) view.findViewById(R.id.com_facebook_usersettingsfragment_login_button);
    loginButton.setProperties(loginButtonProperties);
    loginButton.setFragment(this);
    loginButton.setLoginLogoutEventName(AnalyticsEvents.EVENT_USER_SETTINGS_USAGE);

    Session session = getSession();
    if (session != null && !session.equals(Session.getActiveSession())) {
        loginButton.setSession(session);
    }
    connectedStateLabel = (TextView) view.findViewById(R.id.com_facebook_usersettingsfragment_profile_name);
    
    // if no background is set for some reason, then default to Facebook blue
    if (view.getBackground() == null) {
        view.setBackgroundColor(getResources().getColor(R.color.com_facebook_blue));
    } else {
        view.getBackground().setDither(true);
    }
    return view;
}
 
Example 6
Source File: BaseSearchablePolicyPreferenceFragment.java    From android-testdpc with Apache License 2.0 5 votes vote down vote up
@Override
public void onBindViewHolder(PreferenceViewHolder holder, int position) {
    super.onBindViewHolder(holder, position);
    if (position == mHighlightPosition) {
        View v = holder.itemView;
        if (v.getBackground() != null) {
            final int centerX = v.getWidth() / 2;
            final int centerY = v.getHeight() / 2;
            v.getBackground().setHotspot(centerX, centerY);
        }
        v.setPressed(true);
        v.setPressed(false);
        mHighlightPosition = -1;
    }
}
 
Example 7
Source File: SlidingPaneLayout.java    From CodenameOne with GNU General Public License v2.0 5 votes vote down vote up
private static boolean hasOpaqueBackground(View v) {
    final Drawable bg = v.getBackground();
    if (bg != null) {
        return bg.getOpacity() == PixelFormat.OPAQUE;
    }
    return false;
}
 
Example 8
Source File: ConvertUtils.java    From Android-UtilCode with Apache License 2.0 5 votes vote down vote up
/**
 * view转Bitmap
 *
 * @param view 视图
 * @return bitmap
 */
public static Bitmap view2Bitmap(View view) {
    if (view == null) return null;
    Bitmap ret = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(ret);
    Drawable bgDrawable = view.getBackground();
    if (bgDrawable != null) {
        bgDrawable.draw(canvas);
    } else {
        canvas.drawColor(Color.WHITE);
    }
    view.draw(canvas);
    return ret;
}
 
Example 9
Source File: AnimatorUtils.java    From FancyAccordionView with Apache License 2.0 5 votes vote down vote up
@Override
public Integer get(View view) {
    Drawable background = view.getBackground();
    if (background instanceof LayerDrawable
            && ((LayerDrawable) background).getNumberOfLayers() > 0) {
        background = ((LayerDrawable) background).getDrawable(0);
    }
    return DrawableCompat.getAlpha(background);
}
 
Example 10
Source File: CustomActivity.java    From WhereYouGo with GNU General Public License v3.0 5 votes vote down vote up
private void unbindDrawables(View view) {
    if (view == null)
        return;
    if (view.getBackground() != null) {
        view.getBackground().setCallback(null);
    }
    if (view instanceof ViewGroup) {
        for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
            unbindDrawables(((ViewGroup) view).getChildAt(i));
        }
        ((ViewGroup) view).removeAllViews();
    }
}
 
Example 11
Source File: EmBackgroundTintHelper.java    From AndroidTint with Apache License 2.0 5 votes vote down vote up
/**
 *
 * @param view
 * @param info
 */
static void applySupportBackgroundTint(View view, TintInfo info) {
    final Drawable background = view.getBackground();
    if (background != null) {
        if (info != null) {
            EmTintManager.tintDrawable(background, info, view.getDrawableState());
        }
    }
}
 
Example 12
Source File: SlidingPaneLayout.java    From android-recipes-app with Apache License 2.0 5 votes vote down vote up
private static boolean viewIsOpaque(View v) {
    if (ViewCompat.isOpaque(v)) return true;

    // View#isOpaque didn't take all valid opaque scrollbar modes into account
    // before API 18 (JB-MR2). On newer devices rely solely on isOpaque above and return false
    // here. On older devices, check the view's background drawable directly as a fallback.
    if (Build.VERSION.SDK_INT >= 18) return false;

    final Drawable bg = v.getBackground();
    if (bg != null) {
        return bg.getOpacity() == PixelFormat.OPAQUE;
    }
    return false;
}
 
Example 13
Source File: DebugDrawerLayout.java    From u2020 with Apache License 2.0 5 votes vote down vote up
private static boolean hasOpaqueBackground(View v) {
  final Drawable bg = v.getBackground();
  if (bg != null) {
    return bg.getOpacity() == PixelFormat.OPAQUE;
  }
  return false;
}
 
Example 14
Source File: BackgroundFade.java    From android-proguards with Apache License 2.0 5 votes vote down vote up
@Override
public Animator onAppear(ViewGroup sceneRoot, View view,
                         TransitionValues startValues, TransitionValues endValues) {
    if (view == null || view.getBackground() == null) return null;
    Drawable background = view.getBackground();
    background.setAlpha(0);
    return ObjectAnimator.ofInt(background, ViewUtils.DRAWABLE_ALPHA, 0, 255);
}
 
Example 15
Source File: ImageUtils.java    From Android-UtilCode with Apache License 2.0 5 votes vote down vote up
/**
 * view转Bitmap
 *
 * @param view 视图
 * @return bitmap
 */
public static Bitmap view2Bitmap(View view) {
    if (view == null) return null;
    Bitmap ret = Bitmap.createBitmap(view.getWidth(), view.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(ret);
    Drawable bgDrawable = view.getBackground();
    if (bgDrawable != null) {
        bgDrawable.draw(canvas);
    } else {
        canvas.drawColor(Color.WHITE);
    }
    view.draw(canvas);
    return ret;
}
 
Example 16
Source File: VitoViewImpl2.java    From fresco with MIT License 4 votes vote down vote up
@Nullable
private static FrescoDrawable2 getDrawable(final View view) {
  Drawable d =
      view instanceof ImageView ? ((ImageView) view).getDrawable() : view.getBackground();
  return d instanceof FrescoDrawable2 ? (FrescoDrawable2) d : null;
}
 
Example 17
Source File: SlidingUpPanelLayout.java    From AndroidSlidingUpPanel-ScrollView with Apache License 2.0 4 votes vote down vote up
private static boolean hasOpaqueBackground(View v) {
    final Drawable bg = v.getBackground();
    return bg != null && bg.getOpacity() == PixelFormat.OPAQUE;
}
 
Example 18
Source File: TutorialActivity.java    From PhoneTutorial with Apache License 2.0 4 votes vote down vote up
private void setSmallBackground(View v){
	v.setBackgroundResource(R.drawable.background_small_indicator);
	LayerDrawable layer = (LayerDrawable) v.getBackground();
	GradientDrawable shape =  (GradientDrawable) layer.findDrawableByLayerId(R.id.shape_bacground);
	shape.setColor(colorIndicator);
}
 
Example 19
Source File: LinearScrollView.java    From Tangram-Android with MIT License 4 votes vote down vote up
private void setViewColor(View view, int color) {
    if (view.getBackground() instanceof GradientDrawable) {
        GradientDrawable drawable = (GradientDrawable) view.getBackground().mutate();
        drawable.setColor(color);
    }
}
 
Example 20
Source File: SlidingUpPanelLayout.java    From mobile-manager-tool with MIT License 4 votes vote down vote up
private static boolean hasOpaqueBackground(View v) {
    final Drawable bg = v.getBackground();
    return bg != null && bg.getOpacity() == PixelFormat.OPAQUE;
}