package com.metaio.sdk;

import android.content.Context;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;

class TextToSpeechHelper
{
  private Context mContext;
  private List<String> mQueue = new ArrayList();
  private TextToSpeech mTextToSpeech;
  private boolean mTextToSpeechInitialized = false;

  TextToSpeechHelper(Context paramContext)
  {
    this.mContext = paramContext;
  }

  private void performTextToSpeech()
  {
    try
    {
      if (this.mTextToSpeech == null)
      {
        this.mTextToSpeech = new TextToSpeech(this.mContext, new TextToSpeech.OnInitListener()
        {
          public void onInit(int paramAnonymousInt)
          {
            int i = 1;
            while (true)
            {
              try
              {
                TextToSpeech localTextToSpeech = TextToSpeechHelper.this.mTextToSpeech;
                if (localTextToSpeech == null)
                  return;
                if (paramAnonymousInt != 0)
                  break label261;
                j = i;
                if (j == 0)
                  break label255;
                Locale[] arrayOfLocale = new Locale[3];
                arrayOfLocale[0] = Locale.getDefault();
                arrayOfLocale[1] = Locale.UK;
                arrayOfLocale[2] = Locale.US;
                int k = 0;
                if (k >= arrayOfLocale.length)
                  break label274;
                int m = TextToSpeechHelper.this.mTextToSpeech.setLanguage(arrayOfLocale[k]);
                if ((m == -1) || (m == -2))
                {
                  StringBuilder localStringBuilder = new StringBuilder().append("Failed to set text-to-speech language to ").append(arrayOfLocale[k].getDisplayName()).append(" (unsupported or missing TTS data)");
                  if (k != 0)
                    break label267;
                  str = "";
                  MetaioDebug.log(6, str + " (result=" + m + ")");
                  k++;
                  continue;
                }
                if (i == 0)
                {
                  MetaioDebug.log(6, "Text-to-speech functionality failed to initialize, see potential errors above");
                  TextToSpeechHelper.this.mQueue.clear();
                  if (TextToSpeechHelper.this.mTextToSpeech == null)
                    continue;
                  TextToSpeechHelper.this.mTextToSpeech.shutdown();
                  TextToSpeechHelper.access$002(TextToSpeechHelper.this, null);
                  continue;
                }
              }
              finally
              {
              }
              TextToSpeechHelper.access$202(TextToSpeechHelper.this, true);
              TextToSpeechHelper.this.performTextToSpeech();
              continue;
              label255: i = j;
              continue;
              label261: int j = 0;
              continue;
              label267: String str = " (fallback)";
              continue;
              label274: i = 0;
            }
          }
        });
        return;
      }
      if (!this.mTextToSpeechInitialized)
        return;
      Iterator localIterator = this.mQueue.iterator();
      while (localIterator.hasNext())
      {
        String str = (String)localIterator.next();
        this.mTextToSpeech.speak(str, 1, null);
      }
    }
    catch (Exception localException)
    {
      MetaioDebug.log(6, localException.getMessage());
      return;
    }
    this.mQueue.clear();
  }

  public void shutdown()
  {
    if (this.mTextToSpeech != null)
    {
      this.mTextToSpeech.shutdown();
      this.mTextToSpeech = null;
    }
  }

  public void speak(String paramString)
  {
    this.mQueue.add(paramString);
    performTextToSpeech();
  }
}

/* Location:           C:\Documents and Settings\Cesar Cabello Cea\Mis documentos\Downloads\apk-downloader\com.ikea.kompis-6_dex2jar.jar
 * Qualified Name:     com.metaio.sdk.TextToSpeechHelper
 * JD-Core Version:    0.6.2
 */