link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/>

Monday, June 16, 2014

Flashy Complete code

package com.NYSapps.flashy_blog;

import android.app.Activity;
import android.hardware.Camera;
import android.hardware.Camera.Parameters;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ToggleButton;

public class MainActivity extends Activity implements OnClickListener {

 ToggleButton tb;
 public static Camera ourCam = null;
 Parameters p;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.activity_main);

  tb = (ToggleButton) findViewById(R.id.toggleButton1);
  tb.setOnClickListener(this);

  if (ourCam != null) {
   tb.setChecked(true);
  }

 }

 @Override
 public void onClick(View v) {
  // TODO Auto-generated method stub
  if (tb.isChecked()) {
   ourCam = Camera.open();
   p = ourCam.getParameters();
   p.setFlashMode(Parameters.FLASH_MODE_TORCH);
   ourCam.setParameters(p);
   ourCam.startPreview();

  } else {
   ourCam.stopPreview();
   ourCam.release();
  }

 }


}


    
    

    
        
            
            
                

                
            
        
    





    



Flashy the Flash Light: a tutorial to make your own flash light app Day 3

I ended the last tutorial saying that there are a few errors in the code that won't allow it to function properly.  Yea, I know, I'm a jerk.  Deal with it :P

1.  One of the problems mysteriously fixed its self.........  When I wrote the original app I was having a problem with the light going off when the screen was rotated.  This is currently not an issue and I have no idea why... hmmmm.... maybe one of you can help me out?

either way......

2. The other issue is when the back or the home button is pressed.  This causes the program to close but the light stays on.  The problem occurs when you go to turn off the light because the toggle button resets.  The result is a crashhhhh.......

There are 2 methods to fix this problem depending on how you want your flashlight to work.  If you WANT the camera to stay on when the app is closed then all you have to do is check if the light is on. Simple right???  It's actually very very easy.  All you have to do is add an if statement in the onCreate() method.

if (ourCam !=null){
			tb.setChecked(true);
		}

DONE!! simple and clean.


The other option is to turn the light off when you close out of the app.  This is also pretty simple and to do it you'll need to use the onStop() method
protected void onStop() {
		// TODO Auto-generated method stub
		if (tb.isChecked()) {
			tb.setChecked(false);
			ourCam.stopPreview();
			ourCam.release();			
		}
		super.onStop();
	}

Add that to your code and you should be all done!!

Hope you enjoyed!

Sunday, June 15, 2014

Flashy the Flash Light: a tutorial to make your own flash light app Day 2

Hello again!!

First lets quickly recap what we went over on the first day of this tutorial:

  • build an .XML with a toggle button that will be used to turn the LED light of your phone on and off
  • how to modify the Manifest file to get permission to use the camera features of the phone
your layout.xml should look like this:


    


and your manifest file should look like this:


    
    

    
        
            
                

                
            
        
    



Now that that's settled lets get into the JAVA section!! woot woot!
First open the java activity (project>src>com.something...>MainActivity.Java).  When you open the file there should only be about 10 lines of code and we're going to be working the public class first.  It should read "public class MainActivity extends Activity".  After activity type "implements OnClickListener"

This should bring up an error on the 'OnClickListener" hover over it and you should get these options:



Click on the first option import 'OnClickListener' (android.view.View).  Now this should bring up another error over the activity name 'MainActivity'.  Hover over the underlined phrase and click on the first quick fix 'Add unimplemented methods' and this will add an onClick method.

An onClick method is exactly what it sounds like (just like when someone says 'do this on three'). So on a button click it will perform a task.  In our case, this task will be turning on a light.

Now we're going to define the toggle button and the camera.  This is done above the On Create method.  I want you to write "ToggleButton = tb;"  "public static Camera OurCam= null;" and "Parameters p;"

The next step is to connect the toggle button we just defined to the toggle button inside the activity.xml file that was defined earlier.  To do this just type "tb = (ToggleButton) findViewById(R.id.toggleButton1);" "tb.setOnClickListener(this);"

