android - Splash Screen synchronized loading -
i have implemented loading screen (splashscreen) want synchronize actual app loading. want app load main page in background when done timed load on loading screen, have main screen pulled in background. relatively new async task , threads since don't apps games use this. thanks
canvas load bar movement:
public class customrectangle extends view{ float left = 0, right = 500, top = 500, bot = 1000; boolean check = false, finish = false; int screenwidth = 0, screenheight = 0; bitmap image; @targetapi(build.version_codes.honeycomb_mr2) public customrectangle(context context){ super(context); windowmanager wm = (windowmanager) context.getsystemservice(context.window_service); display display = wm.getdefaultdisplay(); point size = new point(); display.getsize(size); this.screenheight = size.y; this.screenwidth = size.x; this.image = bitmapfactory.decoderesource(getresources(), r.drawable.logo); this.image = bitmap.createscaledbitmap(this.image, screenwidth, screenheight, false); } @targetapi(build.version_codes.kitkat) @override protected void ondraw(canvas canvas) { super.ondraw(canvas); if(check == false) { paint paintinitial = new paint(); paintinitial.setcolor(color.yellow); this.left = 0; this.top = canvas.getheight() - 10; this.right = canvas.getwidth(); this.bot = canvas.getheight(); canvas.drawrect(left, top - 10, right, bot, paintinitial); this.check = true; } if(check == true && finish == false) { paint paintwhite = new paint(); paintwhite.setcolor(color.white); paint paintyellow = new paint(); paintyellow.setcolor(color.yellow); canvas.drawrect(left, top, right, bot, paintyellow); canvas.drawbitmap(image, 0, 0, null); top = top - 5; invalidate(); if(top <= 0){ finish = true; intent intent = new intent(getcontext(), home_page.class); getcontext().startactivity(intent); log.e("", "finished loading!"); } } }
}
splash screen activity:
public class splashscreen extends actionbaractivity { rect loadbar; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(new customrectangle(this)); }
}
as of now, bar loads top of screen , starts main activity don't think main screen loads til end doesn't load synchronously. if lead me in right direction examples or post revised code, great.
i'm little confused have done, if need loading bar, suggest have 1 activity. in layout file, make framelayout or relativelayout. inside, can have progress bar, , layout main activity layout. make main activity layout invisible start with, , both should have width/height match_parent.
when activity starts up, showing progress bar, once have finished loading, can set progress bar invisible, , main layout visible.
one thing careful of make sure when change visibility of views run on ui thread. can calling runonuithread
runonuithread(new runnable() { @override public void run() { progressbar.setvisibility(view.invisible); mainlayout.setvisibility(view.visible); } } );
Comments
Post a Comment