Auckland GTUG Message Board › Shake an Elf Application Challenge
| Simon C | |
|
|
Hey all,
Seeing as Xmas is coming I thought maybe giving you all a Xmas themed sample application that you can modify yourselves. All the information you need should be on this site http://blog.serendipi... As you will see in the above link, I am currently trying to get hold of a prize for the "winner". - So why not have a go. - I'll give a quick intro in the November meetup But the "winner" be decided at the December meetup (2 Dec 2010). Good luck to you all!!! - Any Questions can either be posted on this discussion thread or as a comment on our blog. Simon Collings Solutions Manager Serendipity IT Ltd http://serendipityit.... http://blog.serendipi... |
| Simon C | |
|
|
The Rules
The Rules/Guidelines for the 'Shake an Elf' challenge are as follows: 1. Your application must contain an image of an Elf 2. The Elf must do something when someone shakes the phone How will I do it? All the information about the application is located here http://blog.serendipi... But I'm not an Android developer - can I still do it? All you need is a working development environment which can be set up easily if you follow this link : http://developer.andr... Why? The main aim is to share your learning / experiences at the December Meet-up, but there may be a prize - I'll tell you more on Thursday at the meet-up (then post that info here). Also at the end I'd like to get some feedback on how this 'challenge' worked so I can run more if they are wanted. -NOTE: To claim any Prize you must present your application at the December 2010 Androids in Auckland Meetup! - But anyone can use this code as training to create an app. Edited by Simon C on Nov 2, 2010 10:05 AM |
| Simon C | |
|
|
What / How to deliver your Elf Application
The due date is 2nd Dec 2010 7:00PM. You will be required to provide via USB or similar:
(If you will not be at the meetup then email the above list to Simon Collings ( simonc at serendipityit. co. nz ) and he can show your app off for you but you wont be in the draw for the prize) Rules The full set 1. Your application must contain an image of an Elf 2. The Elf must do something when someone shakes the phone 3. Your application must be able to run on Android version 1.6 (i.e. target 1.6 when you are developing) 4. You can use any development tools or language you like including App Inventor, Eclipse, LUA, Adobe Air - so long as you can fulfil all of the other rules 5. Your application must do no evil! 6. The due date is 2nd Dec 2010 7:00PM 7. You must be there in person to deliver your application, demonstrate your application and receive the prize. On the night (2 Dec 2010) You can demo your application including learning's from the development process (time allocation will depend on how many entrants) just be ready to tell everyone how cool your app is!!! The winner will be picked and the prize will be given (See below for details of the phone / prize!) Post event We would like to upload the entries, including APK's / links to the market, source code and contact details to a website, so other people can use your application to learn from. This is optional. Edited by Simon C on Nov 17, 2010 6:31 PM |
| Simon C | |
|
|
Hey all,
Great news, Telecom have given us a "Motorola Flipout" ( http://bit.ly/bE6V3H... Features Android 2.1 3.1MP Camera WiFi b/g Flip out keyboard Get going on your Elf apps! Just a reminder, the rules etc are posted above - the apps don't have to be brilliant, it's about the experience, growing the number of Android developers in Auckland (& winning the Telecom Android phone)! Someone will go home with this phone at the end of the meet-up! ![]() |
| Simon C | |
|
|
For everyones information Tong won the phone with an app that told a story as it went - including waking the elf via shaking the phone and some xmas music to set the theme! nice work!
Honorable mention goes to John who used the Carona system to create his app and added a physics engine to detect when crates hit the elf!! Great work!!! And a special thanks to Telecom for giving us a new phone as a prize. See you all in 2011!! Simon C |
| Tong | |
|
|
//Here attached the code. The app is available on Android market. It is called Free Christmas Elf.
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.elfshake); mgr=(SensorManager)this.getSystemService if(mgr==null){ throw new UnsupportedOperationException("Sens } boolean supported = mgr.registerListener(listener,mgr.getDef if (!supported) { mgr.unregisterListener(listener); throw new UnsupportedOperationException("Acce } treeView = (ImageView) findViewById(R.id.christmastree); elfImageView = (ImageView) findViewById(R.id.christmastree); christmas = (TextView) findViewById(R.id.txtChristmas); christmas.setTypeface(Typeface.SANS_SERI mSwitcher = (ImageSwitcher) findViewById(R.id.switcherelf); mSwitcher.setFactory(this); mSwitcher.setInAnimation(AnimationUtils. mSwitcher.setOutAnimation(AnimationUtils mSwitcher.setImageResource(mImageIds[0]); christmas.setText(R.string.Wake); christmas.bringToFront(); christmas.setVisibility(1); fadeIn = AnimationUtils.loadAnimation(this, R.anim.fadein); fadeIn.setAnimationListener( myFadeInAnimationListener ); fadeOut = AnimationUtils.loadAnimation(this, R.anim.fadeout); fadeOut.setAnimationListener( myFadeOutAnimationListener ); launchInAnimation(); threshold = Elf_SHAKE_THRESHOLD*Elf_SHAKE_THRESHOLD* try { mp = MediaPlayer.create(getBaseContext(),R.ra mp.setLooping(true); mp.start(); } catch (Exception ex) { mp.release(); mp = null; } try { wishMerryXmas = MediaPlayer.create(getBaseContext(),R.ra wishMerryXmas.start(); } catch (Exception ex) { wishMerryXmas.release(); wishMerryXmas = null; } } @Override public boolean onTouchEvent(MotionEvent event) { isTouching = true; long now=System.currentTimeMillis(); long timegap; timegap = now-lastShakeTimestamp; if (timegap > Elf_SHAKE_GAP || FirstShakeFlag == true) { elfAction(false, isTouching); } return true; } private SensorEventListener listener=new SensorEventListener() { public void onSensorChanged(SensorEvent e) { if (e.sensor.getType()==Sensor.TYPE_ACCELER long now=System.currentTimeMillis(); long timegap; timegap = now-lastShakeTimestamp; if (timegap> Elf_SHAKE_GAP || FirstShakeFlag == true) { double netForce=e.values[0]*e.values[0]; netForce+=e.values[1]*e.values[1]; netForce+=e.values[2]*e.values[2]; if (netForce>threshold) { isShaking = true; elfAction(isShaking, false); } } } } public void onAccuracyChanged(Sensor sensor, int accuracy) {} }; private Runnable runnable = new Runnable() { public void run() { handler.postDelayed(this, 1000); myslideshow(); } }; private void myslideshow() { if (PicPosition <mImageIds.length){ FirstShakeFlag = false; mSwitcher.setOutAnimation(AnimationUtils android.R.anim.fade_out)); mSwitcher.setImageResource(mImageIds[Pic mSwitcher.setOutAnimation(AnimationUtils android.R.anim.fade_out)); if (PicPosition==1){ christmas.setText(""); } else if (PicPosition==4 ){ try { if(mp.isPlaying()==true){ mp.stop(); } mp = MediaPlayer.create(getBaseContext(),R.ra mp.setLooping(false); mp.start(); } catch (Exception ex) { mp.release(); mp = null; } }else if (PicPosition==5 ){ christmas.setText(R.string.Christmas); try{ if(mp.isPlaying()==true){ mp.stop(); } }catch(Exception ex) { } }else if (PicPosition==7 ){ try { mp = MediaPlayer.create(getBaseContext(),R.ra mp.setLooping(false); mp.start(); } catch (Exception ex) { mp.release(); } } PicPosition++; } else if (PicPosition ==mImageIds.length){ try{ if(mp.isPlaying()==true){ mp.stop(); } }catch(Exception ex) { } christmas.setText(R.string.Shake); SecondShakeFlag=true; } } private Runnable runnable2 = new Runnable() { public void run() { handler.postDelayed(this,3000); runsecondHalf(); } }; private void runsecondHalf(){ if (SecondHalfFlag==1 ){ PicPosition++; christmas.setText(R.string.Christmas); SecondHalfFlag=2; mSwitcher.setVisibility(View.GONE); elfImageView.setBackgroundResource(R.dra Animation elfImageAnimation = AnimationUtils.loadAnimation(this, R.anim.elf_rotate_anim); elfImageView.startAnimation(elfImageAnim }else if (SecondHalfFlag ==2){ elfImageView.setBackgroundResource(R.dra BounceInterpolator bi = new BounceInterpolator(); Animation elfImageAnimation = AnimationUtils.loadAnimation(this, R.anim.elf_fall_anim); elfImageAnimation.setInterpolator(bi); elfImageView.startAnimation(elfImageAnim SecondHalfFlag=3; } else if (SecondHalfFlag ==3){ christmas.setText(R.string.Light); elfImageView.setBackgroundResource(R.dra Animation elfImageAnimation = AnimationUtils.loadAnimation(this, R.anim.elf_rise_anim); elfImageAnimation.setDuration((long) (Math.random() * 3000)); elfImageView.startAnimation(elfImageAnim ThirdHalfFlag =1; ThirdShakeFlag = true; SecondShakeFlag = false; SecondHalfFlag=4; } } private void ThirdPart(){ elfImageView.setBackgroundResource(R.dra AnimationDrawable treeAnimation = (AnimationDrawable)elfImageView.getBackg treeAnimation.start(); christmas.setText(R.string.Touch); ThirdHalfFlag++; TheEndFlag=1; //FourthShakeFlag = true; } private void TheEnd(){ if(TheEndFlag==1){ setContentView(R.layout.end); } } ... |
| Tong | |
|
|
public View makeView() {
ImageView i = new ImageView(this); i.setBackgroundColor(0xFF000000); i.setScaleType(ImageView.ScaleType.FIT_C i.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams. LayoutParams.FILL_PARENT)); return i; } private void elfAction(boolean Shaking, boolean Touching) { boolean currentShaking, currentTouching; currentShaking = Shaking; currentTouching = Touching; if (currentShaking == true || currentTouching == true) { long curTime = System.currentTimeMillis(); long diffTime = (curTime - lastShakeTimestamp); if (FirstShakeFlag == true ){ // Log.i("diffTime", "diffTime: "+diffTime); lastShakeTimestamp = curTime+4000; runnable.run(); } else if (SecondShakeFlag ==true ){ lastShakeTimestamp = curTime; SecondShakeFlag= false; runnable2.run(); } else if (ThirdShakeFlag ==true && diffTime>3000 ){ ThirdShakeFlag=false; lastShakeTimestamp = curTime; ThirdPart(); } else if (TheEndFlag >0 && diffTime>2000 ){ lastShakeTimestamp = curTime; TheEnd(); } } } @Override protected void onPause() { super.onPause(); try{ if(mp!=null){ if(mp.isPlaying()==true){ mp.stop(); } // mp=null; mp.release(); } if( wishMerryXmas!= null){ if( wishMerryXmas.isPlaying()==true){ wishMerryXmas.stop(); } wishMerryXmas.release(); // wishMerryXmas=null; } }catch (Exception e){ } handler.removeCallbacks(runnable); handler.removeCallbacks(runnable2); // finish(); } @Override protected void onResume() { super.onResume(); try{ if (mgr != null) { mgr.registerListener(listener, mgr.getDefaultSensor(Sensor.TYPE_ACCELER } }catch (Exception e){ } } @Override protected void onStop() { super.onStop(); try{ if (mgr != null) { mgr.unregisterListener(listener); } }catch (Exception e){ } finish(); } public void launchInAnimation() { christmas.startAnimation(fadeIn); } public void launchOutAnimation() { christmas.startAnimation(fadeOut); } private class LocalFadeInAnimationListener implements AnimationListener { public void onAnimationEnd(Animation animation) { christmas.post(mLaunchFadeOutAnimation); } public void onAnimationRepeat(Animation animation) { } public void onAnimationStart(Animation animation) { } }; private class LocalFadeOutAnimationListener implements AnimationListener { public void onAnimationEnd(Animation animation) { christmas.post(mLaunchFadeInAnimation); } public void onAnimationRepeat(Animation animation) { } public void onAnimationStart(Animation animation) { } }; private LocalFadeInAnimationListener myFadeInAnimationListener = new LocalFadeInAnimationListener(); private LocalFadeOutAnimationListener myFadeOutAnimationListener = new LocalFadeOutAnimationListener(); private Runnable mLaunchFadeOutAnimation = new Runnable() { public void run() { launchOutAnimation(); } }; private Runnable mLaunchFadeInAnimation = new Runnable() { public void run() { launchInAnimation(); } }; @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); } } |
Log in to Meetup with your Facebook account.