/**
   * Adds the status bar view to the window manager.
   *
   * @param statusBarView The view to add.
   * @param barHeight The height of the status bar in collapsed state.
   */
  public void add(View statusBarView, int barHeight) {

    // Now that the status bar window encompasses the sliding panel and its
    // translucent backdrop, the entire thing is made TRANSLUCENT and is
    // hardware-accelerated.
    mLp =
        new WindowManager.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            barHeight,
            WindowManager.LayoutParams.TYPE_STATUS_BAR,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
                | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH
                | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
                | WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS,
            PixelFormat.TRANSLUCENT);
    mLp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
    mLp.gravity = Gravity.TOP;
    mLp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
    mLp.setTitle("StatusBar");
    mLp.packageName = mContext.getPackageName();
    mStatusBarView = statusBarView;
    mBarHeight = barHeight;
    mWindowManager.addView(mStatusBarView, mLp);
    mLpChanged = new WindowManager.LayoutParams();
    mLpChanged.copyFrom(mLp);
  }
  private static final View createScrim(Context context) {
    View view = new View(context);

    int flags =
        WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
            | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
            | WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN
            | WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;

    final int stretch = ViewGroup.LayoutParams.MATCH_PARENT;
    final int type = WindowManager.LayoutParams.TYPE_KEYGUARD_SCRIM;
    WindowManager.LayoutParams lp =
        new WindowManager.LayoutParams(stretch, stretch, type, flags, PixelFormat.TRANSLUCENT);
    lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
    lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
    lp.setTitle("KeyguardScrim");
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    wm.addView(view, lp);
    view.setVisibility(View.GONE);
    // Disable pretty much everything in statusbar until keyguard comes back and we know
    // the state of the world.
    view.setSystemUiVisibility(
        View.STATUS_BAR_DISABLE_HOME
            | View.STATUS_BAR_DISABLE_BACK
            | View.STATUS_BAR_DISABLE_RECENT
            | View.STATUS_BAR_DISABLE_EXPAND
            | View.STATUS_BAR_DISABLE_SEARCH);
    return view;
  }
Exemplo n.º 3
0
  /** 自定义归属地浮窗 */
  private void showToast(String string) {
    windowManager = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);

    WindowManager.LayoutParams params = new WindowManager.LayoutParams();
    params.height = WindowManager.LayoutParams.WRAP_CONTENT;
    params.width = WindowManager.LayoutParams.WRAP_CONTENT;
    params.flags =
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
            | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
            | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
    params.format = PixelFormat.TRANSLUCENT;
    params.type = WindowManager.LayoutParams.TYPE_TOAST;
    params.setTitle("Toast");

    view = View.inflate(this, R.layout.toast_layout, null);

    int[] bgs =
        new int[] {
          R.drawable.call_locate_white,
          R.drawable.call_locate_orange,
          R.drawable.call_locate_blue,
          R.drawable.call_locate_gray,
          R.drawable.call_locate_green
        };
    int style = getSharedPreferences("config", MODE_PRIVATE).getInt("address_style", 0);
    TextView textView = (TextView) view.findViewById(R.id.tv_number);
    view.setBackgroundResource(bgs[style]);
    textView.setText(string);
    windowManager.addView(view, params);
  }
    @Override
    /** 监听电话状态 */
    public void onCallStateChanged(int state, String incomingNumber) {
      // TODO Auto-generated method stub
      super.onCallStateChanged(state, incomingNumber);
      switch (state) {
        case TelephonyManager.CALL_STATE_RINGING:
          if (serviceState) {
            boolean falg = new BlackNumDao(ShowAddressService.this).find(incomingNumber);
            if (falg) {
              ringOff();
              getContentResolver()
                  .registerContentObserver(
                      CallLog.Calls.CONTENT_URI,
                      true,
                      new CallLogChangeObserver(new Handler(), incomingNumber));
              return;
            }
          }

          String value = AddressService.getAddressService(incomingNumber);
          view = inflater.inflate(R.layout.show_phone_address, null);
          TextView address_tv = (TextView) view.findViewById(R.id.show_phone_address_address);
          TextView phone_tv = (TextView) view.findViewById(R.id.show_phone_address_phone);
          address_tv.setText(value);
          String phoneName =
              new MyContentProvider(ShowAddressService.this).getPhoneName(incomingNumber);
          if (phoneName != null) {
            phone_tv.setText(phoneName);
          } else {
            phone_tv.setText(incomingNumber);
          }

          WindowManager.LayoutParams params = new LayoutParams();
          params.height = WindowManager.LayoutParams.WRAP_CONTENT + 70;
          params.width = WindowManager.LayoutParams.WRAP_CONTENT + 200;

          params.y = params.y + 23;
          new Thread(new SaveParamsCoord(params.x, params.y, params.width, params.height)).start();
          params.flags =
              WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                  | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                  | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
          params.format = PixelFormat.TRANSLUCENT;
          params.type = WindowManager.LayoutParams.TYPE_TOAST;
          params.setTitle("Toast");

          windowManager.addView(view, params);
          break;
        case TelephonyManager.CALL_STATE_IDLE:
          if (view != null) {
            windowManager.removeView(view);
            view = null;
          }
        default:
          break;
      }
    }
