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

The following examples show how to use android.widget.ImageView#setId() . 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 check out the related API usage on the sidebar.
Example 1
Source File: ImageWindow.java    From ImageWindow with Apache License 2.0 6 votes vote down vote up
private void init() {

        ImageView closeButton = new ImageView(getContext());
        closeButton.setLayoutParams(new RelativeLayout.LayoutParams((int) (mCloseButtonSize), (int) (mCloseButtonSize)));
        StateListDrawable drawable = new StateListDrawable();
        ShapeDrawable shape = new ShapeDrawable(new OvalShape());
        ShapeDrawable shapePressed = new ShapeDrawable(new OvalShape());
        shape.setColorFilter(mCloseColor, PorterDuff.Mode.SRC_ATOP);
        shapePressed.setColorFilter(mCloseColor - 0x444444, PorterDuff.Mode.SRC_ATOP);//a little bit darker
        drawable.addState(new int[]{android.R.attr.state_pressed}, shapePressed);
        drawable.addState(new int[]{}, shape);
        closeButton.setImageResource(mCloseIcon);
        closeButton.setBackground(drawable); //todo change this to support lower api
        closeButton.setClickable(true);
        closeButton.setId(R.id.closeId);
        mImageView = new CustomImageView(getContext(), mCloseButtonSize, mCloseButtonMargin, mCornerRadius);
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        params.setMargins(Math.round(mTopLeftMargin), Math.round(mTopLeftMargin), 0, 0);
        mImageView.setLayoutParams(params);
        mImageView.setAdjustViewBounds(true);
        addView(mImageView);
        addView(closeButton);
    }
 
