Objective с to android java

[Resolve]-Porting an iOS Objective-c app to Android Java

Didn’t check it myself, so please post your opinion on this.

Read More

I’ve used O2J — Objective-C to Java Converter for a similar scenario and it worked very well.

It will do a great job on your algorithms/logic without much work.

It’s customizable so you can add you own translations for your Bluetooth code. You may be able to get by translating the bluetooth method calls directly to java if the APIs work the same but they probably don’t. It’s best to have a layer of indirection in your Objective-C code for the bluetooth to make it really easy to supply a Android specific implementation. For example create a BluetoothHelper.m and a BluetoothHelper.java and the translation will go much smoother.

I have used it for projects which used FMDatabase. For the FMDatabase part we already have FMDatabase/FMResultSet as the layer of indirection! I implemented FMDatabase/FMResultSet myself since the API for sqlite Objective-c (c based sqlite functions) is too different from Android. O2J helped me get started on translating FMDatabase/FMResultSet and this is what I ended up with.

public class FMDatabase < private SQLiteDatabase database; private HashMapcompiled; public FMDatabase(SQLiteDatabase database) < this.database = database; >public FMResultSet executeQuery_arguments(String sql, Object. args) < synchronized (database) < String[] selectionArgs = objectArgsAsStrings(args); Cursor rawQuery = database.rawQuery(sql, selectionArgs); return new FMResultSet(rawQuery); >> public FMResultSet executeQuery(String sql, Object. args) < synchronized (database) < String[] selectionArgs = objectArgsAsStrings(args); Cursor rawQuery = database.rawQuery(sql, selectionArgs); return new FMResultSet(rawQuery); >> public String debugQuery(String sql, Object. args) < StringBuilder sb = new StringBuilder(); FMResultSet rs = executeQuery(sql, args); rs.setupColumnNames(); HashMap names = rs.columnNameToIndexMap(); Set ks = names.keySet(); for (Object k : ks) < sb.append(k); sb.append("\t"); >sb.append("\n"); while(rs.next()) < for (Object k : ks) < String key = k.toString(); if(rs.getType(key) == Cursor.FIELD_TYPE_STRING) < sb.append(rs.stringForColumn(key)); >else if(rs.getType(key) == Cursor.FIELD_TYPE_INTEGER) < sb.append(rs.longForColumn(key)); >else if(rs.getType(key) == Cursor.FIELD_TYPE_FLOAT) < sb.append(rs.doubleForColumn(key)); >else if(rs.getType(key) == Cursor.FIELD_TYPE_BLOB) < sb.append(rs.stringForColumn(key)); >else < sb.append(""); > sb.append("\t"); > sb.append("\n"); > return sb.toString(); > public String[] objectArgsAsStrings(Object. args) < String[] selectionArgs = new String[args.length]; for (int i = 0; i < args.length; i++) < Object o = args[i]; if(o instanceof Date) < selectionArgs[i] = Long.toString(((Date) o).getTime()); >else if(o instanceof Boolean) < selectionArgs[i] = ((Boolean) o).booleanValue() ? "TRUE" : "FALSE"; >else < selectionArgs[i] = args[i] == null ? "" : o.toString(); >> return selectionArgs; > public boolean executeUpdate_arguments(String sql, Object. args) < synchronized (database) < String[] selectionArgs = objectArgsAsStrings(args); database.execSQL(sql, selectionArgs); return true; >> public boolean executeUpdate(String sql, Object. args) < synchronized (database) < SQLiteStatement statement = bindToCachedCompiledStatement(sql, args); statement.execute(); return true; >> private SQLiteStatement bindToCachedCompiledStatement(String sql, Object. args) < HashMapstatments = getCompiledStatements(); SQLiteStatement statement = statments.get(sql); if (statement == null) < statement = database.compileStatement(sql); statments.put(sql, statement); >statement.clearBindings(); // bindAllArgsAsStrings(statement, objectArgsAsStrings(args)); bindAllArgs(statement, args); return statement; > private void bindAllArgs(SQLiteStatement statement, Object[] bindArgs) < if (bindArgs == null) < return; >int size = bindArgs.length; for (int i = 0; i < size; i++) < Object arg = bindArgs[i]; int index = i + 1; if(arg == null) < statement.bindNull(index); >else if (arg instanceof String) < statement.bindString(index, (String) arg); >else if (arg instanceof Double || arg instanceof Float) < Number numArg = (Number) arg; statement.bindDouble(index, numArg.doubleValue()); >else if (arg instanceof Integer || arg instanceof Long) < Number numArg = (Number) arg; statement.bindDouble(index, numArg.longValue()); >else < statement.bindString(index, arg.toString()); >> > public long executeInsert(String string, Object. args) < synchronized (database) < SQLiteStatement statement = bindToCachedCompiledStatement(string, args); try < return statement.executeInsert(); >catch (Exception e) < Log.i("STD", "No Rows inserted", e); return 0; >> > public void bindAllArgsAsStrings(SQLiteStatement statement, String[] bindArgs) < if (bindArgs == null) < return; >int size = bindArgs.length; for (int i = 0; i < size; i++) < statement.bindString(i + 1, bindArgs[i]); >> private HashMap getCompiledStatements() < if (compiled == null) < compiled = new HashMap(); > return compiled; > public boolean rollback() < synchronized (database) < database.execSQL("ROLLBACK;"); >return true; > public boolean commit() < synchronized (database) < database.execSQL("COMMIT;"); >return true; > public boolean beginDeferredTransaction() < synchronized (database) < database.execSQL("BEGIN DEFERRED TRANSACTION;"); >return true; > public boolean beginTransaction() < synchronized (database) < database.execSQL("BEGIN EXCLUSIVE TRANSACTION;"); >return true; > public boolean open() < return true; >public void setShouldCacheStatements(boolean shouldCacheStatements) < // TODO >> 
public class FMResultSet < private boolean columnNamesSetup; private HashMapcolumnNameToIndexMap; private Cursor rawQuery; public FMResultSet(Cursor rawQuery) < this.rawQuery = rawQuery; >public void close() < rawQuery.close(); >public void setupColumnNames() < if (columnNameToIndexMap == null) < this.setColumnNameToIndexMap(new HashMap()); >int columnCount = rawQuery.getColumnCount(); int columnIdx = 0; for (columnIdx = 0; columnIdx < columnCount; columnIdx++) < columnNameToIndexMap.put(rawQuery.getColumnName(columnIdx).toLowerCase(), new Integer(columnIdx)); >columnNamesSetup = true; > public boolean next() < return rawQuery.moveToNext(); >public int columnIndexForName(String columnName) < if (!columnNamesSetup) < this.setupColumnNames(); >columnName = columnName.toLowerCase(); Number n = columnNameToIndexMap.get(columnName); if (n != null) < return NumberValueUtil.intVal(n); >Log.i("StdLog", String.format("Warning: I could not find the column named '%s'.", columnName)); return -1; > public int intForColumn(String columnName) < if (!columnNamesSetup) < this.setupColumnNames(); >int columnIdx = this.columnIndexForName(columnName); if (columnIdx == -1) < return 0; >return intForColumnIndex(columnIdx); > public int intForColumnIndex(int columnIdx) < return rawQuery.getInt(columnIdx); >public long longForColumn(String columnName) < if (!columnNamesSetup) < this.setupColumnNames(); >int columnIdx = this.columnIndexForName(columnName); if (columnIdx == -1) < return 0; >return longForColumnIndex(columnIdx); > public long longForColumnIndex(int columnIdx) < return (long) rawQuery.getLong(columnIdx); >public boolean boolForColumn(String columnName) < return (this.intForColumn(columnName) != 0); >public boolean boolForColumnIndex(int columnIdx) < return (this.intForColumnIndex(columnIdx) != 0); >public double doubleForColumn(String columnName) < if (!columnNamesSetup) < this.setupColumnNames(); >int columnIdx = this.columnIndexForName(columnName); if (columnIdx == -1) < return 0; >return doubleForColumnIndex(columnIdx); > public double doubleForColumnIndex(int columnIdx) < return rawQuery.getDouble(columnIdx); >public String stringForColumnIndex(int columnIdx) < return rawQuery.getString(columnIdx); >public String stringForColumn(String columnName) < if (!columnNamesSetup) < this.setupColumnNames(); >int columnIdx = this.columnIndexForName(columnName); if (columnIdx == -1) < return null; >return this.stringForColumnIndex(columnIdx); > public Date dateForColumn(String columnName) < if (!columnNamesSetup) < this.setupColumnNames(); >int columnIdx = this.columnIndexForName(columnName); if (columnIdx == -1) < return null; >return new Date((this.longForColumn(columnName))); > public Date dateForColumnIndex(int columnIdx) < return new Date((this.longForColumnIndex(columnIdx))); >public byte[] dataForColumn(String columnName) < if (!columnNamesSetup) < this.setupColumnNames(); >int columnIdx = this.columnIndexForName(columnName); if (columnIdx == -1) < return null; >return this.dataForColumnIndex(columnIdx); > public byte[] dataForColumnIndex(int columnIdx) < return rawQuery.getBlob(columnIdx); >public HashMap columnNameToIndexMap() < return columnNameToIndexMap; >public void setColumnNameToIndexMap(HashMap value) < columnNameToIndexMap = value; >@SuppressLint("NewApi") public int getType(String string) < return rawQuery.getType(columnIndexForName(string)); >> 

