How to Properly Encode Video for Android Devices – Tested
How to Properly Encode Video for Android Devices - Tested.
Good article on encoding.
Customizing actionbar items
I just wanted to point out this really handy method that lets you specify your own layout for an action item.
<strong>android:actionlayout="@layout/action_layout"</strong>
Super cool albeit a bit obscure!
This is all you need to do:
In your menu xml:
<item android:id="@+id/menu_item" android:showAsAction="always|withText" android:actionLayout="@layout/action_layout" android:title="@string/menu_settings"/>
It's that simple!
Your layout can be anything! in my case i just tried it out with a button.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="horizontal" tools:context=".CacheTestActivity" > <ImageButton android:layout_width="wrap_content" android:layout_height="match_parent" android:contentDescription="Custom button!" android:scaleType="fitCenter" android:src="@drawable/logo" /> </LinearLayout>
This really makes it simple to customize your actionbar action items!
Hope this helps!
TD Ameritrade released!
- Level II quotes
- Option chains
- Market data
- Trade stocks and options
- Order status
- News
- Account information
- Balances and positions
- Transaction history
- Much more!
Customizing the Action Bar
If you've ever worked with the Action Bar apis you'll probably agree that it's not the most fun to work with. I have seen a fair share of projects now using ActionBar Sherlock which is great and all (especially for the backwards compatibility) but that doesn't really save you from needing to understand many of the intricacies of customizing the Action Bar UI. This post from the Android Developers Blog goes a long way in helping make sense of things.
How to Debug / View source of Android Support Library (compatibility package)
This is a cool trick that will allow you to view the source of your android-support library (Compatibility package).
Here's what you need to do
Make sure you have the correct version of ADT.
You need to be on ADT 20 or later. Go here to get the latest ADT installed.
Add the support library to your project
After adding your Support Library, (project properties > android tools > add compatibility package.
Create a .properties file for your jar and set the path to the support source. It is in your SDK
Now go to your project's libs folder and create a file that is the same name as your android-support-v4.jar file and add .properties at the end.
Something like this:
Your path will be in your <SDK_PATH>/extras/android/support/v4/src
src=/android-sdk-macosx/extras/android/support/v4/src
Now close your project and open it back up.
You should now be able to open up the source code for your library. To confirm, go under Android Dependencies, find the android-support-v4.jar
Expand down to the classes inside the package, clicking one should open up the source in your editor.
This neat feature works for any Jar library you have the source to. Enjoy! thanks to Simon for showing me this cool feature.
Summary:
You can set a source attachment for your android-support or any other JAR that doesn't allow source attachments by adding a properties file. It's easy and works for any jar you have the source to.
And it only takes a few easy steps:
- Make sure you have the correct version of ADT.
- Create a .properties file for your jar and set the src=/path/to/your/source inside it.
- Close and re-open your project
How to properly use the viewHolder pattern on a listView adapter with multiple viewTypes.
The viewHolder pattern is great for making your listViews feel more responsive. Examples abound.
It seems to work great up until you start doing more complex things with it. Things can get a bit tricky once you have more than viewType that your adapter needs to provide.
Consider this code:
package com.oner.test;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class Adapter_testActivity extends Activity {
private ListView mListView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mListView = (ListView) findViewById(android.R.id.list);
mListView.setAdapter(new AdapterTest((Context) this));
}
private class AdapterTest extends BaseAdapter {
String[] items = { "a", "b", "c", "d", "e", "a", "b", "c", "d", "e",
"a", "b", "c", "d", "e", "a", "b", "c", "d", "e", "a", "b",
"c", "d", "e", "a", "b", "c", "d", "e", "a", "b", "c", "d", "e" };
private Context mContext;
private LayoutInflater inflater;
public AdapterTest(final Context context) {
mContext = context;
inflater = LayoutInflater.from(mContext);
}
@Override
public int getCount() {
return items.length;
}
@Override
public Object getItem(int position) {
return items[position];
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = convertView;
ViewHolder holder;
int type = getItemViewType(position);
Log.d("Adapter test","setting type:"+type);
if (v == null) {
holder = new ViewHolder();
if (type == 0) {
v = inflater.inflate(R.layout.item_type_one, null);
holder.txtOne = (TextView) v.findViewById(R.id.txt_one);
}else if(type ==1){
v = inflater.inflate(R.layout.item_type_two, null);
holder.txtTwo = (TextView) v.findViewById(R.id.txt_two);
}
else {
v = inflater.inflate(R.layout.item_type_three, null);
holder.txtThree = (TextView) v.findViewById(R.id.txt_three);
}
holder.type = type;
v.setTag(holder);
} else {
holder = (ViewHolder) v.getTag();
Log.d("Adapter test", " holder ::" + holder);
}
String item = (String) getItem(position);
if (item != null) {
if (type == 0) {
holder.txtOne.setText(item);
} else if(type ==1 ) {
holder.txtTwo.setText(item);
}else{
holder.txtThree.setText(item);
}
}
return v;
}
@Override
public int getItemViewType(int position) {
String item = (String) getItem(position);
if(item.equals("a"))return =0;
else if(item.equals("b"))return=1;
else (item.equals("c"))return=2;
}
@Override
public int getViewTypeCount() {
return 3;
}
}
static class ViewHolder {
public int type;
TextView txtOne;
TextView txtTwo;
TextView txtThree;
@Override
public String toString() {
return "ViewHolder [type=" + type + ", txtOne=" + txtOne
+ ", txtTwo=" + txtTwo + ", txtThree=" + txtThree + "]";
}
}
}
For the purposes of this example the list items being inflated all contain the same TextView with just a different id. I'm sure you get the idea.
Here's what the layout for the items looks like in case you're feeling lazy.
The listView will keep a cache of every view type you give it. The trick to avoid problems is to make sure that you properly implement getViewItemType().
@Override
public int getItemViewType(int position) {
String item = (String) getItem(position);
if(item.equals("a"))return =0;
else if(item.equals("b"))return=1;
else (item.equals("c"))return=2;
}
A common mistake (my first mistake) was to implement that logic inside of getView instead of getItemViewType. Prior to getting one of the view types out of it's cache the listView will call getItemViewType for its cache lookup, so you need to make sure it knows how to do so. Also make sure that your getItemId return something other than just 0. This will also make sure things work smoothly.
In my example I determine the item type by looking at the data.
After that it's a simply matter of looking at the type to re-populate the viewHolder.
I hope this helps. Thanks to Simon and Noah for helping me work through the problems.
eclipse – autocomplete has stopped working with android sdk
After my recent update to the latest ADT the autocomplete features of eclipse suddenly stopped working.
Luckily a quick search lead to the indispensable stackoverflow.
The way to fix it is to go to:
Window -> Preferences -> Java -> Editor -> Content Assist -> Advanced
And check the boxes labeled "Java Proposals" and hit Apply.
Thanks to dchimento for the answer.
Link to the question / answer here:
eclipse - autocomplete has stopped working with android sdk - Stack Overflow.
The Gmail Public Labels API | Android Developers Blog
This is pretty cool. I'm gonna have to play with it.
How to find unused resources in your Android project
UPDATE:
This was written prior to the release of Android Lint, so it's no longer really necessary. Running lint will do the same thing.
Design changes!
They happen all the time. At least they do on our project, and let's face it, designers don't always stick to naming conventions meant to prevent asset duplication.
In any case, i'm not casting blame. Orphaned resources happen pretty easily. Luckily there's a great tool to help you keep track of the stuff in your project that's not being used.
With it you can find unused strings in your android project.
Find unused raw assets in your android project.
Find unused drawables in your android project.
Find unused layouts in your android project.
Check it out!
android-unused-resources - Android Unused Resource Detector - Google Project Hosting
android-unused-resources - Android Unused Resource Detector - Google Project Hosting.
It does have some imperfections. You'll sometimes get false positives. For example:
If you're getting a dynamic reference to a resource, this tool won't catch that (not that I would expect it to). But that's just a minor thing.
Anyway thanks @google!




