use of android.content.pm.ActivityInfo in project cw-omnibus by commonsguy.
the class FreecarTileService method onClick.
@Override
public void onClick() {
super.onClick();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
String cnFlat = prefs.getString(PREF_TO_LAUNCH, null);
if (cnFlat != null) {
ComponentName cn = ComponentName.unflattenFromString(cnFlat);
try {
ActivityInfo info = getPackageManager().getActivityInfo(cn, 0);
ActivityInfo.WindowLayout layout = info.windowLayout;
Intent i = new Intent().setComponent(cn).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Point size = new Point();
getSystemService(DisplayManager.class).getDisplay(Display.DEFAULT_DISPLAY).getSize(size);
if (layout == null) {
size.x = size.x / 2;
size.y = size.y / 2;
} else {
if (layout.widthFraction > 0.0f) {
size.x = Math.max(layout.minWidth, (int) (size.x * layout.widthFraction));
} else {
size.x = layout.width;
}
if (layout.heightFraction > 0.0f) {
size.y = Math.max(layout.minHeight, (int) (size.y * layout.heightFraction));
} else {
size.y = layout.height;
}
}
ActivityOptions opts = ActivityOptions.makeBasic().setLaunchBounds(new Rect(0, 0, size.x, size.y));
startActivity(i, opts.toBundle());
} catch (Exception e) {
Log.e(getClass().getSimpleName(), "Exception trying to launch activity", e);
toast(R.string.msg_sorry);
}
} else {
toast(R.string.msg_choose);
}
}
use of android.content.pm.ActivityInfo in project cw-omnibus by commonsguy.
the class MainActivity method onListItemClick.
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
ResolveInfo launchable = adapter.getItem(position);
ActivityInfo activity = launchable.activityInfo;
ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
PreferenceManager.getDefaultSharedPreferences(this).edit().putString(FreecarTileService.PREF_TO_LAUNCH, name.flattenToString()).apply();
Toast.makeText(this, R.string.msg_saved, Toast.LENGTH_LONG).show();
finish();
}
use of android.content.pm.ActivityInfo in project cw-omnibus by commonsguy.
the class Launchalot method onListItemClick.
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
ResolveInfo launchable = adapter.getItem(position);
ActivityInfo activity = launchable.activityInfo;
ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
Intent i = new Intent(Intent.ACTION_MAIN);
i.addCategory(Intent.CATEGORY_LAUNCHER);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
i.setComponent(name);
startActivity(i);
}
use of android.content.pm.ActivityInfo in project AndroidTraining by mixi-inc.
the class SuggestionsAdapter method getActivityIcon.
/**
* Gets the activity or application icon for an activity.
*
* @param component Name of an activity.
* @return A drawable, or {@code null} if neither the acitivy or the application
* have an icon set.
*/
private Drawable getActivityIcon(ComponentName component) {
PackageManager pm = mContext.getPackageManager();
final ActivityInfo activityInfo;
try {
activityInfo = pm.getActivityInfo(component, PackageManager.GET_META_DATA);
} catch (NameNotFoundException ex) {
Log.w(LOG_TAG, ex.toString());
return null;
}
int iconId = activityInfo.getIconResource();
if (iconId == 0)
return null;
String pkg = component.getPackageName();
Drawable drawable = pm.getDrawable(pkg, iconId, activityInfo.applicationInfo);
if (drawable == null) {
Log.w(LOG_TAG, "Invalid icon resource " + iconId + " for " + component.flattenToShortString());
return null;
}
return drawable;
}
use of android.content.pm.ActivityInfo in project atlas by alibaba.
the class AtlasBundleInfoManager method findBundleByComponentName.
// private String getFromAssets(String fileName,Context context){
// BufferedReader bufReader = null;
// try {
// InputStreamReader inputReader = new InputStreamReader(context.getResources().getAssets().open(fileName), CHARSET);
// bufReader = new BufferedReader(inputReader);
// String line="";
// String result="";
// while((line = bufReader.readLine()) != null)
// result += line;
// return result;
// } catch (Exception e) {
// e.printStackTrace();
// return null;
// } finally {
// if(bufReader!=null){
// try {
// bufReader.close();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
// }
// }
//
// private String getFromFile(String fileName){
// File file = new File(fileName);
// Long fileLength = file.length();
// byte[] filecontent = new byte[fileLength.intValue()];
// try {
// FileInputStream in = new FileInputStream(file);
// in.read(filecontent);
// in.close();
// return new String(filecontent,CHARSET);
// } catch (Throwable e) {
// e.printStackTrace();
// }
// return null;
// }
private String findBundleByComponentName(String componentClassName) {
getComponentInfoFromManifestIfNeed();
ComponentName componentName = new ComponentName(RuntimeVariables.androidApplication.getPackageName(), componentClassName);
if (activityInfos != null) {
ActivityInfo info = activityInfos.get(componentClassName);
if (info != null) {
if (info.metaData != null) {
return info.metaData.getString("bundleLocation");
} else {
try {
ActivityInfo detailInfo = RuntimeVariables.androidApplication.getPackageManager().getActivityInfo(componentName, PackageManager.GET_META_DATA);
if (detailInfo != null && detailInfo.metaData != null) {
info.metaData = detailInfo.metaData;
return detailInfo.metaData.getString("bundleLocation");
} else {
return null;
}
} catch (Throwable e) {
}
}
}
}
if (serviceInfos != null) {
ServiceInfo info = serviceInfos.get(componentClassName);
if (info != null) {
if (info.metaData != null) {
return info.metaData.getString("bundleLocation");
} else {
try {
ServiceInfo detailInfo = RuntimeVariables.androidApplication.getPackageManager().getServiceInfo(componentName, PackageManager.GET_META_DATA);
if (detailInfo != null && detailInfo.metaData != null) {
info = detailInfo;
return detailInfo.metaData.getString("bundleLocation");
} else {
return null;
}
} catch (Throwable e) {
}
}
}
}
if (receiverInfos != null) {
ActivityInfo info = receiverInfos.get(componentClassName);
if (info != null) {
if (info.metaData != null) {
return info.metaData.getString("bundleLocation");
} else {
try {
ActivityInfo detailInfo = RuntimeVariables.androidApplication.getPackageManager().getReceiverInfo(componentName, PackageManager.GET_META_DATA);
if (detailInfo != null && detailInfo.metaData != null) {
info.metaData = detailInfo.metaData;
return detailInfo.metaData.getString("bundleLocation");
} else {
return null;
}
} catch (Throwable e) {
}
}
}
}
if (providerInfos != null) {
ProviderInfo info = providerInfos.get(componentClassName);
if (info != null) {
if (info.metaData != null) {
return info.metaData.getString("bundleLocation");
} else {
try {
ProviderInfo detailInfo = RuntimeVariables.androidApplication.getPackageManager().getProviderInfo(componentName, PackageManager.GET_META_DATA);
if (detailInfo != null && detailInfo.metaData != null) {
info.metaData = detailInfo.metaData;
return detailInfo.metaData.getString("bundleLocation");
} else {
return null;
}
} catch (Throwable e) {
}
}
}
}
return null;
}
Aggregations