Commit c2233032 authored by Donald's avatar Donald

asd

parents
.gradle
# User-specific configurations
.idea/
*.iml
/local.properties
.DS_Store
/build
/captures
# LeafPic
Material Gallery App
LOL
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
}
}
apply plugin: 'com.android.application'
repositories {
jcenter()
}
android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.leafpic.app"
minSdkVersion 23
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_6
targetCompatibility JavaVersion.VERSION_1_6
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:+'
compile 'com.nostra13.universalimageloader:universal-image-loader:+'
compile 'com.readystatesoftware.systembartint:systembartint:1.0.3'
//add for using CardView
compile 'com.android.support:cardview-v7:+'
//add for using recicle view
compile 'com.android.support:recyclerview-v7:+'
}
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /home/dnld/Android/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 *;
#}
package com.leafpic.app;
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);
}
}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.leafpic.app" >
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity android:name=".AlbumsActivity"
android:label="@string/app_name"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
>
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".PhotosActivity"
android:label="Album"
android:parentActivityName=".AlbumsActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".AlbumsActivity"/>
<intent-filter>
<action android:name="android.intent.action.albumPhotos"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
<activity android:name=".PhotoActivity"
android:label="Album"
android:parentActivityName=".PhotosActivity"
android:theme="@style/Theme.AppCompat.Light.NoActionBar"
>
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".PhotosActivity"/>
<intent-filter>
<action android:name="android.intent.action.albumPhoto"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
</application>
</manifest>
package com.leafpic.app.Adapters;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import com.leafpic.app.Album;
import com.leafpic.app.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import java.util.ArrayList;
/**
* Created by dnld on 12/12/15.
*/
public class AlbumAdapter extends ArrayAdapter<Album> {
ArrayList<Album> albums;
Bitmap photoPlaceHolder = BitmapFactory.decodeResource(Resources.getSystem(), R.drawable.ic_launcher);
private Context localContext;
private int layout_ID;
public AlbumAdapter (Context ct,int Layout_ID, ArrayList<Album> a){
super(ct, Layout_ID, a);
this.localContext = ct;
this.layout_ID = Layout_ID;
albums = a;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
RelativeLayout card_layout;
View v;
ImageView picture;
TextView name;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) localContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(this.layout_ID, parent, false);
v.setTag(R.id.picture, v.findViewById(R.id.picture));
v.setTag(R.id.picturetext, v.findViewById(R.id.picturetext));
v.setTag(R.id.layout_card_id, v.findViewById(R.id.layout_card_id));
} else
v = convertView;
card_layout = (RelativeLayout) v.getTag(R.id.layout_card_id);
picture = (ImageView) v.getTag(R.id.picture);
name = (TextView) v.getTag(R.id.picturetext);
Album a = albums.get(position);
//non so se serve
picture.setTag(a.getPathCoverAlbum());
//impostazioni libreria immagini
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.ic_empty)
.imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2)
.cacheInMemory(true)
.cacheOnDisk(true)
.build();
//Setta immagine
ImageLoader.getInstance().displayImage(a.getPathCoverAlbum(), picture, defaultOptions);
//setta titolo
name.setText(a.DisplayName);
//setta numero immaghini
//a.getImagesCount();
if (a.isSelected()) {
//name.setBackgroundColor(localContext.getColor(R.color.selected_album));
card_layout.setBackgroundColor(localContext.getColor(R.color.selected_album));
} else {
//name.setBackgroundColor(localContext.getColor(R.color.unselected_album));
card_layout.setBackgroundColor(localContext.getColor(R.color.unselected_album));
}
return v;
}
}
\ No newline at end of file
package com.leafpic.app.Adapters;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import com.leafpic.app.Photo;
import com.leafpic.app.R;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
import java.util.ArrayList;
/**
* Created by dnld on 12/12/15.
*/
public class PhotosAdapter extends ArrayAdapter<Photo> {
ArrayList<Photo> photos;
private Context localContext;
private int layout_ID;
//Bitmap photoPlaceholder = BitmapFactory.decodeResource(Resources.getSystem(), R.drawable.ic_launcher);
public PhotosAdapter (Context ct,int Layout_ID, ArrayList<Photo> a){
super(ct, Layout_ID, a);
this.localContext = ct;
this.layout_ID = Layout_ID;
photos = a;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v;
ImageView picture;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) localContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
v = inflater.inflate(this.layout_ID, parent, false);
v.setTag(R.id.pic, v.findViewById(R.id.pic));
} else
v = convertView;
picture = (ImageView) v.getTag(R.id.pic);
picture.setTag(photos.get(position).Path);
DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.ic_empty)
.imageScaleType(ImageScaleType.IN_SAMPLE_POWER_OF_2)
.cacheInMemory(true)
.cacheOnDisk(true)
.build();
ImageLoader.getInstance().displayImage("file://"+photos.get(position).Path, picture, defaultOptions);
return v;
}
}
\ No newline at end of file
package com.leafpic.app;
import android.os.Parcel;
import android.os.Parcelable;
import com.leafpic.app.utils.string;
import java.util.ArrayList;
/**
* Created by dnld on 12/11/15.
*/
public class Album implements Parcelable {
@SuppressWarnings("unused")
public static final Parcelable.Creator<Album> CREATOR = new Parcelable.Creator<Album>() {
@Override
public Album createFromParcel(Parcel in) {
return new Album(in);
}
@Override
public Album[] newArray(int size) {
return new Album[size];
}
};
public String Path = "";
public String DisplayName;
ArrayList<Photo> photos;
private boolean hidden = false;
private boolean selected = false;
public Album() {
photos = new ArrayList<Photo>();
}
public Album(String path){
photos = new ArrayList<Photo>();
DisplayName = string.getBucketNamebyBucketPath(path);
Path = path;
}
public Album(String path, String displayName) {
photos = new ArrayList<Photo>();
DisplayName = displayName;
Path = path;
}
public Album(String path, String displayName, boolean hidden) {
photos = new ArrayList<Photo>();
DisplayName = displayName;
Path = path;
setHidden(hidden);
}
protected Album(Parcel in) {
Path = in.readString();
DisplayName = in.readString();
if (in.readByte() == 0x01) {
photos = new ArrayList<Photo>();
in.readList(photos, Photo.class.getClassLoader());
} else {
photos = null;
}
hidden = in.readByte() != 0x00;
selected = in.readByte() != 0x00;
}
public void setPath() {
try {
Path = string.getBucketPathbyImagePath(photos.get(0).Path);
} catch (NullPointerException e) {
e.printStackTrace();
}
}
public boolean isHidden() {
return hidden;
}
public void setHidden(boolean value) {
hidden = value;
}
public boolean isSelected() {
return selected;
}
public void setSelcted(boolean value) {
selected = value;
}
public String getPathCoverAlbum() {
if (photos.size() > 0)
return "file://" + photos.get(0).Path;
else
return "drawable://" + R.drawable.ic_empty;
}
public int getImagesCount() {
return photos.size();
}
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeString(Path);
dest.writeString(DisplayName);
if (photos == null) {
dest.writeByte((byte) (0x00));
} else {
dest.writeByte((byte) (0x01));
dest.writeList(photos);
}
dest.writeByte((byte) (hidden ? 0x01 : 0x00));
dest.writeByte((byte) (selected ? 0x01 : 0x00));
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
package com.leafpic.app;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import java.io.File;
import java.io.FileOutputStream;
import java.util.ArrayList;
public class HandlingAlbums {
public ArrayList<Album> dispAlbums;
private Context context;
private ArrayList<Album> selectedAlbums;
public HandlingAlbums(Context ctx) {
context = ctx;
dispAlbums = new ArrayList<Album>();
selectedAlbums = new ArrayList<Album>();
}
public int getSelectedCount() {
return selectedAlbums.size();
}
public void loadHiddenAlbums() {
DatabaseHandler db = new DatabaseHandler(context);
if (db.getDataBaseHiddenPhotosCount() == 0)
db.loadHiddenALbums();
dispAlbums = db.getHiddenAlbums();
for (Album dispAlbum : dispAlbums) {
dispAlbum.setHidden(true);
dispAlbum.photos = db.getPhotosByAlbum(dispAlbum.Path);
}
db.close();
}
public void loadAlbums() {
DatabaseHandler db = new DatabaseHandler(context);
dispAlbums = db.getAllAlbums();
for (Album dispAlbum : dispAlbums)
dispAlbum.photos = db.getPhotosByAlbum(dispAlbum.Path);
db.close();
}
public void selectAlbum(Album a, boolean val) {
Album x = dispAlbums.get(dispAlbums.indexOf(a));
x.setPath();
x.setSelcted(val);
if (val) selectedAlbums.add(x);
else selectedAlbums.remove(x);
}
public void hideSelectedAlbums() {
for (Album selectedAlbum : selectedAlbums)
hideAlbum(selectedAlbum);
clearSelectedAlbums();
}
public void hideAlbum(Album a) {
DatabaseHandler db = new DatabaseHandler(context);
File dirName = new File(a.Path);
File file = new File(dirName, ".nomedia");
if (!file.exists()) {
try {
FileOutputStream out = new FileOutputStream(file);
out.flush();
out.close();
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
} catch (Exception e) {
e.printStackTrace();
}
}
db.hideAlbum(a.Path);
db.close();
dispAlbums.remove(a);
}
public void unHideSelectedAlbums() {
for (Album selectedAlbum : selectedAlbums)
unHideAlbum(selectedAlbum);
clearSelectedAlbums();
}
public void unHideAlbum(Album a) {
DatabaseHandler db = new DatabaseHandler(context);
File dirName = new File(a.Path);
File file = new File(dirName, ".nomedia");
if (file.exists()) {
try {
file.delete();
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
} catch (Exception e) {
e.printStackTrace();
}
}
db.unHideAlbum(a.Path);
db.close();
dispAlbums.remove(a);
}
public void deleteSelectedAlbums() {
for (Album selectedAlbum : selectedAlbums)
deleteAlbum(selectedAlbum);
clearSelectedAlbums();
}
public void deleteAlbum(Album a) {
DatabaseHandler db = new DatabaseHandler(context);
File dir = new File(a.Path);
deleteFolderRecursive(dir);
db.deleteAlbum(a.Path);
db.close();
dispAlbums.remove(a);
}
public void excludeSelectedAlbums() {
for (Album selectedAlbum : selectedAlbums)
excludeAlbum(selectedAlbum);
clearSelectedAlbums();
}
public void excludeAlbum(Album a) {
DatabaseHandler db = new DatabaseHandler(context);
Log.i("asd_sring", a.Path);
db.excludeAlbum(a.Path);
db.close();
dispAlbums.remove(a);
}
void deleteFolderRecursive(File dir) {
if (dir.isDirectory()) {
String[] children = dir.list();
for (int i = 0; i < children.length; i++) {
File temp = new File(dir, children[i]);
if (temp.isDirectory())
deleteFolderRecursive(temp);
else {
temp.delete();
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(temp)));
}
}
}
dir.delete();
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(dir)));
}
public void clearSelectedAlbums() {
for (Album dispAlbum : dispAlbums) {
dispAlbum.setSelcted(false);
}
selectedAlbums.clear();
}
public void Log() {
Log.i("numero album", "" + dispAlbums.size());
for (int i = 0; i < dispAlbums.size(); i++) {
Log.i("album", dispAlbums.get(i).DisplayName + " " + dispAlbums.get(i).getImagesCount());
for (Photo photo : dispAlbums.get(i).photos) {
Log.i("foto", "PHOTO_FOLDER_PATH->>" + photo.FolderPath);
Log.i("foto", "PHOTO_PATH->>" + photo.Path);
}
}
}
}
\ No newline at end of file
package com.leafpic.app;
import android.content.Context;
import java.io.File;
import java.util.ArrayList;
/**
* Created by dnld on 1/4/16.
*/
class HandlingPhotos {
public String FolderPath;
public ArrayList<Photo> photos;
public ArrayList<Photo> selectedPhotos;
Context context;
boolean hidden;
public HandlingPhotos(Context ctx, String folderPath, boolean hide) {
context = ctx;
DatabaseHandler db = new DatabaseHandler(context);
FolderPath = folderPath;
hidden = hide;
photos = db.getPhotosByAlbum(FolderPath);
selectedPhotos = new ArrayList<Photo>();
db.close();
}
public void selectPhoto(Photo a, boolean val) {
Photo x = photos.get(photos.indexOf(a));
//x.setSelcted(val);
if (val) selectedPhotos.add(x);
else selectedPhotos.remove(x);
}
public void deleteSelectedPhotos() {
for (Photo photo : selectedPhotos)
deletePhoto(photo);
clearSelectedPhotos();
}
public void deletePhoto(Photo a) {
HandlingAlbums h = new HandlingAlbums(context);
DatabaseHandler db = new DatabaseHandler(context);
File dir = new File(a.Path);
h.deleteFolderRecursive(dir);
db.deleteAlbum(a.Path);
db.close();
photos.remove(a);
}
public void clearSelectedPhotos() {
for (Photo photo : photos) {