Commit a1a14217 authored by Gilbert Ndresaj's avatar Gilbert Ndresaj

Merge pull request #15 from DNLDsht/master

map provider option
parents 34adf0a1 b6e27568
......@@ -71,4 +71,5 @@ dependencies {
compile 'com.davemorrissey.labs:subsampling-scale-image-view:3.5.0'
compile 'de.hdodenhof:circleimageview:2.0.0'
compile files('src/main/assets/libs/metadata-extractor-2.9.1.jar')
compile 'org.jetbrains:annotations-java5:15.0'
}
......@@ -31,14 +31,14 @@ import de.psdev.licensesdialog.model.Notices;
*/
public class AboutActivity extends ThemedActivity {
Toolbar toolbar;
private Toolbar toolbar;
int color;
/**** CustomTabService*/
CustomTabService cts;
private CustomTabService cts;
/**** Scroll View*/
ScrollView scr;
private ScrollView scr;
@Override
protected void onPostCreate(Bundle savedInstanceState) {
......@@ -57,7 +57,7 @@ public class AboutActivity extends ThemedActivity {
setTheme();
}
public void setTheme(){
private void setTheme(){
/**** ToolBar *****/
toolbar.setBackgroundColor(getPrimaryColor());
setSupportActionBar(toolbar);
......@@ -104,7 +104,7 @@ public class AboutActivity extends ThemedActivity {
/***** Images *****/
Glide.with(this)
.load("https://lh3.googleusercontent.com/-4lGmk-K4r4U/Vw1Vj8yERrI/AAAAAAAANww/FIsb58PcO-U-9AfD8FXfruK1c75SZ184QCL0B/w958-h539-no/asd.png")
.placeholder(getic_empity())
.placeholder(getPlaceHolder())
.priority(Priority.HIGH)
.error(R.drawable.ic_error)
.animate(R.anim.fade_in)
......@@ -130,7 +130,7 @@ public class AboutActivity extends ThemedActivity {
/***** Images *****/
Glide.with(this)
.load("https://lh6.googleusercontent.com/-CQSWRHA3PMU/U1giCTxx3LI/AAAAAAAAAZU/YVnUYwwnNOEE7ob0LyHmRnbUtEtC5znIQCL0B/w958-h639-no/1397233014-game-over-samus.jpg")
.placeholder(getic_empity())
.placeholder(getPlaceHolder())
.priority(Priority.HIGH)
.error(R.drawable.ic_error)
.animate(R.anim.fade_in)
......@@ -157,10 +157,10 @@ public class AboutActivity extends ThemedActivity {
setScrollViewColor(scr);
setThemeOnChangeListener();
ClickListeners();
setUpActions();
}
public void ClickListeners(){
private void setUpActions(){
//GitHub
findViewById(R.id.ll_about_support_github).setOnClickListener(new View.OnClickListener() {
......@@ -259,7 +259,7 @@ public class AboutActivity extends ThemedActivity {
}
public void setThemeOnChangeListener(){
private void setThemeOnChangeListener(){
/** BackGround **/
findViewById(R.id.about_background).setBackgroundColor(getBackgroundColor());
......@@ -309,7 +309,8 @@ public class AboutActivity extends ThemedActivity {
((TextView) findViewById(R.id.about_support_report_bug_sub)).setTextColor(color);
}
public void licenseDialog(){
private void licenseDialog() {
//TODO I HATE THIS redo please.
final Notices notices = new Notices();
notices.addNotice(new Notice("Glide", "http://github.com/bumptech/glide", "Copyright 2014 Google, Inc. All rights reserved.", new ApacheSoftwareLicense20()));
notices.addNotice(new Notice("Ion", "http://github.com/koush/ion", "Copyright 2013 Koushik Dutta (2013)", new ApacheSoftwareLicense20()));
......
......@@ -32,8 +32,8 @@ import java.util.ArrayList;
*/
public class AlbumsAdapter extends RecyclerView.Adapter<AlbumsAdapter.ViewHolder> {
ArrayList<Album> albums;
SharedPreferences SP;
private ArrayList<Album> albums;
private SharedPreferences SP;
private View.OnClickListener mOnClickListener;
private View.OnLongClickListener mOnLongClickListener;
......@@ -138,7 +138,7 @@ public class AlbumsAdapter extends RecyclerView.Adapter<AlbumsAdapter.ViewHolder
return albums.size();
}
public static class ViewHolder extends RecyclerView.ViewHolder {
static class ViewHolder extends RecyclerView.ViewHolder {
LinearLayout card_layout;
ImageView picture;
ImageView selectHolder;
......@@ -146,7 +146,7 @@ public class AlbumsAdapter extends RecyclerView.Adapter<AlbumsAdapter.ViewHolder
TextView nPhotos;
CardView cv;
public ViewHolder(View itemView) {
ViewHolder(View itemView) {
super(itemView);
picture = (ImageView) itemView.findViewById(R.id.album_preview);
selectHolder = (ImageView) itemView.findViewById(R.id.selected_icon);
......
......@@ -21,9 +21,9 @@ import java.util.ArrayList;
public class MediaPagerAdapter extends FragmentStatePagerAdapter {
ArrayList<Media> medias;
View.OnClickListener videoOnClickListener;
SparseArray<Fragment> registeredFragments = new SparseArray<Fragment>();
private ArrayList<Media> medias;
private View.OnClickListener videoOnClickListener;
private SparseArray<Fragment> registeredFragments = new SparseArray<Fragment>();
public MediaPagerAdapter(FragmentManager fm, ArrayList<Media> medias) {
......
......@@ -30,10 +30,10 @@ import java.util.ArrayList;
public class PhotosAdapter extends RecyclerView.Adapter<PhotosAdapter.ViewHolder> {
ArrayList<Media> medias;
SharedPreferences SP;
private ArrayList<Media> medias;
private SharedPreferences SP;
BitmapDrawable drawable;
private BitmapDrawable drawable;
private View.OnClickListener mOnClickListener;
private View.OnLongClickListener mOnLongClickListener;
......@@ -142,11 +142,11 @@ public class PhotosAdapter extends RecyclerView.Adapter<PhotosAdapter.ViewHolder
}
public static class ViewHolder extends RecyclerView.ViewHolder {
static class ViewHolder extends RecyclerView.ViewHolder {
ImageView imageView, selectHolder, gifIcon, videoIcon;
TextView path;
public ViewHolder(View itemView) {
ViewHolder(View itemView) {
super(itemView);
imageView = (ImageView) itemView.findViewById(R.id.photo_preview);
selectHolder = (ImageView) itemView.findViewById(R.id.selected_icon);
......
......@@ -29,14 +29,12 @@ import java.util.List;
public class Album {
String name = null;
String path = null;
int count = -1;
boolean selected = false;
private String path = null;
private int count = -1;
private boolean selected = false;
private int filter_photos;
public AlbumSettings settings = new AlbumSettings();
SharedPreferences SP;
MediaComparators mediaComparators;
int current = -1;
private int current = -1;
private String storageRootPath;
......@@ -83,7 +81,7 @@ public class Album {
}
public void updatePhotos(Context context) {
SP = PreferenceManager.getDefaultSharedPreferences(context);
SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(context);
ArrayList<Media> mediaArrayList = new ArrayList<Media>();
File[] images = new File(getPath()).listFiles(new ImageFileFilter(filter_photos, SP.getBoolean("set_include_video",true)));
for (File image : images)
......@@ -141,7 +139,7 @@ public class Album {
return settings.coverPath != null;
}
public void setSelected(boolean selected) {
void setSelected(boolean selected) {
this.selected = selected;
}
......@@ -169,7 +167,7 @@ public class Album {
return path;
}
public void setCount(int count) {
private void setCount(int count) {
this.count = count;
}
......@@ -177,7 +175,7 @@ public class Album {
return count;
}
public void setCoverPath(String path) {
void setCoverPath(String path) {
settings.coverPath = path;
}
......@@ -201,7 +199,7 @@ public class Album {
}
}
public void setCurrentPhoto(String path) {
private void setCurrentPhoto(String path) {
for (int i = 0; i < media.size(); i++)
if (media.get(i).getPath().equals(path)) current = i;
}
......@@ -312,7 +310,7 @@ public class Album {
}
public void sortPhotos() {
mediaComparators = new MediaComparators(settings.ascending);
MediaComparators mediaComparators = new MediaComparators(settings.ascending);
switch (settings.columnSortingMode) {
case AlbumSettings.SORT_BY_NAME:
Collections.sort(media, mediaComparators.getNameComparator());
......@@ -358,7 +356,7 @@ public class Album {
setCount(media.size());
}
public void deleteMedia(Context context, Media media) {
private void deleteMedia(Context context, Media media) {
File file = new File(media.getPath());
if (file.delete())
scanFile(context, new String[]{ file.getAbsolutePath() });
......
......@@ -17,17 +17,17 @@ public class AlbumSettings {
public final static int SORT_BY_DATE = 0;
public final static int SORT_BY_SIZE = 1;
public String coverPath;
String coverPath;
public int columnSortingMode;
public boolean ascending;
public AlbumSettings(String cover, int SortingMode, boolean asce) {
AlbumSettings(String cover, int SortingMode, boolean asce) {
coverPath = cover;
columnSortingMode = SortingMode;
ascending = asce;
}
public AlbumSettings() {
AlbumSettings() {
coverPath = null;
columnSortingMode = 0;
ascending = false;
......
......@@ -5,14 +5,14 @@ import java.util.Comparator;
/**
* Created by dnld on 26/04/16.
*/
public class AlbumsComparators {
class AlbumsComparators {
boolean ascending = true;
public AlbumsComparators(boolean ascending){
AlbumsComparators(boolean ascending){
this.ascending = ascending;
}
public Comparator<Album> getDateComparator(){
Comparator<Album> getDateComparator(){
return new Comparator<Album>(){
public int compare(Album f1, Album f2) {
return ascending
......@@ -23,7 +23,7 @@ public class AlbumsComparators {
};
}
public Comparator<Album> getNameComparator() {
Comparator<Album> getNameComparator() {
return new Comparator<Album>() {
public int compare(Album f1, Album f2) {
return ascending
......@@ -33,7 +33,7 @@ public class AlbumsComparators {
};
}
public Comparator<Album> getSizeComparator() {
Comparator<Album> getSizeComparator() {
return new Comparator<Album>() {
public int compare(Album f1, Album f2) {
return ascending
......
......@@ -54,7 +54,7 @@ public class CustomAlbumsHandler extends SQLiteOpenHelper {
onCreate(db);
}
public ArrayList<File> getExcludedFolders() {
ArrayList<File> getExcludedFolders() {
ArrayList<File> list = new ArrayList<File>();
SQLiteDatabase db = this.getReadableDatabase();
Cursor cur = db.query(TABLE_ALBUMS, new String[]{ ALBUM_PATH }, ALBUM_EXCLUDED + "=1", null, null, null, null);
......@@ -68,7 +68,7 @@ public class CustomAlbumsHandler extends SQLiteOpenHelper {
return list;
}
public void clearAlbumExclude(String id) {
void clearAlbumExclude(String id) {
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("UPDATE " + TABLE_ALBUMS + " SET " + ALBUM_EXCLUDED + "=0 WHERE " + ALBUM_PATH + "='" + StringUtils.quoteReplace(id) + "'");
db.close();
......@@ -81,7 +81,7 @@ public class CustomAlbumsHandler extends SQLiteOpenHelper {
db.close();
}
public AlbumSettings getSettings(String id) {
AlbumSettings getSettings(String id) {
checkAndCreateAlbum(id);
AlbumSettings s = new AlbumSettings();
SQLiteDatabase db = this.getWritableDatabase();
......@@ -93,7 +93,7 @@ public class CustomAlbumsHandler extends SQLiteOpenHelper {
return s;
}
public void checkAndCreateAlbum(String path) {
private void checkAndCreateAlbum(String path) {
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery("SELECT " + ALBUM_PATH + " FROM " + TABLE_ALBUMS + " WHERE " + ALBUM_PATH + "='" + StringUtils.quoteReplace(path) + "'", null);
if (cursor.getCount() == 0) {
......@@ -106,10 +106,10 @@ public class CustomAlbumsHandler extends SQLiteOpenHelper {
db.close();
}
public String getPhotPrevieAlbum(String id) {
String getCoverPathAlbum(String path) {
String s = null;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery("SELECT " + ALBUM_COVER + " FROM " + TABLE_ALBUMS + " WHERE " + ALBUM_PATH + "='" + StringUtils.quoteReplace(id)
Cursor cursor = db.rawQuery("SELECT " + ALBUM_COVER + " FROM " + TABLE_ALBUMS + " WHERE " + ALBUM_PATH + "='" + StringUtils.quoteReplace(path)
+ "'", null);
if (cursor.moveToFirst())
s = cursor.getString(0);
......@@ -119,7 +119,7 @@ public class CustomAlbumsHandler extends SQLiteOpenHelper {
return s;
}
public void setAlbumPhotPreview(String id, String path) {
void setAlbumPhotPreview(String id, String path) {
checkAndCreateAlbum(id);
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("UPDATE " + TABLE_ALBUMS + " SET " + ALBUM_COVER + "='" + path + "' WHERE " + ALBUM_PATH + "='" + StringUtils.quoteReplace(id) + "'");
......@@ -133,7 +133,7 @@ public class CustomAlbumsHandler extends SQLiteOpenHelper {
db.close();
}
public void setAlbumSortingMode(String id, int column) {
void setAlbumSortingMode(String id, int column) {
checkAndCreateAlbum(id);
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("UPDATE " + TABLE_ALBUMS + " SET " + ALBUM_DEAFAULT_SORTMODE + "=" + column +
......@@ -141,7 +141,7 @@ public class CustomAlbumsHandler extends SQLiteOpenHelper {
db.close();
}
public void setAlbumSortingAscending(String id, boolean asc) {
void setAlbumSortingAscending(String id, boolean asc) {
checkAndCreateAlbum(id);
SQLiteDatabase db = this.getWritableDatabase();
db.execSQL("UPDATE " + TABLE_ALBUMS + " SET " + ALBUM_DEAFAULT_SORT_ASCENDING + "=" + (asc ? 1 : 0) +
......
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;
}
}
\ No newline at end of file
......@@ -34,21 +34,21 @@ import java.util.regex.Pattern;
public class HandlingAlbums {
public final static String TAG = "HandlingAlbums";
Pattern CAMERA_FOLDER_PATTERN = Pattern.compile("\\b/DCIM/Camera/?$");
private Pattern CAMERA_FOLDER_PATTERN = Pattern.compile("\\b/DCIM/Camera/?$");
public ArrayList<Album> dispAlbums;
private ArrayList<Album> selectedAlbums;
boolean includeVideo = true;
private boolean includeVideo = true;
CustomAlbumsHandler customAlbumsHandler;
private CustomAlbumsHandler customAlbumsHandler;
private SharedPreferences SP;
int indexCamera = -1;
int current = -1;
boolean hidden;
private int indexCamera = -1;
private int current = -1;
private boolean hidden;
ArrayList<File> excludedfolders;
AlbumsComparators albumsComparators;
private ArrayList<File> excludedfolders;
private AlbumsComparators albumsComparators;
public HandlingAlbums(Context context) {
SP = PreferenceManager.getDefaultSharedPreferences(context);
......@@ -98,67 +98,26 @@ public class HandlingAlbums {
return dispAlbums.get(current);
}
public void clearCameraIndex() {
private void clearCameraIndex() {
indexCamera = -1;
}
public HashSet<File> listStorages(Context context) {
private HashSet<File> listStorages(Context context) {
HashSet<File> roots = new HashSet<File>();
roots.add(Environment.getExternalStorageDirectory());
String[] extSdCardPaths = ContentHelper.getExtSdCardPaths(context);
for (String extSdCardPath : extSdCardPaths) {
File mas = new File(extSdCardPath);
if (mas.canRead())
roots.add(mas);
}
//Log.wtf(TAG, Environment.getExternalStorageDirectory().getAbsolutePath());
/*for (String mount : getExternalMounts()) {
File mas = new File(mount);
if (mas.canRead())
roots.add(mas);
}*/
String sdCard = System.getenv("SECONDARY_STORAGE");
if (sdCard != null) roots.add(new File(sdCard));
return roots;
}
public static HashSet<String> getExternalMounts() {
final HashSet<String> out = new HashSet<String>();
String reg = "(?i).*vold.*(vfat|ntfs|exfat|fat32|ext3|ext4).*rw.*";
String s = "";
try {
final Process process = new ProcessBuilder().command("mount")
.redirectErrorStream(true).start();
process.waitFor();
final InputStream is = process.getInputStream();
final byte[] buffer = new byte[1024];
while (is.read(buffer) != -1) {
s = s + new String(buffer);
}
is.close();
} catch (final Exception e) {
e.printStackTrace();
}
// parse output
final String[] lines = s.split("\n");
for (String line : lines) {
if (!line.toLowerCase(Locale.US).contains("asec")) {
if (line.matches(reg)) {
String[] parts = line.split(" ");
for (String part : parts) {
if (part.startsWith("/"))
if (!part.toLowerCase(Locale.US).contains("vold"))
out.add(part);
}
}
}
}
return out;
}
public ArrayList<Album> getValidFolders(Context context,boolean hidden) {
ArrayList<Album> folders = new ArrayList<Album>();
if (hidden)
......@@ -251,12 +210,12 @@ public class HandlingAlbums {
return excludedfolders;
}
public void checkAndAddAlbum(File temp, ArrayList<Album> albumArrayList, String rootExternalStorage) {
private void checkAndAddAlbum(File temp, ArrayList<Album> albumArrayList, String rootExternalStorage) {
File[] files = temp.listFiles(new ImageFileFilter(includeVideo));
if (files != null && files.length > 0) {
//valid folder
Album asd = new Album(temp.getAbsolutePath(), temp.getName(), files.length, rootExternalStorage);
asd.setCoverPath(customAlbumsHandler.getPhotPrevieAlbum(asd.getPath()));
asd.setCoverPath(customAlbumsHandler.getCoverPathAlbum(asd.getPath()));
long lastMod = Long.MIN_VALUE;
File choice = null;
......@@ -369,7 +328,8 @@ public class HandlingAlbums {
}
return dstBmp;
}
public void scanFile(Context context, String[] path) { MediaScannerConnection.scanFile(context, path, null, null); }
private void scanFile(Context context, String[] path) { MediaScannerConnection.scanFile(context, path, null, null); }
public void hideAlbum(String path, Context context) {
File dirName = new File(path);
......@@ -391,7 +351,7 @@ public class HandlingAlbums {
clearSelectedAlbums();
}
public void hideAlbum(final Album a, Context context) {
private void hideAlbum(final Album a, Context context) {
hideAlbum(a.getPath(), context);
dispAlbums.remove(a);
}
......@@ -410,7 +370,7 @@ public class HandlingAlbums {
clearSelectedAlbums();
}
public void unHideAlbum(final Album a, Context context) {
private void unHideAlbum(final Album a, Context context) {
unHideAlbum(a.getPath(), context);
dispAlbums.remove(a);
}
......@@ -439,7 +399,7 @@ public class HandlingAlbums {
clearSelectedAlbums();
}
public void excludeAlbum(Context context, Album a) {
private void excludeAlbum(Context context, Album a) {
CustomAlbumsHandler h = new CustomAlbumsHandler(context);
h.excludeAlbum(a.getPath());
excludedfolders.add(new File(a.getPath()));
......
......@@ -17,17 +17,17 @@ public class ImageFileFilter implements FilenameFilter
public final static int FILTER_IMAGES = 1;
public final static int FILTER_GIFS = 2;
public final static int FILTER_VIDEO = 3;
public final static int FILTER_NO_VIDEO = 4;
private final static int FILTER_NO_VIDEO = 4;
HashSet<String> extensions;
public static String[] imagesExtensions =
private HashSet<String> extensions;
private static String[] imagesExtensions =
new String[] { "jpg", "png", "jpe", "jpeg", "bmp", "webp" };
public static String[] videoExtensions = new String[] { "mp4", "mkv", "webm", "avi" };
public static String[] gifsExtensions = new String[] { "gif"} ;