A powerful Gradle Plugin to help you demonstrate your android app

Overview

English | 简体中文

sample-gradle-plugin

version license

🚀 A powerful Gradle Plugin to help you demonstrate your android app.

We often write demo applications that contain a lot of template code, such as lists of different demo cases, jump logic, application permissions and fake data, and more.

SamplePlugin provides various components through annotations and automatically generates this template code so that people viewing the demo application can understand the application more easily.

Download the sample apk to see more: Sample APK.

Minimal supported versions

Due to limited effort, SamplePlugin is currently supported up to version 7.x:

Setup

  1. Add the following code to the root project build.gradle.kts file:
" apply false }">
plugins {
  id("com.airsaid.sample") version "" apply false
}
  1. Add the following code to the android application project (app by default) build.gradle.kts file:
") }">
plugins {
  id("com.airsaid.sample")
}

dependencies {
  implementation("com.airsaid:sample-extension:")
}
Old setup method
  1. Add the following code to the root project build.gradle.kts file:
") } }">
buildscript {
  dependencies {
    classpath("com.airsaid:sample-gradle:")
  }
}
  1. Add the following code to the android application project (app by default) build.gradle.kts file:
") }">
plugins {
  id("com.airsaid.sample")
}

dependencies {
  implementation("com.airsaid:sample-extension:")
}

How to use

Register as an example by adding the @Register annotation to the activity or fragment class ( or other supported component) for which the example code is written. For example:

@Register
class DemoFragment : Fragment() {
  ...
}

Then we run the application and we can see that the example we just registered has appeared in the automatically generated list.

By default, the title of each example item in the list is the class name of the example. If you want to change the title or add a description, you can add the title and desc attributes to the annotation. For example:

@Register(title = "Demo", desc = "Demonstrate how to use.")
class DemoFragment : Fragment() {
  ...
}

For the case of multiple examples, we organize the relationship between the examples by package name.

For example, suppose this is the structure of your project:

com.airsaid.demo.fragment
    FragmentDemo1.kt
    FragmentDemo2.kt
com.airsaid.demo.ui
    ViewDemo1.kt
    ViewDemo2.kt

The result of the automatic generation of the demo list is:

|-- fragment
  |-- FragmentDemo1
  |-- FragmentDemo2
|-- ui
  |-- ViewDemo1
  |-- ViewDemo2

That's all, You don't need to do anything. Or you can specify it manually using the path attribute of the @Register annotation. For example:

@Register(path = "android/view")
class DemoFragment : Fragment() {
  ...
}

Working with testcase

Imagine you have a vast demonstration app, and finding one demo is hard. So you may want to open it directly whenever you launch your app.

The solution is to use the @TestCase annotation, which specifies a test case that will be automatically opened when you start the application. In the case of specifying multiple test cases, a dialog will alert for you to select:

@TestCase
@Register
class DemoFragment : Fragment() {
  ...
}

Working with extension

We provide a number of extension annotations to easily add additional demos to the sample.

For example, When you use @SampleSourceCode, it will help you generate a ViewPager and put your source code as a list:

@SampleSourceCode
@Register
class DemoFragment : Fragment() {
  ...
}

Currently, the sample framework itself provides the following extension annotations. Or you can extend it yourself, as seen in the sample application.

@SampleDocument

Display the related document. For example:

// You can specify the documents in the assets directory:
@SampleDocument("assets://sample_document.md")
// Or you can set up an online documentation address:
// @SampleDocument("https://raw.githubusercontent.com/Airsaid/sample-gradle-plugin/master/README.md")
// Or you can specify documents in any directory, e.g. under the same level as the current class:
// @SampleDocument("sample_document.md")
@Register(
  title = "SampleDocument",
  desc = "Use @SampleDocument to associate documents to sample."
)
class SampleDocumentFragment : Fragment() {
  ...
}

@SampleSourceCode

Display the source file. For example:

// By default, all source classes of the package where the current class is located are displayed.
@SampleSourceCode
// Or you can use regular expressions that filter only the required classes:
// @SampleSourceCode("SampleSourceCodeFragment.kt")
@Register(
  title = "SampleSourceCode",
  desc = "Use @SampleSourceCode to associate source code to sample."
)
class SampleSourceCodeFragment : Fragment() {
  ...
}

@SampleMessage

Display the test message. For example:

@SampleMessage
@Register(
  title = "SampleMessage",
  desc = "Use @SampleMessage to take the messages output by System.out " +
      "and display them on the page."
)
class SampleMessageFragment : Fragment() {
  ...
}

@SampleMemory

Display the runtime memory. For example:

@SampleMemory
@Register(
  title = "SampleMemory",
  desc = "Use @SampleMemory to quickly see the current memory usage on the page."
)
class SampleMemoryFragment : Fragment() {
  ...
}

@SamplePermission

Automatically request specified permissions. For example:

if (result.granted) { Toast.makeText(context, "${result.name} Permission request successful!", Toast.LENGTH_SHORT) .show() } else { Toast.makeText(context, "${result.name} Permission request failed!", Toast.LENGTH_SHORT) .show() } } } ... }">
@SamplePermission(
  Manifest.permission.CAMERA,
  Manifest.permission.READ_EXTERNAL_STORAGE
)
@Register(
  title = "SamplePermission",
  desc = "Use @SamplePermission and specify the permissions to be requested to " +
      "automatically request permissions when the page is first opened."
)
class SamplePermissionFragment : Fragment() {

  override fun onActivityCreated(savedInstanceState: Bundle?) {
    super.onActivityCreated(savedInstanceState)
    addPermissionObserver { result ->
      if (result.granted) {
        Toast.makeText(context, "${result.name} Permission request successful!", Toast.LENGTH_SHORT)
          .show()
      } else {
        Toast.makeText(context, "${result.name} Permission request failed!", Toast.LENGTH_SHORT)
          .show()
      }
    }
  }
  ...
}

Project structure

  • app: the demo app.
  • sample-api: common api for both library and plugin.
  • sample-core: the core library. Support for core APIs such as the base action processor.
  • sample-extension: the extension library. Based on the core library, it provides all kinds of extended functions.
  • sample-plugin: GradlePlugin for collecting annotation information at compile time and modifying bytecode files.

License

Copyright 2022 Airsaid. https://github.com/airsaid

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.
You might also like...
GPP is Android's unofficial release automation Gradle Plugin. It can do anything from building, uploading, and then promoting your App Bundle or APK to publishing app listings and other metadata.
GPP is Android's unofficial release automation Gradle Plugin. It can do anything from building, uploading, and then promoting your App Bundle or APK to publishing app listings and other metadata.

Gradle Play Publisher Gradle Play Publisher is Android's unofficial release automation Gradle Plugin. It can do anything from building, uploading, and

A plugin for Jetbrains IDE, Your code is powerful, unleash it like playing osu!

Osu! Mode A plugin for Jetbrains IDE, Your code is powerful, unleash it like playing osu! Demo 2021-10-15.18-50-30.mp4 Bilibili Feature open project /

 Gradle plugin which downloads and manages your Android SDK.
Gradle plugin which downloads and manages your Android SDK.

DEPRECATED This plugin is deprecated and is no longer being developed. Tools and dependencies are automatically downloaded using version 2.2.0 of the

A Gradle plugin to report the number of method references in your APK on every build.
A Gradle plugin to report the number of method references in your APK on every build.

Dexcount Gradle Plugin A Gradle plugin to report the number of method references in your APK, AAR, or java module. This helps you keep tabs on the gro

An Android Studio / IntelliJ plug-in help you upload your apk or listing to Google Play.

DroidLane An Android Studio / IntelliJ plug-in help you upload your apk or listing to Google Play. Installation Open Android Studio or IntelliJ IDEA O

IntelliJ plugin that provides a modern and powerful byte code analyzer tool window.
IntelliJ plugin that provides a modern and powerful byte code analyzer tool window.

IntelliJ Byte Code Analyzer Plugin This IntelliJ plugin provides a modern and powerful byte code analyzer tool window. Its supports Java, Kotlin, Groo

K6-intellij-plugin - IntelliJ-based Plugin to run k6 tests locally or in the k6 Cloud from your IntelliJ IDE
K6-intellij-plugin - IntelliJ-based Plugin to run k6 tests locally or in the k6 Cloud from your IntelliJ IDE

IntelliJ-based Plugin to run k6 tests locally or in the k6 Cloud from your Intel

This is an android studio plugin that allows you to creates new color in hex format based on a percentage (0-100) and a base color you specify.

alpha-color Description This is an android studio plugin that allows you to creates new color in hex format based on a percentage (0-100) and a base c

A Gradle plugin to support the Groovy language for building Android apps

Groovy language support for Android Deprecated: This plugin has been deprecated in favor of Kotlin which has the full support of JetBrains and Google.

Comments
Releases(v1.1.2)
Owner
Yoo Zhou
Senior Software Engineer, with a focus on Android.
Yoo Zhou
gradle-android-scala-plugin adds scala language support to official gradle android plugin

gradle-android-scala-plugin gradle-android-scala-plugin adds scala language support to official gradle android plugin. See also sample projects at htt

saturday06 345 Dec 10, 2022
Ownership-gradle-plugin - Gradle code ownership verification plugin

Gradle code ownership verification plugin A gradle plugin that will verify owner

null 4 Dec 15, 2022
Helper to upload Gradle Android Artifacts, Gradle Java Artifacts and Gradle Kotlin Artifacts to Maven repositories (JCenter, Maven Central, Corporate staging/snapshot servers and local Maven repositories).

GradleMavenPush Helper to upload Gradle Android Artifacts, Gradle Java Artifacts and Gradle Kotlin Artifacts to Maven repositories (JCenter, Maven Cen

 Vorlonsoft LLC 21 Oct 3, 2022
Gradle plugin to help use create project

Infra-Gradle-Plugin 该插件旨在简化 Gradle 项目配置,几行代码就可以迅速开始一个项目, 仅支持 Kotlin DSL, Groovy 未测试! 引入插件 plugins { id("com.labijie.infra") version "your version"

Red Sparrow 0 Dec 23, 2021
Add a different ribbon to each of your Android app variants using this gradle plugin. Of course, configure it as you will

Easylauncher gradle plugin for Android Modify the launcher icon of each of your app-variants using simple gradle rules. Add ribbons of any color, over

Mikel 960 Dec 18, 2022
This plugin help you to set material design icon to your project.

Android Material Design Icon Generator Plugin This plugin help you to set material design icons to your Android project. Installation Manually Downloa

Yusuke Konishi 2.4k Dec 30, 2022
Gradle plugin which helps you analyze the size of your Android apps.

Ruler Ruler is a Gradle plugin which helps you analyze the size of your Android apps. Motivation App size is an important metric which directly correl

Spotify 913 Dec 28, 2022
Gradle plugin which validates the licenses of your dependency graph match what you expect

Licensee ?? ?? A Gradle plugin which validates the licenses of your dependency graph match what you expect, or it fails your build! Jump to: Introduct

Cash App 506 Jan 8, 2023
A Gradle plugin for providing your secrets to your Android project.

Secrets Gradle Plugin for Android A Gradle plugin for providing your secrets securely to your Android project. This Gradle plugin reads secrets from a

Google 560 Jan 8, 2023