PythonでWebServerを動かす方法
python -m http.server --bind 192.168.11.111
python -m http.server --bind 192.168.11.111 --directory C:\FFmpeg
python -m http.server 80 --bind 192.168.11.111 --directory C:\FFmpeg
downloads
https://www.python.org/downloads/release/python-380/
2019年11月23日土曜日
2019年11月7日木曜日
chrome コマンドの一覧を表示する方法
about:about
一覧画面はアドレスバーに
about:about
と入力すると確認できます。
パソコンに接続されている従来のプリンタを Google クラウド プリントに追加できます。
chrome://devices/
一覧画面はアドレスバーに
about:about
と入力すると確認できます。
パソコンに接続されている従来のプリンタを Google クラウド プリントに追加できます。
chrome://devices/
2019年10月20日日曜日
在前台运行服务
在前台运行服务
https://developer.android.com/guide/components/services#Foreground
Intent notificationIntent = new Intent(this, ExampleActivity.class);
PendingIntent pendingIntent =
PendingIntent.getActivity(this, 0, notificationIntent, 0);
Notification notification =
new Notification.Builder(this, CHANNEL_DEFAULT_IMPORTANCE)
.setContentTitle(getText(R.string.notification_title))
.setContentText(getText(R.string.notification_message))
.setSmallIcon(R.drawable.icon)
.setContentIntent(pendingIntent)
.setTicker(getText(R.string.ticker_text))
.build();
startForeground(ONGOING_NOTIFICATION_ID, notification);
https://developer.android.com/guide/components/services#Foreground
Intent notificationIntent = new Intent(this, ExampleActivity.class);
PendingIntent pendingIntent =
PendingIntent.getActivity(this, 0, notificationIntent, 0);
Notification notification =
new Notification.Builder(this, CHANNEL_DEFAULT_IMPORTANCE)
.setContentTitle(getText(R.string.notification_title))
.setContentText(getText(R.string.notification_message))
.setSmallIcon(R.drawable.icon)
.setContentIntent(pendingIntent)
.setTicker(getText(R.string.ticker_text))
.build();
startForeground(ONGOING_NOTIFICATION_ID, notification);
2019年10月8日火曜日
网络安全配置
网络安全配置
https://developer.android.com/training/articles/security-config
NetworkSecurityConfig: No Network Security Config specified, using platform default
res/xml/network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">ekidata.jp</domain>
</domain-config>
</network-security-config>
<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
<application android:networkSecurityConfig="@xml/network_security_config"
... >
...
</application>
</manifest>
https://developer.android.com/training/articles/security-config
NetworkSecurityConfig: No Network Security Config specified, using platform default
res/xml/network_security_config.xml
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
<domain-config cleartextTrafficPermitted="true">
<domain includeSubdomains="true">ekidata.jp</domain>
</domain-config>
</network-security-config>
<?xml version="1.0" encoding="utf-8"?>
<manifest ... >
<application android:networkSecurityConfig="@xml/network_security_config"
... >
...
</application>
</manifest>
2019年9月1日日曜日
android 音声の周波数を作成
android 音声の周波数を作成
byte b = (byte)(Math.sin(bufferIndex/2*Math.PI(SamplingRate /Frequency))
角度 =bufferIndex /2*Math.PI(4400/800);
byte値(音声のビット、B辺) = (byte) (Math.sin(temp) * 120(C辺);
private void hz() {
byte[] bs = new byte[44100];
Double temp;
for (int i = 0; i < bs.length; i++) {
temp = i / 2 * Math.PI / (44100 / Double.parseDouble("800"));
bs[i] = (byte) (Math.sin(temp) * 120);
}
audioTrack.play();
while (true) {
audioTrack.write(bs, 0, bs.length);
}
}
byte b = (byte)(Math.sin(bufferIndex/2*Math.PI(SamplingRate /Frequency))
角度 =bufferIndex /2*Math.PI(4400/800);
byte値(音声のビット、B辺) = (byte) (Math.sin(temp) * 120(C辺);
private void hz() {
byte[] bs = new byte[44100];
Double temp;
for (int i = 0; i < bs.length; i++) {
temp = i / 2 * Math.PI / (44100 / Double.parseDouble("800"));
bs[i] = (byte) (Math.sin(temp) * 120);
}
audioTrack.play();
while (true) {
audioTrack.write(bs, 0, bs.length);
}
}
private void hz() { byte[] bs = new byte[44100]; Double temp; for (int i = 0; i < bs.length; i++) { temp = i / 2 * Math.PI / (44100 / Double.parseDouble("800")); bs[i] = (byte) (Math.sin(temp) * 120); } audioTrack.play(); while (true) { audioTrack.write(bs, 0, bs.length); } }
2019年8月9日金曜日
minSdkVersion 28
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.kankanla.pi28"
minSdkVersion 28
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.kankanla.pi28"
minSdkVersion 28
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
compileSdkVersion 29
apply plugin: 'com.android.application'
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.kankanla.pi292"
minSdkVersion 29
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
android {
compileSdkVersion 29
defaultConfig {
applicationId "com.kankanla.pi292"
minSdkVersion 29
targetSdkVersion 29
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}
2019年8月5日月曜日
DialogFragment 生命周期
DialogFragment 生命周期
I/### DialogF: onCreate 1
I/### DialogF: onGetLayoutInflater 2
I/### DialogF: onCreateDialog 3
I/### DialogF: onCreateView 4
I/### DialogF: onStart 5
I/### DialogF: onResume 6
I/### DialogF: onCancel 7
I/### DialogF: onPause 8
I/### DialogF: onStop 9
I/### DialogF: onDestroyView 10
I/### DialogF: onDestroy 11
I/### DialogF: onDetach 12
I/### DialogF: onCreate 1
I/### DialogF: onGetLayoutInflater 2
I/### DialogF: onCreateDialog 3
I/### DialogF: onCreateView 4
I/### DialogF: onStart 5
I/### DialogF: onResume 6
I/### DialogF: onCancel 7
I/### DialogF: onPause 8
I/### DialogF: onStop 9
I/### DialogF: onDestroyView 10
I/### DialogF: onDestroy 11
I/### DialogF: onDetach 12
2019年7月11日木曜日
Understand the Activity Lifecycle 生命周期
生命周期
package com.kankanla.m20190711m_recorder;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
public class MainActivity extends AppCompatActivity {
private final String T = "### MainActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
Log.i(T, "1 onCreate");
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
protected void onStart() {
Log.i(T, "2 onStart");
super.onStart();
}
@Override
protected void onResume() {
Log.i(T, "3 onResume");
super.onResume();
}
@Override
protected void onPostResume() {
Log.i(T, "4 onPostResume");
super.onPostResume();
}
@Override
protected void onPause() {
Log.i(T, "5 onPause");
super.onPause();
}
@Override
protected void onStop() {
Log.i(T, "6 onStop");
super.onStop();
}
@Override
protected void onDestroy() {
Log.i(T, "7 onDestroy");
super.onDestroy();
}
@Override
protected void onRestart() {
Log.i(T, "8 onRestart");
super.onRestart();
}
}
2019年7月7日日曜日
自動バックアップ
自動バックアップ
SharedPreferencesが再インストール時にリセットされない
bmgr
https://stuff.mit.edu/afs/sipb/project/android/docs/tools/help/bmgr.html
Auto Backup for Android codelab
https://codelabs.developers.google.com/codelabs/android-backup-codelab/#0
Data backup overview
https://developer.android.com/guide/topics/data/backup
<manifest
<application
android:allowBackup="true"
adb shell bmgr enabled
adb shell bmgr enable <true|false>
adb shell bmgr list transports
adb shell bmgr backupnow <PACKAGE>
adb shell bmgr backup <PACKAGE>
adb shell bmgr run
adb shell bmgr restore <TOKEN> <PACKAGE>
SharedPreferencesが再インストール時にリセットされない
bmgr
https://stuff.mit.edu/afs/sipb/project/android/docs/tools/help/bmgr.html
Auto Backup for Android codelab
https://codelabs.developers.google.com/codelabs/android-backup-codelab/#0
Data backup overview
https://developer.android.com/guide/topics/data/backup
<manifest
<application
android:allowBackup="true"
adb shell bmgr enabled
adb shell bmgr enable <true|false>
adb shell bmgr list transports
adb shell bmgr backupnow <PACKAGE>
adb shell bmgr backup <PACKAGE>
adb shell bmgr run
adb shell bmgr restore <TOKEN> <PACKAGE>
2019年7月5日金曜日
adb shell dumpsys jobscheduler
adb shell dumpsys jobscheduler
Active jobs:
Slot #0: inactive since -9m38s404ms, stopped because: app called jobFinished
Slot #1: inactive since -11m39s487ms, stopped because: cancel() called by app, callingUid=10049 uid=10049 jobId=43
Slot #2: inactive since -11m39s594ms, stopped because: cancel() called by app, callingUid=10049 uid=10049 jobId=183
Slot #3: inactive since -3h35m29s108ms, stopped because: last work dequeued
Slot #4: inactive since -3h45m4s586ms, stopped because: last work dequeued
Slot #5: inactive since -3h45m4s848ms, stopped because: app called jobFinished
Slot #6: inactive
Slot #7: inactive
Slot #8: inactive
Slot #9: inactive
Slot #10: inactive
Slot #11: inactive
Slot #12: inactive
Slot #13: inactive
Slot #14: inactive
Slot #15: inactive
mReadyToRock=true
mReportedActive=false
mMaxActiveJobs=6
PersistStats: FirstLoad: 78/11/9 LastSave: 67/6/4
Active jobs:
Slot #0: inactive since -9m38s404ms, stopped because: app called jobFinished
Slot #1: inactive since -11m39s487ms, stopped because: cancel() called by app, callingUid=10049 uid=10049 jobId=43
Slot #2: inactive since -11m39s594ms, stopped because: cancel() called by app, callingUid=10049 uid=10049 jobId=183
Slot #3: inactive since -3h35m29s108ms, stopped because: last work dequeued
Slot #4: inactive since -3h45m4s586ms, stopped because: last work dequeued
Slot #5: inactive since -3h45m4s848ms, stopped because: app called jobFinished
Slot #6: inactive
Slot #7: inactive
Slot #8: inactive
Slot #9: inactive
Slot #10: inactive
Slot #11: inactive
Slot #12: inactive
Slot #13: inactive
Slot #14: inactive
Slot #15: inactive
mReadyToRock=true
mReportedActive=false
mMaxActiveJobs=6
PersistStats: FirstLoad: 78/11/9 LastSave: 67/6/4
2019年6月9日日曜日
AdRequest.addTestDevice
AdRequest.Builder builder = new AdRequest.Builder();
builder.addTestDevice("7026FA2EC1DC7E60FBEA02C64D33BD8B");
builder.addTestDevice("53185CF5BFA5B2121DF7FA86E7064C22");
builder.addTestDevice("78957C13BCC9AA1AC5D8462F2DEC083A");
builder.addTestDevice("C9517774AEB25C5D4B40D8175F152E03");
2019年6月6日木曜日
ADBコマンド導入の方法
ADBコマンド導入の方法
https://developer.android.com/studio/releases/platform-tools.html
platform-tools_r29.0.0-windows.zip
adb.exe
fastboot.exe
https://dl.google.com/android/repository/usb_driver_r11-windows.zip
http://adakoda.github.io/android-screen-monitor/
Android Screen Monitor
https://developer.android.com/studio/releases/platform-tools.html
platform-tools_r29.0.0-windows.zip
adb.exe
fastboot.exe
https://dl.google.com/android/repository/usb_driver_r11-windows.zip
http://adakoda.github.io/android-screen-monitor/
Android Screen Monitor
2019年6月4日火曜日
raspberrypi3 Apache2 PHP7 Sqlite3 curl vsftpd
raspberrypi3 Apache2 PHP7 Sqlite3 curl vsftpd
sudo apt-get install apache2
sudo apt-get install php
sudo apt-get install sqlite3
sudo apt-get install php-sqlite
sudo apt-get install php-curl
sudo apt-get install vsftpd
raspberrypi3 の省エネ設定
sudo tvservice --off
sudo ifconfig wlan0 down
ファームウェアのバージョン
$ vcgencmd version
メモリの割り当て
sudo apt-get install apache2
sudo apt-get install php
sudo apt-get install sqlite3
sudo apt-get install php-sqlite
sudo apt-get install php-curl
sudo apt-get install vsftpd
raspberrypi3 の省エネ設定
sudo tvservice --off
sudo ifconfig wlan0 down
2020/11/05
電圧の状態を調べる方法
$ vcgencmd get_throttled
throttled 値 状態
0x0 正常
0x50000 過去に低電圧状態になったが、現在は正常
0x50005 現在低電圧状態にある。
0x80000 過去に熱によりクロックダウンした。
0x80008 現在熱によりクロックダウンしている。
コア電圧を確認
$ vcgencmd measure_volts
volt=1.2000V
CPUの温度
$ vcgencmd measure_temp
temp=42.9'C
CPUの動作周波数
$ vcgencmd measure_clock arm
frequency(45)=600000000
$ vcgencmd version
Aug 15 2019 12:06:42
Copyright (c) 2012 Broadcom
version 0e6daa5106dd4164474616408e0dc24f997ffcf3 (clean) (release) (start)
メモリの割り当て
$ vcgencmd get_mem arm
arm=948M
$ vcgencmd get_mem gpu
gpu=76M
https://www.raspberrypi.org/documentation/raspbian/applications/vcgencmd.md
https://www.raspberrypi.org/documentation/raspbian/applications/vcgencmd.md
end
2019年5月22日水曜日
在自定义的SurfaceView 上打开 DialogFragment
在自定义的SurfaceView 上打开 DialogFragment
myDialogFragment.show(((AppCompatActivity) getContext()).getSupportFragmentManager(), "text");
@Override
public boolean onTouchEvent(MotionEvent event) {
boolean show = true;
if (show) {
AboutDialog aboutDialog = new AboutDialog(getContext());
aboutDialog.show();
Toast.makeText(getContext(), "xxxxxxxxxx", Toast.LENGTH_SHORT).show();
} else {
MyDialogFragment myDialogFragment = new MyDialogFragment();
myDialogFragment.item("99");
myDialogFragment.show(((AppCompatActivity) getContext()).getSupportFragmentManager(), "text");
}
return true;
}
myDialogFragment.show(((AppCompatActivity) getContext()).getSupportFragmentManager(), "text");
@Override
public boolean onTouchEvent(MotionEvent event) {
boolean show = true;
if (show) {
AboutDialog aboutDialog = new AboutDialog(getContext());
aboutDialog.show();
Toast.makeText(getContext(), "xxxxxxxxxx", Toast.LENGTH_SHORT).show();
} else {
MyDialogFragment myDialogFragment = new MyDialogFragment();
myDialogFragment.item("99");
myDialogFragment.show(((AppCompatActivity) getContext()).getSupportFragmentManager(), "text");
}
return true;
}
2019年4月13日土曜日
admob 設定
admob 設定
public class MainActivity extends AppCompatActivity {
private String T = "### MainActivity";
private MySurfaceView3 mySurfaceView;
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mySurfaceView = new MySurfaceView3(this);
RelativeLayout.LayoutParams rl = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT);
addContentView(mySurfaceView, rl);
Google_admob();
View view = findViewById(R.id.activity_main);
view.bringToFront();
}
protected void Google_admob() {
MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");
ViewGroup viewGroup = findViewById(R.id.activity_main);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
AdView adView = new AdView(this);
adView.setAdSize(AdSize.BANNER);
adView.setBackgroundColor(ContextCompat.getColor(this, R.color.colorAccent));
layoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
adView.setLayoutParams(layoutParams);
adView.setAdUnitId("ca-app-pub-3940256099942544/6300978111");
AdRequest.Builder builder = new AdRequest.Builder();
builder.addTestDevice("7026FA2EC1DC7E60FBEA02C64D33BD8B");
builder.addTestDevice("53185CF5BFA5B2121DF7FA86E7064C22");
AdRequest adRequest = builder.build();
adView.loadAd(adRequest);
viewGroup.addView(adView);
adView.setAdListener(new AdListener() {
@Override public void onAdLoaded() {
super.onAdLoaded();
Log.i(T, "onAdLoaded");
}
@Override public void onAdOpened() {
super.onAdOpened();
Log.i(T, "onAdOpened");
}
@Override public void onAdLeftApplication() {
super.onAdLeftApplication();
Log.i(T, "onAdLeftApplication");
}
@Override public void onAdClosed() {
super.onAdClosed();
Log.i(T, "onAdClosed");
}
});
}
}
//
I / ### MainActivity: onAdLoaded
I / ### MainActivity: onAdOpened
I / ### MainActivity: onAdLeftApplication
I / ### MainActivity: onAdClosed
I / ### MainActivity: onAdLoaded
Java 練習
java 練習
import java.util.*;
class demo1 {
public static void main(String[] args) {
int x = 123456789;
StringBuffer b = new StringBuffer();
while (x != 0) {
int t = x % 10;
x = (x - t) / 10;
b.append(t + ",");
}
System.out.println(b);
}
}
//
C:\>java demo1
9,8,7,6,5,4,3,2,1,
import java.util.*;
class demo1 {
public static void main(String[] args) {
int x = 123456789;
StringBuffer b = new StringBuffer();
while (x != 0) {
int t = x % 10;
x = (x - t) / 10;
b.append(t + ",");
}
System.out.println(b);
}
}
//
C:\>java demo1
9,8,7,6,5,4,3,2,1,
2019年3月31日日曜日
Android游戏编程之从零开始, 練習
Android游戏编程之从零开始, 練習
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Region;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class MySurfaceView2 extends SurfaceView implements SurfaceHolder.Callback, Runnable {
private final String T = "### MySurfaceView2";
private SurfaceHolder surfaceHolder;
private boolean flag;
private Canvas canvas;
private Paint paintA, paintB, paintC;
private Rect rectA, rectB, rectC;
private int rectAx, rectAy, rectBx, rectBy, rectCx, rectCy;
private int tag;
private int px, py;
private Region regionA, regionB, regionC;
private Bitmap bitmapA, bitmapB, bitmapC;
private Matrix matrixA, matrixB, matrixC;
private Thread th;
private int screenW, screenH;
public MySurfaceView2(Context context) {
super(context);
surfaceHolder = this.getHolder();
surfaceHolder.addCallback(this);
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
flag = true;
th = new Thread(this);
th.start();
init();
}
private void init() {
screenH = getHeight();
screenW = getWidth();
TGA();
TGB();
TGC();
}
private void TGA() {
bitmapA = BitmapFactory.decodeResource(getResources(), R.mipmap.a);
rectAx = 0;
rectAy = 0;
paintA = new Paint();
rectA = new Rect();
rectA.set(rectAx, rectAy, rectAx + bitmapA.getWidth(), rectAy + bitmapA.getHeight());
regionA = new Region();
regionA.op(rectA, Region.Op.XOR);
matrixA = new Matrix();
}
private void TGB() {
bitmapB = BitmapFactory.decodeResource(getResources(), R.mipmap.b);
rectBx = this.getWidth() - bitmapB.getWidth();
rectBy = 0;
paintB = new Paint();
rectB = new Rect();
rectB.set(rectBx, rectBy, rectBx + bitmapB.getWidth(), rectBy + bitmapB.getHeight());
regionB = new Region();
regionB.op(rectA, Region.Op.DIFFERENCE);
matrixB = new Matrix();
}
private void TGC() {
bitmapC = BitmapFactory.decodeResource(getResources(), R.mipmap.c);
rectCx = 0;
rectCy = this.getHeight() - bitmapC.getHeight();
paintC = new Paint();
rectC = new Rect();
rectC.set(rectCx, rectCy, rectCx + bitmapC.getWidth(), rectCy + bitmapC.getHeight());
regionC = new Region();
regionC.op(rectC, Region.Op.REVERSE_DIFFERENCE);
matrixC = new Matrix();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_UP:
tag = 0;
break;
case MotionEvent.ACTION_MOVE:
switch (tag) {
case 1:
rectAx = (int) event.getX() + px;
rectAy = (int) event.getY() + py;
break;
case 2:
rectBx = (int) event.getX() + px;
rectBy = (int) event.getY() + py;
break;
case 3:
rectCx = (int) event.getX() + px;
rectCy = (int) event.getY() + py;
break;
default:
}
break;
case MotionEvent.ACTION_DOWN: {
if (regionA.contains((int) event.getX(), (int) event.getY())) {
px = (int) (rectA.left - event.getX());
py = (int) (rectA.top - event.getY());
tag = 1;
}
if (regionB.contains((int) event.getX(), (int) event.getY())) {
px = (int) (rectB.left - event.getX());
py = (int) (rectB.top - event.getY());
tag = 2;
}
if (regionC.contains((int) event.getX(), (int) event.getY())) {
px = (int) (rectC.left - event.getX());
py = (int) (rectC.top - event.getY());
tag = 3;
}
break;
}
default:
}
return true;
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
flag = false;
}
private void T1(Canvas canvas) {
canvas.drawColor(Color.CYAN);
mA(canvas);
mB(canvas);
mC(canvas);
}
private void mA(Canvas canvas) {
matrixA.postTranslate(rectAx, rectAy);
rectA.set(rectAx, rectAy, rectAx + bitmapA.getWidth(), rectAy + bitmapA.getHeight());
regionA.set(rectA);
paintA.setAlpha(0);
canvas.drawRect(rectA, paintA);
paintA.setAlpha(255);
canvas.drawBitmap(bitmapA, matrixA, paintA);
matrixA.reset();
}
private void mB(Canvas canvas) {
matrixB.postTranslate(rectBx, rectBy);
rectB.set(rectBx, rectBy, rectBx + bitmapB.getWidth(), rectBy + bitmapB.getHeight());
regionB.set(rectB);
canvas.drawRect(rectB, paintB);
canvas.drawBitmap(bitmapB, matrixB, paintB);
matrixB.reset();
}
private void mC(Canvas canvas) {
matrixC.postTranslate(rectCx, rectCy);
rectC.set(rectCx, rectCy, rectCx + bitmapC.getWidth(), rectCy + bitmapC.getHeight());
regionC.set(rectC);
canvas.drawRect(rectC, paintC);
canvas.drawBitmap(bitmapC, matrixC, paintC);
matrixC.reset();
}
private void MyDraw() {
try {
canvas = surfaceHolder.lockCanvas();
if (canvas != null) {
T1(canvas);
}
} catch (Exception e) {
Log.i(T, "MyDraw Exception");
e.printStackTrace();
} finally {
if (canvas != null) {
surfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
@Override
public void run() {
while (true) {
long s = System.currentTimeMillis();
MyDraw();
long e = System.currentTimeMillis();
if (50 - (e - s) > 0) {
try {
Thread.sleep(50 - (e - s));
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}
}
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Region;
import android.util.Log;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
public class MySurfaceView2 extends SurfaceView implements SurfaceHolder.Callback, Runnable {
private final String T = "### MySurfaceView2";
private SurfaceHolder surfaceHolder;
private boolean flag;
private Canvas canvas;
private Paint paintA, paintB, paintC;
private Rect rectA, rectB, rectC;
private int rectAx, rectAy, rectBx, rectBy, rectCx, rectCy;
private int tag;
private int px, py;
private Region regionA, regionB, regionC;
private Bitmap bitmapA, bitmapB, bitmapC;
private Matrix matrixA, matrixB, matrixC;
private Thread th;
private int screenW, screenH;
public MySurfaceView2(Context context) {
super(context);
surfaceHolder = this.getHolder();
surfaceHolder.addCallback(this);
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
flag = true;
th = new Thread(this);
th.start();
init();
}
private void init() {
screenH = getHeight();
screenW = getWidth();
TGA();
TGB();
TGC();
}
private void TGA() {
bitmapA = BitmapFactory.decodeResource(getResources(), R.mipmap.a);
rectAx = 0;
rectAy = 0;
paintA = new Paint();
rectA = new Rect();
rectA.set(rectAx, rectAy, rectAx + bitmapA.getWidth(), rectAy + bitmapA.getHeight());
regionA = new Region();
regionA.op(rectA, Region.Op.XOR);
matrixA = new Matrix();
}
private void TGB() {
bitmapB = BitmapFactory.decodeResource(getResources(), R.mipmap.b);
rectBx = this.getWidth() - bitmapB.getWidth();
rectBy = 0;
paintB = new Paint();
rectB = new Rect();
rectB.set(rectBx, rectBy, rectBx + bitmapB.getWidth(), rectBy + bitmapB.getHeight());
regionB = new Region();
regionB.op(rectA, Region.Op.DIFFERENCE);
matrixB = new Matrix();
}
private void TGC() {
bitmapC = BitmapFactory.decodeResource(getResources(), R.mipmap.c);
rectCx = 0;
rectCy = this.getHeight() - bitmapC.getHeight();
paintC = new Paint();
rectC = new Rect();
rectC.set(rectCx, rectCy, rectCx + bitmapC.getWidth(), rectCy + bitmapC.getHeight());
regionC = new Region();
regionC.op(rectC, Region.Op.REVERSE_DIFFERENCE);
matrixC = new Matrix();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_UP:
tag = 0;
break;
case MotionEvent.ACTION_MOVE:
switch (tag) {
case 1:
rectAx = (int) event.getX() + px;
rectAy = (int) event.getY() + py;
break;
case 2:
rectBx = (int) event.getX() + px;
rectBy = (int) event.getY() + py;
break;
case 3:
rectCx = (int) event.getX() + px;
rectCy = (int) event.getY() + py;
break;
default:
}
break;
case MotionEvent.ACTION_DOWN: {
if (regionA.contains((int) event.getX(), (int) event.getY())) {
px = (int) (rectA.left - event.getX());
py = (int) (rectA.top - event.getY());
tag = 1;
}
if (regionB.contains((int) event.getX(), (int) event.getY())) {
px = (int) (rectB.left - event.getX());
py = (int) (rectB.top - event.getY());
tag = 2;
}
if (regionC.contains((int) event.getX(), (int) event.getY())) {
px = (int) (rectC.left - event.getX());
py = (int) (rectC.top - event.getY());
tag = 3;
}
break;
}
default:
}
return true;
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
flag = false;
}
private void T1(Canvas canvas) {
canvas.drawColor(Color.CYAN);
mA(canvas);
mB(canvas);
mC(canvas);
}
private void mA(Canvas canvas) {
matrixA.postTranslate(rectAx, rectAy);
rectA.set(rectAx, rectAy, rectAx + bitmapA.getWidth(), rectAy + bitmapA.getHeight());
regionA.set(rectA);
paintA.setAlpha(0);
canvas.drawRect(rectA, paintA);
paintA.setAlpha(255);
canvas.drawBitmap(bitmapA, matrixA, paintA);
matrixA.reset();
}
private void mB(Canvas canvas) {
matrixB.postTranslate(rectBx, rectBy);
rectB.set(rectBx, rectBy, rectBx + bitmapB.getWidth(), rectBy + bitmapB.getHeight());
regionB.set(rectB);
canvas.drawRect(rectB, paintB);
canvas.drawBitmap(bitmapB, matrixB, paintB);
matrixB.reset();
}
private void mC(Canvas canvas) {
matrixC.postTranslate(rectCx, rectCy);
rectC.set(rectCx, rectCy, rectCx + bitmapC.getWidth(), rectCy + bitmapC.getHeight());
regionC.set(rectC);
canvas.drawRect(rectC, paintC);
canvas.drawBitmap(bitmapC, matrixC, paintC);
matrixC.reset();
}
private void MyDraw() {
try {
canvas = surfaceHolder.lockCanvas();
if (canvas != null) {
T1(canvas);
}
} catch (Exception e) {
Log.i(T, "MyDraw Exception");
e.printStackTrace();
} finally {
if (canvas != null) {
surfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
@Override
public void run() {
while (true) {
long s = System.currentTimeMillis();
MyDraw();
long e = System.currentTimeMillis();
if (50 - (e - s) > 0) {
try {
Thread.sleep(50 - (e - s));
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}
}
ラベル:
Android游戏编程之从零开始
2019年3月28日木曜日
Math.random()
Math.random()
指定范围内乱数。
import java.util.*;
class random {
public static void main(String[] args) {
double temp = Math.random();
System.out.println(temp);
System.out.println(temp * (500 - 600));
System.out.println((int)(temp * (500 - 600) + 600));
System.out.println(Math.random() * (5 - 10) + 10);
}
}
指定范围内乱数。
import java.util.*;
class random {
public static void main(String[] args) {
double temp = Math.random();
System.out.println(temp);
System.out.println(temp * (500 - 600));
System.out.println((int)(temp * (500 - 600) + 600));
System.out.println(Math.random() * (5 - 10) + 10);
}
}
2019年3月27日水曜日
Android游戏编程之从零开始、p190
Android游戏编程之从零开始、p190
4.14.1 矩形碰撞
public boolean isCollsion(Rect rectA, Rect rectB) {
// left
// A B
if (rectA.left < rectB.left && rectA.right < rectB.left) {
return false;
}
// top
// A
// B
if (rectA.bottom < rectB.top && rectA.bottom < rectB.bottom) {
return false;
}
// right
// B A
if (rectA.left > rectB.left && rectA.left > rectB.right) {
return false;
}
// bottom
// B
// A
if (rectA.top > rectB.bottom && rectA.bottom > rectB.bottom) {
return false;
}
return true;
}
4.14.1 矩形碰撞
public boolean isCollsion(Rect rectA, Rect rectB) {
// left
// A B
if (rectA.left < rectB.left && rectA.right < rectB.left) {
return false;
}
// top
// A
// B
if (rectA.bottom < rectB.top && rectA.bottom < rectB.bottom) {
return false;
}
// right
// B A
if (rectA.left > rectB.left && rectA.left > rectB.right) {
return false;
}
// bottom
// B
// A
if (rectA.top > rectB.bottom && rectA.bottom > rectB.bottom) {
return false;
}
return true;
}
ラベル:
Android游戏编程之从零开始
2019年3月24日日曜日
Android游戏编程之从零开始、p173
Android游戏编程之从零开始、p173
自定义动画
动态位图
private void T1set() {
btax = bitmapB.getWidth() - this.getWidth();
btay = -bitmapB.getHeight() + this.getHeight();
}
private void T1(Canvas canvas) {
btax -= 10;
canvas.drawColor(Color.RED);
canvas.drawBitmap(bitmapB, -btax, btay, paint);
}
private void mDraw() {
try {
canvas = surfaceHolder.lockCanvas();
if (canvas != null) {
T1(canvas);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (canvas != null) {
surfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
@Override
public void run() {
while (thflag) {
long s = System.currentTimeMillis();
mDraw();
long e = System.currentTimeMillis();
if (e - s < 50) {
try {
Thread.sleep(50 - (e - s));
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}
自定义动画
动态位图
private void T1set() {
btax = bitmapB.getWidth() - this.getWidth();
btay = -bitmapB.getHeight() + this.getHeight();
}
private void T1(Canvas canvas) {
btax -= 10;
canvas.drawColor(Color.RED);
canvas.drawBitmap(bitmapB, -btax, btay, paint);
}
private void mDraw() {
try {
canvas = surfaceHolder.lockCanvas();
if (canvas != null) {
T1(canvas);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (canvas != null) {
surfaceHolder.unlockCanvasAndPost(canvas);
}
}
}
@Override
public void run() {
while (thflag) {
long s = System.currentTimeMillis();
mDraw();
long e = System.currentTimeMillis();
if (e - s < 50) {
try {
Thread.sleep(50 - (e - s));
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
}
ラベル:
Android游戏编程之从零开始
Android游戏编程之从零开始 P166
Android游戏编程之从零开始
②第二种是利用Regin来对画布设置可视区域。
canvas.clipRegion(region) 过时。
canvas.clipPath(region.getBoundaryPath()) 利用
private void T3(Canvas canvas) {
canvas.save();
canvas.drawColor(Color.WHITE);
Region region = new Region();
region.op(new Rect(200, 200, 1000, 1000), Region.Op.UNION);
region.op(new Rect(400, 300, 900, 900), Region.Op.REVERSE_DIFFERENCE);
region.op(new Rect(500, 200, 800, 800), Region.Op.XOR);
canvas.clipPath(region.getBoundaryPath());
canvas.drawBitmap(bitmapC, 0, 0, paint);
canvas.restore();
}
②第二种是利用Regin来对画布设置可视区域。
canvas.clipRegion(region) 过时。
canvas.clipPath(region.getBoundaryPath()) 利用
private void T3(Canvas canvas) {
canvas.save();
canvas.drawColor(Color.WHITE);
Region region = new Region();
region.op(new Rect(200, 200, 1000, 1000), Region.Op.UNION);
region.op(new Rect(400, 300, 900, 900), Region.Op.REVERSE_DIFFERENCE);
region.op(new Rect(500, 200, 800, 800), Region.Op.XOR);
canvas.clipPath(region.getBoundaryPath());
canvas.drawBitmap(bitmapC, 0, 0, paint);
canvas.restore();
}
adb devices 查询设备
查询设备
$ adb devices
将文件复制到设备/从设备复制文件
$ adb pull remote local
$ adb push local remote
进行屏幕截图
$ adb shell screencap /sdcard/screen.png
录制视频
$ adb shell screenrecord /sdcard/demo.mp4
$ adb devices
将文件复制到设备/从设备复制文件
$ adb pull remote local
$ adb push local remote
进行屏幕截图
$ adb shell screencap /sdcard/screen.png
录制视频
$ adb shell screenrecord /sdcard/demo.mp4
2019年3月21日木曜日
ldpi,mdpi,hdpi,xhdpi,xxhdpi,xxxhdpi
ldpi,mdpi,hdpi,xhdpi,xxhdpi,xxxhdpi
float xdpi = getResources().getDisplayMetrics().xdpi;
float ydpi = getResources().getDisplayMetrics().ydpi;
https://blog.csdn.net/guolin_blog/article/details/50727753
https://developer.android.com/reference/android/util/DisplayMetrics.html
float xdpi = getResources().getDisplayMetrics().xdpi;
float ydpi = getResources().getDisplayMetrics().ydpi;
https://blog.csdn.net/guolin_blog/article/details/50727753
https://developer.android.com/reference/android/util/DisplayMetrics.html
ラベル:
Android_Layout
登録:
投稿 (Atom)