theblaine.com

Here's my little spot on the Net

Unfinished Posts

Posted by theBlaine July - 31 - 2011 - Sunday ADD COMMENTS

All the posts in this category are unfinished. Currently they are just lines of code with no explanation other than the post title. When I get time I will go back through all these posts and thoroughly comment them. ~ Blaine

SharedPreferences Sample

Posted by theBlaine July - 29 - 2011 - Friday ADD COMMENTS
import android.content.SharedPreferences;
SharedPreferences settings = getSharedPreferences(GAME_PREFERENCES, MODE_PRIVATE);
String lastLaunch = "First launch";
if (settings.contains("lastLaunch") == true)
	lastLaunch = settings.getString("lastLaunch", lastLaunch);
String currentTime = (String) DateFormat.format("yyyy-MM-dd hh:mm:ss", new Date());
SharedPreferences.Editor prefEditor = settings.edit();
prefEditor.putString("lastLaunch", currentTime);
prefEditor.commit();

Sample Get Current Date and Time to String

Posted by theBlaine July - 29 - 2011 - Friday ADD COMMENTS
import java.util.Date;
import android.text.format.DateFormat;

 

String currentTime = (String) DateFormat.format("yyyy-MM-dd hh:mm:ss", new Date());

Sample Layout File

Posted by theBlaine July - 29 - 2011 - Friday ADD COMMENTS
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    android:textColor="@color/text_top_color"
	android:textSize="@dimen/text_top_size"
    />
<TextView
	android:layout_width="fill_parent"
	android:layout_height="wrap_content"
	android:text="@string/moretext"
	/>
<ImageView
	android:layout_width="wrap_content"
	android:layout_height="wrap_content"
	android:src="@drawable/computer"
/>
</LinearLayout>

Sample arrays.xml File

Posted by theBlaine July - 29 - 2011 - Friday ADD COMMENTS
<?xml version="1.0" encoding="utf-8"?>
<resources>
   <array name="difficulty">
      <item>@string/easy_label</item>
      <item>@string/medium_label</item>
      <item>@string/hard_label</item>
   </array>	

   <array name="languages">
      <item>Bulgarian (bg)</item>
      <item>Chinese Simplified (zh-CN)</item>
      <item>Chinese Traditional (zh-TW)</item>
      <item>Catalan (ca)</item>
      <item>Croatian (hr)</item>
      <item>Czech (cs)</item>
      <item>Danish (da)</item>
      <item>Dutch (nl)</item>
      <item>English (en)</item>
      <item>Filipino (tl)</item>
      <item>Finnish (fi)</item>
      <item>French (fr)</item>
      <item>German (de)</item>
      <item>Greek (el)</item>
      <item>Indonesian (id)</item>
      <item>Italian (it)</item>
      <item>Japanese (ja)</item>
      <item>Korean (ko)</item>
      <item>Latvian (lv)</item>
      <item>Lithuanian (lt)</item>
      <item>Norwegian (no)</item>
      <item>Polish (pl)</item>
      <item>Portuguese (pt-PT)</item>
      <item>Romanian (ro)</item>
      <item>Russian (ru)</item>
      <item>Spanish (es)</item>
      <item>Serbian (sr)</item>
      <item>Slovak (sk)</item>
      <item>Slovenian (sl)</item>
      <item>Swedish (sv)</item>
      <item>Ukrainian (uk)</item>
   </array>
</resources>

Sample colors.xml File

Posted by theBlaine July - 29 - 2011 - Friday ADD COMMENTS
<?xml version="1.0" encoding="utf-8"?>
<resources>
	<color name="text_top_color">#00ff00</color>
	<color name="test_color">#FF0000</color>
</resources>

Sample dimens.xml File

Posted by theBlaine July - 29 - 2011 - Friday ADD COMMENTS
<?xml version="1.0" encoding="utf-8"?>
<resources>
	<dimen name="text_top_size">22pt</dimen>
</resources>

Sample strings.xml File

Posted by theBlaine July - 29 - 2011 - Friday ADD COMMENTS
<?xml version="1.0" encoding="utf-8"?>
<resources>
	<color name="text_top_color">#00ff00</color>
	<color name="test_color">#FF0000</color>
</resources>

Sample AndroidManifest.xml File

Posted by theBlaine July - 29 - 2011 - Friday 4 COMMENTS
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.sample.someapp"
      android:versionCode="1"
      android:versionName="1.0">
    <uses-sdk android:minSdkVersion="7" />

    <uses-permission android:name="android.permission.CAMERA"></uses-permission>

    <application android:label="@string/app_name" android:description="@string/app_desc"
    	android:icon="@drawable/quizicon" android:debuggable="true">
        <activity android:name=".QuizSplashActivity"
                  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="QuizMenuActivity"></activity>
        <activity android:name="QuizHelpActivity"></activity>
        <activity android:name="QuizScoresActivity"></activity>
        <activity android:name="QuizSettingsActivity"></activity>
        <activity android:name="QuizGameActivity"></activity>

        <activity android:name="About"
        	android:label="@string/about_title"
        	android:theme="@android:style/Theme.Dialog" />
    
        <activity android:name="Prefs"
        	android:label="@string/settings_title" />
        	
        <activity android:name="Game"
        	android:label="@string/game_title" />
        	
        <activity android:name="Keypad"
        	android:label="@string/keypad_title" />

    </application>
</manifest>

Android Log File Sample

Posted by theBlaine June - 11 - 2011 - Saturday ADD COMMENTS
import android.util.Log;

 

private static final String TAG = "Droid1";
Log.i(TAG, "--- Raw stream test ---");

Most Commented

About me

Hi, my name is Blaine Sherman (aka theBlaine). I am a 37 year old Network Administrator by day and a mobile app developer and web app developer at night. I am a proud father of a 16 year old daughter and a mellow cat named Tough Guy. Welcome to my new web site. It is geared towards application development, but will also include tid-bits about my life and my whacky family!! I hope there is at least one thing entertaining or educational you can get from my site. If not, oh well, you will get over it!! Thanks for stopping by my little spot on the Net. ~ Blaine Sherman

Switch to our mobile site