ex
Fork of mbed-os-example-mbed5-blinky by
dcs-sdk-java-master/app/src/main/java/com/baidu/duer/dcs/androidsystemimpl/PlatformFactoryImpl.java@45:2aa9f933c8d2, 2017-07-18 (annotated)
- Committer:
- TMBOY
- Date:
- Tue Jul 18 16:34:48 2017 +0800
- Revision:
- 45:2aa9f933c8d2
?
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| TMBOY | 45:2aa9f933c8d2 | 1 | /* |
| TMBOY | 45:2aa9f933c8d2 | 2 | * Copyright (c) 2017 Baidu, Inc. All Rights Reserved. |
| TMBOY | 45:2aa9f933c8d2 | 3 | * |
| TMBOY | 45:2aa9f933c8d2 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| TMBOY | 45:2aa9f933c8d2 | 5 | * you may not use this file except in compliance with the License. |
| TMBOY | 45:2aa9f933c8d2 | 6 | * You may obtain a copy of the License at |
| TMBOY | 45:2aa9f933c8d2 | 7 | * |
| TMBOY | 45:2aa9f933c8d2 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| TMBOY | 45:2aa9f933c8d2 | 9 | * |
| TMBOY | 45:2aa9f933c8d2 | 10 | * Unless required by applicable law or agreed to in writing, software |
| TMBOY | 45:2aa9f933c8d2 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| TMBOY | 45:2aa9f933c8d2 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| TMBOY | 45:2aa9f933c8d2 | 13 | * See the License for the specific language governing permissions and |
| TMBOY | 45:2aa9f933c8d2 | 14 | * limitations under the License. |
| TMBOY | 45:2aa9f933c8d2 | 15 | */ |
| TMBOY | 45:2aa9f933c8d2 | 16 | package com.baidu.duer.dcs.androidsystemimpl; |
| TMBOY | 45:2aa9f933c8d2 | 17 | |
| TMBOY | 45:2aa9f933c8d2 | 18 | import android.content.Context; |
| TMBOY | 45:2aa9f933c8d2 | 19 | import android.os.Looper; |
| TMBOY | 45:2aa9f933c8d2 | 20 | |
| TMBOY | 45:2aa9f933c8d2 | 21 | import com.baidu.duer.dcs.androidsystemimpl.alert.AlertsFileDataStoreImpl; |
| TMBOY | 45:2aa9f933c8d2 | 22 | import com.baidu.duer.dcs.androidsystemimpl.audioinput.AudioVoiceInputImpl; |
| TMBOY | 45:2aa9f933c8d2 | 23 | import com.baidu.duer.dcs.androidsystemimpl.playbackcontroller.IPlaybackControllerImpl; |
| TMBOY | 45:2aa9f933c8d2 | 24 | import com.baidu.duer.dcs.androidsystemimpl.player.MediaPlayerImpl; |
| TMBOY | 45:2aa9f933c8d2 | 25 | import com.baidu.duer.dcs.androidsystemimpl.wakeup.WakeUpImpl; |
| TMBOY | 45:2aa9f933c8d2 | 26 | import com.baidu.duer.dcs.systeminterface.IAlertsDataStore; |
| TMBOY | 45:2aa9f933c8d2 | 27 | import com.baidu.duer.dcs.systeminterface.IAudioInput; |
| TMBOY | 45:2aa9f933c8d2 | 28 | import com.baidu.duer.dcs.systeminterface.IAudioRecord; |
| TMBOY | 45:2aa9f933c8d2 | 29 | import com.baidu.duer.dcs.systeminterface.IHandler; |
| TMBOY | 45:2aa9f933c8d2 | 30 | import com.baidu.duer.dcs.systeminterface.IMediaPlayer; |
| TMBOY | 45:2aa9f933c8d2 | 31 | import com.baidu.duer.dcs.systeminterface.IPlatformFactory; |
| TMBOY | 45:2aa9f933c8d2 | 32 | import com.baidu.duer.dcs.systeminterface.IPlaybackController; |
| TMBOY | 45:2aa9f933c8d2 | 33 | import com.baidu.duer.dcs.systeminterface.IWakeUp; |
| TMBOY | 45:2aa9f933c8d2 | 34 | import com.baidu.duer.dcs.systeminterface.IWebView; |
| TMBOY | 45:2aa9f933c8d2 | 35 | |
| TMBOY | 45:2aa9f933c8d2 | 36 | import java.util.concurrent.LinkedBlockingDeque; |
| TMBOY | 45:2aa9f933c8d2 | 37 | |
| TMBOY | 45:2aa9f933c8d2 | 38 | /** |
| TMBOY | 45:2aa9f933c8d2 | 39 | * Created by wuruisheng on 2017/6/7. |
| TMBOY | 45:2aa9f933c8d2 | 40 | */ |
| TMBOY | 45:2aa9f933c8d2 | 41 | public class PlatformFactoryImpl implements IPlatformFactory { |
| TMBOY | 45:2aa9f933c8d2 | 42 | private IHandler mainHandler; |
| TMBOY | 45:2aa9f933c8d2 | 43 | private IAudioInput voiceInput; |
| TMBOY | 45:2aa9f933c8d2 | 44 | private IWebView webView; |
| TMBOY | 45:2aa9f933c8d2 | 45 | private IPlaybackController playback; |
| TMBOY | 45:2aa9f933c8d2 | 46 | private Context context; |
| TMBOY | 45:2aa9f933c8d2 | 47 | private IAudioRecord audioRecord; |
| TMBOY | 45:2aa9f933c8d2 | 48 | private LinkedBlockingDeque<byte[]> linkedBlockingDeque = new LinkedBlockingDeque<>(); |
| TMBOY | 45:2aa9f933c8d2 | 49 | |
| TMBOY | 45:2aa9f933c8d2 | 50 | public PlatformFactoryImpl(Context context) { |
| TMBOY | 45:2aa9f933c8d2 | 51 | this.context = context.getApplicationContext(); |
| TMBOY | 45:2aa9f933c8d2 | 52 | } |
| TMBOY | 45:2aa9f933c8d2 | 53 | |
| TMBOY | 45:2aa9f933c8d2 | 54 | @Override |
| TMBOY | 45:2aa9f933c8d2 | 55 | public IHandler createHandler() { |
| TMBOY | 45:2aa9f933c8d2 | 56 | return new HandlerImpl(); |
| TMBOY | 45:2aa9f933c8d2 | 57 | } |
| TMBOY | 45:2aa9f933c8d2 | 58 | |
| TMBOY | 45:2aa9f933c8d2 | 59 | @Override |
| TMBOY | 45:2aa9f933c8d2 | 60 | public IHandler getMainHandler() { |
| TMBOY | 45:2aa9f933c8d2 | 61 | if (mainHandler == null) { |
| TMBOY | 45:2aa9f933c8d2 | 62 | mainHandler = new HandlerImpl(Looper.getMainLooper()); |
| TMBOY | 45:2aa9f933c8d2 | 63 | } |
| TMBOY | 45:2aa9f933c8d2 | 64 | |
| TMBOY | 45:2aa9f933c8d2 | 65 | return mainHandler; |
| TMBOY | 45:2aa9f933c8d2 | 66 | } |
| TMBOY | 45:2aa9f933c8d2 | 67 | |
| TMBOY | 45:2aa9f933c8d2 | 68 | @Override |
| TMBOY | 45:2aa9f933c8d2 | 69 | public IAudioRecord getAudioRecord() { |
| TMBOY | 45:2aa9f933c8d2 | 70 | if (audioRecord == null) { |
| TMBOY | 45:2aa9f933c8d2 | 71 | audioRecord = new AudioRecordThread(linkedBlockingDeque); |
| TMBOY | 45:2aa9f933c8d2 | 72 | } |
| TMBOY | 45:2aa9f933c8d2 | 73 | return audioRecord; |
| TMBOY | 45:2aa9f933c8d2 | 74 | } |
| TMBOY | 45:2aa9f933c8d2 | 75 | |
| TMBOY | 45:2aa9f933c8d2 | 76 | @Override |
| TMBOY | 45:2aa9f933c8d2 | 77 | public IWakeUp getWakeUp() { |
| TMBOY | 45:2aa9f933c8d2 | 78 | return new WakeUpImpl(context, linkedBlockingDeque); |
| TMBOY | 45:2aa9f933c8d2 | 79 | } |
| TMBOY | 45:2aa9f933c8d2 | 80 | |
| TMBOY | 45:2aa9f933c8d2 | 81 | @Override |
| TMBOY | 45:2aa9f933c8d2 | 82 | public IAudioInput getVoiceInput() { |
| TMBOY | 45:2aa9f933c8d2 | 83 | if (voiceInput == null) { |
| TMBOY | 45:2aa9f933c8d2 | 84 | voiceInput = new AudioVoiceInputImpl(linkedBlockingDeque); |
| TMBOY | 45:2aa9f933c8d2 | 85 | } |
| TMBOY | 45:2aa9f933c8d2 | 86 | |
| TMBOY | 45:2aa9f933c8d2 | 87 | return voiceInput; |
| TMBOY | 45:2aa9f933c8d2 | 88 | } |
| TMBOY | 45:2aa9f933c8d2 | 89 | |
| TMBOY | 45:2aa9f933c8d2 | 90 | @Override |
| TMBOY | 45:2aa9f933c8d2 | 91 | public IMediaPlayer createMediaPlayer() { |
| TMBOY | 45:2aa9f933c8d2 | 92 | return new MediaPlayerImpl(); |
| TMBOY | 45:2aa9f933c8d2 | 93 | } |
| TMBOY | 45:2aa9f933c8d2 | 94 | |
| TMBOY | 45:2aa9f933c8d2 | 95 | public IAlertsDataStore createAlertsDataStore() { |
| TMBOY | 45:2aa9f933c8d2 | 96 | return new AlertsFileDataStoreImpl(); |
| TMBOY | 45:2aa9f933c8d2 | 97 | } |
| TMBOY | 45:2aa9f933c8d2 | 98 | |
| TMBOY | 45:2aa9f933c8d2 | 99 | @Override |
| TMBOY | 45:2aa9f933c8d2 | 100 | public IWebView getWebView() { |
| TMBOY | 45:2aa9f933c8d2 | 101 | return webView; |
| TMBOY | 45:2aa9f933c8d2 | 102 | } |
| TMBOY | 45:2aa9f933c8d2 | 103 | |
| TMBOY | 45:2aa9f933c8d2 | 104 | @Override |
| TMBOY | 45:2aa9f933c8d2 | 105 | public IPlaybackController getPlayback() { |
| TMBOY | 45:2aa9f933c8d2 | 106 | if (playback == null) { |
| TMBOY | 45:2aa9f933c8d2 | 107 | playback = new IPlaybackControllerImpl(); |
| TMBOY | 45:2aa9f933c8d2 | 108 | } |
| TMBOY | 45:2aa9f933c8d2 | 109 | |
| TMBOY | 45:2aa9f933c8d2 | 110 | return playback; |
| TMBOY | 45:2aa9f933c8d2 | 111 | } |
| TMBOY | 45:2aa9f933c8d2 | 112 | |
| TMBOY | 45:2aa9f933c8d2 | 113 | public void setWebView(IWebView webView) { |
| TMBOY | 45:2aa9f933c8d2 | 114 | this.webView = webView; |
| TMBOY | 45:2aa9f933c8d2 | 115 | } |
| TMBOY | 45:2aa9f933c8d2 | 116 | } |
