Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7738d4f9 authored by Sara Ting's avatar Sara Ting Committed by Android (Google) Code Review
Browse files

Merge "Revert "Add autocompletion for title in edit-event."" into ics-ub-calendar-burgundy

parents dcf6e77d d19fa1c8
Loading
Loading
Loading
Loading
+1 −1
Original line number Original line Diff line number Diff line
@@ -72,7 +72,7 @@
            android:id="@+id/what_label"
            android:id="@+id/what_label"
            android:text="@string/what_label"
            android:text="@string/what_label"
            style="@style/TextAppearance.EditEvent_Label" />
            style="@style/TextAppearance.EditEvent_Label" />
        <AutoCompleteTextView
        <EditText
            android:id="@+id/title"
            android:id="@+id/title"
            style="@style/TextAppearance.EditEvent_Value"
            style="@style/TextAppearance.EditEvent_Value"
            android:layout_width="wrap_content"
            android:layout_width="wrap_content"
+1 −2
Original line number Original line Diff line number Diff line
@@ -68,7 +68,7 @@
    </LinearLayout>
    </LinearLayout>


    <!-- WHAT -->
    <!-- WHAT -->
    <AutoCompleteTextView
    <EditText
        android:id="@+id/title"
        android:id="@+id/title"
        style="@style/TextAppearance.EditEvent_Value"
        style="@style/TextAppearance.EditEvent_Value"
        android:singleLine="true"
        android:singleLine="true"
@@ -78,7 +78,6 @@
        android:minHeight="48dip"
        android:minHeight="48dip"
        android:hint="@string/hint_what"
        android:hint="@string/hint_what"
        android:capitalize="sentences"
        android:capitalize="sentences"
        android:imeOptions="actionDone"
        android:inputType="textAutoCorrect|textCapSentences"
        android:inputType="textAutoCorrect|textCapSentences"
        android:focusable="true" />
        android:focusable="true" />


+2 −133
Original line number Original line Diff line number Diff line
@@ -24,14 +24,12 @@ import android.app.ProgressDialog;
import android.app.Service;
import android.app.Service;
import android.app.TimePickerDialog;
import android.app.TimePickerDialog;
import android.app.TimePickerDialog.OnTimeSetListener;
import android.app.TimePickerDialog.OnTimeSetListener;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.content.res.Resources;
import android.database.Cursor;
import android.database.Cursor;
import android.database.MatrixCursor;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Drawable;
import android.provider.CalendarContract.Attendees;
import android.provider.CalendarContract.Attendees;
import android.provider.CalendarContract.Calendars;
import android.provider.CalendarContract.Calendars;
@@ -100,7 +98,6 @@ import java.util.Formatter;
import java.util.HashMap;
import java.util.HashMap;
import java.util.Locale;
import java.util.Locale;
import java.util.TimeZone;
import java.util.TimeZone;
import java.util.TreeMap;


