Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wertalp/51a099f1607a6e1886f1 to your computer and use it in GitHub Desktop.
Save wertalp/51a099f1607a6e1886f1 to your computer and use it in GitHub Desktop.
main
package com.example.wertalp.sensortester;
import android.content.Context;
import android.widget.Button;
import android.widget.Toast;
/**
* Created by wertalp on 28.08.15.
*/
public class CellButton extends Button{
int xField ;
int yField ;
Context ctx;
public CellButton(Context context) {
super(context);
this.ctx = context;
}
public int getxField() {
return xField;
}
public void setxField(int xField) {
this.xField = xField;
}
public int getyField() {
return yField;
}
public void setyField(int yField) {
this.yField = yField;
}
public String getPositionText(){
return "Position X/Y"+getxField()+":"+getyField();
};
}
package com.example.wertalp.sensortester;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridLayout;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.Toast;
import com.example.wertalp.sensortester.CellButton;
import java.util.ArrayList;
/**
* Created by wertalp on 26.08.15.
*/
public class ChessBoard {
int heigth ;
int width ;
Activity activity ;
GridLayout board ;
Display display;
int laenge ;
int breite ;
LayoutInflater inflater;
PopupWindow pw;
static int i=0;
Ship[] ships = new Ship[50];
Button Butty;
CellButton[] liCellBut;
public ChessBoard(Activity activity) {
this.activity = activity;
this.display = activity.getWindowManager().getDefaultDisplay();
this.heigth = display.getHeight();
this.width = display.getWidth() ;
}
public int getHeigth() {
return heigth;
}
public void setHeigth(int heigth) {
this.heigth = heigth;
}
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public void create() {
int width = display.getWidth();
int height =display.getHeight();
board = (GridLayout) activity.findViewById(R.id.board);
board.removeAllViews();
Button buttonSet = (Button) activity.findViewById(R.id.button23);
EditText edit1 = (EditText) activity.findViewById(R.id.editText);
//board.setColumnCount(Integer.parseInt(edit1.getText().toString()));
//board.setRowCount(Integer.parseInt(edit1.getText().toString()));
board.setColumnCount(10);
board.setRowCount(10);
laenge = (int) (this.getWidth()-300)/board.getColumnCount();
breite = laenge ;
for (int i = 0; i <= board.getRowCount() - 1; i++) {
for (int j = 0; j <= board.getColumnCount() - 1; j++) {
CellButton button = new CellButton(activity);
button.setBackgroundResource(R.drawable.rectangle);
button.setId(i + j);
button.setyField(j);
button.setxField(i);
//button.setText(""+i+j);
button.setLayoutParams(new LinearLayout.LayoutParams(laenge, breite));
board.addView(button);
//anz++;
if (i == 0) {
button.setText("" + j);
button.setBackgroundResource(R.drawable.rectangle_second);
}
if (j == 0) {
button.setText("" + i);
button.setBackgroundResource(R.drawable.rectangle_second);
}
if ((i != 0) &&(j !=0)) {
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CellButton b = (CellButton) v;
Toast.makeText(getActivity().getBaseContext(), "" + b.getPositionText(), Toast.LENGTH_SHORT).show();
b.setBackgroundResource(R.drawable.cross);
Butty = b;
//Ship cur_Ship = new Ship(board);
// show_popup(b);
}
})
;};
}
} // create Methode Fine
} // End Create
public CellButton[] getallcells(){
int l =0;
for (int i =0;i<= board.getChildCount();i++){
View tmpView = board.getChildAt(i);
if (tmpView instanceof CellButton){
liCellBut[l] = (CellButton) tmpView;
l++;
}
}
return liCellBut;
}
//private void show_popup(Button b) {
//inflater = LayoutInflater.from(activity);
//pw = new PopupWindow(inflater.inflate(R.layout.ship_choose2, null, false),1200,1600, true);
//View viewPopup =(View) pw.getContentView();
//pw.showAtLocation(activity.findViewById(R.id.rel), Gravity.CENTER, 0, 0);
//add_listener((ViewGroup) viewPopup);
//ImageButton imgB1 = (ImageButton) viewPopup.findViewById(R.id.imgBShip1a);
//ImageButton imgB2 = (ImageButton) viewPopup.findViewById(R.id.imgBShip1b);
//ImageButton imgB3 = (ImageButton) viewPopup.findViewById(R.id.imgBShip1c);
//ImageButton imgB4 = (ImageButton) viewPopup.findViewById(R.id.imgBShip1d);
//ImageButton imgB5 = (ImageButton) viewPopup.findViewById(R.id.imgBShip1e);
//}
private void add_listener(ViewGroup viewPopup) {
ViewGroup v1 = (ViewGroup) viewPopup.findViewById(R.id.linView);
for(int i=0; i < v1.getChildCount(); i++)
{
View v = v1.getChildAt(i);
if (v instanceof ImageButton) {
ImageButton b = (ImageButton) v;
b.setOnClickListener(myClickListener);
}
}
}
private View.OnClickListener myClickListener = new View.OnClickListener() {
public void onClick(View v) {
Drawable shippicture = v.getBackground();
Ship cur_Ship = new Ship(board);
cur_Ship.add_ship_to_view(Butty, shippicture);
cur_Ship.name = "testboot_"+i;
ships[i]= cur_Ship;
pw.dismiss();
Toast.makeText(getActivity().getBaseContext(), "" + ships[i].name, Toast.LENGTH_SHORT).show();
i++;
}
;
};
// new Board create
//
//
public Activity getActivity () {
return activity;
}
public void setActivity (Activity activity){
this.activity = activity;
};
}
package com.example.wertalp.sensortester;
import android.content.Context;
import android.content.Intent;
import android.graphics.Point;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.AbsoluteLayout;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridLayout;
import android.widget.GridView;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
public class Main extends ActionBarActivity implements SensorEventListener{
private TextView txt1,txt2,txt3;
private ProgressBar progb1, progb2, progb3;
private ListView listview;
LayoutInflater inflater;
Context ctx ;
Button buttonSet ;
EditText edit1 ;
ChessBoard chessboard ;
Ship[] ships ;
PopupWindow pw;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ctx = this.getBaseContext();
chessboard = new ChessBoard(Main.this) ;
chessboard.create();
Display display = getWindowManager().getDefaultDisplay();
int width = display.getWidth();
int height =display.getHeight();
//Toast.makeText(getBaseContext(), "WIDTH HEIGHT: " + width+" : "+height, Toast.LENGTH_LONG).show();
buttonSet = (Button) findViewById(R.id.button23);
edit1 = (EditText) findViewById(R.id.editText);
Button buttonShoot = (Button) findViewById(R.id.button2) ;
buttonShoot.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent shootIntent = new Intent(Main.this,ShooterActivity.class);
Main.this.startActivity(shootIntent);
}
});
buttonSet.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
chessboard = new ChessBoard(Main.this) ;
chessboard.create();
}
}
);
// inflater = LayoutInflater.from(ctx);
//createBoard();
}
private void show_popup(Button b) {
inflater = LayoutInflater.from(this);
pw = new PopupWindow(inflater.inflate(R.layout.ship_choose2, null, false),1200,1600, true);
View viewPopup =(View) pw.getContentView();
pw.showAtLocation(this.findViewById(R.id.rel), Gravity.CENTER, 0, 0);
add_listener((ViewGroup) viewPopup);
ImageButton imgB1 = (ImageButton) viewPopup.findViewById(R.id.imgBShip1a);
ImageButton imgB2 = (ImageButton) viewPopup.findViewById(R.id.imgBShip1b);
ImageButton imgB3 = (ImageButton) viewPopup.findViewById(R.id.imgBShip1c);
ImageButton imgB4 = (ImageButton) viewPopup.findViewById(R.id.imgBShip1d);
ImageButton imgB5 = (ImageButton) viewPopup.findViewById(R.id.imgBShip1e);
}
@Override
public void onSensorChanged(SensorEvent event) {
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
}
}
package com.example.wertalp.sensortester.net;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicHeader;
import org.apache.http.protocol.HTTP;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.List;
public class GameConnector {
HttpClient client;
HttpPost post ;
StringEntity se ;
JSONObject Parent;
JSONArray jsonGameMoves ;
List<GameMove> datastreamList ;
public GameConnector(String url) throws UnsupportedEncodingException {
this.client = new DefaultHttpClient();
this.post = new HttpPost(url);
StringEntity se = new StringEntity( Parent.toString()) ;
se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
post.setHeader("Accept", "application/json");
post.setHeader("Content-type", "application/json");
post.setEntity(se);
}
public void makeJSONData() throws JSONException {
this.Parent = new JSONObject();
JSONArray jsonGameMoves = new JSONArray();
for (int i = 0 ; i < datastreamList.size() ; i++)
{
JSONObject jsonObj = new JSONObject();
jsonObj.put("id", datastreamList.get(i).getId());
jsonObj.put("current_value", datastreamList.get(i).getCurrent_value());
jsonGameMoves.put(jsonObj);
}
// Parent.put("datastreamList", jsonGameMoves);
//Parent.put("version", version);
}
public void SENDDATA () throws IOException {
this.client.execute(post);
}
class GameMove {
String id;
String current_value; // or int
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getCurrent_value() {
return current_value;
}
public void setCurrent_value(String current_value) {
this.current_value = current_value;
}
//get
//set
}
}
package com.example.wertalp.sensortester;
import android.content.Context;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.shapes.Shape;
import android.widget.Button;
import android.widget.GridLayout;
import android.widget.ImageButton;
/**
* Created by wertalp on 26.08.15.
*/
public class Ship {
Context ctx;
Button button;
String name;
Point position;
Shape shape;
Integer hSpan = 1;
Integer vSpan = 1;
GridLayout board;
public Ship(Button button, String name, Point position, Shape shape) {
this.button = button;
this.name = name;
this.position = position;
this.shape = shape;
}
public Ship(GridLayout board)
{
this.board = board;
}
public void add_ship_to_view(Button but,Drawable shippicture){
but.setBackground(shippicture);
}
}
// new Ship.
package com.example.wertalp.sensortester;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class ShooterActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_shooter);
ChessBoard chessboard = new ChessBoard(ShooterActivity.this) ;
chessboard.create();
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_shooter, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
var app = angular.module('myApp', ['ui.bootstrap']).
config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/Home', {templateUrl: 'home.html'}).
when('/Aloe', {templateUrl: 'aloe.html'}).
when('/Land', {templateUrl: 'land.html',controller:'ctrl'}).
otherwise({redirectTo: '/Home'});
}]).
directive('navTabs', ['$location', function(location) {
return {
restrict: 'A',
link: function(scope, element) {
var $ul = $(element);
$ul.addClass("nav nav-tabs");
var $tabs = $ul.children();
var tabMap = {};
$tabs.each(function() {
var $li = $(this);
//Substring 1 to remove the # at the beginning (because location.path() below does not return the #)
tabMap[$li.find('a').attr('href').substring(1)] = $li;
});
scope.location = location;
scope.$watch('location.path()', function(newPath) {
$tabs.removeClass("active");
tabMap[newPath].addClass("active");
});
}
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment