use of android.content.Intent in project AndroidTreeView by bmelnychuk.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final LinkedHashMap<String, Class<?>> listItems = new LinkedHashMap<>();
listItems.put("Folder Structure Example", FolderStructureFragment.class);
listItems.put("Custom Holder Example", CustomViewHolderFragment.class);
listItems.put("Selectable Nodes", SelectableTreeFragment.class);
listItems.put("2d scrolling", TwoDScrollingFragment.class);
listItems.put("Expand with arrow only", TwoDScrollingArrowExpandFragment.class);
final List<String> list = new ArrayList(listItems.keySet());
final ListView listview = (ListView) findViewById(R.id.listview);
final SimpleArrayAdapter adapter = new SimpleArrayAdapter(this, list);
listview.setAdapter(adapter);
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Class<?> clazz = listItems.values().toArray(new Class<?>[] {})[position];
Intent i = new Intent(MainActivity.this, SingleFragmentActivity.class);
i.putExtra(SingleFragmentActivity.FRAGMENT_PARAM, clazz);
MainActivity.this.startActivity(i);
}
});
}
use of android.content.Intent in project VirtualApp by asLody.
the class VirtualCore method getLaunchIntent.
public Intent getLaunchIntent(String packageName, int userId) {
VPackageManager pm = VPackageManager.get();
Intent intentToResolve = new Intent(Intent.ACTION_MAIN);
intentToResolve.addCategory(Intent.CATEGORY_INFO);
intentToResolve.setPackage(packageName);
List<ResolveInfo> ris = pm.queryIntentActivities(intentToResolve, intentToResolve.resolveType(context), 0, userId);
// Otherwise, try to find a main launcher activity.
if (ris == null || ris.size() <= 0) {
// reuse the intent instance
intentToResolve.removeCategory(Intent.CATEGORY_INFO);
intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER);
intentToResolve.setPackage(packageName);
ris = pm.queryIntentActivities(intentToResolve, intentToResolve.resolveType(context), 0, userId);
}
if (ris == null || ris.size() <= 0) {
return null;
}
Intent intent = new Intent(intentToResolve);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setClassName(ris.get(0).activityInfo.packageName, ris.get(0).activityInfo.name);
return intent;
}
use of android.content.Intent in project VirtualApp by asLody.
the class VirtualCore method createShortcut.
public boolean createShortcut(int userId, String packageName, Intent splash, OnEmitShortcutListener listener) {
InstalledAppInfo setting = getInstalledAppInfo(packageName, 0);
if (setting == null) {
return false;
}
ApplicationInfo appInfo = setting.getApplicationInfo(userId);
PackageManager pm = context.getPackageManager();
String name;
Bitmap icon;
try {
CharSequence sequence = appInfo.loadLabel(pm);
name = sequence.toString();
icon = BitmapUtils.drawableToBitmap(appInfo.loadIcon(pm));
} catch (Throwable e) {
return false;
}
if (listener != null) {
String newName = listener.getName(name);
if (newName != null) {
name = newName;
}
Bitmap newIcon = listener.getIcon(icon);
if (newIcon != null) {
icon = newIcon;
}
}
Intent targetIntent = getLaunchIntent(packageName, userId);
if (targetIntent == null) {
return false;
}
Intent shortcutIntent = new Intent();
shortcutIntent.setClassName(getHostPkg(), Constants.SHORTCUT_PROXY_ACTIVITY_NAME);
shortcutIntent.addCategory(Intent.CATEGORY_DEFAULT);
if (splash != null) {
shortcutIntent.putExtra("_VA_|_splash_", splash.toUri(0));
}
shortcutIntent.putExtra("_VA_|_intent_", targetIntent);
shortcutIntent.putExtra("_VA_|_uri_", targetIntent.toUri(0));
shortcutIntent.putExtra("_VA_|_user_id_", VUserHandle.myUserId());
Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
context.sendBroadcast(addIntent);
return true;
}
use of android.content.Intent in project VirtualApp by asLody.
the class ActivityFixer method fixActivity.
public static void fixActivity(Activity activity) {
Context baseContext = activity.getBaseContext();
try {
TypedArray typedArray = activity.obtainStyledAttributes((R_Hide.styleable.Window.get()));
if (typedArray != null) {
boolean showWallpaper = typedArray.getBoolean(R_Hide.styleable.Window_windowShowWallpaper.get(), false);
if (showWallpaper) {
activity.getWindow().setBackgroundDrawable(WallpaperManager.getInstance(activity).getDrawable());
}
typedArray.recycle();
}
} catch (Throwable e) {
e.printStackTrace();
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Intent intent = activity.getIntent();
ApplicationInfo applicationInfo = baseContext.getApplicationInfo();
PackageManager pm = activity.getPackageManager();
if (intent != null && activity.isTaskRoot()) {
try {
String label = applicationInfo.loadLabel(pm) + "";
Bitmap icon = null;
Drawable drawable = applicationInfo.loadIcon(pm);
if (drawable instanceof BitmapDrawable) {
icon = ((BitmapDrawable) drawable).getBitmap();
}
activity.setTaskDescription(new ActivityManager.TaskDescription(label, icon));
} catch (Throwable e) {
e.printStackTrace();
}
}
}
}
use of android.content.Intent in project VirtualApp by asLody.
the class AppInstrumentation method callActivityOnResume.
@Override
public void callActivityOnResume(Activity activity) {
VirtualCore.get().getComponentDelegate().beforeActivityResume(activity);
VActivityManager.get().onActivityResumed(activity);
super.callActivityOnResume(activity);
VirtualCore.get().getComponentDelegate().afterActivityResume(activity);
Intent intent = activity.getIntent();
if (intent != null) {
Bundle bundle = intent.getBundleExtra("_VA_|_sender_");
if (bundle != null) {
IBinder loadingPageToken = BundleCompat.getBinder(bundle, "_VA_|_loading_token_");
ActivityManagerCompat.finishActivity(loadingPageToken, -1, null);
}
}
}
Aggregations