how to zoom a view in android - android

I am trying to develop an application that displays lines of path of travel using openGL. I want to zoomin or zoomout the contents. Created a RelativeLayout and added the GLSurfaceView and ZoomControls to it. Now in the zoomControls.setOnZoomInClickListener i need to write how to zoom the view. For a view there are no zoom controls. Please help me if there is a way to zoom the view. Thank you..
mGLSView = new GLSurfaceView(this);
final RelativeLayout rl = new RelativeLayout(this);
ZoomControls zc = new ZoomControls(this);
zc.setOnZoomInClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
//// ??? WHAT TO DO WITH THE VIEW ?
}
});
zc.setVisibility(View.VISIBLE);
zc.bringToFront();
rl.addView(mGLSView);
rl.addView(zc);
setContentView(rl);

As far as I know, you cannot treat the GL Surface like a canvas and scale it.
So you will have to redraw the scaled version again using GL calls. An alternative would be to draw into FBO and render the scaled texture to the surface.

Related

SVG zoom and scroll gesture

I have a simple activity which display a fullscreen SVG thanks to this
android lib. The SVG displayed is a map and I need to enable zoom/scroll gesture on it. That is why I use this lib, which works perfectly with normal ImageView.
Here, I'm using PhotoView lib attacher to SVGImageView :
PhotoViewAttacher mAttacher;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LinearLayout layout = new LinearLayout(this);
SVGImageView svgImageView = new SVGImageView(this);
svgImageView.setImageAsset("map.svg");
layout.addView(svgImageView, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
setContentView(layout);
mAttacher = new PhotoViewAttacher(svgImageView);
}
PhotoView works but it takes like 10 second to apply zoom or scroll gesture.
Do you have any ideas on how I could efficiently scale & scroll in ?
Thank you in advance.

UnityPlayer as a SubView with Transparent Background? (Unity Game Engine)

I am trying to do the following on Android (then possibly on iOS) and any advices will be appreciated:
Overlaying UnityPlayer view on top of Native Android view where only the 3D objects being drawn and no camera background (transparent background)
My current progress:
So far I managed to use my Unity3D project as library into another Android project and assign UnityPlayer view to a FrameLayout on top of another Android view but the camera background color showing... I tried changing the clear flag option to depth only but it didn't work.
I also managed to use a separate GLSurfaceView which I assigned class extending UnityPlayer and implementing GLSurfaceView.Renderer to as the renderer but I am still getting opaque background.
My code as follows:
// the class extending the player
class CustomUnityPlayer extends UnityPlayer implements GLSurfaceView.Renderer {
public CustomUnityPlayer(ContextWrapper context) {
super(context);
}
public void onDrawFrame(GL10 gl) {
super.onDrawFrame(gl);
}
}
// inside OnCreate function:
m_UnityPlayer = new CustomUnityPlayer(this);
int glesMode = m_UnityPlayer.getSettings().getInt("gles_mode", 1);
m_UnityPlayer.init(glesMode, false);
mUnityView = new GLSurfaceView(getApplication());
mUnityView.setEGLContextClientVersion(2);
mUnityView.setZOrderOnTop(true);
mUnityView.setZOrderMediaOverlay(true);
mUnityView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
mUnityView.setRenderer(m_UnityPlayer);
mUnityView.getHolder().setFormat(PixelFormat.TRANSLUCENT);
setContentView(R.layout.activity_fullscreen);
FrameLayout layout = (FrameLayout) findViewById(R.id.UnityView);
LayoutParams lp = new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT);
layout.addView(mUnityView, 0, lp);
Am I missing something and is it even possible? Any help will be much appreciated.
Thanks alot
after some attempts...removing mUnityView.setZOrderMediaOverlay(true); did the trick for me (works on Unity 4.2 and below... not in Unity 4.3 and above)

How to rotate GLSurfaceView?

