OSDN Git Service

Allow Taskbar to be built from Android 7.1 source
authorBraden Farmer <farmerbb@gmail.com>
Tue, 24 Oct 2017 03:52:42 +0000 (21:52 -0600)
committerBraden Farmer <farmerbb@gmail.com>
Tue, 24 Oct 2017 03:52:42 +0000 (21:52 -0600)
30 files changed:
Android.mk
app/build.gradle
app/src/androidx86/java/com/farmerbb/taskbar/util/OreoUtils.java [new file with mode: 0644]
app/src/main/java/com/farmerbb/taskbar/MainActivity.java
app/src/main/java/com/farmerbb/taskbar/activity/ClearDataActivity.java
app/src/main/java/com/farmerbb/taskbar/activity/ContextMenuActivity.java
app/src/main/java/com/farmerbb/taskbar/activity/DashboardActivity.java
app/src/main/java/com/farmerbb/taskbar/activity/IconPackActivity.java
app/src/main/java/com/farmerbb/taskbar/activity/InvisibleActivityAlt.java
app/src/main/java/com/farmerbb/taskbar/activity/SelectAppActivity.java
app/src/main/java/com/farmerbb/taskbar/adapter/AppListAdapter.java
app/src/main/java/com/farmerbb/taskbar/adapter/StartMenuAdapter.java
app/src/main/java/com/farmerbb/taskbar/fragment/AdvancedFragment.java
app/src/main/java/com/farmerbb/taskbar/fragment/AppearanceFragment.java
app/src/main/java/com/farmerbb/taskbar/fragment/FreeformModeFragment.java
app/src/main/java/com/farmerbb/taskbar/fragment/GeneralFragment.java
app/src/main/java/com/farmerbb/taskbar/fragment/RecentAppsFragment.java
app/src/main/java/com/farmerbb/taskbar/fragment/SettingsFragment.java
app/src/main/java/com/farmerbb/taskbar/receiver/BootReceiver.java
app/src/main/java/com/farmerbb/taskbar/receiver/PackageUpgradeReceiver.java
app/src/main/java/com/farmerbb/taskbar/receiver/ShowHideTaskbarReceiver.java
app/src/main/java/com/farmerbb/taskbar/receiver/StartReceiver.java
app/src/main/java/com/farmerbb/taskbar/receiver/ToggleFreeformModeReceiver.java
app/src/main/java/com/farmerbb/taskbar/service/DashboardService.java
app/src/main/java/com/farmerbb/taskbar/service/NotificationService.java
app/src/main/java/com/farmerbb/taskbar/service/StartMenuService.java
app/src/main/java/com/farmerbb/taskbar/service/TaskbarService.java
app/src/main/java/com/farmerbb/taskbar/util/U.java
app/src/oreoutils/java/com/farmerbb/taskbar/util/OreoUtils.java [new file with mode: 0644]
build.gradle

index 4ca13b6..97604e2 100644 (file)
@@ -18,8 +18,6 @@ LOCAL_MANIFEST_FILE := app/src/androidx86/AndroidManifest.xml
 LOCAL_STATIC_JAVA_LIBRARIES := \
         android-support-v4 \
         android-support-v7-appcompat \
-        android-support-v7-recyclerview \
-        android-support-transition \
         android-support-design
 
 LOCAL_PROGUARD_ENABLED := disabled
@@ -30,12 +28,12 @@ LOCAL_JAVA_LANGUAGE_VERSION := 1.8
 
 LOCAL_PRIVILEGED_MODULE := true
 
+LOCAL_SDK_VERSION := 25
+
 LOCAL_AAPT_FLAGS := \
         --auto-add-overlay \
         --rename-manifest-package com.farmerbb.taskbar.androidx86 \
         --extra-packages android.support.v7.appcompat \
-        --extra-packages android.support.v7.recyclerview \
-        --extra-packages android.support.transition \
         --extra-packages android.support.design
 
 include $(BUILD_PACKAGE)
index 4c9320e..e42a119 100644 (file)
@@ -64,7 +64,7 @@ android {
     }
 
     flavorDimensions "default"
