Skip to content

Commit

Permalink
Merge pull request #164 from DNLDsht/master
Browse files Browse the repository at this point in the history
v3.0.1
  • Loading branch information
Donald Shtjefni committed May 9, 2016
2 parents fdf7b17 + a5444e2 commit 08ccd04
Show file tree
Hide file tree
Showing 36 changed files with 3,506 additions and 188 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/crowdin-cli.jar
/crowdin.yaml
.gradle
# User-specific configurations
/.directory
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ android {
applicationId "com.horaapps.leafpic"
minSdkVersion 19
targetSdkVersion 23
versionCode 4
versionName "v0.3"
versionCode 5
versionName "v0.3.1"
}

lintOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public PhotosAdapter(ArrayList<Media> ph , Context context) {
SP = PreferenceManager.getDefaultSharedPreferences(context);
switch (SP.getInt("basic_theme", 1)){
case 2: drawable = ((BitmapDrawable) ContextCompat.getDrawable(context, R.drawable.ic_empty));break;
case 3: drawable = ((BitmapDrawable) ContextCompat.getDrawable(context, R.drawable.ic_empty_amoled));break;
case 3: drawable = null ;break;
case 1: default: drawable = ((BitmapDrawable) ContextCompat.getDrawable(context, R.drawable.ic_empty_white));break;
}
}
Expand Down
143 changes: 143 additions & 0 deletions app/src/main/java/com/horaapps/leafpic/Base/ExternalStorage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
package com.horaapps.leafpic.Base;

import android.os.Build;
import android.os.Environment;
import android.util.Log;

import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

/**
* Created by dnld on 09/05/16.
*/
public class ExternalStorage {
public static final String SD_CARD = "sdCard";
public static final String EXTERNAL_SD_CARD = "externalSdCard";

/**
* @return True if the external storage is available. False otherwise.
*/
public static boolean isAvailable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
return true;
}
return false;
}

public static String getSdCardPath() {
return Environment.getExternalStorageDirectory().getPath() + "/";
}

/**
* @return True if the external storage is writable. False otherwise.
*/
public static boolean isWritable() {
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
return true;
}
return false;

}

