Thursday 29 December 2011

Detect multi-touch (for 10 pointers)

It's a example to detect multi-touch on screen. Logically it can detect 10 pointers.

Detect multi-touch

Implement the custom view to detect multi-touch, by overriding onTouchEvent().
package com.exercise.AndroidMultiTouch;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

public class MultiToucnView extends View {

private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);

final int MAX_NUMBER_OF_POINT = 10;
float[] x = new float[MAX_NUMBER_OF_POINT];
float[] y = new float[MAX_NUMBER_OF_POINT];
boolean[] touching = new boolean[MAX_NUMBER_OF_POINT];

public MultiToucnView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init();
}

public MultiToucnView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}

public MultiToucnView(Context context) {
super(context);
init();
}

void init() {
paint.setStyle(Paint.Style.STROKE);
paint.setStrokeWidth(1);
paint.setColor(Color.WHITE);
}

@Override
protected void onDraw(Canvas canvas) {

for(int i = 0; i < MAX_NUMBER_OF_POINT; i++){
if(touching[i]){
canvas.drawCircle(x[i], y[i], 50f, paint);
}
}
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// TODO Auto-generated method stub
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec),
MeasureSpec.getSize(heightMeasureSpec));
}

@Override
public boolean onTouchEvent(MotionEvent event) {
int action = (event.getAction() & MotionEvent.ACTION_MASK);
int pointCount = event.getPointerCount();

for (int i = 0; i < pointCount; i++) {
int id = event.getPointerId(i);

//Ignore pointer higher than our max.
if(id < MAX_NUMBER_OF_POINT){
x[id] = (int)event.getX(i);
y[id] = (int)event.getY(i);

if((action == MotionEvent.ACTION_DOWN)
||(action == MotionEvent.ACTION_POINTER_DOWN)
||(action == MotionEvent.ACTION_MOVE)){
touching[id] = true;
}else{
touching[id] = false;
}
}
}

invalidate();
return true;

}

}


Modify main.xml to include the custom view, com.exercise.AndroidMultiTouch.MultiToucnView.
<?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:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<com.exercise.AndroidMultiTouch.MultiToucnView
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
</LinearLayout>



Download the files.



How to Compile Android from Source Code


Ever wonder how developers on XDA take the source code released to the AOSP and create ROMs? While creating software for your phone isn't as easy as this (you also need lots of drivers), the process for compiling Android isn't that difficult. In this video, Shen tells you about the process.

For the full steps, check out this link: http://bit.ly/sClp20

Tuesday 27 December 2011

Apple TV 4.4.3 support

Sorry I skipped this version. I've updated TU to work with Apple TV 4.4.3. For those of you with Apple TV 2 - be ABSOLUTELY sure you have your 4.4.3 SHSH for your device... It may be QUITE important.





#justsayin

Backward compatibility using Android Support Package

Refer to the last exercise "Honeycomb's tab look of DatePicker", the app is created target API level 11. It can run on device with Android 3.0 or above only. If you want to make it run on early version, you can using Android Compatibility package (or named Android Support Package).

- Refer to the former article to Install and setup Compatibility Package.

- Modify AndroidManifest.xml to add minSdkVersion and targetSdkVersion.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.exercise.AndroidDatePicker"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="11"/>

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

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>


- Modify the main activity AndroidDatePickerActivity, to extends FragmentActivity. And import android.support.v4.app.FragmentActivity.
package com.exercise.AndroidDatePicker;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;

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


- Keep no change on layout, 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:orientation="vertical" >

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


- Now the app can run on device running Android 2.1 or above.

* Run on HTC Flyer running Android 3.2.1
Run on HTC Flyer running Android 3.2.1

* Run on Nexus One running Android 2.3.6
Run on Nexus One running Android 2.3.6

remark:
If you build the DatePicker exercise, target Android 2.2, API level 8. The app can run on both Android 2.3.6 and 3.2.1, and have traditional look.

* The app target API level8, run on HTC Flyer with Android 3.2.1
The app target API level8, run on HTC Flyer with Android 3.2.1

* The app target API level8, run on Nexus One with Android 2.3.6
The app target API level8, run on Nexus One with Android 2.3.6

Monday 26 December 2011

Honeycomb's tab look of DatePicker

Honeycomb's tap look of DatePicker

Create a new Android Project target Android 3.0. Modify main.xml to add a DatePicker:
<?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:orientation="vertical" >

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


