List of usage examples for android.view ViewGroup setBackground
public void setBackground(Drawable background)
From source file:Main.java
public static void setLayoutGradient(final ViewGroup viewGroup, final int[] colors, final float[] distribution) { ShapeDrawable.ShaderFactory shaderFactory = new ShapeDrawable.ShaderFactory() { @Override/* www . j ava2s . c o m*/ public Shader resize(final int width, final int height) { return new LinearGradient(0, 0, 0, height, colors, //substitute the correct colors for these distribution, Shader.TileMode.REPEAT); } }; PaintDrawable paint = new PaintDrawable(); paint.setShape(new RectShape()); paint.setShaderFactory(shaderFactory); viewGroup.setBackground(paint); }
From source file:com.example.app_2.utils.Utils.java
public static void setWallpaper(android.view.ViewGroup vg, int reqWidth, int reqHeight, Bitmap wallpaper, ScalingLogic sl) {/*from w w w .j a va 2 s. co m*/ if (wallpaper == null) { WallpaperManager wallpaperManager = WallpaperManager.getInstance(App_2.getAppContext()); Drawable wallpaperDrawable = wallpaperManager.getDrawable(); wallpaper = BitmapCalc.drawableToBitmap(wallpaperDrawable); } if (reqHeight == 0 || reqWidth == 0) { reqHeight = App_2.getMaxHeight(); reqWidth = App_2.getMaxWidth(); } Resources r = App_2.getAppContext().getResources(); int orientation = r.getConfiguration().orientation; switch (orientation) { case Configuration.ORIENTATION_LANDSCAPE: // landscape Bitmap wallpaperLandscape = ScalingUtilities.createScaledBitmap(wallpaper, reqHeight, reqWidth, sl); if (Utils.hasJellyBean()) vg.setBackground(new BitmapDrawable(r, wallpaperLandscape)); else { if (vg instanceof LinearLayout) { LinearLayout ll = (LinearLayout) vg; ll.setBackgroundDrawable(new BitmapDrawable(r, wallpaperLandscape)); } else if (vg instanceof DrawerLayout) { DrawerLayout dl = (DrawerLayout) vg; dl.setBackgroundDrawable(new BitmapDrawable(r, wallpaperLandscape)); } } //wallpaperLandscape.recycle(); break; case Configuration.ORIENTATION_PORTRAIT: // portrait Bitmap wallpaperPortrait = ScalingUtilities.createScaledBitmap(wallpaper, reqWidth, reqHeight, sl); if (Utils.hasJellyBean()) vg.setBackground(new BitmapDrawable(r, wallpaperPortrait)); else { if (vg instanceof LinearLayout) { LinearLayout ll = (LinearLayout) vg; ll.setBackgroundDrawable(new BitmapDrawable(r, wallpaperPortrait)); } else if (vg instanceof DrawerLayout) { DrawerLayout dl = (DrawerLayout) vg; dl.setBackgroundDrawable(new BitmapDrawable(r, wallpaperPortrait)); } } //wallpaperPortrait.recycle(); break; default: //ll.setBackgroundDrawable(App_2.wallpaperDrawable); break; } }
From source file:com.example.administrator.mywebviewdrawsign.SysWebView.java
public void hideCustomView() { // This code is adapted from the original Android Browser code, licensed under the Apache License, Version 2.0 LogUtils.d("Hidding Custom View"); if (mCustomView == null) { return;//from w ww .jav a2 s . co m } // Hide the custom view. mCustomView.setVisibility(View.GONE); // Remove the custom view from its container. ViewGroup parent = (ViewGroup) this.getParent(); if (background != null) { parent.setBackground(background); } parent.removeView(mCustomView); mCustomView = null; mCustomViewCallback.onCustomViewHidden(); // Show the content view. this.setVisibility(View.VISIBLE); if (objects != null && objects.length > 0) { for (Object obj : objects) { if (obj instanceof View) { ((View) obj).setVisibility(View.VISIBLE); } else if (obj instanceof Fragment) { ((Fragment) obj).getView().setVisibility(View.VISIBLE); } } } ((Activity) mContext).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); final WindowManager.LayoutParams attrs = ((Activity) mContext).getWindow().getAttributes(); attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN); ((Activity) mContext).getWindow().setAttributes(attrs); ((Activity) mContext).getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS); }
From source file:com.example.administrator.mywebviewdrawsign.SysWebView.java
public void showCustomView(View view, WebChromeClient.CustomViewCallback callback) { // This code is adapted from the original Android Browser code, licensed under the Apache License, Version 2.0 LogUtils.d("showing Custom View"); // if a view already exists then immediately terminate the new one if (mCustomView != null) { callback.onCustomViewHidden();//from w w w .j ava 2 s. com return; } // Store the view and its callback for later (to kill it properly) mCustomView = view; mCustomViewCallback = callback; // Add the custom view to its container. ViewGroup parent = (ViewGroup) this.getParent(); background = parent.getBackground(); parent.setBackground(new ColorDrawable(Color.BLACK)); parent.addView(view, COVER_SCREEN_GRAVITY_CENTER); // Hide the content view. this.setVisibility(View.GONE); // Finally show the custom view container. parent.setVisibility(View.VISIBLE); parent.bringToFront(); if (objects != null && objects.length > 0) { for (Object obj : objects) { if (obj instanceof View) { ((View) obj).setVisibility(View.GONE); } else if (obj instanceof Fragment) { ((Fragment) obj).getView().setVisibility(View.GONE); } } } ((Activity) mContext).setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); ((Activity) mContext).getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); }
From source file:ca.taglab.PictureFrame.ScreenSlidePageFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout containing a title and body text. final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.fragment_screen_slide_page, container, false);/* w w w .j a v a 2 s. c o m*/ Bitmap picture = BitmapFactory.decodeFile(mImgPath); rootView.setBackground(new BitmapDrawable(getResources(), picture)); mConfirmation = (ImageView) rootView.findViewById(R.id.confirm); ((TextView) rootView.findViewById(R.id.name)).setText(mName); rootView.findViewById(R.id.control).getBackground().setAlpha(200); optionsOpen = false; mMsgHistory = rootView.findViewById(R.id.msg); mMsgHistory.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(), MessagesActivity.class); intent.putExtra("user_name", mName); intent.putExtra("user_id", mId); intent.putExtra("owner_id", mOwnerId); startActivity(intent); hideOptions(); } }); mPhoto = rootView.findViewById(R.id.photo); mPhoto.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { String filename = String.valueOf(System.currentTimeMillis()) + ".jpg"; ContentValues values = new ContentValues(); values.put(MediaStore.Images.Media.TITLE, filename); mCapturedImageURI = getActivity().getContentResolver() .insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedImageURI); startActivityForResult(intent, CAPTURE_PICTURE); hideOptions(); } catch (Exception e) { Log.e(TAG, "Camera intent failed"); } } }); mVideo = rootView.findViewById(R.id.video); mVideo.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { String filename = String.valueOf(System.currentTimeMillis()) + ".3gp"; ContentValues values = new ContentValues(); values.put(MediaStore.Video.Media.TITLE, filename); mCapturedVideoURI = getActivity().getContentResolver() .insert(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, values); Intent intent = new Intent(MediaStore.ACTION_VIDEO_CAPTURE); intent.putExtra(MediaStore.EXTRA_OUTPUT, mCapturedVideoURI); startActivityForResult(intent, CAPTURE_VIDEO); hideOptions(); } catch (Exception e) { Log.e(TAG, "Video intent failed"); } } }); mAudio = rootView.findViewById(R.id.audio); mAudio.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { Intent intent = new Intent(getActivity(), AudioRecorderActivity.class); startActivityForResult(intent, CAPTURE_AUDIO); hideOptions(); } catch (Exception e) { Log.e(TAG, "Audio intent failed"); } } }); mWave = rootView.findViewById(R.id.wave); mWave.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { new SendEmailAsyncTask(getActivity(), mEmail, "PictureFrame: I'm thinking of you", "Wave sent via PictureFrame", null).execute(); //Toast.makeText(getActivity(), "Wave sent to: " + mEmail, Toast.LENGTH_SHORT).show(); hideOptions(); messageSent(v); } catch (Exception e) { Log.e("SendEmailAsyncTask", e.getMessage(), e); //Toast.makeText(getActivity(), "Wave to " + mEmail + " failed", Toast.LENGTH_SHORT).show(); } } }); mCancel = rootView.findViewById(R.id.close); mPhoto.getBackground().setAlpha(200); mVideo.getBackground().setAlpha(200); mAudio.getBackground().setAlpha(200); mWave.getBackground().setAlpha(200); mShortAnimationDuration = getResources().getInteger(android.R.integer.config_shortAnimTime); mLongAnimationDuration = getResources().getInteger(android.R.integer.config_longAnimTime); rootView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (!optionsOpen) showOptions(); } }); mCancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (optionsOpen) hideOptions(); } }); Cursor unread = getActivity().getContentResolver().query(UserContentProvider.MESSAGE_CONTENT_URI, MessageTable.PROJECTION, MessageTable.COL_TO_ID + "=? AND " + MessageTable.COL_FROM_ID + "=? AND " + MessageTable.COL_READ + "=?", new String[] { Long.toString(mOwnerId), Long.toString(mId), Long.toString(0) }, null); if (unread != null && unread.moveToFirst()) { rootView.findViewById(R.id.notification).setVisibility(View.VISIBLE); rootView.findViewById(R.id.notification).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(), MessagesActivity.class); intent.putExtra("user_name", mName); intent.putExtra("user_id", mId); intent.putExtra("owner_id", mOwnerId); startActivity(intent); v.setVisibility(View.INVISIBLE); } }); } if (unread != null) { unread.close(); } return rootView; }
From source file:com.android.tv.settings.dialog.old.BaseDialogFragment.java
public void performEntryTransition(final Activity activity, final ViewGroup contentView, int iconResourceId, Uri iconResourceUri, final ImageView icon, final TextView title, final TextView description, final TextView breadcrumb) { // Pull out the root layout of the dialog and set the background drawable, to be // faded in during the transition. final ViewGroup twoPane = (ViewGroup) contentView.getChildAt(0); twoPane.setVisibility(View.INVISIBLE); // If the appropriate data is embedded in the intent and there is an icon specified // in the content fragment, we animate the icon from its initial position to the final // position. Otherwise, we perform a simpler transition in which the ActionFragment // slides in and the ContentFragment text fields slide in. mIntroAnimationInProgress = true;//from ww w . ja v a2s .c o m List<TransitionImage> images = TransitionImage.readMultipleFromIntent(activity, activity.getIntent()); TransitionImageAnimation ltransitionAnimation = null; final Uri iconUri; final int color; if (images != null && images.size() > 0) { if (iconResourceId != 0) { iconUri = Uri.parse(UriUtils.getAndroidResourceUri(activity, iconResourceId)); } else if (iconResourceUri != null) { iconUri = iconResourceUri; } else { iconUri = null; } TransitionImage src = images.get(0); color = src.getBackground(); if (iconUri != null) { ltransitionAnimation = new TransitionImageAnimation(contentView); ltransitionAnimation.addTransitionSource(src); ltransitionAnimation.transitionDurationMs(ANIMATE_IN_DURATION).transitionStartDelayMs(0) .interpolator(new DecelerateInterpolator(1f)); } } else { iconUri = null; color = 0; } final TransitionImageAnimation transitionAnimation = ltransitionAnimation; // Fade out the old activity, and hard cut the new activity. activity.overridePendingTransition(R.anim.hard_cut_in, R.anim.fade_out); int bgColor = mFragment.getResources().getColor(R.color.dialog_activity_background); mBgDrawable.setColor(bgColor); mBgDrawable.setAlpha(0); twoPane.setBackground(mBgDrawable); // If we're animating the icon, we create a new ImageView in which to place the embedded // bitmap. We place it in the root layout to match its location in the previous activity. mShadowLayer = (FrameLayoutWithShadows) twoPane.findViewById(R.id.shadow_layout); if (transitionAnimation != null) { transitionAnimation.listener(new TransitionImageAnimation.Listener() { @Override public void onRemovedView(TransitionImage src, TransitionImage dst) { if (icon != null) { //want to make sure that users still see at least the source image // if the dst image is too large to finish downloading before the // animation is done. Check if the icon is not visible. This mean // BaseContentFragement have not finish downloading the image yet. if (icon.getVisibility() != View.VISIBLE) { icon.setImageDrawable(src.getBitmap()); int intrinsicWidth = icon.getDrawable().getIntrinsicWidth(); LayoutParams lp = icon.getLayoutParams(); lp.height = lp.width * icon.getDrawable().getIntrinsicHeight() / intrinsicWidth; icon.setVisibility(View.VISIBLE); } icon.setAlpha(1f); } if (mShadowLayer != null) { mShadowLayer.setShadowsAlpha(1f); } onIntroAnimationFinished(); } }); icon.setAlpha(0f); if (mShadowLayer != null) { mShadowLayer.setShadowsAlpha(0f); } } // We need to defer the remainder of the animation preparation until the first // layout has occurred, as we don't yet know the final location of the icon. twoPane.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { twoPane.getViewTreeObserver().removeOnGlobalLayoutListener(this); // if we buildLayer() at this time, the texture is actually not created // delay a little so we can make sure all hardware layer is created before // animation, in that way we can avoid the jittering of start animation twoPane.postOnAnimationDelayed(mEntryAnimationRunnable, ANIMATE_DELAY); } final Runnable mEntryAnimationRunnable = new Runnable() { @Override public void run() { if (!mFragment.isAdded()) { // We have been detached before this could run, so just bail return; } twoPane.setVisibility(View.VISIBLE); final int secondaryDelay = SLIDE_IN_DISTANCE; // Fade in the activity background protection ObjectAnimator oa = ObjectAnimator.ofInt(mBgDrawable, "alpha", 255); oa.setDuration(ANIMATE_IN_DURATION); oa.setStartDelay(secondaryDelay); oa.setInterpolator(new DecelerateInterpolator(1.0f)); oa.start(); View actionFragmentView = activity.findViewById(mActionAreaId); boolean isRtl = ViewCompat.getLayoutDirection(contentView) == ViewCompat.LAYOUT_DIRECTION_RTL; int startDist = isRtl ? SLIDE_IN_DISTANCE : -SLIDE_IN_DISTANCE; int endDist = isRtl ? -actionFragmentView.getMeasuredWidth() : actionFragmentView.getMeasuredWidth(); // Fade in and slide in the ContentFragment TextViews from the start. prepareAndAnimateView(title, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION, new DecelerateInterpolator(1.0f), false); prepareAndAnimateView(breadcrumb, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION, new DecelerateInterpolator(1.0f), false); prepareAndAnimateView(description, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION, new DecelerateInterpolator(1.0f), false); // Fade in and slide in the ActionFragment from the end. prepareAndAnimateView(actionFragmentView, 0, endDist, secondaryDelay, ANIMATE_IN_DURATION, new DecelerateInterpolator(1.0f), false); if (icon != null && transitionAnimation != null) { // now we get the icon view in place, update the transition target TransitionImage target = new TransitionImage(); target.setUri(iconUri); target.createFromImageView(icon); if (icon.getBackground() instanceof ColorDrawable) { ColorDrawable d = (ColorDrawable) icon.getBackground(); target.setBackground(d.getColor()); } transitionAnimation.addTransitionTarget(target); transitionAnimation.startTransition(); } else if (icon != null) { prepareAndAnimateView(icon, 0, startDist, secondaryDelay, ANIMATE_IN_DURATION, new DecelerateInterpolator(1.0f), true /* is the icon */); if (mShadowLayer != null) { mShadowLayer.setShadowsAlpha(0f); } } } }; }); }