前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >短视频直播源码,日夜模式切换配置

短视频直播源码,日夜模式切换配置

原创
作者头像
yunbaokeji柯基
修改2020-11-19 14:18:37
4950
修改2020-11-19 14:18:37
举报
文章被收录于专栏:直播知识

短视频直播源码,日夜模式切换配置相关的代码

代码语言:javascript
复制
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-----------------");
    }
}

以上就是短视频直播源码,日夜模式切换配置相关的代码, 更多内容欢迎关注之后的文章

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
实时音视频
实时音视频(Tencent RTC)基于腾讯21年来在网络与音视频技术上的深度积累,以多人音视频通话和低延时互动直播两大场景化方案,通过腾讯云服务向开发者开放,致力于帮助开发者快速搭建低成本、低延时、高品质的音视频互动解决方案。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档