Thursday, December 27, 2012

Increment certain values in an ArrayList.

I needed to add 1 to certain values in an ArrayList and this was the only way I could figure it out easily.
ArrayList<Integer> q3=new ArrayList<Integer>();
q3.add(4); /// Populate the arraylist
q3.add(6);
q3.add(10);
q3.set(1,((q3.get(1)+1))); ///adds 1 to the current location
view raw gistfile1.txt hosted with ❤ by GitHub

It is basically calling to set q3 at location 1 with the former q3 value +1.  IN this case 6+1=7;

Sunday, December 23, 2012

SQLite Android and Variables

While working on a project I recently realized I was going to have to learn, or try, to save to a database.  I trolled hundreds of samples and examples and after a while got a grasp.  The thing that stumped me hard was if I wanted to implement a variable in the mix, or two, or an ArrayList.

Here is a brief synopsis should you encounter it.

Here  is the easy way to iterate some of a db with a ListArray.  Notice the "  These are the crucial differences from being in sql and not.

public void insertIntoTable(){
try{
myDB = openOrCreateDatabase(DBTeam, Context.MODE_PRIVATE,null);
///////Iterate the db with List Arrays
for (int i = 0; i < playerNames.size(); i++) {
myDB.execSQL("INSERT INTO " + TABLE + "(PNUMBER,NAME,NUMBER1 ,NUMBER2) VALUES('" +playerNumbers.get(i)+"','"+playerNames.get(i)+"','1','0')");
Log.d("-----",""+playerNames.get(i));////Testing proof they were working
}///End For Loop
Toast.makeText(this, "Database filled", Toast.LENGTH_LONG).show();
myDB.close();
}catch(Exception e){
Toast.makeText(this, "Error in inserting into table", Toast.LENGTH_LONG).show();
}
}
view raw gistfile1.txt hosted with ❤ by GitHub


Here is the way to update something with a variable.  BOTH ways work, just showing them.  I am basically adding a certain id # and location with the variable and updating it.  In this case TWOS is an integer.
public void updateTable(){
int idnum=1;
int idnum2=4;
int tests=3;
try{
mydb = openOrCreateDatabase(DBTeam, Context.MODE_PRIVATE,null);
mydb.execSQL("UPDATE " + TABLE + " SET TWOS = TWOS+"+tests+" WHERE ID ="+ idnum);
mydb.execSQL("UPDATE " + TABLE + " SET TWOS = TWOS+'"+tests+"' WHERE ID ="+ idnum2);
mydb.close();
}catch(Exception e){
Toast.makeText(getApplicationContext(), "OH crap, so sad", Toast.LENGTH_LONG);
}
}
view raw gistfile1.txt hosted with ❤ by GitHub



Sunday, December 2, 2012

Vector Candle Flame Tutorial (sort of)

Today while tinkering with an app, I really needed a flame with alpha. After snapping a suitable picture I decided to use Fireworks to make one. After the fact I realized it was really very simple. 








 STEP 1: Take 2 circles and draw them. Next shape one like an oblong oval for the main part of the flame. Next, form the bottom to an oval and use the subselection tool form the top of that oval to match the bottom of the top oval.  








STEP 2: Carefully place them together and adjust the gradient and alpha accordingly. 













STEP 3I placed a white square around the wick so you could see the detail.  I basically drew a square and used the reshape area tool to make it kind of rough.  I also added a little texture and adjusted the gradient.  The sort of ember on the top is just a distorted shape I used and added a circle gradient in the center of it.  When you place them all together you have the final product above!