Coder Social home page Coder Social logo

turkergoksu / socialorbitlayout Goto Github PK

View Code? Open in Web Editor NEW
28.0 1.0 1.0 17.84 MB

Kotlin based custom view to show floating objects that can be used for social apps.

License: MIT License

Kotlin 100.00%
android kotlin custom-view social-media social orbit floating

socialorbitlayout's Introduction

SocialOrbitLayout

Adjustable custom view that can be used for loading screens or welcome pages inside social apps to show floating objects around an orbit. Inspired by Blogging app landing page.

intro

All the example images are generated from thispersondoesnotexist.com.

🛠️Setup

1. Add the JitPack repository to your build file.

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

2. Add the dependency

dependencies {
    implementation 'com.github.turkergoksu:SocialOrbitLayout:1.0.0'
}

🕹️Usage

<me.turkergoksu.lib.view.SocialOrbitLayout
            android:id="@+id/socialOrbitLayout"
            android:layout_width="match_parent"
            android:layout_height="400dp"
            app:innerOrbitAngleDistance="120"
            app:innerOrbitAnimDuration="30000"
            app:innerOrbitColor="#e0ecff"
            app:innerOrbitRadius="90dp"
            app:innerOrbitStartAngle="20"
            app:innerOrbitWidth="40dp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:outerOrbitAngleDistance="90"
            app:outerOrbitAnimDuration="60000"
            app:outerOrbitColor="#d3d3d3"
            app:outerOrbitPadding="40dp"
            app:outerOrbitStartAngle="70"
            app:outerOrbitWidth="2dp" />

Currently, you can programmatically add FloatingImage to Orbit with given Bitmap.

⚠️ You may set Orbit attributes programmatically but it will be overwritten by the values in the layout.

var orbit = Orbit.Builder()
        .setFloatingObjectList(
                mutableListOf(
                    // .
                    // .
                    // .
                    FloatingImage.Builder()
                        .setBitmap(BitmapFactory.decodeResource(resources, R.drawable.dummy1))
                        .setBackgroundColor(Color.parseColor("#2e7fff"))
                        .setSize(70f)
                        .setLocation(FloatingObjectLocation.CENTER)
                        .build(),
                    FloatingImage.Builder()
                        .setBitmap(BitmapFactory.decodeResource(resources, R.drawable.dummy2))
                        .setSize(50f)
                        .setLocation(FloatingObjectLocation.INNER)
                        .build(),
                    FloatingImage.Builder()
                        .setBitmap(BitmapFactory.decodeResource(resources, R.drawable.dummy3))
                        .setLocation(FloatingObjectLocation.OUTER)
                        .build(),
                    // .
                    // .
                    // .
                )
        )
        .setOuterOrbitWidth(width = 2f)
        .setInnerOrbitColor(Color.parseColor("#2e7fff"))
        .setOuterOrbitAngleDistance(distance = 90.0)
        .setOuterOrbitAnimDuration(duration = 60000)
        .setInnerOrbitRadius(radius = 90f)
        .setInnerOrbitAngleDistance(distance = 120.0)
        .setInnerOrbitAnimDuration(duration = 30000)
        .build()
socialOrbitLayout.setOrbit(orbit)

If you don't want to create a FloatingImageBuilder for every FloatingImage object, you may create a single builder and change it's attributes. This implementation actually better for objects that shares same attributes(Or the majority). Check the following example.

val floatingImageBuilder = FloatingImage.Builder()
                .setBackgroundColor(Color.RED)
                .setBorderWidth(3f)
                .setSize(50f)
                
var orbit = Orbit.Builder()
        .setFloatingObjectList(
                mutableListOf(
                    // .
                    // .
                    // .
                    floatingImageBuilder.copy() // copy() is crucial here!
                        .setBitmap(BitmapFactory.decodeResource(resources, R.drawable.dummy1))
                        .setBackgroundColor(Color.WHITE)
                        .setSize(70f)
                        .setLocation(FloatingObjectLocation.CENTER)
                        .build(),
                    floatingImageBuilder.copy()
                        .setBitmap(BitmapFactory.decodeResource(resources, R.drawable.dummy2))
                        .setLocation(FloatingObjectLocation.INNER)
                        .build(),
                    floatingImageBuilder.copy()
                        .setBitmap(BitmapFactory.decodeResource(resources, R.drawable.dummy3))
                        .setBorderWidth(2f)
                        .build(),
                    // .
                    // .
                    // .
                )
        )
        .build()
socialOrbitLayout.setOrbit(orbit)

📝Attributes

SocialOrbitLayout

Name Format Default Description
outerOrbitColor color Color.LTGRAY Color of the outer orbit.
outerOrbitWidth dimension 2dp Width of the outer orbit.
outerOrbitAnimDuration integer 60000 The time that any floating object will make 1 full turn in outer orbit with given milliseconds.
outerOrbitPadding dimension 40dp The padding between outer orbit and whole view.
outerOrbitStartAngle integer 70 The start angle of first floating object on outer orbit.
outerOrbitAngleDistance integer 90 The angle distance between floating objects on outer orbit.
innerOrbitRadius dimension 90dp Radius of the inner orbit.
innerOrbitColor color #F8F4FE Color of the inner orbit.
innerOrbitWidth dimension 40dp Width of the inner orbit.
innerOrbitAnimDuration integer 30000 The time that any floating object will make 1 full turn in inner orbit with given milliseconds.
innerOrbitStartAngle integer 20 The start angle of first floating object on inner orbit.
innerOrbitAngleDistance integer 120 The angle distance between floating objects on inner orbit.

FloatingImage

⚠️ To avoid any future confusion after seeing SocialOrbitLayout, the following attributes are for the FloatingImage object and not for the layout file. Because currently there isn't any FloatingObjectView attribute implementation.

Name Format Default Description
bitmap Bitmap null The image that FloatingObjectView shows.
backgroundColor Int Color.WHITE Background color of floating image. In order to observe the color borderWidth needs to be bigger than 0f.
borderWidth Float 2f Border width of FloatingObjectView.
size Float 40f Size of the FloatingObjectView(not bitmap).
elevation Float 10f Elevation value of FloatingObjectView.
location FloatingObjectLocation FloatingObjectLocation.OUTER Location of FloatingObjectView. Can take three values named FloatingObjectLocation.CENTER, FloatingObjectLocation.OUTER and FloatingObjectLocation.INNER.

socialorbitlayout's People

Contributors

turkergoksu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

ladroshan

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.