Java Code Examples for android.widget.ImageView#setPadding()

The following examples show how to use android.widget.ImageView#setPadding() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
public ChatUnreadCell(Context context) {
    super(context);

    backgroundLayout = new FrameLayout(context);
    backgroundLayout.setBackgroundResource(R.drawable.newmsg_divider);
    backgroundLayout.getBackground().setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_unreadMessagesStartBackground), PorterDuff.Mode.MULTIPLY));
    addView(backgroundLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 27, Gravity.LEFT | Gravity.TOP, 0, 7, 0, 0));

    imageView = new ImageView(context);
    imageView.setImageResource(R.drawable.ic_ab_new);
    imageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_unreadMessagesStartArrowIcon), PorterDuff.Mode.MULTIPLY));
    imageView.setPadding(0, AndroidUtilities.dp(2), 0, 0);
    backgroundLayout.addView(imageView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.RIGHT | Gravity.CENTER_VERTICAL, 0, 0, 10, 0));

    textView = new TextView(context);
    textView.setPadding(0, 0, 0, AndroidUtilities.dp(1));
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    textView.setTextColor(Theme.getColor(Theme.key_chat_unreadMessagesStartText));
    textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    addView(textView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
}
 
Example 2
Source Project: UltimateAndroid   File: PagerIndicator.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * redraw the indicators.
 */
public void redraw(){
    mItemCount = getShouldDrawCount();
    mPreviousSelectedIndicator = null;
    for(View i:mIndicators){
        removeView(i);
    }


    for(int i =0 ;i< mItemCount; i++){
        ImageView indicator = new ImageView(mContext);
        indicator.setImageDrawable(mUnselectedDrawable);
        indicator.setPadding((int)mUnSelectedPadding_Left,
                (int)mUnSelectedPadding_Top,
                (int)mUnSelectedPadding_Right,
                (int)mUnSelectedPadding_Bottom);
        addView(indicator);
        mIndicators.add(indicator);
    }
    setItemAsSelected(mPreviousSelectedPosition);
}
 
Example 3
Source Project: LockPattern   File: LockPatternView.java    License: MIT License 6 votes vote down vote up
private ImageView addPatternNewItem(){
    ImageView item = new ImageView(mContext);
    item.setImageBitmap(mDotBitmapNormal);
    int scale = 2;
    if (mPatternItemParams == null){
        mPatternItemParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        mPatternItemParams.gravity = Gravity.CENTER_VERTICAL;
        mPatternItemMargin = Math.round(mPatternItemMargin * mDisplayDensity);
        mPatternItemParams.setMargins(mPatternItemMargin, mPatternItemMargin, mPatternItemMargin, mPatternItemMargin);
    }

    mPatternItemParams.weight = 1f;

    item.setPadding(mPatternItemPadding, mPatternItemPadding * scale,
            mPatternItemPadding, mPatternItemPadding * scale);
    item.setLayoutParams(mPatternItemParams);

    mAllDots.add(item);
    item.setTag(String.valueOf(mTouchedDotFirst));
    mTouchedDotFirst++;

    item.setVisibility(INVISIBLE);

    return item;
}
 
Example 4
@Override
protected void onCreate(Bundle savedInstanceState) {
  // Log.d(TAG, "onCreate");
  super.onCreate(savedInstanceState);
  setContentView(mResourceFragmentPager);

  // Set up the action bar
  final ActionBar actionBar = getActionBar();
  actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
  ImageView view = (ImageView) findViewById(android.R.id.home);
  view.setPadding(10, 0, 20, 10);

  // Set up the ViewPager with the sections adapter.
  mViewPager = (ViewPager) findViewById(mResourceIdPager);
  mViewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
    @Override
    public void onPageSelected(int n) {
      // Log.d(TAG, "onPageSelected: " + n);
      actionBar.setSelectedNavigationItem(n);
    }
  });
  // Create the adapter that will return a fragment for each section
  mSectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager());

  // Set up the ViewPager with the sections adapter.
  mViewPager.setAdapter(mSectionsPagerAdapter);
}
 
Example 5
public PickerAdapter(Context context, AttributeSet attrs) {

		super(context, attrs);
		icon = new ImageView(context);
		icon.setLayoutParams(pro);
		icon.setPadding(6, 5, 15, 5);
		addView(icon);
		name = new TextView(context);
		name.setPadding(8, 15, 2, 2);
		name.setTextColor(Color.BLACK);
		name.setTextSize(20);
		addView(name);

	}
 
