Skip to content

Latest commit

 

History

History
300 lines (260 loc) · 11 KB

SldingDrawer.md

File metadata and controls

300 lines (260 loc) · 11 KB

How to use SlidingDrawer Library for HarmonyOS: A developer’s Guide

1. Introduction

SlidingDrawer hides content out of the screen and allows the user to drag a handle to bring the content on screen. SlidingDrawer can be used vertically or horizontally. A special widget composed of two children views: the handle, that the users drags, and the content, attached to the handle and dragged with it. SlidingDrawer should be used as an overlay inside layouts. This means SlidingDrawer should only be used inside of a FrameLayout or a RelativeLayout for instance. The size of the SlidingDrawer defines how much space the content will occupy once slid out so SlidingDrawer should usually use match_parent for both its dimensions

2. Typical Use Cases

This library - hollowsoft.demo.slidingdrawer, is very useful in the development of applications which are in our daily use. Some of such examples mentioned below:

  • Banking
    Internet Banking, is an electronic payment system
  • ImageEditior
    Images to be edited and also converted to different graphics formats

Italian Trulli

Italian Trulli

3. Capability

In this section, we can see the list of features which the library provides which makes the use of this library very easy and friendly. Primarily, this library supports customization of component attributes using the below mechanism.

  • Java APIs
    SlidingDrawer uses a simple fluent java API's that allows users to make most requests in a single line:

4. Features

Features supported by this component includes the below:

  • Sliding Drawer Via Java & XML:
    Sliding Drawer Should be created with the handle and content Components along with given Height/Width and background inputs

  • Customizing the Handle:
    Sliding Drawer should be created and the Handle should be customized with text view and Background color on it.

  • Customizing the Content:
    Sliding Drawer should be created and the Content should be customized with you can add multiple views on it.

  • Supports Animate open & Animate Close:
    Sliding Drawer should be created and can be able to open and close the drawer by clicking on the handle

  • Supports Call back functions:
    Sliding Drawer should be created and should be able to open and close the drawer with Listeners

  • Sliding Horizontal and Vertical:
    Sliding Drawer should be created and should be able to slide the drawer Vertically and Horizontally.

5. Installation

For using the library in your HarmonyOS mobile app, you need to first install it by following below methods.

  • Method 1:
    Generate the .har package through the library and add the .har package to the libs folder.Add the following code to the entry level build.gradle:
         
      implementation fileTree  (dir: 'libs', include: ['* .jar', '* .har'])
         
    
  • Method 2 :
    Copy the dependency from the gitee and add it to the entry level build.gradle:
dependencies {
    implementation fileTree(dir: 'libs', include: ['*.har'])
    implementation 'io.openharmony.tpc.thirdlib:SlidingDrawer:1.0.2'
           }

6. Usage

This section will help us to understand the usage of the library as you use it in your Harmony-application developemnt project.

Step 1: Define layout via XML

We are going to load list into SlidingDrawer component using This Library. So, add SlidingDrawer component into resource_file.xml file.

    <?xml version="1.0" encoding="utf-8"?>
    <DirectionalLayout
        xmlns:ohos="http://schemas.huawei.com/res/ohos"
        xmlns:app="http://schemas.huawei.com/hap/res-auto"
        ohos:height="match_parent"
        ohos:width="match_parent"
        ohos:orientation="vertical"
        ohos:background_element="#000000">
            
        <hollowsoft.slidingdrawer.SlidingDrawer
        ohos:id="$+id:slide" xmlns:ohos="http://schemas.huawei.com/res/ohos"
        ohos:height="match_parent"
        ohos:width="match_content"
        ohos:orientation="horizontal">
       <Component ohos:width="100vp"
               ohos:height="100vp"
               ohos:text="Click"
               ohos:id="$+id:handle"
               ohos:background_element="#EB00FF"/>      
	 </hollowsoft.slidingdrawer.SlidingDrawer>

    </DirectionalLayout>

Step 2: Customize programmatically via Java API

   @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
       SlidingDrawer drawer1 = (SlidingDrawer) findComponentById(ResourceTable.Id_slide);
        drawer1.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                drawer1.animateOpen();
            }
        });

        PositionLayout drawerMain = (PositionLayout) findComponentById(ResourceTable.Id_main);
        SlidingDrawer drawer = new SlidingDrawer(this);
        drawer.setOrientation(Component.VERTICAL);
        Component viewHandle = new Component(this);
        PositionLayout.LayoutConfig drawerConfig = new DirectionalLayout.LayoutConfig(100, 200);
        viewHandle.setLayoutConfig(drawerConfig);
        drawer.setHandle(viewHandle);

    }

