/** Создаёт новую кнопку элемента меню */ View newView(MenuEntry ent) { Button btn = new Button(st.c()); int pad = (int) st.floatDp(10, st.c()); if (st.kv().isDefaultDesign()) { btn.setBackgroundDrawable(st.kv().m_drwKeyBack.mutate()); } else { try { RectShape clon = st.kv().m_curDesign.m_keyBackground.clone(); btn.setBackgroundDrawable(((GradBack) clon).getStateDrawable()); } catch (Throwable e) { // TODO: handle exception } } // setButtonKeyboardBackground(btn); btn.setHeight(st.kv().m_KeyHeight); btn.setTextColor(st.paint().mainColor); if (st.has(m_state, STAT_TEMPLATES) || st.has(m_state, STAT_CLIPBOARD)) { btn.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL); btn.setLongClickable(true); btn.setOnLongClickListener(m_longListener); } btn.setMaxLines(1); btn.setEllipsize(TruncateAt.MARQUEE); btn.setPadding(pad, pad, pad, pad); btn.setTag(ent); btn.setText(ent.text); btn.setOnClickListener(m_listener); return btn; }
/** * 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; }