6 Star 4 Fork 2

HarmonyOS-TPC / material-dialogs

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

MaterialDialogs

Introduction

Material Dialog is a combination of various types of dialog supported by openharmony APIs. It has approx all the UI components with multiple test cases which includes dialog with Text, Image, Buttons, ListContainer items, Color Palette, Custom Views & Progressbar.

Usage Instructions:

Core The core module contains everything you need to get started with the library. It contains all core and normal-use functionality. dependencies { ... implementation 'com.afollestad.material-dialogs:core:3.2.1' }

  • Basics Here's a very basic example of creating and showing a dialog:

      new MaterialDialog.Builder(this)
        .content(ResourceTable.String_shareLocationPrompt)
        .positiveText(ResourceTable.String_agree)
        .negativeText(ResourceTable.String_disagree)
        .show();

    this should be a Context which is attached to a window, like an Ability.

  • Action Buttons There are simple methods for adding action buttons:

      new MaterialDialog.Builder(this)
         .title(ResourceTable.String_useGoogleLocationServices)
         .content(ResourceTable.String_useGoogleLocationServicesPrompt)
         .positiveText(ResourceTable.String_agree)
         .negativeText(ResourceTable.String_disagree)
         .show();

    If action buttons together are too long to fit in the dialog's width, they will be automatically stacked:

  • Adding an Icon You can display an icon to the left of the title:

      new MaterialDialog.Builder(this)
        .icon(ResourceTable.Media_ic_launcher)
        .limitIconToDefaultSize()
        .title(ResourceTable.String_useGoogleLocationServices)
        .content(ResourceTable.String_useGoogleLocationServicesPrompt)
        .positiveText(ResourceTable.String_agree)
        .negativeText(ResourceTable.String_disagree)
        .show();
  • Callbacks There are a few lifecycle callbacks you can hook into: new MaterialDialog.Builder(this) .title(ResourceTable.String_useGoogleLocationServices) .content(ResourceTable.String_useGoogleLocationServicesPrompt) .positiveText(ResourceTable.String_agree) .negativeText(ResourceTable.String_disagree) .neutralText(ResourceTable.String_more_info) .showListener(dialog -> showToast("onShow")) .cancelListener(dialog -> showToast("onCancel")) .dismissListener(dialog -> showToast("onDismiss")) .show();

List The List test cases are having multiple test cases which has single & multi choice list.

  • Plain You can show lists using the listItems extension on MaterialDialog:

      new MaterialDialog.Builder(this)
      	.title(ResourceTable.String_socialNetworks)
          .items(new String[]{"Twitter", "Google", "Instagram", "Facebook"})
          .itemsCallback((dialog, view, which, text) -> showToast(which + ": " + text))
          .show();
  • Single Choice You can show single choice (radio button) lists using the listItemsSingleChoice extension on MaterialDialog:

     new MaterialDialog.Builder(this)
     	.title(ResourceTable.String_socialNetworks)
         .items(new String[]{"Twitter", "Google", "Instagram", "Facebook"})
         .itemsDisabledIndices(1, 3)
         .itemsCallbackSingleChoice(2, (dialog, view, which, text) -> {
         	showToast(which + ": " + text);
             return true; // allow selection
         })
         .positiveText(ResourceTable.String_md_choose_label)
         .show();
  • Multiple Choice You can show multiple choice (checkbox) lists using the listItemsMultiChoice extension on MaterialDialog:

      new MaterialDialog.Builder(this)
      	.title(ResourceTable.String_socialNetworks)
          .items(new String[]{"Twitter", "Google", "Instagram", "Facebook"})
          .itemsCallbackMultiChoice(
          	new Integer[]{1, 3},
              (dialog, which, text) -> {
              	StringBuilder str = new StringBuilder();
                  for (int i = 0; i < which.length; i++) {
                  	if (i > 0) {
                      	str.append('\n');
                      }
                      str.append(which[i]);
                      str.append(": ");
                      str.append(text[i]);
              	}
              	showToast(str.toString());
                  return true; // allow selection
          })
          .onNeutral((dialog, which) -> dialog.clearSelectedIndices(true))
          .onPositive((dialog, which) -> dialog.hide())
          .alwaysCallMultiChoiceCallback()
          .positiveText(ResourceTable.String_md_choose_label)
          .autoDismiss(false)
          .neutralText(ResourceTable.String_clear_selection)
          .show();
  • Custom Adapters If you want to customize lists to use your own views, you need to use a custom adapter. final ButtonItemAdapter buttonItemAdapter = new ButtonItemAdapter(this, new String[]{"Twitter", "Google", "Instagram", "Facebook"}); buttonItemAdapter.setCallbacks( itemIndex -> showToast("Item clicked: " + itemIndex), buttonIndex -> showToast("Button clicked: " + buttonIndex)); new MaterialDialog.Builder(this).title(ResourceTable.String_socialNetworks).baseItemProvider(buttonItemAdapter).show();

Checkbox Prompts Checkbox prompts can be used together with any other dialog type, it gets shown in the same view which shows the action buttons.

new MaterialDialog.Builder(this)
	.icon(ResourceTable.Media_ic_launcher)
    .limitIconToDefaultSize()
    .title(ResourceTable.String_permissionSample)
    .positiveText(ResourceTable.String_allow)
    .negativeText(ResourceTable.String_deny)
    .onAny((dialog, which) -> showToast("Prompt checked? " + dialog.isPromptCheckBoxChecked()))
   	.checkBoxPrompt(ResourceTable.String_dont_ask_again, false, new AbsButton.CheckedStateChangedListener() {
    	@Override
        public void onCheckedChanged(AbsButton absButton, boolean checked) {
        	if (checked) {
            	setAbsButtonBackgroundElement(absButton, ResourceTable.Media_abc_btn_check_to_on_mtrl_015);
            } else {
            	setAbsButtonBackgroundElement(absButton, ResourceTable.Media_abc_btn_check_to_on_mtrl_000);
            }
        }
    })
    .show();

Custom Views A lot of the included extensions use custom views, such as the color chooser dialog. There's also a simple example in the sample project.

case ResourceTable.Id_customView:
	showCustomView();
break;

Progress In this module we have progressbar test case with horizintal & circular progressbar execution.

Input The input module contains extensions to the core module, such as a text input dialog.

Color The color module contains extensions to the core module, such as a color chooser. This test case will help us to change the navigation & status bar color using selected color from the palatte. We can also change the color from the custom color section which has SeekBar to change the ARGB color.

  • Basics Color choosers show a simple grid of colors.

      new ColorChooserDialog.Builder(this, ResourceTable.String_color_palette)
      	.titleSub(ResourceTable.String_colors)
      	.preselect(primaryPreselect)
      	.show();
  • Sub Colors You can specify sub-colors, which are a level down from each top level color. The size of the top level array must match the size of the sub-colors array.

  • ARGB Selection

DateTime The datetime module contains extensions to make date, time, and date-time picker dialogs.

	MaterialDialog dialog = new MaterialDialog.Builder(this)
		.title(ResourceTable.String_date_picker)
    	.customView(ResourceTable.Layout_dialog_datepicker, false)
    	.positiveText(ResourceTable.String_ok)
    	.negativeText(ResourceTable.String_cancel)
    	.build();
	DatePicker datePicker = (DatePicker) dialog.getCustomView().findComponentById(ResourceTable.Id_datePicker);
	datePicker.setDateOrder(DatePicker.DateOrder.DMY);
	dialog.show();

Files The files module contains extensions to the core module, such as a file and folder chooser. Using this test case we can select file & folder from the local storage.

new FolderChooserDialog.Builder(this)
	.chooseButton(ResourceTable.String_md_choose_label)
    .allowNewFolder(true, 0)
    .show();

Installation instructions

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 gradle: implementation fileTree (dir: 'libs', include: ['.jar', '.har'])

Method 2: allprojects{ repositories{ mavenCentral() } } implementation 'io.openharmony.tpc.thirdlib:material-dialogs:1.0.2'

The MIT License (MIT) Copyright (c) 2014-2016 Aidan Michael Follestad Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

Material Dialog is a combination of various types of dialog supported by openharmony APIs. 展开 收起
Java
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/HarmonyOS-tpc/material-dialogs.git
git@gitee.com:HarmonyOS-tpc/material-dialogs.git
HarmonyOS-tpc
material-dialogs
material-dialogs
main

搜索帮助