Wednesday, 8 September 2010

Firefox Browser Gaming Competition

Firefox LogoThe Mozilla foundation is sponsoring a browser based gaming competition. Details from Mashable.



This a great idea. It will make a lot more developers aware of what is possible in a modern browser. Plus we should get some cool games out of it. :)

Detect Battery Info.

In the last exercise "Detect Battery Level", the app simple detect the battery level only. It's modified to have more info to be displayed, include: battery level, voltage, temperature, technology, charging status, and health of the battery.

Detect Battery Info.

main.xml
<?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"
/>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Battery Info."
/>
<TextView
android:id="@+id/batterylevel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Battery Level:"
/>
<TextView
android:id="@+id/batteryvoltage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Battery Voltage:"
/>
<TextView
android:id="@+id/batterytemperature"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Battery Temperature:"
/>
<TextView
android:id="@+id/batterytechology"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Technology:"
/>
<TextView
android:id="@+id/batterystatus"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Status:"
/>
<TextView
android:id="@+id/batteryhealth"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Health:"
/>
</LinearLayout>


AndroidBattery.java
package com.exercise.AndroidBattery;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.BatteryManager;
import android.os.Bundle;
import android.widget.TextView;

public class AndroidBattery extends Activity {

private TextView batteryLevel, batteryVoltage, batteryTemperature,
batteryTechnology, batteryStatus, batteryHealth;


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

batteryLevel = (TextView)findViewById(R.id.batterylevel);
batteryVoltage = (TextView)findViewById(R.id.batteryvoltage);
batteryTemperature = (TextView)findViewById(R.id.batterytemperature);
batteryTechnology = (TextView)findViewById(R.id.batterytechology);
batteryStatus = (TextView)findViewById(R.id.batterystatus);
batteryHealth = (TextView)findViewById(R.id.batteryhealth);

this.registerReceiver(this.myBatteryReceiver,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
}

private BroadcastReceiver myBatteryReceiver
= new BroadcastReceiver(){

@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub

if (arg1.getAction().equals(Intent.ACTION_BATTERY_CHANGED)){
batteryLevel.setText("Level: "
+ String.valueOf(arg1.getIntExtra("level", 0)) + "%");
batteryVoltage.setText("Voltage: "
+ String.valueOf((float)arg1.getIntExtra("voltage", 0)/1000) + "V");
batteryTemperature.setText("Temperature: "
+ String.valueOf((float)arg1.getIntExtra("temperature", 0)/10) + "c");
batteryTechnology.setText("Technology: " + arg1.getStringExtra("technology"));

int status = arg1.getIntExtra("status", BatteryManager.BATTERY_STATUS_UNKNOWN);
String strStatus;
if (status == BatteryManager.BATTERY_STATUS_CHARGING){
strStatus = "Charging";
} else if (status == BatteryManager.BATTERY_STATUS_DISCHARGING){
strStatus = "Dis-charging";
} else if (status == BatteryManager.BATTERY_STATUS_NOT_CHARGING){
strStatus = "Not charging";
} else if (status == BatteryManager.BATTERY_STATUS_FULL){
strStatus = "Full";
} else {
strStatus = "Unknown";
}
batteryStatus.setText("Status: " + strStatus);

int health = arg1.getIntExtra("health", BatteryManager.BATTERY_HEALTH_UNKNOWN);
String strHealth;
if (health == BatteryManager.BATTERY_HEALTH_GOOD){
strHealth = "Good";
} else if (health == BatteryManager.BATTERY_HEALTH_OVERHEAT){
strHealth = "Over Heat";
} else if (health == BatteryManager.BATTERY_HEALTH_DEAD){
strHealth = "Dead";
} else if (health == BatteryManager.BATTERY_HEALTH_OVER_VOLTAGE){
strHealth = "Over Voltage";
} else if (health == BatteryManager.BATTERY_HEALTH_UNSPECIFIED_FAILURE){
strHealth = "Unspecified Failure";
} else{
strHealth = "Unknown";
}
batteryHealth.setText("Health: " + strHealth);

}
}

};
}


Download the files.

Related Article:
- Home Screen Battery Widget



Tuesday, 7 September 2010

TinyUmbrella - New Updates with 4.1 looming...

EDIT: I just got a report of someone getting their baseband updated even though the protection was in place. DO NOT UPDATE to 4.1 unless you absolutely have to. I need to look at what happened in this case.





Let me preface this by saying that it is important that you do not update to 4.1 if you wish to keep your unlock and jailbreak.

