// Path: src/main/java/com/vackosar/searchbasedlauncher/control/RegexEscaper.java
// @ContextSingleton
// public class RegexEscaper {
//     private static final String[] SPECIAL_CHARACTERS = {".", "+", "-", "&", "|", "(", ")", "{", "}", "[", "]", "^", "\"", "~", "*", "?", ":", "\\"};
//     private static final String PREFIX = "([";
//     private static final String SUFFIX = "])";
//     private static final String BACKSLASH = "\\";
//     private static final String REPLACEMENT = "\\\\$1";
//     private static final Pattern PATTERN = createPattern();
// 
//     public String act(String input) {
//         return PATTERN.matcher(input).replaceAll(REPLACEMENT);
//     }
// 
//     private static Pattern createPattern() {
//         final StringBuilder builder = new StringBuilder();
//         builder.append(PREFIX);
//         for (String character: SPECIAL_CHARACTERS) {
//             builder.append(BACKSLASH).append(character);
//         }
//         builder.append(SUFFIX);
//         return Pattern.compile(builder.toString());
//     }
// }
// 
// Path: src/main/java/com/vackosar/searchbasedlauncher/entity/Indentifiable.java
// public interface Indentifiable {
//     public String getId();
// }
// 
// Path: src/main/java/com/vackosar/searchbasedlauncher/entity/SingletonPersister.java
// @ContextSingleton
// public class SingletonPersister<T extends Indentifiable> {
// 
//     @Inject private Context context;
//     private static final String KEY = "json";
// 
//     public SingletonPersister() {}
// 
//     public SingletonPersister(Context context) {
//         this.context = context;
//     }
// 
//     private Gson createGson(T singleton) {
//         requireNonNull(singleton);
//         return new GsonBuilder()
//                 .excludeFieldsWithoutExposeAnnotation()
//                 .serializeNulls()
//                 .registerTypeAdapter(singleton.getClass(), createInstanceCreator(singleton))
//                 .create();
//     }
// 
//     private void requireNonNull(T singleton) {
//         if (singleton == null) {
//             throw new IllegalArgumentException("Cannot save null objects.");
//         }
//     }
// 
//     private InstanceCreator<T> createInstanceCreator(final T singletonInstance) {
//         return new InstanceCreator<T>() {
//             @Override
//             public T createInstance(Type type) {
//                 return singletonInstance;
//             }
//         };
//     }
//     
//     public void save(T singleton) {
//         final String json = jsonfy(singleton);
//         getEditor(singleton).putString(KEY, json).commit();
//     }
// 
//     private String jsonfy(T singleton) {
//         return createGson(singleton).toJson(singleton);
//     }
// 
//     public void load(T singleton) {
//         requireNonNull(singleton);
//         final String json = getSharedPreferences(singleton).getString(KEY, null);
//         if (json != null) {
//             try {
//                 dejsonfy(singleton, json);
//             } catch (Exception e) {
//                 save(singleton);
//             }
//         } else {
//             save(singleton);
//         }
//     }
// 
//     private void dejsonfy(T singleton, String json) {
//         createGson(singleton).fromJson(json, singleton.getClass());
//     }
// 
//     private SharedPreferences.Editor getEditor(T singleton) {
//         SharedPreferences prefs = getSharedPreferences(singleton);
//         return prefs.edit();
//     }
// 
//     private SharedPreferences getSharedPreferences(T singleton) {
//         final String preferencesName = singleton.getId();
//         return context.getSharedPreferences(preferencesName, Context.MODE_PRIVATE);
//     }
// 
// }


import android.graphics.Color;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import com.google.inject.Inject;
import com.vackosar.searchbasedlauncher.R;
import com.vackosar.searchbasedlauncher.control.RegexEscaper;
import com.vackosar.searchbasedlauncher.entity.Indentifiable;
import com.vackosar.searchbasedlauncher.entity.SingletonPersister;
import java.util.Arrays;
import roboguice.activity.event.OnResumeEvent;
import roboguice.activity.event.OnStopEvent;
import roboguice.context.event.OnCreateEvent;
import roboguice.event.Observes;
import roboguice.inject.ContextSingleton;
import roboguice.inject.InjectView;
package com.vackosar.searchbasedlauncher.boundary;





@ContextSingleton
public class SearchText implements TextWatcher, Indentifiable {

    @InjectView(R.id.searchText) private EditText editText;
    @Inject private RegexEscaper regexEscaper;
    @Inject private SingletonPersister<SearchText> persister;
    @Inject private ThemeSelector themeSelector;

    private static final String EMPTY = "";
    private static final String SPACE = " ";
    private static final String REGEX_MATCH_ALL = ".*";
    private TextChangedCallback textChangedCallback;

