Move the buttons to the options menu UI accessible via the menu button.

This commit is contained in:
Reece H. Dunn
2012-12-19 15:20:03 +00:00
parent 42aba8a20b
commit d92abbe342
3 changed files with 41 additions and 95 deletions
-60
View File
@@ -38,66 +38,6 @@
android:layout_height="wrap_content" >
</ListView>
<LinearLayout
android:id="@+id/updateVoicesLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/updateVoices"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/update_voices" />
<TextView
android:id="@+id/textView3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
<LinearLayout
android:id="@+id/engineSettingsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/engineSettings"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="@string/engine_settings" />
<TextView
android:id="@+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:id="@+id/ttsSettingsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<Button
android:id="@+id/ttsSettings"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="@string/tts_settings" />
<TextView
android:id="@+id/textView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
<LinearLayout
+8
View File
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:id="@+id/updateVoices" android:title="@string/update_voices"></item>
<item android:id="@+id/espeakSettings" android:title="@string/engine_settings"></item>
<item android:id="@+id/ttsSettings" android:title="@string/tts_settings"></item>
</menu>
@@ -30,9 +30,11 @@ import android.preference.PreferenceActivity;
import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.util.Pair;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
@@ -79,7 +81,6 @@ public class eSpeakActivity extends Activity {
((ListView)findViewById(R.id.properties)).setAdapter(mInformationView);
setState(State.LOADING);
manageSettingVisibility();
checkVoiceData();
}
@@ -92,6 +93,36 @@ public class eSpeakActivity extends Activity {
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu)
{
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.options, menu);
if (Build.VERSION.SDK_INT < 14) {
// Hide the eSpeak setting menu item on pre-ICS.
menu.getItem(R.id.espeakSettings).setVisible(false);
}
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item)
{
switch (item.getItemId())
{
case R.id.espeakSettings:
startActivityForResult(new Intent(eSpeakActivity.this, TtsSettingsActivity.class), REQUEST_DEFAULT);
return true;
case R.id.ttsSettings:
launchGeneralTtsSettings();
return true;
case R.id.updateVoices:
downloadVoiceData();
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* Sets the UI state.
*
@@ -132,16 +163,6 @@ public class eSpeakActivity extends Activity {
mTts = new TextToSpeech(this, mInitListener);
}
/**
* Hides preferences according to SDK level.
*/
private void manageSettingVisibility() {
if (Build.VERSION.SDK_INT < 14) {
// Hide the eSpeak setting button on pre-ICS.
findViewById(R.id.engineSettingsLayout).setVisibility(View.GONE);
}
}
private void populateInformationView() {
mInformation.clear();
@@ -227,10 +248,6 @@ public class eSpeakActivity extends Activity {
return;
}
findViewById(R.id.updateVoices).setOnClickListener(mOnClickListener);
findViewById(R.id.ttsSettings).setOnClickListener(mOnClickListener);
findViewById(R.id.engineSettings).setOnClickListener(mOnClickListener);
populateInformationView();
setState(State.SUCCESS);
}
@@ -334,25 +351,6 @@ public class eSpeakActivity extends Activity {
}
private final Handler mHandler = new EspeakHandler(this);
private final View.OnClickListener mOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.updateVoices:
downloadVoiceData();
break;
case R.id.engineSettings:
startActivityForResult(
new Intent(eSpeakActivity.this, TtsSettingsActivity.class),
REQUEST_DEFAULT);
break;
case R.id.ttsSettings:
launchGeneralTtsSettings();
break;
}
}
};
private void launchGeneralTtsSettings()
{
Intent intent;