Skip to content
This repository was archived by the owner on Feb 24, 2023. It is now read-only.

Commit cf6a9cc

Browse files
committed
Initial commit
0 parents  commit cf6a9cc

File tree

70 files changed

+2798
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

70 files changed

+2798
-0
lines changed

.gitignore

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
### Android ###
2+
# Built application files
3+
*.apk
4+
*.ap_
5+
6+
# Files for the Dalvik VM
7+
*.dex
8+
9+
# Java class files
10+
*.class
11+
12+
# Generated files
13+
bin/
14+
gen/
15+
16+
# Gradle files
17+
.gradle/
18+
build/
19+
20+
# Local configuration file (sdk path, etc)
21+
local.properties
22+
23+
# Proguard folder generated by Eclipse
24+
proguard/
25+
26+
27+
### Intellij ###
28+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm
29+
30+
## Directory-based project format
31+
.idea/
32+
# if you remove the above rule, at least ignore user-specific stuff:
33+
# .idea/workspace.xml
34+
# .idea/tasks.xml
35+
# and these sensitive or high-churn files:
36+
# .idea/dataSources.ids
37+
# .idea/dataSources.xml
38+
# .idea/sqlDataSources.xml
39+
# .idea/dynamic.xml
40+
41+
## File-based project format
42+
*.ipr
43+
*.iws
44+
*.iml
45+
46+
## Additional for IntelliJ
47+
out/
48+
49+
# generated by mpeltonen/sbt-idea plugin
50+
.idea_modules/
51+
52+
# generated by JIRA plugin
53+
atlassian-ide-plugin.xml

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 23
5+
buildToolsVersion "23.0.2"
6+
7+
defaultConfig {
8+
applicationId "com.litao.android.androidimagepicker"
9+
minSdkVersion 14
10+
targetSdkVersion 23
11+
versionCode 1
12+
versionName "1.0"
13+
vectorDrawables.useSupportLibrary = true
14+
}
15+
buildTypes {
16+
release {
17+
minifyEnabled false
18+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
19+
}
20+
}
21+
}
22+
23+
dependencies {
24+
compile fileTree(dir: 'libs', include: ['*.jar'])
25+
compile project(':lib')
26+
compile 'org.greenrobot:eventbus:3.0.0'
27+
}

app/proguard-rules.pro

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /Users/demohour/Desktop/litao/soft/adt-bundle-mac-x86_64-20140702/sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.litao.android.androidimagepicker;
2+
3+
import android.app.Application;
4+
import android.test.ApplicationTestCase;
5+
6+
/**
7+
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
8+
*/
9+
public class ApplicationTest extends ApplicationTestCase<Application> {
10+
public ApplicationTest() {
11+
super(Application.class);
12+
}
13+
}

