package medicomed.keymon.com.mx;


import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.B4AClass;
import anywheresoftware.b4a.BALayout;
import anywheresoftware.b4a.debug.*;

public class filehandler extends B4AClass.ImplB4AClass implements BA.SubDelegator{
    private static java.util.HashMap<String, java.lang.reflect.Method> htSubs;
    private void innerInitialize(BA _ba) throws Exception {
        if (ba == null) {
            ba = new BA(_ba, this, htSubs, "medicomed.keymon.com.mx.filehandler");
            if (htSubs == null) {
                ba.loadHtSubs(this.getClass());
                htSubs = ba.htSubs;
            }
            
        }
        if (BA.isShellModeRuntimeCheck(ba)) 
			   this.getClass().getMethod("_class_globals", medicomed.keymon.com.mx.filehandler.class).invoke(this, new Object[] {null});
        else
            ba.raiseEvent2(null, true, "class_globals", false);
    }

 public anywheresoftware.b4a.keywords.Common __c = null;
public Object _ion = null;
public anywheresoftware.b4a.objects.IntentWrapper _oldintent = null;
public b4a.example.dateutils _dateutils = null;
public medicomed.keymon.com.mx.main _main = null;
public medicomed.keymon.com.mx.starter _starter = null;
public medicomed.keymon.com.mx.appupdater _appupdater = null;
public medicomed.keymon.com.mx.mapa_rutas _mapa_rutas = null;
public medicomed.keymon.com.mx.mapa_cliente _mapa_cliente = null;
public medicomed.keymon.com.mx.subs _subs = null;
public medicomed.keymon.com.mx.notificationservice _notificationservice = null;
public medicomed.keymon.com.mx.pendientes _pendientes = null;
public medicomed.keymon.com.mx.tracker _tracker = null;
public medicomed.keymon.com.mx.newinst2 _newinst2 = null;
public medicomed.keymon.com.mx.b4xpages _b4xpages = null;
public medicomed.keymon.com.mx.b4xcollections _b4xcollections = null;
public medicomed.keymon.com.mx.httputils2service _httputils2service = null;
public medicomed.keymon.com.mx.xuiviewsutils _xuiviewsutils = null;
public static class _loadresult{
public boolean IsInitialized;
public boolean Success;
public String Dir;
public String FileName;
public String RealName;
public long Size;
public long Modified;
public String MimeType;
public void Initialize() {
IsInitialized = true;
Success = false;
Dir = "";
FileName = "";
RealName = "";
Size = 0L;
Modified = 0L;
MimeType = "";
}
@Override
		public String toString() {
			return BA.TypeToString(this, false);
		}}
public medicomed.keymon.com.mx.filehandler._loadresult  _checkforreceivedfiles() throws Exception{
anywheresoftware.b4a.objects.ActivityWrapper _activity = null;
anywheresoftware.b4a.objects.IntentWrapper _in = null;
String _uri = "";
medicomed.keymon.com.mx.filehandler._loadresult _res = null;
 //BA.debugLineNum = 96;BA.debugLine="Public Sub CheckForReceivedFiles As LoadResult";
 //BA.debugLineNum = 97;BA.debugLine="Dim Activity As Activity = B4XPages.GetNativePare";
_activity = new anywheresoftware.b4a.objects.ActivityWrapper();
_activity = _b4xpages._getnativeparent /*anywheresoftware.b4a.objects.ActivityWrapper*/ (getActivityBA(),(Object)(_b4xpages._mainpage /*medicomed.keymon.com.mx.b4xmainpage*/ (getActivityBA())));
 //BA.debugLineNum = 98;BA.debugLine="If IsRelevantIntent(Activity.GetStartingIntent) T";
if (_isrelevantintent(_activity.GetStartingIntent())) { 
 //BA.debugLineNum = 99;BA.debugLine="Dim in As Intent = Activity.GetStartingIntent";
_in = new anywheresoftware.b4a.objects.IntentWrapper();
_in = _activity.GetStartingIntent();
 //BA.debugLineNum = 100;BA.debugLine="Dim uri As String";
_uri = "";
 //BA.debugLineNum = 101;BA.debugLine="If in.HasExtra(\"android.intent.extra.STREAM\") Th";
if (_in.HasExtra("android.intent.extra.STREAM")) { 
 //BA.debugLineNum = 102;BA.debugLine="uri = in.As(JavaObject).RunMethod(\"getParcelabl";
_uri = BA.ObjectToString(((anywheresoftware.b4j.object.JavaObject) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4j.object.JavaObject(), (java.lang.Object)(_in.getObject()))).RunMethod("getParcelableExtra",new Object[]{(Object)("android.intent.extra.STREAM")}));
 }else {
 //BA.debugLineNum = 104;BA.debugLine="uri = in.GetData";
_uri = _in.GetData();
 };
 //BA.debugLineNum = 106;BA.debugLine="Dim res As LoadResult = CreateLoadResult(True, \"";
_res = _createloadresult(__c.True,"ContentDir",_uri);
 //BA.debugLineNum = 107;BA.debugLine="ExtractInformationFromURI(res.FileName, res)";
_extractinformationfromuri(_res.FileName /*String*/ ,_res);
 //BA.debugLineNum = 108;BA.debugLine="Return res";
if (true) return _res;
 };
 //BA.debugLineNum = 110;BA.debugLine="Return CreateLoadResult(False, \"\", \"\")";
if (true) return _createloadresult(__c.False,"","");
 //BA.debugLineNum = 111;BA.debugLine="End Sub";
return null;
}
public String  _class_globals() throws Exception{
 //BA.debugLineNum = 14;BA.debugLine="Sub Class_Globals";
 //BA.debugLineNum = 16;BA.debugLine="Private ion As Object";
_ion = new Object();
 //BA.debugLineNum = 17;BA.debugLine="Private OldIntent As Intent";
_oldintent = new anywheresoftware.b4a.objects.IntentWrapper();
 //BA.debugLineNum = 19;BA.debugLine="Type LoadResult (Success As Boolean, Dir As Strin";
;
 //BA.debugLineNum = 21;BA.debugLine="End Sub";
return "";
}
public medicomed.keymon.com.mx.filehandler._loadresult  _createloadresult(boolean _success,String _dir,String _filename) throws Exception{
medicomed.keymon.com.mx.filehandler._loadresult _t1 = null;
 //BA.debugLineNum = 149;BA.debugLine="Private Sub CreateLoadResult (Success As Boolean,";
 //BA.debugLineNum = 150;BA.debugLine="Dim t1 As LoadResult";
_t1 = new medicomed.keymon.com.mx.filehandler._loadresult();
 //BA.debugLineNum = 151;BA.debugLine="t1.Initialize";
_t1.Initialize();
 //BA.debugLineNum = 152;BA.debugLine="t1.Success = Success";
_t1.Success /*boolean*/  = _success;
 //BA.debugLineNum = 153;BA.debugLine="t1.Dir = Dir";
_t1.Dir /*String*/  = _dir;
 //BA.debugLineNum = 154;BA.debugLine="t1.FileName = FileName";
_t1.FileName /*String*/  = _filename;
 //BA.debugLineNum = 155;BA.debugLine="Return t1";
if (true) return _t1;
 //BA.debugLineNum = 156;BA.debugLine="End Sub";
return null;
}
public String  _extractinformationfromuri(String _uri,medicomed.keymon.com.mx.filehandler._loadresult _res) throws Exception{
anywheresoftware.b4a.objects.ContentResolverWrapper _resolver = null;
anywheresoftware.b4a.objects.ContentResolverWrapper.UriWrapper _u = null;
anywheresoftware.b4a.sql.SQL.ResultSetWrapper _rs = null;
medicomed.keymon.com.mx.b4xset _columns = null;
int _i = 0;
 //BA.debugLineNum = 70;BA.debugLine="Private Sub ExtractInformationFromURI (Uri As Stri";
 //BA.debugLineNum = 71;BA.debugLine="Try";
try { //BA.debugLineNum = 73;BA.debugLine="Dim resolver As ContentResolver";
_resolver = new anywheresoftware.b4a.objects.ContentResolverWrapper();
 //BA.debugLineNum = 74;BA.debugLine="resolver.Initialize(\"\")";
_resolver.Initialize("");
 //BA.debugLineNum = 75;BA.debugLine="Dim u As Uri";
_u = new anywheresoftware.b4a.objects.ContentResolverWrapper.UriWrapper();
 //BA.debugLineNum = 76;BA.debugLine="u.Parse(Uri)";
_u.Parse(_uri);
 //BA.debugLineNum = 77;BA.debugLine="Dim rs As ResultSet = resolver.Query(u, Null, \"\",";
_rs = new anywheresoftware.b4a.sql.SQL.ResultSetWrapper();
_rs = (anywheresoftware.b4a.sql.SQL.ResultSetWrapper) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.sql.SQL.ResultSetWrapper(), (android.database.Cursor)(_resolver.Query(_u,(String[])(__c.Null),"",(String[])(__c.Null),"").getObject()));
 //BA.debugLineNum = 78;BA.debugLine="If rs.NextRow Then";
if (_rs.NextRow()) { 
 //BA.debugLineNum = 79;BA.debugLine="Dim columns As B4XSet = B4XCollections.CreateSet";
_columns = _b4xcollections._createset /*medicomed.keymon.com.mx.b4xset*/ (getActivityBA());
 //BA.debugLineNum = 80;BA.debugLine="For i = 0 To rs.ColumnCount - 1";
{
final int step9 = 1;
final int limit9 = (int) (_rs.getColumnCount()-1);
_i = (int) (0) ;
for (;_i <= limit9 ;_i = _i + step9 ) {
 //BA.debugLineNum = 81;BA.debugLine="columns.Add(rs.GetColumnName(i))";
_columns._add /*String*/ ((Object)(_rs.GetColumnName(_i)));
 }
};
 //BA.debugLineNum = 83;BA.debugLine="If columns.Contains(\"_display_name\") Then res.Re";
if (_columns._contains /*boolean*/ ((Object)("_display_name"))) { 
_res.RealName /*String*/  = _rs.GetString("_display_name");};
 //BA.debugLineNum = 84;BA.debugLine="If columns.Contains(\"_size\") Then res.Size = rs.";
if (_columns._contains /*boolean*/ ((Object)("_size"))) { 
_res.Size /*long*/  = _rs.GetLong("_size");};
 //BA.debugLineNum = 85;BA.debugLine="If columns.Contains(\"last_modified\") Then res.Mo";
if (_columns._contains /*boolean*/ ((Object)("last_modified"))) { 
_res.Modified /*long*/  = _rs.GetLong("last_modified");};
 //BA.debugLineNum = 86;BA.debugLine="If columns.Contains(\"mime_type\") Then res.MimeTy";
if (_columns._contains /*boolean*/ ((Object)("mime_type"))) { 
_res.MimeType /*String*/  = _rs.GetString("mime_type");};
 };
 //BA.debugLineNum = 88;BA.debugLine="rs.Close";
_rs.Close();
 } 
       catch (Exception e19) {
			ba.setLastException(e19); //BA.debugLineNum = 91;BA.debugLine="Log(\"error extracting information from file prov";
__c.LogImpl("775169813","error extracting information from file provider",0);
 //BA.debugLineNum = 92;BA.debugLine="Log(LastException)";
__c.LogImpl("775169814",BA.ObjectToString(__c.LastException(getActivityBA())),0);
 };
 //BA.debugLineNum = 94;BA.debugLine="End Sub";
