Advertisement
Guest User

Untitled

a guest
Dec 17th, 2014
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.70 KB | None | 0 0
  1. package pl.wroc.pwr.schoolproject.randommusic;
  2.  
  3. import pl.wroc.pwr.schoolproject.randommusic.util.SystemUiHider;
  4.  
  5. import android.annotation.TargetApi;
  6. import android.app.Activity;
  7. import android.content.res.AssetFileDescriptor;
  8. import android.media.MediaPlayer;
  9. import android.os.Build;
  10. import android.os.Bundle;
  11. import android.os.Handler;
  12. import android.view.MotionEvent;
  13. import android.view.View;
  14. import android.view.View.OnClickListener;
  15. import android.app.Dialog;
  16. import android.widget.Button;
  17. import android.widget.EditText;
  18. import android.widget.TextView;
  19.  
  20. import java.io.IOException;
  21. import java.util.Random;
  22.  
  23.  
  24. /**
  25. * An example full-screen activity that shows and hides the system UI (i.e.
  26. * status bar and navigation/system bar) with user interaction.
  27. *
  28. * @see SystemUiHider
  29. */
  30. public class FullscreenActivity extends Activity {
  31. /**
  32. * Whether or not the system UI should be auto-hidden after
  33. * {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.
  34. */
  35. private static final boolean AUTO_HIDE = true;
  36.  
  37. /**
  38. * If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after
  39. * user interaction before hiding the system UI.
  40. */
  41. private static final int AUTO_HIDE_DELAY_MILLIS = 9000;
  42.  
  43. /**
  44. * If set, will toggle the system UI visibility upon interaction. Otherwise,
  45. * will show the system UI visibility upon interaction.
  46. */
  47. private static final boolean TOGGLE_ON_CLICK = true;
  48.  
  49. /**
  50. * The flags to pass to {@link SystemUiHider#getInstance}.
  51. */
  52. private static final int HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION;
  53.  
  54. /**
  55. * The instance of the {@link SystemUiHider} for this activity.
  56. */
  57. private SystemUiHider mSystemUiHider;
  58.  
  59. @Override
  60. protected void onCreate(Bundle savedInstanceState) {
  61. super.onCreate(savedInstanceState);
  62.  
  63. setContentView(R.layout.activity_fullscreen);
  64.  
  65. final View controlsView = findViewById(R.id.fullscreen_content_controls);
  66. final View contentView = findViewById(R.id.fullscreen_content);
  67.  
  68. // Set up an instance of SystemUiHider to control the system UI for
  69. // this activity.
  70. mSystemUiHider = SystemUiHider.getInstance(this, contentView, HIDER_FLAGS);
  71. mSystemUiHider.setup();
  72. mSystemUiHider
  73. .setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() {
  74. // Cached values.
  75. int mControlsHeight;
  76. int mShortAnimTime;
  77.  
  78. @Override
  79. @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
  80. public void onVisibilityChange(boolean visible) {
  81. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
  82. // If the ViewPropertyAnimator API is available
  83. // (Honeycomb MR2 and later), use it to animate the
  84. // in-layout UI controls at the bottom of the
  85. // screen.
  86. if (mControlsHeight == 0) {
  87. mControlsHeight = controlsView.getHeight();
  88. }
  89. if (mShortAnimTime == 0) {
  90. mShortAnimTime = getResources().getInteger(
  91. android.R.integer.config_shortAnimTime);
  92. }
  93. controlsView.animate()
  94. .translationY(visible ? 0 : mControlsHeight)
  95. .setDuration(mShortAnimTime);
  96. } else {
  97. // If the ViewPropertyAnimator APIs aren't
  98. // available, simply show or hide the in-layout UI
  99. // controls.
  100. controlsView.setVisibility(visible ? View.VISIBLE : View.GONE);
  101. }
  102.  
  103. if (visible && AUTO_HIDE) {
  104. // Schedule a hide().
  105. delayedHide(AUTO_HIDE_DELAY_MILLIS);
  106. }
  107. }
  108. });
  109.  
  110.  
  111.  
  112. //MediaPlayer
  113. final MediaPlayer mp = new MediaPlayer();
  114. Button b = (Button) findViewById(R.id.playButton);
  115.  
  116. b.setOnClickListener(new OnClickListener() {
  117.  
  118. @Override
  119. public void onClick(View v) {
  120.  
  121. if(mp.isPlaying())
  122. {
  123. mp.stop();
  124. mp.reset();
  125. }
  126. try {
  127. AssetFileDescriptor afd;
  128. afd = getAssets().openFd("muzyczka.mp3");
  129. mp.setDataSource(afd.getFileDescriptor(),afd.getStartOffset(),afd.getLength());
  130. mp.prepare();
  131. mp.start();
  132. } catch (IllegalStateException e) {
  133. e.printStackTrace();
  134. } catch (IOException e) {
  135. e.printStackTrace();
  136. }
  137.  
  138. }
  139. });
  140.  
  141. // Info button
  142. Button B = (Button) findViewById(R.id.infoButton);
  143. B.setOnClickListener(new OnClickListener(){
  144. public void onClick(View arg0) {
  145. Dialog d = new Dialog(FullscreenActivity.this);
  146. d.setContentView(R.layout.info_dialog);
  147. d.setTitle("App Information");
  148. d.show();
  149. }
  150. });
  151.  
  152.  
  153.  
  154. }
  155.  
  156. @Override
  157. protected void onPostCreate(Bundle savedInstanceState) {
  158. super.onPostCreate(savedInstanceState);
  159.  
  160. // Trigger the initial hide() shortly after the activity has been
  161. // created, to briefly hint to the user that UI controls
  162. // are available.
  163. delayedHide(100);
  164. }
  165.  
  166. /**
  167. * Touch listener to use for in-layout UI controls to delay hiding the
  168. * system UI. This is to prevent the jarring behavior of controls going away
  169. * while interacting with activity UI.
  170. */
  171. View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
  172. @Override
  173. public boolean onTouch(View view, MotionEvent motionEvent) {
  174. if (AUTO_HIDE) {
  175. delayedHide(AUTO_HIDE_DELAY_MILLIS);
  176. }
  177. return false;
  178. }
  179. };
  180.  
  181. Handler mHideHandler = new Handler();
  182. Runnable mHideRunnable = new Runnable() {
  183. @Override
  184. public void run() {
  185. mSystemUiHider.hide();
  186. }
  187. };
  188.  
  189. /**
  190. * Schedules a call to hide() in [delay] milliseconds, canceling any
  191. * previously scheduled calls.
  192. */
  193. private void delayedHide(int delayMillis) {
  194. mHideHandler.removeCallbacks(mHideRunnable);
  195. mHideHandler.postDelayed(mHideRunnable, delayMillis);
  196. }
  197.  
  198. //losuj z tablict
  199. public String randMp3return() {
  200. String[][] mp3s = {
  201. {"gatunek", "D. Kwiatkowski - Jak to", "muzyczka.mp3"},
  202. {"gatunek", "Fasolki - Zając Poziomka", "muzyczka.mp3"},
  203. {"gatunek", "Mezo/Lajner - Mezokracja", "muzyczka.mp3"},
  204. {"gatunek", "Peja - Ciemno już", "muzyczka.mp3"}
  205. };
  206.  
  207. int idx = new Random().nextInt(mp3s.length);
  208. String mp3NameString = (mp3s[idx][1]);
  209. return mp3NameString;
  210. }
  211.  
  212. //przypisz nazwe pod pole TextView
  213. public void randMp3(View view) {
  214. //String mp3FileString = (mp3s[idx][2]);
  215. String mp3NameString = randMp3return();
  216. TextView mp3Name = (TextView)findViewById(R.id.mp3Name);
  217. mp3Name.setText(mp3NameString);
  218. }
  219.  
  220. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement