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)
Read file from URL to array of byte and convert to UTF-8 String Android examle source code.
URL urlLoc = new URL("//myweb.com/myfile.html");
URLConnection conexion = urlLoc.openConnection();
conexion.setConnectTimeout(4000);
conexion.setReadTimeout(1000);
conexion.connect();
// downlod the file
InputStream input = new BufferedInputStream(urlLoc
.openStream());
StringBuffer responseBuffer = new StringBuffer();
byte[] byteArray = new byte[1024];
while (input.read(byteArray) != -1)
{
String res = new String(byteArray, "UTF-8");
responseBuffer.append(res);
byteArray = null;
byteArray = new byte[1024];
}
String response = responseBuffer.toString().trim();
Try convert WAV file to MP3 format for example by Audacity sound editor and replay:
//audacity.sourceforge.net/help/faq_i18n?s=install&i=lame-mp3
//audacity.sourceforge.net/help/faq_i18n?s=install&i=lame-mp3
MediaPlayer mp = MediaPlayer.create(getApplicationContext(), R.raw.mymp3file);
mp.setLooping(true);
mp.start();
Example from SDK C:\Program Files\Android\android-sdk-windows\samples\android-10\ApiDemos\src\com\example\android\apis\text\Link.java
Source: //developer.android.com/resources/browser.html?tag=sample
License: //www.apache.org/licenses/LICENSE-2.0
1.) Automatically linkifies using android:autoLink="all"
2.) Link text by setMovementMethod
3.) Link as html code using Html.fromHtml()
4.) Link string by SpannableString
Source: //developer.android.com/resources/browser.html?tag=sample
License: //www.apache.org/licenses/LICENSE-2.0
1.) Automatically linkifies using android:autoLink="all"
// res/values/strings.xml
<string name="link_text_auto"><b>text1:</b> This is some text. In
this text are some things that are actionable. For instance,
you can click on //www.google.com and it will launch the
web browser. You can click on google.com too. And, if you
click on (415) 555-1212 it should dial the phone.
</string>
// main.xml
<!-- text1 automatically linkifies things like URLs and phone numbers. -->
<TextView xmlns:android="//schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:autoLink="all"
android:text="@string/link_text_auto"
/>
2.) Link text by setMovementMethod
// MainActivity.java onCreate
/*Be warned that if you want a TextView with a key listener or movement method not to be focusable, or if you want a TextView without a key listener or movement method to be focusable, you must call setFocusable(boolean) again after calling this to get the focusability back the way you want it. */
TextView t2 = (TextView) findViewById(R.id.text2);
t2.setMovementMethod(LinkMovementMethod.getInstance());
// main.xml
<!-- text2 uses a string resource containing explicit <a> tags to
specify links. -->
<TextView xmlns:android="//schemas.android.com/apk/res/android"
android:id="@+id/text2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/link_text_manual"
/>
//strings.xml
<string name="link_text_manual"><b>text2:</b> This is some other
text, with a <a href="//www.google.com">link</a> specified
via an <a> tag. Use a "tel:" URL
to <a href="tel:4155551212">dial a phone number</a>.
</string>
3.) Link as html code using Html.fromHtml()
// MainActivity.java onCreate
TextView t3 = (TextView) findViewById(R.id.text3);
t3.setText(
Html.fromHtml(
"<b>text3:</b> Text with a " +
"<a href="//www.google.com">link</a> " +
"created in the Java source code using HTML."));
t3.setMovementMethod(LinkMovementMethod.getInstance());
4.) Link string by SpannableString
SpannableString ss = new SpannableString(
"text4: Click here to dial the phone.");
ss.setSpan(new StyleSpan(Typeface.BOLD), 0, 6,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(new URLSpan("tel:4155551212"), 13, 17,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
TextView t4 = (TextView) findViewById(R.id.text4);
t4.setText(ss);
t4.setMovementMethod(LinkMovementMethod.getInstance());
AlertDialog like MessageBox by WinApi:
If error: Unable to add window -- token null is not for an application
try change get Context.
If error: Unable to add window -- token null is not for an application
try change get Context.
// you can put this text into some function body or case in switch statement
new AlertDialog.Builder(this)
.setMessage("Hello boys!!!")
.setPositiveButton("OK", null)
.show();
Context context = getApplicationContext();
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle("Select font size");
final CharSequence[] chsSize= { "Small", "Medium", "Large"};
builder.setSingleChoiceItems(chsSize, 0 /*sel.item*/,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(context, "Hello from dialog!!!", Toast.LENGTH_SHORT).show();
dialog.dismiss();
}
});
AlertDialog alert = builder.create();
alert.show();
Set in AndroidManifest.xml android:theme="@android:style/Theme.NoTitleBar" AndroidManifest.xml example source code.
AndroidManifest.xml
AndroidManifest.xml
<manifest xmlns:android="//schemas.android.com/apk/res/android"
package="com.myexample.without_titlebar">
<application android:label="My app">
<activity android:name="NoTitleBar"
android:theme="@android:style/Theme.NoTitleBar"
android:screenOrientation="portrait"
android:configChanges="keyboardHidden|orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Editace: 2013-01-02 12:12:34
Počet článků v kategorii: 396
Url:replace-graphic-accent-java-function