Replace graphic accent diacritic Java Function
Replace diacritic marks: Á Č Ď É Ě Í Ň Ó Ř Š Ť Ú Ů Ý Ž
á č ď é ě í ň ó ř š ť ú ů ý ž
á č ď é ě í ň ó ř š ť ú ů ý ž
public String replaceDiacritic (String inputStr) {
Map<String, String> replacements = new LinkedHashMap<String,String>() {{
//Velká
put("Á","A");
put("Č","C");
put("Ď","D");
put("É","E");
put("Ě","E");
put("Í","I");
put("Ň","N");
put("Ó","O");
put("Ř","R");
put("Š","S");
put("Ť","T");
put("Ú","U");
put("Ů","U");
put("Ý","Y");
put("Ž","Z");
//Malá "," ");
put("á","a");
put("č","c");
put("ď","d");
put("é","e");
put("ě","e");
put("í","i");
put("ň","n");
put("ó","o");
put("ř","r");
put("š","s");
put("ť","t");
put("ú","u");
put("ů","u");
put("ý","y");
put("ž","z");
}
};
for(Map.Entry<String, String> entry : replacements.entrySet()) {
inputStr = inputStr.replaceAll(entry.getKey(), entry.getValue());
}
return inputStr;
}
396LW NO topic_id
AD
Další témata ....(Topics)
Spinner, ArrayAdapter, setOnItemSelectedListener, onItemSelected, setDropDownViewResource
MainClass.java
strings.xml
MainClass.java
public class Vypocet extends Activity {
Spinner hSpinnerMetry;
// .......
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
hSpinnerMetry = (Spinner) findViewById(R.id.idSpinnerMetry);
ArrayAdapter<CharSequence> adapterMetry = ArrayAdapter.createFromResource(
this, R.array.metry_array, android.R.layout.simple_spinner_item);
adapterMetry.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
hSpinnerMetry.setAdapter(adapterMetry);
hSpinnerMetry.setOnItemSelectedListener(
new OnItemSelectedListener() {
public void onItemSelected(
AdapterView<?> parent, View view, int position, long id) {
int nPos = position;
}
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
}
strings.xml
<string-array name="metry_array">
<item>m</item>
<item>dm</item>
<item>cm</item>
<item>mm</item>
</string-array>
Error for example:
webcoreglue(2075): The real object has been deleted
Solution:
If this error message shows if orientation the screen is changed
try insert into AndroidManifest.xml this code:
android:configChanges="keyboard|keyboardHidden|orientation"
webcoreglue(2075): The real object has been deleted
Solution:
If this error message shows if orientation the screen is changed
try insert into AndroidManifest.xml this code:
android:configChanges="keyboard|keyboardHidden|orientation"
<activity
android:label="@string/app_name"
android:name=".MyActivity"
android:screenOrientation="portrait"
android:configChanges="keyboard|keyboardHidden|orientation"
>
Bitmap size calculation:
bmpHeight * bmpWidth
For example:
Resolution of image 1024x860 = 880 640 pixels
If every pixel get 4 byte of memory:
880 640x4= 3 522 560 (3.5MB)
Get bitmap size without allocation of memory:
Get Memory size:
Make your bitmap not bigger as maxMemory size
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
bmpHeight * bmpWidth
For example:
Resolution of image 1024x860 = 880 640 pixels
If every pixel get 4 byte of memory:
880 640x4= 3 522 560 (3.5MB)
Get bitmap size without allocation of memory:
BitmapFactory.Options options = new BitmapFactory.Options();
// If set to true, the decoder will return null (no bitmap), but the out... fields will still
// be set, allowing the caller to query the bitmap without having to allocate the memory for its pixels.
options.inJustDecodeBounds = true;
BitmapFactory.decodeResource(getResources(), R.drawable.my_image, options);
int imageHeight = options.outHeight; // 1024
int imageWidth = options.outWidth; // 860
String imageType = options.outMimeType; // .jpg .png .gif
Get Memory size:
Make your bitmap not bigger as maxMemory size
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
float density = getResources().getDisplayMetrics().density;
Debug.MemoryInfo memoryInfo = new Debug.MemoryInfo();
Debug.getMemoryInfo(memoryInfo);
final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
final int freeMemory = (int) (Runtime.getRuntime().freeMemory() / 1024);
String memMessage = String.format(
"Free=%d kB,
MaxMem=%d kB,
Memory: Pss=%.2f MB, Private=%.2f MB, Shared=%.2f MB",
freeMemory,
maxMemory,
memoryInfo.getTotalPss() / 1024.0,
memoryInfo.getTotalPrivateDirty() / 1024.0,
memoryInfo.getTotalSharedDirty() / 1024.0);
((TextView)findViewById(R.id.textViewInfo)).setText(memMessage );
public class MainActivity extends Activity {
// //www.apache.org/licenses/LICENSE-2.0
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new SampleView(this));
}
private static class SampleView extends View {
private Rect mRect;
private GradientDrawable mDrawable;
public SampleView(Context context) {
super(context);
setFocusable(true);
mRect = new Rect(0, 0, 220, 120);
/* GradientDrawable.Orientation BL_TR draw the gradient from the bottom-left to the top-right
BOTTOM_TOP draw the gradient from the bottom to the top
BR_TL draw the gradient from the bottom-right to the top-left
LEFT_RIGHT draw the gradient from the left to the right
RIGHT_LEFT draw the gradient from the right to the left
TL_BR draw the gradient from the top-left to the bottom-right
TOP_BOTTOM draw the gradient from the top to the bottom
TR_BL draw the gradient from the top-right to the bottom-left
*/
mDrawable = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT,
new int[] { 0xFFFF0000, 0xFF00FF00,
0xFF0000FF });
mDrawable.setShape(GradientDrawable.RECTANGLE);
mDrawable.setGradientRadius((float)(Math.sqrt(2) * 60));
}
static void setCornerRadius(GradientDrawable drawable, float r0,
float r1, float r2, float r3) {
/* setCornerRadii
Specify radii for each of the 4 corners. For each corner,
the array contains 2 values, [X_radius, Y_radius].
The corners are ordered top-left, top-right, bottom-right,
bottom-left
*/
drawable.setCornerRadii(new float[] { r0, r0, r1, r1,
r2, r2, r3, r3 });
}
@Override protected void onDraw(Canvas canvas) {
mDrawable.setBounds(mRect);
float r = 35;
canvas.save();
canvas.translate(10, 10);
mDrawable.setGradientType(GradientDrawable.LINEAR_GRADIENT);
setCornerRadius(mDrawable, r, r, 0, 0);
mDrawable.draw(canvas);
canvas.restore();
canvas.translate(0, mRect.height() + 10);
canvas.save();
canvas.translate(10, 10);
mDrawable.setGradientType(GradientDrawable.RADIAL_GRADIENT);
setCornerRadius(mDrawable, 0, 0, r, r);
mDrawable.draw(canvas);
canvas.restore();
canvas.translate(0, mRect.height() + 10);
canvas.save();
canvas.translate(10, 10);
mDrawable.setGradientType(GradientDrawable.SWEEP_GRADIENT);
setCornerRadius(mDrawable, 0, r, r, 0);
mDrawable.draw(canvas);
canvas.restore();
}
}
}
Constructor SimpleCursorAdapter is deprecated.
If using api 11 and above, you can try add last parameter 0.
If using api 11 and above, you can try add last parameter 0.
Cursor cursor = managedQuery(...........,,,,);
// Specify the columns we want to display in the result
String[] from = new String[] { KEY_WORD,
KEY_DEFINITION };
// Specify the corresponding layout elements where we want the columns to go
int[] to = new int[] { R.id.word,
R.id.definition };
// deprecated
SimpleCursorAdapter words =
new SimpleCursorAdapter(this,
R.layout.result, cursor, from, to);
// working
SimpleCursorAdapter words =
new SimpleCursorAdapter(this,
R.layout.result, cursor, from, to, 0); // to, 0!!!!
//working in Fragment
SimpleCursorAdapter mAdapter = new SimpleCursorAdapter(getActivity(),
android.R.layout.simple_list_item_2, null,
new String[] { "name", "age" }, // cursor parameters
new int[] { android.R.id.text1, android.R.id.text2 }, 0);
Editace: 2013-01-02 12:12:34
Počet článků v kategorii: 396
Url:replace-graphic-accent-java-function