Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7606405b authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "DestinationSpinner intercepts click not touch"

parents 02d082dd a436bf59
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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>

+9 −14
Original line number Diff line number Diff line
@@ -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) {
            mDestinationSpinner.setPerformClickListener((v) -> {
                mShowDestinationPrompt = false;
                mSummaryCopies.setEnabled(true);
                mSummaryPaperSize.setEnabled(true);
                updateOptionsUi();

                    mDestinationSpinner.setOnTouchListener(null);
                mDestinationSpinner.setPerformClickListener(null);
                mDestinationSpinnerAdapter.notifyDataSetChanged();

                    return false;
                }
            });
        }
    }
+56 −0
Original line number Diff line number Diff line
/*
 * 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();
    }
}