Showing posts with label Android. Show all posts
Showing posts with label Android. Show all posts

Thursday, January 17, 2013

[Android] slideshow on the main page.




Slideshow on main page. Add all of images into drawable folder. and

int imgid[]={R.drawable.s1,R.drawable.s2,R.drawable.s3,R.drawable.s4};

Make array like this, and copy below code into your activity.

Friday, December 21, 2012

[Android] BestKeeper code block 4

Left block is for initialize x,y value with random number.  When ball collision is happened with goal, then right side methods will be called. This method check how many chance is left, and change the chance score board to red and X mark. If there is no more chance is left, then call game over method.

[Android] BestKeeper code block 3

Left block means when start button is clicked, save all the rankings(name, score), change screen to play mode, change all the value to initial setting. Right side means the keeper collided with ball, then call new ball to the ground, and block score will be increased. And “you got it” sound is also be played.

[Android] BestKeeper code block 2

When game is over, the "GAMEOVER" picture will be shown up on the main screen and then switch the ground screen to the score screen. On the right side blocks is for if any ball reached edges, then recall new ball in the ground.

[Android] BestKeeper code block 1

There are 4 timers, the first timer will be started when the start button is clicked. Clock2 will be started when player got block point 2, and clock3 will be started at block point reach 4. Clock 4 will be started when block point 6. Right side block is for the resetting of the balls' directions.

Monday, June 18, 2012

[Android] Save parameter before quit the activity

Save fontsize before finish current activity and call the value when activity is restarted.

public static final String KEY_MY_PREFERENCE = "my_preference";
int fontsize;
public void onCreate(Bundle savedInstanceState) 
{
     SharedPreferences prefs = getSharedPreferences("fontsize", MODE_PRIVATE);
     fontsize = prefs.getInt(KEY_MY_PREFERENCE, fontsize);
}
protected void onStop() {
     super.onStop();
     SharedPreferences prefs = getSharedPreferences("fontsize", MODE_PRIVATE);
     SharedPreferences.Editor editor = prefs.edit();
     editor.putInt(KEY_MY_PREFERENCE, fontsize);
     editor.commit();
}


Wednesday, June 13, 2012

[Android] Google map with own logo

Show Google map with own logo where you want to mark. Just like this.



Before you start, you should make sure your project is built by google API, not Android.

package Byung_Yong.sample.mapView;

import java.util.List;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.os.Bundle;
import android.util.Log;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class Map extends MapActivity{

 MapView mapview;

 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
  
  mapview = (MapView) findViewById(R.id.mapview);
                mapview.setBuiltInZoomControls(true);
  mapview.setSatellite(false);  
  GeoPoint gpoint = new GeoPoint(12345678,12345678);   
  MapController controller = mapview.getController();  
  controller.animateTo(gpoint);
  controller.setZoom(16); 
  Bitmap image = 
                      BitmapFactory.decodeResource(getResources(), R.drawable.place);
  
  MyOverlay myoverlay = new MyOverlay(image);

  List overlayList = mapview.getOverlays();
  overlayList.add(myoverlay);
  
  }
  @Override
  protected boolean isRouteDisplayed() {
   // TODO Auto-generated method stub
   return false;
  }
 } 
 
 class MyOverlay extends Overlay {
 
  Bitmap bitmap; 
  public MyOverlay(Bitmap bitmap){
  this.bitmap = bitmap;
 }
 
 @Override
 public void draw(Canvas canvas, MapView mapView, boolean shadow) {
  super.draw(canvas, mapView, shadow);
  
  Log.d("BB", "overlay");

  Paint paint1 = new Paint(); 
  Paint paint2 = new Paint();
  paint2.setARGB(255, 0, 0, 0); 
  
  GeoPoint geopoint = new GeoPoint(12345678,12345678);
  Point geopix = new Point();
  Projection project = mapView.getProjection();

  project.toPixels(geopoint, geopix);
  canvas.drawBitmap(bitmap, geopix.x-50, geopix.y, paint1); 
  canvas.drawText("My Church", geopix.x-50, geopix.y+80, paint2);  
 }
}

You can easy to get the location information by searching at Google map.

Press right mouse where you want to mark, and click "What's here".

Then you could see the two 8 digit numbers of coordinate values on search bar or put the mouse on the arrow mark.

Copy the numbers and paste on highlight below.


Manifest will be like this.

Important!!!! Look carefully the highlight part.

You should add "com.google.android.maps" at application and make it "true" just like line 19.



Your Layout can be similar like this.

You should get Google API key by following the direction of below link.

http://mirnauman.wordpress.com/2012/01/26/how-to-get-google-maps-api-key-for-android-issues-and-errors-solved/


Sunday, June 10, 2012

[Android] webView with a table format of HTML




WebView with a table format of HTML.
package ByungYong.library.webView;

import android.app.*;
import android.os.*;
import android.view.*;
import android.webkit.*;
import android.widget.*;

public class WebViewActivity extends Activity {
 WebView mWeb;
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);

  mWeb = (WebView)findViewById(R.id.web);
        mWeb.loadUrl("file:///android_asset/test.html");
        mWeb.getSettings().setJavaScriptEnabled(true);
        mWeb.getSettings().setSaveFormData(true);
        mWeb.getSettings().setBuiltInZoomControls(true);
        mWeb.setWebViewClient(new MyWebClient());
 }

 
 class MyWebClient extends WebViewClient {
  public boolean shouldOverrideUrlLoading(WebView view, String url) {
   view.loadUrl(url);
   return true;
  }
 }
}
layout can be like this.

Add HTML code into assets.

Don't forget add the code below on AndroidManifest.xml


Saturday, June 9, 2012

[Android]Simple scrollView for Image

Quite simple scrollView.

It is useful to show the picture that contains lots of texts.

that will zoom in or out depend on the mobile screen width with keeping ratio of the image file.



Wednesday, June 6, 2012

[Android] pinch zoom event with font size change

Android Java code for the pinch zoom event that makes increase font size.

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.TextView;


public class Introduce extends Activity implements OnTouchListener{
 
 final static float STEP = 200;
 TextView mtxtRatio1,mtxtRatio2,mtxtRatio3,mtxtRatio4;
 float mRatio = 1.0f;
 int mBaseDist;
 float mBaseRatio;
 float fontsize = 13;

 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.introduce);
  
  mtxtRatio1 = (TextView)findViewById(R.id.intro1);
  mtxtRatio1.setTextSize(mRatio+13);  
 }

 public boolean onTouchEvent(MotionEvent event) {
  if (event.getPointerCount() == 2) {
   int action = event.getAction();
   int pureaction = action & MotionEvent.ACTION_MASK;
   if (pureaction == MotionEvent.ACTION_POINTER_DOWN) {
    mBaseDist = getDistance(event);
    mBaseRatio = mRatio;
   } else {
    float delta = (getDistance(event) - mBaseDist) / STEP;
    float multi = (float)Math.pow(2, delta);
    mRatio = Math.min(1024.0f, Math.max(0.1f, mBaseRatio * multi));
    mtxtRatio1.setTextSize(mRatio+13);
   }
  }
  return true; 
 }

 int getDistance(MotionEvent event) {
  int dx = (int)(event.getX(0) - event.getX(1));
  int dy = (int)(event.getY(0) - event.getY(1));
  return (int)(Math.sqrt(dx * dx + dy * dy));
 }

 public boolean onTouch(View v, MotionEvent event) {
  // TODO Auto-generated method stub
  return false;
 }
}

[Android:Xml]Android Layout TableView


This code is for set up the layout of the Android Application.

Two images will be post on the middle of screen in a line.

The size of images should be same, if you want to put it same with the picture below.


package ByungYong.sample.tableView;

import android.app.Activity;
import android.os.Bundle;

public class TableViewActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    }
}