@Override
 public int getCount() {
   if (LocaleController.getInstance().sortedLanguages == null) {
     return 0;
   }
   return LocaleController.getInstance().sortedLanguages.size();
 }
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
      if (view == null) {
        view = new TextSettingsCell(mContext);
      }

      LocaleController.LocaleInfo localeInfo =
          LocaleController.getInstance().sortedLanguages.get(i);
      ((TextSettingsCell) view)
          .setText(localeInfo.name, i != LocaleController.getInstance().sortedLanguages.size() - 1);

      return view;
    }
 public void setText(String text) {
   if (text == null || text.length() == 0) {
     setVisibility(GONE);
     return;
   }
   if (text != null && oldText != null && text.equals(oldText)) {
     return;
   }
   oldText = text;
   setVisibility(VISIBLE);
   if (AndroidUtilities.isTablet()) {
     width = (int) (AndroidUtilities.getMinTabletSide() * 0.7f);
   } else {
     width =
         (int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.7f);
   }
   SpannableStringBuilder stringBuilder = new SpannableStringBuilder();
   String help = LocaleController.getString("BotInfoTitle", R.string.BotInfoTitle);
   stringBuilder.append(help);
   stringBuilder.append("\n\n");
   stringBuilder.append(text);
   MessageObject.addLinks(stringBuilder);
   stringBuilder.setSpan(
       new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")),
       0,
       help.length(),
       Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
   textLayout =
       new StaticLayout(
           stringBuilder, textPaint, width, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
   width = 0;
   height = textLayout.getHeight() + AndroidUtilities.dp(4 + 18);
   int count = textLayout.getLineCount();
   for (int a = 0; a < count; a++) {
     width =
         (int) Math.ceil(Math.max(width, textLayout.getLineWidth(a) - textLayout.getLineLeft(a)));
   }
   width += AndroidUtilities.dp(4 + 18);
 }
 private void updateSubtitle() {
   if (actionBar == null) {
     return;
   }
   if (currentChat != null || currentUser == null) {
     return;
   }
   if (currentUser.id / 1000 != 777
       && currentUser.id / 1000 != 333
       && ContactsController.getInstance().contactsDict.get(currentUser.id) == null
       && (ContactsController.getInstance().contactsDict.size() != 0
           || !ContactsController.getInstance().isLoadingContacts())) {
     if (currentUser.phone != null && currentUser.phone.length() != 0) {
       nameTextView.setText(PhoneFormat.getInstance().format("+" + currentUser.phone));
     } else {
       nameTextView.setText(UserObject.getUserName(currentUser));
     }
   } else {
     nameTextView.setText(UserObject.getUserName(currentUser));
   }
   CharSequence printString =
       MessagesController.getInstance().printingStrings.get(currentMessageObject.getDialogId());
   if (printString == null || printString.length() == 0) {
     lastPrintString = null;
     setTypingAnimation(false);
     TLRPC.User user = MessagesController.getInstance().getUser(currentUser.id);
     if (user != null) {
       currentUser = user;
     }
     onlineTextView.setText(LocaleController.formatUserStatus(currentUser));
   } else {
     lastPrintString = printString;
     onlineTextView.setText(printString);
     setTypingAnimation(true);
   }
 }
  @Override
  public View createView(Context context, LayoutInflater inflater) {
    searching = false;
    searchWas = false;

    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setTitle(LocaleController.getString("Language", R.string.Language));

    actionBar.setActionBarMenuOnItemClick(
        new ActionBar.ActionBarMenuOnItemClick() {
          @Override
          public void onItemClick(int id) {
            if (id == -1) {
              finishFragment();
            }
          }
        });

    ActionBarMenu menu = actionBar.createMenu();
    ActionBarMenuItem item =
        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.setAdapter(searchListViewAdapter);
                      }
                    }
                  }
                });
    item.getSearchField().setHint(LocaleController.getString("Search", R.string.Search));

    listAdapter = new ListAdapter(context);
    searchListViewAdapter = new SearchAdapter(context);

    fragmentView = new FrameLayout(context);

    LinearLayout emptyTextLayout = new LinearLayout(context);
    emptyTextLayout.setVisibility(View.INVISIBLE);
    emptyTextLayout.setOrientation(LinearLayout.VERTICAL);
    ((FrameLayout) fragmentView).addView(emptyTextLayout);
    FrameLayout.LayoutParams layoutParams =
        (FrameLayout.LayoutParams) emptyTextLayout.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.gravity = Gravity.TOP;
    emptyTextLayout.setLayoutParams(layoutParams);
    emptyTextLayout.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            return true;
          }
        });

    emptyTextView = new TextView(context);
    emptyTextView.setTextColor(0xff808080);
    emptyTextView.setTextSize(20);
    emptyTextView.setGravity(Gravity.CENTER);
    emptyTextView.setText(LocaleController.getString("NoResult", R.string.NoResult));
    emptyTextLayout.addView(emptyTextView);
    LinearLayout.LayoutParams layoutParams1 =
        (LinearLayout.LayoutParams) emptyTextView.getLayoutParams();
    layoutParams1.width = LayoutHelper.MATCH_PARENT;
    layoutParams1.height = LayoutHelper.MATCH_PARENT;
    layoutParams1.weight = 0.5f;
    emptyTextView.setLayoutParams(layoutParams1);

    FrameLayout frameLayout = new FrameLayout(context);
    emptyTextLayout.addView(frameLayout);
    layoutParams1 = (LinearLayout.LayoutParams) frameLayout.getLayoutParams();
    layoutParams1.width = LayoutHelper.MATCH_PARENT;
    layoutParams1.height = LayoutHelper.MATCH_PARENT;
    layoutParams1.weight = 0.5f;
    frameLayout.setLayoutParams(layoutParams1);

    listView = new ListView(context);
    listView.setEmptyView(emptyTextLayout);
    listView.setVerticalScrollBarEnabled(false);
    listView.setDivider(null);
    listView.setDividerHeight(0);
    listView.setAdapter(listAdapter);
    ((FrameLayout) fragmentView).addView(listView);
    layoutParams = (FrameLayout.LayoutParams) listView.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    listView.setLayoutParams(layoutParams);

    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);
            showDialog(builder.create());
            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) {}
        });

    return fragmentView;
  }
 @Override
 public boolean isEmpty() {
   return LocaleController.getInstance().sortedLanguages == null
       || LocaleController.getInstance().sortedLanguages.size() == 0;
 }