Your best bet is to use Apportable. It’s a platform that provides a port of clang, the objective-c runtime, and most of the frameworks on iOS (including UIKit).

Читайте также:  Python reshape что делает

There isn’t a Core Bluetooth wrapper yet but you can call the java APIs from their platform for that. FMDatabase will work fine and the Phone gap interface should in theory work fine.

I would avoid the code generators suggestions though. They will end up eating a lot of time reimplement everything you already built if you have a type of significate code base.

Google has some open source projects that do this.

You will need to use SVN to access these repositories. Here are the links:

Anup Cowkur 20163

More questions

  • What is the best way of converting a svg into App Icons for both iOS and Android
  • Flurry integration into same app on Android and iOS
  • How to invite all facebook friends from ios or android app after ios sdk 3.2
  • Documentation/Sample to integrate official WebRTC SDK into Android / iOS APP
  • Creating iOS & Android app from a simple html5 + javascript game?
  • App OpenStreetMap for Android & iOS
  • Best way to develop a simple video chat app for android and iOS
  • Same Firebase Instance for iOS and Android app
  • Looking for an equivalent for UIWebViewDelegate for porting an iOS app to OSX
  • Detect if web page is loaded within native Facebook app on iOS / Android
  • Porting SDL App to iOS
  • Build, deploy and run a Flutter app for iOS from Android Studio on a Linux computer using a remote Mac with an Xcode server or an SSH server?
  • Rapid App Prototyping Tools for Android and iOS
  • Dynamically alter App Icon on iOS and Android
  • Is there a Java / Android equivalent to the iOS function «componentsJoinedByString» for an NSArray?
  • Can I use SVG for app icon and splash screen? for both ios and android
  • How to limit my paid app for only one device on same account in Android and iOS
  • How to share content/data through other apps in an iOS app like we do in an Android app with Intent.ACTION_SEND?
  • How to integrate braintree to iOS or Android app using flutter?
  • AES/CBC/PKCS5Padding in iOS objective c result differs from Android
  • Android and iOS web app wrapped in a native one
  • Integrating Multiple Ad Networks on iOS and Android App
  • Why porting an iOS App to tvOS does not work?
  • Can an IOS / Android Phonegap app do nothing but link to a website?
  • How to Show Badge count on App icon in Xamarin Cross-Plotform Application for both Android and iOS
  • Check if app is already installed on iOS from safari «Browser» using java script or any other way.
  • porting c++ opengl game to android and IOS in the easiest way
  • Native Web RTC Video Call freeze on Android when call from iOS app
  • How to set Icon for app using Cordova for Android and iOS
  • Flutter app : IOS emulator not connecting to Android Studio
  • Compile Android app to iOS
  • Converting android app to ios
  • Create UDP server using C++ to embed in cross platform iOS and Android app
  • Backend for an Android and iOS app
  • need to convert blocks used in iOS to Android Java code
  • Unable to build iOS or Android app after upgrade to Flutter 3.0
  • EXPO app is blink at iOS when it is appeared to front but Android is no problem. It was created automatically by EXPO (react navigation)
  • How do I create a web app that is installable on homescreen for both ios and android
  • Different web app icons for android and ios
  • ios and android payments with paypal App store Guidelines

