福尔摩斯的烟斗

福尔摩斯的烟斗的笔记

来自千锋3G学院-Android游戏开发教程-数独-第3讲(0)

Paint paint = new Paint(); paint.setColor(Color.BLACK); // 设置画笔透明度以及RGB属性1、a(透明度)1~255越小越透明 。2、R(红色)0~255越小越淡。3、G(绿色) // 0~255。4、B(蓝色)0~255。 paint.setARGB(200, 5, 100, 230); // 设置抗锯齿 注:设置这个属性后会消耗大量资源,绘制图形时会变慢。 paint.setAntiAlias(true); // 设置画笔的大小,也就是粗细。 paint.setStrokeWidth(1); // 设置画笔的样式。1、STROKE:空心图不填充颜色, paint.setStyle(Style.STROKE); // 绘制矩形,1、左边界的位置,2、上边界的位置,3、有边界的位置,4、下边界的位置。 paint.setTextSize(100); canvas.drawRect(200, 100, 300, 400, paint); // 绘制一条线,前俩个参数是x,y的起始位置的坐标,后俩个是x,y的终止位置的坐标。 canvas.drawLine(100, 100, 400, 400, paint); // 绘制圆形,前两个是圆心 x,y坐标,radius:是圆的半径。 canvas.drawCircle(200, 200, 50, paint); canvas.drawText("appde", 150, 300, paint); canvas.drawBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher),300,100,paint);    Paint backgroundpaint = new Paint(); backgroundpaint.setColor(getResources().getColor( R.color.BackgroundColor)); canvas.drawRect(0, 0, getWidth(), getHeight(), backgroundpaint);Paint blackpaint = new Paint(); blackpaint.setColor(getResources().getColor(R.color.black));Paint strikingpaint = new Paint(); strikingpaint.setColor(getResources().getColor(R.color.Striking));Paint brightpaint = new Paint(); brightpaint.setColor(getResources().getColor(R.color.Bright));for (int i = 0; i < 9; i++) { canvas.drawLine(0, i * height, getWidth(), i * height, strikingpaint); canvas.drawLine(0, i * height + 1, getWidth(), i * height + 1, brightpaint); canvas.drawLine(i * width, 0, i * width, getHeight(), strikingpaint); canvas.drawLine(i * width + 1, 0, i * width + 1, getHeight(), brightpaint); } for (int i = 0; i < 9; i++) { if (i % 3 != 0) { continue; } canvas.drawLine(0, i * height, getWidth(), i * height, blackpaint); canvas.drawLine(0, i * height + 1, getWidth(), i * height + 1, brightpaint); canvas.drawLine(i * width, 0, i * width, getHeight(), blackpaint); canvas.drawLine(i * width + 1, 0, i * width + 1, getHeight(), brightpaint); }Paint textpaint = new Paint(); textpaint.setColor(Color.BLACK); textpaint.setStyle(Paint.Style.STROKE); textpaint.setTextSize(height * 0.75f); textpaint.setTextAlign(Paint.Align.CENTER); float x = width / 2; canvas.drawText("1", 3 * width + x, 61, textpaint);

来自千锋3G学院-Android游戏开发教程-数独-第4讲(0)

