Java Code Examples for android.content.ComponentName.flattenToShortString()

The following are Jave code examples for showing how to use flattenToShortString() of the android.content.ComponentName class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: CSipSimple   File: SuggestionsAdapter.java   Source Code and License Vote up 6 votes
/**
 * Gets the activity or application icon for an activity.
 * Uses the local icon cache for fast repeated lookups.
 *
 * @param component Name of an activity.
 * @return A drawable, or {@code null} if neither the activity nor the application
 *         has an icon set.
 */
private Drawable getActivityIconWithCache(ComponentName component) {
    // First check the icon cache
    String componentIconKey = component.flattenToShortString();
    // Using containsKey() since we also store null values.
    if (mOutsideDrawablesCache.containsKey(componentIconKey)) {
        Drawable.ConstantState cached = mOutsideDrawablesCache.get(componentIconKey);
        return cached == null ? null : cached.newDrawable(mProviderContext.getResources());
    }
    // Then try the activity or application icon
    Drawable drawable = getActivityIcon(component);
    // Stick it in the cache so we don't do this lookup again.
    Drawable.ConstantState toCache = drawable == null ? null : drawable.getConstantState();
    mOutsideDrawablesCache.put(componentIconKey, toCache);
    return drawable;
}
 
Example 2
Project: FreshMember   File: MyService.java   Source Code and License Vote up 6 votes
private void getCurrentActivityName(AccessibilityEvent event) {
    if (event.getEventType() != AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        return;
    }
    try {
        String pkgName = event.getPackageName().toString();
        String className = event.getClassName().toString();
        ComponentName componentName = new ComponentName(pkgName, className);
        getPackageManager().getActivityInfo(componentName, 0);
        currentActivityName = componentName.flattenToShortString();
        Log.d("MyService", "cur=" + currentActivityName);
        if(sp.getBoolean("notification_switch",false)){
            NotificationUtils.updateNotification(this,currentActivityName);
        }
    } catch (PackageManager.NameNotFoundException e) {
        //只是窗口变化,并无activity调转
        Log.d("MyService", "e=" + e.getLocalizedMessage());
    }
}
 
Example 3
Project: WeChatLuckyMoney   File: HongbaoService.java   Source Code and License Vote up 6 votes
private void setCurrentActivityName(AccessibilityEvent event) {
    if (event.getEventType() != AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
        return;
    }

    try {
        ComponentName componentName = new ComponentName(
                event.getPackageName().toString(),
                event.getClassName().toString()
        );

        getPackageManager().getActivityInfo(componentName, 0);
        currentActivityName = componentName.flattenToShortString();
    } catch (PackageManager.NameNotFoundException e) {
        currentActivityName = WECHAT_LUCKMONEY_GENERAL_ACTIVITY;
    }
}
 
Example 4
Project: rental-calc   File: PropertyOverviewActivityTest.java   Source Code and License Vote up 6 votes
private void checkOpenActivity(int viewId, String nextActivity)
{
    ActivityController controller = startWithProperty(new Property());
    Activity activity = (Activity)controller.get();

    View propertyView = activity.findViewById(viewId);
    propertyView.performClick();

    assertTrue(activity.isFinishing() == false);
    Intent next = shadowOf(activity).getNextStartedActivity();

    ComponentName componentName = next.getComponent();
    String name = componentName.flattenToShortString();
    assertEquals(nextActivity, name);

    Bundle extras = next.getExtras();
    assertNotNull(extras);
    assertTrue(extras.containsKey("id"));
    long id = extras.getLong("id", -1);
    assertEquals(DatabaseTestHelper.FIRST_ID, id);
}
 
Example 5
Project: rental-calc   File: PropertiesListActivityTest.java   Source Code and License Vote up 6 votes
@Test
public void clickAddLaunchesActivity()
{
    ActivityController controller = Robolectric.buildActivity(PropertiesListActivity.class).create();
    Activity activity = (Activity)controller.get();

    controller.start();
    controller.visible();
    controller.resume();

    shadowOf(activity).clickMenuItem(R.id.action_add);
    assertTrue(activity.isFinishing() == false);

    Intent next = shadowOf(activity).getNextStartedActivity();

    ComponentName componentName = next.getComponent();
    String name = componentName.flattenToShortString();
    assertEquals("protect.rentalcalc/.PropertyViewActivity", name);

    Bundle extras = next.getExtras();
    assertNull(extras);
}
 
Example 6
Project: rental-calc   File: PropertiesListActivityTest.java   Source Code and License Vote up 6 votes
@Test
public void testFirstRunStartsIntro()
{
    prefs.edit().remove("firstrun").commit();

    ActivityController controller = Robolectric.buildActivity(PropertiesListActivity.class).create();
    Activity activity = (Activity)controller.get();

    assertTrue(activity.isFinishing() == false);

    Intent next = shadowOf(activity).getNextStartedActivity();

    ComponentName componentName = next.getComponent();
    String name = componentName.flattenToShortString();
    assertEquals("protect.rentalcalc/.IntroActivity", name);

    Bundle extras = next.getExtras();
    assertNull(extras);

    assertEquals(false, prefs.getBoolean("firstrun", true));
}
 
