Search in sources :

Example 1 with Image

use of org.openstack4j.model.image.v2.Image in project Douya by DreaminginCodeZH.

the class BroadcastLayout method bindBroadcast.

public void bindBroadcast(final Broadcast broadcast) {
    final Context context = getContext();
    if (broadcast.isInterest) {
        mAvatarImage.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.recommendation_avatar_icon_grey600_40dp));
        mAvatarImage.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {
                UriHandler.open(DoubanUtils.getInterestTypeUrl(broadcast.interestType), context);
            }
        });
    } else {
        ImageUtils.loadAvatar(mAvatarImage, broadcast.author.avatar);
        mAvatarImage.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {
                context.startActivity(ProfileActivity.makeIntent(broadcast.author, context));
            }
        });
    }
    mNameText.setText(broadcast.getAuthorName());
    mTimeActionText.setDoubanTimeAndAction(broadcast.createdAt, broadcast.action);
    boolean isRebind = mBoundBroadcastId != null && mBoundBroadcastId == broadcast.id;
    // HACK: Attachment and text should not change on rebind.
    if (!isRebind) {
        Attachment attachment = broadcast.attachment;
        if (attachment != null) {
            mAttachmentLayout.setVisibility(VISIBLE);
            mAttachmentTitleText.setText(attachment.title);
            mAttachmentDescriptionText.setText(attachment.description);
            if (!TextUtils.isEmpty(attachment.image)) {
                mAttachmentImage.setVisibility(VISIBLE);
                ImageUtils.loadImage(mAttachmentImage, attachment.image);
            } else {
                mAttachmentImage.setVisibility(GONE);
            }
            final String attachmentUrl = attachment.href;
            if (!TextUtils.isEmpty(attachmentUrl)) {
                mAttachmentLayout.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        UriHandler.open(attachmentUrl, context);
                    }
                });
            } else {
                mAttachmentLayout.setOnClickListener(null);
            }
        } else {
            mAttachmentLayout.setVisibility(GONE);
        }
        final ArrayList<Image> images = broadcast.images.size() > 0 ? broadcast.images : Photo.toImageList(broadcast.photos);
        int numImages = images.size();
        if (numImages == 1) {
            final Image image = images.get(0);
            mSingleImageLayout.setVisibility(VISIBLE);
            mSingleImageLayout.loadImage(image);
            mSingleImageLayout.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View view) {
                    context.startActivity(GalleryActivity.makeIntent(image, context));
                }
            });
        } else {
            mSingleImageLayout.setVisibility(GONE);
        }
        if (numImages > 1) {
            mImageListLayout.setVisibility(VISIBLE);
            mImageListDescriptionText.setText(context.getString(R.string.broadcast_image_list_count_format, numImages));
            mImageListAdapter.replace(images);
            mImageListAdapter.setOnImageClickListener(new HorizontalImageAdapter.OnImageClickListener() {

                @Override
                public void onImageClick(int position) {
                    context.startActivity(GalleryActivity.makeImageListIntent(images, position, context));
                }
            });
        } else {
            mImageListLayout.setVisibility(GONE);
        }
        boolean textSpaceVisible = (attachment != null || numImages > 0) && !TextUtils.isEmpty(broadcast.text);
        ViewUtils.setVisibleOrGone(mTextSpace, textSpaceVisible);
        mTextText.setText(broadcast.getTextWithEntities(context));
    }
    mLikeButton.setText(broadcast.getLikeCountString());
    LikeBroadcastManager likeBroadcastManager = LikeBroadcastManager.getInstance();
    if (likeBroadcastManager.isWriting(broadcast.id)) {
        mLikeButton.setActivated(likeBroadcastManager.isWritingLike(broadcast.id));
        mLikeButton.setEnabled(false);
    } else {
        mLikeButton.setActivated(broadcast.isLiked);
        mLikeButton.setEnabled(true);
    }
    mLikeButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            if (mListener != null) {
                mListener.onLikeClicked();
            }
        }
    });
    RebroadcastBroadcastManager rebroadcastBroadcastManager = RebroadcastBroadcastManager.getInstance();
    if (rebroadcastBroadcastManager.isWriting(broadcast.id)) {
        mRebroadcastButton.setActivated(rebroadcastBroadcastManager.isWritingRebroadcast(broadcast.id));
        mRebroadcastButton.setEnabled(false);
    } else {
        mRebroadcastButton.setActivated(broadcast.isRebroadcasted());
        mRebroadcastButton.setEnabled(true);
    }
    mRebroadcastButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            if (mListener != null) {
                mListener.onRebroadcastClicked();
            }
        }
    });
    mCommentButton.setText(broadcast.getCommentCountString());
    mCommentButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            if (mListener != null) {
                mListener.onCommentClicked();
            }
        }
    });
    mBoundBroadcastId = broadcast.id;
}
Also used : Context(android.content.Context) HorizontalImageAdapter(me.zhanghai.android.douya.ui.HorizontalImageAdapter) Attachment(me.zhanghai.android.douya.network.api.info.apiv2.Attachment) Image(me.zhanghai.android.douya.network.api.info.apiv2.Image) ImageView(android.widget.ImageView) BindView(butterknife.BindView) TimeActionTextView(me.zhanghai.android.douya.ui.TimeActionTextView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) RebroadcastBroadcastManager(me.zhanghai.android.douya.broadcast.content.RebroadcastBroadcastManager) LikeBroadcastManager(me.zhanghai.android.douya.broadcast.content.LikeBroadcastManager)

