RSS

HAC is now freeware

HyperNext Android Creator is now freeware and you can download the full version from our forums.

http://www.hypernextandroid.com/forum/index.php


 

The current version is v1.16 and next to its forum download links are the serial number and registration details. The next update will remove the requirement for these.

HAC v1.16 was tested from Android 1.6 to 4.1 and should still work on the latest 5.x.

https://en.wikipedia.org/wiki/Android_version_history
.
.
If you are new to developing apps for Android then these links might help you:-

How to: making android apps

Earning a living from android

Coding and no-coding app makers

HAC for presentation-type apps

HAC v1.11 runs on even more devices

HAC v1.12 with easy installer

How to: create and use an emulator avd

Android more reliable than Apple ios

HAC and the Kindle Fire

HAC v1.13 with Kindle Fire

How to: develop for the Kindle Fire

 
Leave a comment

Posted by on 01/10/2015 in HAC, Kindle, News, Updates

 

9 How To: RSS and News Feeds

RSS is a term that encompasses a number of web feed formats used in the publication of frequently updated works such as information on news-related sites, blogs, forum posts. Articles can contain both text and links to media such as images, movies etc.

What does RSS actually stand for? – there are several expansions of the term RSS such as Really Simple Syndication, Rich Site Summary etc. Here some descriptions of RSS:-

RSS Explained:-
http://www.whatisrss.com/

Wikipedia RSS
http://en.wikipedia.org/wiki/RSS

.
The most commonly used formats are RSS followed by Atom. HAC can process both these formats plus some custom formats as well. It can also process sources from either a URL or a text file. Usually the term RSS is generic and refers to RSS plus Atom and custom formats.
.
With HAC, users do not have to specify the format because HAC tries to be flexible and process as much of each article as possible. For each article it is asked to keep, it saves every field it can parse, and also saves their field names. This allows the programmer/user to decide which fields to use. Fields are created by HAC in the order in which they were found.

Apps handling news feeds need some protection because RSS feeds can potentially be huge and any attempt to download/process the entire feed could cause a memory exception in the app. Therefore HAC allows feeds to be interrogated for their size and has options to process a specified range of articles. For instance, if there were 1000 articles in the source, then the user might like to just look at articles in the range 100 to 150 without downloading/parsing the entire source.
.
.
Example Feeds
Here are some example feeds used in testing the HAC RSS example project.

Atom feed
http://blog.case.edu/news/feed.atom

HAC Forums RSS:-
http://www.tigabyte.com/forum/index.php?action=.xml;type=rss

BBC News Feed:-
http://feeds.bbci.co.uk/news/world/middle_east/rss.xml

Global Sport feed:-
http://globoesporte.globo.com/dynamo/futebol/times/vasco/rss2.xml
.
.
Reading Feeds
There are 3 steps in using RSS

  1. Get feed from URL or a file.
  2. Parse the feed for articles.
  3. Examine or display articles.

The format of articles is explained below.

.

Feeds and Articles

Feeds are comprised from a number of articles and each article can have several named fields although there can be more than one field with the same name. The situation can be more complex though as some sources use custom formats where fields have sub fields etc. Custom formats are more complex to parse and HAC RSS parsing currently doesn’t support them as its parser just looks for top level elements/fields.

The list below shows comparative field names for RSS and Atom although there is nothing to stop sources having their own unique field names:

.
.

EXAMPLE: Creating an RSS Reader

Here we will show you the scripts behind a basic RSS reader that can work with the formats: RSS, Atom and some custom ones. As mentioned above there are 3 stages to reading an RSS feed although HAC combines both the fetch and parse stages into one function. Note, for clarity, it does not show any error checking.

a) Open and Parse Feed

To parse an RSS source use the RssParseSourceFN function. This function returns a count of the number of articles found although if an error occurred it returns -1. It automatically stores any retrieved articles and their field names so later they can be processed or displayed. Note, for app safety, a maximum article limit must be specified so for instance if the feed contained a million articles then your app could limit itself to just 100 articles. There is also a start value that enables a number of articles to be skipped.

The code below shows how to parse an RSS feed:-

@ --- Reads BBC news source ---
Local mode,source,start,max

@ read from URL so set mode = 2 (=1 for file)
PUT 2 INTO mode

@ Set URL
PUT 'http://feeds.bbci.co.uk/news/world/middle_east/rss.xml' INTO source

@ Set limits
PUT 1 INTO start
PUT 100 INTO max

@ Retrieve and parse source
PUT RssParseSourceFN(mode,source,start,max) INTO field 1

@ Display article count found
PUT RssArticleCountFN INTO field 2

.
It you just want to count how many articles are in the source then use the RssParseCountFN function. This parses the source but does not store any articles. Again, for safety it requires the maximum number of articles to parse. The example below shows how to do this.

@ --- Reads BBC news source ---
Local mode,source,max

@ read from URL so set mode = 2 (=1 for file)
PUT 2 INTO mode

@ Set URL
PUT 'http://feeds.bbci.co.uk/news/world/middle_east/rss.xml' INTO source

@ Set limits
PUT 10000 INTO max

@ Parse and count source
PUT RssParseCountFN(mode,source,max) INTO field 1

.

b) Accessing Retrieved Articles

Once the articles are retrieved to memory then they can be processed and displayed. The RssArticleCountFN returns the number of articles previously retrieved and can be used to loop over the articles.

Each article has a number of named fields such as AUTHOR, CATEGORY, DESCRIPTION etc. There is no restriction though on uniqueness of the field names so for example an article might have several fields named DESCRIPTION. Furthermore, articles within the same feed can have different numbers of fields and different field names. The number of field names and a list of their names can be retrieved using the functions RssFieldCountFN and RssFieldNamesFN respectively. Note, all field names are forced to uppercase. There is also a function called RssFieldListFN that returns in list form the name of every field found in the source.
.
The script below shows how to retrieve the contents of a known named field called DESCRIPTION from article number 5.

@ --- Display DESCRIPTION field of article 5 ---

PUT RssFieldByNameFN(5,'DESCRIPTION') INTO field 1

.
.

The script below shows how to loop over all of the fields in article 5.

@ --- Displays article 5 ---
Local aid,count,f

@ set article number
PUT 5 INTO aid

@ how many fields
PUT RssFieldCountFN(aid) INTO count

@ Loop over all fields and place into text field 1
Clear field 1
FOR f=1 TO count
   PUT RssFieldByNumberFN(aid,f) AFTER field 1
ENDFOR

.
.
c) Tidying Up

Once you have finished using the retrieved articles it is a good idea to clean up and free the memory they occupied, especially if hundreds or more articles were retrieved. The RssClear command frees memory used for storing all article headers, fields and articles themselves.

@ --- Clear memory used by RSS ---

RssClear

.
.

.
Summary
This article shows how to create a very simple RSS reader using HAC and briefly looks at a few of its RSS commands/functions. For more details see the project link below.

With HAC an RSS app can:

  1. Read RSS, Atom and some custom formats.
  2. Read from either a URL feed or a text file.
  3. Limit the number of articles parsed
  4. Skip articles and retrieve just a range.

For more information about creating RSS apps with HAC, look at HAC’s built-in help or its HAC Help pdf.

There is an RSS project and its built app on our examples web page http://www.hypernextandroid.com/hnfiles/rescreator.html The project example is only test bed that demonstrates HAC’s RSS functionality.

.

Members of HAC forums can download the latest trial version of HAC, see details here:- http://www.hypernextandroid.com/hnfiles/downloads.html

 

HAC v1.16 with RSS news reading

HAC v1.16 released for Windows (2nd November 2012 )

This update adds parsing of News Feeds(RSS), transparent fields plus better debugging during HAC startup. There are also some memory usage improvements and some minor bug fixes.

The News Feed functionality supports both RSS and Atom formats. It also allows feeds from both URLs and files to be parsed. It can cope with huge feeds and allows the user to skip unwanted articles and just store the sequence they need.

The HAC startup debugging makes it much easier for users with installation problems to find out where the problem is.

For further details see the release notes accompanying HAC and the posts listed in our forums.

HAC apps can run on Android OS API 1.6 up to the latest 4.1 (Jelly Bean).

For further details see the release notes accompanying HAC and the posts listed in our forums

http://www.tigabyte.com/forum/index.php?topic=202.0

Thank you again to our forum users and others for submitting such valuable feedback.

 

8 How To: Android Databases

Android Databases

This article give a brief overview of Android (SQLite) databases and how they are used with HAC. It then shows how to create a simple book database app. Both a book database project and its app can be downloaded from the HAC projects web page.

So what is a database? A database is an organized collection of data arranged in one or more tables. Each table represents one collection such as a book or video catalog and has its own layout as defined by its record structure. Each record within a table is stored in its own a row, and all rows within the table have the same format as defined by the number of fields(columns) and their data types.

A table within a database has:-
– rows and columns
– a row = one record
– a column = fields within the records

For instance a record may have the following format:-
Column:-      1       2                   3                   4
Name:-        ID     Title             Author         Comment
Values:-       1      Android      J Smithy      Android coding

Note, each table has a primary column and the primary column values must be unique to ensure individual records can found. Generally the database itself takes care of the primary column as records are added to it.

.

Location of Database Files

The Android OS ensures that each app can store database files within the app’s private protected folder thus preventing other apps from accessing them and users from browsing for them. These protected database files are often referred to as internal database files.

There are times though when it is necessary to work with so called external database files, These are database files in other locations such as on the SD card or when bundled with an app in its data folder. External database files are particularly useful when it comes to backing up, upgrading, emailing or exporting the database onto a desktop computer.

HAC apps can work with both internal and external database files. It also has Export and Import functions for copying databases both from the internal area and into the internal area.

HAC apps can work with multiple databases simultaneously and in order to do this most HAC database related commands/functions identify the database by specifying its full file path.

.

Using a Database

The 4 basic operation on databases are Create or Open, Insert, Query and Upgrade

  1. Create – this creates a database as specified by the location, table name and record structure
  2. Insert – this puts records into the database
  3. Query – this requests information or records meeting certain criteria from the database
  4. Upgrade – used when the structure of the database must be changed – eg adding an extra column.

.

Defining a Database

Before creating and using a database some thought must be given to the structure and format of the data to be stored. For instance, are the fields numeric or text, and which field is the primary one.

Android SQLite has the following three data types although it does not check for valid data formats -:-

  • text (string) – eg ‘Hello World’,
  • long integer – eg 23095
  • real – eg 14.268

Note, HAC uses strings(text) for all its variables and will automatically convert the data types to string.

.

Example of a Book Database

This example is a simple book database where the database file name is ‘infox.db’ and the table name is ‘books’. It has the following record format:-

ID (primary) – integer
Title – string
Authors – string
Comment – string

With HAC most of the database related commands and functions require that the database be identified by specifying its full file path.

Note, many of HAC’s database functions return a 1 if successful, otherwise they return 0. However, in the example below, no error checking is carried out in order to try and make the code easier to understand.

a) Open or Create

A database must be open before it can be used. If it already exists then opening it will do, otherwise it must be created, after which it will be in the open state.

Opening an existing database is easy, just use the DbOpenFN function. This function needs the full file path to the database and the file path can point to either an internal or external database file. The database can be set to either read-only mode or read/write mode by setting the mode flag to 0 or 1 respectively.

Creating a database is more complex because the structure of the database must be passed to the DbCreateFN function. In the following example it is assumed that the database does not exist and therefore must be created.

Note the part where it forms the file path pointing to the database. Line 10 uses a database file within the App’s ‘Local Folder’ while Line 11 has a commented out part which refers to an Internal database file.

@ --- sets the database path ---
@ -- local path is chosen but internal commented out ---
Global dpPath
Local dbname

@ filename
Put 'infox.db' into dbname

@ --- form source path ---
Put LocalPathFN into dbPath
@Put DatabasePathFN into dbPath
Append '/' onto dbPath
Append dbname onto dbPath

This next part specifies the table structure and then creates the database:-

@ --- sets up and creates database from dbPath ---
@ --- table name is 'books'
Global dbPath
Local version,table,structure,okay

@ db version
Put 1 into version

@ table name
Put 'books' into table

@ form db structure - columns and their data types
Put '(' into structure
Append '_id integer primary key autoincrement,' onto structure
Append  ' title text not null,' onto structure
Append  ' author text not null,' onto structure
Append  ' comment text not null);' onto structure

@ --- Create Database ---
Put DbCreateFN(dbPath,version,table,structure) into okay

.

b) Insert 3 records

The SQL commands for inserting a record and its data into a database can appear quite daunting to the uninitiated therefore the HAC commands try to make it easier for the beginner to insert data into a database.

The insert data process uses three steps to insert a record:-
1 – Init – creates the record
2 – Build – adds data to the record
3 – Insert – inserts the record into the database

@ --- insert 3 records into the database ---
Global dbPath
Local dbname,path,command,okay

@ --- Record 1 ---
DbInsertInit(dbPath,'books')

DbInsertByName(dbPath,'title','Android G1')
DbInsertByName(dbPath,'author','Zaks')
DbInsertByName(dbPath,'comment','info about phone')

Put DbInsertDoFN(dbPath) into okay

@ --- Record 2 ---
DbInsertInit(dbPath,'books')

DbInsertByName(dbPath,'title','Dogs')
DbInsertByName(dbPath,'author','Meloni')
DbInsertByName(dbPath,'comment','about dogs')

Put DbInsertDoFN(dbPath) into okay

@ --- Record 3 ---
DbInsertInit(dbPath,'books')

DbInsertByName(dbPath,'title','Android Databases')
DbInsertByName(dbPath,'author','Peters')
DbInsertByName(dbPath,'comment','Android and sql')

Put DbInsertDoFN(dbPath) into okay

.

c) Queries

Querying a database involves asking it if certain fields contain a search value(s), either strings or numbers. The database will then return any requested fields in the form of an array that can then be accessed for information. Queries can be quite complex, involving matching several fields to values, in which case SQLite really shows its power.

Building the query is the most difficult part of querying a database because the programmer needs to have some understanding of SQLite syntax. The example shown here is simple but still very useful.

There are three steps to querying a database:-
1 – Build – build the query command(string).
2 – Execute – execute the query command on the database.
3 – Retrieve – retrieve any results from query.

Note, if the query string contains single quotes then this can clash with HAC’s compiler syntax as HAC uses single quotes to start and end literal strings. Therefore in the example below the single quotes which are part of the query are implemented using the ChrFN(39) function. At the present time there are also some issues with the Android OS implementation of SQLite, in particular for strings containing special characters such as % sign.

@ --- Query database records for titles including 'Android' ---
Global dpPath
Local table,query,count,n

@ -- set table name --
Put 'books' into table

@ -- build SQLite query string --
Put 'SELECT _id, title FROM books WHERE title LIKE ' into query
Append ChrFN(39) onto query
Append '%Android%' onto query
Append ChrFN(39) onto query

@ -- display query in field 1 --
Put query into field 1

@ -- execute and display query status in field 2 --
Put DbExecQueryFN(dbPath,query) into field 2

@ -- see how many results were returned --
Put DbQueryCountFN(dbPath) into count

@ -- display count in field 3 --
Put count into field 3

@ -- display any results in field 4 --
Clear field 4
if count>0 then
    for n=1 to count
        Put DbQueryResultFN(dbPath,n,'title') after field 4
    endfor
endif

.

d) Close
It is best to close a database when it is not in use as this makes it less likely to be corrupted and also saves memory.

@ --- Close database ---
Global dbPath

DbClose(dbPath)

.
Summary
The above example should help almost anyone create their own database app with HAC. Although it doesn’t go into much depth with SQLite syntax it still shows how to create a database, add information to it, query the database, and then close it.

HAC supports both internal and external databases, and apps can have multiple databases open at the same time.

For more information about creating database apps with HAC, look at HAC’s built-in help or its HAC Help pdf.

There is a database project and its built app on our examples web page http://www.hypernextandroid.com/hnfiles/rescreator.html Compared to the example presented here, the project is more of a test bed that demonstrates HAC’s database functionality.

.

Members of HAC forums can download the latest trial version of HAC, see details here:- http://www.hypernextandroid.com/hnfiles/downloads.html

 
Leave a comment

Posted by on 15/10/2012 in Databases, HAC, How-to

 

Android Apps – No Coding Development?

For anyone wanting to create their own Android app, the options can seem bewildering. Options range from so called No-Coding app makers to the standard Google Android Java approach.

Most of us tend to pick the easiest options, and this can be fine for many tasks. However when creating software it is usually  best to consider the options because they can have long term implications. Choosing the wrong option can waste both your time and your money.

There are basically two quite different approaches to creating Android apps:-

  1. For those comfortable with programming – Eclipse Java and the Android SDK.
  2. For those new to programming – No-Coding Template based app makers.

HAC is in the middle ground as it offers an easy to understand coding language and visual designer.

There are also tools like App Inventor that make programming easy with their coloured blocks/segments although they are harder to use for larger projects.
.

Code – just instructions

Code is just a list of instructions that tells the computer how to carry out a task.

There is no need to fear coding and if one follows some basic steps then the coding will be easier.

So if you try to break the task into smaller pieces it can be easier to design and create the code.

Perhaps the reason so many people try the No-Coding approach is because the Java approach and its Object Orientated aspects has a tough learning curve. HAC tries to make coding easier as each HAC English-like instruction executes a number of often complex Java instructions so hiding much of the complexity from the coder.
.

No-Coding Approach

The No-Coding aproach is very attractive and can produce some impressive looking apps.

Such app makers work by allowing the creator to select a template for a particular task and then personalise or tune the template to their needs. Usually the template changes are mainly to do with their appearance and content but not with functionality. Changing functionality generally needs code changes.

To make an app that way is very simple. Select the template, modify the template and click the build app button. The built app will then be emailed to you after 10 minutes or will be available to download.

However, what about unsupported functionality? For instance, suppose the template can do a task once but you need it to do the task several times and each time process the data before displaying it. In this case you would need to learn some HTML/Javascript. Unfortunately HTML/Javascript are both limited in the functionality they can provide and have limitations in updating displays and handling user feedback. This might not be a problem for your app but its wise to check the web site’s forum posts to see how they implement the functions your app will need.

If you intend to charge money for your app then you might try to deter piracy by some kind of registration scheme using name/address and a serial number. If you are lucky then the app maker might provide this functionality otherwise you will need to code your own scheme.
.

Where is the Code?

Generally, the code will reside on their No-Coding web server and will be innaccessible inside the template. Although any custom code you made such as HTML and Javascript could be saved onto your own computer.

Being able to see the code can be important if you want to understand how it works, improve it or sell it to someone else.

Of course, if you are happy with the standard template then the issue of code does not arise
.

Who Owns Your App?

The issue of who actually owns your app and its code can be very important.

Ownership of the app can be a grey area as some No-Coding sites say you are only granted non-exclusive rights to your creation. They explain that this is because of the way their template works inside the app’s runtime engine and that the templates are used by others.

There is also the issue of will the app look like your app. That is, will it display you as creator or will it display the No-Coding website’s name.

If you want to own your app then make sure you read their agreement and are happy with it.
.

Subscription Issues

With traditional fixed term licensed software, when the license expires the software keeps on working but cannot be updated. Therefore the owner can keep on developing their apps.

With a No-Coding app maker, what happens when your Subscription expires? Is your app locked or can you still access it, see its details or export it? Also will you still be able to modify or rebuild your app?

Is there a limit of how many apps you can make with the subscription or are there extra charges?

Its worthwhile reading their FAQ to see what the subscription offers.
.

HAC Advantages

Although No-Coding app makers can produce some excellent results they are limited by the number of available templates. With time they will get even better as more templates and functionality are added. However, if you need something special and their template system doesn’t support it, then generally you will have to learn HTML/Javascript and incorporate it into the template.

Comparing HAC to No-Coding app makers:-

  1. Your HAC license lasts forever – no subscriptions.
  2. Security, as your projects and code are stored on your own computer.
  3. Having your own source code puts you in control.
  4. Code is infinitely more flexible than template systems.
  5. To make money, you probably need unique ideas – not templates.

In summary, check out what the No-Coding maker offers and you might find that they offer just what you need.

Bear in mind that HAC doesn’t offer full Android functionality so No-Coding could be the route to go.

Finally, don’t be afraid of coding – its just telling a computer how to carry out a task.

 

HAC v1.15 with Database Support

HAC v1.15 released for Windows (24th August 2012 )

This update adds SQLite database support, status bar notifications, fullscreen mode, AES cypher, Base 64, Toast Message and some further boolean/conversion functions. There are also memory performance improvements and some bug fixes.

The SQLite database functions can work either with database files on an app’s internal protected file space or on the external SD card.

HAC apps can run on Android OS API 1.6 up to the latest 4.1 (Jelly Bean).

For further details see the release notes accompanying HAC and the posts listed in our forums

http://www.tigabyte.com/forum/index.php?topic=190.0

Thank you to our forum users and others for submitting such valuable feedback.

 

7 How To: UDP Messaging and Datagrams

UDP Messaging
This article describes how to use UDP to create a simple chat program with HAC but first what is UDP?

UDP stands for User Datagram Protocol and is an easy way to send short messages because unlike TCP it does not expect an acknowledgment from the receiver. The message is sent to the target as a datagram which has just two parts, the sender’s address and the message content. UDP is often used in games and other time critical applications where the sender does not have time to wait for an acknowledgement from the receiving party. It is useful when the loss of a single message is not crucial although in practical terms message loss is very unlikely on local networks unless the network and/or the related devices are very busy.

UDP advantages are:-

  1. fire and forget with no need to check if received.
  2. fast as packets are much shorter.

UDP disadvantages are:-

  1. does not work on some phone networks as they block ports.
  2. for internet use it may not work if you or your target are behind a router.

A example of using UDP is when a master device must communicate with a number of slave devices such as in local network of a school or business. Another example is using a device to communicate with a microprocessor or other hardware device that supports UDP.

More information about UDP is given towards the end of this article and further details can also be found here:-

eHow – about UDP ports

What is UDP on Yahoo

.

How to use UDP?
Using UDP is very simple, just create a socket and set some parameters. You need to know the device input address, target address and which ports to use. As HAC apps can have several sockets open at a time so most UDP commands/functions need a socket number.

The app has to create a socket and then attach this socket to a port on the device. Ports are like openings onto the computer that can both receive and send data. Ports can listen for incoming datagrams and trigger an event when one arrives.

The basic parts of using a UDP socket are:-

  1. Create a UDP socket that handles ports and events.
  2. Connect the socket to a port to enable listening and receiving.
  3. Send a message.
  4. Receive a message.
  5. Event Handling.

.

UDP Example Project
This example comes from the HAC UDP demo project which is included with the more recent versions of HAC installer. It is also available on our website along with a built Android app:- HAC Project Web Page

If you need to test your UDP app then a full featured but easy to use UDP tester can be downloaded from  here:- Simple Tools UDP Test Tool

The UDP project described here has just two screens, the network setup screen and the chat screen.

The network setup screen in Fig 1 shows the device(host/local address) as 192.168.1.64 and the target/recipient as 192.168.1.71. Both the host and target are using port 5042.

Fig 1- UDP Network Setup

.

A screen shot of the actual chat part of the app is shown below in Fig 2. The top field is where the user enters their message and the lower field is the log where both their text and that of their target appear.

Fig 2 – UDP Chat

.

1) UDP Socket Creation
A socket is used to connect with the port and trigger any UDP events. The UdpCreateFN function will try to create a socket and if successful will return a positive integer as the socket number, otherwise it will return 0.

Global sockNum

Put UdpCreateFN into sockNum

if sockNum<1 then
   Message 'Cannot create socket'
endif

To delete a socket and free up its memory use the UdpDelete command.

.

2) UDP Binding to a Port
In order to send or receive messages a socket must be bound or connected to a port. Once a connection is made then the port will listen for incoming messages and transfer them to the socket so it can raise a UDP event. As well as a socket number, making a port connection also requires the expected maximum size of the message in bytes and a rest time specified in milliseconds. The maximum message size is used in creating a buffer for holding the message and details of acceptable sizes are given later on. The rest time is used to reduces the load on the device so that after a message is received the listener will rest before listening again. If the rest time is set to zero then no rest is allowed and the listener will work continuously.

In the code below the message size is set as 1024 bytes and the rest time as 1000mS.
The port number is obtained from field 2 and is 5042 as shown in Fig 2.

Global sockNum
Local port

Put field 2 into port

UdpConnect(sockNum,port,1000,1024)

To stop listening but still keep the socket in memory use the UdpClose command.

.

3) UDP Sending a Message
Sending a message requires specifying the target address, the message and the encoding to use for the message.

In the code below field 1 is where the user enters their text and field 2 is the log window as shown in Fig 2. The target address is obtained from the network screen, in Fig 1, as when the Chat button is pressed it simply loads the value of field 1 into the global variable targetAddress.

The encoding is used to set the format of the message string and depends upon the message contents such as language used or whether it is binary. Both the sender and receiver should agree on the encoding used.

Global sockNum,targetAddress
Local message

Put field 1 into message

Put 'Local ' after field 2
Append message onto field 2

UdpSend(sockNum,targetAddress,message,'UTF8')

.

4) UDP Receiving a Message
When a message is received by a port that is bound to a socket then that socket will trigger a UDP ‘Data Received’ event. In this event the app can process the message and make any necessary response.

The received datagram has two parts, the message, and the sender’s address. Assuming a datagram has been received then the following code would extract the data and address from the specified socket. The actual socket number can be found within the event as shown later.

Local data,address

Put UdpRxDataFN(sock) into data

Put UdpRxAddressFN(sock) into address

.

5) UDP Events
There are three types of UDP event in HAC apps, Data Received, Message Sent, and Error. Their integer values are 1,2 and 3 respectively.

