Home | History | Annotate | Download | only in view
      1 /*
      2  * Copyright (C) 2010 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.example.android.apis.view;
     18 
     19 import com.example.android.apis.R;
     20 
     21 import android.content.Context;
     22 import android.util.AttributeSet;
     23 import android.view.View;
     24 import android.view.ViewGroup;
     25 
     26 /**
     27  * This view is part of the {@link SecureView} demonstration activity.
     28  *
     29  * This view is constructed in such a way as to obscure the buttons and descriptive
     30  * text of the activity in a poor attempt to fool the user into clicking on the buttons
     31  * despite the activity telling the user that they may be harmful.
     32  */
     33 public class SecureViewOverlay extends ViewGroup {
     34     private SecureView mActivity;
     35 
     36     public SecureViewOverlay(Context context, AttributeSet attrs) {
     37         super(context, attrs);
     38     }
     39 
     40     public void setActivityToSpoof(SecureView activity) {
     41         this.mActivity = activity;
     42     }
     43 
     44     @Override
     45     protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
     46         measureChildren(widthMeasureSpec, heightMeasureSpec);
     47 
     48         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
     49     }
     50 
     51     @Override
     52     protected void onLayout(boolean changed, int l, int t, int r, int b) {
     53         spoofLayout(findViewById(R.id.secure_view_overlay_description),
     54                 mActivity.findViewById(R.id.secure_view_description));
     55         spoofLayout(findViewById(R.id.secure_view_overlay_button1),
     56                 mActivity.findViewById(R.id.secure_view_unsecure_button));
     57         spoofLayout(findViewById(R.id.secure_view_overlay_button2),
     58                 mActivity.findViewById(R.id.secure_view_builtin_secure_button));
     59         spoofLayout(findViewById(R.id.secure_view_overlay_button3),
     60                 mActivity.findViewById(R.id.secure_view_custom_secure_button));
     61     }
     62 
     63     private void spoofLayout(View spoof, View original) {
     64         final int[] globalPos = new int[2];
     65         getLocationOnScreen(globalPos);
     66         int x = globalPos[0];
     67         int y = globalPos[1];
     68 
     69         original.getLocationOnScreen(globalPos);
     70         x = globalPos[0] - x;
     71         y = globalPos[1] - y;
     72         spoof.layout(x, y, x + original.getWidth(), y + original.getHeight());
     73     }
     74 }
     75