How to access nook gallery with Adobe Air for Android - Nook Color Android Development

So, I have an application that I'm doing in Adobe air that lets a user upload an image from their nook. Right now I have this code in AS3:
Code:
var newbitmap:Bitmap;
var loadInfo : LoaderInfo;
var puzzBitmap : Bitmap;
var fileReference:FileReference; //declare file
var loader:Loader = new Loader();
browsebutton.addEventListener(MouseEvent.CLICK, uploadstuff)
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
function uploadstuff(e:MouseEvent):void
{
fileReference = new FileReference();
fileReference.addEventListener(Event.SELECT, selectHandler);
fileReference.addEventListener(Event.COMPLETE, completeHandler);
var fileFilter:FileFilter = new FileFilter("Images","*.jpg;*.jpeg;*.gif;*.png;*.bmp;");
fileReference.browse([fileFilter]);
}
function selectHandler(event:Event):void
{
fileReference.load();
}
function completeHandler(event:Event):void
{
loader.loadBytes(fileReference.data);
//addChild(loader);
}
function imageLoaded(event : Event):void
{
loadInfo = event.target as LoaderInfo;
if(loadInfo != null)
{
var bitmap : Bitmap = loadInfo.content as Bitmap;
var sourceData:BitmapData = bitmap.bitmapData;
puzzBitmap = new Bitmap(sourceData);
var matrix:Matrix = new Matrix();
matrix.scale(450/puzzBitmap.width,300/puzzBitmap.height);
var smallBMD:BitmapData = new BitmapData(450, 300, true, 0x000000);
smallBMD.draw(puzzBitmap, matrix, null, null, null, true);
newbitmap = new Bitmap(smallBMD, PixelSnapping.NEVER, true);
puzzBitmap.width=450;
puzzBitmap.height=300;
puzzBitmap.x=260;
puzzBitmap.y=147.5;
addChild(puzzBitmap);
}
}
Now on my laptop this works fine, it lets me browse through my folders and select an image to upload. However, when I port it to nook, hitting browse does bring up a window but it just says "no files found". It doesn't even show me the folder so I an browse the folders and find an image. So nook's filesystem works differently from my laptops where file browsing doesn't work. Any ideas how to do file browsing or access the gallery directly on the nook?

Related

[Q] Rotating image using matrix distorts the image when being saved

