Java 类android.widget.SlidingDrawer.OnDrawerOpenListener 实例源码

项目:LemonBlog    文件:ShakeActivity.java   
@Override
public void initViews() {
    mImgUp = (RelativeLayout) findViewById(R.id.shakeImgUp);
    mImgDn = (RelativeLayout) findViewById(R.id.shakeImgDown);
    mTitle = (RelativeLayout) findViewById(R.id.shake_title_bar);

    mDrawer = (SlidingDrawer) findViewById(R.id.slidingDrawer1);
    mDrawerBtn = (Button) findViewById(R.id.handle);
    mDrawer.setOnDrawerOpenListener(new OnDrawerOpenListener()
    {
        public void onDrawerOpened()
        {
            mDrawerBtn.setBackgroundDrawable(getResources().getDrawable(
                    R.drawable.shake_report_dragger_down));
            TranslateAnimation titleup = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0f,
                    Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, 0f,
                    Animation.RELATIVE_TO_SELF, -1.0f);
            titleup.setDuration(200);
            titleup.setFillAfter(true);
            mTitle.startAnimation(titleup);
        }
    });
    /* 设定SlidingDrawer被关闭的事件处理 */
    mDrawer.setOnDrawerCloseListener(new OnDrawerCloseListener()
    {
        public void onDrawerClosed()
        {
            mDrawerBtn.setBackgroundDrawable(getResources().getDrawable(
                    R.drawable.shake_report_dragger_up));
            TranslateAnimation titledn = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0f,
                    Animation.RELATIVE_TO_SELF, 0f, Animation.RELATIVE_TO_SELF, -1.0f,
                    Animation.RELATIVE_TO_SELF, 0f);
            titledn.setDuration(200);
            titledn.setFillAfter(false);
            mTitle.startAnimation(titledn);
        }
    });

    mShakeListener = new ShakeListener(this);
    mShakeListener.setOnShakeListener(new OnShakeListener() {
        public void onShake() {
            // Toast.makeText(getApplicationContext(),
            // "抱歉,暂时没有找到在同一时刻摇一摇的人。\n再试一次吧!", Toast.LENGTH_SHORT).show();
            startAnim(); // 开始 摇一摇手掌动画
            mShakeListener.stop();
            startVibrato(); // 开始 震动
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    // Toast.makeText(getApplicationContext(),
                    // "抱歉,暂时没有找到\n在同一时刻摇一摇的人。\n再试一次吧!",
                    // 500).setGravity(Gravity.CENTER,0,0).show();
                    Toast mtoast;
                    mtoast = Toast.makeText(getApplicationContext(),
                            "抱歉,暂时没有找到\n在同一时刻摇一摇的人。\n再试一次吧!", 10);
                    // mtoast.setGravity(Gravity.CENTER, 0, 0);
                    mtoast.show();
                    mVibrator.cancel();
                    mShakeListener.start();
                }
            }, 2000);
        }
    });

    findViewById(R.id.back).setOnClickListener(this);
    findViewById(R.id.done).setOnClickListener(this);
}