# SwipeBackLayout **Repository Path**: baijuncheng-open-source/SwipeBackLayout ## Basic Information - **Project Name**: SwipeBackLayout - **Description**: No description available - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-06-01 - **Last Updated**: 2021-07-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # SwipebackLayout **Harmony library to use different SwipeBackLayout.** How to include it in your project: Solution 1: Local HAR package integration Add the HAR(SwipeBackLayout-debug.har) package to the lib folder Add the following code to gradle of Entry implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) Solution 2: remote maven repo integration Add the following code in the entry's gradle implementation 'com.gitee.baijuncheng-open-source:SwipeBackLayout:1.0.0' SwipeBackLayout available are: >1.Start new activity! >2.Finish Activity >3.Left >4.Right >5.Bottom >6.All ## Screenshot ![输入图片说明](https://images.gitee.com/uploads/images/2021/0705/175229_0bc55d20_8230582.gif "swipe_back.gif") ![输入图片说明](https://images.gitee.com/uploads/images/2021/0604/175858_cc3f7b90_8230582.png "left.png") ![输入图片说明](https://images.gitee.com/uploads/images/2021/0604/175919_5e561b1c_8230582.png "right.png") ![输入图片说明](https://images.gitee.com/uploads/images/2021/0604/175930_415c0912_8230582.png "bottom.png") ![输入图片说明](https://images.gitee.com/uploads/images/2021/0604/175941_4168b029_8230582.png "all.png") ## Using styledDialos Library in your application ### Solution 1: local source code integration, users can customize base on the source code 1.Copy library folders to the project directory; 2.Modify project settings.gradle, add dependencies on three modules as follows: ``` include ':samples', ':library' ``` 3.Introduce the dependency of imported module in the project. Take the entry module as an example, you need to modify the dependency of imported module in the entry module build.gradle file to add dependencies: dependencies { implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) testImplementation 'junit:junit:4.13' implementation project(path: ':library') ohosTestImplementation 'com.huawei.ohos.testkit:runner:1.0.0.100' } ### Solution 2: local har package integration 1.Compile the project and copy the har package generated in the build directory of folder library to the project lib folder 2.Add the following code in gradle of entry ``` implementation fileTree(dir: 'libs', include: ['*.jar', '*.har']) ``` ### Solution 3: remote maven repo integration The lib is available on Maven Central, you can find it with [Gradle, please] ```xml dependencies { implementation 'com.gitee.baijuncheng-open-source:SwipeBackLayout:1.0.0' } ``` ## Sample usage ``` public void onStart(Intent intent) { super.onStart(intent); setUIContent(ResourceTable.Layout_activity_demo); findViews(); changeActionBarColor(); mSwipeBackLayout = (SwipeBackLayout) findComponentById(ResourceTable.Id_SwipeBackLayout); setSwipeBackLayout(mSwipeBackLayout); mTrackingModeGroup.mark(checked); mSwipeBackLayout.setEdgeTrackingEnabled(edgeFlag); mTrackingModeGroup.setMarkChangedListener(new RadioContainer.CheckedStateChangedListener() { @Override public void onCheckedChanged(RadioContainer radioContainer, int index) { HiLog.info(LABEL, "onCheckedChanged"); switch (index) { case 0: edgeFlag = SwipeBackLayout.EDGE_LEFT; checked = 0; break; case 1: edgeFlag = SwipeBackLayout.EDGE_RIGHT; checked = 1; break; case 2: edgeFlag = SwipeBackLayout.EDGE_BOTTOM; checked = 2; break; default: edgeFlag = SwipeBackLayout.EDGE_ALL; checked = 3; } mSwipeBackLayout.setEdgeTrackingEnabled(edgeFlag); } }); } private void changeActionBarColor() { mToolbar.setBackground(getColors()[mBgIndex]); mBgIndex++; if (mBgIndex >= getColors().length) { mBgIndex = 0; } } private void findViews() { mToolbar = (Text) findComponentById(ResourceTable.Id_mToolbar); mStart = (Button) findComponentById(ResourceTable.Id_btn_start); mfinish = (Button) findComponentById(ResourceTable.Id_btn_finish); right_title_image = (Image) findComponentById(ResourceTable.Id_right_title_image); mStart.setClickedListener(this); mfinish.setClickedListener(this); right_title_image.setClickedListener(this); mTrackingModeGroup = (RadioContainer) findComponentById(ResourceTable.Id_tracking_mode); } private Element[] getColors() { if (mBgColors == null) { mBgColors = new Element[] { AttrHelper.convertValueToElement("#33B5E5"), AttrHelper.convertValueToElement("#AA66CC"), AttrHelper.convertValueToElement("#99CC00"), AttrHelper.convertValueToElement("#FFBB33"), AttrHelper.convertValueToElement("#FF4444"), }; } return mBgColors; } @Override public void onClick(Component component) { HiLog.info(LABEL, "onClick"); switch (component.getId()) { case ResourceTable.Id_btn_start: HiLog.info(LABEL, "onClick:Id_btn_start" + ResourceTable.Id_btn_start); Intent intent = new Intent(); // 指定待启动FA的bundleName和abilityName Operation operation = new Intent.OperationBuilder() .withBundleName("me.imid.swipebacklayout.demo.samples") .withAbilityName("me.imid.swipebacklayout.demo.samples.MainAbility") .build(); intent.setOperation(operation); // 通过AbilitySlice的startAbility接口实现启动另一个页面 startAbility(intent); break; case ResourceTable.Id_btn_finish: HiLog.info(LABEL, "onClick:Id_btn_finish" + ResourceTable.Id_btn_finish); scrollToFinishActivity(); //terminateAbility(); break; case ResourceTable.Id_right_title_image: HiLog.info(LABEL, "onClick:Id_right_title_image" + ResourceTable.Id_btn_finish); onCreateOptionsMenu(); mMenuDialog.show(); break; } } // menu public void onCreateOptionsMenu() { if (mMenuDialog != null) { return; } Component menu = LayoutScatter.getInstance(getContext()).parse(ResourceTable.Layout_menu, null, false); Text github = (Text) menu.findComponentById(ResourceTable.Id_github); github.setClickedListener(new Component.ClickedListener() { @Override public void onClick(Component component) { Intent i = new Intent(); i.setUri(Uri.parse("https://gitee.com/baijuncheng-open-source/SwipeBackLayout")); startAbility(i); mMenuDialog.remove(); mMenuDialog = null; //remove()失效 } }); mMenuDialog = new PopupDialog(MainAbility.this, right_title_image); mMenuDialog.setCustomComponent(menu); mMenuDialog.showOnCertainPosition(LayoutAlignment.TOP,400,150); mMenuDialog.setDialogListener(new BaseDialog.DialogListener() { @Override public boolean isTouchOutside() { mMenuDialog.remove(); mMenuDialog = null; //remove()失效 HiLog.info(LABEL, "onCreateOptionsMenu:isTouchOutside"); return false; } }); mMenuDialog.registerRemoveCallback(new BaseDialog.RemoveCallback() { @Override public void onRemove(IDialog iDialog) { HiLog.info(LABEL, "mMenuDialog is remove:registerRemoveCallback"); } }); } ``` ## Change Log ## [1.0.0] - May , 2021 * 增加SwipeBackLayout demo; ## License ``` Copyright 2013 Isaac Wang 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 ``` >Todo: Add documentation.