I try to use setRotation() on my GLSurfaceView, but the view seems not rotate around the pivot which is the center of the screen. the code like below:
class MyGLSurfaceView extends GLSurfaceView {
private float mCurRotation = 0.0f;
#Override
public boolean onTouchEvent(MotionEvent e) {
mCurRotation = mCurRotation + 10;
setRotation(mCurRotation);
}
}
Is there any body know the reason and teach me how to rotate my GLSurfaceView?
Contrary to your expectation, methods of View doesn't work well.
GLSurfaceView punches a hole to display underneath surface. Actually it has only transparent pixels.
If you want to rotate your image, you have to use OpenGL operations.

How to use native Textview (View) in Andengine Game Activity

I want to know is there any way to use native TextView or any other layout of android inside BaseAndEngine Activity.
My application is using Andengine for one of its whole screen. This screen is extended from BaseAndEngine and I need to use some native view like textview inside that screen. Because Andengine does not work fine for Arabic text and I need to show some Arabic text on gaming screen.
OR if possible how to show Arabic text in changeable text in Andengine. As changeable text write Arabic from left to right in reverse order.
Of course you can.
Check this code out - basically you override onSetContentView, then you can set whatever you want.
#Override
protected void onSetContentView() {
final FrameLayout frameLayout = new FrameLayout(this);
final FrameLayout.LayoutParams frameLayoutLayoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.FILL_PARENT, FrameLayout.LayoutParams.FILL_PARENT);
this.mRenderSurfaceView = new RenderSurfaceView(this);
mRenderSurfaceView.setRenderer(mEngine);
final FrameLayout.LayoutParams surfaceViewLayoutParams = new FrameLayout.LayoutParams(super.createSurfaceViewLayoutParams());
frameLayout.addView(this.mRenderSurfaceView, surfaceViewLayoutParams);
//Create any other views you want here, and add them to the frameLayout.
this.setContentView(frameLayout, frameLayoutLayoutParams);
}
(This method goes to your subclass of BaseGameActivity.)
You could also do it through xml, but I think this method is more clear.
You can use Andengine for Arabic and Persian fonts too. But in a different manner. to do that you need to create a Sprite and add a bitmap to it. before that you draw your text on that bitmap.
the following code is an example that draw the Persian/Arabians text and attach it to a sprite. so we can attach the sprite to our scene.
this is an example to show how we can do that, so you can adjust the bitmap and text size by yourself.
if your device support Persian/Arabians, this code will work properly. if the text does not appear in your scene, change its position, it is out of screen
the example code function will print the "Persian Golf" in Persian/Arabians.
private void persianGolfPrinter(){
BitmapTextureAtlas mBitmapTextureAtlas = new BitmapTextureAtlas(ResourceManager.getInstance().gameActivity.getTextureManager(), 400, 800, TextureOptions.BILINEAR);
ITextureRegion mDecoratedBalloonTextureRegion;
final IBitmapTextureAtlasSource baseTextureSource = new EmptyBitmapTextureAtlasSource(400, 800);
final IBitmapTextureAtlasSource decoratedTextureAtlasSource = new BaseBitmapTextureAtlasSourceDecorator(baseTextureSource) {
#Override
protected void onDecorateBitmap(Canvas pCanvas) throws Exception {
this.mPaint.setColor(Color.BLACK);
this.mPaint.setStyle(Style.FILL);
this.mPaint.setTextSize(32f);
this.mPaint.setTextAlign(Align.CENTER);
pCanvas.drawText("خلیج فارس", 150, 150, this.mPaint);
}
#Override
public BaseBitmapTextureAtlasSourceDecorator deepCopy() {
throw new DeepCopyNotSupportedException();
}
};
mDecoratedBalloonTextureRegion = BitmapTextureAtlasTextureRegionFactory.createFromSource(mBitmapTextureAtlas, decoratedTextureAtlasSource, 0, 0);
mBitmapTextureAtlas.load();
Sprite test = new Sprite(0,0,mDecoratedBalloonTextureRegion,ResourceManager.getInstance().engine.getVertexBufferObjectManager());
this.attachChild(test);
}
don't use android textview... it makes your game ugly ....
You cannot use them directly in AndEngine, because the objects in Andengine are OpenGL objects. But you can use android OS to draw a bitmap of any standard view, and then create a texture and a sprite from that view. This is less than optimum for a case such as arabic text, but it will work. Be careful about memory leaks as you create the bitmaps of your views.

