<action android:name="com.farmerbb.taskbar.DISABLE_HOME"/>
</intent-filter>
</receiver>
+ <receiver
+ android:name=".receiver.ToggleFreeformModeReceiver"
+ android:permission="${applicationId}.START_STOP_TASKBAR" >
+ <intent-filter>
+ <action android:name="com.farmerbb.taskbar.TOGGLE_FREEFORM_MODE"/>
+ </intent-filter>
+ </receiver>
</application>
import android.annotation.TargetApi;
import android.content.ActivityNotFoundException;
+import android.content.BroadcastReceiver;
+import android.content.Context;
import android.content.Intent;
+import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
public class FreeformModeFragment extends SettingsFragment implements Preference.OnPreferenceClickListener {
+ private BroadcastReceiver checkBoxReceiver = new BroadcastReceiver() {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ CheckBoxPreference preference = (CheckBoxPreference) findPreference("freeform_hack");
+ if(preference != null) {
+ SharedPreferences pref = U.getSharedPreferences(getActivity());
+ preference.setChecked(pref.getBoolean("freeform_hack", false));
+ }
+ }
+ };
+
@Override
public void onActivityCreated(Bundle savedInstanceState) {
finishedLoadingPrefs = false;
}
}
+ LocalBroadcastManager.getInstance(getActivity()).registerReceiver(checkBoxReceiver, new IntentFilter("com.farmerbb.taskbar.UPDATE_FREEFORM_CHECKBOX"));
+
finishedLoadingPrefs = true;
}
}
}
+ @Override
+ public void onDestroy() {
+ super.onDestroy();
+
+ LocalBroadcastManager.getInstance(getActivity()).unregisterReceiver(checkBoxReceiver);
+ }
+
@TargetApi(Build.VERSION_CODES.N)
@Override
public boolean onPreferenceClick(final Preference p) {
LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(new Intent("com.farmerbb.taskbar.FORCE_TASKBAR_RESTART"));
}
+ restartNotificationService();
break;
case "freeform_mode_help":
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
if(restartNotificationService) {
restartNotificationService = false;
- if(U.isServiceRunning(getActivity(), NotificationService.class)) {
- SharedPreferences pref = U.getSharedPreferences(getActivity());
- pref.edit().putBoolean("is_restarting", true).apply();
+ restartNotificationService();
+ }
+ }
- Intent intent = new Intent(getActivity(), NotificationService.class);
- getActivity().stopService(intent);
- getActivity().startService(intent);
- }
+ protected void restartNotificationService() {
+ if(U.isServiceRunning(getActivity(), NotificationService.class)) {
+ SharedPreferences pref = U.getSharedPreferences(getActivity());
+ pref.edit().putBoolean("is_restarting", true).apply();
+
+ Intent intent = new Intent(getActivity(), NotificationService.class);
+ getActivity().stopService(intent);
+ getActivity().startService(intent);
}
}
}
\ No newline at end of file
--- /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.receiver;
+
+import android.content.BroadcastReceiver;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+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.U;
+
+public class ToggleFreeformModeReceiver extends BroadcastReceiver {
+ @Override
+ public void onReceive(Context context, Intent intent) {
+ Intent notificationIntent = new Intent(context, NotificationService.class);
+
+ SharedPreferences pref = U.getSharedPreferences(context);
+ if(pref.getBoolean("freeform_hack", false)) {
+ pref.edit().putBoolean("freeform_hack", false).apply();
+
+ context.stopService(notificationIntent);
+
+ pref.edit().putBoolean("is_restarting", true).apply();
+
+ context.startService(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"));
+ } else if(U.hasFreeformSupport(context)) {
+ pref.edit().putBoolean("freeform_hack", true).apply();
+
+ context.stopService(notificationIntent);
+
+ pref.edit().putBoolean("is_restarting", true).apply();
+
+ Intent intent2 = new Intent(context, DummyActivity.class);
+ intent2.putExtra("start_freeform_hack", true);
+ intent2.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
+ context.startActivity(intent2);
+
+ context.startService(notificationIntent);
+
+ LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent("com.farmerbb.taskbar.UPDATE_FREEFORM_CHECKBOX"));
+ } else
+ U.showToastLong(context, R.string.no_freeform_support);
+ }
+}
Intent intent = new Intent(this, MainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
+ Intent receiverIntent = new Intent("com.farmerbb.taskbar.SHOW_HIDE_TASKBAR");
+ receiverIntent.setPackage(BuildConfig.APPLICATION_ID);
+
+ Intent receiverIntent2 = new Intent("com.farmerbb.taskbar.QUIT");
+ receiverIntent.setPackage(BuildConfig.APPLICATION_ID);
+
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);
- PendingIntent receiverIntent = PendingIntent.getBroadcast(this, 0, new Intent("com.farmerbb.taskbar.SHOW_HIDE_TASKBAR"), PendingIntent.FLAG_UPDATE_CURRENT);
- PendingIntent receiverIntent2 = PendingIntent.getBroadcast(this, 0, new Intent("com.farmerbb.taskbar.QUIT"), PendingIntent.FLAG_UPDATE_CURRENT);
+ PendingIntent receiverPendingIntent = PendingIntent.getBroadcast(this, 0, receiverIntent, PendingIntent.FLAG_UPDATE_CURRENT);
+ PendingIntent receiverPendingIntent2 = PendingIntent.getBroadcast(this, 0, receiverIntent2, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(pref.getBoolean("app_drawer_icon", false) ? R.drawable.ic_system : R.drawable.ic_allapps)
.setContentTitle(getString(R.string.taskbar_is_active))
.setContentText(getString(R.string.click_to_open_settings))
.setColor(ContextCompat.getColor(this, R.color.colorPrimary))
- .addAction(0, label, receiverIntent)
- .addAction(0, getString(R.string.action_quit), receiverIntent2)
.setPriority(Notification.PRIORITY_MIN)
.setShowWhen(false)
.setOngoing(true);
+ if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
+ String freeformLabel = getString(pref.getBoolean("freeform_hack", false) ? R.string.freeform_off : R.string.freeform_on);
+
+ Intent freeformIntent = new Intent("com.farmerbb.taskbar.TOGGLE_FREEFORM_MODE");
+ freeformIntent.setPackage(BuildConfig.APPLICATION_ID);
+
+ PendingIntent freeformPendingIntent = PendingIntent.getBroadcast(this, 0, freeformIntent, PendingIntent.FLAG_UPDATE_CURRENT);
+
+ mBuilder.addAction(0, freeformLabel, freeformPendingIntent);
+ }
+
+ mBuilder.addAction(0, label, receiverPendingIntent)
+ .addAction(0, getString(R.string.action_quit), receiverPendingIntent2);
+
startForeground(8675309, mBuilder.build());
LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent("com.farmerbb.taskbar.UPDATE_SWITCH"));
}
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.N || !pref.getBoolean("freeform_hack", false)) {
+ Bundle bundle = Build.VERSION.SDK_INT < Build.VERSION_CODES.N ? null : getActivityOptions(getApplicationType(context, packageName)).toBundle();
if(shortcut == null) {
UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
if(userId == userManager.getSerialNumberForUser(Process.myUserHandle())) {
try {
- context.startActivity(intent, null);
+ context.startActivity(intent, bundle);
} catch (ActivityNotFoundException e) {
- launchAndroidForWork(context, intent.getComponent(), null, userId);
+ launchAndroidForWork(context, intent.getComponent(), bundle, userId);
} catch (IllegalArgumentException e) { /* Gracefully fail */ }
} else
- launchAndroidForWork(context, intent.getComponent(), null, userId);
+ launchAndroidForWork(context, intent.getComponent(), bundle, userId);
} else
- launchShortcut(context, shortcut, null);
+ launchShortcut(context, shortcut, bundle);
} else switch(windowSize) {
case "standard":
if(FreeformHackHelper.getInstance().isInFreeformWorkspace() && !specialLaunch) {
switch(applicationType) {
case APPLICATION:
- // Let the system determine the stack id
+ if(!FreeformHackHelper.getInstance().isFreeformHackActive())
+ stackId = FULLSCREEN_WORKSPACE_STACK_ID;
break;
case GAME:
stackId = FULLSCREEN_WORKSPACE_STACK_ID;
<resources>
<string name="pref_description_launcher">Taskbar als Homescreen verwenden</string>
+ <string name="action_show">Taskbar anzeigen</string>
+ <string name="action_hide">Taskbar verstecken</string>
</resources>
\ No newline at end of file
<string name="widget_restore_toast">Select \"%1$s\" to restore this widget</string>
+ <string name="freeform_on">Freeform on</string>
+ <string name="freeform_off">Freeform off</string>
+
</resources>
<resources>
<string name="pref_description_launcher">Taskbar をホーム画面の置き換えとして使用します</string>
+ <string name="action_show">Taskbar を表示</string>
+ <string name="action_hide">Taskbar を非表示</string>
</resources>
\ No newline at end of file
<string name="widget_restore_toast">\"%1$s\" を選択してこのウィジェットを復元します</string>
+ <string name="freeform_on">Freeform on</string>
+ <string name="freeform_off">Freeform off</string>
+
</resources>
<resources>
<string name="pref_description_launcher">Использовать Taskbar как замену главного экрана\n\nКогда режим Freeform включен, это позволит Taskbar всегда запускать приложения в этом режиме.</string>
+ <string name="action_show">Показать</string>
+ <string name="action_hide">Скрыть</string>
</resources>
<string name="widget_restore_toast">Select \"%1$s\" to restore this widget</string>
+ <string name="freeform_on">Freeform on</string>
+ <string name="freeform_off">Freeform off</string>
+
</resources>
<resources>
<string name="pref_description_launcher">Use Taskbar as a home screen replacement\n\nWhen freeform window support is also enabled, this will allow Taskbar to always launch apps in freeform mode.</string>
+ <string name="action_show">Show</string>
+ <string name="action_hide">Hide</string>
</resources>
<string name="widget_restore_toast">Select \"%1$s\" to restore this widget</string>
+ <string name="freeform_on">Freeform on</string>
+ <string name="freeform_off">Freeform off</string>
+
</resources>