List of usage examples for android.widget ImageView setPadding
public void setPadding(int left, int top, int right, int bottom)
From source file:com.mydatingapp.ui.base.SkBaseInnerActivity.java
public void setActionBarLogoCounter(int count) { ImageView logo = (ImageView) findViewById(android.R.id.home); if (count < 1) { currentLogoCounter = 0;/*from www . j av a 2 s . c o m*/ logo.setVisibility(View.GONE); return; } else { logo.setVisibility(View.VISIBLE); } currentLogoCounter = count; TextView v = new TextView(getApp()); v.setText(new Integer(count).toString()); v.setBackgroundResource(R.drawable.sidebar_menu_counterbg); v.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15); v.setDrawingCacheEnabled(true); v.setTextColor(Color.WHITE); v.setPadding(SKDimensions.convertDpToPixel(6, getApp()), 0, SKDimensions.convertDpToPixel(6, getApp()), 0); ActionBar.LayoutParams paramsExample = new ActionBar.LayoutParams(ActionBar.LayoutParams.WRAP_CONTENT, ActionBar.LayoutParams.WRAP_CONTENT, 1); paramsExample.setMargins(0, 0, 0, 0); v.setHeight(SKDimensions.convertDpToPixel(20, getApp())); v.setLayoutParams(paramsExample); // this is the important code :) // Without it the view will have a dimension of 0,0 and the bitmap will be null v.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight()); v.buildDrawingCache(true); Bitmap b = Bitmap.createBitmap(v.getDrawingCache()); v.setDrawingCacheEnabled(false); logo.setImageDrawable(new BitmapDrawable(getApp().getResources(), b)); logo.setPadding(SKDimensions.convertDpToPixel(3, getApp()), 0, 0, 0); }
From source file:uk.ac.horizon.artcodes.scanner.ScannerActivity.java
private void createSettingsUI(List<DetectorSetting> settings) { settingIcons.removeAllViews();/*from w ww . j av a2 s. co m*/ if (settings != null && !settings.isEmpty()) { final int padding = getResources().getDimensionPixelSize(R.dimen.setting_padding); List<DetectorSetting> settingList = settings; if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { settingList = Lists.reverse(settings); } for (final DetectorSetting setting : settingList) { final ImageView button = new ImageView(this); button.setContentDescription(getString(setting.getText())); final int[] attrs = new int[] { android.R.attr.selectableItemBackground }; final TypedArray ta = obtainStyledAttributes(attrs); final Drawable drawableFromTheme = ta.getDrawable(0); ta.recycle(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { button.setImageResource(setting.getIcon()); button.setImageTintList(ColorStateList.valueOf(Color.WHITE)); button.setBackground(drawableFromTheme); } else { button.setImageDrawable(getTintedDrawable(setting.getIcon(), Color.WHITE)); //noinspection deprecation button.setBackgroundDrawable(drawableFromTheme); } button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setting.nextValue(); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { button.setImageResource(setting.getIcon()); } else { button.setImageDrawable(getTintedDrawable(setting.getIcon(), Color.WHITE)); } button.setContentDescription(getString(setting.getText())); textAnimator.setText(setting.getText()); } }); final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1); params.weight = 1; button.setLayoutParams(params); settingIcons.addView(button); button.setPadding(padding, padding, padding, padding); } } menuAnimator.setViewVisible(settingIcons.getChildCount() > 0); }
From source file:com.lifehackinnovations.siteaudit.FloorPlanActivity.java
public void getscaledialog() { ImageView googlemaps = new ImageView(this); googlemaps.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); googlemaps.setPadding(25, 25, 25, 25); googlemaps.setImageResource(R.drawable.google_maps256x256); googlemaps.setOnClickListener(new ImageView.OnClickListener() { public void onClick(View v) { startActivity(u.intent("Getscalefromgooglemaps")); getscaledialog.cancel();// w w w .j a va 2 s . co m } }); ImageView twopoints = new ImageView(this); twopoints.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); twopoints.setPadding(25, 25, 25, 25); twopoints.setImageResource(R.drawable.pointsonmapicon); twopoints.setOnClickListener(new ImageView.OnClickListener() { public void onClick(View v) { ACTION = ACTION_GETSCALEFROMPOINTS; toptoolbar.setVisibility(View.INVISIBLE); righttoolbar.setVisibility(View.INVISIBLE); floorplantitle.setVisibility(View.VISIBLE); floorplantitle.setText("Please select first point"); GETSCALESTAGE = STAGE_GETFIRSTPOINT; getscaledialog.cancel(); } }); LinearLayout choosepicturelocationlayout; choosepicturelocationlayout = new LinearLayout(this); choosepicturelocationlayout .setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); choosepicturelocationlayout.setOrientation(LinearLayout.HORIZONTAL); choosepicturelocationlayout.addView(googlemaps); choosepicturelocationlayout.addView(twopoints); choosepicturelocationlayout.setGravity(Gravity.CENTER_HORIZONTAL); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Choose Method for Getting Scale") .setMessage("Please choose Google Maps, or Two Points on Map").setView(choosepicturelocationlayout) .setCancelable(false).setIcon(R.drawable.ic_launcher) .setNegativeButton("CANCEL", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.cancel(); } }).setCancelable(true); getscaledialog = builder.create(); getscaledialog.show(); }
From source file:de.ub0r.android.websms.WebSMS.java
/** * Create a Emoticons {@link Dialog}.// www .ja va 2 s . co m * * @return Emoticons {@link Dialog} */ private Dialog createEmoticonsDialog() { final Dialog d = new Dialog(this); d.setTitle(R.string.emo_); d.setContentView(R.layout.emo); d.setCancelable(true); final String[] emoticons = this.getResources().getStringArray(R.array.emoticons); final GridView gridview = (GridView) d.findViewById(R.id.gridview); gridview.setAdapter(new BaseAdapter() { // references to our images // keep order and count synced with string-array! private Integer[] mThumbIds = { R.drawable.emo_im_angel, R.drawable.emo_im_cool, R.drawable.emo_im_crying, R.drawable.emo_im_foot_in_mouth, R.drawable.emo_im_happy, R.drawable.emo_im_kissing, R.drawable.emo_im_laughing, R.drawable.emo_im_lips_are_sealed, R.drawable.emo_im_money_mouth, R.drawable.emo_im_sad, R.drawable.emo_im_surprised, R.drawable.emo_im_tongue_sticking_out, R.drawable.emo_im_undecided, R.drawable.emo_im_winking, R.drawable.emo_im_wtf, R.drawable.emo_im_yelling }; @Override public long getItemId(final int position) { return 0; } @Override public Object getItem(final int position) { return null; } @Override public int getCount() { return this.mThumbIds.length; } @Override public View getView(final int position, final View convertView, final ViewGroup parent) { ImageView imageView; if (convertView == null) { // if it's not recycled, // initialize some attributes imageView = new ImageView(WebSMS.this); imageView.setLayoutParams(new GridView.LayoutParams(EMOTICONS_SIZE, EMOTICONS_SIZE)); imageView.setScaleType(ImageView.ScaleType.CENTER_CROP); imageView.setPadding(EMOTICONS_PADDING, EMOTICONS_PADDING, EMOTICONS_PADDING, EMOTICONS_PADDING); } else { imageView = (ImageView) convertView; } imageView.setImageResource(this.mThumbIds[position]); return imageView; } }); gridview.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(final AdapterView<?> adapter, final View v, final int id, final long arg3) { EditText et = WebSMS.this.etText; final String e = emoticons[id]; int i = et.getSelectionStart(); int j = et.getSelectionEnd(); if (i > j) { int x = i; i = j; j = x; } String t = et.getText().toString(); et.setText(t.substring(0, i) + e + t.substring(j)); et.setSelection(i + e.length()); d.dismiss(); et.requestFocus(); } }); return d; }
From source file:com.mishiranu.dashchan.ui.navigator.DrawerForm.java
private View makeHeader(ViewGroup parent, boolean button, float density) { if (C.API_LOLLIPOP) { LinearLayout linearLayout = new LinearLayout(context); linearLayout.setOrientation(LinearLayout.VERTICAL); View divider = makeSimpleDivider(); int paddingTop = divider.getPaddingBottom(); divider.setPadding(divider.getPaddingLeft(), divider.getPaddingTop(), divider.getPaddingRight(), 0); linearLayout.addView(divider, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); LinearLayout linearLayout2 = new LinearLayout(context); linearLayout2.setOrientation(LinearLayout.HORIZONTAL); linearLayout.addView(linearLayout2, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); TextView textView = makeCommonTextView(true); LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(0, (int) (32f * density), 1); layoutParams.setMargins((int) (16f * density), paddingTop, (int) (16f * density), (int) (8f * density)); linearLayout2.addView(textView, layoutParams); ViewHolder holder = new ViewHolder(); holder.text = textView;//from w ww . j a va 2 s . co m if (button) { ImageView imageView = new ImageView(context); imageView.setScaleType(ImageView.ScaleType.CENTER); imageView.setBackgroundResource(ResourceUtils.getResourceId(context, android.R.attr.borderlessButtonStyle, android.R.attr.background, 0)); imageView.setOnClickListener(headerButtonListener); imageView.setImageAlpha(0x5e); int size = (int) (48f * density); layoutParams = new LinearLayout.LayoutParams(size, size); layoutParams.rightMargin = (int) (4f * density); linearLayout2.addView(imageView, layoutParams); holder.extra = imageView; holder.icon = imageView; } linearLayout.setTag(holder); return linearLayout; } else { View view = LayoutInflater.from(context) .inflate(ResourceUtils.getResourceId(context, android.R.attr.preferenceCategoryStyle, android.R.attr.layout, android.R.layout.preference_category), parent, false); ViewHolder holder = new ViewHolder(); holder.text = (TextView) view.findViewById(android.R.id.title); if (button) { int measureSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); view.measure(measureSpec, measureSpec); int size = view.getMeasuredHeight(); if (size == 0) { size = (int) (32f * density); } FrameLayout frameLayout = new FrameLayout(context); frameLayout.addView(view); view = frameLayout; ImageView imageView = new ImageView(context); imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); int padding = (int) (4f * density); imageView.setPadding(padding, padding, padding, padding); frameLayout.addView(imageView, new FrameLayout.LayoutParams((int) (48f * density), size, Gravity.END)); View buttonView = new View(context); buttonView.setBackgroundResource( ResourceUtils.getResourceId(context, android.R.attr.selectableItemBackground, 0)); buttonView.setOnClickListener(headerButtonListener); frameLayout.addView(buttonView, FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT); holder.extra = buttonView; holder.icon = imageView; } view.setTag(holder); return view; } }
From source file:com.android.launcher3.Utilities.java
public static void showEditMode(final Activity activity, final ShortcutInfo shortcutInfo) { ContextThemeWrapper theme;/*from w w w.j a v a 2 s .com*/ final Set<String> setString = new HashSet<String>(); if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M) { theme = new ContextThemeWrapper(activity, R.style.AlertDialogCustomAPI23); } else { theme = new ContextThemeWrapper(activity, R.style.AlertDialogCustom); } AlertDialog.Builder alert = new AlertDialog.Builder(theme); LinearLayout layout = new LinearLayout(activity.getApplicationContext()); layout.setOrientation(LinearLayout.VERTICAL); layout.setPadding(100, 0, 100, 100); final ImageView img = new ImageView(activity.getApplicationContext()); Drawable icon = null; if (Utilities.getAppIconPackageNamePrefEnabled(activity.getApplicationContext()) != null) { if (Utilities.getAppIconPackageNamePrefEnabled(activity.getApplicationContext()).equals("NULL")) { if (Utilities.loadBitmapPref(Launcher.getLauncherActivity(), shortcutInfo.getTargetComponent().getPackageName()) != null) { icon = new BitmapDrawable(activity.getResources(), Utilities.loadBitmapPref(activity, shortcutInfo.getTargetComponent().getPackageName())); } else { icon = new BitmapDrawable(activity.getResources(), shortcutInfo.getIcon(new IconCache(activity.getApplicationContext(), Launcher.getLauncher(activity).getDeviceProfile().inv))); } } else { if (Utilities.loadBitmapPref(Launcher.getLauncherActivity(), shortcutInfo.getTargetComponent().getPackageName()) != null) { icon = new BitmapDrawable(activity.getResources(), Utilities.loadBitmapPref(activity, shortcutInfo.getTargetComponent().getPackageName())); } else { icon = new BitmapDrawable(activity.getResources(), Launcher.getIcons().get(shortcutInfo.getTargetComponent().getPackageName())); } } } else { if (Utilities.loadBitmapPref(Launcher.getLauncherActivity(), shortcutInfo.getTargetComponent().getPackageName()) != null) { icon = new BitmapDrawable(activity.getResources(), Utilities.loadBitmapPref(activity, shortcutInfo.getTargetComponent().getPackageName())); } else { icon = new BitmapDrawable(activity.getResources(), shortcutInfo.getIcon(new IconCache(activity.getApplicationContext(), Launcher.getLauncher(Launcher.getLauncherActivity()).getDeviceProfile().inv))); } } img.setImageDrawable(icon); img.setPadding(0, 100, 0, 0); img.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { showIconPack(activity, shortcutInfo); } }); final EditText titleBox = new EditText(activity.getApplicationContext()); try { Set<String> title = new HashSet<>( Utilities.getTitle(activity, shortcutInfo.getTargetComponent().getPackageName())); for (Iterator<String> it = title.iterator(); it.hasNext();) { String titleApp = it.next(); titleBox.setText(titleApp); } } catch (Exception e) { titleBox.setText(shortcutInfo.title); } titleBox.getBackground().mutate().setColorFilter( ContextCompat.getColor(activity.getApplicationContext(), R.color.colorPrimary), PorterDuff.Mode.SRC_ATOP); layout.addView(img); layout.addView(titleBox); alert.setTitle(activity.getApplicationContext().getResources().getString(R.string.edit_label)); alert.setView(layout); alert.setPositiveButton(activity.getApplicationContext().getString(R.string.ok), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { for (ItemInfo itemInfo : AllAppsList.data) { if (shortcutInfo.getTargetComponent().getPackageName() .equals(itemInfo.getTargetComponent().getPackageName())) { setString.add(titleBox.getText().toString()); getPrefs(activity.getApplicationContext()).edit() .putStringSet(itemInfo.getTargetComponent().getPackageName(), setString) .apply(); Launcher.getShortcutsCreation().clearAllLayout(); applyChange(activity); } } } }); alert.setNegativeButton(activity.getApplicationContext().getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { Launcher.getShortcutsCreation().clearAllLayout(); } }); alert.show(); }