LiveWallpaper背景 [英] LiveWallpaper Background

查看:235
本文介绍了LiveWallpaper背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有在preVIEW动态壁纸问题mode.ie墙纸图像在横向上portrait.i mode.it的伟大工程,不适合也需要用help.hope你会帮我,我增加了$ C $ç

RajawaliRenderer.java

 公共类RipplesRenderer扩展RajawaliRenderer {
    私人最终诠释NUM_CUBES_H = 4;
    私人最终诠释NUM_CUBES_V = 4;
    私人最终诠释NUM_CUBES = NUM​​_CUBES_H * NUM_CUBES_V;
    //私人Animation3D [] mAnims;
    私人TouchRippleFilter MFILTER;
    私人长期frameCount;
    私人最终诠释QUAD_SEGMENTS = 40;
    INT mScreenHeight,
    mScreenWeight;
    Gallery_Activity毫米;
    布尔flag_check = FALSE;
    INT POS = 0;
    INT viewBackgroundImageName;
    位图纹理;
    SimpleMaterial planeMat;
    INT randPosition = 1;    INT change_value;
    INT Ripple_number,速度1;
    preferences preferences;    私人MediaPlayer的myplayer;
    私人布尔的声音;    公共RipplesRenderer(上下文的背景下){
        超级(上下文);
        setFrameRate(50);
        this.mContext =背景;        randPosition = BitmapUpdate.randomGenerator;
        质地= BitmapFactory.de codeResource(mContext.getResources(),R.drawable.gthree_one);
        //sp=mContext.getShared$p$pferences(\"wallpapersettings\",0);
        preferences =新的preferences(mContext);
    }    保护无效initScene(){        如果(randPosition!= 1){
            质地= BitmapUpdate.bit;
        }        mCamera.setPosition(0,0,-9);        平行光灯=新的平行光(0,0,1);
        light.setPower(1F);        BaseObject3D组=新BaseObject3D();
        DiffuseMaterial材料=新DiffuseMaterial();
        material.setUseColor(真);
        mScreenHeight = GNWallpaper.hieght;        mScreenWeight = GNWallpaper.weight;
        随机RND =新的随机();        planeMat =新SimpleMaterial();
        架专机=新飞机(9,7,1,1);        //架专机=新飞机(4,4,1,1);
        plane.setRotZ(-90);
        plane.setScale(1.0F);
        plane.setMaterial(planeMat);
        的addChild(平面);        MFILTER =新TouchRippleFilter();        mPostProcessingRenderer.setQuadSegments(QUAD_SEGMENTS);
        mPostProcessingRenderer.setQuality(PostProcessingQuality.MEDIUM);
        addPostProcessingFilter(MFILTER);
    }    公共无效onSurfaceCreated(GL10 GL,EGLConfig配置){
        如果(POS!= com.themebowlapp.galaxynote3livewallpaper.Gallery_Activity.wallpaper_position || randPosition!= BitmapUpdate.randomGenerator){
            质地= BitmapUpdate.bit;
            POS = com.themebowlapp.galaxynote3livewallpaper.Gallery_Activity.wallpaper_position;
            randPosition = BitmapUpdate.randomGenerator;
        }        Ripple_number = preferences.getSpeed​​_controler();        速度1 = Ripple_number * 100;
        super.onSurfaceCreated(GL,配置);
    }    公共无效onDrawFrame(GL10 glUnused){
        super.onDrawFrame(glUnused);        mFilter.setTime((浮点)frameCount ++ * .05f);
    }    公共无效onSurfaceChanged(GL10 GL,诠释的宽度,高度INT){
        super.onSurfaceChanged(GL,宽度,高度);
        mFilter.setScreenSize(宽度,高度);
        mFilter.setRippleSize((40 +速度1));
        planeMat.addTexture(mTextureManager.addTexture(纹理));
    }    公共无效setTouch(浮法X,浮法Y){
        mFilter.addTouch(X,Y,frameCount * .05f);
    }    @覆盖
    公共无效onTouchEvent(MotionEvent事件){
        最终诠释行动= event.getAction();        如果(event.getAction()== MotionEvent.ACTION_DOWN){
            //声音
            myplayer = MediaPlayer.create(的getContext(),R.raw.water_drop);
            myplayer.setVolume(100,100);
            myplayer.start();            myplayer.setOnCompletionListener(新OnCompletionListener(){                @覆盖
                公共无效onCompletion(MediaPlayer的myplayer){
                    myplayer.release();
                }
            });            setTouch(event.getX()/ mScreenWeight,1.0F - (event.getY()/ mScreenHeight));
        }        super.onTouchEvent(事件);
    }
}

Settings.java

 公共类设置延伸活动{
    公众的TextView SettingTextObj,BackgroundTextObj;
    私人的RelativeLayout chose_background;
    公共preferences preferences;
    上下文CONT =这一点;
    私人复选框soundcheckbox;
    私人字符串preFRENCES_NAME;
    共享preferences设置;
    //专用按钮choosebackground;    @覆盖
    保护无效的onCreate(捆绑savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.settings);
        chose_background =(RelativeLayout的)findViewById(R.id.BackgroundLayoutId);
        BackgroundTextObj =(的TextView)findViewById(R.id.backgroundTxtViewId);        soundcheckbox =(复选框)findViewById(R.id.checkBox1);
        设置= getShared preferences(preFRENCES_NAME,0);
        布尔=器isChecked settings.getBoolean(cbx1_ischecked,FALSE);
        soundcheckbox.setChecked(器isChecked);        soundcheckbox.setOnCheckedChangeListener(新OnCheckedChangeListener(){            私人MediaPlayer的myplayer;
            @覆盖
            公共无效onCheckedChanged(CompoundButton为arg0,布尔器isChecked){
                编辑编辑= getShared preferences(preFRENCES_NAME,0).edit();
                editor.putBoolean(cbx1_ischecked,器isChecked);
                editor.commit();
                Toast.makeText(getApplicationContext(),检查,Toast.LENGTH_SHORT).show();
                myplayer = MediaPlayer.create(getBaseContext(),R.raw.water_drop);
                myplayer.setVolume(100,100);
                myplayer.start();
            }
        });
        preferences =新的preferences(续)        chose_background.setOnClickListener(新OnClickListener(){
            @覆盖
            公共无效的onClick(视图v){
                最终的String []项目= {手机图库,选择背景};                AlertDialog.Builder建设者=新AlertDialog.Builder(
                        Settings.this);
                builder.setTitle(选择一个背景);
                builder.setItems(项目,新DialogInterface.OnClickListener(){
                    @覆盖
                    公共无效的onClick(DialogInterface对话,诠释项){
                        如果(项目[项目] .equals(项目[0])){
                            startActivity(新意图(Settings.this,PhoneGallery_Activity.class));
                        }其他{
                            startActivity(新意图(Settings.this,Gallery_Activity.class));
                        }
                    }
                });                AlertDialog警报= builder.create();
                alert.show();
            }
        });
    }    @覆盖
    公共布尔onCreateOptionsMenu(菜单菜单){
        //充气菜单;如果是present这增加了项目操作栏。
        。getMenuInflater()膨胀(R.menu.settings,菜单);
        返回true;
    }
}

GNWallpaper.java

 公共类GNWallpaper扩展壁纸{
    私人RipplesRenderer mRenderer;
    私人字符串imageBg;
    私人诠释cvwidth;
    私人诠释cvheight;
    私人诠释visibleWidth;
    私人位图BG;
    私人字符串LoadText;
    私人布尔的声音;
    私人MediaPlayer的myplayer;
    公共静态窗口管理器显示;
    静态INT的高度,宽度;    //私人整数[] = mImageIds {R.drawable.gthree_one,R.drawable.gthree_two,R.drawable.gthree_three,R.drawable.gthree_four,R.drawable.gthree_five,R.drawable.gthree_six,};
    私人诠释的位置;    公共引擎onCreateEngine(){
        显示=(窗口管理器)getSystemService(Context.WINDOW_SERVICE);        身高= display.getDefaultDisplay()的getHeight()。
        宽度= display.getDefaultDisplay()的getWidth()。
        mRenderer =新RipplesRenderer(本);        //Log.i(\"shibbu,你好);
        返回新WallpaperEngine(this.getShared preferences(SHARED_ preFS_NAME,
                Context.MODE_PRIVATE),getBaseContext(),mRenderer,FALSE);
    }    公共无效onShared preferenceChanged(共享preferences preFS,
            字符串键){        imageBg = prefs.getString(image_custom,坏形象);
        的getBackground();        听起来= prefs.getBoolean(pref_sound,FALSE);        // //声音
        //声音= prefs.getBoolean(pref_sound,FALSE);
    }    无效的getBackground(){
        如果(this.cvwidth == 0 || this.cvheight == 0 || this.visibleWidth == 0){
            this.cvwidth = 1290;
            this.cvheight = 800;
            this.visibleWidth = 1290;
        }        如果(新文件(imageBg).exists()){
            INT采样大小= 1;            做{
                BitmapFactory.Options选项=新BitmapFactory.Options();
                options.inJustDe codeBounds = TRUE;
                BG = BitmapFactory.de codeFILE(imageBg,期权);
                采样大小=(INT)(Math.ceil(options.outWidth /(this.visibleWidth * 2))* 2);
                options.inJustDe codeBounds = FALSE;
                尝试{
                    options.inSampleSize =采样大小;
                    BG = BitmapFactory.de codeFILE(imageBg,期权);
                }赶上(OutOfMemoryError异常五){
                    采样大小=采样大小* 2;
                }
            }而(BG == NULL);            BG = Bitmap.createScaledBitmap(BG,this.cvwidth / 2,this.cvheight,真正的);
        }其他{
            BG = BitmapFactory.de codeResource(getResources(),R.drawable.gthree_one);
            // BG = BitmapFactory.de codeResource(getResources(),mImageIds [位置]);
            //位置++;
            BG = Bitmap.createScaledBitmap(BG,this.cvwidth / 2,this.cvheight,真正的);
            LoadText =;
        }
    }
}


解决方案

转寄此link.It将帮助您切换到横向视图..
http://tips4android.blogspot.in/2012 /01/android-tips-how-to-get-screen.html

i have problem with live wallpaper on preview mode.ie the wallpaper image doesn't fit well in landscape mode.it works great on portrait.i need your help.hope you would help me.i have added code

RajawaliRenderer.java

public class RipplesRenderer extends RajawaliRenderer {
    private final int NUM_CUBES_H = 4;
    private final int NUM_CUBES_V = 4;
    private final int NUM_CUBES = NUM_CUBES_H * NUM_CUBES_V;
    //private Animation3D[] mAnims;
    private TouchRippleFilter mFilter;
    private long frameCount;
    private final int QUAD_SEGMENTS = 40;
    int mScreenHeight,
    mScreenWeight;
    Gallery_Activity mm;
    boolean flag_check = false;
    int pos = 0;
    int viewBackgroundImageName;
    Bitmap texture;
    SimpleMaterial planeMat;
    int randPosition=1;

    int change_value;
    int Ripple_number,speed1;
    Preferences preferences;

    private MediaPlayer myplayer;
    private boolean sound;

    public RipplesRenderer(Context context) {
        super(context);
        setFrameRate(50);
        this.mContext=context;

        randPosition = BitmapUpdate.randomGenerator;
        texture = BitmapFactory.decodeResource(mContext.getResources(), R.drawable.gthree_one);
        //sp=mContext.getSharedPreferences("wallpapersettings",0);
        preferences=new Preferences(mContext);
    }

    protected void initScene() {

        if(randPosition!=1) {
            texture = BitmapUpdate.bit;
        }

        mCamera.setPosition(0, 0, -9);

        DirectionalLight light = new DirectionalLight(0, 0, 1);
        light.setPower(1f);

        BaseObject3D group = new BaseObject3D();
        DiffuseMaterial material = new DiffuseMaterial();
        material.setUseColor(true);
        mScreenHeight = GNWallpaper.hieght;

        mScreenWeight = GNWallpaper.weight;
        Random rnd = new Random();        

        planeMat = new SimpleMaterial();
        Plane plane=new Plane(9,7,1,1);

        //Plane plane = new Plane(4, 4, 1, 1);
        plane.setRotZ(-90);
        plane.setScale(1.0f);
        plane.setMaterial(planeMat);
        addChild(plane);

        mFilter = new TouchRippleFilter();

        mPostProcessingRenderer.setQuadSegments(QUAD_SEGMENTS);
        mPostProcessingRenderer.setQuality(PostProcessingQuality.MEDIUM);
        addPostProcessingFilter(mFilter);
    }

    public void onSurfaceCreated(GL10 gl, EGLConfig config) {
        if (pos != com.themebowlapp.galaxynote3livewallpaper.Gallery_Activity.wallpaper_position || randPosition != BitmapUpdate.randomGenerator) {
            texture = BitmapUpdate.bit;
            pos = com.themebowlapp.galaxynote3livewallpaper.Gallery_Activity.wallpaper_position;
            randPosition = BitmapUpdate.randomGenerator;
        }

        Ripple_number=preferences.getSpeed_controler();

        speed1=Ripple_number*100;
        super.onSurfaceCreated(gl, config);
    }

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

        mFilter.setTime((float) frameCount++ *.05f);
    }

    public void onSurfaceChanged(GL10 gl, int width, int height) {
        super.onSurfaceChanged(gl, width, height);
        mFilter.setScreenSize(width, height);
        mFilter.setRippleSize((40+speed1));
        planeMat.addTexture(mTextureManager.addTexture(texture));
    }

    public void setTouch(float x, float y) {
        mFilter.addTouch(x, y, frameCount *.05f);
    }

    @Override
    public void  onTouchEvent(MotionEvent event) {
        final int action = event.getAction();

        if(event.getAction() == MotionEvent.ACTION_DOWN) {            
            //sound
            myplayer = MediaPlayer.create(getContext(), R.raw.water_drop);
            myplayer.setVolume(100, 100);
            myplayer.start();

            myplayer.setOnCompletionListener(new OnCompletionListener() {

                @Override
                public void onCompletion(MediaPlayer myplayer) {
                    myplayer.release();
                } 
            });

            setTouch(event.getX() / mScreenWeight, 1.0f - (event.getY() / mScreenHeight));
        }

        super.onTouchEvent(event);
    }
}

Settings.java

public class Settings extends Activity  {
    public TextView SettingTextObj, BackgroundTextObj;
    private RelativeLayout chose_background;
    public Preferences preferences;
    Context cont = this;
    private CheckBox soundcheckbox;
    private String PREFRENCES_NAME;
    SharedPreferences settings;
    //    private Button choosebackground;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.settings);
        chose_background = (RelativeLayout) findViewById(R.id.BackgroundLayoutId);
        BackgroundTextObj = (TextView) findViewById(R.id.backgroundTxtViewId);

        soundcheckbox = (CheckBox)findViewById(R.id.checkBox1);
        settings = getSharedPreferences(PREFRENCES_NAME, 0);
        Boolean isChecked = settings.getBoolean("cbx1_ischecked", false);
        soundcheckbox.setChecked(isChecked);

        soundcheckbox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

            private MediaPlayer myplayer;
            @Override
            public void onCheckedChanged(CompoundButton arg0, boolean isChecked) {
                Editor editor = getSharedPreferences(PREFRENCES_NAME, 0).edit();
                editor.putBoolean("cbx1_ischecked", isChecked);
                editor.commit();
                Toast.makeText(getApplicationContext(), "Check", Toast.LENGTH_SHORT).show();
                myplayer = MediaPlayer.create(getBaseContext(), R.raw.water_drop);
                myplayer.setVolume(100, 100);
                myplayer.start();
            }
        });


        preferences = new Preferences(cont);

        chose_background.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                final String[] items = { "Phone Gallery", "Choose Background" };

                AlertDialog.Builder builder = new AlertDialog.Builder(
                        Settings.this);
                builder.setTitle("Pick a Background");
                builder.setItems(items, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int item) {
                        if (items[item].equals(items[0])) {
                            startActivity(new Intent(Settings.this, PhoneGallery_Activity.class));
                        } else {
                            startActivity(new Intent(Settings.this, Gallery_Activity.class));
                        }
                    }
                });

                AlertDialog alert = builder.create();
                alert.show();
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.settings, menu);
        return true;
    }
}

GNWallpaper.java

public class GNWallpaper extends Wallpaper {
    private RipplesRenderer mRenderer;
    private  String imageBg;
    private int cvwidth;
    private int cvheight;
    private int visibleWidth;
    private Bitmap bg;
    private String LoadText;
    private boolean sound;
    private MediaPlayer myplayer;
    public static WindowManager display;
    static int height,width;

    //private Integer[] mImageIds = { R.drawable.gthree_one,R.drawable.gthree_two,R.drawable.gthree_three, R.drawable.gthree_four, R.drawable.gthree_five, R.drawable.gthree_six,};
    private int position;

    public Engine onCreateEngine() {
        display =(WindowManager) getSystemService(Context.WINDOW_SERVICE);

        height= display.getDefaultDisplay().getHeight();
        width= display.getDefaultDisplay().getWidth();
        mRenderer = new RipplesRenderer(this);

        //Log.i("shibbu"," hello");
        return new WallpaperEngine(this.getSharedPreferences(SHARED_PREFS_NAME,
                Context.MODE_PRIVATE), getBaseContext(), mRenderer, false);
    }

    public void onSharedPreferenceChanged(SharedPreferences prefs,
            String key) {

        imageBg = prefs.getString("image_custom", "Bad Image");
        getBackground();

        sound=prefs.getBoolean("pref_sound", false);

        //          //sound
        //            sound=prefs.getBoolean("pref_sound", false);
    }

    void getBackground() {
        if (this.cvwidth == 0 || this.cvheight == 0 || this.visibleWidth == 0) {
            this.cvwidth = 1290;
            this.cvheight = 800;
            this.visibleWidth = 1290;
        }

        if(new File(imageBg).exists()) {
            int SampleSize = 1;

            do {
                BitmapFactory.Options options = new BitmapFactory.Options();
                options.inJustDecodeBounds = true;
                bg = BitmapFactory.decodeFile(imageBg, options);
                SampleSize = (int) (Math.ceil(options.outWidth/(this.visibleWidth * 2))*2);
                options.inJustDecodeBounds = false;
                try {
                    options.inSampleSize = SampleSize;
                    bg = BitmapFactory.decodeFile(imageBg, options);
                } catch (OutOfMemoryError e) {
                    SampleSize = SampleSize * 2;
                }
            } while (bg == null);

            bg = Bitmap.createScaledBitmap(bg, this.cvwidth/2, this.cvheight, true);
        } else {
            bg = BitmapFactory.decodeResource(getResources(), R.drawable.gthree_one);
            //bg = BitmapFactory.decodeResource(getResources(), mImageIds[position]);
            //position++;
            bg = Bitmap.createScaledBitmap(bg, this.cvwidth/2, this.cvheight, true);
            LoadText = "";    
        }
    }
}

解决方案

Refer this link.It will help you to change to landscape view.. http://tips4android.blogspot.in/2012/01/android-tips-how-to-get-screen.html

这篇关于LiveWallpaper背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