Update the UI to use a preferences-style display for the information items (default voice and installed voices).

This commit is contained in:
Reece H. Dunn
2012-12-19 14:52:46 +00:00
parent eea0946e82
commit 42aba8a20b
51 changed files with 283 additions and 215 deletions
@@ -0,0 +1,70 @@
/*
* Copyright (C) 2012 Reece H. Dunn
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.reecedunn.espeak;
import java.util.List;
import android.app.Activity;
import android.content.Context;
import android.util.Pair;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
public class InformationListAdapter extends ArrayAdapter<Pair<String,String>>
{
private final List<Pair<String,String>> information;
private final LayoutInflater inflater;
static class ViewHolder
{
public TextView title;
public TextView summary;
}
public InformationListAdapter(Activity context, List<Pair<String,String>> information)
{
super(context, R.layout.information_view, information);
this.inflater = context.getLayoutInflater();
this.information = information;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
ViewHolder holder;
if (convertView == null)
{
convertView = inflater.inflate(R.layout.information_view, parent, false);
holder = new ViewHolder();
holder.title = (TextView)convertView.findViewById(R.id.title);
holder.summary = (TextView)convertView.findViewById(R.id.summary);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder)convertView.getTag();
}
Pair<String,String> info = information.get(position);
holder.title.setText(info.first);
holder.summary.setText(info.second);
return convertView;
}
}
@@ -29,11 +29,15 @@ import android.os.Message;
import android.preference.PreferenceActivity;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.util.Pair;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
public class eSpeakActivity extends Activity {
private static final String ACTION_TTS_SETTINGS = "com.android.settings.TTS_SETTINGS";
@@ -57,9 +61,12 @@ public class eSpeakActivity extends Activity {
SUCCESS
}
private State mState;
private boolean mDownloadedVoiceData;
private ArrayList<String> mVoices;
private TextToSpeech mTts;
private List<Pair<String,String>> mInformation;
private InformationListAdapter mInformationView;
@Override
public void onCreate(Bundle savedInstanceState) {
@@ -67,6 +74,10 @@ public class eSpeakActivity extends Activity {
setContentView(R.layout.main);
mInformation = new ArrayList<Pair<String,String>>();
mInformationView = new InformationListAdapter(this, mInformation);
((ListView)findViewById(R.id.properties)).setAdapter(mInformationView);
setState(State.LOADING);
manageSettingVisibility();
checkVoiceData();
@@ -87,6 +98,7 @@ public class eSpeakActivity extends Activity {
* @param state The current state.
*/
private void setState(State state) {
mState = state;
findViewById(R.id.loading).setVisibility((state == State.LOADING) ? View.VISIBLE
: View.GONE);
findViewById(R.id.success).setVisibility((state == State.SUCCESS) ? View.VISIBLE
@@ -130,6 +142,27 @@ public class eSpeakActivity extends Activity {
}
}
private void populateInformationView() {
mInformation.clear();
if (mTts != null) {
Locale language = mTts.getLanguage();
if (language != null) {
final String currentLocale = getString(R.string.current_tts_locale);
mInformation.add(new Pair<String,String>(currentLocale, mTts.getLanguage().getDisplayName()));
}
}
final String availableVoices = getString(R.string.available_voices);
if (mVoices == null) {
mInformation.add(new Pair<String,String>(availableVoices, "0"));
} else {
mInformation.add(new Pair<String,String>(availableVoices, Integer.toString(mVoices.size())));
}
mInformationView.notifyDataSetChanged();
}
/**
* Handles the result of voice data verification. If verification fails
* following a successful installation, displays an error dialog. Otherwise,
@@ -153,13 +186,7 @@ public class eSpeakActivity extends Activity {
mVoices = data.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);
initializeEngine();
final TextView availableVoices = (TextView) findViewById(R.id.availableVoices);
if (mVoices == null) {
availableVoices.setText("0");
} else {
availableVoices.setText(Integer.toString(mVoices.size()));
}
populateInformationView();
}
/**
@@ -200,13 +227,11 @@ public class eSpeakActivity extends Activity {
return;
}
final TextView currentLocale = (TextView) findViewById(R.id.currentLocale);
currentLocale.setText(mTts.getLanguage().getDisplayName());
findViewById(R.id.updateVoices).setOnClickListener(mOnClickListener);
findViewById(R.id.ttsSettings).setOnClickListener(mOnClickListener);
findViewById(R.id.engineSettings).setOnClickListener(mOnClickListener);
populateInformationView();
setState(State.SUCCESS);
}