kopia lustrzana https://github.com/ge0rg/aprsdroid
prefs: symbol picker, fix #118
rodzic
78ca04995c
commit
ae1902ac0e
|
@ -72,6 +72,9 @@
|
|||
<activity android:name=".BackendPrefs" android:label="@string/app_prefs"
|
||||
android:parentActivityName=".PrefsAct"
|
||||
/>
|
||||
<activity android:name=".PrefSymbolAct" android:label="@string/p_symbol"
|
||||
android:parentActivityName=".PrefsAct"
|
||||
/>
|
||||
<activity android:name=".LocationPrefs" android:label="@string/app_prefs"
|
||||
android:parentActivityName=".PrefsAct"
|
||||
android:launchMode="singleTop"
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
>
|
||||
<GridView
|
||||
android:id="@+id/gridview"
|
||||
android:columnWidth="64dp"
|
||||
android:numColumns="auto_fit"
|
||||
android:verticalSpacing="16dp"
|
||||
android:horizontalSpacing="16dp"
|
||||
android:stretchMode="columnWidth"
|
||||
android:gravity="center"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="100sp"
|
||||
android:layout_weight="1"
|
||||
/>
|
||||
<LinearLayout
|
||||
android:id="@+id/buttonlayout"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="4sp"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
>
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="4sp"
|
||||
android:textSize="16sp"
|
||||
android:text="@string/p_symbol_overlay"/>
|
||||
<EditText android:id="@+id/overlay"
|
||||
android:layout_width="20sp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textSize="16sp"
|
||||
android:maxLength="1"
|
||||
android:inputType="textCapCharacters"
|
||||
android:digits="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
|
||||
android:text="" />
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="4sp"
|
||||
android:textSize="16sp"
|
||||
android:text="@string/p_symbol_result"/>
|
||||
<org.aprsdroid.app.SymbolView android:id="@+id/symbol"
|
||||
android:padding="4sp"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
/>
|
||||
</LinearLayout>
|
||||
<Button android:id="@+id/ok"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:onClick="onOkClicked"
|
||||
android:text="@android:string/ok"
|
||||
/>
|
||||
|
||||
</LinearLayout>
|
|
@ -161,7 +161,8 @@
|
|||
</string-array>
|
||||
<string name="p_symbol">APRS symbol</string>
|
||||
<string name="p_symbol_summary">Your symbol for map display</string>
|
||||
<string name="p_symbol_entry">Enter the symbol encoded as two characters</string>
|
||||
<string name="p_symbol_overlay">Overlay:</string>
|
||||
<string name="p_symbol_result">Result:</string>
|
||||
<string name="p_status">Comment field</string>
|
||||
<string name="p_status_summary">The text after your coordinates</string>
|
||||
<string name="p_status_entry">Enter your beacon comment</string>
|
||||
|
|
|
@ -49,13 +49,14 @@
|
|||
|
||||
<PreferenceCategory
|
||||
android:title="@string/p__position">
|
||||
<de.duenndns.EditTextPreferenceWithValue
|
||||
android:key="symbol"
|
||||
android:hint="@string/default_symbol"
|
||||
android:title="@string/p_symbol"
|
||||
android:summary="@string/p_symbol_summary"
|
||||
android:defaultValue="@string/default_symbol"
|
||||
android:dialogTitle="@string/p_symbol_entry" />
|
||||
<PreferenceScreen
|
||||
android:title="@string/p_symbol"
|
||||
android:summary="@string/p_symbol_summary" >
|
||||
|
||||
<intent android:action="android.intent.action.MAIN"
|
||||
android:targetPackage="org.aprsdroid.app"
|
||||
android:targetClass="org.aprsdroid.app.PrefSymbolAct" />
|
||||
</PreferenceScreen>
|
||||
|
||||
<de.duenndns.EditTextPreferenceWithValue
|
||||
android:key="status"
|
||||
|
|
|
@ -0,0 +1,102 @@
|
|||
package org.aprsdroid.app
|
||||
|
||||
import _root_.android.app.Activity
|
||||
import _root_.android.content.Context
|
||||
import _root_.android.os.Bundle
|
||||
import _root_.android.text.{Editable, TextWatcher}
|
||||
import _root_.android.view.{View, ViewGroup}
|
||||
import _root_.android.util.TypedValue
|
||||
import _root_.android.widget.{AbsListView, AdapterView, BaseAdapter, EditText, ImageView, GridView}
|
||||
import _root_.android.widget.AdapterView.OnItemClickListener
|
||||
|
||||
class PrefSymbolAct extends Activity with TextWatcher {
|
||||
lazy val overlayedit = findViewById(R.id.overlay).asInstanceOf[EditText]
|
||||
lazy val symbolview = findViewById(R.id.symbol).asInstanceOf[SymbolView]
|
||||
lazy val prefs = new PrefsWrapper(this)
|
||||
var chosen_sym : String = ""
|
||||
|
||||
val OVERLAYABLE = "#&0>A^_acnsuvz"
|
||||
|
||||
def overlayAllowed(symbol : String) = {
|
||||
symbol(0) != '/' && OVERLAYABLE.contains(symbol(1))
|
||||
}
|
||||
|
||||
def setSymbol(symbol : String) {
|
||||
val ov_en = overlayAllowed(symbol)
|
||||
overlayedit.setEnabled(ov_en)
|
||||
|
||||
val ov = overlayedit.getText().toString()
|
||||
if (ov_en && (ov.length == 1)) {
|
||||
chosen_sym = "%c%c".format(ov(0), symbol(1))
|
||||
} else {
|
||||
chosen_sym = symbol
|
||||
}
|
||||
if (chosen_sym.length == 2)
|
||||
symbolview.setSymbol(chosen_sym)
|
||||
else symbolview.setSymbol("/$")
|
||||
}
|
||||
|
||||
override def onCreate(savedInstanceState: Bundle) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.prefsymbol)
|
||||
val gv = findViewById(R.id.gridview).asInstanceOf[GridView]
|
||||
gv.setAdapter(new SymbolAdapter(this))
|
||||
gv.setOnItemClickListener(new OnItemClickListener() {
|
||||
override def onItemClick(av : AdapterView[_], v : View, position : Int, id : Long) {
|
||||
android.util.Log.d("PrefSymbolAct", "tapped " + v.asInstanceOf[SymbolView].symbol)
|
||||
setSymbol(v.asInstanceOf[SymbolView].symbol)
|
||||
}})
|
||||
chosen_sym = prefs.getString("symbol", "/$")
|
||||
if (chosen_sym.length != 2)
|
||||
chosen_sym = "/$"
|
||||
val ov = chosen_sym(0)
|
||||
if (ov != '/' && ov != '\\')
|
||||
overlayedit.setText("" + ov)
|
||||
overlayedit.addTextChangedListener(this)
|
||||
setSymbol(chosen_sym)
|
||||
}
|
||||
|
||||
// OK button XML
|
||||
def onOkClicked(view : View) {
|
||||
prefs.prefs.edit().putString("symbol", chosen_sym).commit()
|
||||
finish()
|
||||
}
|
||||
|
||||
// TextWatcher for edit
|
||||
override def afterTextChanged(s : Editable) {
|
||||
setSymbol("%c%c".format('\\', chosen_sym(1)))
|
||||
}
|
||||
override def beforeTextChanged(s : CharSequence, start : Int, before : Int, count : Int) {
|
||||
}
|
||||
override def onTextChanged(s : CharSequence, start : Int, before : Int, count : Int) {
|
||||
}
|
||||
|
||||
|
||||
class SymbolAdapter(context : Context) extends BaseAdapter {
|
||||
override def getCount() = 16*12 - 2
|
||||
|
||||
override def getItem(position : Int) : Object = {
|
||||
val primary = position / 95
|
||||
val secondary = position%95
|
||||
return "/\\"(primary) + ('!' + secondary).asInstanceOf[Char].toString
|
||||
}
|
||||
|
||||
override def getItemId(position : Int) = position.asInstanceOf[Long]
|
||||
|
||||
override def getView(position : Int, convertView : View, parent : ViewGroup) : View = {
|
||||
val v = if (convertView == null) {
|
||||
val vt = new SymbolView(context, null)
|
||||
|
||||
val px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 48,
|
||||
getResources().getDisplayMetrics()).asInstanceOf[Int]
|
||||
|
||||
vt.setLayoutParams(new AbsListView.LayoutParams(px, px))
|
||||
vt.setScaleType(ImageView.ScaleType.CENTER_INSIDE)
|
||||
//vt.setPadding(8, 8, 8, 8)
|
||||
vt
|
||||
} else convertView.asInstanceOf[SymbolView]
|
||||
v.setSymbol(getItem(position).asInstanceOf[String])
|
||||
return v
|
||||
}
|
||||
}
|
||||
}
|
Ładowanie…
Reference in New Issue