Remove deprecated API-level related code
This commit is contained in:
parent
cab37665c6
commit
75ad0a0239
|
@ -18,7 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package net.nullsum.audinaut.activity;
|
package net.nullsum.audinaut.activity;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.widget.Toolbar;
|
import android.support.v7.widget.Toolbar;
|
||||||
|
@ -32,7 +31,6 @@ public class SettingsActivity extends SubsonicActivity {
|
||||||
private static final String TAG = SettingsActivity.class.getSimpleName();
|
private static final String TAG = SettingsActivity.class.getSimpleName();
|
||||||
private PreferenceCompatFragment fragment;
|
private PreferenceCompatFragment fragment;
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1)
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
|
@ -832,14 +832,11 @@ public class SubsonicActivity extends AppCompatActivity implements OnItemSelecte
|
||||||
private void applyFullscreen() {
|
private void applyFullscreen() {
|
||||||
fullScreen = Util.getPreferences(this).getBoolean(Constants.PREFERENCES_KEY_FULL_SCREEN, false);
|
fullScreen = Util.getPreferences(this).getBoolean(Constants.PREFERENCES_KEY_FULL_SCREEN, false);
|
||||||
if(fullScreen ) {
|
if(fullScreen ) {
|
||||||
// Hide additional elements on higher Android versions
|
int flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
View.SYSTEM_UI_FLAG_FULLSCREEN |
|
||||||
int flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
|
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
|
||||||
View.SYSTEM_UI_FLAG_FULLSCREEN |
|
|
||||||
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
|
|
||||||
|
|
||||||
getWindow().getDecorView().setSystemUiVisibility(flags);
|
getWindow().getDecorView().setSystemUiVisibility(flags);
|
||||||
}
|
|
||||||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,6 @@ import java.io.Serializable;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.media.audiofx.BassBoost;
|
import android.media.audiofx.BassBoost;
|
||||||
import android.media.audiofx.Equalizer;
|
import android.media.audiofx.Equalizer;
|
||||||
import android.os.Build;
|
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import net.nullsum.audinaut.util.FileUtil;
|
import net.nullsum.audinaut.util.FileUtil;
|
||||||
|
|
||||||
|
@ -35,164 +34,162 @@ import net.nullsum.audinaut.util.FileUtil;
|
||||||
*/
|
*/
|
||||||
public class EqualizerController {
|
public class EqualizerController {
|
||||||
|
|
||||||
private static final String TAG = EqualizerController.class.getSimpleName();
|
private static final String TAG = EqualizerController.class.getSimpleName();
|
||||||
|
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private Equalizer equalizer;
|
private Equalizer equalizer;
|
||||||
private BassBoost bass;
|
private BassBoost bass;
|
||||||
private boolean loudnessAvailable = false;
|
private boolean loudnessAvailable = false;
|
||||||
private LoudnessEnhancerController loudnessEnhancerController;
|
private LoudnessEnhancerController loudnessEnhancerController;
|
||||||
private boolean released = false;
|
private boolean released = false;
|
||||||
private int audioSessionId = 0;
|
private int audioSessionId = 0;
|
||||||
|
|
||||||
public EqualizerController(Context context, int audioSessionId) {
|
public EqualizerController(Context context, int audioSessionId) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
this.audioSessionId = audioSessionId;
|
this.audioSessionId = audioSessionId;
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
equalizer = new Equalizer(0, audioSessionId);
|
equalizer = new Equalizer(0, audioSessionId);
|
||||||
bass = new BassBoost(0, audioSessionId);
|
bass = new BassBoost(0, audioSessionId);
|
||||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
loudnessAvailable = true;
|
||||||
loudnessAvailable = true;
|
loudnessEnhancerController = new LoudnessEnhancerController(context, audioSessionId);
|
||||||
loudnessEnhancerController = new LoudnessEnhancerController(context, audioSessionId);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void saveSettings() {
|
public void saveSettings() {
|
||||||
try {
|
try {
|
||||||
if (isAvailable()) {
|
if (isAvailable()) {
|
||||||
FileUtil.serialize(context, new EqualizerSettings(equalizer, bass, loudnessEnhancerController), "equalizer.dat");
|
FileUtil.serialize(context, new EqualizerSettings(equalizer, bass, loudnessEnhancerController), "equalizer.dat");
|
||||||
}
|
}
|
||||||
} catch (Throwable x) {
|
} catch (Throwable x) {
|
||||||
Log.w(TAG, "Failed to save equalizer settings.", x);
|
Log.w(TAG, "Failed to save equalizer settings.", x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void loadSettings() {
|
public void loadSettings() {
|
||||||
try {
|
try {
|
||||||
if (isAvailable()) {
|
if (isAvailable()) {
|
||||||
EqualizerSettings settings = FileUtil.deserialize(context, "equalizer.dat", EqualizerSettings.class);
|
EqualizerSettings settings = FileUtil.deserialize(context, "equalizer.dat", EqualizerSettings.class);
|
||||||
if (settings != null) {
|
if (settings != null) {
|
||||||
settings.apply(equalizer, bass, loudnessEnhancerController);
|
settings.apply(equalizer, bass, loudnessEnhancerController);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Throwable x) {
|
} catch (Throwable x) {
|
||||||
Log.w(TAG, "Failed to load equalizer settings.", x);
|
Log.w(TAG, "Failed to load equalizer settings.", x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAvailable() {
|
public boolean isAvailable() {
|
||||||
return equalizer != null && bass != null;
|
return equalizer != null && bass != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isEnabled() {
|
public boolean isEnabled() {
|
||||||
try {
|
try {
|
||||||
return isAvailable() && equalizer.getEnabled();
|
return isAvailable() && equalizer.getEnabled();
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void release() {
|
public void release() {
|
||||||
if (isAvailable()) {
|
if (isAvailable()) {
|
||||||
released = true;
|
released = true;
|
||||||
equalizer.release();
|
equalizer.release();
|
||||||
bass.release();
|
bass.release();
|
||||||
if(loudnessEnhancerController != null && loudnessEnhancerController.isAvailable()) {
|
if(loudnessEnhancerController != null && loudnessEnhancerController.isAvailable()) {
|
||||||
loudnessEnhancerController.release();
|
loudnessEnhancerController.release();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Equalizer getEqualizer() {
|
public Equalizer getEqualizer() {
|
||||||
if(released) {
|
if(released) {
|
||||||
released = false;
|
released = false;
|
||||||
try {
|
try {
|
||||||
init();
|
init();
|
||||||
} catch (Throwable x) {
|
} catch (Throwable x) {
|
||||||
equalizer = null;
|
equalizer = null;
|
||||||
released = true;
|
released = true;
|
||||||
Log.w(TAG, "Failed to create equalizer.", x);
|
Log.w(TAG, "Failed to create equalizer.", x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return equalizer;
|
return equalizer;
|
||||||
}
|
}
|
||||||
public BassBoost getBassBoost() {
|
public BassBoost getBassBoost() {
|
||||||
if(released) {
|
if(released) {
|
||||||
released = false;
|
released = false;
|
||||||
try {
|
try {
|
||||||
init();
|
init();
|
||||||
} catch (Throwable x) {
|
} catch (Throwable x) {
|
||||||
bass = null;
|
bass = null;
|
||||||
Log.w(TAG, "Failed to create bass booster.", x);
|
Log.w(TAG, "Failed to create bass booster.", x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bass;
|
return bass;
|
||||||
}
|
}
|
||||||
public LoudnessEnhancerController getLoudnessEnhancerController() {
|
public LoudnessEnhancerController getLoudnessEnhancerController() {
|
||||||
if(loudnessAvailable && released) {
|
if(loudnessAvailable && released) {
|
||||||
released = false;
|
released = false;
|
||||||
try {
|
try {
|
||||||
init();
|
init();
|
||||||
} catch (Throwable x) {
|
} catch (Throwable x) {
|
||||||
loudnessEnhancerController = null;
|
loudnessEnhancerController = null;
|
||||||
Log.w(TAG, "Failed to create loudness enhancer.", x);
|
Log.w(TAG, "Failed to create loudness enhancer.", x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return loudnessEnhancerController;
|
return loudnessEnhancerController;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class EqualizerSettings implements Serializable {
|
private static class EqualizerSettings implements Serializable {
|
||||||
|
|
||||||
private short[] bandLevels;
|
private short[] bandLevels;
|
||||||
private short preset;
|
private short preset;
|
||||||
private boolean enabled;
|
private boolean enabled;
|
||||||
private short bass;
|
private short bass;
|
||||||
private int loudness;
|
private int loudness;
|
||||||
|
|
||||||
public EqualizerSettings() {
|
public EqualizerSettings() {
|
||||||
|
|
||||||
}
|
}
|
||||||
public EqualizerSettings(Equalizer equalizer, BassBoost boost, LoudnessEnhancerController loudnessEnhancerController) {
|
public EqualizerSettings(Equalizer equalizer, BassBoost boost, LoudnessEnhancerController loudnessEnhancerController) {
|
||||||
enabled = equalizer.getEnabled();
|
enabled = equalizer.getEnabled();
|
||||||
bandLevels = new short[equalizer.getNumberOfBands()];
|
bandLevels = new short[equalizer.getNumberOfBands()];
|
||||||
for (short i = 0; i < equalizer.getNumberOfBands(); i++) {
|
for (short i = 0; i < equalizer.getNumberOfBands(); i++) {
|
||||||
bandLevels[i] = equalizer.getBandLevel(i);
|
bandLevels[i] = equalizer.getBandLevel(i);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
preset = equalizer.getCurrentPreset();
|
preset = equalizer.getCurrentPreset();
|
||||||
} catch (Exception x) {
|
} catch (Exception x) {
|
||||||
preset = -1;
|
preset = -1;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
bass = boost.getRoundedStrength();
|
bass = boost.getRoundedStrength();
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
bass = 0;
|
bass = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
loudness = (int) loudnessEnhancerController.getGain();
|
loudness = (int) loudnessEnhancerController.getGain();
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
loudness = 0;
|
loudness = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void apply(Equalizer equalizer, BassBoost boost, LoudnessEnhancerController loudnessController) {
|
public void apply(Equalizer equalizer, BassBoost boost, LoudnessEnhancerController loudnessController) {
|
||||||
for (short i = 0; i < bandLevels.length; i++) {
|
for (short i = 0; i < bandLevels.length; i++) {
|
||||||
equalizer.setBandLevel(i, bandLevels[i]);
|
equalizer.setBandLevel(i, bandLevels[i]);
|
||||||
}
|
}
|
||||||
equalizer.setEnabled(enabled);
|
equalizer.setEnabled(enabled);
|
||||||
if(bass != 0) {
|
if(bass != 0) {
|
||||||
boost.setEnabled(true);
|
boost.setEnabled(true);
|
||||||
boost.setStrength(bass);
|
boost.setStrength(bass);
|
||||||
}
|
}
|
||||||
if(loudness != 0) {
|
if(loudness != 0) {
|
||||||
loudnessController.enable();
|
loudnessController.enable();
|
||||||
loudnessController.setGain(loudness);
|
loudnessController.setGain(loudness);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package net.nullsum.audinaut.domain;
|
package net.nullsum.audinaut.domain;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.media.MediaMetadataRetriever;
|
import android.media.MediaMetadataRetriever;
|
||||||
|
@ -256,7 +255,6 @@ public class MusicDirectory implements Serializable {
|
||||||
this.linkedArtist = artist;
|
this.linkedArtist = artist;
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.GINGERBREAD_MR1)
|
|
||||||
public void loadMetadata(File file) {
|
public void loadMetadata(File file) {
|
||||||
try {
|
try {
|
||||||
MediaMetadataRetriever metadata = new MediaMetadataRetriever();
|
MediaMetadataRetriever metadata = new MediaMetadataRetriever();
|
||||||
|
|
|
@ -20,7 +20,6 @@ import java.util.concurrent.Executors;
|
||||||
import java.util.concurrent.ScheduledExecutorService;
|
import java.util.concurrent.ScheduledExecutorService;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -711,7 +710,6 @@ public class NowPlayingFragment extends SubsonicFragment implements OnGestureLis
|
||||||
}
|
}
|
||||||
|
|
||||||
// Scroll to current playing/downloading.
|
// Scroll to current playing/downloading.
|
||||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
|
||||||
private void scrollToCurrent() {
|
private void scrollToCurrent() {
|
||||||
if (getDownloadService() == null || songListAdapter == null) {
|
if (getDownloadService() == null || songListAdapter == null) {
|
||||||
scrollWhenLoaded = true;
|
scrollWhenLoaded = true;
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package net.nullsum.audinaut.fragments;
|
package net.nullsum.audinaut.fragments;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
@ -57,7 +56,6 @@ public class SelectArtistFragment extends SelectRecyclerFragment<Serializable> i
|
||||||
outState.putSerializable(Constants.FRAGMENT_LIST2, (Serializable) musicFolders);
|
outState.putSerializable(Constants.FRAGMENT_LIST2, (Serializable) musicFolders);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) {
|
||||||
Bundle args = getArguments();
|
Bundle args = getArguments();
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package net.nullsum.audinaut.fragments;
|
package net.nullsum.audinaut.fragments;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.support.v7.app.AlertDialog;
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package net.nullsum.audinaut.fragments;
|
package net.nullsum.audinaut.fragments;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.SearchManager;
|
import android.app.SearchManager;
|
||||||
import android.app.SearchableInfo;
|
import android.app.SearchableInfo;
|
||||||
|
|
|
@ -58,7 +58,6 @@ import java.util.Date;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.ComponentCallbacks2;
|
import android.content.ComponentCallbacks2;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
|
@ -186,12 +185,8 @@ public class DownloadService extends Service {
|
||||||
|
|
||||||
if(audioSessionId == -1) {
|
if(audioSessionId == -1) {
|
||||||
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
|
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
|
||||||
try {
|
audioSessionId = mediaPlayer.getAudioSessionId();
|
||||||
audioSessionId = mediaPlayer.getAudioSessionId();
|
prefs.edit().putInt(Constants.CACHE_AUDIO_SESSION_ID, audioSessionId).apply();
|
||||||
prefs.edit().putInt(Constants.CACHE_AUDIO_SESSION_ID, audioSessionId).apply();
|
|
||||||
} catch (Throwable t) {
|
|
||||||
// Froyo or lower
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
|
mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
|
||||||
|
@ -202,15 +197,6 @@ public class DownloadService extends Service {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
/*try {
|
|
||||||
Intent i = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION);
|
|
||||||
i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, audioSessionId);
|
|
||||||
i.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
|
|
||||||
sendBroadcast(i);
|
|
||||||
} catch(Throwable e) {
|
|
||||||
// Froyo or lower
|
|
||||||
}*/
|
|
||||||
|
|
||||||
effectsController = new AudioEffectsController(DownloadService.this, audioSessionId);
|
effectsController = new AudioEffectsController(DownloadService.this, audioSessionId);
|
||||||
if(prefs.getBoolean(Constants.PREFERENCES_EQUALIZER_ON, false)) {
|
if(prefs.getBoolean(Constants.PREFERENCES_EQUALIZER_ON, false)) {
|
||||||
getEqualizerController();
|
getEqualizerController();
|
||||||
|
@ -285,14 +271,10 @@ public class DownloadService extends Service {
|
||||||
if(currentPlaying != null) currentPlaying.setPlaying(false);
|
if(currentPlaying != null) currentPlaying.setPlaying(false);
|
||||||
lifecycleSupport.onDestroy();
|
lifecycleSupport.onDestroy();
|
||||||
|
|
||||||
try {
|
Intent i = new Intent(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION);
|
||||||
Intent i = new Intent(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION);
|
i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, audioSessionId);
|
||||||
i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, audioSessionId);
|
i.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
|
||||||
i.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName());
|
sendBroadcast(i);
|
||||||
sendBroadcast(i);
|
|
||||||
} catch(Throwable e) {
|
|
||||||
// Froyo or lower
|
|
||||||
}
|
|
||||||
|
|
||||||
mediaPlayer.release();
|
mediaPlayer.release();
|
||||||
if(nextMediaPlayer != null) {
|
if(nextMediaPlayer != null) {
|
||||||
|
|
|
@ -37,7 +37,6 @@ import java.util.List;
|
||||||
import java.util.zip.DeflaterOutputStream;
|
import java.util.zip.DeflaterOutputStream;
|
||||||
import java.util.zip.InflaterInputStream;
|
import java.util.zip.InflaterInputStream;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
|
@ -775,7 +774,6 @@ public class FileUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
|
|
||||||
public static <T extends Serializable> T deserializeCompressed(Context context, String fileName, Class<T> tClass) {
|
public static <T extends Serializable> T deserializeCompressed(Context context, String fileName, Class<T> tClass) {
|
||||||
Input in = null;
|
Input in = null;
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package net.nullsum.audinaut.util;
|
package net.nullsum.audinaut.util;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
|
|
|
@ -1,16 +1,16 @@
|
||||||
/*
|
/*
|
||||||
This file is part of Subsonic.
|
This file is part of Subsonic.
|
||||||
Subsonic is free software: you can redistribute it and/or modify
|
Subsonic is free software: you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
the Free Software Foundation, either version 3 of the License, or
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
(at your option) any later version.
|
(at your option) any later version.
|
||||||
Subsonic is distributed in the hope that it will be useful,
|
Subsonic is distributed in the hope that it will be useful,
|
||||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
GNU General Public License for more details.
|
GNU General Public License for more details.
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
|
along with Subsonic. If not, see <http://www.gnu.org/licenses/>.
|
||||||
Copyright 2015 (C) Scott Jackson
|
Copyright 2015 (C) Scott Jackson
|
||||||
*/
|
*/
|
||||||
package net.nullsum.audinaut.view;
|
package net.nullsum.audinaut.view;
|
||||||
|
|
||||||
|
@ -36,110 +36,108 @@ import net.nullsum.audinaut.R;
|
||||||
import net.nullsum.audinaut.util.FileUtil;
|
import net.nullsum.audinaut.util.FileUtil;
|
||||||
|
|
||||||
public class CacheLocationPreference extends EditTextPreference {
|
public class CacheLocationPreference extends EditTextPreference {
|
||||||
private static final String TAG = CacheLocationPreference.class.getSimpleName();
|
private static final String TAG = CacheLocationPreference.class.getSimpleName();
|
||||||
private Context context;
|
private Context context;
|
||||||
|
|
||||||
public CacheLocationPreference(Context context, AttributeSet attrs, int defStyle) {
|
public CacheLocationPreference(Context context, AttributeSet attrs, int defStyle) {
|
||||||
super(context, attrs, defStyle);
|
super(context, attrs, defStyle);
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
public CacheLocationPreference(Context context, AttributeSet attrs) {
|
public CacheLocationPreference(Context context, AttributeSet attrs) {
|
||||||
super(context, attrs);
|
super(context, attrs);
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
public CacheLocationPreference(Context context) {
|
public CacheLocationPreference(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onBindDialogView(View view) {
|
protected void onBindDialogView(View view) {
|
||||||
super.onBindDialogView(view);
|
super.onBindDialogView(view);
|
||||||
|
|
||||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
view.setLayoutParams(new ViewGroup.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||||
view.setLayoutParams(new ViewGroup.LayoutParams(android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT));
|
|
||||||
|
|
||||||
final EditText editText = (EditText) view.findViewById(android.R.id.edit);
|
final EditText editText = (EditText) view.findViewById(android.R.id.edit);
|
||||||
ViewGroup vg = (ViewGroup) editText.getParent();
|
ViewGroup vg = (ViewGroup) editText.getParent();
|
||||||
|
|
||||||
LinearLayout cacheButtonsWrapper = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.cache_location_buttons, vg, true);
|
LinearLayout cacheButtonsWrapper = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.cache_location_buttons, vg, true);
|
||||||
Button internalLocation = (Button) cacheButtonsWrapper.findViewById(R.id.location_internal);
|
Button internalLocation = (Button) cacheButtonsWrapper.findViewById(R.id.location_internal);
|
||||||
Button externalLocation = (Button) cacheButtonsWrapper.findViewById(R.id.location_external);
|
Button externalLocation = (Button) cacheButtonsWrapper.findViewById(R.id.location_external);
|
||||||
|
|
||||||
File[] dirs;
|
File[] dirs;
|
||||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
dirs = context.getExternalMediaDirs();
|
dirs = context.getExternalMediaDirs();
|
||||||
} else {
|
} else {
|
||||||
dirs = ContextCompat.getExternalFilesDirs(context, null);
|
dirs = ContextCompat.getExternalFilesDirs(context, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Past 5.0 we can query directly for SD Card
|
// Past 5.0 we can query directly for SD Card
|
||||||
File internalDir = null, externalDir = null;
|
File internalDir = null, externalDir = null;
|
||||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
for(int i = 0; i < dirs.length; i++) {
|
for(int i = 0; i < dirs.length; i++) {
|
||||||
try {
|
try {
|
||||||
if (dirs[i] != null) {
|
if (dirs[i] != null) {
|
||||||
if(Environment.isExternalStorageRemovable(dirs[i])) {
|
if(Environment.isExternalStorageRemovable(dirs[i])) {
|
||||||
if(externalDir != null) {
|
if(externalDir != null) {
|
||||||
externalDir = dirs[i];
|
externalDir = dirs[i];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
internalDir = dirs[i];
|
internalDir = dirs[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if(internalDir != null && externalDir != null) {
|
if(internalDir != null && externalDir != null) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e(TAG, "Failed to check if is external", e);
|
Log.e(TAG, "Failed to check if is external", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Before 5.0, we have to guess. Most of the time the SD card is last
|
// Before 5.0, we have to guess. Most of the time the SD card is last
|
||||||
if(externalDir == null) {
|
if(externalDir == null) {
|
||||||
for (int i = dirs.length - 1; i >= 0; i--) {
|
for (int i = dirs.length - 1; i >= 0; i--) {
|
||||||
if (dirs[i] != null) {
|
if (dirs[i] != null) {
|
||||||
externalDir = dirs[i];
|
externalDir = dirs[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(internalDir == null) {
|
if(internalDir == null) {
|
||||||
for (int i = 0; i < dirs.length; i++) {
|
for (int i = 0; i < dirs.length; i++) {
|
||||||
if (dirs[i] != null) {
|
if (dirs[i] != null) {
|
||||||
internalDir = dirs[i];
|
internalDir = dirs[i];
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final File finalInternalDir = new File(internalDir, "music");
|
final File finalInternalDir = new File(internalDir, "music");
|
||||||
final File finalExternalDir = new File(externalDir, "music");
|
final File finalExternalDir = new File(externalDir, "music");
|
||||||
|
|
||||||
if(finalInternalDir != null && (finalInternalDir.exists() || finalInternalDir.mkdirs())) {
|
if(finalInternalDir != null && (finalInternalDir.exists() || finalInternalDir.mkdirs())) {
|
||||||
internalLocation.setOnClickListener(new View.OnClickListener() {
|
internalLocation.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
String path = finalInternalDir.getPath();
|
String path = finalInternalDir.getPath();
|
||||||
editText.setText(path);
|
editText.setText(path);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
internalLocation.setEnabled(false);
|
internalLocation.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(finalExternalDir != null && !finalInternalDir.equals(finalExternalDir) && (finalExternalDir.exists() || finalExternalDir.mkdirs())) {
|
if(finalExternalDir != null && !finalInternalDir.equals(finalExternalDir) && (finalExternalDir.exists() || finalExternalDir.mkdirs())) {
|
||||||
externalLocation.setOnClickListener(new View.OnClickListener() {
|
externalLocation.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
String path = finalExternalDir.getPath();
|
String path = finalExternalDir.getPath();
|
||||||
editText.setText(path);
|
editText.setText(path);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
externalLocation.setEnabled(false);
|
externalLocation.setEnabled(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package net.nullsum.audinaut.view;
|
package net.nullsum.audinaut.view;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Path;
|
import android.graphics.Path;
|
||||||
|
@ -32,7 +31,6 @@ public class CardView extends FrameLayout{
|
||||||
init(context);
|
init(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
|
||||||
public CardView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
public CardView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||||
super(context, attrs, defStyleAttr, defStyleRes);
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
init(context);
|
init(context);
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
|
|
||||||
package net.nullsum.audinaut.view;
|
package net.nullsum.audinaut.view;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
|
|
Loading…
Reference in New Issue