Search in sources :

Example 1 with ListPopup

use of rocks.tbog.tblauncher.ui.ListPopup in project TBLauncher by TBog.

the class LiveWallpaper method onLongClick.

private void onLongClick(View view) {
    if (!view.isAttachedToWindow()) {
        return;
    }
    view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
    Context ctx = view.getContext();
    ListPopup menu = TBApplication.widgetManager(ctx).getConfigPopup(mTBLauncherActivity);
    TBApplication.getApplication(getContext()).registerPopup(menu);
    int x = (int) (mLastTouchPos.x + .5f);
    int y = (int) (mLastTouchPos.y + .5f);
    menu.showAtLocation(view, Gravity.START | Gravity.TOP, x, y);
}
Also used : Context(android.content.Context) ListPopup(rocks.tbog.tblauncher.ui.ListPopup) Point(android.graphics.Point)

Example 2 with ListPopup

use of rocks.tbog.tblauncher.ui.ListPopup in project TBLauncher by TBog.

the class TBLauncherActivity method dispatchTouchEvent.

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    boolean shouldDismissPopup = false;
    ListPopup listPopup = TBApplication.getApplication(this).getPopup();
    if (listPopup != null) {
        int action = event.getActionMasked();
        if (action == MotionEvent.ACTION_DOWN) {
            // this check is not needed
            // we'll not receive the event if it happened inside the popup
            int x = (int) (event.getRawX() + .5f);
            int y = (int) (event.getRawY() + .5f);
            if (!listPopup.isInsideViewBounds(x, y))
                shouldDismissPopup = true;
        }
    }
    if (shouldDismissPopup && TBApplication.getApplication(this).dismissPopup())
        return true;
    return super.dispatchTouchEvent(event);
}
Also used : ListPopup(rocks.tbog.tblauncher.ui.ListPopup)

Example 3 with ListPopup

use of rocks.tbog.tblauncher.ui.ListPopup in project TBLauncher by TBog.

the class Behaviour method onCreateActivity.