- Compare with traditional look of DatePicker on Phone.

Next:
- Backward compatibility using Android Support Package



Sunday 25 December 2011

Targeting Android with Qt - video from Qt Developer Days 2011

In the last two years, Android has become one of the most popular smartphone platforms in the world. In the same time, Qt has developed an elegant and mature solution for creating mobile apps with Qt Quick. Necessitas is a community project that adds Android support to the Qt SDK. This talk will explain how you can deploy your Qt app to the Android Market using Necessitas.
Targeting Android with Qt - video from Qt Developer Days 2011

View the video: Targeting Android with Qt



Saturday 24 December 2011

New standard of C Programming language published officially

The new C Programming language (informally known as C11, or C1x), ISO/IEC 9899:2011, officially published by ISO at 2011-12-08.

ISO/IEC 9899:2011 specifies the form and establishes the interpretation of programs written in the C programming language.It specifies

  • the representation of C programs;
  • the syntax and constraints of the C language;
  • the semantic rules for interpreting C programs;
  • the representation of input data to be processed by C programs;
  • the representation of output data produced by C programs;
  • the restrictions and limits imposed by a conforming implementation of C.

ISO/IEC 9899:2011 does not specify

  • the mechanism by which C programs are transformed for use by a data-processing system;
  • the mechanism by which C programs are invoked for use by a data-processing system;
  • the mechanism by which input data are transformed for use by a C program;
  • the mechanism by which output data are transformed after being produced by a C program;
  • the size or complexity of a program and its data that will exceed the capacity of any specific data-processing system or the capacity of a particular processor;
  • all minimal requirements of a data-processing system that is capable of supporting a conforming implementation.

ISO/IEC 9899:2011 is designed to promote the portability of C programs among a variety of data-processing systems. It is intended for use by implementers and programmers.



Reference: ISO/IEC 9899:2011

Friday 23 December 2011

Apple TV 4.4.4 support

I've updated TU for AppleTV 4.4.4 support. Sorry for the delay! Busy during the holidays :)

Thursday 22 December 2011

Google Gives Back 2011

At Google, philanthropy is a core value. This year Google gave more than $100 million to various organizations around the world -- including $40 million in grants that celebrate the giving season by supporting four causes that is considered particularly important: science, technology, engineering and math (STEM) education; girls' education; empowerment through technology; and fighting human trafficking and modern-day slavery.

Google invite you to celebrate the giving season along with us by learning about these organizations, the great work they're doing, and how you can support them.

know more: http://www.google.com/intl/en/landing/givesback/2011/





Intel's Medfield Based Android Smartphone Reference Design



Wednesday 21 December 2011

The Latest on Mozilla Firefox

Firefox LogoCNET has a nice write up on what's going on with the Mozilla foundation and Firefox.



CNET: Mozilla is more than just Firefox



Sometimes I think people forget the importance of open source software and affect on the growth of the Internet. I regularly use Firefox, Chrome, and Safari and still find Firefox the best of the bunch.

Setup HTC Flyer for Android Development, on Ubuntu 11.10

You can develop and debug on real Android device (HTC Fly in this case) just as you would on the emulator. Before you can start, there are just a few things to do. Refer to Android document Using Hardware Devices. I will not repeat here. I describe how to add the file /etc/udev/rules.d/51-android.rules on Ubuntu 11.10 only.

- Start Terminal

- Switch to /etc/udev/rules.d/ directory
$cd /etc/udev/rules.d/

- In Ubuntu, create/open 51-android.rules as su.
$sudo gedit 51-android.rules

- Add the text in the file (for HTC), and save it:
SUBSYSTEM=="usb", ATTR{idVendor}=="0bb4", MODE="0666", GROUP="plugdev"

for other vendor ID, refer to USB Vendor IDs in the document Using Hardware Devices.

- execute :
$chmod a+r /etc/udev/rules.d/51-android.rules

- Finally, check if your device connected; run the command from your SDK platform-tools/ directory:
$./adb devices

Two devices connected.

Monday 19 December 2011

HP Pavilion dm4t Laptop Review, Specs and Price

HP one of the well-known notebook maker has announced the launch of its new edition laptop namely, HP Pavilion dm4t Beats Edition series. This is an enhancement to the existing Pavilion dm4t regular edition that was released earlier this year. The Pavilion dm4t which powered by Intel Core i3-2330M, with HD Graphics 3000 intel wich runs on Genuine Windows 7 Home Premium 64-bit. The details related to the specs of the device are discussed below.

