Friday, March 29, 2013

Android 2.0-Tutorial 26

CLASS

Mainactivity.java
*****************************************************************
package com.nanolaser;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
   
}
*********************************************************************
Menu.java
***********************************************************************
package com.nanolaser;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Menu extends ListActivity{
 String classes[]={"MainActivity","TextPlay","Email","Camera"
   ,"Data","example5","example6"};

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setListAdapter(new ArrayAdapter<String>(Menu.this, android.R.layout.simple_list_item_1, classes));
 }
 @Override
 protected void onListItemClick(ListView l, View v, int position, long id) {
  // TODO Auto-generated method stub
  super.onListItemClick(l, v, position, id);
  String cheese=classes[position];
  try{
  Class ourClass=Class.forName("com.nanolaser."+cheese);
  Intent ourIntent=new Intent(Menu.this, ourClass);
  startActivity(ourIntent);
  }catch(ClassNotFoundException e){
   e.printStackTrace();
   }
 }


}

************************************************************************
Splash.java
************************************************************************
package com.nanolaser;
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
public class Splash extends Activity{
     MediaPlayer ourSong;
 @Override
 protected void onCreate(Bundle TravisLoveBacon) {
  // TODO Auto-generated method stub
  super.onCreate(TravisLoveBacon);
  setContentView(R.layout.splash);
  ourSong=MediaPlayer.create(Splash.this, R.raw.music);
  ourSong.start();
  Thread timer=new Thread(){
   public void run(){
    try{
     sleep(5000);

    }catch(InterruptedException e){
     e.printStackTrace();
    }finally{
     Intent openStartingPoint=new Intent("com.nanolaser.MENU");
     startActivity(openStartingPoint);

    }

   }
  };
  timer.start();
 }
 @Override
 protected void onPause() {
  // TODO Auto-generated method stub
  super.onPause();
  ourSong.release();
  finish();
 }
   
}
*************************************************************************
TextPlay.java
*************************************************************************
package com.nanolaser;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.ToggleButton;
public class TextPlay extends Activity{
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.text);
  Button chkCmd=(Button)findViewById(R.id.bResults);
  ToggleButton passTog=(ToggleButton)findViewById(R.id.tbPassword);
     EditText input=(EditText)findViewById(R.id.etCommands);
     TextView display=(TextView)findViewById(R.id.tvResults);

 }
}
************************************************************************
Email.java
************************************************************************
package com.nanolaser;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class Email extends Activity implements View.OnClickListener {
 EditText personsEmail, intro, personsName, stupidThings, hatefulAction,
   outro;
 String emailAdd, beginning, name, stupidAction, hatefulAct, out;
 Button sendEmail;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.email);
  initializeVars();
  sendEmail.setOnClickListener(this);
 }
 private void initializeVars() {
  // TODO Auto-generated method stub
  personsEmail = (EditText) findViewById(R.id.etEmails);
  intro = (EditText) findViewById(R.id.etIntro);
  personsName = (EditText) findViewById(R.id.etName);
  stupidThings = (EditText) findViewById(R.id.etThings);
  hatefulAction = (EditText) findViewById(R.id.etAction);
  outro = (EditText) findViewById(R.id.etOutro);
  sendEmail = (Button) findViewById(R.id.bSentEmail);
 }
 public void onClick(View v) {
  // TODO Auto-generated method stub
  convertEditTextVarsIntoStringsAndYesThisIsAMethodWeCreated();
  String emailaddress[] = { emailAdd };
  String message = "Well hello "
    + name
    + " I just wanted to say "
    + beginning
    + ".  Not only that but I hate when you "
    + stupidAction
    + ", that just really makes me crazy.  I just want to make you "
    + hatefulAct
    + ".  Welp, thats all I wanted to chit-chatter about, oh and"
    + out
    + ".  Oh also if you get bored you should check out www.mybringback.com"
    + '\n' + "PS. I think I love you...   :( ";
        Intent emailIntent=new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailaddress);
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "I hate you");
        emailIntent.setType("plain/text");
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
     startActivity(emailIntent);
 }
 private void convertEditTextVarsIntoStringsAndYesThisIsAMethodWeCreated() {
  // TODO Auto-generated method stub
  emailAdd = personsEmail.getText().toString();
  beginning = intro.getText().toString();
  name = personsName.getText().toString();
  stupidAction = stupidThings.getText().toString();
  hatefulAct = hatefulAction.getText().toString();
  out = outro.getText().toString();
 }
 @Override
 protected void onPause() {
  // TODO Auto-generated method stub
  super.onPause();
  finish();
 }
}
******************************************************************************
Data.java
******************************************************************************
package com.nanolaser;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Data extends Activity implements OnClickListener{
 Button start,startFor;
 EditText sendET;
 TextView gotAnswer;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.get);
  initialize();
 }
 private void initialize() {
  // TODO Auto-generated method stub
  start=(Button)findViewById(R.id.bSA);
  startFor=(Button)findViewById(R.id.bSAFR);
  sendET=(EditText)findViewById(R.id.etSend);
  gotAnswer=(TextView)findViewById(R.id.tvGot);
  start.setOnClickListener(this);
  startFor.setOnClickListener(this);

 }
 @Override
 public void onClick(View arg0) {
  // TODO Auto-generated method stub
  switch (arg0.getId()){
  case R.id.bSA:
   String bread=sendET.getText().toString();
   Bundle basket=new Bundle();
   basket.putString("key", bread);
   Intent a=new Intent(Data.this,OpenedClass.class);
   a.putExtras(basket);
   startActivity(a);
   break;
  case R.id.bSAFR:

   break;


  }

 }

}
*******************************************************************************
OpenedClass
*******************************************************************************
package com.nanolaser;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TextView;
public class OpenedClass extends Activity implements OnClickListener, OnCheckedChangeListener{
 TextView question,test;
 Button returnData;
 RadioGroup selectionList;
 String gotBread;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.send);
  initialize();
  Bundle gotBasket=getIntent().getExtras();
  gotBread=gotBasket.getString("key");
  question.setText(gotBread);

 }
 private void initialize() {
  // TODO Auto-generated method stub
  question=(TextView)findViewById(R.id.tvQuestion);
  test=(TextView)findViewById(R.id.tvText);
  returnData=(Button)findViewById(R.id.bReturn);
  returnData.setOnClickListener(this);
  selectionList=(RadioGroup)findViewById(R.id.rgAnswers);
  selectionList.setOnCheckedChangeListener(this);
 }
 @Override
 public void onClick(View v) {
  // TODO Auto-generated method stub

 }
 @Override
 public void onCheckedChanged(RadioGroup arg0, int arg1) {
  // TODO Auto-generated method stub
  switch(arg1){
  case R.id.rCrazy:
   break;
  case R.id.rSexy:
   break;
  case R.id.rBoth:
   break;
  }
 }



}
******************************************************************************
AboutUs.jave
******************************************************************************
package com.nanolaser;
import android.app.Activity;
import android.os.Bundle;
public class AboutUs extends Activity {
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.about);
 }



}

******************************************************************************
Camera.java
******************************************************************************
package com.nanolaser;
import java.io.IOException;
import java.io.InputStream;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
public class Camera extends Activity implements View.OnClickListener{
 ImageButton ib;
 Button b;
 ImageView iv;
 Intent i;
 final static int cameraData=0;
 Bitmap bmp;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.photo);
  initialize();
  InputStream is=getResources().openRawResource(R.drawable.ic_launcher);
     bmp=BitmapFactory.decodeStream(is);
 }
 private void initialize(){
  //TODO auto-generated method stub
  iv=(ImageView)findViewById(R.id.ivReturnedPic);
  ib=(ImageButton)findViewById(R.id.ibTakepic);
  b=(Button)findViewById(R.id.bSerWall);
  b.setOnClickListener(this);
  ib.setOnClickListener(this);
 }
 @Override
 public void onClick(View v) {
  // TODO Auto-generated method stub
  switch(v.getId()){
   case R.id.bSerWall:
   try {
    getApplicationContext().setWallpaper(bmp);
   } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }
   break;
   case R.id.ibTakepic:
    i=new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(i,cameraData);
   break;

  }

 }
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  // TODO Auto-generated method stub
  super.onActivityResult(requestCode, resultCode, data);
  if (resultCode==RESULT_OK){
   Bundle extras=data.getExtras();
   bmp=(Bitmap)extras.get("data");
   iv.setImageBitmap(bmp);
  }
 }

}
******************************************************************************
Data.java
******************************************************************************
package com.nanolaser;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class Data extends Activity implements OnClickListener{
 Button start,startFor;
 EditText sendET;
 TextView gotAnswer;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.get);
  initialize();
 }
 private void initialize() {
  // TODO Auto-generated method stub
  start=(Button)findViewById(R.id.bSA);
  startFor=(Button)findViewById(R.id.bSAFR);
  sendET=(EditText)findViewById(R.id.etSend);
  gotAnswer=(TextView)findViewById(R.id.tvGot);
  start.setOnClickListener(this);
  startFor.setOnClickListener(this);

 }
 @Override
 public void onClick(View arg0) {
  // TODO Auto-generated method stub
  switch (arg0.getId()){
  case R.id.bSA:
   String bread=sendET.getText().toString();
   Bundle basket=new Bundle();
   basket.putString("key", bread);
   Intent a=new Intent(Data.this,OpenedClass.class);
   a.putExtras(basket);
   startActivity(a);
   break;
  case R.id.bSAFR:
   Intent i=new Intent(Data.this,OpenedClass.class);
   startActivityForResult(i,0);
   break;

  }

 }
 @Override
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {
  // TODO Auto-generated method stub
  super.onActivityResult(requestCode, resultCode, data);
  if(resultCode==RESULT_OK){
   Bundle basket=data.getExtras();
   String s=basket.getString("answer");
   gotAnswer.setText(s);
  }
 }


}

******************************************************************************
SharedPrefs.java
******************************************************************************
package com.nanolaser;
import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class SharedPrefs extends Activity implements OnClickListener{
   EditText sharedData;
   TextView dataResults;
   public static String filename="MySharedString";
   SharedPreferences someData;
@Override
protected void onCreate(Bundle savedInstanceState) {
 // TODO Auto-generated method stub
 super.onCreate(savedInstanceState);
 setContentView(R.layout.sharedpreferences);
 setupVariables();
 someData=getSharedPreferences(filename,0);
}
private void setupVariables() {
 // TODO Auto-generated method stub
 Button save=(Button)findViewById(R.id.bSave);
 Button load=(Button)findViewById(R.id.bLoad);
 sharedData=(EditText)findViewById(R.id.etSharedPrefs);
 dataResults=(TextView)findViewById(R.id.tvLoadSharedPrefs);
 save.setOnClickListener(this);
 load.setOnClickListener(this);

}
@Override
public void onClick(View v) {
 // TODO Auto-generated method stub
 switch (v.getId()){
 case R.id.bSave:
  String stringData=sharedData.getText().toString();
  SharedPreferences.Editor editor=someData.edit();
  editor.putString("sharedString", stringData);
  editor.commit();
  break;
 case R.id.bLoad:
  someData=getSharedPreferences(filename,0);
  String dataReturned=someData.getString("sharedString", "cannot load data");
  dataResults.setText(dataReturned);
  break;

 }
}

}
******************************************************************************
InternalData.java
******************************************************************************
package com.nanolaser;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class InternalData extends Activity implements OnClickListener{
    EditText sharedData;
    TextView dataResults;
    FileOutputStream fos;
    String FILENAME="InteralString";
   
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.sharedpreferences);
  setupVariables();
 }
 private void setupVariables() {
  // TODO Auto-generated method stub
  Button save=(Button)findViewById(R.id.bSave);
  Button load=(Button)findViewById(R.id.bLoad);
  sharedData=(EditText)findViewById(R.id.etSharedPrefs);
  dataResults=(TextView)findViewById(R.id.tvLoadSharedPrefs);
  save.setOnClickListener(this);
  load.setOnClickListener(this);
  try {
   fos=openFileOutput(FILENAME,Context.MODE_PRIVATE);
   fos.close();
  } catch (FileNotFoundException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
 @Override
 public void onClick(View v) {
  // TODO Auto-generated method stub
  switch (v.getId()){
  case R.id.bSave:
   String data=sharedData.getText().toString();
   //Saving data via File
   /*File f=new File(FILENAME);
   try {
    fos=new FileOutputStream(f);
    fos.close();
   } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }*/
   try {
   fos=openFileOutput(FILENAME, Context.MODE_PRIVATE);
   fos.write(data.getBytes());
   fos.close();
   } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }

   break;
  case R.id.bLoad:
   String collected=null;
   FileInputStream fis=null;
   try {
     fis=openFileInput(FILENAME);
    byte[] dataArray=new byte[fis.available()];
    while (fis.read(dataArray)!=-1){
     collected=new String(dataArray);
    }
   } catch (FileNotFoundException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   } catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
   }finally{
    try {
     fis.close();
     dataResults.setText(collected);
    } catch (IOException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
    }
   }

   break;

  }
 }

}
******************************************************************************
Flipper.java
******************************************************************************
package com.nanolaser;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ViewFlipper;
public class Flipper extends Activity implements OnClickListener {
 ViewFlipper flippy;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.flipper);
  flippy=(ViewFlipper)findViewById(R.id.viewFlipper1);
  flippy.setOnClickListener(this);
  flippy.setFlipInterval(500);
  flippy.startFlipping();
 }
 @Override
 public void onClick(View arg0) {
  // TODO Auto-generated method stub
  flippy.showNext();
 }


}
******************************************************************************
GFX.java
******************************************************************************
package com.nanolaser;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.PowerManager;
import android.os.PowerManager.WakeLock;
public class GFX extends Activity{

