Java Code Examples for androidx.core.view.ViewCompat#setElevation()

The following examples show how to use androidx.core.view.ViewCompat#setElevation() . 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: Frag2D.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle bdl) {
    View v = inflater.inflate(R.layout.compass_2d, container, false);
    mCompassView = v.findViewById(R.id.compass);
    if (mHidden) {
        mCompassView.setScaleX(0);
        mCompassView.setScaleY(0);
    }
    
    mAngleTV = v.findViewById(R.id.angle);
    mDistanceTV = v.findViewById(R.id.distance);
    mInfo = v.findViewById(R.id.infobox);
    mBG = v.findViewById(R.id.background);
    View info = (View) mAngleTV.getParent();
    ViewCompat.setElevation(info, info.getPaddingTop());
    
    setAngle(mAngle);
    setQiblaAngle(mQiblaAngle);
    setQiblaDistance(mQiblaDistance);
    return v;
}
 
Example 2
Source File: ActivityControlImpl.java    From FastLib with Apache License 2.0 6 votes vote down vote up
/**
 * 根据程序使用的三方库进行改造:本示例使用的三方库实现了自己的沉浸式状态栏及导航栏但和Demo的滑动返回不搭配故做相应调整
 *
 * @param activity
 */
private void setStatusBarActivity(Activity activity) {
    if (PictureBaseActivity.class.isAssignableFrom(activity.getClass())) {
        View contentView = FastUtil.getRootView(activity);
        //该属性会影响适配滑动返回效果
        contentView.setFitsSystemWindows(false);
        ImageView imageView = contentView != null ? contentView.findViewById(R.id.picture_left_back) : null;
        if (imageView != null) {
            RelativeLayout layout = contentView.findViewById(R.id.rl_picture_title);
            if (layout != null) {
                ViewCompat.setElevation(layout, activity.getResources().getDimension(R.dimen.dp_elevation));
            }
            //调整返回箭头大小
            imageView.setPadding(SizeUtil.dp2px(15), SizeUtil.dp2px(4), SizeUtil.dp2px(4), SizeUtil.dp2px(4));
        }
    }
}
 
Example 3
Source File: FragQiblaTime.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle bdl) {
    View v = inflater.inflate(R.layout.compass_qiblatime, container, false);
    mQiblaTimeView = v.findViewById(R.id.qiblatime);
    
    mQiblaAngle = v.findViewById(R.id.angle);
    mQiblaDistance = v.findViewById(R.id.distance);
    
    View info = (View) mQiblaAngle.getParent();
    ViewCompat.setElevation(info, info.getPaddingTop());
    
    
    setQiblaAngle(mAngle);
    setQiblaDistance(mDistance);
    setUserLocation(mLat,mLng,mAlt);
    return v;
}
 
Example 4
Source File: RecyclerViewFragment.java    From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onDestroy() {
    super.onDestroy();
    mItems.clear();
    mRecyclerViewAdapter = null;
    setAppBarLayoutAlpha(255);
    if (mAppBarLayout != null && !isForeground()) {
        mAppBarLayout.setTranslationY(0);
        ViewCompat.setElevation(mAppBarLayout, 0);
    }
    if (mLoader != null) {
        mLoader.cancel(true);
        mLoader = null;
    }
    if (mReloader != null) {
        mReloader.cancel(true);
        mReloader = null;
    }
    if (mDialogLoader != null) {
        mDialogLoader.cancel(true);
        mDialogLoader = null;
    }
    for (RecyclerViewItem item : mItems) {
        item.onDestroy();
    }
}
 
Example 5
Source File: TabBar.java    From AndroidNavigation with MIT License 6 votes vote down vote up
private void init(Context context) {
    selectedItemColor = AppUtils.fetchContextColor(context, R.attr.colorAccent);
    unselectedItemColor = Color.LTGRAY;
    barBackgroundColor = Color.WHITE;
    badgeColor = Color.parseColor("#FF3B30");

    setLayoutParams(new ViewGroup.LayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)));
    LayoutInflater inflater = LayoutInflater.from(getContext());
    View parentView = inflater.inflate(R.layout.nav_tab_bar_container, this, true);
    container = parentView.findViewById(R.id.nav_tab_bar_container);
    tabContainer = parentView.findViewById(R.id.nav_tab_bar_item_container);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        this.setOutlineProvider(ViewOutlineProvider.BOUNDS);
    }

    ViewCompat.setElevation(this, 0);
    setClipToPadding(false);
}
 
Example 6
Source File: FragQiblaTime.java    From prayer-times-android with Apache License 2.0 6 votes vote down vote up
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle bdl) {
    View v = inflater.inflate(R.layout.compass_qiblatime, container, false);
    mQiblaTimeView = v.findViewById(R.id.qiblatime);
    
    mQiblaAngle = v.findViewById(R.id.angle);
    mQiblaDistance = v.findViewById(R.id.distance);
    
    View info = (View) mQiblaAngle.getParent();
    ViewCompat.setElevation(info, info.getPaddingTop());
    
    
    setQiblaAngle(mAngle);
    setQiblaDistance(mDistance);
    setUserLocation(mLat,mLng,mAlt);
    return v;
}
 
Example 7
Source File: ItemTouchUIUtilImpl.java    From Carbon with Apache License 2.0 6 votes vote down vote up
@Override
public void onDraw(Canvas c, RecyclerView recyclerView, View view,
                   float dX, float dY, int actionState, boolean isCurrentlyActive) {
    if (isCurrentlyActive) {
        Object originalElevation = view.getTag(R.id.item_touch_helper_previous_elevation);
        if (originalElevation == null) {
            originalElevation = view instanceof ShadowView ? ((ShadowView) view).getElevation() : ViewCompat.getElevation(view);
            float newElevation = 1f + findMaxElevation(recyclerView, view);
            if (view instanceof ShadowView) {
                ((ShadowView) view).setElevation(newElevation);
            } else {
                ViewCompat.setElevation(view, newElevation);
            }
            view.setTag(R.id.item_touch_helper_previous_elevation, originalElevation);
        }
    }
    super.onDraw(c, recyclerView, view, dX, dY, actionState, isCurrentlyActive);
}
 
Example 8
Source File: SelectableAdapter.java    From FlexibleAdapter with Apache License 2.0 6 votes vote down vote up
@Override
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position, @NonNull List payloads) {
    // Bind the correct view elevation
    if (holder instanceof FlexibleViewHolder) {
        FlexibleViewHolder flexHolder = (FlexibleViewHolder) holder;
        flexHolder.getContentView().setActivated(isSelected(position));
        if (flexHolder.getContentView().isActivated() && flexHolder.getActivationElevation() > 0) {
            ViewCompat.setElevation(flexHolder.getContentView(), flexHolder.getActivationElevation());
        } else if (flexHolder.getActivationElevation() > 0) { // Leave unaltered the default elevation
            ViewCompat.setElevation(flexHolder.getContentView(), 0);
        }
        if (flexHolder.isRecyclable()) {
            mBoundViewHolders.add(flexHolder);
            log.v("onViewBound    viewSize=%s %s %s", mBoundViewHolders.size(), getClassName(holder), holder);
        } else {
            log.v("onViewBound    recyclable=%s %s %s", holder.isRecyclable(), getClassName(holder), holder);
        }
    } else {
        // When user scrolls, this line binds the correct selection status
        holder.itemView.setActivated(isSelected(position));
    }
}
 
Example 9
Source File: AppImpl.java    From FastLib with Apache License 2.0 5 votes vote down vote up
/**
 * 控制全局TitleBarView
 *
 * @param titleBar
 * @return
 */
@Override
public boolean createTitleBarViewControl(TitleBarView titleBar, Class<?> cls) {
    //默认的MD风格返回箭头icon如使用该风格可以不用设置
    Drawable mDrawable = DrawableUtil.setTintDrawable(ContextCompat.getDrawable(mContext, R.drawable.fast_ic_back),
            ContextCompat.getColor(mContext, R.color.colorTitleText));
    //是否支持状态栏白色
    boolean isSupport = StatusBarUtil.isSupportStatusBarFontChange();
    boolean isActivity = Activity.class.isAssignableFrom(cls);
    Activity activity = FastStackUtil.getInstance().getActivity(cls);
    //设置TitleBarView 所有TextView颜色
    titleBar.setStatusBarLightMode(isSupport)
            //不支持黑字的设置白透明
            .setStatusAlpha(isSupport ? 0 : 102)
            .setLeftTextDrawable(isActivity ? mDrawable : null)
            .setDividerHeight(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP ? SizeUtil.dp2px(0.5f) : 0);
    if (activity != null) {
        titleBar.setTitleMainText(activity.getTitle())
                .setOnLeftTextClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        activity.finish();
                    }
                });
    }
    if (activity instanceof WebAppActivity) {
        return false;
    }
    ViewCompat.setElevation(titleBar, mContext.getResources().getDimension(R.dimen.dp_elevation));
    return false;
}
 