HP Pavilion dm4t Laptop Specification :
  • Screen : 14.0? diagonal High-Definition HP BrightView LED Display (1366 x 768)
  • Processor : Intel Core i3-2330M Processor (2.2 GHz) Intel HD Graphics 3000
  • Memory : 6GB DDR3 System Memory (2 Dimm)
  • Storgage : 640GB 5400 rpm Hard Drive with HP ProtectSmart Hard Drive Protection
  • Optical Drive : SuperMulti 8X DVD+/-R/RW with Double Layer Support
  • Web Cam : HP TrueVision HD Webcam with Integrated Digital Microphone
  • Wireless : Intel 802.11b/g/n WLAN with Wireless Display Support
  • Dimensions : 13.42in (L) x 8.98in (W) x 0.98in (min H) / 1.27in (max H)
  • Battery : 6-Cell Lithium-Ion Battery Up to 6.75 hours of battery life +++
  • OS : Genuine Windows 7 Home Premium 64-bit
  • Weight : 4.41lbs

Price about : $900

HTML5 test - How well does your browser support HTML5?


The HTML5 test score is an indication of how well your browser supports the upcoming HTML5 standard and related specifications. Even though the specification isn't finalized yet, all major browser manufacturers are making sure their browser is ready for the future. Find out which parts of HTML5 are already supported by your browser today and compare the results with other browsers.

Visit http://html5test.com/ to test your browser.

  • Tested on Build-in Browser at Nexus One running Android 2.3.6
    Tested on Build-in Browser at Nexus One running Android 2.3.6

  • Tested on Firefox 8.0 at Nexus One running Android 2.3.6
    Tested on Firefox 8.0 at Nexus One running Android 2.3.6

  • Tested on Opera Mobile 11.5.3 at Nexus One running Android 2.3.6
    Tested on Opera Mobile 11.5.3 at Nexus One running Android 2.3.6

  • Tested on Build-in Browser at HTC Flyer running Android 3.2.1
    Tested on Build-in Browser at HTC Flyer running Android 3.2.1

  • Tested on Firefox 8.0 at HTC Flyer running Android 3.2.1
    Tested on Firefox 8.0 at HTC Flyer running Android 3.2.1

  • Tested on Opera Mobile 11.5.3 at HTC Flyer running Android 3.2.1
    Tested on Opera Mobile 11.5.3 at HTC Flyer running Android 3.2.1

Sunday 18 December 2011

Example of using Compatibility Package, implement Fragment on pre-Android 3.0 devices

In this exercise, we will modify from the article "Programmatically add fragment", using Compatibility Package. To make it run on both Android 3.0 device and older version device.

on Nexus One running Android 2.3.6:
Fragment on Nexus One running Android 2.3.6

on HTC Flyer running Android 3.2.1:
Fragment on HTC Flyer running Android 3.2.1

- Create a new project with minSdkVersion="7" nd targetSdkVersion="11".
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.exercise.FragmentTest"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk android:minSdkVersion="7" android:targetSdkVersion="11"/>

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

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>


- Follow the last article to "Install and setup Compatibility Package" on your project.

- Create /res/layout/fragmentlayout.xml to define the layout of our fragment.
<?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:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="It's Fragment" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/ic_launcher"/>
</LinearLayout>


- Implement our Fragment class MyFragment.java extends Fragment.
package com.exercise.FragmentTest;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class MyFragment extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View myFragmentView = inflater.inflate(R.layout.fragmentlayout, container, false);
return myFragmentView;
}

}


- Modify main.xml to add a FrameLayout, it will be added with our fragment.
<?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:orientation="horizontal" >

<TextView
android:layout_width="0px"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="It's TextView in main Activity"
android:background="#555555"/>
<FrameLayout
android:id="@+id/myfragment"
android:layout_width="0px"
android:layout_weight="4"
android:layout_height="match_parent">
</FrameLayout>

</LinearLayout>


- Modify main activity, FragmentTestActivity extends FragmentActivity, to add our fragment in the FrameLayout.
package com.exercise.FragmentTest;

import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;

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

// get an instance of FragmentTransaction from your Activity
FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();

//add a fragment
MyFragment myFragment = new MyFragment();
fragmentTransaction.add(R.id.myfragment, myFragment);
fragmentTransaction.commit();
}
}