 MyBringBack ourView;
 WakeLock wL;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
 
  //wake-lock
  PowerManager pM=(PowerManager)getSystemService(Context.POWER_SERVICE);
  wL=pM.newWakeLock(PowerManager.FULL_WAKE_LOCK, "whatever");
 
  super.onCreate(savedInstanceState);
  wL.acquire();
  ourView=new MyBringBack(this);
  setContentView(ourView);
 }
 @Override
 protected void onPause() {
  // TODO Auto-generated method stub
  super.onPause();
  wL.release();
 }

}
******************************************************************************
GFXSurface.java
******************************************************************************
package com.nanolaser;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnTouchListener;
public class GFXSurface extends Activity implements OnTouchListener{
    MyBringBackSurface ourSurfaceView;
 float x,y, sX, sY, fX, fY,dX,dY,aniX,aniY,scaledX,scaledY;
 Bitmap test, plus;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  ourSurfaceView=new MyBringBackSurface(this);
  ourSurfaceView.setOnTouchListener(this);
  x=0;
  y=0;
  sX=0;
  sY=0;
  fX=0;
  fY=0;
  dX=dY=aniX=aniY=scaledX=scaledY=0;
  test=BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
  plus=BitmapFactory.decodeResource(getResources(), R.drawable.plus);
  setContentView(ourSurfaceView);
 }

 @Override
 protected void onPause() {
  // TODO Auto-generated method stub
  super.onPause();
  ourSurfaceView.pause();
 }

 @Override
 protected void onResume() {
  // TODO Auto-generated method stub
  super.onResume();
  ourSurfaceView.resume();
 }

 @Override
 public boolean onTouch(View v, MotionEvent event) {
  // TODO Auto-generated method stub
  try {
   Thread.sleep(50);
  } catch (InterruptedException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 
  x=event.getX();
  y=event.getY();
  switch(event.getAction()){
  case MotionEvent.ACTION_DOWN:
   sX=event.getX();
   sY=event.getY();
   dX=dY=aniX=aniY=scaledX=scaledY=fX=fY=0;
   break;
  case MotionEvent.ACTION_UP:
   fX=event.getX();
   fY=event.getY();
   dX=fX-sX;
   dY=fY-sY;
   scaledX=dX/30;
   scaledY=dY/30;
   x=y=0;
   break;
  }
  return true;
 }

 public class MyBringBackSurface extends SurfaceView implements Runnable{
     SurfaceHolder ourHolder;
     Thread ourThread=null;
     boolean isRunning=false;
  public MyBringBackSurface(Context context) {
   // TODO Auto-generated constructor stub
   super(context);
   ourHolder=getHolder();
  
  }
 
     public void pause(){
     isRunning=false;
     while(true){
      try{
      ourThread.join();
      }catch(InterruptedException e){
       e.printStackTrace();
      }
        
      break;
    
     }
     ourThread=null;
     }
     public void resume(){
     isRunning=true;
     ourThread=new Thread(this);
  ourThread.start();
    
     }
  @Override
  public void run() {
   // TODO Auto-generated method stub
   while(isRunning){
    if(!ourHolder.getSurface().isValid())
     continue;
    Canvas canvas=ourHolder.lockCanvas();
    canvas.drawRGB(02, 02, 150);
    if(x!=0 && y!=0){
     canvas.drawBitmap(test, x-(test.getWidth()/2), y-(test.getHeight()/2), null);
    }
    if(sX!=0 && sY!=0){
     canvas.drawBitmap(plus, sX-(plus.getWidth()/2), sY-(plus.getHeight()/2), null);
    }
    if(fX!=0 && fY!=0){
     canvas.drawBitmap(test, fX-(test.getWidth()/2)-aniX, fY-(test.getHeight()/2)-aniY, null);
     canvas.drawBitmap(plus, fX-(plus.getWidth()/2), fY-(plus.getHeight()/2), null);
    }
    aniX=aniX+scaledX;
    aniY=aniY+scaledY;
    ourHolder.unlockCanvasAndPost(canvas);
   
   }
  }
 }

}
******************************************************************************
MyBringBack.java
******************************************************************************
package com.nanolaser;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.view.View;
public class MyBringBack extends View{
    Bitmap gBall;
    float changingY;
    Typeface font;
 public MyBringBack(Context context) {
  super(context);
  // TODO Auto-generated constructor stub
  gBall=BitmapFactory.decodeResource(getResources(), R.drawable.plus);
     changingY=0;
     font=Typeface.createFromAsset(context.getAssets(), "G-Unit.ttf");
 }
 @Override
 protected void onDraw(Canvas canvas) {
  // TODO Auto-generated method stub
  super.onDraw(canvas);
  canvas.drawColor(Color.WHITE);
  Paint textPaint=new Paint();
  textPaint.setARGB(50, 254, 10, 50);
  textPaint.setTextAlign(Align.CENTER);
  textPaint.setTextSize(50);
  textPaint.setTypeface(font);
  canvas.drawText("mybringback", getWidth()/2, 200, textPaint);
  canvas.drawBitmap(gBall, (canvas.getWidth()/2),changingY, null);
     if(changingY<canvas.getHeight()){
      changingY+=10;
         
     }else{
      changingY=0;
     }
     Rect middleRect=new Rect();
     middleRect.set(0, 400, canvas.getWidth(), 550);
     Paint ourBlue=new Paint();
     ourBlue.setColor(Color.BLUE);
     canvas.drawRect(middleRect, ourBlue);
     invalidate();
 }
   
}

******************************************************************************
ourViewClient.java
******************************************************************************
package com.nanolaser;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class ourViewClient extends WebViewClient {
 @Override
 public boolean shouldOverrideUrlLoading(WebView v,String url){
  v.loadUrl(url);
  return true;
 
 }
}
******************************************************************************
Prefs.java
******************************************************************************
package com.nanolaser;
import android.R;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.support.v4.app.FragmentTransaction;
import android.support.v4.app.Fragment;

public class Prefs extends PreferenceActivity{


 @Override
 protected void onCreate(Bundle savedInstanceState) {
 
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
     
  addPreferencesFromResource(com.nanolaser.R.xml.prefs);
 }
}
******************************************************************************
SimpleBrowser.java
******************************************************************************
package com.nanolaser;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.InputMethodManager;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
public class SimpleBrowser extends Activity implements OnClickListener{
 EditText url;
 WebView ourBrow;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.simplebrowser);
  ourBrow=(WebView)findViewById(R.id.wvBrowser);
  ourBrow.getSettings().setJavaScriptEnabled(true);
  ourBrow.getSettings().setLoadsImagesAutomatically(true);
  ourBrow.getSettings().setUseWideViewPort(true);
  ourBrow.setWebViewClient(new ourViewClient());
  try{
  ourBrow.loadUrl("http://www.cnn.com");
  }catch(Exception e){
   e.printStackTrace();
  }
 
  Button go=(Button)findViewById(R.id.bGo);
  Button back=(Button)findViewById(R.id.bBack);
  Button refresh=(Button)findViewById(R.id.bRefresh);
  Button forward=(Button)findViewById(R.id.bForward);
  Button clearHistory=(Button)findViewById(R.id.bHistory);
  url=(EditText)findViewById(R.id.etURL);
  go.setOnClickListener(this);
  back.setOnClickListener(this);
  refresh.setOnClickListener(this);
  forward.setOnClickListener(this);
  clearHistory.setOnClickListener(this);
 
 }
 @Override
 public void onClick(View v) {
  // TODO Auto-generated method stub
  switch(v.getId()){
  case R.id.bGo:
  String theWebsite=url.getText().toString();
  ourBrow.loadUrl(theWebsite);
  InputMethodManager imm=(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
  imm.hideSoftInputFromWindow(url.getWindowToken(), 0);
  break;
  case R.id.bBack:
  if(ourBrow.canGoBack())
  ourBrow.goBack();
  break;
  case R.id.bForward:
  if(ourBrow.canGoForward())
  ourBrow.goBack();
  break;
  case R.id.bRefresh:
  ourBrow.reload();
  break;
  case R.id.bHistory:
  ourBrow.clearHistory();
  break;
 
  }
 
 }

}
******************************************************************************
Slider.java
******************************************************************************
package com.nanolaser;
import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.SlidingDrawer;
import android.widget.SlidingDrawer.OnDrawerOpenListener;
public class Slider extends Activity implements OnDrawerOpenListener, OnClickListener, OnCheckedChangeListener{
 SlidingDrawer sd;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.sliding);
  Button handle1=(Button)findViewById(R.id.handle1);
  Button handle2=(Button)findViewById(R.id.handle2);
  Button handle3=(Button)findViewById(R.id.handle3);
  Button handle4=(Button)findViewById(R.id.handle4);
  CheckBox checkbox=(CheckBox)findViewById(R.id.cbSlidable);
  checkbox.setOnCheckedChangeListener(this);
  sd=(SlidingDrawer)findViewById(R.id.slidingD);
  sd.setOnDrawerOpenListener(this);
  handle1.setOnClickListener(this);
  handle2.setOnClickListener(this);
  handle3.setOnClickListener(this);
  handle4.setOnClickListener(this);
 }
 public void onClick(View arg0){
  switch(arg0.getId()){
  case R.id.handle1:
  sd.open();
  break;
  case R.id.handle2:
 
  break;
  case R.id.handle3:
  sd.toggle();
  break;
  case R.id.handle4:
  sd.close();
  break;
 
  }
 
 }
 public void onCheckedChanged(CompoundButton arg0, boolean arg1)
 {
 if(arg0.isChecked()){
  sd.lock();
 }else{
  sd.unlock();
 
 }
 
 }
 @Override
 public void onDrawerOpened() {
  // TODO Auto-generated method stub
  MediaPlayer mp=MediaPlayer.create(this, R.raw.music);
  mp.start();
 }
}
******************************************************************************
SoundStuff.java
******************************************************************************
package com.nanolaser;
import android.app.Activity;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.media.SoundPool;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
public class SoundStuff extends Activity implements OnClickListener, OnLongClickListener {
 SoundPool sp;
 int explosion=0;
 MediaPlayer mp;

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  View v=new View(this);
  v.setOnClickListener(this);
  v.setOnLongClickListener(this);
  setContentView(v);
  sp=new SoundPool(5,AudioManager.STREAM_MUSIC,0);
  explosion=sp.load(this, R.raw.music, 1);
  mp=MediaPlayer.create(this, R.raw.music);
 }
 @Override
 public void onClick(View arg0) {
  // TODO Auto-generated method stub
  if(explosion!=0)
  sp.play(explosion, 1, 1, 0, 0, 1);
 }
 @Override
 public boolean onLongClick(View arg0) {
  // TODO Auto-generated method stub
  mp.start();
  return false;
 }
 }
