Search in sources :

Example 11 with AppEntry

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

the class StartMenuService method drawStartMenu.

@SuppressLint("RtlHardcoded")
private void drawStartMenu() {
    IconCache.getInstance(this).clearCache();
    final SharedPreferences pref = U.getSharedPreferences(this);
    final boolean hasHardwareKeyboard = getResources().getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS;
    switch(pref.getString("show_search_bar", "keyboard")) {
        case "always":
            shouldShowSearchBox = true;
            break;
        case "keyboard":
            shouldShowSearchBox = hasHardwareKeyboard;
            break;
        case "never":
            shouldShowSearchBox = false;
            break;
    }
    // Initialize layout params
    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
    U.setCachedRotation(windowManager.getDefaultDisplay().getRotation());
    final WindowManager.LayoutParams params = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT, CompatUtils.getOverlayType(), shouldShowSearchBox ? 0 : WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM, PixelFormat.TRANSLUCENT);
    // Determine where to show the start menu on screen
    switch(U.getTaskbarPosition(this)) {
        case "bottom_left":
            layoutId = R.layout.start_menu_left;
            params.gravity = Gravity.BOTTOM | Gravity.LEFT;
            break;
        case "bottom_vertical_left":
            layoutId = R.layout.start_menu_vertical_left;
            params.gravity = Gravity.BOTTOM | Gravity.LEFT;
            break;
        case "bottom_right":
            layoutId = R.layout.start_menu_right;
            params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
            break;
        case "bottom_vertical_right":
            layoutId = R.layout.start_menu_vertical_right;
            params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
            break;
        case "top_left":
            layoutId = R.layout.start_menu_top_left;
            params.gravity = Gravity.TOP | Gravity.LEFT;
            break;
        case "top_vertical_left":
            layoutId = R.layout.start_menu_vertical_left;
            params.gravity = Gravity.TOP | Gravity.LEFT;
            break;
        case "top_right":
            layoutId = R.layout.start_menu_top_right;
            params.gravity = Gravity.TOP | Gravity.RIGHT;
            break;
        case "top_vertical_right":
            layoutId = R.layout.start_menu_vertical_right;
            params.gravity = Gravity.TOP | Gravity.RIGHT;
            break;
    }
    // Initialize views
    layout = (StartMenuLayout) LayoutInflater.from(U.wrapContext(this)).inflate(layoutId, null);
    startMenu = U.findViewById(layout, R.id.start_menu);
    if ((shouldShowSearchBox && !hasHardwareKeyboard) || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP_MR1)
        layout.viewHandlesBackButton();
    boolean scrollbar = pref.getBoolean("scrollbar", false);
    startMenu.setFastScrollEnabled(scrollbar);
    startMenu.setFastScrollAlwaysVisible(scrollbar);
    startMenu.setScrollBarStyle(scrollbar ? View.SCROLLBARS_OUTSIDE_INSET : View.SCROLLBARS_INSIDE_OVERLAY);
    if (pref.getBoolean("transparent_start_menu", false))
        startMenu.setBackgroundColor(0);
    if (U.visualFeedbackEnabled(this))
        startMenu.setRecyclerListener(view -> view.setBackgroundColor(0));
    searchView = U.findViewById(layout, R.id.search);
    int backgroundTint = U.getBackgroundTint(this);
    FrameLayout startMenuFrame = U.findViewById(layout, R.id.start_menu_frame);
    FrameLayout searchViewLayout = U.findViewById(layout, R.id.search_view_layout);
    startMenuFrame.setBackgroundColor(backgroundTint);
    searchViewLayout.setBackgroundColor(backgroundTint);
    if (shouldShowSearchBox) {
        if (!hasHardwareKeyboard)
            searchView.setIconifiedByDefault(true);
        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 = U.findViewById(view, R.id.entry);
                            layout.performClick();
                        } else {
                            if (U.shouldCollapse(StartMenuService.this, true))
                                LocalBroadcastManager.getInstance(StartMenuService.this).sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_TASKBAR"));
                            else
                                LocalBroadcastManager.getInstance(StartMenuService.this).sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));
                            Intent intent;
                            if (Patterns.WEB_URL.matcher(query).matches()) {
                                intent = new Intent(Intent.ACTION_VIEW);
                                intent.setData(Uri.parse(URLUtil.guessUrl(query)));
                                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            } else {
                                intent = new Intent(Intent.ACTION_WEB_SEARCH);
                                intent.putExtra(SearchManager.QUERY, query);
                                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            }
                            if (intent.resolveActivity(getPackageManager()) != null)
                                startActivity(intent);
                            else {
                                Uri uri = new Uri.Builder().scheme("https").authority("www.google.com").path("search").appendQueryParameter("q", query).build();
                                intent = new Intent(Intent.ACTION_VIEW);
                                intent.setData(uri);
                                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                try {
                                    startActivity(intent);
                                } catch (ActivityNotFoundException e) {
                                /* Gracefully fail */
                                }
                            }
                        }
                    }
                }
                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) {
                    new Handler().postDelayed(() -> {
                        EditText editText = U.findViewById(searchView, R.id.search_src_text);
                        if (editText != null) {
                            editText.requestFocus();
                            editText.setSelection(editText.getText().length());
                        }
                    }, 50);
                }
                return true;
            }
        });
        searchView.setOnQueryTextFocusChangeListener((view, b) -> {
            if (!hasHardwareKeyboard) {
                ViewGroup.LayoutParams params1 = startMenu.getLayoutParams();
                params1.height = getResources().getDimensionPixelSize(b && !isSecondScreenDisablingKeyboard() ? R.dimen.start_menu_height_half : R.dimen.start_menu_height);
                startMenu.setLayoutParams(params1);
            }
            if (!b) {
                if (hasHardwareKeyboard && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1)
                    LocalBroadcastManager.getInstance(StartMenuService.this).sendBroadcast(new Intent("com.farmerbb.taskbar.HIDE_START_MENU"));
                else {
                    InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
                    imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
                }
            }
        });
        searchView.setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
        LinearLayout powerButton = U.findViewById(layout, 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((parent, view, position, id) -> {
            hideStartMenu(true);
            AppEntry entry = (AppEntry) parent.getAdapter().getItem(position);
            U.launchApp(StartMenuService.this, entry.getPackageName(), entry.getComponentName(), entry.getUserId(StartMenuService.this), null, false, false);
        });
        if (pref.getBoolean("transparent_start_menu", false))
            layout.findViewById(R.id.search_view_child_layout).setBackgroundColor(0);
    } else
        searchViewLayout.setVisibility(View.GONE);
    textView = U.findViewById(layout, R.id.no_apps_found);
    LocalBroadcastManager lbm = LocalBroadcastManager.getInstance(this);
    lbm.unregisterReceiver(toggleReceiver);
    lbm.unregisterReceiver(hideReceiver);
    lbm.unregisterReceiver(hideReceiverNoReset);
    lbm.unregisterReceiver(showSpaceReceiver);
    lbm.unregisterReceiver(hideSpaceReceiver);
    lbm.unregisterReceiver(resetReceiver);
    lbm.registerReceiver(toggleReceiver, new IntentFilter("com.farmerbb.taskbar.TOGGLE_START_MENU"));
    lbm.registerReceiver(hideReceiver, new IntentFilter("com.farmerbb.taskbar.HIDE_START_MENU"));
    lbm.registerReceiver(hideReceiverNoReset, new IntentFilter("com.farmerbb.taskbar.HIDE_START_MENU_NO_RESET"));
    lbm.registerReceiver(showSpaceReceiver, new IntentFilter("com.farmerbb.taskbar.SHOW_START_MENU_SPACE"));
    lbm.registerReceiver(hideSpaceReceiver, new IntentFilter("com.farmerbb.taskbar.HIDE_START_MENU_SPACE"));
    lbm.registerReceiver(resetReceiver, new IntentFilter("com.farmerbb.taskbar.RESET_START_MENU"));
    handler = new Handler();
    refreshApps(true);
    windowManager.addView(layout, params);
}
Also used : Rect(android.graphics.Rect) LinearLayout(android.widget.LinearLayout) GridView(android.widget.GridView) PackageManager(android.content.pm.PackageManager) SearchView(android.support.v7.widget.SearchView) Uri(android.net.Uri) WindowManager(android.view.WindowManager) FrameLayout(android.widget.FrameLayout) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) MenuHelper(com.farmerbb.taskbar.util.MenuHelper) Drawable(android.graphics.drawable.Drawable) IconCache(com.farmerbb.taskbar.util.IconCache) IBinder(android.os.IBinder) Patterns(android.util.Patterns) TopApps(com.farmerbb.taskbar.util.TopApps) Handler(android.os.Handler) View(android.view.View) TargetApi(android.annotation.TargetApi) LauncherHelper(com.farmerbb.taskbar.util.LauncherHelper) InvisibleActivityAlt(com.farmerbb.taskbar.activity.InvisibleActivityAlt) Service(android.app.Service) IntentFilter(android.content.IntentFilter) U(com.farmerbb.taskbar.util.U) AppEntry(com.farmerbb.taskbar.util.AppEntry) CompatUtils(com.farmerbb.taskbar.util.CompatUtils) BroadcastReceiver(android.content.BroadcastReceiver) DisplayMetrics(android.util.DisplayMetrics) ViewGroup(android.view.ViewGroup) LauncherApps(android.content.pm.LauncherApps) List(java.util.List) TextView(android.widget.TextView) 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) ContextMenuActivity(com.farmerbb.taskbar.activity.ContextMenuActivity) Intent(android.content.Intent) InvisibleActivity(com.farmerbb.taskbar.activity.InvisibleActivity) PixelFormat(android.graphics.PixelFormat) 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) Settings(android.provider.Settings) Build(android.os.Build) ContextMenuActivityDark(com.farmerbb.taskbar.activity.dark.ContextMenuActivityDark) Collator(java.text.Collator) UserManager(android.os.UserManager) ApplicationType(com.farmerbb.taskbar.util.ApplicationType) URLUtil(android.webkit.URLUtil) R(com.farmerbb.taskbar.R) ComponentName(android.content.ComponentName) LayoutInflater(android.view.LayoutInflater) StartMenuAdapter(com.farmerbb.taskbar.adapter.StartMenuAdapter) FreeformHackHelper(com.farmerbb.taskbar.util.FreeformHackHelper) Gravity(android.view.Gravity) SharedPreferences(android.content.SharedPreferences) Configuration(android.content.res.Configuration) Comparator(java.util.Comparator) Collections(java.util.Collections) EditText(android.widget.EditText) InputMethodManager(android.view.inputmethod.InputMethodManager) Uri(android.net.Uri) WindowManager(android.view.WindowManager) ListAdapter(android.widget.ListAdapter) EditText(android.widget.EditText) IntentFilter(android.content.IntentFilter) SharedPreferences(android.content.SharedPreferences) ViewGroup(android.view.ViewGroup) Handler(android.os.Handler) Intent(android.content.Intent) GridView(android.widget.GridView) SearchView(android.support.v7.widget.SearchView) View(android.view.View) TextView(android.widget.TextView) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) SuppressLint(android.annotation.SuppressLint) SearchView(android.support.v7.widget.SearchView) AppEntry(com.farmerbb.taskbar.util.AppEntry) ActivityNotFoundException(android.content.ActivityNotFoundException) FrameLayout(android.widget.FrameLayout) LinearLayout(android.widget.LinearLayout) SuppressLint(android.annotation.SuppressLint)

Example 12 with AppEntry

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

the class TaskbarService method getAppEntriesUsingUsageStats.

@TargetApi(Build.VERSION_CODES.LOLLIPOP_MR1)
private List<AppEntry> getAppEntriesUsingUsageStats() {
    UsageStatsManager mUsageStatsManager = (UsageStatsManager) getSystemService(USAGE_STATS_SERVICE);
    List<UsageStats> usageStatsList = mUsageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_BEST, searchInterval, System.currentTimeMillis());
    List<AppEntry> entries = new ArrayList<>();
    for (UsageStats usageStats : usageStatsList) {
        AppEntry newEntry = new AppEntry(usageStats.getPackageName(), null, null, null, false);
        newEntry.setTotalTimeInForeground(usageStats.getTotalTimeInForeground());
        newEntry.setLastTimeUsed(usageStats.getLastTimeUsed());
        entries.add(newEntry);
    }
    return entries;
}
Also used : AppEntry(com.farmerbb.taskbar.util.AppEntry) ArrayList(java.util.ArrayList) UsageStatsManager(android.app.usage.UsageStatsManager) UsageStats(android.app.usage.UsageStats) TargetApi(android.annotation.TargetApi)

Example 13 with AppEntry

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

the class TaskbarService method getAppEntriesUsingActivityManager.

@SuppressWarnings("deprecation")
@TargetApi(Build.VERSION_CODES.M)
private List<AppEntry> getAppEntriesUsingActivityManager(int maxNum) {
    ActivityManager mActivityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    List<ActivityManager.RecentTaskInfo> usageStatsList = mActivityManager.getRecentTasks(maxNum, 0);
    List<AppEntry> entries = new ArrayList<>();
    for (int i = 0; i < usageStatsList.size(); i++) {
        ActivityManager.RecentTaskInfo recentTaskInfo = usageStatsList.get(i);
        if (recentTaskInfo.id != -1) {
            String packageName = recentTaskInfo.baseActivity.getPackageName();
            AppEntry newEntry = new AppEntry(packageName, null, null, null, false);
            try {
                Field field = ActivityManager.RecentTaskInfo.class.getField("firstActiveTime");
                newEntry.setLastTimeUsed(field.getLong(recentTaskInfo));
            } catch (Exception e) {
                newEntry.setLastTimeUsed(i);
            }
            entries.add(newEntry);
        }
    }
    return entries;
}
Also used : Field(java.lang.reflect.Field) AppEntry(com.farmerbb.taskbar.util.AppEntry) ArrayList(java.util.ArrayList) ActivityManager(android.app.ActivityManager) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point) ActivityNotFoundException(android.content.ActivityNotFoundException) TargetApi(android.annotation.TargetApi)