Exemplo n.º 5
0
  /** @param context everything needs a context :( */
  public GlobalScreenshot(Context context) {
    Resources r = context.getResources();
    mContext = context;
    LayoutInflater layoutInflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    // Inflate the screenshot layout
    mDisplayMatrix = new Matrix();
    mScreenshotLayout = layoutInflater.inflate(R.layout.global_screenshot, null);
    mBackgroundView = (ImageView) mScreenshotLayout.findViewById(R.id.global_screenshot_background);
    mScreenshotView = (ImageView) mScreenshotLayout.findViewById(R.id.global_screenshot);
    mScreenshotFlash = (ImageView) mScreenshotLayout.findViewById(R.id.global_screenshot_flash);
    mScreenshotLayout.setFocusable(true);
    mScreenshotLayout.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            // Intercept and ignore all touch events
            return true;
          }
        });

    // Setup the window that we are going to use
    mWindowLayoutParams =
        new WindowManager.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT,
            0,
            0,
            WindowManager.LayoutParams.TYPE_SECURE_SYSTEM_OVERLAY,
            WindowManager.LayoutParams.FLAG_FULLSCREEN
                | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED
                | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED,
            PixelFormat.TRANSLUCENT);
    mWindowLayoutParams.setTitle("ScreenshotAnimation");
    mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    mNotificationManager =
        (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
    mDisplay = mWindowManager.getDefaultDisplay();
    mDisplayMetrics = new DisplayMetrics();
    mDisplay.getRealMetrics(mDisplayMetrics);

    // Get the various target sizes
    mNotificationIconSize = r.getDimensionPixelSize(android.R.dimen.notification_large_icon_height);

    // Scale has to account for both sides of the bg
    mBgPadding = (float) r.getDimensionPixelSize(R.dimen.global_screenshot_bg_padding);
    mBgPaddingScale = mBgPadding / mDisplayMetrics.widthPixels;

    // Setup the Camera shutter sound
    mCameraSound = new CameraSound();
  }
  private WindowManager.LayoutParams createPopupLayout(IBinder token) {
    WindowManager.LayoutParams p = new WindowManager.LayoutParams();
    p.gravity = Gravity.START | Gravity.TOP;
    p.width = ViewGroup.LayoutParams.MATCH_PARENT;
    p.height = ViewGroup.LayoutParams.MATCH_PARENT;
    p.format = PixelFormat.TRANSLUCENT;
    p.flags = computeFlags(p.flags);
    p.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
    p.token = token;
    p.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN;
    p.setTitle("DiscreteSeekBar Indicator:" + Integer.toHexString(hashCode()));

    return p;
  }
Exemplo n.º 7
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    A.v(MainActivity.class, "onCreate");
    //
    //	//测试FLAG_ACTIVITY_FORWARD_RESULT的使用:MainActivity---startActivityForResult(SecondActivity---startActivity(ThirdActivity
    //		startActivityForResult(new Intent(this, SecondActivity.class), 0x10);

    // 测试添加系统窗口
    Button btn = new Button(getApplicationContext());
    btn.setText("Hello window");
    btn.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            A.i("clicked...");
          }
        });
    WindowManager.LayoutParams lp =
        new WindowManager.LayoutParams(
            150,
            100,
            WindowManager.LayoutParams.TYPE_PRIORITY_PHONE,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING,
            PixelFormat.RGB_888);
    lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
    lp.setTitle("title");
    lp.token = new Binder();
    WindowManager wm = (WindowManager) getApplicationContext().getSystemService("window");
    btn.setTag("123");
    wm.addView(btn, lp);

    super.onCreate(savedInstanceState);

    // 测试ContentObserver
    Uri uri = Uri.parse("test://haha");
    getContentResolver().registerContentObserver(uri, true, new OneContentObserver());
    // 调用notifyChange后,会通知到OneContentObserver
    getContentResolver().notifyChange(uri, null);

    // 测试文件系统更改的通知

    SharedPreferences sp = getSharedPreferences("ad_sp", Context.MODE_PRIVATE);

    sp.registerOnSharedPreferenceChangeListener(new OneSharedPreferenceChangeListener());

    sp.edit().putInt("testkey", 100).commit();
  }
Exemplo n.º 8
0
 @Override
 public void onCreate() {
   super.onCreate();
   // Toast.makeText(getBaseContext(),"onCreate", Toast.LENGTH_LONG).show();
   mView = new HUDView(this);
   WindowManager.LayoutParams params =
       new WindowManager.LayoutParams(
           WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
           WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
           PixelFormat.TRANSLUCENT);
   params.gravity = Gravity.RIGHT | Gravity.TOP;
   params.setTitle("Load Average");
   WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
   wm.addView(mView, params);
 }
Exemplo n.º 9
0
 TN() {
   // XXX This should be changed to use a Dialog, with a Theme.Toast
   // defined that sets up the layout params appropriately.
   final WindowManager.LayoutParams params = mParams;
   params.height = WindowManager.LayoutParams.WRAP_CONTENT;
   params.width = WindowManager.LayoutParams.WRAP_CONTENT;
   params.flags =
       WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
           | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
           | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
   params.format = PixelFormat.TRANSLUCENT;
   params.windowAnimations = com.android.internal.R.style.Animation_Toast;
   params.type = WindowManager.LayoutParams.TYPE_TOAST;
   params.setTitle("Toast");
 }
    private void createWindow() {
      LayoutInflater inflater = LayoutInflater.from(mContext);

      mWindowContent = inflater.inflate(R.layout.overlay_display_window, null);
      mWindowContent.setOnTouchListener(mOnTouchListener);

      mTextureView = (TextureView) mWindowContent.findViewById(R.id.overlay_display_window_texture);
      mTextureView.setPivotX(0);
      mTextureView.setPivotY(0);
      mTextureView.getLayoutParams().width = mWidth;
      mTextureView.getLayoutParams().height = mHeight;
      mTextureView.setOpaque(false);
      mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);

      mNameTextView = (TextView) mWindowContent.findViewById(R.id.overlay_display_window_title);
      mNameTextView.setText(mName);

      mWindowParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
      mWindowParams.flags |=
          WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
              | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
              | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
              | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
              | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
      if (DISABLE_MOVE_AND_RESIZE) {
        mWindowParams.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
      }
      mWindowParams.alpha = WINDOW_ALPHA;
      mWindowParams.gravity = Gravity.TOP | Gravity.LEFT;
      mWindowParams.setTitle(mName);

      mGestureDetector = new GestureDetector(mContext, mOnGestureListener);
      mScaleGestureDetector = new ScaleGestureDetector(mContext, mOnScaleGestureListener);

      // Set the initial position and scale.
      // The position and scale will be clamped when the display is first shown.
      mWindowX = (mGravity & Gravity.LEFT) == Gravity.LEFT ? 0 : mDefaultDisplayMetrics.widthPixels;
      mWindowY = (mGravity & Gravity.TOP) == Gravity.TOP ? 0 : mDefaultDisplayMetrics.heightPixels;
      Log.d(TAG, mDefaultDisplayMetrics.toString());
      mWindowScale = INITIAL_SCALE;

      // calculate and save initial settings
      updateWindowParams();
      saveWindowParams();
    }
 private WindowManager.LayoutParams getLayoutParams() {
   WindowManager.LayoutParams lp =
       new WindowManager.LayoutParams(
           ViewGroup.LayoutParams.MATCH_PARENT,
           mContext.getResources().getDimensionPixelSize(R.dimen.assist_orb_scrim_height),
           WindowManager.LayoutParams.TYPE_VOICE_INTERACTION_STARTING,
           WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
               | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
               | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
           PixelFormat.TRANSLUCENT);
   if (ActivityManager.isHighEndGfx()) {
     lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
   }
   lp.gravity = Gravity.BOTTOM | Gravity.START;
   lp.setTitle("AssistPreviewPanel");
   lp.softInputMode =
       WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED
           | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING;
   return lp;
 }
Exemplo n.º 12
0
  /**
   * Construct an empty OnScreenHint object.
   *
   * @param context The context to use. Usually your {@link android.app.Application} or {@link
   *     android.app.Activity} object.
   */
  private OnScreenHint(Context context) {
    mWM = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    /*
     * Configuration newConfig = context.getResources().getConfiguration();
     * mY = context.getResources().getDimensionPixelSize(
     * newConfig.orientation == Configuration.ORIENTATION_PORTRAIT ?
     * R.dimen.screen_margin_left : R.dimen.screen_margin_right);
     */
    mParams.height = WindowManager.LayoutParams.MATCH_PARENT;
    mParams.width = WindowManager.LayoutParams.MATCH_PARENT;
    mParams.flags =
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
            | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
            | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            | WindowManager.LayoutParams.FLAG_FULLSCREEN;
    mParams.format = PixelFormat.TRANSLUCENT;
    // mParams.windowAnimations = R.style.Animation_OnScreenHint;
    mParams.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
    mParams.setTitle("OnScreenHint");

    mContext = context;
  }
  private void attachBehindWindow(Window window) {
    if (DEBUG) Log.v(TAG, "attachBehindWindow " + window);
    mWindow = window;
    mWindowManager = window.getWindowManager();

    WindowManager.LayoutParams params =
        new WindowManager.LayoutParams(
            // Media window sits behind the main application window
            WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA,
            // Avoid default to software format RGBA
            WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
            android.graphics.PixelFormat.TRANSLUCENT);
    params.setTitle(WINDOW_NAME);
    params.width = ViewGroup.LayoutParams.MATCH_PARENT;
    params.height = ViewGroup.LayoutParams.MATCH_PARENT;

    View backgroundView =
        LayoutInflater.from(mContext).inflate(R.layout.lb_background_window, null);
    mWindowManager.addView(backgroundView, params);

    attachToView(backgroundView);
  }
Exemplo n.º 14
0
 private WindowManager.LayoutParams generateLayoutParam() {
   WindowManager.LayoutParams lp =
       new WindowManager.LayoutParams(
           ViewGroup.LayoutParams.MATCH_PARENT,
           ViewGroup.LayoutParams.MATCH_PARENT,
           WindowManager.LayoutParams.TYPE_STATUS_BAR_PANEL,
           WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
               | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
               | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
               | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON,
           PixelFormat.TRANSLUCENT);
   // Turn on hardware acceleration for high end gfx devices.
   if (ActivityManager.isHighEndGfx()) {
     lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
     lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
   }
   // This title is for debugging only. See: dumpsys window
   lp.setTitle("PieControlPanel");
   lp.windowAnimations = android.R.style.Animation;
   lp.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_BEHIND;
   return lp;
 }
    @Override
    public void show() {
      if (!mWindowVisible) {
        mSurfaceView = new SurfaceView(mContext);

        Display display = mWindowManager.getDefaultDisplay();

        WindowManager.LayoutParams params =
            new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
        params.flags |=
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
                | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
        params.alpha = WINDOW_ALPHA;
        params.gravity = Gravity.LEFT | Gravity.BOTTOM;
        params.setTitle(mName);

        int width = (int) (display.getWidth() * INITIAL_SCALE);
        int height = (int) (display.getHeight() * INITIAL_SCALE);
        if (mWidth > mHeight) {
          height = mHeight * width / mWidth;
        } else {
          width = mWidth * height / mHeight;
        }
        params.width = width;
        params.height = height;

        mWindowManager.addView(mSurfaceView, params);
        mWindowVisible = true;

        SurfaceHolder holder = mSurfaceView.getHolder();
        holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        mListener.onWindowCreated(holder);
      }
    }