Example 2
Source File: MediaLayout.java    From commcare-android with Apache License 2.0 6 votes vote down vote up
private View setupQRView(String qrCodeContent) {
    Bitmap image;
    int minimumDim = getScreenMinimumDimension();

    try {
        QRCodeEncoder qrCodeEncoder =
                new QRCodeEncoder(qrCodeContent, minimumDim);

        image = qrCodeEncoder.encodeAsBitmap();

        ImageView imageView = new ImageView(getContext());
        imageView.setPadding(10, 10, 10, 10);
        imageView.setAdjustViewBounds(true);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setImageBitmap(image);
        imageView.setId(IMAGE_VIEW_ID);
        return imageView;
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 3
Source File: StickerCollectionActivity.java    From Mobike with Apache License 2.0 6 votes vote down vote up
private void initPhysicsLayout() {
    for (int i=0; i<10; i++) {
        ImageView imageView = new ImageView(StickerCollectionActivity.this);
        imageView.setImageResource(R.drawable.mobike_logo);
        LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(
                getResources().getDimensionPixelSize(R.dimen.square_size),
                getResources().getDimensionPixelSize(R.dimen.square_size));
        imageView.setLayoutParams(llp);
        imageView.setId(catIndex);
        catIndex++;
        mPhysicsLayout.addView(imageView);
        Glide.with(StickerCollectionActivity.this)
                .load(R.drawable.mobike_logo)
                .placeholder(R.drawable.mobike_logo)
                .into(imageView);
    }


}
 
Example 4
Source File: StoriesAdapter.java    From RxZhihuDaily with MIT License 6 votes vote down vote up
private void setCurPage(TopViewHolder holder, int pageCount, int page) {
    holder.topPagerIndicator.removeAllViews();

    for (int i = 0; i < pageCount; i++) {
        ImageView imgCur = new ImageView(context);
        imgCur.setPadding(8, 0, 8, 0);
        imgCur.setId(i);

        if (i == page) {
            imgCur.setImageResource(R.drawable.indicator_round__unselect_bg);
        } else {
            imgCur.setImageResource(R.drawable.indicator_round__select_bg);
        }

        holder.topPagerIndicator.addView(imgCur);
    }
}
 
Example 5
Source File: SelectableView.java    From belvedere with Apache License 2.0 5 votes vote down vote up
private ImageView getCheckBox(int colorPrimary) {
    final FrameLayout.LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    params.gravity = Gravity.CENTER;

    final ImageView imageView = new ImageView(getContext());
    imageView.setId(R.id.belvedere_selectable_view_checkbox);
    imageView.setImageDrawable(ContextCompat.getDrawable(getContext(), R.drawable.belvedere_ic_check_circle));
    ViewCompat.setBackground(imageView, ContextCompat.getDrawable(getContext(), R.drawable.belvedere_ic_check_bg));
    imageView.setLayoutParams(params);
    imageView.setVisibility(View.GONE);
    Utils.internalSetTint(imageView, colorPrimary);

    return imageView;
}
 
Example 6
Source File: AttachFragment.java    From actor-platform with GNU Affero General Public License v3.0 5 votes vote down vote up
private View instantiateShareMenuItem(ShareMenuField f) {
    LinearLayout shareItem = new LinearLayout(getActivity());
    shareItem.setOrientation(LinearLayout.VERTICAL);
    shareItem.setGravity(Gravity.CENTER_HORIZONTAL);

    TextView title = new TextView(getActivity());
    title.setGravity(Gravity.CENTER);
    title.setTextColor(ActorSDK.sharedActor().style.getTextSecondaryColor());
    title.setText(f.getTitle());
    title.setTextSize(14);

    ImageView icon = new ImageView(getActivity());
    icon.setClickable(true);
    if (f.getSelector() != 0) {
        icon.setBackgroundResource(f.getSelector());
    } else {
        icon.setBackgroundDrawable(ShareMenuButtonFactory.get(f.getColor(), getActivity()));
        icon.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        icon.setImageResource(f.getIcon());
    }

    shareItem.addView(icon, shareIconSize, shareIconSize);
    shareItem.addView(title);

    View.OnClickListener l = v -> {
        hide();
        onItemClicked(v.getId());
    };
    icon.setId(f.getId());
    icon.setOnClickListener(l);

    shareItem.setTag(R.id.title, title);
    shareItem.setTag(R.id.icon, icon);
    shareItem.setTag(R.id.list, l);

    return shareItem;
}
 
Example 7
Source File: ScrollGalleryView.java    From ScrollGalleryView with MIT License 5 votes vote down vote up
private ImageView createThumbnailView(LinearLayout.LayoutParams lp, Bitmap thumbnail) {
    ImageView thumbnailView = new ImageView(context);
    thumbnailView.setLayoutParams(lp);
    thumbnailView.setImageBitmap(thumbnail);
    thumbnailView.setId(mListOfMedia.size() - 1);
    thumbnailView.setOnClickListener(thumbnailOnClickListener);
    thumbnailView.setScaleType(ImageView.ScaleType.CENTER);
    return thumbnailView;
}
 
Example 8
Source File: PuzzleLayout.java    From X-Alarm with GNU Affero General Public License v3.0 5 votes vote down vote up
private void initItem() {
    // mColumn means also number of piece in one row
    mItemWidth = (mWidth - mPadding * 2 - mMargin * (mColumn - 1))
            / mColumn;
    mPuzzleItems = new ImageView[mColumn * mColumn];

    for (int i = 0; i < mPuzzleItems.length; i++)
    {
        ImageView item = new ImageView(getContext());
        item.setOnClickListener(this);
        item.setImageBitmap(mItemBitmaps.get(i).getBitmap());

        mPuzzleItems[i] = item;
        item.setId(i + 1);

        // Save index in tag
        item.setTag(i + "_" + mItemBitmaps.get(i).getIndex());

        LayoutParams lp = new LayoutParams(
                mItemWidth, mItemWidth);

        // If not last column
        if ((i + 1) % mColumn != 0) {
            lp.rightMargin = mMargin;
        }
        // If not first column
        if (i % mColumn != 0) {
            lp.addRule(RelativeLayout.RIGHT_OF, mPuzzleItems[i - 1].getId());
        }
        // If not first row, set topMargin and rule
        if ((i + 1) > mColumn) {
            lp.topMargin = mMargin;
            lp.addRule(RelativeLayout.BELOW, mPuzzleItems[i - mColumn].getId());
        }
        addView(item, lp);
    }
}
 
Example 9
Source File: TestFragment.java    From glide-support with The Unlicense 5 votes vote down vote up
@Override public @Nullable View onCreateView(LayoutInflater inflater, ViewGroup container,
		Bundle savedInstanceState) {
	imageView = new ImageView(container.getContext());
	imageView.setLayoutParams(new MarginLayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
	imageView.setScaleType(ScaleType.CENTER_CROP);
	imageView.setId(R.id.image);
	imageView.setOnClickListener(new OnClickListener() {
		@Override public void onClick(View v) {
			cycler.startNext();
		}
	});
	return imageView;
}
 
Example 10
Source File: GamePintuLayout.java    From AndroidAnimationExercise with Apache License 2.0 5 votes vote down vote up
/**
 * 初始化Item
 */
private void initItem() {
    // 获得Item的宽度
    int childWidth = (mWidth - mPadding * 2 - mMargin * (mColumn - 1))
            / mColumn;
    mItemWidth = childWidth;
    mGamePintuItems = new ImageView[mColumn * mColumn];
    // 放置Item
    for (int i = 0; i < mGamePintuItems.length; i++) {
        ImageView item = new ImageView(getContext());

        item.setOnClickListener(this);

        item.setImageBitmap(mItemBitmaps.get(i).bitmap);
        mGamePintuItems[i] = item;

        item.setId(i + 1);
        item.setTag(i + "_" + mItemBitmaps.get(i).index);

        LayoutParams lp = new LayoutParams(mItemWidth,
                mItemWidth);
        // 设置横向边距,不是最后一列
        if ((i + 1) % mColumn != 0) {
            lp.rightMargin = mMargin;
        }
        // 如果不是第一列
        if (i % mColumn != 0) {
            lp.addRule(RelativeLayout.RIGHT_OF,//
                    mGamePintuItems[i - 1].getId());
        }
        // 如果不是第一行,//设置纵向边距,非最后一行
        if ((i + 1) > mColumn) {
            lp.topMargin = mMargin;
            lp.addRule(RelativeLayout.BELOW,//
                    mGamePintuItems[i - mColumn].getId());
        }
        addView(item, lp);
    }

}
 
Example 11
Source File: FieldAnnotationParserTest.java    From easy-adapter with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("ResourceType") //Because of warning when setting a hardcoded ID into the view
private static LinearLayout createTestLinearLayout() {
    LinearLayout linearLayout = new LinearLayout(RuntimeEnvironment.application);
    TextView textView = new TextView(RuntimeEnvironment.application);
    textView.setId(TEXT_VIEW_ID);
    linearLayout.addView(textView);
    ImageView imageView = new ImageView(RuntimeEnvironment.application);
    imageView.setId(IMAGE_VIEW_ID);
    linearLayout.addView(imageView);
    return linearLayout;
}
 
Example 12
Source File: SocialAuthAdapter.java    From socialauth-android with MIT License 5 votes vote down vote up
/**
 * Enables a LinearLayout with SocialAuth functionality
 * 
 * @param linearbar
 *            The LinearLayout which is created as a bar
 */
public void enable(LinearLayout linearbar) {
	Log.d("SocialAuthAdapter", "Enabling bar with SocialAuth");
	final Context ctx = linearbar.getContext();

	// Handles Clicking Events for Buttons
	View.OnClickListener viewlistener = new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			// Getting selected provider and starting authentication
			if (authProviders[v.getId()].toString().startsWith("share_mail")
					|| authProviders[v.getId()].toString().startsWith("share_mms")) {
				Bundle bundle = new Bundle();
				bundle.putString(SocialAuthAdapter.PROVIDER, authProviders[v.getId()].toString());
				dialogListener.onComplete(bundle);
			} else {
				// Getting selected provider and starting authentication
				authorize(ctx, authProviders[v.getId()]);
			}
		}
	};

	// Adding Buttons to Bar
	for (int i = 0; i < providerCount; i++) {
		ImageView provider = new ImageView(ctx);
		provider.setId(i);
		provider.setImageResource(authProviderLogos[i]);
		provider.setPadding(5, 5, 5, 5);
		provider.setOnClickListener(viewlistener);
		linearbar.addView(provider);
	}

	// If network not available show message
	if (!Util.isNetworkAvailable(ctx)) {
		dialogListener.onError(new SocialAuthError("Please check your Internet connection", new Exception("")));
		return;
	}
}
 
Example 13
Source File: CategoryActivity.java    From financisto with GNU General Public License v2.0 5 votes vote down vote up
private void addAttribute(Attribute a) {
    View v = x.inflater.new Builder(attributesLayout, R.layout.select_entry_simple_minus).withId(R.id.edit_attribute, this).create();
    setAttributeData(v, a);
    ImageView plusImageView = v.findViewById(R.id.plus_minus);
    plusImageView.setId(R.id.remove_attribute);
    plusImageView.setOnClickListener(this);
    plusImageView.setTag(v.getTag());
    v.setTag(a);
    scrollView.fullScroll(ScrollView.FOCUS_DOWN);
}
 
Example 14
Source File: CategoryActivity.java    From financisto with GNU General Public License v2.0 5 votes vote down vote up
/**
 * todo.mb: consider refactoring to common logic with attributes and so on.
 */
private void addSmsTemplate(SmsTemplate t) {
    View v = x.inflater.new Builder(smsTemplatesLayout, R.layout.select_entry_simple_minus).withId(R.id.edit_sms_template, this).create();
    setSmsTemplateData(v, t);
    ImageView minusImageView = v.findViewById(R.id.plus_minus);
    minusImageView.setId(R.id.remove_sms_template);
    minusImageView.setOnClickListener(this);
    minusImageView.setTag(t.id);
    v.setTag(t);
    scrollView.fullScroll(ScrollView.FOCUS_DOWN);
}
 
Example 15
Source File: ViewMaker.java    From iGap-Android with GNU Affero General Public License v3.0 4 votes vote down vote up
static View getFileItem() {

        LinearLayout mainContainer = new LinearLayout(G.context);
        mainContainer.setId(R.id.mainContainer);
        mainContainer.setOrientation(HORIZONTAL);
        LinearLayout.LayoutParams layout_106 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        mainContainer.setLayoutParams(layout_106);

        LinearLayout linearLayout_768 = new LinearLayout(G.context);
        linearLayout_768.setOrientation(VERTICAL);
        LinearLayout.LayoutParams layout_577 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        linearLayout_768.setLayoutParams(layout_577);

        LinearLayout contentContainer = new LinearLayout(G.context);
        LinearLayout.LayoutParams layoutParamsContentContainer = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        contentContainer.setId(R.id.contentContainer);
        contentContainer.setLayoutParams(layoutParamsContentContainer);
        contentContainer.setPadding(i_Dp(R.dimen.dp4), i_Dp(R.dimen.dp4), i_Dp(R.dimen.dp4), i_Dp(R.dimen.dp4));
        contentContainer.setLayoutParams(layoutParamsContentContainer);

        LinearLayout m_container = new LinearLayout(G.context);
        m_container.setId(R.id.m_container);
        m_container.setOrientation(VERTICAL);
        LinearLayout.LayoutParams layout_346 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        m_container.setLayoutParams(layout_346);

        LinearLayout linearLayout_784 = new LinearLayout(G.context);
        linearLayout_784.setGravity(Gravity.CENTER_VERTICAL);
        setLayoutDirection(linearLayout_784, View.LAYOUT_DIRECTION_LTR);
        linearLayout_784.setOrientation(HORIZONTAL);
        linearLayout_784.setPadding(0, 0, (int) G.context.getResources().getDimension(R.dimen.messageContainerPadding), 0);
        LinearLayout.LayoutParams layout_419 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        layout_419.gravity = CENTER;
        linearLayout_784.setLayoutParams(layout_419);

        FrameLayout frameLayout = new FrameLayout(G.context);
        FrameLayout.LayoutParams layoutParamsFrameLayout = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT);
        layoutParamsFrameLayout.gravity = CENTER;
        frameLayout.setPadding(10, 10, 10, 10);
        frameLayout.setLayoutParams(layoutParamsFrameLayout);

        ImageView imgThumbnail = new ImageView(G.context);
        imgThumbnail.setId(R.id.thumbnail);
        LinearLayout.LayoutParams thumbnailParams = new LinearLayout.LayoutParams((int) G.context.getResources().getDimension(R.dimen.dp48), (int) G.context.getResources().getDimension(R.dimen.dp48));
        thumbnailParams.gravity = CENTER;
        imgThumbnail.setBackgroundColor(Color.TRANSPARENT);
        imgThumbnail.setScaleType(ImageView.ScaleType.FIT_CENTER);
        AppUtils.setImageDrawable(imgThumbnail, R.drawable.file_icon);
        imgThumbnail.setLayoutParams(thumbnailParams);

        LinearLayout linearLayout_780 = new LinearLayout(G.context);
        linearLayout_780.setOrientation(VERTICAL);
        LinearLayout.LayoutParams layout_752 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        layout_752.gravity = CENTER;
        linearLayout_780.setLayoutParams(layout_752);

        TextView songArtist = new TextView(G.context);
        songArtist.setId(R.id.songArtist);
        songArtist.setEllipsize(TextUtils.TruncateAt.MIDDLE);
        songArtist.setSingleLine(true);

        songArtist.setMaxWidth((int) G.context.getResources().getDimension(R.dimen.dp180));
        songArtist.setText("file_name.ext");
        songArtist.setTextColor(Color.parseColor(G.textBubble));
        setTextSize(songArtist, R.dimen.dp14);
        songArtist.setTypeface(G.typeface_IRANSansMobile_Bold, BOLD);
        LinearLayout.LayoutParams layout_1000 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        songArtist.setLayoutParams(layout_1000);
        linearLayout_780.addView(songArtist);

        TextView fileSize = new TextView(G.context);
        fileSize.setId(R.id.fileSize);
        fileSize.setSingleLine(true);
        fileSize.setText("3.2 mb");
        fileSize.setAllCaps(TRUE);
        fileSize.setTextColor(Color.parseColor(G.textBubble));
        setTextSize(fileSize, R.dimen.dp10);
        setTypeFace(fileSize);
        LinearLayout.LayoutParams layout_958 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        layout_958.topMargin = 3;
        fileSize.setLayoutParams(layout_958);
        linearLayout_780.addView(fileSize);
        linearLayout_784.addView(frameLayout);
        linearLayout_784.addView(linearLayout_780);
        m_container.addView(linearLayout_784);

        LinearLayout csliwt_layout_container_message = new LinearLayout(G.context);
        csliwt_layout_container_message.setId(R.id.csliwt_layout_container_message);
        csliwt_layout_container_message.setOrientation(HORIZONTAL);
        LinearLayout.LayoutParams layout_312 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        csliwt_layout_container_message.setLayoutParams(layout_312);
        m_container.addView(csliwt_layout_container_message);
        contentContainer.addView(m_container);
        linearLayout_768.addView(contentContainer);

        frameLayout.addView(imgThumbnail);
        frameLayout.addView(getProgressBar(R.dimen.dp52));
        mainContainer.addView(linearLayout_768);

        return mainContainer;
    }
 