When a UDP event occurs it triggers the UDP script. This script can be edited using the script editor and is located in the Specials section of the Editor.

Whenever a UDP event occurs then the event script should check to see:-

  1. Which socket raised the event.
  2. What the event is.

The following code shows how to handle a UDP event:-

Local sock,event,data,address

Put UdpIndexFN into sock

Put UdpEventFN into event

if event=1 then
   @ Data Received
   Put UdpRxDataFN(sock) into data
   Put UdpRxAddress(sock) into address
else
   if event=2 then
      @ Message sent
   else
      @ Error
   endif
endif


Additonal Info
It is possible to create your own protocol by embedding commands inside the messages so that both receiver and sender can coordinate their responses. As the messages are just strings then a simple protocol might be as follows:-

  • first 3 characters representing the command – eg 001
  • the next 5 characters representing the port – eg 45000
  • the rest of the message.

Note, on some platforms the UDP listener will hear its own messages but they can be filtered out by checking if the address of the incoming datagram matches that of the device address. An app can find its own address using the function InputAddressFN.

The maximum size of a datagram message is 65,508 bytes although some networks limit this to 8,192 bytes. If the message size exceeds the network limit then the message will be split into multiple datagram packets therefore if the maximum size is not known then 8192 bytes might be a safe size to use.

.

Summary
With UDP it is very easy to make a simple messaging system although how complex it becomes will depend upon your needs. Messages are sent to the target machine as a datagram that includes just the message and sender’s address so allowing simple chat systems to be built. The main drawback of UDP is that it has problems  working on the internet where the computers are one of several connected behind a router or on mobile phone networks where mobile providers often block ports.

Despite UDP’s drawbacks it is very easy to set up a messaging system on a local network or send data to any device that understand UDP.

.

Members of HAC forums can download the latest trial version of HAC, see details here:- http://www.hypernextandroid.com/hnfiles/downloads.html

 
Leave a comment

Posted by on 01/06/2012 in HAC, How-to, network

 

HAC v1.14 with UDP Messaging

HAC v1.14 released for Windows (25th May 2012 )

This update adds UDP messaging plus improvements and bug fixes.

UDP messaging is an easy to use communications protocol that is ideal for messaging between apps in local networks such as in schools and businesses. It allows fast communications and can also interact with hardware that supports the UDP protocol.

For further details see the release notes accompanying HAC and the posts listed in our forums

http://www.tigabyte.com/forum/index.php

Thank you to our forum users and others for submitting such valuable feedback.

 
 

6 How To: Develop for the Kindle Fire

What is the Kindle Fire
Amazon’s Kindle Fire is a tablet computer version of their Kindle eBook reader. It runs a modified version of Google’s Android operating system so allowing users to run and source apps originally intended for Android devices.

http://en.wikipedia.org/wiki/Kindle_Fire

http://www.amazon.com/Kindle-Fire-Amazon-Tablet/dp/B0051VVOB2

http://gigaom.com/mobile/kindle-fire-helps-amazon-appstore-hits-31000-apps-in-first-year/

This article takes a brief look at using HAC(HyperNext Android Creator) to develop apps for the Kindle Fire. Before that though we mention the two traditional approaches to developing for the Kindle Fire. However, if you don’t know or don’t want to use Java then just skip this next section and go to:- HAC and Kindle development.

Kindle and Android SDKs
Amazon provides a free Kindle SDK(Software Development Kit) so developers with a good knowledge of Java and the Android APIs can create their own apps. The Kindle Fire runs a modified version of Android Gingerbread and therefore has some differences from the official Google Android Gingerbread.

It is possible to use Google’s Android SDK to develop apps for the Kindle Fire but there is some Kindle functionality that the Android SDK cannot provide.  In contrast the Kindle SDK gives the developer full access to all the Kindle Fire’s functionality such as showing and hiding the Options Bar whereas the Android SDK cannot access these Kindle specific features.

The advantage of using only the Android SDK approach is that your app can potentially run on both standard Android devices such as Xoom etc as well as the Kindle Fire and you do not have to try to keep projects synchronised with the Kindle SDK. The disadvantage is that it can be awkward to get your app to look right on the screen because the Options Bar can hide the lower part of it:-
http://stackoverflow.com/questions/9340606/