Exemplo n.º 16
0
    void updateSurface(boolean forceRelayout, boolean forceReport, boolean redrawNeeded) {
      if (mDestroyed) {
        Log.w(TAG, "Ignoring updateSurface: destroyed");
      }

      int myWidth = mSurfaceHolder.getRequestedWidth();
      if (myWidth <= 0) myWidth = ViewGroup.LayoutParams.MATCH_PARENT;
      int myHeight = mSurfaceHolder.getRequestedHeight();
      if (myHeight <= 0) myHeight = ViewGroup.LayoutParams.MATCH_PARENT;

      final boolean creating = !mCreated;
      final boolean surfaceCreating = !mSurfaceCreated;
      final boolean formatChanged = mFormat != mSurfaceHolder.getRequestedFormat();
      boolean sizeChanged = mWidth != myWidth || mHeight != myHeight;
      final boolean typeChanged = mType != mSurfaceHolder.getRequestedType();
      final boolean flagsChanged =
          mCurWindowFlags != mWindowFlags || mCurWindowPrivateFlags != mWindowPrivateFlags;
      if (forceRelayout
          || creating
          || surfaceCreating
          || formatChanged
          || sizeChanged
          || typeChanged
          || flagsChanged
          || redrawNeeded
          || !mIWallpaperEngine.mShownReported) {

        if (DEBUG)
          Log.v(
              TAG,
              "Changes: creating="
                  + creating
                  + " format="
                  + formatChanged
                  + " size="
                  + sizeChanged);

        try {
          mWidth = myWidth;
          mHeight = myHeight;
          mFormat = mSurfaceHolder.getRequestedFormat();
          mType = mSurfaceHolder.getRequestedType();

          mLayout.x = 0;
          mLayout.y = 0;
          mLayout.width = myWidth;
          mLayout.height = myHeight;

          mLayout.format = mFormat;

          mCurWindowFlags = mWindowFlags;
          mLayout.flags =
              mWindowFlags
                  | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
                  | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
                  | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
          mCurWindowPrivateFlags = mWindowPrivateFlags;
          mLayout.privateFlags = mWindowPrivateFlags;

          mLayout.memoryType = mType;
          mLayout.token = mWindowToken;

          if (!mCreated) {
            mLayout.type = mIWallpaperEngine.mWindowType;
            mLayout.gravity = Gravity.START | Gravity.TOP;
            mLayout.setTitle(WallpaperService.this.getClass().getName());
            mLayout.windowAnimations = com.android.internal.R.style.Animation_Wallpaper;
            mInputChannel = new InputChannel();
            if (mSession.addToDisplay(
                    mWindow,
                    mWindow.mSeq,
                    mLayout,
                    View.VISIBLE,
                    Display.DEFAULT_DISPLAY,
                    mContentInsets,
                    mInputChannel)
                < 0) {
              Log.w(TAG, "Failed to add window while updating wallpaper surface.");
              return;
            }
            mCreated = true;

            mInputEventReceiver = new WallpaperInputEventReceiver(mInputChannel, Looper.myLooper());
          }

          mSurfaceHolder.mSurfaceLock.lock();
          mDrawingAllowed = true;

          final int relayoutResult =
              mSession.relayout(
                  mWindow,
                  mWindow.mSeq,
                  mLayout,
                  mWidth,
                  mHeight,
                  View.VISIBLE,
                  0,
                  mWinFrame,
                  mContentInsets,
                  mVisibleInsets,
                  mConfiguration,
                  mSurfaceHolder.mSurface);

          if (DEBUG) Log.v(TAG, "New surface: " + mSurfaceHolder.mSurface + ", frame=" + mWinFrame);

          int w = mWinFrame.width();
          if (mCurWidth != w) {
            sizeChanged = true;
            mCurWidth = w;
          }
          int h = mWinFrame.height();
          if (mCurHeight != h) {
            sizeChanged = true;
            mCurHeight = h;
          }

          mSurfaceHolder.setSurfaceFrameSize(w, h);
          mSurfaceHolder.mSurfaceLock.unlock();

          if (!mSurfaceHolder.mSurface.isValid()) {
            reportSurfaceDestroyed();
            if (DEBUG) Log.v(TAG, "Layout: Surface destroyed");
            return;
          }

          boolean didSurface = false;

          try {
            mSurfaceHolder.ungetCallbacks();

            if (surfaceCreating) {
              mIsCreating = true;
              didSurface = true;
              if (DEBUG) Log.v(TAG, "onSurfaceCreated(" + mSurfaceHolder + "): " + this);
              onSurfaceCreated(mSurfaceHolder);
              SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks();
              if (callbacks != null) {
                for (SurfaceHolder.Callback c : callbacks) {
                  c.surfaceCreated(mSurfaceHolder);
                }
              }
            }

            redrawNeeded |=
                creating || (relayoutResult & WindowManagerGlobal.RELAYOUT_RES_FIRST_TIME) != 0;

            if (forceReport || creating || surfaceCreating || formatChanged || sizeChanged) {
              if (DEBUG) {
                RuntimeException e = new RuntimeException();
                e.fillInStackTrace();
                Log.w(
                    TAG,
                    "forceReport="
                        + forceReport
                        + " creating="
                        + creating
                        + " formatChanged="
                        + formatChanged
                        + " sizeChanged="
                        + sizeChanged,
                    e);
              }
              if (DEBUG)
                Log.v(
                    TAG,
                    "onSurfaceChanged("
                        + mSurfaceHolder
                        + ", "
                        + mFormat
                        + ", "
                        + mCurWidth
                        + ", "
                        + mCurHeight
                        + "): "
                        + this);
              didSurface = true;
              onSurfaceChanged(mSurfaceHolder, mFormat, mCurWidth, mCurHeight);
              SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks();
              if (callbacks != null) {
                for (SurfaceHolder.Callback c : callbacks) {
                  c.surfaceChanged(mSurfaceHolder, mFormat, mCurWidth, mCurHeight);
                }
              }
            }

            if (redrawNeeded) {
              onSurfaceRedrawNeeded(mSurfaceHolder);
              SurfaceHolder.Callback callbacks[] = mSurfaceHolder.getCallbacks();
              if (callbacks != null) {
                for (SurfaceHolder.Callback c : callbacks) {
                  if (c instanceof SurfaceHolder.Callback2) {
                    ((SurfaceHolder.Callback2) c).surfaceRedrawNeeded(mSurfaceHolder);
                  }
                }
              }
            }

            if (didSurface && !mReportedVisible) {
              // This wallpaper is currently invisible, but its
              // surface has changed.  At this point let's tell it
              // again that it is invisible in case the report about
              // the surface caused it to start running.  We really
              // don't want wallpapers running when not visible.
              if (mIsCreating) {
                // Some wallpapers will ignore this call if they
                // had previously been told they were invisble,
                // so if we are creating a new surface then toggle
                // the state to get them to notice.
                if (DEBUG) Log.v(TAG, "onVisibilityChanged(true) at surface: " + this);
                onVisibilityChanged(true);
              }
              if (DEBUG) Log.v(TAG, "onVisibilityChanged(false) at surface: " + this);
              onVisibilityChanged(false);
            }

          } finally {
            mIsCreating = false;
            mSurfaceCreated = true;
            if (redrawNeeded) {
              mSession.finishDrawing(mWindow);
            }
            mIWallpaperEngine.reportShown();
          }
        } catch (RemoteException ex) {
        }
        if (DEBUG)
          Log.v(
              TAG,
              "Layout: x="
                  + mLayout.x
                  + " y="
                  + mLayout.y
                  + " w="
                  + mLayout.width
                  + " h="
                  + mLayout.height);
      }
    }
  private void maybeCreateKeyguardLocked(
      boolean enableScreenRotation, boolean force, Bundle options) {
    if (mKeyguardHost != null) {
      mKeyguardHost.saveHierarchyState(mStateContainer);
    }

    if (mKeyguardHost == null) {
      if (DEBUG) Log.d(TAG, "keyguard host is null, creating it...");

      mKeyguardHost = new ViewManagerHost(mContext);

      int flags =
          WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
              | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
              | WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN
              | WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;

      if (!mNeedsInput) {
        flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
      }

      final int stretch = ViewGroup.LayoutParams.MATCH_PARENT;
      final int type = WindowManager.LayoutParams.TYPE_KEYGUARD;
      WindowManager.LayoutParams lp =
          new WindowManager.LayoutParams(stretch, stretch, type, flags, PixelFormat.TRANSLUCENT);
      lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
      lp.windowAnimations = R.style.Animation_LockScreen;
      lp.screenOrientation =
          enableScreenRotation
              ? ActivityInfo.SCREEN_ORIENTATION_USER
              : ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;

      if (ActivityManager.isHighEndGfx()) {
        lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
        lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
      }
      lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SET_NEEDS_MENU_KEY;
      /// M: Poke user activity when operating Keyguard
      // lp.inputFeatures |= WindowManager.LayoutParams.INPUT_FEATURE_DISABLE_USER_ACTIVITY;
      lp.setTitle("Keyguard");
      mWindowLayoutParams = lp;
      /// M: skip add KeyguardHost into viewManager in AT case
      if (!KeyguardViewMediator.isKeyguardInActivity) {
        mViewManager.addView(mKeyguardHost, lp);
      } else {
        if (DEBUG) Log.d(TAG, "skip add mKeyguardHost into mViewManager for testing");
      }
      KeyguardUpdateMonitor.getInstance(mContext).registerCallback(mBackgroundChanger);
    }

    /// M: If force and keyguardView is not null, we should relase memory hold by old keyguardview
    if (force && mKeyguardView != null) {
      mKeyguardView.cleanUp();
    }

    if (force || mKeyguardView == null) {
      mKeyguardHost.setCustomBackground(null);
      mKeyguardHost.removeAllViews();
      inflateKeyguardView(options);
      mKeyguardView.requestFocus();
    }
    updateUserActivityTimeoutInWindowLayoutParams();
    mViewManager.updateViewLayout(mKeyguardHost, mWindowLayoutParams);

    mKeyguardHost.restoreHierarchyState(mStateContainer);
  }
