From 807076b3a4e127e6d6681f36c704f865babd497a Mon Sep 17 00:00:00 2001 From: xuexiangjys Date: Thu, 23 Sep 2021 01:23:12 +0800 Subject: [PATCH 01/19] =?UTF-8?q?=E5=88=87=E5=88=86=E5=87=BA1.1.9=E5=88=86?= =?UTF-8?q?=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/build.gradle | 8 +-- .../res/layout/fragment_material_edittext.xml | 2 + .../xuexiang/xui/utils/StatusBarUtils.java | 68 ++++--------------- .../java/com/xuexiang/xui/utils/Utils.java | 14 ++++ .../widget/banner/recycler/BannerLayout.java | 2 +- 5 files changed, 35 insertions(+), 59 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 568bcca4..f39ea393 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -14,8 +14,8 @@ android { applicationId "com.xuexiang.xuidemo" minSdkVersion 17 targetSdkVersion build_versions.target_sdk - versionCode 19 - versionName "1.1.8" + versionCode 20 + versionName "1.1.9" multiDexEnabled true vectorDrawables.useSupportLibrary = true @@ -103,8 +103,8 @@ dependencies { implementation 'com.github.bumptech.glide:glide:4.12.0' //XUI框架 -// implementation project(':xui_lib') - implementation 'com.github.xuexiangjys:XUI:1.1.8' + implementation project(':xui_lib') +// implementation 'com.github.xuexiangjys:XUI:1.1.8' // implementation 'com.qmuiteam:qmui:1.2.0' //工具类 diff --git a/app/src/main/res/layout/fragment_material_edittext.xml b/app/src/main/res/layout/fragment_material_edittext.xml index 3d277598..4da96070 100755 --- a/app/src/main/res/layout/fragment_material_edittext.xml +++ b/app/src/main/res/layout/fragment_material_edittext.xml @@ -107,7 +107,9 @@ = KITKAT) { if (isMIUICustomStatusBarLightModeImpl() && MIUISetStatusBarLightMode(activity.getWindow(), true)) { - mStatuBarType = STATUSBAR_TYPE_MIUI; + mStatusBarType = STATUSBAR_TYPE_MIUI; return true; } else if (FlymeSetStatusBarLightMode(activity.getWindow(), true)) { - mStatuBarType = STATUSBAR_TYPE_FLYME; + mStatusBarType = STATUSBAR_TYPE_FLYME; return true; } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { Android6SetStatusBarLightMode(activity.getWindow(), true); - mStatuBarType = STATUSBAR_TYPE_ANDROID6; + mStatusBarType = STATUSBAR_TYPE_ANDROID6; return true; } } @@ -253,16 +253,16 @@ public static boolean setStatusBarDarkMode(Activity activity) { if (activity == null) { return false; } - if (mStatuBarType == STATUSBAR_TYPE_DEFAULT) { + if (mStatusBarType == STATUSBAR_TYPE_DEFAULT) { // 默认状态,不需要处理 return true; } - if (mStatuBarType == STATUSBAR_TYPE_MIUI) { + if (mStatusBarType == STATUSBAR_TYPE_MIUI) { return MIUISetStatusBarLightMode(activity.getWindow(), false); - } else if (mStatuBarType == STATUSBAR_TYPE_FLYME) { + } else if (mStatusBarType == STATUSBAR_TYPE_FLYME) { return FlymeSetStatusBarLightMode(activity.getWindow(), false); - } else if (mStatuBarType == STATUSBAR_TYPE_ANDROID6) { + } else if (mStatusBarType == STATUSBAR_TYPE_ANDROID6) { return Android6SetStatusBarLightMode(activity.getWindow(), false); } return true; @@ -450,57 +450,17 @@ public static boolean supportTransclentStatusBar6() { /** * 获取状态栏的高度。 + * + * @param context 上下文 + * @return 状态栏高度 */ public static int getStatusBarHeight(Context context) { if (sStatusbarHeight == -1) { - initStatusBarHeight(context); + sStatusbarHeight = Utils.getStatusBarHeight(context); } return sStatusbarHeight; } - private static void initStatusBarHeight(Context context) { - Class clazz; - Object obj = null; - Field field = null; - try { - clazz = Class.forName("com.android.internal.R$dimen"); - obj = clazz.newInstance(); - if (DeviceUtils.isMeizu()) { - try { - field = clazz.getField("status_bar_height_large"); - } catch (Throwable t) { - t.printStackTrace(); - } - } - if (field == null) { - field = clazz.getField("status_bar_height"); - } - } catch (Throwable t) { - t.printStackTrace(); - } - if (field != null && obj != null) { - try { - int id = Integer.parseInt(field.get(obj).toString()); - sStatusbarHeight = context.getResources().getDimensionPixelSize(id); - } catch (Throwable t) { - t.printStackTrace(); - } - } - if (DeviceUtils.isTablet(context) - && sStatusbarHeight > DensityUtils.dp2px(context, STATUS_BAR_DEFAULT_HEIGHT_DP)) { - //状态栏高度大于25dp的平板,状态栏通常在下方 - sStatusbarHeight = 0; - } else { - if (sStatusbarHeight <= 0) { - if (sVirtualDensity == -1) { - sStatusbarHeight = DensityUtils.dp2px(context, STATUS_BAR_DEFAULT_HEIGHT_DP); - } else { - sStatusbarHeight = (int) (STATUS_BAR_DEFAULT_HEIGHT_DP * sVirtualDensity + 0.5f); - } - } - } - } - public static void setVirtualDensity(float density) { sVirtualDensity = density; } diff --git a/xui_lib/src/main/java/com/xuexiang/xui/utils/Utils.java b/xui_lib/src/main/java/com/xuexiang/xui/utils/Utils.java index 3fe908d5..763d7aa8 100644 --- a/xui_lib/src/main/java/com/xuexiang/xui/utils/Utils.java +++ b/xui_lib/src/main/java/com/xuexiang/xui/utils/Utils.java @@ -80,6 +80,20 @@ public static int getScreenHeight(Context context) { private static final String STATUS_BAR_HEIGHT_RES_NAME = "status_bar_height"; + /** + * 计算状态栏高度 getStatusBarHeight + * + * @param context 上下文 + * @return 状态栏高度 + */ + public static int getStatusBarHeight(Context context) { + if (context == null) { + return getStatusBarHeight(); + } + return getInternalDimensionSize(context.getResources(), + STATUS_BAR_HEIGHT_RES_NAME); + } + /** * 计算状态栏高度 getStatusBarHeight * diff --git a/xui_lib/src/main/java/com/xuexiang/xui/widget/banner/recycler/BannerLayout.java b/xui_lib/src/main/java/com/xuexiang/xui/widget/banner/recycler/BannerLayout.java index 7d790990..117aebca 100644 --- a/xui_lib/src/main/java/com/xuexiang/xui/widget/banner/recycler/BannerLayout.java +++ b/xui_lib/src/main/java/com/xuexiang/xui/widget/banner/recycler/BannerLayout.java @@ -78,7 +78,7 @@ public class BannerLayout extends FrameLayout { protected Handler mHandler = new Handler(new Handler.Callback() { @Override - public boolean handleMessage(Message msg) { + public boolean handleMessage(@NonNull Message msg) { if (msg.what == WHAT_AUTO_PLAY) { if (mCurrentIndex == mLayoutManager.getCurrentPosition()) { ++mCurrentIndex; From bd41406c00140098585145f56487b76d770d8f4c Mon Sep 17 00:00:00 2001 From: xuexiangjys Date: Fri, 24 Sep 2021 02:18:09 +0800 Subject: [PATCH 02/19] =?UTF-8?q?VerifyCodeEditText=E6=96=B0=E5=A2=9Evcet?= =?UTF-8?q?=5Fis=5Fdivide=5Fequally=E5=B1=9E=E6=80=A7=EF=BC=8C=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E5=B9=B3=E5=88=86=E8=BE=93=E5=85=A5=E6=A1=86=E7=9A=84?= =?UTF-8?q?=E5=AE=BD=E5=BA=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../edittext/VerifyCodeEditTextFragment.java | 4 + .../res/layout/fragment_arcloadingview.xml | 4 +- .../main/res/layout/fragment_city_picker.xml | 4 +- .../res/layout/fragment_custom_edittext.xml | 5 +- .../layout/fragment_determinatecircular.xml | 14 +- .../res/layout/fragment_flexbox_layout.xml | 5 +- .../res/layout/fragment_flowtaglayout.xml | 26 ++- .../layout/fragment_guidecase_view_style.xml | 4 +- .../layout/fragment_material_progress_bar.xml | 4 +- .../res/layout/fragment_popupwindow_style.xml | 4 +- .../res/layout/fragment_qrcode_produce.xml | 4 +- .../res/layout/fragment_radius_imageview.xml | 4 +- .../main/res/layout/fragment_ruler_view.xml | 58 ++++--- .../main/res/layout/fragment_shadowbutton.xml | 5 +- .../layout/fragment_super_picture_loading.xml | 5 +- .../res/layout/fragment_util_statusbar.xml | 4 +- .../layout/fragment_verify_code_edittext.xml | 108 +++++++----- .../main/res/layout/fragment_xui_popup.xml | 4 +- .../com/xuexiang/xui/utils/DensityUtils.java | 24 +++ .../edittext/verify/VerifyCodeEditText.java | 158 ++++++++++++++---- .../xui/widget/spinner/DropDownMenu.java | 2 +- .../res/layout/xui_layout_verify_code.xml | 6 +- xui_lib/src/main/res/values/xui_attrs.xml | 2 + 23 files changed, 281 insertions(+), 177 deletions(-) diff --git a/app/src/main/java/com/xuexiang/xuidemo/fragment/components/edittext/VerifyCodeEditTextFragment.java b/app/src/main/java/com/xuexiang/xuidemo/fragment/components/edittext/VerifyCodeEditTextFragment.java index a0706d65..ead0d5a1 100644 --- a/app/src/main/java/com/xuexiang/xuidemo/fragment/components/edittext/VerifyCodeEditTextFragment.java +++ b/app/src/main/java/com/xuexiang/xuidemo/fragment/components/edittext/VerifyCodeEditTextFragment.java @@ -24,6 +24,8 @@ public class VerifyCodeEditTextFragment extends BaseFragment implements VerifyCo VerifyCodeEditText vcet3; @BindView(R.id.vcet_4) VerifyCodeEditText vcet4; + @BindView(R.id.vcet_5) + VerifyCodeEditText vcet5; @Override protected int getLayoutId() { @@ -41,6 +43,7 @@ protected void initListeners() { vcet2.setOnInputListener(this); vcet3.setOnInputListener(this); vcet4.setOnInputListener(this); + vcet5.setOnInputListener(this); } @Override @@ -64,5 +67,6 @@ public void onViewClicked() { vcet2.clearInputValue(); vcet3.clearInputValue(); vcet4.clearInputValue(); + vcet5.clearInputValue(); } } diff --git a/app/src/main/res/layout/fragment_arcloadingview.xml b/app/src/main/res/layout/fragment_arcloadingview.xml index eaf606e9..dbdfcce0 100644 --- a/app/src/main/res/layout/fragment_arcloadingview.xml +++ b/app/src/main/res/layout/fragment_arcloadingview.xml @@ -5,9 +5,7 @@ android:layout_height="match_parent" android:orientation="vertical"> - + - + - + - + + android:paddingBottom="?attr/xui_config_content_spacing_horizontal"> @@ -102,8 +100,8 @@ @@ -143,8 +141,8 @@ diff --git a/app/src/main/res/layout/fragment_flexbox_layout.xml b/app/src/main/res/layout/fragment_flexbox_layout.xml index cb653394..af0c4fe1 100644 --- a/app/src/main/res/layout/fragment_flexbox_layout.xml +++ b/app/src/main/res/layout/fragment_flexbox_layout.xml @@ -20,10 +20,7 @@ android:layout_height="match_parent" android:orientation="vertical"> - + - - + + android:layout_height="wrap_content" /> + android:layout_height="wrap_content" /> + app:ftl_single_cancelable="true" /> + app:ftl_selecteds="@array/tags_selects_values" /> + android:text="添加标签" /> + android:text="清除标签" /> @@ -118,7 +114,7 @@ android:layout_width="match_parent" android:layout_height="wrap_content" app:ftl_check_mode="display" - app:ftl_entries="@array/tags_values"/> + app:ftl_entries="@array/tags_values" /> diff --git a/app/src/main/res/layout/fragment_guidecase_view_style.xml b/app/src/main/res/layout/fragment_guidecase_view_style.xml index 80e1c4f2..0ab93dc3 100755 --- a/app/src/main/res/layout/fragment_guidecase_view_style.xml +++ b/app/src/main/res/layout/fragment_guidecase_view_style.xml @@ -4,9 +4,7 @@ android:layout_height="match_parent" android:orientation="vertical"> - + - + - + - + - + - + + android:inputType="numberDecimal" /> + android:layout_marginStart="10dp" + android:text="设值" /> + android:text="取值" /> @@ -58,18 +56,18 @@ android:layout_height="120dp" android:layout_margin="10dp" + app:rv_bgColor="#fcfffc" app:rv_firstScale="50" - app:rv_minScale="0" + app:rv_largeScaleColor="#50b586" app:rv_maxScale="100" - app:rv_scaleCount="10" - app:rv_unit="kg" - - app:rv_bgColor="#fcfffc" - app:rv_smallScaleColor="#aaaaaa" app:rv_midScaleColor="#999999" - app:rv_largeScaleColor="#50b586" + + app:rv_minScale="0" app:rv_resultNumColor="#50b586" + app:rv_scaleCount="10" app:rv_scaleNumColor="#666666" + app:rv_smallScaleColor="#aaaaaa" + app:rv_unit="kg" app:rv_unitColor="#50b586" app:rv_unitTextSize="10sp" /> @@ -83,18 +81,18 @@ android:layout_height="120dp" android:layout_margin="10dp" + app:rv_bgColor="#fcfffc" app:rv_firstScale="175" - app:rv_minScale="50" + app:rv_largeScaleColor="@color/colorAccent" app:rv_maxScale="230" - app:rv_scaleCount="5" - app:rv_unit="cm" - - app:rv_bgColor="#fcfffc" - app:rv_smallScaleColor="@color/colorPrimary" app:rv_midScaleColor="@color/colorPrimaryDark" - app:rv_largeScaleColor="@color/colorAccent" + + app:rv_minScale="50" app:rv_resultNumColor="#50b586" + app:rv_scaleCount="5" app:rv_scaleNumColor="#666666" + app:rv_smallScaleColor="@color/colorPrimary" + app:rv_unit="cm" app:rv_unitColor="#50b586" app:rv_unitTextSize="10sp" /> @@ -108,18 +106,18 @@ android:layout_height="120dp" android:layout_margin="10dp" + app:rv_bgColor="#fcfffc" app:rv_firstScale="1.0" - app:rv_minScale="0" + app:rv_largeScaleColor="#50b586" app:rv_maxScale="6" - app:rv_scaleCount="10" - app:rv_unit=" " - - app:rv_bgColor="#fcfffc" - app:rv_smallScaleColor="#aaaaaa" app:rv_midScaleColor="#999999" - app:rv_largeScaleColor="#50b586" + + app:rv_minScale="0" app:rv_resultNumColor="#50b586" + app:rv_scaleCount="10" app:rv_scaleNumColor="#666666" + app:rv_smallScaleColor="#aaaaaa" + app:rv_unit=" " app:rv_unitColor="#50b586" app:rv_unitTextSize="10sp" /> diff --git a/app/src/main/res/layout/fragment_shadowbutton.xml b/app/src/main/res/layout/fragment_shadowbutton.xml index 4bd501a2..db2ff599 100755 --- a/app/src/main/res/layout/fragment_shadowbutton.xml +++ b/app/src/main/res/layout/fragment_shadowbutton.xml @@ -5,10 +5,7 @@ android:gravity="center_vertical" android:orientation="vertical"> - + - + - + - - - - - - - - - + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_xui_popup.xml b/app/src/main/res/layout/fragment_xui_popup.xml index 95744c40..47b88403 100644 --- a/app/src/main/res/layout/fragment_xui_popup.xml +++ b/app/src/main/res/layout/fragment_xui_popup.xml @@ -4,9 +4,7 @@ android:layout_height="match_parent" android:orientation="vertical"> - + mEtNumber) { + break; + } + setText(strArray[i], true); + } + } + setListener(); + } + + /** + * 初始化控件 + * + * @param context 上下文 + */ + private void initView(Context context) { + initTextViews(context, mEtNumber, mEtWidth, mEtDivider, mEtTextSize, mEtTextColor); initEtContainer(mPwdTextViews); setListener(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { - // 设置当 高为 warpContent 模式时的默认值 为 50dp int heightMeasureSpecValue = heightMeasureSpec; - int heightMode = MeasureSpec.getMode(heightMeasureSpecValue); if (heightMode == MeasureSpec.AT_MOST) { - heightMeasureSpecValue = MeasureSpec.makeMeasureSpec((int) dp2px(50, getContext()), MeasureSpec.EXACTLY); + // 设置当高为 warpContent 模式时的最小高度是50dp + int minHeight = (int) dp2px(DEFAULT_HEIGHT, getContext()); + if (mEtWidth < minHeight) { + heightMeasureSpecValue = MeasureSpec.makeMeasureSpec(minHeight, MeasureSpec.EXACTLY); + } } super.onMeasure(widthMeasureSpec, heightMeasureSpecValue); } @@ -170,12 +231,13 @@ private void initTextViews(Context context, int etNumber, int etWidth, Drawable mLlContainer.setDividerDrawable(etDividerDrawable); } mPwdTextViews = new PwdTextView[etNumber]; - for (int i = 0; i < mPwdTextViews.length; i++) { PwdTextView textView = new PwdTextView(context); textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, etTextSize); textView.setTextColor(etTextColor); - textView.setWidth(etWidth); + if (!mIsDivideEqually) { + textView.setWidth(etWidth); + } textView.setHeight(etWidth); if (i == 0) { textView.setBackgroundDrawable(mBackgroundFocus); @@ -191,11 +253,27 @@ private void initTextViews(Context context, int etNumber, int etWidth, Drawable /** * 初始化存储TextView 的容器 * - * @param mTextViews + * @param textViews 输入文字 */ - private void initEtContainer(TextView[] mTextViews) { - for (TextView mTextView : mTextViews) { - mLlContainer.addView(mTextView); + private void initEtContainer(TextView[] textViews) { + if (mIsDivideEqually) { + FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) mLlContainer.getLayoutParams(); + if (layoutParams == null) { + layoutParams = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); + layoutParams.gravity = Gravity.CENTER; + } else { + layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT; + } + mLlContainer.setLayoutParams(layoutParams); + LinearLayout.LayoutParams childParams = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT); + childParams.weight = 1; + for (TextView textView : textViews) { + mLlContainer.addView(textView, childParams); + } + } else { + for (TextView textView : textViews) { + mLlContainer.addView(textView); + } } } @@ -222,8 +300,13 @@ public boolean onBackspace() { }); } - // 给TextView 设置文字 - private void setText(String inputContent) { + /** + * 设置输入 + * + * @param inputContent 输入内容 + * @param isSilent 是否静默输入 + */ + private void setText(String inputContent, boolean isSilent) { if (TextUtils.isEmpty(inputContent)) { return; } @@ -237,11 +320,11 @@ private void setText(String inputContent) { tv.setBackgroundDrawable(mBackgroundNormal); if (i < mEtNumber - 1) { mPwdTextViews[i + 1].setBackgroundDrawable(mBackgroundFocus); - if (mOnInputListener != null) { + if (mOnInputListener != null && !isSilent) { mOnInputListener.onChange(getInputValue()); } } else if (i == mEtNumber - 1) { - if (mOnInputListener != null) { + if (mOnInputListener != null && !isSilent) { mOnInputListener.onComplete(getInputValue()); } } @@ -318,13 +401,16 @@ public void clearInputValue() { /** * 设置输入框个数 * - * @param etNumber + * @param etNumber 输入框个数 */ public void setEtNumber(int etNumber) { mEtNumber = etNumber; mEditText.removeTextChangedListener(mTextWatcher); mLlContainer.removeAllViews(); - initUI(); + if (mIsDivideEqually) { + refreshEditSizeWhenDivideEqually(); + } + initView(getContext()); } /** @@ -338,9 +424,9 @@ public int getEtNumber() { /** - * 设置是否是密码模式 默认不是 + * 设置是否是密码模式 默认false * - * @param isPwdMode + * @param isPwdMode 是否是密码模式 */ public void setPwdMode(boolean isPwdMode) { this.mIsPwd = isPwdMode; @@ -356,7 +442,9 @@ public EditText getEditText() { return mEditText; } - // 输入完成 和 删除成功 的监听 + /** + * 输入完成 和 删除成功 的监听 + */ private OnInputListener mOnInputListener; public void setOnInputListener(OnInputListener onInputListener) { @@ -370,13 +458,15 @@ public void setOnInputListener(OnInputListener onInputListener) { public interface OnInputListener { /** * 输入完成 + * + * @param input 输入内容 */ void onComplete(String input); /** * 输入变化 * - * @param input + * @param input 变化内容 */ void onChange(String input); @@ -423,7 +513,7 @@ public void afterTextChanged(Editable editable) { if (i > mEtNumber) { break; } - setText(strArray[i]); + setText(strArray[i], false); mEditText.setText(""); } } diff --git a/xui_lib/src/main/java/com/xuexiang/xui/widget/spinner/DropDownMenu.java b/xui_lib/src/main/java/com/xuexiang/xui/widget/spinner/DropDownMenu.java index 7d7b06e1..5b6942db 100644 --- a/xui_lib/src/main/java/com/xuexiang/xui/widget/spinner/DropDownMenu.java +++ b/xui_lib/src/main/java/com/xuexiang/xui/widget/spinner/DropDownMenu.java @@ -249,7 +249,7 @@ public void onClick(View v) { } mPopupMenuViews = new FrameLayout(getContext()); - mPopupMenuViews.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) (DensityUtils.getDisplaySize(getContext(), true).y * mMenuHeightPercent))); + mPopupMenuViews.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, (int) (DensityUtils.getDisplayHeight(getContext(), true) * mMenuHeightPercent))); mPopupMenuViews.setVisibility(GONE); mContainerView.addView(mPopupMenuViews, 2); diff --git a/xui_lib/src/main/res/layout/xui_layout_verify_code.xml b/xui_lib/src/main/res/layout/xui_layout_verify_code.xml index 2eb6bfb0..fdd9e0f5 100644 --- a/xui_lib/src/main/res/layout/xui_layout_verify_code.xml +++ b/xui_lib/src/main/res/layout/xui_layout_verify_code.xml @@ -1,5 +1,5 @@ - @@ -7,7 +7,7 @@ android:id="@+id/ll_container" android:layout_width="wrap_content" android:layout_height="match_parent" - android:layout_centerInParent="true" + android:layout_gravity="center" android:gravity="start|center_vertical" android:orientation="horizontal" android:showDividers="beginning|middle|end"> @@ -21,4 +21,4 @@ android:background="@color/xui_config_color_transparent" android:inputType="number" /> - \ No newline at end of file + \ No newline at end of file diff --git a/xui_lib/src/main/res/values/xui_attrs.xml b/xui_lib/src/main/res/values/xui_attrs.xml index faa80bd5..a0bed84b 100755 --- a/xui_lib/src/main/res/values/xui_attrs.xml +++ b/xui_lib/src/main/res/values/xui_attrs.xml @@ -1066,6 +1066,8 @@ + + From a708fd044327e9ec1e8185f65704fb02a6e31650 Mon Sep 17 00:00:00 2001 From: xuexiangjys Date: Fri, 8 Oct 2021 00:38:31 +0800 Subject: [PATCH 03/19] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E6=A1=8C=E9=9D=A2=E5=BF=AB=E6=8D=B7=E6=96=B9=E5=BC=8F=E7=9A=84?= =?UTF-8?q?=E5=B7=A5=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/src/main/AndroidManifest.xml | 21 +++ .../xuidemo/activity/SettingsActivity.java | 8 +- .../xuexiang/xuidemo/base/BaseActivity.java | 15 --- .../components/tabbar/JPTabBarFragment.java | 17 +-- .../fragment/utils/ShortcutUtilsFragment.java | 94 +++++++++++++ .../CreateShortcutResultIntentActivity.java | 50 +++++++ .../utils/shortcut/ShortcutReceiver.java | 42 ++++++ .../res/drawable-hdpi/ic_expand_alibaba.png | Bin 1471 -> 1463 bytes .../res/drawable-hdpi/ic_expand_camera.png | Bin 810 -> 805 bytes .../res/drawable-hdpi/ic_util_shortcut.png | Bin 0 -> 652 bytes .../res/layout/fragment_shortcututils.xml | 32 +++++ .../com/xuexiang/xui/utils/ShortcutUtils.java | 125 ++++++++++++++++++ 12 files changed, 380 insertions(+), 24 deletions(-) create mode 100644 app/src/main/java/com/xuexiang/xuidemo/fragment/utils/ShortcutUtilsFragment.java create mode 100644 app/src/main/java/com/xuexiang/xuidemo/fragment/utils/shortcut/CreateShortcutResultIntentActivity.java create mode 100644 app/src/main/java/com/xuexiang/xuidemo/fragment/utils/shortcut/ShortcutReceiver.java create mode 100644 app/src/main/res/drawable-hdpi/ic_util_shortcut.png create mode 100644 app/src/main/res/layout/fragment_shortcututils.xml create mode 100644 xui_lib/src/main/java/com/xuexiang/xui/utils/ShortcutUtils.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 710edb6f..50d6379a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -26,6 +26,8 @@ + + @@ -200,6 +204,23 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/xuexiang/xuidemo/activity/SettingsActivity.java b/app/src/main/java/com/xuexiang/xuidemo/activity/SettingsActivity.java index 84e1582a..dc346cef 100644 --- a/app/src/main/java/com/xuexiang/xuidemo/activity/SettingsActivity.java +++ b/app/src/main/java/com/xuexiang/xuidemo/activity/SettingsActivity.java @@ -32,6 +32,7 @@ import com.xuexiang.xuidemo.R; import com.xuexiang.xuidemo.base.AppCompatPreferenceActivity; +import com.xuexiang.xuidemo.utils.Utils; import com.xuexiang.xuidemo.utils.XToastUtils; /** @@ -125,12 +126,17 @@ public boolean onMenuItemSelected(int featureId, MenuItem item) { int id = item.getItemId(); if (id == android.R.id.home) { if (!super.onMenuItemSelected(featureId, item)) { -// NavUtils.navigateUpFromSameTask(this); finish(); + Utils.syncMainPageStatus(); } return true; } return super.onMenuItemSelected(featureId, item); } + @Override + public void onBackPressed() { + Utils.syncMainPageStatus(); + super.onBackPressed(); + } } diff --git a/app/src/main/java/com/xuexiang/xuidemo/base/BaseActivity.java b/app/src/main/java/com/xuexiang/xuidemo/base/BaseActivity.java index f6f59800..131f4002 100644 --- a/app/src/main/java/com/xuexiang/xuidemo/base/BaseActivity.java +++ b/app/src/main/java/com/xuexiang/xuidemo/base/BaseActivity.java @@ -4,18 +4,13 @@ import android.content.res.Configuration; import android.os.Bundle; -import androidx.annotation.Keep; import androidx.annotation.NonNull; -import com.jpeng.jptabbar.anno.NorIcons; -import com.jpeng.jptabbar.anno.SeleIcons; -import com.jpeng.jptabbar.anno.Titles; import com.xuexiang.xpage.base.XPageActivity; import com.xuexiang.xpage.base.XPageFragment; import com.xuexiang.xpage.core.CoreSwitchBean; import com.xuexiang.xui.utils.ResUtils; import com.xuexiang.xui.widget.slideback.SlideBack; -import com.xuexiang.xuidemo.R; import com.xuexiang.xuidemo.utils.Utils; import butterknife.ButterKnife; @@ -28,18 +23,8 @@ * @author XUE * @since 2019/3/22 11:21 */ -@Keep public class BaseActivity extends XPageActivity { - //==============需要注意的是,由于JPTabBar反射获取注解的是context,也就是容器Activity,因此需要将注解写在容器Activity内======================// - @Titles - public static final int[] mTitles = {R.string.tab1, R.string.tab2, R.string.tab3, R.string.tab4}; - @SeleIcons - public static final int[] mSelectIcons = {R.drawable.nav_01_pre, R.drawable.nav_02_pre, R.drawable.nav_04_pre, R.drawable.nav_05_pre}; - @NorIcons - public static final int[] mNormalIcons = {R.drawable.nav_01_nor, R.drawable.nav_02_nor, R.drawable.nav_04_nor, R.drawable.nav_05_nor}; - - //============================================================================================================================================================// /** * 是否支持侧滑返回 */ diff --git a/app/src/main/java/com/xuexiang/xuidemo/fragment/components/tabbar/JPTabBarFragment.java b/app/src/main/java/com/xuexiang/xuidemo/fragment/components/tabbar/JPTabBarFragment.java index e8061f3e..7c0c5036 100644 --- a/app/src/main/java/com/xuexiang/xuidemo/fragment/components/tabbar/JPTabBarFragment.java +++ b/app/src/main/java/com/xuexiang/xuidemo/fragment/components/tabbar/JPTabBarFragment.java @@ -14,7 +14,6 @@ import com.xuexiang.xpage.annotation.Page; import com.xuexiang.xui.XUI; import com.xuexiang.xuidemo.R; -import com.xuexiang.xuidemo.base.BaseActivity; import com.xuexiang.xuidemo.base.BaseFragment; import com.xuexiang.xuidemo.utils.XToastUtils; @@ -23,8 +22,6 @@ import butterknife.BindView; -import static com.xuexiang.xuidemo.base.BaseActivity.mTitles; - /** * @author xuexiang * @since 2019/4/14 下午8:07 @@ -37,6 +34,10 @@ public class JPTabBarFragment extends BaseFragment implements OnTabSelectListene @BindView(R.id.tabbar) JPTabBar mTabbar; + private int[] mTitles = {R.string.tab1, R.string.tab2, R.string.tab3, R.string.tab4}; + private int[] mSelectIcons = {R.drawable.nav_01_pre, R.drawable.nav_02_pre, R.drawable.nav_04_pre, R.drawable.nav_05_pre}; + private int[] mNormalIcons = {R.drawable.nav_01_nor, R.drawable.nav_02_nor, R.drawable.nav_04_nor, R.drawable.nav_05_nor}; + private Map mPageMap = new HashMap<>(); private PagerAdapter mPagerAdapter = new PagerAdapter() { @@ -89,13 +90,13 @@ protected int getLayoutId() { /** * 初始化控件 - * mTabbar的设置详细参见 - * {@link BaseActivity#mTitles} - * {@link BaseActivity#mSelectIcons} - * {@link BaseActivity#mNormalIcons} */ @Override protected void initViews() { + mTabbar.setTitles(mTitles); + mTabbar.setNormalIcons(mNormalIcons); + mTabbar.setSelectedIcons(mSelectIcons); + mTabbar.generate(); //页面可以滑动 mTabbar.setGradientEnable(true); mTabbar.setPageAnimateEnable(true); @@ -108,7 +109,7 @@ protected void initViews() { mTabbar.getMiddleView().setOnClickListener(v -> XToastUtils.toast("中间点击")); } - mTabbar.showBadge(2,"", true); + mTabbar.showBadge(2, "", true); } @Override diff --git a/app/src/main/java/com/xuexiang/xuidemo/fragment/utils/ShortcutUtilsFragment.java b/app/src/main/java/com/xuexiang/xuidemo/fragment/utils/ShortcutUtilsFragment.java new file mode 100644 index 00000000..88b3260b --- /dev/null +++ b/app/src/main/java/com/xuexiang/xuidemo/fragment/utils/ShortcutUtilsFragment.java @@ -0,0 +1,94 @@ +/* + * Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.xuexiang.xuidemo.fragment.utils; + +import android.view.View; + +import com.xuexiang.xaop.annotation.SingleClick; +import com.xuexiang.xpage.annotation.Page; +import com.xuexiang.xui.utils.ResUtils; +import com.xuexiang.xui.utils.ShortcutUtils; +import com.xuexiang.xui.widget.actionbar.TitleBar; +import com.xuexiang.xui.widget.grouplist.XUIGroupListView; +import com.xuexiang.xuidemo.R; +import com.xuexiang.xuidemo.activity.SearchComponentActivity; +import com.xuexiang.xuidemo.activity.SettingsActivity; +import com.xuexiang.xuidemo.base.BaseFragment; +import com.xuexiang.xuidemo.fragment.utils.shortcut.ShortcutReceiver; +import com.xuexiang.xuidemo.utils.Utils; + +import butterknife.BindView; + +/** + * 快捷方式创建工具类 + * + * @author xuexiang + * @since 2021/10/6 3:33 PM + */ +@Page(name = "ShortcutUtils", extra = R.drawable.ic_util_shortcut) +public class ShortcutUtilsFragment extends BaseFragment { + + @BindView(R.id.groupListView) + XUIGroupListView groupListView; + + @Override + protected TitleBar initTitle() { + return super.initTitle().setLeftClickListener(new View.OnClickListener() { + @SingleClick + @Override + public void onClick(View v) { + popToBack(); + Utils.syncMainPageStatus(); + } + }); + } + + @Override + protected int getLayoutId() { + return R.layout.fragment_shortcututils; + } + + @Override + protected void initViews() { + XUIGroupListView.newSection(getContext()) + .setDescription("支持7.0以上版本的桌面快捷方式的创建") + .addItemView(groupListView.createItemView("增加搜索至桌面快捷方式"), v -> createSearchShortcut()) + .addItemView(groupListView.createItemView("增加设置至桌面快捷方式"), v -> createSettingShortcut()) + .addTo(groupListView); + } + + /** + * 创建搜索桌面快捷方式 + */ + private void createSearchShortcut() { + ShortcutUtils.addPinShortcut(getContext(), + SearchComponentActivity.class, + "shortcut_search_id", + R.drawable.ic_action_search, ResUtils.getString(R.string.shortcut_label_search), ShortcutReceiver.class); + } + + /** + * 创建搜索桌面快捷方式s + */ + private void createSettingShortcut() { + ShortcutUtils.addPinShortcut(getContext(), + SettingsActivity.class, + "shortcut_setting_id", + R.drawable.ic_action_setting, ResUtils.getString(R.string.shortcut_label_setting), ShortcutReceiver.class); + } +} diff --git a/app/src/main/java/com/xuexiang/xuidemo/fragment/utils/shortcut/CreateShortcutResultIntentActivity.java b/app/src/main/java/com/xuexiang/xuidemo/fragment/utils/shortcut/CreateShortcutResultIntentActivity.java new file mode 100644 index 00000000..ad17c0ac --- /dev/null +++ b/app/src/main/java/com/xuexiang/xuidemo/fragment/utils/shortcut/CreateShortcutResultIntentActivity.java @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.xuexiang.xuidemo.fragment.utils.shortcut; + +import android.os.Bundle; + +import com.xuexiang.xpage.core.PageOption; +import com.xuexiang.xpage.enums.CoreAnim; +import com.xuexiang.xuidemo.base.BaseActivity; +import com.xuexiang.xuidemo.fragment.utils.ShortcutUtilsFragment; +import com.xuexiang.xuidemo.utils.Utils; + +/** + * @author xuexiang + * @since 2021/10/7 7:00 PM + */ +public class CreateShortcutResultIntentActivity extends BaseActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + PageOption.to(ShortcutUtilsFragment.class) + .setAnim(CoreAnim.none) + .open(this); + } + + @Override + public void onBackPressed() { + if (this.getSupportFragmentManager().getBackStackEntryCount() == 1) { + Utils.syncMainPageStatus(); + } + super.onBackPressed(); + } +} diff --git a/app/src/main/java/com/xuexiang/xuidemo/fragment/utils/shortcut/ShortcutReceiver.java b/app/src/main/java/com/xuexiang/xuidemo/fragment/utils/shortcut/ShortcutReceiver.java new file mode 100644 index 00000000..d469a98e --- /dev/null +++ b/app/src/main/java/com/xuexiang/xuidemo/fragment/utils/shortcut/ShortcutReceiver.java @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.xuexiang.xuidemo.fragment.utils.shortcut; + +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; + +import com.xuexiang.xuidemo.utils.XToastUtils; +import com.xuexiang.xutil.common.logger.Logger; + +/** + * 快捷方式创建接收广播 + * + * @author xuexiang + * @since 2021/10/6 4:43 PM + */ +public class ShortcutReceiver extends BroadcastReceiver { + + private static final String TAG = "ShortcutReceiver"; + + @Override + public void onReceive(Context context, Intent intent) { + Logger.dTag(TAG, "onReceive:" + intent.getAction()); + XToastUtils.toast("开始创建快捷方式"); + } +} diff --git a/app/src/main/res/drawable-hdpi/ic_expand_alibaba.png b/app/src/main/res/drawable-hdpi/ic_expand_alibaba.png index f5cf732873742e324545803743dc04771bd71d8f..da1fbc819b58dc2787a13cbaccf9a39f136d0fbd 100644 GIT binary patch literal 1463 zcmX9-2~ZPP7+wfL2xt*dxx@frvzu@!qTqqy5af_S#FV4f-~k9Kprlg|ENHYvWRy{q znCynT6a_hKM~h>NMx;s=5v_nivKv4u^}g|RW=GkFd? z48vwdtO<>SXAs;HGY*Wq<$w0T!z3+eEo?TQu=tq5g|*S1xbR@C@vhSth8eGnjgDU( zo*j)-EJ^E0HA_-@k;Xu(SRq`Lo}gH7&5%gNxGJCGGy_$FVh9>wfM7h!hhj8G831HNWP>tAtnWS|j&A0;w*g#Rm66XwFmEB^R5z;^oud^_c z6ob<`LaCe9LOdR-r!YqtN(Yt%RpUYmU^-F7Fn|e-L4=lwfl#9hR}PCbLqfFyT0`nI z(4q#R5kX16sD2Dcgc_tJRI`95H4F(mAUzEukYUh5RMU;?U@k7#<0@7__2Zf$QU(4Q zF^v+y5zH`6VgM%~2i^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CVsyd Y>q=6ua(g%M10$Hh)78&qol`;+084Uu0RR91 diff --git a/app/src/main/res/drawable-hdpi/ic_util_shortcut.png b/app/src/main/res/drawable-hdpi/ic_util_shortcut.png new file mode 100644 index 0000000000000000000000000000000000000000..98cda894cdb2f0d7f68edae1a4899a7ab32ad407 GIT binary patch literal 652 zcmeAS@N?(olHy`uVBq!ia0vp^4j|0I3?%1nZ+ru!SkfJR9T^xl_H+M9WCijWi-X*q z7}lMWc?sm?2l#}zx)=Cp%zdOi?}^6T$3Ubx@3F?bN9uDQs?P>89;;4&q&XLefZ~sU z%7AR3pyu3%KxJC6w$840zfmCNFHdv;5Aa|No`Uw{B9NzGU;`b8qy1Dy-+MUE+Cb(IS~|?Ps<)p2{g^ zOHjznVPnXwWf@SMB?^({I75KtRx;awUMwGW8 z_RFd1kG&YT#IzmcwKo;K9B{8`!tZFN0}iR0Uf~QDO3xTX<}QkmFyLqqS@0xW+*V6m zi)(tfkb){hNkc=t?nf1WC58)}4D#xC)-qc8bo(=W$aolat@h5{mV)k+y85Rg^4~L> zuH@g8>)@7?dNxw}ZH7>{XY4bFsjneV|-zuDcax&b!_jT28-3DFjd-I;Ve&T0VPXDvve!~38`m3vgPtI`% PMk9l#tDnm{r-UW|m?a}t literal 0 HcmV?d00001 diff --git a/app/src/main/res/layout/fragment_shortcututils.xml b/app/src/main/res/layout/fragment_shortcututils.xml new file mode 100644 index 00000000..0c53cb4c --- /dev/null +++ b/app/src/main/res/layout/fragment_shortcututils.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/xui_lib/src/main/java/com/xuexiang/xui/utils/ShortcutUtils.java b/xui_lib/src/main/java/com/xuexiang/xui/utils/ShortcutUtils.java new file mode 100644 index 00000000..a28821cb --- /dev/null +++ b/xui_lib/src/main/java/com/xuexiang/xui/utils/ShortcutUtils.java @@ -0,0 +1,125 @@ +/* + * Copyright (C) 2021 xuexiangjys(xuexiangjys@163.com) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +package com.xuexiang.xui.utils; + +import android.app.PendingIntent; +import android.content.BroadcastReceiver; +import android.content.Context; +import android.content.Intent; +import android.os.Build; + +import androidx.annotation.AnyRes; +import androidx.annotation.NonNull; +import androidx.core.content.pm.ShortcutInfoCompat; +import androidx.core.content.pm.ShortcutManagerCompat; +import androidx.core.graphics.drawable.IconCompat; + +/** + * Shortcut应用快捷方式创建工具类 + * + * @author xuexiang + * @since 2021/10/6 2:50 PM + */ +public final class ShortcutUtils { + + private static final String ACTION_ADD_SHORTCUT = "com.android.launcher.action.INSTALL_SHORTCUT"; + + private ShortcutUtils() { + throw new UnsupportedOperationException("u can't instantiate me..."); + } + + /** + * 增加桌面快捷方式 + * + * @param context 上下文 + * @param targetClass 快捷方式跳转的目标页面 + * @param shortcutId 快捷方式id + * @param iconResourceId 快捷方式的图标 + * @param shortLabel 快捷方式的标题 + * @param resultReceiver 添加结果的接收器 + * @return 是否添加成功 + */ + public static boolean addPinShortcut(@NonNull Context context, @NonNull Class targetClass, @NonNull String shortcutId, @AnyRes int iconResourceId, @NonNull CharSequence shortLabel, Class resultReceiver) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { + return addPinShortcutAboveN(context, targetClass, shortcutId, IconCompat.createWithResource(context, iconResourceId), shortLabel, resultReceiver); + } else { + return addShortcutBelowAndroidN(context, targetClass, iconResourceId, shortLabel); + } + } + + /** + * 增加桌面快捷方式 + * + * @param context 上下文 + * @param targetClass 快捷方式跳转的目标页面 + * @param shortcutId 快捷方式id + * @param icon 快捷方式的图标 + * @param shortLabel 快捷方式的标题 + * @param resultReceiver 添加结果的接收器 + * @return 是否添加成功 + */ + public static boolean addPinShortcutAboveN(@NonNull Context context, @NonNull Class targetClass, @NonNull String shortcutId, @NonNull IconCompat icon, @NonNull CharSequence shortLabel, Class resultReceiver) { + if (ShortcutManagerCompat.isRequestPinShortcutSupported(context)) { + Intent shortcutInfoIntent = new Intent(context, targetClass); + shortcutInfoIntent.setAction(Intent.ACTION_VIEW); + ShortcutInfoCompat info = new ShortcutInfoCompat.Builder(context, shortcutId) + .setIcon(icon) + .setShortLabel(shortLabel) + .setIntent(shortcutInfoIntent) + .build(); + // 当添加快捷方式的确认弹框弹出来时,将被回调 + Intent resultIntent = resultReceiver != null ? new Intent(context, resultReceiver) : ShortcutManagerCompat.createShortcutResultIntent(context, info); + PendingIntent shortcutCallbackIntent = PendingIntent.getBroadcast(context, 0, resultIntent, PendingIntent.FLAG_UPDATE_CURRENT); + return ShortcutManagerCompat.requestPinShortcut(context, info, shortcutCallbackIntent.getIntentSender()); + } + return false; + } + + + /** + * 增加桌面快捷方式 + * + * @param context 上下文 + * @param targetClass 快捷方式跳转的目标页面 + * @param shortLabel 快捷方式的标题 + * @param iconResourceId 快捷方式的图标 + * @return 是否添加成功 + */ + public static boolean addShortcutBelowAndroidN(@NonNull Context context, @NonNull Class targetClass, @AnyRes int iconResourceId, @NonNull CharSequence shortLabel) { + try { + Intent addShortcutIntent = new Intent(ACTION_ADD_SHORTCUT); + // 不允许重复创建,不是根据快捷方式的名字判断重复的 + addShortcutIntent.putExtra("duplicate", false); + // 快捷方式的图标 + addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, iconResourceId)); + // 快捷方式的名称 + addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortLabel); + // 设置关联程序 + Intent launcherIntent = new Intent(); + launcherIntent.setClass(context, targetClass); + addShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launcherIntent); + // 发送广播 + context.sendBroadcast(addShortcutIntent); + return true; + } catch (Exception e) { + e.printStackTrace(); + } + return false; + } + +} From ded1c6757b21fd03373723b70e365ecf626ef501 Mon Sep 17 00:00:00 2001 From: xuexiangjys Date: Mon, 18 Oct 2021 21:00:37 +0800 Subject: [PATCH 04/19] =?UTF-8?q?=E5=9F=BA=E7=A1=80=E4=B8=BB=E9=A2=98?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=EF=BC=9ATheme.AppCompat.Light.NoActionBar=20?= =?UTF-8?q?->=20Theme.MaterialComponents.Light.NoActionBar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../materialdesign/ToolBarFragment.java | 57 +++++++++++++++---- app/src/main/res/layout/fragment_toolbar.xml | 53 +++++++++++++++++ app/src/main/res/values/styles_demo.xml | 2 +- .../src/main/res/layout/xui_layout_xtoast.xml | 2 +- xui_lib/src/main/res/values/xui_themes.xml | 2 +- 5 files changed, 103 insertions(+), 13 deletions(-) diff --git a/app/src/main/java/com/xuexiang/xuidemo/fragment/expands/materialdesign/ToolBarFragment.java b/app/src/main/java/com/xuexiang/xuidemo/fragment/expands/materialdesign/ToolBarFragment.java index 98832bcd..bce56572 100644 --- a/app/src/main/java/com/xuexiang/xuidemo/fragment/expands/materialdesign/ToolBarFragment.java +++ b/app/src/main/java/com/xuexiang/xuidemo/fragment/expands/materialdesign/ToolBarFragment.java @@ -2,15 +2,23 @@ import android.view.View; import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.TextView; import androidx.appcompat.widget.Toolbar; import com.xuexiang.xpage.annotation.Page; +import com.xuexiang.xui.utils.ResUtils; +import com.xuexiang.xui.utils.ViewUtils; +import com.xuexiang.xui.widget.popupwindow.popup.XUISimplePopup; import com.xuexiang.xuidemo.R; import com.xuexiang.xuidemo.base.BaseFragment; import com.xuexiang.xuidemo.utils.XToastUtils; +import com.xuexiang.xutil.common.StringUtils; +import com.xuexiang.xutil.display.DensityUtils; import butterknife.BindView; +import butterknife.OnClick; /** * @author xuexiang @@ -28,6 +36,15 @@ public class ToolBarFragment extends BaseFragment { EditText editSearch; @BindView(R.id.tool_bar_4) Toolbar toolBar4; + @BindView(R.id.ll_action) + LinearLayout llAction; + @BindView(R.id.tool_bar_5) + Toolbar toolBar5; + @BindView(R.id.tv_title) + TextView tvTitle; + @BindView(R.id.tv_sub_title) + TextView tvSubTitle; + /** * 布局的资源id @@ -48,9 +65,10 @@ protected void initViews() { initToolbar2(); initToolbar3(); initToolbar4(); + initToolbar5(); } - private void initToolbar1(){ + private void initToolbar1() { //设置NavigationIcon toolBar1.setNavigationIcon(R.drawable.ic_navigation_menu); // 设置 NavigationIcon 点击事件 @@ -76,36 +94,55 @@ private void initToolbar1(){ toolBar1.setOnMenuItemClickListener(menuItemClickListener); } - private void initToolbar2(){ + private void initToolbar2() { toolBar2.setNavigationOnClickListener(onClickListener); toolBar2.inflateMenu(R.menu.menu_setting); toolBar2.setOnMenuItemClickListener(menuItemClickListener); } - private void initToolbar3(){ + private void initToolbar3() { toolBar3.setNavigationOnClickListener(onClickListener); toolBar3.inflateMenu(R.menu.menu_setting); toolBar3.setOnMenuItemClickListener(menuItemClickListener); } - private void initToolbar4(){ + private void initToolbar4() { toolBar4.setNavigationOnClickListener(onClickListener); toolBar4.inflateMenu(R.menu.menu_search); toolBar4.setOnMenuItemClickListener(menuItemClickListener); } + private void initToolbar5() { + toolBar5.setNavigationOnClickListener(onClickListener); + toolBar5.setOnMenuItemClickListener(menuItemClickListener); + tvTitle.setText("主页"); + } + + private View.OnClickListener onClickListener = v -> XToastUtils.toast("点击了NavigationIcon"); Toolbar.OnMenuItemClickListener menuItemClickListener = item -> { XToastUtils.toast("点击了:" + item.getTitle()); - switch (item.getItemId()){ - case R.id.item_setting: - //点击设置 - break; - default: - break; + if (item.getItemId() == R.id.item_setting) { + //点击设置 } return false; }; + + @OnClick(R.id.ll_action) + public void onViewClicked(View view) { + if (view.getId() == R.id.ll_action) { + showSelectPopWindow(view); + } + } + + private void showSelectPopWindow(View view) { + new XUISimplePopup<>(getContext(), ResUtils.getStringArray(R.array.grid_titles_entry)) + .create(DensityUtils.dip2px(getContext(), 170), (adapter, item, position) -> { + ViewUtils.setText(tvSubTitle, String.format("<%s>", item)); + }) + .setHasDivider(true) + .showDown(view); + } } diff --git a/app/src/main/res/layout/fragment_toolbar.xml b/app/src/main/res/layout/fragment_toolbar.xml index ba9abbe3..f444ca66 100644 --- a/app/src/main/res/layout/fragment_toolbar.xml +++ b/app/src/main/res/layout/fragment_toolbar.xml @@ -60,4 +60,57 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/styles_demo.xml b/app/src/main/res/values/styles_demo.xml index 58357d18..76469b6b 100644 --- a/app/src/main/res/values/styles_demo.xml +++ b/app/src/main/res/values/styles_demo.xml @@ -127,7 +127,7 @@ true - -