merge heads

This commit is contained in:
Jimmy Shih
2012-04-02 14:49:12 -07:00
parent 0bd4461c32
commit 2d05ff98ca
75 changed files with 783 additions and 794 deletions
@@ -18,6 +18,7 @@ package com.google.android.apps.mytracks.util;
import com.google.android.apps.mytracks.Constants;
import com.google.android.apps.mytracks.services.sensors.BluetoothConnectionManager;
import android.annotation.TargetApi;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import android.util.Log;
@@ -29,6 +30,7 @@ import java.io.IOException;
*
* @author Jimmy Shih
*/
@TargetApi(10)
public class Api10Adapter extends Api9Adapter {
@Override
@@ -16,8 +16,8 @@
package com.google.android.apps.mytracks.util;
import com.google.android.apps.mytracks.io.backup.BackupPreferencesListener;
import com.google.android.apps.mytracks.io.backup.BackupPreferencesListenerImpl;
import com.google.android.apps.mytracks.services.tasks.FroyoStatusAnnouncerTask;
import com.google.android.apps.mytracks.io.backup.Api8BackupPreferencesListener;
import com.google.android.apps.mytracks.services.tasks.Api8StatusAnnouncerTask;
import com.google.android.apps.mytracks.services.tasks.PeriodicTask;
import android.content.Context;
@@ -31,11 +31,11 @@ public class Api8Adapter extends Api7Adapter {
@Override
public PeriodicTask getStatusAnnouncerTask(Context context) {
return new FroyoStatusAnnouncerTask(context);
return new Api8StatusAnnouncerTask(context);
}
@Override
public BackupPreferencesListener getBackupPreferencesListener(Context context) {
return new BackupPreferencesListenerImpl(context);
return new Api8BackupPreferencesListener(context);
}
}
@@ -19,6 +19,7 @@ import com.google.android.apps.mytracks.Constants;
import com.google.api.client.http.HttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import android.annotation.TargetApi;
import android.content.SharedPreferences.Editor;
import android.os.StrictMode;
import android.util.Log;
@@ -30,6 +31,7 @@ import java.util.Arrays;
*
* @author Rodrigo Damazio
*/
@TargetApi(9)
public class Api9Adapter extends Api8Adapter {
@Override
@@ -37,15 +37,15 @@ public class DialogUtils {
* Creates a confirmation dialog.
*
* @param context the context
* @param message the confirmation message
* @param messageId the confirmation message id
* @param onClickListener the listener to invoke when the user clicks OK
*/
public static Dialog createConfirmationDialog(
Context context, String message, DialogInterface.OnClickListener onClickListener) {
Context context, int messageId, DialogInterface.OnClickListener onClickListener) {
return new AlertDialog.Builder(context)
.setCancelable(true)
.setIcon(android.R.drawable.ic_dialog_alert)
.setMessage(message)
.setMessage(context.getString(messageId))
.setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(android.R.string.ok, onClickListener)
.setTitle(R.string.generic_confirm_title)
@@ -56,39 +56,47 @@ public class DialogUtils {
* Creates a spinner progress dialog.
*
* @param context the context
* @param message the progress message
* @param onCancelListener the listener to invoke when the user cancels
* @param messageId the progress message id
* @param onCancelListener the cancel listener
*/
public static ProgressDialog createSpinnerProgressDialog(
Context context, String message, DialogInterface.OnCancelListener onCancelListener) {
ProgressDialog progressDialog = new ProgressDialog(context);
progressDialog.setCancelable(true);
progressDialog.setIcon(android.R.drawable.ic_dialog_info);
progressDialog.setIndeterminate(true);
progressDialog.setMessage(message);
progressDialog.setOnCancelListener(onCancelListener);
progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
progressDialog.setTitle(R.string.generic_progress_title);
return progressDialog;
Context context, int messageId, DialogInterface.OnCancelListener onCancelListener) {
return createProgressDialog(true, context, messageId, onCancelListener);
}
/**
* Creates a horizontal progress dialog.
*
* @param context the context
* @param message the progress message
* @param onCancelListener the listener to invoke when the user cancels
* @param messageId the progress message id
* @param onCancelListener the cancel listener
* @param formatArgs the format arguments for the messageId
*/
public static ProgressDialog createHorizontalProgressDialog(
Context context, String message, DialogInterface.OnCancelListener onCancelListener) {
public static ProgressDialog createHorizontalProgressDialog(Context context, int messageId,
DialogInterface.OnCancelListener onCancelListener, Object... formatArgs) {
return createProgressDialog(false, context, messageId, onCancelListener, formatArgs);
}
/**
* Creates a progress dialog.
*
* @param spinner true to use the spinner style
* @param context the context
* @param messageId the progress message id
* @param onCancelListener the cancel listener
* @param formatArgs the format arguments for the message id
*/
private static ProgressDialog createProgressDialog(boolean spinner, Context context,
int messageId, DialogInterface.OnCancelListener onCancelListener, Object... formatArgs) {
ProgressDialog progressDialog = new ProgressDialog(context);
progressDialog.setCancelable(true);
progressDialog.setIcon(android.R.drawable.ic_dialog_info);
progressDialog.setIndeterminate(true);
progressDialog.setMessage(message);
progressDialog.setMessage(context.getString(messageId, formatArgs));
progressDialog.setOnCancelListener(onCancelListener);
progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setTitle(R.string.generic_progress_title);
progressDialog.setProgressStyle(spinner ? ProgressDialog.STYLE_SPINNER
: ProgressDialog.STYLE_HORIZONTAL);
progressDialog.setTitle(R.string.generic_progress_title);
return progressDialog;
}
}
@@ -35,6 +35,7 @@ public class EulaUtils {
// Accepting Google mobile terms of service
private static final String EULA_PREFERENCE_KEY = "eula.google_mobile_tos_accepted";
// Google's mobile page
private static final String HOST_NAME = "m.google.com";
private EulaUtils() {}
@@ -56,7 +57,7 @@ public class EulaUtils {
public static String getEulaMessage(Context context) {
return context.getString(R.string.eula_date)
+ "\n\n"
+ context.getString(R.string.eula_body, HOST_NAME, HOST_NAME, HOST_NAME, HOST_NAME)
+ context.getString(R.string.eula_body, HOST_NAME)
+ "\n\n"
+ context.getString(R.string.eula_footer, HOST_NAME)
+ "\n\n"
@@ -29,20 +29,46 @@ import java.io.File;
*/
public class FileUtils {
private FileUtils() {}
/**
* The maximum FAT32 path length. See the FAT32 spec at
* http://msdn.microsoft.com/en-us/windows/hardware/gg463080
*/
@VisibleForTesting
static final int MAX_FAT32_PATH_LENGTH = 260;
/**
* Returns whether the SD card is available.
*/
public static boolean isSdCardAvailable() {
return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
}
/**
* Ensures the given directory exists by creating it and its parents if
* necessary.
*
* @return whether the directory exists (either already existed or was
* successfully created)
*/
public static boolean ensureDirectoryExists(File dir) {
if (dir.exists() && dir.isDirectory()) {
return true;
}
if (dir.mkdirs()) {
return true;
}
return false;
}
/**
* Builds a path inside the My Tracks directory in the SD card.
*
* @param components the path components inside the mytracks directory
* @return the full path to the destination
*/
public String buildExternalDirectoryPath(String... components) {
public static String buildExternalDirectoryPath(String... components) {
StringBuilder dirNameBuilder = new StringBuilder();
dirNameBuilder.append(Environment.getExternalStorageDirectory());
dirNameBuilder.append(File.separatorChar);
@@ -54,33 +80,6 @@ public class FileUtils {
return dirNameBuilder.toString();
}
/**
* Returns whether the SD card is available.
*/
public boolean isSdCardAvailable() {
return Environment.MEDIA_MOUNTED.equals(
Environment.getExternalStorageState());
}
/**
* Ensures the given directory exists by creating it and its parents if
* necessary.
*
* @return whether the directory exists (either already existed or was
* successfully created)
*/
public boolean ensureDirectoryExists(File dir) {
if (dir.exists() && dir.isDirectory()) {
return true;
}
if (dir.mkdirs()) {
return true;
}
return false;
}
/**
* Builds a filename with the given base name (prefix) and the given
* extension, possibly adding a suffix to ensure the file doesn't exist.
@@ -90,8 +89,8 @@ public class FileUtils {
* @param extension the file's extension
* @return the complete file name, without the directory
*/
public synchronized String buildUniqueFileName(File directory,
String fileBaseName, String extension) {
public static synchronized String buildUniqueFileName(
File directory, String fileBaseName, String extension) {
return buildUniqueFileName(directory, fileBaseName, extension, 0);
}
@@ -105,7 +104,8 @@ public class FileUtils {
* @param suffix the first numeric suffix to try to use, or 0 for none
* @return the complete filename, without the directory
*/
private String buildUniqueFileName(File directory, String base, String extension, int suffix) {
private static String buildUniqueFileName(
File directory, String base, String extension, int suffix) {
String suffixName = "";
if (suffix > 0) {
suffixName += "(" + Integer.toString(suffix) + ")";
@@ -115,8 +115,8 @@ public class FileUtils {
String baseName = sanitizeFileName(base);
baseName = truncateFileName(directory, baseName, suffixName);
String fullName = baseName + suffixName;
if (!fileExists(directory, fullName)) {
if (!new File(directory, fullName).exists()) {
return fullName;
}
return buildUniqueFileName(directory, base, extension, suffix + 1);
@@ -131,7 +131,7 @@ public class FileUtils {
* @param name name
*/
@VisibleForTesting
String sanitizeFileName(String name) {
static String sanitizeFileName(String name) {
StringBuffer buffer = new StringBuffer(name.length());
for (int i = 0; i < name.length(); i++) {
int codePoint = name.codePointAt(i);
@@ -145,13 +145,13 @@ public class FileUtils {
String result = buffer.toString();
return result.replaceAll("_+", "_");
}
/**
* Returns true if it is a special FAT32 character.
*
*
* @param character the character
*/
private boolean isSpecialFat32(char character) {
private static boolean isSpecialFat32(char character) {
switch (character) {
case '$':
case '%':
@@ -191,8 +191,8 @@ public class FileUtils {
* @param suffix suffix
*/
@VisibleForTesting
String truncateFileName(File directory, String name, String suffix) {
// 1 at the end accounts for the FAT32 filename trailing NUL character
static String truncateFileName(File directory, String name, String suffix) {
// 1 at the end accounts for the FAT32 filename trailing NUL character
int requiredLength = directory.getPath().length() + suffix.length() + 1;
if (name.length() + requiredLength > MAX_FAT32_PATH_LENGTH) {
int limit = MAX_FAT32_PATH_LENGTH - requiredLength;
@@ -201,13 +201,4 @@ public class FileUtils {
return name;
}
}
/**
* Checks whether a file with the given name exists in the given directory.
* This is isolated so it can be overridden in tests.
*/
protected boolean fileExists(File directory, String fullName) {
File file = new File(directory, fullName);
return file.exists();
}
}
@@ -24,7 +24,6 @@ import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
@@ -96,7 +95,7 @@ public class PlayTrackUtils {
.setCancelable(true)
.setMessage(R.string.track_list_play_install_earth_message)
.setNegativeButton(android.R.string.cancel, null)
.setPositiveButton(android.R.string.ok, new OnClickListener() {
.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Intent intent = new Intent();
@@ -1,12 +1,12 @@
/*
* Copyright 2011 Google Inc.
*
*
* 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
@@ -22,7 +22,6 @@ import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.Signature;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
import android.util.Log;
@@ -34,26 +33,6 @@ import android.util.Log;
*/
public class SystemUtils {
private static final int RELEASE_SIGNATURE_HASHCODE = -1855564782;
/**
* Returns whether or not this is a release build.
*/
public static boolean isRelease(Context context) {
try {
Signature [] sigs = context.getPackageManager().getPackageInfo(
context.getPackageName(), PackageManager.GET_SIGNATURES).signatures;
for (Signature sig : sigs) {
if (sig.hashCode() == RELEASE_SIGNATURE_HASHCODE) {
return true;
}
}
} catch (NameNotFoundException e) {
Log.e(Constants.TAG, "Unable to get signatures", e);
}
return false;
}
/**
* Get the My Tracks version from the manifest.
*