How to layout zoom Control with setBuiltInZoomControls(true)?

would like to add a zoom control to the map. I also want to layout the position of the zoom Control instead of the default middle bottom position. I can do this by getZoomControl but it is deprecated.
Could anyone tell me how to do this with setBuildtInZoomControls?
This is how I got mine working finally (by embedding a ZoomControl in XML layout).
mapView = (MapView) this.findViewById(R.id.mapView);
ZoomControls zoomControls = (ZoomControls) findViewById(R.id.zoomcontrols);
zoomControls.setOnZoomInClickListener(new OnClickListener() {
public void onClick(View v) {
mapView.getController().zoomIn();
}
});
zoomControls.setOnZoomOutClickListener(new OnClickListener() {
public void onClick(View v) {
mapView.getController().zoomOut();
}
});
See: Always show zoom controls on a MapView
mapView.getZoomButtonsController()
Although this is undocumented (at least in the javadoc available here: com.google.android.maps) I am quite sure this is the replacement for the deprecated getZoomControls
Edit: just found out that it is documented, just not in the google api docs but rather here: ZoomButtonsController on developer.android.com
You could then call getContainer () or getZoomControls () (depending on what you want to do) to get access to the zoom controls view.
And then do something like
RelativeLayout.LayoutParams zoomParams = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
zoomParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
mapView.getZoomButtonsController().getZoomControls().setLayoutParams(zoomParams);
although I have to admit that I am not sure what layout the maps view uses, could be LinearLayout as well.
LinearLayout zoomLayout = (LinearLayout) findViewById(R.id.layout_zoom);
View mapController = mapView.getZoomButtonsController().getZoomControls();
zoomLayout.addView(mapController, new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
I'm pretty sure that the only way to do this is to either use the MapView's deprecated getZoomControls() or to DIY it. The MapController has the methods necessary (e.g. zoomIn() and zoomOut()).
RelativeLayout relativeLayout = new RelativeLayout(this);
setContentView(relativeLayout);
final MapView mapView = new MapView(this, DEBUG_MAP_API_KEY);
RelativeLayout.LayoutParams mapViewLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.FILL_PARENT,RelativeLayout.LayoutParams.FILL_PARENT );
relativeLayout.addView(mapView, mapViewLayoutParams);
RelativeLayout.LayoutParams zoomControlsLayoutParams = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,RelativeLayout.LayoutParams.WRAP_CONTENT );
zoomControlsLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
zoomControlsLayoutParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
relativeLayout.addView(mapView.getZoomControls(), zoomControlsLayoutParams);
mapView.setClickable(true);
mapView.setEnabled(true);
I think this should work ... Hope this is useful :)
The solution provided by George on Placing Zoom Controls in a MapView allows to layout the built in zoom controls by using gravity attributes. This attribute positions the element into its container which seems that is positioned on the bottom of the screen so its not possible to position the zoom controls on the top of the screen by layouting the zoom controls.
In conclusion you can layout the built in zoom controls by doing:
((FrameLayout.LayoutParams) mapView.getZoomButtonsController().getZoomControls().getLayoutParams()).gravity = Gravity.RIGHT;
Remember that the zoom controls are contained into a FrameLayout therefore any try to use rules like RelativeLayout.ALIGN_PARENT_BOTTOM or RelativeLayout.ALIGN_PARENT_TOP will lead you only to pain and sorrow.

Categories

Resources