Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make default showVolumeUI configurable #43

Closed
belens opened this issue Jul 2, 2018 · 19 comments
Closed

make default showVolumeUI configurable #43

belens opened this issue Jul 2, 2018 · 19 comments

Comments

@belens
Copy link

belens commented Jul 2, 2018

Would be handy to define if the volume ui feedback is shown by default, now if you just want to track volume and nothing else, the volume feedback is suppressed.

It would be nice to be able to set if the ui is shown initially, since it is always turned off once you load react-native-system-setting.

@c19354837
Copy link
Owner

since it is always turned off once you load react-native-system-setting

setVolumn(0.5, { showUI: true }) doesn't work ?

@amsul
Copy link

amsul commented Jul 24, 2018

@c19354837 that doesn't seem to work for me. It'd be really nice to have this as a configurable open on initialize :)

@c19354837
Copy link
Owner

How about the example?

@amsul
Copy link

amsul commented Jul 25, 2018

That would only be when you're changing the volume. But if you're only using the library to listen to the volume changes, then setVolume is never going to be called.

@c19354837
Copy link
Owner

Do you mean that hide the system volume UI when you press volume up/down buttons?

@amsul
Copy link

amsul commented Jul 25, 2018

@c19354837 I mean, we should be able to see the system volume UI when the up/down volume buttons are pressed if we're only using SystemSetting.addVolumeListener

@alexfigliolia
Copy link

Agreed, with a volume listener this library will hide the default UI

@c19354837
Copy link
Owner

I reproduce in iOS, while Android is OK. Have you tested it in Android @amsul @alexfigliolia ?

@amsul
Copy link

amsul commented Aug 1, 2018

@c19354837 nope..I only checked iOS. Is there an easy way to resolve this?

@c19354837
Copy link
Owner

V 1.5.1 is available. It'll show volume UI by default for iOS when you press the physical volume button

setVolumn(value, { showUI: false }) will hide the UI again for iOS.

Android shows the UI always

@amsul
Copy link

amsul commented Aug 2, 2018

@c19354837 awesome!! Thanks for the quick release 🙏

@pppppppppppp12
Copy link

For Android, when I press the physical volume button, how can i hide the system Volum UI with a volume listener ?

@c19354837
Copy link
Owner

For Android, you can add these codes in yourPorject/src/main/java/.../MainActivity.java

public class MainActivity extends ReactActivity {
    @Override
    protected String getMainComponentName() {
        return "SystemSettingExample";
    }

    // hide the system volume UI
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
            AudioManager manager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
            manager.adjustVolume(AudioManager.ADJUST_LOWER, 0);
        }
        if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)) {
            AudioManager manager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
            manager.adjustVolume(AudioManager.ADJUST_RAISE, 0);
        }
        return true;
    }
}

@pppppppppppp12
Copy link

@c19354837 thanks~

@alexfigliolia
Copy link

@c19354837 Thank you for quick fix

@heyman333
Copy link

@c19354837 Sorry to bother you..

this code makes android hardware backButton not working properly

    // hide the system volume UI
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
            AudioManager manager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
            manager.adjustVolume(AudioManager.ADJUST_LOWER, 0);
        }
        if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)) {
            AudioManager manager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
            manager.adjustVolume(AudioManager.ADJUST_RAISE, 0);
        }
        return true;
    }

@heyman333
Copy link

heyman333 commented Oct 15, 2018

I found a solution

import android.os.Bundle;
import org.devio.rn.splashscreen.SplashScreen;
import android.view.KeyEvent;
import android.media.AudioManager;
import android.content.Context;
import com.facebook.react.ReactActivity;
import com.facebook.react.ReactInstanceManager;


public class MainActivity extends ReactActivity {
    private ReactInstanceManager mReactInstanceManager;

    /**
     * Returns the name of the main component registered from JavaScript.
     * This is used to schedule rendering of the component.
     */

    .....

    // hide the system volume UI
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            if (mReactInstanceManager != null) {
                mReactInstanceManager.onBackPressed();
            } else {
                super.onBackPressed();
            }  
        }
        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
            AudioManager manager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
            manager.adjustVolume(AudioManager.ADJUST_LOWER, 0);
        }
        if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
            AudioManager manager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
            manager.adjustVolume(AudioManager.ADJUST_RAISE, 0);
        }
        return true;
    }
}

@c19354837
Copy link
Owner

Thank you. It's my fault, and my codes will block any key event. The right codes can be

public class MainActivity extends ReactActivity {
    @Override
    protected String getMainComponentName() {
        return "SystemSettingExample";
    }

    // hide the system volume UI
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if ((keyCode == KeyEvent.KEYCODE_VOLUME_DOWN)) {
            AudioManager manager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
            manager.adjustVolume(AudioManager.ADJUST_LOWER, 0);
            return true;
        }
        if ((keyCode == KeyEvent.KEYCODE_VOLUME_UP)) {
            AudioManager manager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE);
            manager.adjustVolume(AudioManager.ADJUST_RAISE, 0);
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }
}

@heyman333 @pppppppppppp12

@heyman333
Copy link

@c19354837 really appriciate it 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants