1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
package com.android.systemui.statusbar.powerwidget;
import com.android.systemui.R;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.media.AudioManager;
import android.os.SystemClock;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
public abstract class MediaKeyEventButton extends PowerButton {
private static final String TAG = "MediaKeyEventButton";
private static AudioManager AUDIO_MANAGER = null;
protected void sendMediaKeyEvent(int code) {
Context context = mView.getContext();
long eventtime = SystemClock.uptimeMillis();
Intent downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
KeyEvent downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN, code, 0);
downIntent.putExtra(Intent.EXTRA_KEY_EVENT, downEvent);
context.sendOrderedBroadcast(downIntent, null);
Intent upIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
KeyEvent upEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_UP, code, 0);
upIntent.putExtra(Intent.EXTRA_KEY_EVENT, upEvent);
context.sendOrderedBroadcast(upIntent, null);
}
protected static AudioManager getAudioManager(Context context) {
if(AUDIO_MANAGER == null) {
AUDIO_MANAGER = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
}
return AUDIO_MANAGER;
}
}
|