用户注册



邮箱:

密码:

用户登录


邮箱:

密码:
记住登录一个月忘记密码?

发表随想


还能输入:200字

不会编程的程序猪    -  云代码空间

——

大华摄像头demo

2018-09-13|19阅||

摘要:package dahuatech.netsdk.activity; import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; im

package dahuatech.netsdk.activity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Resources;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;

import com.example.androiddemo.R;
import dahuatech.netsdk.common.DialogProgress;
import dahuatech.netsdk.common.PrefsConstants;
import dahuatech.netsdk.module.IPLoginModule;
import dahuatech.netsdk.common.ToolKits;

public class IPLoginActivity extends Activity {
    private EditText mEditTextAddress;
    private EditText mEditTextPort;
    private EditText mEditTextUsername;
    private EditText mEditTextPassword;
    private CheckBox mCheckBox;

    private SharedPreferences mSharedPrefs;
    private IPLoginModule mLoginModule;
    private NetSDKApplication app;
    private DialogProgress mDialogProgress;
    private Resources res;

    private String mAddress;
    private String mPort;
    private String mUsername;
    private String mPassword;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_iplogin);
        setTitle(R.string.activity_main_ip_domin);
        /// get global data得到全局数据
        app = (NetSDKApplication)getApplication();//调用NETSDKapplication
        res = getResources();
        mDialogProgress = new DialogProgress(this);
        mLoginModule = new IPLoginModule();
        setupView();  //初始化视频页面 
    }

    @Override
    protected void onDestroy() {
        if(null != mLoginModule) {
            mLoginModule.logout();
            mLoginModule = null;
        }
        super.onDestroy();
   }

    @Override
    protected void onResume() {
                                    // 在onResume时,我们应该注销该设备。
        mLoginModule.logout();
        super.onResume();
    }

    private void setupView() {
        mEditTextAddress = (EditText)findViewById(R.id.editTextServerIp);
        mEditTextPort = (EditText)findViewById(R.id.editTextServerPort);
        mEditTextUsername = (EditText)findViewById(R.id.editTextUsername);
        mEditTextPassword = (EditText)findViewById(R.id.et_pwd);
        Button ButtonLogin = (Button)findViewById(R.id.buttonLogin);
        ButtonLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if(checkLoginEditText()) {
                    LoginTask loginTask = new LoginTask();
                    loginTask.execute();//登录执行
                }
            }
        });
        mCheckBox = (CheckBox)findViewById(R.id.checkBox);
        getSharePrefs();
    }

    // LoginTask 登录任务
    private class LoginTask extends AsyncTask<String, Integer, Boolean> {
        @Override
        protected void onPreExecute(){
            super.onPreExecute();
            mDialogProgress.setMessage(res.getString(R.string.logining));
            mDialogProgress.setSpinnerType(DialogProgress.FADED_ROUND_SPINNER);
            mDialogProgress.setCancelable(false);
            mDialogProgress.show();
            Log.d("debugtest", "这里是弹窗------"+mAddress);
        }
        
        @Override
        protected Boolean doInBackground(String... params) {
//            return mLoginModule.login("192.168.16.108", "37777", "admin", "admin");
        	 return mLoginModule.login(mAddress, mPort, mUsername, mPassword);
        }
        @Override
        protected void onPostExecute(Boolean result){
            mDialogProgress.dismiss();
            if (result) {
                putSharePrefs();
                app.setLoginHandle(mLoginModule.getLoginHandle());
                app.setDeviceInfo(mLoginModule.getDeviceInfo());
                startActivity(new Intent(IPLoginActivity.this, LivePreviewActivity.class));
                Log.d("debugtest", "这是登录跳转------"+result);
            } else {
                ToolKits.showMessage(IPLoginActivity.this, getErrorCode(getResources(), mLoginModule.errorCode()));
                Log.d("debugtest", "这是登录不能跳转------"+result);
            }
        }
    }

    private void putSharePrefs() {
        SharedPreferences.Editor editor = mSharedPrefs.edit();
        if (mCheckBox.isChecked()) {
            editor.putString(PrefsConstants.LOGIN_IP, mAddress);
            editor.putString(PrefsConstants.LOGIN_PORT, mPort);
            editor.putString(PrefsConstants.LOGIN_USERNAME, mUsername);
            editor.putString(PrefsConstants.LOGIN_PASSWORD, mPassword);
            editor.putBoolean(PrefsConstants.LOGIN_CHECK, true);
        }
        editor.apply();
    }

    private void getSharePrefs() {
        mSharedPrefs = getPreferences(MODE_PRIVATE);
        SharedPreferences.Editor editor = mSharedPrefs.edit();
        mEditTextAddress.setText(mSharedPrefs.getString(PrefsConstants.LOGIN_IP, "171.35.13.64"));
        mEditTextPort.setText(mSharedPrefs.getString(PrefsConstants.LOGIN_PORT, "37777"));
        mEditTextUsername.setText(mSharedPrefs.getString(PrefsConstants.LOGIN_USERNAME, "admin"));
        mEditTextPassword.setText(mSharedPrefs.getString(PrefsConstants.LOGIN_PASSWORD, "admin"));
        mCheckBox.setChecked(mSharedPrefs.getBoolean(PrefsConstants.LOGIN_CHECK, false));

        editor.apply();
    }

    private boolean checkLoginEditText() {
        mAddress = mEditTextAddress.getText().toString();
        mPort = mEditTextPort.getText().toString();
        mUsername = mEditTextUsername.getText().toString();
        mPassword = mEditTextPassword.getText().toString();

        if(mAddress.length() == 0) {
            ToolKits.showMessage(IPLoginActivity.this, res.getString(R.string.activity_iplogin_ip_empty));
            return false;
        }
        if(mPort.length() == 0) {
            ToolKits.showMessage(IPLoginActivity.this, res.getString(R.string.activity_iplogin_port_empty));
            return false;
        }
        if(mUsername.length() == 0) {
            ToolKits.showMessage(IPLoginActivity.this, res.getString(R.string.activity_iplogin_username_empty));
            return false;
        }
        if(mPassword.length() == 0) {
            ToolKits.showMessage(IPLoginActivity.this, res.getString(R.string.activity_iplogin_password_empty));
            return false;
        }

        try {
            Integer.parseInt(mPort);
        } catch (Exception e) {
            e.printStackTrace();
            ToolKits.showMessage(IPLoginActivity.this, res.getString(R.string.activity_iplogin_port_err));
            return false;
        }

        return true;
    }

    public static String getErrorCode(Resources res, int errorCode) {
        switch(errorCode) {
            case IPLoginModule.NET_USER_FLASEPWD_TRYTIME:
                return res.getString(R.string.NET_USER_FLASEPWD_TRYTIME);
            case IPLoginModule.NET_LOGIN_ERROR_PASSWORD:
                return res.getString(R.string.NET_LOGIN_ERROR_PASSWORD);
            case IPLoginModule.NET_LOGIN_ERROR_USER:
                return res.getString(R.string.NET_LOGIN_ERROR_USER);
            case IPLoginModule.NET_LOGIN_ERROR_TIMEOUT:
                return res.getString(R.string.NET_LOGIN_ERROR_TIMEOUT);
            case IPLoginModule.NET_LOGIN_ERROR_RELOGGIN:
                return res.getString(R.string.NET_LOGIN_ERROR_RELOGGIN);
            case IPLoginModule.NET_LOGIN_ERROR_LOCKED:
                return res.getString(R.string.NET_LOGIN_ERROR_LOCKED);
            case IPLoginModule.NET_LOGIN_ERROR_BLACKLIST:
                return res.getString(R.string.NET_LOGIN_ERROR_BLACKLIST);
            case IPLoginModule.NET_LOGIN_ERROR_BUSY:
                return res.getString(R.string.NET_LOGIN_ERROR_BUSY);
            case IPLoginModule.NET_LOGIN_ERROR_CONNECT:
                return res.getString(R.string.NET_LOGIN_ERROR_CONNECT);
            case IPLoginModule.NET_LOGIN_ERROR_NETWORK:
                return res.getString(R.string.NET_LOGIN_ERROR_NETWORK);
            default:
               return res.getString(R.string.NET_ERROR);
        }
    }  
}

