aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/research/FeedbackFragment.java37
-rw-r--r--java/src/com/android/inputmethod/research/FixedLogBuffer.java26
-rw-r--r--java/src/com/android/inputmethod/research/MainLogBuffer.java17
-rw-r--r--java/src/com/android/inputmethod/research/UploaderService.java25
4 files changed, 38 insertions, 67 deletions
diff --git a/java/src/com/android/inputmethod/research/FeedbackFragment.java b/java/src/com/android/inputmethod/research/FeedbackFragment.java
index 8ee2d8e71..a0738292e 100644
--- a/java/src/com/android/inputmethod/research/FeedbackFragment.java
+++ b/java/src/com/android/inputmethod/research/FeedbackFragment.java
@@ -79,10 +79,7 @@ public class FeedbackFragment extends Fragment implements OnClickListener {
public void onClick(final View view) {
final ResearchLogger researchLogger = ResearchLogger.getInstance();
if (view == mIncludingUserRecordingCheckBox) {
- if (hasUserRecording()) {
- // Remove the recording
- setHasUserRecording(false);
- } else {
+ if (mIncludingUserRecordingCheckBox.isChecked()) {
final Bundle bundle = new Bundle();
onSaveInstanceState(bundle);
@@ -101,9 +98,9 @@ public class FeedbackFragment extends Fragment implements OnClickListener {
R.string.research_feedback_empty_feedback_error_message,
Toast.LENGTH_LONG).show();
} else {
- final boolean isIncludingAccountName = isIncludingAccountName();
- researchLogger.sendFeedback(feedbackContents,
- false /* isIncludingHistory */, isIncludingAccountName, hasUserRecording());
+ final boolean isIncludingAccountName = mIncludingAccountNameCheckBox.isChecked();
+ researchLogger.sendFeedback(feedbackContents, false /* isIncludingHistory */,
+ isIncludingAccountName, mIncludingUserRecordingCheckBox.isChecked());
getActivity().finish();
researchLogger.setFeedbackDialogBundle(null);
researchLogger.onLeavingSendFeedbackDialog();
@@ -123,29 +120,13 @@ public class FeedbackFragment extends Fragment implements OnClickListener {
final String savedFeedbackString = mEditText.getText().toString();
bundle.putString(KEY_FEEDBACK_STRING, savedFeedbackString);
- bundle.putBoolean(KEY_INCLUDE_ACCOUNT_NAME, isIncludingAccountName());
- bundle.putBoolean(KEY_HAS_USER_RECORDING, hasUserRecording());
+ bundle.putBoolean(KEY_INCLUDE_ACCOUNT_NAME, mIncludingAccountNameCheckBox.isChecked());
+ bundle.putBoolean(KEY_HAS_USER_RECORDING, mIncludingUserRecordingCheckBox.isChecked());
}
- public void restoreState(final Bundle bundle) {
+ private void restoreState(final Bundle bundle) {
mEditText.setText(bundle.getString(KEY_FEEDBACK_STRING));
- setIsIncludingAccountName(bundle.getBoolean(KEY_INCLUDE_ACCOUNT_NAME));
- setHasUserRecording(bundle.getBoolean(KEY_HAS_USER_RECORDING));
- }
-
- private boolean hasUserRecording() {
- return mIncludingUserRecordingCheckBox.isChecked();
- }
-
- private void setHasUserRecording(final boolean hasRecording) {
- mIncludingUserRecordingCheckBox.setChecked(hasRecording);
- }
-
- private boolean isIncludingAccountName() {
- return mIncludingAccountNameCheckBox.isChecked();
- }
-
- private void setIsIncludingAccountName(final boolean isIncludingAccountName) {
- mIncludingAccountNameCheckBox.setChecked(isIncludingAccountName);
+ mIncludingAccountNameCheckBox.setChecked(bundle.getBoolean(KEY_INCLUDE_ACCOUNT_NAME));
+ mIncludingUserRecordingCheckBox.setChecked(bundle.getBoolean(KEY_HAS_USER_RECORDING));
}
}
diff --git a/java/src/com/android/inputmethod/research/FixedLogBuffer.java b/java/src/com/android/inputmethod/research/FixedLogBuffer.java
index 78dc59562..641bf7eae 100644
--- a/java/src/com/android/inputmethod/research/FixedLogBuffer.java
+++ b/java/src/com/android/inputmethod/research/FixedLogBuffer.java
@@ -51,10 +51,6 @@ public class FixedLogBuffer extends LogBuffer {
mNumActualWords = 0;
}
- protected int getNumActualWords() {
- return mNumActualWords;
- }
-
/**
* Adds a new LogUnit to the front of the LIFO queue, evicting existing LogUnit's
* (oldest first) if word capacity is reached.
@@ -119,12 +115,24 @@ public class FixedLogBuffer extends LogBuffer {
return logUnit;
}
- protected void shiftOutWords(final int numWords) {
- final int targetNumWords = mNumActualWords - numWords;
- final LinkedList<LogUnit> logUnits = getLogUnits();
- while (mNumActualWords > targetNumWords && !logUnits.isEmpty()) {
- shiftOut();
+ /**
+ * Remove LogUnits from the front of the LogBuffer until {@code numWords} have been removed.
+ *
+ * If there are less than {@code numWords} word-containing {@link LogUnit}s, shifts out
+ * all {@code LogUnit}s in the buffer.
+ *
+ * @param numWords the number of word-containing {@link LogUnit}s to shift out
+ * @return the number of actual {@code LogUnit}s shifted out
+ */
+ protected int shiftOutWords(final int numWords) {
+ int numWordContainingLogUnitsShiftedOut = 0;
+ for (LogUnit logUnit = shiftOut(); logUnit != null
+ && numWordContainingLogUnitsShiftedOut < numWords; logUnit = shiftOut()) {
+ if (logUnit.hasWord()) {
+ numWordContainingLogUnitsShiftedOut++;
+ }
}
+ return numWordContainingLogUnitsShiftedOut;
}
public void shiftOutAll() {
diff --git a/java/src/com/android/inputmethod/research/MainLogBuffer.java b/java/src/com/android/inputmethod/research/MainLogBuffer.java
index 3303d2bdb..cd4c1db6e 100644
--- a/java/src/com/android/inputmethod/research/MainLogBuffer.java
+++ b/java/src/com/android/inputmethod/research/MainLogBuffer.java
@@ -25,7 +25,6 @@ import com.android.inputmethod.latin.define.ProductionFlag;
import java.util.ArrayList;
import java.util.LinkedList;
-import java.util.Random;
/**
* MainLogBuffer is a FixedLogBuffer that tracks the state of LogUnits to make privacy guarantees.
@@ -100,10 +99,6 @@ public abstract class MainLogBuffer extends FixedLogBuffer {
return mSuggest.getMainDictionary();
}
- public void resetWordCounter() {
- mNumWordsUntilSafeToSample = mNumWordsBetweenNGrams;
- }
-
public void setIsStopping() {
mIsStopping = true;
}
@@ -201,7 +196,7 @@ public abstract class MainLogBuffer extends FixedLogBuffer {
// Good n-gram at the front of the buffer. Publish it, disclosing details.
publish(logUnits, true /* canIncludePrivateData */);
shiftOutWords(N_GRAM_SIZE);
- resetWordCounter();
+ mNumWordsUntilSafeToSample = mNumWordsBetweenNGrams;
} else {
// No good n-gram at front, and buffer is full. Shift out the first word (or if there
// is none, the existing logUnits).
@@ -224,13 +219,13 @@ public abstract class MainLogBuffer extends FixedLogBuffer {
final boolean canIncludePrivateData);
@Override
- protected void shiftOutWords(final int numWords) {
- final int oldNumActualWords = getNumActualWords();
- super.shiftOutWords(numWords);
- final int numWordsShifted = oldNumActualWords - getNumActualWords();
- mNumWordsUntilSafeToSample -= numWordsShifted;
+ protected int shiftOutWords(final int numWords) {
+ final int numWordContainingLogUnitsShiftedOut = super.shiftOutWords(numWords);
+ mNumWordsUntilSafeToSample = Math.max(0, mNumWordsUntilSafeToSample
+ - numWordContainingLogUnitsShiftedOut);
if (DEBUG) {
Log.d(TAG, "wordsUntilSafeToSample now at " + mNumWordsUntilSafeToSample);
}
+ return numWordContainingLogUnitsShiftedOut;
}
}
diff --git a/java/src/com/android/inputmethod/research/UploaderService.java b/java/src/com/android/inputmethod/research/UploaderService.java
index 6a9717b7c..d2db34927 100644
--- a/java/src/com/android/inputmethod/research/UploaderService.java
+++ b/java/src/com/android/inputmethod/research/UploaderService.java
@@ -22,6 +22,7 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
+import android.os.SystemClock;
import com.android.inputmethod.latin.define.ProductionFlag;
@@ -79,28 +80,14 @@ public final class UploaderService extends IntentService {
*/
public static void cancelAndRescheduleUploadingService(final Context context,
final boolean needsRescheduling) {
- final PendingIntent pendingIntent = getPendingIntentForService(context);
+ final Intent intent = new Intent(context, UploaderService.class);
+ final PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0);
final AlarmManager alarmManager = (AlarmManager) context.getSystemService(
Context.ALARM_SERVICE);
- cancelAnyScheduledServiceAlarm(alarmManager, pendingIntent);
+ alarmManager.cancel(pendingIntent);
if (needsRescheduling) {
- scheduleServiceAlarm(alarmManager, pendingIntent);
+ alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime()
+ + UploaderService.RUN_INTERVAL, pendingIntent);
}
}
-
- private static PendingIntent getPendingIntentForService(final Context context) {
- final Intent intent = new Intent(context, UploaderService.class);
- return PendingIntent.getService(context, 0, intent, 0);
- }
-
- private static void cancelAnyScheduledServiceAlarm(final AlarmManager alarmManager,
- final PendingIntent pendingIntent) {
- alarmManager.cancel(pendingIntent);
- }
-
- private static void scheduleServiceAlarm(final AlarmManager alarmManager,
- final PendingIntent pendingIntent) {
- alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, UploaderService.RUN_INTERVAL,
- pendingIntent);
- }
}