SVG zoom and scroll gesture - android

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.

Related

Open ScrollView by Click

I want to open a horizontal ScrollView with images by clicking on a central image. I already have my ScrollView loading dynamically my images:
int[] images = new int[] { R.drawable.image1, R.drawable.image2, R.drawable.image3 };
LinearLayout sv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_advanced);
sv = (LinearLayout) findViewById(R.id.ScrollView);
for (int i = 0; i<images.length; i++) {
ImageView iv = new ImageView(this);
iv.setBackgroundResource(images[i]);
sv.addView(iv);
}
}
I have following problem, right now the ScrollView is already expand, but I want the ScrollView to expand when clicking on the last selected image from the ScrollView (and a default one if its the first time). I dont know if ScrollView is the right way to do that or if there is a better method for that. I already searched on Stackoverflow and found similiar questions but no of them did really fit my problem.
Hope someone can help me
If this question is already answered somewhere and I didnt found it, send me the link please.
Thanks in advance

Semi transparent Instruction activity in android

I want to display instruction activity when user opens the app for the first time. I am using shared preference for that. Whatever I am doing so far is working. But I think my way of achieving this is not right.
What I am following:
I am drawing a transparent instruction image(with instructions) in photoshop.
Checking if user is opening that page for the first time(using shared preference).
Displaying that particular image in an activity with translucent theme
private void showFrontPageGuideIfFirstTime(){
if(!prefKeeper.getBoolean(PreferenceKey.FRONT_GUIDE)){
Intent intent = new Intent(this, ShowGuide.class);
intent.putExtra(BACKGROUND_KEY, R.drawable.front_page_png);
this.startActivity(intent);
prefKeeper.putBoolean(PreferenceKey.FRONT_GUIDE, true);
}
}
And my instruction page looks something like(made in photoshop):
The Instruction Image
But I think by this way it would not work in all smart phone screens.
Where am I wrong, and what would be the best way of doing this?
Implementation as below
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:id="#+id/framelayout"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="in.excogitation.example_mvptdd.MainActivity">
<!-- Include your layout here-->
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World!"/>
</FrameLayout>
In your activity.java
public class MainActivity extends AppCompatActivity {
FrameLayout frameLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Parent FrameLayout
frameLayout = (FrameLayout) findViewById(R.id.framelayout);
// Dynamically create a relativelayout which will be appended to framelayout
final RelativeLayout relativeLayout = new RelativeLayout(getApplicationContext());
relativeLayout.setLayoutParams(new RelativeLayout.LayoutParams(ViewGroup.LayoutParams
.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
relativeLayout.setBackgroundColor(Color.DKGRAY);
relativeLayout.setAlpha(0.7f);
relativeLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// remove the whole relativelayout on click
frameLayout.removeView(relativeLayout);
}
});
RelativeLayout.LayoutParams params;
// Place 1st 30x40 ImageView at (50,60) coordinates
params = new RelativeLayout.LayoutParams(100, 100);
params.leftMargin = 20;
params.topMargin = 50;
final ImageView imageView1 = new ImageView(getApplicationContext());
imageView1.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_star));
// Add 1st imageview to relative layout
relativeLayout.addView(imageView1, params);
// Place 2nd 30x40 ImageView at (100,60) coordinates
params = new RelativeLayout.LayoutParams(120, 120);
params.leftMargin = 800;
params.topMargin = 450;
final ImageView imageView2 = new ImageView(getApplicationContext());
imageView2.setImageDrawable(getResources().getDrawable(R.drawable.ic_action_star));
// Add 2nd imageview to relative layout
relativeLayout.addView(imageView2, params);
// finally add it ot the framelayout
frameLayout.addView(relativeLayout);
}
}
Ofcourse you should modify this code with your own images and colors and interactions. Its just a simple working version that is better than loading a whole image upfront when you all you want is smaller helper images on a translucent background for the instructions.
Also you in this way you make things more Android-ish and editable. You can add more children to the relative layout like a textview to include instructions.
Screenshot on load of app and hence the relative layout as an overlay.
Screenshot on click/touch , the relative layout is removed.

How to set Background of an Class Activity

I don't have any XML-Layout's. I directly start my Activity like that
super.onCreate(savedInstanceState);
setContentView(new DrawingPanel(this));
It's a drawing App and the default Background is Black. I want to change the Background to an ImageBackground. How can I do that?
EDIT: IT'S NOT ABOUT JUST SETTING A BACKGROUND. I´ve got a SurfaceView (DrawingPanel) with a black Background by default. I want to change the black background to a Picture, so I can draw ON the picture.
// try this way,hope this will help you...
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout parent = new LinearLayout(this);
parent.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT));
parent.setBackgroundResource(R.drawable.ic_launcher); // here set your background
parent.addView(new DrawingPanel(this));
setContentView(parent);
}
I support #haresh, I think the problem occur because you are trying to load big images. Here is a good tutorial how to load large bitmaps.
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html
Bitmap background = BitmapFactory.decodeResource(getResources(), R.drawable.mypicture);
scaled = Bitmap.createScaledBitmap(background, width, height, true);
and then using
canvas.drawBitmap(scaled, 0, 0, null);
solved that problem!
Below code is working fine to set the background image.
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
ImageView imageView = new ImageView(this);
imageView.setImageResource(R.drawable.ic_launcher);
setContentView(imageView);
}
this works fine for me
logo = new ImageView(this);
logo.setImageResource(R.drawable.sync_cloud_logo);
logo.setBackgroundColor(getResources().getColor(R.color.drawer_bkground));// your color
setContentView(logo);

how to zoom a view in 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.

Using ViewGroup.addView() to add a GestureOverlayView to a SurfaceView game panel

After much help from the good people here, I finally almost got my little game panel (thats a surfaceview class) up and running with a GestureOverlayView. Through the use of addView I finally was able to add the GestureOverlayView and get it to work, the trouble is that calling this:
/** create the login form */
private ViewGroup _createGameStuffs() {
GestureOverlayView gestures = new GestureOverlayView(this);
gestures.setOrientation(gestures.ORIENTATION_VERTICAL);
gestures.setEventsInterceptionEnabled(true);
gestures.setGestureStrokeType(gestures.GESTURE_STROKE_TYPE_MULTIPLE);
gestures.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
//GestureOverlayView gestures = (GestureOverlayView) findViewById(R.id.gestures);
gestures.addOnGesturePerformedListener(this);
Panel p = new Panel(this); //my game view
panel.addView(p,0); //add it to the group
panel.addView(gestures,1); //add the gestureoverlayview i made to the group
return panel;
}
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
mLibrary = GestureLibraries.fromRawResource(this, R.raw.myspells);
// create the panel to enclose everything
View mainPanel = _createGameStuffs();
// show the panel on the screen
setContentView(mainPanel);
//setContentView(p);
}
Depending upon which index I give which view takes presedence. This leads me to believe my game panel has to be added as a child view to the GestureOverlayView, is this correct? If so, how do I get at the children views of the GestureOverlayView? Or is it the other way around, GestureOverlayView becomes a child of my main view?

Categories

Resources