Gesture Overlay on SplashScreen - android

I'm trying to use a gesture overlay on a activity that is used as a splash screen.
The problem is when I : gOverlay = (GestureOverlayView) this.findViewById(R.id.gOverlay); , gOverlay is null.
This is my XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout android:id="#+id/LinearLayout01"
android:layout_width="fill_parent" android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="center" android:background="#000000"
android:weightSum="1">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.11">
<android.gesture.GestureOverlayView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/gOverlay"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:visibility="visible"
android:background="#000000"
>
</android.gesture.GestureOverlayView>
</RelativeLayout>
</LinearLayout>
This is Splash java code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
/** set time to splash out */
Bundle extras = getIntent().getExtras();
if (extras != null) {
Duration = extras.getString("Duration");
}
welcomeScreenDisplay = 4000;
try {
welcomeScreenDisplay = Integer.parseInt(Duration);
} catch (Exception x) {
}
gLibrary = GestureLibraries.fromRawResource(this, R.raw.gestures);
if (!gLibrary.load()) {
finish();
}
gOverlay = (GestureOverlayView) this.findViewById(R.id.gOverlay);
gOverlay.setGestureVisible(false);
gOverlay.addOnGesturePerformedListener(this);
/** create a thread to show splash up to splash time */
Thread welcomeThread = new Thread() {
int wait = 0;
#Override
public void run() {
try {
super.run();
while (wait < welcomeScreenDisplay) {
sleep(100);
wait += 100;
}
} catch (Exception e) {
System.out.println("EXc=" + e);
} finally {
finish();
}
}
};
welcomeThread.start();
}
What i'm trying to do is :
1. When user presses back button Splash screen will show.
2. This splash screen will be on the screen for n seconds
3. If the user draw a 'L' on the splash screen, implicit on Gesture Overlay, main activity will .finish()
Thanks

From the comments you gave, it seems that you are inflating the wrong layout.
You said, the layout containing the GestureOverlayView is named splash2.
setContentView(R.layout.splash);
But instead you are inflating splash, not splash2. If splash.xml does not contain the GestureOverlayView with android:id="#+id/gOverlay", then requesting gOverlay from splash, will throw a nullpointer.
Changing setContentView() in your activity to following should help:
setContentView(R.layout.splash2);

Related

Android app splash screen from file on device

I want to display a splash screen for x seconds at the app launch from a PNG file on the device.
I have tried android:windowBackground in the theme however that cannot be taken from a file and only predefined Drawable
The file may change at anytime so at next app launch it will be different.
Below is the code to set timer for Splash Screen activity. Also, do not forget to include the activity in manifest.
splash_screen.java
public class Splash extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
Thread timerThread = new Thread(){
public void run(){
try{
sleep(5000); //Change the timing of the Screen
}catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent intent = new Intent(SplashScreen.this,MainActivity.class);
startActivity(intent);
}
}
};
timerThread.start();
}
}
Make your layout, full screen, remove action bar. Here's the code for splash_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/splashscreen"
android:orientation="vertical">
</LinearLayout>
Change the image of splashscreen, when you need, in your case, each time app is launched. HTH.
You can use ImageView.
Set scale image to fit the screen.
Make window fullscreen with no titlebar. By this you can set drawable different every time.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/splashscreen"
android:orientation="vertical">
<ImageView
android:id="#+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/image2"
/>
</LinearLayout>
Access this ImageView in splash screen activity by..
ImageView img = (ImageView) findviewbyId(R.id.imageView);
Bitmap bitmapImage = BitmapFactory.decodeFile(imagePathFromSDCard);
Drawable drawableImage = new BitmapDrawable(bitmapImage);
img.setBackgroundDrawable(drawableImage);

App loading splash screen with processbar and Text for showing percentage of loading

