Skip to content
프로젝트

소개

VoronoiView는 Voronoi 다이어그램 영역 안에 뷰를 추가하고 표시할 수 있는 뷰(ViewGroup)입니다.

디자인 및 미디어

이 수치를 측정하는 방법

측정된 스타 증가

in 24h
0
in 7 days
0
in 15 days
+1
in 1 month
기록 수집 중

서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.

README.md

Original

Vorolay

Vorolay is an Android ViewGroup that clips each child view to a cell of a Voronoi diagram. The library has no runtime dependencies and declares a minimum SDK of 17 (Android 4.2).

A simple Voronoi diagram Border controls in the demo app List items with Voronoi backgrounds Photos clipped to Voronoi cells

Install from source

With JDK 17 and Android SDK Platform 36 installed, publish the library to your local Maven repository from the Vorolay checkout. On Windows, use ./gradlew.bat in place of ./gradlew.

./gradlew :vorolay:publishReleasePublicationToMavenLocal

In your app project's settings.gradle.kts, add mavenLocal() to dependencyResolutionManagement.repositories. The content filter limits lookup in this repository to Vorolay.

dependencyResolutionManagement {
    repositories {
        mavenLocal {
            content { includeModule("com.github.Quatja", "vorolay") }
        }
        google()
        mavenCentral()
    }
}

Add the dependency to your app module's build.gradle.kts.

dependencies {
    implementation("com.github.Quatja:vorolay:1.1.0")
}

To build the library with your app, include the vorolay directory as a Gradle module named :vorolay, declare the com.android.library plugin in your root build, and use implementation(project(":vorolay")).

Quick start

Put VoronoiView in your activity layout.

<quatja.com.vorolay.VoronoiView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/voronoi"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:border_color="#FFFFFF"
    app:generation_type="ordered" />

After loading the layout in your activity, add one child for each cell.

VoronoiView voronoi = findViewById(R.id.voronoi);
int[] colors = {0xFF90CAF9, 0xFFA5D6A7, 0xFFFFCC80};
for (int color : colors) {
    View child = new View(this);
    child.setBackgroundColor(color);
    voronoi.addView(child, new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
}

On API 17, call voronoi.setHardwareAccelerationEnabled(false) to use software rendering for clipping. Hardware-accelerated Canvas.clipPath() is available from API 18. Android hardware acceleration support

The diagram updates when the child list or content size changes. A child marked INVISIBLE still occupies a cell. Children marked GONE are skipped. Call refresh() to regenerate the diagram at the next layout pass.

Use setOnRegionClickListener to receive the child view and its index in the ViewGroup when the parent handles a tap. Clickable children can handle their own taps.

Customize the diagram

Set app:generation_type to random (the default), ordered to place points in a grid, or custom to supply your own points. In Java, use setGenerationType with GENERATION_TYPE_RANDOM, GENERATION_TYPE_ORDERED, or GENERATION_TYPE_CUSTOM.

XML attribute Java method Effect
app:show_border enableBorders Shows the cell borders.
app:border_color setBorderColor Sets the border color. Pass an Android color integer in Java.
app:border_width setBorderWidth Sets the width in pixels.
app:border_round enableBorderRoundCorners Rounds the border corners.

Custom points

The points map to children in order, skipping children marked GONE. Provide one distinct point per participating child. Coordinates are relative to the content area inside the view's padding.

For the three children in the quick start, change app:generation_type to custom, add app:custom_points="@array/voronoi_points" to the view, and save this resource in res/values/voronoi_points.xml.

<resources>
    <string-array name="voronoi_points">
        <item>0.25, 0.25</item>
        <item>0.75, 0.25</item>
        <item>0.50, 0.75</item>
    </string-array>
</resources>

Each XML entry is an x, y pair from 0 to 1, inclusive. These coordinates scale with the content area. Malformed entries and coordinates outside that range are rejected when the view is inflated.

In Java, call setCustomPoints(List<VoronoiPoint>) with pixel coordinates and select GENERATION_TYPE_CUSTOM before the next layout. The method replaces any points supplied in XML. A mismatched count, duplicate points, or coordinates outside the content bounds cause an IllegalArgumentException during layout. See the Java example in the demo app.

License

Vorolay is licensed under the Apache License 2.0. The AAR includes the third-party license and attribution notices.

관련 프로젝트 살펴보기

불러오는 중…