import android.app.Activity;
import android.app.AlertDialog;
+import android.appwidget.AppWidgetHost;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
import android.content.ActivityNotFoundException;
import android.widget.LinearLayout;
import com.farmerbb.taskbar.R;
-import com.farmerbb.taskbar.util.LauncherAppWidgetHost;
import com.farmerbb.taskbar.util.U;
public class DashboardActivity extends Activity {
private AppWidgetManager mAppWidgetManager;
- private LauncherAppWidgetHost mAppWidgetHost;
+ private AppWidgetHost mAppWidgetHost;
int REQUEST_PICK_APPWIDGET = 456;
int REQUEST_CREATE_APPWIDGET = 789;
@Override
public void onReceive(Context context, Intent intent) {
mAppWidgetManager = AppWidgetManager.getInstance(context);
- mAppWidgetHost = new LauncherAppWidgetHost(context, intent.getIntExtra("appWidgetId", -1));
+ mAppWidgetHost = new AppWidgetHost(context, intent.getIntExtra("appWidgetId", -1));
cellId = intent.getIntExtra("cellId", -1);
int appWidgetId = mAppWidgetHost.allocateAppWidgetId();
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Service;
+import android.appwidget.AppWidgetHost;
+import android.appwidget.AppWidgetHostView;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProviderInfo;
import android.content.BroadcastReceiver;
import android.support.v4.content.LocalBroadcastManager;
import android.util.SparseArray;
import android.view.MotionEvent;
+import android.view.PointerIcon;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import com.farmerbb.taskbar.activity.DashboardActivity;
import com.farmerbb.taskbar.activity.DashboardActivityDark;
import com.farmerbb.taskbar.util.FreeformHackHelper;
-import com.farmerbb.taskbar.util.LauncherAppWidgetHost;
-import com.farmerbb.taskbar.util.LauncherAppWidgetHostView;
import com.farmerbb.taskbar.util.LauncherHelper;
import com.farmerbb.taskbar.util.U;
public class DashboardService extends Service {
private AppWidgetManager mAppWidgetManager;
- private LauncherAppWidgetHost mAppWidgetHost;
+ private AppWidgetHost mAppWidgetHost;
private WindowManager windowManager;
private LinearLayout layout;
@Override
public boolean onHover(View v, MotionEvent event) {
cellClick(v, false);
+
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
+ v.setPointerIcon(PointerIcon.getSystemIcon(DashboardService.this, PointerIcon.TYPE_DEFAULT));
+
return false;
}
};
AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
- LauncherAppWidgetHostView hostView = (LauncherAppWidgetHostView) mAppWidgetHost.createView(DashboardService.this, appWidgetId, appWidgetInfo);
+ FrameLayout 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());
Bundle bundle = new Bundle();
bundle.putInt("cellId", cellId);
hostView.setTag(bundle);
- FrameLayout cellLayout = cells.get(cellId);
cellLayout.findViewById(R.id.empty).setVisibility(View.GONE);
cellLayout.setOnLongClickListener(olcl);
cellLayout.setOnGenericMotionListener(ogml);
}
mAppWidgetManager = AppWidgetManager.getInstance(this);
- mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID);
+ mAppWidgetHost = new AppWidgetHost(this, APPWIDGET_HOST_ID);
mAppWidgetHost.stopListening();
LocalBroadcastManager.getInstance(this).unregisterReceiver(toggleReceiver);
+++ /dev/null
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * 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.util;
-
-import android.appwidget.AppWidgetHost;
-import android.appwidget.AppWidgetHostView;
-import android.appwidget.AppWidgetProviderInfo;
-import android.content.Context;
-
-/**
- * Specific {@link AppWidgetHost} that creates our {@link LauncherAppWidgetHostView}
- * which correctly captures all long-press events. This ensures that users can
- * always pick up and move widgets.
- */
-public class LauncherAppWidgetHost extends AppWidgetHost {
- public LauncherAppWidgetHost(Context context, int hostId) {
- super(context, hostId);
- }
-
- @Override
- protected AppWidgetHostView onCreateView(Context context, int appWidgetId,
- AppWidgetProviderInfo appWidget) {
- return new LauncherAppWidgetHostView(context);
- }
-}
\ No newline at end of file
+++ /dev/null
-/*
- * Copyright (C) 2009 The Android Open Source Project
- *
- * 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.util;
-
-import android.appwidget.AppWidgetHostView;
-import android.content.Context;
-import android.view.LayoutInflater;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.ViewConfiguration;
-import android.widget.TextView;
-
-import com.farmerbb.taskbar.R;
-
-/**
- * {@inheritDoc}
- */
-public class LauncherAppWidgetHostView extends AppWidgetHostView {
- private boolean mHasPerformedLongPress;
-
- private CheckForLongPress mPendingCheckForLongPress;
-
- private LayoutInflater mInflater;
-
- public LauncherAppWidgetHostView(Context context) {
- super(context);
- mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
- }
-
- @Override
- protected View getErrorView() {
- TextView textView = new TextView(getContext());
- textView.setText(R.string.error_loading_widget);
- return textView;
- }
-
- public boolean onInterceptTouchEvent(MotionEvent ev) {
- // Consume any touch events for ourselves after longpress is triggered
- if (mHasPerformedLongPress) {
- mHasPerformedLongPress = false;
- return true;
- }
-
- // Watch for longpress events at this level to make sure
- // users can always pick up this widget
- switch (ev.getAction()) {
- case MotionEvent.ACTION_DOWN: {
- postCheckForLongClick();
- break;
- }
-
- case MotionEvent.ACTION_UP:
- case MotionEvent.ACTION_CANCEL:
- mHasPerformedLongPress = false;
- if (mPendingCheckForLongPress != null) {
- removeCallbacks(mPendingCheckForLongPress);
- }
- break;
- }
-
- // Otherwise continue letting touch events fall through to children
- return false;
- }
-
- class CheckForLongPress implements Runnable {
- private int mOriginalWindowAttachCount;
-
- public void run() {
- if (hasWindowFocus()
- && mOriginalWindowAttachCount == getWindowAttachCount()
- && !mHasPerformedLongPress) {
- if (performLongClick()) {
- mHasPerformedLongPress = true;
- }
- }
- }
-
- public void rememberWindowAttachCount() {
- mOriginalWindowAttachCount = getWindowAttachCount();
- }
- }
-
- private void postCheckForLongClick() {
- mHasPerformedLongPress = false;
-
- if (mPendingCheckForLongPress == null) {
- mPendingCheckForLongPress = new CheckForLongPress();
- }
- mPendingCheckForLongPress.rememberWindowAttachCount();
- postDelayed(mPendingCheckForLongPress, ViewConfiguration.getLongPressTimeout());
- }
-
- @Override
- public void cancelLongPress() {
- super.cancelLongPress();
-
- mHasPerformedLongPress = false;
- if (mPendingCheckForLongPress != null) {
- removeCallbacks(mPendingCheckForLongPress);
- }
- }
-}
\ No newline at end of file