예제 #1
1
  @Override
  public void onCreate() {

    super.onCreate();

    sp = getSharedPreferences("date", 0);
    sp_setting = PreferenceManager.getDefaultSharedPreferences(this);
    sp_userinfo = getSharedPreferences("userinfo", 0);
    C.FRAME = Integer.parseInt(sp_setting.getString("Frame", "60"));
    Wm = (WindowManager) getApplication().getSystemService(Context.WINDOW_SERVICE);
    wmParams = new WindowManager.LayoutParams();
    wmParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
    // 设置悬浮窗为全屏
    wmParams.flags = 1280;
    wmParams.format = PixelFormat.RGBA_8888;
    wmParams.alpha = 0.8f;
    wmParams.gravity = Gravity.LEFT | Gravity.BOTTOM;
    wmParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
    wmParams.height = ViewGroup.LayoutParams.MATCH_PARENT;

    Wm_control = (WindowManager) getApplication().getSystemService(Context.WINDOW_SERVICE);
    wmParams_control = new WindowManager.LayoutParams();
    wmParams_control.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
    wmParams_control.format = PixelFormat.RGB_888;
    wmParams_control.flags =
        WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
            | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
            | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
    wmParams_control.alpha = 0;
    wmParams_control.width = 0;
    wmParams_control.height = 0;
    win_control = new View(this);
    Wm_control.addView(win_control, wmParams_control);

    // 注册系统广播
    sr = new ScreenReceiver();
    sr.registerScreenActionReceiver(MSSService.this);
    registerBattery();

    // 注册自己程序的广播
    IntentFilter inf = new IntentFilter();
    inf.addAction("com.jiusg.mainscreenshow");
    mssr = new MSSReceiver();
    registerReceiver(mssr, inf);

    sa_IsEvent = new SparseBooleanArray();
    sa_Animation = new SparseArray<Integer>();
    animManage = new AnimationManage(Wm, wmParams, getApplicationContext());

    isView = false;

    mHandler = new MssHandler();

    imageCache = new ImageCache(getApplicationContext());

    AVAnalytics.onEvent(MSSService.this, "Server Create", TAG);

    startService(new Intent(this, MSSLiveWallpaper.class));
  }
  /**
   * Show the controller on screen. It will go away automatically after 'timeout' milliseconds of
   * inactivity.
   *
   * @param timeout The timeout in milliseconds. Use 0 to show the controller until hide() is
   *     called.
   */
  public void show(int timeout) {

    if (!mShowing && mAnchor != null) {
      setProgress();

      int[] anchorpos = new int[2];
      mAnchor.getLocationOnScreen(anchorpos);

      WindowManager.LayoutParams p = new WindowManager.LayoutParams();
      p.gravity = Gravity.TOP;
      p.width = mAnchor.getWidth();
      p.height = LayoutParams.WRAP_CONTENT;
      p.x = 0;
      p.y = anchorpos[1] + mAnchor.getHeight() - p.height;
      p.format = PixelFormat.TRANSLUCENT;
      p.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
      p.flags |= WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
      p.token = null;
      p.windowAnimations = 0; // android.R.style.DropDownAnimationDown;
      mWindowManager.addView(mDecor, p);
      mShowing = true;
    }
    updatePausePlay();

    // cause the progress bar to be updated even if mShowing
    // was already true.  This happens, for example, if we're
    // paused with the progress bar showing the user hits play.
    mHandler.sendEmptyMessage(SHOW_PROGRESS);

    Message msg = mHandler.obtainMessage(FADE_OUT);
    if (timeout != 0) {
      mHandler.removeMessages(FADE_OUT);
      mHandler.sendMessageDelayed(msg, timeout);
    }
  }
예제 #3
0
  @Override
  public void initialize(CordovaInterface cordova, CordovaWebView webView) {

    super.initialize(cordova, webView);

    WindowManager manager =
        ((WindowManager)
            cordova.getActivity().getApplicationContext().getSystemService(Context.WINDOW_SERVICE));

    WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
    localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
    localLayoutParams.gravity = Gravity.TOP;
    localLayoutParams.flags =
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
            |

            // this is to enable the notification to recieve touch events
            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
            |

            // Draws over status bar
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;

    localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
    localLayoutParams.height =
        (int) (30 * cordova.getActivity().getResources().getDisplayMetrics().scaledDensity);
    localLayoutParams.format = PixelFormat.TRANSPARENT;

    CustomViewGroup view = new CustomViewGroup(cordova.getActivity().getApplicationContext());

    manager.addView(view, localLayoutParams);
  }
