OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.midi; | 5 package org.chromium.midi; |
6 | 6 |
7 import android.annotation.TargetApi; | 7 import android.annotation.TargetApi; |
8 import android.content.Context; | 8 import android.content.Context; |
9 import android.media.midi.MidiDevice; | 9 import android.media.midi.MidiDevice; |
10 import android.media.midi.MidiDeviceInfo; | 10 import android.media.midi.MidiDeviceInfo; |
11 import android.media.midi.MidiManager; | 11 import android.media.midi.MidiManager; |
12 import android.os.Build; | 12 import android.os.Build; |
13 import android.os.Handler; | 13 import android.os.Handler; |
14 | 14 |
| 15 import org.chromium.base.ContextUtils; |
15 import org.chromium.base.ThreadUtils; | 16 import org.chromium.base.ThreadUtils; |
16 import org.chromium.base.annotations.CalledByNative; | 17 import org.chromium.base.annotations.CalledByNative; |
17 import org.chromium.base.annotations.JNINamespace; | 18 import org.chromium.base.annotations.JNINamespace; |
18 | 19 |
19 import java.util.ArrayList; | 20 import java.util.ArrayList; |
20 import java.util.HashSet; | 21 import java.util.HashSet; |
21 import java.util.List; | 22 import java.util.List; |
22 import java.util.Set; | 23 import java.util.Set; |
23 | 24 |
24 /** | 25 /** |
(...skipping 22 matching lines...) Expand all Loading... |
47 * Callbacks will run on the message queue associated with this handler. | 48 * Callbacks will run on the message queue associated with this handler. |
48 */ | 49 */ |
49 private final Handler mHandler; | 50 private final Handler mHandler; |
50 /** | 51 /** |
51 * The associated midi::MidiDeviceAndroid instance. | 52 * The associated midi::MidiDeviceAndroid instance. |
52 */ | 53 */ |
53 private final long mNativeManagerPointer; | 54 private final long mNativeManagerPointer; |
54 | 55 |
55 /** | 56 /** |
56 * A creation function called by C++. | 57 * A creation function called by C++. |
57 * @param context | |
58 * @param nativeManagerPointer The native pointer to a midi::MidiManagerAndr
oid object. | 58 * @param nativeManagerPointer The native pointer to a midi::MidiManagerAndr
oid object. |
59 */ | 59 */ |
60 @CalledByNative | 60 @CalledByNative |
61 static MidiManagerAndroid create(Context context, long nativeManagerPointer)
{ | 61 static MidiManagerAndroid create(long nativeManagerPointer) { |
62 return new MidiManagerAndroid(context, nativeManagerPointer); | 62 return new MidiManagerAndroid(nativeManagerPointer); |
63 } | 63 } |
64 | 64 |
65 /** | 65 /** |
66 * @param context | |
67 * @param nativeManagerPointer The native pointer to a midi::MidiManagerAndr
oid object. | 66 * @param nativeManagerPointer The native pointer to a midi::MidiManagerAndr
oid object. |
68 */ | 67 */ |
69 private MidiManagerAndroid(Context context, long nativeManagerPointer) { | 68 private MidiManagerAndroid(long nativeManagerPointer) { |
70 assert !ThreadUtils.runningOnUiThread(); | 69 assert !ThreadUtils.runningOnUiThread(); |
71 | 70 |
72 mManager = (MidiManager) context.getSystemService(Context.MIDI_SERVICE); | 71 mManager = (MidiManager) ContextUtils.getApplicationContext().getSystemS
ervice( |
| 72 Context.MIDI_SERVICE); |
73 mHandler = new Handler(ThreadUtils.getUiThreadLooper()); | 73 mHandler = new Handler(ThreadUtils.getUiThreadLooper()); |
74 mNativeManagerPointer = nativeManagerPointer; | 74 mNativeManagerPointer = nativeManagerPointer; |
75 } | 75 } |
76 | 76 |
77 /** | 77 /** |
78 * Initializes this object. | 78 * Initializes this object. |
79 * This function must be called right after creation. | 79 * This function must be called right after creation. |
80 */ | 80 */ |
81 @CalledByNative | 81 @CalledByNative |
82 void initialize() { | 82 void initialize() { |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 mIsInitialized = true; | 165 mIsInitialized = true; |
166 } | 166 } |
167 } | 167 } |
168 | 168 |
169 static native void nativeOnInitialized( | 169 static native void nativeOnInitialized( |
170 long nativeMidiManagerAndroid, MidiDeviceAndroid[] devices); | 170 long nativeMidiManagerAndroid, MidiDeviceAndroid[] devices); |
171 static native void nativeOnInitializationFailed(long nativeMidiManagerAndroi
d); | 171 static native void nativeOnInitializationFailed(long nativeMidiManagerAndroi
d); |
172 static native void nativeOnAttached(long nativeMidiManagerAndroid, MidiDevic
eAndroid device); | 172 static native void nativeOnAttached(long nativeMidiManagerAndroid, MidiDevic
eAndroid device); |
173 static native void nativeOnDetached(long nativeMidiManagerAndroid, MidiDevic
eAndroid device); | 173 static native void nativeOnDetached(long nativeMidiManagerAndroid, MidiDevic
eAndroid device); |
174 } | 174 } |
OLD | NEW |