If you think the Android project opensudoku listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package org.moire.opensudoku.utils;
//fromwww.java2s.comimport java.util.List;
import org.moire.opensudoku.R;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.preference.PreferenceManager;
publicclass AndroidUtils {
/**
* Indicates whether the specified action can be used as an intent. This
* method queries the package manager for installed packages that can
* respond to an intent with the specified action. If no suitable package is
* found, this method returns false.
*
* @param context The application's environment.
* @param action The Intent action to check for availability.
* @return True if an Intent with the specified action can be sent and
* responded to, false otherwise.
*/publicstaticboolean isIntentAvailable(Context context, String action) {
final PackageManager packageManager = context.getPackageManager();
final Intent intent = new Intent(action);
List<ResolveInfo> list =
packageManager.queryIntentActivities(intent,
PackageManager.MATCH_DEFAULT_ONLY);
return list.size() > 0;
}
publicstaticvoid setThemeFromPreferences(Context context) {
SharedPreferences gameSettings = PreferenceManager.getDefaultSharedPreferences(context);
String theme = gameSettings.getString("theme", "default");
if (theme.equals("default")) {
context.setTheme(R.style.Theme_Default);
} elseif (theme.equals("paperi")) {
context.setTheme(R.style.Theme_PaperI);
} elseif (theme.equals("paperii")) {
context.setTheme(R.style.Theme_PaperII);
} else {
context.setTheme(R.style.Theme_Default);
}
}
/**
* Returns version code of OpenSudoku.
*
* @return
*/publicstaticint getAppVersionCode(Context context) {
try {
return context.getPackageManager().getPackageInfo(
context.getPackageName(), 0).versionCode;
} catch (NameNotFoundException e) {
thrownew RuntimeException(e);
}
}
/**
* Returns version name of OpenSudoku.
*
* @return
*/publicstatic String getAppVersionName(Context context) {
try {
return context.getPackageManager().getPackageInfo(
context.getPackageName(), 0).versionName;
} catch (NameNotFoundException e) {
thrownew RuntimeException(e);
}
}
}