diff --git a/Android/dokit/build.gradle b/Android/dokit/build.gradle index d7855d529..40d3fff8d 100644 --- a/Android/dokit/build.gradle +++ b/Android/dokit/build.gradle @@ -82,7 +82,7 @@ dependencies { implementation rootProject.ext.dependencies["kotlin_v13"] } implementation rootProject.ext.dependencies["lifecycle-comm"] - + implementation rootProject.ext.dependencies["material"] implementation rootProject.ext.dependencies["constraintLayout"] implementation rootProject.ext.dependencies["appcompat"] implementation rootProject.ext.dependencies["cardview"] diff --git a/Android/dokit/src/main/java/com/didichuxing/doraemonkit/kit/fileexplorer/SpFragment.java b/Android/dokit/src/main/java/com/didichuxing/doraemonkit/kit/fileexplorer/SpFragment.java index 1870464f1..3222bf8d6 100644 --- a/Android/dokit/src/main/java/com/didichuxing/doraemonkit/kit/fileexplorer/SpFragment.java +++ b/Android/dokit/src/main/java/com/didichuxing/doraemonkit/kit/fileexplorer/SpFragment.java @@ -99,7 +99,7 @@ public void spUpData(SpBean bean) { String key = bean.key; switch (bean.value.getClass().getSimpleName()) { case SpInputType.STRING: - DoKitSPUtil.putString(key, bean.value.toString()); + DoKitSPUtil.putString(spTableName, key,bean.value.toString()); break; case SpInputType.BOOLEAN: DoKitSPUtil.putBoolean(spTableName, key, (Boolean) bean.value); diff --git a/Android/dokit/src/main/java/com/didichuxing/doraemonkit/kit/fileexplorer/SpInputView.java b/Android/dokit/src/main/java/com/didichuxing/doraemonkit/kit/fileexplorer/SpInputView.java index 908d43700..f57154fd7 100644 --- a/Android/dokit/src/main/java/com/didichuxing/doraemonkit/kit/fileexplorer/SpInputView.java +++ b/Android/dokit/src/main/java/com/didichuxing/doraemonkit/kit/fileexplorer/SpInputView.java @@ -2,6 +2,8 @@ import android.content.Context; import androidx.annotation.Nullable; +import androidx.fragment.app.FragmentActivity; + import android.text.InputType; import android.util.AttributeSet; import android.view.LayoutInflater; @@ -13,6 +15,7 @@ import com.didichuxing.doraemonkit.R; import com.didichuxing.doraemonkit.constant.SpInputType; +import com.didichuxing.doraemonkit.util.ActivityUtils; import com.didichuxing.doraemonkit.widget.bottomview.BottomUpWindow; import com.didichuxing.doraemonkit.widget.bottomview.EditSpInputView; @@ -105,8 +108,8 @@ public void refresh() { } private void showInputView(View view, final SpBean spBean, int inputType) { - new BottomUpWindow(getContext()).setContent(new EditSpInputView(getContext(), spBean, inputType)) - .show(view).setOnSubmitListener(new BottomUpWindow.OnSubmitListener() { + BottomUpWindow bottomUpWindow = new BottomUpWindow().setContent(new EditSpInputView(getContext(), spBean, inputType)) + .setOnSubmitListener(new BottomUpWindow.OnSubmitListener() { @Override public void submit(Object object) { spBean.value = object; @@ -120,6 +123,7 @@ public void cancel() { } }); + bottomUpWindow.show(((FragmentActivity)ActivityUtils.getTopActivity()).getSupportFragmentManager(),"BottomUpWindow"); } public interface OnDataChangeListener { diff --git a/Android/dokit/src/main/java/com/didichuxing/doraemonkit/widget/bottomview/BottomUpWindow.java b/Android/dokit/src/main/java/com/didichuxing/doraemonkit/widget/bottomview/BottomUpWindow.java index 1352b62ed..a0a29d024 100644 --- a/Android/dokit/src/main/java/com/didichuxing/doraemonkit/widget/bottomview/BottomUpWindow.java +++ b/Android/dokit/src/main/java/com/didichuxing/doraemonkit/widget/bottomview/BottomUpWindow.java @@ -1,17 +1,19 @@ package com.didichuxing.doraemonkit.widget.bottomview; -import android.content.Context; +import android.app.Dialog; import android.graphics.drawable.ColorDrawable; -import android.view.Gravity; +import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import android.view.animation.Animation; -import android.view.animation.TranslateAnimation; import android.widget.FrameLayout; -import android.widget.PopupWindow; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.fragment.app.FragmentTransaction; import com.didichuxing.doraemonkit.R; +import com.google.android.material.bottomsheet.BottomSheetDialogFragment; /** * 从底部向上弹出的选择器 @@ -19,11 +21,11 @@ * @author vinda * @since 15/5/21 */ -public class BottomUpWindow extends PopupWindow { +public class BottomUpWindow extends BottomSheetDialogFragment { private final String TAG = "BottomUpSelectWindow"; private View thisView; private View tv_submit; - private final View titleViiew; + private View titleViiew; private FrameLayout contentPanel; private AssociationView associationView; @@ -45,29 +47,43 @@ public void onClick(View v) { }; - public BottomUpWindow(Context context) { - super(context); - LayoutInflater layoutInflater = LayoutInflater.from(context); - thisView = layoutInflater.inflate(R.layout.dk_item_layout_bottom_up_select_window, null); + @Nullable + @Override + public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { + thisView = inflater.inflate(R.layout.dk_item_layout_bottom_up_select_window, container,false); + return thisView; + } + + @Override + public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { + super.onViewCreated(view, savedInstanceState); ll_panel = thisView.findViewById(R.id.ll_panel); titleViiew = thisView.findViewById(R.id.tv_title); contentPanel = thisView.findViewById(R.id.content); - this.setContentView(thisView); initView(); - this.setWidth(ViewGroup.LayoutParams.MATCH_PARENT); - this.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT); - this.setFocusable(true); - this.setTouchable(true); - this.setOutsideTouchable(true); + thisView.setFocusable(true); ColorDrawable dw = new ColorDrawable(0x80000000); - this.setBackgroundDrawable(dw); + thisView.setBackgroundDrawable(dw); + setUpContent(); + } + + private void setUpContent() { + contentPanel.removeAllViews(); + contentPanel.addView(associationView.getView()); + associationView.setOnStateChangeListener(new AssociationView.OnStateChangeListener() { + @Override + public void onStateChanged() { + tv_submit.setEnabled(associationView.isCanSubmit()); + } + }); } + private void initView() { tv_submit = thisView.findViewById(R.id.tv_submit); tv_submit.setOnClickListener(onClickListener); @@ -89,58 +105,24 @@ public void onClick(View v) { */ public BottomUpWindow setContent(AssociationView view) { associationView = view; - contentPanel.removeAllViews(); - contentPanel.addView(associationView.getView()); - associationView.setOnStateChangeListener(new AssociationView.OnStateChangeListener() { - @Override - public void onStateChanged() { - tv_submit.setEnabled(associationView.isCanSubmit()); - } - }); return this; } @Override public void dismiss() { - //动画 - TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, - Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 1); - animation.setDuration(200); - animation.setAnimationListener(new Animation.AnimationListener() { - @Override - public void onAnimationStart(Animation animation) { - - } - - @Override - public void onAnimationEnd(Animation animation) { - ll_panel.setVisibility(View.GONE); - dismissWindow(); - } - - @Override - public void onAnimationRepeat(Animation animation) { - - } - }); - ll_panel.startAnimation(animation); if (associationView != null) { associationView.onHide(); } + super.dismiss(); } - /** - * 隐藏整个窗口 - */ - private void dismissWindow() { - try { - super.dismiss(); - } catch (Throwable e) { - } - } + private void cancel() { - associationView.cancel(); + if (associationView!=null) { + associationView.cancel(); + } + dismiss(); if (mOnSubmitListener != null) { @@ -148,25 +130,21 @@ private void cancel() { } } - public BottomUpWindow show(View parent) { - this.showAtLocation(parent, Gravity.BOTTOM - | Gravity.CENTER_HORIZONTAL, 0, 0); - ll_panel.setVisibility(View.VISIBLE); - //动画 - TranslateAnimation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, - Animation.RELATIVE_TO_SELF, 1, Animation.RELATIVE_TO_SELF, 0); - animation.setDuration(200); - ll_panel.startAnimation(animation); + @Override + public int show(@NonNull FragmentTransaction transaction, @Nullable String tag) { if (associationView != null) { associationView.onShow(); } - return this; + return super.show(transaction, tag); + } + private OnSubmitListener mOnSubmitListener; - public void setOnSubmitListener(OnSubmitListener onSubmitListener) { + public BottomUpWindow setOnSubmitListener(OnSubmitListener onSubmitListener) { this.mOnSubmitListener = onSubmitListener; + return this; } public interface OnSubmitListener { diff --git a/Android/dokit/src/main/res/layout/dk_item_layout_bottom_up_select_window.xml b/Android/dokit/src/main/res/layout/dk_item_layout_bottom_up_select_window.xml index 377b7ef17..7870fc02c 100644 --- a/Android/dokit/src/main/res/layout/dk_item_layout_bottom_up_select_window.xml +++ b/Android/dokit/src/main/res/layout/dk_item_layout_bottom_up_select_window.xml @@ -9,7 +9,6 @@ android:id="@+id/ll_panel" android:layout_width="fill_parent" android:layout_height="wrap_content" - android:layout_alignParentBottom="true" android:background="@color/foreground_wtf" android:clickable="true" android:gravity="center_horizontal" @@ -63,4 +62,4 @@ - \ No newline at end of file + diff --git a/Android/dokit/src/main/res/layout/dk_item_text_content.xml b/Android/dokit/src/main/res/layout/dk_item_text_content.xml index f9cb0d7d6..e46455bf2 100644 --- a/Android/dokit/src/main/res/layout/dk_item_text_content.xml +++ b/Android/dokit/src/main/res/layout/dk_item_text_content.xml @@ -7,7 +7,8 @@ style="@style/DK.Text.Darker" android:id="@+id/text" android:gravity="left" + android:textIsSelectable="true" android:layout_width="match_parent" android:layout_height="wrap_content" /> - \ No newline at end of file +