*** Please take a notice on the import statements.

in FragmentTestActivity.java:
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentTransaction;

in MyFragment.java
import android.support.v4.app.Fragment;

They are imported from android.support.v4.app, not android.app. Otherwise, your app can run on Android 3.0 or above, but fail in pre-3.0 device.

Download the files.

Install and setup Compatibility Package


Update@2012-06-22

It seem no longer work!

Refer to another post: to know how to add Android Support Package.




Compatibility Package is a static library that exposes the same Fragments API from Android 3.0, so that applications compatible with Android 1.6 or later can use fragments to create tablet-compatible user interfaces.

Before you can apply Compatibility Package on your project, you have to prepare something first:

- First of all, make sure you have installed Compatibility Package:
In Eclipse, click Window -> Android SDK Manager, scroll down to Extras, install Android Compatibility package.
install Android Compatibility package

- Include Compatibility Package in your Build Path:
Right click on your project in Package Explorer, -> Properties.
Select Java Build Path tab on the left.
Click Add External JARS button on the right.
Browse to select your instaled android-support-v4.jar, and click OK.
Add android-support-v4.jar

Now you should have android-support-v4.jar in your Java Build Path, click OK.
Java Build Path


updated@2011-12-27:

It's called Android Support Package now, in /android-sdks/extras/android/support/v4/android-support-v4.jar
Android Support Package


next:
- Example of using Compatibility Package, implement Fragment on pre-Android 3.0 devices

Friday 16 December 2011

Android 4.0.3 released and SDK tools updated


Android 4.0.3, an incremental release of the Android 4.0 (Ice Cream Sandwich) platform, announced. The new release includes a variety of optimizations and bug fixes for phones and tablets, as well as a small number of new APIs for developers. The new API level is 15.

For a complete overview of what�s new in the platform, see the Android 4.0.3 API Overview.

Android 4.0.3 will be the base version of Ice Cream Sandwich. The new platform will be rolling out to production phones and tablets in the weeks ahead.

Also updated include new version of the SDK Tools (r16), Eclipse plug-in (ADT 16.0.1) and NDK r7.

Visit the Android Developers site for more information about Android 4.0.3 and other platform versions. To get started developing or testing on the new platform, you can download it into your SDK using the Android SDK Manager.

TinyCFW: Create a custom IPSW for iPad2 and iPhone4

TinyCFW is a simple tool I put together for a friend of mine. He has an iPad2 GSM and has his 4.3.3 SHSH but since Apple is no longer signing 4.3.3, it isn't possible to downgrade to 4.3.3 without getting stuck in a 1015 recovery loop.

What TinyCFW is:



  • It will modify an existing ipsw for an ipad2 gsm/cdma or iphone4 gsm/cdma

  • It WILL modify the ipsw TO UPDATE YOUR BASEBAND TO THE LATEST!

  • It will create an ipsw that you can use with TinyUmbrella AND iTunes to restore to a version of iOS that you have SHSHs for.

  • It is primarily for iPad2 with a baseband OR iPhone 4.

What TinyCFW is NOT:
  • A jailbreak

  • An unlock

  • A tool to protect your baseband.

  • A tool that will restore your device to any firmware

  • A tool for use with iPhone 3GS, iPhone 3G, iPad, or iPhone 4S

The usage is simple. Start the application (double click on the jar or run the .exe file). You must have java and at least 2.5gb ram. (Yes I know. It's a lot. Get over it. I didn't write this to be massively distributed. I wrote this for a friend and am now just sharing it with everyone). Once the window comes up, click the top button and choose an ipsw for which you have SHSHs for. The app will scan it and tell you the firmware and baseband versions in the ipsw you selected and the firmware and baseband versions that will be in the target ipsw when you click the second button. If you're ready, click 'Save Target IPSW'. This will take a minute or two and when it is finished, you will have a file named:


<your original ipsw name>.bbupdate.ipsw.


You can use this ipsw with iTunes and TinyUmbrella to restore your iPad2 GSM/CDMA back to say 4.3.3 (if you have 4.3.3 SHSH).


This is a VERY initial release. I never intended on it being a massively supported tool. It's just something I used in passing. If it helps you great! This functionality will exist in far more robust form when I finally ever release TinyPwn.


Enjoy!

Android Training announced :)


Google just announced the beta launch of Android Training � a collection of classes that will help Android Developer to build better Android apps.

