kopia lustrzana https://github.com/ge0rg/aprsdroid
refactored menus
rodzic
2417c5398b
commit
11193c8a2f
|
@ -43,9 +43,21 @@
|
|||
android:title="@string/startlog"
|
||||
android:alphabeticShortcut="t"
|
||||
android:icon="@android:drawable/ic_menu_compass" />
|
||||
<item android:id="@+id/singlebtn"
|
||||
android:title="@string/singlelog"
|
||||
android:alphabeticShortcut="s"
|
||||
android:icon="@android:drawable/ic_menu_myplaces" />
|
||||
<item android:id="@+id/clear"
|
||||
android:title="@string/clear_log"
|
||||
android:alphabeticShortcut="c"
|
||||
android:icon="@android:drawable/ic_menu_delete" />
|
||||
<item android:id="@+id/preferences"
|
||||
android:title="@string/preferences"
|
||||
android:alphabeticShortcut="p"
|
||||
android:icon="@android:drawable/ic_menu_preferences" />
|
||||
<item android:id="@+id/about"
|
||||
android:title="@string/about"
|
||||
android:alphabeticShortcut="a"
|
||||
android:icon="@android:drawable/ic_menu_info_details" />
|
||||
</menu>
|
||||
|
||||
|
|
|
@ -19,8 +19,7 @@ import _root_.android.widget.TextView
|
|||
import _root_.android.widget.Toast
|
||||
import _root_.java.util.Date
|
||||
|
||||
class APRSdroid extends Activity with OnClickListener
|
||||
with DialogInterface.OnClickListener {
|
||||
class APRSdroid extends Activity with OnClickListener {
|
||||
val TAG = "APRSdroid"
|
||||
|
||||
lazy val prefs = new PrefsWrapper(this)
|
||||
|
@ -76,15 +75,7 @@ class APRSdroid extends Activity with OnClickListener
|
|||
|
||||
override def onResume() {
|
||||
super.onResume()
|
||||
if (prefs.getBoolean("firstrun", true)) {
|
||||
new AlertDialog.Builder(this).setTitle(getString(R.string.fr_title))
|
||||
.setMessage(getString(R.string.fr_text))
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.setPositiveButton(android.R.string.ok, this)
|
||||
.setNegativeButton(android.R.string.cancel, this)
|
||||
.create.show
|
||||
return
|
||||
}
|
||||
uihelper.checkFirstRun()
|
||||
if (!uihelper.checkConfig())
|
||||
return
|
||||
setTitle(getString(R.string.app_name) + ": " + prefs.getCallSsid())
|
||||
|
@ -121,16 +112,6 @@ class APRSdroid extends Activity with OnClickListener
|
|||
}
|
||||
}
|
||||
|
||||
override def onClick(d : DialogInterface, which : Int) {
|
||||
which match {
|
||||
case DialogInterface.BUTTON_POSITIVE =>
|
||||
prefs.prefs.edit().putBoolean("firstrun", false).commit();
|
||||
uihelper.checkConfig()
|
||||
case _ =>
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
override def onClick(view : View) {
|
||||
Log.d(TAG, "onClick: " + view + "/" + view.getId)
|
||||
|
||||
|
|
|
@ -8,11 +8,20 @@ import _root_.android.net.Uri
|
|||
import _root_.android.view.{LayoutInflater, Menu, MenuItem, View}
|
||||
import _root_.android.widget.Toast
|
||||
|
||||
class UIHelper(ctx : Activity, menu_id : Int, prefs : PrefsWrapper) {
|
||||
class UIHelper(ctx : Activity, menu_id : Int, prefs : PrefsWrapper)
|
||||
extends DialogInterface.OnClickListener {
|
||||
|
||||
var openedPrefs = false
|
||||
|
||||
def openPrefs(toastId : Int) {
|
||||
ctx.startActivity(new Intent(ctx, classOf[PrefsAct]));
|
||||
Toast.makeText(ctx, toastId, Toast.LENGTH_SHORT).show()
|
||||
if (openedPrefs) {
|
||||
// only open prefs once, exit app afterwards
|
||||
ctx.finish()
|
||||
} else {
|
||||
ctx.startActivity(new Intent(ctx, classOf[PrefsAct]));
|
||||
Toast.makeText(ctx, toastId, Toast.LENGTH_SHORT).show()
|
||||
openedPrefs = true
|
||||
}
|
||||
}
|
||||
|
||||
def passcodeWarning(call : String, pass : String) {
|
||||
|
@ -36,6 +45,27 @@ class UIHelper(ctx : Activity, menu_id : Int, prefs : PrefsWrapper) {
|
|||
}
|
||||
}
|
||||
|
||||
def checkFirstRun() {
|
||||
if (prefs.getBoolean("firstrun", true)) {
|
||||
new AlertDialog.Builder(ctx).setTitle(ctx.getString(R.string.fr_title))
|
||||
.setMessage(ctx.getString(R.string.fr_text))
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.setPositiveButton(android.R.string.ok, this)
|
||||
.setNegativeButton(android.R.string.cancel, this)
|
||||
.create.show
|
||||
return
|
||||
}
|
||||
}
|
||||
override def onClick(d : DialogInterface, which : Int) {
|
||||
which match {
|
||||
case DialogInterface.BUTTON_POSITIVE =>
|
||||
prefs.prefs.edit().putBoolean("firstrun", false).commit();
|
||||
checkConfig()
|
||||
case _ =>
|
||||
ctx.finish()
|
||||
}
|
||||
}
|
||||
|
||||
def checkConfig() : Boolean = {
|
||||
val callsign = prefs.getCallsign()
|
||||
val passcode = prefs.getPasscode()
|
||||
|
@ -55,7 +85,6 @@ class UIHelper(ctx : Activity, menu_id : Int, prefs : PrefsWrapper) {
|
|||
true
|
||||
}
|
||||
|
||||
|
||||
def aboutDialog() {
|
||||
val pi = ctx.getPackageManager().getPackageInfo(ctx.getPackageName(), 0)
|
||||
val title = ctx.getString(R.string.ad_title, pi.versionName);
|
||||
|
@ -69,9 +98,6 @@ class UIHelper(ctx : Activity, menu_id : Int, prefs : PrefsWrapper) {
|
|||
.create.show
|
||||
}
|
||||
|
||||
def showFirstRunDialog() {
|
||||
}
|
||||
|
||||
def onPrepareOptionsMenu(menu : Menu) : Boolean = {
|
||||
val mi = menu.findItem(R.id.startstopbtn)
|
||||
mi.setTitle(if (AprsService.running) R.string.stoplog else R.string.startlog)
|
||||
|
@ -113,11 +139,16 @@ class UIHelper(ctx : Activity, menu_id : Int, prefs : PrefsWrapper) {
|
|||
case R.id.startstopbtn =>
|
||||
val is_running = AprsService.running
|
||||
if (!is_running) {
|
||||
passcodeWarning(prefs.getCallsign(), prefs.getPasscode())
|
||||
ctx.startService(AprsService.intent(ctx, AprsService.SERVICE))
|
||||
} else {
|
||||
ctx.stopService(AprsService.intent(ctx, AprsService.SERVICE))
|
||||
}
|
||||
true
|
||||
case R.id.singlebtn =>
|
||||
passcodeWarning(prefs.getCallsign(), prefs.getPasscode())
|
||||
ctx.startService(AprsService.intent(ctx, AprsService.SERVICE_ONCE))
|
||||
true
|
||||
// quit the app
|
||||
case R.id.quit =>
|
||||
// XXX deprecated!
|
||||
|
|
Ładowanie…
Reference in New Issue