Search in sources :

Example 81 with TargetApi

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);
                }
            }
        });
    }
}
Also used : SizableSeekBar(com.simplecity.amp_library.ui.views.SizableSeekBar) SeekBar(android.widget.SeekBar) SystemBarTintManager(com.readystatesoftware.systembartint.SystemBarTintManager) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) SizableSeekBar(com.simplecity.amp_library.ui.views.SizableSeekBar) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar) AudioEffect(android.media.audiofx.AudioEffect) SuppressLint(android.annotation.SuppressLint) TargetApi(android.annotation.TargetApi)

Example 82 with TargetApi

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));
}
Also used : TestSubscriber(rx.observers.TestSubscriber) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 83 with TargetApi

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));
}
Also used : Activity(android.app.Activity) TestSubscriber(rx.observers.TestSubscriber) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 84 with TargetApi

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)));
}
Also used : TestSubscriber(rx.observers.TestSubscriber) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Example 85 with TargetApi

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));
}
Also used : TestSubscriber(rx.observers.TestSubscriber) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test) TargetApi(android.annotation.TargetApi)

Aggregations

TargetApi (android.annotation.TargetApi)1365 Intent (android.content.Intent)153 View (android.view.View)147 Test (org.junit.Test)119 SuppressLint (android.annotation.SuppressLint)115 Uri (android.net.Uri)70 ArrayList (java.util.ArrayList)68 Animator (android.animation.Animator)67 Point (android.graphics.Point)64 Window (android.view.Window)56 TextView (android.widget.TextView)56 IOException (java.io.IOException)56 ViewGroup (android.view.ViewGroup)53 Matchers.anyString (org.mockito.Matchers.anyString)53 SharedPreferences (android.content.SharedPreferences)44 File (java.io.File)44 Field (java.lang.reflect.Field)44 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)43 Bitmap (android.graphics.Bitmap)42 ImageView (android.widget.ImageView)40