Sunday, April 6, 2014
Eclipse ADT (Build v22.2.1 for Mac OS) Pointers
When you create a new app from scratch (file->new->Android Application Project) and select the defaults, it automatically opens the java file (from the src folder) for editing, and the main xml file (from the res->layout folder) for editing. The xml file has two panes, text and graphical layout. Start with the graphical layout to drag and drop objects like fields and buttons onto your UI. Then edit the xml text and the java file to handle events with the objects.
The YouTube tutorials on this, called "Android: project 1(v1)", up to (v6), by "Lecture Snippets" are very efficient and provide simple java code for this. The YouTube tutorial "Android Basic SQLite Database" by "profgustin" gives some basic SQLite code, which I have enhanced below to interact with a field from Lecture Snippets.
The main thing not to forget is: although SQLite is "built-in" to the Android Developer Tools SDK, the new app cannot use the classes until they are imported in the java code AND attached to the build path. I found that typing SQLiteDatabase in the java code, and either hovering over it or double clicking on it brought up a dialog box that allowed me to both make the import statement in the code, and add the android.jar file as a Source Attachment in the Java Build Path (this is otherwise found by right-clicking the project file in the navigator pane-> Properties->Java Build Class->Android.
I use the Cursor class to manipulate SQL data, so I also had to import android.database.Cursor; as well. I think import android.database.*; may also work.
package com.example.foo2;
import android.os.Bundle;
import android.app.Activity;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.view.*;
import android.widget.*;
public class MainActivity extends Activity {
Button btn1;
EditText etxt1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SQLiteDatabase db = openOrCreateDatabase("MyDB", MODE_PRIVATE, null);
db.execSQL("CREATE TABLE IF NOT EXISTS MyTable (field1 VARCHAR, field2 VARCHAR, field3 VARCHAR);");
db.execSQL("INSERT INTO MyTable VALUES('red','green','blue');");
Cursor c = db.rawQuery("SELECT field1 FROM MyTable", null);
c.moveToFirst();
final String MyString = c.getString(c.getColumnIndex("field1"));
db.close();
btn1=(Button)findViewById(R.id.button1);
etxt1=(EditText)findViewById(R.id.editText1);
btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
etxt1.setText(MyString);
}
});
}
Saturday, December 14, 2013
ADT - Android Developer Tools - with Eclipse: Starters.
Here is a refresher on how to start a new project by copying an old one. In my case, I keep my projects on a Mac in Documents->Android->Workspace folder. That is my default folder for new projects. For this example I have a same, working project that compiles with no errors and runs on a Kindle via USB cable called "Notepad". You must be sure to open the Eclipse IDE correctly. I select Eclipse from Spotlight, but I have more than one installation. It has to be the ADT version. Once Eclipse is open, in the Navigator bar on the left one has to be sure the project being copied is "open" (either double click it, or ctrl-click->open project. Can close projects the same way, for faster loading of Eclipse).
1. Highlight open project -> cmd-c -> unhighlight -> cmd-v -> select name for the project.
2. ctrl-click project -> Android Tools -> Rename Application Package -> follow instructions.
3. Navigate to res->values->strings.xml->app.name to rename the app for the device.
This creates a new project in the default folder, opens it in Eclipse, allows you to independently name the folder it is in, the application package, and the app on the target device. All of 3 of these names can be the same or be named independently.
This allows one to revert to a project in a skeleton form, but has all the right settings, jars, and so on to allow error-free compilation and installation to the desired target device.
To run, click the run button. To stop from running, go to the app page on the target device, hold your finger on the app icon to delete the app.
Sunday, September 30, 2012
SSH Server for Windows XP
For a Mac, turning on SSH server is built-in and is just one click inside System Preferences -> Sharing Pane -> Remote Login -> just check the checkbox and it even tells you the command line syntax to use to SSH in from the client.
For Windows it is more work:
MobaSSH Server is the software I selected. Install it last.
First, go into control panel -> Windows Firewall and add exception: name it SSH and use port 22. (I also turned on remote desktop in the same pane, not sure it was necessary but I read that on a forum somewhere)
Second, don't make the mistake I made. I changed my username in control panel -> Users to make it all one word with no spaces, thinking that the two word name would mess up the SSH client at the command line. WRONG! Because when you change your user name, it does not change your user file directory. (If it did it would mess up everything you have installed on the computer). Well it turns out MobaSSH uses your user name from the file pathway, instead of from the login, if they do not match. That problem had me stumped for two weeks. Make sure you have a password for your Windows login.
Third, install MobaSSH.
From the Client (I used Terminal (Unix) from a Mac):
ssh "firstusername lastusername@192.168.1.xxx"
With the quotes!!!
Saturday, September 15, 2012
Creating Icon for iPhone app in Xcode 4.4
Create a png image with name below
resize it to 57x57 using from command prompt (terminal):
sips -z 57 57 icon.png
Drag and drop to the project by clicking on the target, opening the summary panel, and dragging and dropping to the app icon section.
Will test this with other image file names, sizes, and formats, but for now, this works
Sunday, August 21, 2011
Click on Element within a Frame using AHK
The syntax is tricky and threw me off this project for months. I finally have cleared it up, and here it is for posterity:
The syntax for plain javascript, executable from internet explorer DebugBar v5.4.1 is:
document.parentWindow.actualframename.document.getElementByID("actualID").click()
In distinction, the syntax for AHK COM SCRIPTS is:
COM_Invoke(pwb, "document.parentWindow.actualframename.document.getElementByID[actualID].click")
NOTICE (I usually don't shout, but in this case I will make an exception): THE ARGUMENT OF getElementById IN JAVASCRIPT IS ENCLOSED IN PARENTHESES AND QUOTES. THE SAME ARGUMENT IN AHK IS ENCLOSED INSTEAD IN BRACKETS AND NO QUOTES. ALSO THE METHOD IN JAVASCRIPT HAS PARENTHESES AFTER IT click() WHEREAS IN AHK IT DOES NOT click (THE REASON FOR THESE DIFFERENCES IS THE AHK COM_Invoke FUNCTION, WHICH REQUIRES ARGUMENTS CONTAINED IN PARENTHESES AND QUOTES.)
Also it is worth saying what is the quickest way to find the actual frame name (yes it is the name, not the ID) and the actual element ID (yes ID, not the name). Answer: A magnificent AHK script called iWebBrowser2 Learner Build 2.5, by "Tank, Jethrow, and Sinkfaze" of the AHK forum. Just hover over the element until it has a red box around it, and read the answer in the dialog box.
More info can be found at these forum posts: (primer on COM functions, and link to the all-important GetWebBrowser() function the COM functions depend on)
http://www.autohotkey.com/forum/topic51020.html
http://www.autohotkey.com/forum/topic24930.html
Thank you Sean, Tank, Jethrow, and Sinkfaze, whoever you are.
The syntax for plain javascript, executable from internet explorer DebugBar v5.4.1 is:
document.parentWindow.actualframename.document.getElementByID("actualID").click()
In distinction, the syntax for AHK COM SCRIPTS is:
COM_Invoke(pwb, "document.parentWindow.actualframename.document.getElementByID[actualID].click")
NOTICE (I usually don't shout, but in this case I will make an exception): THE ARGUMENT OF getElementById IN JAVASCRIPT IS ENCLOSED IN PARENTHESES AND QUOTES. THE SAME ARGUMENT IN AHK IS ENCLOSED INSTEAD IN BRACKETS AND NO QUOTES. ALSO THE METHOD IN JAVASCRIPT HAS PARENTHESES AFTER IT click() WHEREAS IN AHK IT DOES NOT click (THE REASON FOR THESE DIFFERENCES IS THE AHK COM_Invoke FUNCTION, WHICH REQUIRES ARGUMENTS CONTAINED IN PARENTHESES AND QUOTES.)
Also it is worth saying what is the quickest way to find the actual frame name (yes it is the name, not the ID) and the actual element ID (yes ID, not the name). Answer: A magnificent AHK script called iWebBrowser2 Learner Build 2.5, by "Tank, Jethrow, and Sinkfaze" of the AHK forum. Just hover over the element until it has a red box around it, and read the answer in the dialog box.
More info can be found at these forum posts: (primer on COM functions, and link to the all-important GetWebBrowser() function the COM functions depend on)
http://www.autohotkey.com/forum/topic51020.html
http://www.autohotkey.com/forum/topic24930.html
Thank you Sean, Tank, Jethrow, and Sinkfaze, whoever you are.
Saturday, January 8, 2011
Transparent Images for FPDF
This post is really to help me remember the layers of FPDF class extensions I am using.
Remember that FPDF is a class defined in the fpdf.php file and contains many useful functions for manipulating pdf files. These functions can be called by the syntax
$pdfobject->function();
class FPDF_TPL extends FPDF
class FPDI extends FPDF_TPL
class AlphaPDF extends FPDI
The AlphaPDF class (alphapdf.php) is a small script courtesy of Martin Hall-May and is found at
http://www.fpdf.de/downloads/addons/74/
It was originally written as an extension of FPDF but I modified it to be an extension of FPDI so that my pdfobject can call functions both for purposes of importing PDF images, and superimposing gif images using the marvelous SetAlpha() function, as described below
// alpha: real value from 0 (transparent) to 1 (opaque)
// bm: blend mode, one of the following:
// Normal, Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn,
// HardLight, SoftLight, Difference, Exclusion, Hue, Saturation, Color, Luminosity
function SetAlpha($alpha, $bm='Normal')
Remember that FPDF is a class defined in the fpdf.php file and contains many useful functions for manipulating pdf files. These functions can be called by the syntax
$pdfobject->function();
class FPDF_TPL extends FPDF
class FPDI extends FPDF_TPL
class AlphaPDF extends FPDI
The AlphaPDF class (alphapdf.php) is a small script courtesy of Martin Hall-May and is found at
http://www.fpdf.de/downloads/addons/74/
It was originally written as an extension of FPDF but I modified it to be an extension of FPDI so that my pdfobject can call functions both for purposes of importing PDF images, and superimposing gif images using the marvelous SetAlpha() function, as described below
// alpha: real value from 0 (transparent) to 1 (opaque)
// bm: blend mode, one of the following:
// Normal, Multiply, Screen, Overlay, Darken, Lighten, ColorDodge, ColorBurn,
// HardLight, SoftLight, Difference, Exclusion, Hue, Saturation, Color, Luminosity
function SetAlpha($alpha, $bm='Normal')
Thursday, January 6, 2011
More on using MacBook Pro (Snow Leopard) as a Server
You can actually turn a MBP into a WiFi hot spot with the built-in software. Here's the trick:
System Preferences -> Sharing -> Internet Sharing checkbox -> Share your connection from Ethernet
You see AirPort pop up as an option. Click it and click on Airport Options and VIOLA you can configure your MBP to be a router!
You can create a network name, a password, and select level of encryptation. Remember to activate the Internet Sharing checkbox again at the end to "start" the WiFi hotspot.
This was designed to allow you to pipe your ethernet broadband internet connection wirelessly to other devices in the neighborhood, the great thing is even if you do NOT have the ethernet port connected to anything, it will still broadcast a WiFi signal and you can use the local computer name (name.local:8888) to browse to the MAMP server in the MBP.
Why would anyone want to do this? The answer is sometimes you want to browse to the server on a handheld device, even when you are not connected to a local WiFi hotspot. One way is to leave the server behind, at a hotspot, and browse to it using 3G, using methods described previously. But NOW, even if you have a WiFi ONLY device such as an iPod or iPad that doesn't have 3G, if you bring the server with you, you can still run your server scripts on the handheld.
The only problem being: even with the MBP lid closed? The answer is yup, but you have to run a free software called InsomniaX to keep the MBP running even with the lid closed.
Remember, Airport can only go one way at a time. You gotta turn off Internet Sharing to restore Airport to a receiver (instead of a transmitter) once you use it. Crazy.
System Preferences -> Sharing -> Internet Sharing checkbox -> Share your connection from Ethernet
You see AirPort pop up as an option. Click it and click on Airport Options and VIOLA you can configure your MBP to be a router!
You can create a network name, a password, and select level of encryptation. Remember to activate the Internet Sharing checkbox again at the end to "start" the WiFi hotspot.
This was designed to allow you to pipe your ethernet broadband internet connection wirelessly to other devices in the neighborhood, the great thing is even if you do NOT have the ethernet port connected to anything, it will still broadcast a WiFi signal and you can use the local computer name (name.local:8888) to browse to the MAMP server in the MBP.
Why would anyone want to do this? The answer is sometimes you want to browse to the server on a handheld device, even when you are not connected to a local WiFi hotspot. One way is to leave the server behind, at a hotspot, and browse to it using 3G, using methods described previously. But NOW, even if you have a WiFi ONLY device such as an iPod or iPad that doesn't have 3G, if you bring the server with you, you can still run your server scripts on the handheld.
The only problem being: even with the MBP lid closed? The answer is yup, but you have to run a free software called InsomniaX to keep the MBP running even with the lid closed.
Remember, Airport can only go one way at a time. You gotta turn off Internet Sharing to restore Airport to a receiver (instead of a transmitter) once you use it. Crazy.
Subscribe to:
Posts (Atom)