3.5 毫米耳机:配件规范
https://source.android.com/devices/accessories/headset/plug-headset-spec
2018年10月28日日曜日
直接启动
直接启动
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
https://developer.android.com/training/articles/direct-boot?hl=zh-cn
<action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
https://developer.android.com/training/articles/direct-boot?hl=zh-cn
2018年10月23日火曜日
アルファベットArrayList作成
import java.util.*;
class chart {
public static void main(String[] args) {
ArrayList<String> keyList = new ArrayList<>();
for (int i = 0x41; i < 0x5B; i++) {
keyList.add(String.valueOf((char)i));
}
for (int i = 0x30; i < 0x3A; i++) {
keyList.add(String.valueOf((char)i));
}
System.out.println(keyList);
String x = keyList.toString();
char[] temp = x.toCharArray();
temp = x.toCharArray();
for (char cc : temp) {
System.out.println(cc);
}
StringBuffer temp2 = new StringBuffer();
for(String xx :keyList){
temp2.append(xx);
}
System.out.println(temp2);
}
}
class chart {
public static void main(String[] args) {
ArrayList<String> keyList = new ArrayList<>();
for (int i = 0x41; i < 0x5B; i++) {
keyList.add(String.valueOf((char)i));
}
for (int i = 0x30; i < 0x3A; i++) {
keyList.add(String.valueOf((char)i));
}
System.out.println(keyList);
String x = keyList.toString();
char[] temp = x.toCharArray();
temp = x.toCharArray();
for (char cc : temp) {
System.out.println(cc);
}
StringBuffer temp2 = new StringBuffer();
for(String xx :keyList){
temp2.append(xx);
}
System.out.println(temp2);
}
}
2018年9月12日水曜日
【Android】快速切换到主线程更新UI的几种方法
【Android】快速切换到主线程更新UI的几种方法
方法一: view.post(Runnable action)
textView.post(new Runnable() {
@Override
public void run() {
textView.setText("更新textView");
//还可以更新其他的控件
imageView.setBackgroundResource(R.drawable.update);
}
});
方法二: activity.runOnUiThread(Runnable action)
public void updateUI(final Context context) {
((MainActivity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
//此时已在主线程中,可以更新UI了
}
});
}
方法三: Handler机制
...
方法一: view.post(Runnable action)
textView.post(new Runnable() {
@Override
public void run() {
textView.setText("更新textView");
//还可以更新其他的控件
imageView.setBackgroundResource(R.drawable.update);
}
});
方法二: activity.runOnUiThread(Runnable action)
public void updateUI(final Context context) {
((MainActivity) context).runOnUiThread(new Runnable() {
@Override
public void run() {
//此时已在主线程中,可以更新UI了
}
});
}
方法三: Handler机制
...
2018年7月19日木曜日
java_Semaphore
java_Semaphore
import java.util.concurrent.Semaphore;
import java.lang.System;
class M180717_Semaphore {
public static void main(String[] args) {
Semaphore semaphore = new Semaphore(8);
long s = System.currentTimeMillis();
A a = new A(semaphore);
a.start();
B b = new B(semaphore);
b.start();
B b2 = new B(semaphore);
b2.start();
}
}
class A extends Thread {
private Semaphore semaphore;
public A(Semaphore semaphore) {
this.semaphore = semaphore;
}
@Override
public void run() {
try {
semaphore.acquire();
System.out.println(Thread.currentThread().getName() + "-------");
for (int i = 0 ; i < 99 ; i++) {
System.out.print("a");
}
semaphore.release();
} catch (Exception e) {
System.out.println(semaphore.getQueueLength());
}
}
}
class B extends Thread {
private Semaphore semaphore;
public B(Semaphore semaphore) {
this.semaphore = semaphore;
}
@Override
public void run() {
try {
// System.out.println(semaphore.getQueueLength());
semaphore.acquire();
System.out.println(Thread.currentThread().getName() + "-------");
for (int i = 0 ; i < 99 ; i++) {
System.out.print("b");
}
semaphore.release();
} catch (Exception e) {
System.out.println(semaphore.getQueueLength());
}
}
}
class C extends Thread {
@Override
public void run() {
System.out.println(Thread.currentThread().getName() + "-------");
for (int i = 0 ; i < 99 ; i++) {
System.out.print("c");
}
}
}
class X implements Runnable {
@Override
public void run() {
System.out.println("xxxxx");
}
}
import java.util.concurrent.Semaphore;
import java.lang.System;
class M180717_Semaphore {
public static void main(String[] args) {
Semaphore semaphore = new Semaphore(8);
long s = System.currentTimeMillis();
A a = new A(semaphore);
a.start();
B b = new B(semaphore);
b.start();
B b2 = new B(semaphore);
b2.start();
}
}
class A extends Thread {
private Semaphore semaphore;
public A(Semaphore semaphore) {
this.semaphore = semaphore;
}
@Override
public void run() {
try {
semaphore.acquire();
System.out.println(Thread.currentThread().getName() + "-------");
for (int i = 0 ; i < 99 ; i++) {
System.out.print("a");
}
semaphore.release();
} catch (Exception e) {
System.out.println(semaphore.getQueueLength());
}
}
}
class B extends Thread {
private Semaphore semaphore;
public B(Semaphore semaphore) {
this.semaphore = semaphore;
}
@Override
public void run() {
try {
// System.out.println(semaphore.getQueueLength());
semaphore.acquire();
System.out.println(Thread.currentThread().getName() + "-------");
for (int i = 0 ; i < 99 ; i++) {
System.out.print("b");
}
semaphore.release();
} catch (Exception e) {
System.out.println(semaphore.getQueueLength());
}
}
}
class C extends Thread {
@Override
public void run() {
System.out.println(Thread.currentThread().getName() + "-------");
for (int i = 0 ; i < 99 ; i++) {
System.out.print("c");
}
}
}
class X implements Runnable {
@Override
public void run() {
System.out.println("xxxxx");
}
}
Android Handler Thread HandlerThread
Android Handler Thread HandlerThread
Handler.Callback callback = new Handler.Callback()
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = findViewById(R.id.textView);
button = findViewById(R.id.button);
CC();
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
handler.sendEmptyMessage(99);
}
});
}
protected void CC() {
HandlerThread handlerThread = new HandlerThread("test");
handlerThread.start();
Handler.Callback callback = new Handler.Callback() {
@Override
public boolean handleMessage(Message message) {
System.out.println();
System.out.println(Thread.currentThread().getName());
System.out.println("0000000000000000000000000000000000000");
return false;
}
};
handler = new Handler(handlerThread.getLooper(), callback);
}
Handler.Callback callback = new Handler.Callback()
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = findViewById(R.id.textView);
button = findViewById(R.id.button);
CC();
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
handler.sendEmptyMessage(99);
}
});
}
protected void CC() {
HandlerThread handlerThread = new HandlerThread("test");
handlerThread.start();
Handler.Callback callback = new Handler.Callback() {
@Override
public boolean handleMessage(Message message) {
System.out.println();
System.out.println(Thread.currentThread().getName());
System.out.println("0000000000000000000000000000000000000");
return false;
}
};
handler = new Handler(handlerThread.getLooper(), callback);
}
Android Handler Thread HandlerThread
Android Handler Thread HandlerThread
從主線程發送消息到子線程。
子線程必須創建Looper,
handlerThread.getLooper(),
Looper.prepare(),Looper.loop()
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = findViewById(R.id.button2);
Tthread tthread = new Tthread();
tthread.start();
T3();
T4();
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
hh.sendEmptyMessage(12);
handler.sendEmptyMessage(12);
handlerT4.sendEmptyMessage(12);
}
});
}
protected void T3() {
HandlerThread handlerThread = new HandlerThread("name-thread");
handlerThread.start();
handler = new Handler(handlerThread.getLooper()) {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
System.out.println(Thread.currentThread().getName());
System.out.println("T33333333333333333");
}
};
}
protected void T4() {
Thread thread = new Thread() {
@Override
public void run() {
super.run();
Looper.prepare();
handlerT4 = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
System.out.println("T44444444444444444444");
}
};
Looper.loop();
}
};
thread.start();
}
class Tthread extends Thread {
@Override
public void run() {
super.run();
Looper.prepare();
hh = new HH();
Looper.loop();
}
}
class HH extends Handler {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
System.out.println("HHHHHHHHHHHHHHHHHHHHHHHH");
System.out.println(Thread.currentThread().getName());
}
}
從主線程發送消息到子線程。
子線程必須創建Looper,
handlerThread.getLooper(),
Looper.prepare(),Looper.loop()
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = findViewById(R.id.button2);
Tthread tthread = new Tthread();
tthread.start();
T3();
T4();
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
hh.sendEmptyMessage(12);
handler.sendEmptyMessage(12);
handlerT4.sendEmptyMessage(12);
}
});
}
protected void T3() {
HandlerThread handlerThread = new HandlerThread("name-thread");
handlerThread.start();
handler = new Handler(handlerThread.getLooper()) {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
System.out.println(Thread.currentThread().getName());
System.out.println("T33333333333333333");
}
};
}
protected void T4() {
Thread thread = new Thread() {
@Override
public void run() {
super.run();
Looper.prepare();
handlerT4 = new Handler() {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
System.out.println("T44444444444444444444");
}
};
Looper.loop();
}
};
thread.start();
}
class Tthread extends Thread {
@Override
public void run() {
super.run();
Looper.prepare();
hh = new HH();
Looper.loop();
}
}
class HH extends Handler {
@Override
public void handleMessage(Message msg) {
super.handleMessage(msg);
System.out.println("HHHHHHHHHHHHHHHHHHHHHHHH");
System.out.println(Thread.currentThread().getName());
}
}
登録:
投稿 (Atom)