venerdì 31 marzo 2017

Immagini PNG e iOS

Il sistema di sviluppo per creare app per iOS, chiamato da Apple XCode, quando incontra un'immagine PNG, la compatta rendendola illegibile per molti programmi.
Per farle tornare normali bisogna usare il comando:
xcrun -sdk iphoneos pngcrush -revert-iphone-optimizations -q compresso.png nonCompresso.png

Ma come farlo dentro la APP?
Ecco il codice:
on mouseUp
   -- CHECK FOR EXISTENCE OF PNGCRUSH UTILITY
   put "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/pngcrush" into crushPath
   if there is not a file crushPath then
      answer error "Unable to locate pngcrush tool. Check location of xCode."
      exit mouseUp
   end if
   -- APPEND THE SHELL COMMAND PARAMETERSTO THE PNGCRUSH PATH
   put crushPath && "-revert-iphone-optimizations -q source.png destination.png" into theCommand
   -- ESTABLISH SOURCE AND DESTINATION FOLDERS
   put directory into D -- store the current directory
   answer folder "Locate folder containing PNG files:"
   if the result is "Cancel" then exit mouseUp
   put it into theSourceFolder
   set directory to theSourceFolder
   put the files into theList
   set directory to D -- restore the directory
   answer folder "Choose output folder:"
   if the result is "Cancel" then exit mouseUp
   put it into theDestinationFolder
   -- PROCESS FILES
   put 0 into theCount
   repeat for each line theFile in theList
      put theCommand into newCommand
      if char -4 to -1 of theFile is not ".png" then next repeat -- ignore non-PNG files
      put q(theSourceFolder & "/" & theFile) into theSourceFile
      put q(theDestinationFolder & "/" & theFile) into theDestinationFile
      replace "source.png" with theSourceFile in newCommand
      replace "destination.png" with theDestinationFile in newCommand
      get shell(newCommand)
      wait 20 millisecs with messages
      add 1 to theCount
      put theCount -- show processed file count in message box
   end repeat
   answer "PNGs have been fixed!"
end mouseUp

function q pString
   return quote & pString & quote
end q

lunedì 27 marzo 2017

Markdown

Oggi vediamo cosa fa la funzione mergMarkdownToXHTML(). In pratica prende un testo formattato MarkDown e lo converte in HTML.
Ad esempio il testo MarkDown:

An h1 header
============

Paragraphs are separated by a blank line.

2nd paragraph. *Italic*, **bold**, and `monospace`. Itemized lists
look like:

 * this one
 * that one
 * the other one


diventa:

<h1>An h1 header</h1>
 
 <p>Paragraphs are separated by a blank line.</p>
 
 <p>2nd paragraph. <em>Italic</em>, <strong>bold</strong>, and <code>monospace</code>. Itemized lists
 look like:</p>
 
 <ul>
 <li>this one</li>
 <li>that one</li>
 <li>the other one</li>
 </ul>

venerdì 24 marzo 2017

blur

Un nuovo comando è disponibile in livecode: blur.
Questo comando può sfocare un'immagine, ad esempio il seguente codice:

put the imageData of image 1 into theOriginalImageData
blur 5,"theOriginalImageData",the width of image 1,the height of image 1,"theNewImageData"
set the imageData of image 2 to theNewImageData


potete sfocare un'immagine così:

martedì 21 marzo 2017

Creare un lettore di codice QR (QR reader)

Il sito http://goqr.me/api/doc/read-qr-code/ vi permette di leggere o generare codici QR, basta inviare i dati al loro sito e lor si occupano dell'elaborazione della risposta.
Allora ho creato il seguente programma per vedere se funziona:
postimage
confermo che funziona. Potete scaricarlo da qui.
Il codice sorgente è questo:
on mouseUp
   put empty into tForm
   put "http://api.qrserver.com/v1/read-qr-code/" into tUrl
   put the filename of image 1 into tFile   
   put "<file>" & tFile into tFile
   if libURLMultipartFormData(tForm, "name","file","type","file", "file", tFile) is not empty then
      answer it ##error
   else
      set the httpHeaders to line 1 of tForm
      post line 2 to -1 of tForm to url tUrl
      put it into field "rawdata"
      ## check the result, etc., here
      set the httpHeaders to empty
      put jsonimport(the text of field "rawdata") into temp
      put temp[1]["symbol"][1]["data"] into field "text1"
   end if
end mouseUp

Vediamo come funziona: l'immagine deve essere spedita ad una pagina web. Il creatore della pagina web vuole ricevere via POST:
  • una variabile chiamata name, che contenga la parola file
  • una variabile chiamata type, che contenga la parola file
  • il file dell'immagine
Per fare questo dobbiamo usale il comando  libURLMultipartFormData, fatto ciò la risposta è un testo in formato JSON che trasformiamo in un array e prendiamo solo il testo.

mercoledì 15 marzo 2017

Tabelle

Scott Rossi ha creato un esempio di come sia possibile usare le normali tabelle invece dei datagrid. Questo esempio lo potete usare o digitando:

go url "http://tactilemedia.com/blog/tablelab1"

oppure scaricarlo da questo link  https://mega.nz/#!BJpRWLRB!jBdMghOOf2QeEFpGHXaOYGyEGG4Ew6tcZk1_e3xTjsc

venerdì 10 marzo 2017

Livecode 9 dp6

E' uscita una nuova versione di livecode la 9 dp6.
La novità più importante è che ora potete importare funzioni o classi Java dentro livecode, in questo modo se c'è qualcosa scritto in Java che vorreste usare in livecode, ora potete. Il sistema per sfruttarle è creare un widget che le integri al suo interno. Vi consiglio di leggere:

mercoledì 8 marzo 2017

Safe boating app

Oggi presentiamo un'app realizzata in pochi mesi: Safe boating disponibule per iOS e Android.
Potete scaricarla da qui per Android:
https://play.google.com/store/apps/details?id=com.rcmsar.safeboating&hl=en
Si tratta di un programma per pianificare in sicurezza viaggin in nave vicino alle coste del Canada, con link, previsione del tempo e condizioni per la pesca.
E' stata realizzata da Adam Hyde membro della Royal Canadian Marine Search and Rescue.
Il Sig. Hyde non era un programmatore prima di conoscere liveocde, ma in pochi mesi.
Ecco alcune immagini: