Advertisement
Guest User

Untitled

a guest
Jul 24th, 2014
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.48 KB | None | 0 0
  1. import android.app.Activity;
  2. import android.content.Intent;
  3. import android.media.AudioManager;
  4. import android.media.MediaPlayer;
  5. import android.os.Bundle;
  6. import android.view.View;
  7. import android.view.View.OnClickListener;
  8.  
  9.  
  10.  
  11.  
  12. public class MainActivity extends Activity implements OnClickListener {
  13. private MediaPlayer mp;
  14.  
  15. @Override
  16. public void onCreate(Bundle savedInstanceState) {
  17. super.onCreate(savedInstanceState);
  18. setContentView(R.layout.activity_main);
  19. setContentView(new MYGIFView (this));
  20. setVolumeControlStream(AudioManager.STREAM_MUSIC);
  21. findViewById(R.id.button_1).setOnClickListener(this);
  22. findViewById(R.id.button_2).setOnClickListener(this);
  23. findViewById(R.id.button_3).setOnClickListener(this);
  24. }
  25. public void onClick(View v) {
  26. int resId=1;
  27.  
  28. // Release any resources from previous MediaPlayer
  29. if (mp != null) {
  30. mp.release();
  31. }
  32.  
  33. switch (v.getId()) {
  34. case R.id.button_1: resId = R.raw.button_1; break;
  35. case R.id.button_2: resId = R.raw.button_2; break;
  36. case R.id.button_3:
  37. startActivity(new Intent(MainActivity.this,SecondActivity.class));
  38. return;
  39.  
  40. }
  41.  
  42. // Create a new MediaPlayer to play this sound
  43. mp = MediaPlayer.create(this, resId);
  44. mp.start();
  45. }
  46. }
  47.  
  48. import android.app.Activity;
  49. import android.content.Intent;
  50. import android.os.Bundle;
  51. import android.os.Handler;
  52.  
  53. public class SplashScreen extends Activity {
  54.  
  55. // Splash screen timer
  56. private static int SPLASH_TIME_OUT = 3000;
  57.  
  58. @Override
  59. protected void onCreate(Bundle savedInstanceState) {
  60. super.onCreate(savedInstanceState);
  61.  
  62. new Handler().postDelayed(new Runnable() {
  63.  
  64. /*
  65. * Showing splash screen with a timer. This will be useful when you
  66. * want to show case your app logo / company
  67. */
  68.  
  69. @Override
  70. public void run() {
  71. // This method will be executed once the timer is over
  72. // Start your app main activity
  73. Intent i = new Intent(SplashScreen.this, MYGIFView.class);
  74. startActivity(i);
  75.  
  76. // close this activity
  77. finish();
  78. }
  79. }, SPLASH_TIME_OUT);
  80. }
  81.  
  82. }
  83.  
  84. import java.io.InputStream;
  85. import android.content.Context;
  86. import android.graphics.Canvas;
  87. import android.graphics.Color;
  88. import android.graphics.Movie;
  89. import android.view.View;
  90.  
  91. class MYGIFView extends View{
  92.  
  93. Movie movie,movie1;
  94. InputStream is=null,is1=null;
  95. long moviestart;
  96. public MYGIFView(Context context) {
  97. super(context);
  98.  
  99.  
  100.  
  101.  
  102. is=context.getResources().openRawResource(R.drawable.th_welcome);
  103. movie=Movie.decodeStream(is);
  104.  
  105. }
  106.  
  107. @Override
  108. protected void onDraw(Canvas canvas) {
  109.  
  110. canvas.drawColor(Color.BLACK);
  111. super.onDraw(canvas);
  112. long now=android.os.SystemClock.uptimeMillis();
  113. System.out.println("now="+now);
  114. if (moviestart == 0) { // first time
  115. moviestart = now;
  116.  
  117. }
  118. System.out.println("tmoviestart="+moviestart);
  119. int relTime = (int)((now - moviestart) % movie.duration()) ;
  120. System.out.println("time="+relTime+"treltime="+movie.duration());
  121. movie.setTime(relTime);
  122. canvas.scale(3.50f, 3.50f);
  123. movie.draw(canvas,20,20);
  124. this.invalidate();
  125. }
  126. }
  127.  
  128. <uses-sdk
  129. android:minSdkVersion="8"
  130. android:targetSdkVersion="11" />
  131.  
  132. <application
  133. android:allowBackup="true"
  134. android:icon="@drawable/ic_launcher"
  135. android:label="@string/app_name"
  136. android:theme="@style/AppTheme" >
  137. <activity
  138. android:name=".SplashScreen"
  139. android:label="@string/app_name"
  140. android:screenOrientation="portrait"
  141. android:theme="@android:style/Theme.Black.NoTitleBar" >
  142. <intent-filter>
  143. <action android:name="android.intent.action.MAIN" />
  144.  
  145. <category android:name="android.intent.category.LAUNCHER" />
  146. </intent-filter>
  147. </activity>
  148.  
  149. <activity
  150. android:name=".MainActivity"
  151. android:label="@string/app_name" >
  152. <intent-filter>
  153. <action android:name="android.intent.action.MAIN" />
  154.  
  155. <category android:name="android.intent.category.LAUNCHER" />
  156. </intent-filter>
  157. </activity>
  158.  
  159. <activity
  160. android:name=".SecondActivity"
  161. android:label="@string/app_name"/>
  162. </application>
  163.  
  164. </manifest>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement