List of usage examples for android.widget ImageView setPadding
public void setPadding(int left, int top, int right, int bottom)
From source file:com.github.takumalee.simplematerialtabpager.view.PagerSlidingTabStrip.java
private View addIconTab(final int position, int resId) { ImageView tab = new ImageView(getContext()); tab.setImageResource(resId);/* w w w .j a va 2 s . co m*/ tab.setPadding(0, iconPaddingTop, 0, iconPaddingBottom); addTab(position, tab); return tab; }
From source file:com.cube.storm.ui.view.PagerSlidingTabStrip.java
private void addIconTab(final int position, Bitmap bitmap) { ImageView tab = new ImageView(getContext()); tab.setImageBitmap(bitmap);// w w w . j a va 2 s . com tab.setColorFilter(tabIconTint); tab.setScaleType(ScaleType.FIT_CENTER); DisplayMetrics dm = getResources().getDisplayMetrics(); int padding = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm); tab.setPadding(padding + tabPadding, padding, padding + tabPadding, padding); tab.setFocusable(true); tab.setOnClickListener(new OnClickListener() { @Override public void onClick(android.view.View v) { pager.setCurrentItem(position); } }); tabsContainer.addView(tab, position, shouldExpand ? expandedTabLayoutParams : defaultTabLayoutParams); }
From source file:example.example.com.sportsofficial.presentation.views.ViewTabs.java
/** * Create a default view to be used for tabs. This is called if a custom tab view is not set via * {@link #setCustomTabView(int, int, int)}. *//* ww w.j a v a 2 s . c o m*/ protected ImageView createDefaultIconTabView(Context context) { ImageView tabIconImageView = new ImageView(context); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the Theme's // selectableItemBackground to ensure that the View has a pressed state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); tabIconImageView.setBackgroundResource(outValue.resourceId); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); tabIconImageView.setPadding(padding, padding, padding, padding); return tabIconImageView; }
From source file:com.androprogrammer.tutorials.customviews.SlidingTabLayout.java
protected ImageView createDefaultIconTabView(Context context) { ImageView tabIconImageView = new ImageView(context); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the Theme's // selectableItemBackground to ensure that the View has a pressed state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); tabIconImageView.setBackgroundResource(outValue.resourceId); }/*w ww . ja va 2 s . c o m*/ int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); tabIconImageView.setPadding(padding, padding, padding, padding); return tabIconImageView; }
From source file:org.telegram.ui.MessagesActivity.java
@Override public void applySelfActionBar() { if (parentActivity == null) { return;// www . ja va 2 s . c o m } final ActionBar actionBar = parentActivity.getSupportActionBar(); if (onlySelect) { actionBar.setDisplayShowTitleEnabled(true); actionBar.setDisplayShowHomeEnabled(false); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayUseLogoEnabled(false); actionBar.setDisplayShowCustomEnabled(false); actionBar.setSubtitle(null); actionBar.setCustomView(null); actionBar.setTitle(getStringEntry(R.string.SelectChat)); ((ApplicationActivity) parentActivity).fixBackButton(); } else { ImageView view = (ImageView) parentActivity.findViewById(16908332); if (view == null) { view = (ImageView) parentActivity.findViewById(R.id.home); } if (view != null) { view.setPadding(Utilities.dp(6), 0, Utilities.dp(6), 0); } actionBar.setHomeButtonEnabled(false); actionBar.setDisplayShowTitleEnabled(true); actionBar.setDisplayShowHomeEnabled(true); actionBar.setDisplayHomeAsUpEnabled(false); actionBar.setDisplayUseLogoEnabled(true); actionBar.setDisplayShowCustomEnabled(false); actionBar.setCustomView(null); actionBar.setSubtitle(null); actionBar.setTitle(getStringEntry(R.string.AppName)); } TextView title = (TextView) parentActivity.findViewById(R.id.action_bar_title); if (title == null) { final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android"); title = (TextView) parentActivity.findViewById(subtitleId); } if (title != null) { title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0); title.setCompoundDrawablePadding(0); } }
From source file:tk.melnichuk.kommunalchik.CustomViews.SlidingTabLayout.java
private void populateTabStrip() { PagerAdapter adapter = mViewPager.getAdapter(); final OnClickListener tabClickListener = new TabClickListener(); for (int i = 0; i < adapter.getCount(); i++) { View tabView = null;/* w w w . j a v a 2 s . c om*/ TextView tabTitleView = null; if (mTabViewLayoutId != 0) { // If there is a custom tab view layout id set, try and inflate it tabView = LayoutInflater.from(getContext()).inflate(R.layout.bills_menu_icon, mTabStrip, false); int mipmapResName = ((BillsFragment.BillsPagerAdapter) adapter).getMipMapResourceName(i); ImageView imageView = (ImageView) tabView; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { // If we're running on Honeycomb or newer, then we can use the Theme's // selectableItemBackground to ensure that the View has a pressed state TypedValue outValue = new TypedValue(); getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true); imageView.setBackgroundResource(outValue.resourceId); } int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density); imageView.setPadding(2 * padding, padding, 2 * padding, padding); ; // imageView.setLayoutParams(mTabStrip.getLayoutParams()); imageView.setImageResource(mipmapResName); tabView.setOnClickListener(tabClickListener); mTabStrip.addView(imageView); imageView.requestLayout(); continue; } // if (tabView == null) { // tabView = createDefaultTabView(getContext()); // } // if (tabTitleView == null && TextView.class.isInstance(tabView)) { // tabTitleView = (TextView) tabView; // } // tabTitleView.setText(adapter.getPageTitle(i)); // tabView.setOnClickListener(tabClickListener); // mTabStrip.addView(tabView); } }
From source file:com.gh4a.IssueActivity.java
private void fillData() { new LoadCommentsTask(this).execute(); Typeface boldCondensed = getApplicationContext().boldCondensed; ListView lvComments = (ListView) findViewById(R.id.list_view); // set details inside listview header LayoutInflater infalter = getLayoutInflater(); LinearLayout mHeader = (LinearLayout) infalter.inflate(R.layout.issue_header, lvComments, false); mHeader.setClickable(false);//from w w w . ja va2 s. c o m lvComments.addHeaderView(mHeader, null, false); RelativeLayout rlComment = (RelativeLayout) findViewById(R.id.rl_comment); if (!isAuthorized()) { rlComment.setVisibility(View.GONE); } TextView tvCommentTitle = (TextView) mHeader.findViewById(R.id.comment_title); mCommentAdapter = new CommentAdapter(IssueActivity.this, new ArrayList<Comment>(), mIssue.getNumber(), mIssue.getState(), mRepoOwner, mRepoName); lvComments.setAdapter(mCommentAdapter); ImageView ivGravatar = (ImageView) mHeader.findViewById(R.id.iv_gravatar); aq.id(R.id.iv_gravatar).image(GravatarUtils.getGravatarUrl(mIssue.getUser().getGravatarId()), true, false, 0, 0, aq.getCachedImage(R.drawable.default_avatar), AQuery.FADE_IN); ivGravatar.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { getApplicationContext().openUserInfoActivity(IssueActivity.this, mIssue.getUser().getLogin(), null); } }); TextView tvExtra = (TextView) mHeader.findViewById(R.id.tv_extra); TextView tvState = (TextView) mHeader.findViewById(R.id.tv_state); TextView tvTitle = (TextView) mHeader.findViewById(R.id.tv_title); TextView tvDescTitle = (TextView) mHeader.findViewById(R.id.desc_title); tvDescTitle.setTypeface(getApplicationContext().boldCondensed); tvDescTitle.setTextColor(Color.parseColor("#0099cc")); tvCommentTitle.setTypeface(getApplicationContext().boldCondensed); tvCommentTitle.setTextColor(Color.parseColor("#0099cc")); tvCommentTitle .setText(getResources().getString(R.string.issue_comments) + " (" + mIssue.getComments() + ")"); TextView tvDesc = (TextView) mHeader.findViewById(R.id.tv_desc); tvDesc.setMovementMethod(LinkMovementMethod.getInstance()); TextView tvMilestone = (TextView) mHeader.findViewById(R.id.tv_milestone); ImageView ivComment = (ImageView) findViewById(R.id.iv_comment); if (Gh4Application.THEME == R.style.DefaultTheme) { ivComment.setImageResource(R.drawable.social_send_now_dark); } ivComment.setBackgroundResource(R.drawable.abs__list_selector_holo_dark); ivComment.setPadding(5, 2, 5, 2); ivComment.setOnClickListener(this); tvExtra.setText(mIssue.getUser().getLogin() + "\n" + pt.format(mIssue.getCreatedAt())); tvState.setTextColor(Color.WHITE); if ("closed".equals(mIssue.getState())) { tvState.setBackgroundResource(R.drawable.default_red_box); tvState.setText("C\nL\nO\nS\nE\nD"); } else { tvState.setBackgroundResource(R.drawable.default_green_box); tvState.setText("O\nP\nE\nN"); } tvTitle.setText(mIssue.getTitle()); tvTitle.setTypeface(boldCondensed); boolean showInfoBox = false; if (mIssue.getAssignee() != null) { showInfoBox = true; TextView tvAssignee = (TextView) mHeader.findViewById(R.id.tv_assignee); tvAssignee.setText(mIssue.getAssignee().getLogin() + " is assigned"); tvAssignee.setVisibility(View.VISIBLE); tvAssignee.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { getApplicationContext().openUserInfoActivity(IssueActivity.this, mIssue.getAssignee().getLogin(), null); } }); ImageView ivAssignee = (ImageView) mHeader.findViewById(R.id.iv_assignee); aq.id(R.id.iv_assignee).image(GravatarUtils.getGravatarUrl(mIssue.getAssignee().getGravatarId()), true, false, 0, 0, aq.getCachedImage(R.drawable.default_avatar), AQuery.FADE_IN); ivAssignee.setVisibility(View.VISIBLE); ivAssignee.setOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { getApplicationContext().openUserInfoActivity(IssueActivity.this, mIssue.getAssignee().getLogin(), null); } }); } if (mIssue.getMilestone() != null) { showInfoBox = true; tvMilestone.setText( getResources().getString(R.string.issue_milestone) + ": " + mIssue.getMilestone().getTitle()); } else { tvMilestone.setVisibility(View.GONE); } String body = mIssue.getBodyHtml(); if (!StringUtils.isBlank(body)) { HttpImageGetter imageGetter = new HttpImageGetter(this); body = HtmlUtils.format(body).toString(); imageGetter.bind(tvDesc, body, mIssue.getNumber()); } LinearLayout llLabels = (LinearLayout) findViewById(R.id.ll_labels); List<Label> labels = mIssue.getLabels(); if (labels != null && !labels.isEmpty()) { showInfoBox = true; for (Label label : labels) { TextView tvLabel = new TextView(this); tvLabel.setSingleLine(true); tvLabel.setText(label.getName()); tvLabel.setTextAppearance(this, R.style.default_text_small); tvLabel.setBackgroundColor(Color.parseColor("#" + label.getColor())); tvLabel.setPadding(5, 2, 5, 2); int r = Color.red(Color.parseColor("#" + label.getColor())); int g = Color.green(Color.parseColor("#" + label.getColor())); int b = Color.blue(Color.parseColor("#" + label.getColor())); if (r + g + b < 383) { tvLabel.setTextColor(getResources().getColor(android.R.color.primary_text_dark)); } else { tvLabel.setTextColor(getResources().getColor(android.R.color.primary_text_light)); } llLabels.addView(tvLabel); View v = new View(this); v.setLayoutParams(new LayoutParams(5, LayoutParams.WRAP_CONTENT)); llLabels.addView(v); } } else { llLabels.setVisibility(View.GONE); } TextView tvPull = (TextView) mHeader.findViewById(R.id.tv_pull); if (mIssue.getPullRequest() != null && mIssue.getPullRequest().getDiffUrl() != null) { showInfoBox = true; tvPull.setVisibility(View.VISIBLE); tvPull.setOnClickListener(this); } if (!showInfoBox) { RelativeLayout rl = (RelativeLayout) mHeader.findViewById(R.id.info_box); rl.setVisibility(View.GONE); } }
From source file:net.jongrakko.zipsuri.activity.PostReviseActivity.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { if (resultCode == Activity.RESULT_OK && requestCode == UCrop.REQUEST_CROP) { File cropFile = new File(UCrop.getOutput(data).getPath()); int index = 0; for (int id : postImageViewIds) { ImageView mImageView = (ImageView) rootView.findViewById(id); if (mImageView.getTag() == null) { rootView.findViewById(postImageViewPlusIds[index]).setVisibility(View.VISIBLE); rootView.findViewById(postImageViewRemoveIds[index]).setVisibility(View.VISIBLE); mImageView.setImageBitmap(BitmapFactory.decodeFile(cropFile.getPath())); mImageView.setScaleType(ImageView.ScaleType.FIT_XY); mImageView.setPadding(10, 10, 10, 10); mImageView.setTag(cropFile.getPath()); mImageViewTitle.setImageDrawable(((ImageView) rootView.findViewById(id)).getDrawable()); mImageViewTitle.setTag(id); break; }/*from www . jav a2 s .c o m*/ index++; } } else if (resultCode == Activity.RESULT_OK && requestCode == PICK_PHOTO_FOR_AVATAR) { UCrop.of(data.getData(), Uri.fromFile( new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg"))) .withMaxResultSize(1920, 1920).start(getContext(), this); } else if (resultCode == Activity.RESULT_OK && requestCode == TAKE_PHOTO_FOR_AVATAR) { UCrop.of(Uri.fromFile(takeFile), Uri.fromFile( new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), System.currentTimeMillis() + ".jpg"))) .withMaxResultSize(1920, 1920).start(getContext(), this); } else if (resultCode == UCrop.RESULT_ERROR) { final Throwable cropError = UCrop.getError(data); Log.d("mox", "croperror" + cropError.toString()); } else if (resultCode == Activity.RESULT_OK && requestCode == SEARCH_ADDRESS) { AddressModel mAddressModel = (AddressModel) data.getSerializableExtra("data"); setAddressModel(mAddressModel); } else if (resultCode == Activity.RESULT_OK && requestCode == PICK_VIDEO_FOR_AVATAR) { String path = getPath(data.getData()); showVideoAlertDialog(path); } else if (resultCode == Activity.RESULT_OK && requestCode == TAKE_VIDEO_FOR_AVATAR) { String path = takeFile.getPath(); showVideoAlertDialog(path); } }
From source file:com.teitsmch.hearthmaker.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.navigation_drawer, menu); final MenuItem item = menu.findItem(R.id.action_search); //item.setActionView(R.layout.iv_rotate); //ImageView refresh = (ImageView) item.getActionView(); final ImageView image = new ImageView(this); ViewGroup.MarginLayoutParams layoutParams = new ViewGroup.MarginLayoutParams( ViewGroup.MarginLayoutParams.WRAP_CONTENT, ViewGroup.MarginLayoutParams.WRAP_CONTENT); image.setLayoutParams(layoutParams); image.setImageResource(R.drawable.ic_filter_list_24dp); int padding_in_dp = 16; final float scale = getResources().getDisplayMetrics().density; int padding_in_px = (int) (padding_in_dp * scale + 0.5f); image.setPadding(padding_in_px, 0, padding_in_px, 0); image.setOnClickListener(new View.OnClickListener() { @Override//from www . ja va2s . com public void onClick(View v) { if (mSpinnerView.getVisibility() == View.VISIBLE) image.setImageResource(R.drawable.rev_ic_filter_list_24dp); else image.setImageResource(R.drawable.ic_filter_list_24dp); onOptionsItemSelected(item); } }); item.setActionView(image); if (mFragment.getClass() == CardViewFragment.class) { menu.findItem(MENU_ITEM_RENAME).setVisible(false); menu.findItem(MENU_ITEM_CLEAR).setVisible(false); menu.findItem(MENU_ITEM_DELETE).setVisible(false); menu.findItem(R.id.class_icon).setVisible(false); } else { menu.findItem(MENU_ITEM_RENAME).setVisible(true); menu.findItem(MENU_ITEM_CLEAR).setVisible(true); menu.findItem(MENU_ITEM_DELETE).setVisible(true); menu.findItem(R.id.class_icon).setVisible(true); menu.findItem(R.id.class_icon).setIcon(classIcon); } return super.onCreateOptionsMenu(menu); }
From source file:onion.chat.MainActivity.java
void showQR() { String name = db.getName();/*from w w w. ja va2 s . co m*/ String txt = "Its Ur's " + tor.getID() + " " + name; QRCode qr; try { //qr = Encoder.encode(txt, ErrorCorrectionLevel.H); qr = Encoder.encode(txt, ErrorCorrectionLevel.M); } catch (Exception ex) { throw new Error(ex); } ByteMatrix mat = qr.getMatrix(); int width = mat.getWidth(); int height = mat.getHeight(); int[] pixels = new int[width * height]; for (int y = 0; y < height; y++) { int offset = y * width; for (int x = 0; x < width; x++) { pixels[offset + x] = mat.get(x, y) != 0 ? Color.BLACK : Color.WHITE; } } Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); bitmap.setPixels(pixels, 0, width, 0, 0, width, height); bitmap = Bitmap.createScaledBitmap(bitmap, bitmap.getWidth() * 8, bitmap.getHeight() * 8, false); ImageView view = new ImageView(this); view.setImageBitmap(bitmap); int pad = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, getResources().getDisplayMetrics()); view.setPadding(pad, pad, pad, pad); Rect displayRectangle = new Rect(); Window window = getWindow(); window.getDecorView().getWindowVisibleDisplayFrame(displayRectangle); int s = (int) (Math.min(displayRectangle.width(), displayRectangle.height()) * 0.9); view.setMinimumWidth(s); view.setMinimumHeight(s); new AlertDialog.Builder(this) //.setMessage(txt) .setView(view).show(); }