Example 6
Source Project: AutoTest   File: ActionSheetDialog.java    License: MIT License 5 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    final DialogMenuItem item = mContents.get(position);

    LinearLayout llItem = new LinearLayout(mContext);
    llItem.setOrientation(LinearLayout.HORIZONTAL);
    llItem.setGravity(Gravity.CENTER_VERTICAL);

    ImageView ivItem = new ImageView(mContext);
    ivItem.setPadding(0, 0, dp2px(15), 0);
    llItem.addView(ivItem);

    TextView tvItem = new TextView(mContext);
    tvItem.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    tvItem.setSingleLine(true);
    tvItem.setGravity(Gravity.CENTER);
    tvItem.setTextColor(mItemTextColor);
    tvItem.setTextSize(TypedValue.COMPLEX_UNIT_SP, mItemTextSize);
    tvItem.setHeight(dp2px(mItemHeight));

    llItem.addView(tvItem);
    float radius = dp2px(mCornerRadius);
    if (mIsTitleShow) {
        llItem.setBackgroundDrawable((CornerUtils.listItemSelector(radius, Color.TRANSPARENT, mItemPressColor,
                position == mContents.size() - 1)));
    } else {
        llItem.setBackgroundDrawable(CornerUtils.listItemSelector(radius, Color.TRANSPARENT, mItemPressColor,
                mContents.size(), position));
    }

    ivItem.setImageResource(item.mResId);
    tvItem.setText(item.mOperName);
    ivItem.setVisibility(item.mResId == 0 ? View.GONE : View.VISIBLE);

    return llItem;
}
 
Example 7
Source Project: recent-images   File: ImageAdapter.java    License: MIT License 5 votes vote down vote up
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
	ImageView imageView = new BetterImageView(mContext.getApplicationContext());
	imageView.setLayoutParams(new TwoWayAbsListView.LayoutParams(mImageWidth, mImageHeight));
	imageView.setPadding(mImagePadding, mImagePadding, mImagePadding, mImagePadding);
	imageView.setScaleType(SCALE_TYPE);
	return imageView;
}
 
Example 8
Source Project: ChangeTabLayout   File: ChangeTabLayout.java    License: Apache License 2.0 5 votes vote down vote up
protected LinearLayout createTabView(CharSequence title, int icon, int selectIcon) {

        LinearLayout mLinearLayout = new LinearLayout(getContext());
        mLinearLayout.setOrientation(LinearLayout.HORIZONTAL);
        mLinearLayout.setGravity(Gravity.CENTER_VERTICAL);
        mLinearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, tabViewHeight));

        ImageView imageView = new ImageView(getContext());
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(tabImageHeight + (int) (16 * density), tabViewHeight);
        imageView.setPadding((int) (9 * density), 0, (int) (7 * density), 0);
        imageView.setLayoutParams(lp);

        RevealDrawable drawable;

        if(selectIcon != 0){
            drawable = new RevealDrawable(DrawableUtils.getDrawable(getContext(), icon), DrawableUtils.getDrawable(getContext(), selectIcon), RevealDrawable.VERTICAL);
        }else{
            drawable = new RevealDrawable(DrawableUtils.getTabDrawable(getContext(), icon, defaultTabImageColor),
                    DrawableUtils.getTabDrawable(getContext(), icon, selectedTabImageColor), RevealDrawable.VERTICAL);
        }

        imageView.setImageDrawable(drawable);

        ChangeTextView textView = new ChangeTextView(getContext());
        textView.setDefaultTabTextColor(defaultTabTextColor);
        textView.setSelectedTabTextColor(selectedTabTextColor);
        textView.setIndicatorPadding(indicatorPadding);
        textView.setTabViewTextSize(textSize);
        textView.setText(title.toString());
        textView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));

        mLinearLayout.addView(imageView);
        mLinearLayout.addView(textView);
        return mLinearLayout;
    }
 
