Diminuzione e aumento del brightness in base al fatto che stia playando o no. Workaround #1
This commit is contained in:
parent
b09c81568b
commit
49e79b723f
1 changed files with 25 additions and 3 deletions
|
@ -18,6 +18,7 @@ import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.WindowManager;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.SeekBar;
|
import android.widget.SeekBar;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
@ -40,6 +41,8 @@ public class MusicPlayerActivity extends Activity implements OnCompletionListene
|
||||||
// Media Player
|
// Media Player
|
||||||
private MediaPlayer mp;
|
private MediaPlayer mp;
|
||||||
// Handler to update UI timer, progress bar etc,.
|
// Handler to update UI timer, progress bar etc,.
|
||||||
|
private WindowManager.LayoutParams layout;
|
||||||
|
|
||||||
private Handler mHandler = new Handler();
|
private Handler mHandler = new Handler();
|
||||||
private SongsManager songManager;
|
private SongsManager songManager;
|
||||||
private Utilities utils;
|
private Utilities utils;
|
||||||
|
@ -54,6 +57,9 @@ public class MusicPlayerActivity extends Activity implements OnCompletionListene
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.pl_player);
|
setContentView(R.layout.pl_player);
|
||||||
|
|
||||||
|
layout = getWindow().getAttributes();
|
||||||
|
|
||||||
Log.d(LOG_TAG, "onCreate()");
|
Log.d(LOG_TAG, "onCreate()");
|
||||||
// All player buttons
|
// All player buttons
|
||||||
btnPlay = (ImageButton) findViewById(R.id.btnPlay);
|
btnPlay = (ImageButton) findViewById(R.id.btnPlay);
|
||||||
|
@ -265,6 +271,9 @@ public class MusicPlayerActivity extends Activity implements OnCompletionListene
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View arg0) {
|
public void onClick(View arg0) {
|
||||||
|
layout.screenBrightness = -1;
|
||||||
|
getWindow().setAttributes(layout);
|
||||||
|
|
||||||
Intent i = new Intent(getApplicationContext(), PlayListActivity.class);
|
Intent i = new Intent(getApplicationContext(), PlayListActivity.class);
|
||||||
startActivityForResult(i, 100);
|
startActivityForResult(i, 100);
|
||||||
}
|
}
|
||||||
|
@ -275,6 +284,7 @@ public class MusicPlayerActivity extends Activity implements OnCompletionListene
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
resumeSong();
|
resumeSong();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -292,6 +302,9 @@ public class MusicPlayerActivity extends Activity implements OnCompletionListene
|
||||||
} else {
|
} else {
|
||||||
playng=true;
|
playng=true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
layout.screenBrightness = 0.1f;
|
||||||
|
getWindow().setAttributes(layout);
|
||||||
}
|
}
|
||||||
|
|
||||||
return playng;
|
return playng;
|
||||||
|
@ -306,10 +319,10 @@ public class MusicPlayerActivity extends Activity implements OnCompletionListene
|
||||||
int resultCode, Intent data) {
|
int resultCode, Intent data) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
if(resultCode == 100){
|
if(resultCode == 100){
|
||||||
currentSongIndex = data.getExtras().getInt("songIndex");
|
currentSongIndex = data.getExtras().getInt("songIndex");
|
||||||
Log.d(LOG_TAG, "onActivityResult(), dalla playlist "+currentSongIndex);
|
Log.d(LOG_TAG, "onActivityResult(), dalla playlist "+currentSongIndex);
|
||||||
// play selected song
|
// play selected song
|
||||||
playSong(currentSongIndex);
|
playSong(currentSongIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -322,6 +335,10 @@ public class MusicPlayerActivity extends Activity implements OnCompletionListene
|
||||||
// Play song
|
// Play song
|
||||||
try {
|
try {
|
||||||
Log.d(LOG_TAG, "playSong() "+songIndex);
|
Log.d(LOG_TAG, "playSong() "+songIndex);
|
||||||
|
|
||||||
|
layout.screenBrightness = 0.1f;
|
||||||
|
getWindow().setAttributes(layout);
|
||||||
|
|
||||||
mp.reset();
|
mp.reset();
|
||||||
mp.setDataSource(songsList.get(songIndex).get("songPath"));
|
mp.setDataSource(songsList.get(songIndex).get("songPath"));
|
||||||
mp.prepare();
|
mp.prepare();
|
||||||
|
@ -448,6 +465,9 @@ public class MusicPlayerActivity extends Activity implements OnCompletionListene
|
||||||
if(mp != null) {
|
if(mp != null) {
|
||||||
if(mp.isPlaying()){
|
if(mp.isPlaying()){
|
||||||
mp.pause();
|
mp.pause();
|
||||||
|
|
||||||
|
layout.screenBrightness = -1;
|
||||||
|
getWindow().setAttributes(layout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -456,6 +476,8 @@ public class MusicPlayerActivity extends Activity implements OnCompletionListene
|
||||||
public void onDestroy(){
|
public void onDestroy(){
|
||||||
Log.d(LOG_TAG, "onDestroy()");
|
Log.d(LOG_TAG, "onDestroy()");
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
layout.screenBrightness = -1;
|
||||||
|
getWindow().setAttributes(layout);
|
||||||
if(mp != null) {
|
if(mp != null) {
|
||||||
mHandler.removeCallbacks(mUpdateTimeTask);
|
mHandler.removeCallbacks(mUpdateTimeTask);
|
||||||
mp.release();
|
mp.release();
|
||||||
|
|
Loading…
Reference in a new issue