From 883be37b98aa9cfc48d1d59d16cc6a085cfc291b Mon Sep 17 00:00:00 2001 From: Fredrik Fornwall Date: Sat, 19 Nov 2016 15:41:24 +0100 Subject: [PATCH] Add a shake animation on a terminal bell --- .../java/com/termux/app/TermuxActivity.java | 32 ++++++++++++------- app/src/main/res/anim/on_bell.xml | 7 ++++ 2 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 app/src/main/res/anim/on_bell.xml diff --git a/app/src/main/java/com/termux/app/TermuxActivity.java b/app/src/main/java/com/termux/app/TermuxActivity.java index 7490d62c..c51fbfa4 100644 --- a/app/src/main/java/com/termux/app/TermuxActivity.java +++ b/app/src/main/java/com/termux/app/TermuxActivity.java @@ -49,6 +49,8 @@ import android.view.View.OnClickListener; import android.view.View.OnLongClickListener; import android.view.ViewGroup; import android.view.WindowManager; +import android.view.animation.Animation; +import android.view.animation.AnimationUtils; import android.view.inputmethod.InputMethodManager; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; @@ -139,6 +141,8 @@ public final class TermuxActivity extends Activity implements ServiceConnection .setUsage(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION).build()).build(); int mBellSoundId; + Animation mOnBellAnimation; + private final BroadcastReceiver mBroadcastReceiever = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { @@ -209,6 +213,8 @@ public final class TermuxActivity extends Activity implements ServiceConnection public void onCreate(Bundle bundle) { super.onCreate(bundle); + mOnBellAnimation = AnimationUtils.loadAnimation(this, R.anim.on_bell); + mSettings = new TermuxPreferences(this); setContentView(R.layout.drawer_layout); @@ -402,20 +408,22 @@ public final class TermuxActivity extends Activity implements ServiceConnection @Override public void onBell(TerminalSession session) { - if (mIsVisible) { - switch (mSettings.mBellBehaviour) { - case TermuxPreferences.BELL_BEEP: - mBellSoundPool.play(mBellSoundId, 1.f, 1.f, 1, 0, 1.f); - break; - case TermuxPreferences.BELL_VIBRATE: - ((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(50); - break; - case TermuxPreferences.BELL_IGNORE: - // Ignore the bell character. - break; - } + if (!mIsVisible) return; + mTerminalView.startAnimation(mOnBellAnimation); + + switch (mSettings.mBellBehaviour) { + case TermuxPreferences.BELL_BEEP: + mBellSoundPool.play(mBellSoundId, 1.f, 1.f, 1, 0, 1.f); + break; + case TermuxPreferences.BELL_VIBRATE: + ((Vibrator) getSystemService(VIBRATOR_SERVICE)).vibrate(50); + break; + case TermuxPreferences.BELL_IGNORE: + // Ignore the bell character. + break; } + } @Override diff --git a/app/src/main/res/anim/on_bell.xml b/app/src/main/res/anim/on_bell.xml new file mode 100644 index 00000000..a0487bdd --- /dev/null +++ b/app/src/main/res/anim/on_bell.xml @@ -0,0 +1,7 @@ + + +