Introduce the examples of pointer shape API.
Change-Id: Ib0be39d560fbc00db661f639a02c4df2e2c1867b
This commit is contained in:
committed by
Vladislav Kaznacheev
parent
7f5ff73972
commit
6cb3668322
@@ -2691,6 +2691,13 @@
|
|||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
|
<activity android:name=".view.PointerShapes" android:label="Views/Pointer shapes">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<category android:name="android.intent.category.SAMPLE_CODE" />
|
||||||
|
</intent-filter>
|
||||||
|
</activity>
|
||||||
|
|
||||||
<!-- ************************************* -->
|
<!-- ************************************* -->
|
||||||
<!-- GRAPHICS SAMPLES -->
|
<!-- GRAPHICS SAMPLES -->
|
||||||
<!-- ************************************* -->
|
<!-- ************************************* -->
|
||||||
|
|||||||
BIN
samples/ApiDemos/res/drawable-hdpi/smile.png
Normal file
BIN
samples/ApiDemos/res/drawable-hdpi/smile.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.3 KiB |
BIN
samples/ApiDemos/res/drawable-mdpi/smile.png
Normal file
BIN
samples/ApiDemos/res/drawable-mdpi/smile.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 1.7 KiB |
5
samples/ApiDemos/res/drawable/custom_pointer_icon.xml
Normal file
5
samples/ApiDemos/res/drawable/custom_pointer_icon.xml
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<pointer-icon xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:bitmap="@drawable/smile"
|
||||||
|
android:hotSpotX="25dp"
|
||||||
|
android:hotSpotY="25dp" />
|
||||||
216
samples/ApiDemos/res/layout/pointer_shapes.xml
Normal file
216
samples/ApiDemos/res/layout/pointer_shapes.xml
Normal file
@@ -0,0 +1,216 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2016 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<!-- Lots of buttons = might need scrolling -->
|
||||||
|
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pointer_shape_description" />
|
||||||
|
|
||||||
|
<GridLayout
|
||||||
|
android:columnCount="2"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/pointer_shape_view_arrow"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pointer_shape_arrow"
|
||||||
|
android:pointerShape="arrow" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/pointer_shape_view_context_menu"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pointer_shape_context_menu"
|
||||||
|
android:pointerShape="context_menu" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/pointer_shape_view_hand"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pointer_shape_hand"
|
||||||
|
android:pointerShape="hand" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/pointer_shape_view_help"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pointer_shape_help"
|
||||||
|
android:pointerShape="help" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/pointer_shape_view_wait"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pointer_shape_wait"
|
||||||
|
android:pointerShape="wait" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/pointer_shape_view_cell"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pointer_shape_cell"
|
||||||
|
android:pointerShape="cell" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/pointer_shape_view_crosshair"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pointer_shape_crosshair"
|
||||||
|
android:pointerShape="crosshair" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/pointer_shape_view_text"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pointer_shape_text"
|
||||||
|
android:pointerShape="text" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/pointer_shape_view_vertical_text"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pointer_shape_vertical_text"
|
||||||
|
android:pointerShape="vertical_text" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/pointer_shape_view_alias"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pointer_shape_alias"
|
||||||
|
android:pointerShape="alias" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/pointer_shape_view_copy"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pointer_shape_copy"
|
||||||
|
android:pointerShape="copy" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/pointer_shape_view_no_drop"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pointer_shape_no_drop"
|
||||||
|
android:pointerShape="no_drop" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/pointer_shape_view_all_scroll"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pointer_shape_all_scroll"
|
||||||
|
android:pointerShape="all_scroll" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/pointer_shape_view_horizontal_double_arrow"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pointer_shape_horizontal_double_arrow"
|
||||||
|
android:pointerShape="horizontal_double_arrow" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/pointer_shape_view_vertical_double_arrow"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pointer_shape_vertical_double_arrow"
|
||||||
|
android:pointerShape="vertical_double_arrow" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/pointer_shape_view_top_right_diagonal_double_arrow"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pointer_shape_top_right_diagonal_double_arrow"
|
||||||
|
android:pointerShape="top_right_diagonal_double_arrow" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/pointer_shape_view_top_left_diagonal_double_arrow"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pointer_shape_top_left_diagonal_double_arrow"
|
||||||
|
android:pointerShape="top_left_diagonal_double_arrow" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/pointer_shape_view_zoom_in"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pointer_shape_zoom_in"
|
||||||
|
android:pointerShape="zoom_in" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/pointer_shape_view_zoom_out"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pointer_shape_zoom_out"
|
||||||
|
android:pointerShape="zoom_out" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/pointer_shape_view_grab"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pointer_shape_grab"
|
||||||
|
android:pointerShape="grab" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/pointer_shape_view_grabbing"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pointer_shape_grabbing"
|
||||||
|
android:pointerShape="grabbing" />
|
||||||
|
|
||||||
|
<Button
|
||||||
|
android:id="@+id/pointer_shape_view_none"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pointer_shape_none"
|
||||||
|
android:pointerShape="none" />
|
||||||
|
|
||||||
|
<com.example.android.apis.view.StaticPointerIconButton
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pointer_shape_custom_static" />
|
||||||
|
|
||||||
|
<com.example.android.apis.view.ResourcePointerIconButton
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pointer_shape_custom_resource" />
|
||||||
|
|
||||||
|
<com.example.android.apis.view.SystemPointerIconButton
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pointer_shape_custom_system" />
|
||||||
|
|
||||||
|
<com.example.android.apis.view.LivePointerIconButton
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:text="@string/pointer_shape_custom_live" />
|
||||||
|
|
||||||
|
</GridLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</ScrollView>
|
||||||
@@ -1084,6 +1084,33 @@
|
|||||||
<string name="hover_intercept_message_initial">Try hovering over the button.</string>
|
<string name="hover_intercept_message_initial">Try hovering over the button.</string>
|
||||||
<string name="hover_intercept_message_intercepted">Intercepted hover event instead of sending it to the button. Om nom nom!</string>
|
<string name="hover_intercept_message_intercepted">Intercepted hover event instead of sending it to the button. Om nom nom!</string>
|
||||||
<string name="hover_button">Hover Here</string>
|
<string name="hover_button">Hover Here</string>
|
||||||
|
<string name="pointer_shape_description">The following demo is meaningful only with mouse. This does not have any effects on the touch screens.</string>
|
||||||
|
<string name="pointer_shape_arrow">arrow</string>
|
||||||
|
<string name="pointer_shape_context_menu">context menu</string>
|
||||||
|
<string name="pointer_shape_hand">hand</string>
|
||||||
|
<string name="pointer_shape_help">help</string>
|
||||||
|
<string name="pointer_shape_wait">wait</string>
|
||||||
|
<string name="pointer_shape_cell">cell</string>
|
||||||
|
<string name="pointer_shape_crosshair">crosshair</string>
|
||||||
|
<string name="pointer_shape_text">text (I-beam)</string>
|
||||||
|
<string name="pointer_shape_vertical_text">vertical text</string>
|
||||||
|
<string name="pointer_shape_alias">alias</string>
|
||||||
|
<string name="pointer_shape_copy">copy</string>
|
||||||
|
<string name="pointer_shape_no_drop">no drop</string>
|
||||||
|
<string name="pointer_shape_all_scroll">all scroll</string>
|
||||||
|
<string name="pointer_shape_horizontal_double_arrow">horizontal double arrow</string>
|
||||||
|
<string name="pointer_shape_vertical_double_arrow">vertical double arrow</string>
|
||||||
|
<string name="pointer_shape_top_right_diagonal_double_arrow">top right diagonal double arrow</string>
|
||||||
|
<string name="pointer_shape_top_left_diagonal_double_arrow">top left diagonal double arrow</string>
|
||||||
|
<string name="pointer_shape_zoom_in">zoom in</string>
|
||||||
|
<string name="pointer_shape_zoom_out">zoom out</string>
|
||||||
|
<string name="pointer_shape_grab">grab</string>
|
||||||
|
<string name="pointer_shape_grabbing">grabbing</string>
|
||||||
|
<string name="pointer_shape_none">none (invisible)</string>
|
||||||
|
<string name="pointer_shape_custom_static">Custom (static)</string>
|
||||||
|
<string name="pointer_shape_custom_resource">Custom (resource icon)</string>
|
||||||
|
<string name="pointer_shape_custom_system">Custom (system icons)</string>
|
||||||
|
<string name="pointer_shape_custom_live">Custom (live)</string>
|
||||||
|
|
||||||
<!-- ============================== -->
|
<!-- ============================== -->
|
||||||
<!-- GoogleLogin examples strings -->
|
<!-- GoogleLogin examples strings -->
|
||||||
|
|||||||
@@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 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.example.android.apis.view;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.util.Log;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.view.PointerIcon;
|
||||||
|
import android.widget.Button;
|
||||||
|
|
||||||
|
public class LivePointerIconButton extends Button {
|
||||||
|
public LivePointerIconButton(Context context) {
|
||||||
|
this(context, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LivePointerIconButton(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LivePointerIconButton(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LivePointerIconButton(Context context, AttributeSet attrs,
|
||||||
|
int defStyleAttr, int defStyleRes) {
|
||||||
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PointerIcon getPointerIcon(MotionEvent event, float x, float y) {
|
||||||
|
int cursorSize = getHeight();
|
||||||
|
|
||||||
|
Bitmap bitmap = Bitmap.createBitmap(cursorSize, cursorSize, Bitmap.Config.ARGB_8888);
|
||||||
|
Canvas canvas = new Canvas(bitmap);
|
||||||
|
|
||||||
|
Paint paint = new Paint();
|
||||||
|
paint.setARGB(255, 255, 255, 255);
|
||||||
|
paint.setStyle(Paint.Style.STROKE);
|
||||||
|
final int strokeWidth = 4;
|
||||||
|
paint.setStrokeWidth(strokeWidth);
|
||||||
|
|
||||||
|
// Draw a large circle filling the bitmap.
|
||||||
|
final int outerCenterX = cursorSize / 2;
|
||||||
|
final int outerCenterY = cursorSize / 2;
|
||||||
|
final int outerRadius = cursorSize / 2 - strokeWidth;
|
||||||
|
canvas.drawCircle(outerCenterX, outerCenterY, outerRadius, paint);
|
||||||
|
|
||||||
|
// Compute relative offset of the mouse pointer from the view center.
|
||||||
|
// It should be between -0.5 and 0.5.
|
||||||
|
final float relativeX = (x / getWidth()) - 0.5f;
|
||||||
|
final float relativeY = (y / getHeight()) - 0.5f;
|
||||||
|
|
||||||
|
// Draw a smaller circle inside the large circle, offset towards the center of the view.
|
||||||
|
final int innerCenterX = (int) (cursorSize * (1 - relativeX) / 2);
|
||||||
|
final int innerCenterY = (int) (cursorSize * (1 - relativeY) / 2);
|
||||||
|
final int innerRadius = cursorSize / 6;
|
||||||
|
if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
||||||
|
// Fill the inner circle if the mouse button is down.
|
||||||
|
paint.setStyle(Paint.Style.FILL);
|
||||||
|
}
|
||||||
|
canvas.drawCircle(innerCenterX, innerCenterY, innerRadius, paint);
|
||||||
|
|
||||||
|
final int hotSpotX = bitmap.getWidth() / 2;
|
||||||
|
final int hotSpotY = bitmap.getHeight() / 2;
|
||||||
|
return PointerIcon.createCustomIcon(bitmap, hotSpotX, hotSpotY);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 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.example.android.apis.view;
|
||||||
|
|
||||||
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A gallery of the different styles of buttons.
|
||||||
|
*/
|
||||||
|
public class PointerShapes extends Activity {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.pointer_shapes);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 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.example.android.apis.view;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.view.PointerIcon;
|
||||||
|
import android.widget.Button;
|
||||||
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
|
public class ResourcePointerIconButton extends Button {
|
||||||
|
private PointerIcon mCustomIcon;
|
||||||
|
|
||||||
|
public ResourcePointerIconButton(Context context) {
|
||||||
|
this(context, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResourcePointerIconButton(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResourcePointerIconButton(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ResourcePointerIconButton(Context context, AttributeSet attrs,
|
||||||
|
int defStyleAttr, int defStyleRes) {
|
||||||
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PointerIcon getPointerIcon(MotionEvent event, float x, float y) {
|
||||||
|
if (mCustomIcon == null) {
|
||||||
|
mCustomIcon = PointerIcon.loadCustomIcon(getResources(), R.drawable.custom_pointer_icon);
|
||||||
|
}
|
||||||
|
return mCustomIcon;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 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.example.android.apis.view;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.view.PointerIcon;
|
||||||
|
import android.widget.Button;
|
||||||
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
|
public class StaticPointerIconButton extends Button {
|
||||||
|
PointerIcon mCustomIcon;
|
||||||
|
|
||||||
|
public StaticPointerIconButton(Context context) {
|
||||||
|
this(context, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StaticPointerIconButton(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StaticPointerIconButton(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public StaticPointerIconButton(Context context, AttributeSet attrs,
|
||||||
|
int defStyleAttr, int defStyleRes) {
|
||||||
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PointerIcon getPointerIcon(MotionEvent event, float x, float y) {
|
||||||
|
if (mCustomIcon == null) {
|
||||||
|
Drawable d = getContext().getDrawable(R.drawable.smile);
|
||||||
|
final BitmapDrawable bitmapDrawable = (BitmapDrawable) d;
|
||||||
|
final int hotSpotX = d.getIntrinsicWidth() / 2;
|
||||||
|
final int hotSpotY = d.getIntrinsicHeight() / 2;
|
||||||
|
mCustomIcon = PointerIcon.createCustomIcon(
|
||||||
|
bitmapDrawable.getBitmap(), hotSpotX, hotSpotY);
|
||||||
|
}
|
||||||
|
return mCustomIcon;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2016 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.example.android.apis.view;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.AttributeSet;
|
||||||
|
import android.view.MotionEvent;
|
||||||
|
import android.view.PointerIcon;
|
||||||
|
import android.widget.Button;
|
||||||
|
|
||||||
|
public class SystemPointerIconButton extends Button {
|
||||||
|
|
||||||
|
public SystemPointerIconButton(Context context) {
|
||||||
|
this(context, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SystemPointerIconButton(Context context, AttributeSet attrs) {
|
||||||
|
super(context, attrs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SystemPointerIconButton(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
|
super(context, attrs, defStyleAttr);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SystemPointerIconButton(Context context, AttributeSet attrs,
|
||||||
|
int defStyleAttr, int defStyleRes) {
|
||||||
|
super(context, attrs, defStyleAttr, defStyleRes);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PointerIcon getPointerIcon(MotionEvent event, float x, float y) {
|
||||||
|
final int minX = getWidth() / 4;
|
||||||
|
final int maxX = getWidth() - minX;
|
||||||
|
final int minY = getHeight() / 4;
|
||||||
|
final int maxY = getHeight() - minY;
|
||||||
|
int style;
|
||||||
|
if ((x < minX && y < minY) || (x > maxX && y > maxY)) {
|
||||||
|
// Top/left or bottom/right corner.
|
||||||
|
style = PointerIcon.STYLE_TOP_LEFT_DIAGONAL_DOUBLE_ARROW;
|
||||||
|
} else if ((x < minX && y > maxY) || (x > maxX && y < minY)) {
|
||||||
|
// Top/rightor bottom/left corner.
|
||||||
|
style = PointerIcon.STYLE_TOP_RIGHT_DIAGONAL_DOUBLE_ARROW;
|
||||||
|
} else if (x < minX || x > maxX) {
|
||||||
|
// Left or right edge.
|
||||||
|
style = PointerIcon.STYLE_HORIZONTAL_DOUBLE_ARROW;
|
||||||
|
} else if (y < minY || y > maxY) {
|
||||||
|
// Top or bottom edge edge.
|
||||||
|
style = PointerIcon.STYLE_VERTICAL_DOUBLE_ARROW;
|
||||||
|
} else {
|
||||||
|
// Everything else (the middle).
|
||||||
|
style = PointerIcon.STYLE_ALL_SCROLL;
|
||||||
|
}
|
||||||
|
return PointerIcon.getSystemIcon(getContext(), style);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user