diff --git a/.gitignore b/.gitignore index 603b14077394cd2294ac6922fe619669630ef3ab..c5986840b05025a898d4ea39abbc0fbf237b6270 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ /captures .externalNativeBuild .cxx +upload.gradle diff --git a/README.md b/README.md index 008bd7ba919abbec7ec2b9549bc647a834c86f76..99d284204ddf65b3dcd9254c6c6d8f27dca88392 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # MaterialSearchBar -**本项目基于开源项目MaterialSearchBar 进行OpenHarmony化的移植和开发,可以通过项目标签以及github地址()追踪到原安卓项目版本** +**本项目基于开源项目MaterialSearchBar 进行OpenHarmony的移植和开发,可以通过项目标签以及github地址()追踪到原安卓项目版本** #### 项目介绍 - 项目名称:搜索框和侧滑栏 @@ -19,18 +19,23 @@ #### 安装教程 -1.下载library的har包library.har(位于:)。 - -2.启动 DevEco Studio,将下载的har包,导入工程目录“entry->libs”下。 - -3.在moudle级别下的build.gradle文件中添加依赖,在dependencies标签中增加对libs目录下jar包的引用。 - - ``` +1、在项目根目录下的build.gradle文件中 + ```gradle +allprojects { + repositories { + maven { + url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' + } + } +} +``` +2.在entry模块的build.gradle文件中 + ```gradle dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) - ...... + implementation('com.gitee.chinasoft_ohos:MaterialSearchBar:0.0.1-SNAPSHOT') + ...... } - ``` +``` 在sdk5,DevEco Studio2.1 beta3下项目可直接运行 如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件, @@ -120,7 +125,7 @@ CloudTest代码测试无异常 #### 版本迭代 -- v0.0.1_alpha +- 0.0.1-SNAPSHOT #### 版权和许可信息 diff --git a/build.gradle b/build.gradle index 0f37d1b371f1632aaf2af4a2814463596cc0ddf0..ff7362f67029f35dec778c6749a2269326af9339 100644 --- a/build.gradle +++ b/build.gradle @@ -32,6 +32,9 @@ allprojects { maven { url 'https://developer.huawei.com/repo/' } + maven { + url 'https://s01.oss.sonatype.org/content/repositories/snapshots/' + } jcenter() } } diff --git a/entry/libs/library-debug.har b/entry/libs/library-debug.har new file mode 100644 index 0000000000000000000000000000000000000000..0bec79eed6da8383758d0349e3437860947272f1 Binary files /dev/null and b/entry/libs/library-debug.har differ diff --git a/entry/src/main/config.json b/entry/src/main/config.json index 98189c5177a697728b1088399ad167cbb5fe2af5..e6f4fa4e308711c8470f470598ab964974a11dd2 100644 --- a/entry/src/main/config.json +++ b/entry/src/main/config.json @@ -1,6 +1,6 @@ { "app": { - "bundleName": "cn.bingoogolapple.bgabanner.demo", + "bundleName": "com.mancj.example", "vendor": "mancj", "version": { "code": 1, diff --git a/entry/src/main/java/com/mancj/example/slice/NavAbilitySlice.java b/entry/src/main/java/com/mancj/example/slice/NavAbilitySlice.java index 34433c595dd2596fefbf1d76b6f9495ff4827e3a..13cbf06cb6d931faed51cdd71f359f8a85b7fd6a 100644 --- a/entry/src/main/java/com/mancj/example/slice/NavAbilitySlice.java +++ b/entry/src/main/java/com/mancj/example/slice/NavAbilitySlice.java @@ -1,8 +1,9 @@ package com.mancj.example.slice; -import com.balysv.materialripple.MaterialRippleLayout; import com.mancj.example.ResourceTable; import com.mancj.example.RoundRectView; + + import com.mancj.materialsearchbar.adapter.HistoryItemProvider; import com.mancj.materialsearchbar.bean.HistoryBean; import ohos.aafwk.ability.AbilitySlice; @@ -11,8 +12,14 @@ import ohos.agp.animation.Animator; import ohos.agp.animation.AnimatorProperty; import ohos.agp.animation.AnimatorValue; import ohos.agp.colors.RgbColor; -import ohos.agp.components.*; +import ohos.agp.components.Component; +import ohos.agp.components.DependentLayout; +import ohos.agp.components.DirectionalLayout; import ohos.agp.components.element.ShapeElement; +import ohos.agp.components.Image; +import ohos.agp.components.ListContainer; +import ohos.agp.components.Text; +import ohos.agp.components.TextField; import ohos.agp.utils.Color; import ohos.agp.utils.LayoutAlignment; import ohos.agp.window.dialog.ToastDialog; @@ -32,33 +39,75 @@ import java.io.InputStream; import java.util.ArrayList; import java.util.Collections; import java.util.concurrent.atomic.AtomicReference; - import static com.mancj.example.ResourceTable.Color_purple_300; -import static ohos.agp.utils.Color.*; public class NavAbilitySlice extends AbilitySlice implements Animator.StateChangedListener, Component.ClickedListener { private static final boolean ISPD = true; private static final boolean ISPDS = false; private static final HiLogLabel LABLE = new HiLogLabel(HiLog.LOG_APP, 0x002, "SearchBarDemo"); - - private DirectionalLayout ly_import, ly_gallery, ly_slideshow, ly_tools, ly_share, header, ly_send, mDrawerLayout, mMainLayout; - private Image iv_import, iv_gallery, iv_slideshow, iv_tools, main_search, mDrawerImage; + private static final int IS_SIXTY = 60; + private static final int IS_ONETHOUSANDANDEIGHTY = 1080; + private static final int IS_ONETHOUSANDANDNINEHUNDRED = 1900; + private static final int ISTWOHUNDREDANDFIFTYFIVE = 255; + private static final int ISONEHUNDREDANDNINETYTWO = 192; + private static final int ISTWOHUNDREDANDSIXTY = 260; + private static final int ISONETHOUSAND = 1000; + private static final int ISTWOTHOUSAND = 2000; + private static final int ISTHIRTY = 30; + private static final int ISTHREE = 3; + private static final int ISFIVEHUNDRED = 500; + private static final int ISONEHUNDRED = 100; + private static final int ISTHREEHUNDREDANDFIFTY = 350; + private static final int ISTWOHUNDRED = 200; + private static final int ISTWOHUNDREDANDSEVENTY = 270; + private static final int ISONEHUNDREDANDEIGHTY = 180; + private static final int ISTWO = 2; + private static final int ISTHREEHUNDREDANDSIXTY = 360; + private static final int ISSEVENHUNDRED = -700; + private static final int ISFOUR = 4; + private static final int ISEIGHT = 8; + private static final float ISZEROPOINTTHREE = 0.3f; + private static final float ISZEROPOINTNINE = 0.9f; + private static final float ISONETHOUSANDF = 1000.0f; + private DirectionalLayout lyImport; + private DirectionalLayout lyGallery; + private DirectionalLayout lySlideshow; + private DirectionalLayout lyTools; + private DirectionalLayout lyShare; + private DirectionalLayout header; + private DirectionalLayout lySend; + private DirectionalLayout mDrawerLayout; + private DirectionalLayout mMainLayout; + private Image ivImport; + private Image ivGallery; + private Image ivSlideshow; + private Image ivTools; + private Image mainSearch; + private Image mDrawerImage; private RoundRectView android; - private Text tv_import, tv_gallery, tv_slideshow, tv_tools; - private ShapeElement element, elements, elementTwo; - private Image main_item; - private TextField main_tf, tf_but, tf_ss; - private DependentLayout depen_layout; + private Text tvImport; + private Text tvGallery; + private Text tvSlideshow; + private Text tvTools; + private ShapeElement element; + private ShapeElement elements; + private ShapeElement elementTwo; + private Image mainItem; + private TextField mainTf; + private TextField tfSs; + private TextField tfBut; + private DependentLayout depenLayout; private AnimatorProperty mAnimatorIcon; private AnimatorProperty mAnimatorLayout; private AnimatorProperty animatorProperty; - private Boolean isSelOpen = ISPD; private Boolean isFlag = ISPDS; private Boolean isItem = ISPD; - private ListContainer list, dialog; + private ListContainer list; + private ListContainer dialog; private int count = 0; - private HistoryItemProvider provider, itemProvider; + private HistoryItemProvider provider; + private HistoryItemProvider itemProvider; private ArrayList beans = new ArrayList<>(); private ArrayList beans1 = new ArrayList<>(); private Image search; @@ -79,13 +128,17 @@ public class NavAbilitySlice extends AbilitySlice implements Animator.StateChang } private void onFocusChangedListener() { - main_tf.setFocusChangedListener((component, isFocused) -> { + mainTf.setFocusChangedListener((component, isFocused) -> { if (isFocused) { - // 获取到焦点 - depen_layout.setContentPositionY(1080); + /* + * 获取到焦点 + */ + depenLayout.setContentPositionY(IS_ONETHOUSANDANDEIGHTY); } else { - // 失去焦点 - depen_layout.setContentPositionY(1900); + /* + * 失去焦点 + */ + depenLayout.setContentPositionY(IS_ONETHOUSANDANDNINEHUNDRED); } }); } @@ -94,8 +147,8 @@ public class NavAbilitySlice extends AbilitySlice implements Animator.StateChang try { int color = getResourceManager().getElement(ResourceTable.Color_barColor).getColor(); /* - * 状态栏颜色 - */ + * 状态栏颜色 + */ WindowManager.getInstance().getTopWindow().get().setStatusBarColor(color); } catch (Exception e) { e.printStackTrace(); @@ -109,10 +162,11 @@ public class NavAbilitySlice extends AbilitySlice implements Animator.StateChang */ android.putPixelMap(getPixelMap(ResourceTable.Media_android)); android.setScaleMode(Image.ScaleMode.ZOOM_CENTER); - DirectionalLayout.LayoutConfig layoutConfig = new DirectionalLayout.LayoutConfig(DirectionalLayout.LayoutConfig.MATCH_PARENT, DirectionalLayout.LayoutConfig.MATCH_PARENT); + DirectionalLayout.LayoutConfig layoutConfig = new DirectionalLayout.LayoutConfig( + DirectionalLayout.LayoutConfig.MATCH_PARENT, DirectionalLayout.LayoutConfig.MATCH_PARENT); header.addComponent(android, layoutConfig); list.setItemProvider(provider); - for (int ia = 1; ia <= 3; ia++) { + for (int ia = 1; ia <= ISTHREE; ia++) { beans1.add(new HistoryBean("Item " + ia)); } itemProvider = new HistoryItemProvider(beans1, NavAbilitySlice.this, ResourceTable.Layout_item_layout); @@ -122,44 +176,47 @@ public class NavAbilitySlice extends AbilitySlice implements Animator.StateChang elements = new ShapeElement(); elementTwo = new ShapeElement(); try { - element.setRgbColor(RgbColor.fromArgbInt(getResourceManager().getElement(ResourceTable.Color_bg).getColor())); + element.setRgbColor( + RgbColor.fromArgbInt(getResourceManager().getElement(ResourceTable.Color_bg).getColor())); } catch (Exception e) { e.printStackTrace(); } - elements.setRgbColor(new RgbColor(255, 255, 255)); - elementTwo.setRgbColor(new RgbColor(192, 192, 192)); + elements.setRgbColor( + new RgbColor(ISTWOHUNDREDANDFIFTYFIVE, ISTWOHUNDREDANDFIFTYFIVE, ISTWOHUNDREDANDFIFTYFIVE)); + elementTwo.setRgbColor( + new RgbColor(ISONEHUNDREDANDNINETYTWO, ISONEHUNDREDANDNINETYTWO, ISONEHUNDREDANDNINETYTWO)); } private void initView() { search = (Image) findComponentById(ResourceTable.Id_search); - ly_import = (DirectionalLayout) findComponentById(ResourceTable.Id_ly_import); - iv_import = (Image) findComponentById(ResourceTable.Id_iv_import); - tv_import = (Text) findComponentById(ResourceTable.Id_tv_import); - ly_gallery = (DirectionalLayout) findComponentById(ResourceTable.Id_ly_gallery); - iv_gallery = (Image) findComponentById(ResourceTable.Id_iv_gallery); - tv_gallery = (Text) findComponentById(ResourceTable.Id_tv_gallery); - ly_slideshow = (DirectionalLayout) findComponentById(ResourceTable.Id_ly_slideshow); - iv_slideshow = (Image) findComponentById(ResourceTable.Id_iv_slideshow); - tv_slideshow = (Text) findComponentById(ResourceTable.Id_tv_slideshow); - ly_tools = (DirectionalLayout) findComponentById(ResourceTable.Id_ly_tools); - iv_tools = (Image) findComponentById(ResourceTable.Id_iv_tools); - tv_tools = (Text) findComponentById(ResourceTable.Id_tv_tools); - ly_share = (DirectionalLayout) findComponentById(ResourceTable.Id_ly_share); + lyImport = (DirectionalLayout) findComponentById(ResourceTable.Id_ly_import); + ivImport = (Image) findComponentById(ResourceTable.Id_iv_import); + tvImport = (Text) findComponentById(ResourceTable.Id_tv_import); + lyGallery = (DirectionalLayout) findComponentById(ResourceTable.Id_ly_gallery); + ivGallery = (Image) findComponentById(ResourceTable.Id_iv_gallery); + tvGallery = (Text) findComponentById(ResourceTable.Id_tv_gallery); + lySlideshow = (DirectionalLayout) findComponentById(ResourceTable.Id_ly_slideshow); + ivSlideshow = (Image) findComponentById(ResourceTable.Id_iv_slideshow); + tvSlideshow = (Text) findComponentById(ResourceTable.Id_tv_slideshow); + lyTools = (DirectionalLayout) findComponentById(ResourceTable.Id_ly_tools); + ivTools = (Image) findComponentById(ResourceTable.Id_iv_tools); + tvTools = (Text) findComponentById(ResourceTable.Id_tv_tools); + lyShare = (DirectionalLayout) findComponentById(ResourceTable.Id_ly_share); header = (DirectionalLayout) findComponentById(ResourceTable.Id_header); - android = new RoundRectView(this, new Size(260, 260)); + android = new RoundRectView(this, new Size(ISTWOHUNDREDANDSIXTY, ISTWOHUNDREDANDSIXTY)); - ly_send = (DirectionalLayout) findComponentById(ResourceTable.Id_ly_send); + lySend = (DirectionalLayout) findComponentById(ResourceTable.Id_ly_send); mDrawerImage = (Image) findComponentById(ResourceTable.Id_main_drawer); mDrawerImage.setClickedListener(NavAbilitySlice.this); mMainLayout = (DirectionalLayout) findComponentById(ResourceTable.Id_main_layout); mMainLayout.setClickedListener(NavAbilitySlice.this); mDrawerLayout = (DirectionalLayout) findComponentById(ResourceTable.Id_main_drawer_layout); - main_item = (Image) findComponentById(ResourceTable.Id_main_item); - main_search = (Image) findComponentById(ResourceTable.Id_main_search); - main_tf = (TextField) findComponentById(ResourceTable.Id_main_tf); - tf_but = (TextField) findComponentById(ResourceTable.Id_tf_but); - tf_ss = (TextField) findComponentById(ResourceTable.Id_tf_ss); - depen_layout = (DependentLayout) findComponentById(ResourceTable.Id_depen_layout); + mainItem = (Image) findComponentById(ResourceTable.Id_main_item); + mainSearch = (Image) findComponentById(ResourceTable.Id_main_search); + mainTf = (TextField) findComponentById(ResourceTable.Id_main_tf); + tfBut = (TextField) findComponentById(ResourceTable.Id_tf_but); + tfSs = (TextField) findComponentById(ResourceTable.Id_tf_ss); + depenLayout = (DependentLayout) findComponentById(ResourceTable.Id_depen_layout); list = (ListContainer) findComponentById(ResourceTable.Id_history); provider = new HistoryItemProvider(beans, NavAbilitySlice.this, ResourceTable.Layout_item_last_request); @@ -175,11 +232,10 @@ public class NavAbilitySlice extends AbilitySlice implements Animator.StateChang drawableInputStream = getResourceManager().getResource(drawableId); ImageSource.SourceOptions sourceOptions = new ImageSource.SourceOptions(); sourceOptions.formatHint = "image/png"; - ImageSource imageSource = ImageSource.create(drawableInputStream, sourceOptions); ImageSource.DecodingOptions decodingOptions = new ImageSource.DecodingOptions(); - decodingOptions.desiredSize = new Size(0, 0); - decodingOptions.desiredRegion = new Rect(0, 0, 0, 0); + decodingOptions.desiredSize = new Size(0, 0);decodingOptions.desiredRegion = new Rect(0, 0, 0, 0); decodingOptions.desiredPixelFormat = PixelFormat.ARGB_8888; + ImageSource imageSource = ImageSource.create(drawableInputStream, sourceOptions); PixelMap pixelMap = imageSource.createPixelmap(decodingOptions); return pixelMap; } catch (Exception e) { @@ -199,8 +255,9 @@ public class NavAbilitySlice extends AbilitySlice implements Animator.StateChang private void setBackGround(Image image) { try { ShapeElement shapeElement = new ShapeElement(); - shapeElement.setCornerRadius(image.getHeight() * 2); - shapeElement.setRgbColor(RgbColor.fromArgbInt(getResourceManager().getElement(ResourceTable.Color_teal_701).getColor())); + shapeElement.setCornerRadius(image.getHeight() * ISTWO); + shapeElement.setRgbColor( + RgbColor.fromArgbInt(getResourceManager().getElement(ResourceTable.Color_teal_701).getColor())); image.setBackground(shapeElement); } catch (Exception ignored) { } @@ -208,14 +265,14 @@ public class NavAbilitySlice extends AbilitySlice implements Animator.StateChang private void hideList() { AnimatorValue value = new AnimatorValue(); - value.setDuration(1000); + value.setDuration(ISONETHOUSAND); value.setLoopedCount(0); value.setCurveType(Animator.CurveType.LINEAR); value.setValueUpdateListener((animatorValue, v) -> { - if (v >= 0.3f) { + if (v >= ISZEROPOINTTHREE) { list.setVisibility(Component.HIDE); } - list.setContentPosition(0, (1 - v) * (main_tf.getHeight() + 30)); + list.setContentPosition(0, (1 - v) * (mainTf.getHeight() + ISTHIRTY)); }); value.start(); } @@ -223,14 +280,14 @@ public class NavAbilitySlice extends AbilitySlice implements Animator.StateChang private void showList() { if (beans.size() != 0) { AnimatorValue value = new AnimatorValue(); - value.setDuration(2000); + value.setDuration(ISONETHOUSAND); value.setLoopedCount(0); value.setCurveType(Animator.CurveType.LINEAR); value.setValueUpdateListener((animatorValue, v) -> { - if (v >= 0.9f) { + if (v >= ISZEROPOINTNINE) { list.setVisibility(Component.VISIBLE); } - list.setContentPosition(0, v * (main_tf.getHeight() + 30)); + list.setContentPosition(0, v * (mainTf.getHeight() + ISTHIRTY)); }); value.start(); } @@ -247,7 +304,7 @@ public class NavAbilitySlice extends AbilitySlice implements Animator.StateChang } private void OnClickListener() { - main_item.setClickedListener(component -> { + mainItem.setClickedListener(component -> { if (isItem) { dialog.setVisibility(Component.VISIBLE); } else { @@ -261,14 +318,14 @@ public class NavAbilitySlice extends AbilitySlice implements Animator.StateChang getUITaskDispatcher().delayDispatch(() -> { isItem = true; dialog.setVisibility(Component.INVISIBLE); - }, 500); + }, ISFIVEHUNDRED); }); list.setItemClickedListener((listContainer, component, i, l) -> { Text text = (Text) listContainer.getComponentAt(i).findComponentById(ResourceTable.Id_text); text.setClickedListener(component1 -> { String name = beans.get(i).getName(); - main_tf.setText(name); + mainTf.setText(name); }); Image delete = (Image) listContainer.getComponentAt(i).findComponentById(ResourceTable.Id_iv_delete); @@ -280,7 +337,7 @@ public class NavAbilitySlice extends AbilitySlice implements Animator.StateChang }); }); - main_tf.setClickedListener(component -> { + mainTf.setClickedListener(component -> { getFocusable(); hideItem(); if (!isFlag) { @@ -290,7 +347,7 @@ public class NavAbilitySlice extends AbilitySlice implements Animator.StateChang } }); - main_search.setClickedListener(component -> { + mainSearch.setClickedListener(component -> { getFocusable(); hideItem(); if (!isFlag) { @@ -320,157 +377,157 @@ public class NavAbilitySlice extends AbilitySlice implements Animator.StateChang showDraw(); } if (temp.get() > x && isFlag) { - OnAnimatorIcon(); + onAnimatorIcon(); } - if (x > 100) { + if (x > ISONEHUNDRED) { temp.set(x); } else { - temp.set(1000.0f); + temp.set(ISONETHOUSANDF); } } if (touchEvent.getAction() == TouchEvent.PRIMARY_POINT_UP) { - temp.set(1000.0f); + temp.set(ISONETHOUSANDF); } return true; }); -/** - * element 紫色 - * elements 白色 - */ - ly_import.setClickedListener(component -> { - ly_gallery.setBackground(elements); - ly_slideshow.setBackground(elements); - ly_tools.setBackground(elements); - iv_import.setPixelMap(ResourceTable.Media_a2); - iv_gallery.setPixelMap(ResourceTable.Media_c1); - iv_slideshow.setPixelMap(ResourceTable.Media_d1); - iv_tools.setPixelMap(ResourceTable.Media_b1); + /** + * element 紫色 + * elements 白色 + */ + lyImport.setClickedListener(component -> { + lyGallery.setBackground(elements); + lySlideshow.setBackground(elements); + lyTools.setBackground(elements); + ivImport.setPixelMap(ResourceTable.Media_a2); + ivGallery.setPixelMap(ResourceTable.Media_c1); + ivSlideshow.setPixelMap(ResourceTable.Media_d1); + ivTools.setPixelMap(ResourceTable.Media_b1); try { int color1 = getResourceManager().getElement(Color_purple_300).getColor(); Color color = new Color(color1); - tv_import.setTextColor(color); + tvImport.setTextColor(color); } catch (Exception e) { e.printStackTrace(); } - tv_gallery.setTextColor(BLACK); - tv_slideshow.setTextColor(BLACK); - tv_tools.setTextColor(BLACK); + tvGallery.setTextColor(Color.BLACK); + tvSlideshow.setTextColor(Color.BLACK); + tvTools.setTextColor(Color.BLACK); getUITaskDispatcher().delayDispatch(() -> { - ly_import.setBackground(element); - OnAnimatorIcon(); - }, 350); + lyImport.setBackground(element); + onAnimatorIcon(); + }, ISTHREEHUNDREDANDFIFTY); }); - ly_gallery.setClickedListener(component -> { - ly_import.setBackground(elements); - ly_slideshow.setBackground(elements); - ly_tools.setBackground(elements); - iv_import.setPixelMap(ResourceTable.Media_a1); - iv_gallery.setPixelMap(ResourceTable.Media_c2); - iv_slideshow.setPixelMap(ResourceTable.Media_d1); - iv_tools.setPixelMap(ResourceTable.Media_b1); + lyGallery.setClickedListener(component -> { + lyImport.setBackground(elements); + lySlideshow.setBackground(elements); + lyTools.setBackground(elements); + ivImport.setPixelMap(ResourceTable.Media_a1); + ivGallery.setPixelMap(ResourceTable.Media_c2); + ivSlideshow.setPixelMap(ResourceTable.Media_d1); + ivTools.setPixelMap(ResourceTable.Media_b1); try { int color1 = getResourceManager().getElement(Color_purple_300).getColor(); Color color = new Color(color1); - tv_gallery.setTextColor(color); + tvGallery.setTextColor(color); } catch (Exception e) { e.printStackTrace(); } - tv_import.setTextColor(BLACK); - tv_slideshow.setTextColor(BLACK); - tv_tools.setTextColor(BLACK); + tvImport.setTextColor(Color.BLACK); + tvSlideshow.setTextColor(Color.BLACK); + tvTools.setTextColor(Color.BLACK); getUITaskDispatcher().delayDispatch(() -> { - ly_gallery.setBackground(element); - OnAnimatorIcon(); - }, 350); + lyGallery.setBackground(element); + onAnimatorIcon(); + }, ISTHREEHUNDREDANDFIFTY); }); - ly_slideshow.setClickedListener(component -> { - ly_import.setBackground(elements); - ly_gallery.setBackground(elements); - ly_tools.setBackground(elements); - iv_import.setPixelMap(ResourceTable.Media_a1); - iv_gallery.setPixelMap(ResourceTable.Media_c1); - iv_slideshow.setPixelMap(ResourceTable.Media_d2); - iv_tools.setPixelMap(ResourceTable.Media_b1); + lySlideshow.setClickedListener(component -> { + lyImport.setBackground(elements); + lyGallery.setBackground(elements); + lyTools.setBackground(elements); + ivImport.setPixelMap(ResourceTable.Media_a1); + ivGallery.setPixelMap(ResourceTable.Media_c1); + ivSlideshow.setPixelMap(ResourceTable.Media_d2); + ivTools.setPixelMap(ResourceTable.Media_b1); try { int color1 = getResourceManager().getElement(Color_purple_300).getColor(); Color color = new Color(color1); - tv_slideshow.setTextColor(color); + tvSlideshow.setTextColor(color); } catch (Exception e) { e.printStackTrace(); } - tv_import.setTextColor(BLACK); - tv_gallery.setTextColor(BLACK); - tv_tools.setTextColor(BLACK); + tvImport.setTextColor(Color.BLACK); + tvGallery.setTextColor(Color.BLACK); + tvTools.setTextColor(Color.BLACK); getUITaskDispatcher().delayDispatch(() -> { - ly_slideshow.setBackground(element); - OnAnimatorIcon(); - }, 350); + lySlideshow.setBackground(element); + onAnimatorIcon(); + }, ISTHREEHUNDREDANDFIFTY); }); - ly_tools.setClickedListener(component -> { - ly_import.setBackground(elements); - ly_gallery.setBackground(elements); - ly_slideshow.setBackground(elements); - iv_import.setPixelMap(ResourceTable.Media_a1); - iv_gallery.setPixelMap(ResourceTable.Media_c1); - iv_slideshow.setPixelMap(ResourceTable.Media_d1); - iv_tools.setPixelMap(ResourceTable.Media_b2); + lyTools.setClickedListener(component -> { + lyImport.setBackground(elements); + lyGallery.setBackground(elements); + lySlideshow.setBackground(elements); + ivImport.setPixelMap(ResourceTable.Media_a1); + ivGallery.setPixelMap(ResourceTable.Media_c1); + ivSlideshow.setPixelMap(ResourceTable.Media_d1); + ivTools.setPixelMap(ResourceTable.Media_b2); try { int color1 = getResourceManager().getElement(Color_purple_300).getColor(); Color color = new Color(color1); - tv_tools.setTextColor(color); + tvTools.setTextColor(color); } catch (Exception e) { e.printStackTrace(); } - tv_import.setTextColor(BLACK); - tv_gallery.setTextColor(BLACK); - tv_slideshow.setTextColor(BLACK); + tvImport.setTextColor(Color.BLACK); + tvGallery.setTextColor(Color.BLACK); + tvSlideshow.setTextColor(Color.BLACK); getUITaskDispatcher().delayDispatch(() -> { - ly_tools.setBackground(element); - OnAnimatorIcon(); - }, 350); + lyTools.setBackground(element); + onAnimatorIcon(); + }, ISTHREEHUNDREDANDFIFTY); }); - ly_share.setClickedListener(component -> { + lyShare.setClickedListener(component -> { getUITaskDispatcher().delayDispatch(() -> { - ly_share.setBackground(elementTwo); - OnAnimatorIcon(); - }, 350); + lyShare.setBackground(elementTwo); + onAnimatorIcon(); + }, ISTHREEHUNDREDANDFIFTY); }); - ly_send.setClickedListener(component -> { + lySend.setClickedListener(component -> { getUITaskDispatcher().delayDispatch(() -> { - ly_send.setBackground(elementTwo); - OnAnimatorIcon(); - }, 350); + lySend.setBackground(elementTwo); + onAnimatorIcon(); + }, ISTHREEHUNDREDANDFIFTY); }); - main_tf.setEditorActionListener(j -> { + mainTf.setEditorActionListener(j -> { if (j == 1) { - String text = main_tf.getText(); + String text = mainTf.getText(); if (text.length() == 0) { new ToastDialog(getContext()) .setText("搜索内容不能为空") .show(); - depen_layout.setContentPositionY(1900); + depenLayout.setContentPositionY(IS_ONETHOUSANDANDNINEHUNDRED); } else { hideItem(); HistoryBean historyBean = null; - int i = 0; - if (!main_tf.getText().trim().equals("")) { - String trim = main_tf.getText().trim(); + int ISI = 0; + if (!mainTf.getText().trim().equals("")) { + String trim = mainTf.getText().trim(); if (beans.size() == 0) { historyBean = new HistoryBean(trim); } for (HistoryBean bean : beans) { if (bean.getName().equals(trim)) { - i++; + ISI++; } } - if (i == 0) { + if (ISI == 0) { historyBean = new HistoryBean(trim); } if (historyBean != null) { Collections.reverse(beans); beans.add(historyBean); - if (beans.size() == 4) { + if (beans.size() == ISFOUR) { beans.remove(0); } Collections.reverse(beans); @@ -478,17 +535,17 @@ public class NavAbilitySlice extends AbilitySlice implements Animator.StateChang } hideList(); } - depen_layout.setContentPositionY(1900); + depenLayout.setContentPositionY(IS_ONETHOUSANDANDNINEHUNDRED); return true; } } return false; - }); + }); /* * 下面的搜索按钮下的输入框 */ - tf_but.setClickedListener(component -> { + tfBut.setClickedListener(component -> { /* * 点击之后焦点设置在主输入框 */ @@ -498,12 +555,12 @@ public class NavAbilitySlice extends AbilitySlice implements Animator.StateChang changeIc(); showList(); isFlag = true; - } + } }); /* * 搜索栏的放大镜下面的输入框 */ - tf_ss.setClickedListener(component -> { + tfSs.setClickedListener(component -> { /* * 点击之后焦点设置在主输入框 */ @@ -528,9 +585,9 @@ public class NavAbilitySlice extends AbilitySlice implements Animator.StateChang } private void getFocusable() { - main_tf.setFocusable(8); - main_tf.setTouchFocusable(true); - main_tf.requestFocus(); + mainTf.setFocusable(ISEIGHT); + mainTf.setTouchFocusable(true); + mainTf.requestFocus(); } private void hideItem() { @@ -540,29 +597,29 @@ public class NavAbilitySlice extends AbilitySlice implements Animator.StateChang private void changeIc() { animatorProperty = mDrawerImage.createAnimatorProperty(); - animatorProperty.rotate(270).setDuration(200).start(); - main_search.setPixelMap(ResourceTable.Media_ic_close_black_48dp); + animatorProperty.rotate(ISTWOHUNDREDANDSEVENTY).setDuration(ISTWOHUNDRED).start(); + mainSearch.setPixelMap(ResourceTable.Media_ic_close_black_48dp); setHint(); mDrawerImage.setPixelMap(ResourceTable.Media_close); } private void changeClose() { animatorProperty = mDrawerImage.createAnimatorProperty(); - animatorProperty.rotate(180).setDuration(200).start(); - main_search.setPixelMap(ResourceTable.Media_ic_magnify_black_48dp); + animatorProperty.rotate(ISONEHUNDREDANDEIGHTY).setDuration(ISTWOHUNDRED).start(); + mainSearch.setPixelMap(ResourceTable.Media_ic_magnify_black_48dp); setGoogle(); mDrawerImage.setPixelMap(ResourceTable.Media_open); } private void setHint() { - main_tf.setText(""); + mainTf.setText(""); if (count == 0) { count++; - main_tf.setText("Hello World!"); + mainTf.setText("Hello World!"); } else { - main_tf.setHint("Search"); + mainTf.setHint("Search"); } - main_tf.setHintColor(GRAY); + mainTf.setHintColor(Color.GRAY); } @Override @@ -578,17 +635,20 @@ public class NavAbilitySlice extends AbilitySlice implements Animator.StateChang @Override public void onStart(Animator animator) { + } @Override public void onStop(Animator animator) { + } @Override public void onCancel(Animator animator) { + } - public void onEnd(Animator animator) { + public void onEnd(Animator animator) { if (mAnimatorIcon != null && animator == mAnimatorIcon) { /* * 重置动画 @@ -600,7 +660,7 @@ public class NavAbilitySlice extends AbilitySlice implements Animator.StateChang * 初始化抽屉效果动画 */ if (mAnimatorLayout == null) { - mAnimatorLayout = mDrawerLayout.createAnimatorProperty(); + mAnimatorLayout = mDrawerLayout.createAnimatorProperty(); } /* * 切换图标 @@ -609,13 +669,13 @@ public class NavAbilitySlice extends AbilitySlice implements Animator.StateChang /* * 展示抽屉导航动画 */ - mAnimatorLayout.moveFromX(-700).moveToX(0).setDuration(500); - } else { + mAnimatorLayout.moveFromX(ISSEVENHUNDRED).moveToX(0).setDuration(ISFIVEHUNDRED); + } else { mDrawerImage.setPixelMap(ResourceTable.Media_open); /* * 收起抽屉导航动画 */ - mAnimatorLayout.moveFromX(0).moveToX(-700).setDuration(500); + mAnimatorLayout.moveFromX(0).moveToX(ISSEVENHUNDRED).setDuration(ISFIVEHUNDRED); } /* * 开启动画 @@ -628,14 +688,11 @@ public class NavAbilitySlice extends AbilitySlice implements Animator.StateChang @Override public void onPause(Animator animator) { } + @Override public void onResume(Animator animator) { } - /** - ** 页面点击事件处理 - * @param component - */ @Override public void onClick(Component component) { switch (component.getId()) { @@ -644,7 +701,7 @@ public class NavAbilitySlice extends AbilitySlice implements Animator.StateChang setGoogle(); hideList(); hideItem(); - break; + break; case ResourceTable.Id_main_layout: /* * 执行抽屉导航缩起动画 @@ -653,7 +710,7 @@ public class NavAbilitySlice extends AbilitySlice implements Animator.StateChang if (mAnimatorIcon == null) { mAnimatorIcon = mDrawerImage.createAnimatorProperty(); } - mAnimatorIcon.rotate(180).setDuration(200); + mAnimatorIcon.rotate(ISONEHUNDREDANDEIGHTY).setDuration(ISTWOHUNDRED); mAnimatorIcon.setStateChangedListener(NavAbilitySlice.this); /* * 开启动画 @@ -663,16 +720,17 @@ public class NavAbilitySlice extends AbilitySlice implements Animator.StateChang } hideItem(); break; + default: } } private void showDraw() { - ly_share.setBackground(elements); - ly_send.setBackground(elements); + lyShare.setBackground(elements); + lySend.setBackground(elements); if (!isFlag) { if (mAnimatorIcon == null) { mAnimatorIcon = mDrawerImage.createAnimatorProperty(); - } + } mAnimatorIcon.setStateChangedListener(NavAbilitySlice.this); /* * 开启动画 @@ -681,11 +739,12 @@ public class NavAbilitySlice extends AbilitySlice implements Animator.StateChang setGoogle(); } else { changeClose(); - main_tf.setFocusable(0); + mainTf.setFocusable(0); } + isFlag = !isFlag; + } - isFlag = !isFlag;} - private void OnAnimatorIcon() { + private void onAnimatorIcon() { /* * 执行抽屉导航缩起动画 */ @@ -693,30 +752,32 @@ public class NavAbilitySlice extends AbilitySlice implements Animator.StateChang if (mAnimatorIcon == null) { mAnimatorIcon = mDrawerImage.createAnimatorProperty(); } - mAnimatorIcon.rotate(360).setDuration(200); + mAnimatorIcon.rotate(ISTHREEHUNDREDANDSIXTY).setDuration(ISTWOHUNDRED); mAnimatorIcon.setStateChangedListener(NavAbilitySlice.this); /* - * 开启动画 - */ + * 开启动画 + */ mAnimatorIcon.start(); isFlag = false; } } private void setGoogle() { - main_tf.setText(""); - main_tf.setHint("Google Play"); - main_tf.setHintColor(BLACK); + mainTf.setText(""); + mainTf.setHint("Google Play"); + mainTf.setHintColor(Color.BLACK); } + /** * 点击事件延时显示,用以解决不知道什么原因的toast和数值动画冲突 */ private class HandlerRunClick implements Runnable { @Override public void run() { - new ToastDialog(NavAbilitySlice.this).setContentText("Short click").setSize(DirectionalLayout.LayoutConfig.MATCH_CONTENT, DirectionalLayout.LayoutConfig.MATCH_CONTENT) + new ToastDialog(NavAbilitySlice.this).setContentText("Short click") + .setSize(DirectionalLayout.LayoutConfig.MATCH_CONTENT, DirectionalLayout.LayoutConfig.MATCH_CONTENT) .setAlignment(LayoutAlignment.BOTTOM | LayoutAlignment.HORIZONTAL_CENTER) - .setOffset(0, 60).show(); + .setOffset(0, IS_SIXTY).show(); } } } diff --git a/entry/src/main/resources/base/layout/ability_nav.xml b/entry/src/main/resources/base/layout/ability_nav.xml index ec423693b230c2ab6f61cee7c5f6777820923c26..a94fb0fb09c5a6631c81808881f2d6524a9b131b 100644 --- a/entry/src/main/resources/base/layout/ability_nav.xml +++ b/entry/src/main/resources/base/layout/ability_nav.xml @@ -28,17 +28,17 @@ + ohos:start_margin="20"/> + ohos:text_weight="500"/> - + ohos:scale_mode="zoom_center"> @@ -125,8 +123,7 @@ ohos:end_margin="20" ohos:top_margin="-650" ohos:layout_alignment="right" - ohos:visibility="invisible" - /> + ohos:visibility="invisible"/> - + ohos:background_element="#fff"> - - - + ohos:width="match_parent"> + + + + + + - + - \ No newline at end of file + \ No newline at end of file diff --git a/library/build.gradle b/library/build.gradle index 115ec9dab4917734bb2e858c3797e205259e0bf5..0dcb4e0b1a4c454ccfdcae15d6b72c2a59776518 100644 --- a/library/build.gradle +++ b/library/build.gradle @@ -1,4 +1,11 @@ apply plugin: 'com.huawei.ohos.library' +apply from: '../upload.gradle' +rootProject.ext { + DEFAULT_GROUP_ID = 'com.gitee.chinasoft_ohos' + DEFAULT_ARTIFACT_ID = "MaterialSearchBar" + DEFAULT_VERSION = '0.0.1-SNAPSHOT' +} + ohos { compileSdkVersion 5 defaultConfig {