OSDN Git Service

Dashboard fixes
authorBraden Farmer <farmerbb@gmail.com>
Mon, 19 Dec 2016 20:09:54 +0000 (13:09 -0700)
committerBraden Farmer <farmerbb@gmail.com>
Mon, 19 Dec 2016 20:09:54 +0000 (13:09 -0700)
app/src/main/java/com/farmerbb/taskbar/activity/DashboardActivity.java
app/src/main/java/com/farmerbb/taskbar/service/DashboardService.java
app/src/main/java/com/farmerbb/taskbar/util/LauncherAppWidgetHost.java [deleted file]
app/src/main/java/com/farmerbb/taskbar/util/LauncherAppWidgetHostView.java [deleted file]

index f451a9b..f1e1b12 100644 (file)
@@ -20,6 +20,7 @@ package com.farmerbb.taskbar.activity;
 
 import android.app.Activity;
 import android.app.AlertDialog;
+import android.appwidget.AppWidgetHost;
 import android.appwidget.AppWidgetManager;
 import android.appwidget.AppWidgetProviderInfo;
 import android.content.ActivityNotFoundException;
@@ -39,13 +40,12 @@ import android.widget.FrameLayout;
 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;
@@ -58,7 +58,7 @@ public class DashboardActivity extends Activity {
         @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();
index 301861c..6841c53 100644 (file)
@@ -23,6 +23,8 @@ import android.animation.AnimatorListenerAdapter;
 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;
@@ -39,6 +41,7 @@ import android.provider.Settings;
 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;
@@ -50,15 +53,13 @@ import com.farmerbb.taskbar.R;
 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;
@@ -92,6 +93,10 @@ public class DashboardService extends Service {
         @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;
         }
     };
@@ -133,14 +138,15 @@ public class DashboardService extends Service {
 
                 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);
@@ -308,7 +314,7 @@ public class DashboardService extends Service {
         }
 
         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);
diff --git a/app/src/main/java/com/farmerbb/taskbar/util/LauncherAppWidgetHost.java b/app/src/main/java/com/farmerbb/taskbar/util/LauncherAppWidgetHost.java
deleted file mode 100644 (file)
index 90069af..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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
diff --git a/app/src/main/java/com/farmerbb/taskbar/util/LauncherAppWidgetHostView.java b/app/src/main/java/com/farmerbb/taskbar/util/LauncherAppWidgetHostView.java
deleted file mode 100644 (file)
index 24f49f8..0000000
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * 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