Example 9
Source Project: timecat   File: UserDetailActivity.java    License: Apache License 2.0 5 votes vote down vote up
private void setupColorChooser() {

        colorList = findViewById(R.id.color_chooser);
        colorList.removeAllViews();

        for (final String hex : COLORS) {
            ImageView colorView = (ImageView) getLayoutInflater().inflate(R.layout.item_color_chooser, null);
            final int color = Color.parseColor(hex);
            colorView.setBackgroundColor(color);
            colorView.setPadding(2, 2, 2, 2);
            if (color == user.color()) {
                colorView.setImageDrawable(new IconicsDrawable(this).icon(CommunityMaterial.Icon.cmd_checkbox_marked_circle).paddingDp(30).color(Color.WHITE).sizeDp(80));
            } else {
                colorView.setImageDrawable(new IconicsDrawable(this).icon(CommunityMaterial.Icon.cmd_checkbox_marked_circle).paddingDp(30).color(Color.TRANSPARENT).sizeDp(80));
            }
            colorView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    user.setColor(color);
                    setupColorChooser();
                    int x = (int) view.getX() + view.getWidth() / 2 - colorScroll.getScrollX();
                    updateAvatar(user.avatar(), 1, 400, x);
                    colorList.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            scrollToColor(color);
                        }
                    }, 300);
                    //Toast.makeText(getBaseContext(), "Color: " + hex, Toast.LENGTH_SHORT).show();
                }
            });
            colorList.addView(colorView);
        }
    }
 
Example 10
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    AlertDialog.Builder builder = new AlertDialog.Builder(getContext());

    Bundle args = getArguments();
    if (args == null) {
        return super.onCreateDialog(savedInstanceState);
    }
    String name = args.getString("name");
    String url = args.getString("url");

    ImageView avatarView = new ImageView(getContext());
    int padding = getResources().getDimensionPixelSize(R.dimen.material_standard);
    avatarView.setPadding(0, padding, 0, 0);
    ImageUtils.loadAvatar(avatarView, url);
    if (!TextUtils.isEmpty(url)) {
        avatarView.setOnClickListener(v -> {
            Intent intent = new Intent();
            intent.putExtra(ImageZoomActivity.KEY_GALLERY_CUR_URL, url);
            intent.setClass(getContext(), ImageZoomActivity.class);
            getContext().startActivity(intent);
        });
    }

    builder.setTitle(name + "的头像")
            .setView(avatarView)
            .setPositiveButton("关闭", null);

    return builder.create();
}
 
Example 11
Source Project: FlycoDialog_Master   File: TestAdapter.java    License: MIT License 5 votes vote down vote up
@Override
public View getView(int position, View convertView, ViewGroup parent) {
	final DialogMenuItem item = mMenuItems.get(position);

	LinearLayout ll_item = new LinearLayout(mContext);
	ll_item.setOrientation(LinearLayout.HORIZONTAL);
	ll_item.setGravity(Gravity.CENTER_VERTICAL);

	ImageView iv_item = new ImageView(mContext);
	iv_item.setPadding(0, 0, (int) (15 * mDisplayMetrics.density), 0);
	ll_item.addView(iv_item);

	TextView tv_item = new TextView(mContext);
	tv_item.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
			LinearLayout.LayoutParams.WRAP_CONTENT));
	tv_item.setSingleLine(true);
	tv_item.setTextColor(Color.parseColor("#303030"));
	tv_item.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14);

	ll_item.addView(tv_item);
	ll_item.setPadding(item.mResId == 0 ? (int) (18 * mDisplayMetrics.density) : (int) (16 * mDisplayMetrics.density), (int) (10 * mDisplayMetrics.density), 0,
			(int) (10 * mDisplayMetrics.density));

	iv_item.setImageResource(item.mResId);
	tv_item.setText(item.mOperName);
	iv_item.setVisibility(item.mResId == 0 ? View.GONE : View.VISIBLE);

	return ll_item;
}
 
Example 12
Source Project: TGPassportAndroidSDK   File: TelegramPassport.java    License: MIT License 5 votes vote down vote up
/**
 * Show an app installation alert, in case you need to do that yourself.
 * @param activity calling Activity
 */
public static void showAppInstallAlert(final Activity activity){
	String appName=null;
	try{
		PackageManager pm=activity.getPackageManager();
		appName=pm.getApplicationLabel(pm.getApplicationInfo(activity.getPackageName(), 0)).toString().replace("<", "&lt;");
	}catch(PackageManager.NameNotFoundException ignore){}
	ImageView banner=new ImageView(activity);
	banner.setImageResource(R.drawable.telegram_logo_large);
	banner.setBackgroundColor(0xFF4fa9e6);
	float dp=activity.getResources().getDisplayMetrics().density;
	int pad=Math.round(34*dp);
	banner.setPadding(0, pad, 0, pad);
	LinearLayout content=new LinearLayout(activity);
	content.setOrientation(LinearLayout.VERTICAL);
	content.addView(banner);
	TextView alertText=new TextView(activity);
	alertText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
	alertText.setTextColor(0xFF000000);
	alertText.setText(Html.fromHtml(activity.getString(R.string.PassportSDK_DownloadTelegram, appName).replaceAll("\\*\\*([^*]+)\\*\\*", "<b>$1</b>")));
	alertText.setPadding(Math.round(24*dp), Math.round(24*dp), Math.round(24*dp), Build.VERSION.SDK_INT<Build.VERSION_CODES.LOLLIPOP ? Math.round(24*dp) : Math.round(2*dp));
	content.addView(alertText);
	AlertDialog alert=new AlertDialog.Builder(activity, /*Build.VERSION.SDK_INT<Build.VERSION_CODES.LOLLIPOP ? AlertDialog.THEME_HOLO_LIGHT :*/ R.style.Theme_Telegram_Alert)
			.setView(content)
			.setPositiveButton(R.string.PassportSDK_OpenGooglePlay, new DialogInterface.OnClickListener(){
				@Override
				public void onClick(DialogInterface dialog, int which){
					activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=org.telegram.messenger")));
				}
			})
			.setNegativeButton(R.string.PassportSDK_Cancel, null)
			.show();
	if(Build.VERSION.SDK_INT<Build.VERSION_CODES.LOLLIPOP){
		int titleDividerId=activity.getResources().getIdentifier("titleDivider", "id", "android");
		View titleDivider=alert.findViewById(titleDividerId);
		if(titleDivider!=null){
			titleDivider.setVisibility(View.GONE);
		}
	}
}
 
Example 13
private void initView(Context context) {
    measurementRow = new TableRow(context);

    iconView = new ImageView(context);
    iconViewBackground = new GradientDrawable();
    nameView = new TextView(context);
    valueView = new TextView(context);
    editModeView = new ImageView(context);
    indicatorView = new ImageView(context);

    evaluatorRow = new TableRow(context);
    evaluatorView = new LinearGaugeView(context);

    incDecLayout = new LinearLayout(context);

    measurementRow.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT, 1.0f));
    measurementRow.setGravity(Gravity.CENTER);
    measurementRow.addView(iconView);
    measurementRow.addView(nameView);
    measurementRow.addView(valueView);
    measurementRow.addView(incDecLayout);
    measurementRow.addView(editModeView);
    measurementRow.addView(indicatorView);

    addView(measurementRow);
    addView(evaluatorRow);

    iconViewBackground.setColor(ColorUtil.COLOR_GRAY);
    iconViewBackground.setShape(GradientDrawable.OVAL);
    iconViewBackground.setGradientRadius(iconView.getWidth());

    iconView.setImageResource(iconId);
    iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    iconView.setPadding(25,25,25,25);

    iconView.setColorFilter(ColorUtil.COLOR_BLACK);
    iconView.setBackground(iconViewBackground);

    TableRow.LayoutParams iconLayout = new TableRow.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    iconLayout.setMargins(10, 5, 10, 5);
    iconView.setLayoutParams(iconLayout);

    nameView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
    nameView.setLines(2);
    nameView.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 0.55f));

    valueView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
    valueView.setGravity(Gravity.RIGHT | Gravity.CENTER);
    valueView.setPadding(0,0,20,0);
    valueView.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 0.29f));

    incDecLayout.setOrientation(VERTICAL);
    incDecLayout.setVisibility(View.GONE);
    incDecLayout.setPadding(0,0,0,0);
    incDecLayout.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.MATCH_PARENT, 0.05f));

    editModeView.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_editable));
    editModeView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
    editModeView.setVisibility(View.GONE);
    editModeView.setColorFilter(getForegroundColor());

    indicatorView.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.MATCH_PARENT, 0.01f));
    indicatorView.setBackgroundColor(Color.GRAY);

    evaluatorRow.setLayoutParams(new TableRow.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT, 1.0f));
    evaluatorRow.addView(new Space(context));
    evaluatorRow.addView(evaluatorView);
    Space spaceAfterEvaluatorView = new Space(context);
    evaluatorRow.addView(spaceAfterEvaluatorView);
    evaluatorRow.setVisibility(View.GONE);

    evaluatorView.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 0.99f));
    spaceAfterEvaluatorView.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 0.01f));

    setOnClickListener(new onClickListenerEvaluation());
}
 
Example 14
public IndicatorLayout(Context context, PullToRefreshBase.Mode mode) {
	super(context);
	mArrowImageView = new ImageView(context);

	Drawable arrowD = getResources().getDrawable(R.drawable.indicator_arrow);
	mArrowImageView.setImageDrawable(arrowD);

	final int padding = getResources().getDimensionPixelSize(R.dimen.indicator_internal_padding);
	mArrowImageView.setPadding(padding, padding, padding, padding);
	addView(mArrowImageView);

	int inAnimResId, outAnimResId;
	switch (mode) {
		case PULL_FROM_END:
			inAnimResId = R.anim.slide_in_from_bottom;
			outAnimResId = R.anim.slide_out_to_bottom;
			setBackgroundResource(R.drawable.indicator_bg_bottom);

			// Rotate Arrow so it's pointing the correct way
			mArrowImageView.setScaleType(ScaleType.MATRIX);
			Matrix matrix = new Matrix();
			matrix.setRotate(180f, arrowD.getIntrinsicWidth() / 2f, arrowD.getIntrinsicHeight() / 2f);
			mArrowImageView.setImageMatrix(matrix);
			break;
		default:
		case PULL_FROM_START:
			inAnimResId = R.anim.slide_in_from_top;
			outAnimResId = R.anim.slide_out_to_top;
			setBackgroundResource(R.drawable.indicator_bg_top);
			break;
	}

	mInAnim = AnimationUtils.loadAnimation(context, inAnimResId);
	mInAnim.setAnimationListener(this);

	mOutAnim = AnimationUtils.loadAnimation(context, outAnimResId);
	mOutAnim.setAnimationListener(this);

	final Interpolator interpolator = new LinearInterpolator();
	mRotateAnimation = new RotateAnimation(0, -180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
			0.5f);
	mRotateAnimation.setInterpolator(interpolator);
	mRotateAnimation.setDuration(DEFAULT_ROTATION_ANIMATION_DURATION);
	mRotateAnimation.setFillAfter(true);

	mResetRotateAnimation = new RotateAnimation(-180, 0, Animation.RELATIVE_TO_SELF, 0.5f,
			Animation.RELATIVE_TO_SELF, 0.5f);
	mResetRotateAnimation.setInterpolator(interpolator);
	mResetRotateAnimation.setDuration(DEFAULT_ROTATION_ANIMATION_DURATION);
	mResetRotateAnimation.setFillAfter(true);

}
 
Example 15
public void drawItemView() {
    if (!mInitialized) {
        return;
    }

    clearUi();

    float totalPadding = getPaddingLeft() + getPaddingRight();
    int indexFrontView = 0;

    LayoutParams itemParams = getItemLayoutParams();

    for (int i = 0; i < mItems.size(); i++) {
        final Item item = mItems.get(i);
        if (mCheckedItems != null && mCheckedItems.containsKey(item.id)) {
            item.isSelected = true;
        }

        final int position = i;
        final View itemLayout = createItemView(item);

        if (!simplifiedTags) {
            itemLayout.setOnClickListener(new OnClickListener() {
                @Override
                public void onClick(View v) {
                    animateView(v);
                    item.isSelected = !item.isSelected;
                    if (item.isSelected) {
                        mCheckedItems.put(item.id, item);
                    } else {
                        mCheckedItems.remove(item.id);
                    }

                    if (isJellyBeanAndAbove()) {
                        itemLayout.setBackground(getSelector(item));
                    } else {
                        itemLayout.setBackgroundDrawable(getSelector(item));
                    }
                    ImageView iconView = (ImageView) itemLayout.findViewById(R.id.item_icon);
                    iconView.setBackgroundResource(getItemIcon(item.isSelected));
                    if (mClickListener != null) {
                        mClickListener.onClick(item, position);
                    }
                }
            });
        }

        TextView itemTextView = (TextView) itemLayout.findViewById(R.id.item_name);
        itemTextView.setText(item.text);
        itemTextView.setPadding(textPaddingLeft, textPaddingTop, textPaddingRight,
                texPaddingBottom);
        itemTextView.setTextColor(getResources().getColor(mTextColor));

        float itemWidth = itemTextView.getPaint().measureText(item.text) + textPaddingLeft
                + textPaddingRight;

        // if (!simplifiedTags) {
        ImageView indicatorView = (ImageView) itemLayout.findViewById(R.id.item_icon);
        indicatorView.setBackgroundResource(getItemIcon(item.isSelected));
        indicatorView.setPadding(0, textPaddingTop, textPaddingRight, texPaddingBottom);

        if (simplifiedTags) {
            indicatorView.setVisibility(View.GONE);
        }

        itemWidth += Utils.dpToPx(getContext(), 30) + textPaddingLeft
                + textPaddingRight;

        if (mWidth <= totalPadding + itemWidth + Utils
                .dpToPx(this.getContext(), LAYOUT_WIDTH_OFFSET)) {
            totalPadding = getPaddingLeft() + getPaddingRight();
            indexFrontView = i;
            addItemView(itemLayout, itemParams, true, i);
        } else {
            if (i != indexFrontView) {
                itemParams.leftMargin = mItemMargin;
                totalPadding += mItemMargin;
            }
            addItemView(itemLayout, itemParams, false, i);
        }
        totalPadding += itemWidth;
    }
    // }
}
 
Example 16
private LinearLayout getView(int position, OnClickListener ocL, Context context) {
	Bitmap logo;
	String label;
	OnClickListener listener;
	if (beans[position] instanceof Platform) {
		logo = getIcon((Platform) beans[position]);
		label = getName((Platform) beans[position]);
		listener = ocL;
	} else {
		logo = ((CustomerLogo) beans[position]).enableLogo;
		label = ((CustomerLogo) beans[position]).label;
		listener = ocL;
	}

	LinearLayout ll = new LinearLayout(context);
	ll.setOrientation(LinearLayout.VERTICAL);

	ImageView iv = new ImageView(context);
	int dp_5 = com.mob.tools.utils.R.dipToPx(context, 5);
	iv.setPadding(dp_5, dp_5, dp_5, dp_5);
	iv.setScaleType(ScaleType.CENTER_INSIDE);
	LayoutParams lpIv = new LayoutParams(
			LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	lpIv.setMargins(dp_5, dp_5, dp_5, dp_5);
	lpIv.gravity = Gravity.CENTER_HORIZONTAL;
	iv.setLayoutParams(lpIv);
	iv.setImageBitmap(logo);
	ll.addView(iv);

	TextView tv = new TextView(context);
	tv.setTextColor(0xff303030);
	tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
	tv.setSingleLine();
	tv.setIncludeFontPadding(false);
	LayoutParams lpTv = new LayoutParams(
			LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
	lpTv.gravity = Gravity.CENTER_HORIZONTAL;
	lpTv.weight = 1;
	lpTv.setMargins(dp_5, 0, dp_5, dp_5);
	tv.setLayoutParams(lpTv);
	tv.setText(label);
	ll.addView(tv);
	ll.setOnClickListener(listener);

	return ll;
}
 
Example 17
public IndicatorLayout(Context context, PullToRefreshBase.Mode mode) {
	super(context);
	mArrowImageView = new ImageView(context);

	Drawable arrowD = getResources().getDrawable(R.drawable.indicator_arrow);
	mArrowImageView.setImageDrawable(arrowD);

	final int padding = getResources().getDimensionPixelSize(R.dimen.indicator_internal_padding);
	mArrowImageView.setPadding(padding, padding, padding, padding);
	addView(mArrowImageView);

	int inAnimResId, outAnimResId;
	switch (mode) {
		case PULL_FROM_END:
			inAnimResId = R.anim.slide_in_from_bottom;
			outAnimResId = R.anim.slide_out_to_bottom;
			setBackgroundResource(R.drawable.indicator_bg_bottom);

			// Rotate Arrow so it's pointing the correct way
			mArrowImageView.setScaleType(ScaleType.MATRIX);
			Matrix matrix = new Matrix();
			matrix.setRotate(180f, arrowD.getIntrinsicWidth() / 2f, arrowD.getIntrinsicHeight() / 2f);
			mArrowImageView.setImageMatrix(matrix);
			break;
		default:
		case PULL_FROM_START:
			inAnimResId = R.anim.slide_in_from_top;
			outAnimResId = R.anim.slide_out_to_top;
			setBackgroundResource(R.drawable.indicator_bg_top);
			break;
	}

	mInAnim = AnimationUtils.loadAnimation(context, inAnimResId);
	mInAnim.setAnimationListener(this);

	mOutAnim = AnimationUtils.loadAnimation(context, outAnimResId);
	mOutAnim.setAnimationListener(this);

	final Interpolator interpolator = new LinearInterpolator();
	mRotateAnimation = new RotateAnimation(0, -180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
			0.5f);
	mRotateAnimation.setInterpolator(interpolator);
	mRotateAnimation.setDuration(DEFAULT_ROTATION_ANIMATION_DURATION);
	mRotateAnimation.setFillAfter(true);

	mResetRotateAnimation = new RotateAnimation(-180, 0, Animation.RELATIVE_TO_SELF, 0.5f,
			Animation.RELATIVE_TO_SELF, 0.5f);
	mResetRotateAnimation.setInterpolator(interpolator);
	mResetRotateAnimation.setDuration(DEFAULT_ROTATION_ANIMATION_DURATION);
	mResetRotateAnimation.setFillAfter(true);

}
 
Example 18
Source Project: GifAssistant   File: IndicatorLayout.java    License: Apache License 2.0 4 votes vote down vote up
public IndicatorLayout(Context context, PullToRefreshBase.Mode mode) {
	super(context);
	mArrowImageView = new ImageView(context);

	Drawable arrowD = getResources().getDrawable(R.mipmap.indicator_arrow);
	mArrowImageView.setImageDrawable(arrowD);

	final int padding = getResources().getDimensionPixelSize(R.dimen.indicator_internal_padding);
	mArrowImageView.setPadding(padding, padding, padding, padding);
	addView(mArrowImageView);

	int inAnimResId, outAnimResId;
	switch (mode) {
		case PULL_FROM_END:
			inAnimResId = R.anim.slide_in_from_bottom;
			outAnimResId = R.anim.slide_out_to_bottom;
			setBackgroundResource(R.drawable.indicator_bg_bottom);

			// Rotate Arrow so it's pointing the correct way
			mArrowImageView.setScaleType(ScaleType.MATRIX);
			Matrix matrix = new Matrix();
			matrix.setRotate(180f, arrowD.getIntrinsicWidth() / 2f, arrowD.getIntrinsicHeight() / 2f);
			mArrowImageView.setImageMatrix(matrix);
			break;
		default:
		case PULL_FROM_START:
			inAnimResId = R.anim.slide_in_from_top;
			outAnimResId = R.anim.slide_out_to_top;
			setBackgroundResource(R.drawable.indicator_bg_top);
			break;
	}

	mInAnim = AnimationUtils.loadAnimation(context, inAnimResId);
	mInAnim.setAnimationListener(this);

	mOutAnim = AnimationUtils.loadAnimation(context, outAnimResId);
	mOutAnim.setAnimationListener(this);

	final Interpolator interpolator = new LinearInterpolator();
	mRotateAnimation = new RotateAnimation(0, -180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
			0.5f);
	mRotateAnimation.setInterpolator(interpolator);
	mRotateAnimation.setDuration(DEFAULT_ROTATION_ANIMATION_DURATION);
	mRotateAnimation.setFillAfter(true);

	mResetRotateAnimation = new RotateAnimation(-180, 0, Animation.RELATIVE_TO_SELF, 0.5f,
			Animation.RELATIVE_TO_SELF, 0.5f);
	mResetRotateAnimation.setInterpolator(interpolator);
	mResetRotateAnimation.setDuration(DEFAULT_ROTATION_ANIMATION_DURATION);
	mResetRotateAnimation.setFillAfter(true);

}
 
Example 19
Source Project: TabletClock   File: WeatherView.java    License: MIT License 4 votes vote down vote up
public WeatherView(Context context, AttributeSet attrs) {
	super(context, attrs);
	WeatherUnits.setResourceContext(context.getApplicationContext());
	if (ICON_ASPECT_RATIO == 0.0f) {
		Drawable r = getResources().getDrawable(R.drawable.p01d);
		ICON_ASPECT_RATIO = (float) r.getIntrinsicHeight()
				/ (float) r.getIntrinsicWidth();
		mIconViewWidth = r.getIntrinsicWidth();
		mIconViewHeight = r.getIntrinsicHeight();
	}
	setOrientation(HORIZONTAL);
	LinearLayout layoutV1 = new LinearLayout(getContext());
	FrameLayout fLayout = new FrameLayout(getContext());
	mIconBrightnessView = new View(getContext());
	mWhenView = new TextView(getContext());
	mMoonView = new ImageView(getContext());
	mIconView = new ImageView(getContext());
	mDescriptionView = new TextView(getContext());

	layoutV1.setOrientation(VERTICAL);
	mWhenView.setGravity(Gravity.CENTER_HORIZONTAL);
	mMoonView.setScaleType(ScaleType.MATRIX);
	mIconView.setScaleType(ScaleType.MATRIX);
	setPadding(0, 0, 0, 0);
	layoutV1.setPadding(0, 0, 0, 0);
	mMoonView.setPadding(0, ICON_PADDING, ICON_PADDING, 0);
	mIconView.setPadding(0, ICON_PADDING, ICON_PADDING, 0);
	mIconBrightnessView.setPadding(0, ICON_PADDING, ICON_PADDING, 0);

	fLayout.addView(mMoonView);
	fLayout.addView(mIconView);
	fLayout.addView(mIconBrightnessView);

	layoutV1.addView(mWhenView);
	layoutV1.addView(fLayout);

	addView(layoutV1);
	addView(mDescriptionView);

	mFontSize = mWhenView.getTextSize();
}
 
Example 20
public IndicatorLayout(Context context, PullToRefreshBase.Mode mode) {
	super(context);
	mArrowImageView = new ImageView(context);

	Drawable arrowD = getResources().getDrawable(R.drawable.indicator_arrow);
	mArrowImageView.setImageDrawable(arrowD);

	final int padding = getResources().getDimensionPixelSize(R.dimen.indicator_internal_padding);
	mArrowImageView.setPadding(padding, padding, padding, padding);
	addView(mArrowImageView);

	int inAnimResId, outAnimResId;
	switch (mode) {
		case PULL_FROM_END:
			inAnimResId = R.anim.slide_in_from_bottom;
			outAnimResId = R.anim.slide_out_to_bottom;
			setBackgroundResource(R.drawable.indicator_bg_bottom);

			// Rotate Arrow so it's pointing the correct way
			mArrowImageView.setScaleType(ScaleType.MATRIX);
			Matrix matrix = new Matrix();
			matrix.setRotate(180f, arrowD.getIntrinsicWidth() / 2f, arrowD.getIntrinsicHeight() / 2f);
			mArrowImageView.setImageMatrix(matrix);
			break;
		default:
		case PULL_FROM_START:
			inAnimResId = R.anim.slide_in_from_top;
			outAnimResId = R.anim.slide_out_to_top;
			setBackgroundResource(R.drawable.indicator_bg_top);
			break;
	}

	mInAnim = AnimationUtils.loadAnimation(context, inAnimResId);
	mInAnim.setAnimationListener(this);

	mOutAnim = AnimationUtils.loadAnimation(context, outAnimResId);
	mOutAnim.setAnimationListener(this);

	final Interpolator interpolator = new LinearInterpolator();
	mRotateAnimation = new RotateAnimation(0, -180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
			0.5f);
	mRotateAnimation.setInterpolator(interpolator);
	mRotateAnimation.setDuration(DEFAULT_ROTATION_ANIMATION_DURATION);
	mRotateAnimation.setFillAfter(true);

	mResetRotateAnimation = new RotateAnimation(-180, 0, Animation.RELATIVE_TO_SELF, 0.5f,
			Animation.RELATIVE_TO_SELF, 0.5f);
	mResetRotateAnimation.setInterpolator(interpolator);
	mResetRotateAnimation.setDuration(DEFAULT_ROTATION_ANIMATION_DURATION);
	mResetRotateAnimation.setFillAfter(true);

}