Tuesday, September 11, 2012

EMMA

C:\Program Files\Android\android-sdk\tools\ant\build.xml

        <!--property name="emma.dump.file"
                value="/data/data/${tested.manifest.package}/coverage.ec" /-->
<property name="emma.dump.file"
                value="/sdcard/coverage.ec" />


        <!--delete file="coverage.ec" /-->
        <!--delete file="coverage.em" /-->



java emma merge -input coverage.em,coverage.ec -out module1.es
java emma merge -input module1.es,module2.es -out all.es
java emma report -r txt,html -in all.es -sp c:\workspace\project\src

Wednesday, August 17, 2011

What can be done in Intent ?

17 Aug 2011
How to pass Object from Activity A to B ?

import java.util.*;
import android.os.*;

public class Data implements Parcelable {
public int value = 0;

public Data() {}

private Data(Parcel in) {
value = in.readInt();
}

public int describeContents() {
return 0;
}

public void writeToParcel(Parcel out, int flags) {
out.writeInt(value);
}

public static final Parcelable.Creator CREATOR = new Parcelable.Creator() {
public Data createFromParcel(Parcel in) {
return new Data(in);
}

public Data[] newArray(int size) {
return new Data[size];
}
};
}


Intent intent = new Intent(ActivityA.this, Activity.class);
intent.putExtra("data", data);
startActivityForResult(intent, 0);


Intent i = getIntent();
Data data = (Data) i.getParcelableExtra("data");

20 June 2011
How to choose Email writer and fill in ?
Intent i = new Intent(Intent.ACTION_SEND);

i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL, "youremail@domain.com");
i.putExtra(Intent.EXTRA_SUBJECT, "subject");
i.putExtra(Intent.EXTRA_TEXT, "message");
startActivity(Intent.createChooser(i, "Select email application."));


30 Sep 2010
How to open a System Screen ?
startActivityForResult(new Intent(Settings.ACTION_SOUND_SETTINGS), 0);


16 Aug 2010
How to open an URL in a native browser ?
Intent intent = new Intent(Intent.ACTION_VIEW);

intent.setData(Uri.parse("http://www.google.com/"));
startActivity(intent);

How to make a call ?
String url = "tel:1234567";

startActivity(new Intent(Intent.ACTION_CALL, Uri.parse(url)));

How to go to Dial keyword to make a call ?
String url = "tel:1234567";

Intent callIntent = new Intent(Intent.ACTION_DIAL, Uri.parse(url));
startActivity(callIntent);

Thursday, June 30, 2011

What to do with AndroidManifest.xml ?

30 June 2011
How to prevent onCreate() from being called when the orientation is changed ?
<activity name="YourActivity" android:configChanges="orientation|keyboardHidden" />

16 Aug 2010
How to allow to access internet ?
<uses-permission android:name="android.permission.INTERNET" />

How to disable orientation change ?
android:screenOrientation="nosensor"

Do not show softkeyboard on Activiry showing ?
<activity name="YourActivity" android:windowSoftInputMode="stateHidden" />

Tuesday, June 28, 2011

How to do them in View ?

16 June 2011
How to remove the button shape of an ImageButton ?
android:background="@null"

07 Sept 2010
How to create Full Screen activity ?

requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.xxx);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

16 Aug 2010
How to know about screen width and height ?

Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();

How to show an Alert ?

AlertDialog dialog = new AlertDialog.Builder(this)
.setMessage(R.string.message)
.setPositiveButton(R.string.yes,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
}
)
.setNegativeButton(R.string.no,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
}
).create();
dialog.show();

Monday, June 20, 2011

What to do in I/O and File ?

18 June 2011
How to unzip a .zip file ?

public static void unzip(String filePath, InputStream is) {
ZipInputStream in = null;
try {
in = new ZipInputStream(is);
for (ZipEntry entry = in.getNextEntry(); entry != null; entry = in.getNextEntry()) {
if (entry.isDirectory()) {
File file1 = new File(filePath + entry.getName());
file1.mkdir();
} else {
FileOutputStream outputfile = new FileOutputStream(filePath + entry.getName());
int data = 0;
while ((data = in.read()) != -1) {
outputfile.write( data );
}
outputfile.close();
}
}
} catch (IOException e) {
} finally {
try {
if (in != null) {
in.close();
}
} catch (IOException ignored) {
}
in = null;
}
}

Friday, June 17, 2011

What to do in Storage ?

18 June 2011
How to save and use a pair of key and value in a reference ?

SharedPreferences settings = getSharedPreferences("settings", 0);
SharedPreferences.Editor editor = settings.edit();
editor.putString("name", "yourname");
editor.commit();

String url = settings.getString("name", "noname");