Example usage for android.view PointerIcon getSystemIcon

List of usage examples for android.view PointerIcon getSystemIcon

Introduction

In this page you can find the example usage for android.view PointerIcon getSystemIcon.

Prototype

public static PointerIcon getSystemIcon(@NonNull Context context, int type) 

Source Link

Document

Gets a system pointer icon for the given type.

Usage

From source file:com.farmerbb.taskbar.adapter.StartMenuAdapter.java

@Override
public @NonNull View getView(int position, View convertView, final @NonNull ViewGroup parent) {
    // Check if an existing view is being reused, otherwise inflate the view
    if (convertView == null)
        convertView = LayoutInflater.from(getContext()).inflate(isGrid ? R.layout.row_alt : R.layout.row,
                parent, false);//ww  w .jav a2 s. com

    final AppEntry entry = getItem(position);
    assert entry != null;

    final SharedPreferences pref = U.getSharedPreferences(getContext());

    TextView textView = (TextView) convertView.findViewById(R.id.name);
    textView.setText(entry.getLabel());

    Intent intent = new Intent();
    intent.setComponent(ComponentName.unflattenFromString(entry.getComponentName()));
    ActivityInfo activityInfo = intent.resolveActivityInfo(getContext().getPackageManager(), 0);

    if (activityInfo != null)
        textView.setTypeface(null, isTopApp(activityInfo) ? Typeface.BOLD : Typeface.NORMAL);

    switch (pref.getString("theme", "light")) {
    case "light":
        textView.setTextColor(ContextCompat.getColor(getContext(), R.color.text_color));
        break;
    case "dark":
        textView.setTextColor(ContextCompat.getColor(getContext(), R.color.text_color_dark));
        break;
    }

    ImageView imageView = (ImageView) convertView.findViewById(R.id.icon);
    imageView.setImageDrawable(entry.getIcon(getContext()));

    LinearLayout layout = (LinearLayout) convertView.findViewById(R.id.entry);
    layout.setOnClickListener(view -> {
        LocalBroadcastManager.getInstance(getContext())
                .sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));
        U.launchApp(getContext(), entry.getPackageName(), entry.getComponentName(),
                entry.getUserId(getContext()), null, false, false);
    });

    layout.setOnLongClickListener(view -> {
        int[] location = new int[2];
        view.getLocationOnScreen(location);
        openContextMenu(entry, location);
        return true;
    });

    layout.setOnGenericMotionListener((view, motionEvent) -> {
        int action = motionEvent.getAction();

        if (action == MotionEvent.ACTION_BUTTON_PRESS
                && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
            int[] location = new int[2];
            view.getLocationOnScreen(location);
            openContextMenu(entry, location);
        }

        if (action == MotionEvent.ACTION_SCROLL && pref.getBoolean("visual_feedback", true))
            view.setBackgroundColor(0);

        return false;
    });

    if (pref.getBoolean("visual_feedback", true)) {
        layout.setOnHoverListener((v, event) -> {
            if (event.getAction() == MotionEvent.ACTION_HOVER_ENTER) {
                int backgroundTint = pref.getBoolean("transparent_start_menu", false)
                        ? U.getAccentColor(getContext())
                        : U.getBackgroundTint(getContext());

                //noinspection ResourceAsColor
                backgroundTint = ColorUtils.setAlphaComponent(backgroundTint, Color.alpha(backgroundTint) / 2);
                v.setBackgroundColor(backgroundTint);
            }

            if (event.getAction() == MotionEvent.ACTION_HOVER_EXIT)
                v.setBackgroundColor(0);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                v.setPointerIcon(PointerIcon.getSystemIcon(getContext(), PointerIcon.TYPE_DEFAULT));

            return false;
        });

        layout.setOnTouchListener((v, event) -> {
            v.setAlpha(
                    event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE
                            ? 0.5f
                            : 1);
            return false;
        });
    }

    return convertView;
}

From source file:com.farmerbb.taskbar.service.TaskbarService.java

private View getView(List<AppEntry> list, int position) {
    View convertView = View.inflate(this, R.layout.icon, null);

    final AppEntry entry = list.get(position);
    final SharedPreferences pref = U.getSharedPreferences(this);

    ImageView imageView = (ImageView) convertView.findViewById(R.id.icon);
    ImageView imageView2 = (ImageView) convertView.findViewById(R.id.shortcut_icon);
    imageView.setImageDrawable(entry.getIcon(this));
    imageView2.setBackgroundColor(/*from   w  w w  .ja  va  2  s  . c om*/
            pref.getInt("accent_color", getResources().getInteger(R.integer.translucent_white)));

    String taskbarPosition = U.getTaskbarPosition(this);
    if (pref.getBoolean("shortcut_icon", true)) {
        boolean shouldShowShortcutIcon;
        if (taskbarPosition.contains("vertical"))
            shouldShowShortcutIcon = position >= list.size() - numOfPinnedApps;
        else
            shouldShowShortcutIcon = position < numOfPinnedApps;

        if (shouldShowShortcutIcon)
            imageView2.setVisibility(View.VISIBLE);
    }

    if (taskbarPosition.equals("bottom_right") || taskbarPosition.equals("top_right")) {
        imageView.setRotationY(180);
        imageView2.setRotationY(180);
    }

    FrameLayout layout = (FrameLayout) convertView.findViewById(R.id.entry);
    layout.setOnClickListener(view -> U.launchApp(TaskbarService.this, entry.getPackageName(),
            entry.getComponentName(), entry.getUserId(TaskbarService.this), null, true, false));

    layout.setOnLongClickListener(view -> {
        int[] location = new int[2];
        view.getLocationOnScreen(location);
        openContextMenu(entry, location);
        return true;
    });

    layout.setOnGenericMotionListener((view, motionEvent) -> {
        int action = motionEvent.getAction();

        if (action == MotionEvent.ACTION_BUTTON_PRESS
                && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
            int[] location = new int[2];
            view.getLocationOnScreen(location);
            openContextMenu(entry, location);
        }

        if (action == MotionEvent.ACTION_SCROLL && pref.getBoolean("visual_feedback", true))
            view.setBackgroundColor(0);

        return false;
    });

    if (pref.getBoolean("visual_feedback", true)) {
        layout.setOnHoverListener((v, event) -> {
            if (event.getAction() == MotionEvent.ACTION_HOVER_ENTER) {
                int accentColor = U.getAccentColor(TaskbarService.this);
                accentColor = ColorUtils.setAlphaComponent(accentColor, Color.alpha(accentColor) / 2);
                v.setBackgroundColor(accentColor);
            }

            if (event.getAction() == MotionEvent.ACTION_HOVER_EXIT)
                v.setBackgroundColor(0);

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                v.setPointerIcon(PointerIcon.getSystemIcon(TaskbarService.this, PointerIcon.TYPE_DEFAULT));

            return false;
        });

        layout.setOnTouchListener((v, event) -> {
            v.setAlpha(
                    event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE
                            ? 0.5f
                            : 1);
            return false;
        });
    }

    return convertView;
}