예제 #4
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);
  }
  @DSComment("From safe class list")
  @DSSafe(DSCat.SAFE_LIST)
  @DSGenerator(
      tool_name = "Doppelganger",
      tool_version = "2.0",
      generated_on = "2013-12-30 12:27:59.218 -0500",
      hash_original_method = "E0AAB102B3ED3AF261F94C84219E8ECE",
      hash_generated_method = "AFAC94750396B597F8BB4B9A0515357A")
  @DSVerified
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    WindowManager.LayoutParams params = getWindow().getAttributes();
    params.token = mView.getApplicationWindowToken();
    params.type = params.TYPE_APPLICATION_ATTACHED_DIALOG;
    params.flags = params.flags | Window.FEATURE_NO_TITLE;

    setContentView(R.layout.character_picker);

    GridView grid = (GridView) findViewById(R.id.characterPicker);
    grid.setAdapter(new OptionsAdapter(getContext()));
    grid.setOnItemClickListener(this); // this will trigger onItemClick

    mCancelButton = (Button) findViewById(R.id.cancel);
    mCancelButton.setOnClickListener(this);
  }
  private void initView() {
    mWM = (WindowManager) mContext.getSystemService(WINDOW_SERVICE);
    mTextView =
        new TextView(mContext) {
          @Override
          protected void onDraw(android.graphics.Canvas canvas) {
            int t = getTop();
            int l = getLeft();
            int b = getBottom();
            int r = getRight();
            mRect.top = t;
            mRect.left = t;
            mRect.right = r;
            mRect.bottom = b;
            canvas.drawRect(mRect, mPaint);
            super.onDraw(canvas);
          };
        };

    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.type = 2002;
    // wmParams.format=1;
    lp.flags |= 8;

    lp.gravity = Gravity.LEFT | Gravity.TOP; // 调整悬浮窗口至左上角
    // 以屏幕左上角为原点,设置x、y初始值
    lp.x = 0;
    lp.y = 0;

    // 设置悬浮窗口长宽数据
    lp.width = 300;
    lp.height = 25;
    mTextView.setText("");
    mWM.addView(mTextView, lp);
  }
    @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;
      }
    }
예제 #8
0
  private void showDialog(Dialog dialog) {

    Window dialogWindow = dialog.getWindow();

    WindowManager.LayoutParams param = dialogWindow.getAttributes();

    param.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;

    dialogWindow.setAttributes(param);

    dialog.show();
  }
예제 #9
0
 public OverlayDialog(Activity activity) {
   super(activity, R.style.OverlayDialog);
   WindowManager.LayoutParams params = getWindow().getAttributes();
   params.type = TYPE_SYSTEM_ALERT;
   params.dimAmount = 0.0F; // transparent
   params.width = 0;
   params.height = 0;
   params.gravity = Gravity.BOTTOM;
   getWindow().setAttributes(params);
   getWindow().setFlags(FLAG_SHOW_WHEN_LOCKED | FLAG_NOT_TOUCH_MODAL, 0xffffff);
   setOwnerActivity(activity);
   setCancelable(false);
 }
예제 #10
0
 private android.view.WindowManager.LayoutParams createPopupLayout(IBinder token) {
   android.view.WindowManager.LayoutParams p = new android.view.WindowManager.LayoutParams();
   p.gravity = 51;
   p.width = mWidth;
   p.height = mHeight;
   p.format = -3;
   p.flags = 16;
   if (!mFocusable) p.flags |= 8;
   p.type = 1000;
   p.token = token;
   p.animation = 0x102002c;
   return p;
 }
  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;
  }
    @Override
    public void onCallStateChanged(int state, String incomingNumber) {
      switch (state) {
          // 电话铃声正在响
        case TelephonyManager.CALL_STATE_RINGING:
          // 查询出电话号码的归属地
          NumberAddressDao numberAddressDao = new NumberAddressDao(getApplicationContext());
          String address = numberAddressDao.getAddress(incomingNumber);

          // 通过布局填充器将布局转换为view
          view = View.inflate(getApplicationContext(), R.layout.show_address, null);
          LinearLayout ll = (LinearLayout) view.findViewById(R.id.ll_show_address);
          int style = sp.getInt("which", 0);
          ll.setBackgroundResource(bg_styles[style]);
          TextView tv = (TextView) view.findViewById(R.id.tv_show_address);
          tv.setText(address);

          final 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;
          // 显示在窗体上的style为半透明
          params.format = PixelFormat.TRANSLUCENT;
          // 窗体view的类型为吐司
          params.type = WindowManager.LayoutParams.TYPE_TOAST;
          windowManager.addView(view, params);
          break;
          // 电话空闲状态
        case TelephonyManager.CALL_STATE_IDLE:
          // 将窗体上的吐司移除
          if (view != null) {
            windowManager.removeView(view);
            view = null;
          }
          break;
          // 电话接通状态
        case TelephonyManager.CALL_STATE_OFFHOOK:
          // 将窗体上的吐司移除
          if (view != null) {
            windowManager.removeView(view);
            view = null;
          }
          break;
      }

      super.onCallStateChanged(state, incomingNumber);
    }
예제 #13
0
 // Allocate and initialize the static parts of mDecorLayoutParams. Must
 // also call updateFloatingWindowLayout() to fill in the dynamic parts
 // (y and width) before mDecorLayoutParams can be used.
 private void initFloatingWindowLayout() {
   mDecorLayoutParams = new WindowManager.LayoutParams();
   WindowManager.LayoutParams p = mDecorLayoutParams;
   p.gravity = Gravity.TOP | Gravity.LEFT;
   p.height = LayoutParams.WRAP_CONTENT;
   p.x = 0;
   p.format = PixelFormat.TRANSLUCENT;
   p.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
   p.flags |=
       WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
           | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
           | WindowManager.LayoutParams.FLAG_SPLIT_TOUCH;
   p.token = null;
   p.windowAnimations = 0; // android.R.style.DropDownAnimationDown;
 }
예제 #14
0
 // 设置LayoutParams
 private void setLayoutParams() {
   if (null == mLayoutParams) {
     mLayoutParams = new WindowManager.LayoutParams();
     mLayoutParams.type = LayoutParams.TYPE_SYSTEM_ERROR;
     mLayoutParams.gravity = Gravity.LEFT | Gravity.TOP;
     mLayoutParams.x = 0;
     mLayoutParams.y = 0;
     mLayoutParams.format = PixelFormat.RGBA_8888;
     mLayoutParams.width = WindowManager.LayoutParams.FILL_PARENT;
     mLayoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
     mLayoutParams.flags |=
         WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
             | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
   }
 }
예제 #15
0
파일: Toast.java 프로젝트: Jiangyi/12055
 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");
 }
예제 #16
0
  private void addWindow() {
    WindowManager.LayoutParams params = new WindowManager.LayoutParams();
    params.type = WindowManager.LayoutParams.TYPE_KEYGUARD;
    //		 params.type = WindowManager.LayoutParams.TYPE_SYSTEM_DIALOG;
    //		params.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
    //				| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
    //		 params.flags = WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN
    //                 |  WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM;
    params.flags =
        WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
            | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
    params.width = 0; // WindowManager.LayoutParams.FILL_PARENT;
    params.height = 0; // WindowManager.LayoutParams.FILL_PARENT;
    params.format = PixelFormat.TRANSLUCENT;
    params.gravity = Gravity.LEFT | Gravity.TOP;
    // ����Ļ���Ͻ�Ϊԭ�㣬����x��y��ʼֵ
    params.x = 0;
    params.y = 0;

    wm.addView(v, params);
    v.requestFocus();
    v.setOnKeyListener(
        new OnKeyListener() {
          public boolean onKey(View v, int keyCode, KeyEvent event) {
            switch (event.getAction()) {
              case KeyEvent.ACTION_DOWN:
                mKeyTestView.setKeyDown(event.getKeyCode());
                break;
              case KeyEvent.ACTION_UP:
                mKeyTestView.setKeyUp(event.getKeyCode());
                if (keyCode == KeyEvent.KEYCODE_HOME) {
                  Log.d(
                      TAG,
                      getWindow().getAttributes().type
                          + " _____________---- onKeyEEEE(),   "
                          + event.getKeyCode());
                  return true;
                }

                break;
            }
            return false;
          }
        });
  }