HAC and Kindle Development
Developing for the Kindle Fire with HAC(HyperNext Android Creator) is much the same as using HAC to develop for a standard Android device with just a couple of things to look out for. Note, that HAC apps know when they are running on a Kindle Fire and automatically take care of optimising the screen coverage so users don’t have content hidden by the Options Bar. HAC developers can also add a device check inside their app to see which type of Android device it is running on and so take appropriate actions.

1) Screen Sizes
The Kindle Fire screen size is 1024 x 600 pixels with 20 pixels taken by the top Status bar and 40 pixels taken by bottom Options bar. HAC built apps automatically detect screen dimensions and handle the screen drawing so the app creator just has to choose the appropriate screen settings as described below.

HAC offers 3 options for allowable screen orientation;- either portrait or landscape, portrait only, landscape only.

During the development of your app HAC offers 3 screen scaling options: none, fit or stretch. The option none is only really useful when targeting a specific device where both orientation and screen size are known in advance. The fit option keeps the ratio of the apps height to width ratio constant irrespective of which physical device it is running on or whether the screen orientation is changed. This ratio is determined from the size given to the home card. The stretch option simply stretches the app’s screen area to fully cover the usable screen area but can result in large distortion if both portrait and landscape orientations are allowed.

To setup the screen orientation and scaling, open HAC’s Your Application window via the Android menu and it should look similar to Fig 1 below:-

Setting orientations and screen scaling

Fig 1 –  HAC’s Your Application window showing app screen setup

2) Carousel Icons
Most Android smart phones and tablets have used a 2D array of icons to represent their installed apps but the Kindle Fire also has a  stylish carousel to display them in. The carousel displays the most recent apps, books etc and represents an app by displaying its attached icon . If it can’t find the correct icon it will use an app’s launcher icon although this can result in apps with low resolution  icons looking very shabby and dated.

Fig 2 below shows the carousel on a Kindle Fire although unfortunately the camera could not accurately capture the true color of the app icons.  Three of the apps are made by HAC with one having a 200 x 200 icon and the others using older 48 x 48 icons.

From left to right the apps on the carousel are:-

1 – Kindle Test with 200 x 200 icon

2 – Lunar Lander with 48 x 48 icon

3, 4, 5 – standard high res Kindle icons

6 – PreSchool Sums with 48 x 48 icon

Note that as they are PNGs their transparency works

Fig 2 – Kindle Fire carousel

HAC supports icons up to 800 x 800 pixels so allowing an app to look stylish in the Kindle Fire’s carousel. If the icon is in PNG format then transparency is supported. Note that these icons will still work on older Android devices such as the G1 smartphone because the Android system does its own scaling.

To add an icon to your app, open HAC’s Your Application window using the Android menu and assign the icon to the area highlighted by red as shown in Fig 3  below. Either drop your icon onto the icon area or else navigate to it using the Launcher button:-

Setting icon for your app

Fig 3 – HAC’s Your Application window showing launcher icon area


Summary
When designing for the Kindle Fire, just treat it as another Android Device but remember to create a higher resolution icon for it otherwise your app can look shabby and dated sitting on the carousel. Also think about which screen orientation(s) your app needs. Note, although this article has covered the Kindle Fire, the above points about screen sizes, orientations and launcher icons are still relevant to creating apps for other Android devices.

Members of HAC forums can download the latest trial version of HAC, see details here:- http://www.hypernextandroid.com/hnfiles/downloads.html

 
 

HAC v1.13 with Kindle Fire update

HAC v1.13 released for Windows (17th Mar 2012 )

This update brings many improvements to HAC and HAC created apps running on both standard Android devices and Amazon’s Kindle Fire.

The Persistant Storage option now works. This allows an app upon quitting to automatically save all its variables/fields so that on restarting they can be automatically reloaded thus saving the programmer a lot of work.

There are some major improvements including fixing screen orientation, better detection of status bar height plus several bug fixes.

Extra functionality include 4 new functions for fast array searching and 30 commands/functions for operating on Binary files.

Improvements directed at the Kindle fire include better use of its screen area and the ability to use up to 800×800 icons for the carousel. Also apps are now fully refreshed after being sent to the background such as might happen when the user activated another app or pressed the Home or Back buttons on the Options Bar.

For further details see the release notes accompanying HAC and the posts listed in our forums

http://www.tigabyte.com/forum/index.php

Thank you to our forum users and others for submitting such valuable feedback.

 
Leave a comment

Posted by on 19/03/2012 in Kindle, Updates