package csu.xiaoya.robotApp.baidu_libs.uidialog;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import android.content.res.ColorStateList;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.StateListDrawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.speech.SpeechRecognizer;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.URLSpan;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import java.util.MissingResourceException;
import java.util.Random;
import java.util.ResourceBundle;
import csu.xiaoya.robotApp.R;
/**
* 语音识别对话框
*
* @author yangliang02
*/
public class BaiduASRDigitalDialog extends BaiduASRDialog {
private static final String TAG = "BSDigitalDialog";
// 国际化标识定义Begin
private static final String KEY_TIPS_ERROR_SILENT = "tips.error.silent";
private static final String KEY_TIPS_ERROR_DECODER = "tips.error.decoder";
private static final String KEY_TIPS_ERROR_SPEECH_TOO_SHORT = "tips.error.speech_too_short";
private static final String KEY_TIPS_ERROR_SPEECH_TOO_LONG = "tips.error.speech_too_long";
private static final String KEY_TIPS_ERROR_NETWORK = "tips.error.network";
private static final String KEY_TIPS_ERROR_NETWORK_UNUSABLE = "tips.error.network_unusable";
private static final String KEY_TIPS_ERROR_INTERNAL = "tips.error.internal";
private static final String KEY_TIPS_STATE_READY = "tips.state.ready";
private static final String KEY_TIPS_STATE_WAIT = "tips.state.wait";
private static final String KEY_TIPS_STATE_INITIALIZING = "tips.state.initializing";
private static final String KEY_TIPS_STATE_LISTENING = "tips.state.listening";
private static final String KEY_TIPS_STATE_RECOGNIZING = "tips.state.recognizing";
private static final String KEY_TIPS_COPYRIGHT = "tips.copyright";
private static final String KEY_TIPS_WAITNET = "tips.wait.net";
private static final String KEY_BTN_DONE = "btn.done";
private static final String KEY_BTN_CANCEL = "btn.cancel";
private static final String KEY_BTN_RETRY = "btn.retry";
private static final String KEY_TIPS_HELP_TITLE = "tips.help.title";
private static final String KEY_BTN_START = "btn.start";
private static final String KEY_BTN_HELP = "btn.help";
private static final String KEY_TIPS_PREFIX = "tips.suggestion.prefix";
private static final int ERROR_NETWORK_UNUSABLE = 0x90000;
private int mErrorCode;
// 国际化标识定义end
// TOTO 更新最终地址
private static final String mUrl = "http://developer.baidu.com/static/community/servers/voice/sdk.html";
private CharSequence mErrorRes = "";
private View mContentRoot = null;
private View mMainLayout;
private RelativeLayout cancle;
private View mErrorLayout;
private TextView mTipsTextView;
private TextView mWaitNetTextView;
private TextView mCompleteTextView;
private TextView mCancelTextView;
private TextView mRetryTextView;
private SDKAnimationView mVoiceWaveView;
private TextView mErrorTipsTextView;
// private TextView mLogoText1;
// private TextView mLogoText2;
private ImageButton mCancelBtn;
private ImageButton mHelpBtn;
private TextView mTitle;
private View mHelpView;
private TipsAdapter mTipsAdapter;
/**
* 动效下面的提示,3S不说话出现,文字在列表中随机出。出现后隐藏版权声明
*/
private TextView mSuggestionTips;
/**
* 静音异常时的提示语
*/
private TextView mSuggestionTips2;
private View mRecognizingView;
/**
* 连续上屏控件
*/
private EditText mInputEdit;
/**
* 识别中的进度条
*
* @author zhaopengfei04
*/
private static final int BAR_ONEND = 0;
private static final int BAR_ONFINISH = 1;
private SDKProgressBar mSDKProgressBar;
private int step = 0;
// 3秒不出识别结果,显示网络不稳定,15秒转到重试界面
private int delayTime = 0;
// 当前活跃的引擎类型
private volatile int mEngineType = 0;
Message mMessage = Message.obtain();
private Drawable mBg;
/**
* “说完了”按钮背景
*/
private StateListDrawable mButtonBg = new StateListDrawable();
/**
* 左侧按钮背景
*/
private StateListDrawable mLeftButtonBg = new StateListDrawable();
/**
* 右侧按钮背景
*/
private StateListDrawable mRightButtonBg = new StateListDrawable();
/**
* 帮助按钮
*/
private StateListDrawable mHelpButtonBg = new StateListDrawable();
/**
* 按钮文字颜色
*/
private ColorStateList mButtonColor;
/**
* 按钮文字颜色反色
*/
private ColorStateList mButtonReverseColor;
/**
* 底部版本声明字体颜色
*/
private int mCopyRightColor = 0;
/**
* 状态提示字体 颜色
*/
private int mStateTipsColor = 0;
/**
* 错误提示字体颜色
*/
private int mErrorTipsColor = 0;
private int mTheme = 0;
// 识别启动后间隔多长时间不说话出现提示,单位毫秒
private static final long SHOW_SUGGESTION_INTERVAL = 3000;
public static final int THEME_BLUE_LIGHTBG = BaiduASRDialogTheme.THEME_BLUE_LIGHTBG;
public static final int THEME_BLUE_DEEPBG = BaiduASRDialogTheme.THEME_BLUE_DEEPBG;
public static final int THEME_RED_LIGHTBG = BaiduASRDialogTheme.THEME_RED_LIGHTBG;
public static final int THEME_RED_DEEPBG = BaiduASRDialogTheme.THEME_RED_DEEPBG;
public static final int THEME_GREEN_LIGHTBG = BaiduASRDialogTheme.THEME_GREEN_LIGHTBG;
public static final int THEME_GREEN_DEEPBG = BaiduASRDialogTheme.THEME_GREEN_DEEPBG;
public static final int THEME_ORANGE_LIGHTBG = BaiduASRDialogTheme.THEME_ORANGE_LIGHTBG;
public static final int THEME_ORANGE_DEEPBG = BaiduASRDialogTheme.THEME_ORANGE_DEEPBG;
protected static final int ERROR_NONE = 0;
/**
* 国际化文本资源
*/
private ResourceBundle mLableRes;
/**
* 对话框主题,取值参考 {@link BaiduASRDialogTheme#THEME_BLUE_DEEPBG}等
*/
public static final String PARAM_DIALOG_THEME = "BaiduASRDigitalDialog_theme";
/**
* 对话框启动后展示引导提示,不启动识别
*/
@Deprecated
public static final String PARAM_SHOW_TIPS_ON_START = "BaiduASRDigitalDialog_showTips";
/**
* 引擎启动后3秒没检测到语音,在动效下方随机出现一条提示语。在配置了提示语列表后,默认开启。
*/
@Deprecated
public static final String PARAM_SHOW_TIP = "BaiduASRDigitalDialog_showTip";
/**
* 未检测到语音异常时,将“取消”按钮替换成帮助按钮。在配置了提示语列表后,默认开启。
*/
@Deprecated
public static final String PARAM_SHOW_HELP_ON