Search in sources :

Example 6 with DisplayInfo

use of com.farmerbb.taskbar.util.DisplayInfo in project Taskbar by farmerbb.

the class DashboardActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    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);
    DisplayInfo display = U.getDisplayInfo(this);
    setContentView(R.layout.tb_incognito);
    LinearLayout layout = findViewById(R.id.incognitoLayout);
    layout.setLayoutParams(new FrameLayout.LayoutParams(display.width, display.height));
    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();
}
Also used : DisplayInfo(com.farmerbb.taskbar.util.DisplayInfo) FrameLayout(android.widget.FrameLayout) LinearLayout(android.widget.LinearLayout)

Example 7 with DisplayInfo

use of com.farmerbb.taskbar.util.DisplayInfo in project Taskbar by farmerbb.

the class TaskbarController method calculateScrollViewParams.

@VisibleForTesting
void calculateScrollViewParams(Context context, SharedPreferences pref, ViewGroup.LayoutParams params, boolean fullLength, int numOfEntries) {
    DisplayInfo display = U.getDisplayInfo(context, true);
    int recentsSize = context.getResources().getDimensionPixelSize(R.dimen.tb_icon_size) * numOfEntries;
    float maxRecentsSize = fullLength ? Float.MAX_VALUE : recentsSize;
    int maxScreenSize;
    float baseStart = U.getBaseTaskbarSizeStart(context);
    float baseEnd = U.getBaseTaskbarSizeEnd(context, sysTrayIconStates);
    int baseTotal = Math.round(baseStart + baseEnd);
    int diff = Math.round(Math.max(baseStart, baseEnd) - Math.min(baseStart, baseEnd));
    boolean startIsBigger = Math.max(baseStart, baseEnd) == baseStart;
    if (TaskbarPosition.isVertical(context)) {
        maxScreenSize = Math.max(0, display.height - U.getStatusBarHeight(context) - baseTotal);
        params.height = (int) Math.min(maxRecentsSize, maxScreenSize) + context.getResources().getDimensionPixelSize(R.dimen.tb_divider_size);
        if (fullLength) {
            try {
                Space whitespaceStart = layout.findViewById(R.id.whitespace_start);
                Space whitespaceEnd = layout.findViewById(R.id.whitespace_end);
                int height = maxScreenSize - recentsSize;
                if (pref.getBoolean(PREF_CENTERED_ICONS, false)) {
                    int startHeight = (height / 2) + (diff / (startIsBigger ? -2 : 2));
                    int endHeight = (height / 2) + (diff / (startIsBigger ? 2 : -2));
                    if (startHeight < 0) {
                        startHeight = 0;
                        endHeight = height;
                    }
                    if (endHeight < 0) {
                        startHeight = height;
                        endHeight = 0;
                    }
                    ViewGroup.LayoutParams startParams = whitespaceStart.getLayoutParams();
                    startParams.height = startHeight;
                    whitespaceStart.setLayoutParams(startParams);
                    ViewGroup.LayoutParams endParams = whitespaceEnd.getLayoutParams();
                    endParams.height = endHeight;
                    whitespaceEnd.setLayoutParams(endParams);
                } else {
                    ViewGroup.LayoutParams endParams = whitespaceEnd.getLayoutParams();
                    endParams.height = height;
                    whitespaceEnd.setLayoutParams(endParams);
                }
            } catch (NullPointerException ignored) {
            }
        }
    } else {
        maxScreenSize = Math.max(0, display.width - baseTotal);
        params.width = (int) Math.min(maxRecentsSize, maxScreenSize) + context.getResources().getDimensionPixelSize(R.dimen.tb_divider_size);
        if (fullLength) {
            try {
                Space whitespaceStart = layout.findViewById(R.id.whitespace_start);
                Space whitespaceEnd = layout.findViewById(R.id.whitespace_end);
                int width = maxScreenSize - recentsSize;
                if (pref.getBoolean(PREF_CENTERED_ICONS, false)) {
                    int startWidth = (width / 2) + (diff / (startIsBigger ? -2 : 2));
                    int endWidth = (width / 2) + (diff / (startIsBigger ? 2 : -2));
                    if (startWidth < 0) {
                        startWidth = 0;
                        endWidth = width;
                    }
                    if (endWidth < 0) {
                        startWidth = width;
                        endWidth = 0;
                    }
                    ViewGroup.LayoutParams startParams = whitespaceStart.getLayoutParams();
                    startParams.width = startWidth;
                    whitespaceStart.setLayoutParams(startParams);
                    ViewGroup.LayoutParams endParams = whitespaceEnd.getLayoutParams();
                    endParams.width = endWidth;
                    whitespaceEnd.setLayoutParams(endParams);
                } else {
                    ViewGroup.LayoutParams endParams = whitespaceEnd.getLayoutParams();
                    endParams.width = width;
                    whitespaceEnd.setLayoutParams(endParams);
                }
            } catch (NullPointerException ignored) {
            }
        }
    }
    boolean realMatchParent = maxRecentsSize >= maxScreenSize && pref.getBoolean(PREF_COLLAPSED, false) && !(TaskbarPosition.isVertical(context) && U.isChromeOs(context));
    if (realMatchParent != matchParent) {
        matchParent = realMatchParent;
        U.newHandler().post(updateParamsRunnable);
    }
}
Also used : Space(android.widget.Space) DisplayInfo(com.farmerbb.taskbar.util.DisplayInfo) ViewGroup(android.view.ViewGroup) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) VisibleForTesting(androidx.annotation.VisibleForTesting)

Aggregations

DisplayInfo (com.farmerbb.taskbar.util.DisplayInfo)7 SuppressLint (android.annotation.SuppressLint)5 SharedPreferences (android.content.SharedPreferences)4 FrameLayout (android.widget.FrameLayout)4 Bundle (android.os.Bundle)3 LinearLayout (android.widget.LinearLayout)3 AlertDialog (android.app.AlertDialog)2 View (android.view.View)2 ViewGroup (android.view.ViewGroup)2 WindowManager (android.view.WindowManager)2 TargetApi (android.annotation.TargetApi)1 WallpaperManager (android.app.WallpaperManager)1 ActivityNotFoundException (android.content.ActivityNotFoundException)1 BroadcastReceiver (android.content.BroadcastReceiver)1 ClipData (android.content.ClipData)1 ComponentName (android.content.ComponentName)1 Context (android.content.Context)1 Intent (android.content.Intent)1 LauncherApps (android.content.pm.LauncherApps)1 ColorStateList (android.content.res.ColorStateList)1