Example 10
Source File: DetailFragment.java    From Passbook with Apache License 2.0 5 votes vote down vote up
private void setupToolbar(View rootView, String title) {
    Toolbar toolbar;
    TextView titleView;
    toolbar = rootView.findViewById(R.id.toolbar);
    View close = rootView.findViewById(R.id.close);
    close.setOnClickListener(this);
    View header = rootView.findViewById(R.id.header);
    ImageButton fab = rootView.findViewById(R.id.fab);

    fab.setOnClickListener(this);
    header.setBackgroundColor(mColor);
    titleView = rootView.findViewById(android.R.id.title);
    titleView.setText(title);
    // Elevation to minus 1 so that fab would not be covered on 5.0
    float elevation = getResources().getDimension(R.dimen.fab_small_elevation) - 0.5f;
    ViewCompat.setElevation(header, elevation);
    if(rootView.findViewById(R.id.frame_box)==null) {
        MainActivity ma = (MainActivity) getActivity();
        if (ma != null) {
            ma.setStatusBarColor(mColor, 200, false);
        }
    }
    toolbar.inflateMenu(R.menu.menu_detail);
    toolbar.getMenu().getItem(0).getIcon().setColorFilter(
            C.ThemedColors[C.colorTextNormal], PorterDuff.Mode.SRC_ATOP);
    toolbar.setOnMenuItemClickListener(this);
}
 
Example 11
Source File: MainActivity.java    From nextcloud-notes with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("PrivateResource")
private void updateToolbars(boolean disableSearch) {
    activityBinding.homeToolbar.setVisibility(disableSearch ? VISIBLE : GONE);
    activityBinding.toolbar.setVisibility(disableSearch ? GONE : VISIBLE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activityBinding.appBar.setStateListAnimator(AnimatorInflater.loadStateListAnimator(activityBinding.appBar.getContext(),
                disableSearch ? R.animator.appbar_elevation_off : R.animator.appbar_elevation_on));
    } else {
        ViewCompat.setElevation(activityBinding.appBar, disableSearch ? 0 : getResources().getDimension(R.dimen.design_appbar_elevation));
    }
    if (disableSearch) {
        activityBinding.searchView.setQuery(null, true);
    }
    activityBinding.searchView.setIconified(disableSearch);
}
 
Example 12
Source File: BaseTransientBottomBar.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
protected SnackbarBaseLayout(@NonNull Context context, AttributeSet attrs) {
  super(wrap(context, attrs, 0, 0), attrs);
  // Ensure we are using the correctly themed context rather than the context that was passed
  // in.
  context = getContext();
  TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SnackbarLayout);
  if (a.hasValue(R.styleable.SnackbarLayout_elevation)) {
    ViewCompat.setElevation(
        this, a.getDimensionPixelSize(R.styleable.SnackbarLayout_elevation, 0));
  }
  animationMode = a.getInt(R.styleable.SnackbarLayout_animationMode, ANIMATION_MODE_SLIDE);
  backgroundOverlayColorAlpha =
      a.getFloat(R.styleable.SnackbarLayout_backgroundOverlayColorAlpha, 1);
  setBackgroundTintList(
      MaterialResources.getColorStateList(
          context, a, R.styleable.SnackbarLayout_backgroundTint));
  setBackgroundTintMode(
      ViewUtils.parseTintMode(
          a.getInt(R.styleable.SnackbarLayout_backgroundTintMode, -1), PorterDuff.Mode.SRC_IN));
  actionTextColorAlpha = a.getFloat(R.styleable.SnackbarLayout_actionTextColorAlpha, 1);
  a.recycle();

  setOnTouchListener(consumeAllTouchListener);
  setFocusable(true);

  if (getBackground() == null) {
    ViewCompat.setBackground(this, createThemedBackground());
  }
}
 
