summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/PrintSpooler/res/layout/print_activity.xml4
-rw-r--r--packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java23
-rw-r--r--packages/PrintSpooler/src/com/android/printspooler/widget/ClickInterceptSpinner.java56
3 files changed, 67 insertions, 16 deletions
diff --git a/packages/PrintSpooler/res/layout/print_activity.xml b/packages/PrintSpooler/res/layout/print_activity.xml
index 94519d425f0a..774f320d6fd2 100644
--- a/packages/PrintSpooler/res/layout/print_activity.xml
+++ b/packages/PrintSpooler/res/layout/print_activity.xml
@@ -31,7 +31,7 @@
android:elevation="@dimen/preview_controls_elevation"
android:background="?android:attr/colorPrimary">
- <Spinner
+ <com.android.printspooler.widget.ClickInterceptSpinner
android:id="@+id/destination_spinner"
android:layout_width="wrap_content"
android:minWidth="@dimen/preview_destination_spinner_width"
@@ -39,7 +39,7 @@
android:layout_marginTop="4dip"
android:dropDownWidth="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeightSmall">
- </Spinner>
+ </com.android.printspooler.widget.ClickInterceptSpinner>
</FrameLayout>
diff --git a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java
index 601491abfd7e..1b7a1b8b9567 100644
--- a/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java
+++ b/packages/PrintSpooler/src/com/android/printspooler/ui/PrintActivity.java
@@ -70,7 +70,6 @@ import android.util.ArraySet;
import android.util.Log;
import android.util.TypedValue;
import android.view.KeyEvent;
-import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
@@ -101,6 +100,7 @@ import com.android.printspooler.util.ApprovedPrintServices;
import com.android.printspooler.util.MediaSizeUtils;
import com.android.printspooler.util.MediaSizeUtils.MediaSizeComparator;
import com.android.printspooler.util.PageRangeUtils;
+import com.android.printspooler.widget.ClickInterceptSpinner;
import com.android.printspooler.widget.PrintContentView;
import com.android.printspooler.widget.PrintContentView.OptionsStateChangeListener;
import com.android.printspooler.widget.PrintContentView.OptionsStateController;
@@ -200,7 +200,7 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
private TextView mPageRangeTitle;
private EditText mPageRangeEditText;
- private Spinner mDestinationSpinner;
+ private ClickInterceptSpinner mDestinationSpinner;
private DestinationAdapter mDestinationSpinnerAdapter;
private boolean mShowDestinationPrompt;
@@ -1383,19 +1383,14 @@ public class PrintActivity extends Activity implements RemotePrintDocument.Updat
mSummaryCopies.setEnabled(false);
mSummaryPaperSize.setEnabled(false);
- mDestinationSpinner.setOnTouchListener(new View.OnTouchListener() {
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- mShowDestinationPrompt = false;
- mSummaryCopies.setEnabled(true);
- mSummaryPaperSize.setEnabled(true);
- updateOptionsUi();
-
- mDestinationSpinner.setOnTouchListener(null);
- mDestinationSpinnerAdapter.notifyDataSetChanged();
+ mDestinationSpinner.setPerformClickListener((v) -> {
+ mShowDestinationPrompt = false;
+ mSummaryCopies.setEnabled(true);
+ mSummaryPaperSize.setEnabled(true);
+ updateOptionsUi();
- return false;
- }
+ mDestinationSpinner.setPerformClickListener(null);
+ mDestinationSpinnerAdapter.notifyDataSetChanged();
});
}
}
diff --git a/packages/PrintSpooler/src/com/android/printspooler/widget/ClickInterceptSpinner.java b/packages/PrintSpooler/src/com/android/printspooler/widget/ClickInterceptSpinner.java
new file mode 100644
index 000000000000..1d3aac9997ff
--- /dev/null
+++ b/packages/PrintSpooler/src/com/android/printspooler/widget/ClickInterceptSpinner.java
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2017 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.printspooler.widget;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.widget.Spinner;
+
+/**
+ * Spinner that can intercept {@link Spinner#performClick()}
+ */
+public class ClickInterceptSpinner extends Spinner {
+ private OnClickListener mListener;
+
+ /**
+ * Create a new spinner with the given attributes.
+ *
+ * @param context The context for the spinner
+ * @param attrs Attributes of the spinner
+ */
+ public ClickInterceptSpinner(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ /**
+ * Set a listener invoked on {@link #performClick()}
+ *
+ * @param listener The listener to be invoked
+ */
+ public void setPerformClickListener(OnClickListener listener) {
+ mListener = listener;
+ }
+
+ @Override
+ public boolean performClick() {
+ if (mListener != null) {
+ mListener.onClick(this);
+ }
+
+ return super.performClick();
+ }
+}