public class Game { private final String str = "360000000004230800000004200"+ "070460003820000014500013020"+ "001900000007048300000000045"; private int [] soduku = new int [9*9]; public Game(){ soduku = fromPuzzleString(str); }// 根据9宫格的坐标,返回坐标的格子中的数据; private int getTile(int x, int y){ return soduku[y* 9 + x]; } public String getTileString(int x, int y){ int v = getTile(x,y); if(v == 0){ return ""; }else{ return String.valueOf(v); } } protected int[] fromPuzzleString(String src){ int[] sudo = new int[str.length()]; for(int i = 0;i < sudo.length;i++){ sudo[i] = str.charAt(i) - '0'; } return sudo; }}   //画字体 Paint textpaint = new Paint(); textpaint.setColor(Color.BLACK); textpaint.setStyle(Paint.Style.STROKE); textpaint.setTextSize(height * 0.75f); textpaint.setTextAlign(Paint.Align.CENTER); textpaint.setAntiAlias(true); //计算字体大小 FontMetrics fm = textpaint.getFontMetrics(); float x = width / 2; float y = height / 2 - (fm.ascent + fm.descent)/2; for(int i = 0 ;i < 9 ;i++){ for(int j = 0 ; j < 9 ; j++){ canvas.drawText(new Game().getTileString(i, j), i * width + x,j * height + y, textpaint); } }

来自千锋3G学院-Android游戏开发教程-数独-第5讲(0)

//取出不可用的数据; public int[] getUsedTilesByCoor(int x, int y){ return used[x][y]; } //计算单元格中不可用的数据; public int[] calculateUsedTiles(int x, int y){ int [] c = new int[9]; //计算Y轴方向不可用数据; for(int i = 0; i < 9; i ++){ if( i == y ){ continue; } int t = getTile(x,i); if(t!=0){ c[t-1]=t; } } //计算X轴方向不可用数据: for(int i = 0; i < 9 ; i++){ if(i == x){ continue; } int t = getTile(i,y); if(t != 0){ c[t-1] = t; } } //计算小九宫格不可用数据; int startx = (x / 3) * 3; int starty = (y / 3) * 3; for(int i = startx; i < startx + 3; i++){ for(int j = starty; j < starty + 3; j++){ if(i == x && j == y){ continue; } int t = getTile(i,j); if(t != 0 ){ c[t-1] = t; } } } int nused = 0; for(int t : c){ if(t != 0){ nused ++; } } int [] c1 = new int[nused]; nused = 0 ; for(int t : c){ if(t != 0){ c1[nused++] = t; } } return c1; } //获取屏幕点击的焦点 @Override public boolean onTouchEvent(MotionEvent event) { if(event.getAction() != MotionEvent.ACTION_DOWN){ return super.onTouchEvent(event); } int selectedX = (int)(event.getX()/width); int selectedY = (int)(event.getY()/height); int used[] = game.getUsedTilesByCoor(selectedX, selectedY); for(int i = 0 ; i < used.length ; i++){ System.out.println(used[i]); } return true; }

来自千锋3G学院-Android游戏开发教程-数独-第6讲(0)

//可以分成2大块来看!!! //1、第一块是 创建View,把自定义的布局文件转换成View对象; LayoutInflater layout = LayoutInflater.from(this.getContext()); View layoutView = layout.inflate(R.layout.dialog, null); TextView textView = (TextView) layoutView.findViewById(R.id.textID); textView.setText(sb.toString()); //2、创建Dialog对象并把设置好的View填充进去; AlertDialog.Builder builder = new AlertDialog.Builder(this.getContext()); builder.setView(layoutView); AlertDialog dialog = builder.create(); dialog.show();

来自千锋3G学院-Android游戏开发教程-数独-第7讲(0)

public class MyDialog extends Dialog { private final View[] keys = new View[9]; private final int[] used;public MyDialog(Context context, int[] used) { super(context); this.used = used; }// Dialog第一次显示时调用onCreate方法; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 设置Dialog的标题和布局文件; setTitle("KeyDialog"); setContentView(R.layout.dialog); // 调用这个方法取得封装的Button控件; findViews(); //遍历整个used数组,得到不可用的数据; for (int i = 0; i < used.length; i++) { if (used[i] != 0) { //根据used得到的数据,把可以用的数据赋值给Button控件, //设置keys数组里的按钮是否可见,INVISIBLE参数为不可见; keys[used[i]-1].setVisibility(View.INVISIBLE); } }}private void findViews() { keys[0] = findViewById(R.id.NO1); keys[1] = findViewById(R.id.NO2); keys[2] = findViewById(R.id.NO3); keys[3] = findViewById(R.id.NO4); keys[4] = findViewById(R.id.NO5); keys[5] = findViewById(R.id.NO6); keys[6] = findViewById(R.id.NO7); keys[7] = findViewById(R.id.NO8); keys[8] = findViewById(R.id.NO9); }}   注意:TableLayout 下的android:stretchColumns属性:设置可伸展的列。该列可以向行方向伸展,最多可占据一整行。控制Dialog的宽度。

来自1.5_Activity值传递(0)

//mainActivitypublic class MainActivity extends Activity {private EditText edit;private Button button;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);edit = (EditText) this.findViewById (R.id.eidt);button = (Button) this.findViewById(R.id.but);button.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View arg0) {String s =edit.getText().toString();Intent intent = new Intent(MainActivity.this,FindEdit.class);Bundle bundle = new Bundle();bundle.putString("edit", s);intent.putExtra("bundle", bundle);startActivity(intent);}});}}//跳转的Activitypublic class FindEdit extends Activity{private TextView text;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.findedit_activity);text = (TextView) findViewById (R.id.text);Intent intent = getIntent();Bundle bundle = intent.getBundleExtra("bundle");String s = bundle.getString("edit");text.setText(s);}}

来自1.6_Activity回传值(0)

//MainActivitypublic class MainActivity extends Activity {private EditText edit; private Button button; private TextView text; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); edit = (EditText) this.findViewById (R.id.eidt); button = (Button) this.findViewById(R.id.but); text = (TextView) this.findViewById(R.id.text); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { String s =edit.getText().toString().trim(); Intent intent = new Intent(MainActivity.this,FindEdit.class); intent.putExtra("edit", s); startActivityForResult(intent, 840626); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if(requestCode == 840626 && resultCode == 617724){ String a = data.getStringExtra("edit1").toString().trim(); text.setText(a); } }}//FindEditpublic class FindEdit extends Activity{ private EditText edit ; private TextView text; private Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.findedit_activity); text = (TextView) findViewById (R.id.text); edit = (EditText) findViewById (R.id.edit1); button = (Button) findViewById (R.id.button); Intent intent = getIntent(); String s = intent.getStringExtra("edit").toString().trim(); text.setText(s); button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { String str = edit.getText().toString().trim(); Intent ent = new Intent(); ent.putExtra("edit1", str); setResult(617724, ent); finish(); } }); }}