Skip to main content
Samsung Developer Program

Integrating PointerIcon

PointerIcon enables your app to display a custom design as the S-Pen pointer icon when your users hover their S-Pen close above viewports. Your app can display a more intuitive or specialized icon, for example, an icon that indicates an activity, a region of your app's UI, or the status of the S-Pen by changing the design, shape and/or color of the icon.

SPen_UI_PI_Default_Custom_Icon.png

Note: The display of default and custom S-Pen pointer icons is controlled by device configuration ( Settings > (Motion) S-Pen > Pointer On / Off).

For details about the PointerIcon API, see PointerIcon API Structure.

Controlling the S-Pen Pointer Hover Icon

Your app can display a custom S-Pen pointer hover icon defined in a drawable class object or the default icon when the user hovers the S-Pen over a specific view.

To control the S-Pen pointer hover icon in a view:

  1. Create an SlookPointerIcon instance.
  2. To display a custom pointer icon, call setHoverIcon(), specify the view and the custom icon image object.
  3. To display the default pointer icon, call setHoverIcon(), specify the view and the second image parameter as null.

Example Code: Displaying a Custom S-Pen Pointer Hover Icon in a View

public class MainActivity extends Activity { 

    /* Create a PointerIcon instance */ 
    private SlookPointerIcon mPointerIcon = new SlookPointerIcon();

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
    ...

        /* Set a custom pointer hover icon to be used. */ 
        mPointerIcon.setHoverIcon(mHoverTextView, getResources() 
            .getDrawable(R.drawable.ic_launcher)); 
    } 
}

Example Code: Displaying the Default S-Pen Pointer Hover Icon in a View

public class MainActivity extends Activity { 

    private SlookPointerIcon mPointerIcon = new SlookPointerIcon();

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
    ...

        /*  Set the default pointer hover icon to be used. */
        mPointerIcon.setHoverIcon(mHoverTextView, null); 
    } 
}

Example Code: Controlling the Display of the S-Pen Pointer Hover Icon via UI Buttons

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>

<Button
android:id="@+id/btn_changeicon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Turn off"
/>

<TextView
android:id="@+id/text_hoverarea"
android:layout_width="match_parent"
android:layout_height="100dip"
android:layout_gravity="center_horizontal"
android:background="#FFDDDDDD"
android:text="Please hover the pen"
/>

</LinearLayout>

package com.example.pointericon; 

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.widget.Button; 
import android.widget.TextView; 

import com.samsung.android.sdk.look.SlookPointerIcon; 

public class MainActivity extends Activity {

private boolean mIsDefault = false; 

private TextView mHoverTextView; 

private SlookPointerIcon mPointerIcon = new SlookPointerIcon(); 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 

    setContentView(R.layout.activity_main); 

    Button changeIcon = (Button) findViewById(R.id.btn_changeicon); 

    mHoverTextView = (TextView) findViewById(R.id.text_hoverarea); 
    mPointerIcon.setHoverIcon(mHoverTextView, getResources() 
        .getDrawable(R.drawable.ic_launcher)); 
    changeIcon.setOnClickListener(new View.OnClickListener() { 

        public void onClick(View v) { 
            if (mIsDefault) { 
                mPointerIcon.setHoverIcon(mHoverTextView, 
                    getResources() 
                        .getDrawable(R.drawable.ic_launcher)); 
                mIsDefault = false; 
                ((Button) v).setText("Turn off"); 
            } else { 
                mPointerIcon.setHoverIcon(mHoverTextView, null); 
                mIsDefault = true; 
                ((Button) v).setText("Turn on"); 
            } 
        }
    });
}

 

  • Was this article helpful?