I am working on splash screen for my android app. The screen starts from my MainActivity.java, in which onCreate() method contains the following code. Also the same activity class is loading maps in its onResume() method and in it i m loading a new layout which is activity_main.xml. That xml has black screen and no background screen.
MainActivity.java
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.loading_screen);
progressBar = (ProgressBar) findViewById(R.id.progressBar1);
textView = (TextView) findViewById(R.id.textView1);
new Thread(new Runnable() {
public void run() {
while (progressStatus < 100) {
progressStatus += 1;
handler.post(new Runnable() {
public void run() {
progressBar.setProgress(progressStatus);
textView.setText(progressStatus + "/"
+ progressBar.getMax());
}
});
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
compass = new CompassSensor(this, compassHandler);
}
my layout for loading_screen.xml is as follow.
loading_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/splash_screen_loading" xmlns:android="http://schemas.android.com/apk/res/android">
<ProgressBar
android:id="#+id/progressBar1"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="25dp" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/progressBar1"
android:layout_marginLeft="15dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
The problem i m facing is that only black screen shows during app loading. I tried to debug the problem but all my efforts were useless. Plz help.
You should not attempt this in onCreate, if you expect visual changes. Nothing is shown to user during onCreate. I am aware of Thread.sleep(200).
You may want to try doing it in your onResume, just after calling super.onResume. The way you described it, R.layout.loading_screen is not even supposed to be shown.
Also, if you're using AsyncTask to load maps, Developers lets you know how to publish progress. Take a look at this: AsyncTask. Maybe you could add this prior work (with progress on R.layout.loading_screen) to asynchronous task, too.

Android pre`loading Activity

I have a question regarding the loading of the first Activity in my App. Before loading it, app shows this screen: https://www.dropbox.com/s/r33n3u3xfmth345/Screenshot_2013-08-16-12-02-08.png , and what I would like, is to load directly my Activity.
I'll mention that Im using SherlockActivity, and I already tried setting the Theme both in Manifest or programatically in onCreate() of my Activity, with same result (pre-loads with that screen for 2-3 secs, then loads my Activity).
Any thoughts ?
You have to use the splash screen Activity and after that you have to start your own activity from that Splash screen Activity.
Here is the code for splashActivity.
public class SplashActivity extends Activity {
private int splashTime = 3000;
private Thread thread;
private ProgressBar mSpinner;
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
mSpinner = (ProgressBar) findViewById(R.id.Splash_ProgressBar);
mSpinner.setIndeterminate(true);
thread = new Thread(runable);
thread.start();
}
public Runnable runable = new Runnable() {
public void run() {
try {
Thread.sleep(splashTime);
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
startActivity(new Intent(SplashActivity.this,YourActivityName.class));
finish();
} catch (Exception e) {
// TODO: handle exception
}
}
};
}
Here is code for activity_spalsh.xml file .....
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#48AD83"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginBottom="20dp"
android:layout_marginTop="10dp"
android:gravity="center_horizontal"
android:text=" your app name "
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#A52A2A" />
<ProgressBar
android:id="#+id/Splash_ProgressBar"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_centerInParent="true"
android:layout_marginTop="5dp" />
</RelativeLayout>

How can you fade out and in between two images? [duplicate]

This question already has answers here:
How to fade out and in between two images?
(2 answers)
Closed 9 years ago.
I have two images loading in my splash screen. The first image opens (starting the splash screen) then the second image opens. Once the second image fades out the MainActivity starts. Now my question is how do I make my first image fade out, then fade in with my second image?
I'm not trying to cross fade between the two either. I'm trying to do a complete fade out then fade in transition.
The splash.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:id="#+id/lin_lay"
android:gravity="center" >
<ImageView
android:contentDescription="#string/desc"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/spinning_wheel_image"
android:background="#drawable/splashscreen1" />
</LinearLayout>
The mainanim.xml
<animation-list xmlns:android="http://schemas.android.com/apk/res/android" android:oneshot="false">
<item android:drawable="#drawable/splashscreen1" android:duration="2500" />
<item android:drawable="#drawable/splashscreen2" android:duration="4000" />
</animation-list>
The Splash.java
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
ourSong = MediaPlayer.create(Splash.this, R.raw.splashsound);
ourSong.start();
Thread timer = new Thread(){
public void run(){
try{
sleep(10500);
} catch (InterruptedException e){
e.printStackTrace();
}finally{
Intent openStartingPoint = new Intent("com.theapplication.app.STARTINGPOINT");
startActivity(openStartingPoint);
}
}
};
timer.start();
}
#Override
public void setRequestedOrientation(int requestedOrientation) {
super.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}
#Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
ImageView mainimage = (ImageView)findViewById(R.id.spinning_wheel_image);
mainimage.setBackgroundResource(R.anim.mainamin);
mainanimation = (AnimationDrawable) mainimage.getBackground();
mainanimation.start();
}
You can try this demo.
may be helpful for you.

Android: make animation from still images

I've a series of still images and total of more than 500 images presented in drawable directory. I need to make an animation (load about 20 images per second). I want it to run smoothly and with no Out Of Memory Exception.
I've idea to do this that images for 2 to 3 seconds (40 to 60 images) should load in memory and displayed and then they should disposed off (release the memory) and then images for next 2 to 3 seconds should load. This technique can prevent Out Of Memory Exception. Its just an idea, I dont know whether its a good idea or not. Please guide me some better idea with some code to go with... If my idea is much better and can work then please tell me some helping code to do that.
After reading replies and doing as you suggest, I've written some code like this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/llMain">
<ViewFlipper android:id="#+id/imageflipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView android:id="#+id/ImageView01"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerInside"
android:layout_gravity="center" />
</ViewFlipper>
</LinearLayout>
and here is my code for doing animation:
public class Animation extends Activity {
ViewFlipper flipper;
int myIndex = 216;
private final Handler handler = new Handler();
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
flipper=(ViewFlipper)findViewById(R.id.imageflipper);
doTheAutoRefresh();
//displayData();
}
private void doTheAutoRefresh() {
handler.postDelayed(new Runnable() {
public void run(){
displayData(); // this is where you put your refresh code
doTheAutoRefresh();
}
}, 30);
}
private void displayData()
{
Resources r = getResources();
if(myIndex > 230){
myIndex = 216;
ImageView myImg = (ImageView)findViewById(R.id.ImageView01);
myImg.setImageResource(r.getIdentifier("drum0" + myIndex, "drawable", "com.vt.animation"));
myIndex += 1;
flipper.showNext();
}
else{
ImageView myImg = (ImageView)findViewById(R.id.ImageView01);
myImg.setImageResource(r.getIdentifier("drum0" + myIndex, "drawable", "com.vt.animation"));
myIndex += 1;
flipper.showNext();
}
}
}
but its very slow. I've set up the refresh time to 30 milliseconds but actually its not refreshing too fast rather its refresh time is about 1 second. Any suggestion to make it fast to feel like real animation?
Thanks,
Use a FrameAnimation, eg in res/drawable/movie.xml:
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:oneshot="true">
<item android:drawable="#drawable/frame1" android:duration="50" />
<item android:drawable="#drawable/frame2" android:duration="50" />
<item android:drawable="#drawable/frame3" android:duration="50" />
etc...
</animation-list>
And then in Java:
imageView.setBackgroundResource(R.drawable.movie);
AnimationDrawable anim = (AnimationDrawable) imageView.getBackground();
anim.start();
OK. The biggest problem and the easiest solution I got to go with after so many days. I would never expect that it would be so easy to do... :D
I've used both handler and timer to achieve with just an image view, no flipper, no animator nothing else at all... Here is my solution:
----- main.xml file -----
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView1">
</ImageView>
And here is the way I have done it:
public class MainActivity extends Activity {
private ImageView _imagView;
private Timer _timer;
private int _index;
private MyHandler handler;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
handler= new MyHandler();
_imagView=(ImageView) findViewById(R.id.imageView1);
_index=0;
_timer= new Timer();
_timer.schedule(new TickClass(), 500, 200);
}
private class TickClass extends TimerTask
{
#Override
public void run() {
// TODO Auto-generated method stub
handler.sendEmptyMessage(_index);
_index++;
}
}
private class MyHandler extends Handler
{
#Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
super.handleMessage(msg);
try {
Bitmap bmp= BitmapFactory.decodeStream(MainActivity.this.getAssets().open("drum_"+_index+".png"));
_imagView.setImageBitmap(bmp);
Log.v("Loaing Image: ",_index+"");
} catch (IOException e) {
// TODO Auto-generated catch block
Log.v("Exception in Handler ",e.getMessage());
}
}
}
}
Note: I've placed all my images to asset directory.
Its so simple as it can, nothing big to do...
I hope it'll be helpful for someone looking to go like this :)
Loading several images is very expensive.
I think it's better to load a single image containing all the movements of that certain animation. An animation strip.
private Bitmap animation = BitmapFactory.decodeResource(getResources(), R.drawable.myPng);
The idea is to traverse the bitmap.
Well, I'm using viewFlipper, switching between views. Good thing about this one is that u can see previous picture sliding out while the new one slides in.
Inside image displaying method:
if (direction == NEXT) {
viewFlipper.setInAnimation(slideLeftIn);
viewFlipper.setOutAnimation(slideLeftOut);
if (currImg < max)
currImg++;
if (currImg == max)
currImg = 0;
if (currentView == 0) {
currentView = 1;
ImageView iv = (ImageView) findViewById(R.id.ImageView02);
iv.setImageResource(images[currImg]);
} else if (currentView == 1) {
currentView = 2;
ImageView iv = (ImageView) findViewById(R.id.ImageView03);
iv.setImageResource(images[currImg]);
} else {
currentView = 0;
ImageView iv = (ImageView) findViewById(R.id.ImageView01);
iv.setImageResource(images[currImg]);
}
viewFlipper.showNext();
}
else if (direction == PREV) {
viewFlipper.setInAnimation(slideRightIn);
viewFlipper.setOutAnimation(slideRightOut);
if (currImg > 0)
currImg--;
else if (currImg <= 0)
currImg = (max-1);
if (currentView == 0) {
currentView = 2;
ImageView iv = (ImageView) findViewById(R.id.ImageView03);
iv.setImageResource(images[currImg]);
} else if (currentView == 2) {
currentView = 1;
ImageView iv = (ImageView) findViewById(R.id.ImageView02);
iv.setImageResource(images[currImg]);
} else {
currentView = 0;
ImageView iv = (ImageView) findViewById(R.id.ImageView01);
iv.setImageResource(images[currImg]);
}
viewFlipper.showPrevious();
And inside XML file:
<ViewFlipper android:id="#+id/imageflipper"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView android:id="#+id/ImageView01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:layout_gravity="center" />
<ImageView android:id="#+id/ImageView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:layout_gravity="center" />
<ImageView android:id="#+id/ImageView03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerInside"
android:layout_gravity="center" />
</ViewFlipper>

Categories

Resources