Wednesday, July 3, 2013

Layman's Guide to Android Programming - 1 - Setting up your project

Hi all,

Today I'll start with, setting up your first project. I can hear a "What??? We're setting the project and not learning programming?" somewhere. Chill people, there are some minor details we have to pore over first.

-Creating a new Android Application Project

In Eclipse, click on "File" (top left), "New" then "Android Application Project".

You should then arrive at the next image. Let's take a look at the various fields.



-Specifying the application details

For details, mouse over the fields.

"Application Name" is the name of your application, which according to the help text at the bottom, "... is shown in the Play Store, as well as in the Manage Application list in Settings.".
I would like to add that that is the name of your app in the menu as well.
No fear, if you typed it wrong here you can change it later, in res/values/string.xml under the string app_name.

"Project Name", used within Eclipse as an identifier. No big deal screwing up here, but name stuff properly for the sake of it and also if you have many applications to manage. I wouldn't want to name it MyApp1 to MyApp10 and have no freaking idea what's what.

"Package Name". This is the unique name that must be set for your app. Note that this must stay the same for your app. If you ever have two applications that is almost the same, e.g. A free version and a paid version the package must be different.
It's usually in the format com.organization_name.product_name.
So in my case it would be com.turtleSpeedCoder.superAlarm or something like that.

"Minimum Required SDK". This determines what users can access your app on the Play Store. Somewhat to the tune of "Minimum height to play this ride". Changeable easily later.

"Target SDK". This is the version supported up to. If your app is designed and tested til a certain version, this is what you'll select. Changeable easily later.

"Compile With". This will be compiling with the SDK version. In layman's terms, this would be equivalent to validating your code with a particular set of rules. You can keep it the same as Target SDK.

"Theme". Presets your app with a theme. Note that themes are included as part of the SDK, so some themes will not be available with the older SDK versions.

Let's go "Next"



-Configure Project

For now, let's uncheck "Create custom launcher icon". It's a hassle for me to explain it since it's more of a design issue rather than a programming one.

"Next"



-Create Activity

What is an activity? It is something that you show to the user. Think of it as a piece of paper that you hand out to your users. Be it a log in screen, a welcome screen or a menu, these are represented by an activity.

It is possible to code many interfaces and pages into just one activity, however that is bad practice and tedious.

Let's start with a blank one. (FYI, I haven't meddled with the other two. As of today, I'll be learning the Fragment UI, which is associated with the "Master/Detail Flow".

"Next"



-Blank Activity

"Activity Name", This is the class name that your main java file will be named. You can name it to your liking, hopefully with the proper naming conventions, like LoginActivity or MenuActivity.

"Layout Name", Similarly, this is is the Android XML file. Likewise as above. Note however, that for Android XML files, they are all lower cased. You can separate words by dashes "-" or underscores "_". The guys at Google typically use underscores.

"Navigation Type", This is some presets that you can set to your activity. However, since we're here with the intention to learn, let's start with a blank slate. Select "None" and "Finish".



And with that, you have gotten through your first step in Android Programming! Stay tuned for the next lesson (or my on and on droning).

Monday, June 24, 2013

's been a long time! (Yes I left out the It) - Foreword to Layman's Guide to Android Programming

Hey my dear non-existent (and perhaps the lost user that reached here by accident) readers,

I'll be starting a new section of "Guide to Android Programming" page. This shall serve as the foreword (which will be linked to as Foreword when I create the guide).

Why the intention to create a guide? First off, I needed to transfer my knowledge to my interns. Rather than being a one-off effort, I might as well create a guide that they can refer to and look back upon which can also be reused by future potential colleagues/interns/subordinates/minions (BWAHAHAH!!!).

I've thought of creating my own guide for a long time but lacked the reason and motivation to do so. Since most books and guides are cryptic and riddled with terminologies that befuddle the newborn Android infant, often filling useless (useless at the point in time) information in tutorials that trip and waylay the poor programmers, I've decided to throw in a simple and easy guide.

For example, assuming I've creating a guide to Java Programming, here's what you'll see in most tutorials. The most basic would always be the "Hello World" example so let's not talk about that.

"Here's a tutorial to Web Form, now let's throw in various unnecessary and hard to understand (many) lines of programming code to get my point across."

