天天看點

短視訊直播源碼,日夜模式切換配置

短視訊直播源碼,日夜模式切換配置相關的代碼

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager.LayoutParams;
import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.bwie.today_topline.MyApplication;
import com.bwie.today_topline.R;
import com.bwie.today_topline.menu.MenuFragment;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.app.SlidingFragmentActivity;

public abstract class BaseActivity extends SlidingFragmentActivity {

    public LinearLayout lly;
    public ImageButton ib_activity_back;
    public TextView tv_title;
    public TextView tv_deal;
    public FrameLayout fl_base;
    public SlidingMenu slidingMenu;
    public MenuFragment menuFragment;
    private boolean mIsAddedView;
    private LayoutParams myNightViewParams;
    private View mNightView;
    private WindowManager manager;

    @Override
    public void onCreate(Bundle savedInstanceState) {
       
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.pagr_tab);
       
        if (MyApplication.isNeightMode) {
            initNightView();
            // 設定windowmaneger背景圖的顔色
            mNightView.setBackgroundResource(R.color.night_mask);
        }
        initSlidingMenu();
        lly = (LinearLayout) findViewById(R.id.ll_title);
        ib_activity_back = (ImageButton) findViewById(R.id.ib_activity_back);
        tv_title = (TextView) findViewById(R.id.tv_title);
        tv_deal = (TextView) findViewById(R.id.tv_deal);
        fl_base = (FrameLayout) findViewById(R.id.fl_base);
        fl_base.addView(initView());
   
        initData();
    }

    // 設定夜間模式給試圖設定一層布
    private void initNightView() {
        if (mIsAddedView == true)
            return;
        myNightViewParams = new LayoutParams(LayoutParams.TYPE_APPLICATION,
                LayoutParams.FLAG_NOT_TOUCHABLE
                        | LayoutParams.FLAG_NOT_FOCUSABLE,
                PixelFormat.TRANSPARENT);
        manager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
        mNightView = new View(this);
        manager.addView(mNightView, myNightViewParams);
        mIsAddedView = true;
    }

    public void ChangeToDay() {
        MyApplication.setNeightMode(false);
        Toast.makeText(this, "白天", 0).show();
        manager.removeView(mNightView);
        mNightView.setBackgroundResource(android.R.color.transparent);
    }

    public void ChangeToNight() {
        Toast.makeText(this, "黑天", 0).show();
        MyApplication.setNeightMode(true);
        
        if (mIsAddedView != true) {
            
            initNightView();
            mIsAddedView = false;
        }
        mNightView.setBackgroundResource(R.color.night_mask);
    }

    /**
     * 改變目前日夜模式
     */

    public void changeViewMode() {
        // 判斷目前模式,如果是白天模式,改成夜間,如果是夜間模式,改成白天
        boolean isNight = MyApplication.isNeightMode;
        if (isNight) {
            ChangeToDay();
        } else {
            ChangeToNight();
        }

        // // 重新建立Activity
        //recreate();
    }

    @Override
    protected void onDestroy() {
        if (mIsAddedView) {
            manager.removeViewImmediate(mNightView);
            manager = null;
            mNightView = null;
        }
        super.onDestroy();
    }

    // 傳回時調用
    public void goBack() {
        finish();
        overridePendingTransition(R.anim.anim_back_in, R.anim.anim_back_out);
    }

    public void inten(Class activity) {
        Intent intent = new Intent(this, activity);
        startActivity(intent);
        overridePendingTransition(R.anim.anim_in, R.anim.anim_out);
    }

    // 初始化控件
    public abstract View initView();

    // 初始化資料
    public abstract void initData();

    // 設定側拉框以及其監聽活動
    public void initSlidingMenu() {
        // 設定側拉條目布局
        setBehindContentView(R.layout.menu_frame);
        // 擷取側拉欄目對象
        slidingMenu = getSlidingMenu();
        /*
         * SlidingMenu.TOUCHMODE_FULLSCREEN全屏觸摸有效 SlidingMenu.TOUCHMODE_MARGIN
         * 拖拽邊緣有效 SlidingMenu.TOUCHMODE_NONE 不響應觸摸事件
         */
        slidingMenu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);

        // 設定内容顯示頁對應的dp大小
        slidingMenu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
        // //設定左側側拉欄目寬度
        // slidingMenu.setBehindWidth(140);
        // 設定側拉欄目所在位置
        /*
         * SlidingMenu.LEFT SlidingMenu.LEFT_RIGHT SlidingMenu.RIGHT
         */
        slidingMenu.setMode(SlidingMenu.LEFT);
        // 給側拉欄目和左側内容頁區分開(加線)
        slidingMenu.setShadowDrawable(R.drawable.ic_launcher);
        // 設定線的寬度
        slidingMenu.setShadowWidthRes(R.dimen.shadow_width);

        // fragment去替換布局中節點
        menuFragment = MenuFragment.getInstance();
        // FragmentManager管理者
        getSupportFragmentManager()
        // 開啟事物
                .beginTransaction()
                // 通過fragment去替換對應布局
                .replace(R.id.menu, menuFragment, "MENU")
                // 送出事物
                .commit();

    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        menuFragment.onActivityResult(requestCode, resultCode, data);
        Log.i("com", "baseactivity     onActivityResult-----------------");
    }
}
           

以上就是短視訊直播源碼,日夜模式切換配置相關的代碼, 更多内容歡迎關注之後的文章

繼續閱讀