Example 16
Source File: MediaLayout.java    From commcare-android with Apache License 2.0 4 votes vote down vote up
private View setupImage(String imageURI, String bigImageURI) {
    View mediaPane = null;
    try {
        int[] maxBounds = getMaxCenterViewBounds();
        final String imageFilename = ReferenceManager.instance().DeriveReference(imageURI).getLocalURI();
        final File imageFile = new File(imageFilename);
        if (imageFile.exists()) {
            Bitmap b = MediaUtil.inflateDisplayImage(getContext(), imageURI, maxBounds[0],
                    maxBounds[1]);
            if (b != null) {
                ImageView mImageView = new ImageView(getContext());
                if (useResizingImageView()) {
                    mImageView = new ResizingImageView(getContext(), imageURI, bigImageURI);
                    mImageView.setAdjustViewBounds(true);
                    mImageView.setMaxWidth(maxBounds[0]);
                    mImageView.setMaxHeight(maxBounds[1]);
                } else {
                    mImageView.setScaleType(ImageView.ScaleType.CENTER);
                }
                mImageView.setPadding(10, 10, 10, 10);
                if (imageFilename.toLowerCase().endsWith(IMAGE_GIF_EXTENSION)) {
                    Glide.with(mImageView).asGif()
                            .override(b.getWidth(), b.getHeight())
                            .load(imageFilename)
                            .into(mImageView);
                    b.recycle();
                } else {
                    mImageView.setImageBitmap(b);
                }
                mImageView.setId(IMAGE_VIEW_ID);
                mediaPane = mImageView;
            }
        } else {
            // An error hasn't been logged. We should have an image, but the file doesn't
            // exist.
            mediaPane = getMissingMediaView(imageURI,
                    StringUtils.getStringRobust(getContext(), R.string.video_download_prompt),
                    true);
        }
    } catch (InvalidReferenceException e) {
        Log.e(TAG, "image invalid reference exception");
        e.printStackTrace();
    }
    return mediaPane;
}
 