If you're asking me, what is a Java class? I'll give it to you in less than 20 characters. Yes, 20 characters, not words.

public class a {}
That's a working class, but does it do anything? No? Of course. A program does what YOU want. So I'll be teaching how to construct a basic class (depending if you're wanting program or applet) and then the little itty bitty basic stuff which will help you do the stuff YOU want. No crazy words and stuff that you'll need a dictionary by your side.

So with this, enjoy your journey!

Tuesday, July 17, 2012

Mini Bluetooth Keyboard Android FIx

Hey all,

I've just bought a mini bluetooth keyboard off the internet. It's supposedly compatible with Android devices. I MUD (Multi User Dungeon, I call it the grandfather of MMOs) and seeing the possibility to MUD on the go without an entire computer, I was enticed to buy it.

Just a brief description:

It's a 49 key small keyboard, not the full QWERTY design but it's working well enough.
I bought it off Qoo10, though you can find it on places like Amazon as well.



***WARNING***
This item will not be easy to set up for the non tech savvy.

But for the rest who are frustrated, here's how I got it working.

Summary
1) Pair up keyboard
2) Connect keyboard
3) To reuse after turning off

Steps
1) Pair up keyboard
-Go into Android, Settings, Wireless & Networks, Turn on Bluetooth, Bluetooth Settings.
-Turn on keyboard, it will glow blue (top right) for about 2 seconds.
-Click the button next to the blue LED, it should start flashing, this is the pairing mode.
-On phone, you should get "Bluetooth Keyboard, Pair with this device", click it.
***IMPORTANT STEP***
-When it asks for a PIN code, enter 0000, click 'OK' (on phone) and then on the keyboard, press 0000 and then the enter key. This will pair it up.

If you take too long and the keyboard stops flashing, press and hold the pairing button until it flashes again.

***Step 1 done***

2) Connect keyboard
-You will need an app called BlueKeyboard JP by Elbrain. Download it off the Play Store.
-Start up the program, you should end up in the Language & Keyboard Settings. You can get here again by going from Android, Settings, Language & Keyboard Settings.
-Check BlueKeyboard JP, read through warning and click 'OK' if you're acceptable with it.
-Click BlueKeyboard JP to edit the settings or you can click the BlueKeyboard JP program from the app list.
-You will arrive at 'BlueKeyboard Settings'.
-Click 'Selected keyboard' and select the only option, which should be 'Bluetooth keyboard'.
-Make sure 'Connecting process' is checked.
-Go to any text input app, for example, SMS.
-Long press on the text input, choose 'Input Method' and select 'BlueKeyboard JP'
-Type something on the bluetooth keyboard, there should be a message prompt on the screen saying something similar to 'Connecting to keyboard, change keyboard state to pairing mode'. Press and hold the pairing button on the mini bluetooth keyboard.
-There should be a notification on top that says 'Connected. Bluetooth keyboard etc'.

***Congratulations, your mini bluetooth keyboard is usable now!***

3) To reuse after turning off
-To go back to normal usage, turn off keyboard and long press on text input and select back 'International keyboard' or whichever keyboard you were using.
-To go back to using the mini bluetooth keyboard again, turn on keyboard. Long press text input and change to to BlueKeyboard JP. It will show a 'Connecting' notification. Press and hold the pairing button on keyboard.
-Once it shows 'Connected', you're back to typing!

***If this post has helped you, you can help me in return. Click on one of the Google Ads on the side :) ***

Tuesday, May 22, 2012

HTML To PDF

Hey all, just a quick post.

I found a .exe file that converts html to pdf. Kind of nifty. Now I need to try integrating this into a web app to see if I can churn PDFs on the fly.

If you are interested in it as well, here's the link:
http://code.google.com/p/wkhtmltopdf/

Wednesday, May 9, 2012

Dynamically creating QML objects via Javascript

Hey all, Now in the midst of work so this is going to be a quick post. I needed to create QML Objects on the fly and needed to do it via Javascript. So how do I do it? Here's the quick and dirty, read it yourself!

// Variables
ListModel {
    id: listModelData
}