Example 7
Project: rental-calc   File: PropertyWorksheetActivityTest.java   Source Code and License Vote up 6 votes
private void checkOpenActivity(ActivityController controller, int viewId, HashMap<String, Integer> items)
{
    Activity activity = (Activity)controller.get();
    activity.findViewById(viewId).performClick();

    assertTrue(activity.isFinishing() == false);

    ShadowActivity.IntentForResult next = shadowOf(activity).getNextStartedActivityForResult();

    ComponentName componentName = next.intent.getComponent();
    String name = componentName.flattenToShortString();
    assertEquals("protect.rentalcalc/.ItemizeActivity", name);

    Bundle extras = next.intent.getExtras();
    assertNotNull(extras);
    assertTrue(extras.containsKey("title"));
    assertTrue(extras.getInt("title") > 0);
    assertTrue(extras.containsKey("description"));
    assertTrue(extras.getInt("description") > 0);
    assertTrue(extras.containsKey("items"));
    assertEquals(items, extras.getSerializable("items"));

    // As the next activity is started, this activity is paused
    controller.pause();
}
 
Example 8
Project: GetRedPackets   File: WXRedPluginService.java   Source Code and License Vote up 5 votes
private void setCurrentActivityName(AccessibilityEvent event) {
    if (event.getEventType() != AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) return;
    try {
        ComponentName componentName = new ComponentName(event.getPackageName().toString(), event.getClassName().toString());
        getPackageManager().getActivityInfo(componentName, 0);
        currentActivityName = componentName.flattenToShortString();
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
}
 
Example 9
Project: boohee_v5.6   File: SuggestionsAdapter.java   Source Code and License Vote up 5 votes
private Drawable getActivityIconWithCache(ComponentName component) {
    String componentIconKey = component.flattenToShortString();
    if (this.mOutsideDrawablesCache.containsKey(componentIconKey)) {
        ConstantState cached = (ConstantState) this.mOutsideDrawablesCache.get(componentIconKey);
        if (cached == null) {
            return null;
        }
        return cached.newDrawable(this.mProviderContext.getResources());
    }
    Drawable drawable = getActivityIcon(component);
    this.mOutsideDrawablesCache.put(componentIconKey, drawable == null ? null : drawable.getConstantState());
    return drawable;
}
 
Example 10
Project: rental-calc   File: PropertiesListActivityTest.java   Source Code and License Vote up 5 votes
@Test
public void clickPropertyLaunchesActivity()
{
    db.insertProperty(new Property());
    ActivityController controller = Robolectric.buildActivity(PropertiesListActivity.class).create();
    Activity activity = (Activity)controller.get();

    controller.start();
    controller.visible();
    controller.resume();

    ListView list = (ListView)activity.findViewById(R.id.list);
    ShadowListView shadowList = shadowOf(list);

    shadowList.populateItems();

    assertEquals(1, list.getCount());
    shadowList.performItemClick(0);

    assertTrue(activity.isFinishing() == false);

    Intent next = shadowOf(activity).getNextStartedActivity();

    ComponentName componentName = next.getComponent();
    String name = componentName.flattenToShortString();
    assertEquals("protect.rentalcalc/.PropertyOverviewActivity", name);

    Bundle extras = next.getExtras();
    assertNotNull(extras);
    assertTrue(extras.containsKey("id"));
    assertEquals(DatabaseTestHelper.FIRST_ID, extras.getLong("id"));
}
 
Example 11
Project: rental-calc   File: PropertyViewActivityTest.java   Source Code and License Vote up 5 votes
@Test
public void startWithoutPropertyAndSave() throws IllegalAccessException
{
    Intent intent = new Intent();
    final Bundle bundle = new Bundle();
    intent.putExtras(bundle);

    ActivityController controller = Robolectric.buildActivity(PropertyViewActivity.class, intent).create();
    Activity activity = (Activity)controller.get();
    controller.start();
    controller.visible();
    controller.resume();

    Property property = new Property();
    preloadProperty(property);
    setFields(activity, property);

    assertNotNull(shadowOf(activity).getOptionsMenu().findItem(R.id.action_save));
    shadowOf(activity).clickMenuItem(R.id.action_save);
    assertTrue(activity.isFinishing());

    Intent next = shadowOf(activity).getNextStartedActivity();
    ComponentName componentName = next.getComponent();
    String name = componentName.flattenToShortString();
    assertEquals("protect.rentalcalc/.PropertyOverviewActivity", name);
    Bundle nextBundle = next.getExtras();
    assertNotNull(nextBundle);
    assertTrue(nextBundle.containsKey("id"));
    assertEquals(DatabaseTestHelper.FIRST_ID, nextBundle.getLong("id"));

    Property updatedProperty = db.getProperty(DatabaseTestHelper.FIRST_ID);

    compareRelevantPropertyFields(property, updatedProperty);
}