Java Code Examples for android.content.pm.ShortcutManager#reportShortcutUsed()

The following examples show how to use android.content.pm.ShortcutManager#reportShortcutUsed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: QuickToggleShortcut.java    From ShadowsocksRR with Apache License 2.0 8 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String action = getIntent().getAction();

    if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) {
        setResult(Activity.RESULT_OK, new Intent()
                .putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(this, QuickToggleShortcut.class))
                .putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.quick_toggle))
                .putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                        Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher)));
        finish();
    } else {
        mServiceBoundContext.attachService();
        if (Build.VERSION.SDK_INT >= 25) {
            ShortcutManager service = getSystemService(ShortcutManager.class);
            if (service != null) {
                service.reportShortcutUsed("toggle");
            }
        }
    }
}
 
Example 2
Source File: ScannerActivity.java    From ShadowsocksRR with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_scanner);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(getTitle());
    toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_material);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            navigateUp();
        }
    });

    scannerView = (ZXingScannerView) findViewById(R.id.scanner);

    if (Build.VERSION.SDK_INT >= 25) {
        ShortcutManager service = getSystemService(ShortcutManager.class);
        if (service != null) {
            service.reportShortcutUsed("scan");
        }
    }
}
 
Example 3
Source File: QuickToggleShortcut.java    From Maying with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    String action = getIntent().getAction();

    if (Intent.ACTION_CREATE_SHORTCUT.equals(action)) {
        setResult(Activity.RESULT_OK, new Intent()
                .putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(this, QuickToggleShortcut.class))
                .putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.quick_toggle))
                .putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                        Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher)));
        finish();
    } else {
        mServiceBoundContext.attachService();
        if (Build.VERSION.SDK_INT >= 25) {
            ShortcutManager service = getSystemService(ShortcutManager.class);
            if (service != null) {
                service.reportShortcutUsed("toggle");
            }
        }
    }
}
 
Example 4
Source File: ScannerActivity.java    From Maying with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_scanner);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(getTitle());
    toolbar.setNavigationIcon(R.drawable.abc_ic_ab_back_material);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            navigateUp();
        }
    });

    scannerView = (ZXingScannerView) findViewById(R.id.scanner);

    if (Build.VERSION.SDK_INT >= 25) {
        ShortcutManager service = getSystemService(ShortcutManager.class);
        if (service != null) {
            service.reportShortcutUsed("scan");
        }
    }
}
 
Example 5
Source File: AppShortcutsHelper.java    From rcloneExplorer with MIT License 6 votes vote down vote up
public static void reportAppShortcutUsage(Context context, String remoteName) {
    if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.N_MR1) {
        return;
    }

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
    Set<String> appShortcutIds = sharedPreferences.getStringSet(context.getString(R.string.shared_preferences_app_shortcuts), new HashSet<String>());

    String id = getUniqueIdFromString(remoteName);

    if (appShortcutIds.contains(id)) {
        ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
        if (shortcutManager == null) {
            return;
        }
        shortcutManager.reportShortcutUsed(id);
    }
}
 
Example 6
Source File: WechatContactsActivity.java    From GcmForMojo with GNU General Public License v3.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_wechat_contacts);
    //Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    //setSupportActionBar(toolbar);

    WechatFriendArrayList = MyApplication.getInstance().getWechatFriendArrayList();
    WechatFriendGroups = MyApplication.getInstance().getWechatFriendGroups();

    init();

    // Android 7.1 用于提升Shortcut启动性能
    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        ShortcutManager mShortcutManager = getSystemService(ShortcutManager.class);
        mShortcutManager.reportShortcutUsed("static_wechat_contacts");
    }

}
 
Example 7
Source File: ShortcutHelper.java    From zapp with MIT License 5 votes vote down vote up
/**
 * Call to report a shortcut used.
 * You may call this using any api level.
 *
 * @param context   to access system services
 * @param channelId id of the channel that has been selected
 */
public static void reportShortcutUsageGuarded(Context context, String channelId) {
	if (areShortcutsSupported()) {
		ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
		if (shortcutManager != null) {
			shortcutManager.reportShortcutUsed(channelId);
		}
	}
}
 
Example 8
Source File: OpenVPNService.java    From bitmask_android with GNU General Public License v3.0 5 votes vote down vote up
@RequiresApi(Build.VERSION_CODES.N_MR1)
private void updateShortCutUsage(VpnProfile profile) {
    if (profile == null)
        return;
    ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
    shortcutManager.reportShortcutUsed(profile.getUUIDString());
}
 
Example 9
Source File: ShortcutService.java    From Conversations with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(25)
public void report(Contact contact) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        ShortcutManager shortcutManager = xmppConnectionService.getSystemService(ShortcutManager.class);
        shortcutManager.reportShortcutUsed(getShortcutId(contact));
    }
}
 
Example 10
Source File: ChromeTabbedActivity.java    From 365browser with Apache License 2.0 5 votes vote down vote up
/**
 * Reports that a new tab launcher shortcut was selected or an action equivalent to a shortcut
 * was performed.
 * @param isIncognito Whether the shortcut or action created a new incognito tab.
 */
@TargetApi(Build.VERSION_CODES.N_MR1)
private void reportNewTabShortcutUsed(boolean isIncognito) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) return;

    ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
    shortcutManager.reportShortcutUsed(
            isIncognito ? "new-incognito-tab-shortcut" : "new-tab-shortcut");
}
 
Example 11
Source File: ShortcutService.java    From Pix-Art-Messenger with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(25)
public void report(Contact contact) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        ShortcutManager shortcutManager = xmppConnectionService.getSystemService(ShortcutManager.class);
        shortcutManager.reportShortcutUsed(getShortcutId(contact));
    }
}
 
Example 12
Source File: DeepLinkIntentReceiver.java    From aptoide-client-v8 with GNU General Public License v3.0 5 votes vote down vote up
private void dealWithShortcuts() {
  if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) {

    ShortcutManager shortcutManager =
        getApplicationContext().getSystemService(ShortcutManager.class);
    Intent fromShortcut = getIntent();

    if (fromShortcut != null) {
      if (fromShortcut.hasExtra("search")) {
        if (fromShortcut.getBooleanExtra("search", false)) {
          shortcutNavigation = true;
          if (shortcutManager != null) {
            shortcutManager.reportShortcutUsed("search");
          }
        }
      } else if (fromShortcut.hasExtra("timeline")) {
        if (fromShortcut.getBooleanExtra("timeline", false)) {
          shortcutNavigation = true;
          if (shortcutManager != null) {
            shortcutManager.reportShortcutUsed("timeline");
          }
        }
      }
    }
  }
  return;
}
 
Example 13
Source File: ShadowsocksQuickSwitchActivity.java    From Maying with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_quick_switch);
    profilesAdapter = new ProfilesAdapter();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(R.string.quick_switch);

    RecyclerView profilesList = (RecyclerView) findViewById(R.id.profilesList);
    LinearLayoutManager lm = new LinearLayoutManager(this);
    profilesList.setLayoutManager(lm);
    profilesList.setItemAnimator(new DefaultItemAnimator());
    profilesList.setAdapter(profilesAdapter);
    if (ShadowsocksApplication.app.profileId() >= 0) {
        int position = 0;
        List<Profile> profiles = profilesAdapter.profiles;
        for (int i = 0; i < profiles.size(); i++) {
            Profile profile = profiles.get(i);
            if (profile.id == ShadowsocksApplication.app.profileId()) {
                position = i + 1;
                break;
            }
        }
        lm.scrollToPosition(position);
    }

    if (Build.VERSION.SDK_INT >= 25) {
        ShortcutManager service = getSystemService(ShortcutManager.class);
        if (service != null) {
            service.reportShortcutUsed("switch");
        }
    }
}
 
Example 14
Source File: ShadowsocksQuickSwitchActivity.java    From ShadowsocksRR with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout_quick_switch);
    profilesAdapter = new ProfilesAdapter();

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    toolbar.setTitle(R.string.quick_switch);

    RecyclerView profilesList = (RecyclerView) findViewById(R.id.profilesList);
    LinearLayoutManager lm = new LinearLayoutManager(this);
    profilesList.setLayoutManager(lm);
    profilesList.setItemAnimator(new DefaultItemAnimator());
    profilesList.setAdapter(profilesAdapter);
    if (app.profileId() >= 0) {
        int position = 0;
        List<Profile> profiles = profilesAdapter.profiles;
        for (int i = 0; i < profiles.size(); i++) {
            Profile profile = profiles.get(i);
            if (profile.id == app.profileId()) {
                position = i + 1;
                break;
            }
        }
        lm.scrollToPosition(position);
    }

    if (Build.VERSION.SDK_INT >= 25) {
        ShortcutManager service = getSystemService(ShortcutManager.class);
        if (service != null) {
            service.reportShortcutUsed("switch");
        }
    }
}
 
Example 15
Source File: ApkUtils.java    From TowerCollector with Mozilla Public License 2.0 4 votes vote down vote up
public static void reportShortcutUsage(Context context, @StringRes int shortcutId) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        ShortcutManager shortcutManager = (ShortcutManager) context.getSystemService(Context.SHORTCUT_SERVICE);
        shortcutManager.reportShortcutUsed(context.getString(shortcutId));
    }
}
 
Example 16
Source File: ShortcutHelper.java    From android-proguards with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.N_MR1)
public static void reportPostUsed(@NonNull Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) return;
    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
    shortcutManager.reportShortcutUsed(POST_SHORTCUT_ID);
}
 
Example 17
Source File: ShortcutHelper.java    From android-proguards with Apache License 2.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.N_MR1)
public static void reportSearchUsed(@NonNull Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) return;
    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
    shortcutManager.reportShortcutUsed(SEARCH_SHORTCUT_ID);
}
 
Example 18
Source File: MainActivity.java    From launcher-icon with Apache License 2.0 4 votes vote down vote up
private void reportShortcutUsed(String shortcutId) {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N_MR1) {
        ShortcutManager shortcutManager = (ShortcutManager) getSystemService(SHORTCUT_SERVICE);
        shortcutManager.reportShortcutUsed(shortcutId);
    }
}