Last active
August 29, 2015 14:07
-
-
Save aftabsikander/1a61cf84c7d7024772c3 to your computer and use it in GitHub Desktop.
Create an Splash Screen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * Copyright 2014 Google Inc. All rights reserved. | |
| * | |
| * 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. | |
| */ | |
| import java.util.Timer; | |
| import java.util.TimerTask; | |
| import android.content.Context; | |
| import android.os.Bundle; | |
| import android.support.v7.app.ActionBarActivity; | |
| import android.view.KeyEvent; | |
| import android.view.Menu; | |
| import android.view.MenuItem; | |
| public class SplashActivity extends ActionBarActivity | |
| { | |
| Context mContext; | |
| private boolean isBackPressed = false; | |
| Timer timer = new Timer(); | |
| @Override | |
| protected void onCreate(Bundle savedInstanceState) | |
| { | |
| super.onCreate(savedInstanceState); | |
| setContentView(R.layout.activity_splash); | |
| mContext = this; | |
| startSplashScreen(); | |
| } | |
| @Override | |
| public boolean onCreateOptionsMenu(Menu menu) | |
| { | |
| // Inflate the menu; this adds items to the action bar if it is present. | |
| // getMenuInflater().inflate(R.menu.splash, menu); | |
| return true; | |
| } | |
| @Override | |
| public boolean onOptionsItemSelected(MenuItem item) | |
| { | |
| // Handle action bar item clicks here. The action bar will | |
| // automatically handle clicks on the Home/Up button, so long | |
| // as you specify a parent activity in AndroidManifest.xml. | |
| int id = item.getItemId(); | |
| if (id == R.id.action_settings) | |
| { | |
| return true; | |
| } | |
| return super.onOptionsItemSelected(item); | |
| } | |
| public void startSplashScreen() | |
| { | |
| TimerTask task = new TimerTask() | |
| { | |
| @Override | |
| public void run() | |
| { | |
| if (!isBackPressed) | |
| { | |
| finish(); | |
| //ProjectUtli.genericIntent(mContext, HomeActivity.class, null); | |
| } | |
| } | |
| }; | |
| timer.schedule(task, ProjectUtli._splashDelay); | |
| } | |
| @Override | |
| public boolean onKeyDown(int keyCode, KeyEvent event) | |
| { | |
| if ((keyCode == KeyEvent.KEYCODE_BACK)) | |
| { | |
| if (null != timer) | |
| { | |
| timer.cancel(); | |
| } | |
| isBackPressed = true; | |
| finish(); | |
| } | |
| return super.onKeyDown(keyCode, event); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment