App
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
mhr.appandroid.adapters.AndroidImageFile Class Reference

implementace ImageFile pro Android More...

Inheritance diagram for mhr.appandroid.adapters.AndroidImageFile:
mhr.appcore.interfaces.ImageFile

Public Member Functions

Document getDocument ()
 
void writeDocument ()
 
PDBitmap createBitmap (BitmapInfo i)
 
PDBitmap loadBitmap (String fName)
 
void writeBitmap (PDBitmap bitmap, String fName)
 
PDBitmap loadMask (String fName)
 
void writeMask (PDBitmap mask, String fName)
 
PDBitmap loadOutput ()
 
void saveOutput (PDBitmap bitmap)
 
void deleteFile ()
 

Static Public Member Functions

static AndroidImageFile createImageFile (String fname, Activity a)
 
static AndroidImageFile openImageFile (String fname, Activity a)
 
static Bitmap loadThumb (File root, int width, int height)
 
static void deleteFile (String fname, Activity a)
 

Protected Member Functions

 AndroidImageFile ()
 

Protected Attributes

Activity activity
 

Detailed Description

implementace ImageFile pro Android

Definition at line 44 of file AndroidImageFile.java.

Constructor & Destructor Documentation

mhr.appandroid.adapters.AndroidImageFile.AndroidImageFile ( )
inlineprotected

Definition at line 61 of file AndroidImageFile.java.

{
}

Member Function Documentation

PDBitmap mhr.appandroid.adapters.AndroidImageFile.createBitmap ( BitmapInfo  i)
inline

Implements mhr.appcore.interfaces.ImageFile.

Definition at line 233 of file AndroidImageFile.java.

{
return new APDBitmap(i);
}
static AndroidImageFile mhr.appandroid.adapters.AndroidImageFile.createImageFile ( String  fname,
Activity  a 
)
inlinestatic

Definition at line 65 of file AndroidImageFile.java.

{
i.activity = a;
i.fname = fname;
File root = a.getExternalFilesDir(null);
i.iDir = new File(root, fname);
i.iDir.mkdirs();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = null;
try {
documentBuilder = documentBuilderFactory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
throw new RuntimeException("Unhandled exception " + e.toString());
}
i.doc = documentBuilder.newDocument();
return i;
}
static void mhr.appandroid.adapters.AndroidImageFile.deleteFile ( String  fname,
Activity  a 
)
inlinestatic

Definition at line 172 of file AndroidImageFile.java.

{
File root = a.getExternalFilesDir(null);
File imageRoot = new File(root, fname);
if (!imageRoot.exists()) {
return;
}
File[] files = imageRoot.listFiles();
for (File f : files) {
f.delete();
}
imageRoot.delete();
}
void mhr.appandroid.adapters.AndroidImageFile.deleteFile ( )
inline

Implements mhr.appcore.interfaces.ImageFile.

Definition at line 371 of file AndroidImageFile.java.

{
deleteFile(fname, activity);
}
Document mhr.appandroid.adapters.AndroidImageFile.getDocument ( )
inline

Implements mhr.appcore.interfaces.ImageFile.

Definition at line 188 of file AndroidImageFile.java.

{
return doc;
}
PDBitmap mhr.appandroid.adapters.AndroidImageFile.loadBitmap ( String  fName)
inline

Implements mhr.appcore.interfaces.ImageFile.

Definition at line 238 of file AndroidImageFile.java.

{
BitmapFactory.Options o = new BitmapFactory.Options();
o.inScaled = false;
InputStream is = null;
APDBitmap retVal = null;
try {
is = new FileInputStream(new File(iDir, fName + ".png"));
retVal = new APDBitmap(BitmapFactory.decodeStream(is));
} catch (FileNotFoundException e) {
throw new RuntimeException("Unhandled exception " + e.toString());
} finally {
try {
is.close();
} catch (IOException e) {
throw new RuntimeException("Unhandled exception " + e.toString());
}
}
return retVal;
}
PDBitmap mhr.appandroid.adapters.AndroidImageFile.loadMask ( String  fName)
inline

