-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #164 from DNLDsht/master
v3.0.1
- Loading branch information
Showing
36 changed files
with
3,506 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
/crowdin-cli.jar | ||
/crowdin.yaml | ||
.gradle | ||
# User-specific configurations | ||
/.directory | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
app/src/main/java/com/horaapps/leafpic/Base/ExternalStorage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.