List of usage examples for android.graphics.drawable ShapeDrawable setPadding
public void setPadding(int left, int top, int right, int bottom)
From source file:com.appeaser.sublimepickerlibrary.utilities.SUtils.java
private static Drawable createButtonShape(Context context, int color) { // Translation of Lollipop's xml button-bg definition to Java int paddingH = context.getResources().getDimensionPixelSize(R.dimen.button_padding_horizontal_material); int paddingV = context.getResources().getDimensionPixelSize(R.dimen.button_padding_vertical_material); int insetH = context.getResources().getDimensionPixelSize(R.dimen.button_inset_horizontal_material); int insetV = context.getResources().getDimensionPixelSize(R.dimen.button_inset_vertical_material); float[] outerRadii = new float[8]; Arrays.fill(outerRadii, CORNER_RADIUS); RoundRectShape r = new RoundRectShape(outerRadii, null, null); ShapeDrawable shapeDrawable = new ShapeDrawable(r); shapeDrawable.getPaint().setColor(color); shapeDrawable.setPadding(paddingH, paddingV, paddingH, paddingV); return new InsetDrawable(shapeDrawable, insetH, insetV, insetH, insetV); }
From source file:com.nile.kmooc.view.custom.popup.menu.MenuPopupHelper.java
public boolean tryShow() { mPopup = new ListPopupWindow(mContext, null, mPopupStyleAttr, mPopupStyleRes); mPopup.setOnDismissListener(this); mPopup.setOnItemClickListener(this); mPopup.setAdapter(mAdapter);/* w w w . java2 s . c o m*/ mPopup.setModal(true); View anchor = mAnchorView; if (anchor != null) { final boolean addGlobalListener = mTreeObserver == null; mTreeObserver = anchor.getViewTreeObserver(); // Refresh to latest if (addGlobalListener) mTreeObserver.addOnGlobalLayoutListener(this); anchor.addOnAttachStateChangeListener(this); mPopup.setAnchorView(anchor); mPopup.setDropDownGravity(mDropDownGravity); } else { return false; } if (mContentWidth == Integer.MIN_VALUE) { mContentWidth = measureContentWidth(); } mPopup.setContentWidth(mContentWidth); // Invert the horizontal offset in RTL mode. if (ViewCompat.getLayoutDirection(mAnchorView) == ViewCompat.LAYOUT_DIRECTION_RTL) { mPopup.setHorizontalOffset(-mPopup.getHorizontalOffset()); } // Implement right gravity manually through horizontal offset pre-KitKat. if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT && (Gravity.getAbsoluteGravity(mDropDownGravity, ViewCompat.getLayoutDirection(anchor)) & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.RIGHT) { mPopup.setHorizontalOffset(mPopup.getHorizontalOffset() + (mAnchorView.getWidth() - mPopup.getWidth())); } // If vertical offset is defined as 0, then ListPopupWindow infers // it as the negative of the top padding of the background, in // order to anchor the content area. Since that is not the effect // we want, we'll force it to use only the explicitly defined // offset by explicitly setting it dynamically as well, and thus // forcing it to discard it's 'unset' flag. mPopup.setVerticalOffset(mPopup.getVerticalOffset()); // Top/bottom padding will be applied on the background drawable, // as the ListView is both initialized and set up only after show() // is called on the ListPopupWindow. Left/right padding will be // set up on the list items from the adapter, to keep the correct // item boundaries for the selector. ShapeDrawable paddedDrawable = new ShapeDrawable(); paddedDrawable.setAlpha(0); // Don't apply top padding if the first item is a header, to // comply with the design. paddedDrawable.setPadding(0, mAdapter.hasHeader() ? 0 : (mPopupPaddingTop - mPopupItemVerticalPadding), 0, mPopupPaddingBottom - mPopupItemVerticalPadding); Drawable background = mPopup.getBackground(); mPopup.setBackgroundDrawable(background == null ? paddedDrawable : new LayerDrawable(new Drawable[] { background, paddedDrawable })); mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NOT_NEEDED); mPopup.show(); mPopup.getListView().setOnKeyListener(this); return true; }
From source file:org.de.jmg.learn.SettingsActivity.java
public void init(boolean blnRestart) throws Exception { if (_Intent == null || _main == null || SettingsView == null || _blnInitialized) { return;// w w w . j a v a2 s . c o m } try { //lib.ShowToast(_main, "Settings Start"); RelativeLayout layout = (RelativeLayout) findViewById(R.id.layoutSettings); // id fetch from xml ShapeDrawable rectShapeDrawable = new ShapeDrawable(); // pre defined class int pxPadding = lib.dpToPx(10); rectShapeDrawable.setPadding(pxPadding, pxPadding, pxPadding, pxPadding * ((lib.NookSimpleTouch()) ? 2 : 1)); Paint paint = rectShapeDrawable.getPaint(); paint.setColor(Color.BLACK); paint.setStyle(Style.STROKE); paint.setStrokeWidth(5); // you can change the value of 5 lib.setBg(layout, rectShapeDrawable); mainView = _main.findViewById(Window.ID_ANDROID_CONTENT); //Thread.setDefaultUncaughtExceptionHandler(ErrorHandler); prefs = _main.getPreferences(Context.MODE_PRIVATE); TextView txtSettings = (TextView) findViewById(R.id.txtSettings); SpannableString Settings = new SpannableString(txtSettings.getText()); Settings.setSpan(new UnderlineSpan(), 0, Settings.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); txtSettings.setText(Settings); initCheckBoxes(); initSpinners(blnRestart); initButtons(); initHelp(); edDataDir = (EditText) findViewById(R.id.edDataDir); edDataDir.setSingleLine(true); edDataDir.setText(_main.JMGDataDirectory); edDataDir.setImeOptions(EditorInfo.IME_ACTION_DONE); edDataDir.setOnEditorActionListener(new TextView.OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_DONE) { String strDataDir = edDataDir.getText().toString(); File fileSelected = new File(strDataDir); if (fileSelected.isDirectory() && fileSelected.exists()) { _main.setJMGDataDirectory(fileSelected.getPath()); edDataDir.setText(_main.JMGDataDirectory); Editor editor = prefs.edit(); editor.putString("JMGDataDirectory", fileSelected.getPath()); editor.commit(); } } return true; } }); edDataDir.setOnLongClickListener(new OnLongClickListener() { @Override public boolean onLongClick(View v) { ShowDataDirDialog(); return true; } }); if (!(lib.NookSimpleTouch()) && !_main.isSmallDevice) { SettingsView.getViewTreeObserver() .addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @Override public void onGlobalLayout() { // Ensure you call it only once : lib.removeLayoutListener(SettingsView.getViewTreeObserver(), this); // Here you can get the size :) resize(0); //lib.ShowToast(_main, "Resize End"); } }); } else { //resize(1.8f); mScale = 1.0f; } _blnInitialized = true; } catch (Exception ex) { lib.ShowException(_main, ex); } }