增加GPIO控制和自动曝光的调整

serial
BlueMatthew 1 year ago
parent 49dfc415a2
commit e8e7632a6e

@ -1,14 +1,11 @@
#include <jni.h>
#include <string>
#include <thread>
#include <Factory.h>
#include <Client/Terminal.h>
#include "TerminalDevice.h"
#include "PhoneDevice.h"
#include "PhoneDevice2.h"
#include <camera/NdkCameraCaptureSession.h>
#include <camera/NdkCameraDevice.h>
#include <camera/NdkCameraError.h>
#include <camera/NdkCameraManager.h>
#include <sys/system_properties.h>
#include <android/multinetwork.h>
@ -51,6 +48,16 @@ static jmethodID mRequestPositionMid = 0;
static jmethodID mWriteLogMid = 0;
class Runner
{
public:
static void RequestCapture(CTerminal* pTerminal, unsigned int channel, unsigned int preset, unsigned int type, unsigned long scheduleTime);
};
void Runner::RequestCapture(CTerminal* pTerminal, unsigned int channel, unsigned int preset, unsigned int type, unsigned long scheduleTime)
{
pTerminal->RequestCapture(channel, preset, type, scheduleTime);
}
jint JNI_OnLoad(JavaVM* vm, void* reserved)
{
JNIEnv* env = NULL;
@ -241,7 +248,9 @@ Java_com_xypower_mpapp_MicroPhotoService_notifyToTakePhoto(
return JNI_FALSE;
}
pTerminal->RequestCapture((unsigned int)channel, (unsigned int)preset, 0, (unsigned long)scheduleTime);
std::thread th(&Runner::RequestCapture, pTerminal, (unsigned int)channel, (unsigned int)preset, 0, (unsigned long)scheduleTime);
th.detach();
// pTerminal->RequestCapture((unsigned int)channel, (unsigned int)preset, 0, (unsigned long)scheduleTime);
return JNI_TRUE;
}