These classes are designed to demonstrate best practices for solving common Android development problems. Each class explains the steps required to solve a problem, or implement a feature, with plenty of code snippets and sample code for you to use within your own apps.

Source: Android Developers Blog - Introducing Android Training

Thursday 15 December 2011

Access View inside Fragment from Activity

In this exercise, TextView inside Fragment can be accessed from Activity.

Access View inside Fragment from Activity

Main Layout:
<?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:orientation="horizontal" >

<LinearLayout
android:layout_width="0px"
android:layout_weight="1"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Activity:" />
<EditText
android:id="@+id/activitytext"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:id="@+id/sendtofragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Send Text to Fragment" />
</LinearLayout>
<LinearLayout
android:id="@+id/myfragment"
android:layout_width="0px"
android:layout_weight="3"
android:layout_height="match_parent" />

</LinearLayout>


Main Activity:
package com.exercise.AndroidFragment;

import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class AndroidFragmentActivity extends Activity {

EditText textActivity;
Button buttonSendToFragment;
MyFragment myFragment;

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

textActivity = (EditText)findViewById(R.id.activitytext);
buttonSendToFragment = (Button)findViewById(R.id.sendtofragment);

// get an instance of FragmentTransaction from your Activity
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

//add a fragment
myFragment = new MyFragment();
fragmentTransaction.add(R.id.myfragment, myFragment);
fragmentTransaction.commit();

buttonSendToFragment.setOnClickListener(new OnClickListener(){

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
String text = textActivity.getText().toString();
TextView textFragment = (TextView)findViewById(R.id.fragmenttext);
textFragment.setText(text);
}});
}
}


Fragment Layout:
<?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:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Fragment:" />
<TextView
android:id="@+id/fragmenttext"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>


Fragment:
package com.exercise.AndroidFragment;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class MyFragment extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View myFragmentView = inflater.inflate(R.layout.fragmentlayout, container, false);
return myFragmentView;
}

}


Download the files.



Introducing Android Development with Ice Cream Sandwich


The Android platform continues to aggressively grow in market share against competing mobile platforms, such as Apple iOS and BlackBerry. Android's latest major platform update, Android 4.0, frequently called by its code-name, Ice Cream Sandwich or just ICS merges the smartphone-centric Android 2.3.x (Gingerbread) and the tablet-centric Android 3.x (Honeycomb) platform editions into a single SDK for all smart-devices, be they phones, tablets, televisions, or toasters.

This short e-book provides an overview from the authors on the importance of Ice Cream Sandwich as well as key preview content from the upcoming book, "Android Wireless Application Development, Third Edition, Volume I." This preview content provides some essential references, updated for Android SDK 4.0, for those interested in jumping into Android application development at this exciting time. To use this e-book most effectively, you need to download the Android development SDK and tools, install them on your development machine, and configure them using the development environment of your choice. You can find instructions for installing and configuring your computer for Android software development on the Android Developer website at http://d.android.com/sdk/.




Wednesday 14 December 2011

Apps are not the Future

Dave Winer wrote some interesting posts in the last couple of days on the future of apps.



Apps are not the Future

Enough Already with the Apps



The gist of his posts are apps can't link like the web. Thus in the end, the web will win out. And, I have to agree. For all the hype about apps, I still spend the vast majority of my time in browsers. Being able to link and share is what gives the Internet its power.



However, I gotta say the Mac app store is super useful. Buy an app, and you can install it on all your Macs. It saves money, time, and hassle. But I think the best apps like Dropbox and Evernote complement the web, they aren't walled gardens.

How do I un-indent an HTML list with CSS?

CSS ButtonI was looking around for the answer to this question and could not find a short answer. Thus the post.



Question: How do I un-indent an HTML list with CSS?



Answer: Set the padding for the <ol> or <ul> tags to zero.

ul { padding:0; }



That's it!

APTicket update

I've pushed a version of TinyUmbrella that will add an ApNonce to the APTicket request. There is no simple way to handle saving both types of SHSH (one with no ApNonce in the request and one with an ApNonce in the request). At least, there is no simple way for me to do it in the time that I have available for such a change.





In order to be the ABSOLUTE safest, your best bet would be to zip up your .shsh directory and put it in a safe place. Normally I would do something to save this for you but it would be a rather bit TU change for me to manage saving two types of the same SHSH version.





I will keep you posted as I discover more information about what details are and are not important.

