package org.sugr.gearshift;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;


public class TransmissionProfileDirectoryAdapter extends ArrayAdapter<String> {

    public TransmissionProfileDirectoryAdapter(Context context, int textViewResourceId) {
        super(context, textViewResourceId);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = super.getView(position, convertView, parent);

        TextView textView = (TextView) view.findViewById(android.R.id.text1);
        String text = (String) textView.getText();

        int lastSlash = text.lastIndexOf('/');
        if (lastSlash > -1) {
            if (lastSlash == 0) {
                textView.setText(text.substring(lastSlash + 1) + " (/)");
            } else {
                textView.setText(text.substring(lastSlash + 1) + " (" + text.substring(0, lastSlash) + ')');
            }
        }

        return view;
    }

    @Override
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
        View view = super.getDropDownView(position, convertView, parent);

        TextView textView = (TextView) view.findViewById(android.R.id.text1);
        String text = (String) textView.getText();

        int lastSlash = text.lastIndexOf('/');
        if (lastSlash > -1) {
            if (lastSlash == 0) {
                textView.setText(text.substring(lastSlash + 1) + " (/)");
            } else {
                textView.setText(text.substring(lastSlash + 1) + " (" + text.substring(0, lastSlash) + ')');
            }
        }

        return view;
    }

    public void sort() {
        sort(G.SIMPLE_STRING_COMPARATOR);
    }
}

@@ -54,16 +54,47 @@
 ontext;%0A
+import android.text.TextUtils;%0A
 import a
@@ -111,16 +111,16 @@
 w.View;%0A
-
 import a
@@ -661,32 +661,92 @@
 id.R.id.text1);%0A
+        textView.setEllipsize(TextUtils.TruncateAt.MIDDLE);%0A
         String t
@@ -1314,32 +1314,32 @@
 View, parent);%0A%0A
-
         TextView
@@ -1392,32 +1392,92 @@
 id.R.id.text1);%0A
+        textView.setEllipsize(TextUtils.TruncateAt.MIDDLE);%0A
         String t

truncate the location in the middle if too long