Example 13
Source File: ElevationOverlayProviderTest.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Before
public void initOverlayView() {
  overlayView = new View(context);
  ViewGroup overlayViewParent = new FrameLayout(context);
  ViewCompat.setElevation(overlayViewParent, ELEVATION_OVERLAY_VIEW_PARENT);
  overlayViewParent.addView(overlayView);
}
 
Example 14
Source File: ItemTouchUIUtilImpl.java    From monero-wallet-android-app with MIT License 5 votes vote down vote up
@Override
public void clearView(View view) {
    final Object tag = view.getTag(R.id.item_touch_helper_previous_elevation);
    if (tag != null && tag instanceof Float) {
        ViewCompat.setElevation(view, (Float) tag);
    }
    view.setTag(R.id.item_touch_helper_previous_elevation, null);
    super.clearView(view);
}
 
Example 15
Source File: MainActivity.java    From Passbook with Apache License 2.0 4 votes vote down vote up
private void setupToolbar() {
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    float elevation = getResources().getDimension(R.dimen.toolbar_elevation) + 0.5f;
    ViewCompat.setElevation(toolbar, elevation);
}
 
Example 16
Source File: MainActivity.java    From Passbook with Apache License 2.0 4 votes vote down vote up
private void setupToolbar() {
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    float elevation = getResources().getDimension(R.dimen.toolbar_elevation) + 0.5f;
    ViewCompat.setElevation(toolbar, elevation);
}
 
Example 17
Source File: SearchFragment.java    From hipda with GNU General Public License v2.0 4 votes vote down vote up
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_search, container, false);
    mRecyclerView = (XRecyclerView) view.findViewById(R.id.rv_threads);
    mRecyclerView.setHasFixedSize(true);
    mRecyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    mRecyclerView.addItemDecoration(new SimpleDivider(getActivity()));

    mRecyclerView.addOnScrollListener(new OnScrollListener());

    mRecyclerView.setAdapter(mSimpleListAdapter);

    mSearchFilterLayout = (RelativeLayout) view.findViewById(R.id.search_filter_layout);
    ViewCompat.setElevation(mSearchFilterLayout, Utils.dpToPx(4));
    mSearchFilterLayout.setAlpha(0);

    mSpForum = (Spinner) view.findViewById(R.id.sp_forum);
    mSpAdapter = new KeyValueArrayAdapter(getActivity(), R.layout.spinner_row);
    mSpAdapter.setEntryValues(getForumIds());
    mSpAdapter.setEntries(getForumNames());
    mSpForum.setAdapter(mSpAdapter);

    mEtAuthor = (EditText) view.findViewById(R.id.et_author);
    mEtAuthor.setOnEditorActionListener(mSearchEditorActionListener);

    mCbFulltext = (CheckBox) view.findViewById(R.id.cb_fulltext);
    mCbFulltext.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (mSearchView != null) {
                if (isChecked) {
                    mSearchView.setQueryHint("搜索全文");
                } else {
                    mSearchView.setQueryHint("搜索标题");
                }
            }
        }
    });

    RecyclerView rvHistory = (RecyclerView) view.findViewById(R.id.rv_history);
    rvHistory.setHasFixedSize(true);
    rvHistory.setLayoutManager(new LinearLayoutManager(getActivity()));
    rvHistory.setAdapter(mHistoryAdapter);

    mHistoryAdapter.setDatas(mQueries);

    mSwipeLayout = (SwipeRefreshLayout) view.findViewById(R.id.swipe_container);
    mSwipeLayout.setOnRefreshListener(this);
    mSwipeLayout.setColorSchemeColors(ColorHelper.getSwipeColor(getActivity()));
    mSwipeLayout.setProgressBackgroundColorSchemeColor(ColorHelper.getSwipeBackgroundColor(getActivity()));
    mSwipeLayout.setEnabled(false);

    mLoadingView = (ContentLoadingView) view.findViewById(R.id.content_loading);
    mLoadingView.setState(ContentLoadingView.NO_DATA);

    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            //hide then show mSearchFilterLayout, cannot get it's height on first show
            //so I use a fixed value here, tell me if you know a better way
            mSearchFilterLayout.animate()
                    .alpha(0)
                    .setDuration(100)
                    .translationYBy(-300)
                    .setListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            super.onAnimationEnd(animation);
                            mSearchFilterLayout.setVisibility(View.GONE);
                            mSearchFilterAnimating = false;
                            showSearchFilter();
                        }
                    });
        }
    }, 150);
    return view;
}
 
Example 18
Source File: TeiDashboardMobileActivity.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
public void hideTabsAndDisableSwipe() {
    binding.tabLayout.setVisibility(View.GONE);
    binding.teiPager.setUserInputEnabled(false);
    ViewCompat.setElevation(binding.toolbar, 0);
}
 
Example 19
Source File: StyleSetter.java    From PlayerBase with Apache License 2.0 4 votes vote down vote up
@Override
public void setElevationShadow(int backgroundColor, float elevation) {
    mView.setBackgroundColor(backgroundColor);
    ViewCompat.setElevation(mView,elevation);
    mView.invalidate();
}
 
Example 20
Source File: MineFragment.java    From FastLib with Apache License 2.0 4 votes vote down vote up
@Override
public void initView(Bundle savedInstanceState) {
    mImagePickerHelper = new ImagePickerHelper(mContext);
    mIvHead = mStvInfo.getLeftIconIV();
    GlideManager.loadCircleImg("https://avatars0.githubusercontent.com/u/19605922?s=460&v=4", mIvHead);
    LoggerManager.d("imageHeight:" + mIvHead.getLayoutParams().height + ";screenWidth:" + SizeUtil.getScreenWidth());
    SpanTool.getBuilder(mStvInfo.getLeftString())
            .append("https://github.com/AriesHoo")
            .setUnderline()
            .setForegroundColor(Color.BLUE)
            .setBoldItalic()
            .into(mStvInfo.getLeftTextView());
    SpanTool.getBuilder(mStvInfo.getLeftBottomString())
            .append("http://www.jianshu.com/u/a229eee96115")
            .setUnderline()
            .setForegroundColor(Color.BLUE)
            .setBoldItalic()
            .into(mStvInfo.getLeftBottomTextView());

    mStvInfo.setLeftTvClickListener(() -> WebViewActivity.start(mContext, "https://github.com/AriesHoo"));
    mStvInfo.setLeftBottomTvClickListener(() -> WebViewActivity.start(mContext, "http://www.jianshu.com/u/a229eee96115"));
    mStvInfo.getLeftBottomTextView().setGravity(Gravity.LEFT);
    ViewCompat.setElevation(mStvInfo, getResources().
            getDimension(R.dimen.dp_elevation));
    ViewCompat.setTranslationZ(mStvInfo, 3f);
    if (!App.isSupportElevation()) {
        mStvInfo.setShapeStrokeWidth(getResources().getDimensionPixelSize(R.dimen.dp_line_size))
                .setShapeStrokeColor(ContextCompat.getColor(mContext, R.color.colorLineGray))
                .useShape();
    }

    mIvHead.setOnClickListener(v -> mImagePickerHelper.selectPicture(1000, (requestCode, list) -> {
        if (list == null || list.size() == 0 || requestCode != 1000) {
            return;
        }
        GlideManager.loadCircleImg(list.get(0), mIvHead);
    }));

    mStvUpdate.setRightString("当前版本:V" + FastUtil.getVersionName(mContext));
    //根据屏幕宽度重新调整背景图
    int heightCover = SizeUtil.getScreenWidth() * 1 / 2;
    ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) mTvCover.getLayoutParams();
    if (params != null) {
        params.height = heightCover;
    }
    ViewGroup.MarginLayoutParams margin = (ViewGroup.MarginLayoutParams) mStvInfo.getLayoutParams();
    if (margin != null) {
        margin.topMargin = heightCover - SizeUtil.dp2px(20);
    }
    mTitleBarViewHelper = new TitleBarViewHelper(mContext)
            .setTitleBarView(mTitleBar)
            .setOverScrollView(mSvContainer)
            .setShowTextEnable(true)
            .setMaxHeight(heightCover)
            .setOnScrollListener(new TitleBarViewHelper.OnScrollListener() {
                @Override
                public void onScrollChange(int alpha, boolean isLightMode) {
                    mIsLight = isLightMode;
                }
            });
    LoggerManager.i("initView_getParent:" + mContentView.getParent() + ";rootView:" + mContentView.getRootView());
}