make!your!own!simple!chat!app!using!c2call!sdk!sdkdocs.android.c2call.com/android-tutorial-simple-chat-app.pdf ·...
TRANSCRIPT
Tutorial Make Your Own Simple Chat App Using C2Call SDK
C2Call SDK Tutorial V1.0
2
Requirements a. Eclipse b. C2Call SDK
1. Open Eclipse
2. Import C2Call SDK File à Import
Select “Existing Android Code Into Workspace”
C2Call SDK Tutorial V1.0
3
Press browse
Locate your SDK and press open
C2Call SDK Tutorial V1.0
4
Your package explorer will look like this
3. Create new Android project
Enter your application name
C2Call SDK Tutorial V1.0
5
Press Next
You will have your application in package explorer
C2Call SDK Tutorial V1.0
6
4. Import the SDK to your application from your project properties.
C2Call SDK Tutorial V1.0
7
Press Add in the library section and select lib-‐c2callsdkres
C2Call SDK Tutorial V1.0
8
Your project properties will look like this
5. Delete android support under libs folder
C2Call SDK Tutorial V1.0
9
6. Edit project.properties and add manifestmerger.enabled=true
7. Create new application class
Change the code into
C2Call SDK Tutorial V1.0
10
You can get Affiliate ID and Secret from C2Call’s developer area website. 8. Create another class for startup activity and change the code into
public class SimpleChatApps extends Application{ @Override public void onCreate() { super.onCreate(); AffiliateCredentials myAffiliate = new AffiliateCredentials("<Your Affiliate ID>",
this.getPackageName(), "<Your Secret>");
C2CallSdk.instance().init(getApplicationContext(), this.getPackageName(), myAffiliate);
}
}
public class MyStartupActivity extends Activity{ @Override protected void onResume() { super.onResume(); if(isConnected()) { startMainActivity(); return; } startLoginActivity(); } private boolean isConnected(){
return SCCoreFacade.instance().isConnectedToService() && SCCoreFacade.instance().isSessionValid();
} private void startMainActivity() { C2CallSdk.instance().getStartControl().openMain(this); finish(); } private void startLoginActivity() { } }
C2Call SDK Tutorial V1.0
11
9. Copy sc_login.xml layout from SDK folder to your project folder
Paste it to your project folder
10. Create another class for login activity and change the code into
public class LoginActivity extends SCLoginFragmentActivity{ protected Fragment onCreateFragment() { return LoginFragment.create(); } }
C2Call SDK Tutorial V1.0
12
11. Create another class for login fragment
12. Edit sc_login.xml and add TextView for the register button
13. Add string value in string.xml for the register button
14. Edit the login fragment class
public class LoginFragment extends SCLoginFragment{ }
<TextView android:id="@+id/sc_login_btn_register" android:layout_width="fill_parent" android:layout_height="wrap_content" android:clickable="true" android:gravity="center_horizontal" android:text="@string/login_btn_register" android:textColor="@color/blue" android:textSize="@dimen/std_button_text_size" tools:ignore="UnusedIds" />
<string name="login_btn_register">Register</string>
C2Call SDK Tutorial V1.0
13
15. Edit your AndroidManifest.xml file Add android:name inside application tag
Add two activity
public class LoginFragment extends SCLoginFragment{ public static LoginFragment create() { return new LoginFragment(); } @Override public void onActivityCreated(Bundle arg0) { super.onActivityCreated(arg0); final View registerButton =
getActivity().findViewById(R.id.sc_login_btn_register); registerButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { C2CallSdk.startControl().openRegister(getActivity(),
null, R.layout.sc_register, null, StartType.FragmentActivity);
} }); } }
<application android:allowBackup="true" android:name=".SimpleChatApps" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/AppTheme" >
C2Call SDK Tutorial V1.0
14
Insert new tag for the provider (before </application>)
For android:authorities, you can change based on your own package (android:authorities=”<your package name>.content”). 16. Create another class for start control
<activity android:name=".myStartupActivity" android:configChanges="orientation|keyboardHidden|screenSize" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".LoginActivity" android:configChanges="orientation|keyboardHidden|screenSize" android:label="@null" android:theme="@android:style/Theme.Holo.Light" ></activity>
<provider android:name="com.c2call.sdk.pub.db.provider.C2CallContentProvider" android:authorities="com.example.mycoolphone.content" android:exported="true" android:grantUriPermissions="true" > <grant-uri-permission android:pathPattern=".*"/> </provider>
C2Call SDK Tutorial V1.0
15
17. Edit main activity class
public class StartControl extends SCStartControl{ @Override public boolean openMain(Activity activity) { Intent intent = new Intent(activity,MainActivity.class); activity.startActivity(intent); return true; } }
public class MainActivity extends SCFriendsFragmentActivity{ protected Fragment onCreateFragment() { return new SCFriendsFragment (); } }
C2Call SDK Tutorial V1.0
16
18. Add a menu xml to your project
Input the file name (in this case it is main_menu)
C2Call SDK Tutorial V1.0
17
19. Edit the main_menu.xml and edit the content
20. Add string value for the menu inside string.xml
21. Add these 2 methods inside Main Activity class
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/menu_profile" android:title="@string/profile" />
<item android:id="@+id/menu_exit" android:title="@string/exit" /> </menu>
<string name="profile">My Profile</string> <string name="exit">Exit</string>
C2Call SDK Tutorial V1.0
18
22. Change the startLoginActivity method inside startup activity class
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.main_menu, menu); return true; } @Override public boolean onMenuItemSelected(int featureId, MenuItem item) { switch(item.getItemId()) { case R.id.menu_profile:
C2CallSdk.startControl().openProfile(this, null, R.layout.sc_edit_profile, StartType.FragmentActivity);
return true; case R.id.menu_exit: AsyncTask<Void, Void, Void> myTask = new AsyncTask<Void, Void, Void>() { protected Void doInBackground(Void... params) { SCCoreFacade.instance().logout(); return null; } protected void onPostExecute(Void result) { Intent intent = new
Intent(MainActivity.this,LoginActivity.class);
MainActivity.this.finish(); startActivity(intent); }; }; myTask.execute(); return true; default: return super.onMenuItemSelected(featureId, item); } }
C2Call SDK Tutorial V1.0
19
23. Add this line into application class
24. Copy sc_contact_detail.xml to your project layout. 25. Delete voice call and video call button inside sc_contact_detail.xml
private void startLoginActivity() { Intent intent = new Intent(this,LoginActivity.class); intent.putExtra(SCExtraData.BaseFragmentData.EXTRA_DATA_LAYOUT,
R.layout.sc_login); this.startActivity(intent); finish(); }
C2CallSdk.instance().setStartControl(new StartControl());
C2Call SDK Tutorial V1.0
20
24. Build and Run your project