diff options
Diffstat (limited to 'java/src/com/android/inputmethod/research/FeedbackFragment.java')
-rw-r--r-- | java/src/com/android/inputmethod/research/FeedbackFragment.java | 152 |
1 files changed, 116 insertions, 36 deletions
diff --git a/java/src/com/android/inputmethod/research/FeedbackFragment.java b/java/src/com/android/inputmethod/research/FeedbackFragment.java index a2e08e2b7..39f9c87a0 100644 --- a/java/src/com/android/inputmethod/research/FeedbackFragment.java +++ b/java/src/com/android/inputmethod/research/FeedbackFragment.java @@ -1,17 +1,17 @@ /* * Copyright (C) 2012 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 + * 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 + * 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. + * 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.research; @@ -20,6 +20,8 @@ import android.app.Activity; import android.app.Fragment; import android.os.Bundle; import android.text.Editable; +import android.text.TextUtils; +import android.util.Log; import android.view.LayoutInflater; import android.view.View; import android.view.View.OnClickListener; @@ -27,12 +29,22 @@ import android.view.ViewGroup; import android.widget.Button; import android.widget.CheckBox; import android.widget.EditText; +import android.widget.Toast; import com.android.inputmethod.latin.R; -public class FeedbackFragment extends Fragment { +public class FeedbackFragment extends Fragment implements OnClickListener { + private static final String TAG = FeedbackFragment.class.getSimpleName(); + + public static final String KEY_FEEDBACK_STRING = "FeedbackString"; + public static final String KEY_INCLUDE_ACCOUNT_NAME = "IncludeAccountName"; + public static final String KEY_HAS_USER_RECORDING = "HasRecording"; + private EditText mEditText; - private CheckBox mCheckBox; + private CheckBox mIncludingAccountNameCheckBox; + private CheckBox mIncludingUserRecordingCheckBox; + private Button mSendButton; + private Button mCancelButton; @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, @@ -40,34 +52,102 @@ public class FeedbackFragment extends Fragment { final View view = inflater.inflate(R.layout.research_feedback_fragment_layout, container, false); mEditText = (EditText) view.findViewById(R.id.research_feedback_contents); - mCheckBox = (CheckBox) view.findViewById(R.id.research_feedback_include_history); - - final Button sendButton = (Button) view.findViewById( - R.id.research_feedback_send_button); - sendButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - final Editable editable = mEditText.getText(); - final String feedbackContents = editable.toString(); - final boolean includeHistory = mCheckBox.isChecked(); - ResearchLogger.getInstance().sendFeedback(feedbackContents, includeHistory); - final Activity activity = FeedbackFragment.this.getActivity(); - activity.finish(); - ResearchLogger.getInstance().onLeavingSendFeedbackDialog(); + mEditText.requestFocus(); + mIncludingAccountNameCheckBox = (CheckBox) view.findViewById( + R.id.research_feedback_include_account_name); + mIncludingUserRecordingCheckBox = (CheckBox) view.findViewById( + R.id.research_feedback_include_recording_checkbox); + mIncludingUserRecordingCheckBox.setOnClickListener(this); + + mSendButton = (Button) view.findViewById(R.id.research_feedback_send_button); + mSendButton.setOnClickListener(this); + mCancelButton = (Button) view.findViewById(R.id.research_feedback_cancel_button); + mCancelButton.setOnClickListener(this); + + if (savedInstanceState != null) { + Log.d(TAG, "restoring from savedInstanceState"); + restoreState(savedInstanceState); + } else { + final Bundle bundle = getActivity().getIntent().getExtras(); + if (bundle != null) { + Log.d(TAG, "restoring from getArguments()"); + restoreState(bundle); } - }); - - final Button cancelButton = (Button) view.findViewById( - R.id.research_feedback_cancel_button); - cancelButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - final Activity activity = FeedbackFragment.this.getActivity(); - activity.finish(); - ResearchLogger.getInstance().onLeavingSendFeedbackDialog(); + } + return view; + } + + @Override + public void onClick(final View view) { + final ResearchLogger researchLogger = ResearchLogger.getInstance(); + if (view == mIncludingUserRecordingCheckBox) { + if (hasUserRecording()) { + // Remove the recording + setHasUserRecording(false); + } else { + final Bundle bundle = new Bundle(); + onSaveInstanceState(bundle); + + // Let the user make a recording + getActivity().finish(); + + researchLogger.setFeedbackDialogBundle(bundle); + researchLogger.onLeavingSendFeedbackDialog(); + researchLogger.startRecording(); } - }); + } else if (view == mSendButton) { + final Editable editable = mEditText.getText(); + final String feedbackContents = editable.toString(); + if (TextUtils.isEmpty(feedbackContents)) { + Toast.makeText(getActivity(), + R.string.research_feedback_empty_feedback_error_message, + Toast.LENGTH_LONG).show(); + } else { + final boolean isIncludingAccountName = isIncludingAccountName(); + researchLogger.sendFeedback(feedbackContents, + false /* isIncludingHistory */, isIncludingAccountName, hasUserRecording()); + getActivity().finish(); + researchLogger.setFeedbackDialogBundle(null); + researchLogger.onLeavingSendFeedbackDialog(); + } + } else if (view == mCancelButton) { + Log.d(TAG, "Finishing"); + getActivity().finish(); + researchLogger.setFeedbackDialogBundle(null); + researchLogger.onLeavingSendFeedbackDialog(); + } else { + Log.e(TAG, "Unknown view passed to FeedbackFragment.onClick()"); + } + } - return view; + @Override + public void onSaveInstanceState(final Bundle bundle) { + 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()); + } + + public 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); } } |