Home | History | Annotate | Download | only in android
      1 /*******************************************************************************
      2  * Copyright 2011 See AUTHORS file.
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *   http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  ******************************************************************************/
     16 
     17 package com.badlogic.gdx.tests.android;
     18 
     19 import javax.microedition.khronos.opengles.GL10;
     20 
     21 import android.content.Intent;
     22 import android.os.Bundle;
     23 import android.util.Log;
     24 import android.view.View;
     25 import android.view.View.OnClickListener;
     26 import android.view.ViewGroup.LayoutParams;
     27 import android.widget.Button;
     28 import android.widget.LinearLayout;
     29 
     30 import com.badlogic.gdx.ApplicationListener;
     31 import com.badlogic.gdx.Gdx;
     32 import com.badlogic.gdx.backends.android.AndroidApplication;
     33 import com.badlogic.gdx.graphics.Color;
     34 
     35 public class WindowedTest extends AndroidApplication implements ApplicationListener {
     36 	Color color = new Color(1, 1, 1, 1);
     37 
     38 	public void onCreate (Bundle bundle) {
     39 		super.onCreate(bundle);
     40 
     41 		Button b1 = new Button(this);
     42 		b1.setText("Change Color");
     43 		b1.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
     44 		Button b2 = new Button(this);
     45 		b2.setText("New Window");
     46 		b2.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
     47 		View view = initializeForView(this);
     48 
     49 		LinearLayout layout = new LinearLayout(this);
     50 		layout.setOrientation(LinearLayout.VERTICAL);
     51 		layout.addView(b1);
     52 		layout.addView(b2);
     53 		layout.addView(view, new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
     54 
     55 		setContentView(layout);
     56 
     57 		b1.setOnClickListener(new OnClickListener() {
     58 
     59 			@Override
     60 			public void onClick (View arg0) {
     61 				color.set((float)Math.random(), (float)Math.random(), (float)Math.random(), 1);
     62 			}
     63 
     64 		});
     65 
     66 		b2.setOnClickListener(new OnClickListener() {
     67 
     68 			@Override
     69 			public void onClick (View v) {
     70 				Intent intent = new Intent(WindowedTest.this, WindowedTest.class);
     71 				WindowedTest.this.startActivity(intent);
     72 			}
     73 		});
     74 	}
     75 
     76 	public void onPause () {
     77 		super.onPause();
     78 	}
     79 
     80 	@Override
     81 	public void onDestroy () {
     82 		super.onDestroy();
     83 		Log.w("WindowedTest", "destroying");
     84 	}
     85 
     86 	@Override
     87 	public void create () {
     88 	}
     89 
     90 	@Override
     91 	public void render () {
     92 		Gdx.gl.glClearColor(color.r, color.g, color.g, color.a);
     93 		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
     94 
     95 	}
     96 
     97 	@Override
     98 	public void dispose () {
     99 	}
    100 
    101 	@Override
    102 	public void pause () {
    103 	}
    104 
    105 	@Override
    106 	public void resume () {
    107 	}
    108 
    109 	@Override
    110 	public void resize (int width, int height) {
    111 	}
    112 }
    113