use of android.annotation.TargetApi in project Shuttle by timusus.
the class EqualizerActivity method onCreate.
@SuppressLint("InlinedApi")
@TargetApi(Build.VERSION_CODES.GINGERBREAD)
@Override
public void onCreate(Bundle savedInstanceState) {
mPrefs = PreferenceManager.getDefaultSharedPreferences(this);
ThemeUtils.setTheme(this);
if (!ShuttleUtils.hasLollipop() && ShuttleUtils.hasKitKat()) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
mTintManager = new SystemBarTintManager(this);
}
if (!ShuttleUtils.hasKitKat()) {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
}
if (SettingsManager.getInstance().canTintNavBar()) {
getWindow().setNavigationBarColor(ColorUtils.getPrimaryColorDark(this));
}
super.onCreate(savedInstanceState);
overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
setContentView(R.layout.activity_equalizer);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
ThemeUtils.themeActionBar(this);
ThemeUtils.themeStatusBar(this, mTintManager);
ActionBar actionBar = getSupportActionBar();
actionBar.setTitle(getResources().getString(R.string.equalizer));
try {
//Query available effects
final AudioEffect.Descriptor[] effects = AudioEffect.queryEffects();
//Determine available/supported effects
if (effects != null && effects.length != 0) {
for (final AudioEffect.Descriptor effect : effects) {
//Equalizer
if (effect.type.equals(UUID.fromString(EFFECT_TYPE_EQUALIZER))) {
mEqualizerSupported = true;
} else if (effect.type.equals(UUID.fromString(EFFECT_TYPE_BASS_BOOST))) {
mBassBoostSupported = true;
} else if (effect.type.equals(UUID.fromString(EFFECT_TYPE_VIRTUALIZER))) {
mVirtualizerSupported = true;
}
}
}
} catch (NoClassDefFoundError ignored) {
//The user doesn't have the AudioEffect/AudioEffect.Descriptor class. How sad.
}
mSpinner = (Spinner) findViewById(R.id.eqSpinner);
mSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
mEqPreset = position;
equalizerSetPreset(position);
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
setupPresets();
if (mSpinnerAdapter != null && mSpinnerAdapter.getCount() > mEqPreset) {
mSpinner.setSelection(mEqPreset);
}
//Initialize the equalizer elements
View eqContainer = findViewById(R.id.eqContainer);
mNumberEqualizerBands = Integer.parseInt(mPrefs.getString("equalizer.number_of_bands", "5"));
final int[] centerFreqs = getCenterFreqs();
final int[] bandLevelRange = getBandLevelRange();
for (int band = 0; band < mNumberEqualizerBands; band++) {
//Unit conversion from mHz to Hz and use k prefix if necessary to display
float centerFreqHz = centerFreqs[band] / 1000;
String unitPrefix = "";
if (centerFreqHz >= 1000) {
centerFreqHz = centerFreqHz / 1000;
unitPrefix = "k";
}
(eqContainer.findViewById(eqViewElementIds[band][0])).setVisibility(View.VISIBLE);
(eqContainer.findViewById(eqViewTextElementIds[band][0])).setVisibility(View.VISIBLE);
(eqContainer.findViewById(eqViewElementIds[band][1])).setVisibility(View.VISIBLE);
(eqContainer.findViewById(eqViewTextElementIds[band][1])).setVisibility(View.VISIBLE);
((TextView) eqContainer.findViewById(eqViewElementIds[band][0])).setText(format("%.0f ", centerFreqHz) + unitPrefix + "Hz");
mEqualizerSeekBar[band] = (SizableSeekBar) eqContainer.findViewById(eqViewElementIds[band][1]);
ThemeUtils.themeSeekBar(this, mEqualizerSeekBar[band]);
mEqualizerSeekBar[band].setMax((bandLevelRange[1] / 100) - (bandLevelRange[0] / 100));
mEqualizerSeekBar[band].setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
if (fromUser) {
//Determine which band changed
int seekbarId = seekBar.getId();
int band = 0;
for (int i = 0; i < eqViewElementIds.length; i++) {
if (eqViewElementIds[i][1] == seekbarId) {
band = i;
}
}
if (mEqPreset != mEqCustomPresetPosition) {
equalizerCopyToCustom();
if (mSpinnerAdapter != null && mSpinnerAdapter.getCount() > mEqCustomPresetPosition) {
mSpinner.setSelection(mEqCustomPresetPosition);
}
} else {
int level = getBandLevelRange()[0] + (progress * 100);
equalizerBandUpdate(band, level);
}
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
mHandler.sendEmptyMessage(MSG_UPDATE_SERVICE);
}
});
}
// Set the SeekBar listener.
if (mBassBoostSupported) {
final SizableSeekBar seekbar = (SizableSeekBar) findViewById(R.id.bb_strength);
ThemeUtils.themeSeekBar(this, seekbar);
seekbar.setMax(OpenSLESConstants.BASSBOOST_MAX_STRENGTH - OpenSLESConstants.BASSBOOST_MIN_STRENGTH);
seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
// set parameter and state
if (fromUser) {
mPrefs.edit().putBoolean("audiofx.bass.enable", true).apply();
mPrefs.edit().putString("audiofx.bass.strength", String.valueOf(progress)).apply();
mHandler.sendEmptyMessage(MSG_UPDATE_SERVICE);
}
}
// If slider pos was 0 when starting re-enable effect
@Override
public void onStartTrackingTouch(final SeekBar seekBar) {
if (seekBar.getProgress() == 0) {
mPrefs.edit().putBoolean("audiofx.bass.enable", true).apply();
mHandler.sendEmptyMessage(MSG_UPDATE_SERVICE);
}
}
// If slider pos = 0 when stopping disable effect
@Override
public void onStopTrackingTouch(final SeekBar seekBar) {
if (seekBar.getProgress() == 0) {
// disable
mPrefs.edit().putBoolean("audiofx.bass.enable", false).apply();
mHandler.sendEmptyMessage(MSG_UPDATE_SERVICE);
}
}
});
}
// Set the SeekBar listener.
if (mVirtualizerSupported) {
final SizableSeekBar seekbar = (SizableSeekBar) findViewById(R.id.virtualizer_strength);
ThemeUtils.themeSeekBar(this, seekbar);
seekbar.setMax(OpenSLESConstants.VIRTUALIZER_MAX_STRENGTH - OpenSLESConstants.VIRTUALIZER_MIN_STRENGTH);
seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) {
// set parameter and state
if (fromUser) {
mPrefs.edit().putBoolean("audiofx.virtualizer.enable", true).apply();
mPrefs.edit().putString("audiofx.virtualizer.strength", String.valueOf(progress)).apply();
mHandler.sendEmptyMessage(MSG_UPDATE_SERVICE);
}
}
// If slider pos was 0 when starting re-enable effect
@Override
public void onStartTrackingTouch(final SeekBar seekBar) {
if (seekBar.getProgress() == 0) {
mPrefs.edit().putBoolean("audiofx.virtualizer.enable", true).apply();
mHandler.sendEmptyMessage(MSG_UPDATE_SERVICE);
}
}
// If slider pos = 0 when stopping disable effect
@Override
public void onStopTrackingTouch(final SeekBar seekBar) {
if (seekBar.getProgress() == 0) {
// disable
mPrefs.edit().putBoolean("audiofx.virtualizer.enable", false).apply();
mHandler.sendEmptyMessage(MSG_UPDATE_SERVICE);
}
}
});
}
}
use of android.annotation.TargetApi in project RxPermissions by tbruyelle.
the class RxPermissionsTest method subscription_granted.
@Test
@TargetApi(Build.VERSION_CODES.M)
public void subscription_granted() {
TestSubscriber<Boolean> sub = new TestSubscriber<>();
String permission = Manifest.permission.READ_PHONE_STATE;
when(mRxPermissions.isGranted(permission)).thenReturn(false);
int[] result = new int[] { PackageManager.PERMISSION_GRANTED };
trigger().compose(mRxPermissions.ensure(permission)).subscribe(sub);
mRxPermissions.onRequestPermissionsResult(new String[] { permission }, result);
sub.assertNoErrors();
sub.assertTerminalEvent();
sub.assertUnsubscribed();
sub.assertReceivedOnNext(singletonList(true));
}
use of android.annotation.TargetApi in project RxPermissions by tbruyelle.
the class RxPermissionsTest method shouldShowRequestPermissionRationale_oneDeniedRationale.
@Test
@TargetApi(Build.VERSION_CODES.M)
public void shouldShowRequestPermissionRationale_oneDeniedRationale() {
when(mRxPermissions.isMarshmallow()).thenReturn(true);
Activity activity = mock(Activity.class);
when(mRxPermissions.isGranted("p1")).thenReturn(true);
when(activity.shouldShowRequestPermissionRationale("p2")).thenReturn(true);
TestSubscriber<Boolean> sub = new TestSubscriber<>();
mRxPermissions.shouldShowRequestPermissionRationale(activity, new String[] { "p1", "p2" }).subscribe(sub);
sub.assertCompleted();
sub.assertNoErrors();
sub.assertReceivedOnNext(Collections.singletonList(true));
}
use of android.annotation.TargetApi in project RxPermissions by tbruyelle.
the class RxPermissionsTest method eachSubscription_granted.
@Test
@TargetApi(Build.VERSION_CODES.M)
public void eachSubscription_granted() {
TestSubscriber<Permission> sub = new TestSubscriber<>();
String permission = Manifest.permission.READ_PHONE_STATE;
when(mRxPermissions.isGranted(permission)).thenReturn(false);
int[] result = new int[] { PackageManager.PERMISSION_GRANTED };
trigger().compose(mRxPermissions.ensureEach(permission)).subscribe(sub);
mRxPermissions.onRequestPermissionsResult(new String[] { permission }, result);
sub.assertNoErrors();
sub.assertTerminalEvent();
sub.assertUnsubscribed();
sub.assertReceivedOnNext(singletonList(new Permission(permission, true)));
}
use of android.annotation.TargetApi in project RxPermissions by tbruyelle.
the class RxPermissionsTest method subscription_alreadyGranted.
@Test
@TargetApi(Build.VERSION_CODES.M)
public void subscription_alreadyGranted() {
TestSubscriber<Boolean> sub = new TestSubscriber<>();
String permission = Manifest.permission.READ_PHONE_STATE;
when(mRxPermissions.isGranted(permission)).thenReturn(true);
trigger().compose(mRxPermissions.ensure(permission)).subscribe(sub);
sub.assertNoErrors();
sub.assertTerminalEvent();
sub.assertUnsubscribed();
sub.assertReceivedOnNext(singletonList(true));
}
Aggregations