Example 17
Source File: ViewMaker.java    From iGap-Android with GNU Affero General Public License v3.0 4 votes vote down vote up
static View getContactItem() {
    LinearLayout lytMainContainer = new LinearLayout(context);
    LinearLayout.LayoutParams layoutParamsMainContainer = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lytMainContainer.setId(R.id.mainContainer);
    lytMainContainer.setOrientation(HORIZONTAL);
    lytMainContainer.setLayoutParams(layoutParamsMainContainer);

    LinearLayout lytContainer1 = new LinearLayout(context);
    LinearLayout.LayoutParams layoutParamsContainer1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lytContainer1.setOrientation(VERTICAL);
    lytContainer1.setLayoutParams(layoutParamsContainer1);

    LinearLayout contentContainer = new LinearLayout(context);
    contentContainer.setId(R.id.contentContainer);
    LinearLayout.LayoutParams layoutParamsContentContainer = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    contentContainer.setLayoutParams(layoutParamsContentContainer);
    contentContainer.setPadding(i_Dp(R.dimen.dp4), i_Dp(R.dimen.dp4), i_Dp(R.dimen.dp4), i_Dp(R.dimen.dp4));

    LinearLayout m_container = new LinearLayout(context);
    LinearLayout.LayoutParams layoutParamsM_container = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    m_container.setId(R.id.m_container);
    m_container.setOrientation(VERTICAL);
    m_container.setLayoutParams(layoutParamsM_container);

    LinearLayout container2 = new LinearLayout(context);
    LinearLayout.LayoutParams layoutParamsContainer2 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    layoutParamsContainer1.gravity = Gravity.CENTER_VERTICAL;
    container2.setOrientation(HORIZONTAL);
    container2.setPadding((int) G.context.getResources().getDimension(messageContainerPadding), 0, 5, 2);
    container2.setLayoutParams(layoutParamsContainer2);

    ImageView image = new ImageView(G.context);
    LinearLayout.LayoutParams layoutParamsImage = new LinearLayout.LayoutParams(i_Dp(R.dimen.dp48), i_Dp(R.dimen.dp48));
    layoutParamsImage.rightMargin = 14;
    image.setId(R.id.image);
    image.setContentDescription(null);
    AppUtils.setImageDrawable(image, R.mipmap.user);
    image.setLayoutParams(layoutParamsImage);

    LinearLayout container3 = new LinearLayout(context);
    LinearLayout.LayoutParams layoutParamsContainer3 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    container3.setOrientation(VERTICAL);
    container3.setLayoutParams(layoutParamsContainer3);

    TextView name = new TextView(G.context);
    LinearLayout.LayoutParams layoutParamsName = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    name.setId(R.id.name);
    name.setTextAppearance(context, android.R.style.TextAppearance_Medium);
    name.setTextColor(Color.parseColor(G.textBubble));
    name.setText("Contact Name");
    setTextSize(name, R.dimen.dp14);
    setTypeFace(name);
    name.setLayoutParams(layoutParamsName);
    container3.addView(name);

    TextView number = new TextView(G.context);
    LinearLayout.LayoutParams layoutParamsNumber = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    number.setId(R.id.number);
    number.setTextAppearance(context, android.R.style.TextAppearance_Small);
    setTypeFace(number);

    number.setTextColor(Color.parseColor(G.textBubble));
    number.setText("Contact Number");
    number.setLayoutParams(layoutParamsNumber);

    container3.addView(number);
    container2.addView(image);
    container2.addView(container3);
    m_container.addView(container2);
    contentContainer.addView(m_container);
    lytContainer1.addView(contentContainer);
    lytMainContainer.addView(lytContainer1);

    return lytMainContainer;
}
 
