1/*
2 * Copyright (C) 2009 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.svox.pico;
18
19import android.content.Intent;
20import android.net.Uri;
21import android.os.Bundle;
22import android.preference.Preference;
23import android.preference.PreferenceActivity;
24import android.preference.Preference.OnPreferenceClickListener;
25import android.speech.tts.TextToSpeech;
26import android.util.Log;
27
28import java.util.ArrayList;
29import java.util.Locale;
30
31/*
32 * Checks if the voice data for the SVOX Pico Engine is present on the
33 * sd card.
34 */
35public class EngineSettings extends PreferenceActivity {
36    private final static String MARKET_URI_START = "market://search?q=pname:com.svox.pico.voice.";
37    private static final int VOICE_DATA_CHECK_CODE = 42;
38
39    @Override
40    protected void onCreate(Bundle savedInstanceState) {
41        super.onCreate(savedInstanceState);
42
43        Intent i = new Intent();
44        i.setClass(this, CheckVoiceData.class);
45        startActivityForResult(i, VOICE_DATA_CHECK_CODE);
46    }
47
48    @Override
49    public void onActivityResult(int requestCode, int resultCode, Intent data){
50        if (requestCode == VOICE_DATA_CHECK_CODE){
51            ArrayList<String> available = data.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);
52            ArrayList<String> unavailable = data.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_UNAVAILABLE_VOICES);
53
54            addPreferencesFromResource(R.xml.voices_list);
55
56            for (int i = 0; i < available.size(); i++){
57                Log.e("debug", available.get(i));
58                String[] languageCountry = available.get(i).split("-");
59                Locale loc = new Locale(languageCountry[0], languageCountry[1]);
60                Preference pref = findPreference(available.get(i));
61                pref.setTitle(loc.getDisplayLanguage() + " (" + loc.getDisplayCountry() + ")");
62                pref.setSummary(R.string.installed);
63                pref.setEnabled(false);
64            }
65
66
67            for (int i = 0; i < unavailable.size(); i++){
68                final String unavailableLang = unavailable.get(i);
69                String[] languageCountry = unavailableLang.split("-");
70                Locale loc = new Locale(languageCountry[0], languageCountry[1]);
71                Preference pref = findPreference(unavailableLang);
72                pref.setTitle(loc.getDisplayLanguage() + " (" + loc.getDisplayCountry() + ")");
73                pref.setSummary(R.string.not_installed);
74                pref.setEnabled(true);
75                pref.setOnPreferenceClickListener(new OnPreferenceClickListener(){
76                    public boolean onPreferenceClick(Preference preference) {
77                        Uri marketUri = Uri.parse(MARKET_URI_START + unavailableLang.toLowerCase().replace("-", "."));
78                        Intent marketIntent = new Intent(Intent.ACTION_VIEW, marketUri);
79                        startActivity(marketIntent);
80                        return false;
81                    }
82                });
83            }
84        }
85    }
86
87
88}
89