// the window will be centered @Override public StandOutLayoutParams getParams(int id, Window window) { StandOutLayoutParams params = new StandOutLayoutParams( id, mSettings.getScreenWidth(), mSettings.getWindowHeight(), StandOutLayoutParams.CENTER, StandOutLayoutParams.CENTER); int x = mSettings.getWindowX(); int y = mSettings.getWindowY(); if (x != -1 && y != -1) { params.x = x; params.y = y; } if (id == SETTING_FRONT || id == SEARCH_FRONT) { params.y = (int) (mSettings.getDefaultHeight() * 1.5); } params.minWidth = mSettings.getScreenWidth(); params.maxWidth = Math.max(mSettings.getScreenWidth(), mSettings.getScreenHeight()); params.minHeight = mSettings.getDefaultHeight() / 4; if (isUnmovable(id)) { params.type = StandOutLayoutParams.TYPE_SYSTEM_OVERLAY; } return params; }
@Override public Animation getCloseAnimation(int id) { if (mSettings.isShowCloseAnim()) { return super.getCloseAnimation(id); } else { return null; } }
@Override public boolean onTouchBody(int id, Window window, View view, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_OUTSIDE: View layout = window.findViewById(R.id.window_layout); if (layout != null) { layout.setBackgroundResource(0); } if (!isFocused && mSettings.isHidingWhenTouch() && id == CALLER_FRONT && getWindow(id) != null) { hide(id); } isFocused = false; break; } return super.onTouchBody(id, window, view, event); }
@Override public boolean isDisableMove(int id) { return id == CALLER_FRONT && mSettings.isDisableMove(); }
@Override public void onReceiveData( int id, int requestCode, Bundle data, Class<? extends StandOutWindow> fromCls, int fromId) { int color = data.getInt(WINDOW_COLOR); String text = data.getString(NUMBER_INFO); int size = data.getInt(TEXT_SIZE); int height = data.getInt(WINDOW_HEIGHT); int trans = data.getInt(WINDOW_TRANS); int error = data.getInt(WINDOW_ERROR); int padding = data.getInt(TEXT_PADDING); Window window = getWindow(id); if (window == null) { return; } View layout = window.findViewById(R.id.content); TextView textView = (TextView) window.findViewById(R.id.number_info); TextView errorText = (TextView) window.findViewById(R.id.error); if (padding == 0) { padding = mSettings.getTextPadding(); } if (id == CALLER_FRONT || id == SETTING_FRONT) { int alignType = mSettings.getTextAlignment(); int gravity; switch (alignType) { case TEXT_ALIGN_LEFT: gravity = Gravity.START | Gravity.CENTER; textView.setPadding(padding, 0, 0, 0); break; case TEXT_ALIGN_CENTER: gravity = Gravity.CENTER; textView.setPadding(0, padding, 0, 0); break; case TEXT_ALIGN_RIGHT: gravity = Gravity.END | Gravity.CENTER; textView.setPadding(0, 0, padding, 0); break; default: gravity = Gravity.CENTER; textView.setPadding(0, padding, 0, 0); break; } errorText.setGravity(gravity); textView.setGravity(gravity); } if (size == 0) { size = mSettings.getTextSize(); } if (height != 0) { StandOutLayoutParams params = window.getLayoutParams(); window.edit().setSize(params.width, height).commit(); } if (trans == 0) { trans = mSettings.getWindowTransparent(); } if (color != 0) { layout.setBackgroundColor(color); if (mSettings.isEnableTextColor() && id == CALLER_FRONT) { textView.setTextColor(color); } } if (text != null) { textView.setText(text); } textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, size); if (mSettings.isTransBackOnly()) { if (layout.getBackground() != null) { layout.getBackground().setAlpha((int) (trans / 100.0 * 255)); } } else { layout.setAlpha(trans / 100f); } if (error != 0) { errorText.setVisibility(View.VISIBLE); errorText.setText(getString(error)); } }
@Override public void onMove(int id, Window window, View view, MotionEvent event) { super.onMove(id, window, view, event); mSettings.setWindow(window.getLayoutParams().x, window.getLayoutParams().y); }