public void onCreateActivity(TBLauncherActivity tbLauncherActivity) {
    mTBLauncherActivity = tbLauncherActivity;
    mPref = PreferenceManager.getDefaultSharedPreferences(mTBLauncherActivity);
    Window window = mTBLauncherActivity.getWindow();
    mDecorView = window.getDecorView();
    KeyboardTriggerBehaviour keyboardListener = new KeyboardTriggerBehaviour(mTBLauncherActivity);
    keyboardListener.observe(mTBLauncherActivity, status -> {
        LauncherState state = TBApplication.state();
        if (status == KeyboardTriggerBehaviour.Status.CLOSED) {
            boolean keyboardClosedByUser = true;
            if (state.getSearchBarVisibility() == LauncherState.AnimatedVisibility.ANIM_TO_VISIBLE) {
                Log.i(TAG, "keyboard closed - app start");
                // don't call onKeyboardClosed() when we start the app
                keyboardClosedByUser = false;
            } else if (mRecycleScrollListener.isClosedOnScroll()) {
                Log.i(TAG, "keyboard closed - scrolling results");
                // keyboard closed because the result list was scrolled
                keyboardClosedByUser = false;
            } else if (isFragmentDialogVisible()) {
                Log.i(TAG, "keyboard closed - fragment dialog");
                // don't send keyboard close event while we have a dialog open
                keyboardClosedByUser = false;
            }
            if (keyboardClosedByUser) {
                Log.i(TAG, "keyboard closed - user");
                onKeyboardClosed();
            }
            if (state.isSearchBarVisible()) {
                int duration = 0;
                if (mPref.getBoolean("search-bar-animation", true))
                    duration = UI_ANIMATION_DURATION;
                mTBLauncherActivity.customizeUI.collapseSearchPill(duration);
            }
        } else {
            if (state.isSearchBarVisible()) {
                int duration = 0;
                if (mPref.getBoolean("search-bar-animation", true))
                    duration = UI_ANIMATION_DURATION;
                mTBLauncherActivity.customizeUI.expandSearchPill(duration);
                mSearchEditText.requestFocus();
            }
        }
    });
    initKeyboardScrollHider();
    initResultLayout();
    initSearchBarContainer();
    mNotificationBackground = findViewById(R.id.notificationBackground);
    mWidgetContainer = findViewById(R.id.widgetContainer);
    // mSearchBarContainer = findViewById(R.id.searchBarContainer);
    // mLauncherButton = mSearchBarContainer.findViewById(R.id.launcherButton);
    // mSearchEditText = mSearchBarContainer.findViewById(R.id.launcherSearch);
    // mClearButton = mSearchBarContainer.findViewById(R.id.clearButton);
    // mMenuButton = mSearchBarContainer.findViewById(R.id.menuButton);
    // WindowCompat.setDecorFitsSystemWindows(window, false);
    // ViewCompat.setOnApplyWindowInsetsListener(window.getDecorView(), (v, insets) -> {
    // int left = v.getPaddingLeft();
    // int top = v.getPaddingTop();
    // int right = v.getPaddingRight();
    // int bottom = v.getPaddingBottom();
    // @WindowInsetsCompat.Type.InsetsType
    // int type = WindowInsetsCompat.Type.systemBars() | WindowInsetsCompat.Type.ime();
    // v.setPadding(left, top, right, insets.getInsets(type).bottom);
    // return insets;
    // });
    initLauncherButton();
    initLauncherSearchEditText();
    // menu button / 3 dot button actions
    mMenuButton.setOnClickListener(v -> {
        Context ctx = v.getContext();
        ListPopup menu = getMenuPopup(ctx);
        registerPopup(menu);
        menu.showCenter(v);
    });
    mMenuButton.setOnLongClickListener(v -> {
        Context ctx = v.getContext();
        ListPopup menu = getMenuPopup(ctx);
        // check if menu contains elements and if yes show it
        if (!menu.getAdapter().isEmpty()) {
            registerPopup(menu);
            menu.show(v, 0f);
            return true;
        }
        return false;
    });
    // clear button actions
    mClearButton.setOnClickListener(v -> clearSearch());
    mClearButton.setOnLongClickListener(v -> {
        clearSearch();
        Context ctx = v.getContext();
        ListPopup menu = getMenuPopup(ctx);
        // check if menu contains elements and if yes show it
        if (!menu.getAdapter().isEmpty()) {
            registerPopup(menu);
            menu.show(v);
            return true;
        }
        return false;
    });
}
Also used : Window(android.view.Window) Context(android.content.Context) KeyboardTriggerBehaviour(rocks.tbog.tblauncher.utils.KeyboardTriggerBehaviour) ListPopup(rocks.tbog.tblauncher.ui.ListPopup)

Example 4 with ListPopup

use of rocks.tbog.tblauncher.ui.ListPopup in project TBLauncher by TBog.

the class AppEntry method popupMenuClickHandler.

