Skip to content

Instantly share code, notes, and snippets.

@tkuenneth
Created January 4, 2020 16:26
Show Gist options
  • Save tkuenneth/2fe3dbfd7969ed4960ac7b50d9c0c3da to your computer and use it in GitHub Desktop.
Save tkuenneth/2fe3dbfd7969ed4960ac7b50d9c0c3da to your computer and use it in GitHub Desktop.
How to use the Magnifier ui component
public class MagnifierDemoActivity extends Activity {
private Handler handler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ViewGroup layout = findViewById(R.id.layout);
Magnifier magnifier = new Magnifier(layout);
layout.setOnTouchListener((view, motionEvent) -> {
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_MOVE:
if (handler == null) {
handler = new Handler();
}
magnifier.show(motionEvent.getX(), motionEvent.getY());
post(handler, magnifier);
return true;
case MotionEvent.ACTION_UP:
view.performClick();
if (handler != null) {
handler = null;
}
magnifier.dismiss();
return true;
default:
return false;
}
});
}
private void post(Handler handler, Magnifier magnifier) {
handler.postDelayed(() -> {
magnifier.update();
post(handler, magnifier);
}, 200);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment