انجمن سایت کلیدستان


رتبه موضوع:
  • 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
راهنمایی در مورد یک پروژه در سایت کلیدستان

راهنمایی در مورد یک پروژه در سایت کلیدستان

#1
سلام در پروژه زیر که در سایت کلیدستان قرار گرفته چطوری میشه اندازه دانه های برف رو بزرگترر کرد..
و نکته بعدی اینکه چطوری میشه جهت ریزش برف و .. رو تغییر داد..
ممنون میشم بزرگواران پاسخ دهید Heart 

http://www.kelidestan.com/keys/keys.php?key=2875
پاسخ

راهنمایی در مورد یک پروژه در سایت کلیدستان

#2
اینها اکتیویتی های این پروژه هست..نمدونم کدوم قسمتش واسه بزرگتر کردن دانه های برف هست
.................
package eu.masconsult.android.androsnow;
import android.app.Activity;
import android.os.Bundle;
public class AndroSnowActivity extends Activity {
    
    SnowView view;
    
    
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
       view = (SnowView) findViewById(R.id.snowView);
    }
    
    @Override
    protected void onPause() {
        view.stopHandler();
        super.onPause();
    }
    
    @Override
    protected void onResume() {
        view.startHandler();
        super.onResume();
    }
    
    
}
........................................................
package eu.masconsult.android.androsnow;
import java.util.ArrayList;
import java.util.Random;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Bitmap.Config;
import android.os.Handler;
import android.service.wallpaper.WallpaperService;
import android.view.SurfaceHolder;
public class AndroSnowService extends WallpaperService {
    private final Handler mHandler = new Handler();
    @Override
    public Engine onCreateEngine() {
        return new CubeEngine();
    }
    
    class CubeEngine extends Engine {
        private Bitmap bitmap;
        /**
         * Everyone needs a little randomness in their life
         */
        private final Random RNG = new Random();
        
        private ArrayList<Coordinate> snowFlakes = new ArrayList<Coordinate>(100);
        
        private boolean mVisible;
        private final Runnable mRefreshSnow = new Runnable() {
            public void run() {
                drawSnow();
            }
        };
        @Override
        public void onDestroy() {
            super.onDestroy();
            mHandler.removeCallbacks(mRefreshSnow);
        }
        
        @Override
        public void onCreate(SurfaceHolder surfaceHolder) {
            bitmap = Bitmap.createBitmap(getApplicationContext().getWallpaperDesiredMinimumWidth(), getApplicationContext().getWallpaperDesiredMinimumHeight(), Config.ARGB_4444);
            bitmap.eraseColor(Color.BLACK);
            super.onCreate(surfaceHolder);
        }
        @Override
        public void onVisibilityChanged(boolean visible) {
            mVisible = visible;
            if (visible) {
                drawSnow();
            } else {
                mHandler.removeCallbacks(mRefreshSnow);
            }
        }
        
        @Override
        public void onSurfaceDestroyed(SurfaceHolder holder) {
            super.onSurfaceDestroyed(holder);
            mVisible = false;
            mHandler.removeCallbacks(mRefreshSnow);
        }
        
        @Override
        public void onDesiredSizeChanged(int desiredWidth, int desiredHeight) {
            super.onDesiredSizeChanged(desiredWidth, desiredHeight);
            snowFlakes.clear();
            bitmap = Bitmap.createBitmap(desiredWidth, desiredHeight, Config.ARGB_4444);
            bitmap.eraseColor(Color.RED);
            System.out.println("asdadasdadasdasdadasssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss");
        }
        void drawSnow() {
            final SurfaceHolder holder = getSurfaceHolder();
            Canvas c = null;
            try {
                c = holder.lockCanvas();
                if (c != null) {
                    update©;
                }
            } finally {
                if (c != null) holder.unlockCanvasAndPost©;
            }
            // Reschedule the next redraw
            mHandler.removeCallbacks(mRefreshSnow);
            if (mVisible) {
                mHandler.postDelayed(mRefreshSnow, 10);
            }
        }
        void update(Canvas c) {
            
            snowFlakes.add(new Coordinate(RNG.nextInt(c.getWidth()), -1));
            int i=0;
            while (i < snowFlakes.size()) {
                final Coordinate flake = snowFlakes.get(i);
                int diff = RNG.nextInt(3)-1;
                if (flake.x+diff < 0) diff = 0;
                if (flake.x+diff >= c.getWidth()) diff = 0;
                if (flake.y+1 >= c.getHeight() || bitmap.getPixel(flake.x+diff, flake.y+1) == Color.WHITE) {
                    snowFlakes.remove(i);
                    continue;
                }
                if (flake.y >= 0)
                    bitmap.setPixel(flake.x, flake.y, Color.BLACK);
                flake.x += diff;
                flake.y++;
                bitmap.setPixel(flake.x, flake.y, Color.WHITE);
                i++;
            }
            
            c.drawBitmap(bitmap, 0, 0, new Paint());
        }
    }
    
    /**
     * Simple class containing two integer values and a comparison function.
     * There's probably something I should use instead, but this was quick and
     * easy to build.
     *
     */
    private class Coordinate {
        public int x;
        public int y;
        public Coordinate(int newX, int newY) {
            x = newX;
            y = newY;
        }
        public boolean equals(Coordinate other) {
            if (x == other.x && y == other.y) {
                return true;
            }
            return false;
        }
        @Override
        public String toString() {
            return "Coordinate: [" + x + "," + y + "]";
        }
    }
}

..............................................
package eu.masconsult.android.androsnow;
import java.util.ArrayList;
import java.util.Random;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Bitmap.Config;
import android.os.Handler;
import android.os.Message;
import android.util.AttributeSet;
import android.view.View;
public class SnowView extends View {
    private Bitmap bitmap;
    /**
     * Everyone needs a little randomness in their life
     */
    private static final Random RNG = new Random();
    /**
     * Create a simple handler that we can use to cause animation to happen. We
     * set ourselves as a target and we can use the sleep() function to cause an
     * update/invalidate to occur at a later date.
     */
    private RefreshHandler mRedrawHandler = new RefreshHandler();
    private ArrayList<Coordinate> snowFlakes = new ArrayList<Coordinate>(100);
    class RefreshHandler extends Handler {
        @Override
        public void handleMessage(Message msg) {
            SnowView.this.update();
            SnowView.this.invalidate();
        }
        public void sleep(long delayMillis) {
            this.removeMessages(0);
            sendMessageDelayed(obtainMessage(0), delayMillis);
        }
    };
    public SnowView(Context context) {
        super(context);
    }
    public void update() {
        snowFlakes.add(new Coordinate(RNG.nextInt(getWidth()), -1));
        int i = 0;
        while (i < snowFlakes.size()) {
            final Coordinate flake = snowFlakes.get(i);
            int diff = RNG.nextInt(3) - 1;
            if (flake.x + diff < 0)
                diff = 0;
            if (flake.x + diff >= getWidth())
                diff = 0;
            if (flake.y + 1 >= getHeight()
                    || bitmap.getPixel(flake.x + diff, flake.y + 1) == Color.WHITE) {
                snowFlakes.remove(i);
                continue;
            }
            if (flake.y >= 0)
                bitmap.setPixel(flake.x, flake.y, Color.BLACK);
            flake.x += diff;
            flake.y++;
            bitmap.setPixel(flake.x, flake.y, Color.WHITE);
            i++;
        }
        if (mRedrawHandler != null)
            mRedrawHandler.sleep(10);
    }
    public SnowView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }
    public SnowView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }
    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        bitmap = Bitmap.createBitmap(getWidth(), getHeight(), Config.ARGB_4444);
        bitmap.eraseColor(Color.BLACK);
        update();
    }
    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
        Paint paint = new Paint();
        canvas.drawBitmap(bitmap, 0, 0, paint);
    }
    public void stopHandler() {
        mRedrawHandler = null;
    }
    public void startHandler() {
        mRedrawHandler = new RefreshHandler();
    }
    /**
     * Simple class containing two integer values and a comparison function.
     * There's probably something I should use instead, but this was quick and
     * easy to build.
     *
     */
    private class Coordinate {
        public int x;
        public int y;
        public Coordinate(int newX, int newY) {
            x = newX;
            y = newY;
        }
        public boolean equals(Coordinate other) {
            if (x == other.x && y == other.y) {
                return true;
            }
            return false;
        }
        @Override
        public String toString() {
            return "Coordinate: [" + x + "," + y + "]";
        }
    }
}
پاسخ
 سپاس شده توسط شماره مجازی امارات ، تلگرام ضد فیلتر 2023


پرش به انجمن:


کاربران در حال بازدید این موضوع: 1 مهمان