app/src/main/AndroidManifest.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.litao.android.androidimagepicker" >
4+
5+
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
6+
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
7+
8+
<application
9+
android:allowBackup="true"
10+
android:icon="@mipmap/ic_launcher"
11+
android:label="@string/app_name"
12+
android:theme="@style/AppTheme" >
13+
<activity
14+
android:name=".MainActivity"
15+
android:label="@string/app_name" >
16+
<intent-filter>
17+
<action android:name="android.intent.action.MAIN" />
18+
19+
<category android:name="android.intent.category.LAUNCHER" />
20+
</intent-filter>
21+
</activity>
22+
<activity android:name=".PhotosActivity"/>
23+
</application>
24+
25+
</manifest>
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
package com.litao.android.androidimagepicker;
2+
3+
import android.content.Context;
4+
import android.content.Intent;
5+
import android.support.v7.widget.RecyclerView;
6+
import android.view.LayoutInflater;
7+
import android.view.View;
8+
import android.view.ViewGroup;
9+
import android.widget.ImageView;
10+
11+
import com.bumptech.glide.Glide;
12+
import com.litao.android.lib.entity.PhotoEntry;
13+
14+
import java.io.File;
15+
import java.util.ArrayList;
16+
import java.util.Arrays;
17+
import java.util.List;
18+
19+
/**
20+
* Created by 李涛 on 16/4/30.
21+
*/
22+
public class ChooseAdapter extends RecyclerView.Adapter<ChooseAdapter.ViewHolder> {
23+
24+
private List<PhotoEntry> list = new ArrayList<PhotoEntry>();
25+
26+
private Context mContext;
27+
28+
private LayoutInflater mInflater;
29+
30+
private OnItmeClickListener mlistener;
31+
32+
public interface OnItmeClickListener{
33+
void onItemClicked(int position);
34+
35+
}
36+
37+
public ChooseAdapter(Context mContext) {
38+
this.mContext = mContext;
39+
mlistener = (OnItmeClickListener) mContext;
40+
mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
41+
list.add(createAddEntry());
42+
}
43+
44+
public void reloadList(List<PhotoEntry> data) {
45+
if (data != null) {
46+
list.clear();
47+
list.addAll(data);
48+
list.add(createAddEntry());
49+
} else {
50+
list.clear();
51+
}
52+
notifyDataSetChanged();
53+
54+
}
55+
56+
public void appendList(List<PhotoEntry> data) {
57+
if (data != null) {
58+
list.addAll(list.size()-1,data);
59+
} else {
60+
list.clear();
61+
}
62+
notifyDataSetChanged();
63+
64+
}
65+
66+
67+
public void appendPhoto(PhotoEntry entry) {
68+
if (entry != null) {
69+
list.add(list.size()-1,entry);
70+
}
71+
notifyDataSetChanged();
72+
}
73+
74+
public List<PhotoEntry> getData(){
75+
return list.subList(0,list.size()-1);
76+
}
77+
public PhotoEntry getEntry(int position) {
78+
return list.get(position);
79+
}
80+
81+
private PhotoEntry createAddEntry(){
82+
return new PhotoEntry();
83+
}
84+
85+
@Override
86+
public int getItemViewType(int position) {
87+
return position;
88+
}
89+
90+
@Override
91+
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
92+
ViewHolder vh = new ViewHolder(mInflater.inflate(R.layout.item_selected_photo, viewGroup, false), i);
93+
return vh;
94+
}
95+
96+
97+
@Override
98+
public void onBindViewHolder(ViewHolder viewHolder, int i) {
99+
if (i==list.size()-1){
100+
viewHolder.mImageView.setImageResource(R.mipmap.add);
101+
}else {
102+
PhotoEntry entry = list.get(i);
103+
Glide.with(mContext)
104+
.load(new File(entry.getPath()))
105+
.centerCrop()
106+
.placeholder(com.litao.android.lib.R.mipmap.default_image)
107+
.into(viewHolder.mImageView);
108+
}
109+
}
110+
111+
@Override
112+
public int getItemCount() {
113+
return list.size();
114+
}
115+
116+
public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
117+
private ImageView mImageView;
118+
119+
private int position;
120+
121+
public ViewHolder(View itemView, int position) {
122+
super(itemView);
123+
this.position = position;
124+
mImageView = (ImageView) itemView.findViewById(R.id.image);
125+
mImageView.setOnClickListener(this);
126+
}
127+
128+
@Override
129+
public void onClick(View view) {
130+
mlistener.onItemClicked(position);
131+
}
132+
}
133+
134+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.litao.android.androidimagepicker;
2+
3+
import com.litao.android.lib.entity.PhotoEntry;
4+
5+
import java.util.List;
6+
7+
/**
8+
* Created by 李涛 on 16/4/30.
9+
*/
10+
public class EventEntry {
11+
12+
public static final int RECEIVED_PHOTOS_ID = 0x00000010;
13+
14+
public static final int SELECTED_PHOTOS_ID = 0x00000020;
15+
16+
17+
public List<PhotoEntry> photos;
18+
public int id;
19+
20+
public EventEntry(List<PhotoEntry> photos, int id){
21+
this.photos = photos;
22+
this.id = id;
23+
}
24+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package com.litao.android.androidimagepicker;
2+
3+
import android.content.Intent;
4+
import android.os.Bundle;
5+
import android.support.v7.app.AppCompatActivity;
6+
import android.support.v7.widget.GridLayoutManager;
7+
import android.support.v7.widget.RecyclerView;
8+
import android.view.Menu;
9+
10+
import com.litao.android.lib.Utils.GridSpacingItemDecoration;
11+
import com.litao.android.lib.entity.PhotoEntry;
12+
13+
import org.greenrobot.eventbus.EventBus;
14+
import org.greenrobot.eventbus.Subscribe;
15+
import org.greenrobot.eventbus.ThreadMode;
16+
17+
public class MainActivity extends AppCompatActivity implements ChooseAdapter.OnItmeClickListener {
18+
19+
private RecyclerView mRecyclerView;
20+
21+
private ChooseAdapter mAdapter;
22+
23+
@Override
24+
protected void onCreate(Bundle savedInstanceState) {
25+
super.onCreate(savedInstanceState);
26+
setContentView(R.layout.activity_main);
27+
28+
EventBus.getDefault().register(this);
29+
30+
mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
31+
mAdapter = new ChooseAdapter(this);
32+
mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3));
33+
mRecyclerView.setAdapter(mAdapter);
34+
mRecyclerView.addItemDecoration(new GridSpacingItemDecoration(3, 4, true));
35+
36+
}
37+
38+
@Override
39+
protected void onDestroy() {
40+
EventBus.getDefault().unregister(this);
41+
super.onDestroy();
42+
}
43+
44+
@Override
45+
public boolean onCreateOptionsMenu(Menu menu) {
46+
getMenuInflater().inflate(R.menu.menu_main, menu);
47+
return true;
48+
}
49+
50+
@Override
51+
public void onItemClicked(int position) {
52+
if (position == mAdapter.getItemCount()-1) {
53+
startActivity(new Intent(MainActivity.this, PhotosActivity.class));
54+
EventBus.getDefault().postSticky(new EventEntry(mAdapter.getData(),EventEntry.SELECTED_PHOTOS_ID));
55+
}
56+
}
57+
58+
@Subscribe(threadMode = ThreadMode.MAIN)
59+
public void photosMessageEvent(EventEntry entries){
60+
if (entries.id == EventEntry.RECEIVED_PHOTOS_ID) {
61+
mAdapter.reloadList(entries.photos);
62+
}
63+
}
64+
65+
@Subscribe(threadMode = ThreadMode.MAIN)
66+
public void photoMessageEvent(PhotoEntry entry){
67+
mAdapter.appendPhoto(entry);
68+
}
69+
70+
}

0 commit comments

Comments
 (0)