Moved to Android Studio.
This commit is contained in:
parent
0fa255ccee
commit
c5aaca4594
38 changed files with 814 additions and 242 deletions
1
app/.gitignore
vendored
Normal file
1
app/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
/build
|
90
app/app.iml
Normal file
90
app/app.iml
Normal file
|
@ -0,0 +1,90 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="SpellIt" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
|
||||
<component name="FacetManager">
|
||||
<facet type="android-gradle" name="Android-Gradle">
|
||||
<configuration>
|
||||
<option name="GRADLE_PROJECT_PATH" value=":app" />
|
||||
</configuration>
|
||||
</facet>
|
||||
<facet type="android" name="Android">
|
||||
<configuration>
|
||||
<option name="SELECTED_BUILD_VARIANT" value="debug" />
|
||||
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
|
||||
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
|
||||
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
|
||||
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
|
||||
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugAndroidTest" />
|
||||
<option name="COMPILE_JAVA_TEST_TASK_NAME" value="compileDebugAndroidTestSources" />
|
||||
<option name="TEST_SOURCE_GEN_TASK_NAME" value="generateDebugAndroidTestSources" />
|
||||
<option name="ALLOW_USER_CONFIGURATION" value="false" />
|
||||
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
|
||||
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
|
||||
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
|
||||
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
|
||||
</configuration>
|
||||
</facet>
|
||||
</component>
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="false">
|
||||
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
|
||||
<output-test url="file://$MODULE_DIR$/build/intermediates/classes/androidTest/debug" />
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/androidTest/debug" isTestSource="true" generated="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/androidTest/debug" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/jni" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
|
||||
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
|
||||
</content>
|
||||
<orderEntry type="jdk" jdkName="Android API 8 Platform (2)" jdkType="Android SDK" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
</component>
|
||||
</module>
|
29
app/build.gradle
Normal file
29
app/build.gradle
Normal file
|
@ -0,0 +1,29 @@
|
|||
apply plugin: 'com.android.application'
|
||||
apply plugin: 'versionPlugin'
|
||||
|
||||
android {
|
||||
compileSdkVersion 8
|
||||
buildToolsVersion "21.1.2"
|
||||
|
||||
defaultConfig {
|
||||
applicationId "net.thauvin.erik.android.spellit"
|
||||
minSdkVersion 3
|
||||
targetSdkVersion 3
|
||||
versionCode 3
|
||||
versionName "0.3.0"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
|
||||
}
|
||||
}
|
||||
|
||||
versionPlugin {
|
||||
buildTypesMatcher = 'release'
|
||||
supportBuildNumber = false
|
||||
|
||||
fileNameFormat = '$projectName'
|
||||
}
|
||||
}
|
20
app/src/main/AndroidManifest.xml
Normal file
20
app/src/main/AndroidManifest.xml
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:installLocation="auto"
|
||||
package="net.thauvin.erik.android.spellit">
|
||||
|
||||
<application
|
||||
android:icon="@drawable/icon"
|
||||
android:label="@string/app_name">
|
||||
<activity
|
||||
android:name=".SpellIt"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
514
app/src/main/java/net/thauvin/erik/android/spellit/SpellIt.java
Normal file
514
app/src/main/java/net/thauvin/erik/android/spellit/SpellIt.java
Normal file
|
@ -0,0 +1,514 @@
|
|||
/*
|
||||
* @(#)SpellIt.java
|
||||
*
|
||||
* Copyright (c) 2008-2012, Erik C. Thauvin (http://erik.thauvin.net/)
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are
|
||||
* met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of the authors nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
|
||||
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
||||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* $Id: SpellIt.java 88 2010-08-05 23:29:48Z erik $
|
||||
*
|
||||
*/
|
||||
package net.thauvin.erik.android.spellit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.text.ClipboardManager;
|
||||
import android.text.Editable;
|
||||
import android.text.TextUtils;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnTouchListener;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.AutoCompleteTextView;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
/**
|
||||
* <code>SpellIt</code> is a alphabet speller for Android.
|
||||
*
|
||||
* @author <a href="mailto:erik@thauvin.net">Erik C. Thauvin</a>
|
||||
* @version $Revision: 88 $, $Date: 2010-08-05 16:29:48 -0700 (Thu, 05 Aug 2010) $
|
||||
* @created Oct 30, 2008
|
||||
* @since 1.0
|
||||
*/
|
||||
public class SpellIt extends Activity
|
||||
{
|
||||
private static final int MAX_HISTORY_SIZE = 15;
|
||||
private static final int MENU_ABOUT = 0;
|
||||
private static final int MENU_NATO = 1;
|
||||
private static final String PREFS_HISTORY = "history";
|
||||
private static final String PREFS_NAME = "SpellIt";
|
||||
private static final String PREFS_NATO = "nato";
|
||||
|
||||
private String[] mAlphabet;
|
||||
private int mCurrentChar = -1;
|
||||
private String mEntry;
|
||||
private final List<String> mHistory = new ArrayList<String>(MAX_HISTORY_SIZE);
|
||||
private boolean mNato;
|
||||
|
||||
/**
|
||||
* Adds to the history.
|
||||
*
|
||||
* @param entry The entry to add.
|
||||
*/
|
||||
private void addHistory(String entry)
|
||||
{
|
||||
if (!mHistory.contains(entry))
|
||||
{
|
||||
if (mHistory.size() >= MAX_HISTORY_SIZE)
|
||||
{
|
||||
mHistory.remove(0);
|
||||
}
|
||||
|
||||
mHistory.add(entry);
|
||||
|
||||
savePrefs();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the specified phonetic alphabet value.
|
||||
*
|
||||
* @param index The desired alphabet index.
|
||||
* @return The specified alphabet value.
|
||||
*/
|
||||
private String getAlphabet(int index)
|
||||
{
|
||||
return mAlphabet[index];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current character count.
|
||||
*
|
||||
* @return The current character count.
|
||||
*/
|
||||
private int getCurrentChar()
|
||||
{
|
||||
return mCurrentChar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current entry.
|
||||
*
|
||||
* @return The new entry.
|
||||
*/
|
||||
private String getEntry()
|
||||
{
|
||||
return mEntry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current version number.
|
||||
*
|
||||
* @return The current version number or empty.
|
||||
*/
|
||||
private String getVersionNumber()
|
||||
{
|
||||
try
|
||||
{
|
||||
return getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
|
||||
}
|
||||
catch (final NameNotFoundException e)
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initializes the various controls.
|
||||
*/
|
||||
private void init()
|
||||
{
|
||||
final AutoCompleteTextView entryFld = (AutoCompleteTextView) findViewById(R.id.main_entry_fld);
|
||||
final Button spellBtn = (Button) findViewById(R.id.main_spell_btn);
|
||||
final TextView resultFld = (TextView) findViewById(R.id.main_result_fld);
|
||||
final TextView tapLbl = (TextView) findViewById(R.id.main_tap_lbl);
|
||||
|
||||
final SharedPreferences settings = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
|
||||
|
||||
setHistory(settings.getString(PREFS_HISTORY, ""));
|
||||
setNato(settings.getBoolean(PREFS_NATO, false));
|
||||
setAutoComplete(entryFld);
|
||||
setAlphabet(isNato());
|
||||
|
||||
final ClipboardManager clip = (ClipboardManager) getSystemService(android.content.Context.CLIPBOARD_SERVICE);
|
||||
if (clip.hasText())
|
||||
{
|
||||
entryFld.setText(clip.getText());
|
||||
}
|
||||
|
||||
final Drawable imgX = getResources().getDrawable(android.R.drawable.presence_offline);
|
||||
|
||||
manageClearButton(entryFld, imgX);
|
||||
|
||||
entryFld.setOnTouchListener(new OnTouchListener()
|
||||
{
|
||||
@Override
|
||||
public boolean onTouch(View v, MotionEvent event)
|
||||
{
|
||||
// Is there an X showing?
|
||||
if (entryFld.getCompoundDrawables()[2] == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Only do this for up touches
|
||||
if (event.getAction() != MotionEvent.ACTION_UP)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Is touch on our clear button?
|
||||
if (event.getX() > entryFld.getWidth() - entryFld.getPaddingRight() - imgX.getIntrinsicWidth())
|
||||
{
|
||||
entryFld.requestFocusFromTouch();
|
||||
entryFld.setText("");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
entryFld.addTextChangedListener(new TextWatcher()
|
||||
{
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count)
|
||||
{
|
||||
manageClearButton(entryFld, imgX);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after)
|
||||
{
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
spellBtn.setOnClickListener(new Button.OnClickListener()
|
||||
{
|
||||
public void onClick(View view)
|
||||
{
|
||||
final String newEntry = entryFld.getText().toString();
|
||||
|
||||
if (!TextUtils.isEmpty(newEntry))
|
||||
{
|
||||
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(spellBtn.getWindowToken(), 0);
|
||||
|
||||
tapLbl.setText(R.string.main_tap_lbl_txt);
|
||||
|
||||
if (!newEntry.equals(getEntry()))
|
||||
{
|
||||
setEntry(newEntry);
|
||||
setCurrentChar(0);
|
||||
addHistory(getEntry());
|
||||
setAutoComplete(entryFld);
|
||||
}
|
||||
showNextChar(resultFld, tapLbl);
|
||||
}
|
||||
else
|
||||
{
|
||||
Toast.makeText(SpellIt.this, R.string.main_entry_err_txt, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
resultFld.setOnClickListener(new Button.OnClickListener()
|
||||
{
|
||||
public void onClick(View view)
|
||||
{
|
||||
if (getCurrentChar() >= 0)
|
||||
{
|
||||
showNextChar(resultFld, tapLbl);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
tapLbl.setOnClickListener(new Button.OnClickListener()
|
||||
{
|
||||
public void onClick(View view)
|
||||
{
|
||||
if (getCurrentChar() >= 0)
|
||||
{
|
||||
showNextChar(resultFld, tapLbl);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the NATO flag.
|
||||
*
|
||||
* @return The NATO flag.
|
||||
*/
|
||||
private boolean isNato()
|
||||
{
|
||||
return mNato;
|
||||
}
|
||||
|
||||
/**
|
||||
* Manages the clear button.
|
||||
*
|
||||
* @param view The text view.
|
||||
* @param img The image.
|
||||
*/
|
||||
private void manageClearButton(TextView view, Drawable img)
|
||||
{
|
||||
if (view.getText().toString().equals(""))
|
||||
{
|
||||
view.setCompoundDrawablesWithIntrinsicBounds(view.getCompoundDrawables()[0], view.getCompoundDrawables()[1], null, view.getCompoundDrawables()[3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
view.setCompoundDrawablesWithIntrinsicBounds(view.getCompoundDrawables()[0], view.getCompoundDrawables()[1], img, view.getCompoundDrawables()[3]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the activity is first created.
|
||||
*/
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.main);
|
||||
init();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu)
|
||||
{
|
||||
menu.add(0, MENU_ABOUT, 0, R.string.about_menu_txt).setIcon(android.R.drawable.ic_menu_info_details);
|
||||
menu.add(0, MENU_NATO, 0, R.string.nato_menu_txt);
|
||||
return super.onCreateOptionsMenu(menu);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item)
|
||||
{
|
||||
if (item.getItemId() == MENU_ABOUT)
|
||||
{
|
||||
final LayoutInflater factory = LayoutInflater.from(this);
|
||||
final View aboutView = factory.inflate(R.layout.about, null);
|
||||
|
||||
new AlertDialog.Builder(this).setView(aboutView).setIcon(android.R.drawable.ic_dialog_info)
|
||||
.setTitle(getString(R.string.app_name) + ' ' + getVersionNumber())
|
||||
.setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener()
|
||||
{
|
||||
public void onClick(DialogInterface dialog, int whichButton)
|
||||
{
|
||||
// do nothing
|
||||
}
|
||||
}).show();
|
||||
|
||||
return true;
|
||||
}
|
||||
else if (item.getItemId() == MENU_NATO)
|
||||
{
|
||||
setAlphabet(toggleNato());
|
||||
savePrefs();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareOptionsMenu(Menu menu)
|
||||
{
|
||||
super.onPrepareOptionsMenu(menu);
|
||||
|
||||
if (isNato())
|
||||
{
|
||||
menu.findItem(MENU_NATO).setIcon(android.R.drawable.presence_online);
|
||||
}
|
||||
else
|
||||
{
|
||||
menu.findItem(MENU_NATO).setIcon(android.R.drawable.presence_offline);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the preferences.
|
||||
*/
|
||||
private void savePrefs()
|
||||
{
|
||||
final SharedPreferences settings = getSharedPreferences(getString(R.string.app_name), Context.MODE_PRIVATE);
|
||||
final SharedPreferences.Editor editor = settings.edit();
|
||||
editor.putString(PREFS_HISTORY, TextUtils.join(",", mHistory));
|
||||
editor.putBoolean(PREFS_NATO, isNato());
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the alphabet.
|
||||
*
|
||||
* @param isNato The NATO flag.
|
||||
*/
|
||||
private void setAlphabet(Boolean isNato)
|
||||
{
|
||||
if (isNato)
|
||||
{
|
||||
mAlphabet = getResources().getStringArray(R.array.nato_alphabet);
|
||||
}
|
||||
else
|
||||
{
|
||||
mAlphabet = getResources().getStringArray(R.array.alphabet);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the auto-complete values of the specified field.
|
||||
*
|
||||
* @param field The field to the auto-complete for.
|
||||
*/
|
||||
private void setAutoComplete(AutoCompleteTextView field)
|
||||
{
|
||||
final ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, mHistory);
|
||||
field.setAdapter(adapter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current character count.
|
||||
*
|
||||
* @param count The current character count to set.
|
||||
*/
|
||||
private void setCurrentChar(int count)
|
||||
{
|
||||
mCurrentChar = count;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the current entry.
|
||||
*
|
||||
* @param entry The entry to set.
|
||||
*/
|
||||
private void setEntry(String entry)
|
||||
{
|
||||
mEntry = entry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the history.
|
||||
*
|
||||
* @param history The comma-delimited history string.
|
||||
*/
|
||||
private void setHistory(String history)
|
||||
{
|
||||
final String[] entries = TextUtils.split(history, ",");
|
||||
Collections.addAll(mHistory, entries);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the NATO flag.
|
||||
*
|
||||
* @param isNato The new NATO flag.
|
||||
*/
|
||||
private void setNato(boolean isNato)
|
||||
{
|
||||
mNato = isNato;
|
||||
}
|
||||
|
||||
private void showNextChar(TextView view, TextView label)
|
||||
{
|
||||
if (getCurrentChar() < getEntry().length())
|
||||
{
|
||||
final char c = getEntry().charAt(getCurrentChar());
|
||||
|
||||
if ((c < 123) && (c > 96) || (c < 91) && (c > 64))
|
||||
{
|
||||
int offset = 97;
|
||||
|
||||
if ((c < 91) && (c > 64))
|
||||
{
|
||||
offset = 65;
|
||||
}
|
||||
|
||||
view.setText(String.valueOf(c).toUpperCase() + ' ' + getString(R.string.as_in_txt) + ' ' + getAlphabet(c - offset));
|
||||
}
|
||||
else if ((c < 58) && (c > 47))
|
||||
{
|
||||
view.setText(getAlphabet(c - 22));
|
||||
}
|
||||
else if (c == ' ')
|
||||
{
|
||||
view.setText(getString(R.string.space_txt));
|
||||
}
|
||||
else
|
||||
{
|
||||
view.setText(String.valueOf(c));
|
||||
}
|
||||
|
||||
setCurrentChar(getCurrentChar() + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
view.setText(getString(R.string.done_txt));
|
||||
label.setText(getString(R.string.main_tap_lbl_repeat_txt));
|
||||
setCurrentChar(0);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggles the NATO flag.
|
||||
*
|
||||
* @return The NATO flag value.
|
||||
*/
|
||||
private boolean toggleNato()
|
||||
{
|
||||
mNato ^= true;
|
||||
|
||||
return mNato;
|
||||
}
|
||||
|
||||
}
|
BIN
app/src/main/res/drawable/icon.png
Normal file
BIN
app/src/main/res/drawable/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 6.3 KiB |
19
app/src/main/res/layout/about.xml
Normal file
19
app/src/main/res/layout/about.xml
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/about_text_fld"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:layout_marginTop="20dp"
|
||||
android:gravity="center"
|
||||
android:autoLink="web|email"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:layout_height="fill_parent"
|
||||
android:layout_width="fill_parent"
|
||||
android:text="@string/about_txt"/>
|
||||
</LinearLayout>
|
||||
|
43
app/src/main/res/layout/main.xml
Normal file
43
app/src/main/res/layout/main.xml
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="10dip">
|
||||
|
||||
<AutoCompleteTextView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/main_entry_fld"
|
||||
android:singleLine="true"
|
||||
android:hint="@string/main_entry_hint_txt"/>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="right">
|
||||
|
||||
<Button
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/main_spell_btn"
|
||||
android:text="@string/main_spell_btn_txt"
|
||||
android:minEms="8"/>
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/main_result_fld"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:gravity="center_horizontal|center_vertical"
|
||||
android:height="136dip"
|
||||
android:text="@string/sample_txt"
|
||||
android:textSize="36dp"/>
|
||||
|
||||
<TextView
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:id="@+id/main_tap_lbl"/>
|
||||
</LinearLayout>
|
79
app/src/main/res/values/arrays.xml
Normal file
79
app/src/main/res/values/arrays.xml
Normal file
|
@ -0,0 +1,79 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string-array name="alphabet">
|
||||
<item>Adam</item>
|
||||
<item>Boy</item>
|
||||
<item>Charlie</item>
|
||||
<item>David</item>
|
||||
<item>Edward</item>
|
||||
<item>Frank</item>
|
||||
<item>George</item>
|
||||
<item>Henry</item>
|
||||
<item>Ida</item>
|
||||
<item>John</item>
|
||||
<item>King</item>
|
||||
<item>Lincoln</item>
|
||||
<item>Mary</item>
|
||||
<item>Nora</item>
|
||||
<item>Ocean</item>
|
||||
<item>Paul</item>
|
||||
<item>Queen</item>
|
||||
<item>Robert</item>
|
||||
<item>Sam</item>
|
||||
<item>Tom</item>
|
||||
<item>Union</item>
|
||||
<item>Victor</item>
|
||||
<item>William</item>
|
||||
<item>X-Ray</item>
|
||||
<item>Young</item>
|
||||
<item>Zebra</item>
|
||||
<item>Zero</item>
|
||||
<item>One</item>
|
||||
<item>Two</item>
|
||||
<item>Three</item>
|
||||
<item>Four</item>
|
||||
<item>Five</item>
|
||||
<item>Six</item>
|
||||
<item>Seven</item>
|
||||
<item>Eight</item>
|
||||
<item>Niner</item>
|
||||
</string-array>
|
||||
<string-array name="nato_alphabet">
|
||||
<item>Alpha</item>
|
||||
<item>Bravo</item>
|
||||
<item>Charlie</item>
|
||||
<item>Delta</item>
|
||||
<item>Echo</item>
|
||||
<item>Foxtrot</item>
|
||||
<item>Golf</item>
|
||||
<item>Hotel</item>
|
||||
<item>India</item>
|
||||
<item>Juliet</item>
|
||||
<item>Kilo</item>
|
||||
<item>Lima</item>
|
||||
<item>Mike</item>
|
||||
<item>November</item>
|
||||
<item>Oscar</item>
|
||||
<item>Papa</item>
|
||||
<item>Quebec</item>
|
||||
<item>Romeo</item>
|
||||
<item>Sierra</item>
|
||||
<item>Tango</item>
|
||||
<item>Uniform</item>
|
||||
<item>Victor</item>
|
||||
<item>Whiskey</item>
|
||||
<item>X-Ray</item>
|
||||
<item>Yankee</item>
|
||||
<item>Zulu</item>
|
||||
<item>Zero</item>
|
||||
<item>One (Wun)</item>
|
||||
<item>Two</item>
|
||||
<item>Three</item>
|
||||
<item>Four (Fower)</item>
|
||||
<item>Five (Fife)</item>
|
||||
<item>Six</item>
|
||||
<item>Seven</item>
|
||||
<item>Eight (Ait)</item>
|
||||
<item>Nine (Niner)</item>
|
||||
</string-array>
|
||||
</resources>
|
19
app/src/main/res/values/strings.xml
Normal file
19
app/src/main/res/values/strings.xml
Normal file
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<string name="app_name">SpellIt</string>
|
||||
<string name="main_spell_btn_txt">Spell It!</string>
|
||||
<string name="main_tap_lbl_txt">Tap to continue…</string>
|
||||
<string name="main_tap_lbl_repeat_txt">Tap to repeat…</string>
|
||||
<string name="main_entry_hint_txt">Start typing for history…</string>
|
||||
<string name="main_entry_err_txt">Please type something…</string>
|
||||
<string name="nato_menu_txt">NATO Phonetic</string>
|
||||
<string name="sample_txt">G as in Google</string>
|
||||
<string name="about_txt">© 2008–12 Erik C. Thauvin\nAll Rights Reserved\n\nerik@thauvin.net\nhttp://m.thauvin.net/android/</string>
|
||||
<string name="about_menu_txt">About</string>
|
||||
<string name="alert_dialog_ok">OK</string>
|
||||
<string name="as_in_txt">as in</string>
|
||||
<string name="space_txt"><space></string>
|
||||
<string name="done_txt"><done></string>
|
||||
|
||||
</resources>
|
Loading…
Add table
Add a link
Reference in a new issue