예제 #17
0
  /** @Method: showTopWindow @Description: 显示最顶层view */
  public void showTopWindow(Activity c) {
    this.a = c;
    View views = null;
    if (PadUtils.isPad(this)) {
      views = LayoutInflater.from(this).inflate(R.layout.pad_splash_screen, null);
    } else {
      views = LayoutInflater.from(this).inflate(R.layout.phone_splash_screen, null);
    }
    WindowManager windowManager =
        (WindowManager) getApplicationContext().getSystemService(WINDOW_SERVICE);
    WindowManager.LayoutParams params = new WindowManager.LayoutParams();
    params.type =
        WindowManager.LayoutParams.TYPE_SYSTEM_ALERT
            | WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
    int screenWidth = windowManager.getDefaultDisplay().getWidth();
    int screenHeight = windowManager.getDefaultDisplay().getHeight(); // 屏幕高
    params.x = 0;
    params.y = 0;
    params.width = screenWidth;
    if (PadUtils.isPad(this)) {
      params.height = screenHeight;

    } else {
      params.height = screenHeight - getStatusHeight(c);
    }
    final View view = views;
    // topWindow显示到最顶部
    windowManager.addView(view, params);

    new Thread(
            new Runnable() {
              @Override
              public void run() {
                try {
                  Thread.sleep(2400);
                  clearTopWindow(view);

                } catch (InterruptedException e) {
                  e.printStackTrace();
                }
              }
            })
        .start();
  }
예제 #18
0
  private void configureOverlayBeforeShow() {
    // The overlay shouldn't capture touch events
    final WindowManager.LayoutParams params = mOverlay.getParams();
    params.type = WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
    params.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
    params.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;

    /* The overlay covers the entire screen. However, there is a left, top, right, and
     * bottom margin.  */
    final WindowManager wm =
        (WindowManager) mOverlay.getContext().getSystemService(Context.WINDOW_SERVICE);
    final Point size = new Point();
    wm.getDefaultDisplay().getRealSize(size);
    params.height = size.y;
    params.width = size.x;
    params.x = 0;
    params.y = 0;

    mOverlay.setParams(params);
  }
  private void createFloatCiew() {
    Point windowSize = new Point();
    this.getWindowManager().getDefaultDisplay().getSize(windowSize);
    myFV = new FloatFrame(getApplicationContext());
    // 获取WindowManager
    wm = (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
    // 设置LayoutParams(全局变量)相关参数
    wmParams = ((FloatApplication) getApplication()).getWmParams();

    /** 以下都是WindowManager.LayoutParams的相关属性 具体用途可参考SDK文档 */
    wmParams.type = 2003; // LayoutParams.TYPE_PHONE; // 设置window type
    wmParams.format = PixelFormat.RGBA_8888; // 设置图片格式,效果为背景透明

    // 设置Window flag
    wmParams.flags = LayoutParams.FLAG_NOT_TOUCH_MODAL | LayoutParams.FLAG_NOT_FOCUSABLE;

    /*
     * 下面的flags属性的效果形同“锁定”。 悬浮窗不可触摸,不接受任何事件,同时不影响后面的事件响应。
     * wmParams.flags=LayoutParams.FLAG_NOT_TOUCH_MODAL |
     * LayoutParams.FLAG_NOT_FOCUSABLE | LayoutParams.FLAG_NOT_TOUCHABLE;
     */

    wmParams.gravity = Gravity.LEFT | Gravity.TOP; // 调整悬浮窗口至左上角
    //      wmParams.gravity = Gravity.CENTER_VERTICAL | Gravity.RIGHT; // 调整悬浮窗口至左上角
    // 设置默认显示位置
    //      wmParams.x = 0;<span style="font-family: Arial, Helvetica, sans-serif;">//
    // 以屏幕左上角为原点,设置x、y初始值</span>
    //      wmParams.y = 0;
    wmParams.x = windowSize.x;
    // <span style="font-family: Arial, Helvetica, sans-serif;"> </span>

    wmParams.y = windowSize.y / 2;

    // 设置悬浮窗口长宽数据
    wmParams.width = android.view.ViewGroup.LayoutParams.WRAP_CONTENT; // 40;
    wmParams.height = android.view.ViewGroup.LayoutParams.WRAP_CONTENT; // 40;

    // 显示myFloatView图像
    wm.addView(myFV, wmParams);
  }
예제 #20
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;
  }