Lifecycle of Fragment: onCreate(), onCreateView() and onPause().

A fragment can be thinked as a modular section of an activity, which has its own lifecycle, receives its own input events, and which you can add or remove while the activity is running (sort of like a "sub activity" that you can reuse in different activities).

A fragment must always be embedded in an activity and the fragment's lifecycle is directly affected by the host activity's lifecycle. For example, when the activity is paused, so are all fragments in it, and when the activity is destroyed, so are all fragments. However, while an activity is running (it is in the resumed lifecycle state), you can manipulate each fragment independently, such as add or remove them.

Usually, you should implement at least the following lifecycle methods:
  • onCreate()
    The system calls this when creating the fragment. Within your implementation, you should initialize essential components of the fragment that you want to retain when the fragment is paused or stopped, then resumed.
  • onCreateView()
    The system calls this when it's time for the fragment to draw its user interface for the first time. To draw a UI for your fragment, you must return a View from this method that is the root of your fragment's layout. You can return null if the fragment does not provide a UI.
  • onPause()
    The system calls this method as the first indication that the user is leaving the fragment (though it does not always mean the fragment is being destroyed). This is usually where you should commit any changes that should be persisted beyond the current user session (because the user might not come back).


Lifecycle of Fragment

Here, modify from the last exercise "Dynamic change fragment using Java code"; implement(modify) onCreate(), onCreateView() and onPause() methods of MyFragment.java and MyFragment2.java, display a Toast to check the lifecycle of fragment.

MyFragment.java
package com.exercise.FragmentTest;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

public class MyFragment extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View myFragmentView = inflater.inflate(R.layout.fragmentlayout, container, false);

Toast.makeText(getActivity(),
"MyFragment.onCreateView()",
Toast.LENGTH_LONG).show();

return myFragmentView;
}

@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);

Toast.makeText(getActivity(),
"MyFragment.onCreate()",
Toast.LENGTH_LONG).show();
}

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

Toast.makeText(getActivity(),
"MyFragment.onPause()",
Toast.LENGTH_LONG).show();
}

}


MyFragment2.java
package com.exercise.FragmentTest;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

public class MyFragment2 extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View myFragmentView = inflater.inflate(R.layout.fragmentlayout2, container, false);

Toast.makeText(getActivity(),
"MyFragment2.onCreateView()",
Toast.LENGTH_LONG).show();

return myFragmentView;
}

@Override
public void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);

Toast.makeText(getActivity(),
"MyFragment2.onCreate()",
Toast.LENGTH_LONG).show();
}

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

Toast.makeText(getActivity(),
"MyFragment2.onPause()",
Toast.LENGTH_LONG).show();
}

}


Download the files.

Monday 12 December 2011

WebOS Lives

Internet IconIt looks like WebOS lives! It is going to be opened sourced by HP. However, tablets only, no more phones.



The Verge: WebOS Open Sourced



It will be nice to have another open source option. But since it is tablet only, you have to wonder if it will have the same kind of traction of iOS and Android.

Dynamic change fragment using Java code

Last exercise show how to "Programmatically add fragment". Such that we can change fragment in run-time using using Java code.

Dynamic change fragment using Java code

Modify from the last exercise, keep MyFragment.java and fragmentlayout.xml no change.

Create a new /res/layout/fragmentlayout2.xml to define our second fragment.
<?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:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="It's Fragment 2" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="center"
android:src="@drawable/ic_launcher"/>
</LinearLayout>


Create MyFragment2.java to implement our second fragment class.
package com.exercise.FragmentTest;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class MyFragment2 extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View myFragmentView = inflater.inflate(R.layout.fragmentlayout2, container, false);

return myFragmentView;
}

}


Modify main.xml, to add buttons to change fragment.
<?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:orientation="horizontal" >

<LinearLayout
android:layout_width="0px"
android:layout_weight="1"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Select Fragment:" />
<Button
android:id="@+id/displayfragment1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Fragment 1" />
<Button
android:id="@+id/displayfragment2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Fragment 2" />
</LinearLayout>
<LinearLayout
android:id="@+id/myfragment"
android:layout_width="0px"
android:layout_weight="3"
android:layout_height="match_parent" />

</LinearLayout>


