[F/OS] 🍓 ContextMenu - Context Menus For Your Components

:computer: Introduction

A non-visible extension to show context menus for your components. A context menu is a popup containing features to autofill, copy, paste, cut, etc.

Note that I have no guarantee that the context menu will 100% show. The best way is to set the component selectable, then show the context menu. Even Google is aware of this, so the TextView.showContextMenu function is not void, but boolean.

:date: Release date:

:clock9: Version: 1

:package: Package name: com.gordonlu.contextmenu

:hammer_and_wrench: Built with: Niotron IDE

:sandwich: Recommended Android version: Nougat 7.0

:open_book: Documentation

Event blocks

OnFinish

image

This event is fired when the action is completed. The isCustom parameter identifies whether the action is showing an advanced context menu, and the successful parameter is whether the action is successfully completed.

Parameters: isAdvanced = boolean, successful = boolean

Method blocks

SetSelectable

image

Sets the component's text selectable by the user.

Parameters: component = component

ShowAdvancedContextMenu

image

Shows the advanced context menu for this component and fires the OnFinish event for whether it is successful. What's different from ShowContextMenu is that you can specify the x and y position of the context menu. This function will require devices with Android versions larger or 7.0.

Parameters: component = component, x = number (float), y = number (float)

ShowContextMenu

image

Shows a simple context menu for the given component.

Parameters: component = component

:bookmark_tabs: What does a context menu look like?

These are screenshots of sample context menus. Order: Classic, Device Default, Dark.

If you want a custom context menu, use the DaffyMenu extension to build your own.

:lock: Open Source

Here you go.

package com.gordonlu.contextmenu;

import android.app.Activity;
import android.content.Context;
import com.google.appinventor.components.annotations.*;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.EventDispatcher;

import com.google.appinventor.components.runtime.AndroidViewComponent;
import android.widget.TextView;
import android.view.View;

import androidx.annotation.RequiresApi;

@DesignerComponent(
        version = 1,
        description = "A non-visible extension to show the context menu of your components.<br><br>Made by Gordon Lu (AICODE).",
        category = ComponentCategory.EXTENSION,
        nonVisible = true,
        iconName = "https://docs.google.com/drawings/d/e/2PACX-1vQCI87PHLBF0jb8QWyYmIRQSjjNW3EFXf-qpsWCvBYkUQ9vEgPAB8SpxcMpblxNpbIYrjCjLrRLIU2c/pub?w=16&h=16")

@SimpleObject(external = true)
//Libraries
@UsesLibraries(libraries = "")
//Permissions
@UsesPermissions(permissionNames = "")

public class ContextMenu extends AndroidNonvisibleComponent {

    //Activity and Context
    private Context context;
    private Activity activity;

    public ContextMenu(ComponentContainer container){
        super(container.$form());
        this.activity = container.$context();
        this.context = container.$context();
    }

    @SimpleFunction(description = "Shows the context menu for this component and fires the OnFinish event for whether it is successful.")
    public void ShowContextMenu (AndroidViewComponent component) {
        View view = component.getView();
        TextView tv = (TextView) view;
        boolean test = tv.showContextMenu();
        OnFinish(false, test);
    }

    @RequiresApi(api = 24)
    @SimpleFunction(description = "Shows the advanced context menu for this component and fires the OnFinish event for whether it is successful." + 
    " What's different from ShowContextMenu is that you can specify the x and y position of the context menu. This function will require devices with Android" + 
    " versions larger or 7.0.")
    public void ShowAdvancedContextMenu (AndroidViewComponent component, float x, float y) {
        View view = component.getView();
        TextView tv = (TextView) view;
        boolean test = tv.showContextMenu(x, y);
        OnFinish(true, test);
    }

    @SimpleEvent(description = "This event is fired when the action is completed. The isAdvanced parameter identifies whether the action is"
    + " showing an advanced context menu, and the successful parameter is whether the action is successfully completed.")
    public void OnFinish(boolean isAdvanced, boolean successful) {
        EventDispatcher.dispatchEvent(this, "OnFinish", isAdvanced, successful);
    }

    @SimpleFunction(description = "Sets the component's text selectable by the user.")
    public void SetSelectable(AndroidViewComponent component) {
        View view = component.getView();
        TextView tv = (TextView) view;
        tv.setTextIsSelectable(true);
    }
}

:inbox_tray: Downloads

AIX:
com.gordonlu.contextmenu.aix (7.5 KB)


Made with Niotron IDE.

Kindly :email: PM me if you have any questions! Also, if you like my extension, please :heart: like it! It takes some effort for me to make it...

Likes tell me the general user feedback of my extension. If you read this extension, please take 20 seconds to drop by and give a like!

If you have any features that you want to add and you know the code, PM me or directly reply below using the image button.

If you find any :lady_beetle: bugs, please reply below.

Feature requests?

I currently have a lot of work to do, because I am currently working on 4 different extensions and I have problems in real life (i.e. English debate competition). If you have feature requests, please consider whether this is important, because I do not have a lot of time, but I may hang out in the community.


Gordon Lu

:speech_balloon: Message :earth_africa: Website :e-mail: E-mail

5 Likes