Sunday, July 6, 2014

Cornboyz Video 8 - Correct Syntax and Code

It took a few iterations to get the code correct.  Looking at the comments, other people seemed to have similar issues.  Here is the code for the various java classes and xml docs.

Realized that I added some code from the next lesson on playing the mp3 file.

myMain.java

package com.mikeyj777.trial2;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;

public class myMain extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);

//oddly enough, having more than just the activity and bundle imports causes issues with setContentView, so you may have to remove the other import statements, clean the project, add this line, and then re-add the import statements.

MediaPlayer mpSplash = MediaPlayer.create(this, R.raw.bootybounce);
mpSplash.start();

Thread logoTimer = new Thread() {
public void run() {
try{
int logoTimer = 0;
while(logoTimer < 5000) {
sleep(100);
logoTimer = logoTimer + 100;
};
startActivity(new Intent("com.mikeyj777.trial2.CLEARSCREEN"));
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

finally{
finish();
}
}
};
logoTimer.start();
}

@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
}

@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
}

@Override
protected void onResume() {
// TODO Auto-generated method stub
super.onResume();
}

@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
}

@Override
protected void onStop() {
// TODO Auto-generated method stub
super.onStop();
}
 
}

myMenu.java

package com.mikeyj777.trial2;

import android.app.Activity;
import android.os.Bundle;

public class myMenu2 extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}



}

layouts

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/bkgrng"
    android:orientation="vertical" >

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="@string/hello" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="blah" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/title" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Click Me"
        android:textSize="25dp"
        android:textStyle="bold" />

    <Button
        android:id="@+id/ClickMe2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Click Me 2" android:textSize="25dp" android:textStyle="bold"/>

</LinearLayout>

splash.xml (splash screen picture is named "newer")

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
    
    <ImageView
        android:src="@drawable/newer"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    />
       

</LinearLayout>

Android Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mikeyj777.trial2"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk android:minSdkVersion="8" />

    <application
        android:icon="@drawable/trashy"
        android:label="@string/app_name" >
        <activity
            android:name=".myMain"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        
        <activity
            android:name=".myMenu2"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.mikeyj777.trial2.CLEARSCREEN" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        
    </application>

</manifest>

No comments:

Post a Comment