public void closeSelf() { SharedPreferences sp = tempContext.getSharedPreferences("SP", Context.MODE_PRIVATE); // 存入数据 Editor editor = sp.edit(); editor.putString("lastUrl", lastUrl); editor.commit(); MyWindowManager.removeBigWindow(tempContext); MyWindowManager.createSmallWindow(tempContext); }
private void initFloatviews() { mManager.setBtnGestureListener( new MyWindowManager.IGestureListener() { @Override public void onShowPress(View view, MotionEvent event) { Message msg = locationHandler.obtainMessage(); msg.arg1 = MODE_CYCLE; switch (view.getId()) { case R.id.left: Log.i(TAG, "left onShowPress."); msg.what = TO_LEFT; break; case R.id.right: Log.i(TAG, "right onShowPress."); msg.what = TO_RIGHT; break; case R.id.top: Log.i(TAG, "top onShowPress."); msg.what = TO_TOP; break; } locationHandler.sendMessage(msg); } @Override public void onPressUp(View view, MotionEvent event) { Log.i(TAG, "left onPressUp."); isMocking = false; } /** * 1.该方法相当于onClick,只有单击才会调用 2.如果用onclick,长按也会被调用,除非有设长按监听setLongClickListener才会区分长按和单击; * * @param view * @param event */ @Override public void onSingleTap(View view, MotionEvent event) { isMocking = false; switch (view.getId()) { case R.id.left: Log.i(TAG, "left button tap. currentThread:" + Thread.currentThread().getId()); mockGpsPoint(TO_LEFT); break; case R.id.right: Log.i(TAG, "right button tap. currentThread:" + Thread.currentThread().getId()); mockGpsPoint(TO_RIGHT); break; case R.id.top: Log.i(TAG, "top button tap. currentThread:" + Thread.currentThread().getId()); mockGpsPoint(TO_TOP); break; } } }); }
@Override public int onStartCommand(Intent intent, int flags, int startId) { Log.i(MockService.TAG, "MockService onStartCommand."); mWorkThread = new HandlerThread("UpdateThread", Process.THREAD_PRIORITY_BACKGROUND); mWorkThread.start(); // Get the Looper for the thread mUpdateLooper = mWorkThread.getLooper(); locationHandler = new LocationHandler(mUpdateLooper); mManager = MyWindowManager.createInstance(MockService.this); lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); try { lm.addTestProvider(providerName, false, false, false, false, false, true, true, 0, 5); lm.setTestProviderEnabled(providerName, true); } catch (SecurityException e1) { Toast.makeText(this, e1.getMessage().toString(), Toast.LENGTH_LONG).show(); e1.printStackTrace(); } initFloatviews(); mLocation = new Location(providerName); if (MainActivity.localLocation != null) { mLocation.setLatitude(MainActivity.localLocation.getLatitude()); mLocation.setLongitude(MainActivity.localLocation.getLongitude()); mLocation.setBearing(MainActivity.localLocation.getBearing()); } else { mLocation.setLatitude(XIAMEN[1]); mLocation.setLongitude(XIAMEN[0]); mLocation.setBearing(0); } return super.onStartCommand(intent, flags, startId); }