You've already forked lazarus-ccr
Adds an example application for Android
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@1789 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
21
examples/androidlcl/android/AndroidManifest.xml
Normal file
21
examples/androidlcl/android/AndroidManifest.xml
Normal file
@ -0,0 +1,21 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.pascal.androidlcl"
|
||||
android:versionCode="1"
|
||||
android:versionName="1.0">
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<supports-screens android:smallScreens="true" android:normalScreens="true" android:largeScreens="true" android:anyDensity="true" />
|
||||
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="4" />
|
||||
<application android:label="@string/app_name" android:icon="@drawable/icon"
|
||||
android:debuggable="True">
|
||||
<activity android:name="AndroidLCLTest"
|
||||
android:configChanges="orientation|keyboardHidden"
|
||||
android:label="@string/app_name"
|
||||
android:launchMode="singleTop">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
</application>
|
||||
</manifest>
|
17
examples/androidlcl/android/build.properties
Normal file
17
examples/androidlcl/android/build.properties
Normal file
@ -0,0 +1,17 @@
|
||||
# This file is used to override default values used by the Ant build system.
|
||||
#
|
||||
# This file must be checked in Version Control Systems, as it is
|
||||
# integral to the build system of your project.
|
||||
|
||||
# This file is only used by the Ant script.
|
||||
|
||||
# You can use this to override default values such as
|
||||
# 'source.dir' for the location of your java source folder and
|
||||
# 'out.dir' for the location of your output folder.
|
||||
|
||||
# You can also use it define how the release builds are signed by declaring
|
||||
# the following properties:
|
||||
# 'key.store' for the location of your keystore and
|
||||
# 'key.alias' for the name of the key to use.
|
||||
# The password will be asked during the build when you use the 'release' target.
|
||||
|
84
examples/androidlcl/android/build.xml
Normal file
84
examples/androidlcl/android/build.xml
Normal file
@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="AndroidLCLTest" default="help">
|
||||
|
||||
<!-- The local.properties file is created and updated by the 'android'
|
||||
tool.
|
||||
It contains the path to the SDK. It should *NOT* be checked into
|
||||
Version Control Systems. -->
|
||||
<property file="local.properties" />
|
||||
|
||||
<!-- The build.properties file can be created by you and is never touched
|
||||
by the 'android' tool. This is the place to change some of the
|
||||
default property values used by the Ant rules.
|
||||
Here are some properties you may want to change/update:
|
||||
|
||||
source.dir
|
||||
The name of the source directory. Default is 'src'.
|
||||
out.dir
|
||||
The name of the output directory. Default is 'bin'.
|
||||
|
||||
Properties related to the SDK location or the project target should
|
||||
be updated using the 'android' tool with the 'update' action.
|
||||
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems.
|
||||
|
||||
-->
|
||||
<property file="build.properties" />
|
||||
|
||||
<!-- The default.properties file is created and updated by the 'android'
|
||||
tool, as well as ADT.
|
||||
This file is an integral part of the build system for your
|
||||
application and should be checked into Version Control Systems. -->
|
||||
<property file="default.properties" />
|
||||
|
||||
<!-- Custom Android task to deal with the project target, and import the
|
||||
proper rules.
|
||||
This requires ant 1.6.0 or above. -->
|
||||
<path id="android.antlibs">
|
||||
<pathelement path="${sdk.dir}/tools/lib/anttasks.jar" />
|
||||
<pathelement path="${sdk.dir}/tools/lib/sdklib.jar" />
|
||||
<pathelement path="${sdk.dir}/tools/lib/androidprefs.jar" />
|
||||
</path>
|
||||
|
||||
<taskdef name="setup"
|
||||
classname="com.android.ant.SetupTask"
|
||||
classpathref="android.antlibs" />
|
||||
|
||||
<!-- extension targets. Uncomment the ones where you want to do custom work
|
||||
in between standard targets -->
|
||||
<!--
|
||||
<target name="-pre-build">
|
||||
</target>
|
||||
<target name="-pre-compile">
|
||||
</target>
|
||||
|
||||
[This is typically used for code obfuscation.
|
||||
Compiled code location: ${out.classes.absolute.dir}
|
||||
If this is not done in place, override ${out.dex.input.absolute.dir}]
|
||||
<target name="-post-compile">
|
||||
</target>
|
||||
-->
|
||||
|
||||
|
||||
<!-- Execute the Android Setup task that will setup some properties
|
||||
specific to the target, and import the build rules files.
|
||||
|
||||
The rules file is imported from
|
||||
<SDK>/platforms/<target_platform>/ant/ant_rules_r#.xml
|
||||
|
||||
To customize existing targets, there are two options:
|
||||
- Customize only one target:
|
||||
- copy/paste the target into this file, *before* the
|
||||
<setup> task.
|
||||
- customize it to your needs.
|
||||
- Customize the whole script.
|
||||
- copy/paste the content of the rules files (minus the top node)
|
||||
into this file, *after* the <setup> task
|
||||
- disable the import of the rules by changing the setup task
|
||||
below to <setup import="false" />.
|
||||
- customize to your needs.
|
||||
-->
|
||||
<setup />
|
||||
|
||||
</project>
|
11
examples/androidlcl/android/default.properties
Normal file
11
examples/androidlcl/android/default.properties
Normal file
@ -0,0 +1,11 @@
|
||||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must be checked in Version Control Systems.
|
||||
#
|
||||
# To customize properties used by the Ant build system use,
|
||||
# "build.properties", and override values to adapt the script to your
|
||||
# project structure.
|
||||
|
||||
# Project target.
|
||||
target=android-4
|
10
examples/androidlcl/android/local.properties
Normal file
10
examples/androidlcl/android/local.properties
Normal file
@ -0,0 +1,10 @@
|
||||
# This file is automatically generated by Android Tools.
|
||||
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
|
||||
#
|
||||
# This file must *NOT* be checked in Version Control Systems,
|
||||
# as it contains information specific to your local configuration.
|
||||
|
||||
# location of the SDK. This is only used by Ant
|
||||
# For customization when using a Version Control System, please read the
|
||||
# header note.
|
||||
sdk.dir=/home/felipe/Programas/android-sdk-linux_x86
|
BIN
examples/androidlcl/android/res/drawable-hdpi/icon.png
Normal file
BIN
examples/androidlcl/android/res/drawable-hdpi/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.9 KiB |
BIN
examples/androidlcl/android/res/drawable-ldpi/icon.png
Normal file
BIN
examples/androidlcl/android/res/drawable-ldpi/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
BIN
examples/androidlcl/android/res/drawable-mdpi/icon.png
Normal file
BIN
examples/androidlcl/android/res/drawable-mdpi/icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.8 KiB |
4
examples/androidlcl/android/res/values/strings.xml
Normal file
4
examples/androidlcl/android/res/values/strings.xml
Normal file
@ -0,0 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<string name="app_name">LCL Test</string>
|
||||
</resources>
|
@ -0,0 +1,525 @@
|
||||
package com.pascal.androidlcl;
|
||||
|
||||
import android.app.*;
|
||||
import android.view.*;
|
||||
import android.os.*;
|
||||
import android.util.*;
|
||||
import android.content.*;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
import java.util.*;
|
||||
import java.lang.*;
|
||||
|
||||
public class AndroidAll
|
||||
{
|
||||
// info from other classes
|
||||
Activity activity;
|
||||
AndroidPipesComm MyAndroidPipesComm;
|
||||
JavaLang MyJavaLang;
|
||||
// lists of variables
|
||||
ArrayList ViewElements;
|
||||
|
||||
public AndroidAll(AndroidPipesComm AAndroidPipesComm, Activity AActivity, JavaLang AJavaLang)
|
||||
{
|
||||
activity = AActivity;
|
||||
MyAndroidPipesComm = AAndroidPipesComm;
|
||||
MyJavaLang = AJavaLang;
|
||||
ViewElements = new ArrayList();
|
||||
}
|
||||
|
||||
public void DebugOut(String Str)
|
||||
{
|
||||
MyAndroidPipesComm.DebugOut(Str);
|
||||
}
|
||||
|
||||
// DisplayMetrics
|
||||
static final int amkUI_TDisplayMetrics_Create = 0x00101000;
|
||||
static final int amkUI_TDisplayMetrics_density = 0x00101001;
|
||||
static final int amkUI_TDisplayMetrics_densityDpi = 0x00101002;
|
||||
static final int amkUI_TDisplayMetrics_heightPixels = 0x00101003;
|
||||
static final int amkUI_TDisplayMetrics_scaledDensity = 0x00101004;
|
||||
static final int amkUI_TDisplayMetrics_widthPixels = 0x00101005;
|
||||
static final int amkUI_TDisplayMetrics_xdpi = 0x00101006;
|
||||
static final int amkUI_TDisplayMetrics_ydpi = 0x00101007;
|
||||
// Display
|
||||
static final int amkUI_TDisplay_getMetrics = 0x00102000;
|
||||
// WindowManager
|
||||
static final int amkUI_TWindowManager_getDefaultDisplay = 0x00103000;
|
||||
// ViewGroup.LayoutParams
|
||||
static final int amkUI_TViewGroup_LayoutParams_Create = 0x00104000;
|
||||
// View
|
||||
static final int amkUI_TView_setLayoutParams = 0x00105000;
|
||||
static final int amkUI_TView_setVisibility = 0x00105001;
|
||||
// ViewGroup
|
||||
static final int amkUI_TViewGroup_addView = 0x00106000;
|
||||
// LinearLayout
|
||||
static final int amkUI_TLinearLayout_Create = 0x00107000;
|
||||
static final int amkUI_TLinearLayout_setOrientation = 0x00107001;
|
||||
// AbsoluteLayout
|
||||
static final int amkUI_TAbsoluteLayout_Create = 0x00108000;
|
||||
// AbsoluteLayout.LayoutParams
|
||||
static final int amkUI_TAbsoluteLayout_LayoutParams_Create = 0x00109000;
|
||||
// TextView
|
||||
static final int amkUI_TTextView_Create = 0x0010A000;
|
||||
static final int amkUI_TTextView_setText = 0x0010A001;
|
||||
static final int amkUI_TTextView_setOnClickListener = 0x0010A002;
|
||||
static final int amkUI_TTextView_OnClickListener_Start = 0x0010A002;
|
||||
static final int amkUI_TTextView_OnClickListener_Finished = 0x0010A002;
|
||||
static final int amkUI_TTextView_setTextSize = 0x0010A002;
|
||||
// EditText
|
||||
static final int amkUI_TEditText_Create = 0x0010B000;
|
||||
static final int amkUI_TEditText_setText = 0x0010B001;
|
||||
// Button
|
||||
static final int amkUI_TButton_Create = 0x0010C000;
|
||||
static final int amkUI_TButton_setText = 0x0010C001;
|
||||
// FrameLayout
|
||||
// TimePicker
|
||||
static final int amkUI_TTimePicker_Create = 0x0010E000;
|
||||
static final int amkUI_TTimePicker_getCurrentHour = 0x0010E001;
|
||||
static final int amkUI_TTimePicker_setCurrentHour = 0x0010E002;
|
||||
static final int amkUI_TTimePicker_getCurrentMinute = 0x0010E003;
|
||||
static final int amkUI_TTimePicker_setCurrentMinute = 0x0010E004;
|
||||
static final int amkUI_TTimePicker_is24HourView = 0x0010E005;
|
||||
static final int amkUI_TTimePicker_setIs24HourView = 0x0010E006;
|
||||
// ScrollView
|
||||
static final int amkUI_TScrollView_Create = 0x0010F000;
|
||||
// CompoundButton
|
||||
static final int amkUI_TCompoundButton_isChecked = 0x00110000;
|
||||
static final int amkUI_TCompoundButton_performClick = 0x00110001;
|
||||
static final int amkUI_TCompoundButton_setChecked = 0x00110002;
|
||||
static final int amkUI_TCompoundButton_toggle = 0x00110003;
|
||||
// CheckBox
|
||||
static final int amkUI_TCheckBox_Create = 0x00111000;
|
||||
|
||||
public boolean ProcessCommand(int Buffer)
|
||||
{
|
||||
//DebugOut("AndroidUI.ProcessCommand Command=" + java.lang.Integer.toHexString(Buffer));
|
||||
// basic types
|
||||
int lInt, lIndex, lPascalPointer;
|
||||
boolean lBool;
|
||||
float lFloat;
|
||||
// Self params
|
||||
View param_self_View;
|
||||
ViewGroup param_self_ViewGroup;
|
||||
TextView param_self_TextView;
|
||||
Button param_self_Button;
|
||||
EditText param_self_EditText;
|
||||
LinearLayout param_self_LinearLayout;
|
||||
TimePicker param_self_TimePicker;
|
||||
Display param_self_Display;
|
||||
DisplayMetrics param_self_DisplayMetrics;
|
||||
CompoundButton param_self_CompoundButton;
|
||||
WindowManager param_self_WindowManager;
|
||||
// Params
|
||||
ViewGroup.LayoutParams lViewGroup_LayoutParams_1, lViewGroup_LayoutParams_2;
|
||||
DisplayMetrics lDisplayMetrics_1;
|
||||
CharSequence lCharSequence_1;
|
||||
View lView_1;
|
||||
int lint_1, lint_2, lint_3, lint_4;
|
||||
float lfloat_1, lfloat_2;
|
||||
boolean lboolean_1;
|
||||
// Results
|
||||
float lResult_float;
|
||||
int lResult_int;
|
||||
boolean lResult_boolean;
|
||||
Display lResult_Display;
|
||||
|
||||
switch (Buffer)
|
||||
{
|
||||
|
||||
case amkUI_TDisplayMetrics_Create:
|
||||
DebugOut("amkUI_TDisplayMetrics_Create");
|
||||
ViewElements.add(new DisplayMetrics());
|
||||
MyAndroidPipesComm.SendIntResult(ViewElements.size() - 1);
|
||||
break;
|
||||
// field float density
|
||||
case amkUI_TDisplayMetrics_density:
|
||||
DebugOut("amkUI_TDisplayMetrics_density");
|
||||
// Self
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
param_self_DisplayMetrics = (DisplayMetrics) ViewElements.get(lInt);
|
||||
// params
|
||||
//
|
||||
lResult_float = param_self_DisplayMetrics.density;
|
||||
MyAndroidPipesComm.SendFloatResult(lResult_float);
|
||||
break;
|
||||
// field int densityDpi
|
||||
case amkUI_TDisplayMetrics_densityDpi:
|
||||
DebugOut("amkUI_TDisplayMetrics_densityDpi");
|
||||
// Self
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
param_self_DisplayMetrics = (DisplayMetrics) ViewElements.get(lInt);
|
||||
// params
|
||||
//
|
||||
lResult_int = param_self_DisplayMetrics.densityDpi;
|
||||
MyAndroidPipesComm.SendIntResult(lResult_int);
|
||||
break;
|
||||
// field int heightPixels
|
||||
case amkUI_TDisplayMetrics_heightPixels:
|
||||
DebugOut("amkUI_TDisplayMetrics_heightPixels");
|
||||
// Self
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
param_self_DisplayMetrics = (DisplayMetrics) ViewElements.get(lInt);
|
||||
// params
|
||||
//
|
||||
lResult_int = param_self_DisplayMetrics.heightPixels;
|
||||
MyAndroidPipesComm.SendIntResult(lResult_int);
|
||||
break;
|
||||
// field float scaledDensity
|
||||
case amkUI_TDisplayMetrics_scaledDensity:
|
||||
DebugOut("amkUI_TDisplayMetrics_scaledDensity");
|
||||
// Self
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
param_self_DisplayMetrics = (DisplayMetrics) ViewElements.get(lInt);
|
||||
// params
|
||||
//
|
||||
lResult_float = param_self_DisplayMetrics.scaledDensity;
|
||||
MyAndroidPipesComm.SendFloatResult(lResult_float);
|
||||
break;
|
||||
// field int widthPixels
|
||||
case amkUI_TDisplayMetrics_widthPixels:
|
||||
DebugOut("amkUI_TDisplayMetrics_widthPixels");
|
||||
// Self
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
param_self_DisplayMetrics = (DisplayMetrics) ViewElements.get(lInt);
|
||||
// params
|
||||
//
|
||||
lResult_int = param_self_DisplayMetrics.widthPixels;
|
||||
MyAndroidPipesComm.SendIntResult(lResult_int);
|
||||
break;
|
||||
// field float xdpi
|
||||
case amkUI_TDisplayMetrics_xdpi:
|
||||
DebugOut("amkUI_TDisplayMetrics_xdpi");
|
||||
// Self
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
param_self_DisplayMetrics = (DisplayMetrics) ViewElements.get(lInt);
|
||||
// params
|
||||
//
|
||||
lResult_float = param_self_DisplayMetrics.xdpi;
|
||||
MyAndroidPipesComm.SendFloatResult(lResult_float);
|
||||
break;
|
||||
// field float ydpi
|
||||
case amkUI_TDisplayMetrics_ydpi:
|
||||
DebugOut("amkUI_TDisplayMetrics_ydpi");
|
||||
// Self
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
param_self_DisplayMetrics = (DisplayMetrics) ViewElements.get(lInt);
|
||||
// params
|
||||
//
|
||||
lResult_float = param_self_DisplayMetrics.ydpi;
|
||||
MyAndroidPipesComm.SendFloatResult(lResult_float);
|
||||
break;
|
||||
// method void getMetrics(DisplayMetrics outMetrics)
|
||||
case amkUI_TDisplay_getMetrics:
|
||||
DebugOut("amkUI_TDisplay_getMetrics");
|
||||
// Self
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
param_self_Display = (Display) ViewElements.get(lInt);
|
||||
// params
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
lDisplayMetrics_1 = (DisplayMetrics) ViewElements.get(lInt);
|
||||
//
|
||||
param_self_Display.getMetrics(lDisplayMetrics_1);
|
||||
MyAndroidPipesComm.SendResult();
|
||||
break;
|
||||
// method Display getDefaultDisplay()
|
||||
case amkUI_TWindowManager_getDefaultDisplay:
|
||||
DebugOut("amkUI_TWindowManager_getDefaultDisplay");
|
||||
// Self
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
param_self_WindowManager = (WindowManager) ViewElements.get(lInt);
|
||||
// params
|
||||
//
|
||||
lResult_Display = param_self_WindowManager.getDefaultDisplay();
|
||||
ViewElements.add(lResult_Display);
|
||||
MyAndroidPipesComm.SendIntResult(ViewElements.size() - 1);
|
||||
break;
|
||||
case amkUI_TViewGroup_LayoutParams_Create:
|
||||
DebugOut("amkUI_TViewGroup_LayoutParams_Create");
|
||||
lint_1 = MyAndroidPipesComm.GetInt();
|
||||
lint_2 = MyAndroidPipesComm.GetInt();
|
||||
ViewElements.add(new ViewGroup.LayoutParams(lint_1, lint_2));
|
||||
MyAndroidPipesComm.SendIntResult(ViewElements.size() - 1);
|
||||
break;
|
||||
// method void setLayoutParams(ViewGroup.LayoutParams params);
|
||||
case amkUI_TView_setLayoutParams:
|
||||
DebugOut("amkUI_TView_setLayoutParams");
|
||||
// Self
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
param_self_View = (View) ViewElements.get(lInt);
|
||||
// params
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
lViewGroup_LayoutParams_1 = (ViewGroup.LayoutParams) ViewElements.get(lInt);
|
||||
//
|
||||
param_self_View.setLayoutParams(lViewGroup_LayoutParams_1);
|
||||
MyAndroidPipesComm.SendResult();
|
||||
break;
|
||||
// method void setVisibility(int visibility);
|
||||
case amkUI_TView_setVisibility:
|
||||
DebugOut("amkUI_TView_setVisibility");
|
||||
// Self
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
param_self_View = (View) ViewElements.get(lInt);
|
||||
// params
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
lint_1 = lInt;
|
||||
//
|
||||
param_self_View.setVisibility(lint_1);
|
||||
MyAndroidPipesComm.SendResult();
|
||||
break;
|
||||
// method void addView(View child, ViewGroup.LayoutParams params);
|
||||
case amkUI_TViewGroup_addView:
|
||||
DebugOut("amkUI_TViewGroup_addView");
|
||||
// Self
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
param_self_ViewGroup = (ViewGroup) ViewElements.get(lInt);
|
||||
// params
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
lView_1 = (View) ViewElements.get(lInt);
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
lViewGroup_LayoutParams_2 = (ViewGroup.LayoutParams) ViewElements.get(lInt);
|
||||
//
|
||||
param_self_ViewGroup.addView(lView_1, lViewGroup_LayoutParams_2);
|
||||
MyAndroidPipesComm.SendResult();
|
||||
break;
|
||||
case amkUI_TLinearLayout_Create:
|
||||
DebugOut("amkUI_TLinearLayout_Create");
|
||||
ViewElements.add(new LinearLayout(activity));
|
||||
MyAndroidPipesComm.SendIntResult(ViewElements.size() - 1);
|
||||
break;
|
||||
// method void setOrientation(int orientation);
|
||||
case amkUI_TLinearLayout_setOrientation:
|
||||
DebugOut("amkUI_TLinearLayout_setOrientation");
|
||||
// Self
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
param_self_LinearLayout = (LinearLayout) ViewElements.get(lInt);
|
||||
// params
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
lint_1 = lInt;
|
||||
//
|
||||
param_self_LinearLayout.setOrientation(lint_1);
|
||||
MyAndroidPipesComm.SendResult();
|
||||
break;
|
||||
case amkUI_TAbsoluteLayout_Create:
|
||||
DebugOut("amkUI_TAbsoluteLayout_Create");
|
||||
ViewElements.add(new AbsoluteLayout(activity));
|
||||
MyAndroidPipesComm.SendIntResult(ViewElements.size() - 1);
|
||||
break;
|
||||
case amkUI_TAbsoluteLayout_LayoutParams_Create:
|
||||
DebugOut("amkUI_TAbsoluteLayout_LayoutParams_Create");
|
||||
lint_1 = MyAndroidPipesComm.GetInt();
|
||||
lint_2 = MyAndroidPipesComm.GetInt();
|
||||
lint_3 = MyAndroidPipesComm.GetInt();
|
||||
lint_4 = MyAndroidPipesComm.GetInt();
|
||||
ViewElements.add(new AbsoluteLayout.LayoutParams(lint_1, lint_2, lint_3, lint_4));
|
||||
MyAndroidPipesComm.SendIntResult(ViewElements.size() - 1);
|
||||
break;
|
||||
case amkUI_TTextView_Create:
|
||||
DebugOut("amkUI_TTextView_Create");
|
||||
ViewElements.add(new TextView(activity));
|
||||
MyAndroidPipesComm.SendIntResult(ViewElements.size() - 1);
|
||||
break;
|
||||
// method void setText(CharSequence AText); virtual;
|
||||
case amkUI_TTextView_setText:
|
||||
DebugOut("amkUI_TTextView_setText");
|
||||
// Self
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
param_self_TextView = (TextView) ViewElements.get(lInt);
|
||||
// params
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
lCharSequence_1 = (CharSequence) MyJavaLang.LangElements.get(lInt);
|
||||
//
|
||||
param_self_TextView.setText(lCharSequence_1);
|
||||
MyAndroidPipesComm.SendResult();
|
||||
break;
|
||||
// method void setTextSize(int unit_; float size);
|
||||
case amkUI_TTextView_setTextSize:
|
||||
DebugOut("amkUI_TTextView_setTextSize");
|
||||
// Self
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
param_self_TextView = (TextView) ViewElements.get(lInt);
|
||||
// params
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
lint_1 = lInt;
|
||||
lFloat = MyAndroidPipesComm.GetFloat();
|
||||
lfloat_2 = lFloat;
|
||||
//
|
||||
param_self_TextView.setTextSize(lint_1, lfloat_2);
|
||||
MyAndroidPipesComm.SendResult();
|
||||
break;
|
||||
case amkUI_TEditText_Create:
|
||||
DebugOut("amkUI_TEditText_Create");
|
||||
ViewElements.add(new EditText(activity));
|
||||
MyAndroidPipesComm.SendIntResult(ViewElements.size() - 1);
|
||||
break;
|
||||
// method void setText(CharSequence AText); override;
|
||||
case amkUI_TEditText_setText:
|
||||
DebugOut("amkUI_TEditText_setText");
|
||||
// Self
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
param_self_EditText = (EditText) ViewElements.get(lInt);
|
||||
// params
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
lCharSequence_1 = (CharSequence) MyJavaLang.LangElements.get(lInt);
|
||||
//
|
||||
param_self_EditText.setText(lCharSequence_1);
|
||||
MyAndroidPipesComm.SendResult();
|
||||
break;
|
||||
case amkUI_TButton_Create:
|
||||
DebugOut("amkUI_TButton_Create");
|
||||
ViewElements.add(new Button(activity));
|
||||
MyAndroidPipesComm.SendIntResult(ViewElements.size() - 1);
|
||||
break;
|
||||
// method void setText(CharSequence AText); override;
|
||||
case amkUI_TButton_setText:
|
||||
DebugOut("amkUI_TButton_setText");
|
||||
// Self
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
param_self_Button = (Button) ViewElements.get(lInt);
|
||||
// params
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
lCharSequence_1 = (CharSequence) MyJavaLang.LangElements.get(lInt);
|
||||
//
|
||||
param_self_Button.setText(lCharSequence_1);
|
||||
MyAndroidPipesComm.SendResult();
|
||||
break;
|
||||
case amkUI_TTimePicker_Create:
|
||||
DebugOut("amkUI_TTimePicker_Create");
|
||||
ViewElements.add(new TimePicker(activity));
|
||||
MyAndroidPipesComm.SendIntResult(ViewElements.size() - 1);
|
||||
break;
|
||||
// method int getCurrentHour();
|
||||
case amkUI_TTimePicker_getCurrentHour:
|
||||
DebugOut("amkUI_TTimePicker_getCurrentHour");
|
||||
// Self
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
param_self_TimePicker = (TimePicker) ViewElements.get(lInt);
|
||||
// params
|
||||
//
|
||||
lResult_int = param_self_TimePicker.getCurrentHour();
|
||||
MyAndroidPipesComm.SendIntResult(lResult_int);
|
||||
break;
|
||||
// method void setCurrentHour(int currentHour);
|
||||
case amkUI_TTimePicker_setCurrentHour:
|
||||
DebugOut("amkUI_TTimePicker_setCurrentHour");
|
||||
// Self
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
param_self_TimePicker = (TimePicker) ViewElements.get(lInt);
|
||||
// params
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
lint_1 = lInt;
|
||||
//
|
||||
param_self_TimePicker.setCurrentHour(lint_1);
|
||||
MyAndroidPipesComm.SendResult();
|
||||
break;
|
||||
// method int getCurrentMinute;
|
||||
case amkUI_TTimePicker_getCurrentMinute:
|
||||
DebugOut("amkUI_TTimePicker_getCurrentMinute");
|
||||
// Self
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
param_self_TimePicker = (TimePicker) ViewElements.get(lInt);
|
||||
// params
|
||||
//
|
||||
lResult_int = param_self_TimePicker.getCurrentMinute();
|
||||
MyAndroidPipesComm.SendIntResult(lResult_int);
|
||||
break;
|
||||
// method void setCurrentMinute(int currentMinute);
|
||||
case amkUI_TTimePicker_setCurrentMinute:
|
||||
DebugOut("amkUI_TTimePicker_setCurrentMinute");
|
||||
// Self
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
param_self_TimePicker = (TimePicker) ViewElements.get(lInt);
|
||||
// params
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
lint_1 = lInt;
|
||||
//
|
||||
param_self_TimePicker.setCurrentMinute(lint_1);
|
||||
MyAndroidPipesComm.SendResult();
|
||||
break;
|
||||
// method boolean is24HourView;
|
||||
case amkUI_TTimePicker_is24HourView:
|
||||
DebugOut("amkUI_TTimePicker_is24HourView");
|
||||
// Self
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
param_self_TimePicker = (TimePicker) ViewElements.get(lInt);
|
||||
// params
|
||||
//
|
||||
lResult_boolean = param_self_TimePicker.is24HourView();
|
||||
MyAndroidPipesComm.SendBoolResult(lResult_boolean);
|
||||
break;
|
||||
// method void setIs24HourView(boolean AIs24HourView);
|
||||
case amkUI_TTimePicker_setIs24HourView:
|
||||
DebugOut("amkUI_TTimePicker_setIs24HourView");
|
||||
// Self
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
param_self_TimePicker = (TimePicker) ViewElements.get(lInt);
|
||||
// params
|
||||
lBool = MyAndroidPipesComm.GetBool();
|
||||
lboolean_1 = lBool;
|
||||
//
|
||||
param_self_TimePicker.setIs24HourView(lboolean_1);
|
||||
MyAndroidPipesComm.SendResult();
|
||||
break;
|
||||
case amkUI_TScrollView_Create:
|
||||
DebugOut("amkUI_TScrollView_Create");
|
||||
ViewElements.add(new ScrollView(activity));
|
||||
MyAndroidPipesComm.SendIntResult(ViewElements.size() - 1);
|
||||
break;
|
||||
// method boolean isChecked()
|
||||
case amkUI_TCompoundButton_isChecked:
|
||||
DebugOut("amkUI_TCompoundButton_isChecked");
|
||||
// Self
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
param_self_CompoundButton = (CompoundButton) ViewElements.get(lInt);
|
||||
// params
|
||||
//
|
||||
lResult_boolean = param_self_CompoundButton.isChecked();
|
||||
MyAndroidPipesComm.SendBoolResult(lResult_boolean);
|
||||
break;
|
||||
// method boolean performClick()
|
||||
case amkUI_TCompoundButton_performClick:
|
||||
DebugOut("amkUI_TCompoundButton_performClick");
|
||||
// Self
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
param_self_CompoundButton = (CompoundButton) ViewElements.get(lInt);
|
||||
// params
|
||||
//
|
||||
lResult_boolean = param_self_CompoundButton.performClick();
|
||||
MyAndroidPipesComm.SendBoolResult(lResult_boolean);
|
||||
break;
|
||||
// method void setChecked(boolean checked)
|
||||
case amkUI_TCompoundButton_setChecked:
|
||||
DebugOut("amkUI_TCompoundButton_setChecked");
|
||||
// Self
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
param_self_CompoundButton = (CompoundButton) ViewElements.get(lInt);
|
||||
// params
|
||||
lBool = MyAndroidPipesComm.GetBool();
|
||||
lboolean_1 = lBool;
|
||||
//
|
||||
param_self_CompoundButton.setChecked(lboolean_1);
|
||||
MyAndroidPipesComm.SendResult();
|
||||
break;
|
||||
// method void toggle()
|
||||
case amkUI_TCompoundButton_toggle:
|
||||
DebugOut("amkUI_TCompoundButton_toggle");
|
||||
// Self
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
param_self_CompoundButton = (CompoundButton) ViewElements.get(lInt);
|
||||
// params
|
||||
//
|
||||
param_self_CompoundButton.toggle();
|
||||
MyAndroidPipesComm.SendResult();
|
||||
break;
|
||||
case amkUI_TCheckBox_Create:
|
||||
DebugOut("amkUI_TCheckBox_Create");
|
||||
ViewElements.add(new CheckBox(activity));
|
||||
MyAndroidPipesComm.SendIntResult(ViewElements.size() - 1);
|
||||
break;
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,77 @@
|
||||
package com.pascal.androidlcl;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.os.*;
|
||||
import android.util.*;
|
||||
import android.content.*;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
import java.util.*;
|
||||
|
||||
public class AndroidApp
|
||||
{
|
||||
// info from other classes
|
||||
Activity activity;
|
||||
AndroidPipesComm MyAndroidPipesComm;
|
||||
JavaLang MyJavaLang;
|
||||
AndroidAll MyAndroidAll;
|
||||
|
||||
// lists of variables
|
||||
ArrayList ViewElements;
|
||||
|
||||
//
|
||||
// android.app.*
|
||||
static final int amkUI_Activity_setContentView = 0x0000;
|
||||
static final int amkUI_Activity_getWindowManager = 0x0080;
|
||||
|
||||
public AndroidApp(AndroidPipesComm AAndroidPipesComm, Activity AActivity, JavaLang AJavaLang, AndroidAll AAndroidAll)
|
||||
{
|
||||
activity = AActivity;
|
||||
MyAndroidPipesComm = AAndroidPipesComm;
|
||||
MyJavaLang = AJavaLang;
|
||||
MyAndroidAll = AAndroidAll;
|
||||
ViewElements = AAndroidAll.ViewElements;
|
||||
}
|
||||
|
||||
public void DebugOut(String Str)
|
||||
{
|
||||
MyAndroidPipesComm.DebugOut(Str);
|
||||
}
|
||||
|
||||
public boolean ProcessCommand(int Buffer)
|
||||
{
|
||||
//DebugOut("AndroidUI.ProcessCommand");
|
||||
//DebugOut("AndroidUI.ProcessCommand Command=" + java.lang.Integer.toHexString(Buffer));
|
||||
|
||||
int lInt, lIndex, lPascalPointer;
|
||||
Integer lTag;
|
||||
TextView lTextView;
|
||||
CharSequence lChars;
|
||||
//
|
||||
WindowManager param_self_WindowManager;
|
||||
//
|
||||
|
||||
switch (Buffer)
|
||||
{
|
||||
// android.app.Activity
|
||||
// public void setContentView (View view)
|
||||
case amkUI_Activity_setContentView:
|
||||
DebugOut("amkUI_Activity_setContentView");
|
||||
lInt = MyAndroidPipesComm.GetInt();
|
||||
View lView = (View) ViewElements.get(lInt);
|
||||
activity.setContentView(lView);
|
||||
MyAndroidPipesComm.SendResult();
|
||||
break;
|
||||
/* case amkUI_Activity_getWindowManager:
|
||||
DebugOut("amkUI_Activity_getWindowManager");
|
||||
WindowManagerElements.add(activity.getWindowManager());
|
||||
MyAndroidPipesComm.SendIntResult(WindowManagerElements.size() - 1);
|
||||
break;*/
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,273 @@
|
||||
package com.pascal.androidlcl;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.os.*;
|
||||
import android.util.Log;
|
||||
import android.content.*;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
import java.io.*;
|
||||
|
||||
public class AndroidLCLTest extends Activity
|
||||
{
|
||||
AndroidPipesComm MyAndroidPipesComm;
|
||||
String ExecutablePath;
|
||||
// Debug
|
||||
boolean DEBUG_PASCAL4ANDROID = true;
|
||||
|
||||
// Android Message subtype
|
||||
static int ams_ActivityCallback_onCreateStarted = 0x0001;
|
||||
static int ams_ActivityCallback_onStartStarted = 0x0002;
|
||||
static int ams_ActivityCallback_onRestartStarted = 0x0003;
|
||||
static int ams_ActivityCallback_onResumeStarted = 0x0004;
|
||||
static int ams_ActivityCallback_onPauseStarted = 0x0005;
|
||||
static int ams_ActivityCallback_onStopStarted = 0x0006;
|
||||
static int ams_ActivityCallback_onDestroyStarted = 0x0007;
|
||||
static int ams_ActivityCallback_onCreateOptionsMenuStarted = 0x0008;
|
||||
static int ams_ActivityCallback_onKeyUpStarted = 0x0010;
|
||||
|
||||
static int ams_ActivityCallback_onCreateFinished = 0x1001;
|
||||
static int ams_ActivityCallback_onStartFinished = 0x1002;
|
||||
static int ams_ActivityCallback_onRestartFinished = 0x1003;
|
||||
static int ams_ActivityCallback_onResumeFinished = 0x1004;
|
||||
static int ams_ActivityCallback_onPauseFinished = 0x1005;
|
||||
static int ams_ActivityCallback_onStopFinished = 0x1006;
|
||||
static int ams_ActivityCallback_onDestroyFinished = 0x1007;
|
||||
static int ams_ActivityCallback_onCreateOptionsMenuFinished = 0x1008;
|
||||
static int ams_ActivityCallback_onKeyUpFinished = 0x1010;
|
||||
|
||||
Button.OnClickListener buttonClickCallback = new Button.OnClickListener()
|
||||
{
|
||||
public void onClick(View v)
|
||||
{
|
||||
MyAndroidPipesComm.DebugOut("Click!");
|
||||
}
|
||||
};
|
||||
|
||||
/** Called when the activity is first created. */
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
MyAndroidPipesComm = new AndroidPipesComm(this);
|
||||
|
||||
// Prepare the application
|
||||
ExecutablePath = getApplicationContext().getFilesDir() + "/androidlcltest";
|
||||
|
||||
String LibraryPathPath = "/data/data/com.pascal.androidlcl/lib/libandroidlcltest.so";
|
||||
|
||||
MyAndroidPipesComm.DebugOut("Executing application " + LibraryPathPath + " copied to " + ExecutablePath);
|
||||
|
||||
String Str = FileCopy(LibraryPathPath, ExecutablePath);
|
||||
|
||||
String Str2 = RunProgram("/system/bin/chmod", "755", ExecutablePath);
|
||||
|
||||
// Run the application
|
||||
RunPascalProgram(ExecutablePath);
|
||||
|
||||
// Waits until the Pascal side finishes its initialization
|
||||
MyAndroidPipesComm.DebugOut("WaitForPascalMessage(amkActivityCallback, ams_ActivityCallback_onCreateFinished)");
|
||||
MyAndroidPipesComm.WaitForPascalMessage(MyAndroidPipesComm.amkActivityCallback, ams_ActivityCallback_onCreateFinished);
|
||||
MyAndroidPipesComm.DebugOut("END onCreate");
|
||||
}
|
||||
|
||||
/** */
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
MyAndroidPipesComm.DebugOut("START onStart");
|
||||
super.onStart();
|
||||
MyAndroidPipesComm.SendMessage(MyAndroidPipesComm.amkActivityCallback, ams_ActivityCallback_onStartStarted);
|
||||
MyAndroidPipesComm.WaitForPascalMessage(MyAndroidPipesComm.amkActivityCallback, ams_ActivityCallback_onStartFinished);
|
||||
MyAndroidPipesComm.DebugOut("END onStart");
|
||||
}
|
||||
|
||||
/** */
|
||||
@Override
|
||||
protected void onRestart()
|
||||
{
|
||||
MyAndroidPipesComm.DebugOut("START onRestart");
|
||||
super.onRestart();
|
||||
MyAndroidPipesComm.SendMessage(MyAndroidPipesComm.amkActivityCallback, ams_ActivityCallback_onRestartStarted);
|
||||
MyAndroidPipesComm.WaitForPascalMessage(MyAndroidPipesComm.amkActivityCallback, ams_ActivityCallback_onRestartFinished);
|
||||
MyAndroidPipesComm.DebugOut("END onRestart");
|
||||
}
|
||||
|
||||
/** */
|
||||
@Override
|
||||
protected void onResume()
|
||||
{
|
||||
MyAndroidPipesComm.DebugOut("START onResume");
|
||||
super.onResume();
|
||||
MyAndroidPipesComm.SendMessage(MyAndroidPipesComm.amkActivityCallback, ams_ActivityCallback_onResumeStarted);
|
||||
MyAndroidPipesComm.WaitForPascalMessage(MyAndroidPipesComm.amkActivityCallback, ams_ActivityCallback_onResumeFinished);
|
||||
MyAndroidPipesComm.DebugOut("END onResume");
|
||||
}
|
||||
|
||||
/** */
|
||||
@Override
|
||||
protected void onPause()
|
||||
{
|
||||
MyAndroidPipesComm.DebugOut("START onPause");
|
||||
super.onPause();
|
||||
MyAndroidPipesComm.SendMessage(MyAndroidPipesComm.amkActivityCallback, ams_ActivityCallback_onPauseStarted);
|
||||
MyAndroidPipesComm.WaitForPascalMessage(MyAndroidPipesComm.amkActivityCallback, ams_ActivityCallback_onPauseFinished);
|
||||
MyAndroidPipesComm.DebugOut("END onPause");
|
||||
}
|
||||
|
||||
/** */
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
MyAndroidPipesComm.DebugOut("START onStop");
|
||||
super.onStop();
|
||||
MyAndroidPipesComm.SendMessage(MyAndroidPipesComm.amkActivityCallback, ams_ActivityCallback_onStopStarted);
|
||||
MyAndroidPipesComm.WaitForPascalMessage(MyAndroidPipesComm.amkActivityCallback, ams_ActivityCallback_onStopFinished);
|
||||
MyAndroidPipesComm.DebugOut("END onStop");
|
||||
}
|
||||
|
||||
/** */
|
||||
@Override
|
||||
protected void onDestroy()
|
||||
{
|
||||
MyAndroidPipesComm.DebugOut("START onDestroy");
|
||||
super.onDestroy();
|
||||
MyAndroidPipesComm.SendMessage(MyAndroidPipesComm.amkActivityCallback, ams_ActivityCallback_onStartStarted);
|
||||
MyAndroidPipesComm.WaitForPascalMessage(MyAndroidPipesComm.amkActivityCallback, ams_ActivityCallback_onStartFinished);
|
||||
MyAndroidPipesComm.DebugOut("END onDestroy");
|
||||
}
|
||||
|
||||
// public boolean onCreateOptionsMenu (Menu menu)
|
||||
/*@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu)
|
||||
{
|
||||
if (DEBUG_PASCAL4ANDROID == true) MyAndroidPipesComm.DebugOut("START onCreateOptionsMenu");
|
||||
MyAndroidPipesComm.SendMessage(MyAndroidPipesComm.amkActivityCallback, ams_ActivityCallback_onCreateOptionsMenuStarted);
|
||||
MyAndroidPipesComm.MyAndroidMenu.MenuElements.add(menu);
|
||||
int lMenuIndex = MyAndroidPipesComm.MyAndroidMenu.MenuElements.size() - 1;
|
||||
MyAndroidPipesComm.SendInt(lMenuIndex);
|
||||
MyAndroidPipesComm.WaitForPascalMessage(MyAndroidPipesComm.amkActivityCallback, ams_ActivityCallback_onCreateOptionsMenuFinished);
|
||||
int lInt = MyAndroidPipesComm.GetInt();
|
||||
// ToDo: If we start supporting object deletion then we need to use indexOf to get the new index
|
||||
MyAndroidPipesComm.MyAndroidMenu.MenuElements.remove(lMenuIndex);
|
||||
if (DEBUG_PASCAL4ANDROID == true) MyAndroidPipesComm.DebugOut("END onCreateOptionsMenu");
|
||||
return (lInt != 0);
|
||||
}*/
|
||||
|
||||
// generic Key Listener
|
||||
@Override
|
||||
public boolean onKeyUp(int keyCode, KeyEvent event)
|
||||
{
|
||||
if (DEBUG_PASCAL4ANDROID == true) MyAndroidPipesComm.DebugOut("START onKeyUp");
|
||||
MyAndroidPipesComm.SendMessage(MyAndroidPipesComm.amkActivityCallback, ams_ActivityCallback_onKeyUpStarted);
|
||||
MyAndroidPipesComm.SendInt(keyCode);
|
||||
// ToDo: Also send the KeyEvent
|
||||
//MyAndroidPipesComm.MyAndroidMenu.MenuElements.add(menu);
|
||||
//int lMenuIndex = MyAndroidPipesComm.MyAndroidMenu.MenuElements.size() - 1;
|
||||
MyAndroidPipesComm.WaitForPascalMessage(MyAndroidPipesComm.amkActivityCallback, ams_ActivityCallback_onKeyUpFinished);
|
||||
int lInt = MyAndroidPipesComm.GetInt();
|
||||
if (DEBUG_PASCAL4ANDROID == true) MyAndroidPipesComm.DebugOut("END onCreateOptionsMenu");
|
||||
if (lInt != 0) return true;
|
||||
return super.onKeyUp(keyCode, event);
|
||||
}
|
||||
|
||||
//
|
||||
private static String FileCopy(String srFile, String dtFile)
|
||||
{
|
||||
try
|
||||
{
|
||||
File f1 = new File(srFile);
|
||||
File f2 = new File(dtFile);
|
||||
InputStream in = new FileInputStream(f1);
|
||||
|
||||
//For Overwrite the file.
|
||||
OutputStream out = new FileOutputStream(f2, true);
|
||||
|
||||
byte[] buf = new byte[1024];
|
||||
int len;
|
||||
while ((len = in.read(buf)) > 0){
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
in.close();
|
||||
out.close();
|
||||
|
||||
return "Success dest=" + dtFile;
|
||||
}
|
||||
catch(FileNotFoundException e)
|
||||
{
|
||||
return "Error=FileNotFoundException=" + e.getMessage();
|
||||
}
|
||||
catch(IOException e)
|
||||
{
|
||||
return "Error=IOException=" + e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Simple method for running external applications.
|
||||
It waits until the program finishes running.
|
||||
it uses Runtime.getRuntime()
|
||||
*/
|
||||
public String RunProgram(String cmd, String param1, String param2)
|
||||
{
|
||||
String output = "";
|
||||
try
|
||||
{
|
||||
if (param1 == null) param1 = "";
|
||||
if (param2 == null) param2 = "";
|
||||
|
||||
// Runs the application
|
||||
java.lang.Process process = Runtime.getRuntime().exec(cmd + " " + param1 + " " + param2);
|
||||
|
||||
// Now connects pipes to it
|
||||
DataInputStream reader = new DataInputStream(process.getInputStream());
|
||||
|
||||
// Waits until it finishes
|
||||
process.waitFor();
|
||||
|
||||
// And stores the result of the pipes in the result of the function
|
||||
String line;
|
||||
String separator = System.getProperty("line.separator");
|
||||
while ((line = reader.readLine()) != null)
|
||||
{
|
||||
output += line + separator;
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
output += "error=IOException=" + e.getMessage();
|
||||
}
|
||||
catch (InterruptedException e)
|
||||
{
|
||||
output += "error=InterruptedException=" + e.getMessage();
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/*
|
||||
This function will run a Pascal program and interact with it via pipes
|
||||
Uses Runtime.getRuntime()
|
||||
*/
|
||||
public void RunPascalProgram(String cmd)
|
||||
{
|
||||
try
|
||||
{
|
||||
// Runs the application
|
||||
MyAndroidPipesComm.PascalProcess = Runtime.getRuntime().exec(cmd);
|
||||
|
||||
// Now connects pipes to it
|
||||
MyAndroidPipesComm.writer = new DataOutputStream(
|
||||
MyAndroidPipesComm.PascalProcess.getOutputStream());
|
||||
MyAndroidPipesComm.reader = new DataInputStream(
|
||||
MyAndroidPipesComm.PascalProcess.getInputStream());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
MyAndroidPipesComm.DebugOut("error=IOException=" + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,276 @@
|
||||
package com.pascal.androidlcl;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.os.*;
|
||||
import android.util.Log;
|
||||
import android.content.*;
|
||||
import android.view.*;
|
||||
import android.widget.*;
|
||||
import java.io.*;
|
||||
|
||||
public class AndroidPipesComm
|
||||
{
|
||||
// info from other classes
|
||||
Activity activity;
|
||||
|
||||
// Data pool accessed by many methods
|
||||
java.lang.Process PascalProcess;
|
||||
DataOutputStream writer;
|
||||
DataInputStream reader;
|
||||
// Data pool to solve the lack of passing parameter by reference
|
||||
byte lType = 0;
|
||||
int lSubtype = 0;
|
||||
|
||||
// Android Message Kind
|
||||
static byte amkFloatResult = 103;
|
||||
static byte amkIntResult = 102;
|
||||
static byte amkResult = 101;
|
||||
static byte amkActivityCallback = 0;
|
||||
static byte amkLog = 1;
|
||||
static byte amkUICommand = 2;
|
||||
static byte amkJavaLangCall = 3;
|
||||
static byte amkTimer = 4;
|
||||
|
||||
// Add / remove modules here
|
||||
public JavaLang MyJavaLang;
|
||||
public AndroidAll MyAndroidAll;
|
||||
public AndroidApp MyAndroidApp;
|
||||
|
||||
public AndroidPipesComm(Activity AActivity)
|
||||
{
|
||||
activity = AActivity;
|
||||
MyJavaLang = new JavaLang(this);
|
||||
MyAndroidAll = new AndroidAll(this, activity, MyJavaLang);
|
||||
MyAndroidApp = new AndroidApp(this, activity, MyJavaLang, MyAndroidAll);
|
||||
}
|
||||
|
||||
public void DebugOut(String Str)
|
||||
{
|
||||
Log.v("AndroidPipesComm:", Str);
|
||||
// tv.setText(tv.getText().toString() + Str);
|
||||
}
|
||||
|
||||
public void ErrorOut(String Str)
|
||||
{
|
||||
Log.v("AndroidPipesComm:", Str);
|
||||
// tv.setText(tv.getText().toString() + Str);
|
||||
}
|
||||
|
||||
// Waits for a particular Pascal message.
|
||||
// In the mean time processes any other incoming messages
|
||||
public void WaitForPascalMessage(byte AExpectedMessageType, int AExpectedMessageSubtype)
|
||||
{
|
||||
DebugOut("START WaitForPascalMessage AExpectedMessageType=" + AExpectedMessageType
|
||||
+ " AExpectedMessageSubtype=" + java.lang.Integer.toHexString(AExpectedMessageSubtype));
|
||||
|
||||
while (true)
|
||||
{
|
||||
WaitAndProcessPascalMessage();
|
||||
DebugOut("MID_END WaitForPascalMessage lType=" + lType + " lSubtype=" + java.lang.Integer.toHexString(lSubtype));
|
||||
if ((lType == AExpectedMessageType) && (lSubtype == AExpectedMessageSubtype)) return;
|
||||
if ((lType == amkActivityCallback) && (AExpectedMessageType == amkActivityCallback)) return;
|
||||
}
|
||||
}
|
||||
|
||||
// Waits for and processes a Pascal message
|
||||
public void WaitAndProcessPascalMessage()
|
||||
{
|
||||
try
|
||||
{
|
||||
DebugOut("WaitAndProcessPascalMessage");
|
||||
byte Buffer = reader.readByte(); // blocking read
|
||||
lType = Buffer;
|
||||
lSubtype = 0;
|
||||
|
||||
if (Buffer == amkActivityCallback)
|
||||
{
|
||||
DebugOut("amkActivityCallback");
|
||||
// lSubtype = reader.readInt(); // blocking read
|
||||
}
|
||||
else if (Buffer == amkLog)
|
||||
{
|
||||
DebugOut("amkLog");
|
||||
}
|
||||
else if (Buffer == amkUICommand)
|
||||
{
|
||||
DebugOut("amkUICommand");
|
||||
lSubtype = reader.readInt(); // blocking read
|
||||
if (MyAndroidAll.ProcessCommand(lSubtype) == true) ;
|
||||
else if (MyAndroidApp.ProcessCommand(lSubtype) == true) ;
|
||||
else
|
||||
{
|
||||
ErrorOut("Unknown UI Command!!!" + java.lang.Integer.toHexString(lSubtype));
|
||||
};
|
||||
}
|
||||
else if (Buffer == amkJavaLangCall)
|
||||
{
|
||||
DebugOut("amkJavaLangCall");
|
||||
lSubtype = reader.readInt(); // blocking read
|
||||
MyJavaLang.ProcessCommand(lSubtype);
|
||||
}
|
||||
// else if (Buffer == amkTimer)
|
||||
// {
|
||||
// DebugOut("amkTimer");
|
||||
// lSubtype = reader.readInt(); // blocking read
|
||||
// MyAndroidTimer.ProcessCommand(lSubtype);
|
||||
// }
|
||||
else
|
||||
{
|
||||
ErrorOut("Unknown Pascal message!!! " + java.lang.Integer.toHexString(Buffer));
|
||||
}
|
||||
}
|
||||
catch (EOFException e)
|
||||
{
|
||||
ErrorOut("[WaitAndProcessPascalMessage] EOFException=" + e.getMessage());
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
ErrorOut("[WaitAndProcessPascalMessage] IOException=" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Receiving data
|
||||
|
||||
public byte GetByte()
|
||||
{
|
||||
try
|
||||
{
|
||||
return reader.readByte();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
ErrorOut("[GetByte] IOException=" + e.getMessage());
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int GetInt()
|
||||
{
|
||||
try
|
||||
{
|
||||
return reader.readInt();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
ErrorOut("[GetInt] IOException=" + e.getMessage());
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public boolean GetBool()
|
||||
{
|
||||
try
|
||||
{
|
||||
int Tmp = reader.readInt();
|
||||
if (Tmp == 0) return false;
|
||||
else return true;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
ErrorOut("[GetBool] IOException=" + e.getMessage());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public float GetFloat()
|
||||
{
|
||||
try
|
||||
{
|
||||
return reader.readFloat();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
ErrorOut("[GetFloat] IOException=" + e.getMessage());
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Sending results
|
||||
|
||||
public void SendResult()
|
||||
{
|
||||
try
|
||||
{
|
||||
writer.writeByte(amkResult);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
ErrorOut("[SendResult] IOException=" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void SendIntResult(int Result)
|
||||
{
|
||||
try
|
||||
{
|
||||
writer.writeByte(amkIntResult);
|
||||
writer.writeInt(Result);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
ErrorOut("[SendIntResult] IOException=" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void SendFloatResult(float Result)
|
||||
{
|
||||
try
|
||||
{
|
||||
writer.writeByte(amkFloatResult);
|
||||
writer.writeFloat(Result);
|
||||
// writer.writeInt(Float.floatToIntBits(Result));
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
ErrorOut("[SendFloatResult] IOException=" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
// Sending data
|
||||
|
||||
// Convenience routine, uses SendIntResult
|
||||
public void SendBoolResult(boolean Result)
|
||||
{
|
||||
if (Result == false) SendIntResult(0);
|
||||
else SendIntResult(-1);
|
||||
}
|
||||
|
||||
public void SendInt(int AData)
|
||||
{
|
||||
try
|
||||
{
|
||||
writer.writeInt(AData);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
ErrorOut("[SendBoolResult] IOException=" + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public void SendMessage(byte AMessageKind, int AMessageSubtype)
|
||||
{
|
||||
try
|
||||
{
|
||||
writer.writeByte(AMessageKind);
|
||||
writer.writeInt(AMessageSubtype);
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
ErrorOut("[SendMessage] IOException=" + e.getMessage());
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
// String separator = System.getProperty("line.separator");
|
||||
/* // Displays a dialog with the result of the operation
|
||||
AlertDialog alertDialog;
|
||||
alertDialog = new AlertDialog.Builder(this).create();
|
||||
alertDialog.setTitle("Result of cp");
|
||||
alertDialog.setMessage(Str + "||" + Str2 + "||" + Str3);
|
||||
alertDialog.show();*/
|
||||
// Waits until it finishes
|
||||
// process.waitFor();
|
||||
// Thread.currentThread().sleep(1000);
|
||||
}
|
||||
|
@ -0,0 +1,50 @@
|
||||
package com.pascal.androidlcl;
|
||||
|
||||
import java.lang.*;
|
||||
import java.util.*;
|
||||
|
||||
public class JavaLang
|
||||
{
|
||||
// info from other classes
|
||||
AndroidPipesComm MyAndroidPipesComm;
|
||||
|
||||
// lists of variables
|
||||
ArrayList LangElements = new ArrayList();
|
||||
|
||||
//
|
||||
static final int amkJavaLang_New_String = 0x0000;
|
||||
|
||||
public JavaLang(AndroidPipesComm AAndroidPipesComm)
|
||||
{
|
||||
MyAndroidPipesComm = AAndroidPipesComm;
|
||||
}
|
||||
|
||||
public void DebugOut(String Str)
|
||||
{
|
||||
MyAndroidPipesComm.DebugOut(Str);
|
||||
}
|
||||
|
||||
public void ProcessCommand(int Buffer)
|
||||
{
|
||||
// DebugOut("<before readByte>");
|
||||
int lInt;
|
||||
|
||||
switch (Buffer)
|
||||
{
|
||||
// java.lang.String
|
||||
// String(char[] data)
|
||||
case amkJavaLang_New_String:
|
||||
DebugOut("amkJavaLang_New_String");
|
||||
lInt = MyAndroidPipesComm.GetInt(); // Length
|
||||
char[] lChars = new char[lInt];
|
||||
for (int i = 0; i < lInt; i++)
|
||||
{
|
||||
lChars[i] = (char) MyAndroidPipesComm.GetByte();
|
||||
}
|
||||
LangElements.add(new String(lChars));
|
||||
MyAndroidPipesComm.SendIntResult(LangElements.size() - 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
BIN
examples/androidlcl/androidlcltest.ico
Normal file
BIN
examples/androidlcl/androidlcltest.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 134 KiB |
158
examples/androidlcl/androidlcltest.lpi
Normal file
158
examples/androidlcl/androidlcltest.lpi
Normal file
@ -0,0 +1,158 @@
|
||||
<?xml version="1.0"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="9"/>
|
||||
<General>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<MainUnit Value="0"/>
|
||||
<UseXPManifest Value="True"/>
|
||||
<Icon Value="0"/>
|
||||
</General>
|
||||
<i18n>
|
||||
<EnableI18N LFM="False"/>
|
||||
</i18n>
|
||||
<VersionInfo>
|
||||
<StringTable ProductVersion=""/>
|
||||
</VersionInfo>
|
||||
<MacroValues Count="1">
|
||||
<Macro1 Name="LCLWidgetType" Value="android"/>
|
||||
</MacroValues>
|
||||
<BuildModes Count="3">
|
||||
<Item1 Name="Android" Default="True"/>
|
||||
<Item2 Name="Desktop">
|
||||
<MacroValues Count="1">
|
||||
<Macro1 Name="LCLWidgetType" Value="gtk2"/>
|
||||
</MacroValues>
|
||||
<CompilerOptions>
|
||||
<Version Value="10"/>
|
||||
<Target>
|
||||
<Filename Value="androidlcltest"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Linking>
|
||||
<Options>
|
||||
<Win32>
|
||||
<GraphicApplication Value="True"/>
|
||||
</Win32>
|
||||
</Options>
|
||||
</Linking>
|
||||
<Other>
|
||||
<CompilerMessages>
|
||||
<UseMsgFile Value="True"/>
|
||||
</CompilerMessages>
|
||||
<CompilerPath Value="$(CompPath)"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
</Item2>
|
||||
<Item3 Name="Android-Desktop">
|
||||
<MacroValues Count="1">
|
||||
<Macro1 Name="LCLWidgetType" Value="android"/>
|
||||
</MacroValues>
|
||||
<CompilerOptions>
|
||||
<Version Value="10"/>
|
||||
<Target>
|
||||
<Filename Value="androidlcltest"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<CodeGeneration>
|
||||
<TargetCPU Value="arm"/>
|
||||
<TargetOS Value="linux"/>
|
||||
</CodeGeneration>
|
||||
<Linking>
|
||||
<Options>
|
||||
<Win32>
|
||||
<GraphicApplication Value="True"/>
|
||||
</Win32>
|
||||
</Options>
|
||||
</Linking>
|
||||
<Other>
|
||||
<CompilerMessages>
|
||||
<UseMsgFile Value="True"/>
|
||||
</CompilerMessages>
|
||||
<CompilerPath Value="$(CompPath)"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
</Item3>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
|
||||
<ExcludeFileFilter Value="*.(bak|ppu|o|so);*~;backup"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<local>
|
||||
<FormatVersion Value="1"/>
|
||||
<LaunchingApplication PathPlusParams="/usr/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
|
||||
</local>
|
||||
</RunParams>
|
||||
<RequiredPackages Count="1">
|
||||
<Item1>
|
||||
<PackageName Value="LCL"/>
|
||||
</Item1>
|
||||
</RequiredPackages>
|
||||
<Units Count="2">
|
||||
<Unit0>
|
||||
<Filename Value="androidlcltest.lpr"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="androidlcltest"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<Filename Value="mainform.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<ComponentName Value="Form2"/>
|
||||
<ResourceBaseClass Value="Form"/>
|
||||
<UnitName Value="mainform"/>
|
||||
</Unit1>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="10"/>
|
||||
<Target>
|
||||
<Filename Value="android/libs/armeabi/libandroidlcltest.so"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="lib/$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<CodeGeneration>
|
||||
<TargetCPU Value="arm"/>
|
||||
<TargetOS Value="linux"/>
|
||||
</CodeGeneration>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
<UseLineInfoUnit Value="False"/>
|
||||
<StripSymbols Value="True"/>
|
||||
</Debugging>
|
||||
<Options>
|
||||
<Win32>
|
||||
<GraphicApplication Value="True"/>
|
||||
</Win32>
|
||||
</Options>
|
||||
</Linking>
|
||||
<Other>
|
||||
<CompilerMessages>
|
||||
<UseMsgFile Value="True"/>
|
||||
</CompilerMessages>
|
||||
<CompilerPath Value="$(CompPath)"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions Count="3">
|
||||
<Item1>
|
||||
<Name Value="EAbort"/>
|
||||
</Item1>
|
||||
<Item2>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item2>
|
||||
<Item3>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item3>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
20
examples/androidlcl/androidlcltest.lpr
Normal file
20
examples/androidlcl/androidlcltest.lpr
Normal file
@ -0,0 +1,20 @@
|
||||
program androidlcltest;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
{$IFDEF UNIX}{$IFDEF UseCThreads}
|
||||
cthreads,
|
||||
{$ENDIF}{$ENDIF}
|
||||
Interfaces, // this includes the LCL widgetset
|
||||
Forms, mainform
|
||||
{ you can add units after this };
|
||||
|
||||
//{$R *.res}
|
||||
|
||||
begin
|
||||
Application.Initialize;
|
||||
Application.CreateForm(TForm2, Form2);
|
||||
Application.Run;
|
||||
end.
|
||||
|
BIN
examples/androidlcl/androidlcltest.res
Normal file
BIN
examples/androidlcl/androidlcltest.res
Normal file
Binary file not shown.
18
examples/androidlcl/mainform.lfm
Normal file
18
examples/androidlcl/mainform.lfm
Normal file
@ -0,0 +1,18 @@
|
||||
object Form2: TForm2
|
||||
Left = 313
|
||||
Height = 240
|
||||
Top = 186
|
||||
Width = 320
|
||||
Caption = 'Form2'
|
||||
ClientHeight = 240
|
||||
ClientWidth = 320
|
||||
LCLVersion = '0.9.31'
|
||||
object Button1: TButton
|
||||
Left = 33
|
||||
Height = 25
|
||||
Top = 35
|
||||
Width = 75
|
||||
Caption = 'Button1'
|
||||
TabOrder = 0
|
||||
end
|
||||
end
|
32
examples/androidlcl/mainform.pas
Normal file
32
examples/androidlcl/mainform.pas
Normal file
@ -0,0 +1,32 @@
|
||||
unit mainform;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
|
||||
StdCtrls;
|
||||
|
||||
type
|
||||
|
||||
{ TForm2 }
|
||||
|
||||
TForm2 = class(TForm)
|
||||
Button1: TButton;
|
||||
private
|
||||
{ private declarations }
|
||||
public
|
||||
{ public declarations }
|
||||
end;
|
||||
|
||||
var
|
||||
Form2: TForm2;
|
||||
|
||||
implementation
|
||||
|
||||
initialization
|
||||
{$I mainform.lrs}
|
||||
|
||||
end.
|
||||
|
Reference in New Issue
Block a user