/**
* @return A map of all storage locations available
*/
public static ArrayList<File> getAllStorageLocations() {
//Map<String, File> map = new HashMap<String, File>(10);
ArrayList<File> roots = new ArrayList<File>();

List<String> mMounts = new ArrayList<String>(10);
List<String> mVold = new ArrayList<String>(10);
mMounts.add("/mnt/sdcard");
mVold.add("/mnt/sdcard");

try {
File mountFile = new File("/proc/mounts");
if(mountFile.exists()){
Scanner scanner = new Scanner(mountFile);
while (scanner.hasNext()) {
String line = scanner.nextLine();
if (line.startsWith("/dev/block/vold/")) {
String[] lineElements = line.split(" ");
String element = lineElements[1];

// don't add the default mount path
// it's already in the list.
if (!element.equals("/mnt/sdcard"))
mMounts.add(element);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}

try {
File voldFile = new File("/system/etc/vold.fstab");
if(voldFile.exists()){
Scanner scanner = new Scanner(voldFile);
while (scanner.hasNext()) {
String line = scanner.nextLine();
if (line.startsWith("dev_mount")) {
String[] lineElements = line.split(" ");
String element = lineElements[2];

if (element.contains(":"))
element = element.substring(0, element.indexOf(":"));
if (!element.equals("/mnt/sdcard"))
mVold.add(element);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}

for (int i = 0; i < mMounts.size(); i++) {
String mount = mMounts.get(i);
if (!mVold.contains(mount))
mMounts.remove(i--);
}
mVold.clear();

List<String> mountHash = new ArrayList<String>(10);

for(String mount : mMounts){
File root = new File(mount);
if (root.exists() && root.isDirectory() && root.canWrite()) {
File[] list = root.listFiles();
String hash = "[";
if(list!=null){
for(File f : list){
hash += f.getName().hashCode()+":"+f.length()+", ";
}
}
hash += "]";
if(!mountHash.contains(hash)){
/*String key = SD_CARD + "_" + map.size();
if (map.size() == 0) {
key = SD_CARD;
} else if (map.size() == 1) {
key = EXTERNAL_SD_CARD;
}*/
mountHash.add(hash);
roots.add(root);
//map.put(key, root);
}
}
}

mMounts.clear();

/*if(map.isEmpty()){
map.put(SD_CARD, Environment.getExternalStorageDirectory());
}*/
return roots;
}
}
60 changes: 31 additions & 29 deletions app/src/main/java/com/horaapps/leafpic/Base/HandlingAlbums.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,6 @@ public class HandlingAlbums {
ArrayList<File> excludedfolders;
AlbumsComparators albumsComparators;

public HandlingAlbums() {
excludedfolders = new ArrayList<File>();
dispAlbums = new ArrayList<Album>();
selectedAlbums = new ArrayList<Album>();
}

public HandlingAlbums(Context context) {
SP = context.getSharedPreferences("albums-sort", Context.MODE_PRIVATE);
customAlbumsHandler = new CustomAlbumsHandler(context);
Expand Down Expand Up @@ -88,17 +82,19 @@ public ArrayList<Album> getValidFolders(boolean hidden) {
private void fetchRecursivelyFolder(File dir, ArrayList<Album> folders) {
if (!excludedfolders.contains(dir)) {
File[] listFiles = dir.listFiles(new ImageFileFilter());
if (listFiles.length > 0)
if (listFiles != null && listFiles.length > 0)
folders.add(new Album(dir.getAbsolutePath(), dir.getName(), listFiles.length));

File[] children = dir.listFiles(new FoldersFileFilter());
for (File temp : children) {
File nomedia = new File(temp, ".nomedia");
if (!excludedfolders.contains(temp) && !temp.isHidden() && !nomedia.exists()) {
if (children != null) {
for (File temp : children) {
File nomedia = new File(temp, ".nomedia");
if (!excludedfolders.contains(temp) && !temp.isHidden() && !nomedia.exists()) {
/*File[] files = temp.listFiles(new ImageFileFilter());
if (files.length > 0)
folders.add(new Album(temp.getAbsolutePath(), temp.getName(), files.length));*/
fetchRecursivelyFolder(temp, folders);
fetchRecursivelyFolder(temp, folders);
}
}
}
}
Expand All @@ -107,26 +103,30 @@ private void fetchRecursivelyFolder(File dir, ArrayList<Album> folders) {
private void fetchRecursivelyHiddenFolder(File dir, ArrayList<Album> folders) {
if (!excludedfolders.contains(dir)) {
File[] asdf = dir.listFiles(new FoldersFileFilter());
for (File temp : asdf) {
File nomedia = new File(temp, ".nomedia");
if (!excludedfolders.contains(temp) && nomedia.exists()) {
File[] files = temp.listFiles(new ImageFileFilter());
if (files.length > 0)
folders.add(new Album(temp.getAbsolutePath(), temp.getName(), files.length));
if (asdf !=null) {
for (File temp : asdf) {
File nomedia = new File(temp, ".nomedia");
if (!excludedfolders.contains(temp) && nomedia.exists()) {
File[] files = temp.listFiles(new ImageFileFilter());
if (files != null && files.length > 0)
folders.add(new Album(temp.getAbsolutePath(), temp.getName(), files.length));
}
fetchRecursivelyHiddenFolder(temp, folders);
}
fetchRecursivelyHiddenFolder(temp, folders);
}
}
}
private void fetchRecursivelyFolder(File dir) {
if (!excludedfolders.contains(dir)) {
checkAndAddAlbum(dir);
File[] children = dir.listFiles(new FoldersFileFilter());
for (File temp : children) {
File nomedia = new File(temp, ".nomedia");
if (!excludedfolders.contains(temp) && !temp.isHidden() && !nomedia.exists()) {
//not excluded/hidden folder
fetchRecursivelyFolder(temp);
if (children != null) {
for (File temp : children) {
File nomedia = new File(temp, ".nomedia");
if (!excludedfolders.contains(temp) && !temp.isHidden() && !nomedia.exists()) {
//not excluded/hidden folder
fetchRecursivelyFolder(temp);
}
}
}
}
Expand All @@ -135,19 +135,21 @@ private void fetchRecursivelyFolder(File dir) {
private void fetchRecursivelyHiddenFolder(File dir) {
if (!excludedfolders.contains(dir)) {
File[] folders = dir.listFiles(new FoldersFileFilter());
for (File temp : folders) {
File nomedia = new File(temp, ".nomedia");
if (!excludedfolders.contains(temp) && nomedia.exists()) {
checkAndAddAlbum(temp);
if (folders != null) {
for (File temp : folders) {
File nomedia = new File(temp, ".nomedia");
if (!excludedfolders.contains(temp) && nomedia.exists()) {
checkAndAddAlbum(temp);
}
fetchRecursivelyHiddenFolder(temp);
}
fetchRecursivelyHiddenFolder(temp);
}
}
}

public void checkAndAddAlbum(File temp) {
File[] files = temp.listFiles(new ImageFileFilter());
if (files.length > 0) {
if (files != null && files.length > 0) {
//valid folder
Album asd = new Album(temp.getAbsolutePath(), temp.getName(), files.length);
asd.setCoverPath(customAlbumsHandler.getPhotPrevieAlbum(asd.getPath()));
Expand Down
56 changes: 54 additions & 2 deletions app/src/main/java/com/horaapps/leafpic/Base/Media.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.horaapps.leafpic.Base;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.ExifInterface;
import android.net.Uri;
import android.os.Parcel;
Expand Down Expand Up @@ -84,8 +86,18 @@ public long getSize() {
public int getOrientation() {
ExifInterface exif;
try { exif = new ExifInterface(getPath()); }
catch (IOException e) { return 0; }
return Integer.parseInt(exif.getAttribute(ExifInterface.TAG_ORIENTATION));
catch (IOException ex) { return 0; }
if (exif != null) {
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, -1);
if (orientation != -1) {
switch (orientation) {
case ExifInterface.ORIENTATION_ROTATE_90: return 90;
case ExifInterface.ORIENTATION_ROTATE_180: return 180;
case ExifInterface.ORIENTATION_ROTATE_270: return 270;
}
}
}
return 0;
}

public int getWidth() { //TODO improve
Expand Down Expand Up @@ -122,6 +134,46 @@ public boolean isSelected() {
return selected;
}

public Bitmap getBitmap(){
/*
Bitmap bm = null;
InputStream is = null;
BufferedInputStream bis = null;
try {
URLConnection conn = new URL(path).openConnection();
conn.connect();
is = conn.getInputStream();
bis = new BufferedInputStream(is, 8192);
bm = BitmapFactory.decodeStream(bis);
}
catch (Exception e) {
e.printStackTrace();
} finally {
if (bis != null) {
try {
bis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (is != null) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return bm;
*/
//File sd = Environment.getExternalStorageDirectory();
//File image = new File(sd+path, getName);
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
Bitmap bitmap = BitmapFactory.decodeFile(path,bmOptions);
bitmap = Bitmap.createScaledBitmap(bitmap,bitmap.getWidth(),bitmap.getHeight(),true);
return bitmap;
}

protected Media(Parcel in) {
path = in.readString();
dateModified = in.readLong();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand Down Expand Up @@ -89,7 +90,7 @@ public void onOutsidePhotoTap() {
}
});
photoView.setZoomTransitionDuration(375);
photoView.setScaleLevels(1.0F, 3.5F, 6.0F);
photoView.setScaleLevels(1.0F, 3.5F, 6.0F);//TODO improve
return photoView;
}

Expand Down
Loading

0 comments on commit 08ccd04

Please sign in to comment.