Added tich delegation to the map button, to make them easier to click

Change-Id: Ia43fa2a13af68c5e81f6023a8948d4d851479f21
Signed-off-by: Ricky Barrette <rickbarrette@gmail.com>
This commit is contained in:
2012-03-09 10:48:05 -05:00
parent 9835514d29
commit cd1a00ac52
4 changed files with 113 additions and 38 deletions

Binary file not shown.

View File

@@ -3,91 +3,92 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/distance_background"
android:baselineAligned="false"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dip"
android:layout_marginTop="10dip"
android:layout_weight="1"
android:orientation="vertical" >
android:paddingBottom="10dip"
android:paddingTop="10dip" >
<ImageButton
<com.TwentyCodes.android.FindMyCarLib.UI.DelegatedImageButton
android:id="@+id/my_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/my_location_action_bar"
android:contentDescription="@string/my_location" />
android:contentDescription="@string/my_location"
android:duplicateParentState="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dip"
android:layout_marginTop="10dip"
android:layout_weight="1"
android:orientation="vertical" >
android:paddingBottom="10dip"
android:paddingTop="10dip" >
<ImageButton
<com.TwentyCodes.android.FindMyCarLib.UI.DelegatedImageButton
android:id="@+id/mark_my_location"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/mark_my_location_action_bar"
android:contentDescription="@string/mark_car" />
android:contentDescription="@string/mark_car"
android:duplicateParentState="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dip"
android:layout_marginTop="10dip"
android:layout_weight="1"
android:orientation="vertical" >
android:paddingBottom="10dip"
android:paddingTop="10dip" >
<ImageButton
<com.TwentyCodes.android.FindMyCarLib.UI.DelegatedImageButton
android:id="@+id/show_both"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_gravity="center"
android:background="@drawable/car_action_bar" />
android:background="@drawable/car_action_bar"
android:duplicateParentState="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dip"
android:layout_marginTop="10dip"
android:layout_weight="1"
android:orientation="vertical" >
android:paddingBottom="10dip"
android:paddingTop="10dip" >
<ImageButton
<com.TwentyCodes.android.FindMyCarLib.UI.DelegatedImageButton
android:id="@+id/parking_timer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/time_action_bar"
android:contentDescription="@string/parking_timer" />
android:contentDescription="@string/parking_timer"
android:duplicateParentState="true" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="10dip"
android:layout_marginTop="10dip"
android:layout_weight="1"
android:orientation="vertical" >
android:paddingBottom="10dip"
android:paddingTop="10dip" >
<ImageButton
<com.TwentyCodes.android.FindMyCarLib.UI.DelegatedImageButton
android:id="@+id/directions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/nav_action_bar"
android:contentDescription="@string/directions" />
android:contentDescription="@string/directions"
android:duplicateParentState="true" />
</RelativeLayout>
</LinearLayout>

View File

@@ -1,14 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="com.admob.android.ads.AdView">
<attr format="color" name="backgroundColor" />
<attr format="color" name="primaryTextColor" />
<attr format="color" name="secondaryTextColor" />
<attr format="string" name="keywords" />
<attr format="integer" name="refreshInterval" />
</declare-styleable>
<!--
Copyright (C) 2011 Patrik Åkerfeldt
Copyright (C) 2011 Jake Wharton

View File

@@ -0,0 +1,82 @@
/**
* DelegatedImageButton.java
* @date Mar 9, 2012
* @author ricky barrette
* @author Twenty Codes, LLC
*/
package com.TwentyCodes.android.FindMyCarLib.UI;
import android.content.Context;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.TouchDelegate;
import android.view.View;
import android.view.View.OnAttachStateChangeListener;
import android.widget.LinearLayout;
/**
* This button is a simple image button that extends it's touch hit rect
* @author ricky barrette
*/
public class DelegatedImageButton extends LinearLayout implements OnAttachStateChangeListener {
/**
* @param context
* @author ricky barrette
*/
public DelegatedImageButton(Context context) {
super(context);
this.addOnAttachStateChangeListener(this);
}
/**
* @param context
* @param attrs
* @author ricky barrette
*/
public DelegatedImageButton(Context context, AttributeSet attrs) {
super(context, attrs);
this.addOnAttachStateChangeListener(this);
}
/**
* @param context
* @param attrs
* @param defStyle
* @author ricky barrette
*/
public DelegatedImageButton(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.addOnAttachStateChangeListener(this);
}
public void initDelegate(){
final View parent = (View) this.getParent();
parent.post(new Runnable() {
@Override
public void run() {
Rect bounds = new Rect();
DelegatedImageButton.this.getHitRect(bounds);
bounds.top -= 40;
bounds.left -= 40;
bounds.bottom += 40;
bounds.right += 40;
TouchDelegate touchDelegate = new TouchDelegate(bounds, DelegatedImageButton.this);
if (View.class.isInstance(DelegatedImageButton.this.getParent())) {
((View) DelegatedImageButton.this.getParent()).setTouchDelegate(touchDelegate);
}
}
});
}
@Override
public void onViewAttachedToWindow(View v) {
initDelegate();
}
@Override
public void onViewDetachedFromWindow(View v) {
// UNUSED
}
}