******************************************************************************
Tabs.java
******************************************************************************
package com.nanolaser;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;
import android.widget.TextView;
public class Tabs extends Activity implements OnClickListener {
 TabHost th;
 TextView showResults;
 long start, stop;
 @Override
 protected void onCreate(Bundle savedInstanceState) {
  // TODO Auto-generated method stub
  super.onCreate(savedInstanceState);
  setContentView(R.layout.tabs);
  th=(TabHost)findViewById(R.id.tabhost);
  Button newTab=(Button)findViewById(R.id.bAddTab);
  Button bStart=(Button)findViewById(R.id.bStartWatch);
  Button bStop=(Button)findViewById(R.id.bStopWatch);
  showResults=(TextView)findViewById(R.id.tvShowResults);
  bStart.setOnClickListener(this);
  bStop.setOnClickListener(this);
 
 
  newTab.setOnClickListener(this);
  th.setup();
  TabSpec specs=th.newTabSpec("tag1");
  specs.setContent(R.id.tab1);
  specs.setIndicator("StopWatch");
  th.addTab(specs);
  specs=th.newTabSpec("tag2");
  specs.setContent(R.id.tab2);
  specs.setIndicator("Tab 2");
  th.addTab(specs);
  specs=th.newTabSpec("tag3");
  specs.setContent(R.id.tab3);
  specs.setIndicator("Add a Tab");
  th.addTab(specs);
  start=0;
 
 }
 @Override
 public void onClick(View arg0) {
  // TODO Auto-generated method stub
  switch(arg0.getId()){
  case R.id.bAddTab:
   TabSpec ourSpec=th.newTabSpec("tag1");
   ourSpec.setContent(new TabHost.TabContentFactory() {
   
    @Override
    public View createTabContent(String tag) {
     // TODO Auto-generated method stub
     TextView text=new TextView(Tabs.this);
     text.setText("You've created a new Tab!");
     return null;
    }
   });
   ourSpec.setIndicator("New");
   th.addTab(ourSpec);
   break;
  case R.id.bStartWatch:
   start=System.currentTimeMillis();
   break;
  case R.id.bStopWatch:
   stop=System.currentTimeMillis();
   if(start!=0){
    long result=stop-start;
    int millis=(int) result;
    int seconds=(int) result/1000;
    int minutes=seconds/60;
    millis=millis%100;
    seconds=seconds%60;
    showResults.setText(String.format("%d:%02d:%02d", minutes, seconds, millis));
   
   }
   break;
 
  }
 }
 }
