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

Commit 9785f9a1 authored by Georg Veichtlbauer's avatar Georg Veichtlbauer
Browse files

ExactCalculator: Replace HapticImageButton with the Material based one

Change-Id: If6bae52c7e93b484bd73316bfdf5d73bd704a79b
parent a3904c40
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -24,11 +24,11 @@
    app:rowCount="5"
    app:columnCount="1">

    <com.android.calculator2.HapticImageButton
    <com.android.calculator2.HapticButton
        android:id="@+id/del"
        style="@style/PadButtonStyle.Operator"
        style="@style/PadButtonStyle.Operator.Image"
        android:contentDescription="@string/desc_del"
        android:src="@drawable/ic_del"
        app:icon="@drawable/ic_del"
        app:layout_row="0"
        app:layout_column="0" />

+3 −3
Original line number Diff line number Diff line
@@ -32,11 +32,11 @@
        app:layout_row="0"
        app:layout_column="0" />

    <com.android.calculator2.HapticImageButton
    <com.android.calculator2.HapticButton
        android:id="@+id/del"
        style="@style/PadButtonStyle.Operator"
        style="@style/PadButtonStyle.Operator.Image"
        android:contentDescription="@string/desc_del"
        android:src="@drawable/ic_del"
        app:icon="@drawable/ic_del"
        app:layout_row="0"
        app:layout_column="1" />

+6 −0
Original line number Diff line number Diff line
@@ -102,6 +102,12 @@
        <item name="android:textSize">12dip</item>
    </style>

    <style name="PadButtonStyle.Operator.Image">
        <item name="iconTint">@color/pad_button_text_color</item>
        <item name="iconGravity">textStart</item>
        <item name="iconSize">32dp</item>
    </style>

    <style name="PadLayoutStyle">
        <item name="android:layout_width">match_parent</item>
        <item name="android:layout_height">match_parent</item>
+0 −59
Original line number Diff line number Diff line
/*
 * Copyright (C) 2007 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.calculator2;

import android.content.Context;
import android.util.AttributeSet;
import android.view.HapticFeedbackConstants;
import android.view.MotionEvent;
import android.view.View;

import androidx.appcompat.widget.AppCompatImageButton;

/**
 * A basic ImageButton that vibrates on finger down.
 */
public class HapticImageButton extends AppCompatImageButton {
    public HapticImageButton(Context context) {
        super(context);
        initVibration(context);
    }

    public HapticImageButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        initVibration(context);
    }

    public HapticImageButton(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initVibration(context);
    }

    private void initVibration(Context context) {
        setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN) {
                    performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
                }

                // Passthrough
                return false;
            }
        });
    }
}