Skip to content

Commit

Permalink
Add examples Activities for conversion on background thread, Fix race…
Browse files Browse the repository at this point in the history
… problems in MMTextView initalization, readd licenese that was wrongly removed due to update in gitignore
  • Loading branch information
vincent-paing committed Jul 16, 2018
1 parent 4aa6174 commit ee5fd73
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 53 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,3 @@ captures/

# Keystore files
*.jks

LICENSE
README.md
21 changes: 21 additions & 0 deletions License.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2016 Myat Min Soe

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".LargeTextActivity"/>
</application>

</manifest>
40 changes: 40 additions & 0 deletions app/src/main/java/me/myatminsoe/mdetectsample/LargeTextActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package me.myatminsoe.mdetectsample

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.TextView
import me.myatminsoe.mdetect.MMTextView

class LargeTextActivity : AppCompatActivity() {

companion object {

private const val IE_ENABLE_BACKGROUND_CONVERT = "IE_ENABLE_BACKGROUND_CONVERT"

fun newIntent(context: Context, enableBackgroundConvert: Boolean): Intent {
val intent = Intent(context, LargeTextActivity::class.java)
intent.putExtra(IE_ENABLE_BACKGROUND_CONVERT, enableBackgroundConvert)
return intent
}
}

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_large_text)

supportActionBar?.setDisplayHomeAsUpEnabled(true)
val enableBackgroundConvert = intent.getBooleanExtra(IE_ENABLE_BACKGROUND_CONVERT, true)

val textView = findViewById<MMTextView>(R.id.tvLargeText)
val string = getString(R.string.large_text)
if (enableBackgroundConvert) {
textView.setMMText(string)
} else {
textView.setMMText(string, null)
}

}
}

71 changes: 48 additions & 23 deletions app/src/main/java/me/myatminsoe/mdetectsample/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,59 @@ import me.myatminsoe.mdetect.MMToast

class MainActivity : AppCompatActivity() {

private val items = arrayOf("ဧရာဝတီတိုင်းဒေသကြီး","ပဲခူးတိုင်းဒေသကြီး","ချင်းပြည်နယ်","ကချင်ပြည်နယ်","ကယားပြည်နယ်","ကရင်ပြည်နယ်","မကွေးတိုင်းဒေသကြီး","မန္တလေးတိုင်းဒေသကြီး","မွန်ပြည်နယ်","ရခိုင်ပြည်နယ်","ရှမ်းပြည်နယ်","စစ်ကိုင်းတိုင်းဒေသကြီး","တနင်္သာရီတိုင်းဒေသကြီး","ရန်ကုန်တိုင်းဒေသကြီး","နေပြည်တော် ပြည်ထောင်စုနယ်မြေ")
private val items = arrayOf(
"ဧရာဝတီတိုင်းဒေသကြီး",
"ပဲခူးတိုင်းဒေသကြီး",
"ချင်းပြည်နယ်",
"ကချင်ပြည်နယ်",
"ကယားပြည်နယ်",
"ကရင်ပြည်နယ်",
"မကွေးတိုင်းဒေသကြီး",
"မန္တလေးတိုင်းဒေသကြီး",
"မွန်ပြည်နယ်",
"ရခိုင်ပြည်နယ်",
"ရှမ်းပြည်နယ်",
"စစ်ကိုင်းတိုင်းဒေသကြီး",
"တနင်္သာရီတိုင်းဒေသကြီး",
"ရန်ကုန်တိုင်းဒေသကြီး",
"နေပြည်တော် ပြည်ထောင်စုနယ်မြေ"
)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

val tv = findViewById(R.id.tv_main) as MMTextView
val tv = findViewById<MMTextView>(R.id.tv_main)

title = MDetect.getText("မြန်မာ")

if (MDetect.isUnicode()) {
tv.text = "ယူနီကုဒ်စနစ်ကိုအသုံးပြုထားပါသည်။"
tv.setTextColor(resources.getColor(R.color.green_500))
} else {
tv.text = "ေဇာ္ဂ်ီစနစ္ကိုအသံုးျပဳထားပါသည္။"
tv.setTextColor(resources.getColor(R.color.red_500))
}
title = MDetect.getText("မြန်မာ")

if (MDetect.isUnicode()) {
tv.text = "ယူနီကုဒ်စနစ်ကိုအသုံးပြုထားပါသည်။"
tv.setTextColor(resources.getColor(R.color.green_500))
} else {
tv.text = "ေဇာ္ဂ်ီစနစ္ကိုအသံုးျပဳထားပါသည္။"
tv.setTextColor(resources.getColor(R.color.red_500))
}

fun divisions(v: View) {
val builder = AlertDialog.Builder(this)
builder.setItems(MDetect.getStringArray(items)) { dialog, which ->
(v as MMButtonView).setMMText(items[which])
}.show()
}
}

fun divisions(v: View) {
val builder = AlertDialog.Builder(this)
builder.setItems(MDetect.getStringArray(items)) { dialog, which ->
(v as MMButtonView).setMMText(items[which])
}.show()
}

fun showMyanmarToast(v: View) {
MMToast.showShortToast(this, "မင်္ဂလာပါ")
}

fun foreground(v: View) {
startActivity(LargeTextActivity.newIntent(this, false))
}

fun background(v: View) {
startActivity(LargeTextActivity.newIntent(this, true))
}

fun showMyanmarToast(v: View) {
MMToast.showShortToast(this, "မင်္ဂလာပါ")
}
}
23 changes: 23 additions & 0 deletions app/src/main/res/layout/activity_large_text.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>


<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>

<me.myatminsoe.mdetect.MMTextView
android:id="@+id/tvLargeText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>


</LinearLayout>

</ScrollView>
52 changes: 35 additions & 17 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,43 @@
android:layout_height="match_parent"
android:gravity="center_horizontal"
android:orientation="vertical"
android:padding="16dp">
android:padding="16dp"
>

<me.myatminsoe.mdetect.MMTextView
android:id="@+id/tv_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp"
android:textAppearance="@android:style/TextAppearance.Large" />
<me.myatminsoe.mdetect.MMTextView
android:id="@+id/tv_main"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp"
android:textAppearance="@android:style/TextAppearance.Large"
/>

<me.myatminsoe.mdetect.MMButtonView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="showMyanmarToast"
android:text="တို့(စ်)ထုတ်ရန်" />
<me.myatminsoe.mdetect.MMButtonView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="showMyanmarToast"
android:text="တို့(စ်)ထုတ်ရန်"
/>

<me.myatminsoe.mdetect.MMButtonView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="divisions"
android:text="@string/divisions" />
<me.myatminsoe.mdetect.MMButtonView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="divisions"
android:text="@string/divisions"
/>

<me.myatminsoe.mdetect.MMButtonView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="background"
android:text="@string/try_background"
/>

<me.myatminsoe.mdetect.MMButtonView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="foreground"
android:text="@string/try_foreground"
/>

</LinearLayout>
Loading

0 comments on commit ee5fd73

Please sign in to comment.