mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-06-07 00:18:21 +02:00
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:
parent
6a416d091f
commit
eb2efeec24
@ -665,7 +665,8 @@ public class LCLActivity extends Activity implements SensorEventListener, Locati
|
|||||||
//
|
//
|
||||||
// output: Calls LCLOnMessageBoxFinished which will call LCLIntf.OnListViewDialogResult
|
// 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);
|
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,
|
android.R.layout.simple_list_item_2,
|
||||||
new String[] { "title", "description" },
|
new String[] { "title", "description" },
|
||||||
new int[] { android.R.id.text1, android.R.id.text2 });
|
new int[] { android.R.id.text1, android.R.id.text2 });
|
||||||
|
listAdapter.colors[0] = AColorOddRow;
|
||||||
|
listAdapter.colors[1] = AColorEvenRow;
|
||||||
lListView.setAdapter(listAdapter);
|
lListView.setAdapter(listAdapter);
|
||||||
lListView.setClickable(true);
|
lListView.setClickable(true);
|
||||||
AdapterView.OnItemClickListener listviewClickListener = new AdapterView.OnItemClickListener()
|
AdapterView.OnItemClickListener listviewClickListener = new AdapterView.OnItemClickListener()
|
||||||
@ -741,7 +744,7 @@ public class LCLActivity extends Activity implements SensorEventListener, Locati
|
|||||||
{
|
{
|
||||||
private List<LCL_ListViewItem> Items;
|
private List<LCL_ListViewItem> Items;
|
||||||
// Colors to alternate
|
// Colors to alternate
|
||||||
private int[] colors = new int[] { 0xff292C29, 0xff424542 };
|
public int[] colors = new int[] { 0xff292C29, 0xff424542 };
|
||||||
|
|
||||||
@SuppressWarnings("unchecked") public LCL_ListViewAdapter(
|
@SuppressWarnings("unchecked") public LCL_ListViewAdapter(
|
||||||
Context context,
|
Context context,
|
||||||
|
@ -58,7 +58,6 @@ type
|
|||||||
procedure HandleMessageDialogFinished(Sender: TObject; AResult: Integer);
|
procedure HandleMessageDialogFinished(Sender: TObject; AResult: Integer);
|
||||||
procedure SocketProc;
|
procedure SocketProc;
|
||||||
function LoadHTMLPageViaJNI(AURL: string): string;
|
function LoadHTMLPageViaJNI(AURL: string): string;
|
||||||
procedure ShowListViewDialog(ATitle: string; ATitles, ADescriptions: array of string);
|
|
||||||
procedure MyOnListViewDialogResult(ASelectedItem: Integer);
|
procedure MyOnListViewDialogResult(ASelectedItem: Integer);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -467,52 +466,6 @@ begin
|
|||||||
{$endif}
|
{$endif}
|
||||||
end;
|
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);
|
procedure TForm1.MyOnListViewDialogResult(ASelectedItem: Integer);
|
||||||
begin
|
begin
|
||||||
DebugLn(Format('[MyOnListViewDialogResult] ASelectedItem=%d', [ASelectedItem]));
|
DebugLn(Format('[MyOnListViewDialogResult] ASelectedItem=%d', [ASelectedItem]));
|
||||||
|
@ -2,6 +2,10 @@ unit secondform;
|
|||||||
|
|
||||||
{$mode objfpc}{$H+}
|
{$mode objfpc}{$H+}
|
||||||
|
|
||||||
|
{$ifdef Linux}{$ifdef CPUARM}
|
||||||
|
{$define Android}
|
||||||
|
{$endif}{$endif}
|
||||||
|
|
||||||
interface
|
interface
|
||||||
|
|
||||||
uses
|
uses
|
||||||
@ -52,7 +56,11 @@ var
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses TypInfo, mainform;
|
uses
|
||||||
|
{$ifdef LCLCustomDrawn}
|
||||||
|
customdrawnint,
|
||||||
|
{$endif}
|
||||||
|
TypInfo, mainform;
|
||||||
|
|
||||||
{$R *.lfm}
|
{$R *.lfm}
|
||||||
|
|
||||||
@ -101,9 +109,11 @@ end;
|
|||||||
|
|
||||||
procedure TForm2.Button3Click(Sender: TObject);
|
procedure TForm2.Button3Click(Sender: TObject);
|
||||||
begin
|
begin
|
||||||
Form1.ShowListViewDialog('Dialog Title',
|
{$ifdef Android}
|
||||||
|
CDWidgetSet.ShowListViewDialog('Dialog Title',
|
||||||
['Title1', 'Title2', 'Title3', 'Title4', 'Title5', 'Title6'],
|
['Title1', 'Title2', 'Title3', 'Title4', 'Title5', 'Title6'],
|
||||||
['Descr1', 'Descr2', 'Descr3', 'Descr4', 'Descr5', 'Descr6']);
|
['Descr1', 'Descr2', 'Descr3', 'Descr4', 'Descr5', 'Descr6']);
|
||||||
|
{$endif}
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TForm2.textDestExit(Sender: TObject);
|
procedure TForm2.textDestExit(Sender: TObject);
|
||||||
|
@ -199,6 +199,9 @@ type
|
|||||||
function DoOpenDocumentWidgetsetImplementation(APath: string): Boolean;
|
function DoOpenDocumentWidgetsetImplementation(APath: string): Boolean;
|
||||||
function DoOpenAndroidURI(AURI: JObject; AMimeType: string): Boolean;
|
function DoOpenAndroidURI(AURI: JObject; AMimeType: string): Boolean;
|
||||||
function GetMimeTypeFromFileName(AFileName: string): string;
|
function GetMimeTypeFromFileName(AFileName: string): string;
|
||||||
|
procedure ShowListViewDialog(ATitle: string; ATitles,
|
||||||
|
ADescriptions: array of string;
|
||||||
|
AColorOddRow: jint = $ff292C29; AColorEvenRow: jint = $ff424542);
|
||||||
{$endif}
|
{$endif}
|
||||||
{$ifdef CD_Cocoa}
|
{$ifdef CD_Cocoa}
|
||||||
pool : NSAutoreleasePool;
|
pool : NSAutoreleasePool;
|
||||||
|
@ -1095,6 +1095,51 @@ begin
|
|||||||
else Result := 'text/plain';
|
else Result := 'text/plain';
|
||||||
end;
|
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;
|
function TCDWidgetSet.GetAppHandle: THandle;
|
||||||
begin
|
begin
|
||||||
Result := 0;
|
Result := 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user