Implements mhr.appcore.interfaces.ImageFile.

Definition at line 284 of file AndroidImageFile.java.

{
BitmapFactory.Options o = new BitmapFactory.Options();
o.inScaled = false;
InputStream is = null;
APDBitmap retVal = null;
try {
is = new FileInputStream(new File(iDir, fName + ".png"));
retVal = new APDBitmap(BitmapFactory.decodeStream(is).extractAlpha());
} catch (FileNotFoundException e) {
throw new RuntimeException("Unhandled exception " + e.toString());
} finally {
try {
is.close();
} catch (IOException e) {
throw new RuntimeException("Unhandled exception " + e.toString());
}
}
return retVal;
}
PDBitmap mhr.appandroid.adapters.AndroidImageFile.loadOutput ( )
inline

Implements mhr.appcore.interfaces.ImageFile.

Definition at line 324 of file AndroidImageFile.java.

{
BitmapFactory.Options o = new BitmapFactory.Options();
o.inScaled = false;
InputStream is = null;
APDBitmap retVal = null;
try {
is = new FileInputStream(new File(iDir, "out.png"));
retVal = new APDBitmap(BitmapFactory.decodeStream(is));
} catch (FileNotFoundException e) {
throw new RuntimeException("Unhandled exception " + e.toString());
} finally {
try {
is.close();
} catch (IOException e) {
throw new RuntimeException("Unhandled exception " + e.toString());
}
}
return retVal;
}
static Bitmap mhr.appandroid.adapters.AndroidImageFile.loadThumb ( File  root,
int  width,
int  height 
)
inlinestatic

Definition at line 133 of file AndroidImageFile.java.

{
// BitmapFactory.Options o = new BitmapFactory.Options();
// o.inScaled = false;
InputStream is = null;
// Bitmap tmp = null;
Bitmap retVal = null;
try {
is = new FileInputStream(new File(root, "out.png"));
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true; // Pouze precte rozmery obr.
BitmapFactory.decodeStream(is, null, o);
is.close();
is = null;
int wscale = o.outWidth / width;
int hscale = o.outHeight / height;
o.inJustDecodeBounds = false;
o.inSampleSize = wscale > hscale ? wscale : hscale;
is = new FileInputStream(new File(root, "out.png"));
retVal = BitmapFactory.decodeStream(is, null, o);
} catch (FileNotFoundException e) {
throw new RuntimeException("Unhandled exception " + e.toString());
} catch (IOException e) {
// Zavírání streamu
} finally {
if (is != null) {
try {
is.close();
} catch (IOException e) {
throw new RuntimeException("Unhandled exception " + e.toString());
}
}
}
return retVal;
}
static AndroidImageFile mhr.appandroid.adapters.AndroidImageFile.openImageFile ( String  fname,
Activity  a 
)
inlinestatic

Definition at line 84 of file AndroidImageFile.java.

{
i.activity = a;
i.fname = fname;
File root = a.getExternalFilesDir(null);
i.iDir = new File(root, fname);
if (!i.iDir.exists()) {
throw new RuntimeException("File doesnt exists");
}
InputStream is = null;
try {
is = new FileInputStream(new File(i.iDir, "image.xml"));
} catch (FileNotFoundException e) {
throw new RuntimeException("Unhandled exception " + e.toString());
}
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = null;
try {
builder = factory.newDocumentBuilder();
} catch (ParserConfigurationException e) {
try {
is.close();
} catch (IOException e1) {
throw new RuntimeException("Unhandled exception " + e.toString());
}
throw new RuntimeException("Unhandled exception " + e.toString());
}
Document dom = null;
try {
dom = builder.parse(is);
} catch (SAXException e) {
throw new RuntimeException("Unhandled exception " + e.toString());
} catch (IOException e) {
throw new RuntimeException("Unhandled exception " + e.toString());
} finally {
try {
is.close();
} catch (IOException e) {
throw new RuntimeException("Unhandled exception " + e.toString());
}
}
i.doc = dom;
return i;
}
void mhr.appandroid.adapters.AndroidImageFile.saveOutput ( PDBitmap  bitmap)
inline

