Code Monkey home page Code Monkey logo

treehouse_android_utilities's Introduction

Treehouse Android Utilities

This repository holds helpful utility files for Treehouse Android projects. Included are a couple of helper classes that can be used to work with files in Android, like detecting a shake, resizing images, and converting to byte arrays.

Build a Simple Android App

Download the following file and add it to your project.

  • ShakeDetector.java

ShakeDetector.java

  • Create a ShakeDetector object and implement the onShake() method from the OnShakeListener interface.

Build a Self-Destructing Message Android App

Download the following files and add them to your project.

*This project also requires the Apache IOUtils library. Download the required JAR here. Choose the latest zip file under "Binaries".

  • FileHelper.java
  • ImageResizer.java

FileHelper.java

  • getByteArrayFromFile(Context context, Uri uri): This method converts a file from a URI to a byte array. It accepts regular URIs as well as content URIs.
  • reduceImageForUpload(byte[] imageData): This method is used to reduce a byte array for an image file to a smaller PNG.
  • getFileName(Context context, Uri uri, String fileType): This method creates a file name using file type or the MIME type for both regular URIs and content URIs.

ImageResizer.java

  • resizeImage(byte[] imageData, int targetWidth, int targetHeight): This resizes an image to a specified width and height.
  • resizeImageMaintainAspectRatio(byte[] imageData, int shorterSideTarget): This version resizes an image based on a size for the shorter side of the images (it maintains the aspect ratio).
  • getDimensions(byte[] imageData): This is a helper method to get the dimensions of an image.
  • calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight): This is a helper method to calculate the appropriate sample size to use for resizing an image.

treehouse_android_utilities's People

Contributors

benjakuben avatar

Watchers

James Cloos avatar John Kagga avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.