release notes + welcome window

This commit is contained in:
Sergey Solovyev
2011-12-25 02:54:47 +04:00
parent 53caff263c
commit 4a2511b93c
19 changed files with 382 additions and 44 deletions

View File

@@ -6,6 +6,10 @@
package org.solovyev.android.view.prefs;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
@@ -52,4 +56,37 @@ public final class AndroidUtils {
}
}
}
public static void addTab(@NotNull Context context,
@NotNull TabHost tabHost,
@NotNull String tabId,
int tabCaptionId,
@NotNull Class<? extends Activity> activityClass) {
TabHost.TabSpec spec;
final Intent intent = new Intent().setClass(context, activityClass);
// Initialize a TabSpec for each tab and add it to the TabHost
spec = tabHost.newTabSpec(tabId).setIndicator(context.getString(tabCaptionId)).setContent(intent);
tabHost.addTab(spec);
}
/**
* @param context context
* @param appPackageName - full name of the package of an app, 'com.example.app' for example.
* @return version number we are currently in
*/
public static int getAppVersionCode(@NotNull Context context, @NotNull String appPackageName) {
try {
return context.getPackageManager().getPackageInfo(appPackageName, 0).versionCode;
} catch (PackageManager.NameNotFoundException e) {
// App not installed!
}
return -1;
}
}

View File

@@ -8,6 +8,7 @@ package org.solovyev.android.view.prefs;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.util.Log;
import android.view.View;
@@ -84,24 +85,43 @@ public enum ResourceCache {
if (!initialized(locale)) {
final Map<String, String> captionsByLanguage = new HashMap<String, String>();
for (Field field : resourceClass.getDeclaredFields()) {
int modifiers = field.getModifiers();
if (Modifier.isFinal(modifiers) && Modifier.isStatic(modifiers)) {
try {
int captionId = field.getInt(resourceClass);
captionsByLanguage.put(field.getName(), context.getString(captionId));
} catch (IllegalAccessException e) {
Log.e(ResourceCache.class.getName(), e.getMessage());
} catch (Resources.NotFoundException e) {
Log.e(ResourceCache.class.getName(), "Caption with name " + field.getName() + " was not found for " + locale.getLanguage() + " language: " + e.getMessage());
final Locale defaultLocale = Locale.getDefault();
try {
if (!defaultLocale.getLanguage().equals(locale.getLanguage())) {
updateConfiguration(context, locale);
}
for (Field field : resourceClass.getDeclaredFields()) {
int modifiers = field.getModifiers();
if (Modifier.isFinal(modifiers) && Modifier.isStatic(modifiers)) {
try {
int captionId = field.getInt(resourceClass);
captionsByLanguage.put(field.getName(), context.getString(captionId));
} catch (IllegalAccessException e) {
Log.e(ResourceCache.class.getName(), e.getMessage());
} catch (Resources.NotFoundException e) {
Log.e(ResourceCache.class.getName(), "Caption with name " + field.getName() + " was not found for " + locale.getLanguage() + " language: " + e.getMessage());
}
}
}
} finally {
if (!defaultLocale.getLanguage().equals(locale.getLanguage())) {
updateConfiguration(context, defaultLocale);
}
}
captions.put(locale.getLanguage(), captionsByLanguage);
}
}
private static void updateConfiguration(@NotNull Context context, @NotNull Locale locale) {
Locale.setDefault(locale);
final Configuration config = new Configuration();
config.locale = locale;
context.getResources().updateConfiguration(config, context.getResources().getDisplayMetrics());
}
private boolean initialized(@NotNull Locale locale) {
return captions.containsKey(locale.getLanguage());
}