Java Code Examples for android.app.Activity#getApplicationInfo()

The following examples show how to use android.app.Activity#getApplicationInfo() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: VoIpUSSD   File: USSDController.java    License: Apache License 2.0 6 votes vote down vote up
private static void openSettingsAccessibility(final Activity activity) {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity);
    alertDialogBuilder.setTitle("USSD Accessibility permission");
    ApplicationInfo applicationInfo = activity.getApplicationInfo();
    int stringId = applicationInfo.labelRes;
    String name = applicationInfo.labelRes == 0 ?
            applicationInfo.nonLocalizedLabel.toString() : activity.getString(stringId);
    alertDialogBuilder
            .setMessage("You must enable accessibility permissions for the app '" + name + "'");
    alertDialogBuilder.setCancelable(true);
    alertDialogBuilder.setNeutralButton("ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            activity.startActivityForResult(new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS), 1);
        }
    });
    AlertDialog alertDialog = alertDialogBuilder.create();
    if (alertDialog != null) {
        alertDialog.show();
    }
}
 
Example 2
Source Project: VoIpUSSD   File: USSDController.java    License: Apache License 2.0 6 votes vote down vote up
private static void openSettingsOverlay(final Activity activity) {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity);
    alertDialogBuilder.setTitle("USSD Overlay permission");
    ApplicationInfo applicationInfo = activity.getApplicationInfo();
    int stringId = applicationInfo.labelRes;
    String name = applicationInfo.labelRes == 0 ?
            applicationInfo.nonLocalizedLabel.toString() : activity.getString(stringId);
    alertDialogBuilder
            .setMessage("You must allow for the app to appear '" + name + "' on top of other apps.");
    alertDialogBuilder.setCancelable(true);
    alertDialogBuilder.setNeutralButton("ok", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                    Uri.parse("package:" + activity.getPackageName()));
            activity.startActivity(intent);
        }
    });
    AlertDialog alertDialog = alertDialogBuilder.create();
    if (alertDialog != null) {
        alertDialog.show();
    }
}
 
Example 3
Source Project: Neptune   File: PluginActivityControl.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 是否需要设置activity的orientation
 * 8.0系统targetSdk > O时, 系统有bug限制了透明主题的activity不能请求orientation
 */
private static boolean shouldApplyOrientation(Activity activity, ActivityInfo actInfo, Resources.Theme theme) {
    if (actInfo.screenOrientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
        return false;
    }
    // 8.0设备 && targetSdkVersion > O && 透明activity, 不能设置orientation; 8.1中已修复
    // http://androidxref.com/8.0.0_r4/xref/frameworks/base/core/java/android/app/Activity.java
    ApplicationInfo appInfo = activity.getApplicationInfo();
    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.O
            && appInfo.targetSdkVersion > Build.VERSION_CODES.O
            && ActivityInfoUtils.isTranslucent(activity, theme, actInfo)) {
        return false;
    }
    // 默认设置orientation
    return true;
}
 
Example 4
/**
 * Kills all associated processes
 */
public static void killProcessesAround(Activity activity) {
    try {
        ActivityManager am = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE);
        String myProcessPrefix = activity.getApplicationInfo().processName;
        String myProcessName = activity.getPackageManager().getActivityInfo(activity.getComponentName(), 0).processName;
        for (ActivityManager.RunningAppProcessInfo proc : am.getRunningAppProcesses()) {
            if (proc.processName.startsWith(myProcessPrefix) && !proc.processName.equals(myProcessName)) {
                android.os.Process.killProcess(proc.pid);
            }
        }
    } catch (Exception e) {
        Timber.e(e, "could not kill process");
    } finally {
        android.os.Process.killProcess(android.os.Process.myPid());
    }
}
 
Example 5
Source Project: AideHelper   File: XHelper.java    License: MIT License 5 votes vote down vote up
/**
 * 使shared_prefs文件夹下所以preferences文件可读
 *
 * @param activity 用来获取App内置存储路径
 */
@SuppressLint("SetWorldReadable")
public static void setPreferencesReadable(Activity activity) {
  File dataDir = new File(activity.getApplicationInfo().dataDir);
  File prefsDir = new File(dataDir, "shared_prefs");
  File[] arrayOfFiles = prefsDir.listFiles();
  for (File prefsFile : arrayOfFiles) {
    if (prefsFile.exists()) {
      for (File file : new File[]{dataDir, prefsDir, prefsFile}) {
        file.setReadable(true, false);
        file.setExecutable(true, false);
      }
    }
  }
}
 
