How to send an email via an intent

To send an email it is quite simple. You can add an email body, BCC and CC for example by adding extras.


Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("text/plain");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Email");
startActivity(Intent.createChooser(emailIntent, "Send Email"));

Advertisements

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