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

Commit 877b420f authored by Yorke Lee's avatar Yorke Lee Committed by Android (Google) Code Review
Browse files

Merge "Implement dialpad in XML"

parents 9502a16b bf34a90d
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2013 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.
-->

<!-- A layout representing a single key in the dialpad -->
<com.android.dialer.dialpad.DialpadKeyButton
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/dialpad_key"
    style="@style/DialtactsDialpadButtonStyle"
    android:clickable="true" >
    <TextView
        android:id="@+id/dialpad_key_number"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#33b5e5"
        android:textSize="40dp"
        android:fontFamily="sans-serif-light"
        android:layout_centerInParent="true"
        />
    <TextView
        android:id="@+id/dialpad_key_letters"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#aaaaaa"
        android:textSize="11dp"
        android:paddingRight="11dp"
        android:layout_alignBaseline="@id/dialpad_key_number"
        android:fontFamily="sans-serif-light"
        android:layout_alignParentRight="true"
        />
</com.android.dialer.dialpad.DialpadKeyButton>
 No newline at end of file
+13 −48
Original line number Diff line number Diff line
@@ -26,73 +26,38 @@
    android:paddingStart="5dip"
    android:paddingEnd="5dip"
    android:paddingBottom="10dip"
    android:stretchColumns="0,1,2"
    android:layoutDirection="ltr" >

    <TableRow
         android:layout_height="0px"
         android:layout_weight="1">
        <com.android.dialer.dialpad.DialpadImageButton
            android:id="@+id/one" style="@style/DialtactsDialpadButtonStyle"
            android:src="@drawable/dial_num_1_wht"
            android:contentDescription="@string/description_image_button_one" />
        <com.android.dialer.dialpad.DialpadImageButton
            android:id="@+id/two" style="@style/DialtactsDialpadButtonStyle"
            android:src="@drawable/dial_num_2_wht"
            android:contentDescription="@string/description_image_button_two" />
        <com.android.dialer.dialpad.DialpadImageButton
            android:id="@+id/three" style="@style/DialtactsDialpadButtonStyle"
            android:src="@drawable/dial_num_3_wht"
            android:contentDescription="@string/description_image_button_three" />
        <include layout="@layout/dialpad_key" android:id="@+id/one"/>
        <include layout="@layout/dialpad_key" android:id="@+id/two"/>
        <include layout="@layout/dialpad_key" android:id="@+id/three"/>
    </TableRow>

    <TableRow
         android:layout_height="0px"
         android:layout_weight="1">
        <com.android.dialer.dialpad.DialpadImageButton
            android:id="@+id/four" style="@style/DialtactsDialpadButtonStyle"
            android:src="@drawable/dial_num_4_wht"
            android:contentDescription="@string/description_image_button_four" />
        <com.android.dialer.dialpad.DialpadImageButton
            android:id="@+id/five" style="@style/DialtactsDialpadButtonStyle"
            android:src="@drawable/dial_num_5_wht"
            android:contentDescription="@string/description_image_button_five" />
        <com.android.dialer.dialpad.DialpadImageButton
            android:id="@+id/six" style="@style/DialtactsDialpadButtonStyle"
            android:src="@drawable/dial_num_6_wht"
            android:contentDescription="@string/description_image_button_six" />
        <include layout="@layout/dialpad_key" android:id="@+id/four"/>
        <include layout="@layout/dialpad_key" android:id="@+id/five"/>
        <include layout="@layout/dialpad_key" android:id="@+id/six"/>
    </TableRow>

    <TableRow
         android:layout_height="0px"
         android:layout_weight="1">
        <com.android.dialer.dialpad.DialpadImageButton
            android:id="@+id/seven" style="@style/DialtactsDialpadButtonStyle"
            android:src="@drawable/dial_num_7_wht"
            android:contentDescription="@string/description_image_button_seven" />
        <com.android.dialer.dialpad.DialpadImageButton
            android:id="@+id/eight" style="@style/DialtactsDialpadButtonStyle"
            android:src="@drawable/dial_num_8_wht"
            android:contentDescription="@string/description_image_button_eight" />
        <com.android.dialer.dialpad.DialpadImageButton
            android:id="@+id/nine" style="@style/DialtactsDialpadButtonStyle"
            android:src="@drawable/dial_num_9_wht"
            android:contentDescription="@string/description_image_button_nine" />
        <include layout="@layout/dialpad_key" android:id="@+id/seven"/>
        <include layout="@layout/dialpad_key" android:id="@+id/eight"/>
        <include layout="@layout/dialpad_key" android:id="@+id/nine"/>
    </TableRow>

    <TableRow
         android:layout_height="0px"
         android:layout_weight="1">
        <com.android.dialer.dialpad.DialpadImageButton
            android:id="@+id/star" style="@style/DialtactsDialpadButtonStyle"
            android:src="@drawable/dial_num_star_wht"
            android:contentDescription="@string/description_image_button_star" />
        <com.android.dialer.dialpad.DialpadImageButton
            android:id="@+id/zero" style="@style/DialtactsDialpadButtonStyle"
            android:src="@drawable/dial_num_0_wht"
            android:contentDescription="@string/description_image_button_zero" />
        <com.android.dialer.dialpad.DialpadImageButton
            android:id="@+id/pound" style="@style/DialtactsDialpadButtonStyle"
            android:src="@drawable/dial_num_pound_wht"
            android:contentDescription="@string/description_image_button_pound" />
        <include layout="@layout/dialpad_key" android:id="@+id/star"/>
        <include layout="@layout/dialpad_key" android:id="@+id/zero"/>
        <include layout="@layout/dialpad_key" android:id="@+id/pound"/>
    </TableRow>