예제 #21
0
  public void show(int x, int y) {

    wmParams = new WindowManager.LayoutParams();
    wmParams.type =
        WindowManager.LayoutParams.TYPE_SYSTEM_ALERT
            | WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
    wmParams.flags =
        WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
            | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
    wmParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
    wmParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
    wmParams.format = PixelFormat.TRANSLUCENT;

    if (x != -1) {
      wmParams.x = x;
    }
    if (y != -1) {
      wmParams.y = y;
    }

    windowMgr.addView(view, wmParams);
  }
  /**
   * Generate the layout parameters for the popup window.
   *
   * @param token the window token used to bind the popup's window
   * @return the layout parameters to pass to the window manager
   */
  private WindowManager.LayoutParams createPopupLayout(IBinder token) {
    // generates the layout parameters for the drop down
    // we want a fixed size view located at the bottom left of the anchor
    WindowManager.LayoutParams p = new WindowManager.LayoutParams();
    // these gravity settings put the view at the top left corner of the
    // screen. The view is then positioned to the appropriate location
    // by setting the x and y offsets to match the anchor's bottom
    // left corner
    p.gravity = Gravity.LEFT | Gravity.TOP;
    p.width = mWidth;
    p.height = mHeight;
    if (mBackground != null) {
      p.format = mBackground.getOpacity();
    } else {
      p.format = PixelFormat.TRANSLUCENT;
    }
    p.flags = computeFlags(p.flags);
    p.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
    p.token = token;

    return p;
  }
예제 #23
0
  private void createFloatingWindow() {
    SharedPreferences shared = getSharedPreferences("float_flag", Activity.MODE_PRIVATE);
    SharedPreferences.Editor editor = shared.edit();
    editor.putInt("float", 1);
    editor.commit();
    windowManager = (WindowManager) getApplicationContext().getSystemService("window");
    wmParams = ((ProfilerApplication) getApplication()).getMywmParams();
    wmParams.type = 2002;
    wmParams.flags |= 8;
    wmParams.gravity = Gravity.LEFT | Gravity.TOP;
    wmParams.x = 0;
    wmParams.y = 0;
    wmParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
    wmParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
    wmParams.format = 1;
    windowManager.addView(floatingView, wmParams);
    floatingView.setOnTouchListener(
        new View.OnTouchListener() {
          public boolean onTouch(View v, MotionEvent event) {
            x = event.getRawX();
            y = event.getRawY() - 25;
            switch (event.getAction()) {
              case MotionEvent.ACTION_DOWN:
                mTouchStartX = event.getX();
                mTouchStartY = event.getY();
                break;
              case MotionEvent.ACTION_MOVE:
                updateViewPosition();
                break;

              case MotionEvent.ACTION_UP:
                updateViewPosition();
                mTouchStartX = mTouchStartY = 0;
                break;
            }
            return true;
          }
        });
  }
예제 #24
0
  @SuppressWarnings("deprecation")
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub

    super.onCreate(savedInstanceState);
    getWindow().setType(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
    getWindow()
        .addFlags(
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
    setContentView(R.layout.activity_main);
    sLockscreenActivityContext = this;

    WindowManager manager =
        ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE));
    WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
    localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
    localLayoutParams.gravity = Gravity.TOP;
    localLayoutParams.flags =
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
            | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
            | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
    localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
    localLayoutParams.height = (int) (50 * getResources().getDisplayMetrics().scaledDensity);
    localLayoutParams.format = PixelFormat.TRANSPARENT;
    customViewGroup view = new customViewGroup(this);
    manager.addView(view, localLayoutParams);

    setLockGuard();

    mHomeKeyLocker = new HomeKeyLocker();
    PrefUtils.setKioskModeActive(true, getApplicationContext());
    mHomeKeyLocker.lock(MainActivity.this);
  }
예제 #25
0
  private void createView() {
    floatView = new FloatView(getApplicationContext());
    floatView.setOnClickListener(this);
    floatView.setImageResource(
        R.drawable.suspended /*ic_launcher*/); // 锟斤拷锟斤拷虻サ锟斤拷锟斤拷源锟斤拷icon锟斤拷锟斤拷锟斤拷示
    floatView.setAlpha(80);
    // 锟斤拷取WindowManager
    windowManager =
        (WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
    // 锟斤拷锟斤拷LayoutParams(全锟街憋拷锟斤拷锟斤拷锟斤拷夭锟斤拷锟�
    windowManagerParams = ((Application) getApplication()).getMywmParams();

    windowManagerParams.type = LayoutParams.TYPE_PHONE; // 锟斤拷锟斤拷window type
    windowManagerParams.format = PixelFormat.RGBA_8888; // 锟斤拷锟斤拷图片锟斤拷式锟斤拷效锟斤拷为锟斤拷锟斤拷透锟斤拷
    // 锟斤拷锟斤拷Window flag
    windowManagerParams.flags = LayoutParams.FLAG_NOT_TOUCH_MODAL | LayoutParams.FLAG_NOT_FOCUSABLE;
    /*
     * 注锟解,flag锟斤拷值锟斤拷锟斤拷为锟斤拷
     * 锟斤拷锟斤拷锟絝lags锟斤拷锟皆碉拷效锟斤拷锟斤拷同锟斤拷锟斤拷锟斤拷
     * 锟斤拷锟斤拷纱锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷魏锟斤拷录锟�同时锟斤拷影锟斤拷锟斤拷锟斤拷锟铰硷拷锟斤拷应锟斤拷
     * LayoutParams.FLAG_NOT_TOUCH_MODAL 锟斤拷影锟斤拷锟斤拷锟斤拷锟铰硷拷
     * LayoutParams.FLAG_NOT_FOCUSABLE  锟斤拷锟缴聚斤拷
     * LayoutParams.FLAG_NOT_TOUCHABLE 锟斤拷锟缴达拷锟斤拷
     */
    // 锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷锟斤拷辖牵锟斤拷锟斤拷诘锟斤拷锟斤拷锟斤拷
    windowManagerParams.gravity = Gravity.LEFT | Gravity.TOP;
    // 锟斤拷锟斤拷幕锟斤拷锟较斤拷为原锟姐,锟斤拷锟斤拷x锟斤拷y锟斤拷始值
    windowManagerParams.x = /*0*/ mShare.getInt("x", 0);
    windowManagerParams.y = /*0*/ mShare.getInt("y", 0);
    // 锟斤拷锟斤拷锟斤拷诔锟斤拷锟斤拷锟斤拷
    windowManagerParams.width = LayoutParams.WRAP_CONTENT;
    windowManagerParams.height = LayoutParams.WRAP_CONTENT;
    // 锟斤拷示myFloatView图锟斤拷
    windowManager.addView(floatView, windowManagerParams);

    //		mShare.edit().putBoolean("use_suspend_icon", true).commit();
  }
예제 #26
0
  /**
   * コンストラクタ
   *
   * @param context {@link android.content.Context}
   */
  FloatingView(final Context context) {
    super(context);
    mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    mParams = new WindowManager.LayoutParams();
    mMetrics = new DisplayMetrics();
    mWindowManager.getDefaultDisplay().getMetrics(mMetrics);
    mParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
    mParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    mParams.type = WindowManager.LayoutParams.TYPE_PRIORITY_PHONE;
    mParams.flags =
        WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
            | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
            | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL;
    mParams.format = PixelFormat.TRANSLUCENT;
    // 左下の座標を0とする
    mParams.gravity = Gravity.LEFT | Gravity.BOTTOM;
    mAnimationHandler = new FloatingAnimationHandler(this);
    mLongPressHandler = new LongPressHandler(this);
    mMoveEdgeInterpolator = new OvershootInterpolator(MOVE_TO_EDGE_OVERSHOOT_TENSION);
    mMoveDirection = FloatingViewManager.MOVE_DIRECTION_DEFAULT;

    mMoveLimitRect = new Rect();
    mPositionLimitRect = new Rect();

    // ステータスバーの高さを取得
    final Resources resources = context.getResources();
    final int statusBarHeightId = resources.getIdentifier("status_bar_height", "dimen", "android");
    if (statusBarHeightId > 0) {
      mStatusBarHeight = resources.getDimensionPixelSize(statusBarHeightId);
    } else {
      mStatusBarHeight = 0;
    }

    // 初回描画処理用
    getViewTreeObserver().addOnPreDrawListener(this);
  }
예제 #27
0
 /**
  * 创建悬浮球
  *
  * @param context 上下文
  */
 public static void createFloatView(Context context, FloatControlView.OnClickFloatView mListener) {
   WindowManager windowManager = getWindowManager(context);
   int screenWidth = windowManager.getDefaultDisplay().getWidth();
   int screenHeight = windowManager.getDefaultDisplay().getHeight();
   if (mFloatView == null) {
     mFloatView = new FloatControlView(context);
     mFloatView.setClickListener(mListener);
     if (smallWindowParams == null) {
       smallWindowParams = new WindowManager.LayoutParams();
       smallWindowParams.type = WindowManager.LayoutParams.TYPE_PHONE;
       smallWindowParams.format = PixelFormat.RGBA_8888;
       smallWindowParams.flags =
           WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
               | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
       smallWindowParams.gravity = Gravity.LEFT | Gravity.TOP;
       smallWindowParams.width = FloatControlView.viewWidth;
       smallWindowParams.height = FloatControlView.viewHeight;
       smallWindowParams.x = screenWidth;
       smallWindowParams.y = screenHeight / 2;
     }
     mFloatView.setParams(smallWindowParams);
     windowManager.addView(mFloatView, smallWindowParams);
   }
 }
예제 #28
0
 public final void a(Activity paramActivity, View paramView) {
   if ((paramActivity instanceof Activity)) {
     paramActivity.setContentView(paramView);
   }
   while ((any != null) && (anz != null)) {
     return;
   }
   anA = new WindowManager.LayoutParams();
   anA.height = -1;
   anA.width = -1;
   anz = ((WindowManager) paramActivity.getSystemService("window"));
   anA.x = 0;
   anA.y = 0;
   anA.type = 2002;
   mView = paramView;
   anA.gravity = 51;
   anA.format = 1;
   any = new FrameLayout(paramActivity);
   any.setPadding(0, 0, 0, 0);
   anB = new ViewGroup.LayoutParams(-1, -1);
   any.addView(mView, anB);
   anz.addView(any, anA);
   anD = true;
 }
예제 #29
0
  public void show(
      String title,
      String[] displayStrings,
      final Action1<Integer> callback,
      boolean hasCancelButton) {
    if (getParent() == null) {
      WindowManager.LayoutParams wlp = new WindowManager.LayoutParams();
      wlp.type = WindowManager.LayoutParams.TYPE_APPLICATION;
      wlp.format = PixelFormat.TRANSPARENT;
      wlp.gravity = Gravity.LEFT | Gravity.TOP;
      wlp.width = LayoutParams.MATCH_PARENT;
      wlp.height = LayoutParams.MATCH_PARENT;
      windowManager.addView(this, wlp);
    }

    maskView.show();

    int mrg = (int) applyDimension(getContext(), TypedValue.COMPLEX_UNIT_DIP, 5);
    LinearLayout.LayoutParams lp =
        new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    lp.setMargins(0, mrg, 0, mrg);

    actionSheetView.setVisibility(View.VISIBLE);
    actionSheetView.removeAllViews();

    if (null != title && !title.trim().equals("")) {
      titleTextView = new TextView(getContext());
      titleTextView.setBackgroundColor(Color.TRANSPARENT);
      titleTextView.setGravity(Gravity.CENTER);
      titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
      titleTextView.setText(title);
      titleTextView.setTextColor(Color.WHITE);
      actionSheetView.addView(titleTextView, lp);
    }

    for (int i = 0, len = displayStrings.length; i < len; i++) {
      final int index = i;
      Button button = new Button(getContext());
      button.setBackgroundResource(R.drawable.actionsheet_red_btn);
      button.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
      button.setText(displayStrings[index]);
      button.setTextColor(Color.WHITE);
      button.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              callback.invoke(index);
            }
          });
      actionSheetView.addView(button, lp);
    }

    if (hasCancelButton) {
      Button button = new Button(getContext());
      button.setBackgroundResource(R.drawable.actionsheet_black_btn);
      button.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
      button.setTextColor(Color.WHITE);
      button.setText("取消");
      button.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              hide();
            }
          });
      actionSheetView.addView(button, lp);
    }

    actionSheetView.clearAnimation();
    TranslateAnimation an =
        new TranslateAnimation(
            Animation.RELATIVE_TO_SELF,
            0,
            Animation.RELATIVE_TO_SELF,
            0,
            Animation.RELATIVE_TO_SELF,
            1,
            Animation.RELATIVE_TO_SELF,
            0);
    an.setDuration(durationMillis);
    actionSheetView.startAnimation(an);
  }
예제 #30
0
 @Override
 public void onCallStateChanged(int state, String incomingNumber) {
   switch (state) {
     case TelephonyManager.CALL_STATE_OFFHOOK:
       IDLE = true;
       if (myFV == null) {
         wm =
             (WindowManager)
                 currentActivity.getAppContext().getSystemService(Context.WINDOW_SERVICE);
         View view =
             LayoutInflater.from(currentActivity.getAppContext())
                 .inflate(R.layout.module_diallistener, null);
         ImageView ivClose = (ImageView) view.findViewById(R.id.dial_listener_btn_close);
         ivClose.setOnClickListener(
             new View.OnClickListener() {
               @Override
               public void onClick(View v) {
                 // 关闭悬浮窗口
                 if (wm != null && myFV != null) {
                   wm.removeView(myFV);
                   myFV = null;
                 }
               }
             });
         TextView tvMessage = (TextView) view.findViewById(R.id.dial_listener_text);
         tvMessage.setText("您正在与" + SP_CALL_DIAL + "录音通话中…");
         myFV = new DialFloatView(currentActivity.getAppContext());
         myFV.addView(view);
         // 设置LayoutParams(全局变量)相关参数
         WindowManager.LayoutParams wmParams = myFV.getMywmParams();
         // 设置window type
         wmParams.type = LayoutParams.TYPE_PHONE;
         // 设置图片格式,效果为背景透明
         wmParams.format = PixelFormat.RGBA_8888;
         // 设置Window flag
         wmParams.flags =
             LayoutParams.FLAG_NOT_TOUCH_MODAL | LayoutParams.FLAG_NOT_FOCUSABLE;
         // 调整悬浮窗口至左上角
         wmParams.gravity = Gravity.LEFT | Gravity.TOP;
         // 以屏幕左上角为原点,设置x、y初始值
         wmParams.x = 0;
         wmParams.y = 0;
         // 设置悬浮窗口长宽数据
         wmParams.width = android.view.ViewGroup.LayoutParams.MATCH_PARENT;
         wmParams.height = android.view.ViewGroup.LayoutParams.WRAP_CONTENT;
         // 显示myFloatView图像
         wm.addView(myFV, wmParams);
       }
       break;
     case TelephonyManager.CALL_STATE_IDLE:
       // 拨打电话状态顺序1.CALL_STATE_IDLE 2.CALL_STATE_OFFHOOK
       // 3.CALL_STATE_IDLE由于只需要取最后一个CALL_STATE_IDLE所以在这里需要一个逻辑判断
       if (IDLE) {
         IDLE = false;
         // 停止监听手机通话状态
         if (manager != null) {
           manager.listen(stateListener, PhoneStateListener.LISTEN_NONE);
         }
         // 通话结束后关闭悬浮窗口
         if (wm != null && myFV != null) {
           wm.removeView(myFV);
           myFV = null;
         }
         // 设置拨打的号码为空
         BaseContext.getSharedPreferences()
             .putString(Constant.Preferences.SP_CALL_DIAL, AppConstant.EMPTYSTR);
         ActivityManager am =
             (ActivityManager) currentActivity.getSystemService(Context.ACTIVITY_SERVICE);
         ComponentName cn = am.getRunningTasks(1).get(0).topActivity;
         if (!cn.getClassName().equals(MainActivity.class.getName())) {
           // Android4.0以上系统默认打完电话后会跳转到
           Intent intent = new Intent(currentActivity, MainActivity.class);
           intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
           currentActivity.startActivity(intent);
         }
       }
       break;
   }
 }