天气 App 中常见的 Android 自定义控件,可以用来动态展示日出和日落

SunriseSunsetView

简介: :sunny: An Android view to show sunrise and sunset dynamically which is common seen in Weather App. / 天气 App 中常见的 Android 自定义控件,可以用来动态展示日出和日落。
更多:作者   提 Bug   
标签:

An Android view to show sunrise and sunset dynamically which is common seen in Weather App.

天气 App 中常见的 Android 自定义控件,可以用来动态展示日出和日落。

Screenshot

Import

  1. To use this lib you need add jitpack.io repository to your root build.gradle:

     allprojects {
         repositories {
             jcenter()
             maven { url 'https://jitpack.io' } // add this line
         }
     }
    

    Note: don't add the jitpack.io repository under buildscript closure.

  2. Add SunriseSunsetView dependency in your module build.gradle:

     // ...
     // if Android Gradle Plugin after v3.0
     implementation 'com.github.tianma8023:SunriseSunsetView:0.0.2' 
     // if Android Gradle Plugin before v3.0
     // compile 'com.github.tianma8023:SunriseSunsetView:0.0.2'
    

Usage

  1. SunriseSunsetView can be placed in layout xml file:
     <com.github.tianma8023.ssv.SunriseSunsetView
         android:id="@+id/ssv"
         android:layout_height="wrap_content"
         android:layout_margin="10dp"
         android:layout_width="match_parent"
         app:ssv_label_text_color="@color/colorAccent"
         app:ssv_label_text_size="16sp"
         app:ssv_label_horizontal_gap="12dp"
         app:ssv_label_vertical_gap="2dp"
         app:ssv_shadow_color="@color/lightGreen"
         app:ssv_sun_color="@color/amber"
         app:ssv_sun_radius="10dp"
         app:ssv_track_color="@color/teal"
         app:ssv_track_width="1.5dp"
     />
    
  2. You need to set sunrise and sunset time before starting animation:
     mSunriseSunsetView = (SunriseSunsetView) findViewById(R.id.ssv);
     // ...
     mSunriseSunsetView.setSunriseTime(new Time(sunriseHour, sunriseMinute));
     mSunriseSunsetView.setSunsetTime(new Time(sunsetHour, sunsetMinute));
     // start animation
     mSunriseSunsetView.startAnimate();
    

Custom attributes are supported:

attributeformatdefaultdescription
ssv_track_colorcolor\reference#FFFFFFtrack color
ssv_track_widthdimension4pxtrack width
ssv_sun_radiusdimension20pxsun radius
ssv_sun_colorcolor\reference#FFFF00sun color
ssv_shadow_colorcolor\reference#32FFFFFFshadow color
ssv_label_text_sizedimension40pxlabel text size
ssv_label_text_colorcolor\reference#FFFFFFlabel text color
ssv_label_vertical_offsetdimension5pxlabel vertical offset
ssv_label_horizontal_offsetdimension20pxlabel horizontal offset

Other api:

// fotmat label by set label formatter
mSunriseSunsetView.setLabelFormatter(new SunriseSunsetLabelFormatter() {
    @Override
    public String formatSunriseLabel(@NonNull Time sunrise) {
        return formatLabel(sunrise);
    }

    @Override
    public String formatSunsetLabel(@NonNull Time sunset) {
        return formatLabel(sunset);
    }

    private String formatLabel(Time time) {
        return String.format(Locale.getDefault(), "%02dh %02dm", time.hour, time.minute);
    }
});

Sample

There is a sample project in this repo, or you can download demo.apk directly.

License

SunriseSunsetView    
Copyright 2018 Tianma

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.
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值