</TableLayout>
+2 −2
Original line number Diff line number Diff line
@@ -19,7 +19,7 @@
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <!-- spacer view -->
    <View
    <Space
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1" />
+49 −0
Original line number Diff line number Diff line
@@ -545,4 +545,53 @@

    <!--  Title of activity that displays a list of all calls -->
    <string name="call_log_activity_title">History</string>

    <!--  Do not translate. -->
    <string name="dialpad_0_number">0</string>
    <!--  Do not translate. -->
    <string name="dialpad_0_letters">+</string>
    <!--  Do not translate. -->
    <string name="dialpad_1_number">1</string>
    <!--  Do not translate. -->
    <string name="dialpad_1_letters"></string>
    <!--  Do not translate. -->
    <string name="dialpad_2_number">2</string>
    <!--  Do not translate. -->
    <string name="dialpad_2_letters">ABC</string>
    <!--  Do not translate. -->
    <string name="dialpad_3_number">3</string>
    <!--  Do not translate. -->
    <string name="dialpad_3_letters">DEF</string>
    <!--  Do not translate. -->
    <string name="dialpad_4_number">4</string>
    <!--  Do not translate. -->
    <string name="dialpad_4_letters">GHI</string>
    <!--  Do not translate. -->
    <string name="dialpad_5_number">5</string>
    <!--  Do not translate. -->
    <string name="dialpad_5_letters">JKL</string>
    <!--  Do not translate. -->
    <string name="dialpad_6_number">6</string>
    <!--  Do not translate. -->
    <string name="dialpad_6_letters">MNO</string>
    <!--  Do not translate. -->
    <string name="dialpad_7_number">7</string>
    <!--  Do not translate. -->
    <string name="dialpad_7_letters">PQRS</string>
    <!--  Do not translate. -->
    <string name="dialpad_8_number">8</string>
    <!--  Do not translate. -->
    <string name="dialpad_8_letters">TUV</string>
    <!--  Do not translate. -->
    <string name="dialpad_9_number">9</string>
    <!--  Do not translate. -->
    <string name="dialpad_9_letters">WXYZ</string>
    <!--  Do not translate. -->
    <string name="dialpad_star_number">*</string>
    <!--  Do not translate. -->
    <string name="dialpad_star_letters"></string>
    <!--  Do not translate. -->
    <string name="dialpad_pound_number">#</string>
    <!--  Do not translate. -->
    <string name="dialpad_pound_letters"></string>
</resources>
+137 −0
Original line number Diff line number Diff line
/*
 * 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
 *
 *      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.dialer.dialpad;

import android.content.Context;
import android.graphics.Rect;
import android.os.Bundle;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.RelativeLayout;

/**
 * Custom class for dialpad buttons.
 * <p>
 * This class implements lift-to-type interaction when touch exploration is
 * enabled.
 */
public class DialpadKeyButton extends RelativeLayout {
    /** Accessibility manager instance used to check touch exploration state. */
    private AccessibilityManager mAccessibilityManager;

    /** Bounds used to filter HOVER_EXIT events. */
    private Rect mHoverBounds = new Rect();

    public interface OnPressedListener {
        public void onPressed(View view, boolean pressed);
    }

    private OnPressedListener mOnPressedListener;

    public void setOnPressedListener(OnPressedListener onPressedListener) {
        mOnPressedListener = onPressedListener;
    }

    public DialpadKeyButton(Context context, AttributeSet attrs) {
        super(context, attrs);
        initForAccessibility(context);
    }

    public DialpadKeyButton(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        initForAccessibility(context);
    }

    private void initForAccessibility(Context context) {
        mAccessibilityManager = (AccessibilityManager) context.getSystemService(
                Context.ACCESSIBILITY_SERVICE);
    }

    @Override
    public void setPressed(boolean pressed) {
        super.setPressed(pressed);
        if (mOnPressedListener != null) {
            mOnPressedListener.onPressed(this, pressed);
        }
    }

    @Override
    public void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);

        mHoverBounds.left = getPaddingLeft();
        mHoverBounds.right = w - getPaddingRight();
        mHoverBounds.top = getPaddingTop();
        mHoverBounds.bottom = h - getPaddingBottom();
    }

    @Override
    public boolean performAccessibilityAction(int action, Bundle arguments) {
        if (action == AccessibilityNodeInfo.ACTION_CLICK) {
            simulateClickForAccessibility();
            return true;
        }

        return super.performAccessibilityAction(action, arguments);
    }

    @Override
    public boolean onHoverEvent(MotionEvent event) {
        // When touch exploration is turned on, lifting a finger while inside
        // the button's hover target bounds should perform a click action.
        if (mAccessibilityManager.isEnabled()
                && mAccessibilityManager.isTouchExplorationEnabled()) {
            switch (event.getActionMasked()) {
                case MotionEvent.ACTION_HOVER_ENTER:
                    // Lift-to-type temporarily disables double-tap activation.
                    setClickable(false);
                    break;
                case MotionEvent.ACTION_HOVER_EXIT:
                    if (mHoverBounds.contains((int) event.getX(), (int) event.getY())) {
                        simulateClickForAccessibility();
                    }
                    setClickable(true);
                    break;
            }
        }

        return super.onHoverEvent(event);
    }

    /**
     * When accessibility is on, simulate press and release to preserve the
     * semantic meaning of performClick(). Required for Braille support.
     */
    private void simulateClickForAccessibility() {
        // Checking the press state prevents double activation.
        if (isPressed()) {
            return;
        }

        setPressed(true);

        // Stay consistent with performClick() by sending the event after
        // setting the pressed state but before performing the action.
        sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);

        setPressed(false);
    }
}
Loading