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

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
litao0621 committed May 4, 2016
0 parents commit cf6a9cc
Show file tree
Hide file tree
Showing 70 changed files with 2,798 additions and 0 deletions.
53 changes: 53 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
### Android ###
# Built application files
*.apk
*.ap_

# Files for the Dalvik VM
*.dex

# Java class files
*.class

# Generated files
bin/
gen/

# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Proguard folder generated by Eclipse
proguard/


### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm

## Directory-based project format
.idea/
# if you remove the above rule, at least ignore user-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# and these sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.xml
# .idea/sqlDataSources.xml
# .idea/dynamic.xml

## File-based project format
*.ipr
*.iws
*.iml

## Additional for IntelliJ
out/

# generated by mpeltonen/sbt-idea plugin
.idea_modules/

# generated by JIRA plugin
atlassian-ide-plugin.xml
1 change: 1 addition & 0 deletions app/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
27 changes: 27 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"

defaultConfig {
applicationId "com.litao.android.androidimagepicker"
minSdkVersion 14
targetSdkVersion 23
versionCode 1
versionName "1.0"
vectorDrawables.useSupportLibrary = true
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile project(':lib')
compile 'org.greenrobot:eventbus:3.0.0'
}
17 changes: 17 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /Users/demohour/Desktop/litao/soft/adt-bundle-mac-x86_64-20140702/sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.litao.android.androidimagepicker;

import android.app.Application;
import android.test.ApplicationTestCase;

/**
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
*/
public class ApplicationTest extends ApplicationTestCase<Application> {
public ApplicationTest() {
super(Application.class);
}
}
25 changes: 25 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.litao.android.androidimagepicker" >

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".PhotosActivity"/>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
package com.litao.android.androidimagepicker;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.litao.android.lib.entity.PhotoEntry;

import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
* Created by 李涛 on 16/4/30.
*/
public class ChooseAdapter extends RecyclerView.Adapter<ChooseAdapter.ViewHolder> {

private List<PhotoEntry> list = new ArrayList<PhotoEntry>();

private Context mContext;

private LayoutInflater mInflater;

private OnItmeClickListener mlistener;

public interface OnItmeClickListener{
void onItemClicked(int position);

}

public ChooseAdapter(Context mContext) {
this.mContext = mContext;
mlistener = (OnItmeClickListener) mContext;
mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
list.add(createAddEntry());
}

public void reloadList(List<PhotoEntry> data) {
if (data != null) {
list.clear();
list.addAll(data);
list.add(createAddEntry());
} else {
list.clear();
}
notifyDataSetChanged();

}

public void appendList(List<PhotoEntry> data) {
if (data != null) {
list.addAll(list.size()-1,data);
} else {
list.clear();
}
notifyDataSetChanged();

}


public void appendPhoto(PhotoEntry entry) {
if (entry != null) {
list.add(list.size()-1,entry);
}
notifyDataSetChanged();
}

public List<PhotoEntry> getData(){
return list.subList(0,list.size()-1);
}
public PhotoEntry getEntry(int position) {
return list.get(position);
}

private PhotoEntry createAddEntry(){
return new PhotoEntry();
}

@Override
public int getItemViewType(int position) {
return position;
}

@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
ViewHolder vh = new ViewHolder(mInflater.inflate(R.layout.item_selected_photo, viewGroup, false), i);
return vh;
}


@Override
public void onBindViewHolder(ViewHolder viewHolder, int i) {
if (i==list.size()-1){
viewHolder.mImageView.setImageResource(R.mipmap.add);
}else {
PhotoEntry entry = list.get(i);
Glide.with(mContext)
.load(new File(entry.getPath()))
.centerCrop()
.placeholder(com.litao.android.lib.R.mipmap.default_image)
.into(viewHolder.mImageView);
}
}

@Override
public int getItemCount() {
return list.size();
}

public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
private ImageView mImageView;

private int position;

public ViewHolder(View itemView, int position) {
super(itemView);
this.position = position;
mImageView = (ImageView) itemView.findViewById(R.id.image);
mImageView.setOnClickListener(this);
}

@Override
public void onClick(View view) {
mlistener.onItemClicked(position);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.litao.android.androidimagepicker;

import com.litao.android.lib.entity.PhotoEntry;

import java.util.List;

/**
* Created by 李涛 on 16/4/30.
*/
public class EventEntry {

public static final int RECEIVED_PHOTOS_ID = 0x00000010;

public static final int SELECTED_PHOTOS_ID = 0x00000020;


public List<PhotoEntry> photos;
public int id;

public EventEntry(List<PhotoEntry> photos, int id){
this.photos = photos;
this.id = id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.litao.android.androidimagepicker;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.Menu;

import com.litao.android.lib.Utils.GridSpacingItemDecoration;
import com.litao.android.lib.entity.PhotoEntry;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class MainActivity extends AppCompatActivity implements ChooseAdapter.OnItmeClickListener {

private RecyclerView mRecyclerView;

private ChooseAdapter mAdapter;

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

EventBus.getDefault().register(this);

mRecyclerView = (RecyclerView) findViewById(R.id.recycler_view);
mAdapter = new ChooseAdapter(this);
mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3));
mRecyclerView.setAdapter(mAdapter);
mRecyclerView.addItemDecoration(new GridSpacingItemDecoration(3, 4, true));

}

@Override
protected void onDestroy() {
EventBus.getDefault().unregister(this);
super.onDestroy();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public void onItemClicked(int position) {
if (position == mAdapter.getItemCount()-1) {
startActivity(new Intent(MainActivity.this, PhotosActivity.class));
EventBus.getDefault().postSticky(new EventEntry(mAdapter.getData(),EventEntry.SELECTED_PHOTOS_ID));
}
}

@Subscribe(threadMode = ThreadMode.MAIN)
public void photosMessageEvent(EventEntry entries){
if (entries.id == EventEntry.RECEIVED_PHOTOS_ID) {
mAdapter.reloadList(entries.photos);
}
}

@Subscribe(threadMode = ThreadMode.MAIN)
public void photoMessageEvent(PhotoEntry entry){
mAdapter.appendPhoto(entry);
}

}
Loading

0 comments on commit cf6a9cc

Please sign in to comment.