I've created an Android application, which is generally aimed on Tablets. Its main business-logic is in pure java, it contains around 10-15 Activities, SQLite database, it performs HTTP transactions, exports information to different formats etc. My customer now (out of a sudden) wants to have exactly the same application running on Windows 7 or 8. What is the simpliest and the most straightforward way to create such an application (I do not consider using emulators)? I've never created GUI for Java-applications before.
答案 0 :(得分:2)
Since you are probably using gradle already, you can decouple your business model from the platform, moving them to another project, from which your android and desktop projects will depend:
Const xlUp As Long = -4162
Sub ExportToExcel(MyMail As MailItem)
Dim strID As String, olNS As Outlook.NameSpace
Dim olMail As Outlook.MailItem
Dim strFileName As String
Dim strBody As String
Dim Reg1 As RegExp
Dim M1 As MatchCollection
Dim M As Match
Set Reg1 = New RegExp
With Reg1
.Pattern = "http://www\.changedetection\.com/log(.*)"
.IgnoreCase = True
.Global = True
End With
If Reg1.test(olMail.Body) Then
Set M1 = Reg1.Execute(olMail.Body)
For Each M In M1
strBody = M.SubMatches(1)
Next
End If
'~~> Excel Variables
Dim oXLApp As Object, oXLwb As Object, oXLws As Object
Dim lRow As Long
strID = MyMail.EntryID
Set olNS = Application.GetNamespace("MAPI")
Set olMail = olNS.GetItemFromID(strID)
'~~> Establish an EXCEL application object
On Error Resume Next
Set oXLApp = GetObject(, "Excel.Application")
'~~> If not found then create new instance
If Err.Number <> 0 Then
Set oXLApp = CreateObject("Excel.Application")
End If
Err.Clear
On Error GoTo 0
'~~> Show Excel
oXLApp.Visible = True
'~~> Open the relevant file
Set oXLwb = oXLApp.Workbooks.Open("M:\Monitor\Monitor_Test_1.xlsx")
'~~> Set the relevant output sheet. Change as applicable
Set oXLws = oXLwb.Sheets("Test")
lRow = oXLws.Range("A" & oXLApp.Rows.Count).End(xlUp).Row + 1
'~~> Write to outlook
With oXLws
'
'~~> Code here to output data from email to Excel File
'~~> For example
'
.Range("A" & lRow).Value = olMail.Subject
.Range("B" & lRow).Value = olMail.SenderName
.Range("C" & lRow).Value = strBody
'
End With
'~~> Close and Clean up Excel
oXLwb.Close (True)
oXLApp.Quit
Set Reg1 = Nothing
Set oXLws = Nothing
Set oXLwb = Nothing
Set oXLApp = Nothing
Set olMail = Nothing
Set olNS = Nothing
End Sub
https://docs.gradle.org/current/userguide/multi_project_builds.html
If your app is using frameworks like retrofit, which work on both and Android and common java projects, you can move its usages to the core project.
This question covers very well different GUI frameworks from where you can choose.
Decoupling your project in such a way is not an easy task. You'll need to carefully think on how your core project will interact with the others (i.e some internal API). Basically, you will keep working on a MVC-sort-of-architecture, but now your android project will be a view, and your desktop will be another.
Similar question: java desktop and android application at the same time - shared packages
(Little bit off-topic but it might help you)
While the multi-project approach might seem like a nice reuse of existing code, it might get harder depending on how your current project is structured.
Another approach would be to use something like Electron with Polymer and/or AngularJS. If you are familiar with web technologies, it can be a lot easier to create your desktop app like this. And you have a plus: a browser app is just one step ahead. Also, Polymer keeps material design on your desktop app, making your designs more consistent between platforms, which might be difficult to achieve using native java frameworks for desktop.