import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
-import android.content.IntentFilter;
import android.content.SharedPreferences;
+import android.os.Build;
import android.os.Bundle;
-import android.support.v4.content.LocalBroadcastManager;
-import android.util.DisplayMetrics;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.WindowManager;
import android.widget.LinearLayout;
import com.farmerbb.taskbar.R;
-import com.farmerbb.taskbar.util.DashboardHelper;
-import com.farmerbb.taskbar.util.FreeformHackHelper;
+import com.farmerbb.taskbar.helper.DashboardHelper;
+import com.farmerbb.taskbar.util.DisplayInfo;
+import com.farmerbb.taskbar.helper.LauncherHelper;
import com.farmerbb.taskbar.util.U;
+import static com.farmerbb.taskbar.util.Constants.*;
+
public class DashboardActivity extends Activity {
private AppWidgetManager mAppWidgetManager;
@Override
public void onReceive(Context context, Intent intent) {
mAppWidgetManager = AppWidgetManager.getInstance(context);
- mAppWidgetHost = new AppWidgetHost(context, intent.getIntExtra("appWidgetId", -1));
- cellId = intent.getIntExtra("cellId", -1);
+ mAppWidgetHost = new AppWidgetHost(context, intent.getIntExtra(EXTRA_APPWIDGET_ID, -1));
+ cellId = intent.getIntExtra(EXTRA_CELL_ID, -1);
int appWidgetId = mAppWidgetHost.allocateAppWidgetId();
Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
try {
startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET);
+ U.sendBroadcast(DashboardActivity.this, ACTION_TEMP_HIDE_TASKBAR);
} catch (ActivityNotFoundException e) {
- U.showToast(DashboardActivity.this, R.string.lock_device_not_supported);
+ U.showToast(DashboardActivity.this, R.string.tb_lock_device_not_supported);
finish();
}
private BroadcastReceiver removeWidgetReceiver = new BroadcastReceiver() {
@Override
public void onReceive(final Context context, Intent intent) {
- cellId = intent.getIntExtra("cellId", -1);
+ cellId = intent.getIntExtra(EXTRA_CELL_ID, -1);
AlertDialog.Builder builder = new AlertDialog.Builder(DashboardActivity.this);
- builder.setTitle(R.string.remove_widget)
- .setMessage(R.string.are_you_sure)
- .setNegativeButton(R.string.action_cancel, (dialog, which) -> {
- LocalBroadcastManager.getInstance(DashboardActivity.this).sendBroadcast(new Intent("com.farmerbb.taskbar.REMOVE_WIDGET_COMPLETED"));
+ builder.setTitle(R.string.tb_remove_widget)
+ .setMessage(R.string.tb_are_you_sure)
+ .setNegativeButton(R.string.tb_action_cancel, (dialog, which) -> {
+ U.sendBroadcast(DashboardActivity.this, ACTION_REMOVE_WIDGET_COMPLETED);
shouldFinish = true;
})
- .setPositiveButton(R.string.action_ok, (dialog, which) -> {
- Intent intent1 = new Intent("com.farmerbb.taskbar.REMOVE_WIDGET_COMPLETED");
- intent1.putExtra("cellId", cellId);
- LocalBroadcastManager.getInstance(DashboardActivity.this).sendBroadcast(intent1);
+ .setPositiveButton(R.string.tb_action_ok, (dialog, which) -> {
+ Intent intent1 = new Intent(ACTION_REMOVE_WIDGET_COMPLETED);
+ intent1.putExtra(EXTRA_CELL_ID, cellId);
+ U.sendBroadcast(DashboardActivity.this, intent1);
shouldFinish = true;
});
shouldCollapse = false;
if(contextMenuFix)
- U.startFreeformHack(DashboardActivity.this, false, false);
+ U.startFreeformHack(DashboardActivity.this);
finish();
}
};
- @SuppressWarnings("deprecation")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- contextMenuFix = getIntent().hasExtra("context_menu_fix");
+ contextMenuFix = getIntent().hasExtra(EXTRA_CONTEXT_MENU_FIX);
// Detect outside touches, and finish the activity when one is detected
getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL, WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH);
- DisplayMetrics metrics = U.getRealDisplayMetrics(this);
+ DisplayInfo display = U.getDisplayInfo(this);
- setContentView(R.layout.incognito);
+ setContentView(R.layout.tb_incognito);
- LinearLayout layout = (LinearLayout) findViewById(R.id.incognitoLayout);
- layout.setLayoutParams(new FrameLayout.LayoutParams(metrics.widthPixels, metrics.heightPixels));
+ LinearLayout layout = findViewById(R.id.incognitoLayout);
+ layout.setLayoutParams(new FrameLayout.LayoutParams(display.width, display.height));
- LocalBroadcastManager.getInstance(this).registerReceiver(addWidgetReceiver, new IntentFilter("com.farmerbb.taskbar.ADD_WIDGET_REQUESTED"));
- LocalBroadcastManager.getInstance(this).registerReceiver(removeWidgetReceiver, new IntentFilter("com.farmerbb.taskbar.REMOVE_WIDGET_REQUESTED"));
- LocalBroadcastManager.getInstance(this).registerReceiver(finishReceiver, new IntentFilter("com.farmerbb.taskbar.DASHBOARD_DISAPPEARING"));
+ U.registerReceiver(this, addWidgetReceiver, ACTION_ADD_WIDGET_REQUESTED);
+ U.registerReceiver(this, removeWidgetReceiver, ACTION_REMOVE_WIDGET_REQUESTED);
+ U.registerReceiver(this, finishReceiver, ACTION_DASHBOARD_DISAPPEARING);
if(!DashboardHelper.getInstance().isDashboardOpen()) finish();
}
@Override
public void onBackPressed() {
- if(contextMenuFix)
- U.startFreeformHack(this, false, false);
+ if(contextMenuFix) {
+ U.startFreeformHack(this);
+ }
- LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_DASHBOARD"));
+ U.sendBroadcast(this, ACTION_HIDE_DASHBOARD);
}
@Override
return super.dispatchKeyShortcutEvent(event);
}
+ // @Override
+ public void onTopResumedActivityChanged(boolean isTopResumedActivity) {
+ if(!isTopResumedActivity)
+ performOnPauseLogic();
+ }
+
@Override
protected void onPause() {
super.onPause();
+ if(Build.VERSION.SDK_INT <= Build.VERSION_CODES.P)
+ performOnPauseLogic();
+ }
+
+ private void performOnPauseLogic() {
if(shouldFinish) {
if(shouldCollapse) {
- SharedPreferences pref = U.getSharedPreferences(this);
- if(pref.getBoolean("hide_taskbar", true) && !FreeformHackHelper.getInstance().isInFreeformWorkspace())
- LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_TASKBAR"));
- else
- LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));
+ if(U.shouldCollapse(this, true)) {
+ U.sendBroadcast(this, ACTION_HIDE_TASKBAR);
+ } else {
+ U.sendBroadcast(this, ACTION_HIDE_START_MENU);
+ }
}
contextMenuFix = false;
protected void onDestroy() {
super.onDestroy();
- LocalBroadcastManager.getInstance(this).unregisterReceiver(addWidgetReceiver);
- LocalBroadcastManager.getInstance(this).unregisterReceiver(removeWidgetReceiver);
- LocalBroadcastManager.getInstance(this).unregisterReceiver(finishReceiver);
+ U.unregisterReceiver(this, addWidgetReceiver);
+ U.unregisterReceiver(this, removeWidgetReceiver);
+ U.unregisterReceiver(this, finishReceiver);
}
@Override
}
}
- LocalBroadcastManager.getInstance(this).sendBroadcast(new Intent("com.farmerbb.taskbar.ADD_WIDGET_COMPLETED"));
+ U.sendBroadcast(this, ACTION_ADD_WIDGET_COMPLETED);
+ U.sendBroadcast(this, ACTION_TEMP_SHOW_TASKBAR);
shouldFinish = true;
}
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
startActivityForResult(intent, REQUEST_CREATE_APPWIDGET);
+ SharedPreferences pref = U.getSharedPreferences(this);
+ if(LauncherHelper.getInstance().isOnHomeScreen(this)
+ && (!pref.getBoolean(PREF_TASKBAR_ACTIVE, false)
+ || pref.getBoolean(PREF_IS_HIDDEN, false)))
+ pref.edit().putBoolean(PREF_DONT_STOP_DASHBOARD, true).apply();
+
shouldFinish = false;
} else {
createWidget(data);
}
private void createWidget(Intent data) {
- Intent intent = new Intent("com.farmerbb.taskbar.ADD_WIDGET_COMPLETED");
- intent.putExtra("appWidgetId", data.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1));
- intent.putExtra("cellId", cellId);
- LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
+ Intent intent = new Intent(ACTION_ADD_WIDGET_COMPLETED);
+ intent.putExtra(
+ EXTRA_APPWIDGET_ID,
+ data.getExtras().getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, -1)
+ );
+ intent.putExtra(EXTRA_CELL_ID, cellId);
+
+ U.sendBroadcast(this, intent);
+ U.sendBroadcast(this, ACTION_TEMP_SHOW_TASKBAR);
shouldFinish = true;
}