LCL-Android: Moves the JNI code to call the ListView Dialog to the CustomDrawn widgetset to centralize it.

git-svn-id: trunk@37701 -
This commit is contained in:
sekelsenmat 2012-06-20 07:41:05 +00:00
parent 6a416d091f
commit eb2efeec24
5 changed files with 65 additions and 51 deletions

View File

@ -665,7 +665,8 @@ public class LCLActivity extends Activity implements SensorEventListener, Locati
//
// output: Calls LCLOnMessageBoxFinished which will call LCLIntf.OnListViewDialogResult
//
public void LCLDoShowListViewDialog(String ATitle, String[] AItems, String[] ASubItems)
public void LCLDoShowListViewDialog(String ATitle, String[] AItems,
String[] ASubItems, int AColorOddRow, int AColorEvenRow)
{
final Dialog dialog = new Dialog(this);
@ -681,6 +682,8 @@ public class LCLActivity extends Activity implements SensorEventListener, Locati
android.R.layout.simple_list_item_2,
new String[] { "title", "description" },
new int[] { android.R.id.text1, android.R.id.text2 });
listAdapter.colors[0] = AColorOddRow;
listAdapter.colors[1] = AColorEvenRow;
lListView.setAdapter(listAdapter);
lListView.setClickable(true);
AdapterView.OnItemClickListener listviewClickListener = new AdapterView.OnItemClickListener()
@ -741,7 +744,7 @@ public class LCLActivity extends Activity implements SensorEventListener, Locati
{
private List<LCL_ListViewItem> Items;
// Colors to alternate
private int[] colors = new int[] { 0xff292C29, 0xff424542 };
public int[] colors = new int[] { 0xff292C29, 0xff424542 };
@SuppressWarnings("unchecked") public LCL_ListViewAdapter(
Context context,

View File

@ -58,7 +58,6 @@ type
procedure HandleMessageDialogFinished(Sender: TObject; AResult: Integer);
procedure SocketProc;
function LoadHTMLPageViaJNI(AURL: string): string;
procedure ShowListViewDialog(ATitle: string; ATitles, ADescriptions: array of string);
procedure MyOnListViewDialogResult(ASelectedItem: Integer);
end;
@ -467,52 +466,6 @@ begin
{$endif}
end;
procedure TForm1.ShowListViewDialog(ATitle: string; ATitles,
ADescriptions: array of string);
{$ifdef Android}
var
javaClass_LCLActivity, javaClass_String: jclass;
javaMethod_LCLActivity_LCLDoShowListViewDialog: jmethodid;
javaString: jstring;
lParams: array[0..2] of JValue;
lNativeString: PChar;
i: Integer;
{$endif}
begin
{$ifdef Android}
// Here we call this routine:
// public void LCLDoShowListViewDialog(String ATitle, String[] AItems, String[] ASubItems)
DebugLn(':>ShowListViewDialog');
// First call FindClass for all required classes
javaClass_LCLActivity := javaEnvRef^^.FindClass(javaEnvRef, 'com/pascal/lcltest/LCLActivity');
javaClass_String := javaEnvRef^^.FindClass(javaEnvRef, 'java/lang/String');
// Now all Method IDs
DebugLn(':ShowListViewDialog 1');
javaMethod_LCLActivity_LCLDoShowListViewDialog := javaEnvRef^^.GetMethodID(javaEnvRef, javaClass_LCLACtivity,
'LCLDoShowListViewDialog',
'(Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/String;)V');
DebugLn(':ShowListViewDialog 2');
// Create a new instance for the HTTP request object
// HttpGet javaRequest = new HttpGet();
lParams[0].l := javaEnvRef^^.NewStringUTF(javaEnvRef, PChar(ATitle));
lParams[1].l := javaEnvRef^^.NewObjectArray(javaEnvRef, Length(ATitles), javaClass_String, javaEnvRef^^.NewStringUTF(javaEnvRef, ''));
for i := 0 to Length(ATitles)-1 do
javaEnvRef^^.SetObjectArrayElement(javaEnvRef, lParams[1].l, i, javaEnvRef^^.NewStringUTF(javaEnvRef, PChar(ATitles[i])));
lParams[2].l := javaEnvRef^^.NewObjectArray(javaEnvRef, Length(ADescriptions), javaClass_String, javaEnvRef^^.NewStringUTF(javaEnvRef, ''));
for i := 0 to Length(ADescriptions)-1 do
javaEnvRef^^.SetObjectArrayElement(javaEnvRef, lParams[2].l, i, javaEnvRef^^.NewStringUTF(javaEnvRef, PChar(ADescriptions[i])));
//
javaEnvRef^^.CallVoidMethodA(javaEnvRef, javaActivityObject,
javaMethod_LCLActivity_LCLDoShowListViewDialog, @lParams[0]);
javaEnvRef^^.DeleteLocalRef(javaEnvRef, lParams[0].l);
javaEnvRef^^.DeleteLocalRef(javaEnvRef, lParams[1].l);
javaEnvRef^^.DeleteLocalRef(javaEnvRef, lParams[2].l);
DebugLn(':ShowListViewDialog 3');// javaRequest='+IntToHex(PtrInt(javaRequest), 8));
{$endif}
end;
procedure TForm1.MyOnListViewDialogResult(ASelectedItem: Integer);
begin
DebugLn(Format('[MyOnListViewDialogResult] ASelectedItem=%d', [ASelectedItem]));

View File

@ -2,6 +2,10 @@ unit secondform;
{$mode objfpc}{$H+}
{$ifdef Linux}{$ifdef CPUARM}
{$define Android}
{$endif}{$endif}
interface
uses
@ -52,7 +56,11 @@ var
implementation
uses TypInfo, mainform;
uses
{$ifdef LCLCustomDrawn}
customdrawnint,
{$endif}
TypInfo, mainform;
{$R *.lfm}
@ -101,9 +109,11 @@ end;
procedure TForm2.Button3Click(Sender: TObject);
begin
Form1.ShowListViewDialog('Dialog Title',
{$ifdef Android}
CDWidgetSet.ShowListViewDialog('Dialog Title',
['Title1', 'Title2', 'Title3', 'Title4', 'Title5', 'Title6'],
['Descr1', 'Descr2', 'Descr3', 'Descr4', 'Descr5', 'Descr6']);
{$endif}
end;
procedure TForm2.textDestExit(Sender: TObject);

View File

@ -199,6 +199,9 @@ type
function DoOpenDocumentWidgetsetImplementation(APath: string): Boolean;
function DoOpenAndroidURI(AURI: JObject; AMimeType: string): Boolean;
function GetMimeTypeFromFileName(AFileName: string): string;
procedure ShowListViewDialog(ATitle: string; ATitles,
ADescriptions: array of string;
AColorOddRow: jint = $ff292C29; AColorEvenRow: jint = $ff424542);
{$endif}
{$ifdef CD_Cocoa}
pool : NSAutoreleasePool;

View File

@ -1095,6 +1095,51 @@ begin
else Result := 'text/plain';
end;
procedure TCDWidgetSet.ShowListViewDialog(ATitle: string; ATitles,
ADescriptions: array of string;
AColorOddRow: jint = $ff292C29; AColorEvenRow: jint = $ff424542);
var
javaClass_LCLActivity, javaClass_String: jclass;
javaMethod_LCLActivity_LCLDoShowListViewDialog: jmethodid;
javaString: jstring;
lParams: array[0..4] of JValue;
lNativeString: PChar;
i: Integer;
begin
// Here we call this routine:
// public void LCLDoShowListViewDialog(String ATitle, String[] AItems, String[] ASubItems)
DebugLn(':>ShowListViewDialog');
// First call FindClass for all required classes
javaClass_LCLActivity := javaEnvRef^^.FindClass(javaEnvRef, 'com/pascal/lcltest/LCLActivity');
javaClass_String := javaEnvRef^^.FindClass(javaEnvRef, 'java/lang/String');
// Now all Method IDs
//DebugLn(':ShowListViewDialog 1');
javaMethod_LCLActivity_LCLDoShowListViewDialog := javaEnvRef^^.GetMethodID(javaEnvRef, javaClass_LCLACtivity,
'LCLDoShowListViewDialog',
'(Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/String;II)V');
//DebugLn(':ShowListViewDialog 2');
// Create a new instance for the HTTP request object
// HttpGet javaRequest = new HttpGet();
lParams[0].l := javaEnvRef^^.NewStringUTF(javaEnvRef, PChar(ATitle));
lParams[1].l := javaEnvRef^^.NewObjectArray(javaEnvRef, Length(ATitles), javaClass_String, javaEnvRef^^.NewStringUTF(javaEnvRef, ''));
for i := 0 to Length(ATitles)-1 do
javaEnvRef^^.SetObjectArrayElement(javaEnvRef, lParams[1].l, i, javaEnvRef^^.NewStringUTF(javaEnvRef, PChar(ATitles[i])));
lParams[2].l := javaEnvRef^^.NewObjectArray(javaEnvRef, Length(ADescriptions), javaClass_String, javaEnvRef^^.NewStringUTF(javaEnvRef, ''));
for i := 0 to Length(ADescriptions)-1 do
javaEnvRef^^.SetObjectArrayElement(javaEnvRef, lParams[2].l, i, javaEnvRef^^.NewStringUTF(javaEnvRef, PChar(ADescriptions[i])));
lParams[3].i := AColorOddRow;
lParams[4].i := AColorEvenRow;
//
javaEnvRef^^.CallVoidMethodA(javaEnvRef, javaActivityObject,
javaMethod_LCLActivity_LCLDoShowListViewDialog, @lParams[0]);
javaEnvRef^^.DeleteLocalRef(javaEnvRef, lParams[0].l);
javaEnvRef^^.DeleteLocalRef(javaEnvRef, lParams[1].l);
javaEnvRef^^.DeleteLocalRef(javaEnvRef, lParams[2].l);
DebugLn(':<ShowListViewDialog END');
end;
function TCDWidgetSet.GetAppHandle: THandle;
begin
Result := 0;