Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
# Conflicts:
#	README.md
#	build.gradle
  • Loading branch information
razerdp committed Nov 6, 2020
2 parents 17bfdef + c62f5df commit fdd7e3e
Show file tree
Hide file tree
Showing 15 changed files with 769 additions and 65 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package razerdp.demo.model.common;

import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.TranslateAnimation;

import razerdp.basepopup.BasePopupFlag;
import razerdp.demo.model.DemoCommonUsageInfo;
import razerdp.demo.popup.DemoPopup;
import razerdp.demo.popup.options.PopupBarControllerOption;
import razerdp.util.animation.AnimationHelper;
import razerdp.util.animation.ScaleConfig;

/**
* Created by 大灯泡 on 2020/10/30.
*/
public class CommonBarControllerInfo extends DemoCommonUsageInfo {
public int gravity = Gravity.CENTER;
public boolean matchHorizontal = false;
public boolean matchVertical = false;
public boolean overlayStatusbar = true;
public boolean overlayNavigationBar = true;
public int overlayStatusbarMode = BasePopupFlag.OVERLAY_MASK | BasePopupFlag.OVERLAY_CONTENT;
public int overlayNavigationBarMode = BasePopupFlag.OVERLAY_MASK;

DemoPopup mDemoPopup;
PopupBarControllerOption option;

public CommonBarControllerInfo() {
title = "控制系统Bar覆盖";
}

@Override
public void toShow(View v) {
if (mDemoPopup == null) {
mDemoPopup = new DemoPopup(v.getContext());
}
mDemoPopup.setWidth(matchHorizontal ? ViewGroup.LayoutParams.MATCH_PARENT : 0);
mDemoPopup.setHeight(matchVertical ? ViewGroup.LayoutParams.MATCH_PARENT : 0);
mDemoPopup.setOverlayStatusbar(overlayStatusbar);
mDemoPopup.setOverlayNavigationBar(overlayNavigationBar);
mDemoPopup.setOverlayStatusbarMode(overlayStatusbarMode);
mDemoPopup.setOverlayNavigationBarMode(overlayNavigationBarMode);
mDemoPopup.setPopupGravity(gravity);
Animation showAnimation = AnimationHelper.asAnimation()
.withScale(ScaleConfig.CENTER)
.toShow();
Animation dismissAnimation = AnimationHelper.asAnimation()
.withScale(ScaleConfig.CENTER)
.toDismiss();
float fromX = 0;
float fromY = 0;
float toX = 0;
float toY = 0;

switch (gravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
case Gravity.LEFT:
fromX = -1f;
break;
case Gravity.RIGHT:
fromX = 1f;
break;
}

switch (gravity & Gravity.VERTICAL_GRAVITY_MASK) {
case Gravity.TOP:
fromY = -1f;
break;
case Gravity.BOTTOM:
fromY = 1f;
break;
}
if (fromX != 0 || fromY != 0) {
showAnimation = createTranslateAnimation(fromX, toX, fromY, toY);
dismissAnimation = createTranslateAnimation(toX, fromX, toY, fromY);
}
mDemoPopup.setShowAnimation(showAnimation);
mDemoPopup.setDismissAnimation(dismissAnimation);
mDemoPopup.showPopupWindow();
}

@Override
public void toOption(View v) {
if (option == null) {
option = new PopupBarControllerOption(v.getContext());
option.setInfo(this);
}
option.showPopupWindow();
}


private Animation createTranslateAnimation(float fromX, float toX, float fromY, float toY) {
Animation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF,
fromX,
Animation.RELATIVE_TO_SELF,
toX,
Animation.RELATIVE_TO_SELF,
fromY,
Animation.RELATIVE_TO_SELF,
toY);
animation.setDuration(500);
animation.setInterpolator(new DecelerateInterpolator());
return animation;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
package razerdp.demo.popup.options;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.animation.Animation;
import android.widget.CompoundButton;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatCheckBox;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;
import razerdp.basepopup.BasePopupFlag;
import razerdp.basepopup.R;
import razerdp.demo.base.baseadapter.BaseSimpleRecyclerViewHolder;
import razerdp.demo.base.baseadapter.OnItemClickListener;
import razerdp.demo.base.baseadapter.SimpleRecyclerViewAdapter;
import razerdp.demo.model.common.CommonBarControllerInfo;
import razerdp.demo.utils.ButterKnifeUtil;
import razerdp.demo.utils.UIHelper;
import razerdp.demo.widget.DPTextView;
import razerdp.demo.widget.decoration.GridItemDecoration;
import razerdp.demo.widget.decoration.SpaceOption;
import razerdp.util.animation.AnimationHelper;
import razerdp.util.animation.TranslationConfig;

/**
* Created by 大灯泡 on 2019/9/20
* <p>
* Description:Bar控制相关的配置
*/
public class PopupBarControllerOption extends BaseOptionPopup<CommonBarControllerInfo> {

SimpleRecyclerViewAdapter<Info> mAdapter;

@BindView(R.id.rv_content)
RecyclerView rvContent;
@BindView(R.id.tv_go)
DPTextView tvGo;
@BindView(R.id.check_overlay_status)
AppCompatCheckBox checkOverlayStatus;
@BindView(R.id.check_status_mask)
AppCompatCheckBox checkStatusMask;
@BindView(R.id.check_status_content)
AppCompatCheckBox checkStatusContent;
@BindView(R.id.check_overlay_nav)
AppCompatCheckBox checkOverlayNav;
@BindView(R.id.check_nav_mask)
AppCompatCheckBox checkNavMask;
@BindView(R.id.check_nav_content)
AppCompatCheckBox checkNavContent;
@BindView(R.id.check_match_horizontal)
AppCompatCheckBox checkMatchHorizontal;
@BindView(R.id.check_match_vertical)
AppCompatCheckBox checkMatchVertical;

public PopupBarControllerOption(Context context) {
super(context);

List<Info> infos = new ArrayList<>();
infos.add(new Info(Gravity.LEFT, "Gravity.Left"));
infos.add(new Info(Gravity.TOP, "Gravity.Top"));
infos.add(new Info(Gravity.RIGHT, "Gravity.RIGHT"));
infos.add(new Info(Gravity.BOTTOM, "Gravity.BOTTOM"));
infos.add(new Info(Gravity.CENTER_VERTICAL, "Gravity.CENTER_VERTICAL"));
infos.add(new Info(Gravity.CENTER_HORIZONTAL, "Gravity.CENTER_HORIZONTAL"));
infos.add(new Info(Gravity.CENTER, "Gravity.CENTER", true));

mAdapter = new SimpleRecyclerViewAdapter<>(context, infos);
mAdapter.setHolder(InnerViewHolder.class);
rvContent.setLayoutManager(new GridLayoutManager(context, 2));
rvContent.addItemDecoration(new GridItemDecoration(new SpaceOption.Builder().size(UIHelper.DP12)
.build()));
rvContent.setItemAnimator(null);
mAdapter.setOnItemClickListener(new OnItemClickListener<Info>() {
@Override
public void onItemClick(View v, int position, Info data) {
data.checked = !data.checked;
mAdapter.notifyItemChanged(position);
}
});
rvContent.setAdapter(mAdapter);
}

@Override
public View onCreateContentView() {
return createPopupById(R.layout.popup_option_control_bar);
}

@Override
protected Animation onCreateShowAnimation() {
return AnimationHelper.asAnimation()
.withTranslation(TranslationConfig.FROM_BOTTOM)
.toShow();
}

@Override
protected Animation onCreateDismissAnimation() {
return AnimationHelper.asAnimation()
.withTranslation(TranslationConfig.TO_BOTTOM)
.toDismiss();
}

@OnClick(R.id.tv_go)
void apply() {
int gravity = Gravity.NO_GRAVITY;
for (Info data : mAdapter.getDatas()) {
if (data.checked) {
gravity |= data.gravity;
}
}
mInfo.gravity = gravity;
mInfo.matchHorizontal = checkMatchHorizontal.isChecked();
mInfo.matchVertical = checkMatchVertical.isChecked();
mInfo.overlayStatusbar = checkOverlayStatus.isChecked();
mInfo.overlayNavigationBar = checkOverlayNav.isChecked();

int mode = 0;
if (checkStatusMask.isChecked()) {
mode |= BasePopupFlag.OVERLAY_MASK;
}
if (checkStatusContent.isChecked()) {
mode |= BasePopupFlag.OVERLAY_CONTENT;
}
mInfo.overlayStatusbarMode = mode;
mode = 0;
if (checkNavMask.isChecked()) {
mode |= BasePopupFlag.OVERLAY_MASK;
}
if (checkNavContent.isChecked()) {
mode |= BasePopupFlag.OVERLAY_CONTENT;
}
mInfo.overlayNavigationBarMode = mode;
dismiss();
}

static class InnerViewHolder extends BaseSimpleRecyclerViewHolder<Info> {
@BindView(R.id.check_box)
AppCompatCheckBox checkBox;

public InnerViewHolder(@NonNull View itemView) {
super(itemView);
ButterKnifeUtil.bind(this, itemView);
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
getData().checked = isChecked;
}
});
}

@Override
public int inflateLayoutResourceId() {
return R.layout.item_slide_option;
}

@Override
public void onBindData(Info data, int position) {
checkBox.setChecked(data.checked);
checkBox.setText(data.name);
}
}

static class Info {
int gravity;
String name;
boolean checked;

public Info(int gravity, String name) {
this(gravity, name, false);
}

public Info(int gravity, String name, boolean checked) {
this.gravity = gravity;
this.name = name;
this.checked = checked;
}
}
}
2 changes: 2 additions & 0 deletions app/src/main/java/razerdp/demo/ui/CommonUsageActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import razerdp.demo.model.common.CommonArrowInfo;
import razerdp.demo.model.common.CommonBackgroundAlignInfo;
import razerdp.demo.model.common.CommonBackgroundInfo;
import razerdp.demo.model.common.CommonBarControllerInfo;
import razerdp.demo.model.common.CommonBlurInfo;
import razerdp.demo.model.common.CommonBottomSheetDialogInfo;
import razerdp.demo.model.common.CommonControllerInfo;
Expand Down Expand Up @@ -120,6 +121,7 @@ private List<MultiType> createItem() {
result.add(new CommonArrowInfo());
result.add(new DemoCommonUsageTitle("PopupWindow控制相关"));
result.add(new CommonControllerInfo());
result.add(new CommonBarControllerInfo());
result.add(new DemoCommonUsageTitle("动画相关"));
result.add(new CommonAnimateInfo());
result.add(new DemoCommonUsageTitle("背景相关"));
Expand Down
Loading

0 comments on commit fdd7e3e

Please sign in to comment.