List of usage examples for android.media SoundPool SoundPool
public SoundPool(int maxStreams, int streamType, int srcQuality)
From source file:com.ayaseya.nolnotification.GcmIntentService.java
@Override protected void onHandleIntent(final Intent intent) { extras = intent.getExtras();//www .j av a 2s . c o m GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); // displayMessage(this, extras.toString()); if (!extras.isEmpty()) { // has effect of unparcelling Bundle /* * Filter messages based on message type. Since it is likely that GCM will be * extended in the future with new message types, just ignore any message types you're * not interested in, or that you don't recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { // sendNotification("Send error: " + extras.toString()); Log.v(TAG, "Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { // sendNotification("Deleted messages on server: " + extras.toString()); Log.v(TAG, "Deleted messages on server: " + extras.toString()); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // This loop represents the service doing some work. for (int i = 0; i < 5; i++) { Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime()); try { Thread.sleep(5000); } catch (InterruptedException e) { } } Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime()); // Post notification of received message. // ?????IntentService???????? // ????????? new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { // Log.v(TAG, "doInBackground()"); // soundPool????? soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0); // soundPool??Listener?????? soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() { @Override public void onLoadComplete(final SoundPool soundPool, int sampleId, int status) { if (status == 0) { if (notificationPermission) {// ???????? // Notification???? sendNotification("?????" + extras.get("INDEX") + "????", intent); //?????????? if (isPlugged) {// ??????? Log.v(TAG, "??????"); if (ringerMode) {// Log.v(TAG, ""); if (checkbox_sound) { soundPool.play(se, 0.5F, 0.5F, 0, 0, 1.0F); } if (checkbox_vibration) { vibrator.vibrate(1500); } } else if (vibrateMode) {// Log.v(TAG, ""); if (checkbox_vibration) { vibrator.vibrate(1500); } } else if (silentMode) {// Log.v(TAG, ""); if (checkbox_sound) { soundPool.play(se, 0.5F, 0.5F, 0, 0, 1.0F); } } } else {// ????????? Log.v(TAG, "??????"); if (ringerMode) {// Log.v(TAG, ""); if (checkbox_sound) { soundPool.play(se, 0.5F, 0.5F, 0, 0, 1.0F); } if (checkbox_vibration) { vibrator.vibrate(1500); } } else if (vibrateMode) {// Log.v(TAG, ""); if (checkbox_vibration) { vibrator.vibrate(1500); } } else if (silentMode) {// Log.v(TAG, ""); } } } // ?soundPool???? new Thread(new Runnable() { @Override public void run() { try { Thread.sleep(30000); } catch (InterruptedException e) { } // Log.v(TAG, "soundPool.release()"); soundPool.release(); } }).start(); } } }); // soundPool????? se = soundPool.load(GcmIntentService.this, R.raw.notification_sound, 1); return null; } }.execute(null, null, null); // sendNotification("??????" + extras.get("INDEX") + "???", intent); // sendNotification("Received: " + extras.toString()); Log.i(TAG, "Received: " + extras.toString()); } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:io.puzzlebox.orbit.ui.OrbitFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View v = inflater.inflate(R.layout.fragment_orbit, container, false); // requestWindowFeature(Window.FEATURE_CUSTOM_TITLE); // setContentView(R.layout.main); // getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title); buttonConnectOrbit = (Button) v.findViewById(R.id.buttonConnectOrbit); buttonConnectOrbit.setOnClickListener(new View.OnClickListener() { @Override/*from w w w. jav a2 s . c o m*/ public void onClick(View v) { setOrbitActivate(); } }); Button buttonTestFlight = (Button) v.findViewById(R.id.buttonTestFlight); buttonTestFlight.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { demoMode(v); } }); progressBarAttention = (ProgressBar) v.findViewById(R.id.progressBarAttention); final float[] roundedCorners = new float[] { 5, 5, 5, 5, 5, 5, 5, 5 }; ShapeDrawable progressBarAttentionDrawable = new ShapeDrawable( new RoundRectShape(roundedCorners, null, null)); String progressBarAttentionColor = "#FF0000"; progressBarAttentionDrawable.getPaint().setColor(Color.parseColor(progressBarAttentionColor)); ClipDrawable progressAttention = new ClipDrawable(progressBarAttentionDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL); progressBarAttention.setProgressDrawable(progressAttention); progressBarAttention .setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal)); progressBarMeditation = (ProgressBar) v.findViewById(R.id.progressBarMeditation); ShapeDrawable progressBarMeditationDrawable = new ShapeDrawable( new RoundRectShape(roundedCorners, null, null)); String progressBarMeditationColor = "#0000FF"; progressBarMeditationDrawable.getPaint().setColor(Color.parseColor(progressBarMeditationColor)); ClipDrawable progressMeditation = new ClipDrawable(progressBarMeditationDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL); progressBarMeditation.setProgressDrawable(progressMeditation); progressBarMeditation .setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal)); progressBarSignal = (ProgressBar) v.findViewById(R.id.progressBarSignal); ShapeDrawable progressBarSignalDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null, null)); String progressBarSignalColor = "#00FF00"; progressBarSignalDrawable.getPaint().setColor(Color.parseColor(progressBarSignalColor)); ClipDrawable progressSignal = new ClipDrawable(progressBarSignalDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL); progressBarSignal.setProgressDrawable(progressSignal); progressBarSignal.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal)); // progressBarSignal.setProgress(tgSignal); progressBarPower = (ProgressBar) v.findViewById(R.id.progressBarPower); ShapeDrawable progressBarPowerDrawable = new ShapeDrawable(new RoundRectShape(roundedCorners, null, null)); String progressBarPowerColor = "#FFFF00"; progressBarPowerDrawable.getPaint().setColor(Color.parseColor(progressBarPowerColor)); ClipDrawable progressPower = new ClipDrawable(progressBarPowerDrawable, Gravity.LEFT, ClipDrawable.HORIZONTAL); progressBarPower.setProgressDrawable(progressPower); progressBarPower.setBackgroundDrawable(getResources().getDrawable(android.R.drawable.progress_horizontal)); seekBarAttention = (SeekBar) v.findViewById(R.id.seekBarAttention); seekBarAttention.setOnSeekBarChangeListener(this); seekBarMeditation = (SeekBar) v.findViewById(R.id.seekBarMeditation); seekBarMeditation.setOnSeekBarChangeListener(this); imageViewStatus = (ImageView) v.findViewById(R.id.imageViewStatus); textViewLabelScores = (TextView) v.findViewById(R.id.textViewLabelScores); textViewLabelScore = (TextView) v.findViewById(R.id.textViewLabelScore); textViewLabelLastScore = (TextView) v.findViewById(R.id.textViewLabelLastScore); textViewLabelHighScore = (TextView) v.findViewById(R.id.textViewLabelHighScore); viewSpaceScore = (View) v.findViewById(R.id.viewSpaceScore); viewSpaceScoreLast = (View) v.findViewById(R.id.viewSpaceScoreLast); viewSpaceScoreHigh = (View) v.findViewById(R.id.viewSpaceScoreHigh); textViewScore = (TextView) v.findViewById(R.id.textViewScore); textViewLastScore = (TextView) v.findViewById(R.id.textViewLastScore); textViewHighScore = (TextView) v.findViewById(R.id.textViewHighScore); // Hide the "Scores" label by default textViewLabelScores.setVisibility(View.GONE); viewSpaceScore.setVisibility(View.GONE); /** * AudioHandler */ if (!OrbitSingleton.getInstance().audioHandler.isAlive()) { /** * Prepare audio stream */ maximizeAudioVolume(); // Automatically set media volume to maximum /** Set the hardware buttons to control the audio output */ getActivity().setVolumeControlStream(AudioManager.STREAM_MUSIC); /** Preload the flight control WAV file into memory */ OrbitSingleton.getInstance().soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0); OrbitSingleton.getInstance().soundPool .setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() { public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { OrbitSingleton.getInstance().loaded = true; } }); OrbitSingleton.getInstance().soundID = OrbitSingleton.getInstance().soundPool .load(getActivity().getApplicationContext(), OrbitSingleton.getInstance().audioFile, 1); OrbitSingleton.getInstance().audioHandler.start(); } if (OrbitSingleton.getInstance().flightActive) buttonTestFlight.setText(getResources().getString(R.string.button_stop_test)); /** * Update settings according to default UI */ updateScreenLayout(); updatePowerThresholds(); // updatePower(); return v; }
From source file:com.thomasokken.free42.Free42Activity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); instance = this; int init_mode; IntHolder version = new IntHolder(); try {//from www. jav a 2 s . c o m stateFileInputStream = openFileInput("state"); } catch (FileNotFoundException e) { stateFileInputStream = null; } if (stateFileInputStream != null) { if (read_shell_state(version)) init_mode = 1; else { init_shell_state(-1); init_mode = 2; } } else { init_shell_state(-1); init_mode = 0; } setAlwaysRepaintFullDisplay(alwaysRepaintFullDisplay); if (alwaysOn) getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); if (style == 1) setTheme(android.R.style.Theme_NoTitleBar_Fullscreen); else if (style == 2) { try { Method m = View.class.getMethod("setSystemUiVisibility", int.class); m.invoke(getWindow().getDecorView(), PreferencesDialog.immersiveModeFlags); } catch (Exception e) { } } Configuration conf = getResources().getConfiguration(); orientation = conf.orientation == Configuration.ORIENTATION_LANDSCAPE ? 1 : 0; mainHandler = new Handler(); calcView = new CalcView(this); setContentView(calcView); printView = new PrintView(this); printScrollView = new ScrollView(this); printScrollView.setBackgroundColor(PRINT_BACKGROUND_COLOR); printScrollView.addView(printView); skin = null; if (skinName[orientation].length() == 0 && externalSkinName[orientation].length() > 0) { try { skin = new SkinLayout(externalSkinName[orientation], skinSmoothing[orientation], displaySmoothing[orientation]); } catch (IllegalArgumentException e) { } } if (skin == null) { try { skin = new SkinLayout(skinName[orientation], skinSmoothing[orientation], displaySmoothing[orientation]); } catch (IllegalArgumentException e) { } } if (skin == null) { try { skin = new SkinLayout(builtinSkinNames[0], skinSmoothing[orientation], displaySmoothing[orientation]); } catch (IllegalArgumentException e) { // This one should never fail; we're loading a built-in skin. } } nativeInit(); core_init(init_mode, version.value); if (stateFileInputStream != null) { try { stateFileInputStream.close(); } catch (IOException e) { } stateFileInputStream = null; } lowBatteryReceiver = new BroadcastReceiver() { public void onReceive(Context ctx, Intent intent) { low_battery = intent.getAction().equals(Intent.ACTION_BATTERY_LOW); Rect inval = skin.update_annunciators(-1, -1, -1, -1, low_battery ? 1 : 0, -1, -1); if (inval != null) calcView.postInvalidateScaled(inval.left, inval.top, inval.right, inval.bottom); } }; IntentFilter iff = new IntentFilter(); iff.addAction(Intent.ACTION_BATTERY_LOW); iff.addAction(Intent.ACTION_BATTERY_OKAY); registerReceiver(lowBatteryReceiver, iff); if (preferredOrientation != this.getRequestedOrientation()) setRequestedOrientation(preferredOrientation); soundPool = new SoundPool(1, AudioManager.STREAM_SYSTEM, 0); int[] soundResourceIds = { R.raw.tone0, R.raw.tone1, R.raw.tone2, R.raw.tone3, R.raw.tone4, R.raw.tone5, R.raw.tone6, R.raw.tone7, R.raw.tone8, R.raw.tone9, R.raw.squeak, R.raw.click }; soundIds = new int[soundResourceIds.length]; for (int i = 0; i < soundResourceIds.length; i++) soundIds[i] = soundPool.load(this, soundResourceIds[i], 1); }
From source file:org.telegram.messenger.MessagesController.java
public MessagesController() { MessagesStorage storage = MessagesStorage.Instance; NotificationCenter.Instance.addObserver(this, FileLoader.FileDidUpload); NotificationCenter.Instance.addObserver(this, FileLoader.FileDidFailUpload); NotificationCenter.Instance.addObserver(this, 10); addSupportUser();//from ww w . j a va2 s . c o m SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("Notifications", Activity.MODE_PRIVATE); enableJoined = preferences.getBoolean("EnableContactJoined", true); try { soundPool = new SoundPool(1, AudioManager.STREAM_NOTIFICATION, 0); sound = soundPool.load(ApplicationLoader.applicationContext, R.raw.sound_a, 1); } catch (Exception e) { FileLog.e("tmessages", e); } }
From source file:com.nextgis.maplibui.activity.ModifyAttributesActivity.java
@SuppressWarnings("deprecation") protected void createSoundPool() { mSoundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 100); mBeepId = mSoundPool.load(this, R.raw.beep, 1); }
From source file:edu.missouri.bas.service.SensorService.java
@SuppressWarnings("deprecation") @Override/*from w ww . j ava 2 s.c o m*/ public void onCreate() { super.onCreate(); Log.d(TAG, "Starting sensor service"); mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100); soundsMap = new HashMap<Integer, Integer>(); soundsMap.put(SOUND1, mSoundPool.load(this, R.raw.bodysensor_alarm, 1)); soundsMap.put(SOUND2, mSoundPool.load(this, R.raw.voice_notification, 1)); serviceContext = this; mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); bluetoothMacAddress = mBluetoothAdapter.getAddress(); mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); //Get location manager mLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); activityRecognition = new ActivityRecognitionScan(getApplicationContext()); activityRecognition.startActivityRecognitionScan(); mPowerManager = (PowerManager) getSystemService(Context.POWER_SERVICE); serviceWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "SensorServiceLock"); serviceWakeLock.acquire(); //Initialize start time stime = System.currentTimeMillis(); //Setup calendar object Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(stime); /* * Setup notification manager */ notification = new Notification(R.drawable.icon2, "Recorded", System.currentTimeMillis()); notification.defaults = 0; notification.flags |= Notification.FLAG_ONGOING_EVENT; notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Intent notifyIntent = new Intent(Intent.ACTION_MAIN); notifyIntent.setClass(this, MainActivity.class); /* * Display notification that service has started */ notification.tickerText = "Sensor Service Running"; PendingIntent contentIntent = PendingIntent.getActivity(SensorService.this, 0, notifyIntent, Notification.FLAG_ONGOING_EVENT); notification.setLatestEventInfo(SensorService.this, getString(R.string.app_name), "Recording service started at: " + cal.getTime().toString(), contentIntent); notificationManager.notify(SensorService.SERVICE_NOTIFICATION_ID, notification); // locationControl = new LocationControl(this, mLocationManager, 1000 * 60, 200, 5000); IntentFilter activityResultFilter = new IntentFilter(XMLSurveyActivity.INTENT_ACTION_SURVEY_RESULTS); SensorService.this.registerReceiver(alarmReceiver, activityResultFilter); IntentFilter sensorDataFilter = new IntentFilter(SensorService.ACTION_SENSOR_DATA); SensorService.this.registerReceiver(alarmReceiver, sensorDataFilter); Log.d(TAG, "Sensor service created."); try { prepareIO(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } prepareAlarms(); Intent startSensors = new Intent(SensorService.ACTION_START_SENSORS); this.sendBroadcast(startSensors); Intent scheduleCheckConnection = new Intent(SensorService.ACTION_SCHEDULE_CHECK); scheduleCheck = PendingIntent.getBroadcast(serviceContext, 0, scheduleCheckConnection, 0); mAlarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 1000 * 60 * 5, 1000 * 60 * 5, scheduleCheck); mLocationClient = new LocationClient(this, this, this); }
From source file:com.intel.xdk.player.Player.java
public void unloadAllSounds() { Iterator<Entry<String, Integer>> soundPoolNamesAndIdsIter = soundPoolMapName2Id.entrySet().iterator(); while (soundPoolNamesAndIdsIter.hasNext()) { Entry<String, Integer> nameAndId = soundPoolNamesAndIdsIter.next(); Integer id = nameAndId.getValue(); String key = nameAndId.getKey(); soundPoolMapName2Id.remove(key); soundPoolMapId2Name.remove(id); soundPoolShouldPlay.remove(key); }// w w w . j a v a 2 s .c om soundPool.release(); soundPool = null; soundPool = new SoundPool(30, AudioManager.STREAM_MUSIC, 100); // StringBuffer js = new StringBuffer("javascript:var ev = document.createEvent('Events');ev.initEvent('intel.xdk.player.sound.unload',true,true);ev.name='"); // js.append(strRelativeFileURL); // js.append("';e.success="); // js.append(didUnload); // js.append("document.dispatchEvent(ev);"); // // injectJS(js.toString()); }
From source file:com.ferdi2005.secondgram.voip.VoIPService.java
@Override public void onCreate() { super.onCreate(); FileLog.d("=============== VoIPService STARTING ==============="); AudioManager am = (AudioManager) getSystemService(AUDIO_SERVICE); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1 && am.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER) != null) { int outFramesPerBuffer = Integer .parseInt(am.getProperty(AudioManager.PROPERTY_OUTPUT_FRAMES_PER_BUFFER)); VoIPController.setNativeBufferSize(outFramesPerBuffer); } else {//ww w. j a v a 2 s . c om VoIPController.setNativeBufferSize( AudioTrack.getMinBufferSize(48000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT) / 2); } final SharedPreferences preferences = getSharedPreferences("mainconfig", MODE_PRIVATE); VoIPServerConfig.setConfig(preferences.getString("voip_server_config", "{}")); if (System.currentTimeMillis() - preferences.getLong("voip_server_config_updated", 0) > 24 * 3600000) { ConnectionsManager.getInstance().sendRequest(new TLRPC.TL_phone_getCallConfig(), new RequestDelegate() { @Override public void run(TLObject response, TLRPC.TL_error error) { if (error == null) { String data = ((TLRPC.TL_dataJSON) response).data; VoIPServerConfig.setConfig(data); preferences.edit().putString("voip_server_config", data) .putLong("voip_server_config_updated", BuildConfig.DEBUG ? 0 : System.currentTimeMillis()) .apply(); } } }); } try { controller = new VoIPController(); controller.setConnectionStateListener(this); controller.setConfig(MessagesController.getInstance().callPacketTimeout / 1000.0, MessagesController.getInstance().callConnectTimeout / 1000.0, preferences.getInt("VoipDataSaving", VoIPController.DATA_SAVING_NEVER)); cpuWakelock = ((PowerManager) getSystemService(POWER_SERVICE)) .newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "telegram-voip"); cpuWakelock.acquire(); btAdapter = am.isBluetoothScoAvailableOffCall() ? BluetoothAdapter.getDefaultAdapter() : null; IntentFilter filter = new IntentFilter(); filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); filter.addAction(ACTION_HEADSET_PLUG); if (btAdapter != null) { filter.addAction(BluetoothHeadset.ACTION_CONNECTION_STATE_CHANGED); filter.addAction(AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED); } filter.addAction(TelephonyManager.ACTION_PHONE_STATE_CHANGED); filter.addAction(getPackageName() + ".END_CALL"); filter.addAction(getPackageName() + ".DECLINE_CALL"); filter.addAction(getPackageName() + ".ANSWER_CALL"); registerReceiver(receiver, filter); ConnectionsManager.getInstance().setAppPaused(false, false); soundPool = new SoundPool(1, AudioManager.STREAM_VOICE_CALL, 0); spConnectingId = soundPool.load(this, R.raw.voip_connecting, 1); spRingbackID = soundPool.load(this, R.raw.voip_ringback, 1); spFailedID = soundPool.load(this, R.raw.voip_failed, 1); spEndId = soundPool.load(this, R.raw.voip_end, 1); spBusyId = soundPool.load(this, R.raw.voip_busy, 1); am.registerMediaButtonEventReceiver(new ComponentName(this, VoIPMediaButtonReceiver.class)); if (btAdapter != null && btAdapter.isEnabled()) { int headsetState = btAdapter.getProfileConnectionState(BluetoothProfile.HEADSET); updateBluetoothHeadsetState(headsetState == BluetoothProfile.STATE_CONNECTED); if (headsetState == BluetoothProfile.STATE_CONNECTED) am.setBluetoothScoOn(true); for (StateListener l : stateListeners) l.onAudioSettingsChanged(); } NotificationCenter.getInstance().addObserver(this, NotificationCenter.appDidLogout); } catch (Exception x) { FileLog.e("error initializing voip controller", x); callFailed(); } }
From source file:org.docrj.smartcard.reader.AppSelectActivity.java
private void initSoundPool() { synchronized (this) { if (mSoundPool == null) { mSoundPool = new SoundPool(1, AudioManager.STREAM_NOTIFICATION, 0); mTapSound = mSoundPool.load(this, R.raw.tap, 1); }/*from w w w . j a va 2 s . c o m*/ } }
From source file:com.google.android.apps.santatracker.games.gumball.TiltGameFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { mRootView = inflater.inflate(R.layout.fragment_gumball, container, false); mRootView.setKeepScreenOn(true);/*from w w w. jav a2 s. co m*/ // Use a lower resolution background image to conserve memory below ICS if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { View matchScoreLayout = mRootView.findViewById(R.id.tilt_score_layout); matchScoreLayout.setBackgroundResource(R.drawable.score_background_gingerbread); } mViewPlayAgainScore = (TextView) mRootView.findViewById(R.id.play_again_score); mViewPlayAgainScore.setText(String.valueOf(mMatchScore)); mViewPlayAgainLevel = (TextView) mRootView.findViewById(R.id.play_again_level); mViewPlayAgainLevel.setText(String.valueOf(mCurrentLevelNum)); mViewPlayAgainBackground = mRootView.findViewById(R.id.play_again_bkgrd); mViewPlayAgainMain = mRootView.findViewById(R.id.play_again_main); mViewPlayAgainButton = (Button) mRootView.findViewById(R.id.play_again_btn); mViewPlayAgainButton.setOnClickListener(this); mViewGPlusSignIn = (ImageView) mRootView.findViewById(R.id.gplus_button); mViewGPlusSignIn.setOnClickListener(this); mViewGPlusLayout = mRootView.findViewById(R.id.play_again_gplus); mViewGPlusLayout.setVisibility(View.GONE); // Initialise all animations // Construct an animation to blink the timer indefinitely mAnimationTimerAlpha = new AlphaAnimation(0.0f, 1.0f); mAnimationTimerAlpha.setDuration(1000); mAnimationTimerAlpha.setRepeatMode(Animation.REVERSE); mAnimationTimerAlpha.setRepeatCount(Animation.INFINITE); // Load all other animations mAnimationPlayAgainBackground = AnimationUtils.loadAnimation(getActivity(), R.anim.play_again_bkgrd_anim); mAnimationPlayAgainBackground.setFillAfter(true); mAnimationPlayAgainBackground.setAnimationListener(this); mAnimationPlayAgainMain = AnimationUtils.loadAnimation(getActivity(), R.anim.play_again_main_anim); mAnimationPlayAgainMain.setFillAfter(true); mAnimationPlayAgainMain.setAnimationListener(this); mAnimationScaleLevelDown = AnimationUtils.loadAnimation(getActivity(), R.anim.scale_level_anim_down); mAnimationScaleLevelDown.setAnimationListener(this); mAnimationLevelFadeOut = AnimationUtils.loadAnimation(getActivity(), R.anim.level_fade_out_anim); mAnimationLevelFadeOut.setAnimationListener(this); mAnimationLevelScaleUp = AnimationUtils.loadAnimation(getActivity(), R.anim.scale_up_level_anim); mAnimationLevelScaleUp.setAnimationListener(this); mViewMainMenuButton = (ImageButton) mRootView.findViewById(R.id.main_menu_button); mViewMainMenuButton.setVisibility(View.GONE); mViewMainMenuButton.setOnClickListener(this); mGameOutlet = mRootView.findViewById(R.id.tiltGameOutlet); mOutletOffset = getResources().getInteger(R.integer.outlet_offset); mViewIndicators[0] = (ImageView) mRootView.findViewById(R.id.indicator1); mViewIndicators[1] = (ImageView) mRootView.findViewById(R.id.indicator2); mViewIndicators[2] = (ImageView) mRootView.findViewById(R.id.indicator3); mViewIndicators[3] = (ImageView) mRootView.findViewById(R.id.indicator4); mViewIndicators[4] = (ImageView) mRootView.findViewById(R.id.indicator5); mViewIndicators[5] = (ImageView) mRootView.findViewById(R.id.indicator6); mViewCountdown = (TextView) mRootView.findViewById(R.id.tiltTimer); mLevelNumberText = (LevelTextView) mRootView.findViewById(R.id.tilt_end_level_number); mLevelNumberText.setVisibility(View.GONE); mEndLevelCircle = (CircleView) mRootView.findViewById(R.id.tilt_end_level_circle); mEndLevelCircle.setVisibility(View.GONE); mViewPlayButton = (ImageView) mRootView.findViewById(R.id.tilt_play_button); mViewPlayButton.setOnClickListener(this); mViewPlayButton.setVisibility(View.GONE); mViewPauseButton = (ImageView) mRootView.findViewById(R.id.tilt_pause_button); mViewPauseButton.setOnClickListener(this); mViewPauseButton.setVisibility(View.VISIBLE); mViewMatchPauseOverlay = mRootView.findViewById(R.id.tilt_pause_overlay); mViewMatchPauseOverlay.setVisibility(View.GONE); mViewBigPlayButton = (ImageButton) mRootView.findViewById(R.id.tilt_big_play_button); mViewBigPlayButton.setOnClickListener(this); mViewCancelBar = (ImageView) mRootView.findViewById(R.id.tilt_cancel_bar); mViewCancelBar.setOnClickListener(this); mViewCancelBar.setVisibility(View.GONE); mViewScore = (TextView) mRootView.findViewById(R.id.tilt_score); mViewScore.setText(String.valueOf(mMatchScore)); mGameView = (TiltGameView) mRootView.findViewById(R.id.tiltGameView); // Create the Box2D physics world. mWorld = new PhysicsWorld(); Vec2 gravity = new Vec2(0.0f, 0.0f); mWorld.create(gravity); mGameView.setModel(mWorld); mWorld.getWorld().setContactListener(this); mGumballQueue = new LinkedList<>(); // Initialise the sound pool and audio playback mSoundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0); mSoundBounceSmall = mSoundPool.load(getActivity(), R.raw.gbg_ball_bounce_1, 1); mSoundBounceMed = mSoundPool.load(getActivity(), R.raw.gbg_ball_bounce_2, 1); mSoundBounceLarge = mSoundPool.load(getActivity(), R.raw.gbg_ball_bounce_3, 1); mSoundBallInMachine = mSoundPool.load(getActivity(), R.raw.gbg_ball_into_machine, 1); mSoundBallFail = mSoundPool.load(getActivity(), R.raw.gbg_ball_fall_out, 1); mSoundBallDrop = mSoundPool.load(getActivity(), R.raw.gbg_new_ball_bounce_drop, 1); mSoundGameOver = mSoundPool.load(getActivity(), R.raw.gameover, 1); // Display the instructions if they haven't been seen before mSharedPreferences = getActivity().getSharedPreferences(MatchingGameConstants.PREFERENCES_FILENAME, Context.MODE_PRIVATE); if (!mSharedPreferences.getBoolean(MatchingGameConstants.GUMBALL_INSTRUCTIONS_VIEWED, false)) { mDrawableTransition = new AnimationDrawable(); mDrawableTransition.addFrame(getResources().getDrawable(R.drawable.instructions_shake_1), 300); mDrawableTransition.addFrame(getResources().getDrawable(R.drawable.instructions_shake_2), 300); mDrawableTransition.addFrame(getResources().getDrawable(R.drawable.instructions_shake_3), 300); mDrawableTransition.setOneShot(false); mViewInstructions = (ImageView) mRootView.findViewById(R.id.instructions); if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { mViewInstructions.setImageResource(R.drawable.instructions_shake_1); } else { mViewInstructions.setImageDrawable(mDrawableTransition); mViewInstructions.post(new Runnable() { public void run() { mDrawableTransition.start(); } }); } // Hide the instructions after 2 seconds mViewInstructions.postDelayed(new HideInstructionsRunnable(), 2200); } return mRootView; }