新增礼物墙弹窗主题
This commit is contained in:
@@ -0,0 +1,150 @@
|
||||
package com.yunbao.common.dialog;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Typeface;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.viewpager2.adapter.FragmentStateAdapter;
|
||||
import androidx.viewpager2.widget.ViewPager2;
|
||||
|
||||
import com.lxj.xpopup.XPopup;
|
||||
import com.yunbao.common.R;
|
||||
import com.yunbao.common.fragment.BaseFragment;
|
||||
import com.yunbao.common.fragment.GiftWallMainTab1Fragment;
|
||||
import com.yunbao.common.fragment.GiftWallMainTab2Fragment;
|
||||
import com.yunbao.common.utils.DpUtil;
|
||||
import com.yunbao.common.utils.ScreenDimenUtil;
|
||||
import com.yunbao.common.views.CustomEllipsizeTextView;
|
||||
import com.yunbao.common.views.weight.ViewClicksAntiShake;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 礼物墙
|
||||
*/
|
||||
public class GiftWallDialog extends AbsDialogPopupWindow {
|
||||
|
||||
private ImageView mIvBg;
|
||||
private ImageView mIvTips;
|
||||
private ImageView mIvBack;
|
||||
private CustomEllipsizeTextView mTvUserName;
|
||||
private View mAchievement;
|
||||
private TextView mTvTab1, mTvTab2;
|
||||
private ViewPager2 mViewPager;
|
||||
private LinearLayout mIvTabsLayout;
|
||||
private List<BaseFragment> fragments = new ArrayList<>();
|
||||
|
||||
private boolean isFullWindows;
|
||||
|
||||
public GiftWallDialog(@NonNull Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public GiftWallDialog setFullWindows(boolean fullWindows) {
|
||||
isFullWindows = fullWindows;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildDialog(XPopup.Builder builder) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int bindLayoutId() {
|
||||
return R.layout.dialog_gift_wall;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getPopupHeight() {
|
||||
if (isFullWindows) {
|
||||
return super.getPopupHeight();
|
||||
}
|
||||
int screenHeight = ScreenDimenUtil.getInstance().getScreenHeight();
|
||||
return (int) (screenHeight * 0.8);
|
||||
}
|
||||
|
||||
void initView() {
|
||||
mIvBg = findViewById(R.id.iv_root_bg);
|
||||
mIvTips = findViewById(R.id.v_tips);
|
||||
mIvBack = findViewById(R.id.iv_back);
|
||||
mTvUserName = findViewById(R.id.user_name);
|
||||
mAchievement = findViewById(R.id.v_achievement);
|
||||
mTvTab1 = findViewById(R.id.tab1);
|
||||
mTvTab2 = findViewById(R.id.tab2);
|
||||
mViewPager = findViewById(R.id.viewPager2);
|
||||
mIvTabsLayout = findViewById(R.id.tab_layout);
|
||||
|
||||
fragments.add(new GiftWallMainTab1Fragment());
|
||||
fragments.add(new GiftWallMainTab2Fragment());
|
||||
mViewPager.setAdapter(new FragmentStateAdapter((FragmentActivity) mContext) {
|
||||
@NonNull
|
||||
@Override
|
||||
public Fragment createFragment(int position) {
|
||||
return fragments.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return fragments.size();
|
||||
}
|
||||
});
|
||||
mViewPager.setUserInputEnabled(false);
|
||||
|
||||
|
||||
ViewClicksAntiShake.clicksAntiShake(mTvTab1, () -> {
|
||||
mIvBg.setImageResource(R.mipmap.bg_gift_wall_main_root);
|
||||
mIvTabsLayout.setBackgroundResource(R.mipmap.icon_gift_wall_main_switch_main);
|
||||
mTvTab1.setTextColor(Color.parseColor("#9CE7FF"));
|
||||
mTvTab1.setTextSize(16);
|
||||
mTvTab1.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
|
||||
|
||||
mTvTab2.setTextColor(Color.parseColor("#FFFFFF"));
|
||||
mTvTab2.setTextSize(14);
|
||||
mTvTab2.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
|
||||
mViewPager.setCurrentItem(0,false);
|
||||
});
|
||||
ViewClicksAntiShake.clicksAntiShake(mTvTab2, () -> {
|
||||
|
||||
mIvBg.setImageResource(R.mipmap.bg_gift_wall_main_root2);
|
||||
mIvTabsLayout.setBackgroundResource(R.mipmap.icon_gift_wall_main_switch_full);
|
||||
mTvTab1.setTextColor(Color.parseColor("#FFFFFF"));
|
||||
mTvTab1.setTextSize(14);
|
||||
mTvTab1.setTypeface(Typeface.defaultFromStyle(Typeface.NORMAL));
|
||||
|
||||
mTvTab2.setTextColor(Color.parseColor("#FFC593"));
|
||||
mTvTab2.setTextSize(16);
|
||||
mTvTab2.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
|
||||
mViewPager.setCurrentItem(1,false);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate() {
|
||||
super.onCreate();
|
||||
initView();
|
||||
ConstraintLayout.LayoutParams params = (ConstraintLayout.LayoutParams) mIvBack.getLayoutParams();
|
||||
if (isFullWindows) {
|
||||
params.width=DpUtil.dp2px(20);
|
||||
mIvBack.setVisibility(View.VISIBLE);
|
||||
mIvBg.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
} else {
|
||||
params.width=DpUtil.dp2px(1);
|
||||
mIvBack.setVisibility(View.INVISIBLE);
|
||||
mIvBg.setScaleType(ImageView.ScaleType.FIT_XY);
|
||||
}
|
||||
mIvBack.setLayoutParams(params);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.yunbao.common.fragment;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class GiftWallMainTab1Fragment extends BaseFragment {
|
||||
@Override
|
||||
public View createView(LayoutInflater inflater, ViewGroup container) {
|
||||
TextView textView = new TextView(getActivity());
|
||||
textView.setText("第一页");
|
||||
textView.setTextColor(Color.WHITE);
|
||||
textView.setTextSize(24);
|
||||
return textView;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initVariables(Bundle bundle) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initViews(Bundle savedInstanceState, View contentView) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadData() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package com.yunbao.common.fragment;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class GiftWallMainTab2Fragment extends BaseFragment {
|
||||
@Override
|
||||
public View createView(LayoutInflater inflater, ViewGroup container) {
|
||||
TextView textView = new TextView(getActivity());
|
||||
textView.setText("第二页");
|
||||
textView.setTextColor(Color.WHITE);
|
||||
textView.setTextSize(24);
|
||||
return textView;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initVariables(Bundle bundle) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void initViews(Bundle savedInstanceState, View contentView) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void loadData() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.yunbao.common.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.text.Layout;
|
||||
import android.text.TextPaint;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
|
||||
import androidx.appcompat.widget.AppCompatTextView;
|
||||
|
||||
public class CustomEllipsizeTextView extends AppCompatTextView {
|
||||
|
||||
public CustomEllipsizeTextView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public CustomEllipsizeTextView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public CustomEllipsizeTextView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
super.onDraw(canvas);
|
||||
CharSequence text = getText();
|
||||
float measureText = getPaint().measureText(text, 0, text.length());
|
||||
if (measureText > getMeasuredWidth() && text.length() > 5) {
|
||||
CharSequence end = text.subSequence(text.length() - 5, text.length());
|
||||
CharSequence start = text.subSequence(0, text.length() - 5);
|
||||
CharSequence newCharSequence = getAutoText(start, end, getPaint());
|
||||
setText(newCharSequence);
|
||||
}
|
||||
}
|
||||
|
||||
private CharSequence getAutoText(CharSequence start, CharSequence end, TextPaint paint) {
|
||||
CharSequence text = TextUtils.concat(start.subSequence(0, start.length() - 1), "...", end);
|
||||
if (paint.measureText(text, 0, text.length()) > getMeasuredWidth()) {
|
||||
return getAutoText(start.subSequence(0, start.length() - 1), end, paint);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user