Example usage for android.content Intent ACTION_ASSIST

List of usage examples for android.content Intent ACTION_ASSIST

Introduction

In this page you can find the example usage for android.content Intent ACTION_ASSIST.

Prototype

String ACTION_ASSIST

To view the source code for android.content Intent ACTION_ASSIST.

Click Source Link

Document

Activity Action: Perform assist action.

Usage

From source file:com.farmerbb.taskbar.activity.KeyboardShortcutActivity.java

@SuppressWarnings("deprecation")
@Override//from  w w  w . j a va 2 s.c  o  m
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Perform different actions depending on how this activity was launched
    switch (getIntent().getAction()) {
    case Intent.ACTION_MAIN:
        Intent selector = getIntent().getSelector();
        Set<String> categories = selector != null ? selector.getCategories() : getIntent().getCategories();

        if (categories.contains(Intent.CATEGORY_APP_MAPS)) {
            SharedPreferences pref = U.getSharedPreferences(this);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && pref.getBoolean("freeform_hack", false)
                    && isInMultiWindowMode() && !FreeformHackHelper.getInstance().isFreeformHackActive()) {
                U.startFreeformHack(this, false, false);
            }

            Intent startStopIntent;

            if (pref.getBoolean("taskbar_active", false))
                startStopIntent = new Intent("com.farmerbb.taskbar.QUIT");
            else
                startStopIntent = new Intent("com.farmerbb.taskbar.START");

            startStopIntent.setPackage(BuildConfig.APPLICATION_ID);
            sendBroadcast(startStopIntent);
        } else if (categories.contains(Intent.CATEGORY_APP_CALENDAR))
            U.lockDevice(this);

        break;
    case Intent.ACTION_ASSIST:
        if (U.isServiceRunning(this, StartMenuService.class)) {
            LocalBroadcastManager.getInstance(this)
                    .sendBroadcast(new Intent("com.farmerbb.taskbar.TOGGLE_START_MENU"));
        } else {
            Intent intent = new Intent("com.google.android.googlequicksearchbox.TEXT_ASSIST");
            if (intent.resolveActivity(getPackageManager()) == null)
                intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH);

            if (intent.resolveActivity(getPackageManager()) != null) {
                SharedPreferences pref = U.getSharedPreferences(this);
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N && pref.getBoolean("freeform_hack", false)
                        && isInMultiWindowMode()) {
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
                    U.launchAppMaximized(getApplicationContext(), intent);
                } else {
                    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    startActivity(intent);
                }
            }
        }
        break;
    }

    finish();
}

From source file:org.mozilla.gecko.BrowserApp.java

@Override
public void handleMessage(final String event, final NativeJSObject message, final EventCallback callback) {
    if ("Accounts:CreateFirefoxAccountFromJSON".equals(event)) {
        AndroidFxAccount fxAccount = null;
        try {//from www  .  j a  v  a2s .  c  om
            final NativeJSObject json = message.getObject("json");
            final String email = json.getString("email");
            final String uid = json.getString("uid");
            final boolean verified = json.optBoolean("verified", false);
            final byte[] unwrapkB = Utils.hex2Byte(json.getString("unwrapBKey"));
            final byte[] sessionToken = Utils.hex2Byte(json.getString("sessionToken"));
            final byte[] keyFetchToken = Utils.hex2Byte(json.getString("keyFetchToken"));
            final String authServerEndpoint = json.optString("authServerEndpoint",
                    FxAccountConstants.DEFAULT_AUTH_SERVER_ENDPOINT);
            final String tokenServerEndpoint = json.optString("tokenServerEndpoint",
                    FxAccountConstants.DEFAULT_TOKEN_SERVER_ENDPOINT);
            final String profileServerEndpoint = json.optString("profileServerEndpoint",
                    FxAccountConstants.DEFAULT_PROFILE_SERVER_ENDPOINT);
            // TODO: handle choose what to Sync.
            State state = new Engaged(email, uid, verified, unwrapkB, sessionToken, keyFetchToken);
            fxAccount = AndroidFxAccount.addAndroidAccount(this, email, getProfile().getName(),
                    authServerEndpoint, tokenServerEndpoint, profileServerEndpoint, state,
                    AndroidFxAccount.DEFAULT_AUTHORITIES_TO_SYNC_AUTOMATICALLY_MAP);
        } catch (Exception e) {
            Log.w(LOGTAG, "Got exception creating Firefox Account from JSON; ignoring.", e);
            if (callback == null) {
                callback.sendError("Could not create Firefox Account from JSON: " + e.toString());
            }
        }
        if (callback != null) {
            callback.sendSuccess(fxAccount != null);
        }

    } else if ("Accounts:Create".equals(event)) {
        // Do exactly the same thing as if you tapped 'Sync' in Settings.
        final Intent intent = new Intent(getContext(), FxAccountGetStartedActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        final NativeJSObject extras = message.optObject("extras", null);
        if (extras != null) {
            intent.putExtra("extras", extras.toString());
        }
        getContext().startActivity(intent);

    } else if ("CharEncoding:Data".equals(event)) {
        final NativeJSObject[] charsets = message.getObjectArray("charsets");
        final int selected = message.getInt("selected");

        final String[] titleArray = new String[charsets.length];
        final String[] codeArray = new String[charsets.length];
        for (int i = 0; i < charsets.length; i++) {
            final NativeJSObject charset = charsets[i];
            titleArray[i] = charset.getString("title");
            codeArray[i] = charset.getString("code");
        }

        final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
        dialogBuilder.setSingleChoiceItems(titleArray, selected, new AlertDialog.OnClickListener() {
            @Override
            public void onClick(final DialogInterface dialog, final int which) {
                GeckoAppShell.sendEventToGecko(
                        GeckoEvent.createBroadcastEvent("CharEncoding:Set", codeArray[which]));
                dialog.dismiss();
            }
        });
        dialogBuilder.setNegativeButton(R.string.button_cancel, new AlertDialog.OnClickListener() {
            @Override
            public void onClick(final DialogInterface dialog, final int which) {
                dialog.dismiss();
            }
        });
        ThreadUtils.postToUiThread(new Runnable() {
            @Override
            public void run() {
                dialogBuilder.show();
            }
        });

    } else if ("CharEncoding:State".equals(event)) {
        final boolean visible = message.getString("visible").equals("true");
        GeckoPreferences.setCharEncodingState(visible);
        final Menu menu = mMenu;
        ThreadUtils.postToUiThread(new Runnable() {
            @Override
            public void run() {
                if (menu != null) {
                    menu.findItem(R.id.char_encoding).setVisible(visible);
                }
            }
        });

    } else if ("Favicon:CacheLoad".equals(event)) {
        final String url = message.getString("url");
        getFaviconFromCache(callback, url);

    } else if ("Feedback:LastUrl".equals(event)) {
        getLastUrl(callback);

    } else if ("Feedback:MaybeLater".equals(event)) {
        resetFeedbackLaunchCount();

    } else if ("Feedback:OpenPlayStore".equals(event)) {
        final Intent intent = new Intent(Intent.ACTION_VIEW);
        intent.setData(Uri.parse("market://details?id=" + getPackageName()));
        startActivity(intent);

    } else if ("Menu:Add".equals(event)) {
        final MenuItemInfo info = new MenuItemInfo();
        info.label = message.getString("name");
        info.id = message.getInt("id") + ADDON_MENU_OFFSET;
        info.icon = message.optString("icon", null);
        info.checked = message.optBoolean("checked", false);
        info.enabled = message.optBoolean("enabled", true);
        info.visible = message.optBoolean("visible", true);
        info.checkable = message.optBoolean("checkable", false);
        final int parent = message.optInt("parent", 0);
        info.parent = parent <= 0 ? parent : parent + ADDON_MENU_OFFSET;
        final MenuItemInfo menuItemInfo = info;
        ThreadUtils.postToUiThread(new Runnable() {
            @Override
            public void run() {
                addAddonMenuItem(menuItemInfo);
            }
        });

    } else if ("Menu:Remove".equals(event)) {
        final int id = message.getInt("id") + ADDON_MENU_OFFSET;
        ThreadUtils.postToUiThread(new Runnable() {
            @Override
            public void run() {
                removeAddonMenuItem(id);
            }
        });

    } else if ("Reader:Share".equals(event)) {
        final String title = message.getString("title");
        final String url = message.getString("url");
        GeckoAppShell.openUriExternal(url, "text/plain", "", "", Intent.ACTION_SEND, title);
    } else if ("Sanitize:ClearHistory".equals(event)) {
        handleClearHistory(message.optBoolean("clearSearchHistory", false));
        callback.sendSuccess(true);
    } else if ("Sanitize:ClearSyncedTabs".equals(event)) {
        handleClearSyncedTabs();
        callback.sendSuccess(true);
    } else if ("Settings:Show".equals(event)) {
        final String resource = message.optString(GeckoPreferences.INTENT_EXTRA_RESOURCES, null);
        final Intent settingsIntent = new Intent(this, GeckoPreferences.class);
        GeckoPreferences.setResourceToOpen(settingsIntent, resource);
        startActivityForResult(settingsIntent, ACTIVITY_REQUEST_PREFERENCES);

        // Don't use a transition to settings if we're on a device where that
        // would look bad.
        if (HardwareUtils.IS_KINDLE_DEVICE) {
            overridePendingTransition(0, 0);
        }

    } else if ("Telemetry:Gather".equals(event)) {
        final BrowserDB db = getProfile().getDB();
        final ContentResolver cr = getContentResolver();
        Telemetry.addToHistogram("PLACES_PAGES_COUNT", db.getCount(cr, "history"));
        Telemetry.addToHistogram("PLACES_BOOKMARKS_COUNT", db.getCount(cr, "bookmarks"));
        Telemetry.addToHistogram("FENNEC_FAVICONS_COUNT", db.getCount(cr, "favicons"));
        Telemetry.addToHistogram("FENNEC_THUMBNAILS_COUNT", db.getCount(cr, "thumbnails"));
        Telemetry.addToHistogram("FENNEC_READING_LIST_COUNT", db.getReadingListAccessor().getCount(cr));
        Telemetry.addToHistogram("BROWSER_IS_USER_DEFAULT", (isDefaultBrowser(Intent.ACTION_VIEW) ? 1 : 0));
        Telemetry.addToHistogram("FENNEC_TABQUEUE_ENABLED",
                (TabQueueHelper.isTabQueueEnabled(BrowserApp.this) ? 1 : 0));
        if (Versions.feature16Plus) {
            Telemetry.addToHistogram("BROWSER_IS_ASSIST_DEFAULT",
                    (isDefaultBrowser(Intent.ACTION_ASSIST) ? 1 : 0));
        }
    } else if ("Updater:Launch".equals(event)) {
        handleUpdaterLaunch();
    } else {
        super.handleMessage(event, message, callback);
    }
}