Example 18
Source File: ScrollImageController.java    From BigApp_Discuz_Android with Apache License 2.0 4 votes vote down vote up
/**
     * 初始化滚动图片布局
     * 如List<Object> objs,objs中可存储title、imageUrl、id、content等,这样可以将id,content等用于点击事件,传递数据到其他Activity
     *
     * @param list       数据
     * @param banner     滚动图片布局
     * @param ovalLayout 圆点布局
     */
    public void init(List<ScrollImageEntity> list, Banner banner,
                     final LinearLayout ovalLayout, int intervalTime, OnBannerItemClickListener onBannerItemClickListener) {
        this.banner = banner;
        this.ovalLayout = ovalLayout;
        this.onBannerItemClickListener = onBannerItemClickListener;
        this.intervalTime = intervalTime;

        WindowManager wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
        int width = wm.getDefaultDisplay().getWidth();
        int height = wm.getDefaultDisplay().getHeight();

        Log.e("APP", "width:" + width + "ovalLayout.getMeasuredWidth():" + ovalLayout.getMeasuredWidth() + " ovalLayout.getWidth():" + ovalLayout.getWidth());

//        ovalLayout.getViewTreeObserver().addOnGlobalLayoutListener(
//                new ViewTreeObserver.OnGlobalLayoutListener() {
//                    @Override
//                    public void onGlobalLayout() {
//                        int ovalLayoutWidth = ovalLayout.getHeight();
//
//                        Log.e("APP", "width:" + ovalLayoutWidth);
//
//                        ovalLayout.getViewTreeObserver()
//                                .removeGlobalOnLayoutListener(this);
//                    }
//                });


        listViewsImage = new ArrayList<View>(); // 图片组
        // 显示
        if (list != null && list.size() > 0) {
            for (int i = 0; i < list.size(); i++) {
                // 新建布局
                RelativeLayout relativeLayout = new RelativeLayout(activity);
                // 新建图片展示
                ImageView imageView = new ImageView(activity);
                // 新建图片标题
                TextView textView = new TextView(activity);
                imageView.setId(1);
                textView.setId(2);
                RelativeLayout.LayoutParams lp1 = new RelativeLayout.LayoutParams(
                        ViewGroup.LayoutParams.MATCH_PARENT,
                        ViewGroup.LayoutParams.MATCH_PARENT);
                lp1.addRule(RelativeLayout.ALIGN_PARENT_TOP);
                lp1.addRule(RelativeLayout.CENTER_HORIZONTAL,
                        RelativeLayout.TRUE);

                textView.setTextColor(android.graphics.Color.WHITE);
                textView.setSingleLine();
                textView.setTextSize(13);
                textView.setBackgroundColor(android.graphics.Color.BLACK);
                textView.getBackground().setAlpha(100);
                textView.setGravity(Gravity.CENTER_VERTICAL);
                RelativeLayout.LayoutParams lp2;
                PicassoUtils.display(activity, imageView, list.get(i).getImageUrl());

//                String icon = list.get(i).getImageUrl();
//                if (!TextUtils.isEmpty(icon)) {
//                        BitmapUtils.display(iconView, icon, R.drawable.ic_forum_default);
//                    }

                imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                relativeLayout.addView(imageView, lp1);

                textView.setText("   "
                        + list.get(i).getTitle()
                        .substring(0, list.get(i).getTitle().length() > 15
                                ? 15 : list.get(i).getTitle().length())
                        + "   ");

                if (list.get(i).getTitle().getBytes().length > 70) {
                    lp2 = new RelativeLayout.LayoutParams(
                            ViewGroup.LayoutParams.MATCH_PARENT,
                            Convert.dip2px(activity, 38));
                    lp2.addRule(RelativeLayout.BELOW, 1);
                    lp2.setMargins(0, Convert.dip2px(activity, -38), 0, 0);
                } else {
                    lp2 = new RelativeLayout.LayoutParams(
                            ViewGroup.LayoutParams.MATCH_PARENT,
                            Convert.dip2px(activity, 28));
                    lp2.addRule(RelativeLayout.BELOW, 1);
                    lp2.setMargins(0, Convert.dip2px(activity, -28), 0, 0);
                }
                relativeLayout.addView(textView, lp2);
                listViewsImage.add(relativeLayout);

                imageView.setOnClickListener(onBannerItemClickListener);
            }
        }
    }
 
Example 19
Source File: AdpArtworks.java    From freemp with Apache License 2.0 4 votes vote down vote up
@Override
public View getView(int position, View view, ViewGroup parent) {

    if (view == null) {
        final RelativeLayout rl = new RelativeLayout(activity);
        rl.setLayoutParams(layoutParams);

        final ImageView img = new ImageView(activity);
        RelativeLayout.LayoutParams imglp = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.MATCH_PARENT,RelativeLayout.LayoutParams.MATCH_PARENT);

        img.setPadding(10, 10, 0, 0);
        img.setId(imgid);
        //img.setLayoutParams(layoutParams);
        rl.addView(img,imglp);

        TextView tv = new TextView(activity);
        //tv.setSingleLine();
        tv.setPadding(16,0,40,0);
        RelativeLayout.LayoutParams lptv = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        lptv.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, img.getId());
        tv.setShadowLayer(1,-2,-2, Color.BLACK);
        tv.setId(tvid);

        rl.addView(tv,lptv);
        view = rl;
    }

    AQuery aq = listAq.recycle(view);


    final ClsTrack track = data.get(position);
    if (aq.shouldDelay(position, view, parent, "" + track.getAlbumId())) {
        aq.id(imgid).image(R.drawable.row_bgr);
    } else {
        aq.id(imgid).image(MediaUtils.getArtworkQuick(activity, track, 300, 300)).animate(fadeIn);
    }
    aq.id(tvid).getTextView().setText((""+track.getArtist()));
    return view;
}
 
Example 20
Source File: BootstrapAlert.java    From Android-Bootstrap with MIT License 4 votes vote down vote up
private void updateBootstrapState() {
    TextView alertText = new TextView(getContext());
    closeButton = new ImageView(getContext());

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1) {
        alertText.setId(generateViewUniqueId());
        closeButton.setId(generateViewUniqueId());
    }
    else {
        alertText.setId(View.generateViewId());
        closeButton.setId(View.generateViewId());
    }


    LayoutParams textParams = new LayoutParams(LayoutParams.MATCH_PARENT,
                                               LayoutParams.WRAP_CONTENT);
    LayoutParams closeParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
                                                LayoutParams.WRAP_CONTENT);
    textParams.addRule(RelativeLayout.LEFT_OF, closeButton.getId());
    closeParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);

    alertText.setLayoutParams(textParams);
    alertText.setTextSize(baselineFontSize);
    alertText.setGravity(Gravity.START);
    alertText.setTextColor(
            BootstrapDrawableFactory.bootstrapButtonText(getContext(), true, bootstrapBrand));
    alertText.setText(Html.fromHtml(String.format("<b>%s</b>%s", strongText,
                                                  (strongText.length() > 0 ?
                                                          "&nbsp;" + messageText :
                                                          messageText))));

    closeButton.setLayoutParams(closeParams);
    Drawable buttonBg = BootstrapDrawableFactory.bootstrapAlertCloseIcon(
            getContext(), (int) baselineFontSize, (int) baselineFontSize,
            DimenUtils.dpToPixels(6));

    ViewUtils.setBackgroundDrawable(closeButton, buttonBg);

    Drawable bg = BootstrapDrawableFactory.bootstrapAlert(getContext(), bootstrapBrand);
    ViewUtils.setBackgroundDrawable(this, bg);

    addView(alertText);

    if (userDismissible) {
        addView(closeButton);
        ((View) closeButton.getParent()).post(new Runnable() {
            @Override
            public void run() {
                Rect bounds = new Rect();
                closeButton.getHitRect(bounds);
                bounds.top -= DimenUtils.dpToPixels(6);
                bounds.bottom += DimenUtils.dpToPixels(6);
                bounds.left -= DimenUtils.dpToPixels(6);
                bounds.right += DimenUtils.dpToPixels(6);
                TouchDelegate touchDelegate = new TouchDelegate(bounds, closeButton);
                if (View.class.isInstance(closeButton.getParent())) {
                    ((View) closeButton.getParent()).setTouchDelegate(touchDelegate);
                }
            }
        });
        closeButton.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss(true);
            }
        });
    }

    int vert = (int) (baselinePadding * 1.5);
    int hori = (int) (baselinePadding * 1.5);
    setPadding(hori, vert, hori, vert);
}