dashboardButton = layout.findViewById(R.id.dashboard_button);
navbarButtons = layout.findViewById(R.id.navbar_buttons);
-
- dashboardEnabled = pref.getBoolean(PREF_DASHBOARD, context.getResources().getBoolean(R.bool.tb_def_dashboard));
- if(dashboardEnabled) {
- layout.findViewById(R.id.square1).setBackgroundColor(accentColor);
- layout.findViewById(R.id.square2).setBackgroundColor(accentColor);
- layout.findViewById(R.id.square3).setBackgroundColor(accentColor);
- layout.findViewById(R.id.square4).setBackgroundColor(accentColor);
- layout.findViewById(R.id.square5).setBackgroundColor(accentColor);
- layout.findViewById(R.id.square6).setBackgroundColor(accentColor);
-
- dashboardButton.setOnClickListener(v -> U.sendBroadcast(context, ACTION_TOGGLE_DASHBOARD));
- } else
- dashboardButton.setVisibility(View.GONE);
-
+ dashboardEnabled = drawDashboard(context, pref, layout, dashboardButton, accentColor);
navbarButtonsEnabled = drawNavbarButtons(context, layout, pref, accentColor);
-
if(!navbarButtonsEnabled)
navbarButtons.setVisibility(View.GONE);
}
@VisibleForTesting
+ public boolean drawDashboard(Context context,
+ SharedPreferences pref,
+ LinearLayout layout,
+ FrameLayout dashboardButton,
+ int accentColor) {
+ boolean dashboardEnabled =
+ pref.getBoolean(
+ PREF_DASHBOARD,
+ context.getResources().getBoolean(R.bool.tb_def_dashboard)
+ );
+ if(dashboardEnabled) {
+ layout.findViewById(R.id.square1).setBackgroundColor(accentColor);
+ layout.findViewById(R.id.square2).setBackgroundColor(accentColor);
+ layout.findViewById(R.id.square3).setBackgroundColor(accentColor);
+ layout.findViewById(R.id.square4).setBackgroundColor(accentColor);
+ layout.findViewById(R.id.square5).setBackgroundColor(accentColor);
+ layout.findViewById(R.id.square6).setBackgroundColor(accentColor);
+
+ dashboardButton
+ .setOnClickListener(v -> U.sendBroadcast(context, ACTION_TOGGLE_DASHBOARD));
+ dashboardButton.setVisibility(View.VISIBLE);
+ } else {
+ dashboardButton.setVisibility(View.GONE);
+ }
+ return dashboardEnabled;
+ }
+
+ @VisibleForTesting
public boolean drawNavbarButtons(Context context,
LinearLayout layout,
SharedPreferences pref,
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;
+import android.graphics.drawable.ColorDrawable;
+import android.graphics.drawable.Drawable;
import android.os.SystemClock;
import android.view.Gravity;
import android.view.LayoutInflater;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.rule.PowerMockRule;
import org.robolectric.RobolectricTestRunner;
+import org.robolectric.annotation.Config;
import org.robolectric.util.ReflectionHelpers;
import static com.farmerbb.taskbar.util.Constants.POSITION_BOTTOM_LEFT;
import static com.farmerbb.taskbar.util.Constants.PREF_BUTTON_BACK;
import static com.farmerbb.taskbar.util.Constants.PREF_BUTTON_HOME;
import static com.farmerbb.taskbar.util.Constants.PREF_BUTTON_RECENTS;
+import static com.farmerbb.taskbar.util.Constants.PREF_DASHBOARD;
import static com.farmerbb.taskbar.util.Constants.PREF_RECENTS_AMOUNT;
import static com.farmerbb.taskbar.util.Constants.PREF_RECENTS_AMOUNT_APP_START;
import static com.farmerbb.taskbar.util.Constants.PREF_RECENTS_AMOUNT_RUNNING_APPS_ONLY;
}
@Test
+ public void testDrawDashboardWithDefaultConfig() {
+ prefs.edit().remove(PREF_DASHBOARD).apply();
+ checkDashboardEnabled(false);
+ }
+
+ @Test
+ @Config(qualifiers = "sw540dp")
+ public void testDrawDashboardWithDefaultConfigForSw540dp() {
+ prefs.edit().remove(PREF_DASHBOARD).apply();
+ checkDashboardEnabled(false);
+ }
+
+ @Test
+ @Config(qualifiers = "sw720dp")
+ public void testDrawDashboardWithDefaultConfigForSw720dp() {
+ prefs.edit().remove(PREF_DASHBOARD).apply();
+ checkDashboardEnabled(true);
+ }
+
+ @Test
+ public void testDrawDashboardForDashboardButton() {
+ int accentColor = Color.RED;
+ int layoutId = uiController.getTaskbarLayoutId(POSITION_BOTTOM_LEFT);
+ LinearLayout layout = (LinearLayout) LayoutInflater.from(context).inflate(layoutId, null);
+ FrameLayout dashboardButton = layout.findViewById(R.id.dashboard_button);
+
+ prefs.edit().putBoolean(PREF_DASHBOARD, false).apply();
+ boolean dashboardEnabled =
+ uiController.drawDashboard(context, prefs, layout, dashboardButton, accentColor);
+ assertFalse(dashboardEnabled);
+ assertEquals(View.GONE, dashboardButton.getVisibility());
+
+ prefs.edit().putBoolean(PREF_DASHBOARD, true).apply();
+ dashboardEnabled =
+ uiController.drawDashboard(context, prefs, layout, dashboardButton, accentColor);
+ assertTrue(dashboardEnabled);
+ assertTrue(dashboardButton.hasOnClickListeners());
+ assertEquals(View.VISIBLE, dashboardButton.getVisibility());
+ Drawable drawable = layout.findViewById(R.id.square1).getBackground();
+ checkDrawableBackgroundColor(drawable, accentColor);
+ drawable = layout.findViewById(R.id.square2).getBackground();
+ checkDrawableBackgroundColor(drawable, accentColor);
+ drawable = layout.findViewById(R.id.square3).getBackground();
+ checkDrawableBackgroundColor(drawable, accentColor);
+ drawable = layout.findViewById(R.id.square4).getBackground();
+ checkDrawableBackgroundColor(drawable, accentColor);
+ drawable = layout.findViewById(R.id.square5).getBackground();
+ checkDrawableBackgroundColor(drawable, accentColor);
+ drawable = layout.findViewById(R.id.square6).getBackground();
+ checkDrawableBackgroundColor(drawable, accentColor);
+ }
+
+ @Test
public void testDrawNavbarButtons() {
int layoutId = uiController.getTaskbarLayoutId(POSITION_BOTTOM_LEFT);
LinearLayout layout = (LinearLayout) LayoutInflater.from(context).inflate(layoutId, null);
checkDrawSysTrayTimeVisibility(POSITION_BOTTOM_RIGHT, R.id.time_left);
}
+ private void checkDrawableBackgroundColor(Drawable drawable, int color) {
+ assertTrue(drawable instanceof ColorDrawable);
+ ColorDrawable colorDrawable = (ColorDrawable) drawable;
+ assertEquals(color, colorDrawable.getColor());
+ }
+
+ private void checkDashboardEnabled(boolean expectedDashboardEnabled) {
+ int layoutId = uiController.getTaskbarLayoutId(POSITION_BOTTOM_LEFT);
+ LinearLayout layout = (LinearLayout) LayoutInflater.from(context).inflate(layoutId, null);
+ FrameLayout dashboardButton = layout.findViewById(R.id.dashboard_button);
+ boolean dashboardEnabled =
+ uiController.drawDashboard(context, prefs, layout, dashboardButton, Color.RED);
+ assertEquals(expectedDashboardEnabled, dashboardEnabled);
+ }
+
private void checkDrawSysTrayTimeVisibility(String position, int timeId) {
LinearLayout sysTrayLayout = initializeSysTrayLayout(position);
assertEquals(View.VISIBLE, sysTrayLayout.findViewById(timeId).getVisibility());