public static void init(final Activity activity) { final ApplicationInfo applicationInfo = activity.getApplicationInfo(); initListener(); try { // Get the lib_name from AndroidManifest.xml metadata ActivityInfo ai = activity .getPackageManager() .getActivityInfo(activity.getIntent().getComponent(), PackageManager.GET_META_DATA); if (null != ai.metaData) { String lib_name = ai.metaData.getString(META_DATA_LIB_NAME); if (null != lib_name) { System.loadLibrary(lib_name); } else { System.loadLibrary(DEFAULT_LIB_NAME); } } } catch (PackageManager.NameNotFoundException e) { throw new RuntimeException("Error getting activity info", e); } Cocos2dxHelper.sPackageName = applicationInfo.packageName; Cocos2dxHelper.sFileDirectory = activity.getFilesDir().getAbsolutePath(); // Cocos2dxHelper.nativeSetApkPath(applicationInfo.sourceDir); Cocos2dxHelper.sCocos2dMusic = new Cocos2dxMusic(activity); Cocos2dxHelper.sCocos2dSound = new Cocos2dxSound(activity); Cocos2dxHelper.sAssetManager = activity.getAssets(); // Cocos2dxHelper.nativeSetAssetManager(sAssetManager); Cocos2dxBitmap.setContext(activity); sActivity = activity; }
// Copies the mock package to the data directory and returns the file path to it. private String getMockPackagePath() { String mockPackagePath = ""; try { InputStream inStream = getAsset(MOCK_PACKAGE); File dataDir = new File(mActivity.getApplicationInfo().dataDir); File outFile = new File(dataDir, MOCK_PACKAGE); OutputStream outStream = new FileOutputStream(outFile); int b; while ((b = inStream.read()) != -1) { outStream.write(b); } inStream.close(); outStream.close(); mockPackagePath = outFile.getPath(); } catch (Exception e) { mAsserter.ok( false, "exception copying mock distribution package to data directory", e.toString()); } return mockPackagePath; }
@Override public void tearDown() throws Exception { File dataDir = new File(mActivity.getApplicationInfo().dataDir); // Delete mock package from data directory. File mockPackage = new File(dataDir, MOCK_PACKAGE); mAsserter.ok(mockPackage.delete(), "clean up mock package", "deleted " + mockPackage.getPath()); // Recursively delete distribution files that Distribution.init copied to data directory. File distDir = new File(dataDir, "distribution"); delete(distDir); clearDistributionPref(); super.tearDown(); }
public static void init(final Activity activity) { if (!sInited) { final ApplicationInfo applicationInfo = activity.getApplicationInfo(); Cocos2dxHelper.sCocos2dxHelperListener = (Cocos2dxHelperListener) activity; Cocos2dxHelper.sPackageName = applicationInfo.packageName; Cocos2dxHelper.sFileDirectory = activity.getFilesDir().getAbsolutePath(); Cocos2dxHelper.nativeSetApkPath(applicationInfo.sourceDir); Cocos2dxHelper.sCocos2dxAccelerometer = new Cocos2dxAccelerometer(activity); Cocos2dxHelper.sCocos2dMusic = new Cocos2dxMusic(activity); Cocos2dxHelper.sCocos2dSound = new Cocos2dxSound(activity); Cocos2dxHelper.sAssetManager = activity.getAssets(); Cocos2dxHelper.nativeSetContext((Context) activity, Cocos2dxHelper.sAssetManager); Cocos2dxBitmap.setContext(activity); sActivity = activity; sInited = true; } }
private static int loadUiOptionsFromManifest(Activity activity) { int uiOptions = 0; try { final String thisPackage = activity.getClass().getName(); if (DEBUG) Log.i(TAG, "Parsing AndroidManifest.xml for " + thisPackage); final String packageName = activity.getApplicationInfo().packageName; final AssetManager am = activity.createPackageContext(packageName, 0).getAssets(); final XmlResourceParser xml = am.openXmlResourceParser("AndroidManifest.xml"); int eventType = xml.getEventType(); while (eventType != XmlPullParser.END_DOCUMENT) { if (eventType == XmlPullParser.START_TAG) { String name = xml.getName(); if ("application".equals(name)) { // Check if the <application> has the attribute if (DEBUG) Log.d(TAG, "Got <application>"); for (int i = xml.getAttributeCount() - 1; i >= 0; i--) { if (DEBUG) Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i)); if ("uiOptions".equals(xml.getAttributeName(i))) { uiOptions = xml.getAttributeIntValue(i, 0); break; // out of for loop } } } else if ("activity".equals(name)) { // Check if the <activity> is us and has the attribute if (DEBUG) Log.d(TAG, "Got <activity>"); Integer activityUiOptions = null; String activityPackage = null; boolean isOurActivity = false; for (int i = xml.getAttributeCount() - 1; i >= 0; i--) { if (DEBUG) Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i)); // We need both uiOptions and name attributes String attrName = xml.getAttributeName(i); if ("uiOptions".equals(attrName)) { activityUiOptions = xml.getAttributeIntValue(i, 0); } else if ("name".equals(attrName)) { activityPackage = cleanActivityName(packageName, xml.getAttributeValue(i)); if (!thisPackage.equals(activityPackage)) { break; // out of for loop } isOurActivity = true; } // Make sure we have both attributes before processing if ((activityUiOptions != null) && (activityPackage != null)) { // Our activity, uiOptions specified, override with our value uiOptions = activityUiOptions.intValue(); } } if (isOurActivity) { // If we matched our activity but it had no logo don't // do any more processing of the manifest break; } } } eventType = xml.nextToken(); } } catch (Exception e) { e.printStackTrace(); } if (DEBUG) Log.i(TAG, "Returning " + Integer.toHexString(uiOptions)); return uiOptions; }