return "";
}
public Object  _getba() throws Exception{
 //BA.debugLineNum = 66;BA.debugLine="Private Sub GetBA As Object";
 //BA.debugLineNum = 67;BA.debugLine="Return Me.As(JavaObject).RunMethod(\"getBA\", Null)";
if (true) return ((anywheresoftware.b4j.object.JavaObject) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4j.object.JavaObject(), (java.lang.Object)(this))).RunMethod("getBA",(Object[])(__c.Null));
 //BA.debugLineNum = 68;BA.debugLine="End Sub";
return null;
}
public String  _initialize(anywheresoftware.b4a.BA _ba) throws Exception{
innerInitialize(_ba);
 //BA.debugLineNum = 23;BA.debugLine="Public Sub Initialize";
 //BA.debugLineNum = 25;BA.debugLine="End Sub";
return "";
}
public boolean  _isrelevantintent(anywheresoftware.b4a.objects.IntentWrapper _in) throws Exception{
 //BA.debugLineNum = 113;BA.debugLine="Private Sub IsRelevantIntent(in As Intent) As Bool";
 //BA.debugLineNum = 114;BA.debugLine="If in.IsInitialized And in <> OldIntent And in.Ac";
if (_in.IsInitialized() && (_in).equals(_oldintent) == false && (_in.getAction()).equals(_in.ACTION_VIEW)) { 
 //BA.debugLineNum = 115;BA.debugLine="OldIntent = in";
_oldintent = _in;
 //BA.debugLineNum = 116;BA.debugLine="Return True";
if (true) return __c.True;
 };
 //BA.debugLineNum = 118;BA.debugLine="Return False";
if (true) return __c.False;
 //BA.debugLineNum = 119;BA.debugLine="End Sub";
return false;
}
public anywheresoftware.b4a.keywords.Common.ResumableSubWrapper  _load() throws Exception{
ResumableSub_Load rsub = new ResumableSub_Load(this);
rsub.resume(ba, null);
return (anywheresoftware.b4a.keywords.Common.ResumableSubWrapper) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.keywords.Common.ResumableSubWrapper(), rsub);
}
public static class ResumableSub_Load extends BA.ResumableSub {
public ResumableSub_Load(medicomed.keymon.com.mx.filehandler parent) {
this.parent = parent;
}
medicomed.keymon.com.mx.filehandler parent;
anywheresoftware.b4a.phone.Phone.ContentChooser _cc = null;
boolean _success = false;
String _dir = "";
String _filename = "";
medicomed.keymon.com.mx.filehandler._loadresult _res = null;

@Override
public void resume(BA ba, Object[] result) throws Exception{

    while (true) {
        switch (state) {
            case -1:
{
parent.__c.ReturnFromResumableSub(this,null);return;}
case 0:
//C
this.state = 1;
 //BA.debugLineNum = 49;BA.debugLine="Dim cc As ContentChooser";
_cc = new anywheresoftware.b4a.phone.Phone.ContentChooser();
 //BA.debugLineNum = 50;BA.debugLine="cc.Initialize(\"cc\")";
_cc.Initialize("cc");
 //BA.debugLineNum = 51;BA.debugLine="cc.Show(\"application/octet-stream\", \"Choose text";
_cc.Show(ba,"application/octet-stream","Choose text file");
 //BA.debugLineNum = 52;BA.debugLine="Wait For CC_Result (Success As Boolean, Dir As St";
parent.__c.WaitFor("cc_result", ba, this, null);
this.state = 7;
return;
case 7:
//C
this.state = 1;
_success = (Boolean) result[0];
_dir = (String) result[1];
_filename = (String) result[2];
;
 //BA.debugLineNum = 53;BA.debugLine="Log($\"***************************${CRLF}${Dir}${C";
parent.__c.LogImpl("774973189",("***************************"+parent.__c.SmartStringFormatter("",(Object)(parent.__c.CRLF))+""+parent.__c.SmartStringFormatter("",(Object)(_dir))+""+parent.__c.SmartStringFormatter("",(Object)(parent.__c.CRLF))+" "+parent.__c.SmartStringFormatter("",(Object)(_filename))+""),0);
 //BA.debugLineNum = 54;BA.debugLine="Dim res As LoadResult = CreateLoadResult(Success,";
_res = parent._createloadresult(_success,_dir,_filename);
 //BA.debugLineNum = 55;BA.debugLine="Log($\"***************************${CRLF}${res.Fil";
parent.__c.LogImpl("774973191",("***************************"+parent.__c.SmartStringFormatter("",(Object)(parent.__c.CRLF))+""+parent.__c.SmartStringFormatter("",(Object)(_res.FileName /*String*/ ))+""+parent.__c.SmartStringFormatter("",(Object)(parent.__c.CRLF))+" "+parent.__c.SmartStringFormatter("",(Object)(_res))+""),0);
 //BA.debugLineNum = 56;BA.debugLine="If res.Success Then ExtractInformationFromURI(res";
if (true) break;

case 1:
//if
this.state = 6;
if (_res.Success /*boolean*/ ) { 
this.state = 3;
;}if (true) break;

case 3:
//C
this.state = 6;
parent._extractinformationfromuri(_res.FileName /*String*/ ,_res);
if (true) break;

case 6:
//C
this.state = -1;
;
 //BA.debugLineNum = 57;BA.debugLine="Return res";
if (true) {
parent.__c.ReturnFromResumableSub(this,(Object)(_res));return;};
 //BA.debugLineNum = 58;BA.debugLine="End Sub";
if (true) break;

            }
        }
    }
}
public void  _cc_result(boolean _success,String _dir,String _filename) throws Exception{
}
public anywheresoftware.b4a.keywords.Common.ResumableSubWrapper  _saveas(anywheresoftware.b4a.objects.streams.File.InputStreamWrapper _source,String _mimetype,String _title) throws Exception{
ResumableSub_SaveAs rsub = new ResumableSub_SaveAs(this,_source,_mimetype,_title);
rsub.resume(ba, null);
return (anywheresoftware.b4a.keywords.Common.ResumableSubWrapper) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.keywords.Common.ResumableSubWrapper(), rsub);
}
public static class ResumableSub_SaveAs extends BA.ResumableSub {
public ResumableSub_SaveAs(medicomed.keymon.com.mx.filehandler parent,anywheresoftware.b4a.objects.streams.File.InputStreamWrapper _source,String _mimetype,String _title) {
this.parent = parent;
this._source = _source;
this._mimetype = _mimetype;
this._title = _title;
}
medicomed.keymon.com.mx.filehandler parent;
anywheresoftware.b4a.objects.streams.File.InputStreamWrapper _source;
String _mimetype;
String _title;
anywheresoftware.b4a.objects.IntentWrapper _intent = null;
String _methodname = "";
Object[] _args = null;
anywheresoftware.b4a.objects.IntentWrapper _result = null;
anywheresoftware.b4j.object.JavaObject _jo = null;
anywheresoftware.b4j.object.JavaObject _ctxt = null;
anywheresoftware.b4a.objects.streams.File.OutputStreamWrapper _out = null;

@Override
public void resume(BA ba, Object[] result) throws Exception{

    while (true) {
        switch (state) {
            case -1:
{
parent.__c.ReturnFromResumableSub(this,null);return;}
case 0:
//C
this.state = 1;
 //BA.debugLineNum = 29;BA.debugLine="Dim intent As Intent";
_intent = new anywheresoftware.b4a.objects.IntentWrapper();
 //BA.debugLineNum = 30;BA.debugLine="intent.Initialize(\"android.intent.action.CREATE_D";
_intent.Initialize("android.intent.action.CREATE_DOCUMENT","");
 //BA.debugLineNum = 31;BA.debugLine="intent.AddCategory(\"android.intent.category.OPENA";
_intent.AddCategory("android.intent.category.OPENABLE");
 //BA.debugLineNum = 32;BA.debugLine="intent.PutExtra(\"android.intent.extra.TITLE\", Tit";
_intent.PutExtra("android.intent.extra.TITLE",(Object)(_title));
 //BA.debugLineNum = 33;BA.debugLine="intent.SetType(MimeType)";
_intent.SetType(_mimetype);
 //BA.debugLineNum = 34;BA.debugLine="StartActivityForResult(intent)";
parent._startactivityforresult(_intent);
 //BA.debugLineNum = 35;BA.debugLine="Wait For ion_Event (MethodName As String, Args()";
parent.__c.WaitFor("ion_event", ba, this, null);
this.state = 5;
return;
case 5:
//C
this.state = 1;
_methodname = (String) result[0];
_args = (Object[]) result[1];
;
 //BA.debugLineNum = 36;BA.debugLine="If -1 = Args(0) Then 'resultCode = RESULT_OK";
if (true) break;

case 1:
//if
this.state = 4;
if (-1==(double)(BA.ObjectToNumber(_args[(int) (0)]))) { 
this.state = 3;
}if (true) break;

case 3:
//C
this.state = 4;
 //BA.debugLineNum = 37;BA.debugLine="Dim result As Intent = Args(1)";
_result = new anywheresoftware.b4a.objects.IntentWrapper();
_result = (anywheresoftware.b4a.objects.IntentWrapper) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.IntentWrapper(), (android.content.Intent)(_args[(int) (1)]));
 //BA.debugLineNum = 38;BA.debugLine="Dim jo As JavaObject = result";
_jo = new anywheresoftware.b4j.object.JavaObject();
_jo = (anywheresoftware.b4j.object.JavaObject) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4j.object.JavaObject(), (java.lang.Object)(_result.getObject()));
 //BA.debugLineNum = 39;BA.debugLine="Dim ctxt As JavaObject";
_ctxt = new anywheresoftware.b4j.object.JavaObject();
 //BA.debugLineNum = 40;BA.debugLine="Dim out As OutputStream = ctxt.InitializeContext";
_out = new anywheresoftware.b4a.objects.streams.File.OutputStreamWrapper();
_out = (anywheresoftware.b4a.objects.streams.File.OutputStreamWrapper) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4a.objects.streams.File.OutputStreamWrapper(), (java.io.OutputStream)(_ctxt.InitializeContext(ba).RunMethodJO("getContentResolver",(Object[])(parent.__c.Null)).RunMethod("openOutputStream",new Object[]{_jo.RunMethod("getData",(Object[])(parent.__c.Null))})));
 //BA.debugLineNum = 41;BA.debugLine="File.Copy2(Source, out)";
parent.__c.File.Copy2((java.io.InputStream)(_source.getObject()),(java.io.OutputStream)(_out.getObject()));
 //BA.debugLineNum = 42;BA.debugLine="out.Close";
_out.Close();
 //BA.debugLineNum = 43;BA.debugLine="Return True";
if (true) {
parent.__c.ReturnFromResumableSub(this,(Object)(parent.__c.True));return;};
 if (true) break;

case 4:
//C
this.state = -1;
;
 //BA.debugLineNum = 45;BA.debugLine="Return False";
if (true) {
parent.__c.ReturnFromResumableSub(this,(Object)(parent.__c.False));return;};
 //BA.debugLineNum = 46;BA.debugLine="End Sub";
if (true) break;

            }
        }
    }
}
public void  _ion_event(String _methodname,Object[] _args) throws Exception{
}
public String  _startactivityforresult(anywheresoftware.b4a.objects.IntentWrapper _i) throws Exception{
anywheresoftware.b4j.object.JavaObject _jo = null;
 //BA.debugLineNum = 60;BA.debugLine="Private Sub StartActivityForResult(i As Intent)";
 //BA.debugLineNum = 61;BA.debugLine="Dim jo As JavaObject = GetBA";
_jo = new anywheresoftware.b4j.object.JavaObject();
_jo = (anywheresoftware.b4j.object.JavaObject) anywheresoftware.b4a.AbsObjectWrapper.ConvertToWrapper(new anywheresoftware.b4j.object.JavaObject(), (java.lang.Object)(_getba()));
 //BA.debugLineNum = 62;BA.debugLine="ion = jo.CreateEvent(\"anywheresoftware.b4a.IOnAct";
_ion = _jo.CreateEvent(ba,"anywheresoftware.b4a.IOnActivityResult","ion",__c.Null);
 //BA.debugLineNum = 63;BA.debugLine="jo.RunMethod(\"startActivityForResult\", Array(ion,";
_jo.RunMethod("startActivityForResult",new Object[]{_ion,(Object)(_i.getObject())});
 //BA.debugLineNum = 64;BA.debugLine="End Sub";
return "";
}
public Object callSub(String sub, Object sender, Object[] args) throws Exception {
BA.senderHolder.set(sender);
return BA.SubDelegator.SubNotFound;
}
}
