Skip to content

Commit

Permalink
native android add contact fin, ios to be degugged
Browse files Browse the repository at this point in the history
  • Loading branch information
richtwin567 committed Aug 24, 2020
1 parent eaf9892 commit df182a5
Show file tree
Hide file tree
Showing 27 changed files with 456 additions and 319 deletions.
Binary file added .gradle/4.4.1/fileChanges/last-build.bin
Binary file not shown.
Binary file added .gradle/4.4.1/fileHashes/fileHashes.lock
Binary file not shown.
Binary file added .gradle/4.4.1/taskHistory/taskHistory.lock
Binary file not shown.
Binary file added .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
2 changes: 2 additions & 0 deletions .gradle/buildOutputCleanup/cache.properties
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
5 changes: 5 additions & 0 deletions android/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ gradle-wrapper.jar
/gradlew.bat
/local.properties
GeneratedPluginRegistrant.java
/gradle/wrapper/dists

# Remember to never publicly share your keystore.
# See https://flutter.dev/docs/deployment/android#reference-the-keystore-from-the-app
key.properties
17 changes: 17 additions & 0 deletions android/.project
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>
13 changes: 13 additions & 0 deletions android/.settings/org.eclipse.buildship.core.prefs
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
8 changes: 0 additions & 8 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,11 @@ if (flutterVersionName == null) {
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 28

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}

lintOptions {
disable 'InvalidPackage'
}
Expand All @@ -58,6 +53,3 @@ flutter {
source '../..'
}

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
}
2 changes: 2 additions & 0 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
<application
android:name="io.flutter.app.FlutterApplication"
android:label="fst_app_flutter"
Expand Down
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();
}
}
);
}


}
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;
}


}


}

This file was deleted.

This file was deleted.

3 changes: 0 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ rootProject.buildDir = '../build'
subprojects {
project.buildDir = "${rootProject.buildDir}/${project.name}"
}
subprojects {
project.evaluationDependsOn(':app')
}

task clean(type: Delete) {
delete rootProject.buildDir
Expand Down
4 changes: 0 additions & 4 deletions android/settings.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
// Copyright 2014 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

include ':app'

def localPropertiesFile = new File(rootProject.projectDir, "local.properties")
Expand Down
1 change: 0 additions & 1 deletion android/settings_aar.gradle

This file was deleted.

Loading

0 comments on commit df182a5

Please sign in to comment.