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