******************************************************************************


LAYOUT

activity_main.xml
************************************************************************
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />
</RelativeLayout>
*****************************************************************************
splash.xml
*****************************************************************************
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="@drawable/splash_background"
   
    >
   
</LinearLayout>
*****************************************************************************
text.xml
*****************************************************************************
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:padding="25dp"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <EditText
      android:layout_width="fill_parent" android:layout_height="wrap_content"
      android:id="@+id/etCommands"  android:hint="Type a Command"
      android:password="true"
        />
    <LinearLayout
        android:weightSum="100"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
    <Button
        android:layout_weight="20"
        android:id="@+id/bResults"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Try Command" />
    <ToggleButton
        android:layout_weight="80"
        android:paddingBottom="8dp"
        android:checked="true"
        android:id="@+id/tbPassword"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="ToggleButton" />
    </LinearLayout>
    <TextView
        android:id="@+id/tvResults"
        android:gravity="center"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="invalid" />
</LinearLayout>
**********************************************************************************
email.xml
**********************************************************************************
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:orientation="vertical" android:layout_width="match_parent"
 android:weightSum="100" android:layout_height="match_parent">
 <ScrollView android:layout_weight="30" android:layout_width="fill_parent"
  android:layout_height="fill_parent">
  <LinearLayout android:orientation="vertical"
   android:layout_width="match_parent" android:layout_height="match_parent">
   <TextView android:text="Email address(es):"
    android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
   <EditText android:layout_height="wrap_content"
    android:layout_width="match_parent" android:id="@+id/etEmails">
   </EditText>
   <TextView android:text="Hateful Intro:"
    android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
   <EditText android:layout_height="wrap_content"
    android:layout_width="match_parent" android:id="@+id/etIntro"></EditText>
   <TextView android:text="Person's name" android:layout_width="wrap_content"
    android:layout_height="wrap_content"></TextView>
   <EditText android:layout_height="wrap_content"
    android:layout_width="match_parent" android:id="@+id/etName"></EditText>
   <TextView android:text="Stupid Things that this Person does"
    android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
   <EditText android:layout_height="wrap_content"
    android:layout_width="match_parent" android:id="@+id/etThings"></EditText>
   <TextView android:text="What you want to do to this person:"
    android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
   <EditText android:layout_height="wrap_content"
    android:layout_width="match_parent" android:id="@+id/etAction"></EditText>
   <TextView android:text="Hateful Outro" android:layout_width="wrap_content"
    android:layout_height="wrap_content"></TextView>
   <EditText android:layout_height="wrap_content"
    android:layout_width="match_parent" android:id="@+id/etOutro"></EditText>
  </LinearLayout>
 </ScrollView>
 <LinearLayout android:orientation="vertical"
  android:layout_width="match_parent" android:layout_weight="40"
  android:layout_height="fill_parent">
  <Button android:text="Send Email" android:id="@+id/bSentEmail"
   android:layout_width="fill_parent" android:layout_height="fill_parent"></Button>
 </LinearLayout>
 <LinearLayout android:orientation="vertical"
  android:layout_width="match_parent" android:layout_weight="30"
  android:layout_height="fill_parent">
  <AnalogClock android:id="@+id/analogClock1"
   android:layout_width="fill_parent" android:layout_height="fill_parent"></AnalogClock>
 </LinearLayout>