Modify main activity FragmentTestActivity.java to switch between fragments when button click. You should try to switch between fragments and the BACK key, to see how the fragment transaction work.
package com.exercise.FragmentTest;

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class FragmentTestActivity extends Activity{

Fragment fragment;
Button btnFragment1, btnFragment2;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnFragment1 = (Button)findViewById(R.id.displayfragment1);
btnFragment2 = (Button)findViewById(R.id.displayfragment2);

// get an instance of FragmentTransaction from your Activity
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

//add a fragment
MyFragment myFragment = new MyFragment();
fragmentTransaction.add(R.id.myfragment, myFragment);
fragmentTransaction.commit();

btnFragment1.setOnClickListener(btnFragmentOnClickListener);
btnFragment2.setOnClickListener(btnFragmentOnClickListener);
}

Button.OnClickListener btnFragmentOnClickListener
= new Button.OnClickListener(){

@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Fragment newFragment;

// Create new fragment
if(v == btnFragment1){
newFragment = new MyFragment();
}else{
newFragment = new MyFragment2();
}

// Create new transaction
FragmentTransaction transaction = getFragmentManager().beginTransaction();

// Replace whatever is in the fragment_container view with this fragment,
// and add the transaction to the back stack
transaction.replace(R.id.myfragment, newFragment);
transaction.addToBackStack(null);

// Commit the transaction
transaction.commit();
}};

}


Download the files.

Related article:
- Lifecycle of Fragment: onCreate(), onCreateView() and onPause().



Programmatically add fragment

Last post show how to inflate layout from XML. The Fragment is hard coded in layout XML, "fragment" element in main.xml. Alternatively, it can be specified as ViewGroup, LinearLayout in my example here. Then get an instance of FragmentTransaction and add the fragment in the ViewGroup Programmatically.

Programmatically add fragment

Modify the main layout, main.xml, to specify the fragment as LinearLayout instead of MyFragment.
<?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:orientation="horizontal" >

<TextView
android:layout_width="0px"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="It's TextView in main Activity"
android:background="#555555"/>
<LinearLayout
android:id="@+id/myfragment"
android:layout_width="0px"
android:layout_weight="4"
android:layout_height="match_parent" />

</LinearLayout>


Modify onCreate() method of the main activity to get an instance of FragmentTransaction and add the fragment in the LinearLayout.
package com.exercise.FragmentTest;

import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;

public class FragmentTestActivity extends Activity{

Fragment fragment;

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

// get an instance of FragmentTransaction from your Activity
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

//add a fragment
MyFragment myFragment = new MyFragment();
fragmentTransaction.add(R.id.myfragment, myFragment);
fragmentTransaction.commit();

}

}


Both MyFragment.java and /res/layout/fragmentlayout.xml kept no change as last post.

MyFragment.java
package com.exercise.FragmentTest;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class MyFragment extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View myFragmentView = inflater.inflate(R.layout.fragmentlayout, container, false);

return myFragmentView;
}

}


/res/layout/fragmentlayout.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:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="It's Fragment" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher"/>
</LinearLayout>



Download the files.

next:
- Dynamic change fragment using Java code



Sunday 11 December 2011

A simple exercise of Fragment, inflate layout from XML

A simple exercise of Fragment, inflate layout from XML

Create a new Android project target Android 3.0.

Modify layout, main.xml, to add a our fragment.
<?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:orientation="horizontal" >

<TextView
android:layout_width="0px"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="It's TextView in main Activity"
android:background="#555555"/>
<fragment
class="com.exercise.FragmentTest.MyFragment"
android:id="@+id/myfragment"
android:layout_width="0px"
android:layout_weight="4"
android:layout_height="match_parent" />

</LinearLayout>


Implement /res/layout/fragmentlayout.xml, to define the layout of our fragment.
<?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:orientation="vertical" >
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="It's Fragment" />
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/ic_launcher"/>
</LinearLayout>


Add a new class MyFragment extends Fragment. Inside onCreateView(), inflate R.layout.fragmentlayout to generate our view and return it.
package com.exercise.FragmentTest;

import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class MyFragment extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
View myFragmentView = inflater.inflate(R.layout.fragmentlayout, container, false);

return myFragmentView;
}

}


Keep the main activity no change from the auto-generated version.

Related article:
- Programmatically add fragment



Friday 9 December 2011

A simple exercise of Fragment

A simple exercise of Fragment

Create a new Android project target Android 3.0.

Modify layout, main.xml, to add a our fragment
<?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:orientation="horizontal" >