I am implementing a custom camera in android. One of the phones that I am using the default display orientation is landscape mode. The preview of the image looks good when taking the picture. Nonetheless, when the immage is rotated and saved the image becomes distorted.
This is the code I am using to rotate the image:
Code:
Display display = ((WindowManager) MyCamera.this.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int rotation = display.getRotation();
if (rotation == Surface.ROTATION_0) {
rotation = 90;
} else if (rotation == Surface.ROTATION_90) {
rotation = 180;
} else if (rotation == Surface.ROTATION_180) {
rotation = 270;
} else if (rotation == Surface.ROTATION_270) {
rotation = 360;
}
DisplayMetrics metrics = getResources().getDisplayMetrics();
Options options = new BitmapFactory.Options();
options.inDither = false;
options.inScaled = false;
options.inDensity=metrics.densityDpi;
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
bm = BitmapFactory.decodeByteArray(imgBytes, 0, imgBytes.length, options);
Matrix m = new Matrix();
m.postRotate(rotation);
Bitmap nbm = Bitmap.createBitmap(bm, 0, 0, bm.getWidth(), bm.getHeight(), m, true);
file = MyCamera.this.saveBitmap(nbm);
This is the code I'm using to save Bitmap image:
Code:
private File saveBitmap(Bitmap image) {
File pictureFile = getOutputMediaFile(MEDIA_TYPE_IMAGE);
if (pictureFile == null) {
Log.d(TAG,"Error creating media file, check storage permissions: ");// e.getMessage());
return null;
}
try {
FileOutputStream fos = new FileOutputStream(pictureFile);
image.compress(Bitmap.CompressFormat.JPEG, 100, fos);
fos.close();
} catch (FileNotFoundException e) {
Log.d(TAG, "File not found: " + e.getMessage());
finish();
} catch (IOException e) {
Log.d(TAG, "Error accessing file: " + e.getMessage());
finish();
}
return pictureFile;
}
Here are some examples on how the image looks in camera preview mode and how it looks after it is saved on the phones external storage.

How to support icons in FileDialog

So i found this perfect code to be able to select zip from sd, but the list looks so basic and I would like to add icons (like one common icon for all dirs), however it seems too hard to do on my own, here is the code:
Code:
private void loadFileList(File path) {
this.currentPath = path;
List<String> r = new ArrayList<String>();
if (path.exists()) {
if (path.getParentFile() != null) r.add(PARENT_DIR);
FilenameFilter filter = new FilenameFilter() {
@SuppressLint("DefaultLocale")
public boolean accept(File dir, String filename) {
File sel = new File(dir, filename);
if (!sel.canRead()) return false;
if (selectDirectoryOption) return sel.isDirectory();
else {
boolean endsWith = fileEndsWith != null ? filename.toLowerCase().endsWith(fileEndsWith) : true;
return endsWith || sel.isDirectory();
}
}
};
String[] fileList1 = path.list(filter);
for (String file : fileList1) {
r.add(file);
}
}
fileList = (String[]) r.toArray(new String[]{});
}

Android Lollipop save image downloaded in background on SD-CARD

whit ANDROID previous kitkat I was able to store an image on sd-card without problem, now, instead, I've a lot of difficult.
I can't understand how use a new Access Store Framework of Android Lollipop and I don't know if it is useful to case of mine.
This code below is a part of my project and it's worked perfectly
Code:
private Bitmap getBitmap(String url, String image){
String root = Environment.getExternalStorageDirectory().toString();
root = "/mnt/extSdCard/";
Bitmap bitmap = null;
File f=fileCache.getFile(url);
//from SD cache
bitmap = decodeFile(f);
if(bitmap!=null)
return bitmap;
try{
bitmap = BitmapFactory.decodeFile(root + image);
if(bitmap!=null){
return bitmap;
}
}catch (Exception e) {
e.printStackTrace();
}
//from web
if (netInfo != null && netInfo.isConnectedOrConnecting()) {
Foto foto = new Foto();
try {
try{
foto = new ObjectMapper().readValue(new URL("........."),
Foto.class);
if(foto!=null){
String[] values = image.split("/");
File dir = new File(root + values[0]);
if (!dir.exists()) {
dir.mkdir();
String fname = values[1];
File file = new File (dir, fname);
bitmap = BitmapFactory.decodeByteArray(foto.getFoto(), 0, foto.getFoto().length);
try {
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}else{
String fname = values[1];
File file = new File (dir, fname);
bitmap = BitmapFactory.decodeByteArray(foto.getFoto(), 0, foto.getFoto().length);
try {
FileOutputStream out = new FileOutputStream(file);
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
out.flush();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}
//bitmap = decodeFile(f);
return bitmap;
}else{
return bitmap;
}
}catch(Exception e){
e.printStackTrace();
return null;
}
} catch (Exception ex){
if (ex instanceof SQLiteConstraintException){
bitmap = BitmapFactory.decodeByteArray(foto.getFoto(), 0, foto.getFoto().length);
return bitmap;
}else{
ex.printStackTrace();
return null;
}
}
}else{
return bitmap;
}
}
If I use `Environment.getExternalStorageDirectory().getAbsolutePath();` I can't get path of sd-card.
Thanks

Camera real time image processing

I need to do some image processing in real time on mobile. I am using camera2 library. I managed to put camera preview directly on surfaceView but when i redirect it to ImageReader to do something with frames before i preview them it goes really slow, and there is not even processing just taking Y value from YUV_420_888 and converting it to gray picture in ARGB_8888 format. Code is below. For that one for loop i need about 600ms. And for image processing i will need to go trough that image at least one more time. In Bits array i form ARGB_8888 format out of Y array which is Y value of YUV_420_888 format. I test it on phone with Quad Core 1ghz processor and 1gb ram. Is there any way to speed this code up so i can go lets say 2-3 times trough picture and have at least 7-10 fps? If i delete for loop and just measure fps its 8-12fps. Why is it so slow compering to 25fps when i put it directly on surfaceView?
Code:
private final CameraDevice.StateCallback mStateCallback = new CameraDevice.StateCallback() {
@Override
public void onOpened(@NonNull CameraDevice cameraDevice) {
// This method is called when the camera is opened. We start camera preview here.
mCameraOpenCloseLock.release();
mCameraDevice = cameraDevice;
createCameraPreviewSession();
mImageReader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() {
@Override
public void onImageAvailable(ImageReader reader) {
Image image = reader.acquireLatestImage();
if(image != null) {
ByteBuffer buffer0 = image.getPlanes()[0].getBuffer();
byte[] Y = new byte[buffer0.remaining()];
buffer0.get(Y);
byte[] Bits = new byte[Y.length*4]; //That's where the RGBA array goes.
int Ylength = Y.length;
for (int i = 0; i < Ylength; i++) {
int i1 = i*4;
Bits[i1] =Y[i];
Bits[i1 + 1] =Y[i];
Bits[i1 + 2] = Y[i];
Bits[i1 + 3] = -1;//0xff, that's the alpha.
}
Bitmap bm = Bitmap.createBitmap(image.getWidth(), image.getHeight(), Bitmap.Config.ARGB_8888);
bm.copyPixelsFromBuffer(ByteBuffer.wrap(Bits));
Bitmap scaled = Bitmap.createScaledBitmap(bm, surfaceView.getWidth(), surfaceView.getHeight(), true);
Canvas c;
c = surfaceHolder.lockCanvas();
c.drawBitmap(scaled, 0, 0, null);
surfaceHolder.unlockCanvasAndPost(c);
image.close();
time2 = System.nanoTime();
Log.d("Vreme",Double.toString(1000000000/(time2-time1))+"fps");
time1 = System.nanoTime();
}
}
},mBackgroundHandler);
}
@Override
public void onDisconnected(@NonNull CameraDevice cameraDevice) {
mCameraOpenCloseLock.release();
cameraDevice.close();
mCameraDevice = null;
}
@Override
public void onError(@NonNull CameraDevice cameraDevice, int error) {
mCameraOpenCloseLock.release();
cameraDevice.close();
mCameraDevice = null;
}
};

Open specific file with Specific application

Please help i have a file that i need to open with a specific application
but i cant get to to open
public String get_mime_type(String url) {
String ext = MimeTypeMap.getFileExtensionFromUrl(url);
String mime = null;
if (ext != null) {
mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext);
}
return mime;
}
private void openovpn(){
Intent intent = new Intent(Intent.ACTION_GET_CONTENT); Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath() + "/Downloads/");
intent.setDataAndType(uri,"*/*");
intent.setAction(Intent.ACTION_DEFAULT);
startActivityForResult(intent, RQS_OPEN);
Toast.makeText(VpnConfig.this,
"Single-selection: Tap on any file.\n" +
"Multi-selection: Tap & Hold on the first file, " +
"tap for more, tap on OPEN to finish.",
Toast.LENGTH_LONG).show();
}

Categories

Resources