I've updated TinyUmbrella in anticipation of the imminent release of iOS 4.1. Here are some notable features. (Sorry I have not finished the changes I mentioned previously as these features I felt were VERY important with 4.1 coming)

  • Baseband Protection - Updating to 4.1 using TinyUmbrella will protect your baseband from update. THIS ONLY APPLIES TO IPHONE 4!!!!! If you have a 3G or 3GS and you update to 4.1 your baseband will likely be updated.

  • SHSH Retrieval from Cydia - If you don't have your SHSH locally, TinyUmbrella will request them from Cydia on-demand; allowing the restore to continue

  • Automatically point hosts to Cydia - Once you close TinyUmbrella, it points your hosts file to Cydia (for further baseband protection and update/restores without TinyUmbrella)

I hope it helps.

EDIT: I've also added iPod Touch 4G 4.1 support :)

Detect Battery Level

It's a exercise of Android App to detect battery level.

Detect Battery Level

A BroadcastReceiver, myBatteryReceiver, is implemented and registered to receive ACTION_BATTERY_CHANGED, and retrieve "level" via getIntExtra() method.

main.xml

<?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"
/>
<TextView
android:id="@+id/batterylevel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Battery Level:"
/>
</LinearLayout>


AndroidBattery.java
package com.exercise.AndroidBattery;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.widget.TextView;

public class AndroidBattery extends Activity {

private TextView batteryLevel;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

batteryLevel = (TextView)findViewById(R.id.batterylevel);
this.registerReceiver(this.myBatteryReceiver,
new IntentFilter(Intent.ACTION_BATTERY_CHANGED));
}

private BroadcastReceiver myBatteryReceiver
= new BroadcastReceiver(){

@Override
public void onReceive(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
int bLevel = arg1.getIntExtra("level", 0);

batteryLevel.setText("Battery Level: "
+ String.valueOf(bLevel) + " %");
}

};
}


Download the files.

Related Article: Detect Battery Info.

Monday, 6 September 2010

PHP: Call to a member function on a non-object

PHP LogoRan across a PHP thinking in Java problem today. Say you have some code like this:



class MyClass{
private $myObject;

public function MyClass(){
$myObject = new MyObject()
}

}
As soon as the $myObject variable is accessed the following error is thrown: Call to a member function on a non-object.



What?????



This is PHP not Java nimrod. :) $myObject is not getting initialized because the syntax is incorrect. Try this:

class MyClass{
private $myObject;

public function MyClass(){
$this->myObject = new MyObject()
}

}
That should fix it right up. This sort of stuff always happens to me as I bounce between languages. lol.

Friday, 3 September 2010

iOS 4.1 and iTunes 10

Although it may be tempting to update to iOS 4.1 when it comes out, make sure you pay heed to the Dev Team warnings.



  1. iOS 4.1 is not currently jailbroken - you WILL lose your jailbreak

  2. iOS 4.1 contains a new baseband - you WILL lose your carrier unlock as provided by ultrasn0w.

  3. If you ignore the warning and update to 4.1, you can downgrade to whatever version you have SHSH for (either locally or on-file at Cydia. So if TinyUmbrella shows SHSH for 4.0.1, you can downgrade to that version. That said - you cannot downgrade your baseband /ever/. Once you update to a firmware with a new baseband, you are stuck on that baseband regardless of firmware downgrade.

I plan on supporting iOS 4.1 when it is released and hopefully I'll have the UI changes as well as the rare PPC / crash issues worked out.
I've taken a quick look at iTunes 10 and don't see any immediate issues with local restores but as always, please hold off on updating to new versions of iTunes unless you absolutely have to have a feature it provides.

Thursday, 2 September 2010

Copy and Paste using ClipboardManager

ClipboardManager is a interface to the clipboard service, for placing and retrieving text in the global clipboard.

You do not instantiate this class directly; instead, retrieve it through getSystemService(String).

Copy and Paste using ClipboardManager

main.xml

<?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"
/>
<EditText
android:id="@+id/src"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/dest"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="@+id/copynpaste"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Copy'n Paste"
/>
</LinearLayout>


AndroidCopynPaste.java
package com.exercise.AndroidCopynPaste;

import android.app.Activity;
import android.os.Bundle;
import android.text.ClipboardManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class AndroidCopynPaste extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

final EditText src = (EditText)findViewById(R.id.src);
final TextView dest = (TextView)findViewById(R.id.dest);
Button copynPaste = (Button)findViewById(R.id.copynpaste);

final ClipboardManager clipBoard = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);

copynPaste.setOnClickListener(new Button.OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
clipBoard.setText(src.getText());
dest.setText(clipBoard.getText());

}});
}
}



Download the files.