android小代码

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);

 }

}

你可能感兴趣的:(android小代码)