We're finally on the last step of having a functioning LED flashlight!  Inside the onClick method we're going to make an if statement that checks to see if the toggle button is on or off and add the Camera functionality.  The final On Click method will look like this:

@Override
 public void onClick(View v) {
  // TODO Auto-generated method stub
  if (tb.isChecked()) {
   ourCam = Camera.open();
   p = ourCam.getParameters();
   p.setFlashMode(Parameters.FLASH_MODE_TORCH);
   ourCam.setParameters(p);
   ourCam.startPreview();

  } else {
   ourCam.stopPreview();
   ourCam.release();
  }

 }


And that's it!! your LED light should now turn on and off!

There are still a few errors associated with this code, and I'll be going over what they are and how to fix them in the next tutorial!



Wednesday, June 11, 2014

Flashy the Flash Light: a tutorial to make your own flash light app Day 1


Hi Ya'll,
I'm going to be writing this AS i'm developing a very simple flashlight app that will turn on your phones LED so that you can see in the dark..  Are you afraid of the dark???

For this Tutorial, I'm going to assume that you know how to make a new android application.  So make one!! I'm naming mine flashy ;)  The layout will be very very simple because I'm more interested in teach you how to use the LED function

To start off go to your activity layout.  Flashy/res/layout/activity_flashy_main.xml (your's will most likely be something a little bit different.  Maybe even more creative.

First click on the toggle button icon and drag it to the screen. Then on the bottom left click on the activity.xml tab (next to 'Graphical Layout')







All we're going to do for now is change the size of the button so that it'll be easier to click on.  Were the code says (android:layout_width="wrap_content") lets change that to (android:layout_width="100dp").  Do the same thing to the height  (android:layout_height="100dp")

Your code should now look like this:


    




As far as the layout goes, that's pretty much it! Now lets move onto the android manifest file.  The first thing we want to do here is go into the code based tab.


On this page we are going to add 2 things: 1st being the the 'permission' so that we can use the LED feature.  add this code snippet right before '<application'





We're going to wait on the second thing for now so that I can show you exactly why we need to add it!

That's all for tonight ladies and gents.  I'll finish this tutorial up shortly, but in the mean time check out some of my apps :)       http://androiddabble.blogspot.com/2014/06/my-apps.html 

Tuesday, June 3, 2014

My Apps

Hey All!  Since you're on this page I'm assuming that you wanted to see what apps I have out on the market. So here they are!

https://play.google.com/store/search?q=pub%3ANYSapps


White Noise -Relaxation:
https://play.google.com/store/apps/details?id=com.whitenoisesupreme

Tip Master:
https://play.google.com/store/apps/details?id=com.tipmaster

Counter:
https://play.google.com/store/apps/details?id=com.Converter2

Tap Count:
https://play.google.com/store/apps/details?id=com.Converter

Flashy the FlashLight:
https://play.google.com/store/apps/details?id=com.NYSapps.flashy

Soothing Bird Songs:
https://play.google.com/store/apps/details?id=com.NYSapps.SongBirds_Relaxation

Soothing Frog Chorus:
https://play.google.com/store/apps/details?id=com.NYSapps.FrogChorus

Flowing Water:
https://play.google.com/store/apps/details?id=com.NYSapps.RunningWater

Dot Drop
https://play.google.com/store/apps/details?id=com.NYSapps.dotcollector


I'm hoping to have ten new apps by the end of the year!  Check back frequently and let me know what you think!!!

Let's try this again

Hi All!!
Yea it's been a while since I wrote my last (and first) post on here.  That was way back in my first semester senior year at Uconn.  I wrote something about doing all my hobbies and well... yep.. that obviously never happened.  I'm now mostly concentrating on my career and learning some basics in Android development.

If you're interested in learning about Android development I would HIGHLY recommend watching videos from http://thenewboston.org/tutorials.php

I'm on 35ish video now and have learned a ton of little hints and tricks that will make my life easier as I continue to try and develop some apps.

Also, before I hit the hay for the night, I figure I can give you a heads up of what I plan on posting to this blog.  I'm planning on adding some information on this site to help new developers get a had start.

Please check out my apps on the Android market and rate them ;)