diff options
author | 2013-06-24 01:11:32 +0900 | |
---|---|---|
committer | 2013-06-24 17:04:40 +0900 | |
commit | e28eba5074664d5716b8e58b8d0a235746b261eb (patch) | |
tree | 7f055d1617a9d621fb5b51eb4d52a9a93d9bad44 /java/src/com/android/inputmethod/dictionarypack | |
parent | 80a4b7c92e96d359e0360f85b2ed3ed128ad0f3f (diff) | |
download | latinime-e28eba5074664d5716b8e58b8d0a235746b261eb.tar.gz latinime-e28eba5074664d5716b8e58b8d0a235746b261eb.tar.xz latinime-e28eba5074664d5716b8e58b8d0a235746b261eb.zip |
Move util classes to the latin/utils directory
Change-Id: I1c5b27c8edf231680edb8d96f63b9d04cfc6a6fa
Diffstat (limited to 'java/src/com/android/inputmethod/dictionarypack')
6 files changed, 62 insertions, 159 deletions
diff --git a/java/src/com/android/inputmethod/dictionarypack/ActionBatch.java b/java/src/com/android/inputmethod/dictionarypack/ActionBatch.java index bf2230553..be9f87930 100644 --- a/java/src/com/android/inputmethod/dictionarypack/ActionBatch.java +++ b/java/src/com/android/inputmethod/dictionarypack/ActionBatch.java @@ -28,6 +28,8 @@ import android.util.Log; import com.android.inputmethod.compat.DownloadManagerCompatUtils; import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.utils.LogUtils; +import com.android.inputmethod.latin.utils.Utils; import java.util.LinkedList; import java.util.Queue; @@ -98,7 +100,7 @@ public final class ActionBatch { final boolean mForceStartNow; public StartDownloadAction(final String clientId, final WordListMetadata wordList, final boolean forceStartNow) { - Utils.l("New download action for client ", clientId, " : ", wordList); + LogUtils.l("New download action for client ", clientId, " : ", wordList); mClientId = clientId; mWordList = wordList; mForceStartNow = forceStartNow; @@ -110,7 +112,7 @@ public final class ActionBatch { Log.e(TAG, "UpdateAction with a null parameter!"); return; } - Utils.l("Downloading word list"); + LogUtils.l("Downloading word list"); final SQLiteDatabase db = MetadataDbHelper.getDb(context, mClientId); final ContentValues values = MetadataDbHelper.getContentValuesByWordListId(db, mWordList.mId, mWordList.mVersion); @@ -132,7 +134,7 @@ public final class ActionBatch { + " for an upgrade action. Fall back to download."); } // Download it. - Utils.l("Upgrade word list, downloading", mWordList.mRemoteFilename); + LogUtils.l("Upgrade word list, downloading", mWordList.mRemoteFilename); // TODO: if DownloadManager is disabled or not installed, download by ourselves if (null == manager) return; @@ -142,7 +144,7 @@ public final class ActionBatch { // DownloadManager also stupidly cuts the extension to replace with its own that it // gets from the content-type. We need to circumvent this. final String disambiguator = "#" + System.currentTimeMillis() - + com.android.inputmethod.latin.Utils.getVersionName(context) + ".dict"; + + Utils.getVersionName(context) + ".dict"; final Uri uri = Uri.parse(mWordList.mRemoteFilename + disambiguator); final Request request = new Request(uri); @@ -178,7 +180,7 @@ public final class ActionBatch { final long downloadId = UpdateHandler.registerDownloadRequest(manager, request, db, mWordList.mId, mWordList.mVersion); - Utils.l("Starting download of", uri, "with id", downloadId); + LogUtils.l("Starting download of", uri, "with id", downloadId); PrivateLog.log("Starting download of " + uri + ", id : " + downloadId); } } @@ -195,7 +197,8 @@ public final class ActionBatch { public InstallAfterDownloadAction(final String clientId, final ContentValues wordListValues) { - Utils.l("New InstallAfterDownloadAction for client ", clientId, " : ", wordListValues); + LogUtils.l("New InstallAfterDownloadAction for client ", clientId, " : ", + wordListValues); mClientId = clientId; mWordListValues = wordListValues; } @@ -213,7 +216,7 @@ public final class ActionBatch { + " for an InstallAfterDownload action. Bailing out."); return; } - Utils.l("Setting word list as installed"); + LogUtils.l("Setting word list as installed"); final SQLiteDatabase db = MetadataDbHelper.getDb(context, mClientId); MetadataDbHelper.markEntryAsFinishedDownloadingAndInstalled(db, mWordListValues); } @@ -229,7 +232,7 @@ public final class ActionBatch { final WordListMetadata mWordList; public EnableAction(final String clientId, final WordListMetadata wordList) { - Utils.l("New EnableAction for client ", clientId, " : ", wordList); + LogUtils.l("New EnableAction for client ", clientId, " : ", wordList); mClientId = clientId; mWordList = wordList; } @@ -240,7 +243,7 @@ public final class ActionBatch { Log.e(TAG, "EnableAction with a null parameter!"); return; } - Utils.l("Enabling word list"); + LogUtils.l("Enabling word list"); final SQLiteDatabase db = MetadataDbHelper.getDb(context, mClientId); final ContentValues values = MetadataDbHelper.getContentValuesByWordListId(db, mWordList.mId, mWordList.mVersion); @@ -264,7 +267,7 @@ public final class ActionBatch { // The word list to disable. May not be null. final WordListMetadata mWordList; public DisableAction(final String clientId, final WordListMetadata wordlist) { - Utils.l("New Disable action for client ", clientId, " : ", wordlist); + LogUtils.l("New Disable action for client ", clientId, " : ", wordlist); mClientId = clientId; mWordList = wordlist; } @@ -275,7 +278,7 @@ public final class ActionBatch { Log.e(TAG, "DisableAction with a null word list!"); return; } - Utils.l("Disabling word list : " + mWordList); + LogUtils.l("Disabling word list : " + mWordList); final SQLiteDatabase db = MetadataDbHelper.getDb(context, mClientId); final ContentValues values = MetadataDbHelper.getContentValuesByWordListId(db, mWordList.mId, mWordList.mVersion); @@ -311,7 +314,7 @@ public final class ActionBatch { // The word list to make available. May not be null. final WordListMetadata mWordList; public MakeAvailableAction(final String clientId, final WordListMetadata wordlist) { - Utils.l("New MakeAvailable action", clientId, " : ", wordlist); + LogUtils.l("New MakeAvailable action", clientId, " : ", wordlist); mClientId = clientId; mWordList = wordlist; } @@ -328,7 +331,7 @@ public final class ActionBatch { Log.e(TAG, "Unexpected state of the word list '" + mWordList.mId + "' " + " for a makeavailable action. Marking as available anyway."); } - Utils.l("Making word list available : " + mWordList); + LogUtils.l("Making word list available : " + mWordList); // If mLocalFilename is null, then it's a remote file that hasn't been downloaded // yet, so we set the local filename to the empty string. final ContentValues values = MetadataDbHelper.makeContentValues(0, @@ -360,7 +363,7 @@ public final class ActionBatch { // The word list to mark pre-installed. May not be null. final WordListMetadata mWordList; public MarkPreInstalledAction(final String clientId, final WordListMetadata wordlist) { - Utils.l("New MarkPreInstalled action", clientId, " : ", wordlist); + LogUtils.l("New MarkPreInstalled action", clientId, " : ", wordlist); mClientId = clientId; mWordList = wordlist; } @@ -377,7 +380,7 @@ public final class ActionBatch { Log.e(TAG, "Unexpected state of the word list '" + mWordList.mId + "' " + " for a markpreinstalled action. Marking as preinstalled anyway."); } - Utils.l("Marking word list preinstalled : " + mWordList); + LogUtils.l("Marking word list preinstalled : " + mWordList); // This word list is pre-installed : we don't have its file. We should reset // the local file name to the empty string so that we don't try to open it // accidentally. The remote filename may be set by the application if it so wishes. @@ -401,7 +404,7 @@ public final class ActionBatch { private final String mClientId; final WordListMetadata mWordList; public UpdateDataAction(final String clientId, final WordListMetadata wordlist) { - Utils.l("New UpdateData action for client ", clientId, " : ", wordlist); + LogUtils.l("New UpdateData action for client ", clientId, " : ", wordlist); mClientId = clientId; mWordList = wordlist; } @@ -419,7 +422,7 @@ public final class ActionBatch { Log.e(TAG, "Trying to update data about a non-existing word list. Bailing out."); return; } - Utils.l("Updating data about a word list : " + mWordList); + LogUtils.l("Updating data about a word list : " + mWordList); final ContentValues values = MetadataDbHelper.makeContentValues( oldValues.getAsInteger(MetadataDbHelper.PENDINGID_COLUMN), oldValues.getAsInteger(MetadataDbHelper.TYPE_COLUMN), @@ -453,7 +456,7 @@ public final class ActionBatch { final boolean mHasNewerVersion; public ForgetAction(final String clientId, final WordListMetadata wordlist, final boolean hasNewerVersion) { - Utils.l("New TryRemove action for client ", clientId, " : ", wordlist); + LogUtils.l("New TryRemove action for client ", clientId, " : ", wordlist); mClientId = clientId; mWordList = wordlist; mHasNewerVersion = hasNewerVersion; @@ -465,7 +468,7 @@ public final class ActionBatch { Log.e(TAG, "TryRemoveAction with a null word list!"); return; } - Utils.l("Trying to remove word list : " + mWordList); + LogUtils.l("Trying to remove word list : " + mWordList); final SQLiteDatabase db = MetadataDbHelper.getDb(context, mClientId); final ContentValues values = MetadataDbHelper.getContentValuesByWordListId(db, mWordList.mId, mWordList.mVersion); @@ -525,7 +528,7 @@ public final class ActionBatch { // The word list to delete. May not be null. final WordListMetadata mWordList; public StartDeleteAction(final String clientId, final WordListMetadata wordlist) { - Utils.l("New StartDelete action for client ", clientId, " : ", wordlist); + LogUtils.l("New StartDelete action for client ", clientId, " : ", wordlist); mClientId = clientId; mWordList = wordlist; } @@ -536,7 +539,7 @@ public final class ActionBatch { Log.e(TAG, "StartDeleteAction with a null word list!"); return; } - Utils.l("Trying to delete word list : " + mWordList); + LogUtils.l("Trying to delete word list : " + mWordList); final SQLiteDatabase db = MetadataDbHelper.getDb(context, mClientId); final ContentValues values = MetadataDbHelper.getContentValuesByWordListId(db, mWordList.mId, mWordList.mVersion); @@ -564,7 +567,7 @@ public final class ActionBatch { // The word list to delete. May not be null. final WordListMetadata mWordList; public FinishDeleteAction(final String clientId, final WordListMetadata wordlist) { - Utils.l("New FinishDelete action for client", clientId, " : ", wordlist); + LogUtils.l("New FinishDelete action for client", clientId, " : ", wordlist); mClientId = clientId; mWordList = wordlist; } @@ -575,7 +578,7 @@ public final class ActionBatch { Log.e(TAG, "FinishDeleteAction with a null word list!"); return; } - Utils.l("Trying to delete word list : " + mWordList); + LogUtils.l("Trying to delete word list : " + mWordList); final SQLiteDatabase db = MetadataDbHelper.getDb(context, mClientId); final ContentValues values = MetadataDbHelper.getContentValuesByWordListId(db, mWordList.mId, mWordList.mVersion); @@ -632,7 +635,7 @@ public final class ActionBatch { * @param reporter a Reporter to send errors to. */ public void execute(final Context context, final ProblemReporter reporter) { - Utils.l("Executing a batch of actions"); + LogUtils.l("Executing a batch of actions"); Queue<Action> remainingActions = mActions; while (!remainingActions.isEmpty()) { final Action a = remainingActions.poll(); diff --git a/java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java b/java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java index 5ad5900d4..f1a2a8333 100644 --- a/java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java +++ b/java/src/com/android/inputmethod/dictionarypack/DictionaryListInterfaceState.java @@ -18,7 +18,7 @@ package com.android.inputmethod.dictionarypack; import android.view.View; -import com.android.inputmethod.latin.CollectionUtils; +import com.android.inputmethod.latin.utils.CollectionUtils; import java.util.ArrayList; import java.util.HashMap; diff --git a/java/src/com/android/inputmethod/dictionarypack/DictionaryProvider.java b/java/src/com/android/inputmethod/dictionarypack/DictionaryProvider.java index 4fbe16233..4aa4d4b43 100644 --- a/java/src/com/android/inputmethod/dictionarypack/DictionaryProvider.java +++ b/java/src/com/android/inputmethod/dictionarypack/DictionaryProvider.java @@ -31,6 +31,7 @@ import android.text.TextUtils; import android.util.Log; import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.utils.LogUtils; import java.io.File; import java.io.FileNotFoundException; @@ -219,7 +220,7 @@ public final class DictionaryProvider extends ContentProvider { @Override public Cursor query(final Uri uri, final String[] projection, final String selection, final String[] selectionArgs, final String sortOrder) { - Utils.l("Uri =", uri); + LogUtils.l("Uri =", uri); PrivateLog.log("Query : " + uri); final String clientId = getClientId(uri); final int match = matchUri(uri); @@ -227,7 +228,7 @@ public final class DictionaryProvider extends ContentProvider { case DICTIONARY_V1_WHOLE_LIST: case DICTIONARY_V2_WHOLE_LIST: final Cursor c = MetadataDbHelper.queryDictionaries(getContext(), clientId); - Utils.l("List of dictionaries with count", c.getCount()); + LogUtils.l("List of dictionaries with count", c.getCount()); PrivateLog.log("Returned a list of " + c.getCount() + " items"); return c; case DICTIONARY_V2_DICT_INFO: diff --git a/java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java b/java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java index dac12137d..c6cadb823 100644 --- a/java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java +++ b/java/src/com/android/inputmethod/dictionarypack/MetadataDbHelper.java @@ -25,6 +25,7 @@ import android.text.TextUtils; import android.util.Log; import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.utils.LogUtils; import java.io.File; import java.util.ArrayList; @@ -772,12 +773,12 @@ public class MetadataDbHelper extends SQLiteOpenHelper { if (TextUtils.isEmpty(valuesClientId) || null == valuesMetadataUri || null == valuesMetadataAdditionalId) { // We need all these columns to be filled in - Utils.l("Missing parameter for updateClientInfo"); + LogUtils.l("Missing parameter for updateClientInfo"); return; } if (!clientId.equals(valuesClientId)) { // Mismatch! The client violates the protocol. - Utils.l("Received an updateClientInfo request for ", clientId, " but the values " + LogUtils.l("Received an updateClientInfo request for ", clientId, " but the values " + "contain a different ID : ", valuesClientId); return; } @@ -847,7 +848,7 @@ public class MetadataDbHelper extends SQLiteOpenHelper { final ContentValues r) { switch (r.getAsInteger(TYPE_COLUMN)) { case TYPE_BULK: - Utils.l("Ended processing a wordlist"); + LogUtils.l("Ended processing a wordlist"); // Updating a bulk word list is a three-step operation: // - Add the new entry to the table // - Remove the old entry from the table @@ -869,7 +870,7 @@ public class MetadataDbHelper extends SQLiteOpenHelper { // the phone is suddenly cut during an update. final int filenameIndex = c.getColumnIndex(LOCAL_FILENAME_COLUMN); do { - Utils.l("Setting for removal", c.getString(filenameIndex)); + LogUtils.l("Setting for removal", c.getString(filenameIndex)); filenames.add(c.getString(filenameIndex)); } while (c.moveToNext()); } diff --git a/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java b/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java index 3f917f13f..936d00d25 100644 --- a/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java +++ b/java/src/com/android/inputmethod/dictionarypack/UpdateHandler.java @@ -38,6 +38,8 @@ import android.util.Log; import com.android.inputmethod.compat.ConnectivityManagerCompatUtils; import com.android.inputmethod.compat.DownloadManagerCompatUtils; import com.android.inputmethod.latin.R; +import com.android.inputmethod.latin.utils.LogUtils; +import com.android.inputmethod.latin.utils.Utils; import java.io.File; import java.io.FileInputStream; @@ -183,8 +185,8 @@ public final class UpdateHandler { final String clientId = cursor.getString(0); final String metadataUri = MetadataDbHelper.getMetadataUriAsString(context, clientId); - PrivateLog.log("Update for clientId " + Utils.s(clientId)); - Utils.l("Update for clientId", clientId, " which uses URI ", metadataUri); + PrivateLog.log("Update for clientId " + LogUtils.s(clientId)); + LogUtils.l("Update for clientId", clientId, " which uses URI ", metadataUri); uris.add(metadataUri); } while (cursor.moveToNext()); } finally { @@ -211,14 +213,14 @@ public final class UpdateHandler { */ private static void updateClientsWithMetadataUri(final Context context, final boolean updateNow, final String metadataUri) { - PrivateLog.log("Update for metadata URI " + Utils.s(metadataUri)); + PrivateLog.log("Update for metadata URI " + LogUtils.s(metadataUri)); // Adding a disambiguator to circumvent a bug in older versions of DownloadManager. // DownloadManager also stupidly cuts the extension to replace with its own that it // gets from the content-type. We need to circumvent this. final String disambiguator = "#" + System.currentTimeMillis() - + com.android.inputmethod.latin.Utils.getVersionName(context) + ".json"; + + Utils.getVersionName(context) + ".json"; final Request metadataRequest = new Request(Uri.parse(metadataUri + disambiguator)); - Utils.l("Request =", metadataRequest); + LogUtils.l("Request =", metadataRequest); final Resources res = context.getResources(); // By default, download over roaming is allowed and all network types are allowed too. @@ -254,7 +256,7 @@ public final class UpdateHandler { final long downloadId; synchronized (sSharedIdProtector) { downloadId = manager.enqueue(metadataRequest); - Utils.l("Metadata download requested with id", downloadId); + LogUtils.l("Metadata download requested with id", downloadId); // If there is already a download in progress, it's been there for a while and // there is probably something wrong with download manager. It's best to just // overwrite the id and request it again. If the old one happens to finish @@ -326,11 +328,11 @@ public final class UpdateHandler { */ public static long registerDownloadRequest(final DownloadManager manager, final Request request, final SQLiteDatabase db, final String id, final int version) { - Utils.l("RegisterDownloadRequest for word list id : ", id, ", version ", version); + LogUtils.l("RegisterDownloadRequest for word list id : ", id, ", version ", version); final long downloadId; synchronized (sSharedIdProtector) { downloadId = manager.enqueue(request); - Utils.l("Download requested with id", downloadId); + LogUtils.l("Download requested with id", downloadId); MetadataDbHelper.markEntryAsDownloading(db, id, version, downloadId); } return downloadId; @@ -416,7 +418,7 @@ public final class UpdateHandler { // Get and check the ID of the file that was downloaded final long fileId = intent.getLongExtra(DownloadManager.EXTRA_DOWNLOAD_ID, NOT_AN_ID); PrivateLog.log("Download finished with id " + fileId); - Utils.l("DownloadFinished with id", fileId); + LogUtils.l("DownloadFinished with id", fileId); if (NOT_AN_ID == fileId) return; // Spurious wake-up: ignore final DownloadManager manager = @@ -426,7 +428,7 @@ public final class UpdateHandler { final ArrayList<DownloadRecord> recordList = getDownloadRecordsForCompletedDownloadInfo(context, downloadInfo); if (null == recordList) return; // It was someone else's download. - Utils.l("Received result for download ", fileId); + LogUtils.l("Received result for download ", fileId); // TODO: handle gracefully a null pointer here. This is practically impossible because // we come here only when DownloadManager explicitly called us when it ended a @@ -503,7 +505,7 @@ public final class UpdateHandler { private static void publishUpdateCycleCompletedEvent(final Context context) { // Even if this is not successful, we have to publish the new state. PrivateLog.log("Publishing update cycle completed event"); - Utils.l("Publishing update cycle completed event"); + LogUtils.l("Publishing update cycle completed event"); for (UpdateEventListener listener : linkedCopyOfList(sUpdateEventListeners)) { listener.updateCycleCompleted(); } @@ -517,12 +519,12 @@ public final class UpdateHandler { // {@link handleWordList(Context,InputStream,ContentValues)}. // Handle the downloaded file according to its type if (downloadRecord.isMetadata()) { - Utils.l("Data D/L'd is metadata for", downloadRecord.mClientId); + LogUtils.l("Data D/L'd is metadata for", downloadRecord.mClientId); // #handleMetadata() closes its InputStream argument handleMetadata(context, new ParcelFileDescriptor.AutoCloseInputStream( manager.openDownloadedFile(fileId)), downloadRecord.mClientId); } else { - Utils.l("Data D/L'd is a word list"); + LogUtils.l("Data D/L'd is a word list"); final int wordListStatus = downloadRecord.mAttributes.getAsInteger( MetadataDbHelper.STATUS_COLUMN); if (MetadataDbHelper.STATUS_DOWNLOADING == wordListStatus) { @@ -582,7 +584,7 @@ public final class UpdateHandler { */ private static void handleMetadata(final Context context, final InputStream stream, final String clientId) throws IOException, BadFormatException { - Utils.l("Entering handleMetadata"); + LogUtils.l("Entering handleMetadata"); final List<WordListMetadata> newMetadata; final InputStreamReader reader = new InputStreamReader(stream); try { @@ -592,7 +594,7 @@ public final class UpdateHandler { reader.close(); } - Utils.l("Downloaded metadata :", newMetadata); + LogUtils.l("Downloaded metadata :", newMetadata); PrivateLog.log("Downloaded metadata\n" + newMetadata); final ActionBatch actions = computeUpgradeTo(context, clientId, newMetadata); @@ -617,7 +619,7 @@ public final class UpdateHandler { // DownloadManager does not have the ability to put the file directly where we want // it, so we had it download to a temporary place. Now we move it. It will be deleted // automatically by DownloadManager. - Utils.l("Downloaded a new word list :", downloadRecord.mAttributes.getAsString( + LogUtils.l("Downloaded a new word list :", downloadRecord.mAttributes.getAsString( MetadataDbHelper.DESCRIPTION_COLUMN), "for", downloadRecord.mClientId); PrivateLog.log("Downloaded a new word list with description : " + downloadRecord.mAttributes.getAsString(MetadataDbHelper.DESCRIPTION_COLUMN) @@ -676,9 +678,9 @@ public final class UpdateHandler { */ private static void copyFile(final InputStream in, final OutputStream out) throws IOException { - Utils.l("Copying files"); + LogUtils.l("Copying files"); if (!(in instanceof FileInputStream) || !(out instanceof FileOutputStream)) { - Utils.l("Not the right types"); + LogUtils.l("Not the right types"); copyFileFallback(in, out); } else { try { @@ -687,7 +689,7 @@ public final class UpdateHandler { sourceChannel.transferTo(0, Integer.MAX_VALUE, destinationChannel); } catch (IOException e) { // Can't work with channels, or something went wrong. Copy by hand. - Utils.l("Won't work"); + LogUtils.l("Won't work"); copyFileFallback(in, out); } } @@ -702,7 +704,7 @@ public final class UpdateHandler { */ private static void copyFileFallback(final InputStream in, final OutputStream out) throws IOException { - Utils.l("Falling back to slow copy"); + LogUtils.l("Falling back to slow copy"); final byte[] buffer = new byte[FILE_COPY_BUFFER_SIZE]; for (int readBytes = in.read(buffer); readBytes >= 0; readBytes = in.read(buffer)) out.write(buffer, 0, readBytes); @@ -717,10 +719,10 @@ public final class UpdateHandler { */ private static String getTempFileName(final Context context, final String locale) throws IOException { - Utils.l("Entering openTempFileOutput"); + LogUtils.l("Entering openTempFileOutput"); final File dir = context.getFilesDir(); final File f = File.createTempFile(locale + "___", DICT_FILE_SUFFIX, dir); - Utils.l("File name is", f.getName()); + LogUtils.l("File name is", f.getName()); return f.getName(); } @@ -741,7 +743,7 @@ public final class UpdateHandler { final String clientId, List<WordListMetadata> from, List<WordListMetadata> to) { final ActionBatch actions = new ActionBatch(); // Upgrade existing word lists - Utils.l("Comparing dictionaries"); + LogUtils.l("Comparing dictionaries"); final Set<String> wordListIds = new TreeSet<String>(); // TODO: Can these be null? if (null == from) from = new ArrayList<WordListMetadata>(); @@ -756,7 +758,7 @@ public final class UpdateHandler { final WordListMetadata newInfo = null == metadataInfo || metadataInfo.mFormatVersion > MAXIMUM_SUPPORTED_FORMAT_VERSION ? null : metadataInfo; - Utils.l("Considering updating ", id, "currentInfo =", currentInfo); + LogUtils.l("Considering updating ", id, "currentInfo =", currentInfo); if (null == currentInfo && null == newInfo) { // This may happen if a new word list appeared that we can't handle. diff --git a/java/src/com/android/inputmethod/dictionarypack/Utils.java b/java/src/com/android/inputmethod/dictionarypack/Utils.java deleted file mode 100644 index c4a42dbbf..000000000 --- a/java/src/com/android/inputmethod/dictionarypack/Utils.java +++ /dev/null @@ -1,104 +0,0 @@ -/* - * Copyright (C) 2011 The Android Open Source Project - * - * 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.android.inputmethod.dictionarypack; - -import android.util.Log; - -/** - * A class for various utility methods, especially debugging. - */ -public final class Utils { - private final static String TAG = Utils.class.getSimpleName() + ":DEBUG --"; - private final static boolean DEBUG = DictionaryProvider.DEBUG; - - /** - * Calls .toString() on its non-null argument or returns "null" - * @param o the object to convert to a string - * @return the result of .toString() or null - */ - public static String s(final Object o) { - return null == o ? "null" : o.toString(); - } - - /** - * Get the string representation of the current stack trace, for debugging purposes. - * @return a readable, carriage-return-separated string for the current stack trace. - */ - public static String getStackTrace() { - final StringBuilder sb = new StringBuilder(); - try { - throw new RuntimeException(); - } catch (RuntimeException e) { - StackTraceElement[] frames = e.getStackTrace(); - // Start at 1 because the first frame is here and we don't care about it - for (int j = 1; j < frames.length; ++j) { - sb.append(frames[j].toString() + "\n"); - } - } - return sb.toString(); - } - - /** - * Get the stack trace contained in an exception as a human-readable string. - * @param e the exception - * @return the human-readable stack trace - */ - public static String getStackTrace(final Exception e) { - final StringBuilder sb = new StringBuilder(); - final StackTraceElement[] frames = e.getStackTrace(); - for (int j = 0; j < frames.length; ++j) { - sb.append(frames[j].toString() + "\n"); - } - return sb.toString(); - } - - /** - * Helper log method to ease null-checks and adding spaces. - * - * This sends all arguments to the log, separated by spaces. Any null argument is converted - * to the "null" string. It uses a very visible tag and log level for debugging purposes. - * - * @param args the stuff to send to the log - */ - public static void l(final Object... args) { - if (!DEBUG) return; - final StringBuilder sb = new StringBuilder(); - for (final Object o : args) { - sb.append(s(o).toString()); - sb.append(" "); - } - Log.e(TAG, sb.toString()); - } - - /** - * Helper log method to put stuff in red. - * - * This does the same as #l but prints in red - * - * @param args the stuff to send to the log - */ - public static void r(final Object... args) { - if (!DEBUG) return; - final StringBuilder sb = new StringBuilder("\u001B[31m"); - for (final Object o : args) { - sb.append(s(o).toString()); - sb.append(" "); - } - sb.append("\u001B[0m"); - Log.e(TAG, sb.toString()); - } -} |