Home | History | Annotate | Download | only in widget
      1 /*
      2  * Copyright (C) 2016 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License
     15  */
     16 
     17 package com.android.internal.widget;
     18 
     19 import android.annotation.Nullable;
     20 import android.content.Context;
     21 import android.graphics.Rect;
     22 import android.util.AttributeSet;
     23 import android.view.View;
     24 import android.view.accessibility.AccessibilityNodeInfo;
     25 import android.widget.Button;
     26 import android.widget.ImageView;
     27 import android.widget.RemoteViews;
     28 
     29 /**
     30  * An expand button in a notification
     31  */
     32 @RemoteViews.RemoteView
     33 public class NotificationExpandButton extends ImageView {
     34     private View mLabeledBy;
     35 
     36     public NotificationExpandButton(Context context) {
     37         super(context);
     38     }
     39 
     40     public NotificationExpandButton(Context context, @Nullable AttributeSet attrs) {
     41         super(context, attrs);
     42     }
     43 
     44     public NotificationExpandButton(Context context, @Nullable AttributeSet attrs,
     45             int defStyleAttr) {
     46         super(context, attrs, defStyleAttr);
     47     }
     48 
     49     public NotificationExpandButton(Context context, @Nullable AttributeSet attrs, int defStyleAttr,
     50             int defStyleRes) {
     51         super(context, attrs, defStyleAttr, defStyleRes);
     52     }
     53 
     54     @Override
     55     public void getBoundsOnScreen(Rect outRect, boolean clipToParent) {
     56         super.getBoundsOnScreen(outRect, clipToParent);
     57         extendRectToMinTouchSize(outRect);
     58     }
     59 
     60     private void extendRectToMinTouchSize(Rect rect) {
     61         int touchTargetSize = (int) (getResources().getDisplayMetrics().density * 48);
     62         rect.left = rect.centerX() - touchTargetSize / 2;
     63         rect.right = rect.left + touchTargetSize;
     64         rect.top = rect.centerY() - touchTargetSize / 2;
     65         rect.bottom = rect.top + touchTargetSize;
     66     }
     67 
     68     @Override
     69     public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
     70         super.onInitializeAccessibilityNodeInfo(info);
     71         info.setClassName(Button.class.getName());
     72         if (mLabeledBy != null) {
     73             info.setLabeledBy(mLabeledBy);
     74         }
     75     }
     76 
     77     public void setLabeledBy(View labeledBy) {
     78         mLabeledBy = labeledBy;
     79     }
     80 }
     81