我正在使用窗口管理器显示一个浮动布局,它显示正常,但是在向上滑动屏幕时我需要打开浮动布局并向下滑动屏幕,我必须隐藏那个浮动布局..所以我在浮动布局上方采用了一个透明布局,并在透明布局中添加了手势,我的浮动布局打开/关闭工作正常,但因为设备图标(家庭,设置等)触摸不工作。做任何人都可以帮助我。
**Launcher.java**
public class Launcher extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent startIntent = new Intent(Launcher.this, LauncherService.class);
startIntent.setAction(Constants.ACTION.STARTFOREGROUND_ACTION);
startService(startIntent);
}
}
Service:
public class LauncherService extends Service {
private static final Logger logger = Logger.getLogger("ChannelManger");
private LinearLayout mFloatLayout, touch_layout;
private WindowManager.LayoutParams wmParams;
private WindowManager mWindowManager;
private GridView mFloatView;
// private static Context mContext;
public static boolean isShow = true;
private static int selectPositon = 0;
private LinearLayout channelBarTop;
private ViewGroup.LayoutParams channel_bar_topfloatLayoutParams;
private LinearLayout top_line;
private ViewGroup.LayoutParams floatLayoutParams;
public static LinearLayout channelBarLayout;
private HorizontalScrollView channelBarScroolView;
public Handler uiRefresh = null;
private int channelItemleft, channelItemright, channelItemup,
channelItemdown;
private ImageView remote_img;
private static String mLanguage = "";
private static int selectId = -1;
public static ChannelLanguageProvider channelLanguageProvider;
private static ChannelProvider channelProvder;
private static LovellFeaturesProvider lovellFeaturesProvider;
private static ChannelStyleProvider channelStyleProvder;
private static Typeface typeface;
public ChannelBarAdapter mAdapter;
private DisplayMetrics dm;
private GestureDetector gestureDetector;
@Override
public void onCreate() {
super.onCreate();
mLanguage = CommonProvider.getLocalLanguage(getApplicationContext());
if (lovellFeaturesProvider == null) {
lovellFeaturesProvider = LovellFeaturesProvider
.getInstance(getApplicationContext());
}
if (channelProvder == null) {
channelProvder = ChannelProvider
.getInstance(getApplicationContext());
}
if (channelStyleProvder == null) {
channelStyleProvder = ChannelStyleProvider
.getInstance(getApplicationContext());
typeface = channelStyleProvder.getChannelButtonsLabelTypeface();
}
channelLanguageProvider = ChannelLanguageProvider.getInstance(
getApplicationContext(), mLanguage);
createChannelBar(getApplicationContext());
}
public void createChannelBar(Context context) {
try {
// mContext = context;
wmParams = new WindowManager.LayoutParams();
dm = new DisplayMetrics();
mWindowManager = (WindowManager) getApplicationContext()
.getSystemService(Context.WINDOW_SERVICE);
wmParams.flags = LayoutParams.FLAG_NOT_FOCUSABLE;
// wmParams.flags = LayoutParams.FLAG_NOT_TOUCHABLE;
wmParams.type = LayoutParams.TYPE_SYSTEM_OVERLAY;
wmParams.format = PixelFormat.TRANSLUCENT;
wmParams.gravity = Gravity.LEFT | Gravity.BOTTOM;
wmParams.width = WindowManager.LayoutParams.MATCH_PARENT;
wmParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
LayoutInflater inflater = LayoutInflater
.from(getApplicationContext());
mFloatLayout = (LinearLayout) inflater.inflate(
R.layout.channel_bar, null);
channelBarLayout = (LinearLayout) mFloatLayout
.findViewById(R.id.channel_bar);
touch_layout = (LinearLayout) mFloatLayout
.findViewById(R.id.touch_layout);
gestureDetector = new GestureDetector(getApplicationContext(), new GestureListener());
touch_layout.setOnTouchListener(new OnSwipeTouchListener(
getApplicationContext()) {
public void onSwipeTop() {
if (LauncherService.channelBarLayout.getVisibility() == View.GONE) {
LauncherService.channelBarLayout
.setVisibility(View.VISIBLE);
Toast.makeText(getApplicationContext(), "Top",
Toast.LENGTH_SHORT).show();
}
}
public void onSwipeBottom() {
Toast.makeText(getApplicationContext(), "bottom",
Toast.LENGTH_SHORT).show();
if (LauncherService.channelBarLayout.getVisibility() == View.VISIBLE) {
LauncherService.channelBarLayout
.setVisibility(View.GONE);
}
}
});
channelBarScroolView = (HorizontalScrollView) mFloatLayout
.findViewById(R.id.channelBarScroolView);
// shadowLinLayout = (LinearLayout) mFloatLayout
// .findViewById(R.id.shadow);
floatLayoutParams = channelBarScroolView.getLayoutParams();
top_line = (LinearLayout) mFloatLayout.findViewById(R.id.top_line);
mWindowManager.addView(mFloatLayout, wmParams);
mFloatView = (GridView) mFloatLayout
.findViewById(R.id.channel_item_grid);
IntentFilter filter = new IntentFilter();
filter.addAction(Intent.ACTION_LOCALE_CHANGED);
filter.addAction(IntentAction.EVENT_LEVEL_NAVIGATION_BAR_OPEN);
filter.addAction(IntentAction.EVENT_LEVEL_NAVIGATION_BAR_HOME_OFF);
filter.addAction(IntentAction.EVENT_LOVELL_LARGE_TEXT_CHANGE);
filter.addAction(IntentAction.CHANNELBAR_CONFIG_SETTING_VALUE);
// filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
mFloatView.setNumColumns(channelProvder.validChannelsList().size());
mFloatLayout.measure(View.MeasureSpec.makeMeasureSpec(0,
View.MeasureSpec.UNSPECIFIED), View.MeasureSpec
.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
mFloatLayout.findViewById(R.id.channel_bar_but);
remote_img = (ImageView) mFloatLayout.findViewById(R.id.remote_img);
channelBarTop = (LinearLayout) mFloatLayout
.findViewById(R.id.channel_bar_top);
channel_bar_topfloatLayoutParams = channelBarTop.getLayoutParams();
configStyles();
mAdapter = new ChannelBarAdapter();
mAdapter.reset();
mFloatView.setAdapter(mAdapter);
if (!lovellFeaturesProvider.getControlBarSwitch()) {
channelBarTop.setVisibility(View.GONE);
} else {
channelBarTop.setVisibility(View.VISIBLE);
if (!lovellFeaturesProvider.getRemoteControlSwitch()) {
remote_img.setVisibility(View.GONE);
} else {
remote_img.setVisibility(View.VISIBLE);
}
}
isShow = true;
Intent intent = new Intent();
intent.setAction(IntentAction.EVENT_LOVELL_NAVIGATION_UI_OPEN);//
// if (mContext != null) {
sendBroadcast(intent);
// }
} catch (Exception e) {
logger.e(e.toString());
// getApplicationContext() = null;
} finally {
}
}
Gestures:
public class OnSwipeTouchListener implements OnTouchListener {
private final GestureDetector gestureDetector;
public OnSwipeTouchListener(Context ctx) {
gestureDetector = new GestureDetector(ctx, new GestureListener());
}
@Override
public boolean onTouch(View v, MotionEvent event) {
return gestureDetector.onTouchEvent(event);
}
public final class GestureListener extends SimpleOnGestureListener {
private static final int SWIPE_THRESHOLD = 100;
private static final int SWIPE_VELOCITY_THRESHOLD = 100;
@Override
public boolean onDown(MotionEvent e) {
return true;
}
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
float velocityY) {
boolean result = false;
try {
float diffY = e2.getY() - e1.getY();
float diffX = e2.getX() - e1.getX();
if (Math.abs(diffX) > Math.abs(diffY)) {
result = false;
} else if (Math.abs(diffY) > SWIPE_THRESHOLD
&& Math.abs(velocityY) > SWIPE_VELOCITY_THRESHOLD) {
if (diffY > 0) {
onSwipeBottom();
} else {
onSwipeTop();
}
}
result = true;
} catch (Exception exception) {
exception.printStackTrace();
}
return result;
}
}
public void onSwipeTop() {
}
public void onSwipeBottom() {
}
}