How to round corners and create a border for a TextView or EditText

Step one 

Create a Android Resource Directory called drawables within the res file if you don’t already have one.

Step two

Make a new xml page called whatever you like. I called mine rounded_corner_background.

Step three

Within the xml page you have just created add:

<?xml version="1.0" encoding="UTF-8"?>
 <shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#ffffffff"/> <!--Background color-->
    <corners android:radius="5px"/>
    <stroke android:width="1dip" android:color="#000"/> <!--outline stroke -->
    <padding android:left="0dp" android:top="0dp" android:right="0dp" android:bottom="0dp" />
</shape>

Aligning buttons to the bottom/footer of the page easily Android

A simple easy way to buttons at the bottom of the screen is to place them in a layout which would then be set to android:layout_alignParentBottom=”true”. 

If placed inside a container it enables them to exist ever if other content is trying to push them off. 

An example of this is: 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true" />

    <LinearLayout
        android:id="@+id/removeAllButtonLayoutAndCreateGroup"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:weightSum="4"
        android:layout_alignParentBottom="true">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Bye"
            android:id="@+id/byeText"
            android:textColor="@android:color/holo_red_dark"
            android:textSize="22sp"
            android:clickable="true"
            android:layout_marginBottom="5dp"
            android:layout_marginLeft="60dp"
            android:layout_gravity="right" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hello"
            android:id="@+id/helloText"
            android:textColor="@android:color/black"
            android:textSize="22sp"
            android:clickable="true"
            android:layout_marginBottom="5dp"
            android:singleLine="false"
            android:layout_marginLeft="150dp" />

    </LinearLayout>

</RelativeLayout>

Beginning SQLite in Android

My first assumption of SQLite in Android was, there is a lot of code to do very little. Once you get started though its quite easy.

I’m going to step through how to set up the database connection initially and insert and delete some data from it.

CLICK HERE FOR COMPLETE PROJECT
Within the complete project I have provided examples of how to use the methods which are created bellow.

SETTING UP DATABASE CLASS

1. Create a database class and make it extend SQLiteOpenHelper

2. Create a variable for the database version, something like this:

private static final int DATABASE_VERSION = 1;

3. Give you database a name:

private static final String DATABASE_NAME = “imAnExample”;

4. Create your tables names. You can have as many as you like. Within this example I am only going to have one table.

private static final String TABLE_VEGETABLES = “vegetables”;

5. Now create your columns for the tables:

private static final String KEY_ID = “id”;
private static final String KEY_VEG_TYPE = “type”;

6. Create the constructor for the class it should look something like:

public DatabaseConnection(Context context)
{
   super(context, DATABASE_NAME, null, DATABASE_VERSION);
}

7. Creating the tables in the onCreate method. This is where we will be setting up the columns to use and and key etc. It should look something like:

@Override
public void onCreate(SQLiteDatabase sqLiteDatabase)
{
   String CREATE_VEGETABLES_TABLE = "CREATE TABLE " + TABLE_VEGETABLES + "("
                + KEY_ID + " INTEGER PRIMARY KEY," + KEY_VEG_TYPE + " TEXT" + ")";
   sqLiteDatabase.execSQL(CREATE_VEGETABLES_TABLE);
}

8. If the database is upgraded and you don’t want to keep any of the existing content add in a method similar to this:

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
{
  db.execSQL("DROP TABLE IF EXISTS " + TABLE_VEGETABLES);
  onCreate(db);
}

Before I continue with this class. I am going to first make a class to retain the data before it is inserted into the database. This is just simply a class of setter and getter methods. e.g. for this example there should be one method for getting/setting the id and one for getting/setting the vegetable name. This class can be found within the complete example.

ADDING/REMOVING/RETURNING ALL FROM THE DATABASE

9. Adding a new vegetable to the database. In this example I have not specified an id, by not doing this the database will take care of it.

// Adding new vegetable to the table
void addVegetable(GettingVegetableData vegetableData)
{
  SQLiteDatabase db = this.getWritableDatabase();

  ContentValues values = new ContentValues();
  values.put(KEY_VEG_TYPE, vegetableData.getVegetableName()); // vegetable Name
 
  // Inserting Row
  db.insert(TABLE_VEGETABLES, null, values);
  db.close(); // Closing database connection
}

10. Returning all of the vegetables in a list from the database.


// Getting All vegetables
public List gettingVegetableDataList()
{
     List listOfVegetables = new ArrayList();
     // Select All Query
     String selectQuery = "SELECT  * FROM " + TABLE_VEGETABLES;

     SQLiteDatabase db = this.getWritableDatabase();
        Cursor cursor = db.rawQuery(selectQuery, null);

      // looping through all rows and adding to list
      if (cursor.moveToFirst())
      {
           do
           {
               GettingVegetableData vegetableData = new GettingVegetableData();
               vegetableData.setId(Integer.parseInt(cursor.getString(0)));
               vegetableData.setVegetableName(cursor.getString(1));

               // Adding vegetableData to list
               listOfVegetables.add(vegetableData);
           }
           while (cursor.moveToNext());
      }

      // return contact list
      return listOfVegetables;
}

11. There is two possible ways in order to delete a vegetable from the database. By its ID or its name. I have shown the two ways bellow: 

// Deleting single vegetable by id
public void deleteVegetableByID(int id)
{
      SQLiteDatabase db = this.getWritableDatabase();
      db.delete(TABLE_VEGETABLES, KEY_ID + "= " + id, null);
      db.close();
}

// Deleting single vegetable by name
public void deleteVegetableByName(String name)
{
      SQLiteDatabase db = this.getWritableDatabase();
      db.delete(TABLE_VEGETABLES, KEY_VEG_TYPE + "= " + name, null);
      db.close();
}

University Project – The Egg Shop Website

This was a simple project in university where we had to create a website to demonstrate what we had learnt in the second semester. I and two others formed a group and this was what we came up with. The website graphics etc weren’t concentrated on as this wasn’t what we where going to be marked on.

Some things which we included:

– Use a MySQL database.
– Password hashing, when the user created a user login.
– AJAX search for shop location.
– Shopping cart.

Take a look here

4 Weeks into my placement now!

I’ve now been working at my placement company a month which is pretty hard to believe! So far I am really enjoying it. I’ve been working on an Android App which I have now completed, I’m quite pleased with the way it turned out because a lot of the things I wasn’t sure if I was going to be able to complete on my own but somehow I managed it!

The next project I am going to be working on is another Android App. So I am looking forward to that.

2D Unity Game – Dino Roll

For a few weeks in university, within my games module we where given the opportunity to develop a 2D game on Unity. It was really great as we where also developing a 3D one at the same time. It was a fantastic opportunity to be able to explore the different features the engine offers, I can’t wait do work on more stuff within it in the future.

The game I created was fairly simple, as I didn’t have long to do it.

Take a look here

Back again after a while!

I haven’t managed to make a blog post in months unfortunately! however, now that I am done with University I have more time on my hands and have decided to take up blogging again.

Over the past few months I’ve been doing a range of projects within University, these include 2D and 3D games both made on Unity I’ll post these within a few days. I also completed a web project which was quite simple, the theme was Easter.

I have also began my placement year working at a local app development company within Belfast, which is very exciting.

Bit Manipulation Variable Swapping – Java

A simple program which uses bit manipulation to swap out the variables. A benefit of this solution is that it works for more data types than just integers. The code words by using XORs.

 

public class BitManipulationVariableSwapping 
{
    public static void swap_opt(int a, int b)
    {
        a = a^b;
        b = a^b;
        a = a^b;

        System.out.println("a:" + a);

        System.out.println("B:" + b);

    }//swap

    public static void main(String [] args)
    {
        swap_opt(100, 200);
    }//main
}//class

Matching Brackets in the expression – C++

This was an extra programming exercise within university that I completed not so long ago. It was a Microsoft interview question also. I chose to implement it in c++.

The actual question which I was presented with:

Question

#include <iostream>
#include <string>
#include <stack>

using namespace std;

//setting up the stack
stack<char> stacking;

