001/* 002 * #%L 003 * GwtMaterial 004 * %% 005 * Copyright (C) 2015 GwtMaterialDesign 006 * %% 007 * Licensed under the Apache License, Version 2.0 (the "License"); 008 * you may not use this file except in compliance with the License. 009 * You may obtain a copy of the License at 010 * 011 * http://www.apache.org/licenses/LICENSE-2.0 012 * 013 * Unless required by applicable law or agreed to in writing, software 014 * distributed under the License is distributed on an "AS IS" BASIS, 015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 016 * See the License for the specific language governing permissions and 017 * limitations under the License. 018 * #L% 019 */ 020package gwt.material.design.client.ui; 021 022import gwt.material.design.client.base.MaterialWidget; 023import gwt.material.design.client.constants.Display; 024import gwt.material.design.client.ui.html.Div; 025 026import com.google.gwt.dom.client.Document; 027import com.google.gwt.dom.client.Style; 028import com.google.gwt.user.client.ui.HasVisibility; 029import com.google.gwt.user.client.ui.Widget; 030 031//@formatter:off 032/** 033 * An initial screen that act as a loading screen 034 * in order for your apps to load fully. 035 * 036 * <h3>UiBinder Usage:</h3> 037 * <pre> 038 *{@code 039 040<m:MaterialSplashScreen backgroundColor="blue" textColor="white" textAlign="CENTER"> 041 <m:MaterialImage resource="{res.ic_splash}" width="300px"/> 042 <m:MaterialTitle title="gwt-material" description="Material Design Look and Feel for GWT Apps" /> 043</m:MaterialSplashScreen> 044 045 * }</pre> 046 * <h3>Java Usage:</h3> 047 * <pre> 048 *{@code 049 * 050@UiField MaterialSplashScreen splash; 051splash.show(); 052Timer t = new Timer() { 053 @Override 054 public void run() { 055 splash.hide(); 056 } 057}; 058t.schedule(3000); 059 060 * }</pre> 061 * @author kevzlou7979 062 * @author Ben Dol 063 * @see <a href="http://gwt-material-demo.herokuapp.com/#media">Material Splashscreen</a> 064 */ 065//@formatter:on 066public class MaterialSplashScreen extends MaterialWidget implements HasVisibility{ 067 068 private Div div = new Div(); 069 private MaterialProgress progress = new MaterialProgress(); 070 071 public MaterialSplashScreen() { 072 super(Document.get().createDivElement(), "splash-screen"); 073 setDisplay(Display.NONE); 074 div.setWidth("100%"); 075 div.getElement().getStyle().setMarginTop(15, Style.Unit.PCT); 076 super.add(div); 077 super.add(progress); 078 } 079 080 @Override 081 public void add(Widget child) { 082 div.add(child); 083 } 084 085 public void show() { 086 getElement().getStyle().setDisplay(Display.BLOCK.getGwtDisplay()); 087 } 088 089 public void hide() { 090 getElement().getStyle().setDisplay(Display.NONE.getGwtDisplay()); 091 } 092 093}