package dahuatech.netsdk.activity;

import android.content.Context;
import android.content.DialogInterface;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.text.method.DigitsKeyListener;
import android.text.method.KeyListener;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.company.NetSDK.SDK_EXTPTZ_ControlType;
import com.company.NetSDK.SDK_PTZ_ControlType;
import com.example.androiddemo.R;
import dahuatech.netsdk.common.DialogProgress;
import dahuatech.netsdk.common.ToolKits;
import dahuatech.netsdk.module.LivePreviewModule;
import java.util.ArrayList;

public class LivePreviewActivity extends Activity implements
        SurfaceHolder.Callback,
        AdapterView.OnItemSelectedListener,
        View.OnClickListener{
    private final String TAG = LivePreviewActivity.class.getSimpleName();
    Spinner mSelectStream;
    Spinner mSelectChannel;
    Spinner mEncodeMode;
    Spinner mEncodeResolve;
    Spinner mEncodeFps;
    Spinner mEncodeBitRate;
    SurfaceView mRealView;
    EditText mEditText;
    View mPtzControlLayoutView;
    LivePreviewModule mLiveModule;
    AlertDialog.Builder builder;

    private boolean isRecord = false;
    private int count = 0;
  ///touch time.
    ///触摸时间.
    long mTouchStartTime = 0;
    long mTouchMoveTime = 0;

    ///single touch.
    ///单点触摸.
    float mSingleTouchStart_x = 0;
    float mSingleTouchStart_y = 0;
    float mSingleTouchEnd_x = 0;
    float mSingleTouchEnd_y = 0;

    ///double touch.
    ///两点触摸.
    float mDoubleTouchStart_x1 = 0;
    float mDoubleTouchStart_y1 = 0;
    float mDoubleTouchStart_x2 = 0;
    float mDoubleTouchStart_y2 = 0;
    float mDoubleTouchEnd_x1 = 0;
    float mDoubleTouchEnd_y1 = 0;
    float mDoubleTouchEnd_x2 = 0;
    float mDoubleTouchEnd_y2 = 0;
    Button  mEncodeBtn = null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_live_preview);
        mLiveModule = new LivePreviewModule(this);
        setTitle(R.string.activity_function_list_live_preview);

        builder = new AlertDialog.Builder(this);
        builder.setMessage(R.string.ptz_control_fragment_info);
        builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        builder.show();
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
        setupView();
        
    }

    private void setupView(){
        mSelectStream = (Spinner)findViewById(R.id.select_stream_type);
        mSelectChannel = (Spinner)findViewById(R.id.select_channel);
        mRealView = (SurfaceView)findViewById(R.id.real_view);
        mRealView.getHolder().addCallback(this);
        initializeSpinner(mSelectChannel,(ArrayList)mLiveModule.getChannelList()).setSelection(0);
        initializeSpinner(mSelectStream,(ArrayList)mLiveModule.getStreamTypeList(mSelectChannel.getSelectedItemPosition())).setSelection(1);

        ((Button)findViewById(R.id.preview_ptz_control)).setOnClickListener(this);
        mPtzControlLayoutView = (View)findViewById(R.id.ptz_control);
        mEditText = (EditText)mPtzControlLayoutView.findViewById(R.id.edittext_preset);

        ///Only limit to use number		
        ///只允许输入数字
        KeyListener keyListener = new DigitsKeyListener(false, false);
        mEditText.setKeyListener(keyListener);

        ((Button) mPtzControlLayoutView.findViewById(R.id.preview_focus_add)).setOnClickListener(this);
        ((Button) mPtzControlLayoutView.findViewById(R.id.preview_focus_dec)).setOnClickListener(this);
        ((Button) mPtzControlLayoutView.findViewById(R.id.preview_aperture_add)).setOnClickListener(this);
        ((Button) mPtzControlLayoutView.findViewById(R.id.preview_aperture_dec)).setOnClickListener(this);
        ((Button) mPtzControlLayoutView.findViewById(R.id.preview_setpreset)).setOnClickListener(this);
        ((Button) mPtzControlLayoutView.findViewById(R.id.preview_clearpreset)).setOnClickListener(this);
        ((Button) mPtzControlLayoutView.findViewById(R.id.preview_gotopreset)).setOnClickListener(this);

        ((Button)findViewById(R.id.preview_remote_snapPic)).setOnClickListener(this);
        mEncodeBtn = ((Button)findViewById(R.id.preview_encode));
        mEncodeBtn.setOnClickListener(this);
        ((Button)findViewById(R.id.preview_record)).setOnClickListener(this);
    }

    @Override
    protected void onResume(){
        super.onResume();
    }

    @Override
    public void surfaceCreated(SurfaceHolder holder) {
        mLiveModule.initSurfaceView(mRealView);
    }

    @Override
    public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {

    }

    @Override
    public void surfaceDestroyed(SurfaceHolder holder) {

    }

    @Override
    protected void onDestroy(){
        mLiveModule.stopRealPlay();
        mLiveModule = null;
        mRealView = null;
        super.onDestroy();
    }
	
    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        int parentID = parent.getId();
        boolean isMain = isMainStream();

        ///Close the listener event when not triggered.
        ///未触发时关闭侦听器事件。
        if((count == 0)&&(position == 0)) {
            count ++;
            return;
        }

        switch (parentID){
            case R.id.select_channel:
                onChannelChanged(position);
                break;
            case R.id.select_stream_type:
                onStreamTypeChanged(position);
                break;
            case R.id.compress_fromat_spinner:
                onUpdateMode(((TextView)view).getText().toString(),isMain);
                break;
            case R.id.resolve_spinner:
                onUpdateResolve(((TextView)view).getText().toString(),isMain);
                break;
            case R.id.frame_rate_spinner:
                onUpdateFps(position,isMain);
                break;
            case R.id.bit_rate_spinner:
                onUpdateBitRate(((TextView)view).getText().toString(),isMain);
                break;
            default:
                break;
        }
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {

    }

    private void onChannelChanged(int pos){
        if (mLiveModule == null)
            return;
        mLiveModule.stopRealPlay();
        mLiveModule.startPlay(pos,mSelectStream.getSelectedItemPosition(),mRealView);
    }

    private void onStreamTypeChanged(int position){
        if (mLiveModule == null)
            return;
        mLiveModule.stopRealPlay();
        mLiveModule.startPlay(mSelectChannel.getSelectedItemPosition(),position,mRealView);
    }

    @Override
    public void onClick(View v) {
        String text = mEditText.getText().toString();
        switch (v.getId()){
            case R.id.preview_ptz_control:
                if(mPtzControlLayoutView.isShown()) {
                    mPtzControlLayoutView.setVisibility(View.GONE);
                } else  {
                    mPtzControlLayoutView.setVisibility(View.VISIBLE);
                }
                break;
            case R.id.preview_remote_snapPic:
                if(mPtzControlLayoutView.isShown()) {
                    mPtzControlLayoutView.setVisibility(View.GONE);
                }
                mLiveModule.snap(mSelectChannel.getSelectedItemPosition());
                break;
            case R.id.preview_encode:
                if(mPtzControlLayoutView.isShown()) {
                    mPtzControlLayoutView.setVisibility(View.GONE);
                }
                mEncodeBtn.setEnabled(false);
                onEncode();
                break;
            case R.id.preview_record:
                if(mPtzControlLayoutView.isShown()) {
                    mPtzControlLayoutView.setVisibility(View.GONE);
                }
                isRecord = !isRecord;
               onRecord(v, isRecord);
                break;
            case R.id.preview_focus_add:
                mLiveModule.ptzControlEx(mSelectChannel.getSelectedItemPosition(), SDK_PTZ_ControlType.SDK_PTZ_FOCUS_ADD_CONTROL,(byte)8);
                break;
            case R.id.preview_focus_dec:
                mLiveModule.ptzControlEx(mSelectChannel.getSelectedItemPosition(), SDK_PTZ_ControlType.SDK_PTZ_FOCUS_DEC_CONTROL,(byte)8);
                break;
            case R.id.preview_aperture_add:
                mLiveModule.ptzControlEx(mSelectChannel.getSelectedItemPosition(), SDK_PTZ_ControlType.SDK_PTZ_APERTURE_ADD_CONTROL, (byte)8);
                break;
            case R.id.preview_aperture_dec:
                mLiveModule.ptzControlEx(mSelectChannel.getSelectedItemPosition(), SDK_PTZ_ControlType.SDK_PTZ_APERTURE_DEC_CONTROL, (byte)8);
                break;
            case R.id.preview_setpreset:
                if(!text.equals("")) {
                    mLiveModule.ptzControlEx(mSelectChannel.getSelectedItemPosition(), SDK_PTZ_ControlType.SDK_PTZ_POINT_SET_CONTROL,
                            (byte)Integer.parseInt(text)) ;
                }else {
                    ToolKits.showMessage(LivePreviewActivity.this, getString(R.string.input_number));
                }
                break;
            case R.id.preview_clearpreset:
                if(!text.equals("")) {
                    mLiveModule.ptzControlEx(mSelectChannel.getSelectedItemPosition(), SDK_PTZ_ControlType.SDK_PTZ_POINT_DEL_CONTROL,
                            (byte)Integer.parseInt(text));
                }else {
                    ToolKits.showMessage(LivePreviewActivity.this, getString(R.string.input_number));
                }
                break;
            case R.id.preview_gotopreset:
                if(!text.equals("")) {
                    mLiveModule.ptzControlEx(mSelectChannel.getSelectedItemPosition(), SDK_PTZ_ControlType.SDK_PTZ_POINT_MOVE_CONTROL,
                            (byte)Integer.parseInt(text));
                } else {
                    ToolKits.showMessage(LivePreviewActivity.this, getString(R.string.input_number));
                }
                break;
            default:
                break;
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        final int mAction = event.getAction();
        int mPointorCount = event.getPointerCount();

        switch(mAction) {
            case MotionEvent.ACTION_DOWN :
                if(mPtzControlLayoutView.isShown()) {
                    mPtzControlLayoutView.setVisibility(View.GONE);
                }

                ///If the input method has already been shown on the window, it is hidden.
                ///如果输入方法已经显示在窗口中,那么它将被隐藏。
                InputMethodManager inputManager = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
                inputManager.hideSoftInputFromWindow(mRealView.getWindowToken(), 0);

                mTouchStartTime = System.currentTimeMillis();
                mSingleTouchStart_x = event.getX();
                mSingleTouchStart_y = event.getY();
                break;
            case MotionEvent.ACTION_MOVE :
                mTouchMoveTime = System.currentTimeMillis() - mTouchStartTime;
                int mHistorySize = event.getHistorySize();
                if(mHistorySize == 0) {
                    return true;
                }

                if((mPointorCount == 1) && (mTouchMoveTime > 300)){
                    mSingleTouchEnd_x = event.getX();
                    mSingleTouchEnd_y = event.getY();

                    float mSingleTouchValue_x = mSingleTouchEnd_x - mSingleTouchStart_x;
                    float mSingleTouchValue_y = mSingleTouchEnd_y - mSingleTouchStart_y;

                    float mDeviation = Math.abs(mSingleTouchValue_y/mSingleTouchValue_x);

                    if((mSingleTouchValue_x > 0) && (mDeviation < 0.87)) {
                        return mLiveModule.ptzControl(event, mSelectChannel.getSelectedItemPosition(), SDK_PTZ_ControlType.SDK_PTZ_RIGHT_CONTROL, (byte)0, (byte)8);
                    } else if((mSingleTouchValue_x < 0) && (mDeviation < 0.87)) {
                        return mLiveModule.ptzControl(event, mSelectChannel.getSelectedItemPosition(), SDK_PTZ_ControlType.SDK_PTZ_LEFT_CONTROL, (byte)0, (byte)8);
                    } else if((mSingleTouchValue_y > 0) && (mDeviation > 11.43)) {
                        return mLiveModule.ptzControl(event, mSelectChannel.getSelectedItemPosition(), SDK_PTZ_ControlType.SDK_PTZ_DOWN_CONTROL, (byte)0, (byte)8);
                    } else if((mSingleTouchValue_y < 0) && (mDeviation > 11.43)) {
                        return mLiveModule.ptzControl(event, mSelectChannel.getSelectedItemPosition(), SDK_PTZ_ControlType.SDK_PTZ_UP_CONTROL, (byte)0, (byte)8);
                    } else if((mSingleTouchValue_x < 0) && (mSingleTouchValue_y < 0) && (mDeviation <= 11.43) && (mDeviation >= 0.87)) {
                        return mLiveModule.ptzControl(event, mSelectChannel.getSelectedItemPosition(), SDK_EXTPTZ_ControlType.SDK_EXTPTZ_LEFTTOP, (byte)8, (byte)8);
                    } else if((mSingleTouchValue_x < 0) && (mSingleTouchValue_y > 0) && (mDeviation <= 11.43) && (mDeviation >= 0.87)) {
                        return mLiveModule.ptzControl(event, mSelectChannel.getSelectedItemPosition(), SDK_EXTPTZ_ControlType.SDK_EXTPTZ_LEFTDOWN, (byte)8, (byte)8);
                    } else if((mSingleTouchValue_x > 0) && (mSingleTouchValue_y < 0) && (mDeviation <= 11.43) && (mDeviation >= 0.87)) {
                        return mLiveModule.ptzControl(event, mSelectChannel.getSelectedItemPosition(), SDK_EXTPTZ_ControlType.SDK_EXTPTZ_RIGHTTOP, (byte)8, (byte)8);
                    } else if((mSingleTouchValue_x > 0) && (mSingleTouchValue_y > 0) && (mDeviation <= 11.43) && (mDeviation >= 0.87)) {
                        return mLiveModule.ptzControl(event, mSelectChannel.getSelectedItemPosition(), SDK_EXTPTZ_ControlType.SDK_EXTPTZ_RIGHTDOWN, (byte)8, (byte)8);
                    }

                } else if((mPointorCount == 2) && (mTouchMoveTime > 300)){
                    mDoubleTouchStart_x1 = event.getHistoricalX(0, mHistorySize - 1);
                    mDoubleTouchStart_y1 = event.getHistoricalY(0, mHistorySize - 1);
                    mDoubleTouchStart_x2 = event.getHistoricalX(1, mHistorySize - 1);
                    mDoubleTouchStart_y2 = event.getHistoricalY(1, mHistorySize - 1);

                    mDoubleTouchEnd_x1 = event.getX(0);
                    mDoubleTouchEnd_y1 = event.getY(0);
                    mDoubleTouchEnd_x2 = event.getX(1);
                    mDoubleTouchEnd_y2 = event.getY(1);

                    float mStartDistance_x = mDoubleTouchStart_x2 - mDoubleTouchStart_x1;
                    float mStartDistance_y = mDoubleTouchStart_y2 - mDoubleTouchStart_y1;
                    float mEndDistance_x = mDoubleTouchEnd_x2 - mDoubleTouchEnd_x1;
                    float mEndDistance_y = mDoubleTouchEnd_y2 - mDoubleTouchEnd_y1;

                    float mStartTouchDistance = (float)Math.sqrt(mStartDistance_x * mStartDistance_x + mStartDistance_y * mStartDistance_y);
                    float mEndTouchDistance = (float)Math.sqrt(mEndDistance_x * mEndDistance_x + mEndDistance_y * mEndDistance_y);

                    if(mEndTouchDistance > mStartTouchDistance) {
                        return mLiveModule.ptzControl(event, mSelectChannel.getSelectedItemPosition(), SDK_PTZ_ControlType.SDK_PTZ_ZOOM_ADD_CONTROL, (byte)0, (byte)8);
                    } else if(mEndTouchDistance < mStartTouchDistance) {
                        return mLiveModule.ptzControl(event, mSelectChannel.getSelectedItemPosition(), SDK_PTZ_ControlType.SDK_PTZ_ZOOM_DEC_CONTROL, (byte)0, (byte)8);
                    } else {
                        return false;
                    }
                }

                break;
            case MotionEvent.ACTION_UP :
                break;
            default :
                break;
        }
        return false;
    }

    private void onEncode(){
        final Dialog dialog = new Dialog(this);
        LayoutInflater inflater = LayoutInflater.from(this);
        dialog.setContentView(inflater.inflate(R.layout.encode_config_dialog,null));
        mEncodeMode = ((Spinner)dialog.findViewById(R.id.compress_fromat_spinner));
        mEncodeResolve =((Spinner)dialog.findViewById(R.id.resolve_spinner)) ;
        mEncodeFps = ((Spinner)dialog.findViewById(R.id.frame_rate_spinner));
        mEncodeBitRate = ((Spinner)dialog.findViewById(R.id.bit_rate_spinner));
        mLiveModule.setSpinnerDataCallBack(new LivePreviewModule.SpinnerDataCallback() {
            @Override
            public void onSetSpinner(Bundle data, DialogProgress dhdialog) {
                if (data == null)
                    return;
                initializeSpinner(mEncodeMode,data.getStringArrayList(mLiveModule.MODE)).
                        setSelection(data.getInt(mLiveModule.MODE_POS),true);
                initializeSpinner(mEncodeResolve,data.getStringArrayList(mLiveModule.RESOLUTION))
                        .setSelection(data.getInt(mLiveModule.RESOLUTION_POS),true);
                initializeSpinner(mEncodeFps,data.getStringArrayList(mLiveModule.FPS)).
                        setSelection(data.getInt(mLiveModule.FPS_POS),true);
                initializeSpinner(mEncodeBitRate,data.getStringArrayList(mLiveModule.BITRATE)).
                        setSelection(data.getInt(mLiveModule.BITRATE_POS),true);
                dialog.show();
                if (dhdialog != null && dhdialog.isShowing())
                    dhdialog.dismiss();
            }
        });

        // 得到编码设备
        mLiveModule.getEncodeData(mSelectChannel.getSelectedItemPosition(), isMainStream());
        ((Button)dialog.findViewById(R.id.encode_setting_config_btn)).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
                if(mLiveModule.setEncodeConfig(mSelectChannel.getSelectedItemPosition())){
                    ToolKits.showMessage(LivePreviewActivity.this,getString(R.string.encode_set_success));
                }else {
                    ToolKits.showMessage(LivePreviewActivity.this,getString(R.string.encode_set_failed));
                }
            }
        });
        dialog.setCanceledOnTouchOutside(true);
        dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                mEncodeBtn.setEnabled(true);
            }
        });
    }

    private void onUpdateMode(String text,boolean isMainStream){
        mLiveModule.updateMode(mSelectChannel.getSelectedItemPosition(),text,isMainStream);
        ((ArrayAdapter)mEncodeResolve.getAdapter()).notifyDataSetChanged();
        ((ArrayAdapter)mEncodeFps.getAdapter()).notifyDataSetChanged();
        ((ArrayAdapter)mEncodeBitRate.getAdapter()).notifyDataSetChanged();
    }
    private void onUpdateResolve(String text,boolean isMainStream){
        mLiveModule.updateResolve(mSelectChannel.getSelectedItemPosition(),text,isMainStream);
        ((ArrayAdapter)mEncodeFps.getAdapter()).notifyDataSetChanged();
        ((ArrayAdapter)mEncodeBitRate.getAdapter()).notifyDataSetChanged();
    }
    private void onUpdateFps(int pos,boolean isMainStream){
        mLiveModule.updateFps(mSelectChannel.getSelectedItemPosition(),pos,isMainStream);
        ((ArrayAdapter)mEncodeBitRate.getAdapter()).notifyDataSetChanged();
    }
    private void onUpdateBitRate(String value,boolean isMainStream){
        mLiveModule.updateBitRate(value,isMainStream);
    }

    private Spinner initializeSpinner(final Spinner spinner, ArrayList array){
        spinner.setSelection(0,true);
        spinner.setOnItemSelectedListener(this);
        spinner.setAdapter(new ArrayAdapter<String>(this,android.R.layout.simple_spinner_dropdown_item,array));
        return spinner;
    }

    private void onRecord(View v, boolean recordFlag){
        if( mLiveModule.record(recordFlag)){
            if(recordFlag){
                ((Button)v).setText(R.string.stop_record);
            }else {
                ((Button)v).setText(R.string.start_record);
            }
        }
    }

    private boolean isMainStream(){
       return mSelectStream.getSelectedItemPosition() == 0 ? true : false;
    }

}

顶 0踩 0收藏
分享到:
更多
文章评论
    发表评论

    个人资料

    • 昵称: 不会编程的程序猪
    • 等级: 中级程序员
    • 积分: 90
    • 代码: 0 个
    • 文章: 3 篇
    • 随想: 0 条
    • 访问: 0 次
    • 关注

    人气代码

      标签

      最新提问

        站长推荐