@Override
protected boolean popupMenuClickHandler(@NonNull final View view, @NonNull LinearAdapter.MenuItem item, int stringId, View parentView) {
    Context ctx = view.getContext();
    if (item instanceof ShortcutItem) {
        TBApplication.behaviour(ctx).beforeLaunchOccurred();
        final ShortcutInfo shortcutInfo = ((ShortcutItem) item).shortcutInfo;
        parentView.postDelayed(() -> {
            Activity activity = Utilities.getActivity(parentView);
            if (activity == null)
                return;
            ShortcutEntry.doOreoLaunch(activity, parentView, shortcutInfo);
            TBApplication.behaviour(activity).afterLaunchOccurred();
        }, Behaviour.LAUNCH_DELAY);
        return true;
    }
    switch(stringId) {
        // return true;
        case R.string.menu_app_details:
            launchAppDetails(ctx, parentView);
            return true;
        case R.string.menu_app_store:
            launchAppStore(ctx, parentView);
            return true;
        case R.string.menu_app_uninstall:
            launchUninstall(ctx);
            return true;
        case R.string.menu_app_hibernate:
            hibernate(ctx);
            return true;
        // return true;
        case R.string.menu_exclude:
            {
                LinearAdapter adapter = new LinearAdapter();
                ListPopup menu = ListPopup.create(ctx, adapter);
                adapter.add(new LinearAdapter.Item(ctx, R.string.menu_exclude_history));
                adapter.add(new LinearAdapter.Item(ctx, R.string.menu_exclude_kiss));
                menu.setOnItemClickListener((a, v, pos) -> {
                    LinearAdapter.MenuItem menuItem = ((LinearAdapter) a).getItem(pos);
                    @StringRes int id = 0;
                    if (menuItem instanceof LinearAdapter.Item) {
                        id = ((LinearAdapter.Item) a.getItem(pos)).stringId;
                    }
                    switch(id) {
                        case R.string.menu_exclude_history:
                            // excludeFromHistory(v.getContext(), appPojo());
                            Toast.makeText(ctx, "Not Implemented", Toast.LENGTH_LONG).show();
                            break;
                        case R.string.menu_exclude_kiss:
                            // excludeFromKiss(v.getContext(), appPojo(), parent);
                            Toast.makeText(ctx, "Work in progress", Toast.LENGTH_LONG).show();
                            break;
                    }
                });
                menu.show(parentView);
                TBApplication.getApplication(ctx).registerPopup(menu);
                return true;
            }
        case R.string.menu_hide:
            if (TBApplication.dataHandler(ctx).addToHidden(this)) {
                setHiddenByUser(true);
                TBApplication.behaviour(ctx).refreshSearchRecord(this);
            // Toast.makeText(ctx, "App "+getName()+" hidden from search", Toast.LENGTH_LONG).show();
            }
            break;
        case R.string.menu_show:
            if (TBApplication.dataHandler(ctx).removeFromHidden(this)) {
                setHiddenByUser(false);
                TBApplication.behaviour(ctx).refreshSearchRecord(this);
            // Toast.makeText(ctx, "App "+getName()+" shown in searches", Toast.LENGTH_LONG).show();
            }
            break;
        case R.string.menu_tags_add:
        case R.string.menu_tags_edit:
            TBApplication.behaviour(ctx).launchEditTagsDialog(this);
            return true;
        case R.string.menu_app_rename:
            launchRenameDialog(ctx);
            return true;
        case R.string.menu_custom_icon:
            TBApplication.behaviour(ctx).launchCustomIconDialog(this);
            return true;
    }
    return super.popupMenuClickHandler(view, item, stringId, parentView);
}
Also used : Context(android.content.Context) LinearAdapter(rocks.tbog.tblauncher.ui.LinearAdapter) RequiresApi(androidx.annotation.RequiresApi) Context(android.content.Context) Rect(android.graphics.Rect) Bundle(android.os.Bundle) PackageManager(android.content.pm.PackageManager) LinearAdapter(rocks.tbog.tblauncher.ui.LinearAdapter) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) ImageView(android.widget.ImageView) WorkerThread(androidx.annotation.WorkerThread) Intent(android.content.Intent) Drawable(android.graphics.drawable.Drawable) ShortcutUtil(rocks.tbog.tblauncher.shortcut.ShortcutUtil) TBApplication(rocks.tbog.tblauncher.TBApplication) ListPopup(rocks.tbog.tblauncher.ui.ListPopup) DialogHelper(rocks.tbog.tblauncher.utils.DialogHelper) Toast(android.widget.Toast) View(android.view.View) Settings(android.provider.Settings) FLAG_MATCH_MANIFEST(android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_MANIFEST) Build(android.os.Build) TargetApi(android.annotation.TargetApi) ColorFilter(android.graphics.ColorFilter) ComponentName(android.content.ComponentName) ShortcutInfo(android.content.pm.ShortcutInfo) R(rocks.tbog.tblauncher.R) RootHandler(rocks.tbog.tblauncher.utils.RootHandler) Behaviour(rocks.tbog.tblauncher.Behaviour) ContentLoadHelper(rocks.tbog.tblauncher.preference.ContentLoadHelper) ViewGroup(android.view.ViewGroup) LauncherApps(android.content.pm.LauncherApps) IconsHandler(rocks.tbog.tblauncher.handler.IconsHandler) FLAG_MATCH_DYNAMIC(android.content.pm.LauncherApps.ShortcutQuery.FLAG_MATCH_DYNAMIC) StringRes(androidx.annotation.StringRes) List(java.util.List) AsyncSetEntryDrawable(rocks.tbog.tblauncher.result.AsyncSetEntryDrawable) TextView(android.widget.TextView) PrefCache(rocks.tbog.tblauncher.utils.PrefCache) ActivityNotFoundException(android.content.ActivityNotFoundException) LauncherActivityInfo(android.content.pm.LauncherActivityInfo) Utilities(rocks.tbog.tblauncher.utils.Utilities) UserHandleCompat(rocks.tbog.tblauncher.utils.UserHandleCompat) Activity(android.app.Activity) ApplicationInfo(android.content.pm.ApplicationInfo) ResultViewHelper(rocks.tbog.tblauncher.result.ResultViewHelper) DebugInfo(rocks.tbog.tblauncher.utils.DebugInfo) ShortcutInfo(android.content.pm.ShortcutInfo) ListPopup(rocks.tbog.tblauncher.ui.ListPopup) Activity(android.app.Activity)

Example 5 with ListPopup

use of rocks.tbog.tblauncher.ui.ListPopup in project TBLauncher by TBog.

the class WidgetManager method getConfigPopup.

/**
 * Popup with options for all widgets
 *
 * @param activity used to start the widget select popup
 * @return the popup menu
 */
public ListPopup getConfigPopup(Activity activity) {
    LinearAdapter adapter = new LinearAdapter();
    adapter.add(new LinearAdapter.ItemTitle(activity, R.string.menu_widget_title));
    adapter.add(new LinearAdapter.Item(activity, R.string.menu_widget_add));
    if (widgetCount() > 0) {
        adapter.add(new LinearAdapter.Item(activity, R.string.menu_widget_configure));
        adapter.add(new LinearAdapter.Item(activity, R.string.menu_widget_remove));
    }
    adapter.add(new LinearAdapter.Item(activity, R.string.menu_popup_launcher_settings));
    ListPopup menu = ListPopup.create(activity, adapter);
    menu.setOnItemClickListener((a, v, pos) -> {
        LinearAdapter.MenuItem item = ((LinearAdapter) a).getItem(pos);
        @StringRes int stringId = 0;
        if (item instanceof LinearAdapter.Item) {
            stringId = ((LinearAdapter.Item) a.getItem(pos)).stringId;
        }
        switch(stringId) {
            case R.string.menu_widget_add:
                TBApplication.widgetManager(activity).showSelectWidget(activity);
                break;
            case R.string.menu_widget_configure:
                {
                    ListPopup configWidgetPopup = TBApplication.widgetManager(activity).getWidgetListPopup(R.string.menu_widget_configure);
                    configWidgetPopup.setOnItemClickListener((a1, v1, pos1) -> {
                        Object item1 = a1.getItem(pos1);
                        if (item1 instanceof WidgetPopupItem) {
                            AppWidgetHostView widgetView = mLayout.getWidget(((WidgetPopupItem) item1).appWidgetId);
                            if (widgetView == null)
                                return;
                            ListPopup popup = getConfigPopup((WidgetView) widgetView);
                            TBApplication.getApplication(mLayout.getContext()).registerPopup(popup);
                            popup.show(widgetView, 0.f);
                        } else if (item1 instanceof PlaceholderPopupItem) {
                            PlaceholderWidgetRecord placeholder = ((PlaceholderPopupItem) item1).placeholder;
                            View placeholderView = mLayout.getPlaceholder(placeholder.provider);
                            if (placeholderView != null)
                                placeholderView.performClick();
                        }
                    });
                    TBApplication.getApplication(activity).registerPopup(configWidgetPopup);
                    configWidgetPopup.showCenter(activity.getWindow().getDecorView());
                    break;
                }
            case R.string.menu_widget_remove:
                showRemoveWidgetPopup();
                break;
            case R.string.menu_popup_launcher_settings:
                // TBApplication.behaviour(v.getContext()).beforeLaunchOccurred();
                mLayout.postDelayed(() -> {
                    Context c = mLayout.getContext();
                    c.startActivity(new Intent(c, SettingsActivity.class));
                // TBApplication.behaviour(c).afterLaunchOccurred();
                }, Behaviour.LAUNCH_DELAY);
                break;
        }
    });
    return menu;
}
Also used : RequiresApi(androidx.annotation.RequiresApi) Context(android.content.Context) PointF(android.graphics.PointF) PlaceholderWidgetRecord(rocks.tbog.tblauncher.db.PlaceholderWidgetRecord) Bundle(android.os.Bundle) AlertDialog(androidx.appcompat.app.AlertDialog) ResourcesCompat(androidx.core.content.res.ResourcesCompat) PackageManager(android.content.pm.PackageManager) LinearAdapter(rocks.tbog.tblauncher.ui.LinearAdapter) AppWidgetHost(android.appwidget.AppWidgetHost) NonNull(androidx.annotation.NonNull) ImageView(android.widget.ImageView) Intent(android.content.Intent) DrawableUtils(rocks.tbog.tblauncher.drawable.DrawableUtils) AppWidgetProviderInfo(android.appwidget.AppWidgetProviderInfo) Drawable(android.graphics.drawable.Drawable) DBHelper(rocks.tbog.tblauncher.db.DBHelper) ArrayList(java.util.ArrayList) WidgetView(rocks.tbog.tblauncher.ui.WidgetView) ListPopup(rocks.tbog.tblauncher.ui.ListPopup) AppWidgetHostView(android.appwidget.AppWidgetHostView) Toast(android.widget.Toast) ContextThemeWrapper(android.view.ContextThemeWrapper) View(android.view.View) WidgetLayout(rocks.tbog.tblauncher.ui.WidgetLayout) Build(android.os.Build) Log(android.util.Log) ArrayMap(android.util.ArrayMap) WidgetRecord(rocks.tbog.tblauncher.db.WidgetRecord) Iterator(java.util.Iterator) ComponentName(android.content.ComponentName) LayoutInflater(android.view.LayoutInflater) ViewGroup(android.view.ViewGroup) AppWidgetManager(android.appwidget.AppWidgetManager) StringRes(androidx.annotation.StringRes) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) ListAdapter(android.widget.ListAdapter) ActivityNotFoundException(android.content.ActivityNotFoundException) Utilities(rocks.tbog.tblauncher.utils.Utilities) Activity(android.app.Activity) DebugInfo(rocks.tbog.tblauncher.utils.DebugInfo) LinearAdapterPlus(rocks.tbog.tblauncher.ui.LinearAdapterPlus) Context(android.content.Context) PlaceholderWidgetRecord(rocks.tbog.tblauncher.db.PlaceholderWidgetRecord) StringRes(androidx.annotation.StringRes) ListPopup(rocks.tbog.tblauncher.ui.ListPopup) WidgetView(rocks.tbog.tblauncher.ui.WidgetView) Intent(android.content.Intent) ImageView(android.widget.ImageView) WidgetView(rocks.tbog.tblauncher.ui.WidgetView) AppWidgetHostView(android.appwidget.AppWidgetHostView) View(android.view.View) TextView(android.widget.TextView) LinearAdapter(rocks.tbog.tblauncher.ui.LinearAdapter) AppWidgetHostView(android.appwidget.AppWidgetHostView)

Aggregations

ListPopup (rocks.tbog.tblauncher.ui.ListPopup)14 Context (android.content.Context)10 LinearAdapter (rocks.tbog.tblauncher.ui.LinearAdapter)6 View (android.view.View)5 ImageView (android.widget.ImageView)4 TextView (android.widget.TextView)4 StringRes (androidx.annotation.StringRes)4 PlaceholderWidgetRecord (rocks.tbog.tblauncher.db.PlaceholderWidgetRecord)4 AppWidgetHostView (android.appwidget.AppWidgetHostView)3 Intent (android.content.Intent)3 Drawable (android.graphics.drawable.Drawable)3 NonNull (androidx.annotation.NonNull)3 WidgetView (rocks.tbog.tblauncher.ui.WidgetView)3 Activity (android.app.Activity)2 ActivityNotFoundException (android.content.ActivityNotFoundException)2 ComponentName (android.content.ComponentName)2 PackageManager (android.content.pm.PackageManager)2 Build (android.os.Build)2 Bundle (android.os.Bundle)2 LayoutInflater (android.view.LayoutInflater)2