-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
204a251
commit f8a2bed
Showing
18 changed files
with
583 additions
and
0 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -30,3 +30,6 @@ proguard/ | |
|
||
# Android Studio captures folder | ||
captures/ | ||
|
||
# Android Studio IDEA folder | ||
.idea |
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,23 @@ | ||
// Top-level build file where you can add configuration options common to all sub-projects/modules. | ||
|
||
buildscript { | ||
repositories { | ||
jcenter() | ||
} | ||
dependencies { | ||
classpath 'com.android.tools.build:gradle:2.1.0' | ||
|
||
// NOTE: Do not place your application dependencies here; they belong | ||
// in the individual module build.gradle files | ||
} | ||
} | ||
|
||
allprojects { | ||
repositories { | ||
jcenter() | ||
} | ||
} | ||
|
||
task clean(type: Delete) { | ||
delete rootProject.buildDir | ||
} |
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 @@ | ||
/build |
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,36 @@ | ||
apply plugin: 'com.android.application' | ||
|
||
android { | ||
compileSdkVersion 23 | ||
buildToolsVersion "23.0.2" | ||
|
||
defaultConfig { | ||
applicationId "com.zendesk.sample.customfields" | ||
minSdkVersion 10 | ||
targetSdkVersion 23 | ||
versionCode 1 | ||
versionName "1.0" | ||
} | ||
buildTypes { | ||
release { | ||
minifyEnabled false | ||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' | ||
} | ||
} | ||
|
||
lintOptions { | ||
abortOnError false | ||
} | ||
} | ||
|
||
repositories { | ||
maven { url 'https://zendesk.artifactoryonline.com/zendesk/repo' } | ||
} | ||
|
||
dependencies { | ||
compile fileTree(dir: 'libs', include: ['*.jar']) | ||
testCompile 'junit:junit:4.12' | ||
compile 'com.android.support:appcompat-v7:23.3.0' | ||
|
||
compile group: 'com.zendesk', name: 'sdk-providers', version: '1.6.0.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Add project specific ProGuard rules here. | ||
# By default, the flags in this file are appended to flags specified | ||
# in /Users/bfahy/Library/Android/sdk/tools/proguard/proguard-android.txt | ||
# You can edit the include path and order by changing the proguardFiles | ||
# directive in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# Add any project specific keep options here: | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} |
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,20 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.zendesk.sample.customfields"> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:supportsRtl="true" | ||
android:theme="@style/AppTheme"> | ||
<activity android:name=".CustomFieldsActivity"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
144 changes: 144 additions & 0 deletions
144
...fields_sample_app/src/main/java/com/zendesk/sample/customfields/CustomFieldsActivity.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,144 @@ | ||
package com.zendesk.sample.customfields; | ||
|
||
import android.app.ProgressDialog; | ||
import android.os.Bundle; | ||
import android.support.v7.app.AppCompatActivity; | ||
import android.util.Log; | ||
import android.view.View; | ||
import android.widget.Button; | ||
import android.widget.EditText; | ||
import android.widget.Toast; | ||
|
||
import com.zendesk.sdk.model.access.AnonymousIdentity; | ||
import com.zendesk.sdk.model.access.JwtIdentity; | ||
import com.zendesk.sdk.model.request.CreateRequest; | ||
import com.zendesk.sdk.model.request.CustomField; | ||
import com.zendesk.sdk.network.RequestProvider; | ||
import com.zendesk.sdk.network.impl.ZendeskConfig; | ||
import com.zendesk.service.ErrorResponse; | ||
import com.zendesk.service.ZendeskCallback; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class CustomFieldsActivity extends AppCompatActivity { | ||
|
||
private static final String TAG = "CustomFieldsActivity"; | ||
|
||
// EditText Views for text input for custom fields | ||
private EditText customInput1; | ||
private EditText customInput2; | ||
private EditText customInput3; | ||
private EditText customInput4; | ||
private Button submitButton; | ||
|
||
private ProgressDialog progressDialog; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_main); | ||
|
||
// Initialize the Zendesk SDK and set Anonymous or JWT authentication details | ||
initializeZendesk(); | ||
|
||
// Uninteresting method of findViewById calls | ||
captureViews(); | ||
|
||
submitButton.setOnClickListener(new View.OnClickListener() { | ||
@Override | ||
public void onClick(View v) { | ||
// Show friendly ProgressDialog with indeterminate progress spinner, non-cancelable. | ||
progressDialog = ProgressDialog.show(CustomFieldsActivity.this, "Sending Request", "Aligning 1s and 0s...", true, false); | ||
|
||
// Get an instance of the RequestProvider from the ZendeskConfig | ||
RequestProvider provider = ZendeskConfig.INSTANCE.provider().requestProvider(); | ||
|
||
// Build your CreateRequest object, which includes the custom field data | ||
CreateRequest request = buildCreateRequest(); | ||
|
||
// Optionally, create a ZendeskCallback. This can be null. | ||
ZendeskCallback<CreateRequest> callback = buildCallback(); | ||
|
||
// Call the provider method | ||
provider.createRequest(request, callback); | ||
} | ||
}); | ||
} | ||
|
||
private void initializeZendesk() { | ||
// Initialize the SDK with your Zendesk subdomain, mobile SDK app ID, and client ID. | ||
// Get these details from your Zendesk dashboard: Admin -> Channels -> MobileSDK | ||
ZendeskConfig.INSTANCE.init(getApplicationContext(), | ||
"https://[subdomain].zendesk.com", | ||
"[app ID]", | ||
"[client ID]"); | ||
|
||
// Set either Anonymous or JWT identity, as below: | ||
|
||
// 1. Anonymous (All fields are optional.) | ||
ZendeskConfig.INSTANCE.setIdentity( | ||
new AnonymousIdentity.Builder() | ||
.withNameIdentifier("[optional name") | ||
.withEmailIdentifier("[optional email]") | ||
.withExternalIdentifier("[optional external identifier]") | ||
.build() | ||
); | ||
|
||
// 2. JWT (Must be initialized with your JWT identifier) | ||
ZendeskConfig.INSTANCE.setIdentity(new JwtIdentity("[JWT identifier]")); | ||
} | ||
|
||
private CreateRequest buildCreateRequest() { | ||
// Create an instance of CreateRequest | ||
CreateRequest request = new CreateRequest(); | ||
|
||
// Set any details on it you want | ||
request.setSubject("Test Custom Fields Ticket"); | ||
request.setDescription("We should see custom fields on this ticket!"); | ||
|
||
// Build CustomField objects as desired, using the Custom Field IDs from your Zendesk dashboard. | ||
request.setCustomFields(buildCustomFieldsList()); | ||
|
||
return request; | ||
} | ||
|
||
private List<CustomField> buildCustomFieldsList() { | ||
List<CustomField> list = new ArrayList<>(); | ||
|
||
// Make sure to use the Custom Field IDs from your Zendesk dashboard! | ||
list.add(new CustomField(1L, customInput1.getText().toString())); | ||
list.add(new CustomField(2L, customInput2.getText().toString())); | ||
list.add(new CustomField(3L, customInput3.getText().toString())); | ||
list.add(new CustomField(4L, customInput4.getText().toString())); | ||
|
||
return list; | ||
} | ||
|
||
private ZendeskCallback<CreateRequest> buildCallback() { | ||
// Build the optional callback to handle success/error | ||
return new ZendeskCallback<CreateRequest>() { | ||
@Override | ||
public void onSuccess(CreateRequest createRequest) { | ||
progressDialog.dismiss(); | ||
Log.d(TAG, "onSuccess: Ticket created!"); | ||
Toast.makeText(getApplicationContext(), "Success! Ticket created!", Toast.LENGTH_SHORT).show(); | ||
} | ||
|
||
@Override | ||
public void onError(ErrorResponse errorResponse) { | ||
progressDialog.dismiss(); | ||
Log.d(TAG, "onError: " + errorResponse.getReason()); | ||
Toast.makeText(getApplicationContext(), "Error! " + errorResponse.getReason(), Toast.LENGTH_SHORT).show(); | ||
} | ||
}; | ||
} | ||
|
||
private void captureViews() { | ||
customInput1 = (EditText) findViewById(R.id.customInput1); | ||
customInput2 = (EditText) findViewById(R.id.customInput2); | ||
customInput3 = (EditText) findViewById(R.id.customInput3); | ||
customInput4 = (EditText) findViewById(R.id.customInput4); | ||
submitButton = (Button) findViewById(R.id.btnSubmit); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
custom_fields_sample_app/src/main/res/layout/activity_main.xml
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,57 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:orientation="vertical" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:paddingBottom="@dimen/activity_vertical_margin" | ||
android:paddingLeft="@dimen/activity_horizontal_margin" | ||
android:paddingRight="@dimen/activity_horizontal_margin" | ||
android:paddingTop="@dimen/activity_vertical_margin" | ||
tools:context=".CustomFieldsActivity"> | ||
|
||
<TextView | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="Enter information for custom fields below:"/> | ||
|
||
<EditText | ||
android:id="@+id/customInput1" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:hint="Custom Field 1" | ||
android:inputType="text" | ||
/> | ||
|
||
<EditText | ||
android:id="@+id/customInput2" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:hint="Custom Field 2" | ||
android:inputType="text" | ||
/> | ||
|
||
<EditText | ||
android:id="@+id/customInput3" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:hint="Custom Field 3" | ||
android:inputType="text" | ||
/> | ||
|
||
<EditText | ||
android:id="@+id/customInput4" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:hint="Custom Field 4" | ||
android:inputType="text" | ||
/> | ||
|
||
<Button | ||
android:id="@+id/btnSubmit" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:text="Submit" | ||
/> | ||
</LinearLayout> | ||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="colorPrimary">#3F51B5</color> | ||
<color name="colorPrimaryDark">#303F9F</color> | ||
<color name="colorAccent">#FF4081</color> | ||
</resources> |
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,5 @@ | ||
<resources> | ||
<!-- Default screen margins, per the Android Design guidelines. --> | ||
<dimen name="activity_horizontal_margin">16dp</dimen> | ||
<dimen name="activity_vertical_margin">16dp</dimen> | ||
</resources> |
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,3 @@ | ||
<resources> | ||
<string name="app_name">Zendesk Custom Fields Sample</string> | ||
</resources> |
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,11 @@ | ||
<resources> | ||
|
||
<!-- Base application theme. --> | ||
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> | ||
<!-- Customize your theme here. --> | ||
<item name="colorPrimary">@color/colorPrimary</item> | ||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item> | ||
<item name="colorAccent">@color/colorAccent</item> | ||
</style> | ||
|
||
</resources> |
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,6 @@ | ||
#Mon Dec 28 10:00:20 PST 2015 | ||
distributionBase=GRADLE_USER_HOME | ||
distributionPath=wrapper/dists | ||
zipStoreBase=GRADLE_USER_HOME | ||
zipStorePath=wrapper/dists | ||
distributionUrl=https\://services.gradle.org/distributions/gradle-2.10-all.zip |
Oops, something went wrong.