</LinearLayout>
*****************************************************************************
get.xml
*****************************************************************************
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
     >
    <EditText
        android:id="@+id/etSend"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:ems="10" >
      
    </EditText>
    <Button
        android:layout_below="@id/etSend"
        android:layout_alignParentRight="true"
        android:id="@+id/bSA"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="StartActivity" />
    <Button
        android:layout_toLeftOf="@id/bSA"
        android:layout_alignTop="@id/bSA"
        android:id="@+id/bSAFR"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="StartActivityForResult" />
    <TextView
        android:layout_below="@id/bSAFR"
        android:id="@+id/tvGot"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />
</RelativeLayout>
*****************************************************************************
photo.xml
*****************************************************************************
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <ImageView
        android:id="@+id/ivReturnedPic"
        android:layout_gravity="center"
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:src="@drawable/ic_launcher" />
    <ImageButton
        android:id="@+id/ibTakepic"
        android:layout_width="125dp"
        android:layout_gravity="center"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_launcher" />
    <Button
        android:id="@+id/bSerWall"
        android:layout_width="125dp"
        android:layout_gravity="center"
        android:layout_height="wrap_content"
        android:text="Set Wallpaper" />
</LinearLayout>
*******************************************************************************
send.xml
*******************************************************************************
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <TextView
        android:id="@+id/tvQuestion"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Leize is..." />
    <RadioGroup
        android:id="@+id/rgAnswers"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >
        <RadioButton
            android:id="@+id/rCrazy"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:checked="true"
            android:text="Crazy" />
        <RadioButton
            android:id="@+id/rSexy"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="SUPER SEXY" />
        <RadioButton
            android:id="@+id/rBoth"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Both" />
    </RadioGroup>
    <Button
        android:id="@+id/bReturn"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Return" />
    <TextView
        android:id="@+id/tvText"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="TextView" />
</LinearLayout>
****************************************************************************
AndroidManifest.xml
**********************************************************************************
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.nanolaser"
    android:versionCode="1"
    android:versionName="1.0" >
    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="8" />
    <uses-permission android:name="android.permission.SET_WALLPAPER"/>
    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".Splash"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
                <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.nanolaser.MAINACTIVITY" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
                   <activity
            android:name=".Menu"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.nanolaser.MENU" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
                    <activity
            android:name=".TextPlay"
            android:label="@string/app_name" >
          
        </activity>
                 <activity
            android:name=".Email"
            android:label="@string/app_name" >
          
        </activity>
    
                 <activity
            android:name=".Camera"
            android:label="Camera Application"
            android:screenOrientation="portrait">
           
        </activity>
        
    
                 <activity
            android:name=".OpenedClass"
            android:label="OpenedClass"
            android:screenOrientation="portrait">
           
        </activity>
                         <activity
            android:name=".Data"
            android:label="Data"
            android:screenOrientation="portrait">
           
        </activity>
    </application>
</manifest>

No comments:

Post a Comment