List of usage examples for android.view View setElevation
public void setElevation(float elevation)
From source file:Main.java
public static ValueAnimator getRiseElevationValue(final View targetView, int duration, final int mimElevation, final int maxElevation) { ValueAnimator addElevationValueAnim = ValueAnimator.ofInt(1); addElevationValueAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1) @Override/*from ww w . jav a 2s . c o m*/ public void onAnimationUpdate(ValueAnimator animation) { float fraction = animation.getAnimatedFraction(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { targetView.setElevation((1 - fraction) * maxElevation + mimElevation); } } }); addElevationValueAnim.setDuration(duration); return addElevationValueAnim; }
From source file:com.ffmpeger.card.utils.LPreviewUtilsBase.java
public void setViewElevation(View v, float elevation) { if (hasL()) { v.setElevation(elevation); } }
From source file:com.d2connect.droidltest.util.LPreviewUtilsImpl.java
@Override public void setViewElevation(View v, float elevation) { v.setElevation(elevation); }
From source file:com.veniosg.dir.android.fragment.SimpleFileListFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); // We expect the pathbar to add the bottom shadow in this case View toolbar = getActivity().findViewById(R.id.toolbar); if (toolbar != null) toolbar.setElevation(0); PathView pathView = (PathView) getActivity().findViewById(R.id.pathview); pathView.setActivityProvider(mActivityProvider); mPathBar = pathView;//from w ww. ja va 2 s . co m mTransitionView = (AnimatedFileListContainer) view.findViewById(R.id.zoomview); final View backButton = view.findViewById(R.id.empty_img); // Handle mPath differently if we restore state or just initially create the view. if (savedInstanceState == null) { mPathBar.setInitialDirectory(getPath()); } else { mPathBar.cd(getPath()); } mPathBar.setOnDirectoryChangedListener(new OnDirectoryChangedListener() { @Override public void directoryChanged(File newCurrentDir) { open(new FileHolder(newCurrentDir, getActivity())); backButton.setVisibility(mPathBar.isParentDirectoryNavigable() ? VISIBLE : GONE); } }); if (savedInstanceState != null && savedInstanceState.getBoolean(INSTANCE_STATE_PATHBAR_MODE)) { mPathBar.switchToManualInput(); } // Removed else clause as the other mode is the default. initContextualActions(); // For animations' sake ((ViewFlipper) view.findViewById(R.id.flipper)).setInAnimation(null); ((ViewFlipper) view.findViewById(R.id.flipper)).setOutAnimation(null); }
From source file:org.telegram.ui.Adapters.ContactsAdapter.java
@SuppressLint("NewApi") @Override/*w w w .ja v a2 s . c o m*/ public View getItemView(int section, int position, View convertView, ViewGroup parent) { int type = getItemViewType(section, position); if (type == 4) { if (convertView == null) { convertView = new DividerCell(mContext); convertView.setPadding(AndroidUtilities.dp(LocaleController.isRTL ? 28 : 72), 0, AndroidUtilities.dp(LocaleController.isRTL ? 72 : 28), 0); convertView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.chat_list_background)); convertView.setElevation(AndroidUtilities.dp(2)); } } else if (type == 3) { if (convertView == null) { convertView = new GreySectionCell(mContext); ((GreySectionCell) convertView) .setText(LocaleController.getString("Contacts", R.string.Contacts).toUpperCase()); //convertView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.s)); convertView.setElevation(AndroidUtilities.dp(2)); } } else if (type == 2) { if (convertView == null) { convertView = new TextCell(mContext); convertView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.chat_list_background)); } TextCell actionCell = (TextCell) convertView; if (needPhonebook) { actionCell.setTextAndIcon(LocaleController.getString("InviteFriends", R.string.InviteFriends), R.drawable.menu_invite); } else if (isAdmin) { actionCell.setTextAndIcon( LocaleController.getString("InviteToGroupByLink", R.string.InviteToGroupByLink), R.drawable.menu_invite); } else { if (position == 0) { actionCell.setTextAndIcon(LocaleController.getString("NewGroup", R.string.NewGroup), R.drawable.menu_newgroup); } else if (position == 1) { actionCell.setTextAndIcon(LocaleController.getString("NewSecretChat", R.string.NewSecretChat), R.drawable.menu_secret); } else if (position == 2) { actionCell.setTextAndIcon(LocaleController.getString("NewChannel", R.string.NewChannel), R.drawable.menu_broadcast); } } } else if (type == 1) { if (convertView == null) { convertView = new TextCell(mContext); convertView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.chat_list_background)); } ContactsController.Contact contact = ContactsController.getInstance().phoneBookContacts.get(position); TextCell textCell = (TextCell) convertView; if (contact.first_name != null && contact.last_name != null) { textCell.setText(contact.first_name + " " + contact.last_name); } else if (contact.first_name != null && contact.last_name == null) { textCell.setText(contact.first_name); } else { textCell.setText(contact.last_name); } } else if (type == 0) { if (convertView == null) { convertView = new UserCell(mContext, 58, 1, false); convertView.setBackgroundColor(ContextCompat.getColor(mContext, R.color.chat_list_background)); ((UserCell) convertView).setStatusColors(0xffa8a8a8, 0xff3b84c0); } HashMap<String, ArrayList<TLRPC.TL_contact>> usersSectionsDict = onlyUsers == 2 ? ContactsController.getInstance().usersMutualSectionsDict : ContactsController.getInstance().usersSectionsDict; ArrayList<String> sortedUsersSectionsArray = onlyUsers == 2 ? ContactsController.getInstance().sortedUsersMutualSectionsArray : ContactsController.getInstance().sortedUsersSectionsArray; ArrayList<TLRPC.TL_contact> arr = usersSectionsDict .get(sortedUsersSectionsArray.get(section - (onlyUsers != 0 && !isAdmin ? 0 : 1))); TLRPC.User user = MessagesController.getInstance().getUser(arr.get(position).user_id); ((UserCell) convertView).setData(user, null, null, 0); if (checkedMap != null) { ((UserCell) convertView).setChecked(checkedMap.containsKey(user.id), !scrolling); } if (ignoreUsers != null) { if (ignoreUsers.containsKey(user.id)) { convertView.setAlpha(0.5f); } else { convertView.setAlpha(1.0f); } } } if (type != 4) { if (convertView instanceof ForegroundFrameLayout) { ((ForegroundFrameLayout) convertView).setForeground(R.drawable.list_selector); } } return convertView; }
From source file:com.example.android.elevationdrag.ElevationDragFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.ztranslation, container, false); /* Find the {@link View} to apply z-translation to. */ final View floatingShape = rootView.findViewById(R.id.circle); /* Define the shape of the {@link View}'s shadow by setting one of the {@link Outline}s. */ floatingShape.setOutlineProvider(mOutlineProviderCircle); /* Clip the {@link View} with its outline. */ floatingShape.setClipToOutline(true); DragFrameLayout dragLayout = ((DragFrameLayout) rootView.findViewById(R.id.main_layout)); dragLayout.setDragFrameController(new DragFrameLayout.DragFrameLayoutController() { @Override/*from w w w .ja v a 2 s . com*/ public void onDragDrop(boolean captured) { /* Animate the translation of the {@link View}. Note that the translation is being modified, not the elevation. */ floatingShape.animate().translationZ(captured ? 50 : 0).setDuration(100); Log.d(TAG, captured ? "Drag" : "Drop"); } }); dragLayout.addDragView(floatingShape); /* Raise the circle in z when the "z+" button is clicked. */ rootView.findViewById(R.id.raise_bt).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mElevation += mElevationStep; Log.d(TAG, String.format(Locale.US, "Elevation: %.1f", mElevation)); floatingShape.setElevation(mElevation); } }); /* Lower the circle in z when the "z-" button is clicked. */ rootView.findViewById(R.id.lower_bt).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mElevation -= mElevationStep; // Don't allow for negative values of Z. if (mElevation < 0) { mElevation = 0; } Log.d(TAG, String.format(Locale.US, "Elevation: %.1f", mElevation)); floatingShape.setElevation(mElevation); } }); return rootView; }
From source file:com.malmstein.materialanimations.elevation.ElevationDragFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_ztranslation, container, false); /* Find the {@link View} to apply z-translation to. */ final View floatingShape = rootView.findViewById(R.id.circle); /* Define the shape of the {@link View}'s shadow by setting one of the {@link Outline}s. */ floatingShape.setOutlineProvider(mOutlineProviderCircle); /* Clip the {@link View} with its outline. */ floatingShape.setClipToOutline(true); DragFrameLayout dragLayout = ((DragFrameLayout) rootView.findViewById(R.id.main_layout)); dragLayout.setDragFrameController(new DragFrameLayout.DragFrameLayoutController() { @Override// w w w . j a va2 s.c om public void onDragDrop(boolean captured) { /* Animate the translation of the {@link View}. Note that the translation is being modified, not the elevation. */ floatingShape.animate().translationZ(captured ? 50 : 0).scaleX(1.2f).scaleY(1.3f).setDuration(100); Log.d(TAG, captured ? "Drag" : "Drop"); } }); dragLayout.addDragView(floatingShape); /* Raise the circle in z when the "z+" button is clicked. */ rootView.findViewById(R.id.raise_bt).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mElevation += mElevationStep; Log.d(TAG, String.format("Elevation: %.1f", mElevation)); floatingShape.setElevation(mElevation); } }); /* Lower the circle in z when the "z-" button is clicked. */ rootView.findViewById(R.id.lower_bt).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mElevation -= mElevationStep; // Don't allow for negative values of Z. if (mElevation < 0) { mElevation = 0; } Log.d(TAG, String.format("Elevation: %.1f", mElevation)); } }); return rootView; }
From source file:com.mishiranu.dashchan.ui.navigator.NavigatorActivity.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void showThemeDialog() { final int checkedItem = Arrays.asList(Preferences.VALUES_THEME).indexOf(Preferences.getTheme()); Resources resources = getResources(); float density = ResourceUtils.obtainDensity(resources); ScrollView scrollView = new ScrollView(this); LinearLayout outer = new LinearLayout(this); outer.setOrientation(LinearLayout.VERTICAL); int outerPadding = (int) (16f * density); outer.setPadding(outerPadding, outerPadding, outerPadding, outerPadding); scrollView.addView(outer, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); final AlertDialog dialog = new AlertDialog.Builder(this).setTitle(R.string.action_change_theme) .setView(scrollView).setNegativeButton(android.R.string.cancel, null).create(); View.OnClickListener listener = v -> { int index = (int) v.getTag(); if (index != checkedItem) { Preferences.setTheme(Preferences.VALUES_THEME[index]); recreate();//from www. j a v a2s . co m } dialog.dismiss(); }; int circleSize = (int) (56f * density); int itemPadding = (int) (12f * density); LinearLayout inner = null; for (int i = 0; i < Preferences.ENTRIES_THEME.length; i++) { if (i % 3 == 0) { inner = new LinearLayout(this); inner.setOrientation(LinearLayout.HORIZONTAL); outer.addView(inner, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); } LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.VERTICAL); layout.setGravity(Gravity.CENTER); layout.setBackgroundResource( ResourceUtils.getResourceId(this, android.R.attr.selectableItemBackground, 0)); layout.setPadding(0, itemPadding, 0, itemPadding); layout.setOnClickListener(listener); layout.setTag(i); inner.addView(layout, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f)); View view = new View(this); int colorBackgroundAttr = Preferences.VALUES_THEME_COLORS[i][0]; int colorPrimaryAttr = Preferences.VALUES_THEME_COLORS[i][1]; int colorAccentAttr = Preferences.VALUES_THEME_COLORS[i][2]; Resources.Theme theme = getResources().newTheme(); theme.applyStyle(Preferences.VALUES_THEME_IDS[i], true); TypedArray typedArray = theme .obtainStyledAttributes(new int[] { colorBackgroundAttr, colorPrimaryAttr, colorAccentAttr }); view.setBackground(new ThemeChoiceDrawable(typedArray.getColor(0, 0), typedArray.getColor(1, 0), typedArray.getColor(2, 0))); typedArray.recycle(); if (C.API_LOLLIPOP) { view.setElevation(6f * density); } layout.addView(view, circleSize, circleSize); TextView textView = new TextView(this, null, android.R.attr.textAppearanceListItem); textView.setSingleLine(true); textView.setEllipsize(TextUtils.TruncateAt.END); textView.setText(Preferences.ENTRIES_THEME[i]); if (C.API_LOLLIPOP) { textView.setAllCaps(true); textView.setTypeface(GraphicsUtils.TYPEFACE_MEDIUM); textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12f); } else { textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14f); } textView.setGravity(Gravity.CENTER_HORIZONTAL); textView.setPadding(0, (int) (8f * density), 0, 0); layout.addView(textView, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); if (i + 1 == Preferences.ENTRIES_THEME.length && Preferences.ENTRIES_THEME.length % 3 != 0) { if (Preferences.ENTRIES_THEME.length % 3 == 1) { inner.addView(new View(this), 0, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1f)); } inner.addView(new View(this), new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1f)); } } dialog.show(); }
From source file:info.papdt.blacklight.ui.main.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { mLang = Utility.getCurrentLanguage(this); if (mLang > -1) { Utility.changeLanguage(this, mLang); }/* ww w . j ava 2s . c o m*/ Utility.initDarkMode(this); mLayout = R.layout.main; super.onCreate(savedInstanceState); // Initialize views mDrawer = Utility.findViewById(this, R.id.drawer); mDrawerWrapper = Utility.findViewById(this, R.id.drawer_wrapper); mName = Utility.findViewById(this, R.id.account_name); mAvatar = Utility.findViewById(this, R.id.my_avatar); mCover = Utility.findViewById(this, R.id.my_cover); mPager = Utility.findViewById(this, R.id.main_pager); mTabs = Utility.findViewById(this, R.id.main_tabs); mTabsWrapper = Utility.findViewById(this, R.id.main_tab_wrapper); mToolbarTabs = Utility.findViewById(this, R.id.top_tab); mToolbarWrapper = Utility.findViewById(this, R.id.toolbar_wrapper); mTopWrapper = Utility.findViewById(this, R.id.top_wrapper); mShadow = Utility.findViewById(this, R.id.action_shadow); mSetting = Utility.findViewById(this, R.id.drawer_settings); mMultiUser = Utility.findViewById(this, R.id.drawer_multiuser); mAccountSwitch = Utility.findViewById(this, R.id.account_switch); mAccountSwitchIcon = Utility.findViewById(this, R.id.account_switch_icon); mSearchBox = Utility.findViewById(this, R.id.main_search); final String[] pages = getResources().getStringArray(R.array.main_tabs); mPager.setAdapter(new FragmentStatePagerAdapter(getFragmentManager()) { @Override public int getCount() { return pages.length; } @Override public Fragment getItem(int position) { return mFragments[position]; } @Override public CharSequence getPageTitle(int position) { return pages[position]; } }); mPager.setOffscreenPageLimit(pages.length); mTabs.setViewPager(mPager); // Search Box mSearchHistory = new SearchHistoryCache(this); mSearchBox.setLogoText(getString(R.string.search)); mSearchBox.setSearchListener(new SearchBox.SearchListener() { @Override public void onSearchOpened() { } @Override public void onSearchCleared() { } @Override public void onSearchClosed() { mSearchBox.hideCircularly(MainActivity.this); } @Override public void onSearchTermChanged() { } @Override public void onSearch(String result) { mSearchHistory.addHistory(result); Intent i = new Intent(Intent.ACTION_MAIN); i.setClass(MainActivity.this, SearchActivity.class); i.putExtra("keyword", result); startActivity(i); } }); // Initialize toolbar custom view mTopWrapper.setAlpha(0f); final Drawable[] pageIcons = new Drawable[] { getResources().getDrawable(R.drawable.ic_drawer_home), getResources().getDrawable(R.drawable.ic_drawer_comment), getResources().getDrawable(R.drawable.ic_drawer_at), getResources().getDrawable(R.drawable.ic_drawer_at), getResources().getDrawable(R.drawable.ic_drawer_pm), getResources().getDrawable(R.drawable.ic_drawer_fav) }; mToolbarTabs.setIconAdapter(new SlidingTabLayout.TabIconAdapter() { @Override public Drawable getIcon(int position) { return pageIcons[position]; } }); mToolbarTabs.setViewPager(mPager, mTabs); // Prepare listener to be set later final ViewPager.OnPageChangeListener pageListener = new ViewPager.OnPageChangeListener() { @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { if (position + 1 >= mFragments.length) return; Fragment cur = mFragments[position]; Fragment next = mFragments[position + 1]; float factorCur = 0, factorNext = 0; if (cur instanceof HeaderProvider) { factorCur = ((HeaderProvider) cur).getHeaderFactor(); } if (next instanceof HeaderProvider) { factorNext = ((HeaderProvider) next).getHeaderFactor(); } float factor = factorCur + positionOffset * (factorNext - factorCur); updateHeaderTranslation(factor); } @Override public void onPageSelected(int pos) { } @Override public void onPageScrollStateChanged(int state) { } }; final int color = getResources().getColor(R.color.white); SlidingTabStrip.SimpleTabColorizer colorizer = new SlidingTabStrip.SimpleTabColorizer() { @Override public int getIndicatorColor(int position) { return color; } @Override public int getSelectedTitleColor(int position) { return color; } }; mTabs.setCustomTabColorizer(colorizer); mTabs.notifyIndicatorColorChanged(); mToolbarTabs.setCustomTabColorizer(colorizer); mToolbarTabs.notifyIndicatorColorChanged(); mToolbarTabs.setOnClickCurrentTabListener(new SlidingTabLayout.OnClickCurrentTabListener() { @Override public void onClick(int pos) { Fragment f = mFragments[pos]; if (f instanceof Refresher) { ((Refresher) f).goToTop(); } } }); if (Build.VERSION.SDK_INT >= 21) { mToolbar.setElevation(0); //findViewById(R.id.main_tab_wrapper).setElevation(getToolbarElevation()); } else { mShadow.setAlpha(0); } // Detect if the user chose to use right-handed mode boolean rightHanded = Settings.getInstance(this).getBoolean(Settings.RIGHT_HANDED, false); mDrawerGravity = rightHanded ? Gravity.RIGHT : Gravity.LEFT; //set GroupFragmentCallBack GroupFragment.setGfCallBack(new GroupFragment.GFCallBack() { @Override public void onItemClick() { openOrCloseDrawer(); } }); // Set gravity View nav = findViewById(R.id.nav); DrawerLayout.LayoutParams p = (DrawerLayout.LayoutParams) nav.getLayoutParams(); p.gravity = mDrawerGravity; nav.setLayoutParams(p); // Semi-transparent statusbar over drawer if (Build.VERSION.SDK_INT >= 21) { mDrawer.setStatusBarBackgroundColor(Utility.getColorPrimaryDark(this)); } // Initialize naviagtion drawer //mDrawer = (DrawerLayout) findViewById(R.id.drawer); mToggle = new ActionBarDrawerToggle(this, mDrawer, mToolbar, 0, 0) { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); invalidateOptionsMenu(); hideFAB(); } @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); invalidateOptionsMenu(); } }; mToggle.setDrawerIndicatorEnabled(true); mDrawer.setDrawerListener(mToggle); // Use system shadow for Lollipop but fall back for pre-L if (Build.VERSION.SDK_INT >= 21) { nav.setElevation(10.0f); } else if (mDrawerGravity == Gravity.LEFT) { mDrawer.setDrawerShadow(R.drawable.drawer_shadow, Gravity.LEFT); } // My account initUserAccount(); //new GroupsTask().execute(); // Initialize FAB mFAB = new FloatingActionButton.Builder(this).withGravity(Gravity.BOTTOM | Gravity.RIGHT) .withPaddings(0, 0, 16, 16).withDrawable(Utility.getFABNewIcon(this)) .withButtonColor(Utility.getFABBackground(this)).withButtonSize(56 + 16).create(); mFAB.setOnClickListener(this); mFAB.setOnLongClickListener(this); // Bind Utility.bindOnClick(this, mSetting, "settings"); Utility.bindOnClick(this, mAccountSwitch, "drawerSwitch"); Utility.bindOnClick(this, mMultiUser, "muser"); Utility.bindOnClick(this, mCover, "showMe"); // Initialize ActionBar Style getSupportActionBar().setHomeButtonEnabled(true); getSupportActionBar().setDisplayShowHomeEnabled(true); getSupportActionBar().setDisplayUseLogoEnabled(false); getSupportActionBar().setDisplayShowTitleEnabled(true); // Drawer Groups getFragmentManager().beginTransaction().add(R.id.drawer_group, mGroupFragment) .add(R.id.drawer_group, mMultiUserFragment).show(mGroupFragment).hide(mMultiUserFragment).commit(); updateSplashes(); // Ignore first spinner event mIgnore = true; mToolbar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { updateSplashes(); } }); // Adjust drawer layout params mDrawerWrapper.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { mHeaderHeight = mTabs.getHeight() + 10; mWrapperHeight = mTabsWrapper.getHeight(); if (DEBUG) { Log.d(TAG, "Global layout. Wrapper height: " + mWrapperHeight); } mToolbarTabs.setOnPageChangeListener(pageListener); mToolbarTabs.setTabIconSize(mToolbar.getHeight()); if (mWrapperHeight > 0) mDrawerWrapper.getViewTreeObserver().removeGlobalOnLayoutListener(this); } }); MultiUserFragment.setMuCallBack(new MultiUserFragment.MuCallBack() { @Override public void syncAccount() { initUserAccount(); ((HomeTimeLineFragment) mFragments[0]).doRefresh(); drawerSwitch(); mMultiUserFragment.reload(); } @Override public void closeDrawer() { openOrCloseDrawer(); } }); }