package com.Salvy; // Salvatore Oliva // Creazione prima estensione. Agosto 2020. // Questa estensione consente di recuperare il blocco di testo condiviso tramite il menu Share di Android. import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.app.Activity; import com.google.appinventor.components.annotations.DesignerComponent; import com.google.appinventor.components.annotations.DesignerProperty; import com.google.appinventor.components.annotations.PropertyCategory; import com.google.appinventor.components.annotations.SimpleEvent; import com.google.appinventor.components.annotations.SimpleFunction; import com.google.appinventor.components.annotations.SimpleObject; import com.google.appinventor.components.annotations.SimpleProperty; import com.google.appinventor.components.common.ComponentCategory; import com.google.appinventor.components.common.PropertyTypeConstants; import com.google.appinventor.components.runtime.util.MediaUtil; import com.google.appinventor.components.runtime.*; @DesignerComponent(version = SalvyGetSharedText.VERSION, description = "Get Shared Block Text Extension.", category = ComponentCategory.EXTENSION, nonVisible = true, iconName = "") @SimpleObject(external = true) public class SalvyGetSharedText extends AndroidNonvisibleComponent implements Component { public static final int VERSION = 1; private ComponentContainer container; private String sharedText = null; public SalvyGetSharedText(ComponentContainer container) { super(container.$form()); this.container = container; sharedText = ""; } // Get the value of shared text block. @SimpleProperty(category = PropertyCategory.BEHAVIOR) public String GetSharedText() { return sharedText; } // Set shared text block to new value. @DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_STRING, defaultValue = "") @SimpleProperty(description = "Set shared text block to new value.") public void SetSharedText(String newValue) { this.sharedText = newValue; } /* Manifest file update: ... */ // Function to catch text block that has been shared. @SimpleFunction(description = "Catch text block that has been shared.") public String CatchSharedTextBlock() { // Get intent, action and MIME type Intent intent = getIntent(); String action = intent.getAction(); String type = intent.getType(); String caughtText = null; if (Intent.ACTION_SEND.equals(action) && type != null) { if ("text/plain".equals(type)) { // Handle text being sent caughtText = intent.getStringExtra(Intent.EXTRA_TEXT); } } SharedTextBlockCaught(caughtText); return caughtText; } // Event block to set available shared text block after it has been caught. @SimpleEvent(description = "Set available shared text block after it has been caught.") public void SharedTextBlockCaught(String caughtSharedText) { this.sharedText = caughtSharedText; EventDispatcher.dispatchEvent(this, "SharedTextCaught", caughtSharedText); } }