public class EditEventView implements View.OnClickListener, DialogInterface.OnCancelListener,
public class EditEventView implements View.OnClickListener, DialogInterface.OnCancelListener,
        DialogInterface.OnClickListener, OnItemSelectedListener {
        DialogInterface.OnClickListener, OnItemSelectedListener {
@@ -108,19 +105,6 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
    private static final String GOOGLE_SECONDARY_CALENDAR = "calendar.google.com";
    private static final String GOOGLE_SECONDARY_CALENDAR = "calendar.google.com";
    private static final String PERIOD_SPACE = ". ";
    private static final String PERIOD_SPACE = ". ";


    // Constants used for title autocompletion.
    private static final String[] EVENT_PROJECTION = new String[] {
        Events._ID,
        Events.TITLE,
        Events.VISIBLE,
    };
    private static final int EVENT_INDEX_ID = 0;
    private static final int EVENT_INDEX_TITLE = 1;
    private static final int EVENT_INDEX_VISIBLE = 2;
    private static final String TITLE_WHERE = Events.VISIBLE + "=? AND "
            + Events.TITLE + " LIKE ?";
    private static final int MAX_TITLE_SUGGESTIONS = 4;

    ArrayList<View> mEditOnlyList = new ArrayList<View>();
    ArrayList<View> mEditOnlyList = new ArrayList<View>();
    ArrayList<View> mEditViewList = new ArrayList<View>();
    ArrayList<View> mEditViewList = new ArrayList<View>();
    ArrayList<View> mViewOnlyList = new ArrayList<View>();
    ArrayList<View> mViewOnlyList = new ArrayList<View>();
@@ -142,7 +126,7 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
    Spinner mAvailabilitySpinner;
    Spinner mAvailabilitySpinner;
    Spinner mAccessLevelSpinner;
    Spinner mAccessLevelSpinner;
    RadioGroup mResponseRadioGroup;
    RadioGroup mResponseRadioGroup;
    AutoCompleteTextView mTitleTextView;
    TextView mTitleTextView;
    AutoCompleteTextView mLocationTextView;
    AutoCompleteTextView mLocationTextView;
    EventLocationAdapter mLocationAdapter;
    EventLocationAdapter mLocationAdapter;
    TextView mDescriptionTextView;
    TextView mDescriptionTextView;
@@ -648,108 +632,6 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
        }
        }
    }
    }


    /**
     * Adapter for title auto completion.
     */
    private static class TitleAdapter extends ResourceCursorAdapter {
        private final ContentResolver mContentResolver;

        public TitleAdapter(Context context) {
            super(context, android.R.layout.simple_dropdown_item_1line, null, 0);
            mContentResolver = context.getContentResolver();
        }

        @Override
        public int getCount() {
            return Math.min(MAX_TITLE_SUGGESTIONS, super.getCount());
        }

        private static String getTitleAtCursor(Cursor cursor) {
            return cursor.getString(EVENT_INDEX_TITLE);
        }

        @Override
        public final String convertToString(Cursor cursor) {
            return getTitleAtCursor(cursor);
        }

        @Override
        public void bindView(View view, Context context, Cursor cursor) {
            TextView textView = (TextView) view;
            textView.setText(getTitleAtCursor(cursor));
        }

        @Override
        public Cursor runQueryOnBackgroundThread(CharSequence constraint) {
            String filter = constraint == null ? "" : constraint.toString() + "%";
            if (filter.isEmpty()) {
                return null;
            }
            long startTime = System.currentTimeMillis();

            // Query all titles prefixed with the constraint.  There is no way to insert
            // 'DISTINCT' or 'GROUP BY' to get rid of dupes, so use post-processing to
            // remove dupes.  We will order query results by descending event ID to show
            // results that were most recently inputted.
            Cursor tempCursor = mContentResolver.query(Events.CONTENT_URI, EVENT_PROJECTION,
                    TITLE_WHERE, new String[] { "1", filter }, Events._ID + " DESC");
            if (tempCursor != null) {
                try {
                    // Post process query results.
                    Cursor c = uniqueTitlesCursor(tempCursor);

                    // Log the processing duration.
                    if (Log.isLoggable(TAG, Log.DEBUG)) {
                        long duration = System.currentTimeMillis() - startTime;
                        StringBuilder msg = new StringBuilder();
                        msg.append("Autocomplete of ");
                        msg.append(constraint);
                        msg.append(": title query match took ");
                        msg.append(duration);
                        msg.append("ms.");
                        Log.d(TAG, msg.toString());
                    }
                    return c;
                } finally {
                    tempCursor.close();
                }
            } else {
                return null;
            }
        }

        /**
         * Post-process the query results to return the first MAX_TITLE_SUGGESTIONS
         * unique titles in alphabetical order.
         */
        private Cursor uniqueTitlesCursor(Cursor cursor) {
            TreeMap<String, String[]> titleToQueryResults =
                    new TreeMap<String, String[]>(String.CASE_INSENSITIVE_ORDER);
            int numColumns = cursor.getColumnCount();
            cursor.moveToPosition(-1);

            // Remove dupes.
            while ((titleToQueryResults.size() < MAX_TITLE_SUGGESTIONS) && cursor.moveToNext()) {
                String title = getTitleAtCursor(cursor).trim();
                String data[] = new String[numColumns];
                if (!titleToQueryResults.containsKey(title)) {
                    for (int i = 0; i < numColumns; i++) {
                        data[i] = cursor.getString(i);
                    }
                    titleToQueryResults.put(title, data);
                }
            }

            // Copy the sorted results to a new cursor.
            MatrixCursor newCursor = new MatrixCursor(EVENT_PROJECTION);
            for (String[] result : titleToQueryResults.values()) {
                newCursor.addRow(result);
            }
            newCursor.moveToFirst();
            return newCursor;
        }
    }

    /**
    /**
     * Does prep steps for saving a calendar event.
     * Does prep steps for saving a calendar event.
     *
     *
@@ -953,7 +835,7 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa


        // cache all the widgets
        // cache all the widgets
        mCalendarsSpinner = (Spinner) view.findViewById(R.id.calendars_spinner);
        mCalendarsSpinner = (Spinner) view.findViewById(R.id.calendars_spinner);
        mTitleTextView = (AutoCompleteTextView) view.findViewById(R.id.title);
        mTitleTextView = (TextView) view.findViewById(R.id.title);
        mLocationTextView = (AutoCompleteTextView) view.findViewById(R.id.location);
        mLocationTextView = (AutoCompleteTextView) view.findViewById(R.id.location);
        mDescriptionTextView = (TextView) view.findViewById(R.id.description);
        mDescriptionTextView = (TextView) view.findViewById(R.id.description);
        mTimezoneLabel = (TextView) view.findViewById(R.id.timezone_label);
        mTimezoneLabel = (TextView) view.findViewById(R.id.timezone_label);
@@ -987,19 +869,6 @@ public class EditEventView implements View.OnClickListener, DialogInterface.OnCa
        mAttendeesList = (MultiAutoCompleteTextView) view.findViewById(R.id.attendees);
        mAttendeesList = (MultiAutoCompleteTextView) view.findViewById(R.id.attendees);


        mTitleTextView.setTag(mTitleTextView.getBackground());
        mTitleTextView.setTag(mTitleTextView.getBackground());
        mTitleTextView.setAdapter(new TitleAdapter(activity));
        mTitleTextView.setOnEditorActionListener(new OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                if (actionId == EditorInfo.IME_ACTION_DONE) {
                    // Dismiss the suggestions dropdown.  Return false so the other
                    // side effects still occur (soft keyboard going away, etc.).
                    mTitleTextView.dismissDropDown();
                }
                return false;
            }
        });

        mLocationTextView.setTag(mLocationTextView.getBackground());
        mLocationTextView.setTag(mLocationTextView.getBackground());
        mLocationAdapter = new EventLocationAdapter(activity);
        mLocationAdapter = new EventLocationAdapter(activity);
        mLocationTextView.setAdapter(mLocationAdapter);
        mLocationTextView.setAdapter(mLocationAdapter);