Xamarin Forms: Tap and Double Tap - xamarin.forms

I am looking at Xamarin Forms capabilities for handling screen interaction at the highest level possible - ideally 1 set of code for both iOS and Andoid. I created a new XF app (Multiplatform -> App in F#, no XAML) and I added this to the default template:
type App() =
inherit Application()
let stack = StackLayout(VerticalOptions = LayoutOptions.Center)
let label = Label(XAlign = TextAlignment.Center, Text = "Welcome to F# Xamarin.Forms!")
do
let tapRecognizer = new TapGestureRecognizer()
let handleTapEvent (sender:Object) (args:EventArgs) =
label.Text <- "Tapped at " + DateTime.Now.ToString()
()
let tapEventHandler = new EventHandler(handleTapEvent)
tapRecognizer.Tapped.AddHandler(tapEventHandler)
label.GestureRecognizers.Add(tapRecognizer)
let doubleTapRecognizer = new TapGestureRecognizer()
doubleTapRecognizer.NumberOfTapsRequired <- 2
let handleDoubleTapEvent (sender:Object) (args:EventArgs) =
label.Text <- "Double Tapped at " + DateTime.Now.ToString()
()
let doubleTapEventHandler = new EventHandler(handleDoubleTapEvent)
doubleTapRecognizer.Tapped.AddHandler(doubleTapEventHandler)
label.GestureRecognizers.Add(doubleTapRecognizer)
stack.Children.Add(label)
base.MainPage <- ContentPage(Content = stack)
The problem is that the tap still happens as part of the double tap. Is there a way to recognize a tap or a double tap (versus tap and double tap)?
Thanks in advance

Related

How to solve CollectionViewcell image animation images issue?

I have set an animated image in CollectionView cell but I
didSelectItemAt method call but how can solve animated image this hide
issue please see this video URL.
let data:[UIImage] = images![indexPath.row] as! [UIImage]
cell.ivImage.animationImages = data
cell.ivImage.animationDuration = 1.0
cell.ivImage.startAnimating()
stickerCV.allowsSelection = false
Collection Cell
let tap = UITapGestureRecognizer(target: self, action: #selector(self.handleTap(_:)))
tap.accessibilityLabel = "\(indexPath.row),\(indexPath.section)"
tap.numberOfTapsRequired = 1
cell.ivSitcker.isUserInteractionEnabled = true
cell.ivSitcker.addGestureRecognizer(tap)
Tap Gesture
#objc func handleTap(_ sender: UITapGestureRecognizer) {
let data = sender.accessibilityLabel?.components(separatedBy: ",")
let index = Int(data![0])
let section = Int(data![1])
selectedIndex = index!
let sectionData = AppData.sharedInstance.arrOfStickers[selectedStickerIndex]
self.strSelectedSticker = sectionData[index!]
self.createSticker(image: self.strSelectedSticker[0])
self.selectedIndex = index!
self.stickerCV.reloadData()
}

HERE Map UI JS - How to add custom buttons to the Map UI?

I am trying to find guidance in the HERE JS documentation on how to add a custom button to the HERE JS 3.0 map UI we have.
The button is going to move the map to center on the customer's current location (we provide the location outside of HERE functionality and pass it in manually). However, this needs to be triggered by a button on the HERE map itself. But I can't figure out how to attach a button to the map (so far documentation is just about how to customize already existing UI buttons or how to add an info bubble):
https://developer.here.com/documentation/maps/dev_guide/topics/map-controls.html
Is this even possible? Help would be greatly appreciated!
The class H.ui.UI should help you get where you want to reach, and specifically the method addControl (name, control). and using the HERE UI kit makes it easy to craft the UI element (i.e. button) they way you wanted too.
I have written the following piece of code to help you achieve what you are looking for (I assume)
//#region add new UI element
inherits = function (childCtor, parentCtor) {
function tempCtor() { } tempCtor.prototype = parentCtor.prototype; childCtor.superClass_ = parentCtor.prototype; childCtor.prototype = new tempCtor(); childCtor.prototype.constructor = childCtor; childCtor.base = function (me, methodName, var_args) {
var args = new Array(arguments.length - 2);
for (var i = 2; i < arguments.length; i++) {
args[i - 2] = arguments[i];
}
return parentCtor.prototype[methodName].apply(me, args);
};
};
var customUI = function (opt_options) {
'use strict'; var options = opt_options || {};
H.ui.Control.call(this);
this.onButtonClick = this.onButtonClick.bind(this);
// create a button element
this.increaseBtn_ = new H.ui.base.Button({
'label': '<svg class="H_icon H_icon" viewBox="0 0 25 25">' +
'<path d="M 18.5,11 H 14 V 6.5 c 0,-.8 -.7,-1.5 -1.5,-1.5 -.8,0 -1.5,.7 -1.5,1.5 V 11 H 6' +
'.5 C 5.7,11 5,11.7 5,12.5 5,13.3 5.7,14 6.5,14 H 11 v 4.5 c 0,.8 .7,1.5 1.5,1.5 .8,0 1.5,' +
'-.7 1.5,-1.5 V 14 h 4.5 C 19.3,14 20,13.3 20,12.5 20,11.7 19.3,11 18.5,11 z" />' +
'</svg>',
'onStateChange': this.onButtonClick
});
//add the buttons as this control's children
this.addChild(this.increaseBtn_);
this.setAlignment(options['alignment'] || 'top-right');
this.options_ = options;
};
inherits(customUI, H.ui.Control);
customUI.prototype.onButtonClick = function (evt) {
'use strict'; if (evt.currentTarget.getState() === 'down') {
console.log('Hollla, I am the new custom UI element.');
}
};
var WaliedCheetos_CustomUI = new customUI();
ui.addControl('WaliedCheetos_CustomUI', WaliedCheetos_CustomUI);
//#endregion

Getting my buttons to add text to a list

I'm having a problem getting my buttons to actually do something, when one of the buttons on the top left are clicked, I want a text box in the frame below it adding the name of that button to a list but getting really stuck with it, any help would be much appreciated, thank you
Here is my code:
import tkinter
import tkinter as tk
root = tk.Tk()
root.geometry('1000x600')
var=tk.StringVar()
Frame1 = tk.Frame(root)
Frame1.configure(background='light blue',height='300',width='500')
Frame1.grid(sticky="nsew",row='0',column='0')
Frame2 = tk.Frame(root)
Frame2.configure(background='grey',height='300',width='500')
Frame2.grid(sticky="nsew",row='0',column='1')
Frame3 = tk.Frame(root)
Frame3.configure(background='grey',height='300',width='500')
Frame3.grid(sticky="nsew",row='1',column='0')
Frame4 = tk.Frame(root)
Frame4.configure(background='light blue',height='300',width='500')
Frame4.grid(sticky="nsew",row='1',column='1')
def PrintOrder():
LabelOrder = tk.Label(Frame3,text="DONUT ORDER")
LabelOrder.grid(row='0',column='0')
return
Button1 = tk.Button(Frame1,text="Apple Cinnamon",height='2',width='15',padx=10, pady=5,command=PrintOrder).grid(row='0',column='0')
Button2 = tk.Button(Frame1,text="Strawberry",height='2',width='15',padx=10, pady=5,command=PrintOrder).grid(row='0',column='2')
Button3 = tk.Button(Frame1,text="Custard",height='2',width='15',padx=10, pady=5,command=PrintOrder).grid(row='0',column='4')
Button4 = tk.Button(Frame1,text="Sugar Ring",height='2',width='15',padx=10, pady=5,command=PrintOrder).grid(row='2',column='0')
Button5 = tk.Button(Frame1,text="Chocolate Caramel",height='2',width='15',padx=10, pady=5,command=PrintOrder).grid(row='2',column='2')
Button6 = tk.Button(Frame1,text="Lemon Circle",height='2',width='15',padx=10, pady=5,command=PrintOrder).grid(row='2',column='4')
Button7 = tk.Button(Frame1,text="Blueberry Blaster",height='2',width='15',padx=10, pady=5,command=PrintOrder).grid(row='4',column='0')
Button8 = tk.Button(Frame1,text="Strawberry Surprise",height='2',width='15',padx=10, pady=5,command=PrintOrder).grid(row='4',column='2')
Button9 = tk.Button(Frame1,text="Simple Sugar",height='2',width='15',padx=10, pady=5,command=PrintOrder).grid(row='4',column='4')
Label1 = tk.Label(Frame2,text="Donut special 6 for the price of 5",height='5',width='30').grid(row='0',column='0')
Button10 = tk.Button(Frame2,text="SPECIAL",padx=5, pady=5,height='5',width='20').grid(row='2',column='0')
Button11 = tk.Button(Frame3,text="ORDER TOTAL",padx=5, pady=5,height='5',width='20').grid(row='2',column='0')
Button12 = tk.Button(Frame4,text="RUNNING TOTAL",padx=5, pady=5,height='5',width='20').grid(row='2',column='0')
root.mainloop()
The problem is that when you call the PrintOrder function, it doesn't necessarily know what button called it.
To fix this, use a lambda: [see http://effbot.org/zone/tkinter-callbacks.htm, "Passing Arguments to Callbacks"]
Also, you'll need variable strings to work with the list.
Above your PrintOrder function, write this (move the Label creation outside of the function):
LabelContents = tk.StringVar()
LabelOrder = tk.Label(Frame3, textvariable=LabelContents)
LabelOrder.grid(row='0', column='0')
then you can update the text in the label.
So change the PrintOrder function to
def PrintOrder(flavor):
LabelContents.set(LabelContents.get() + '\n' + flavor)
return
This appends the flavor, with a new line, to the label.
then in the button:
Button(text="lemon", command=lambda: PrintOrder("lemon"))
Of course you can modify to fit your program.
For the reasoning behind the lambda, see the link.
Hope that helps!

How to use superscripting in flex?

I want to add a label in flex to display m/s2 (read meters per second square). I would need to use superscripting for this.
I have tried out the following code which is giving me a compilation error.
var richtxt1:RichText = new RichText();
richtxt1.text="m/s";
var richtxt2:RichText = new RichText();
var span:SpanElement = new SpanElement();
span.text = "2";
span.baselineShift = "superscript";
richtxt2.addChild(span);
richtxt1.text=rixhtxt1.txt + richtxt2.text
I am getting a compilation error for the line richtxt2.addChild(span)
The error is
Implicit coercion of a value of type flashX.textLayout.elements.SpanElement
to unrelated type flash.Display.DisplayObject
I think you've to do something like this
var xmlText:String = "<TextFlow xmlns='http://ns.adobe.com/textLayout/2008'>" +
"m/s <span baselineShift='superscript'>2</span>" +
"</TextFlow>";
var txtFlow:TextFlow = TextFlowUtil.importFromXML(xmlText);
var richTxt:RichText = new RichText();
richtxt.textFlow = txtFlow;
I've not tested it so please excuse me of any compilation errors.
This is the code I used in my iPad app to accomplish the above:
var xmlText:String = "m/s <span baselineShift='superscript'>2</span>";
var txtFlow:TextFlow = TextFlowUtil.importFromString(xmlText);
var richTxt:RichText = new RichText();
richTxt.textFlow = txtFlow;
this.addElement(richTxt);
It is based on kaychaks and information I found from Adobe's website. The differences are
I took out the TextFlow markup but left in the HTML;
importFromString rather than importFromXML; and
I added this.addElement(richText) to display the element.

Scaling with BitmapData

I am working on an application that will allow a user to scale an image. The issue that I am having with the method below is that the scaling is always taking place on the previous scale point.
For example: If I scale the image up one and then scale the image down one. I have to scale down twice to get it back to the point I want it to be.
Any help with this is greatly appreciated.
Here is my current code:
private var sourceBMD:BitmapData = testImage.source as BitmapData
private var matrixScaleX:Number = 1;
private var matrixScaleY:Number = 1;
private var baseScaleX:Number = .05;
private var baseScaleY:Number = .05;
private function sourceZoom(zoomType:Boolean = false):void{
var matrix:Matrix = new Matrix();
var matriximage:BitmapData;
if(zoomType){
matrixScaleX = matrixScaleX + baseScaleX;
matrixScaleY = matrixScaleY + baseScaleY;
matrix.a = matrixScaleX;
matrix.d = matrixScaleY
}else{
matrixScaleX = matrixScaleX - baseScaleX;
matrixScaleY = matrixScaleY - baseScaleY;
matrix.a = matrixScaleX;
matrix.d = matrixScaleY;
}
matriximage = new BitmapData(sourceBMD.width, sourceBMD.height, false, 0x0000000);
trace('MatrixScaleX: ' + matrixScaleX);
trace('MatrixScaleY: ' + matrixScaleY);
trace('BaseScaleX: ' + baseScaleX);
trace('BaseScaleY: ' + baseScaleY);
trace('Matrix: ' + ObjectUtil.toString(matrix));
matriximage.draw(sourceBMD, matrix);
testImage.source = matriximage;
}
That looks fine, I'd suspect that the problem lies with your input or the place this is getting called.
In order for it to work, events need to happen like this in your code:
capture input -> scale image -> draw image.
Since you appear to be setting the image to draw at the end of this function, I would check that this function is being called after the input has finished processing.
Can you confirm that's what's happening?

Resources