void printMyInfo()
{
	cout<<"***************************************"<<endl;
	cout<<"* Student Name: Zara McKeown          *"<<endl;
	cout<<"* Registration:                       *"<<endl;
	cout<<"* Course: Data Structures             *"<<endl;
	cout<<"***************************************"<<endl<<endl;
}//printMyInfo

int checkBraces(char *characters)
{
    // Continues to push or pop using a for loop
    // \0 means null termination character
    for (int i = 0; characters[i] != '\0'; i++)
    {
        //seeing if the current character is a ( bracket
        if(characters[i] == '(')
        {
            //pushing the character into the stack
            stacking.push(characters[i]);
        }//if
        
        //seeing if the current character is a { bracket
        else if(characters[i] == '{')
        {
            //pushing the character into the stack
            stacking.push(characters[i]);
        }//else if
        
        //seeing if the current character is a [ bracket
        else if(characters[i]=='[')
        {
            //pushing the character into the stack
            stacking.push(characters[i]);
        }//else if
        
        //Checking to see if the next character is ) bracket
        else if(characters[i] == ')')
        {
            //making sure there is something in the stack already
            //if not it returns false
            if(stacking.empty())
            {
                cout << "0";
                return false;
                
            }//if
            
            //checking to see if there if the last thing added to the stack was an ( bracket
            else if(stacking.top() == '(')
            {
                //because the program has found a match. It now can remove the ( bracket.
                // So it can move onto the next if there is one.
                stacking.pop();
                
            }//else if
            
            //if the ( bracket is not found it will then return false.
            else
            {
                cout << "0";
                return false;
            }//else
        }//else if
        
        
        //Checking to see if the next character is } bracket
        else if(characters[i] == '}')
        {
            //making sure there is something in the stack already
            //if not it returns false
            if(stacking.empty())
            {
                
                cout << "0";
                return false;
            }//if
            
            //checking to see if there if the last thing added to the stack was an { bracket
            else if(stacking.top() == '{')
            {
                //because the program has found a match. It now can remove the ( bracket.
                // So it can move onto the next if there is one.
                stacking.pop();
                
            }//else if
            
            //if the { bracket is not found it will then return false.
            else
            {
                cout << "0";
                return false;
            }//else
        }//else if
        
        
        //Checking to see if the next character is ] bracket
        else if(characters[i] == ']')
        {
            //making sure there is something in the stack already
            //if not it returns false
            if(stacking.empty())
            {
                cout << "0";
                return false;
            }//if
            
            //checking to see if there if the last thing added to the stack was an [ bracket
            else if(stacking.top() == '[')
            {
                //because the program has found a match. It now can remove the [ bracket.
                // So it can move onto the next if there is one.
                stacking.pop();
                
            }//else if
            
            //if the [ bracket is not found it will then return false.
            else
            {
                cout << "0";
                return false;
            }//else
        }//else if
        
    }//for
    
    cout << "1";
    return true;

}//int

int main()
{
    char str1[] = "{1+[2+(3+4)]}";
    
    char str2[] = "{(3+5)-[2*1]}";
    
    char str3[] = "{3+5}-[2+1]";
    
    char str4[] ="(2+[3+5)+1]";
    
    char str5[] ="";
    
    printMyInfo();
    
    cout << "This program checks braces ([{}])" << endl;
    
    cout << endl;

    cout << "Are all the braces matching in the expression " << str1 << "? :";

    checkBraces(str1);
    
    cout << endl;
    
    cout << "Are all the braces matching in the expression " << str2 << "? :";

    checkBraces(str2);
    
    cout << endl;
    
    cout << "Are all the braces matching in the expression " << str3 << "? :";

    checkBraces(str3);
    
    cout << endl;

    cout << "Are all the braces matching in the expression " << str4 << "? :";

    checkBraces(str4);
    
    cout << endl;
    
    cout << "Are all the braces matching in an empty expression " << "? :";
    
    checkBraces(str5);
    
    cout << endl;
    
    cout<<endl<<"Program terminated."<<endl;//have these two lines before "return 0;"
    system("pause");//press any key to close the black screen

    return 0;
}//main