plotting
This commit is contained in:
@@ -29,6 +29,8 @@ public class AutoResizeTextView extends TextView {
|
||||
// Minimum text size for this text view
|
||||
public static final float MIN_TEXT_SIZE = 20;
|
||||
|
||||
private float initialTextSize = 100;
|
||||
|
||||
// Interface for resize notifications
|
||||
public interface OnTextResizeListener {
|
||||
public void onTextResize(TextView textView, float oldSize, float newSize);
|
||||
@@ -207,7 +209,8 @@ public class AutoResizeTextView extends TextView {
|
||||
Log.d(this.getClass().getName(), "Old text size: " + oldTextSize);
|
||||
|
||||
// If there is a max text size set, use the lesser of that and the default text size
|
||||
float newTextSize = 100;
|
||||
// todo serso: +2 is a workaround => to be checked boundary constraints
|
||||
float newTextSize = initialTextSize + 2;
|
||||
|
||||
int newTextHeight;
|
||||
|
||||
@@ -227,7 +230,7 @@ public class AutoResizeTextView extends TextView {
|
||||
if (newTextSize <= minTextSize) {
|
||||
break;
|
||||
}
|
||||
newTextSize = Math.max(newTextSize - 2, minTextSize);
|
||||
newTextSize = Math.max(newTextSize - 1, minTextSize);
|
||||
newTextHeight = getTextRect(text, textPaint, width, newTextSize);
|
||||
logDimensions(newTextSize, newTextHeight);
|
||||
}
|
||||
@@ -236,7 +239,7 @@ public class AutoResizeTextView extends TextView {
|
||||
if (newTextSize <= minTextSize) {
|
||||
break;
|
||||
}
|
||||
newTextSize = Math.max(newTextSize + 2, minTextSize);
|
||||
newTextSize = Math.max(newTextSize + 1, minTextSize);
|
||||
newTextHeight = getTextRect(text, textPaint, width, newTextSize);
|
||||
logDimensions(newTextSize, newTextHeight);
|
||||
}
|
||||
@@ -247,6 +250,8 @@ public class AutoResizeTextView extends TextView {
|
||||
}
|
||||
}
|
||||
|
||||
initialTextSize = newTextSize;
|
||||
|
||||
// If we had reached our minimum text size and still don't fit, append an ellipsis
|
||||
if (addEllipsis && newTextSize == minTextSize && newTextHeight > height) {
|
||||
// Draw using a static layout
|
||||
|
@@ -7,11 +7,14 @@
|
||||
package org.solovyev.android.view.prefs;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.solovyev.android.calculator.CalculatorActivity;
|
||||
import org.solovyev.android.view.widgets.DragButton;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@@ -33,7 +36,13 @@ public enum ResourceCache {
|
||||
// ids of buttons in R.class
|
||||
private List<Integer> buttonIds = null;
|
||||
|
||||
private static final Map<String, Map<String, String>> captions = new HashMap<String, Map<String, String>>();
|
||||
// first map: key: language id, value: map of captions and translations
|
||||
// second mal: key: caption id, value: translation
|
||||
private final Map<String, Map<String, String>> captions = new HashMap<String, Map<String, String>>();
|
||||
|
||||
private Class<?> resourceClass;
|
||||
|
||||
private Context context;
|
||||
|
||||
public List<Integer> getDragButtonIds() {
|
||||
return dragButtonIds;
|
||||
@@ -43,11 +52,28 @@ public enum ResourceCache {
|
||||
return buttonIds;
|
||||
}
|
||||
|
||||
public void initCaptions(@NotNull Class<?> resourceClass, @NotNull Activity activity) {
|
||||
final Locale locale = Locale.getDefault();
|
||||
/**
|
||||
* Method load captions for default locale using android R class
|
||||
* @param context STATIC CONTEXT
|
||||
* @param resourceClass class of captions in android (SUBCLASS of R class)
|
||||
*/
|
||||
public void initCaptions(@NotNull Context context, @NotNull Class<?> resourceClass) {
|
||||
initCaptions(context, resourceClass, Locale.getDefault());
|
||||
}
|
||||
|
||||
if (!captions.containsKey(locale.getLanguage())) {
|
||||
/**
|
||||
* Method load captions for specified locale using android R class
|
||||
* @param context STATIC CONTEXT
|
||||
* @param resourceClass class of captions in android (SUBCLASS of R class)
|
||||
* @param locale language to be used for translation
|
||||
*/
|
||||
public void initCaptions(@NotNull Context context, @NotNull Class<?> resourceClass, @NotNull Locale locale) {
|
||||
assert this.resourceClass == null || this.resourceClass.equals(resourceClass);
|
||||
|
||||
this.context = context;
|
||||
this.resourceClass = resourceClass;
|
||||
|
||||
if (!initialized(locale)) {
|
||||
final Map<String, String> captionsByLanguage = new HashMap<String, String>();
|
||||
|
||||
for (Field field : resourceClass.getDeclaredFields()) {
|
||||
@@ -55,7 +81,7 @@ public enum ResourceCache {
|
||||
if (Modifier.isFinal(modifiers) && Modifier.isStatic(modifiers)) {
|
||||
try {
|
||||
int captionId = field.getInt(resourceClass);
|
||||
captionsByLanguage.put(field.getName(), activity.getString(captionId));
|
||||
captionsByLanguage.put(field.getName(), context.getString(captionId));
|
||||
} catch (IllegalAccessException e) {
|
||||
Log.e(ResourceCache.class.getName(), e.getMessage());
|
||||
}
|
||||
@@ -66,13 +92,39 @@ public enum ResourceCache {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean initialized(@NotNull Locale locale) {
|
||||
return captions.containsKey(locale.getLanguage());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param captionId id of caption to be translated
|
||||
* @return translation by caption id in default language, null if no translation in default language present
|
||||
*/
|
||||
@Nullable
|
||||
public String getCaption(@NotNull String captionId) {
|
||||
final Locale locale = Locale.getDefault();
|
||||
return getCaption(captionId, Locale.getDefault());
|
||||
}
|
||||
|
||||
final Map<String, String> captionsByLanguage = captions.get(locale.getLanguage());
|
||||
|
||||
/**
|
||||
* @param captionId id of caption to be translated
|
||||
* @param locale language to be used for translation
|
||||
* @return translation by caption id in specified language, null if no translation in specified language present
|
||||
*/
|
||||
@Nullable
|
||||
public String getCaption(@NotNull String captionId, @NotNull final Locale locale) {
|
||||
Map<String, String> captionsByLanguage = captions.get(locale.getLanguage());
|
||||
if (captionsByLanguage != null) {
|
||||
return captionsByLanguage.get(captionId);
|
||||
} else {
|
||||
assert resourceClass != null && context != null;
|
||||
|
||||
initCaptions(context, resourceClass, locale);
|
||||
|
||||
captionsByLanguage = captions.get(locale.getLanguage());
|
||||
if (captionsByLanguage != null) {
|
||||
return captionsByLanguage.get(captionId);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
|
@@ -412,7 +412,7 @@ public class NumberPicker extends LinearLayout {
|
||||
}
|
||||
|
||||
private static final char[] DIGIT_CHARACTERS = new char[] {
|
||||
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
|
||||
'-', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
|
||||
};
|
||||
|
||||
private NumberPickerButton mIncrementButton;
|
||||
|
Reference in New Issue
Block a user