Example 6
Source Project: react-native-baidu-map   File: AppUtils.java    License: MIT License 5 votes vote down vote up
public static void checkPermission(Activity activity, String permission) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        if (activity.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.M) {
            if (!hasPermission(activity, permission)) {
                ActivityCompat.requestPermissions(activity, new String[]{permission}, RequestCode.CODE_ASK_PERMISSIONS);
            }
        }
    }
}
 
Example 7
Source Project: Example-of-Cocos2DX   File: Cocos2dxHelper.java    License: MIT License 5 votes vote down vote up
public static void init(final Activity activity) {
    if (!sInited) {
   		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;

           sInited = true;
    }
}
 
Example 8
Source Project: Earlybird   File: Cocos2dxHelper.java    License: Apache License 2.0 5 votes vote down vote up
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;                   
}
 
Example 9
private static int loadUiOptionsFromManifest(Activity activity) {
    int uiOptions = 0;
    try {
        final String thisPackage = activity.getClass().getName();
        if (ActionBarSherlock.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 (ActionBarSherlock.DEBUG) Log.d(TAG, "Got <application>");

                    for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
                        if (ActionBarSherlock.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 (ActionBarSherlock.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 (ActionBarSherlock.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 (ActionBarSherlock.DEBUG) Log.i(TAG, "Returning " + Integer.toHexString(uiOptions));
    return uiOptions;
}
 
Example 10
/**
 * Attempt to programmatically load the logo from the manifest file of an
 * activity by using an XML pull parser. This should allow us to read the
 * logo attribute regardless of the platform it is being run on.
 *
 * @param activity Activity instance.
 * @return Logo resource ID.
 */
private static int loadLogoFromManifest(Activity activity) {
    int logo = 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 ("logo".equals(xml.getAttributeName(i))) {
                            logo = xml.getAttributeResourceValue(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 activityLogo = 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 ("logo".equals(attrName)) {
                            activityLogo = xml.getAttributeResourceValue(i, 0);
                        } else if ("name".equals(attrName)) {
                            activityPackage = ActionBarSherlockCompat.cleanActivityName(packageName, xml.getAttributeValue(i));
                            if (!thisPackage.equals(activityPackage)) {
                                break; //on to the next
                            }
                            isOurActivity = true;
                        }

                        //Make sure we have both attributes before processing
                        if ((activityLogo != null) && (activityPackage != null)) {
                            //Our activity, logo specified, override with our value
                            logo = activityLogo.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(logo));
    return logo;
}
 
Example 11
/**
 * Attempt to programmatically load the logo from the manifest file of an
 * activity by using an XML pull parser. This should allow us to read the
 * logo attribute regardless of the platform it is being run on.
 *
 * @param activity Activity instance.
 * @return Logo resource ID.
 */
public static int loadLogoFromManifest(Activity activity) {
    int logo = 0;
    try {
        final String thisPackage = activity.getClass().getName();
        if (ActionBarSherlock.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 (ActionBarSherlock.DEBUG) Log.d(TAG, "Got <application>");

                    for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
                        if (ActionBarSherlock.DEBUG) Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i));

                        if ("logo".equals(xml.getAttributeName(i))) {
                            logo = xml.getAttributeResourceValue(i, 0);
                            break; //out of for loop
                        }
                    }
                } else if ("activity".equals(name)) {
                    //Check if the <activity> is us and has the attribute
                    if (ActionBarSherlock.DEBUG) Log.d(TAG, "Got <activity>");
                    Integer activityLogo = null;
                    String activityPackage = null;
                    boolean isOurActivity = false;

                    for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
                        if (ActionBarSherlock.DEBUG) Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i));

                        //We need both uiOptions and name attributes
                        String attrName = xml.getAttributeName(i);
                        if ("logo".equals(attrName)) {
                            activityLogo = xml.getAttributeResourceValue(i, 0);
                        } else if ("name".equals(attrName)) {
                            activityPackage = ActionBarSherlockCompat.cleanActivityName(packageName, xml.getAttributeValue(i));
                            if (!thisPackage.equals(activityPackage)) {
                                break; //on to the next
                            }
                            isOurActivity = true;
                        }

                        //Make sure we have both attributes before processing
                        if ((activityLogo != null) && (activityPackage != null)) {
                            //Our activity, logo specified, override with our value
                            logo = activityLogo.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 (ActionBarSherlock.DEBUG) Log.i(TAG, "Returning " + Integer.toHexString(logo));
    return logo;
}
 
Example 12
/**
 * 获取坑位应该使用的主题
 */
private int getThemeId(Activity activity, Intent intent) {

    // 通过反射获取主题(可能获取到坑的主题,或者程序员通过代码设置的主题)
    int dynamicThemeId = getDynamicThemeId(activity);

    // 插件 manifest 中设置的 ThemeId
    int manifestThemeId = intent.getIntExtra(PluginCommImpl.INTENT_KEY_THEME_ID, 0);
    //如果插件上没有主题则使用Application节点的Theme
    if (manifestThemeId == 0) {
        manifestThemeId = activity.getApplicationInfo().theme;
    }

    // 根据 manifest 中声明主题是否透明,获取默认主题
    int defaultThemeId = getDefaultThemeId();
    if (LaunchModeStates.isTranslucentTheme(manifestThemeId)) {
        defaultThemeId = android.R.style.Theme_Translucent_NoTitleBar;
    }

    int themeId;

    if (LOG) {
        LogDebug.d("theme", "defaultThemeId = " + defaultThemeId);
        LogDebug.d("theme", "dynamicThemeId = " + dynamicThemeId);
        LogDebug.d("theme", "manifestThemeId = " + manifestThemeId);
    }

    // 通过反射获取主题成功
    if (dynamicThemeId != -1) {
        // 如果动态主题是默认主题,说明插件未通过代码设置主题,此时应该使用 AndroidManifest 中设置的主题。
        if (dynamicThemeId == defaultThemeId) {
            // AndroidManifest 中有声明主题
            if (manifestThemeId != 0) {
                themeId = manifestThemeId;
            } else {
                themeId = defaultThemeId;
            }

        } else {
            // 动态主题不是默认主题,说明主题是插件通过代码设置的,使用此代码设置的主题。
            themeId = dynamicThemeId;
        }

        // 反射失败,检查 AndroidManifest 是否有声明主题
    } else {
        if (manifestThemeId != 0) {
            themeId = manifestThemeId;
        } else {
            themeId = defaultThemeId;
        }
    }

    if (LOG) {
        LogDebug.d("theme", "themeId = " + themeId);
    }

    return themeId;
}
 
Example 13
Source Project: SwipeBack   File: ModSDK21.java    License: GNU General Public License v3.0 4 votes vote down vote up
@TargetApi(21)
public static void afterOnPostCreateSDK21(XC_MethodHook.MethodHookParam mhparams) throws Throwable {
	Class<?> internalStyleable = findClass("com.android.internal.R.styleable", null);
	int[] internalTheme = $(getStaticObjectField(internalStyleable, "Theme"));
	int internalColorPrimary = getStaticIntField(internalStyleable, "Theme_colorPrimaryDark");
	
	SwipeBackActivityHelper helper = $(getAdditionalInstanceField(mhparams.thisObject, "helper"));
	if (helper != null) {
		final Activity activity = $(mhparams.thisObject);

		String packageName = activity.getApplicationInfo().packageName;
		String className = activity.getClass().getName();
		
		mSettings.reload();
		if (!mSettings.getBoolean(packageName, className, Settings.LOLLIPOP_HACK, false))
			return;
		
		ViewGroup root = $(helper.getSwipeBackLayout().getChildAt(0));
		View content = root.getChildAt(0);
		final WindowInsetsColorDrawable bkg = new WindowInsetsColorDrawable(content.getBackground());
		content.setBackground(bkg);
		
		TypedArray a = activity.getTheme().obtainStyledAttributes(internalTheme);
		int primary = a.getColor(internalColorPrimary, 0);
		a.recycle();

		if (primary != 0) {
			bkg.setTopDrawable(new ColorDrawable(primary));
		} else {
			content.setSystemUiVisibility(content.getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
			content.setFitsSystemWindows(true);
		}

		root.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
			@Override
			public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
				bkg.setTopInset(insets.getSystemWindowInsetTop());
				activity.getWindow().setStatusBarColor(0);
				return insets;
			}
		});
	}
}
 
Example 14
Source Project: zhangshangwuda   File: ResourcesCompat.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Attempt to programmatically load the logo from the manifest file of an
 * activity by using an XML pull parser. This should allow us to read the
 * logo attribute regardless of the platform it is being run on.
 *
 * @param activity Activity instance.
 * @return Logo resource ID.
 */
public static int loadLogoFromManifest(Activity activity) {
    int logo = 0;
    try {
        final String thisPackage = activity.getClass().getName();
        if (ActionBarSherlock.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 (ActionBarSherlock.DEBUG) Log.d(TAG, "Got <application>");

                    for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
                        if (ActionBarSherlock.DEBUG) Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i));

                        if ("logo".equals(xml.getAttributeName(i))) {
                            logo = xml.getAttributeResourceValue(i, 0);
                            break; //out of for loop
                        }
                    }
                } else if ("activity".equals(name)) {
                    //Check if the <activity> is us and has the attribute
                    if (ActionBarSherlock.DEBUG) Log.d(TAG, "Got <activity>");
                    Integer activityLogo = null;
                    String activityPackage = null;
                    boolean isOurActivity = false;

                    for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
                        if (ActionBarSherlock.DEBUG) Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i));

                        //We need both uiOptions and name attributes
                        String attrName = xml.getAttributeName(i);
                        if ("logo".equals(attrName)) {
                            activityLogo = xml.getAttributeResourceValue(i, 0);
                        } else if ("name".equals(attrName)) {
                            activityPackage = ActionBarSherlockCompat.cleanActivityName(packageName, xml.getAttributeValue(i));
                            if (!thisPackage.equals(activityPackage)) {
                                break; //on to the next
                            }
                            isOurActivity = true;
                        }

                        //Make sure we have both attributes before processing
                        if ((activityLogo != null) && (activityPackage != null)) {
                            //Our activity, logo specified, override with our value
                            logo = activityLogo.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 (ActionBarSherlock.DEBUG) Log.i(TAG, "Returning " + Integer.toHexString(logo));
    return logo;
}
 
Example 15
Source Project: android-apps   File: ActionBarSherlockCompat.java    License: MIT License 4 votes vote down vote up
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;
}
 