-    
+
     productFlavors {
         paid {
             dimension "default"
@@ -76,6 +76,20 @@ android {
             applicationId "com.farmerbb.taskbar"
         }
     }
+
+    sourceSets {
+        paid {
+            java {
+                srcDirs('src/main/java', 'src/oreoutils/java')
+            }
+        }
+
+        free {
+            java {
+                srcDirs('src/main/java', 'src/oreoutils/java')
+            }
+        }
+    }
 }
 
 dependencies {
diff --git a/app/src/androidx86/java/com/farmerbb/taskbar/util/OreoUtils.java b/app/src/androidx86/java/com/farmerbb/taskbar/util/OreoUtils.java
new file mode 100644 (file)
index 0000000..ee75367
--- /dev/null
@@ -0,0 +1,40 @@
+/* Copyright 2017 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.util;
+
+import android.content.Context;
+import android.content.Intent;
+import android.support.v7.app.NotificationCompat;
+
+public class OreoUtils {
+
+    private OreoUtils() {}
+
+    static int TYPE_APPLICATION_OVERLAY = 2038;
+    public static String ACTION_APP_NOTIFICATION_SETTINGS = "android.settings.APP_NOTIFICATION_SETTINGS";
+    public static String EXTRA_APP_PACKAGE = "android.provider.extra.APP_PACKAGE";
+
+    public static void pinAppShortcut(Context context) {}
+
+    @SuppressWarnings("deprecation")
+    public static NotificationCompat.Builder getNotificationBuilder(Context context) {
+        return new NotificationCompat.Builder(context);
+    }
+
+    public static void startForegroundService(Context context, Intent intent) {
+        context.startService(intent);
+    }
+}
index a3a4e40..ed93599 100644 (file)
@@ -154,7 +154,7 @@ public class MainActivity extends AppCompatActivity {
             actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);
         }
 
-        theSwitch = findViewById(R.id.the_switch);
+        theSwitch = U.findViewById(this, R.id.the_switch);
         if(theSwitch != null) {
             final SharedPreferences pref = U.getSharedPreferences(this);
             theSwitch.setChecked(pref.getBoolean("taskbar_active", false));
index e95294a..4009385 100644 (file)
@@ -28,6 +28,7 @@ import com.farmerbb.taskbar.util.Blacklist;
 import com.farmerbb.taskbar.util.PinnedBlockedApps;
 import com.farmerbb.taskbar.util.SavedWindowSizes;
 import com.farmerbb.taskbar.util.TopApps;
+import com.farmerbb.taskbar.util.U;
 
 public class ClearDataActivity extends AppCompatActivity {
 
@@ -54,35 +55,35 @@ public class ClearDataActivity extends AppCompatActivity {
         setContentView(R.layout.clear_data);
         setTitle(R.string.clear_pinned_apps);
 
-        pba = findViewById(R.id.clear_pba);
+        pba = U.findViewById(this, R.id.clear_pba);
         pba.setOnCheckedChangeListener(listener);
         
-        hiddenApps = findViewById(R.id.clear_hidden_apps);
+        hiddenApps = U.findViewById(this, R.id.clear_hidden_apps);
         hiddenApps.setOnCheckedChangeListener(listener);
         
-        topApps = findViewById(R.id.clear_top_apps);
+        topApps = U.findViewById(this, R.id.clear_top_apps);
         topApps.setOnCheckedChangeListener(listener);
         
-        savedWindowSizes = findViewById(R.id.clear_window_sizes);
+        savedWindowSizes = U.findViewById(this, R.id.clear_window_sizes);
         if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
             savedWindowSizes.setOnCheckedChangeListener(listener);
         else
             savedWindowSizes.setVisibility(View.GONE);
         
-        button = findViewById(R.id.button);
+        button = U.findViewById(this, R.id.button);
         button.setText(getResources().getString(R.string.action_close).toUpperCase());
         button.setOnClickListener(view -> {
             if(pba.isChecked())
-                PinnedBlockedApps.getInstance(ClearDataActivity.this).clear(ClearDataActivity.this);
+                PinnedBlockedApps.getInstance(this).clear(this);
 
             if(hiddenApps.isChecked())
-                Blacklist.getInstance(ClearDataActivity.this).clear(ClearDataActivity.this);
+                Blacklist.getInstance(this).clear(this);
 
             if(topApps.isChecked())
-                TopApps.getInstance(ClearDataActivity.this).clear(ClearDataActivity.this);
+                TopApps.getInstance(this).clear(this);
 
             if(savedWindowSizes.isChecked())
-                SavedWindowSizes.getInstance(ClearDataActivity.this).clear(ClearDataActivity.this);
+                SavedWindowSizes.getInstance(this).clear(this);
 
             finish();
         });
index 548b3f3..da3f0c6 100644 (file)
@@ -466,7 +466,7 @@ public class ContextMenuActivity extends PreferenceActivity implements Preferenc
             case "show_window_sizes":
                 generateWindowSizes();
 
-                if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+                if(Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
                     U.showToastLong(this, R.string.window_sizes_not_available);
                 }
 
@@ -496,7 +496,7 @@ public class ContextMenuActivity extends PreferenceActivity implements Preferenc
 
                 U.launchApp(getApplicationContext(), packageName, componentName, userId, windowSize, false, true);
 
-                if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+                if(Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1)
                     U.cancelToast();
 
                 showStartMenu = false;
@@ -693,7 +693,7 @@ public class ContextMenuActivity extends PreferenceActivity implements Preferenc
 
             getListView().setOnItemLongClickListener(null);
 
-            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+            if(Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1)
                 U.cancelToast();
         } else {
             if(contextMenuFix && !showStartMenu)
index 2e0bd34..3e6b0a1 100644 (file)
@@ -132,7 +132,7 @@ public class DashboardActivity extends Activity {
 
         setContentView(R.layout.incognito);
 
-        LinearLayout layout = findViewById(R.id.incognitoLayout);
+        LinearLayout layout = U.findViewById(this, R.id.incognitoLayout);
         layout.setLayoutParams(new FrameLayout.LayoutParams(metrics.widthPixels, metrics.heightPixels));
 
         LocalBroadcastManager.getInstance(this).registerReceiver(addWidgetReceiver, new IntentFilter("com.farmerbb.taskbar.ADD_WIDGET_REQUESTED"));
index 0fa8572..a49455f 100644 (file)
@@ -60,8 +60,8 @@ public class IconPackActivity extends AppCompatActivity {
         setFinishOnTouchOutside(false);
         setTitle(R.string.icon_pack);
 
-        progressBar = findViewById(R.id.progress_bar);
-        appList = findViewById(R.id.list);
+        progressBar = U.findViewById(this, R.id.progress_bar);
+        appList = U.findViewById(this, R.id.list);
 
         appListGenerator = new AppListGenerator();
         appListGenerator.execute();
@@ -98,11 +98,11 @@ public class IconPackActivity extends AppCompatActivity {
             final IconPack entry = getItem(position);
             assert entry != null;
 
-            TextView textView = convertView.findViewById(R.id.name);
+            TextView textView = U.findViewById(convertView, R.id.name);
             textView.setText(entry.getName());
 
             PackageManager pm = getPackageManager();
-            ImageView imageView = convertView.findViewById(R.id.icon);
+            ImageView imageView = U.findViewById(convertView, R.id.icon);
 
             if(entry.getPackageName().equals(BuildConfig.APPLICATION_ID)) {
                 imageView.setImageDrawable(null);
@@ -114,7 +114,7 @@ public class IconPackActivity extends AppCompatActivity {
                 }
             }
 
-            LinearLayout layout = convertView.findViewById(R.id.entry);
+            LinearLayout layout = U.findViewById(convertView, R.id.entry);
             layout.setOnClickListener(view -> {
                 SharedPreferences pref = U.getSharedPreferences(IconPackActivity.this);
                 pref.edit().putString("icon_pack", entry.getPackageName()).apply();
index a509d3f..1d02f46 100644 (file)
@@ -44,7 +44,7 @@ public class InvisibleActivityAlt extends InvisibleActivity {
 
         setContentView(R.layout.incognito);
 
-        LinearLayout layout = findViewById(R.id.incognitoLayout);
+        LinearLayout layout = U.findViewById(this, R.id.incognitoLayout);
         layout.setLayoutParams(new FrameLayout.LayoutParams(metrics.widthPixels, metrics.heightPixels));
 
         if(!MenuHelper.getInstance().isStartMenuOpen() && !powerButtonWarning) finish();
index bea2d37..21efec1 100644 (file)
@@ -103,7 +103,7 @@ public class SelectAppActivity extends AppCompatActivity {
                     getWindow().setElevation(0);
             }
 
-            progressBar = findViewById(R.id.progress_bar);
+            progressBar = U.findViewById(this, R.id.progress_bar);
             appListGenerator = new AppListGenerator();
             appListGenerator.execute();
         } else {
@@ -235,10 +235,10 @@ public class SelectAppActivity extends AppCompatActivity {
             topAppsAdapter = adapters[U.TOP_APPS];
 
             SelectAppPagerAdapter pagerAdapter = new SelectAppPagerAdapter(getSupportFragmentManager());
-            ViewPager viewPager = findViewById(R.id.pager);
+            ViewPager viewPager = U.findViewById(SelectAppActivity.this, R.id.pager);
             viewPager.setAdapter(pagerAdapter);
 
-            TabLayout tabLayout = findViewById(R.id.sliding_tabs);
+            TabLayout tabLayout = U.findViewById(SelectAppActivity.this, R.id.sliding_tabs);
             tabLayout.setupWithViewPager(viewPager);
 
             findViewById(R.id.configure_start_menu_layout).setVisibility(View.VISIBLE);
index 4e24b6f..13691de 100644 (file)
@@ -71,13 +71,13 @@ public class AppListAdapter extends ArrayAdapter<BlacklistEntry> {
         final String componentName = entry.getPackageName();
         final String componentNameAlt = componentName.contains("/") ? componentName.split("/")[1] : componentName;
 
-        TextView textView = convertView.findViewById(R.id.name);
+        TextView textView = U.findViewById(convertView, R.id.name);
         textView.setText(entry.getLabel());
 
-        final CheckBox checkBox = convertView.findViewById(R.id.checkbox);
+        final CheckBox checkBox = U.findViewById(convertView, R.id.checkbox);
         checkBox.setChecked(blacklist.isBlocked(componentName) || blacklist.isBlocked(componentNameAlt));
 
-        LinearLayout layout = convertView.findViewById(R.id.entry);
+        LinearLayout layout = U.findViewById(convertView, R.id.entry);
         layout.setOnClickListener(view -> {
             if(topApps.isTopApp(componentName) || topApps.isTopApp(componentNameAlt)) {
                 U.showToast(getContext(),
@@ -103,13 +103,13 @@ public class AppListAdapter extends ArrayAdapter<BlacklistEntry> {
         final String componentName = entry.getPackageName();
         final String componentNameAlt = componentName.contains("/") ? componentName.split("/")[1] : componentName;
 
-        TextView textView = convertView.findViewById(R.id.name);
+        TextView textView = U.findViewById(convertView, R.id.name);
         textView.setText(entry.getLabel());
 
-        final CheckBox checkBox = convertView.findViewById(R.id.checkbox);
+        final CheckBox checkBox = U.findViewById(convertView, R.id.checkbox);
         checkBox.setChecked(topApps.isTopApp(componentName) || topApps.isTopApp(componentNameAlt));
 
-        LinearLayout layout = convertView.findViewById(R.id.entry);
+        LinearLayout layout = U.findViewById(convertView, R.id.entry);
         layout.setOnClickListener(view -> {
             if(blacklist.isBlocked(componentName) || blacklist.isBlocked(componentNameAlt)) {
                 U.showToast(getContext(),
index 7050646..0eefc3a 100644 (file)
@@ -71,7 +71,7 @@ public class StartMenuAdapter extends ArrayAdapter<AppEntry> {
 
         final SharedPreferences pref = U.getSharedPreferences(getContext());
 
-        TextView textView = convertView.findViewById(R.id.name);
+        TextView textView = U.findViewById(convertView, R.id.name);
         textView.setText(entry.getLabel());
 
         Intent intent = new Intent();
@@ -90,10 +90,10 @@ public class StartMenuAdapter extends ArrayAdapter<AppEntry> {
                 break;
         }
 
-        ImageView imageView = convertView.findViewById(R.id.icon);
+        ImageView imageView = U.findViewById(convertView, R.id.icon);
         imageView.setImageDrawable(entry.getIcon(getContext()));
 
-        LinearLayout layout = convertView.findViewById(R.id.entry);
+        LinearLayout layout = U.findViewById(convertView, R.id.entry);
         layout.setOnClickListener(view -> {
             LocalBroadcastManager.getInstance(getContext()).sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));
             U.launchApp(getContext(), entry.getPackageName(), entry.getComponentName(), entry.getUserId(getContext()), null, false, false);
@@ -190,7 +190,7 @@ public class StartMenuAdapter extends ArrayAdapter<AppEntry> {
             if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && FreeformHackHelper.getInstance().isInFreeformWorkspace()) {
                 DisplayMetrics metrics = U.getRealDisplayMetrics(getContext());
 
-                if(intent != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+                if(intent != null && Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1)
                     intent.putExtra("context_menu_fix", true);
 
                 getContext().startActivity(intent, U.getActivityOptions(ApplicationType.CONTEXT_MENU).setLaunchBounds(new Rect(0, 0, metrics.widthPixels, metrics.heightPixels)).toBundle());
@@ -208,6 +208,6 @@ public class StartMenuAdapter extends ArrayAdapter<AppEntry> {
 
     private boolean visualFeedbackEnabled() {
         SharedPreferences pref = U.getSharedPreferences(getContext());
-        return Build.VERSION.SDK_INT < Build.VERSION_CODES.O && pref.getBoolean("visual_feedback", true);
+        return Build.VERSION.SDK_INT <= Build.VERSION_CODES.N_MR1 && pref.getBoolean("visual_feedback", true);
     }
 }
index 2fc6d2d..eccce94 100644 (file)
@@ -152,8 +152,8 @@ public class AdvancedFragment extends SettingsFragment implements Preference.OnP
                     editText2Id = R.id.fragmentEditText2;
                 }
 
-                final EditText editText = dialogLayout.findViewById(editTextId);
-                final EditText editText2 = dialogLayout.findViewById(editText2Id);
+                final EditText editText = U.findViewById(dialogLayout, editTextId);
+                final EditText editText2 = U.findViewById(dialogLayout, editText2Id);
 
                 builder.setView(dialogLayout)
                         .setTitle(R.string.dashboard_grid_size)
index 6359e7b..bf7cd04 100644 (file)
@@ -190,13 +190,13 @@ public class AppearanceFragment extends SettingsFragment implements Preference.O
         View colorPreview = dialogLayout.findViewById(R.id.color_preview);
         colorPreview.setBackgroundColor(Color.argb(alpha, red, green, blue));
 
-        TextView hexPreview = dialogLayout.findViewById(R.id.hex_preview);
+        TextView hexPreview = U.findViewById(dialogLayout, R.id.hex_preview);
         hexPreview.setText("#" + String.format("%08x", Color.argb(alpha, red, green, blue)).toUpperCase());
 
-        final TextView alphaValue = dialogLayout.findViewById(R.id.alpha_value);
+        final TextView alphaValue = U.findViewById(dialogLayout, R.id.alpha_value);
         alphaValue.setText("0");
 
-        final SeekBar alphaSeekBar = dialogLayout.findViewById(R.id.alpha_seekbar);
+        final SeekBar alphaSeekBar = U.findViewById(dialogLayout, R.id.alpha_seekbar);
         alphaSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
             @Override
             public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
@@ -216,10 +216,10 @@ public class AppearanceFragment extends SettingsFragment implements Preference.O
 
         alphaSeekBar.setProgress(Color.alpha(color));
 
-        final TextView redValue = dialogLayout.findViewById(R.id.red_value);
+        final TextView redValue = U.findViewById(dialogLayout, R.id.red_value);
         redValue.setText("0");
 
-        final SeekBar redSeekBar = dialogLayout.findViewById(R.id.red_seekbar);
+        final SeekBar redSeekBar = U.findViewById(dialogLayout, R.id.red_seekbar);
         redSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
             @Override
             public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
@@ -239,10 +239,10 @@ public class AppearanceFragment extends SettingsFragment implements Preference.O
 
         redSeekBar.setProgress(Color.red(color));
 
-        final TextView greenValue = dialogLayout.findViewById(R.id.green_value);
+        final TextView greenValue = U.findViewById(dialogLayout, R.id.green_value);
         greenValue.setText("0");
 
-        final SeekBar greenSeekBar = dialogLayout.findViewById(R.id.green_seekbar);
+        final SeekBar greenSeekBar = U.findViewById(dialogLayout, R.id.green_seekbar);
         greenSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
             @Override
             public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
@@ -262,10 +262,10 @@ public class AppearanceFragment extends SettingsFragment implements Preference.O
 
         greenSeekBar.setProgress(Color.green(color));
 
-        final TextView blueValue = dialogLayout.findViewById(R.id.blue_value);
+        final TextView blueValue = U.findViewById(dialogLayout, R.id.blue_value);
         blueValue.setText("0");
 
-        final SeekBar blueSeekBar = dialogLayout.findViewById(R.id.blue_seekbar);
+        final SeekBar blueSeekBar = U.findViewById(dialogLayout, R.id.blue_seekbar);
         blueSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
             @Override
             public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
index e4e0a1e..896d3f2 100644 (file)
@@ -39,6 +39,7 @@ import android.view.View;
 
 import com.farmerbb.taskbar.R;
 import com.farmerbb.taskbar.util.FreeformHackHelper;
+import com.farmerbb.taskbar.util.OreoUtils;
 import com.farmerbb.taskbar.util.U;
 
 public class FreeformModeFragment extends SettingsFragment implements Preference.OnPreferenceClickListener {
@@ -198,14 +199,8 @@ public class FreeformModeFragment extends SettingsFragment implements Preference
                 dialog.show();
                 break;
             case "add_shortcut":
-                if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
-                    ShortcutManager mShortcutManager = getActivity().getSystemService(ShortcutManager.class);
-
-                    if(mShortcutManager.isRequestPinShortcutSupported()) {
-                        ShortcutInfo pinShortcutInfo = new ShortcutInfo.Builder(getActivity(), "freeform_mode").build();
-                        mShortcutManager.requestPinShortcut(pinShortcutInfo, null);
-                    } else
-                        U.showToastLong(getActivity(), R.string.pin_shortcut_not_supported);
+                if(Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
+                    OreoUtils.pinAppShortcut(getActivity());
                 } else {
                     Intent intent = U.getShortcutIntent(getActivity());
                     intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
@@ -222,7 +217,7 @@ public class FreeformModeFragment extends SettingsFragment implements Preference
                 }
                 break;
             case "window_size":
-                if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+                if(Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1) {
                     U.showToastLong(getActivity(), R.string.window_sizes_not_available);
                 }
 
index 752a7c3..13acafe 100644 (file)
@@ -15,7 +15,6 @@
 
 package com.farmerbb.taskbar.fragment;
 
-import android.annotation.TargetApi;
 import android.content.ActivityNotFoundException;
 import android.content.Intent;
 import android.content.SharedPreferences;
@@ -31,6 +30,7 @@ import com.farmerbb.taskbar.R;
 import com.farmerbb.taskbar.activity.SelectAppActivity;
 import com.farmerbb.taskbar.activity.dark.SelectAppActivityDark;
 import com.farmerbb.taskbar.util.Blacklist;
+import com.farmerbb.taskbar.util.OreoUtils;
 import com.farmerbb.taskbar.util.TopApps;
 import com.farmerbb.taskbar.util.U;
 
@@ -90,7 +90,6 @@ public class GeneralFragment extends SettingsFragment implements Preference.OnPr
         }
     }
 
-    @TargetApi(Build.VERSION_CODES.O)
     @Override
     public boolean onPreferenceClick(final Preference p) {
         final SharedPreferences pref = U.getSharedPreferences(getActivity());
@@ -112,10 +111,10 @@ public class GeneralFragment extends SettingsFragment implements Preference.OnPr
                 break;
             case "notification_settings":
                 Intent intent2 = new Intent();
-                intent2.setAction(Settings.ACTION_APP_NOTIFICATION_SETTINGS);
+                intent2.setAction(OreoUtils.ACTION_APP_NOTIFICATION_SETTINGS);
 
                 if(Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1)
-                    intent2.putExtra(Settings.EXTRA_APP_PACKAGE, BuildConfig.APPLICATION_ID);
+                    intent2.putExtra(OreoUtils.EXTRA_APP_PACKAGE, BuildConfig.APPLICATION_ID);
                 else {
                     intent2.putExtra("app_package", BuildConfig.APPLICATION_ID);
                     intent2.putExtra("app_uid", getActivity().getApplicationInfo().uid);
index 48bbfe6..1826cf1 100644 (file)
@@ -105,10 +105,10 @@ public class RecentAppsFragment extends SettingsFragment implements Preference.O
 
                 String value = pref.getString("max_num_of_recents", "10");
 
-                final TextView textView = dialogLayout.findViewById(R.id.seekbar_value);
+                final TextView textView = U.findViewById(dialogLayout, R.id.seekbar_value);
                 textView.setText("0");
 
-                final SeekBar seekBar = dialogLayout.findViewById(R.id.seekbar);
+                final SeekBar seekBar = U.findViewById(dialogLayout, R.id.seekbar);
                 seekBar.setMax(max);
                 seekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                     @Override
@@ -128,7 +128,7 @@ public class RecentAppsFragment extends SettingsFragment implements Preference.O
 
                 seekBar.setProgress(Integer.parseInt(value));
 
-                TextView blurb = dialogLayout.findViewById(R.id.blurb);
+                TextView blurb = U.findViewById(dialogLayout, R.id.blurb);
                 blurb.setText(R.string.num_of_recents_blurb);
 
                 builder.setView(dialogLayout)
@@ -154,10 +154,10 @@ public class RecentAppsFragment extends SettingsFragment implements Preference.O
 
                 String value2 = pref.getString("refresh_frequency", "2");
 
-                final TextView textView2 = dialogLayout2.findViewById(R.id.seekbar_value);
+                final TextView textView2 = U.findViewById(dialogLayout2, R.id.seekbar_value);
                 textView2.setText(R.string.infinity);
 
-                final SeekBar seekBar2 = dialogLayout2.findViewById(R.id.seekbar);
+                final SeekBar seekBar2 = U.findViewById(dialogLayout2, R.id.seekbar);
                 seekBar2.setMax(max2);
                 seekBar2.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
                     @Override
@@ -177,7 +177,7 @@ public class RecentAppsFragment extends SettingsFragment implements Preference.O
 
                 seekBar2.setProgress((int) (Double.parseDouble(value2) * 2));
 
-                TextView blurb2 = dialogLayout2.findViewById(R.id.blurb);
+                TextView blurb2 = U.findViewById(dialogLayout2, R.id.blurb);
                 blurb2.setText(R.string.refresh_frequency_blurb);
 
                 builder2.setView(dialogLayout2)
index 380bbe2..a74e797 100644 (file)
@@ -42,7 +42,7 @@ public class SettingsFragment extends PreferenceFragment {
         // Remove dividers
         View rootView = getView();
         if(rootView != null) {
-            ListView list = rootView.findViewById(android.R.id.list);
+            ListView list = U.findViewById(rootView, android.R.id.list);
             if(list != null) list.setDivider(null);
         }
 
index 78a2db2..d36fce9 100644 (file)
@@ -23,6 +23,7 @@ import android.os.Build;
 
 import com.farmerbb.taskbar.activity.DummyActivity;
 import com.farmerbb.taskbar.service.NotificationService;
+import com.farmerbb.taskbar.util.OreoUtils;
 import com.farmerbb.taskbar.util.U;
 
 public class BootReceiver extends BroadcastReceiver {
@@ -58,10 +59,7 @@ public class BootReceiver extends BroadcastReceiver {
                 Intent notificationIntent = new Intent(context, NotificationService.class);
                 notificationIntent.putExtra("start_services", startServices);
 
-                if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
-                    context.startForegroundService(notificationIntent);
-                else
-                    context.startService(notificationIntent);
+                OreoUtils.startForegroundService(context, notificationIntent);
             } else {
                 editor.putBoolean("taskbar_active", U.isServiceRunning(context, NotificationService.class));
                 editor.apply();
index 1eec3b8..c7e8239 100644 (file)
@@ -23,6 +23,7 @@ import android.os.Build;
 
 import com.farmerbb.taskbar.activity.DummyActivity;
 import com.farmerbb.taskbar.service.NotificationService;
+import com.farmerbb.taskbar.util.OreoUtils;
 import com.farmerbb.taskbar.util.U;
 
 public class PackageUpgradeReceiver extends BroadcastReceiver {
@@ -48,10 +49,7 @@ public class PackageUpgradeReceiver extends BroadcastReceiver {
                 Intent notificationIntent = new Intent(context, NotificationService.class);
                 notificationIntent.putExtra("start_services", startServices);
 
-                if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
-                    context.startForegroundService(notificationIntent);
-                else
-                    context.startService(notificationIntent);
+                OreoUtils.startForegroundService(context, notificationIntent);
             }
         }
     }
index dffc24b..0e6eeb7 100644 (file)
@@ -29,6 +29,7 @@ import com.farmerbb.taskbar.service.StartMenuService;
 import com.farmerbb.taskbar.service.TaskbarService;
 import com.farmerbb.taskbar.util.IconCache;
 import com.farmerbb.taskbar.util.LauncherHelper;
+import com.farmerbb.taskbar.util.OreoUtils;
 import com.farmerbb.taskbar.util.U;
 
 public class ShowHideTaskbarReceiver extends BroadcastReceiver {
@@ -55,11 +56,7 @@ public class ShowHideTaskbarReceiver extends BroadcastReceiver {
 
             notificationIntent.putExtra("start_services", true);
 
-            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
-                context.startForegroundService(notificationIntent);
-            else
-                context.startService(notificationIntent);
-
+            OreoUtils.startForegroundService(context, notificationIntent);
         } else {
             pref.edit().putBoolean("is_hidden", true).apply();
 
@@ -75,11 +72,7 @@ public class ShowHideTaskbarReceiver extends BroadcastReceiver {
                 LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.START_MENU_DISAPPEARING"));
             }
 
-            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
-                context.startForegroundService(notificationIntent);
-            else
-                context.startService(notificationIntent);
-
+            OreoUtils.startForegroundService(context, notificationIntent);
         }
     }
 }
index 23a8f3b..c4bd49a 100644 (file)
@@ -23,6 +23,7 @@ import android.os.Build;
 
 import com.farmerbb.taskbar.activity.DummyActivity;
 import com.farmerbb.taskbar.service.NotificationService;
+import com.farmerbb.taskbar.util.OreoUtils;
 import com.farmerbb.taskbar.util.U;
 
 public class StartReceiver extends BroadcastReceiver {
@@ -63,10 +64,7 @@ public class StartReceiver extends BroadcastReceiver {
             Intent notificationIntent = new Intent(context, NotificationService.class);
             notificationIntent.putExtra("start_services", true);
 
-            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
-                context.startForegroundService(notificationIntent);
-            else
-                context.startService(notificationIntent);
+            OreoUtils.startForegroundService(context, notificationIntent);
         }
     }
 }
index e4a91a5..14b7497 100644 (file)
@@ -25,6 +25,7 @@ import android.support.v4.content.LocalBroadcastManager;
 import com.farmerbb.taskbar.R;
 import com.farmerbb.taskbar.activity.DummyActivity;
 import com.farmerbb.taskbar.service.NotificationService;
+import com.farmerbb.taskbar.util.OreoUtils;
 import com.farmerbb.taskbar.util.U;
 
 public class ToggleFreeformModeReceiver extends BroadcastReceiver {
@@ -38,10 +39,7 @@ public class ToggleFreeformModeReceiver extends BroadcastReceiver {
 
             context.stopService(notificationIntent);
 
-            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
-                context.startForegroundService(notificationIntent);
-            else
-                context.startService(notificationIntent);
+            OreoUtils.startForegroundService(context, notificationIntent);
 
             LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.FINISH_FREEFORM_ACTIVITY"));
             LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.UPDATE_FREEFORM_CHECKBOX"));
@@ -56,10 +54,7 @@ public class ToggleFreeformModeReceiver extends BroadcastReceiver {
 
             context.startActivity(intent2);
 
-            if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
-                context.startForegroundService(notificationIntent);
-            else
-                context.startService(notificationIntent);
+            OreoUtils.startForegroundService(context, notificationIntent);
 
             LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.UPDATE_FREEFORM_CHECKBOX"));
         } else
index eda82c4..cac4923 100644 (file)
@@ -242,7 +242,7 @@ public class DashboardService extends Service {
                 cellLayout.setOnClickListener(cellOcl);
                 cellLayout.setOnHoverListener(cellOhl);
 
-                TextView empty = cellLayout.findViewById(R.id.empty);
+                TextView empty = U.findViewById(cellLayout, R.id.empty);
                 empty.setBackgroundColor(accentColorAlt);
                 empty.setTextColor(accentColor);
 
@@ -348,7 +348,7 @@ public class DashboardService extends Service {
             }
 
             if(inFreeformMode) {
-                if(intent != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+                if(intent != null && Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1)
                     intent.putExtra("context_menu_fix", true);
 
                 U.launchAppMaximized(this, intent);
@@ -540,7 +540,7 @@ public class DashboardService extends Service {
         cellLayout.setOnGenericMotionListener(ogml);
         cellLayout.setOnInterceptedLongPressListener(listener);
 
-        LinearLayout linearLayout = cellLayout.findViewById(R.id.dashboard);
+        LinearLayout linearLayout = U.findViewById(cellLayout, R.id.dashboard);
         linearLayout.addView(hostView);
 
         Bundle bundle2 = (Bundle) cellLayout.getTag();
@@ -576,7 +576,7 @@ public class DashboardService extends Service {
         mAppWidgetHost.deleteAppWidgetId(bundle.getInt("appWidgetId"));
         bundle.remove("appWidgetId");
 
-        LinearLayout linearLayout = cellLayout.findViewById(R.id.dashboard);
+        LinearLayout linearLayout = U.findViewById(cellLayout, R.id.dashboard);
         linearLayout.removeAllViews();
 
         cellLayout.setTag(bundle);
@@ -600,12 +600,12 @@ public class DashboardService extends Service {
     }
 
     private void addPlaceholder(int cellId) {
-        FrameLayout placeholder = cells.get(cellId).findViewById(R.id.placeholder);
+        FrameLayout placeholder = U.findViewById(cells.get(cellId), R.id.placeholder);
         SharedPreferences pref = U.getSharedPreferences(this);
         String providerName = pref.getString("dashboard_widget_" + Integer.toString(cellId) + "_provider", "null");
 
         if(!providerName.equals("null")) {
-            ImageView imageView = placeholder.findViewById(R.id.placeholder_image);
+            ImageView imageView = U.findViewById(placeholder, R.id.placeholder_image);
             ComponentName componentName = ComponentName.unflattenFromString(providerName);
 
             List<AppWidgetProviderInfo> providerInfoList = mAppWidgetManager.getInstalledProvidersForProfile(Process.myUserHandle());
index 9309407..f587c2c 100644 (file)
@@ -17,8 +17,6 @@ package com.farmerbb.taskbar.service;
 
 import android.annotation.TargetApi;
 import android.app.Notification;
-import android.app.NotificationChannel;
-import android.app.NotificationManager;
 import android.app.PendingIntent;
 import android.app.Service;
 import android.content.BroadcastReceiver;
@@ -39,6 +37,7 @@ import com.farmerbb.taskbar.BuildConfig;
 import com.farmerbb.taskbar.MainActivity;
 import com.farmerbb.taskbar.R;
 import com.farmerbb.taskbar.util.IconCache;
+import com.farmerbb.taskbar.util.OreoUtils;
 import com.farmerbb.taskbar.util.U;
 
 public class NotificationService extends Service {
@@ -104,17 +103,7 @@ public class NotificationService extends Service {
                 PendingIntent receiverPendingIntent = PendingIntent.getBroadcast(this, 0, receiverIntent, PendingIntent.FLAG_UPDATE_CURRENT);
                 PendingIntent receiverPendingIntent2 = PendingIntent.getBroadcast(this, 0, receiverIntent2, PendingIntent.FLAG_UPDATE_CURRENT);
 
-                String id = "taskbar_notification_channel";
-
-                if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
-                    NotificationManager mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
-                    CharSequence name = getString(R.string.app_name);
-                    int importance = NotificationManager.IMPORTANCE_MIN;
-
-                    mNotificationManager.createNotificationChannel(new NotificationChannel(id, name, importance));
-                }
-
-                NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, id)
+                NotificationCompat.Builder mBuilder = OreoUtils.getNotificationBuilder(this)
                         .setSmallIcon(pref.getBoolean("app_drawer_icon", false) ? R.drawable.ic_system : R.drawable.ic_allapps)
                         .setContentIntent(contentIntent)
                         .setContentTitle(getString(R.string.taskbar_is_active))
index d64d519..13f8ff1 100644 (file)
@@ -125,7 +125,7 @@ public class StartMenuService extends Service {
             layout.findViewById(R.id.start_menu_space).setVisibility(View.GONE);
         }
     };
-    
+
     private BroadcastReceiver hideReceiver = new BroadcastReceiver() {
         @Override
         public void onReceive(Context context, Intent intent) {
@@ -271,7 +271,7 @@ public class StartMenuService extends Service {
 
         ContextThemeWrapper wrapper = new ContextThemeWrapper(this, theme);
         layout = (StartMenuLayout) LayoutInflater.from(wrapper).inflate(layoutId, null);
-        startMenu = layout.findViewById(R.id.start_menu);
+        startMenu = U.findViewById(layout, R.id.start_menu);
 
         if((shouldShowSearchBox && !hasHardwareKeyboard) || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1)
             layout.viewHandlesBackButton();
@@ -284,12 +284,12 @@ public class StartMenuService extends Service {
         if(pref.getBoolean("transparent_start_menu", false))
             startMenu.setBackgroundColor(0);
 
-        searchView = layout.findViewById(R.id.search);
+        searchView = U.findViewById(layout, R.id.search);
 
         int backgroundTint = U.getBackgroundTint(this);
 
-        FrameLayout startMenuFrame = layout.findViewById(R.id.start_menu_frame);
-        FrameLayout searchViewLayout = layout.findViewById(R.id.search_view_layout);
+        FrameLayout startMenuFrame = U.findViewById(layout, R.id.start_menu_frame);
+        FrameLayout searchViewLayout = U.findViewById(layout, R.id.search_view_layout);
         startMenuFrame.setBackgroundColor(backgroundTint);
         searchViewLayout.setBackgroundColor(backgroundTint);
 
@@ -306,7 +306,7 @@ public class StartMenuService extends Service {
 
                             if(adapter.getCount() > 0) {
                                 View view = adapter.getView(0, null, startMenu);
-                                LinearLayout layout = view.findViewById(R.id.entry);
+                                LinearLayout layout = U.findViewById(view, R.id.entry);
                                 layout.performClick();
                             } else {
                                 if(U.shouldCollapse(StartMenuService.this, true))
@@ -361,7 +361,7 @@ public class StartMenuService extends Service {
 
                     if(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
                         new Handler().postDelayed(() -> {
-                            EditText editText = searchView.findViewById(R.id.search_src_text);
+                            EditText editText = U.findViewById(searchView, R.id.search_src_text);
                             if(editText != null) {
                                 editText.requestFocus();
                                 editText.setSelection(editText.getText().length());
@@ -395,7 +395,7 @@ public class StartMenuService extends Service {
 
             searchView.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
 
-            LinearLayout powerButton = layout.findViewById(R.id.power_button);
+            LinearLayout powerButton = U.findViewById(layout, R.id.power_button);
             powerButton.setOnClickListener(view -> {
                 int[] location = new int[2];
                 view.getLocationOnScreen(location);
@@ -426,7 +426,7 @@ public class StartMenuService extends Service {
         } else
             searchViewLayout.setVisibility(View.GONE);
         
-        textView = layout.findViewById(R.id.no_apps_found);
+        textView = U.findViewById(layout, R.id.no_apps_found);
 
         LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
         
@@ -612,7 +612,7 @@ public class StartMenuService extends Service {
             layout.setOnClickListener(ocl);
             layout.setVisibility(View.VISIBLE);
 
-            if(Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
+            if(Build.VERSION.SDK_INT <= Build.VERSION_CODES.N_MR1)
                 layout.setAlpha(1);
 
             MenuHelper.getInstance().setStartMenuOpen(true);
@@ -623,7 +623,7 @@ public class StartMenuService extends Service {
             boolean inFreeformMode = FreeformHackHelper.getInstance().isInFreeformWorkspace();
 
             if(!U.isChromeOs(this) && (!onHomeScreen || inFreeformMode)) {
-                Class clazz = inFreeformMode && Build.VERSION.SDK_INT < Build.VERSION_CODES.O
+                Class clazz = inFreeformMode && Build.VERSION.SDK_INT <= Build.VERSION_CODES.N_MR1
                         ? InvisibleActivityAlt.class
                         : InvisibleActivity.class;
 
@@ -645,7 +645,7 @@ public class StartMenuService extends Service {
             refreshApps(false);
 
             new Handler().postDelayed(() -> {
-                if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+                if(Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1)
                     layout.setAlpha(1);
 
                 InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
@@ -749,7 +749,7 @@ public class StartMenuService extends Service {
             if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && FreeformHackHelper.getInstance().isInFreeformWorkspace()) {
                 DisplayMetrics metrics = U.getRealDisplayMetrics(this);
 
-                if(intent != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+                if(intent != null && Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1)
                     intent.putExtra("context_menu_fix", true);
 
                 startActivity(intent, U.getActivityOptions(ApplicationType.CONTEXT_MENU).setLaunchBounds(new Rect(0, 0, metrics.widthPixels, metrics.heightPixels)).toBundle());
index f673604..c283837 100644 (file)
@@ -286,20 +286,20 @@ public class TaskbarService extends Service {
 
         ContextThemeWrapper wrapper = new ContextThemeWrapper(this, theme);
         layout = (LinearLayout) LayoutInflater.from(wrapper).inflate(layoutId, null);
-        taskbar = layout.findViewById(R.id.taskbar);
-        scrollView = layout.findViewById(R.id.taskbar_scrollview);
+        taskbar = U.findViewById(layout, R.id.taskbar);
+        scrollView = U.findViewById(layout, R.id.taskbar_scrollview);
 
         if(altButtonConfig) {
-            space = layout.findViewById(R.id.space_alt);
+            space = U.findViewById(layout, R.id.space_alt);
             layout.findViewById(R.id.space).setVisibility(View.GONE);
         } else {
-            space = layout.findViewById(R.id.space);
+            space = U.findViewById(layout, R.id.space);
             layout.findViewById(R.id.space_alt).setVisibility(View.GONE);
         }
 
         space.setOnClickListener(v -> toggleTaskbar());
 
-        startButton = layout.findViewById(R.id.start_button);
+        startButton = U.findViewById(layout, R.id.start_button);
         int padding;
 
         if(pref.getBoolean("app_drawer_icon", false)) {
@@ -350,10 +350,10 @@ public class TaskbarService extends Service {
         LocalBroadcastManager.getInstance(TaskbarService.this).sendBroadcast(intent);
 
         if(altButtonConfig) {
-            button = layout.findViewById(R.id.hide_taskbar_button_alt);
+            button = U.findViewById(layout, R.id.hide_taskbar_button_alt);
             layout.findViewById(R.id.hide_taskbar_button).setVisibility(View.GONE);
         } else {
-            button = layout.findViewById(R.id.hide_taskbar_button);
+            button = U.findViewById(layout, R.id.hide_taskbar_button);
             layout.findViewById(R.id.hide_taskbar_button_alt).setVisibility(View.GONE);
         }
 
@@ -364,12 +364,12 @@ public class TaskbarService extends Service {
         updateButton(false);
         button.setOnClickListener(v -> toggleTaskbar());
 
-        LinearLayout buttonLayout = layout.findViewById(altButtonConfig
+        LinearLayout buttonLayout = U.findViewById(layout, altButtonConfig
                 ? R.id.hide_taskbar_button_layout_alt
                 : R.id.hide_taskbar_button_layout);
         if(buttonLayout != null) buttonLayout.setOnClickListener(v -> toggleTaskbar());
 
-        LinearLayout buttonLayoutToHide = layout.findViewById(altButtonConfig
+        LinearLayout buttonLayoutToHide = U.findViewById(layout, altButtonConfig
                 ? R.id.hide_taskbar_button_layout
                 : R.id.hide_taskbar_button_layout_alt);
         if(buttonLayoutToHide != null) buttonLayoutToHide.setVisibility(View.GONE);
@@ -377,8 +377,8 @@ public class TaskbarService extends Service {
         int backgroundTint = U.getBackgroundTint(this);
         int accentColor = U.getAccentColor(this);
 
-        dashboardButton = layout.findViewById(R.id.dashboard_button);
-        navbarButtons = layout.findViewById(R.id.navbar_buttons);
+        dashboardButton = U.findViewById(layout, R.id.dashboard_button);
+        navbarButtons = U.findViewById(layout, R.id.navbar_buttons);
 
         dashboardEnabled = pref.getBoolean("dashboard", false);
         if(dashboardEnabled) {
@@ -396,7 +396,7 @@ public class TaskbarService extends Service {
         if(pref.getBoolean("button_back", false)) {
             navbarButtonsEnabled = true;
 
-            ImageView backButton = layout.findViewById(R.id.button_back);
+            ImageView backButton = U.findViewById(layout, R.id.button_back);
             backButton.setVisibility(View.VISIBLE);
             backButton.setOnClickListener(v -> {
                 U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_BACK);
@@ -430,7 +430,7 @@ public class TaskbarService extends Service {
         if(pref.getBoolean("button_home", false)) {
             navbarButtonsEnabled = true;
 
-            ImageView homeButton = layout.findViewById(R.id.button_home);
+            ImageView homeButton = U.findViewById(layout, R.id.button_home);
             homeButton.setVisibility(View.VISIBLE);
             homeButton.setOnClickListener(v -> {
                 U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_HOME);
@@ -472,7 +472,7 @@ public class TaskbarService extends Service {
         if(pref.getBoolean("button_recents", false)) {
             navbarButtonsEnabled = true;
 
-            ImageView recentsButton = layout.findViewById(R.id.button_recents);
+            ImageView recentsButton = U.findViewById(layout, R.id.button_recents);
             recentsButton.setVisibility(View.VISIBLE);
             recentsButton.setOnClickListener(v -> {
                 U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_RECENTS);
@@ -855,7 +855,7 @@ public class TaskbarService extends Service {
 
                             if(fullLength && U.getTaskbarPosition(this).contains("bottom")) {
                                 try {
-                                    Space whitespace = layout.findViewById(R.id.whitespace);
+                                    Space whitespace = U.findViewById(layout, R.id.whitespace);
                                     ViewGroup.LayoutParams params2 = whitespace.getLayoutParams();
                                     params2.height = maxScreenSize - recentsSize;
                                     whitespace.setLayoutParams(params2);
@@ -870,7 +870,7 @@ public class TaskbarService extends Service {
 
                             if(fullLength && U.getTaskbarPosition(this).contains("right")) {
                                 try {
-                                    Space whitespace = layout.findViewById(R.id.whitespace);
+                                    Space whitespace = U.findViewById(layout, R.id.whitespace);
                                     ViewGroup.LayoutParams params2 = whitespace.getLayoutParams();
                                     params2.width = maxScreenSize - recentsSize;
                                     whitespace.setLayoutParams(params2);
@@ -1141,7 +1141,7 @@ public class TaskbarService extends Service {
         if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && FreeformHackHelper.getInstance().isInFreeformWorkspace()) {
             DisplayMetrics metrics = U.getRealDisplayMetrics(this);
 
-            if(intent != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+            if(intent != null && Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1)
                 intent.putExtra("context_menu_fix", true);
 
             startActivity(intent, U.getActivityOptions(ApplicationType.CONTEXT_MENU).setLaunchBounds(new Rect(0, 0, metrics.widthPixels, metrics.heightPixels)).toBundle());
@@ -1186,8 +1186,8 @@ public class TaskbarService extends Service {
         final AppEntry entry = list.get(position);
         final SharedPreferences pref = U.getSharedPreferences(this);
 
-        ImageView imageView = convertView.findViewById(R.id.icon);
-        ImageView imageView2 = convertView.findViewById(R.id.shortcut_icon);
+        ImageView imageView = U.findViewById(convertView, R.id.icon);
+        ImageView imageView2 = U.findViewById(convertView, R.id.shortcut_icon);
         imageView.setImageDrawable(entry.getIcon(this));
         imageView2.setBackgroundColor(pref.getInt("accent_color", getResources().getInteger(R.integer.translucent_white)));
 
@@ -1207,7 +1207,7 @@ public class TaskbarService extends Service {
             imageView2.setRotationY(180);
         }
 
-        FrameLayout layout = convertView.findViewById(R.id.entry);
+        FrameLayout layout = U.findViewById(convertView, R.id.entry);
         layout.setOnClickListener(view -> U.launchApp(TaskbarService.this, entry.getPackageName(), entry.getComponentName(), entry.getUserId(TaskbarService.this), null, true, false));
 
         layout.setOnLongClickListener(view -> {
@@ -1286,7 +1286,7 @@ public class TaskbarService extends Service {
         if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && FreeformHackHelper.getInstance().isInFreeformWorkspace()) {
             DisplayMetrics metrics = U.getRealDisplayMetrics(this);
 
-            if(intent != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+            if(intent != null && Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1)
                 intent.putExtra("context_menu_fix", true);
 
             startActivity(intent, U.getActivityOptions(ApplicationType.CONTEXT_MENU).setLaunchBounds(new Rect(0, 0, metrics.widthPixels, metrics.heightPixels)).toBundle());
index 471dec2..d3b6616 100644 (file)
@@ -49,6 +49,7 @@ import android.support.v4.content.LocalBroadcastManager;
 import android.util.DisplayMetrics;
 import android.view.Display;
 import android.view.Surface;
+import android.view.View;
 import android.view.WindowManager;
 import android.widget.Toast;
 
@@ -251,7 +252,7 @@ public class U {
         SharedPreferences pref = getSharedPreferences(context);
         FreeformHackHelper helper = FreeformHackHelper.getInstance();
 
-        boolean specialLaunch = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
+        boolean specialLaunch = Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1
                 && FreeformHackHelper.getInstance().isInFreeformWorkspace()
                 && MenuHelper.getInstance().isContextMenuOpen();
 
@@ -897,7 +898,7 @@ public class U {
                 stackId = FREEFORM_WORKSPACE_STACK_ID;
                 break;
             case CONTEXT_MENU:
-                if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+                if(Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1)
                     stackId = FULLSCREEN_WORKSPACE_STACK_ID;
         }
 
@@ -1078,8 +1079,8 @@ public class U {
     }
 
     public static int getOverlayType() {
-        return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
-                ? WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
+        return Build.VERSION.SDK_INT > Build.VERSION_CODES.N_MR1
+                ? OreoUtils.TYPE_APPLICATION_OVERLAY
                 : WindowManager.LayoutParams.TYPE_PHONE;
     }
 
@@ -1098,4 +1099,14 @@ public class U {
         } else
             return false;
     }
+
+    @SuppressWarnings("unchecked")
+    public static <T extends View> T findViewById(Activity target, int id) {
+        return (T) target.findViewById(id);
+    }
+
+    @SuppressWarnings("unchecked")
+    public static <T extends View> T findViewById(View target, int id) {
+        return (T) target.findViewById(id);
+    }
 }
diff --git a/app/src/oreoutils/java/com/farmerbb/taskbar/util/OreoUtils.java b/app/src/oreoutils/java/com/farmerbb/taskbar/util/OreoUtils.java
new file mode 100644 (file)
index 0000000..5232be3
--- /dev/null
@@ -0,0 +1,71 @@
+/* Copyright 2017 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.util;
+
+import android.annotation.TargetApi;
+import android.app.NotificationChannel;
+import android.app.NotificationManager;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ShortcutInfo;
+import android.content.pm.ShortcutManager;
+import android.os.Build;
+import android.provider.Settings;
+import android.support.v4.app.NotificationCompat;
+import android.view.WindowManager;
+
+import com.farmerbb.taskbar.R;
+
+@TargetApi(Build.VERSION_CODES.O)
+public class OreoUtils {
+
+    private OreoUtils() {}
+
+    static int TYPE_APPLICATION_OVERLAY = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
+    public static String ACTION_APP_NOTIFICATION_SETTINGS = Settings.ACTION_APP_NOTIFICATION_SETTINGS;
+    public static String EXTRA_APP_PACKAGE = Settings.EXTRA_APP_PACKAGE;
+
+    public static void pinAppShortcut(Context context) {
+        ShortcutManager mShortcutManager = context.getSystemService(ShortcutManager.class);
+
+        if(mShortcutManager.isRequestPinShortcutSupported()) {
+            ShortcutInfo pinShortcutInfo = new ShortcutInfo.Builder(context, "freeform_mode").build();
+            mShortcutManager.requestPinShortcut(pinShortcutInfo, null);
+        } else
+            U.showToastLong(context, R.string.pin_shortcut_not_supported);
+    }
+
+    public static NotificationCompat.Builder getNotificationBuilder(Context context) {
+        String id = "taskbar_notification_channel";
+
+        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+            CharSequence name = context.getString(R.string.app_name);
+            int importance = NotificationManager.IMPORTANCE_MIN;
+
+            NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
+            mNotificationManager.createNotificationChannel(new NotificationChannel(id, name, importance));
+        }
+
+        return new NotificationCompat.Builder(context, id);
+    }
+
+    public static void startForegroundService(Context context, Intent intent) {
+        if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
+            context.startForegroundService(intent);
+        else
+            context.startService(intent);
+    }
+}
index 8fb3182..3d4ecb7 100644 (file)
@@ -7,7 +7,7 @@ buildscript {
     }
 
     dependencies {
-        classpath 'com.android.tools.build:gradle:3.0.0-rc1'
+        classpath 'com.android.tools.build:gradle:3.0.0-rc2'
 
         // NOTE: Do not place your application dependencies here; they belong
         // in the individual module build.gradle files