MatteoBattilana / WeatherView

WeatherView is an Android Library let you make cool weather animations for your app
Apache License 2.0
514 stars 80 forks source link

How to use in a Java Project #30

Closed BambooCertain closed 3 years ago

BambooCertain commented 3 years ago

I fail to use WeatherView in a Java Project.Could you add a Java sample which uses your WeatherView.

MatteoBattilana commented 3 years ago

Thank you for using WeatherView, please refer to the Java section.

This is a small example: Xml:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/black"
    tools:context=".MainActivity">

    <com.github.matteobattilana.weather.WeatherView
        android:id="@+id/weather_view"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

Java:

package com.matteobattilana.myapplication;

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import com.github.matteobattilana.weather.PrecipType;
import com.github.matteobattilana.weather.WeatherView;

public class MainActivity extends AppCompatActivity
{
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        WeatherView weatherView = findViewById(R.id.weather_view);
        weatherView.setWeatherData(PrecipType.RAIN);
    }
}