Wednesday, November 16, 2011
Hide showed Toast Messages
Monday, November 7, 2011
Sample CheckedTextView in listview , Reading contacts all emails
1. Design the main Layout & row Layout with Checked TextView
Main.xml
< ListView android:id="@+id/listView1" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:background="#ffffff" />
Row.xml
< CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/checkedTextView1" android:paddingLeft="20dip"
android:paddingRight="20dip" android:paddingTop="10dip"
android:paddingBottom="10dip" android:orientation="vertical"
android:layout_width="fill_parent" android:layout_height="?android:attr/listPreferredItemHeight"
android:gravity="center_vertical" android:checkMark="@android:drawable/checkbox_off_background"
android:textColor="#000000" />
2. Create the CursurAdpater
private class ContactListAdapter extends CursorAdapter {
public ContactListAdapter(Context context, Cursor c) {
super(context, c);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
String o = cursor
.getString(cursor
.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
CheckedTextView tt = (CheckedTextView) view
.findViewById(R.id.checkedTextView1);
tt.setText(o);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View v;
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
return v;
}
}
3. set the Contact Cursor to the ContactListAdapter
ContentResolver cr = getContentResolver();
Cursor emails = cr.query(
ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, null,
null, null);
l.setAdapter(new ContactListAdapter(this, emails));
4. Change the State while select the Item
l.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView arg0, View v, int arg2,
long arg3) {
CheckedTextView tt = (CheckedTextView) v
.findViewById(R.id.checkedTextView1);
if (!tt.isChecked()) {
tt.setChecked(true);
tt.setCheckMarkDrawable(android.R.drawable.checkbox_on_background);
} else {
tt.setChecked(false);
tt.setCheckMarkDrawable(android.R.drawable.checkbox_off_background);
}
}
});
5. Add the Contact Read Permission in androidmanifest.xml
< uses-permission android:name="android.permission.READ_CONTACTS" />
Sample Program :
public class ContactListingActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ListView l = (ListView) findViewById(R.id.listView1);
Cursor emails = getContentResolver().query(
ContactsContract.CommonDataKinds.Email.CONTENT_URI, null, null,
null, null);
l.setAdapter(new ContactListAdapter(this, emails));
l.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView arg0, View v, int arg2,
long arg3) {
CheckedTextView tt = (CheckedTextView) v
.findViewById(R.id.checkedTextView1);
if (!tt.isChecked()) {
tt.setChecked(true);
tt.setCheckMarkDrawable(android.R.drawable.checkbox_on_background);
} else {
tt.setChecked(false);
tt.setCheckMarkDrawable(android.R.drawable.checkbox_off_background);
}
}
});
}
private class ContactListAdapter extends CursorAdapter {
public ContactListAdapter(Context context, Cursor c) {
super(context, c);
}
@Override
public void bindView(View view, Context context, Cursor cursor) {
String o = cursor
.getString(cursor
.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
CheckedTextView tt = (CheckedTextView) view
.findViewById(R.id.checkedTextView1);
tt.setText(o);
}
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
View v;
LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = vi.inflate(R.layout.row, null);
return v;
}
}
}
Friday, August 12, 2011
Gesture based action
Friday, July 29, 2011
Monday, May 23, 2011
Android Shell Commands
Sunday, May 22, 2011
Combine two images in android java
Sunday, May 15, 2011
Scrollable Text View in andriod -2
Scrollable Text View in andriod
Thursday, May 12, 2011
How to Obfuscated Android Code
1) Setup the obfuscated environment Download the follwing file before you starts
ProGuard
ProGuard is a free Java class file shrinker, optimizer, obfuscator, and preverifier. It detects and removes unused classes, fields, methods, and attributes. It optimizes bytecode and removes unused instructions. It renames the remaining classes, fields, and methods using short meaningless names. Finally, it preverifies the processed code for Java 6 or for Java Micro Edition.
Download From Sourceforge : http://sourceforge.net/
Reference : http://proguard.sourceforge.
Download files from internet
- add-proguard-release.xml
- procfg.txt
1) To update an existing Android project, open a command-line and navigate to the tools/ directory of your SDK. Now run:
android update project --name
2) So, now you have a signed build from the command line, but still no obfuscated build.
To make things easy, you’re going to want to get two helper files:
add-proguard-release.xml and procfg.txt
Copy these files into your root directory (where the build.xml file found).
3) To add Proguard to your build, you first need to edit your local properties file to add the location of the directory that Proguard is installed in:
proguard.dir=/Directory/
3) Finally... you need to add our script to your build file and have it override a few targets. To do this, we use the XML “entity” construct. At the top of your build.xml file, add an entity that references our script file:
]
>
4) By default ADT creates a proguard.cfg file with every new project, so if you have an existing project just copy it over from a new dummy project. The next step is to enable ProGuard, you do this by adding the following to your default.properties file:
proguard.config=proguard.cfg
(assuming proguard.cfg is the ProGuard configuration file created for you, or copied from a new project, into the project root folder.)