More questions with similar tag

  • Rally api to get data for Release Burnup
  • OpenGLES 3 Error at CVOpenGLESTextureCacheCreateTextureFromImage -6683
  • Real time OpenGL ES raytracing\raycasting on iOS with transform feedback?
  • Is there something like NSUserDefaults in Django?
  • Dummy account for app review in iTunes Connect
  • the Benifits of awakeFromNib?
  • How to use new San Francisco font in iOS 9?
  • Transparent UINavigationBar
  • Xcode 8 build crash on iOS 9.2 and below
  • Separator lines for UITableViewCellStyleSubtitle cells not taking the full width
  • Query to get search result from google . iOS
  • Merges’s folder’s content keeps getting deleted with Cordova rm platform command
  • why only viewWillAppear called on navigation back
  • App Processing Error: Unexpected CFBundleExecutable Key
  • How to conditionally use static library only when linked
  • Keeping the text color when the button is clicked
  • App Design: Handling Core Data w/ Background Contexts ; Merging w/ Notifications Filtered by MOC
  • SDL2 based game and GADBannerView
  • No such module ‘CryptoSwift’ in Xcode 8
  • What framework does forecast io use to «download» an app when you visit their website on iPhone
  • Can I use IBOutletCollection with WatchKit?
  • Storyboard — setting delegates
  • How to make a phone number in excel clickable on an iPhone?
  • Core Data with Nested PerformBlock
  • How to retrieve playerGroup attribute from GKTurnBasedMatch?
  • VTDecompressionSessionDecodeFrame fails with code -kVTVideoDecoderBadDataErr
  • Can’t add build to test for Internal tester
  • React-native: scrollview inside of panResponder
  • Drawing custom shapes in an iOS game built upon cocos2d
  • Unable restrict the click event listener outside region of LeftNavButton and RightNavButton?
  • Swift: Help troubleshoot Segue data from one view to another
  • how to add a tool bar with back and fourth button programmatically in a webview to navigate in iphone?
  • Alert action handler
  • Menu from tab bar in storyboarding
  • how to fetch records from two tables using foreign key

Источник

Оцените статью