Search in sources :

Example 1 with TaskbarPosition

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

the class StartMenuController method drawStartMenu.

private void drawStartMenu(UIHost host) {
    IconCache.getInstance(context).clearCache();
    final SharedPreferences pref = U.getSharedPreferences(context);
    boolean shouldShowSearchBox = shouldShowSearchBox(pref, hasHardwareKeyboard);
    // Initialize layout params
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    TaskbarPosition.setCachedRotation(windowManager.getDefaultDisplay().getRotation());
    final ViewParams params = new ViewParams(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, -1, shouldShowSearchBox ? 0 : WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, getBottomMargin(context));
    // Determine where to show the start menu on screen
    String taskbarPosition = TaskbarPosition.getTaskbarPosition(context);
    int layoutId = getStartMenuLayoutId(taskbarPosition);
    params.gravity = getStartMenuGravity(taskbarPosition);
    // Initialize views
    layout = (StartMenuLayout) LayoutInflater.from(U.wrapContext(context)).inflate(layoutId, null);
    layout.setAlpha(0);
    startMenu = layout.findViewById(R.id.start_menu);
    if ((shouldShowSearchBox && !hasHardwareKeyboard) || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1)
        layout.viewHandlesBackButton();
    boolean scrollbar = pref.getBoolean(PREF_SCROLLBAR, false);
    startMenu.setFastScrollEnabled(scrollbar);
    startMenu.setFastScrollAlwaysVisible(scrollbar);
    startMenu.setScrollBarStyle(scrollbar ? View.SCROLLBARS_OUTSIDE_INSET : View.SCROLLBARS_INSIDE_OVERLAY);
    if (pref.getBoolean(PREF_TRANSPARENT_START_MENU, false))
        startMenu.setBackgroundColor(0);
    if (pref.getBoolean(PREF_VISUAL_FEEDBACK, true))
        startMenu.setRecyclerListener(view -> view.setBackgroundColor(0));
    int columns = context.getResources().getInteger(R.integer.tb_start_menu_columns);
    boolean isGrid = pref.getString(PREF_START_MENU_LAYOUT, "grid").equals("grid");
    if (isGrid) {
        ViewGroup.LayoutParams startMenuParams = startMenu.getLayoutParams();
        startMenuParams.width = (int) (startMenuParams.width * (columns / 3f));
        startMenu.setLayoutParams(startMenuParams);
    }
    searchView = layout.findViewById(R.id.search);
    searchViewClicked = false;
    int backgroundTint = U.getBackgroundTint(context);
    FrameLayout startMenuFrame = layout.findViewById(R.id.start_menu_frame);
    FrameLayout searchViewLayout = layout.findViewById(R.id.search_view_layout);
    startMenuFrame.setBackgroundColor(backgroundTint);
    searchViewLayout.setBackgroundColor(backgroundTint);
    if (shouldShowSearchBox) {
        if (!hasHardwareKeyboard)
            searchView.setIconifiedByDefault(true);
        searchView.setOnTouchListener((v, event) -> {
            searchViewClicked = true;
            return false;
        });
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

            @Override
            public boolean onQueryTextSubmit(String query) {
                if (!hasSubmittedQuery) {
                    ListAdapter adapter = startMenu.getAdapter();
                    if (adapter != null) {
                        hasSubmittedQuery = true;
                        if (adapter.getCount() > 0) {
                            View view = adapter.getView(0, null, startMenu);
                            LinearLayout layout = view.findViewById(R.id.entry);
                            layout.performClick();
                        } else {
                            if (U.shouldCollapse(context, true)) {
                                U.sendBroadcast(context, ACTION_HIDE_TASKBAR);
                            } else {
                                hideStartMenu(true);
                            }
                            Intent intent = generateQueryWebSearchIntent(query);
                            if (intent.resolveActivity(context.getPackageManager()) != null) {
                                context.startActivity(intent);
                            } else {
                                intent = generateQueryGoogleIntent(query);
                                try {
                                    context.startActivity(intent);
                                } catch (ActivityNotFoundException ignored) {
                                }
                            }
                        }
                    }
                }
                return true;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                searchView.setIconified(false);
                View closeButton = searchView.findViewById(R.id.search_close_btn);
                if (closeButton != null)
                    closeButton.setVisibility(View.GONE);
                refreshApps(newText, false);
                if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1) {
                    U.newHandler().postDelayed(() -> {
                        EditText editText = searchView.findViewById(R.id.search_src_text);
                        if (editText != null) {
                            editText.requestFocus();
                            editText.setSelection(editText.getText().length());
                        }
                    }, 50);
                }
                return true;
            }
        });
        searchView.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
        LinearLayout powerButton = layout.findViewById(R.id.power_button);
        powerButton.setOnClickListener(view -> {
            int[] location = new int[2];
            view.getLocationOnScreen(location);
            openContextMenu(location);
        });
        powerButton.setOnGenericMotionListener((view, motionEvent) -> {
            if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
                int[] location = new int[2];
                view.getLocationOnScreen(location);
                openContextMenu(location);
            }
            return false;
        });
        searchViewLayout.setOnClickListener(view -> searchView.setIconified(false));
        startMenu.setOnItemClickListener((viewParent, view, position, id) -> {
            hideStartMenu(true);
            AppEntry entry = (AppEntry) viewParent.getAdapter().getItem(position);
            U.launchApp(context, entry, null, false, false, view);
        });
        View childLayout = layout.findViewById(R.id.search_view_child_layout);
        if (pref.getBoolean(PREF_TRANSPARENT_START_MENU, false))
            childLayout.setBackgroundColor(0);
        if (isGrid) {
            ViewGroup.LayoutParams childLayoutParams = childLayout.getLayoutParams();
            childLayoutParams.width = (int) (childLayoutParams.width * (columns / 3f));
            childLayout.setLayoutParams(childLayoutParams);
        }
    } else
        searchViewLayout.setVisibility(View.GONE);
    applyMarginFix(host, layout, params);
    textView = layout.findViewById(R.id.no_apps_found);
    U.registerReceiver(context, toggleReceiver, ACTION_TOGGLE_START_MENU);
    U.registerReceiver(context, hideReceiver, ACTION_HIDE_START_MENU);
    U.registerReceiver(context, hideReceiverNoReset, ACTION_HIDE_START_MENU_NO_RESET);
    U.registerReceiver(context, showSpaceReceiver, ACTION_SHOW_START_MENU_SPACE);
    U.registerReceiver(context, hideSpaceReceiver, ACTION_HIDE_START_MENU_SPACE);
    U.registerReceiver(context, resetReceiver, ACTION_RESET_START_MENU);
    handler = U.newHandler();
    refreshApps(true);
    host.addView(layout, params);
}
Also used : LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) GridView(android.widget.GridView) PackageManager(android.content.pm.PackageManager) TaskbarPosition(com.farmerbb.taskbar.util.TaskbarPosition) Uri(android.net.Uri) WindowManager(android.view.WindowManager) FrameLayout(android.widget.FrameLayout) Drawable(android.graphics.drawable.Drawable) IconCache(com.farmerbb.taskbar.util.IconCache) Patterns(android.util.Patterns) TopApps(com.farmerbb.taskbar.util.TopApps) Handler(android.os.Handler) View(android.view.View) TargetApi(android.annotation.TargetApi) InvisibleActivityAlt(com.farmerbb.taskbar.activity.InvisibleActivityAlt) U(com.farmerbb.taskbar.util.U) AppEntry(com.farmerbb.taskbar.util.AppEntry) SearchView(androidx.appcompat.widget.SearchView) BroadcastReceiver(android.content.BroadcastReceiver) ViewGroup(android.view.ViewGroup) LauncherHelper(com.farmerbb.taskbar.helper.LauncherHelper) LauncherApps(android.content.pm.LauncherApps) FreeformHackHelper(com.farmerbb.taskbar.helper.FreeformHackHelper) List(java.util.List) TextView(android.widget.TextView) MenuHelper(com.farmerbb.taskbar.helper.MenuHelper) ListAdapter(android.widget.ListAdapter) ActivityNotFoundException(android.content.ActivityNotFoundException) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) SearchManager(android.app.SearchManager) EditorInfo(android.view.inputmethod.EditorInfo) Context(android.content.Context) Intent(android.content.Intent) InvisibleActivity(com.farmerbb.taskbar.activity.InvisibleActivity) InputMethodManager(android.view.inputmethod.InputMethodManager) ArrayList(java.util.ArrayList) Blacklist(com.farmerbb.taskbar.util.Blacklist) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) StartMenuLayout(com.farmerbb.taskbar.widget.StartMenuLayout) UserHandle(android.os.UserHandle) Build(android.os.Build) Collator(java.text.Collator) UserManager(android.os.UserManager) URLUtil(android.webkit.URLUtil) R(com.farmerbb.taskbar.R) ComponentName(android.content.ComponentName) LayoutInflater(android.view.LayoutInflater) StartMenuAdapter(com.farmerbb.taskbar.adapter.StartMenuAdapter) Gravity(android.view.Gravity) SharedPreferences(android.content.SharedPreferences) Configuration(android.content.res.Configuration) Comparator(java.util.Comparator) VisibleForTesting(androidx.annotation.VisibleForTesting) Collections(java.util.Collections) EditText(android.widget.EditText) Constants(com.farmerbb.taskbar.util.Constants) EditText(android.widget.EditText) SharedPreferences(android.content.SharedPreferences) ViewGroup(android.view.ViewGroup) Intent(android.content.Intent) GridView(android.widget.GridView) View(android.view.View) SearchView(androidx.appcompat.widget.SearchView) TextView(android.widget.TextView) SuppressLint(android.annotation.SuppressLint) WindowManager(android.view.WindowManager) SearchView(androidx.appcompat.widget.SearchView) AppEntry(com.farmerbb.taskbar.util.AppEntry) ActivityNotFoundException(android.content.ActivityNotFoundException) FrameLayout(android.widget.FrameLayout) ListAdapter(android.widget.ListAdapter) LinearLayout(android.widget.LinearLayout)

Example 2 with TaskbarPosition

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

the class TaskbarController method drawTaskbar.

private void drawTaskbar(UIHost host) {
    IconCache.getInstance(context).clearCache();
    // Initialize layout params
    WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    TaskbarPosition.setCachedRotation(windowManager.getDefaultDisplay().getRotation());
    final ViewParams params = new ViewParams(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, -1, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, getBottomMargin(context));
    // Determine where to show the taskbar on screen
    String taskbarPosition = TaskbarPosition.getTaskbarPosition(context);
    params.gravity = getTaskbarGravity(taskbarPosition);
    int layoutId = getTaskbarLayoutId(taskbarPosition);
    positionIsVertical = TaskbarPosition.isVertical(taskbarPosition);
    // Initialize views
    SharedPreferences pref = U.getSharedPreferences(context);
    boolean altButtonConfig = pref.getBoolean(PREF_ALT_BUTTON_CONFIG, false);
    layout = (LinearLayout) LayoutInflater.from(U.wrapContext(context)).inflate(layoutId, null);
    taskbar = layout.findViewById(R.id.taskbar);
    scrollView = layout.findViewById(R.id.taskbar_scrollview);
    int backgroundTint = U.getBackgroundTint(context);
    int accentColor = U.getAccentColor(context);
    if (altButtonConfig) {
        space = layout.findViewById(R.id.space_alt);
        layout.findViewById(R.id.space).setVisibility(View.GONE);
    } else {
        space = layout.findViewById(R.id.space);
        layout.findViewById(R.id.space_alt).setVisibility(View.GONE);
    }
    space.setOnClickListener(v -> toggleTaskbar(true));
    startButton = layout.findViewById(R.id.start_button);
    drawStartButton(context, startButton, pref);
    refreshInterval = (int) (Float.parseFloat(pref.getString(PREF_REFRESH_FREQUENCY, "1")) * 1000);
    if (refreshInterval == 0)
        refreshInterval = 100;
    sortOrder = pref.getString(PREF_SORT_ORDER, "false");
    runningAppsOnly = PREF_RECENTS_AMOUNT_RUNNING_APPS_ONLY.equals(pref.getString(PREF_RECENTS_AMOUNT, PREF_RECENTS_AMOUNT_PAST_DAY));
    searchInterval = getSearchInterval(pref);
    U.sendBroadcast(context, ACTION_HIDE_START_MENU);
    U.sendBroadcast(context, ACTION_UPDATE_HOME_SCREEN_MARGINS);
    if (altButtonConfig) {
        button = layout.findViewById(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);
        layout.findViewById(R.id.hide_taskbar_button_alt).setVisibility(View.GONE);
    }
    try {
        button.setTypeface(Typeface.createFromFile("/system/fonts/Roboto-Regular.ttf"));
    } catch (RuntimeException ignored) {
    }
    updateButton(false);
    button.setOnClickListener(v -> toggleTaskbar(true));
    LinearLayout buttonLayout = layout.findViewById(altButtonConfig ? R.id.hide_taskbar_button_layout_alt : R.id.hide_taskbar_button_layout);
    if (buttonLayout != null)
        buttonLayout.setOnClickListener(v -> toggleTaskbar(true));
    LinearLayout buttonLayoutToHide = layout.findViewById(altButtonConfig ? R.id.hide_taskbar_button_layout : R.id.hide_taskbar_button_layout_alt);
    if (buttonLayoutToHide != null)
        buttonLayoutToHide.setVisibility(View.GONE);
    dashboardButton = layout.findViewById(R.id.dashboard_button);
    navbarButtons = layout.findViewById(R.id.navbar_buttons);
    dashboardEnabled = drawDashboardButton(context, layout, dashboardButton, accentColor);
    navbarButtonsEnabled = drawNavbarButtons(context, layout, pref, accentColor);
    if (!navbarButtonsEnabled)
        navbarButtons.setVisibility(View.GONE);
    sysTrayEnabled = U.isSystemTrayEnabled(context);
    if (sysTrayEnabled) {
        drawSysTray(context, layoutId, layout);
    }
    layout.setBackgroundColor(backgroundTint);
    layout.findViewById(R.id.divider).setBackgroundColor(pref.getBoolean(PREF_CENTERED_ICONS, false) ? 0 : accentColor);
    button.setTextColor(accentColor);
    applyMarginFix(host, layout, params);
    if (isFirstStart && FreeformHackHelper.getInstance().isInFreeformWorkspace())
        showTaskbar(false);
    else if (!pref.getBoolean(PREF_COLLAPSED, false) && pref.getBoolean(PREF_TASKBAR_ACTIVE, false))
        toggleTaskbar(false);
    if (pref.getBoolean(PREF_AUTO_HIDE_NAVBAR, false))
        U.showHideNavigationBar(context, false);
    if (FreeformHackHelper.getInstance().isTouchAbsorberActive()) {
        U.sendBroadcast(context, ACTION_FINISH_FREEFORM_ACTIVITY);
        U.newHandler().postDelayed(() -> U.startTouchAbsorberActivity(context), 500);
    }
    U.registerReceiver(context, showReceiver, ACTION_SHOW_TASKBAR);
    U.registerReceiver(context, hideReceiver, ACTION_HIDE_TASKBAR);
    U.registerReceiver(context, tempShowReceiver, ACTION_TEMP_SHOW_TASKBAR);
    U.registerReceiver(context, tempHideReceiver, ACTION_TEMP_HIDE_TASKBAR);
    U.registerReceiver(context, startMenuAppearReceiver, ACTION_START_MENU_APPEARING);
    U.registerReceiver(context, startMenuDisappearReceiver, ACTION_START_MENU_DISAPPEARING);
    if (sysTrayEnabled) {
        TelephonyManager manager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        manager.listen(listener, PhoneStateListener.LISTEN_SIGNAL_STRENGTHS);
        U.registerReceiver(context, notificationCountReceiver, ACTION_NOTIFICATION_COUNT_CHANGED);
        U.sendBroadcast(context, ACTION_REQUEST_NOTIFICATION_COUNT);
    }
    matchParent = false;
    updateParamsRunnable = () -> {
        ViewParams newParams;
        if (TaskbarPosition.isVertical(context)) {
            newParams = matchParent ? params.updateHeight(WindowManager.LayoutParams.MATCH_PARENT) : params.updateHeight(WindowManager.LayoutParams.WRAP_CONTENT);
        } else {
            newParams = matchParent ? params.updateWidth(WindowManager.LayoutParams.MATCH_PARENT) : params.updateWidth(WindowManager.LayoutParams.WRAP_CONTENT);
        }
        try {
            host.updateViewLayout(layout, newParams);
        } catch (IllegalArgumentException ignored) {
        }
    };
    startRefreshingRecents();
    host.addView(layout, params);
    isFirstStart = false;
}
Also used : MainActivity(com.farmerbb.taskbar.activity.MainActivity) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) UsageEvents(android.app.usage.UsageEvents) PackageManager(android.content.pm.PackageManager) WifiInfo(android.net.wifi.WifiInfo) Date(java.util.Date) TaskbarPosition(com.farmerbb.taskbar.util.TaskbarPosition) WindowManager(android.view.WindowManager) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) Drawable(android.graphics.drawable.Drawable) IconCache(com.farmerbb.taskbar.util.IconCache) Process(android.os.Process) DisplayInfo(com.farmerbb.taskbar.util.DisplayInfo) PowerManager(android.os.PowerManager) UsageStats(android.app.usage.UsageStats) PointerIcon(android.view.PointerIcon) PinnedBlockedApps(com.farmerbb.taskbar.util.PinnedBlockedApps) HomeActivityDelegate(com.farmerbb.taskbar.activity.HomeActivityDelegate) Handler(android.os.Handler) PhoneStateListener(android.telephony.PhoneStateListener) Map(java.util.Map) Display(android.view.Display) View(android.view.View) Button(android.widget.Button) ContextCompat(androidx.core.content.ContextCompat) TargetApi(android.annotation.TargetApi) ConnectivityManager(android.net.ConnectivityManager) IntentFilter(android.content.IntentFilter) U(com.farmerbb.taskbar.util.U) NetworkInfo(android.net.NetworkInfo) AppEntry(com.farmerbb.taskbar.util.AppEntry) BroadcastReceiver(android.content.BroadcastReceiver) ViewGroup(android.view.ViewGroup) LauncherHelper(com.farmerbb.taskbar.helper.LauncherHelper) LauncherApps(android.content.pm.LauncherApps) AccessibilityService(android.accessibilityservice.AccessibilityService) DateFormat(android.text.format.DateFormat) FreeformHackHelper(com.farmerbb.taskbar.helper.FreeformHackHelper) List(java.util.List) TextView(android.widget.TextView) MenuHelper(com.farmerbb.taskbar.helper.MenuHelper) ActivityNotFoundException(android.content.ActivityNotFoundException) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) Typeface(android.graphics.Typeface) ActivityManager(android.app.ActivityManager) Context(android.content.Context) BatteryManager(android.os.BatteryManager) Space(android.widget.Space) Intent(android.content.Intent) SystemClock(android.os.SystemClock) HashMap(java.util.HashMap) InputMethodManager(android.view.inputmethod.InputMethodManager) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) UserHandle(android.os.UserHandle) TelephonyManager(android.telephony.TelephonyManager) RecognizerIntent(android.speech.RecognizerIntent) Settings(android.provider.Settings) Build(android.os.Build) UserManager(android.os.UserManager) BuildConfig(com.farmerbb.taskbar.BuildConfig) AlarmManager(android.app.AlarmManager) BluetoothAdapter(android.bluetooth.BluetoothAdapter) R(com.farmerbb.taskbar.R) LayoutInflater(android.view.LayoutInflater) SecondaryHomeActivity(com.farmerbb.taskbar.activity.SecondaryHomeActivity) Point(android.graphics.Point) Field(java.lang.reflect.Field) UsageStatsManager(android.app.usage.UsageStatsManager) ResolveInfo(android.content.pm.ResolveInfo) Color(android.graphics.Color) WifiManager(android.net.wifi.WifiManager) Gravity(android.view.Gravity) SignalStrength(android.telephony.SignalStrength) SharedPreferences(android.content.SharedPreferences) InvisibleActivityFreeform(com.farmerbb.taskbar.activity.InvisibleActivityFreeform) ColorUtils(androidx.core.graphics.ColorUtils) VisibleForTesting(androidx.annotation.VisibleForTesting) Collections(java.util.Collections) Resources(android.content.res.Resources) HomeActivity(com.farmerbb.taskbar.activity.HomeActivity) Constants(com.farmerbb.taskbar.util.Constants) SharedPreferences(android.content.SharedPreferences) TelephonyManager(android.telephony.TelephonyManager) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) LinearLayout(android.widget.LinearLayout) WindowManager(android.view.WindowManager)

Aggregations

SuppressLint (android.annotation.SuppressLint)2 TargetApi (android.annotation.TargetApi)2 ActivityNotFoundException (android.content.ActivityNotFoundException)2 BroadcastReceiver (android.content.BroadcastReceiver)2 Context (android.content.Context)2 Intent (android.content.Intent)2 SharedPreferences (android.content.SharedPreferences)2 LauncherActivityInfo (android.content.pm.LauncherActivityInfo)2 LauncherApps (android.content.pm.LauncherApps)2 PackageManager (android.content.pm.PackageManager)2 Drawable (android.graphics.drawable.Drawable)2 Build (android.os.Build)2 Bundle (android.os.Bundle)2 Handler (android.os.Handler)2 UserHandle (android.os.UserHandle)2 UserManager (android.os.UserManager)2 Gravity (android.view.Gravity)2 LayoutInflater (android.view.LayoutInflater)2 MotionEvent (android.view.MotionEvent)2 View (android.view.View)2