Example 14 with AppEntry

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

the class TaskbarService method getView.

private View getView(List<AppEntry> list, int position) {
    View convertView = View.inflate(this, R.layout.icon, null);
    final AppEntry entry = list.get(position);
    final SharedPreferences pref = U.getSharedPreferences(this);
    ImageView imageView = U.findViewById(convertView, R.id.icon);
    ImageView imageView2 = U.findViewById(convertView, R.id.shortcut_icon);
    imageView.setImageDrawable(entry.getIcon(this));
    imageView2.setBackgroundColor(pref.getInt("accent_color", getResources().getInteger(R.integer.translucent_white)));
    String taskbarPosition = U.getTaskbarPosition(this);
    if (pref.getBoolean("shortcut_icon", true)) {
        boolean shouldShowShortcutIcon;
        if (taskbarPosition.contains("vertical"))
            shouldShowShortcutIcon = position >= list.size() - numOfPinnedApps;
        else
            shouldShowShortcutIcon = position < numOfPinnedApps;
        if (shouldShowShortcutIcon)
            imageView2.setVisibility(View.VISIBLE);
    }
    if (taskbarPosition.equals("bottom_right") || taskbarPosition.equals("top_right")) {
        imageView.setRotationY(180);
        imageView2.setRotationY(180);
    }
    FrameLayout layout = U.findViewById(convertView, R.id.entry);
    layout.setOnClickListener(view -> U.launchApp(TaskbarService.this, entry.getPackageName(), entry.getComponentName(), entry.getUserId(TaskbarService.this), null, true, false));
    layout.setOnLongClickListener(view -> {
        int[] location = new int[2];
        view.getLocationOnScreen(location);
        openContextMenu(entry, location);
        return true;
    });
    layout.setOnGenericMotionListener((view, motionEvent) -> {
        int action = motionEvent.getAction();
        if (action == MotionEvent.ACTION_BUTTON_PRESS && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
            int[] location = new int[2];
            view.getLocationOnScreen(location);
            openContextMenu(entry, location);
        }
        if (action == MotionEvent.ACTION_SCROLL && pref.getBoolean("visual_feedback", true))
            view.setBackgroundColor(0);
        return false;
    });
    if (pref.getBoolean("visual_feedback", true)) {
        layout.setOnHoverListener((v, event) -> {
            if (event.getAction() == MotionEvent.ACTION_HOVER_ENTER) {
                int accentColor = U.getAccentColor(TaskbarService.this);
                accentColor = ColorUtils.setAlphaComponent(accentColor, Color.alpha(accentColor) / 2);
                v.setBackgroundColor(accentColor);
            }
            if (event.getAction() == MotionEvent.ACTION_HOVER_EXIT)
                v.setBackgroundColor(0);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
                v.setPointerIcon(PointerIcon.getSystemIcon(TaskbarService.this, PointerIcon.TYPE_DEFAULT));
            return false;
        });
        layout.setOnTouchListener((v, event) -> {
            v.setAlpha(event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE ? 0.5f : 1);
            return false;
        });
    }
    return convertView;
}
Also used : AppEntry(com.farmerbb.taskbar.util.AppEntry) SharedPreferences(android.content.SharedPreferences) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) SuppressLint(android.annotation.SuppressLint) Point(android.graphics.Point)

Example 15 with AppEntry

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

the class DesktopIconAppListAdapter method getView.

@Override
public View getView(int position, View convertView, final ViewGroup parent) {
    // Check if an existing view is being reused, otherwise inflate the view
    if (convertView == null)
        convertView = LayoutInflater.from(getContext()).inflate(R.layout.tb_desktop_icon_row, parent, false);
    final AppEntry entry = getItem(position);
    assert entry != null;
    TextView textView = convertView.findViewById(R.id.name);
    textView.setText(entry.getLabel());
    ImageView imageView = convertView.findViewById(R.id.icon);
    imageView.setImageDrawable(entry.getIcon(getContext()));
    LinearLayout layout = convertView.findViewById(R.id.entry);
    layout.setOnClickListener(view -> {
        AbstractSelectAppActivity activity = (AbstractSelectAppActivity) getContext();
        activity.selectApp(entry);
    });
    return convertView;
}
Also used : AppEntry(com.farmerbb.taskbar.util.AppEntry) TextView(android.widget.TextView) ImageView(android.widget.ImageView) AbstractSelectAppActivity(com.farmerbb.taskbar.activity.AbstractSelectAppActivity) LinearLayout(android.widget.LinearLayout)

Aggregations

AppEntry (com.farmerbb.taskbar.util.AppEntry)25 SuppressLint (android.annotation.SuppressLint)13 ArrayList (java.util.ArrayList)12 SharedPreferences (android.content.SharedPreferences)11 TargetApi (android.annotation.TargetApi)10 Point (android.graphics.Point)10 UserManager (android.os.UserManager)10 LauncherActivityInfo (android.content.pm.LauncherActivityInfo)9 Intent (android.content.Intent)8 LauncherApps (android.content.pm.LauncherApps)8 View (android.view.View)7 ComponentName (android.content.ComponentName)6 PackageManager (android.content.pm.PackageManager)6 ImageView (android.widget.ImageView)6 ActivityNotFoundException (android.content.ActivityNotFoundException)5 Drawable (android.graphics.drawable.Drawable)5 Handler (android.os.Handler)5 TextView (android.widget.TextView)5 PinnedBlockedApps (com.farmerbb.taskbar.util.PinnedBlockedApps)5 Context (android.content.Context)4