    private void onCreate(@Observes OnCreateEvent onCreate) {
        // Fix for missing android:editTextColor in API 10-.
        if (Arrays.asList(ThemeSelector.Theme.Black, ThemeSelector.Theme.Wallpaper).contains(themeSelector.getSelected())) {
            editText.setTextColor(Color.WHITE);
        }
        editText.addTextChangedListener(this);
    }

// Path: src/main/java/com/vackosar/searchbasedlauncher/control/RegexEscaper.java
// @ContextSingleton
// public class RegexEscaper {
//     private static final String[] SPECIAL_CHARACTERS = {".", "+", "-", "&", "|", "(", ")", "{", "}", "[", "]", "^", "\"", "~", "*", "?", ":", "\\"};
//     private static final String PREFIX = "([";
//     private static final String SUFFIX = "])";
//     private static final String BACKSLASH = "\\";
//     private static final String REPLACEMENT = "\\\\$1";
//     private static final Pattern PATTERN = createPattern();
// 
//     public String act(String input) {
//         return PATTERN.matcher(input).replaceAll(REPLACEMENT);
//     }
// 
//     private static Pattern createPattern() {
//         final StringBuilder builder = new StringBuilder();
//         builder.append(PREFIX);
//         for (String character: SPECIAL_CHARACTERS) {
//             builder.append(BACKSLASH).append(character);
//         }
//         builder.append(SUFFIX);
//         return Pattern.compile(builder.toString());
//     }
// }
// 
// Path: src/main/java/com/vackosar/searchbasedlauncher/entity/Indentifiable.java
// public interface Indentifiable {
//     public String getId();
// }
// 
// Path: src/main/java/com/vackosar/searchbasedlauncher/entity/SingletonPersister.java
// @ContextSingleton
// public class SingletonPersister<T extends Indentifiable> {
// 
//     @Inject private Context context;
//     private static final String KEY = "json";
// 
//     public SingletonPersister() {}
// 
//     public SingletonPersister(Context context) {
//         this.context = context;
//     }
// 
//     private Gson createGson(T singleton) {
//         requireNonNull(singleton);
//         return new GsonBuilder()
//                 .excludeFieldsWithoutExposeAnnotation()
//                 .serializeNulls()
//                 .registerTypeAdapter(singleton.getClass(), createInstanceCreator(singleton))
//                 .create();
//     }
// 
//     private void requireNonNull(T singleton) {
//         if (singleton == null) {
//             throw new IllegalArgumentException("Cannot save null objects.");
//         }
//     }
// 
//     private InstanceCreator<T> createInstanceCreator(final T singletonInstance) {
//         return new InstanceCreator<T>() {
//             @Override
//             public T createInstance(Type type) {
//                 return singletonInstance;
//             }
//         };
//     }
//     
//     public void save(T singleton) {
//         final String json = jsonfy(singleton);
//         getEditor(singleton).putString(KEY, json).commit();
//     }
// 
//     private String jsonfy(T singleton) {
//         return createGson(singleton).toJson(singleton);
//     }
// 
//     public void load(T singleton) {
//         requireNonNull(singleton);
//         final String json = getSharedPreferences(singleton).getString(KEY, null);
//         if (json != null) {
//             try {
//                 dejsonfy(singleton, json);
//             } catch (Exception e) {
//                 save(singleton);
//             }
//         } else {
//             save(singleton);
//         }
//     }
// 
//     private void dejsonfy(T singleton, String json) {
//         createGson(singleton).fromJson(json, singleton.getClass());
//     }
// 
//     private SharedPreferences.Editor getEditor(T singleton) {
//         SharedPreferences prefs = getSharedPreferences(singleton);
//         return prefs.edit();
//     }
// 
//     private SharedPreferences getSharedPreferences(T singleton) {
//         final String preferencesName = singleton.getId();
//         return context.getSharedPreferences(preferencesName, Context.MODE_PRIVATE);
//     }
// 
// }


// Path: src/main/java/com/vackosar/searchbasedlauncher/boundary/SearchText.java
import android.graphics.Color;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;
import com.google.inject.Inject;
import com.vackosar.searchbasedlauncher.R;
import com.vackosar.searchbasedlauncher.control.RegexEscaper;
import com.vackosar.searchbasedlauncher.entity.Indentifiable;
import com.vackosar.searchbasedlauncher.entity.SingletonPersister;
import java.util.Arrays;
import roboguice.activity.event.OnResumeEvent;
import roboguice.activity.event.OnStopEvent;
import roboguice.context.event.OnCreateEvent;
import roboguice.event.Observes;
import roboguice.inject.ContextSingleton;
import roboguice.inject.InjectView;

package com.vackosar.searchbasedlauncher.boundary;





@ContextSingleton
public class SearchText implements TextWatcher, Indentifiable {

    @InjectView(R.id.searchText) private EditText editText;
    @Inject private RegexEscaper regexEscaper;
    @Inject private SingletonPersister<SearchText> persister;
    @Inject private ThemeSelector themeSelector;

    private static final String EMPTY = "";
    private static final String SPACE = " ";
    private static final String REGEX_MATCH_ALL = ".*";
    private TextChangedCallback textChangedCallback;

    private void onCreate(@Observes OnCreateEvent onCreate) {
        // Fix for missing android:editTextColor in API 10-.
        if (Arrays.asList(ThemeSelector.Theme.Black, ThemeSelector.Theme.Wallpaper).contains(themeSelector.getSelected())) {
            editText.setTextColor(Color.WHITE);
        }
        editText.addTextChangedListener(this);
    }

    private void onResume(@Observes OnResumeEvent onResumeEvent) {