function splitStringToArray(stringToSplit) {

    var stringArray = stringToSplit.split(';');

    console.log("Length: " + stringArray.length)

    for(var i = 0; i < stringArray.length; i++) {
        var splitStr = stringArray[i]
        var model = Qt.createQmlObject('import QtQuick 1.1; ListModel {}', parentQMLObject);
        model.append({"name":"test"});

        listModelData.append({"model":model})
        console.log("Test model: " + model.get(0).name)
        console.log("Test listModelData: " + listModelData.get(0).model.get(0).name)
    }
}
There!

Have fun!

Friday, March 9, 2012

Tough day at work

Man, what a tough day at work. I'm still fairly new to ASP.Net.
No idea on how to accomplish a certain task.

Tough wall to crack but I'll crack it anyhow, with a little time and patience, just not today...

Anyway, what I'm trying to accomplish is:

1) Pull 2 sets of data out from database via SQL (Done)
2) Populate 2 lists with sets of data (Done)
3) Enable user to manipulate list dynamically without postbacks (Stuck here)
4) Save changes

Still stuck at step 3. Can't think of a way to do this via ASP.Net.
If this was PHP, I would have already done it with the help of Javascript.

Sign, no idea of which web control to use. Repeater? ListView? Or some other web control which I have not heard of or used yet. What a bummer, stumped at my inexperience.

I need the ItemTemplate portion to generate possibly a span item with unique id that can be picked out from a div with unique id (list1) to another div (list2). I would also need checkboxes.

If without postbacks, does it mean I have to put scripts into the page itself rather than code behind? I'll look into in page scripts first thing on Monday.

If any of you readers have any suggestions, do feel free to throw it in the comments section, though I believe that due to the low exposure of this blog at the moment, I would have solved this by then. Do check out my next post then. I should have my solution posted :)

P.S. Looked back on some old code. Had a hard time programming it back then but since I'm touching on a higher level of code now, looking back on those old code really makes it look easy. I would probably be touching up on those old code sometime... In case of TL;DR, Programming level up!

Monday, March 5, 2012

Combine image and text in a PdfPCell

Hey all,

Was confused as to how to combine an image and text together in ASP.net C#, while using the iTextSharp PDF library. Googled a bit and found my answer.

I'm not an expert at this so I'll just list out the code that would be understandable for dabblers.

If it's too long for you to read (including my babbling), just scroll down to the code

Starting off, I use a [Document] to contain a [PdfPTable] that holds [PdfPCell]s.
Being new to this I was hard-wired to think, 1 PdfPCell, 1 item, with that item being maybe text, or just graphics alone.

However I got stumped when I was required to c
ombine text and graphics together in a cell due to formatting, like wanting to have an image next to a label. I tried two separate cells with the image aligned to the right, and text aligned to the right (I needed it to the end) but due to the Colspan and width properties, I got this.


Yeah, you see it right? I needed that round image next to the text, however due to each cell being 100 pixels and the label not using up all the space I had this ugly effect.

Now here's what you were for! A cell can have multiple elements in there.
A quick touchdown on the solution. Remember
PdfPCell? It used to hold one item, either an Image, or a Phrase or Paragraph.

But now, [PdfPcell] holds 1 [Paragraph], which holds 1 [Chunk] (image) and 1 [Phrase] (text). So I get this!
Further formatting can be done with the X and Y offset to shift the image, you'll see it in the code as (image, 0, 0).

Now here's the code:

Document doc = new Document();

doc.Open();

PdfPTable table = new PdfPTable(5);
table.TotalWidth = 500f;
table.LockedWidth = true;

...
Paragraph paragraph = new Paragraph();
paragraph .Add(new Chunk(image, 0, 0)); // x y offsets as 0 but you can edit it in your code to align the image

paragraph.Add(new Phrase("Admin CP J", timesSmallBlack));
paragraph.Alignment = 2; // This alignment affects the positioning within the cell, important!

PdfPCell cell = new PdfPCell(paragraph );
cell.Colspan = 3;
cell.HorizontalAlignment = 2; //0=Left, 1=Centre, 2=Right
cell.Border = 0;
table.AddCell(cell);

...

doc.Add(table);

Now, kudos to the original post which I've found: How to get a gif in a pdfpcell to line up with trailing text

If you enjoyed my post and it has helped you and you would like to return the favour you can click any of the sponsored Google ads around the page, thank you!