-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
native android add contact fin, ios to be degugged
- Loading branch information
1 parent
eaf9892
commit df182a5
Showing
27 changed files
with
456 additions
and
319 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#Mon Aug 24 06:11:19 EST 2020 | ||
gradle.version=4.4.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>android</name> | ||
<comment>Project android created by Buildship.</comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.eclipse.buildship.core.gradleprojectbuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.eclipse.buildship.core.gradleprojectnature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
arguments= | ||
auto.sync=false | ||
build.scans.enabled=false | ||
connection.gradle.distribution=GRADLE_DISTRIBUTION(WRAPPER) | ||
connection.project.dir= | ||
eclipse.preferences.version=1 | ||
gradle.user.home= | ||
java.home=/usr/lib/jvm/java-14-openjdk-amd64 | ||
jvm.arguments= | ||
offline.mode=false | ||
override.workspace.settings=true | ||
show.console.view=true | ||
show.executions.view=true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
android/app/src/main/java/com.example.fst_app_flutter/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.example.fst_app_flutter;/* | ||
Dart Java Kotlin Obj-C Swift | ||
null null null nil (NSNull when nested) nil | ||
bool java.lang.Boolean Boolean NSNumber numberWithBool: NSNumber(value: Bool) | ||
int java.lang.Integer Int NSNumber numberWithInt: NSNumber(value: Int32) | ||
int, 64 java.lang.Long Long NSNumber numberWithLong: NSNumber(value: Int) | ||
double java.lang.Double Double NSNumber numberWithDouble: NSNumber(value: Double) | ||
String java.lang.String String NSString String | ||
Uint8List byte[] ByteArray FlutterStandardTypedData typedDataWithBytes: FlutterStandardTypedData(bytes: Data) | ||
Int32List int[] IntArray FlutterStandardTypedData typedDataWithInt32: FlutterStandardTypedData(int32: Data) | ||
Int64List long[] LongArray FlutterStandardTypedData typedDataWithInt64: FlutterStandardTypedData(int64: Data) | ||
Float64List double[] DoubleArray FlutterStandardTypedData typedDataWithFloat64: FlutterStandardTypedData(float64: Data) | ||
List java.util.ArrayList List NSArray Array | ||
Map java.util.HashMap HashMap NSDictionary Dictionary | ||
*/ | ||
|
||
|
||
import androidx.annotation.NonNull; | ||
|
||
import java.util.HashMap; | ||
|
||
import io.flutter.embedding.android.FlutterActivity; | ||
import io.flutter.embedding.engine.FlutterEngine; | ||
import io.flutter.plugin.common.MethodChannel; | ||
|
||
@SuppressWarnings("unchecked") | ||
public class MainActivity extends FlutterActivity { | ||
|
||
private static final String CHANNEL = "com.example.fst_app_flutter/contacts"; | ||
|
||
@Override | ||
public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) { | ||
super.configureFlutterEngine(flutterEngine); | ||
new MethodChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), CHANNEL) | ||
.setMethodCallHandler( | ||
(call, result) -> { | ||
if ("saveNatively".equals(call.method)) { | ||
try { | ||
NativeContact contact = new NativeContact((HashMap<String, Object>) call.arguments); | ||
contact.saveNatively(getApplicationContext()); | ||
} catch (Exception e) { | ||
System.out.println(e.getMessage()); | ||
} | ||
} else { | ||
result.notImplemented(); | ||
} | ||
} | ||
); | ||
} | ||
|
||
|
||
} |
203 changes: 203 additions & 0 deletions
203
android/app/src/main/java/com.example.fst_app_flutter/NativeContact.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
package com.example.fst_app_flutter; | ||
|
||
|
||
import android.content.ContentValues; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.provider.ContactsContract; | ||
import android.util.Log; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
|
||
|
||
/** | ||
* Contacts class for saving using the native Contacts UI | ||
*/ | ||
@SuppressWarnings("unchecked") | ||
public class NativeContact { | ||
|
||
private String displayName; | ||
private String note; | ||
private String email; | ||
private ArrayList<NativeContactPhone> phones; | ||
private String website; | ||
|
||
/** | ||
* Creates an instance of NativeContact | ||
* | ||
* @param map a Map object passed in from dart saveNatively method in | ||
* * contact_model.dart | ||
*/ | ||
NativeContact(HashMap<String, Object> map) { | ||
this.displayName = (String) map.get("displayName"); | ||
this.email = (String) map.get("email"); | ||
this.note = (String) map.get("note"); | ||
this.website = (String) map.get("website"); | ||
this.phones = new ArrayList<>(); | ||
|
||
try { | ||
ArrayList<HashMap<String, String>> tempPhoneList = (ArrayList<HashMap<String, String>>) map.get( | ||
"phones"); | ||
if (tempPhoneList != null) { | ||
for (HashMap<String, String> phone : tempPhoneList) { | ||
this.phones.add(new NativeContactPhone(phone)); | ||
|
||
} | ||
} | ||
} catch (Exception e) { | ||
System.out.println(e.getMessage()); | ||
} | ||
|
||
|
||
} | ||
|
||
/** | ||
* Opens the native contact form with this contact's data pre-loaded in their respective fields. | ||
* @param context The context from which to start the activity | ||
*/ | ||
public void saveNatively(Context context) { | ||
Intent intent = new Intent(ContactsContract.Intents.Insert.ACTION); | ||
|
||
Log.d("flutter-plugin", displayName); | ||
ArrayList<ContentValues> dataList = new ArrayList<>(); | ||
|
||
Log.d("email", getEmail()); | ||
ContentValues row = new ContentValues(); | ||
row.put(ContactsContract.Data.MIMETYPE, | ||
ContactsContract.CommonDataKinds.Email.CONTENT_ITEM_TYPE); | ||
row.put(ContactsContract.CommonDataKinds.Email.ADDRESS, getEmail()); | ||
row.put(ContactsContract.CommonDataKinds.Email.TYPE, | ||
ContactsContract.CommonDataKinds.Email.TYPE_WORK); | ||
dataList.add(row); | ||
|
||
|
||
for (NativeContactPhone phone : getPhones()) { | ||
Log.d("phone", phone.getNumber()); | ||
row = new ContentValues(); | ||
row.put(ContactsContract.Data.MIMETYPE, | ||
ContactsContract.CommonDataKinds.Phone.CONTENT_ITEM_TYPE); | ||
row.put(ContactsContract.CommonDataKinds.Phone.NUMBER, phone.getNumber()); | ||
row.put(ContactsContract.CommonDataKinds.Phone.TYPE, phone.getLabel()); | ||
dataList.add(row); | ||
} | ||
|
||
Log.d("website", getWebsite()); | ||
row = new ContentValues(); | ||
row.put(ContactsContract.Data.MIMETYPE, | ||
ContactsContract.CommonDataKinds.Website.CONTENT_ITEM_TYPE); | ||
row.put(ContactsContract.CommonDataKinds.Website.URL, getWebsite()); | ||
row.put(ContactsContract.CommonDataKinds.Website.TYPE, | ||
ContactsContract.CommonDataKinds.Website.TYPE_WORK); | ||
dataList.add(row); | ||
|
||
intent.setType(ContactsContract.RawContacts.CONTENT_TYPE); | ||
|
||
intent.putExtra(ContactsContract.Intents.Insert.NAME, getDisplayName()); | ||
intent.putParcelableArrayListExtra(ContactsContract.Intents.Insert.DATA, | ||
dataList); | ||
intent.putExtra(ContactsContract.Intents.Insert.NOTES, getNote()); | ||
|
||
|
||
intent.putExtra("finishActivityOnSaveCompleted", true); | ||
context.startActivity(intent); | ||
|
||
} | ||
|
||
|
||
/** | ||
* Gets this contact's display name / full name | ||
* | ||
* @return The display name for this contact | ||
*/ | ||
public String getDisplayName() { | ||
return displayName; | ||
} | ||
|
||
/** | ||
* Gets the notes for this contact. | ||
* | ||
* @return the note for this contact | ||
*/ | ||
public String getNote() { | ||
return note; | ||
} | ||
|
||
/** | ||
* Gets the email address for this contact | ||
* | ||
* @return the email for this contact | ||
*/ | ||
public String getEmail() { | ||
return email; | ||
} | ||
|
||
/** | ||
* Gets the website for this contact. | ||
* | ||
* @return the website for this contact. | ||
*/ | ||
public String getWebsite() { | ||
return website; | ||
} | ||
|
||
/** | ||
* Gets the list of phone numbers for this contact. | ||
* | ||
* @return The list of phone numbers for this contact. | ||
*/ | ||
public ArrayList<NativeContactPhone> getPhones() { | ||
return phones; | ||
} | ||
|
||
/** | ||
* The class to manage phone numbers for NativeContact. | ||
*/ | ||
private class NativeContactPhone { | ||
|
||
private int label; | ||
private String number; | ||
|
||
/** | ||
* Creates an instance of NativeContactPhone. | ||
* | ||
* @param map A map object passed from the NativeContact constructor from the invoke | ||
* method call arguments passed in dart saveNatively method in | ||
* contact_model.dart. | ||
*/ | ||
NativeContactPhone(HashMap<String, String> map) { | ||
this.number = map.get("value"); | ||
String strLabel = map.get("label"); | ||
if (strLabel != null) { | ||
if ("fax work".equals(strLabel)) { | ||
this.label = ContactsContract.CommonDataKinds.Phone.TYPE_FAX_WORK; | ||
} else { | ||
this.label = ContactsContract.CommonDataKinds.Phone.TYPE_WORK; | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* GGets the phone label. | ||
* | ||
* @return The label / type of phone number for this phone number. This integer represents | ||
* an enum value from ContactsContract.CommonDataKinds.Phone. | ||
*/ | ||
public int getLabel() { | ||
return label; | ||
} | ||
|
||
/** | ||
* Gets the phone number. | ||
* | ||
* @return The phone number for this contact. | ||
*/ | ||
public String getNumber() { | ||
return number; | ||
} | ||
|
||
|
||
} | ||
|
||
|
||
} |
25 changes: 0 additions & 25 deletions
25
android/app/src/main/java/com/example/fst_app_flutter/MainActivity.java
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
android/app/src/main/java/com/example/fst_app_flutter/NativeContact.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.