GitHub上PhotoPicker的使用方法

github地址:https://github.com/donglua/PhotoPicker


PhotoPicker

CircleCI Build Status Android Arsenal Download API


示例

  

Get it on Google Play


用法

Gradle 需要导入的

dependencies {
    compile 'me.iwf.photopicker:PhotoPicker:0.9.7@aar'
    
    compile 'com.android.support:appcompat-v7:25.1.1'
    compile 'com.android.support:recyclerview-v7:25.1.1'
    compile 'com.android.support:design:25.1.1'
    compile 'com.nineoldandroids:library:2.4.0'
    compile 'com.github.bumptech.glide:glide:3.7.0'
}
  • appcompat-v7version >= 23.0.0

eclipse 应该是不能用

GO HOME

Pick Photo 构建PhotoPicker,这里需要设置各种参数

PhotoPicker.builder()
    .setPhotoCount(9)
    .setShowCamera(true)
    .setShowGif(true)
    .setPreviewEnabled(false)
    .start(this, PhotoPicker.REQUEST_CODE);

Preview Photo

ArrayList<String> photoPaths = ...;

PhotoPreview.builder()
    .setPhotos(selectedPhotos)
    .setCurrentItem(position)
    .setShowDeleteButton(false)
    .start(MainActivity.this);

onActivityResult

@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  super.onActivityResult(requestCode, resultCode, data);

  if (resultCode == RESULT_OK && requestCode == PhotoPicker.REQUEST_CODE) {
    if (data != null) {
      ArrayList<String> photos = 
          data.getStringArrayListExtra(PhotoPicker.KEY_SELECTED_PHOTOS);
    }
  }
}

除了以上代码,还需要demo中的RecyclerItemClickListener和PhotoAdapter

manifest

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    >
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.CAMERA" />
  <application
    ...
    >
    ...
    
    <activity android:name="me.iwf.photopicker.PhotoPickerActivity"
      android:theme="@style/Theme.AppCompat.NoActionBar" 
       />

    <activity android:name="me.iwf.photopicker.PhotoPagerActivity"
      android:theme="@style/Theme.AppCompat.NoActionBar"/>
    
  </application>
</manifest>

Custom style

<style name="actionBarTheme" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
  <item name="android:textColorPrimary">@android:color/primary_text_light</item>
  <item name="actionBarSize">@dimen/actionBarSize</item>
</style>

<style name="customTheme" parent="Theme.AppCompat.Light.NoActionBar">
  <item name="actionBarTheme">@style/actionBarTheme</item>
  <item name="colorPrimary">#FFA500</item>
  <item name="actionBarSize">@dimen/actionBarSize</item>
  <item name="colorPrimaryDark">#CCa500</item>
</style>

Proguard

# Glide
-keep public class * implements com.bumptech.glide.module.GlideModule
-keep public enum com.bumptech.glide.load.resource.bitmap.ImageHeaderParser$** {
    **[] $VALUES;
    public *;
}
# nineoldandroids
-keep interface com.nineoldandroids.view.** { *; }
-dontwarn com.nineoldandroids.**
-keep class com.nineoldandroids.** { *; }
# support-v7-appcompat
-keep public class android.support.v7.widget.** { *; }
-keep public class android.support.v7.internal.widget.** { *; }
-keep public class android.support.v7.internal.view.menu.** { *; }
-keep public class * extends android.support.v4.view.ActionProvider {
    public <init>(android.content.Context);
}
# support-design
-dontwarn android.support.design.**
-keep class android.support.design.** { *; }
-keep interface android.support.design.** { *; }
-keep public class android.support.design.R$* { *; }


github地址: https://github.com/LoveZYForever/HXWeiboPhotoPicker 一. 安装 手动导入:将项目中的“HXWeiboPhotoPicker”文件夹拖入项目中 只使用照片选择功能 导入头文件 "HXPhotoViewController.h" 选完照片/视频后自动布局功能 导入头文件 "HXPhotoView.h" 二. 例子 Demo1 // 懒加载 照片管理类 - (HXPhotoManager *)manager { if (!_manager) { _manager = [[HXPhotoManager alloc] initWithType:HXPhotoManagerSelectedTypePhotoAndVideo]; } return _manager; } // 照片选择控制器 HXPhotoViewController *vc = [[HXPhotoViewController alloc] init]; vc.delegate = self; vc.manager = self.manager; [self presentViewController:[[UINavigationController alloc] initWithRootViewController:vc] animated:YES completion:nil]; // 通过 HXPhotoViewControllerDelegate 代理返回选择的图片以及视频 - (void)photoViewControllerDidNext:(NSArray *)allList Photos:(NSArray *)photos Videos:(NSArray *)videos Original:(BOOL)original // 点击取消 - (void)photoViewControllerDidCancel Demo2 // 懒加载 照片管理类 - (HXPhotoManager *)manager { if (!_manager) { _manager = [[HXPhotoManager alloc] initWithType:HXPhotoManagerSelectedTypePhotoAndVideo]; } return _manager; } self.navigationController.navigationBar.translucent = NO; self.automaticallyAdjustsScrollViewInsets = YES; HXPhotoView *photoView = [[HXPhotoView alloc] initWithFrame:CGRectMake((414 - 375) / 2, 100, 375, 400) WithManager:self.manager]; photoView.delegate = self; photoView.backgroundColor = [UIColor whiteColor]; [self.view addSubview:photoView]; // 通过 HXPhotoViewDelegate 代理返回 选择、移动顺序、删除之后的图片以及视频 - (void)photoViewChangeComplete:(NSArray *)allList Photos:(NSArray *)photos Videos:(NSArray *)videos Original:(BOOL)isOriginal // 当 HXPhotoView 更新frame改变大小时 - (void)photoViewUpdateFrame:(CGRect)frame WithView:(UIView *)view 三. 更多 具体代码看请下载项目 发现的哪里有不好或不对的地方麻烦请联系我,大家一起讨论一起学习进步... QQ : 294005139
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值