@Override
  protected void onFinishInflate() {
    super.onFinishInflate();
    mScrollView = (ScrollView) findViewById(R.id.scroll_view);
    mContent = (CellLayout) findViewById(R.id.folder_content);

    mFocusIndicatorHandler = new FocusIndicatorView(getContext());
    mContent.addView(mFocusIndicatorHandler, 0);
    mFocusIndicatorHandler.getLayoutParams().height = FocusIndicatorView.DEFAULT_LAYOUT_SIZE;
    mFocusIndicatorHandler.getLayoutParams().width = FocusIndicatorView.DEFAULT_LAYOUT_SIZE;

    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();

    mContent.setCellDimensions(grid.folderCellWidthPx, grid.folderCellHeightPx);
    mContent.setGridSize(0, 0);
    mContent.getShortcutsAndWidgets().setMotionEventSplittingEnabled(false);
    mContent.setInvertIfRtl(true);
    mFolderName = (FolderEditText) findViewById(R.id.folder_name);
    mFolderName.setFolder(this);
    if (mLauncher.getLockWorkspace()) {
      mFolderName.setKeyListener(null);
      mFolderName.setFocusable(false);
    } else {
      mFolderName.setOnFocusChangeListener(this);
    }

    // We find out how tall the text view wants to be (it is set to wrap_content), so that
    // we can allocate the appropriate amount of space for it.
    int measureSpec = MeasureSpec.UNSPECIFIED;
    mFolderName.measure(measureSpec, measureSpec);
    mFolderNameHeight = mFolderName.getMeasuredHeight();

    // We disable action mode for now since it messes up the view on phones
    mFolderName.setCustomSelectionActionModeCallback(mActionModeCallback);
    mFolderName.setOnEditorActionListener(this);
    mFolderName.setSelectAllOnFocus(true);
    mFolderName.setInputType(
        mFolderName.getInputType()
            | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS
            | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
    mAutoScrollHelper = new FolderAutoScrollHelper(mScrollView);

    boolean hideFolderName =
        SettingsProvider.getBoolean(mLauncher, SettingsProvider.HIDE_FOLDER_NAME, false);
    if (hideFolderName) {
      mFolderName.setVisibility(View.GONE);
      mFolderNameHeight = 0;
    }
  }
  /**
   * Used to inflate the Workspace from XML.
   *
   * @param context The application's context.
   * @param attrs The attribtues set containing the Workspace's customization values.
   */
  public Folder(Context context, AttributeSet attrs) {
    super(context, attrs);

    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
    setAlwaysDrawnWithCacheEnabled(false);
    mInflater = LayoutInflater.from(context);
    mIconCache = app.getIconCache();

    mScrollingFolders =
        SettingsProvider.getBoolean(context, SettingsProvider.KEY_SCROLLING_FOLDERS, false);

    Resources res = getResources();
    mMaxCountX = (int) grid.numColumns;
    // Allow scrolling folders when DISABLE_ALL_APPS is true.
    if (LauncherAppState.isDisableAllApps() || mScrollingFolders) {
      mMaxCountY = mMaxNumItems = Integer.MAX_VALUE;
    } else {
      mMaxCountY = (int) grid.numRows;
      mMaxNumItems = mMaxCountX * mMaxCountY;
    }

    mInputMethodManager =
        (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);

    mExpandDuration = res.getInteger(R.integer.config_folderExpandDuration);
    mMaterialExpandDuration = res.getInteger(R.integer.config_materialFolderExpandDuration);
    mMaterialExpandStagger = res.getInteger(R.integer.config_materialFolderExpandStagger);

    if (sDefaultFolderName == null) {
      sDefaultFolderName = res.getString(R.string.folder_name);
    }
    if (sHintText == null) {
      sHintText = res.getString(R.string.folder_hint_text);
    }
    mLauncher = (Launcher) context;
    // We need this view to be focusable in touch mode so that when text editing of the folder
    // name is complete, we have something to focus on, thus hiding the cursor and giving
    // reliable behvior when clicking the text field (since it will always gain focus on click).
    setFocusableInTouchMode(true);
  }
  protected View createAndAddShortcut(ShortcutInfo item) {
    final BubbleTextView textView =
        (BubbleTextView) mInflater.inflate(R.layout.folder_application, this, false);
    textView.applyFromShortcutInfo(item, mIconCache, false);

    int color =
        SettingsProvider.getInt(
            getContext(),
            SettingsProvider.FOLDER_ICON_TEXT_COLOR,
            getResources().getColor(R.color.folder_items_text_color));
    textView.setTextColor(color);

    textView.setOnClickListener(this);
    textView.setOnLongClickListener(this);
    textView.setOnFocusChangeListener(mFocusIndicatorHandler);

    // We need to check here to verify that the given item's location isn't already occupied
    // by another item.
    if (mContent.getChildAt(item.cellX, item.cellY) != null
        || item.cellX < 0
        || item.cellY < 0
        || item.cellX >= mContent.getCountX()
        || item.cellY >= mContent.getCountY()) {
      // This shouldn't happen, log it.
      Log.e(TAG, "Folder order not properly persisted during bind");
      if (!findAndSetEmptyCells(item)) {
        return null;
      }
    }

    CellLayout.LayoutParams lp =
        new CellLayout.LayoutParams(item.cellX, item.cellY, item.spanX, item.spanY);
    boolean insert = false;
    textView.setOnKeyListener(new FolderKeyEventListener());
    mContent.addViewToCellLayout(textView, insert ? 0 : -1, (int) item.id, lp, true);
    return textView;
  }