List of public APIs for app-developer

The public methods below will help us to operate on the component at runtime.

SlidingDrawer Methods

  • open()
  • animateOpen()
  • animateOpen()
  • onDraw(Component component, Canvas canvas)()
  • close()
  • animateClose()
  • setHandle(Component handle)
  • setHolder(Component holder)
  • animate(final float position, int time)
  • setOnDrawerOpenListener(OnDrawerOpenListener onDrawerOpenListener)
  • setOnDrawerCloseListener(OnDrawerCloseListener onDrawerCloseListener)
  • setOnDrawerScrollListener(OnDrawerScrollListener onDrawerScrollListener)
  • getCurrentPosition
  • scrollLock()
  • scrollUnlock()
  • updateBounds()
  • setHolder(Component holder)()
  • close()

8. API usage examples

In this section, we can have a look at some the examples where the APIs of this library is put to use and the results which we can acheive.

Example1: Sliding with Customizing the Content

Layout.xml:
<hollowsoft.slidingdrawer.SlidingDrawer
        ohos:id="$+id:slide"
        ohos:height="match_parent"
        ohos:width="match_content"
        ohos:orientation="horizontal"
 <Text
    ohos:id="$+id:text_helloworld"
    ohos:height="match_parent"
    ohos:width="match_content" 
    ohos:multiple_lines="true"
    ohos:text="Hi SlidingDrawer"
    ohos:text_size="23fp" >

Java Slice:
  SlidingDrawer drawer = new SlidingDrawer(this);
   DirectionalLayout viewHandle = new DirectionalLayout(this);
PositionLayout.LayoutConfig l =
 new DirectionalLayout.LayoutConfig(200, 200);
viewHandle.setLayoutConfig(l);
 drawer.setHandle(viewHandle);
   ShapeElement dynamic = new ShapeElement();
  dynamic.setRgbColor(RgbColor.fromArgbInt(0xFFD52828));
   viewHandle.setBackground(dynamic);
        

Italian Trulli

Example2: SlidingDrawer With Support Callback

Layout.xml:
<hollowsoft.slidingdrawer.SlidingDrawer
        ohos:id="$+id:slide"
        ohos:height="match_parent"
        ohos:width="match_content"
        ohos:orientation="horizontal">

Java Slice:
SlidingDrawer drawer = new SlidingDrawer(this);
 DirectionalLayout viewHandle =
 new DirectionalLayout(this);
PositionLayout.LayoutConfig l =
 new DirectionalLayout.LayoutConfig(200, 200);
 viewHandle.setLayoutConfig(l);
 drawer.setHandle(viewHandle);
 ShapeElement dynamic = new ShapeElement();
 dynamic.setRgbColor(RgbColor.fromArgbInt(0xff00ff5e));
 viewHandle.setBackground(dynamic);;
 drawer.setOnDrawerOpenListener(this);
        drawer.setOnDrawerCloseListener(this);
        drawer.setOnDrawerScrollListener(this); 
        

Italian Trulli

Example3: SlidingDrawer with Customizing the Handle**

Layout.xml:
<hollowsoft.slidingdrawer.SlidingDrawer
        ohos:id="$+id:slide"
        ohos:height="match_parent"
        ohos:width="match_content"
        ohos:orientation="horizontal"
	<Image
        ohos:height="70vp"
        ohos:width="match_parent"
        ohos:background_element="$media:handle">

Java Slice:
 SlidingDrawer drawer = new SlidingDrawer(this);
  DirectionalLayout viewHandle = 
  new DirectionalLayout(this);
 PositionLayout.LayoutConfig l
 = new DirectionalLayout.LayoutConfig(200, 200);
 viewHandle.setLayoutConfig(l);
 drawer.setHandle(viewHandle);
 ShapeElement dynamic = new ShapeElement();
 dynamic.setRgbColor(RgbColor.fromArgbInt(0xFFD52828));
 viewHandle.setBackground(dynamic);
 ////Customizing handle with image
    Image image = new Image(this);
    image.setPixelMap(ResourceTable.Media_arrow_icon);
    viewHandle.setOrientation(Component.VERTICAL);
    viewHandle.addComponent(image);
        

Italian Trulli

9. Conclusion

SlidingDrawer is a very easy to use and very powerful library.The performance of the library is very good even when it works on one of the latest operating systems in the world, which is HarmonyOS!

  • For more exciting libraries to develop your app, peep into third-party-components at
    OpenHarmony-TPC

  • To know more about the developement work happening on harmony aaplication layer, and even be part of the exciting stuff, watch this space of Application Library Engineering Group