public class MainActivity extends ActivityGroup {

private FanShapedView fanShapedView;

private FanShapedHideView fanShapedHideView;

private LinearLayout eachLayout;

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

this.requestWindowFeature(Window.FEATURE_NO_TITLE);

getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

setContentView(R.layout.main);

eachLayout = (LinearLayout) findViewById(R.id.each_layout);

fanShapedView = (FanShapedView) findViewById(R.id.fanshaped);

fanShapedHideView = (FanShapedHideView) findViewById(R.id.fanshapedhide);

eachLayout.addView(getLocalActivityManager().startActivity("contact",

new Intent(MainActivity.this, ContactActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)).getDecorView());

Animation scaleIn = AnimationUtils.loadAnimation(this, R.anim.scale_in);

fanShapedView.startAnimation(scaleIn);

setListener();

}

private void setListener() {

fanShapedView.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

if (fanShapedView.isStartActivity()) {

String module = fanShapedView.getFirstItem();

Intent intent = new Intent();

intent.setAction(ContactActivity.ACTION_3D);

intent.putExtra("orientation", FanShapedView.orient);

intent.putExtra("module", module);

sendBroadcast(intent);

}else{

Animation scaleOut = AnimationUtils.loadAnimation(MainActivity.this, R.anim.scale_out);

fanShapedView.startAnimation(scaleOut);

fanShapedView.setVisibility(View.INVISIBLE);

fanShapedHideView.setShowAction(ShowOrHideAction.show);

fanShapedHideView.setCurrentModule(fanShapedView.getFirstBitmap());

fanShapedHideView.setVisibility(View.VISIBLE);

}

}

});

fanShapedHideView.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

fanShapedHideView.show(fanShapedView);

fanShapedHideView.setCurrentModule(null);

fanShapedHideView.setVisibility(View.INVISIBLE);

}

});

}

@Override

protected void onDestroy() {

super.onDestroy();

fanShapedView.recycle();

fanShapedHideView.recycle();

System.exit(0);}}






public class SoundManager {
private Context context;
private SoundPool mSoundPool;
private HashMap<Integer, Integer> mSoundPoolMap;
private AudioManager mAudioManager;

public SoundManager(Context context){
this.context = context;
}

public void initSounds() {
mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);
mSoundPoolMap = new HashMap<Integer, Integer>();
mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
}

public void addSound(int index, int SoundID) {
mSoundPoolMap.put(index, mSoundPool.load(context, SoundID, 1));
}

public void playSound(int index) {
float streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
streamVolume = streamVolume / mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, 0, 1f);
}
public void playLoopedSound(int index) {
float streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
streamVolume = streamVolume / mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, -1, 1f);
}
public void removeAll(){
mSoundPoolMap.clear(); } }





public class FanShapedHideView extends View {
private Paint paint;
private Context context;
private Bitmap circleBitmap;
private Bitmap currentBitmap;
// private Bitmap hideBitmap;
private Rect bgRect;
private Rect currentRect;
private static int screenWidth = -1;
private static int screenHeight = -1;
private boolean initPass;
private ShowOrHideAction showOrHideAction = ShowOrHideAction.no;
public FanShapedHideView(Context context) {
super(context);
init(context);
}
public FanShapedHideView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context);
}
private void init(Context context) {
this.context = context;
initPass = true;
showOrHideAction = ShowOrHideAction.hide;
Resources resources = context.getResources();
paint = new Paint(Paint.ANTI_ALIAS_FLAG);
circleBitmap = BitmapFactory.decodeResource(resources, com.turlet.fanshaped.R.drawable.circle);
// showBitmap = BitmapFactory.decodeResource(resources, R.drawable.show_goto);
// hideBitmap = BitmapFactory.decodeResource(resources, R.drawable.hide_goto);
}
private void initOnDraw(boolean initPass) {
screenWidth = this.getWidth();
screenHeight = this.getHeight();
screenWidth = screenWidth < screenHeight ? screenWidth : screenHeight;
bgRect = new Rect((int)(0.05f *screenWidth), (int)(0.0f *screenWidth), (int)(0.9f *screenWidth), (int)(0.85f *screenWidth));
currentRect = new Rect((int)(0.18f *screenWidth), (int)(0.05f *screenWidth), (int)(0.78f *screenWidth), (int)(0.70f *screenWidth));
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
initOnDraw(initPass);
canvas.drawBitmap(circleBitmap, null, bgRect, null);
if (currentBitmap != null) {
canvas.drawBitmap(currentBitmap, null, currentRect, null);
}
// if (showOrHideAction == ShowOrHideAction.show) {
// canvas.drawBitmap(showBitmap, null, bgRect, paint);
// } else if (showOrHideAction == ShowOrHideAction.hide) {
// canvas.drawBitmap(hideBitmap, null, bgRect, paint);
// }
initPass = false;
}
@Override
public boolean onTouchEvent(MotionEvent event) {
int action = event.getAction();
// int x = (int) event.getX();
// int y = (int) event.getY();
if (MotionEvent.ACTION_DOWN == action) {
// refreshView();
return this.performClick();
}
return true;
}
private Handler handler = new Handler();
protected void refreshView() {
handler.post(new Runnable() {
@Override
public void run() {
invalidate();
}
});
}
public void setCurrentModule(Bitmap bitmap){
currentBitmap = bitmap;
}
public void show(final View view) {
handler.post(new Runnable() {
@Override
public void run() {
Animation scaleIn = AnimationUtils.loadAnimation(context, R.anim.scale_in);
view.startAnimation(scaleIn);
view.setVisibility(VISIBLE);
showOrHideAction = ShowOrHideAction.hide;
invalidate();
}
});
}
public void setShowAction(ShowOrHideAction action) {
showOrHideAction = ShowOrHideAction.show;
}
public void recycle() {
circleBitmap.recycle();
// hideBitmap.recycle();
circleBitmap = null;
// hideBitmap = null;
}
public enum ShowOrHideAction {
no, show, hide; } }

周四:今天写了一些小代码:

public class Rotate3d extends Animation {

private float mFromDegree;

private float mToDegree;

private float mCenterX;

private float mCenterY;

private float mLeft;

private float mTop;

private Camera mCamera;

private static final String TAG = "Rotate3d";


public Rotate3d(float fromDegree, float toDegree, float left, float top,

float centerX, float centerY) {

this.mFromDegree = fromDegree;

this.mToDegree = toDegree;

this.mLeft = left;

this.mTop = top;

this.mCenterX = centerX;

this.mCenterY = centerY;


}


@Override

public void initialize(int width, int height, int parentWidth,

int parentHeight) {

super.initialize(width, height, parentWidth, parentHeight);

mCamera = new Camera();

}


@Override

protected void applyTransformation(float interpolatedTime, Transformation t) {

final float FromDegree = mFromDegree;

float degrees = FromDegree + (mToDegree - mFromDegree)

* interpolatedTime;

final float centerX = mCenterX;

final float centerY = mCenterY;

final Matrix matrix = t.getMatrix();


if (degrees <= -76.0f) {

degrees = -90.0f;

mCamera.save();

mCamera.rotateY(degrees);

mCamera.getMatrix(matrix);

mCamera.restore();

} else if (degrees >= 76.0f) {

degrees = 90.0f;

mCamera.save();

mCamera.rotateY(degrees);

mCamera.getMatrix(matrix);

mCamera.restore();

} else {

mCamera.save();

//

mCamera.translate(0, 0, centerX);

mCamera.rotateY(degrees);

mCamera.translate(0, 0, -centerX);

mCamera.getMatrix(matrix);

mCamera.restore();

}


matrix.preTranslate(-centerX, -centerY);

matrix.postTranslate(centerX, centerY);

}

}

更多相关文章

  1. 第一个变化———由support库到Androidx
  2. 编写高效的Android代码(译)
  3. android的ndk开发入门示例
  4. linux: 编译android源代码流程,以及linux环境变量设置。
  5. Android(安卓)Spinner与适配器模式详解及实例代码
  6. Android(安卓)自定义控件外观
  7. Eclipse 无法查看 Android(安卓)源代码
  8. Android程序的签名保护及绕过方法
  9. Vue.js实战——开发Android(安卓)Hybird App之权限设置_11

随机推荐

  1. Android开发中使用CRC校验
  2. Android开源代码解读の地图照片应用Panor
  3. 如何让按钮共享android中对话框宽度的一
  4. Android 字符串资源
  5. 多个dex文件定义了Landroid/支持/v13/app
  6. 在app引擎端点的启动时执行代码
  7. android:WALLPAPER_CHANGED不适用于三星Ga
  8. Android NFC 近场通讯开发全解
  9. 通过不在android游标中工作的顺序
  10. Android全屏模式,沉浸模式。粘性沉浸模式