Exemplo n.º 18
0
  public void onCreate() {
    int flags, screenLightVal = 1;
    Sensor mSensor;
    List<Sensor> sensors;

    if (scanData == null) return; // no ScanData, not possible to run correctly...

    PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
    SP = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
    try {
      screenLightVal = Integer.parseInt(SP.getString("screenLight", "2"));
    } catch (NumberFormatException nfe) {
    }
    if (screenLightVal == 1) flags = PowerManager.PARTIAL_WAKE_LOCK;
    else if (screenLightVal == 3) flags = PowerManager.FULL_WAKE_LOCK;
    else flags = PowerManager.SCREEN_DIM_WAKE_LOCK;
    wl = pm.newWakeLock(flags, "OpenWLANMap");
    wl.acquire();
    while (myWLocate == null) {
      try {
        myWLocate = new MyWLocate(this);
        break;
      } catch (IllegalArgumentException iae) {
        myWLocate = null;
      }
      try {
        Thread.sleep(100);
      } catch (InterruptedException ie) {
      }
    }

    try {
      scanData.setUploadThres(Integer.parseInt(SP.getString("autoUpload", "0")));
    } catch (NumberFormatException nfe) {
    }
    try {
      scanData.setNoGPSExitInterval(
          Integer.parseInt(SP.getString("noGPSExitInterval", "0")) * 60 * 1000);
    } catch (NumberFormatException nfe) {
    }

    Intent intent = new Intent(this, OWMapAtAndroid.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    PendingIntent pendIntent = PendingIntent.getActivity(this, 0, intent, 0);

    notification =
        new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.icon)
            .setContentTitle(getResources().getText(R.string.app_name))
            .setContentText("")
            .setContentIntent(pendIntent)
            .build();

    notification.flags |= Notification.FLAG_NO_CLEAR;
    notification.flags |= Notification.FLAG_ONGOING_EVENT;
    startForeground(1703, notification);

    getScanData().setService(this);
    getScanData().setmView(new HUDView(this));
    getScanData().getmView().setValue(getScanData().incStoredValues());
    WindowManager.LayoutParams params =
        new WindowManager.LayoutParams(
            WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
            WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
                | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
            PixelFormat.TRANSLUCENT);
    params.gravity = Gravity.LEFT | Gravity.BOTTOM;
    params.setTitle("Load Average");
    WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
    wm.addView(getScanData().getmView(), params);

    sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);

    sensorManager.registerListener(
        this,
        sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
        SensorManager.SENSOR_DELAY_GAME);
    sensorManager.registerListener(
        this,
        sensorManager.getDefaultSensor(Sensor.TYPE_ORIENTATION),
        SensorManager.SENSOR_DELAY_GAME);
    sensors = sensorManager.getSensorList(Sensor.TYPE_ACCELEROMETER);
    mSensor = sensors.get(0);
    getScanData().getTelemetryData().setAccelMax(mSensor.getMaximumRange());
    telemetryDir = Environment.getExternalStorageDirectory().getPath() + "/telemetry/";
    File dir = new File(telemetryDir);
    dir.mkdir();

    connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
  }
  /** Show the keyguard. Will handle creating and attaching to the view manager lazily. */
  public synchronized void show() {
    if (DEBUG) Log.d(TAG, "show(); mKeyguardView==" + mKeyguardView);

    Resources res = mContext.getResources();
    boolean enableScreenRotation =
        SystemProperties.getBoolean("lockscreen.rot_override", false)
            || res.getBoolean(R.bool.config_enableLockScreenRotation);
    enableScreenRotation =
        Settings.System.getInt(
                mContext.getContentResolver(),
                Settings.System.LOCKSCREEN_LANDSCAPE,
                enableScreenRotation ? 1 : 0)
            == 1;
    if (mKeyguardHost == null) {
      if (DEBUG) Log.d(TAG, "keyguard host is null, creating it...");

      mKeyguardHost = new KeyguardViewHost(mContext, mCallback);

      final int stretch = ViewGroup.LayoutParams.MATCH_PARENT;
      int flags =
          WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN
              | WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER
              | WindowManager.LayoutParams.FLAG_KEEP_SURFACE_WHILE_ANIMATING
          /*| WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
          | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR*/ ;
      if (!mNeedsInput) {
        flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
      }
      if (ActivityManager.isHighEndGfx(
          ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE))
              .getDefaultDisplay())) {
        flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
      }
      WindowManager.LayoutParams lp =
          new WindowManager.LayoutParams(
              stretch,
              stretch,
              WindowManager.LayoutParams.TYPE_KEYGUARD,
              flags,
              PixelFormat.TRANSLUCENT);
      lp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
      lp.windowAnimations = com.android.internal.R.style.Animation_LockScreen;
      if (ActivityManager.isHighEndGfx(
          ((WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE))
              .getDefaultDisplay())) {
        lp.flags |= WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
        lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
      }
      lp.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SET_NEEDS_MENU_KEY;
      lp.setTitle("Keyguard");
      mWindowLayoutParams = lp;

      mViewManager.addView(mKeyguardHost, lp);
    }

    if (enableScreenRotation
        && Settings.System.getInt(
                mContext.getContentResolver(), Settings.System.ACCELEROMETER_ROTATION, 1)
            == 1) {
      if (DEBUG) Log.d(TAG, "Rotation sensor for lock screen On!");
      mWindowLayoutParams.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR;
    } else {
      if (DEBUG) Log.d(TAG, "Rotation sensor for lock screen Off!");
      mWindowLayoutParams.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
    }

    mViewManager.updateViewLayout(mKeyguardHost, mWindowLayoutParams);

    if (mKeyguardView == null) {
      if (DEBUG) Log.d(TAG, "keyguard view is null, creating it...");
      mKeyguardView = mKeyguardViewProperties.createKeyguardView(mContext, mUpdateMonitor, this);
      mKeyguardView.setId(R.id.lock_screen);
      mKeyguardView.setCallback(mCallback);

      final ViewGroup.LayoutParams lp =
          new FrameLayout.LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

      mKeyguardHost.addView(mKeyguardView, lp);

      if (mScreenOn) {
        mKeyguardView.show();
      }
    }

    // Disable aspects of the system/status/navigation bars that are not appropriate or
    // useful for the lockscreen but can be re-shown by dialogs or SHOW_WHEN_LOCKED activities.
    // Other disabled bits are handled by the KeyguardViewMediator talking directly to the
    // status bar service.
    int visFlags = (View.STATUS_BAR_DISABLE_BACK | View.STATUS_BAR_DISABLE_HOME);
    mKeyguardHost.setSystemUiVisibility(visFlags);

    mViewManager.updateViewLayout(mKeyguardHost, mWindowLayoutParams);
    mKeyguardHost.setVisibility(View.VISIBLE);
    mKeyguardView.requestFocus();
  }