Skip to content

Commit

Permalink
add
Browse files Browse the repository at this point in the history
  • Loading branch information
classichu committed Mar 22, 2017
1 parent ab60ff6 commit d8f6a3b
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,28 @@
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.Toast;

import com.classichu.photoselector.customselector.CustomPhotoSelectorActivity;
import com.classichu.photoselector.customselector.bean.ImagePickerDataWrapper;
import com.classichu.photoselector.customselector.ClassicPhotoSelectorActivity;
import com.classichu.photoselector.helper.ClassicSelectPhotoHelper;
import com.classichu.photoselector.imagespicker.ImagePickRecyclerView;

import java.util.List;
import com.classichu.photoselector.listener.OnNotFastClickListener;

public class MainActivity extends AppCompatActivity {
ImageView id_xsada;
ImagePickRecyclerView iprv;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);


id_xsada = (ImageView) findViewById(R.id.id_xsada);
iprv = (ImagePickRecyclerView) findViewById(R.id.id_xxad_xasa);
iprv.setOnAddClickListener(new ImagePickRecyclerView.OnAddClickListener() {
findViewById(R.id.dsadas).setOnClickListener(new OnNotFastClickListener() {
@Override
public void onAddClick(View view, int maxPickImageCount, int hasImageCount) {
//## ClassicSelectPhotoHelper.initBottomSheetDialog(MainActivity.this,false);

Intent intent= new Intent(MainActivity.this, CustomPhotoSelectorActivity.class);
Bundle bundle=new Bundle();
bundle.putBoolean("isToolbarTitleCenter",true);
intent.putExtras(bundle);
startActivityForResult(intent,44544);

protected void onNotFastClick(View v) {
startActivity(new Intent(MainActivity.this, ClassicPhotoSelectorActivity.class));
}


});



}

@Override
Expand All @@ -55,14 +38,14 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
public void onBackImagePath(String imagePath) {
super.onBackImagePath(imagePath);

Toast.makeText(MainActivity.this, "onBackImagePath imagePath:"+imagePath, Toast.LENGTH_SHORT).show();
Toast.makeText(MainActivity.this, "onBackImagePath imagePath:" + imagePath, Toast.LENGTH_SHORT).show();
}

@Override
public void onUCropBackImagePath(String imagePath) {
super.onUCropBackImagePath(imagePath);

Toast.makeText(MainActivity.this, "onUCropBackImagePath imagePath:"+imagePath, Toast.LENGTH_SHORT).show();
Toast.makeText(MainActivity.this, "onUCropBackImagePath imagePath:" + imagePath, Toast.LENGTH_SHORT).show();
}

@Override
Expand All @@ -72,29 +55,6 @@ public void onUCropBackError(Throwable cropError) {
}
});

//
if (requestCode==44544){
if (resultCode==RESULT_OK){
ImagePickerDataWrapper imagePickerDataWrapper= (ImagePickerDataWrapper) data.getSerializableExtra("imagePickerDataWrapper");
List<String> selectedList= imagePickerDataWrapper.getSelectedImageList();
StringBuilder sbWebId=new StringBuilder();
StringBuilder sbPath=new StringBuilder();
for (String s: selectedList) {
sbWebId.append(s);
sbWebId.append(",");

sbPath.append(s);
sbPath.append("|");
}
// Toast.makeText(this, "已选择:"+sb.toString(), Toast.LENGTH_SHORT).show();
String sbWebIdxx= sbWebId.toString().substring(0,sbWebId.toString().length()-1);

String sbPathxx= sbPath.toString().substring(0,sbPath.toString().length()-1);

iprv.setupDataListStr(sbWebIdxx,sbPathxx);

}
}

}

Expand Down
16 changes: 8 additions & 8 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
tools:context="com.classichu.classicphotoselector.MainActivity">


<com.classichu.photoselector.imagespicker.ImagePickRecyclerView
android:id="@+id/id_xxad_xasa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
<TextView
android:id="@+id/dsadas"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="select photo"
android:gravity="center"
android:layout_gravity="center"
/>


<ImageView
android:id="@+id/id_xsada"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />


</LinearLayout>
7 changes: 4 additions & 3 deletions library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,10 @@
android:name="com.yalantis.ucrop.UCropActivity"
android:screenOrientation="portrait"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
<activity android:name=".customselector.CustomPhotoSelectorActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
></activity>
<activity
android:name=".customselector.CustomPhotoSelectorActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
<activity android:name=".customselector.ClassicPhotoSelectorActivity"></activity>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package com.classichu.photoselector.customselector;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;

import com.classichu.photoselector.R;
import com.classichu.photoselector.customselector.bean.ImagePickerDataWrapper;
import com.classichu.photoselector.imagespicker.ImagePickBean;
import com.classichu.photoselector.imagespicker.ImagePickRecyclerView;

import java.util.ArrayList;
import java.util.List;

public class ClassicPhotoSelectorActivity extends AppCompatActivity {
private ImagePickRecyclerView iprv;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_classic_photo_selector);


iprv = (ImagePickRecyclerView) findViewById(R.id.id_iprv);
iprv.setOnAddClickListener(new ImagePickRecyclerView.OnAddClickListener() {
@Override
public void onAddClick(View view, int maxPickImageCount, int hasImageCount) {
//## ClassicSelectPhotoHelper.initBottomSheetDialog(MainActivity.this,false);

Intent intent = new Intent(ClassicPhotoSelectorActivity.this, CustomPhotoSelectorActivity.class);
Bundle bundle = new Bundle();
bundle.putBoolean("isToolbarTitleCenter", true);
bundle.putInt("maxSelectCount", maxPickImageCount-hasImageCount);
intent.putExtras(bundle);
startActivityForResult(intent, 44544);

}


});

}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
//
if (requestCode == 44544) {
if (resultCode == RESULT_OK) {
ImagePickerDataWrapper imagePickerDataWrapper = (ImagePickerDataWrapper) data.getSerializableExtra("imagePickerDataWrapper");
List<String> selectedList = imagePickerDataWrapper.getSelectedImageList();
List<ImagePickBean> imagePickBeanList=new ArrayList<>();
for (String s : selectedList) {
ImagePickBean imagePickBean=new ImagePickBean();
imagePickBean.setImagePathOrUrl(s);
imagePickBean.setImageWebIdStr(s);
imagePickBeanList.add(imagePickBean);
}
// Toast.makeText(this, "已选择:"+sb.toString(), Toast.LENGTH_SHORT).show();
iprv.addDataList(imagePickBeanList);

}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ public class CustomPhotoSelectorActivity extends AppCompatActivity {
private RecyclerView mRecyclerViewDir;
private ImagePickerDirListAdapter mImagePickerDirListAdapter;

private int mMaxSelectCount;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -89,6 +90,7 @@ protected void onCreate(Bundle savedInstanceState) {
}
if (bundle != null) {
mIsToolbarTitleCenter = bundle.getBoolean("isToolbarTitleCenter");
mMaxSelectCount = bundle.getInt("maxSelectCount");
}

initToolbar();
Expand All @@ -113,14 +115,14 @@ private void iniRecyclerView() {
*
*/

mImagePickerListAdapter = new ImagePickerListAdapter(mNowDirImageList);
mImagePickerListAdapter = new ImagePickerListAdapter(mNowDirImageList,mMaxSelectCount);
mImagePickerListAdapter.setOnItemClickListener(new ImagePickerListAdapter.OnItemClickListener() {
@Override
public void onItemSelected(int selectedCount) {
super.onItemSelected(selectedCount);

//更新标题栏
setToolbarTitle("已选" + selectedCount + "张");
setToolbarTitle(selectedCount + "/"+mMaxSelectCount);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.Toast;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
Expand All @@ -28,9 +29,10 @@ public List<String> getSelectedImageList() {

private List<String> mSelectedImageList = new ArrayList<>();
private List<ImagePickerBean> mImagePickerBeanList = new ArrayList<>();

public ImagePickerListAdapter(List<ImagePickerBean> dataList) {
private int mMaxCount;
public ImagePickerListAdapter(List<ImagePickerBean> dataList,int maxCount) {
mImagePickerBeanList = dataList;
mMaxCount=maxCount;
}


Expand Down Expand Up @@ -84,6 +86,12 @@ protected void onNotFastClick(View v) {
v.setSelected(false);
listViewHolder.itemView.setSelected(false);
} else {
//
if (mSelectedImageList.size()>=mMaxCount){
Toast.makeText(v.getContext(), "最多能选择"+mMaxCount+"张", Toast.LENGTH_SHORT).show();
return;
}
//
mSelectedImageList.add(path);
/**
* notifyDataSetChanged刷新会让图片闪烁 不采用adapter刷新
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
public class ImagePickRecyclerView extends RecyclerView {

private static final String TAG = "ImagePickRecyclerView";
List<ImagePickBean> mImagePickBeanList = new ArrayList<>();
ImagePickRecyclerViewAdapter imagePickRecyclerViewAdapter;
private List<ImagePickBean> mImagePickBeanList = new ArrayList<>();
private ImagePickRecyclerViewAdapter imagePickRecyclerViewAdapter;

int mIp_maxPickCountFromXml;
private int mIp_maxPickCountFromXml;

public static final int mOneColumnImageCount = 4;

Expand Down
16 changes: 16 additions & 0 deletions library/src/main/res/layout/activity_classic_photo_selector.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.classichu.photoselector.customselector.ClassicPhotoSelectorActivity">

<com.classichu.photoselector.imagespicker.ImagePickRecyclerView
android:id="@+id/id_iprv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>

</LinearLayout>

0 comments on commit d8f6a3b

Please sign in to comment.