List of usage examples for android.view ViewGroup setAlpha
public void setAlpha(@FloatRange(from = 0.0, to = 1.0) float alpha)
From source file:Main.java
public static void collapse(final ViewGroup v) { final int initialHeight = v.getMeasuredHeight(); Animation a = new Animation() { @Override//w w w . j a v a 2s. c o m protected void applyTransformation(float interpolatedTime, Transformation t) { if (interpolatedTime == 1) { v.setVisibility(View.GONE); } else { v.getLayoutParams().height = initialHeight - (int) (initialHeight * interpolatedTime); v.setAlpha(1 - interpolatedTime); v.requestLayout(); } } @Override public boolean willChangeBounds() { return true; } }; a.setDuration((int) (initialHeight / v.getContext().getResources().getDisplayMetrics().density)); v.startAnimation(a); }
From source file:Main.java
public static void expand(final ViewGroup v) { v.measure(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.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 ww .j a v a 2 s .co m*/ v.setVisibility(View.VISIBLE); Animation a = new Animation() { @Override protected void applyTransformation(float interpolatedTime, Transformation t) { v.getLayoutParams().height = interpolatedTime == 1 ? ViewGroup.LayoutParams.WRAP_CONTENT : (int) (targetHeight * interpolatedTime); v.setAlpha(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.woodblockwithoutco.quickcontroldock.ui.factory.ServiceViewFactory.java
@SuppressWarnings("deprecation") public View getServiceView() { boolean sameLayout = GeneralResolver.isSameLayoutForLandscape(mContext); int inflateId = 0; if (ScreenUtils.getScreenOrientation(mContext) == Configuration.ORIENTATION_PORTRAIT || sameLayout) { inflateId = R.layout.panel_layout; } else {//w ww. j ava 2 s. c o m inflateId = R.layout.panel_layout_land; } View view = LayoutInflater.from(mContext).inflate(inflateId, null, false); final DragViewGroup dragView = (DragViewGroup) view.findViewById(R.id.panel_drag_handler); dragView.setBackgroundDrawable(ColorsResolver.getBackgroundDrawable(mContext)); if (ConstantHolder.getIsDebug()) { initTestVersionText(dragView); } ViewGroup viewToHide; if (ScreenUtils.getScreenOrientation(mContext) == Configuration.ORIENTATION_PORTRAIT || sameLayout) { LinearLayout panelsContainer = (LinearLayout) dragView.findViewById(R.id.panels_container); viewToHide = panelsContainer; if (ScreenUtils.getScreenOrientation(mContext) == Configuration.ORIENTATION_PORTRAIT) { panelsContainer.setTranslationY(GeneralResolver.getPanelsOffset(mContext)); } List<String> panelsOrder = PanelsOrderResolver.getPanelsOrder(mContext); if (ShortcutsResolver.isShortcutsEnabled(mContext)) { ShortcutsViewFactory svFactory = new ShortcutsViewFactory(mContext); int id = getContainerIdForPanelType(panelsOrder, PanelType.SHORTCUTS.name()); FrameLayout section = (FrameLayout) view.findViewById(id); adjustPanelMargins(section); section.addView(svFactory.getShortcutsSectionView()); } if (MusicResolver.isMusicPanelEnabled(mContext)) { MusicViewFactory mvFactory = new MusicViewFactory(mContext); int id = getContainerIdForPanelType(panelsOrder, PanelType.MUSIC.name()); FrameLayout section = (FrameLayout) view.findViewById(id); adjustPanelMargins(section); section.addView(mvFactory.getMusicView()); } if (TogglesResolver.isTogglesEnabled(mContext)) { TogglesViewFactory tvFactory = new TogglesViewFactory(mContext); int id = getContainerIdForPanelType(panelsOrder, PanelType.TOGGLES.name()); FrameLayout section = (FrameLayout) view.findViewById(id); adjustPanelMargins(section); section.addView(tvFactory.getTogglesSectionView()); } if (InfoResolver.isInfoPanelEnabled(mContext)) { InfoViewFactory ivFactory = new InfoViewFactory(mContext); int id = getContainerIdForPanelType(panelsOrder, PanelType.INFO.name()); FrameLayout section = (FrameLayout) view.findViewById(id); adjustPanelMargins(section); section.addView(ivFactory.getInfoView()); } if (NotificationsResolver.isNotificationsEnabled(mContext)) { final ImageView fakeNotificationsButton = (ImageView) dragView .findViewById(R.id.notifications_button_fake); PressImageView notificationsButton = (PressImageView) dragView .findViewById(R.id.notifications_button); fakeNotificationsButton.setVisibility(View.VISIBLE); notificationsButton.setVisibility(View.VISIBLE); fakeNotificationsButton.setImageResource(R.drawable.ic_notification_switch); fakeNotificationsButton.setColorFilter(ColorsResolver.getActiveColor(mContext)); final float SCALE = 1.5f; fakeNotificationsButton.setScaleX(SCALE); fakeNotificationsButton.setScaleY(SCALE); notificationsButton.setOnPressedStateChangeListener(new OnPressedStateChangeListener() { private final int BG_COLOR = ColorsResolver.getPressedColor(mContext); @Override public void onPressedStateChange(ImageView v, boolean pressed) { if (pressed) { fakeNotificationsButton.setBackgroundColor(BG_COLOR); } else { fakeNotificationsButton.setBackgroundColor(0x00000000); } } }); NotificationViewFactory nvFactory = new NotificationViewFactory(mContext); ViewGroup notificationsView = nvFactory.getNotificationsView(); notificationsView.setAlpha(0.0f); notificationsView.setVisibility(View.INVISIBLE); FrameLayout notificationsContainer = (FrameLayout) dragView .findViewById(R.id.notifications_section); notificationsContainer.addView(notificationsView); notificationsButton .setOnClickListener(new NotificationButtonClickListener(viewToHide, notificationsView)); } } else { ViewPager pager = (ViewPager) view.findViewById(R.id.landscape_pager); viewToHide = pager; List<View> views = new ArrayList<View>(); if (NotificationsResolver.isNotificationsEnabled(mContext)) { NotificationViewFactory nvFactory = new NotificationViewFactory(mContext); ViewGroup notificationsView = nvFactory.getNotificationsView(); views.add(notificationsView); } List<String> panelsOrder = PanelsOrderResolver.getPanelsOrder(mContext); for (String t : panelsOrder) { PanelType type = PanelType.valueOf(t); View v = null; FrameLayout container = (FrameLayout) LayoutInflater.from(mContext) .inflate(R.layout.panel_section_land, null, false); switch (type) { case INFO: // if (InfoResolver.isInfoPanelEnabled(mContext)) { InfoViewFactory ivFactory = new InfoViewFactory(mContext); FrameLayout fourthSection = (FrameLayout) view.findViewById(R.id.fourth_section); fourthSection.addView(ivFactory.getInfoView()); } break; case MUSIC: if (MusicResolver.isMusicPanelEnabled(mContext)) { MusicViewFactory mvFactory = new MusicViewFactory(mContext); v = mvFactory.getMusicView(); } break; case SHORTCUTS: if (ShortcutsResolver.isShortcutsEnabled(mContext)) { ShortcutsViewFactory svFactory = new ShortcutsViewFactory(mContext); v = svFactory.getShortcutsSectionView(); } break; case TOGGLES: if (TogglesResolver.isTogglesEnabled(mContext)) { TogglesViewFactory tvFactory = new TogglesViewFactory(mContext); v = tvFactory.getTogglesSectionView(); } break; } if (v != null) { views.add(v); container.addView(v); } } LandscapePanelsAdapter adapter = new LandscapePanelsAdapter(views); pager.setAdapter(adapter); pager.setOverScrollMode(View.OVER_SCROLL_NEVER); pager.setOffscreenPageLimit(VIEW_PAGER_OFFSCREEN_PAGES_COUNT); pager.setPageMargin(mContext.getResources().getDimensionPixelSize(R.dimen.pager_margin)); } return view; }
From source file:com.google.android.apps.muzei.settings.SettingsActivity.java
private void updateRenderLocally(boolean renderLocally) { if (mRenderLocally == renderLocally) { return;//w ww . j a va 2 s . c o m } mRenderLocally = renderLocally; final View uiContainer = findViewById(R.id.container); final ViewGroup localRenderContainer = (ViewGroup) findViewById(R.id.local_render_container); FragmentManager fm = getSupportFragmentManager(); Fragment localRenderFragment = fm.findFragmentById(R.id.local_render_container); if (mRenderLocally) { if (localRenderFragment == null) { fm.beginTransaction() .add(R.id.local_render_container, MuzeiRendererFragment.createInstance(false, false)) .commit(); } if (localRenderContainer.getAlpha() == 1) { localRenderContainer.setAlpha(0); } localRenderContainer.setVisibility(View.VISIBLE); localRenderContainer.animate().alpha(1).setDuration(2000).withEndAction(null); uiContainer.setBackgroundColor(0x00000000); // for ripple touch feedback } else { if (localRenderFragment != null) { fm.beginTransaction().remove(localRenderFragment).commit(); } localRenderContainer.animate().alpha(0).setDuration(1000).withEndAction(new Runnable() { @Override public void run() { localRenderContainer.setVisibility(View.GONE); } }); uiContainer.setBackground(null); } }