Example 2 with Image

use of org.openstack4j.model.image.v2.Image in project Douya by DreaminginCodeZH.

the class ProfileBroadcastsLayout method bind.

public void bind(final User user, List<Broadcast> broadcastList) {
    final Context context = getContext();
    View.OnClickListener viewMoreListener = new OnClickListener() {

        @Override
        public void onClick(View view) {
            context.startActivity(BroadcastListActivity.makeIntent(user, context));
        }
    };
    mTitleText.setOnClickListener(viewMoreListener);
    mViewMoreText.setOnClickListener(viewMoreListener);
    int i = 0;
    for (final Broadcast broadcast : broadcastList) {
        if (i >= BROADCAST_COUNT_MAX) {
            break;
        }
        if (broadcast.rebroadcastedBroadcast != null) {
            continue;
        }
        if (i >= mBroadcastList.getChildCount()) {
            ViewUtils.inflateInto(R.layout.profile_broadcast_item, mBroadcastList);
        }
        View broadcastLayout = mBroadcastList.getChildAt(i);
        broadcastLayout.setVisibility(VISIBLE);
        BroadcastLayoutHolder holder = (BroadcastLayoutHolder) broadcastLayout.getTag();
        if (holder == null) {
            holder = new BroadcastLayoutHolder(broadcastLayout);
            broadcastLayout.setTag(holder);
            ViewUtils.setTextViewLinkClickable(holder.textText);
        }
        // HACK: Should not change on rebind.
        if (holder.boundBroadcastId != broadcast.id) {
            String imageUrl = null;
            if (broadcast.attachment != null) {
                imageUrl = broadcast.attachment.image;
            }
            if (TextUtils.isEmpty(imageUrl)) {
                List<Image> images = broadcast.images.size() > 0 ? broadcast.images : Photo.toImageList(broadcast.photos);
                if (images.size() > 0) {
                    imageUrl = images.get(0).medium;
                }
            }
            if (!TextUtils.isEmpty(imageUrl)) {
                holder.image.setVisibility(VISIBLE);
                ImageUtils.loadImage(holder.image, imageUrl);
            } else {
                holder.image.setVisibility(GONE);
            }
            CharSequence text = broadcast.getTextWithEntities(context);
            if (TextUtils.isEmpty(text) && broadcast.attachment != null) {
                text = broadcast.attachment.title;
            }
            holder.textText.setText(text);
            holder.timeActionText.setDoubanTimeAndAction(broadcast.createdAt, broadcast.action);
            broadcastLayout.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View view) {
                    context.startActivity(BroadcastActivity.makeIntent(broadcast, context));
                }
            });
            holder.boundBroadcastId = broadcast.id;
        }
        ++i;
    }
    ViewUtils.setVisibleOrGone(mBroadcastList, i != 0);
    ViewUtils.setVisibleOrGone(mEmptyView, i == 0);
    if (user.broadcastCount > i) {
        mViewMoreText.setText(context.getString(R.string.view_more_with_count_format, user.broadcastCount));
    } else {
        mViewMoreText.setVisibility(GONE);
    }
    for (int count = mBroadcastList.getChildCount(); i < count; ++i) {
        mBroadcastList.getChildAt(i).setVisibility(GONE);
    }
}
Also used : Context(android.content.Context) Broadcast(me.zhanghai.android.douya.network.api.info.apiv2.Broadcast) Image(me.zhanghai.android.douya.network.api.info.apiv2.Image) ImageView(android.widget.ImageView) BindView(butterknife.BindView) TimeActionTextView(me.zhanghai.android.douya.ui.TimeActionTextView) TextView(android.widget.TextView) View(android.view.View) FriendlyCardView(me.zhanghai.android.douya.ui.FriendlyCardView)

Example 3 with Image

use of org.openstack4j.model.image.v2.Image in project google-cloud-java by GoogleCloudPlatform.

the class AnnotateImage method main.

public static void main(String... args) throws Exception {
    // Instantiates a client
    ImageAnnotatorClient vision = ImageAnnotatorClient.create();
    // The path to the image file to annotate
    // for example "./resources/wakeupcat.jpg";
    String fileName = "your/image/path.jpg";
    // Reads the image file into memory
    Path path = Paths.get(fileName);
    byte[] data = Files.readAllBytes(path);
    ByteString imgBytes = ByteString.copyFrom(data);
    // Builds the image annotation request
    List<AnnotateImageRequest> requests = new ArrayList<>();
    Image img = Image.newBuilder().setContent(imgBytes).build();
    Feature feat = Feature.newBuilder().setType(Type.LABEL_DETECTION).build();
    AnnotateImageRequest request = AnnotateImageRequest.newBuilder().addFeatures(feat).setImage(img).build();
    requests.add(request);
    // Performs label detection on the image file
    BatchAnnotateImagesResponse response = vision.batchAnnotateImages(requests);
    List<AnnotateImageResponse> responses = response.getResponsesList();
    for (AnnotateImageResponse res : responses) {
        if (res.hasError()) {
            System.out.printf("Error: %s\n", res.getError().getMessage());
            return;
        }
        for (EntityAnnotation annotation : res.getLabelAnnotationsList()) {
            for (Map.Entry<FieldDescriptor, Object> entry : annotation.getAllFields().entrySet()) {
                System.out.printf("%s : %s\n", entry.getKey(), entry.getValue());
            }
        }
    }
}
Also used : Path(java.nio.file.Path) ByteString(com.google.protobuf.ByteString) ImageAnnotatorClient(com.google.cloud.vision.spi.v1.ImageAnnotatorClient) ArrayList(java.util.ArrayList) ByteString(com.google.protobuf.ByteString) Image(com.google.cloud.vision.v1.Image) Feature(com.google.cloud.vision.v1.Feature) FieldDescriptor(com.google.protobuf.Descriptors.FieldDescriptor) AnnotateImageRequest(com.google.cloud.vision.v1.AnnotateImageRequest) AnnotateImageResponse(com.google.cloud.vision.v1.AnnotateImageResponse) EntityAnnotation(com.google.cloud.vision.v1.EntityAnnotation) Map(java.util.Map) BatchAnnotateImagesResponse(com.google.cloud.vision.v1.BatchAnnotateImagesResponse)

Example 4 with Image

use of org.openstack4j.model.image.v2.Image in project openstack4j by ContainX.

the class ImageV2Tests method testGetImage.

public void testGetImage() throws IOException {
    respondWith(IMAGE_JSON);
    String id = "8a2ea42d-06b5-42c2-a54d-97105420f2bb";
    Image image = osv3().imagesV2().get(id);
    assertNotNull(image);
    assertNotNull(image.getId());
    assertEquals(image.getId(), id);
}
Also used : Image(org.openstack4j.model.image.v2.Image)

Example 5 with Image

use of org.openstack4j.model.image.v2.Image in project openstack4j by ContainX.

the class ImageV2Tests method testCreateImage.

public void testCreateImage() throws IOException {
    respondWith(IMAGE_JSON);
    String id = "8a2ea42d-06b5-42c2-a54d-97105420f2bb";
    String name = "amphora-x64-haproxy";
    ContainerFormat cf = ContainerFormat.BARE;
    DiskFormat df = DiskFormat.QCOW2;
    Long mindisk = 0L;
    Long minram = 0L;
    Image.ImageVisibility vis = Image.ImageVisibility.PUBLIC;
    String key1 = "test-key1";
    String key2 = "test-key2";
    String key3 = "id";
    String value1 = "test-value1";
    String value2 = "test-value2";
    String value3 = "test-value3";
    Image im = Builders.imageV2().id(id).name(name).containerFormat(cf).diskFormat(df).minDisk(mindisk).minRam(minram).visibility(vis).additionalProperty(key1, value1).additionalProperty(key2, value2).additionalProperty(key3, value3).build();
    Image image = osv3().imagesV2().create(im);
    assertNotNull(image);
    assertEquals(image.getId(), id);
    assertEquals(image.getName(), name);
    assertEquals(image.getContainerFormat(), cf);
    assertEquals(image.getDiskFormat(), df);
    assertEquals(image.getVisibility(), vis);
    assertEquals(image.getMinDisk(), mindisk);
    assertEquals(image.getMinRam(), minram);
    assertEquals(image.getAdditionalPropertyValue(key1), value1);
    assertEquals(image.getAdditionalPropertyValue(key2), value2);
    assertNull(image.getAdditionalPropertyValue(key3));
}
Also used : ContainerFormat(org.openstack4j.model.image.v2.ContainerFormat) Image(org.openstack4j.model.image.v2.Image) DiskFormat(org.openstack4j.model.image.v2.DiskFormat)

Aggregations

Image (org.openstack4j.model.image.v2.Image)3 Context (android.content.Context)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 BindView (butterknife.BindView)2 Image (me.zhanghai.android.douya.network.api.info.apiv2.Image)2 TimeActionTextView (me.zhanghai.android.douya.ui.TimeActionTextView)2 RecyclerView (android.support.v7.widget.RecyclerView)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 ImageAnnotatorClient (com.google.cloud.vision.spi.v1.ImageAnnotatorClient)1 AnnotateImageRequest (com.google.cloud.vision.v1.AnnotateImageRequest)1 AnnotateImageResponse (com.google.cloud.vision.v1.AnnotateImageResponse)1 BatchAnnotateImagesResponse (com.google.cloud.vision.v1.BatchAnnotateImagesResponse)1 EntityAnnotation (com.google.cloud.vision.v1.EntityAnnotation)1 Feature (com.google.cloud.vision.v1.Feature)1 Image (com.google.cloud.vision.v1.Image)1 ByteString (com.google.protobuf.ByteString)1