001/* 002 * #%L 003 * GwtMaterial 004 * %% 005 * Copyright (C) 2015 - 2017 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 com.google.gwt.dom.client.Document; 023import com.google.gwt.dom.client.Style; 024import com.google.gwt.user.client.ui.Widget; 025import gwt.material.design.client.base.MaterialWidget; 026import gwt.material.design.client.constants.CssName; 027import gwt.material.design.client.constants.Display; 028import gwt.material.design.client.ui.html.Div; 029 030//@formatter:off 031 032/** 033 * An initial screen that act as a loading screen 034 * in order for your apps to load fully. 035 * <p> 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 @UiField MaterialSplashScreen splash; 049 * splash.show(); 050 * Timer t = new Timer() 051 * { @Override 052 * public void run() { 053 * splash.hide(); 054 * } 055 * }; 056 * t.schedule(3000); 057 * }</pre> 058 * } 059 * 060 * 061 * @author kevzlou7979 062 * @author Ben Dol 063 * @see <a href="http://gwtmaterialdesign.github.io/gwt-material-demo/#showcase">Material Splashscreen</a> 064 * @see <a href="https://material.io/guidelines/patterns/launch-screens.html">Material Design Specification</a> 065 */ 066//@formatter:on 067public class MaterialSplashScreen extends MaterialWidget { 068 069 private Div container = new Div(); 070 private MaterialProgress progress = new MaterialProgress(); 071 072 public MaterialSplashScreen() { 073 super(Document.get().createDivElement(), CssName.SPLASH_SCREEN); 074 } 075 076 @Override 077 protected void onLoad() { 078 setDisplay(Display.NONE); 079 080 container.setWidth("100%"); 081 container.getElement().getStyle().setMarginTop(15, Style.Unit.PCT); 082 super.onLoad(); 083 084 super.add(container); 085 super.add(progress); 086 } 087 088 @Override 089 public void add(Widget child) { 090 container.add(child); 091 } 092 093 public void show() { 094 setDisplay(Display.BLOCK); 095 } 096 097 public void hide() { 098 setDisplay(Display.NONE); 099 } 100 101 public Div getContainer() { 102 return container; 103 } 104 105 public MaterialProgress getProgress() { 106 return progress; 107 } 108}