Giter VIP home page Giter VIP logo

Comments (15)

ChristofferGreen avatar ChristofferGreen commented on June 7, 2024

Didf you take a look at the rajawali examples to see how its done?

https://github.com/MasDennis/RajawaliExamples

from rajawali.

power7714 avatar power7714 commented on June 7, 2024

Yes. I'm getting getWindowManager is undefined for wallpaper
and onTouchEvent(MotionEvent) is undefined
On May 29, 2012 12:43 AM, "Christoffer Green" <
[email protected]>
wrote:

Didf you take a look at the rajawali examples to see how its done?

https://github.com/MasDennis/RajawaliExamples


Reply to this email directly or view it on GitHub:
#40 (comment)

from rajawali.

ChristofferGreen avatar ChristofferGreen commented on June 7, 2024

do the examples compile for you?

from rajawali.

MasDennis avatar MasDennis commented on June 7, 2024

With wallpapers it works a bit different. There's no need to implement "OnTouchListener" etc. Just override the onTouchEvent(event) method in your class that extends RajawaliRenderer:

@Override
public void onTouchEvent(MotionEvent event) {
// ... do what ever you want ...
}

See also:
https://github.com/MasDennis/Rajawali/blob/master/src/rajawali/wallpaper/Wallpaper.java#L309

from rajawali.

power7714 avatar power7714 commented on June 7, 2024

What about getWindowManager being undefined? Is that also used differently
for wallpapers?
On May 29, 2012 5:38 AM, "Dennis Ippel" <
[email protected]>
wrote:

With wallpapers it works a bit different. There's no need to implement
"OnTouchListener" etc. Just override the onTouchEvent(event) method in your
class that extends RajawaliRenderer:

@Override
public void onTouchEvent(MotionEvent event) {
// ... do what ever you want ...
}

See also:

https://github.com/MasDennis/Rajawali/blob/master/src/rajawali/wallpaper/Wallpaper.java#L309


Reply to this email directly or view it on GitHub:
#40 (comment)

from rajawali.

MasDennis avatar MasDennis commented on June 7, 2024

http://stackoverflow.com/questions/9052822/where-do-i-use-getwindowmanager-within-live-wallpaper

mContext = getBaseContext();
DisplayMetrics DisplayMetrics = new DisplayMetrics();
DisplayMetrics = mContext.getResources().getDisplayMetrics();
mScreenWidth = DisplayMetrics.widthPixels;
mSreenHeight = DisplayMetrics.heightPixels;

from rajawali.

power7714 avatar power7714 commented on June 7, 2024

mSurfaceView.onTouchListener(this); is getting the unreachable code error now. Everything else is fine.

If I use the eclipse recommended fix and remove it, the mContext lines of code get errors.

from rajawali.

MasDennis avatar MasDennis commented on June 7, 2024

Yeah, so in a wallpaper "this" is the Context. So it should be:

DisplayMetrics DisplayMetrics = new DisplayMetrics();
DisplayMetrics = getResources().getDisplayMetrics();
mScreenWidth = DisplayMetrics.widthPixels;
mSreenHeight = DisplayMetrics.heightPixels;

from rajawali.

power7714 avatar power7714 commented on June 7, 2024

mScreenWidth and mScreenHeight cannot be resolved to a variable

Would I eliminate

private Point mScreenSize;

What would be used for the screen height and width instead?
On May 30, 2012 2:45 AM, "Dennis Ippel" <
[email protected]>
wrote:

Yeah, so in a wallpaper "this" is the Context. So it should be:

DisplayMetrics DisplayMetrics = new DisplayMetrics();
DisplayMetrics = getResources().getDisplayMetrics();
mScreenWidth = DisplayMetrics.widthPixels;
mSreenHeight = DisplayMetrics.heightPixels;


Reply to this email directly or view it on GitHub:
#40 (comment)

from rajawali.

MasDennis avatar MasDennis commented on June 7, 2024

Yeah, you don't need all that. Like I said before, you only need this bit of code in your renderer class:


@Override
public void onTouchEvent(MotionEvent event) {
        // ... do what ever you want ...
}

The rest is all taken care of by the Wallpaper class.
So to spell it out literally here's the whole class:


package com.mydomain.wallpapers.mywallpaper;

import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.opengles.GL10;