Example 16
Source Project: android-apps   File: ActionBarView.java    License: MIT License 4 votes vote down vote up
/**
 * Attempt to programmatically load the logo from the manifest file of an
 * activity by using an XML pull parser. This should allow us to read the
 * logo attribute regardless of the platform it is being run on.
 *
 * @param activity Activity instance.
 * @return Logo resource ID.
 */
private static int loadLogoFromManifest(Activity activity) {
    int logo = 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 ("logo".equals(xml.getAttributeName(i))) {
                            logo = xml.getAttributeResourceValue(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 activityLogo = 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 ("logo".equals(attrName)) {
                            activityLogo = xml.getAttributeResourceValue(i, 0);
                        } else if ("name".equals(attrName)) {
                            activityPackage = ActionBarSherlockCompat.cleanActivityName(packageName, xml.getAttributeValue(i));
                            if (!thisPackage.equals(activityPackage)) {
                                break; //on to the next
                            }
                            isOurActivity = true;
                        }

                        //Make sure we have both attributes before processing
                        if ((activityLogo != null) && (activityPackage != null)) {
                            //Our activity, logo specified, override with our value
                            logo = activityLogo.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(logo));
    return logo;
}
 
Example 17
Source Project: zen4android   File: ActionBarSherlockCompat.java    License: MIT License 4 votes vote down vote up
private static int loadUiOptionsFromManifest(Activity activity) {
    int uiOptions = 0;
    try {
        final String thisPackage = activity.getClass().getName();
        if (ActionBarSherlock.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 (ActionBarSherlock.DEBUG) Log.d(TAG, "Got <application>");

                    for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
                        if (ActionBarSherlock.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 (ActionBarSherlock.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 (ActionBarSherlock.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 (ActionBarSherlock.DEBUG) Log.i(TAG, "Returning " + Integer.toHexString(uiOptions));
    return uiOptions;
}
 
Example 18
Source Project: zen4android   File: ResourcesCompat.java    License: MIT License 4 votes vote down vote up
/**
 * Attempt to programmatically load the logo from the manifest file of an
 * activity by using an XML pull parser. This should allow us to read the
 * logo attribute regardless of the platform it is being run on.
 *
 * @param activity Activity instance.
 * @return Logo resource ID.
 */
public static int loadLogoFromManifest(Activity activity) {
    int logo = 0;
    try {
        final String thisPackage = activity.getClass().getName();
        if (ActionBarSherlock.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 (ActionBarSherlock.DEBUG) Log.d(TAG, "Got <application>");

                    for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
                        if (ActionBarSherlock.DEBUG) Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i));

                        if ("logo".equals(xml.getAttributeName(i))) {
                            logo = xml.getAttributeResourceValue(i, 0);
                            break; //out of for loop
                        }
                    }
                } else if ("activity".equals(name)) {
                    //Check if the <activity> is us and has the attribute
                    if (ActionBarSherlock.DEBUG) Log.d(TAG, "Got <activity>");
                    Integer activityLogo = null;
                    String activityPackage = null;
                    boolean isOurActivity = false;

                    for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
                        if (ActionBarSherlock.DEBUG) Log.d(TAG, xml.getAttributeName(i) + ": " + xml.getAttributeValue(i));

                        //We need both uiOptions and name attributes
                        String attrName = xml.getAttributeName(i);
                        if ("logo".equals(attrName)) {
                            activityLogo = xml.getAttributeResourceValue(i, 0);
                        } else if ("name".equals(attrName)) {
                            activityPackage = ActionBarSherlockCompat.cleanActivityName(packageName, xml.getAttributeValue(i));
                            if (!thisPackage.equals(activityPackage)) {
                                break; //on to the next
                            }
                            isOurActivity = true;
                        }

                        //Make sure we have both attributes before processing
                        if ((activityLogo != null) && (activityPackage != null)) {
                            //Our activity, logo specified, override with our value
                            logo = activityLogo.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 (ActionBarSherlock.DEBUG) Log.i(TAG, "Returning " + Integer.toHexString(logo));
    return logo;
}
 
Example 19
Source Project: Lucid-Browser   File: SettingsV2.java    License: Apache License 2.0 4 votes vote down vote up
static void clearBrowsingTrace(String trace, Activity activity) {
	ApplicationInfo appInfo = activity.getApplicationInfo();
	switch (trace) {
		case "cache":
			new WebView(activity).clearCache(true);
			DeleteRecursive(new File(appInfo.dataDir + "/app_webview/Cache/"));
			DeleteRecursive(new File(appInfo.dataDir + "/app_webview/GPUCache/"));
			DeleteRecursive(new File(appInfo.dataDir + "/app_webview/Service Worker/CacheStorage"));
			DeleteRecursive(new File(appInfo.dataDir + "/app_webview/Service Worker/ScriptCache"));
			DeleteRecursive(new File(appInfo.dataDir + "/app_webview/Local Storage/"));
			DeleteRecursive(new File(appInfo.dataDir + "/cache/"));

			break;
		case "cookies":
			DeleteRecursive(new File(appInfo.dataDir + "/databases/webviewCookiesChromium.db"));
			DeleteRecursive(new File(appInfo.dataDir + "/databases/webviewCookiesChromiumPrivate.db"));
			DeleteRecursive(new File(appInfo.dataDir + "/app_webview/Cookies"));
			DeleteRecursive(new File(appInfo.dataDir + "/app_webview/Cookies-journal"));

			break;
		case "history":
			//DeleteRecursive(new File(appInfo.dataDir+"/databases/webview.db"));
			DeleteRecursive(new File(appInfo.dataDir + "/databases/webview.db-shm"));
			DeleteRecursive(new File(appInfo.dataDir + "/databases/webview.db-wal"));
			DeleteRecursive(new File(appInfo.dataDir + "/app_webview/databases"));
			DeleteRecursive(new File(appInfo.dataDir + "/app_webview/IndexedDB"));
			DeleteRecursive(new File(appInfo.dataDir + "/app_webview/Web Data"));
			DeleteRecursive(new File(appInfo.dataDir + "/app_webview/Service Worker/Database"));
			DeleteRecursive(new File(appInfo.dataDir + "/app_webview/Web Data-journal"));
			DeleteRecursive(new File(appInfo.dataDir + "/app_webview/QuotaManager"));
			DeleteRecursive(new File(appInfo.dataDir + "/app_webview/QuotaManager-journal"));
			break;
		case "all":
			clearBrowsingTrace("cache", activity);
			clearBrowsingTrace("cookies", activity);
			clearBrowsingTrace("history", activity);

			break;
		default:
			System.err
					.println("clearBrowsingTrace(String trace) did nothing. Wrong parameter was given");
			break;
	}
}
 
Example 20
private static int loadUiOptionsFromManifest(Activity activity) {
    int uiOptions = 0;
    try {
        final String thisPackage = activity.getClass().getName();
        if (ActionBarSherlock.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 (ActionBarSherlock.DEBUG) Log.d(TAG, "Got <application>");

                    for (int i = xml.getAttributeCount() - 1; i >= 0; i--) {
                        if (ActionBarSherlock.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 (ActionBarSherlock.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 (ActionBarSherlock.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 (ActionBarSherlock.DEBUG) Log.i(TAG, "Returning " + Integer.toHexString(uiOptions));
    return uiOptions;
}