Search in sources :

Example 1 with LinearAdapter

use of rocks.tbog.tblauncher.ui.LinearAdapter 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 2 with LinearAdapter

use of rocks.tbog.tblauncher.ui.LinearAdapter 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)

Example 3 with LinearAdapter

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

the class WidgetManager method getConfigPopup.

/**
 * Popup with options for the widget in the view
 *
 * @param view of the widget
 * @return the popup menu
 */
protected ListPopup getConfigPopup(WidgetView view) {
    final int appWidgetId = view.getAppWidgetId();
    Context ctx = mLayout.getContext();
    LinearAdapter adapter = new LinearAdapter();
    WidgetRecord widget = mWidgets.get(appWidgetId);
    if (widget != null) {
        addConfigPopupItems(mLayout, adapter, view, widget);
    } else {
        adapter.add(new LinearAdapter.ItemString("ERROR: Not found"));
    }
    ListPopup menu = ListPopup.create(ctx, adapter);
    menu.setOnItemClickListener((a, v, position) -> handleConfigPopupItemClick(a, view, position));
    return menu;
}
Also used : Context(android.content.Context) LinearAdapter(rocks.tbog.tblauncher.ui.LinearAdapter) ListPopup(rocks.tbog.tblauncher.ui.ListPopup) PlaceholderWidgetRecord(rocks.tbog.tblauncher.db.PlaceholderWidgetRecord) WidgetRecord(rocks.tbog.tblauncher.db.WidgetRecord)

Example 4 with LinearAdapter

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

the class EntryItem method inflatePopupMenu.

ListPopup inflatePopupMenu(@NonNull Context context, @NonNull LinearAdapter adapter) {
    ListPopup menu = ListPopup.create(context, adapter);
    // boolean foundInQuickList = false;
    // ArrayList<ModRecord> favRecords = TBApplication.dataHandler(context).getFavorites();
    // for (ModRecord fav : favRecords) {
    // if (id.equals(fav.record) && fav.isInQuickList()) {
    // foundInQuickList = true;
    // break;
    // }
    // }
    QuickListProvider provider = TBApplication.dataHandler(context).getQuickListProvider();
    // get current Quick List content
    List<? extends EntryItem> list = provider != null ? provider.getPojos() : Collections.emptyList();
    boolean foundInQuickList = list.contains(this);
    if (foundInQuickList) {
        // if already in quick list, remove the "Add to QuickList" option
        for (int i = 0; i < adapter.getCount(); i += 1) {
            LinearAdapter.MenuItem item = adapter.getItem(i);
            if (item instanceof LinearAdapter.Item) {
                if (((LinearAdapter.Item) item).stringId == R.string.menu_quick_list_add)
                    adapter.remove(item);
            }
        }
    } else {
        // if not in quick list, remove the "Remove from QuickList" option
        for (int i = 0; i < adapter.getCount(); i += 1) {
            LinearAdapter.MenuItem item = adapter.getItem(i);
            if (item instanceof LinearAdapter.Item) {
                if (((LinearAdapter.Item) item).stringId == R.string.menu_quick_list_remove)
                    adapter.remove(item);
            }
        }
    }
    if (DebugInfo.itemRelevance(context)) {
        String debugTitle = context.getString(R.string.popup_title_debug);
        int pos = -1;
        // find title
        for (int i = 0; i < adapter.getCount(); i += 1) {
            if (debugTitle.equals(adapter.getItem(i).toString())) {
                pos = i + 1;
                break;
            }
        }
        // if title not found, add title
        if (pos == -1) {
            adapter.add(new LinearAdapter.ItemTitle(debugTitle));
            pos = adapter.getCount();
        }
        // add debug data after title
        adapter.add(pos, new LinearAdapter.ItemString("Relevance: " + getRelevance()));
    }
    return menu;
}
Also used : LinearAdapter(rocks.tbog.tblauncher.ui.LinearAdapter) QuickListProvider(rocks.tbog.tblauncher.dataprovider.QuickListProvider) ListPopup(rocks.tbog.tblauncher.ui.ListPopup)

