diff options
author | jenkins4kodi <jenkins4kodi@users.noreply.github.com> | 2015-04-18 12:20:42 +0200 |
---|---|---|
committer | jenkins4kodi <jenkins4kodi@users.noreply.github.com> | 2015-04-18 12:20:42 +0200 |
commit | b791ac4b6cb64dde71c6f4b60e16f24f14b15865 (patch) | |
tree | ff878ad58bc4366ba77f5026fd30b9008196bfee /tools | |
parent | 632d629ff79a1db139dfcf655bc93a1c34fc6fc4 (diff) | |
parent | 1f7ea26f65ecd6d1fdabfe5ead393cebd8fce8b0 (diff) |
Merge pull request #6889 from koying/chgdroidvolume
Diffstat (limited to 'tools')
-rw-r--r-- | tools/android/packaging/xbmc/src/org/xbmc/kodi/Main.java.in | 14 | ||||
-rw-r--r-- | tools/android/packaging/xbmc/src/org/xbmc/kodi/XBMCSettingsContentObserver.java.in | 65 |
2 files changed, 79 insertions, 0 deletions
diff --git a/tools/android/packaging/xbmc/src/org/xbmc/kodi/Main.java.in b/tools/android/packaging/xbmc/src/org/xbmc/kodi/Main.java.in index 7181e87550..7187f06c05 100644 --- a/tools/android/packaging/xbmc/src/org/xbmc/kodi/Main.java.in +++ b/tools/android/packaging/xbmc/src/org/xbmc/kodi/Main.java.in @@ -2,13 +2,17 @@ package org.xbmc.@APP_NAME_LC@; import android.app.NativeActivity; import android.content.Intent; +import android.media.AudioManager; import android.os.Bundle; import android.util.Log; import android.view.View; import android.graphics.PixelFormat; +import android.os.Handler; public class Main extends NativeActivity { + private XBMCSettingsContentObserver mSettingsContentObserver; + native void _onNewIntent(Intent intent); public Main() @@ -20,6 +24,10 @@ public class Main extends NativeActivity public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + setVolumeControlStream(AudioManager.STREAM_MUSIC); + + mSettingsContentObserver = new XBMCSettingsContentObserver(this, new Handler()); + getApplicationContext().getContentResolver().registerContentObserver(android.provider.Settings.System.CONTENT_URI, true, mSettingsContentObserver ); } @Override @@ -66,4 +74,10 @@ public class Main extends NativeActivity } } + @Override + public void onDestroy() + { + getApplicationContext().getContentResolver().unregisterContentObserver(mSettingsContentObserver); + super.onDestroy(); + } } diff --git a/tools/android/packaging/xbmc/src/org/xbmc/kodi/XBMCSettingsContentObserver.java.in b/tools/android/packaging/xbmc/src/org/xbmc/kodi/XBMCSettingsContentObserver.java.in new file mode 100644 index 0000000000..f5657c0aa1 --- /dev/null +++ b/tools/android/packaging/xbmc/src/org/xbmc/kodi/XBMCSettingsContentObserver.java.in @@ -0,0 +1,65 @@ +package org.xbmc.@APP_NAME_LC@; + +import android.content.Context; +import android.database.ContentObserver; +import android.media.AudioManager; +import android.net.Uri; +import android.os.Handler; +import android.util.Log; + +public class XBMCSettingsContentObserver extends ContentObserver +{ + native void _onVolumeChanged(int newVolume); + + private static final String TAG = "@APP_NAME_LC@"; + + int previousVolume; + Context context; + + public XBMCSettingsContentObserver(Context c, Handler handler) + { + super(handler); + context = c; + + AudioManager audio = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); + previousVolume = audio.getStreamVolume(AudioManager.STREAM_MUSIC); + } + + // Implement the onChange(boolean) method to delegate the change notification to + // the onChange(boolean, Uri) method to ensure correct operation on older versions + // of the framework that did not have the onChange(boolean, Uri) method. + @Override + public void onChange(boolean selfChange) + { + onChange(selfChange, null); + } + + // Implement the onChange(boolean, Uri) method to take advantage of the new Uri argument. + public void onChange(boolean selfChange, Uri uri) + { + super.onChange(selfChange); + + Log.d(TAG, "Setting changed: " + uri.toString()); + + if (uri.compareTo(Uri + .parse("content://settings/system/volume_music_speaker")) == 0) + { + AudioManager audio = (AudioManager) context + .getSystemService(Context.AUDIO_SERVICE); + int currentVolume = audio.getStreamVolume(AudioManager.STREAM_MUSIC); + + if (currentVolume != previousVolume) + { + try + { + _onVolumeChanged(currentVolume); + previousVolume = currentVolume; + } + catch (UnsatisfiedLinkError e) + { + Log.e("XBMCSettingsContentObserver", "Native not registered"); + } + } + } + } +} |