@ -23,6 +23,7 @@
#include <Utils.h>
#include <LogThread.h>
#include "ncnn/yolov5ncnn.h"
#include "GPIOControl.h"
#include <opencv2/opencv.hpp>
#include <opencv2/core.hpp>
@ -42,6 +43,10 @@
#include <filesystem>
namespace fs = std::filesystem;
#define CMD_SET_485_EN_STATE 131
#define CMD_SET_CAM_3V3_EN_STATE 132
#define CMD_SET_12V_EN_STATE 133
extern bool GetJniEnv(JavaVM *vm, JNIEnv **env, bool& didAttachThread);
#define WAKELOCK_NAME "NDK_WK_"
@ -173,6 +178,8 @@ CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPa
mNetId = netId;
m_sysApiClass = NULL;
m_vm = vm;
JNIEnv* env = NULL;
bool didAttachThread = false;
@ -202,11 +209,13 @@ CPhoneDevice::CPhoneDevice(JavaVM* vm, jobject service, const std::string& appPa
jclass classSysApi = env->FindClass("com/dev/devapi/api/SysApi");
if(classSysApi != NULL)
{
mTurnOtg = env->GetStaticMethodID(classSysApi, "setOtgState","(Z)V");
m_sysApiClass = (jclass)env->NewGlobalRef(classSysApi);
mTurnOtgMid = env->GetStaticMethodID(classSysApi, "setOtgState", "(Z)V");
mSetCam3V3EnableMid = env->GetStaticMethodID(classSysApi, "setCam3V3Enable", "(Z)V");
env->DeleteLocalRef(classSysApi);
}
if (didAttachThread)
{
vm->DetachCurrentThread();
@ -226,11 +235,16 @@ CPhoneDevice::~CPhoneDevice()
ALOGE("Failed to get JNI Env");
}
env->DeleteGlobalRef(m_javaService);
if (m_sysApiClass != NULL)
{
env->DeleteGlobalRef(m_sysApiClass);
}
if (didAttachThread)
{
m_vm->DetachCurrentThread();
}
m_javaService = NULL;
m_sysApiClass = NULL;
if (m_pRecognizationCfg != NULL)
{
@ -601,10 +615,9 @@ bool CPhoneDevice::FireTimer(timer_uid_t uid, unsigned long times)
if (timerType != 100)
{
int aa = 0;
// int aa = 0;
}
it->second = timerType | (ntimes << 32);
if (m_listener == NULL)
{
return false;
@ -662,9 +675,7 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
params.sensibility = mPhotoInfo.sensibility;
params.orientation = mPhotoInfo.orientation;
if (photoInfo.usbCamera)
{
jboolean otgOn = JNI_TRUE;
// GpioControl::EnableGpio(CMD_SET_CAM_3V3_EN_STATE, true);
JNIEnv* env = NULL;
bool didAttachThread = false;
bool res = GetJniEnv(m_vm, &env, didAttachThread);
@ -674,22 +685,30 @@ bool CPhoneDevice::TakePhoto(const IDevice::PHOTO_INFO& photoInfo, const vector<
return false;
}
jclass classSysApi = env->FindClass("com/dev/devapi/api/SysApi");
if(classSysApi != NULL)
if (photoInfo.usbCamera)
{
jboolean otgOn = JNI_TRUE;
if(m_sysApiClass != NULL)
{
XYLOG(XYLOG_SEVERITY_INFO, "Turn on OTG for USB Camera");
env->CallStaticVoidMethod(classSysApi, mTurnOtg, otgOn);
env->DeleteLocalRef(classSysApi);
env->CallStaticVoidMethod(m_sysApiClass, mTurnOtgMid, otgOn);
}
}
if(m_sysApiClass != NULL)
{
XYLOG(XYLOG_SEVERITY_INFO, "Set Cam3V3 Enabled ");
env->CallStaticVoidMethod(m_sysApiClass, mSetCam3V3EnableMid, JNI_TRUE);
}
if (didAttachThread)
{
m_vm->DetachCurrentThread();
}
}
mCamera = new CPhoneCamera(this, photoInfo.width, photoInfo.height, params);
if (mCamera->open(to_string(mPhotoInfo.cameraId).c_str()) == 0)
if (mCamera->open(to_string(mPhotoInfo.cameraId)) == 0)
{
}
else
@ -715,11 +734,39 @@ bool CPhoneDevice::CloseCamera()
return true;
}
void CPhoneDevice::CloseCamera2(CPhoneDevice::CPhoneCamera* camera)
void CPhoneDevice::CloseCamera2(CPhoneDevice::CPhoneCamera* camera, bool turnOffOtg)
{
std::this_thread::sleep_for(std::chrono::milliseconds(16));
// std::this_thread::sleep_for(std::chrono::milliseconds(16));
camera->close();
delete camera;
// GpioControl::EnableGpio(CMD_SET_CAM_3V3_EN_STATE, true);
JNIEnv* env = NULL;
bool didAttachThread = false;
bool res = GetJniEnv(m_vm, &env, didAttachThread);
if (!res)
{
ALOGE("Failed to get JNI Env");
return;
}
if(m_sysApiClass != NULL)
{
if (turnOffOtg)
{
XYLOG(XYLOG_SEVERITY_INFO, "Turn Off Otg");
env->CallStaticVoidMethod(m_sysApiClass, mTurnOtgMid, JNI_FALSE);
}
XYLOG(XYLOG_SEVERITY_INFO, "Set Cam3V3 Disabled ");
env->CallStaticVoidMethod(m_sysApiClass, mSetCam3V3EnableMid, JNI_FALSE);
}
if (didAttachThread)
{
m_vm->DetachCurrentThread();
}
}
void visualize(const char* filename, const ncnn::Mat& m)
@ -774,6 +821,11 @@ void DrawOutlineText(cv::Mat& mat, const std::string& str, cv::Point startPoint,
bool CPhoneDevice::OnImageReady(cv::Mat& mat)
{
if (mCamera == NULL)
{
int aa = 0;
return false;
}
mPhotoInfo.photoTime = time(NULL);
int baseline = 0;
cv::Size textSize, textSize2;
@ -917,7 +969,8 @@ bool CPhoneDevice::OnImageReady(cv::Mat& mat)
CPhoneCamera* pCamera = mCamera;
mCamera = NULL;
std::thread closeThread(&CPhoneDevice::CloseCamera2, pCamera);
bool turnOffOtg = (mPhotoInfo.usbCamera != 0);
std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, turnOffOtg);
closeThread.detach();
return res;
@ -927,6 +980,11 @@ void CPhoneDevice::onError(const std::string& msg)
{
// XFLOG(XFLOG_SEVERITY_ERROR, "Failed to Take Photo: %s", msg.c_str());
if (mCamera == NULL)
{
int aa = 0;
return;
}
ALOGE("Failed to Take Photo: %s", msg.c_str());
CPhoneCamera* pCamera = mCamera;
@ -934,7 +992,8 @@ void CPhoneDevice::onError(const std::string& msg)
TakePhotoCb(false, mPhotoInfo, mPath, 0);
std::thread closeThread(&CPhoneDevice::CloseCamera2, pCamera);
bool turnOffOtg = (mPhotoInfo.usbCamera != 0);
std::thread closeThread(&CPhoneDevice::CloseCamera2, this, pCamera, turnOffOtg);
closeThread.detach();
}

@ -221,11 +221,13 @@ protected:
bool OnImageReady(cv::Mat& mat);
void onError(const std::string& msg);
static void CloseCamera2(CPhoneCamera* camera);
void CloseCamera2(CPhoneCamera* camera, bool turnOffOtg);
protected:
JavaVM* m_vm;
jobject m_javaService;
jclass m_sysApiClass;
std::string m_appPath;
jmethodID mRegisterTimerMid;
@ -242,7 +244,8 @@ protected:
jmethodID mEnableGpsMid;
jmethodID mRequestPositionMid;
jmethodID mTurnOtg;
jmethodID mTurnOtgMid;
jmethodID mSetCam3V3EnableMid;
std::string mPath;
IDevice::PHOTO_INFO mPhotoInfo;

@ -85,6 +85,10 @@ NdkCamera::NdkCamera(int32_t width, int32_t height, const NdkCamera::CAMERA_PARA
mWidth = width;
mHeight = height;
m_imagesCaptured = ~0;
afSupported = false;
hdrSupported = false;
nightModeSupported = false;
nightPortraitModeSupported = false;
@ -104,17 +108,7 @@ NdkCamera::~NdkCamera()
{
close();
if (image_reader)
{
AImageReader_delete(image_reader);
image_reader = 0;
}
if (image_reader_surface)
{
ANativeWindow_release(image_reader_surface);
image_reader_surface = 0;
}
}
int NdkCamera::open(const std::string& cameraId) {
@ -207,6 +201,13 @@ int NdkCamera::open(const std::string& cameraId) {
}
{
ACameraMetadata_const_entry e = {0};
camera_status_t status = ACameraMetadata_getConstEntry(camera_metadata,
ACAMERA_CONTROL_AF_AVAILABLE_MODES, &e);
afSupported = !(e.count == 0 || (e.count == 1 && e.data.u8[0] == ACAMERA_CONTROL_AF_MODE_OFF));
}
{
ACameraMetadata_const_entry val = {0};
camera_status_t status = ACameraMetadata_getConstEntry(camera_metadata,
@ -373,6 +374,9 @@ int NdkCamera::open(const std::string& cameraId) {
// uint8_t afMode = ACAMERA_CONTROL_AF_MODE_CONTINUOUS_VIDEO;
uint8_t afMode = ACAMERA_CONTROL_AF_MODE_CONTINUOUS_PICTURE;
res = ACaptureRequest_setEntry_u8(capture_request, ACAMERA_CONTROL_AF_MODE, 1, &afMode);
uint8_t trig = ACAMERA_CONTROL_AF_TRIGGER_START;
res = ACaptureRequest_setEntry_u8(capture_request, ACAMERA_CONTROL_AF_TRIGGER, 1, &trig);
}
uint8_t awbMode = ACAMERA_CONTROL_AWB_MODE_AUTO;
@ -424,8 +428,9 @@ int NdkCamera::open(const std::string& cameraId) {
camera_capture_session_capture_callbacks.onCaptureSequenceAborted = onCaptureSequenceAborted;
camera_capture_session_capture_callbacks.onCaptureBufferLost = 0;
// ACameraCaptureSession_setRepeatingRequest(capture_session, &camera_capture_session_capture_callbacks, 1, &capture_request, nullptr);
ACameraCaptureSession_capture(capture_session, &camera_capture_session_capture_callbacks, 1, &capture_request,nullptr);
m_imagesCaptured = ~0;
ACameraCaptureSession_setRepeatingRequest(capture_session, &camera_capture_session_capture_callbacks, 1, &capture_request, nullptr);
// ACameraCaptureSession_capture(capture_session, &camera_capture_session_capture_callbacks, 1, &capture_request,nullptr);
}
return 0;
@ -440,10 +445,10 @@ void NdkCamera::close()
capture_session = 0;
}
if (camera_device)
if (capture_session_output)
{
ACameraDevice_close(camera_device);
camera_device = 0;
ACaptureSessionOutput_free(capture_session_output);
capture_session_output = 0;
}
if (capture_session_output_container)
@ -452,12 +457,6 @@ void NdkCamera::close()
capture_session_output_container = 0;
}
if (capture_session_output)
{
ACaptureSessionOutput_free(capture_session_output);
capture_session_output = 0;
}
if (capture_request)
{
ACaptureRequest_free(capture_request);
@ -470,6 +469,24 @@ void NdkCamera::close()
image_reader_target = 0;
}
if (image_reader_surface)
{
ANativeWindow_release(image_reader_surface);
image_reader_surface = 0;
}
if (image_reader)
{
AImageReader_delete(image_reader);
image_reader = 0;
}
if (camera_device)
{
ACameraDevice_close(camera_device);
camera_device = 0;
}
if (camera_manager)
{
ACameraManager_delete(camera_manager);
@ -492,6 +509,13 @@ void NdkCamera::onImageAvailable(AImageReader* reader)
return;
}
if (m_imagesCaptured == ~0 || m_imagesCaptured >= 1)
{
// Not Ready Or Taken
AImage_delete(image);
return;
}
if (m_firstFrame)
{
// AImage_delete(image);
@ -579,6 +603,7 @@ void NdkCamera::onImageAvailable(AImageReader* reader)
}
AImage_delete(image);
m_imagesCaptured ++;
}
void NdkCamera::on_error(const std::string& msg)
@ -629,7 +654,6 @@ void NdkCamera::on_image(const unsigned char* nv21, int nv21_width, int nv21_hei
cv::Mat nv21_rotated(h + h / 2, w, CV_8UC1);
ncnn::kanna_rotate_yuv420sp(nv21, nv21_width, nv21_height, nv21_rotated.data, w, h, rotate_type);
#ifdef _DEBUG
if (nv21_rotated.empty())
{
@ -655,9 +679,21 @@ void NdkCamera::onCaptureCompleted(ACameraCaptureSession* session, ACaptureReque
// ACAMERA_SENSOR_EXPOSURE_TIME, 1, &exposureTime_));
// ACameraMetadata_getConstEntry(result, )
ACameraMetadata_const_entry val = { 0 };
camera_status_t status = ACameraMetadata_getConstEntry(result, ACAMERA_SENSOR_EXPOSURE_TIME, &val);
camera_status_t status = ACAMERA_ERROR_BASE;
val = { 0 };
status = ACameraMetadata_getConstEntry(result, ACAMERA_CONTROL_AF_STATE, &val);
uint8_t afState = *(val.data.u8);
m_imagesCaptured = 0;
if (afState == ACAMERA_CONTROL_AF_STATE_PASSIVE_FOCUSED || afState == ACAMERA_CONTROL_AF_STATE_FOCUSED_LOCKED)
// if (afState != ACAMERA_CONTROL_AF_STATE_INACTIVE)
{
m_imagesCaptured = 0;
}
val = { 0 };
status = ACameraMetadata_getConstEntry(result, ACAMERA_SENSOR_EXPOSURE_TIME, &val);
int64_t exTime = (status == ACAMERA_OK) ? val.data.i64[0] : -1;
val = { 0 };
@ -665,7 +701,19 @@ void NdkCamera::onCaptureCompleted(ACameraCaptureSession* session, ACaptureReque
uint8_t aeMode = (status == ACAMERA_OK) ? val.data.u8[0] : 0;
// ACaptureRequest_setEntry_i32(capture_request, ACAMERA_SENSOR_SENSITIVITY, 1, &sensitivity_);
ALOGD("onCaptureCompleted EXPOSURE_TIME=%lld, camera id=%s, AE=%s", exTime, mCameraId.c_str(), ((aeMode == 1) ? "ON" : "OFF"));
val = { 0 };
float focusDistance = NAN;
if (afSupported && (m_params.autoFocus != 0))
{
status = ACameraMetadata_getConstEntry(result, ACAMERA_LENS_FOCUS_DISTANCE, &val);
if (status == ACAMERA_OK)
{
focusDistance = *val.data.f;
}
}
ALOGD("onCaptureCompleted EXPOSURE_TIME=%lld, FocusDis=%f camera id=%s, AE=%s", exTime, focusDistance, mCameraId.c_str(), ((aeMode == 1) ? "ON" : "OFF"));
// __android_log_print(ANDROID_LOG_WARN, "NdkCamera", "onCaptureCompleted %p %p %p", session, request, result);
}

@ -48,6 +48,15 @@ public:
unsigned int sensibility;
};
struct CAPTURE_RESULT
{
unsigned char autoFocus;
unsigned char autoExposure;
unsigned long exposureTime;
float FocusDistance;
unsigned int sensitibity;
};
NdkCamera(int32_t width, int32_t height, const CAMERA_PARAMS& params);
virtual ~NdkCamera();
@ -84,7 +93,9 @@ public:
RangeValue<int32_t> sensitivityRange;
RangeValue<int32_t> aeCompensationRange;
unsigned int m_imagesCaptured;
CAPTURE_RESULT mResult;
private:
ACameraManager* camera_manager;

@ -2,6 +2,7 @@ package com.xypower.mpapp;
import android.Manifest;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.SurfaceTexture;
@ -21,6 +22,7 @@ import android.os.SystemClock;
import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AlertDialog;
import androidx.core.app.ActivityCompat;
import androidx.appcompat.app.AppCompatActivity;
@ -456,8 +458,8 @@ public class MainActivity extends AppCompatActivity {
@Override
public void onClick(View v) {
String path = "/sdcard/com.xypower.mpapp/packages/app.apk";
SysApi.installApk(getApplicationContext(), path, v.getContext().getPackageName(), true);
// String path = "/sdcard/com.xypower.mpapp/packages/app.apk";
// SysApi.installApk(getApplicationContext(), path, v.getContext().getPackageName(), true);
// Context context = MainActivity.this.getApplicationContext();
// MicroPhotoService.sendMessage(context, MicroPhotoService.MSG_WHAT_SENDING_HB, 0);
}
@ -472,9 +474,27 @@ public class MainActivity extends AppCompatActivity {
});
binding.btnReboot.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
SysApi.reboot(v.getContext());
public void onClick(final View v) {
AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
builder.setTitle(R.string.confirm_reboot);
builder.setMessage(R.string.text_confirm_reboot);
builder.setCancelable(true);
builder.setPositiveButton(R.string.btn_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
SysApi.reboot(v.getContext().getApplicationContext());
}
});
builder.setNegativeButton(R.string.btn_cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
builder.show();
}
});

@ -10,6 +10,9 @@
<string name="main_restart_app">重启APP</string>
<string name="main_reboot">重启设备</string>
<string name="confirm_reboot">重启设备</string>
<string name="text_confirm_reboot">确认重启设备吗?</string>
<string name="activity_channel_title">通道设置</string>
<string name="osd_left_top">左上 OSD</string>
<string name="osd_right_top">右上 OSD</string>
@ -17,6 +20,8 @@
<string name="osd_left_bottom">左下 OSD</string>
<string name="channel_cfg_camera_id">Camera Id</string>
<string name="btn_save">保存</string>
<string name="btn_ok">确定</string>
<string name="btn_cancel">取消</string>
<string name="channel_cfg_auto_exposure">自动曝光</string>
<string name="channel_cfg_auto_focus">自动对焦</string>
<string name="channel_cfg_width">照片宽</string>

@ -1,224 +0,0 @@
package com.xypower.mpapp;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.graphics.Rect;
import android.os.IBinder;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.xypower.mpmaster.R;
public class FloatingWindow extends Service {
private Context mContext;
private WindowManager mWindowManager;
private View mView;
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
mContext = this;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
allAboutLayout(intent);
moveView();
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onDestroy() {
try {
if (mView != null) {
mWindowManager.removeView(mView);
}
} catch (Exception ex) {
// ex.printStackTrace();
Log.e("FW", "Exception " + ex.getMessage());
}
super.onDestroy();
}
WindowManager.LayoutParams mWindowsParams;
private void moveView() {
/*
DisplayMetrics metrics = mContext.getResources().getDisplayMetrics();
int width = (int) (metrics.widthPixels * 1f);
int height = (int) (metrics.heightPixels * 1f);
mWindowsParams = new WindowManager.LayoutParams(
width,//WindowManager.LayoutParams.WRAP_CONTENT,
height,//WindowManager.LayoutParams.WRAP_CONTENT,
//WindowManager.LayoutParams.TYPE_SYSTEM_ALERT,
(Build.VERSION.SDK_INT <= 25) ? WindowManager.LayoutParams.TYPE_PHONE : WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
,
//WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN // Not displaying keyboard on bg activity's EditText
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON,
//WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, //Not work with EditText on keyboard
PixelFormat.TRANSLUCENT);
mWindowsParams.gravity = Gravity.TOP | Gravity.LEFT;
//params.x = 0;
mWindowsParams.y = 100;
mWindowManager.addView(mView, mWindowsParams);
mView.setOnTouchListener(new View.OnTouchListener() {
private int initialX;
private int initialY;
private float initialTouchX;
private float initialTouchY;
long startTime = System.currentTimeMillis();
@Override
public boolean onTouch(View v, MotionEvent event) {
if (System.currentTimeMillis() - startTime <= 300) {
return false;
}
if (isViewInBounds(mView, (int) (event.getRawX()), (int) (event.getRawY()))) {
editTextReceiveFocus();
} else {
editTextDontReceiveFocus();
}
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
initialX = mWindowsParams.x;
initialY = mWindowsParams.y;
initialTouchX = event.getRawX();
initialTouchY = event.getRawY();
break;
case MotionEvent.ACTION_UP:
break;
case MotionEvent.ACTION_MOVE:
mWindowsParams.x = initialX + (int) (event.getRawX() - initialTouchX);
mWindowsParams.y = initialY + (int) (event.getRawY() - initialTouchY);
mWindowManager.updateViewLayout(mView, mWindowsParams);
break;
}
return false;
}
});
*/
}
private boolean isViewInBounds(View view, int x, int y) {
Rect outRect = new Rect();
int[] location = new int[2];
view.getDrawingRect(outRect);
view.getLocationOnScreen(location);
outRect.offset(location[0], location[1]);
return outRect.contains(x, y);
}
private void editTextReceiveFocus() {
if (!wasInFocus) {
mWindowsParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
mWindowManager.updateViewLayout(mView, mWindowsParams);
wasInFocus = true;
}
}
private void editTextDontReceiveFocus() {
if (wasInFocus) {
mWindowsParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
mWindowManager.updateViewLayout(mView, mWindowsParams);
wasInFocus = false;
hideKeyboard(mContext, edt1);
}
}
private boolean wasInFocus = true;
private EditText edt1;
private void allAboutLayout(Intent intent) {
LayoutInflater layoutInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mView = layoutInflater.inflate(R.layout.ovelay_window, null);
edt1 = (EditText) mView.findViewById(R.id.edt1);
final TextView tvValue = (TextView) mView.findViewById(R.id.tvValue);
Button btnClose = (Button) mView.findViewById(R.id.btnClose);
edt1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mWindowsParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
mWindowsParams.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE;
mWindowManager.updateViewLayout(mView, mWindowsParams);
wasInFocus = true;
showSoftKeyboard(v);
}
});
edt1.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
tvValue.setText(edt1.getText());
}
@Override
public void afterTextChanged(Editable editable) {
}
});
btnClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
stopSelf();
}
});
}
private void hideKeyboard(Context context, View view) {
if (view != null) {
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
public void showSoftKeyboard(View view) {
if (view.requestFocus()) {
InputMethodManager imm = (InputMethodManager)
getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
}
}
}

@ -45,6 +45,9 @@ public class AppMaster {
public static final String CMD_SET_MNTN = "i1_cmd_set_xy_yw_ip_port";
public static final String CMD_SET_APP_HB = "i1_cmd_set_i1_heart_beat_time";
public static final String CMD_UPDATE_CONFIG = "upd_cfg";
public static final String CMD_HOT_SPOT = "yw_cmd_hot_spot";
public static final String CMD_ENABLE_GPS = "yw_cmd_enable_gps";
public static final String CMD_ENABLE_OTG = "yw_cmd_enable_otg";
public AppMaster(MpMasterService service) {
@ -168,7 +171,20 @@ public class AppMaster {
String name = jsonObject.optString("name", null);
int fieldType = jsonObject.optInt("type", 0);
JSONObject val = jsonObject.optJSONObject("value");
} else if (TextUtils.equals(cmd, CMD_HOT_SPOT)) {
int enable = jsonObject.optInt("enable", 1);
String name = jsonObject.optString("name", "XYMP");
if (enable != 0) {
SysApi.enableApp(mService.getApplicationContext(), name);
} else {
SysApi.disableApp(mService.getApplicationContext(), name);
}
} else if (TextUtils.equals(cmd, CMD_ENABLE_GPS)) {
int enable = jsonObject.optInt("enable", 1);
SysApi.enableGps(mService.getApplicationContext(), (enable != 0));
} else if (TextUtils.equals(cmd, CMD_ENABLE_OTG)) {
int enable = jsonObject.optInt("enable", 1);
SysApi.setOtgState((enable != 0));
}

Loading…
Cancel
Save