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
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)
}
flavorDimensions "default"
-
+
productFlavors {
paid {
dimension "default"
applicationId "com.farmerbb.taskbar"
}
}
+
+ sourceSets {
+ paid {
+ java {
+ srcDirs('src/main/java', 'src/oreoutils/java')
+ }
+ }
+
+ free {
+ java {
+ srcDirs('src/main/java', 'src/oreoutils/java')
+ }
+ }
+ }
}
dependencies {
--- /dev/null
+/* 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);
+ }
+}
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));
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 {
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();
});
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);
}
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;
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)
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"));
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();
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);
}
}
- 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();
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();
getWindow().setElevation(0);
}
- progressBar = findViewById(R.id.progress_bar);
+ progressBar = U.findViewById(this, R.id.progress_bar);
appListGenerator = new AppListGenerator();
appListGenerator.execute();
} else {
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);
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(),
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(),
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();
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);
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());
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);
}
}
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)
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) {
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) {
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) {
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) {
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 {
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");
}
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);
}
package com.farmerbb.taskbar.fragment;
-import android.annotation.TargetApi;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.content.SharedPreferences;
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;
}
}
- @TargetApi(Build.VERSION_CODES.O)
@Override
public boolean onPreferenceClick(final Preference p) {
final SharedPreferences pref = U.getSharedPreferences(getActivity());
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);
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
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)
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
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)
// 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);
}
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 {
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();
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 {
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);
}
}
}
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 {
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();
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);
}
}
}
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 {
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);
}
}
}
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 {
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"));
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
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);
}
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);
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();
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);
}
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());
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;
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 {
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))
layout.findViewById(R.id.start_menu_space).setVisibility(View.GONE);
}
};
-
+
private BroadcastReceiver hideReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
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();
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);
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))
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());
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);
} 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);
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);
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;
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);
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());
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)) {
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);
}
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);
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) {
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);
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);
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);
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);
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);
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());
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)));
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 -> {
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());
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.Surface;
+import android.view.View;
import android.view.WindowManager;
import android.widget.Toast;
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();
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;
}
}
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;
}
} 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);
+ }
}
--- /dev/null
+/* 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);
+ }
+}
}
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