gt:                 if (q.length() == 0) {
context: /*
   * This is the source code of Telegram for Android v. 1.3.x.
   * It is licensed under GNU GPL v. 2 or later.
   * You should have received a copy of the license in this archive (see LICENSE).
   *
   * Copyright Nikolai Kudashov, 2013-2014.
   */
  
  package org.telegram.ui;
  
  import android.app.AlertDialog;
  import android.content.Context;
  import android.content.DialogInterface;
  import android.view.LayoutInflater;
  import android.view.MotionEvent;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.AbsListView;
  import android.widget.AdapterView;
  import android.widget.EditText;
  import android.widget.ListView;
  import android.widget.TextView;
  
  import org.telegram.android.AndroidUtilities;
  import org.telegram.messenger.FileLog;
  import org.telegram.android.LocaleController;
  import org.telegram.messenger.R;
  import org.telegram.messenger.Utilities;
  import org.telegram.ui.Adapters.BaseFragmentAdapter;
  import org.telegram.ui.Views.ActionBar.ActionBarLayer;
  import org.telegram.ui.Views.ActionBar.ActionBarMenu;
  import org.telegram.ui.Views.ActionBar.ActionBarMenuItem;
  import org.telegram.ui.Views.ActionBar.BaseFragment;
  
  import java.util.ArrayList;
  import java.util.Timer;
  import java.util.TimerTask;
  
  public class LanguageSelectActivity extends BaseFragment {
      private BaseFragmentAdapter listAdapter;
      private ListView listView;
      private boolean searchWas;
      private boolean searching;
      private BaseFragmentAdapter searchListViewAdapter;
      private TextView emptyTextView;
  
      private Timer searchTimer;
      public ArrayList<LocaleController.LocaleInfo> searchResult;
  
      @Override
      public View createView(LayoutInflater inflater, ViewGroup container) {
          if (fragmentView == null) {
              actionBarLayer.setDisplayHomeAsUpEnabled(true, R.drawable.ic_ab_back);
              actionBarLayer.setBackOverlay(R.layout.updating_state_layout);
              actionBarLayer.setTitle(LocaleController.getString("Language", R.string.Language));
  
              actionBarLayer.setActionBarMenuOnItemClick(new ActionBarLayer.ActionBarMenuOnItemClick() {
                  @Override
                  public void onItemClick(int id) {
                      if (id == -1) {
                          finishFragment();
                      }
                  }
              });
  
              ActionBarMenu menu = actionBarLayer.createMenu();
              menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {
                  @Override
                  public void onSearchExpand() {
                      searching = true;
                  }
  
                  @Override
                  public void onSearchCollapse() {
                      search(null);
                      searching = false;
                      searchWas = false;
                      if (listView != null) {
                          emptyTextView.setVisibility(View.GONE);
                          listView.setAdapter(listAdapter);
                      }
                  }
  
                  @Override
                  public void onTextChanged(EditText editText) {
                      String text = editText.getText().toString();
                      search(text);
                      if (text.length() != 0) {
                          searchWas = true;
                          if (listView != null) {
                              listView.setPadding(AndroidUtilities.dp(16), listView.getPaddingTop(), AndroidUtilities.dp(16), listView.getPaddingBottom());
                              listView.setAdapter(searchListViewAdapter);
                              if(android.os.Build.VERSION.SDK_INT >= 11) {
                                  listView.setFastScrollAlwaysVisible(false);
                              }
                              listView.setFastScrollEnabled(false);
                              listView.setVerticalScrollBarEnabled(true);
                          }
                          if (emptyTextView != null) {
                              emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult));
                          }
                      }
                  }
              });
  
              fragmentView = inflater.inflate(R.layout.language_select_layout, container, false);
              listAdapter = new ListAdapter(getParentActivity());
              listView = (ListView)fragmentView.findViewById(R.id.listView);
              listView.setAdapter(listAdapter);
              emptyTextView = (TextView)fragmentView.findViewById(R.id.searchEmptyView);
              listView.setEmptyView(emptyTextView);
              emptyTextView.setOnTouchListener(new View.OnTouchListener() {
                  @Override
                  public boolean onTouch(View v, MotionEvent event) {
                      return true;
                  }
              });
              searchListViewAdapter = new SearchAdapter(getParentActivity());
  
              listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                  @Override
                  public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                      LocaleController.LocaleInfo localeInfo = null;
                      if (searching && searchWas) {
                          if (i >= 0 && i < searchResult.size()) {
                              localeInfo = searchResult.get(i);
                          }
                      } else {
                          if (i >= 0 && i < LocaleController.getInstance().sortedLanguages.size()) {
                              localeInfo = LocaleController.getInstance().sortedLanguages.get(i);
                          }
                      }
                      if (localeInfo != null) {
                          LocaleController.getInstance().applyLanguage(localeInfo, true);
                          parentLayout.rebuildAllFragmentViews(false);
                      }
                      finishFragment();
                  }
              });
  
              listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
                  @Override
                  public boolean onItemLongClick(AdapterView<?> adapterView, View view, int i, long l) {
                      LocaleController.LocaleInfo localeInfo = null;
                      if (searching && searchWas) {
                          if (i >= 0 && i < searchResult.size()) {
                              localeInfo = searchResult.get(i);
                          }
                      } else {
                          if (i >= 0 && i < LocaleController.getInstance().sortedLanguages.size()) {
                              localeInfo = LocaleController.getInstance().sortedLanguages.get(i);
                          }
                      }
                      if (localeInfo == null || localeInfo.pathToFile == null || getParentActivity() == null) {
                          return false;
                      }
                      final LocaleController.LocaleInfo finalLocaleInfo = localeInfo;
                      AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                      builder.setMessage(LocaleController.getString("DeleteLocalization", R.string.DeleteLocalization));
                      builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                      builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), new DialogInterface.OnClickListener() {
                          @Override
                          public void onClick(DialogInterface dialogInterface, int i) {
                              if (LocaleController.getInstance().deleteLanguage(finalLocaleInfo)) {
                                  if (searchResult != null) {
                                      searchResult.remove(finalLocaleInfo);
                                  }
                                  if (listAdapter != null) {
                                      listAdapter.notifyDataSetChanged();
                                  }
                                  if (searchListViewAdapter != null) {
                                      searchListViewAdapter.notifyDataSetChanged();
                                  }
                              }
                          }
                      });
                      builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                      showAlertDialog(builder);
                      return true;
                  }
              });
  
              listView.setOnScrollListener(new AbsListView.OnScrollListener() {
                  @Override
                  public void onScrollStateChanged(AbsListView absListView, int i) {
                      if (i == SCROLL_STATE_TOUCH_SCROLL && searching && searchWas) {
                          AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
                      }
                  }
  
                  @Override
                  public void onScroll(AbsListView absListView, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
                  }
              });
  
              searching = false;
              searchWas = false;
          } else {
              ViewGroup parent = (ViewGroup)fragmentView.getParent();
              if (parent != null) {
                  parent.removeView(fragmentView);
              }
          }
          return fragmentView;
      }
  
      @Override
      public void onResume() {
          super.onResume();
          if (listAdapter != null) {
              listAdapter.notifyDataSetChanged();
          }
      }
  
      public void search(final String query) {
          if (query == null) {
              searchResult = null;
          } else {
              try {
                  if (searchTimer != null) {
                      searchTimer.cancel();
                  }
              } catch (Exception e) {
                  FileLog.e("tmessages", e);
              }
              searchTimer = new Timer();
              searchTimer.schedule(new TimerTask() {
                  @Override
                  public void run() {
                      try {
                          searchTimer.cancel();
                          searchTimer = null;
                      } catch (Exception e) {
                          FileLog.e("tmessages", e);
                      }
                      processSearch(query);
                  }
              }, 100, 300);
          }
      }
  
      private void processSearch(final String query) {
          Utilities.searchQueue.postRunnable(new Runnable() {
              @Override
              public void run() {
  
                  String q = query.trim().toLowerCase();
  