Implements mhr.appcore.interfaces.ImageFile.

Definition at line 345 of file AndroidImageFile.java.

{
if (!(bitmap instanceof APDBitmap)) {
throw new IllegalArgumentException("Wrong bitmap");
}
Bitmap b = ((APDBitmap) bitmap).getBitmap();
File out = new File(iDir, "out.png");
OutputStream os = null;
try {
os = new FileOutputStream(out);
b.compress(CompressFormat.PNG, 100, os);
os.flush();
} catch (IOException e) {
throw new RuntimeException("Unhandled exception " + e.toString());
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
throw new RuntimeException("Unhandled exception " + e.toString());
}
}
}
}
void mhr.appandroid.adapters.AndroidImageFile.writeBitmap ( PDBitmap  bitmap,
String  fName 
)
inline

Implements mhr.appcore.interfaces.ImageFile.

Definition at line 259 of file AndroidImageFile.java.

{
if (!(bitmap instanceof APDBitmap)) {
throw new IllegalArgumentException("Wrong bitmap");
}
Bitmap b = ((APDBitmap) bitmap).getBitmap();
File out = new File(iDir, fName + ".png");
OutputStream os = null;
try {
os = new FileOutputStream(out);
b.compress(CompressFormat.PNG, 100, os);
os.flush();
} catch (IOException e) {
throw new RuntimeException("Unhandled exception " + e.toString());
} finally {
if (os != null) {
try {
os.close();
} catch (IOException e) {
throw new RuntimeException("Unhandled exception " + e.toString());
}
}
}
}
void mhr.appandroid.adapters.AndroidImageFile.writeDocument ( )
inline

Implements mhr.appcore.interfaces.ImageFile.

Definition at line 193 of file AndroidImageFile.java.

{
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = null;
try {
transformer = factory.newTransformer();
} catch (TransformerConfigurationException e) {
throw new RuntimeException("Unhandled exception " + e.toString());
}
Properties outFormat = new Properties();
outFormat.setProperty(OutputKeys.INDENT, "yes");
outFormat.setProperty(OutputKeys.METHOD, "xml");
outFormat.setProperty(OutputKeys.OMIT_XML_DECLARATION, "no");
outFormat.setProperty(OutputKeys.VERSION, "1.0");
outFormat.setProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperties(outFormat);
DOMSource domSource = new DOMSource(doc);
OutputStream output = null;
try {
output = new FileOutputStream(new File(iDir, "image.xml"));
} catch (FileNotFoundException e) {
throw new RuntimeException("Unhandled exception " + e.toString());
}
StreamResult result = new StreamResult(output);
try {
transformer.transform(domSource, result);
output.flush();
} catch (TransformerException e) {
throw new RuntimeException("Unhandled exception " + e.toString());
} catch (IOException e) {
throw new RuntimeException("Unhandled exception " + e.toString());
} finally {
try {
output.close();
} catch (IOException e) {
throw new RuntimeException("Unhandled exception " + e.toString());
}
}
}
void mhr.appandroid.adapters.AndroidImageFile.writeMask ( PDBitmap  mask,
String  fName 
)
inline

Implements mhr.appcore.interfaces.ImageFile.

Definition at line 305 of file AndroidImageFile.java.

{
if (!(mask instanceof APDBitmap)) {
throw new IllegalArgumentException("Wrong bitmap");
}
Bitmap b = ((APDBitmap) mask).getBitmap();
Bitmap tmp = Bitmap.createBitmap(b.getWidth(), b.getHeight(), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(tmp);
Paint p = new Paint();
p.setColor(0xFF000000);
c.drawARGB(0, 0, 0, 0);
c.drawBitmap(b, null, new Rect(0, 0, b.getWidth(), b.getHeight()), p);
writeBitmap(new APDBitmap(tmp), fName);
tmp.recycle();
}

Member Data Documentation

Activity mhr.appandroid.adapters.AndroidImageFile.activity
protected

Definition at line 49 of file AndroidImageFile.java.


The documentation for this class was generated from the following file: