下面列出了android.view.View#getHandler ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void onClick(View v) {
Drawable background = v.getBackground();
long delay = 0;
if(background != null) {
if (background instanceof RippleDrawable)
delay = ((RippleDrawable) background).getClickDelayTime();
else if (background instanceof ToolbarRippleDrawable)
delay = ((ToolbarRippleDrawable) background).getClickDelayTime();
}
if(delay > 0 && v.getHandler() != null && !mClickScheduled) {
mClickScheduled = true;
v.getHandler().postDelayed(new ClickRunnable(v), delay);
}
else
dispatchClickEvent(v);
}
@Override
public void onClick(View v) {
Drawable background = v.getBackground();
long delay = 0;
if(background != null) {
if (background instanceof RippleDrawable)
delay = ((RippleDrawable) background).getClickDelayTime();
else if (background instanceof ToolbarRippleDrawable)
delay = ((ToolbarRippleDrawable) background).getClickDelayTime();
}
if(delay > 0 && v.getHandler() != null) {
if(!mClickScheduled){
mClickScheduled = true;
v.getHandler().postDelayed(new ClickRunnable(v), delay);
}
}
else
dispatchClickEvent(v);
}
private void updateText(final View localView, final TextView tv, final String s) {
Log.d("DrawStats", "updateText: " + s);
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
//Adrian: after screen rotation it might take some time to attach the view to the window
//Wait up to 3 seconds for this to happen.
int i = 0;
while (localView.getHandler() == null && i < 10) {
i++;
try {
Thread.sleep(300);
} catch (InterruptedException e) {
}
}
if (localView.getHandler() == null) {
Log.d("DrawStats", "no Handler found - stopping to update view");
return;
}
boolean success = localView.post(new Runnable() {
@Override
public void run() {
tv.setText(s);
Log.d("DrawStats", "setText actually called: " + s);
}
});
Log.d("DrawStats", "updateText: " + s + " success: " + success);
}
});
thread.start();
}
private void updateText(final View localView, final TextView tv, final String s) {
Log.d("DrawStats", "updateText: " + s);
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
//Adrian: after screen rotation it might take some time to attach the view to the window
//Wait up to 3 seconds for this to happen.
int i = 0;
while (localView.getHandler() == null && i < 10) {
i++;
try {
Thread.sleep(300);
} catch (InterruptedException e) {
}
}
if (localView.getHandler() == null) {
Log.d("DrawStats", "no Handler found - stopping to update view");
return;
}
boolean success = localView.post(new Runnable() {
@Override
public void run() {
tv.setText(s);
Log.d("DrawStats", "setText actually called: " + s);
}
});
Log.d("DrawStats", "updateText: " + s + " success: " + success);
}
});
thread.start();
}
private void updateText(final View localView, final TextView tv, final String s) {
Log.d("DrawStats", "updateText: " + s);
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
//Adrian: after screen rotation it might take some time to attach the view to the window
//Wait up to 3 seconds for this to happen.
int i = 0;
while (localView.getHandler() == null && i < 10) {
i++;
try {
Thread.sleep(300);
} catch (InterruptedException e) {
}
}
if (localView.getHandler() == null) {
Log.d("DrawStats", "no Handler found - stopping to update view");
return;
}
boolean success = localView.post(new Runnable() {
@Override
public void run() {
tv.setText(s);
Log.d("DrawStats", "setText actually called: " + s);
}
});
Log.d("DrawStats", "updateText: " + s + " success: " + success);
}
});
thread.start();
}
private void updateText(final View localView, final TextView tv, final String s) {
Log.d("DrawStats", "updateText: " + s);
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
//Adrian: after screen rotation it might take some time to attach the view to the window
//Wait up to 3 seconds for this to happen.
int i = 0;
while (localView.getHandler() == null && i < 10) {
i++;
try {
Thread.sleep(300);
} catch (InterruptedException e) {
}
}
if (localView.getHandler() == null) {
Log.d("DrawStats", "no Handler found - stopping to update view");
return;
}
boolean success = localView.post(new Runnable() {
@Override
public void run() {
tv.setText(s);
Log.d("DrawStats", "setText actually called: " + s);
}
});
Log.d("DrawStats", "updateText: " + s + " success: " + success);
}
});
thread.start();
}
private void postCheckRegisterResultOnUiThread(final View view,
final CheckInvalidator checkInvalidator, final int retry) {
// Now posting on UI thread to access view methods.
final Handler viewHandler = view.getHandler();
if (viewHandler == null) return;
viewHandler.post(new Runnable() {
@Override
public void run() {
checkRegisterResult(view, checkInvalidator, retry);
}
});
}
private void updateText(final View localView, final TextView tv, final String s) {
Log.d("DrawStats", "updateText: " + s);
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
//Adrian: after screen rotation it might take some time to attach the view to the window
//Wait up to 3 seconds for this to happen.
int i = 0;
while (localView.getHandler() == null && i < 10) {
i++;
try {
Thread.sleep(300);
} catch (InterruptedException e) {
}
}
if (localView.getHandler() == null) {
Log.d("DrawStats", "no Handler found - stopping to update view");
return;
}
boolean success = localView.post(new Runnable() {
@Override
public void run() {
tv.setText(s);
Log.d("DrawStats", "setText actually called: " + s);
}
});
Log.d("DrawStats", "updateText: " + s + " success: " + success);
}
});
thread.start();
}