本文整理汇总了Java中android.content.ComponentName.flattenToShortString方法的典型用法代码示例。如果您正苦于以下问题:Java ComponentName.flattenToShortString方法的具体用法?Java ComponentName.flattenToShortString怎么用?Java ComponentName.flattenToShortString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.content.ComponentName
的用法示例。
在下文中一共展示了ComponentName.flattenToShortString方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getActivityIconWithCache
import android.content.ComponentName; //导入方法依赖的package包/类
/**
* 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;
}
示例2: getCurrentActivityName
import android.content.ComponentName; //导入方法依赖的package包/类
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());
}
}
示例3: setCurrentActivityName
import android.content.ComponentName; //导入方法依赖的package包/类
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;
}
}
示例4: checkOpenActivity
import android.content.ComponentName; //导入方法依赖的package包/类
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);
}
示例5: clickAddLaunchesActivity
import android.content.ComponentName; //导入方法依赖的package包/类
@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);
}
示例6: testFirstRunStartsIntro
import android.content.ComponentName; //导入方法依赖的package包/类
@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));
}
示例7: checkOpenActivity
import android.content.ComponentName; //导入方法依赖的package包/类
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();
}
示例8: setCurrentActivityName
import android.content.ComponentName; //导入方法依赖的package包/类
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();
}
}
示例9: getActivityIconWithCache
import android.content.ComponentName; //导入方法依赖的package包/类
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;
}
示例10: clickPropertyLaunchesActivity
import android.content.ComponentName; //导入方法依赖的package包/类
@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"));
}
示例11: startWithoutPropertyAndSave
import android.content.ComponentName; //导入方法依赖的package包/类
@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);
}