<TextView
android:layout_width="0px"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="It's TextView in main Activity"
android:background="#555555"/>
<fragment
class="com.exercise.FragmentTest.MyFragment"
android:id="@+id/myfragment"
android:layout_width="0px"
android:layout_weight="4"
android:layout_height="match_parent" />

</LinearLayout>


Add a new class MyFragment extends Fragment.
package com.exercise.FragmentTest;

import android.app.Fragment;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

public class MyFragment extends Fragment {

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// TODO Auto-generated method stub
Context context = getActivity().getApplicationContext();
LinearLayout layout = new LinearLayout(context);
TextView text = new TextView(context);
text.setText("It's Fragment");
layout.addView(text);

return layout;
}

}


Modify the main activity to add our MyFragment.
package com.exercise.FragmentTest;

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

public class FragmentTestActivity extends Activity{

Fragment fragment;

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

}

}




Wednesday 7 December 2011

Free Screen Sharing (VNC) Client on Mac OS X Lion/Snow Leopard

Did you know that there is a free Screen Sharing app included on Mac OS X Lion and Snow Leopard? Obviously I didn't until a few days ago. You will find the Screen Sharing app in the following directory:



/System/Library/CoreServices



You can connect to any other Mac simply by launching the app and typing in the IP address of another Mac. Of course that Mac must have Screen Sharing turned on. I have also tried to connect to a RealVNC server on Windows 7 and that does not seem to work. I have not yet tested other VNC server. I will provide a more complete write up in another post.

Tuesday 6 December 2011

MacLife January Highlights - Chips, Siri, and Rays

Here are some of the highlights from this months MacLife magazine available on the web.



MacLife: The Future of ARM - A great story on where ARM is headed with their processes. More power, less electricity should make for some great devices.



MacLife: iPhone 4s Review - The scoop on what is new with the iPhone 4s.



MacLife: 10 Questions to Ask Siri - I like the fact that Siri has a sense of humor. I look forward to this sort of tech.



Ray Solar Charger - For $50, get your own Solar charger for your iPhone.

Monday 5 December 2011

Samsung Series 7 Chronos Amazing Laptops Review, Specs and Price

new Samsung Series 7 Chronos
Samsung one of the well-known notebook maker has announced the launch of its new notebook namely, Samsung Series 7 CHRONOS premium notebooks at IFA 2011. The Notebook which has dubbed MAX screen technology. The 7 chronos models will come with an Intel Core i7 processor, a spacious 750GB HDD and 8GB of DDR3 system memory. There's also some extra flash memory on the motherboard that's said to result in faster startup times and enhanced performance.

The new Series 7 CHRONOS notebook can wake from sleep in around two seconds and is ready to go from cold in just 19 seconds, representing a 33 percent improvement on previous models. This is achieved thanks to ExpressCache technology that sees an extra 8GB of flash memory on the motherboard, coupled with the raw power offered by Intel's Core i7 2675QM Quad Core processor running at 2.2GHz.latest Samsung Series 7 Chronos

The CHRONOS will be available in two screen sizes, both with an outdoor-friendly 300-nit brightness and 1600 x 900 resolution. The model featuring the anti-reflective, LED backlit, slim bezel 15-inch display weighs just 4.78 pounds (2.17kg), and the 15.6-inch screen version weighs 5.09 pounds (2.31kg). Both versions are 0.94-inch (23.9mm) thin and feature an AMD Radeon HD6750M GPU with a gigabyte of dedicated GDDR5 memory.

High definition audio is supplied by Samsung's SoundAlive audio technology through a pair of 2W stereo speakers and a 2W embedded subwoofer. The notebooks run on Windows 7 Professional (64-bit edition), have a backlit keyboard that incorporates useful ambient light sensing auto adjustment and are shipped with Samsung's Easy Migration software that help take the strain out of file transfer from an old computer over USB connection, Ethernet or Wi-Fi network.
Samsung Series 7 Chronos
Finishing off the specs are two USB 3.0 ports and a USB 2.0 port, a 4-in-1 media card reader, a Super-Multi optical drive, HDMI-out, a 1.3 megapixel high definition webcam and wireless connectivity in the shape of Bluetooth 3.0 and 802.11b/g/n Wi-Fi.

The included 80Wh, 8-cell battery is said to offer up to eight hours on a single charge, and Samsung's Battery Life Plus technology is also reported to significantly extend the useful life of the battery.

Price about : $1299.99 or �999