gwt.material.design.client.ui.MaterialWeather Maven / Gradle / Ivy
/*
* #%L
* GwtMaterial
* %%
* Copyright (C) 2015 - 2017 GwtMaterialDesign
* %%
* 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.
* #L%
*/
package gwt.material.design.client.ui;
//@formatter:off
import com.google.gwt.user.client.DOM;
import gwt.material.design.client.base.AbstractValueWidget;
/**
* Material Weather - used OpenWeatherAPI to get results about location based weather
*
*
*
UiBinder Usage:
*
* {@code
*
* }
*
*
*
* @author kevzlou7979
* @author Ben Dol
* @author paulux84
*
* @see Material Weather
*/
//@formatter:on
@Deprecated
public class MaterialWeather extends AbstractValueWidget {
public MaterialWeather() {
super(DOM.createElement(" -
0
0
-
0
-
0
0
- 0
- 3.9 mph
- 0 hPa
"));
}
private String location;
private String color;
private String name;
@Override
protected void onLoad() {
super.onLoad();
name = "weatherContainer";
addStyleName(name);
getElement().setId("weatherContainer");
showWeather(location, name, color);
}
public String getLocation() {
return getValue();
}
public void setLocation(String location) {
setValue(location, true);
}
@Override
public void setValue(String value, boolean fireEvents) {
this.location = location;
showWeather(location, name, color);
super.setValue(value, fireEvents);
}
@Override
public String getValue() {
return location;
}
public String getColor() {
return color;
}
public void setColor(String color) {
this.color = color;
}
//TODO: Convert to JSInterop
public static native void showWeather(String location, String div, String color)/*-{
$wnd.jQuery.getJSON("http://api.openweathermap.org/data/2.5/weather?q=" + location + "&APPID=53455a3a8a8a46135396f0272314f49d", function (data) {
var items = [];
var location = data.sys.country + ", " + data.name;
var icon = "http://gwt-material.appspot.com/bin/weather/" + data.weather[0].icon + ".png";
var temp = Math.round((data.main.temp - 273.15) * 10) / 10;
var main = data.weather[0].main;
var desc = data.weather[0].description;
var humidity = data.main.humidity;
var pressure = data.main.pressure;
var wind = data.wind.speed;
var d = new Date();
var weekday = new Array(7);
weekday[0] = "Sunday";
weekday[1] = "Monday";
weekday[2] = "Tuesday";
weekday[3] = "Wednesday";
weekday[4] = "Thursday";
weekday[5] = "Friday";
weekday[6] = "Saturday";
var today = weekday[d.getDay()];
items.push(" -
" + main + "
" + desc + "
-
" + temp + "
-
" + location + "
" + today + "
- invert_colors " + humidity + "%
- wifi_tethering" + wind + " mph
- av_timer" + pressure + " hPa
");
$wnd.document.getElementById('weatherContainer').innerHTML = '';
$wnd.jQuery("
", {"class": "my-new-list", html: items.join("")}).appendTo("." + div);
$wnd.Materialize.showStaggeredList('#weatherPanel');
});
}-*/;
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy