import com.farmerbb.taskbar.R;
import com.farmerbb.taskbar.activity.DashboardActivity;
import com.farmerbb.taskbar.activity.DashboardActivityDark;
+import com.farmerbb.taskbar.widget.DashboardCell;
import com.farmerbb.taskbar.util.FreeformHackHelper;
import com.farmerbb.taskbar.util.LauncherHelper;
import com.farmerbb.taskbar.util.U;
private WindowManager windowManager;
private LinearLayout layout;
- private SparseArray<FrameLayout> cells = new SparseArray<>();
+ private SparseArray<DashboardCell> cells = new SparseArray<>();
private final int APPWIDGET_HOST_ID = 123;
}
};
+ private DashboardCell.OnInterceptedLongPressListener listener = new DashboardCell.OnInterceptedLongPressListener() {
+ @Override
+ public void onInterceptedLongPress(DashboardCell cell) {
+ cellLongClick(cell);
+ }
+ };
+
private BroadcastReceiver toggleReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
- FrameLayout cellLayout = cells.get(cellId);
+ DashboardCell cellLayout = cells.get(cellId);
AppWidgetHostView hostView = mAppWidgetHost.createView(DashboardService.this, appWidgetId, appWidgetInfo);
hostView.setAppWidget(appWidgetId, appWidgetInfo);
hostView.updateAppWidgetSize(null, cellLayout.getWidth(), cellLayout.getHeight(), cellLayout.getWidth(), cellLayout.getHeight());
cellLayout.findViewById(R.id.empty).setVisibility(View.GONE);
cellLayout.setOnLongClickListener(olcl);
cellLayout.setOnGenericMotionListener(ogml);
+ cellLayout.setOnInterceptedLongPressListener(listener);
LinearLayout linearLayout = (LinearLayout) cellLayout.findViewById(R.id.dashboard);
linearLayout.addView(hostView);
if(intent.hasExtra("cellId")) {
int cellId = intent.getExtras().getInt("cellId", -1);
- FrameLayout cellLayout = cells.get(cellId);
+ DashboardCell cellLayout = cells.get(cellId);
Bundle bundle = (Bundle) cellLayout.getTag();
mAppWidgetHost.deleteAppWidgetId(bundle.getInt("appWidgetId"));
cellLayout.setOnHoverListener(cellOhl);
cellLayout.setOnLongClickListener(null);
cellLayout.setOnGenericMotionListener(null);
+ cellLayout.setOnInterceptedLongPressListener(null);
}
}
};
layout2.setOrientation(LinearLayout.VERTICAL);
for(int j = 0; j < rows; j++) {
- FrameLayout cellLayout = (FrameLayout) View.inflate(this, R.layout.dashboard, null);
+ DashboardCell cellLayout = (DashboardCell) View.inflate(this, R.layout.dashboard, null);
cellLayout.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1));
cellLayout.setBackgroundColor(backgroundTint);
cellLayout.setOnClickListener(cellOcl);
--- /dev/null
+/* Copyright 2016 Braden Farmer
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.farmerbb.taskbar.widget;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewConfiguration;
+import android.widget.FrameLayout;
+
+public class DashboardCell extends FrameLayout {
+
+ public DashboardCell(Context context) {
+ super(context);
+ }
+
+ public DashboardCell(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ public DashboardCell(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ }
+
+ public interface OnInterceptedLongPressListener {
+ void onInterceptedLongPress(DashboardCell cell);
+ }
+
+ // Use this instance of the interface to deliver action events
+ private OnInterceptedLongPressListener listener;
+
+ long beginTime;
+
+ @Override
+ public boolean onInterceptTouchEvent(MotionEvent ev) {
+ switch(ev.getAction()) {
+ case MotionEvent.ACTION_DOWN: {
+ beginTime = ev.getEventTime();
+ break;
+ }
+
+ case MotionEvent.ACTION_UP:
+ case MotionEvent.ACTION_CANCEL:
+ long eventLength = ev.getEventTime() - beginTime;
+
+ if(eventLength > ViewConfiguration.getLongPressTimeout()) {
+ if(listener != null)
+ listener.onInterceptedLongPress(this);
+
+ cancelLongPress();
+ return true;
+ }
+
+ break;
+ }
+
+ return false;
+ }
+
+ public void setOnInterceptedLongPressListener(OnInterceptedLongPressListener listener) {
+ this.listener = listener;
+ }
+}
\ No newline at end of file