Example 5 with LinearAdapter

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

the class Behaviour method getMenuPopup.

private ListPopup getMenuPopup(Context ctx) {
    LinearAdapter adapter = new LinearAdapter();
    ListPopup menu = ListPopup.create(ctx, adapter);
    adapter.add(new LinearAdapter.ItemTitle(ctx, R.string.menu_popup_title));
    adapter.add(new LinearAdapter.Item(ctx, R.string.change_wallpaper));
    adapter.add(new LinearAdapter.Item(ctx, R.string.menu_widget_add));
    if (TBApplication.widgetManager(ctx).widgetCount() > 0)
        adapter.add(new LinearAdapter.Item(ctx, R.string.menu_widget_remove));
    adapter.add(new LinearAdapter.ItemTitle(ctx, R.string.menu_popup_title_settings));
    adapter.add(new LinearAdapter.Item(ctx, R.string.menu_popup_launcher_settings));
    adapter.add(new LinearAdapter.Item(ctx, R.string.menu_popup_tags_manager));
    adapter.add(new LinearAdapter.Item(ctx, R.string.menu_popup_tags_menu));
    adapter.add(new LinearAdapter.Item(ctx, R.string.menu_popup_android_settings));
    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;
        }
        Context c = mTBLauncherActivity;
        if (stringId == R.string.menu_popup_tags_manager) {
            launchTagsManagerDialog(mTBLauncherActivity);
        } else if (stringId == R.string.menu_popup_tags_menu) {
            executeAction("showTagsMenu", "button-menu");
        } else if (stringId == R.string.menu_popup_launcher_settings) {
            Intent intent = new Intent(mClearButton.getContext(), SettingsActivity.class);
            launchIntent(this, mClearButton, intent);
        } else if (stringId == R.string.change_wallpaper) {
            Intent intent = new Intent(Intent.ACTION_SET_WALLPAPER);
            intent = Intent.createChooser(intent, c.getString(R.string.change_wallpaper));
            launchIntent(this, mClearButton, intent);
        } else if (stringId == R.string.menu_widget_add) {
            TBApplication.widgetManager(c).showSelectWidget(mTBLauncherActivity);
        } else if (stringId == R.string.menu_widget_remove) {
            TBApplication.widgetManager(c).showRemoveWidgetPopup();
        } else if (stringId == R.string.menu_popup_android_settings) {
            Intent intent = new Intent(Settings.ACTION_SETTINGS);
            launchIntent(this, mClearButton, intent);
        }
    });
    return menu;
}
Also used : LinearAdapter(rocks.tbog.tblauncher.ui.LinearAdapter) Context(android.content.Context) EntryItem(rocks.tbog.tblauncher.entry.EntryItem) StringRes(androidx.annotation.StringRes) ListPopup(rocks.tbog.tblauncher.ui.ListPopup) Intent(android.content.Intent)

Aggregations

LinearAdapter (rocks.tbog.tblauncher.ui.LinearAdapter)10 Context (android.content.Context)8 ListPopup (rocks.tbog.tblauncher.ui.ListPopup)6 StringRes (androidx.annotation.StringRes)5 Intent (android.content.Intent)3 ViewGroup (android.view.ViewGroup)3 NonNull (androidx.annotation.NonNull)3 PlaceholderWidgetRecord (rocks.tbog.tblauncher.db.PlaceholderWidgetRecord)3 WidgetRecord (rocks.tbog.tblauncher.db.WidgetRecord)3 Activity (android.app.Activity)2 ActivityNotFoundException (android.content.ActivityNotFoundException)2 ComponentName (android.content.ComponentName)2 ApplicationInfo (android.content.pm.ApplicationInfo)2 LauncherActivityInfo (android.content.pm.LauncherActivityInfo)2 LauncherApps (android.content.pm.LauncherApps)2 PackageManager (android.content.pm.PackageManager)2 ShortcutInfo (android.content.pm.ShortcutInfo)2 Drawable (android.graphics.drawable.Drawable)2 Build (android.os.Build)2 Bundle (android.os.Bundle)2