/** * Creates a Button or ImageButton according to the path. e.g. {@code if(file.getAbsolutePath() * == '/')}, it should return an ImageButton with the home drawable on it. * * @param file The directory this button will represent. * @param navbar The {@link PathBar} which will contain the created buttons. * @return An {@link ImageButton} or a {@link Button}. */ private static View newButton(File file, final PathBar navbar) { View btn = null; if (mPathDrawables.containsKey(file.getAbsolutePath())) { btn = new ImageButton(navbar.getContext()); ((ImageButton) btn).setImageResource(mPathDrawables.get(file.getAbsolutePath())); ((ImageButton) btn).setAdjustViewBounds(true); } else { btn = new Button(navbar.getContext()); ((Button) btn).setText(file.getName()); ((Button) btn).setMaxLines(1); ((Button) btn).setTextColor(navbar.getResources().getColor(R.color.navbar_details)); ((Button) btn).setTextSize(TypedValue.COMPLEX_UNIT_SP, 18); } android.widget.LinearLayout.LayoutParams params = new android.widget.LinearLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT); params.rightMargin = (int) TypedValue.applyDimension( TypedValue.COMPLEX_UNIT_DIP, 4, navbar.getResources().getDisplayMetrics()); btn.setLayoutParams(params); btn.setTag(file); btn.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { navbar.cd((File) v.getTag()); } }); btn.setOnLongClickListener(navbar.getPathButtonLayout()); btn.setBackgroundResource(R.drawable.bg_navbar_btn_standard); return btn; }
@Override public boolean onLongClick(View v) { mPathBar.switchToManualInput(); return true; }