gt:             if (file.getName().startsWith(".")) {
context: /*
   * This is the source code of Telegram for Android v. 3.x.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-2016.
   */
  
  package org.telegram.ui;
  
  import android.annotation.SuppressLint;
  import android.app.AlertDialog;
  import android.content.BroadcastReceiver;
  import android.content.Context;
  import android.content.Intent;
  import android.content.IntentFilter;
  import android.content.res.Configuration;
  import android.os.Build;
  import android.os.Environment;
  import android.os.StatFs;
  import android.view.MotionEvent;
  import android.view.View;
  import android.view.ViewGroup;
  import android.view.ViewTreeObserver;
  import android.widget.AbsListView;
  import android.widget.AdapterView;
  import android.widget.ListView;
  import android.widget.TextView;
  
  import org.telegram.messenger.AndroidUtilities;
  import org.telegram.messenger.ApplicationLoader;
  import org.telegram.messenger.FileLog;
  import org.telegram.messenger.LocaleController;
  import org.decisiongram.R;
  import org.telegram.ui.ActionBar.BackDrawable;
  import org.telegram.ui.Adapters.BaseFragmentAdapter;
  import org.telegram.ui.ActionBar.ActionBar;
  import org.telegram.ui.ActionBar.ActionBarMenu;
  import org.telegram.messenger.AnimationCompat.AnimatorSetProxy;
  import org.telegram.messenger.AnimationCompat.ObjectAnimatorProxy;
  import org.telegram.ui.ActionBar.BaseFragment;
  import org.telegram.ui.Cells.SharedDocumentCell;
  import org.telegram.ui.Components.LayoutHelper;
  import org.telegram.ui.Components.NumberTextView;
  
  import java.io.BufferedReader;
  import java.io.File;
  import java.io.FileReader;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.Comparator;
  import java.util.HashMap;
  import java.util.HashSet;
  import java.util.StringTokenizer;
  
  public class DocumentSelectActivity extends BaseFragment {
  
      public interface DocumentSelectActivityDelegate {
          void didSelectFiles(DocumentSelectActivity activity, ArrayList<String> files);
          void startDocumentSelectActivity();
      }
  
      private ListView listView;
      private ListAdapter listAdapter;
      private NumberTextView selectedMessagesCountTextView;
      private TextView emptyView;
  
      private File currentDir;
      private ArrayList<ListItem> items = new ArrayList<>();
      private boolean receiverRegistered = false;
      private ArrayList<HistoryEntry> history = new ArrayList<>();
      private long sizeLimit = 1024 * 1024 * 1536;
      private DocumentSelectActivityDelegate delegate;
      private HashMap<String, ListItem> selectedFiles = new HashMap<>();
      private ArrayList<View> actionModeViews = new ArrayList<>();
      private boolean scrolling;
  
      private final static int done = 3;
  
      private class ListItem {
          int icon;
          String title;
          String subtitle = "";
          String ext = "";
          String thumb;
          File file;
      }
  
      private class HistoryEntry {
          int scrollItem, scrollOffset;
          File dir;
          String title;
      }
  
      private BroadcastReceiver receiver = new BroadcastReceiver() {
          @Override
          public void onReceive(Context arg0, Intent intent) {
              Runnable r = new Runnable() {
                  public void run() {
                      try {
                          if (currentDir == null) {
                              listRoots();
                          } else {
                              listFiles(currentDir);
                          }
                      } catch (Exception e) {
                          FileLog.e("tmessages", e);
                      }
                  }
              };
              if (Intent.ACTION_MEDIA_UNMOUNTED.equals(intent.getAction())) {
                  listView.postDelayed(r, 1000);
              } else {
                  r.run();
              }
          }
      };
  
      @Override
      public void onFragmentDestroy() {
          try {
              if (receiverRegistered) {
                  ApplicationLoader.applicationContext.unregisterReceiver(receiver);
              }
          } catch (Exception e) {
              FileLog.e("tmessages", e);
          }
          super.onFragmentDestroy();
      }
  
      @Override
      public View createView(Context context) {
          if (!receiverRegistered) {
              receiverRegistered = true;
              IntentFilter filter = new IntentFilter();
              filter.addAction(Intent.ACTION_MEDIA_BAD_REMOVAL);
              filter.addAction(Intent.ACTION_MEDIA_CHECKING);
              filter.addAction(Intent.ACTION_MEDIA_EJECT);
              filter.addAction(Intent.ACTION_MEDIA_MOUNTED);
              filter.addAction(Intent.ACTION_MEDIA_NOFS);
              filter.addAction(Intent.ACTION_MEDIA_REMOVED);
              filter.addAction(Intent.ACTION_MEDIA_SHARED);
              filter.addAction(Intent.ACTION_MEDIA_UNMOUNTABLE);
              filter.addAction(Intent.ACTION_MEDIA_UNMOUNTED);
              filter.addDataScheme("file");
              ApplicationLoader.applicationContext.registerReceiver(receiver, filter);
          }
  
          actionBar.setBackButtonDrawable(new BackDrawable(false));
          actionBar.setAllowOverlayTitle(true);
          actionBar.setTitle(LocaleController.getString("SelectFile", R.string.SelectFile));
          actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
              @Override
              public void onItemClick(int id) {
                  if (id == -1) {
                      if (actionBar.isActionModeShowed()) {
                          selectedFiles.clear();
                          actionBar.hideActionMode();
                          listView.invalidateViews();
                      } else {
                          finishFragment();
                      }
                  } else if (id == done) {
                      if (delegate != null) {
                          ArrayList<String> files = new ArrayList<>();
                          files.addAll(selectedFiles.keySet());
                          delegate.didSelectFiles(DocumentSelectActivity.this, files);
                      }
                  }
              }
          });
          selectedFiles.clear();
          actionModeViews.clear();
  
          final ActionBarMenu actionMode = actionBar.createActionMode();
  
          selectedMessagesCountTextView = new NumberTextView(actionMode.getContext());
          selectedMessagesCountTextView.setTextSize(18);
          selectedMessagesCountTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
          selectedMessagesCountTextView.setTextColor(0xff737373);
          selectedMessagesCountTextView.setOnTouchListener(new View.OnTouchListener() {
              @Override
              public boolean onTouch(View v, MotionEvent event) {
                  return true;
              }
          });
          actionMode.addView(selectedMessagesCountTextView, LayoutHelper.createLinear(0, LayoutHelper.MATCH_PARENT, 1.0f, 65, 0, 0, 0));
  
          actionModeViews.add(actionMode.addItem(done, R.drawable.ic_ab_done_gray, R.drawable.bar_selector_mode, null, AndroidUtilities.dp(54)));
  
          fragmentView = getParentActivity().getLayoutInflater().inflate(R.layout.document_select_layout, null, false);
          listAdapter = new ListAdapter(context);
          emptyView = (TextView) fragmentView.findViewById(R.id.searchEmptyView);
          emptyView.setOnTouchListener(new View.OnTouchListener() {
              @Override
              public boolean onTouch(View v, MotionEvent event) {
                  return true;
              }
          });
          listView = (ListView) fragmentView.findViewById(R.id.listView);
          listView.setEmptyView(emptyView);
          listView.setAdapter(listAdapter);
  
          listView.setOnScrollListener(new AbsListView.OnScrollListener() {
              @Override
              public void onScrollStateChanged(AbsListView view, int scrollState) {
                  scrolling = scrollState != SCROLL_STATE_IDLE;
              }
  
              @Override
              public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
  
              }
          });
  
          listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
              @Override
              public boolean onItemLongClick(AdapterView<?> parent, View view, int i, long id) {
                  if (actionBar.isActionModeShowed() || i < 0 || i >= items.size()) {
                      return false;
                  }
                  ListItem item = items.get(i);
                  File file = item.file;
                  if (file != null && !file.isDirectory()) {
                      if (!file.canRead()) {
                          showErrorBox(LocaleController.getString("AccessError", R.string.AccessError));
                          return false;
                      }
                      if (sizeLimit != 0) {
                          if (file.length() > sizeLimit) {
                              showErrorBox(LocaleController.formatString("FileUploadLimit", R.string.FileUploadLimit, AndroidUtilities.formatFileSize(sizeLimit)));
                              return false;
                          }
                      }
                      if (file.length() == 0) {
                          return false;
                      }
                      selectedFiles.put(file.toString(), item);
                      selectedMessagesCountTextView.setNumber(1, false);
                      if (Build.VERSION.SDK_INT >= 11) {
                          AnimatorSetProxy animatorSet = new AnimatorSetProxy();
                          ArrayList<Object> animators = new ArrayList<>();
                          for (int a = 0; a < actionModeViews.size(); a++) {
                              View view2 = actionModeViews.get(a);
                              AndroidUtilities.clearDrawableAnimation(view2);
                              animators.add(ObjectAnimatorProxy.ofFloat(view2, "scaleY", 0.1f, 1.0f));
                          }
                          animatorSet.playTogether(animators);
                          animatorSet.setDuration(250);
                          animatorSet.start();
                      }
                      scrolling = false;
                      if (view instanceof SharedDocumentCell) {
                          ((SharedDocumentCell) view).setChecked(true, true);
                      }
                      actionBar.showActionMode();
                  }
                  return true;
              }
          });
  
          listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
              @Override
              public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                  if (i < 0 || i >= items.size()) {
                      return;
                  }
                  ListItem item = items.get(i);
                  File file = item.file;
                  if (file == null) {
                      if (item.icon == R.drawable.ic_storage_gallery) {
                          if (delegate != null) {
                              delegate.startDocumentSelectActivity();
                          }
                          finishFragment(false);
                      } else {
                          HistoryEntry he = history.remove(history.size() - 1);
                          actionBar.setTitle(he.title);
                          if (he.dir != null) {
                              listFiles(he.dir);
                          } else {
                              listRoots();
                          }
                          listView.setSelectionFromTop(he.scrollItem, he.scrollOffset);
                      }
                  } else if (file.isDirectory()) {
                      HistoryEntry he = new HistoryEntry();
                      he.scrollItem = listView.getFirstVisiblePosition();
                      he.scrollOffset = listView.getChildAt(0).getTop();
                      he.dir = currentDir;
                      he.title = actionBar.getTitle();
                      history.add(he);
                      if (!listFiles(file)) {
                          history.remove(he);
                          return;
                      }
                      actionBar.setTitle(item.title);
                      listView.setSelection(0);
                  } else {
                      if (!file.canRead()) {
                          showErrorBox(LocaleController.getString("AccessError", R.string.AccessError));
                          file = new File("/mnt/sdcard");
                      }
                      if (sizeLimit != 0) {
                          if (file.length() > sizeLimit) {
                              showErrorBox(LocaleController.formatString("FileUploadLimit", R.string.FileUploadLimit, AndroidUtilities.formatFileSize(sizeLimit)));
                              return;
                          }
                      }
                      if (file.length() == 0) {
                          return;
                      }
                      if (actionBar.isActionModeShowed()) {
                          if (selectedFiles.containsKey(file.toString())) {
                              selectedFiles.remove(file.toString());
                          } else {
                              selectedFiles.put(file.toString(), item);
                          }
                          if (selectedFiles.isEmpty()) {
                              actionBar.hideActionMode();
                          } else {
                              selectedMessagesCountTextView.setNumber(selectedFiles.size(), true);
                          }
                          scrolling = false;
                          if (view instanceof SharedDocumentCell) {
                              ((SharedDocumentCell) view).setChecked(selectedFiles.containsKey(item.file.toString()), true);
                          }
                      } else {
                          if (delegate != null) {
                              ArrayList<String> files = new ArrayList<>();
                              files.add(file.getAbsolutePath());
                              delegate.didSelectFiles(DocumentSelectActivity.this, files);
                          }
                      }
                  }
              }
          });
  
          listRoots();
  
          return fragmentView;
      }
  
      @Override
      public void onResume() {
          super.onResume();
          if (listAdapter != null) {
              listAdapter.notifyDataSetChanged();
          }
          fixLayoutInternal();
      }
  
      @Override
      public void onConfigurationChanged(android.content.res.Configuration newConfig) {
          super.onConfigurationChanged(newConfig);
          if (listView != null) {
              ViewTreeObserver obs = listView.getViewTreeObserver();
              obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
                  @Override
                  public boolean onPreDraw() {
                      listView.getViewTreeObserver().removeOnPreDrawListener(this);
                      fixLayoutInternal();
                      return true;
                  }
              });
          }
      }
  
      private void fixLayoutInternal() {
          if (selectedMessagesCountTextView == null) {
              return;
          }
          if (!AndroidUtilities.isTablet() && ApplicationLoader.applicationContext.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
              selectedMessagesCountTextView.setTextSize(18);
          } else {
              selectedMessagesCountTextView.setTextSize(20);
          }
      }
  
      @Override
      public boolean onBackPressed() {
          if (history.size() > 0) {
              HistoryEntry he = history.remove(history.size() - 1);
              actionBar.setTitle(he.title);
              if (he.dir != null) {
                  listFiles(he.dir);
              } else {
                  listRoots();
              }
              listView.setSelectionFromTop(he.scrollItem, he.scrollOffset);
              return false;
          }
          return super.onBackPressed();
      }
  
      public void setDelegate(DocumentSelectActivityDelegate delegate) {
          this.delegate = delegate;
      }
  
      private boolean listFiles(File dir) {
          if (!dir.canRead()) {
              if (dir.getAbsolutePath().startsWith(Environment.getExternalStorageDirectory().toString())
                      || dir.getAbsolutePath().startsWith("/sdcard")
                      || dir.getAbsolutePath().startsWith("/mnt/sdcard")) {
                  if (!Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)
                          && !Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED_READ_ONLY)) {
                      currentDir = dir;
                      items.clear();
                      String state = Environment.getExternalStorageState();
                      if (Environment.MEDIA_SHARED.equals(state)) {
                          emptyView.setText(LocaleController.getString("UsbActive", R.string.UsbActive));
                      } else {
                          emptyView.setText(LocaleController.getString("NotMounted", R.string.NotMounted));
                      }
                      AndroidUtilities.clearDrawableAnimation(listView);
                      scrolling = true;
                      listAdapter.notifyDataSetChanged();
                      return true;
                  }
              }
              showErrorBox(LocaleController.getString("AccessError", R.string.AccessError));
              return false;
          }
          emptyView.setText(LocaleController.getString("NoFiles", R.string.NoFiles));
          File[] files;
          try {
              files = dir.listFiles();
          } catch(Exception e) {
              showErrorBox(e.getLocalizedMessage());
              return false;
          }
          if (files == null) {
              showErrorBox(LocaleController.getString("UnknownError", R.string.UnknownError));
              return false;
          }
          currentDir = dir;
          items.clear();
          Arrays.sort(files, new Comparator<File>() {
              @Override
              public int compare(File lhs, File rhs) {
                  if (lhs.isDirectory() != rhs.isDirectory()) {
                      return lhs.isDirectory() ? -1 : 1;
                  }
                  return lhs.getName().compareToIgnoreCase(rhs.getName());
                  /*long lm = lhs.lastModified();
                  long rm = lhs.lastModified();
                  if (lm == rm) {
                      return 0;
                  } else if (lm > rm) {
                      return -1;
                  } else {
                      return 1;
                  }*/
              }
          });
          for (File file : files) {
  