// draw bottom wave with the alpha 40 canvas.drawLine(waveX1, startY, waveX1, endY, wavePaint1); // draw top wave with the alpha 60 floatwaveX2= (waveX1 + wave2Shift) % endX; canvas.drawLine(waveX2, startY, waveX2, endY, wavePaint2);
waveX1++; }
// use the bitamp to create the shader mWaveShader = newBitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.CLAMP); mViewPaint.setShader(mWaveShader); }
// sacle shader according to mWaveLengthRatio and mAmplitudeRatio // this decides the size(mWaveLengthRatio for width, mAmplitudeRatio for height) of waves mShaderMatrix.setScale( mWaveLengthRatio / DEFAULT_WAVE_LENGTH_RATIO, mAmplitudeRatio / DEFAULT_AMPLITUDE_RATIO, 0, mDefaultWaterLevel); // translate shader according to mWaveShiftRatio and mWaterLevelRatio this decides the start position(mWaveShiftRatio for x, mWaterLevelRatio for // this decides the start position(mWaveShiftRatio for x, mWaterLevelRatio for y) of waves mShaderMatrix.postTranslate( mWaveShiftRatio * getWidth(), (DEFAULT_WATER_LEVEL_RATIO - mWaterLevelRatio) * getHeight());
// assign matrix to invalidate the shader mWaveShader.setLocalMatrix(mShaderMatrix);
// vertical animation. // water level increases from 0 to center of WaveView ObjectAnimatorwaterLevelAnim= ObjectAnimator.ofFloat( mWaveView, "waterLevelRatio", 0f, 0.5f); waterLevelAnim.setDuration(10000); waterLevelAnim.setInterpolator(newDecelerateInterpolator()); animators.add(waterLevelAnim);