package anywheresoftware.b4a.samples.preferenceactivity;


import anywheresoftware.b4a.B4AMenuItem;
import android.app.Activity;
import android.os.Bundle;
import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.BALayout;
import anywheresoftware.b4a.B4AActivity;
import anywheresoftware.b4a.ObjectWrapper;
import anywheresoftware.b4a.objects.ActivityWrapper;
import java.lang.reflect.InvocationTargetException;
import anywheresoftware.b4a.B4AUncaughtException;
import anywheresoftware.b4a.debug.*;
import java.lang.ref.WeakReference;

public class main extends Activity implements B4AActivity{
	public static main mostCurrent;
	static boolean afterFirstLayout;
	static boolean isFirst = true;
    private static boolean processGlobalsRun = false;
	BALayout layout;
	public static BA processBA;
	BA activityBA;
    ActivityWrapper _activity;
    java.util.ArrayList<B4AMenuItem> menuItems;
	public static final boolean fullScreen = false;
	public static final boolean includeTitle = true;
    public static WeakReference<Activity> previousOne;
    public static boolean dontPause;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
        mostCurrent = this;
		if (processBA == null) {
			processBA = new BA(this.getApplicationContext(), null, null, "anywheresoftware.b4a.samples.preferenceactivity", "anywheresoftware.b4a.samples.preferenceactivity.main");
			processBA.loadHtSubs(this.getClass());
	        float deviceScale = getApplicationContext().getResources().getDisplayMetrics().density;
	        BALayout.setDeviceScale(deviceScale);
            
		}
		else if (previousOne != null) {
			Activity p = previousOne.get();
			if (p != null && p != this) {
                BA.LogInfo("Killing previous instance (main).");
				p.finish();
			}
		}
        processBA.setActivityPaused(true);
        processBA.runHook("oncreate", this, null);
		if (!includeTitle) {
        	this.getWindow().requestFeature(android.view.Window.FEATURE_NO_TITLE);
        }
        if (fullScreen) {
        	getWindow().setFlags(android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN,   
        			android.view.WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
		
        processBA.sharedProcessBA.activityBA = null;
		layout = new BALayout(this);
		setContentView(layout);
		afterFirstLayout = false;
        WaitForLayout wl = new WaitForLayout();
        if (anywheresoftware.b4a.objects.ServiceHelper.StarterHelper.startFromActivity(this, processBA, wl, true))
		    BA.handler.postDelayed(wl, 5);

	}
	static class WaitForLayout implements Runnable {
		public void run() {
			if (afterFirstLayout)
				return;
			if (mostCurrent == null)
				return;
            
			if (mostCurrent.layout.getWidth() == 0) {
				BA.handler.postDelayed(this, 5);
				return;
			}
			mostCurrent.layout.getLayoutParams().height = mostCurrent.layout.getHeight();
			mostCurrent.layout.getLayoutParams().width = mostCurrent.layout.getWidth();
			afterFirstLayout = true;
			mostCurrent.afterFirstLayout();
		}
	}
	private void afterFirstLayout() {
        if (this != mostCurrent)
			return;
		activityBA = new BA(this, layout, processBA, "anywheresoftware.b4a.samples.preferenceactivity", "anywheresoftware.b4a.samples.preferenceactivity.main");
        
        processBA.sharedProcessBA.activityBA = new java.lang.ref.WeakReference<BA>(activityBA);
        anywheresoftware.b4a.objects.ViewWrapper.lastId = 0;
        _activity = new ActivityWrapper(activityBA, "activity");
        anywheresoftware.b4a.Msgbox.isDismissing = false;
        if (BA.isShellModeRuntimeCheck(processBA)) {
			if (isFirst)
				processBA.raiseEvent2(null, true, "SHELL", false);
			processBA.raiseEvent2(null, true, "CREATE", true, "anywheresoftware.b4a.samples.preferenceactivity.main", processBA, activityBA, _activity, anywheresoftware.b4a.keywords.Common.Density, mostCurrent);
			_activity.reinitializeForShell(activityBA, "activity");
		}
        initializeProcessGlobals();		
        initializeGlobals();
        
        BA.LogInfo("** Activity (main) Create, isFirst = " + isFirst + " **");
        processBA.raiseEvent2(null, true, "activity_create", false, isFirst);
		isFirst = false;
		if (this != mostCurrent)
			return;
        processBA.setActivityPaused(false);
        BA.LogInfo("** Activity (main) Resume **");
        processBA.raiseEvent(null, "activity_resume");
        if (android.os.Build.VERSION.SDK_INT >= 11) {
			try {
				android.app.Activity.class.getMethod("invalidateOptionsMenu").invoke(this,(Object[]) null);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}

	}
	public void addMenuItem(B4AMenuItem item) {
		if (menuItems == null)
			menuItems = new java.util.ArrayList<B4AMenuItem>();
		menuItems.add(item);
	}
	@Override
	public boolean onCreateOptionsMenu(android.view.Menu menu) {
		super.onCreateOptionsMenu(menu);
        try {
            if (processBA.subExists("activity_actionbarhomeclick")) {
                Class.forName("android.app.ActionBar").getMethod("setHomeButtonEnabled", boolean.class).invoke(
                    getClass().getMethod("getActionBar").invoke(this), true);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (processBA.runHook("oncreateoptionsmenu", this, new Object[] {menu}))
            return true;
		if (menuItems == null)
			return false;
		for (B4AMenuItem bmi : menuItems) {
			android.view.MenuItem mi = menu.add(bmi.title);
			if (bmi.drawable != null)
				mi.setIcon(bmi.drawable);
            if (android.os.Build.VERSION.SDK_INT >= 11) {
				try {
                    if (bmi.addToBar) {
				        android.view.MenuItem.class.getMethod("setShowAsAction", int.class).invoke(mi, 1);
                    }
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
			mi.setOnMenuItemClickListener(new B4AMenuItemsClickListener(bmi.eventName.toLowerCase(BA.cul)));
		}
        
		return true;
	}   
 @Override
 public boolean onOptionsItemSelected(android.view.MenuItem item) {
    if (item.getItemId() == 16908332) {
        processBA.raiseEvent(null, "activity_actionbarhomeclick");
        return true;
    }
    else
        return super.onOptionsItemSelected(item); 
}
@Override
 public boolean onPrepareOptionsMenu(android.view.Menu menu) {
    super.onPrepareOptionsMenu(menu);
    processBA.runHook("onprepareoptionsmenu", this, new Object[] {menu});
    return true;
    
 }
 protected void onStart() {
    super.onStart();
    processBA.runHook("onstart", this, null);
}
 protected void onStop() {
    super.onStop();
    processBA.runHook("onstop", this, null);
}
    public void onWindowFocusChanged(boolean hasFocus) {
       super.onWindowFocusChanged(hasFocus);
       if (processBA.subExists("activity_windowfocuschanged"))
           processBA.raiseEvent2(null, true, "activity_windowfocuschanged", false, hasFocus);
    }
	private class B4AMenuItemsClickListener implements android.view.MenuItem.OnMenuItemClickListener {
		private final String eventName;
		public B4AMenuItemsClickListener(String eventName) {
			this.eventName = eventName;
		}
		public boolean onMenuItemClick(android.view.MenuItem item) {
			processBA.raiseEventFromUI(item.getTitle(), eventName + "_click");
			return true;
		}
	}
    public static Class<?> getObject() {
		return main.class;
	}
    private Boolean onKeySubExist = null;
    private Boolean onKeyUpSubExist = null;
	@Override
	public boolean onKeyDown(int keyCode, android.view.KeyEvent event) {
        if (processBA.runHook("onkeydown", this, new Object[] {keyCode, event}))
            return true;
		if (onKeySubExist == null)
			onKeySubExist = processBA.subExists("activity_keypress");
		if (onKeySubExist) {
			if (keyCode == anywheresoftware.b4a.keywords.constants.KeyCodes.KEYCODE_BACK &&
					android.os.Build.VERSION.SDK_INT >= 18) {
				HandleKeyDelayed hk = new HandleKeyDelayed();
				hk.kc = keyCode;
				BA.handler.post(hk);
				return true;
			}
			else {
				boolean res = new HandleKeyDelayed().runDirectly(keyCode);
				if (res)
					return true;
			}
		}
		return super.onKeyDown(keyCode, event);
	}
	private class HandleKeyDelayed implements Runnable {
		int kc;
		public void run() {
			runDirectly(kc);
		}
		public boolean runDirectly(int keyCode) {
			Boolean res =  (Boolean)processBA.raiseEvent2(_activity, false, "activity_keypress", false, keyCode);
			if (res == null || res == true) {
                return true;
            }
            else if (keyCode == anywheresoftware.b4a.keywords.constants.KeyCodes.KEYCODE_BACK) {
				finish();
				return true;
			}
            return false;
		}
		
	}
    @Override
	public boolean onKeyUp(int keyCode, android.view.KeyEvent event) {
        if (processBA.runHook("onkeyup", this, new Object[] {keyCode, event}))
            return true;
		if (onKeyUpSubExist == null)
			onKeyUpSubExist = processBA.subExists("activity_keyup");
		if (onKeyUpSubExist) {
			Boolean res =  (Boolean)processBA.raiseEvent2(_activity, false, "activity_keyup", false, keyCode);
			if (res == null || res == true)
				return true;
		}
		return super.onKeyUp(keyCode, event);
	}
	@Override
	public void onNewIntent(android.content.Intent intent) {
        super.onNewIntent(intent);
		this.setIntent(intent);
        processBA.runHook("onnewintent", this, new Object[] {intent});
	}
    @Override 
	public void onPause() {
		super.onPause();
        if (_activity == null)
            return;
        if (this != mostCurrent)
			return;
		anywheresoftware.b4a.Msgbox.dismiss(true);
        if (!dontPause)
            BA.LogInfo("** Activity (main) Pause, UserClosed = " + activityBA.activity.isFinishing() + " **");
        else
            BA.LogInfo("** Activity (main) Pause event (activity is not paused). **");
        if (mostCurrent != null)
            processBA.raiseEvent2(_activity, true, "activity_pause", false, activityBA.activity.isFinishing());		
        if (!dontPause) {
            processBA.setActivityPaused(true);
            mostCurrent = null;
        }

        if (!activityBA.activity.isFinishing())
			previousOne = new WeakReference<Activity>(this);
        anywheresoftware.b4a.Msgbox.isDismissing = false;
        processBA.runHook("onpause", this, null);
	}

	@Override
	public void onDestroy() {
        super.onDestroy();
		previousOne = null;
        processBA.runHook("ondestroy", this, null);
	}
    @Override 
	public void onResume() {
		super.onResume();
        mostCurrent = this;
        anywheresoftware.b4a.Msgbox.isDismissing = false;
        if (activityBA != null) { //will be null during activity create (which waits for AfterLayout).
        	ResumeMessage rm = new ResumeMessage(mostCurrent);
        	BA.handler.post(rm);
        }
        processBA.runHook("onresume", this, null);
	}
    private static class ResumeMessage implements Runnable {
    	private final WeakReference<Activity> activity;
    	public ResumeMessage(Activity activity) {
    		this.activity = new WeakReference<Activity>(activity);
    	}
		public void run() {
            main mc = mostCurrent;
			if (mc == null || mc != activity.get())
				return;
			processBA.setActivityPaused(false);
            BA.LogInfo("** Activity (main) Resume **");
            if (mc != mostCurrent)
                return;
		    processBA.raiseEvent(mc._activity, "activity_resume", (Object[])null);
		}
    }
	@Override
	protected void onActivityResult(int requestCode, int resultCode,
	      android.content.Intent data) {
		processBA.onActivityResult(requestCode, resultCode, data);
        processBA.runHook("onactivityresult", this, new Object[] {requestCode, resultCode});
	}
	private static void initializeGlobals() {
		processBA.raiseEvent2(null, true, "globals", false, (Object[])null);
	}
    public void onRequestPermissionsResult(int requestCode,
        String permissions[], int[] grantResults) {
        for (int i = 0;i < permissions.length;i++) {
            Object[] o = new Object[] {permissions[i], grantResults[i] == 0};
            processBA.raiseEventFromDifferentThread(null,null, 0, "activity_permissionresult", true, o);
        }
            
    }

public anywheresoftware.b4a.keywords.Common __c = null;
public static de.amberhome.objects.preferenceactivity.PreferenceManager _manager = null;
public static de.amberhome.objects.preferenceactivity.PreferenceScreenWrapper _screen = null;
public static anywheresoftware.b4a.audio.MediaPlayerStreamWrapper _mp = null;

public static boolean isAnyActivityVisible() {
    boolean vis = false;
vis = vis | (main.mostCurrent != null);
return vis;}
public static String  _activity_create(boolean _firsttime) throws Exception{
anywheresoftware.b4a.objects.ButtonWrapper _btn = null;
 //BA.debugLineNum = 23;BA.debugLine="Sub Activity_Create(FirstTime As Boolean)";
 //BA.debugLineNum = 24;BA.debugLine="If FirstTime Then";
if (_firsttime) { 
 //BA.debugLineNum = 25;BA.debugLine="CreatePreferenceScreen";
_createpreferencescreen();
 //BA.debugLineNum = 26;BA.debugLine="If manager.GetAll.Size = 0 Then SetDefaults";
if (_manager.GetAll().getSize()==0) { 
_setdefaults();};
 };
 //BA.debugLineNum = 28;BA.debugLine="Dim btn As Button";
_btn = new anywheresoftware.b4a.objects.ButtonWrapper();
 //BA.debugLineNum = 29;BA.debugLine="btn.Initialize(\"btn\")";
_btn.Initialize(mostCurrent.activityBA,"btn");
 //BA.debugLineNum = 30;BA.debugLine="btn.Text = \"Settings\"";
_btn.setText(BA.ObjectToCharSequence("Settings"));
 //BA.debugLineNum = 31;BA.debugLine="Activity.AddView(btn, 10dip, 10dip, 200dip, 100di";
mostCurrent._activity.AddView((android.view.View)(_btn.getObject()),anywheresoftware.b4a.keywords.Common.DipToCurrent((int) (10)),anywheresoftware.b4a.keywords.Common.DipToCurrent((int) (10)),anywheresoftware.b4a.keywords.Common.DipToCurrent((int) (200)),anywheresoftware.b4a.keywords.Common.DipToCurrent((int) (100)));
 //BA.debugLineNum = 32;BA.debugLine="End Sub";
return "";
}
public static String  _activity_pause(boolean _userclosed) throws Exception{
 //BA.debugLineNum = 132;BA.debugLine="Sub Activity_Pause (UserClosed As Boolean)";
 //BA.debugLineNum = 134;BA.debugLine="End Sub";
return "";
}
public static String  _activity_resume() throws Exception{
 //BA.debugLineNum = 106;BA.debugLine="Sub Activity_Resume";
 //BA.debugLineNum = 107;BA.debugLine="HandleSettings";
_handlesettings();
 //BA.debugLineNum = 108;BA.debugLine="End Sub";
return "";
}
public static String  _btn_click() throws Exception{
 //BA.debugLineNum = 42;BA.debugLine="Sub btn_Click";
 //BA.debugLineNum = 43;BA.debugLine="StartActivity(screen.CreateIntent)";
anywheresoftware.b4a.keywords.Common.StartActivity(processBA,(Object)(_screen.CreateIntent()));
 //BA.debugLineNum = 44;BA.debugLine="End Sub";
return "";
}
public static String  _createpreferencescreen() throws Exception{
de.amberhome.objects.preferenceactivity.PreferenceCategoryWrapper _intentcat = null;
de.amberhome.objects.preferenceactivity.PreferenceCategoryWrapper _cat1 = null;
de.amberhome.objects.preferenceactivity.PreferenceCategoryWrapper _cat2 = null;
de.amberhome.objects.preferenceactivity.PreferenceScreenWrapper _intentscreen = null;
anywheresoftware.b4a.objects.IntentWrapper _in = null;
anywheresoftware.b4a.gps.GPS _g = null;
anywheresoftware.b4a.phone.PackageManagerWrapper _pm = null;
anywheresoftware.b4a.objects.collections.List _pl = null;
anywheresoftware.b4a.phone.Phone.PhoneIntents _pi = null;
anywheresoftware.b4a.objects.collections.Map _m = null;
 //BA.debugLineNum = 47;BA.debugLine="Sub CreatePreferenceScreen";
 //BA.debugLineNum = 48;BA.debugLine="screen.Initialize(\"Settings\", \"\")";
_screen.Initialize("Settings","");
 //BA.debugLineNum = 49;BA.debugLine="Dim intentCat, cat1, cat2 As AHPreferenceCategory";
_intentcat = new de.amberhome.objects.preferenceactivity.PreferenceCategoryWrapper();
_cat1 = new de.amberhome.objects.preferenceactivity.PreferenceCategoryWrapper();
_cat2 = new de.amberhome.objects.preferenceactivity.PreferenceCategoryWrapper();
 //BA.debugLineNum = 50;BA.debugLine="Dim intentScreen As AHPreferenceScreen";
_intentscreen = new de.amberhome.objects.preferenceactivity.PreferenceScreenWrapper();
 //BA.debugLineNum = 52;BA.debugLine="intentCat.Initialize(\"Intent Settings\")";
_intentcat.Initialize("Intent Settings");
 //BA.debugLineNum = 53;BA.debugLine="intentCat.AddCheckBox(\"intentenable\", \"Enable Int";
_intentcat.AddCheckBox("intentenable","Enable Intent Settings","Intent settings are enabled","Intent settings are disabled",anywheresoftware.b4a.keywords.Common.True,"");
 //BA.debugLineNum = 54;BA.debugLine="intentScreen.Initialize(\"Intents\", \"Examples with";
_intentscreen.Initialize("Intents","Examples with Intents");
 //BA.debugLineNum = 55;BA.debugLine="intentScreen.AddCheckBox(\"chkwifi\", \"Enable Wifi";
_intentscreen.AddCheckBox("chkwifi","Enable Wifi Settings","Wifi settings enabled","Wifi settings disabled",anywheresoftware.b4a.keywords.Common.False,"");
 //BA.debugLineNum = 58;BA.debugLine="Dim In As Intent";
_in = new anywheresoftware.b4a.objects.IntentWrapper();
 //BA.debugLineNum = 59;BA.debugLine="In.Initialize(\"android.settings.WIFI_SETTINGS\", \"";
_in.Initialize("android.settings.WIFI_SETTINGS","");
 //BA.debugLineNum = 60;BA.debugLine="intentScreen.AddIntent( \"Wifi Settings\", \"Example";
_intentscreen.AddIntent("Wifi Settings","Example for custom Intent",(android.content.Intent)(_in.getObject()),"chkwifi");
 //BA.debugLineNum = 63;BA.debugLine="Dim g As GPS";
_g = new anywheresoftware.b4a.gps.GPS();
 //BA.debugLineNum = 64;BA.debugLine="g.Initialize(\"\")";
_g.Initialize("");
 //BA.debugLineNum = 65;BA.debugLine="intentScreen.AddIntent(\"GPS Settings\", \"Start And";
_intentscreen.AddIntent("GPS Settings","Start Android GPS settings",_g.getLocationSettingsIntent(),"");
 //BA.debugLineNum = 68;BA.debugLine="Dim pm As PackageManager";
_pm = new anywheresoftware.b4a.phone.PackageManagerWrapper();
 //BA.debugLineNum = 69;BA.debugLine="Dim pl As List";
_pl = new anywheresoftware.b4a.objects.collections.List();
 //BA.debugLineNum = 70;BA.debugLine="pl = pm.GetInstalledPackages";
_pl = _pm.GetInstalledPackages();
 //BA.debugLineNum = 72;BA.debugLine="If pl.IndexOf(\"com.android.calculator2\") > 0 Then";
if (_pl.IndexOf((Object)("com.android.calculator2"))>0) { 
 //BA.debugLineNum = 73;BA.debugLine="intentScreen.AddIntent(\"Calculator\", \"Open calcu";
_intentscreen.AddIntent("Calculator","Open calculator",(android.content.Intent)(_pm.GetApplicationIntent("com.android.calculator2").getObject()),"");
 };
 //BA.debugLineNum = 77;BA.debugLine="Dim pi As PhoneIntents";
_pi = new anywheresoftware.b4a.phone.Phone.PhoneIntents();
 //BA.debugLineNum = 78;BA.debugLine="intentScreen.AddIntent(\"Browser\", \"Open http://ww";
_intentscreen.AddIntent("Browser","Open http://www.google.de",_pi.OpenBrowser("http://www.google.com"),"");
 //BA.debugLineNum = 81;BA.debugLine="intentCat.AddPreferenceScreen(intentScreen, \"inte";
_intentcat.AddPreferenceScreen(_intentscreen,"intentenable");
 //BA.debugLineNum = 83;BA.debugLine="cat1.Initialize(\"Examples\")";
_cat1.Initialize("Examples");
 //BA.debugLineNum = 84;BA.debugLine="cat1.AddCheckBox(\"check1\", \"Checkbox1\", \"This is";
_cat1.AddCheckBox("check1","Checkbox1","This is Checkbox1 without second summary","",anywheresoftware.b4a.keywords.Common.True,"");
 //BA.debugLineNum = 85;BA.debugLine="cat1.AddEditText(\"edit1\", \"EditText1\", \"This is E";
_cat1.AddEditText("edit1","EditText1","This is EditText1","","check1");
 //BA.debugLineNum = 86;BA.debugLine="cat1.AddEditText2(\"edit2\", \"EditText2\", \"This is";
_cat1.AddEditText2("edit2","EditText2","This is a number input field","1",(int) (2),anywheresoftware.b4a.keywords.Common.False,anywheresoftware.b4a.keywords.Common.True,"");
 //BA.debugLineNum = 87;BA.debugLine="cat1.AddPassword(\"pwd1\", \"Password1\", \"This is a";
_cat1.AddPassword("pwd1","Password1","This is a password","","");
 //BA.debugLineNum = 88;BA.debugLine="cat1.AddRingtone(\"ring1\", \"Ringtone1\", \"This is a";
_cat1.AddRingtone("ring1","Ringtone1","This is a Ringtone","","",_cat1.RT_NOTIFICATION);
 //BA.debugLineNum = 90;BA.debugLine="cat2.Initialize(\"Set Background Color\")";
_cat2.Initialize("Set Background Color");
 //BA.debugLineNum = 91;BA.debugLine="Dim m As Map";
_m = new anywheresoftware.b4a.objects.collections.Map();
 //BA.debugLineNum = 92;BA.debugLine="m.Initialize";
_m.Initialize();
 //BA.debugLineNum = 93;BA.debugLine="m.Put(\"black\", \"I want a black background\")";
_m.Put((Object)("black"),(Object)("I want a black background"));
 //BA.debugLineNum = 94;BA.debugLine="m.Put(\"red\", \"No, make it red\")";
_m.Put((Object)("red"),(Object)("No, make it red"));
 //BA.debugLineNum = 95;BA.debugLine="m.Put(\"green\", \"I like it green\")";
_m.Put((Object)("green"),(Object)("I like it green"));
 //BA.debugLineNum = 96;BA.debugLine="m.Put(\"blue\", \"Blue is best\")";
_m.Put((Object)("blue"),(Object)("Blue is best"));
 //BA.debugLineNum = 97;BA.debugLine="cat2.AddList2(\"Background Color\", \"Choose color\",";
_cat2.AddList2("Background Color","Choose color","Choose color","black","",_m);
 //BA.debugLineNum = 101;BA.debugLine="screen.AddPreferenceCategory(intentCat)";
_screen.AddPreferenceCategory(_intentcat);
 //BA.debugLineNum = 102;BA.debugLine="screen.AddPreferenceCategory(cat1)";
_screen.AddPreferenceCategory(_cat1);
 //BA.debugLineNum = 103;BA.debugLine="screen.AddPreferenceCategory(cat2)";
_screen.AddPreferenceCategory(_cat2);
 //BA.debugLineNum = 104;BA.debugLine="End Sub";
return "";
}
public static String  _globals() throws Exception{
 //BA.debugLineNum = 19;BA.debugLine="Sub Globals";
 //BA.debugLineNum = 21;BA.debugLine="End Sub";
return "";
}
public static String  _handlesettings() throws Exception{
 //BA.debugLineNum = 110;BA.debugLine="Sub HandleSettings";
 //BA.debugLineNum = 113;BA.debugLine="Log(\"Updated: \" & manager.GetUpdatedKeys)";
anywheresoftware.b4a.keywords.Common.LogImpl("8458755","Updated: "+BA.ObjectToString(_manager.GetUpdatedKeys()),0);
 //BA.debugLineNum = 115;BA.debugLine="Select manager.GetString(\"Background Color\")";
switch (BA.switchObjectToInt(_manager.GetString("Background Color"),"black","red","green","blue")) {
case 0: {
 //BA.debugLineNum = 117;BA.debugLine="Activity.Color = Colors.Black";
mostCurrent._activity.setColor(anywheresoftware.b4a.keywords.Common.Colors.Black);
 break; }
case 1: {
 //BA.debugLineNum = 119;BA.debugLine="Activity.Color = Colors.Red";
mostCurrent._activity.setColor(anywheresoftware.b4a.keywords.Common.Colors.Red);
 break; }
case 2: {
 //BA.debugLineNum = 121;BA.debugLine="Activity.Color = Colors.Green";
mostCurrent._activity.setColor(anywheresoftware.b4a.keywords.Common.Colors.Green);
 break; }
case 3: {
 //BA.debugLineNum = 123;BA.debugLine="Activity.Color = Colors.Blue";
mostCurrent._activity.setColor(anywheresoftware.b4a.keywords.Common.Colors.Blue);
 break; }
}
;
 //BA.debugLineNum = 126;BA.debugLine="If manager.GetString(\"ring1\") <> \"\" Then";
if ((_manager.GetString("ring1")).equals("") == false) { 
 //BA.debugLineNum = 127;BA.debugLine="mp.Initialize(\"mp\")";
_mp.Initialize(processBA,"mp");
 //BA.debugLineNum = 128;BA.debugLine="mp.Load(manager.GetString(\"ring1\"))";
_mp.Load(processBA,_manager.GetString("ring1"));
 };
 //BA.debugLineNum = 130;BA.debugLine="End Sub";
return "";
}
public static String  _mp_streambuffer(int _percentage) throws Exception{
 //BA.debugLineNum = 146;BA.debugLine="Sub mp_StreamBuffer(Percentage As Int)";
 //BA.debugLineNum = 147;BA.debugLine="Log(Percentage)";
anywheresoftware.b4a.keywords.Common.LogImpl("8720897",BA.NumberToString(_percentage),0);
 //BA.debugLineNum = 148;BA.debugLine="End Sub";
return "";
}
public static String  _mp_streamerror(String _errorcode,int _extradata) throws Exception{
 //BA.debugLineNum = 141;BA.debugLine="Sub mp_StreamError (ErrorCode As String, ExtraData";
 //BA.debugLineNum = 142;BA.debugLine="Log(\"Error: \" & ErrorCode & \", \" & ExtraData)";
anywheresoftware.b4a.keywords.Common.LogImpl("8655361","Error: "+_errorcode+", "+BA.NumberToString(_extradata),0);
 //BA.debugLineNum = 143;BA.debugLine="ToastMessageShow(\"Error: \" & ErrorCode & \", \"";
anywheresoftware.b4a.keywords.Common.ToastMessageShow(BA.ObjectToCharSequence("Error: "+_errorcode+", "+BA.NumberToString(_extradata)),anywheresoftware.b4a.keywords.Common.True);
 //BA.debugLineNum = 144;BA.debugLine="End Sub";
return "";
}
public static String  _mp_streamready() throws Exception{
 //BA.debugLineNum = 136;BA.debugLine="Sub mp_StreamReady";
 //BA.debugLineNum = 137;BA.debugLine="Log(\"starts playing\")";
anywheresoftware.b4a.keywords.Common.LogImpl("8589825","starts playing",0);
 //BA.debugLineNum = 138;BA.debugLine="mp.Play";
_mp.Play();
 //BA.debugLineNum = 139;BA.debugLine="End Sub";
return "";
}

public static void initializeProcessGlobals() {
    
    if (main.processGlobalsRun == false) {
	    main.processGlobalsRun = true;
		try {
		        main._process_globals();
		
        } catch (Exception e) {
			throw new RuntimeException(e);
		}
    }
}public static String  _process_globals() throws Exception{
 //BA.debugLineNum = 12;BA.debugLine="Sub Process_Globals";
 //BA.debugLineNum = 13;BA.debugLine="Dim manager As AHPreferenceManager";
_manager = new de.amberhome.objects.preferenceactivity.PreferenceManager();
 //BA.debugLineNum = 14;BA.debugLine="Dim screen As AHPreferenceScreen";
_screen = new de.amberhome.objects.preferenceactivity.PreferenceScreenWrapper();
 //BA.debugLineNum = 16;BA.debugLine="Dim mp As MediaPlayerStream";
_mp = new anywheresoftware.b4a.audio.MediaPlayerStreamWrapper();
 //BA.debugLineNum = 17;BA.debugLine="End Sub";
return "";
}
public static String  _setdefaults() throws Exception{
 //BA.debugLineNum = 34;BA.debugLine="Sub SetDefaults";
 //BA.debugLineNum = 36;BA.debugLine="manager.SetBoolean(\"check1\", True)";
_manager.SetBoolean("check1",anywheresoftware.b4a.keywords.Common.True);
 //BA.debugLineNum = 37;BA.debugLine="manager.SetBoolean(\"check2\", False)";
_manager.SetBoolean("check2",anywheresoftware.b4a.keywords.Common.False);
 //BA.debugLineNum = 38;BA.debugLine="manager.SetString(\"edit1\", \"Hello!\")";
_manager.SetString("edit1","Hello!");
 //BA.debugLineNum = 39;BA.debugLine="manager.SetString(\"list1\", \"Black\")";
_manager.SetString("list1","Black");
 //BA.debugLineNum = 40;BA.debugLine="End Sub";
return "";
}
}
