def onCreatePreferences(self, state, rootKey): self.addPreferencesFromResource(R.xml.activity_ui_demo) from android.media import AudioManager, SoundPool self.sound_pool = SoundPool(1, AudioManager.STREAM_MUSIC, 0) self.sound_id = self.sound_pool.load(self.getActivity(), R.raw.sound, 1)
class MenuFragment(static_proxy(PreferenceFragmentCompat)): @Override(jvoid, [Bundle, String]) def onCreatePreferences(self, state, rootKey): self.addPreferencesFromResource(R.xml.activity_ui_demo) from android.media import AudioManager, SoundPool self.sound_pool = SoundPool(1, AudioManager.STREAM_MUSIC, 0) self.sound_id = self.sound_pool.load(self.getActivity(), R.raw.sound, 1) @Override(jboolean, [Preference]) def onPreferenceTreeClick(self, pref): method = getattr(self, pref.getKey()) if method: method(self.getActivity()) return True else: return False def demo_dialog(self, activity): ColorDialog().show(self.getFragmentManager(), "color") def demo_notify(self, activity): from androidx.core.app import NotificationCompat builder = NotificationCompat.Builder(activity, App.DEFAULT_CHANNEL) builder.setSmallIcon(R.drawable.ic_launcher) builder.setContentTitle( activity.getString(R.string.demo_notify_title)) builder.setContentText( activity.getString(R.string.demo_notify_text)) activity.getSystemService(Context.NOTIFICATION_SERVICE)\ .notify(0, builder.getNotification()) def demo_toast(self, activity): from android.widget import Toast Toast.makeText(activity, R.string.demo_toast_text, Toast.LENGTH_SHORT).show() def demo_sound(self, activity): self.sound_pool.play(self.sound_id, 1, 1, 0, 0, 1) def demo_vibrate(self, activity): activity.getSystemService(Context.VIBRATOR_SERVICE)\ .vibrate(200)