import rajawali.animation.Animation3D;
import rajawali.animation.RotateAnimation3D;
import rajawali.lights.ALight;
import rajawali.lights.DirectionalLight;
import rajawali.materials.DiffuseMaterial;
import rajawali.math.Number3D;
import rajawali.primitives.Cube;
import rajawali.renderer.RajawaliRenderer;
import rajawali.util.RajLog;
import android.content.Context;
import android.view.MotionEvent;
import android.view.animation.AccelerateDecelerateInterpolator;

public class MyWallpaperRenderer extends RajawaliRenderer {
    private Animation3D mAnim;
    
    public MyWallpaperRenderer(Context context) {
        super(context);
        setFrameRate(60);
    }
    
    public void initScene() {
        ALight light = new DirectionalLight();
        light.setPower(1);
        light.setPosition(0, 0, -5);
        mCamera.setPosition(0, 0, -7);

        Cube cube = new Cube(1);
        DiffuseMaterial material = new DiffuseMaterial();
        material.setUseColor(true);
        cube.setMaterial(material);
        cube.addLight(light);
        cube.setColor(0xff00ff00);
        addChild(cube);
        
        Number3D axis = new Number3D(3, 1, 6);
        axis.normalize();
        mAnim = new RotateAnimation3D(axis, 360);
        mAnim.setDuration(8000);
        mAnim.setRepeatCount(Animation3D.INFINITE);
        mAnim.setInterpolator(new AccelerateDecelerateInterpolator());
        mAnim.setTransformable3D(cube);
    }
    
    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        super.onSurfaceCreated(gl, config);
        mAnim.start();
    }
    
    public void onOffsetsChanged(float xOffset, float yOffset, float xOffsetStep, float yOffsetStep, int xPixelOffset, int yPixelOffset) {
        mCamera.setRotY(xOffset * 10);
    }
    
    // THIS IS WHAT YOU NEED!!!!!!!!!!!!!!!!!!!!!!!!

    public void onTouchEvent(MotionEvent event) {
        RajLog.i("TOUCH!!!!!!!!!");
    }       

    public void onDrawFrame(GL10 glUnused) {
        super.onDrawFrame(glUnused);
    }
}

from rajawali.

power7714 avatar power7714 commented on June 7, 2024

I appreciate your help as well as others but here is where I am getting
errors. My renderer is fine.

package com.pspdemocenter.graffitilwp;

import rajawali.wallpaper.Wallpaper;
import rajawali.filters.TouchRippleFilter;
import android.content.Context;
import android.graphics.Point;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.MotionEvent;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.WindowManager;
import android.view.Gravity;

public class GraffitiLWP extends Wallpaper implements OnTouchListener {
private GraffitiLWPRenderer mRenderer;
private Point mScreenSize;
private SurfaceView mSurfaceView;
//private int mScreenWidth;
//private Context mContext;
//private int mSreenHeight;

public Engine onCreateEngine() {
mRenderer = new GraffitiLWPRenderer(this);
return new WallpaperEngine(this.getSharedPreferences(SHARED_PREFS_NAME,
Context.MODE_PRIVATE), getBaseContext(), mRenderer);
mSurfaceView.setOnTouchListener(this);

DisplayMetrics DisplayMetrics = new DisplayMetrics();
DisplayMetrics = getResources().getDisplayMetrics();
mScreenWidth = DisplayMetrics.widthPixels;
mSreenHeight = DisplayMetrics.heightPixels;
}
public void onTouchEvent(MotionEvent event) {
//if(event.getAction() == MotionEvent.ACTION_DOWN)
//{
mRenderer.setTouch(event.getX() / mScreenSize.x, 1.0f - (event.getY() /
mScreenSize.y));
//}
//super.onTouchEvent(event);
}
}

from rajawali.

MasDennis avatar MasDennis commented on June 7, 2024

Like I said before, remove the "implements OnTouchListener" from the class declaration.
To save me some time, just go over the code I posted carefully and compare it to your own class. It's all in the details ...

from rajawali.

mrugeshbapotra avatar mrugeshbapotra commented on June 7, 2024

Hi,
I have tried your code for wallpaper but it not called ontouchevent from GraffitiLWP . so how can i do it? thanks in advanced.

Thanks,

from rajawali.

flynnfernandes avatar flynnfernandes commented on June 7, 2024

I need some help

after writing this code in render class

@OverRide
public void onTouchEvent(MotionEvent event) {
// ... do what ever you want ...
}

where to write this line " mSurfaceView.setOnTouchListener(this); " in which method in render class?

from rajawali.

jwoolston avatar jwoolston commented on June 7, 2024

@flynnfernandes This issue is very old and Im not even certain it applies to your question. Please create a new issue with more context for what you are asking.

from rajawali.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.