コード例 #1
0
    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
      ImageView imageView;
      if (convertView == null) {
        imageView = new ImageView(PicContainerActivity.this);
        imageView.setLayoutParams(
            new GridView.LayoutParams(IMAGE_VIEW_WIDTH, IMAGE_VIEW_WIDTH)); //
        imageView.setAdjustViewBounds(false);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setPadding(8, 8, 8, 8);
      } else {
        imageView = (ImageView) convertView;
      }

      if (!readonly && position == imageFileUriList.size()) {
        imageView.setImageResource(R.drawable.add_camera);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                showPopupWindow(v);
              }
            });
      } else {
        final FileEntity image = (FileEntity) this.getItem(position);
        imageView.setBackgroundResource(0);
        if (image.getFileUri() != null) {
          imageView.setImageBitmap(
              FileHelper.decodeFile(image.getFileUri(), true, IMAGE_VIEW_WIDTH, IMAGE_VIEW_WIDTH));
        } else {
          ImageLoader.getInstance().displayImage(image.getAliasName(), imageView, true);
        }

        imageView.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                Intent intent = new Intent(PicContainerActivity.this, ImagePreviewActivity.class);
                intent.putExtra(ImagePreviewActivity.IMAGE_SRC_KEY, image);
                intent.putExtra(ImagePreviewActivity.IMAGE_INDEX_IN_CONTAINER, position);
                intent.putExtra(ImagePreviewActivity.IMAGE_DELETE_FLAG, !readonly);

                PicContainerActivity.this.startActivityForResult(
                    intent, PREVIEW_IMAGE_ACTIVITY_REQUEST_CODE);
              }
            });
      }
      return imageView;
    }
コード例 #2
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.image_preview);

    ActionBar actionBar = this.getActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);

    Intent intent = this.getIntent();
    imageFile = (FileEntity) intent.getExtras().getSerializable(IMAGE_SRC_KEY);
    imageIndex = intent.getExtras().getInt(IMAGE_INDEX_IN_CONTAINER);
    showDeleteMenuItem = intent.getExtras().getBoolean(IMAGE_DELETE_FLAG);
    // showByLocalFile = intent.getExtras().getBoolean(SHOW_BY_LOCAL_FILE);
    showByLocalFile = imageFile.getFileUri() != null;

    ImageView view = (ImageView) this.findViewById(R.id.image_preview_id);
    if (showByLocalFile) {
      view.setImageURI(Uri.parse(imageFile.getFileUri()));
    } else {
      ImageLoader.getInstance().displayImage(imageFile.getAliasName(), view, false);
    }
  }
コード例 #3
0
ファイル: ShareUtils.java プロジェクト: golden05/yougouhui
  private static void updateShareDetailView(
      final ShareEntity share, final Activity activity, View shareView) {
    if (share == null) {
      return;
    }

    UserEntity publisher = share.getPublisher();
    UserClickListener userClickListener = new UserClickListener(publisher, activity, -1);

    // 设置分享者的头像
    ImageView userImg = (ImageView) shareView.findViewById(R.id.user_img);
    userImg.setScaleType(ImageView.ScaleType.CENTER_CROP);
    userImg.setLayoutParams(
        new LinearLayout.LayoutParams(PUBLISHER_IMAGE_WIDTH, PUBLISHER_IMAGE_WIDTH));
    String userPhoto = publisher.getPhoto();
    if (userPhoto != null && userPhoto.length() > 0) {
      ImageLoader.getInstance().displayImage(userPhoto, userImg, true);
    } else {
      userImg.setImageResource(R.drawable.default_user_photo);
    }
    userImg.setOnClickListener(userClickListener);

    // 设置朋友的点击监听
    TextView userView = (TextView) shareView.findViewById(R.id.user_name);
    userView.getPaint().setFakeBoldText(true); // TODO:使用样式表来处理
    userView.setOnClickListener(userClickListener);
    userView.setText(publisher.getName());

    // 设置内容
    TextView contentView = (TextView) shareView.findViewById(R.id.share_content);
    contentView.setText(share.getContent());

    // 设置时间
    long publishTime = share.getPublishTime();
    TextView publishTimeView = (TextView) shareView.findViewById(R.id.share_publish_time);
    publishTimeView.setText(DateUtils.formatTime_MMdd(publishTime));

    // 设置上传的图片
    List<FileEntity> images = share.getImages();
    GridView picContainer = (GridView) shareView.findViewById(R.id.share_pic_container);
    // 设置GridView的列数
    DisplayMetrics displayMetrics = activity.getResources().getDisplayMetrics();
    int colNumber = displayMetrics.widthPixels / (ShareImageAdapter.IMAGE_VIEW_WIDTH + 25);
    picContainer.setNumColumns(colNumber);
    picContainer.setAdapter(new ShareImageAdapter(activity, images));

    // 设置商铺及距离信息
    final ShopEntity shop = share.getShop();
    if (shop != null) {
      TextView shareShopView = (TextView) shareView.findViewById(R.id.share_shop_name);
      shareShopView.getPaint().setFakeBoldText(true);
      shareShopView.setText(shop.getName());
      shareShopView.setOnClickListener(
          new View.OnClickListener() {

            @Override
            public void onClick(View v) {
              Intent intent = new Intent(activity, ShopBaseInfoActivity.class);
              intent.putExtra(ShopConst.COL_NAME_UUID, shop.getUuid());
              activity.startActivity(intent);
            }
          });

      LocationEntity shopLoc = shop.getLocation();
      LocationEntity userLoc = RunEnv.getInstance().getLocationEntity();
      if (shopLoc != null && userLoc != null) {
        TextView distView = (TextView) shareView.findViewById(R.id.share_shop_distance);
        distView.setText(
            new DecimalFormat("###,###.## 米").format(LocationUtils.distance(shopLoc, userLoc)));
      }
    } else {
      shareView.findViewById(R.id.row_share_shop).setVisibility(View.GONE);
    }
  }