Add inapp purchase

Add account creator
This commit is contained in:
Margaux Clerc 2016-08-09 13:21:34 +02:00
parent 375d2eb2dd
commit 5b264a6685
20 changed files with 821 additions and 313 deletions

View file

@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.linphone" package="org.linphone"
android:versionCode="3100" android:installLocation="auto"> android:versionCode="3120" android:installLocation="auto">
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23"/> <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="23"/>
<!-- Permissions for Push Notification --> <!-- Permissions for Push Notification -->

View file

@ -1,4 +1,4 @@
source.dir=src:submodules/linphone/mediastreamer2/java/src:submodules/linphone/java/j2se:submodules/linphone/java/common:submodules/linphone/java/impl:submodules/linphone/coreapi/help/java source.dir=src:submodules/linphone/mediastreamer2/java/src:submodules/linphone/java/j2se:submodules/linphone/java/common:submodules/linphone/java/impl:submodules/linphone/coreapi/help/java
key.store=bc-android.keystore key.store=bc-android.keystore
key.alias=nw8000 key.alias=nw8000
version.name=2.5.0 version.name=3.1.2

69
res/layout/in_app.xml Normal file
View file

@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:background="@color/colorH"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<fragment
android:id="@+id/status"
android:name="org.linphone.StatusFragment"
android:layout_width="match_parent"
android:layout_height="40dp"
tools:layout="@layout/status"/>
<LinearLayout
android:id="@+id/topbar"
android:background="@color/colorF"
android:orientation="horizontal"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="60dp">
<ImageView
android:id="@+id/back"
android:src="@drawable/back"
android:background="@drawable/toolbar_button"
android:contentDescription="@string/content_description_back"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:padding="18dp"/>
<TextView
android:text="@string/inapp"
style="@style/font1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.6"
android:gravity="center"/>
<ImageView
android:id="@+id/cancel"
android:src="@drawable/dialer_back"
android:background="@drawable/toolbar_button"
android:contentDescription="@string/content_description_dialer_back"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.2"
android:padding="15dp"/>
</LinearLayout>
<ProgressBar
android:id="@+id/purchaseItemsFetchInProgress"
style="?android:attr/progressBarStyle"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="gone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<LinearLayout
android:id="@+id/fragment_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_below="@+id/topbar"/>
</RelativeLayout>

View file

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:id="@+id/inapp_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:divider="@color/colorE"
android:cacheColorHint="@color/transparent"
android:dividerHeight="1dp" />
</LinearLayout>

View file

@ -1,19 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:orientation="vertical" >
<Button
android:id="@+id/inapp_button"
android:text="@string/assistant_create_account"
android:background="@drawable/assistant_button"
style="@style/font8"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_width="match_parent"
android:layout_height="40dp"/>
</LinearLayout>

View file

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/inapp_purchase"
android:background="@color/colorH"
android:layout_width="match_parent"
android:layout_height="60dp">
<ImageView
android:id="@+id/inapp_icon"
android:src="@drawable/linphone_logo"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:layout_margin="5dp"
android:layout_width="40dp"
android:layout_height="40dp"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/inapp_icon">
<TextView
android:id="@+id/purchase_title"
style="@style/font7"
android:textSize="15sp"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<TextView
android:id="@+id/purchase_description"
style="@style/font11"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
<TextView
android:id="@+id/purchase_price"
android:layout_margin="5dp"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>

View file

@ -4,28 +4,10 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" > android:orientation="vertical" >
<LinearLayout
android:id="@+id/topbar"
android:background="@color/colorF"
android:orientation="horizontal"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="60dp">
<TextView
android:text="@string/assistant"
style="@style/font1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"/>
</LinearLayout>
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:padding="30dp" android:padding="30dp"
android:gravity="center" android:gravity="center"
android:orientation="vertical"> android:orientation="vertical">
@ -90,21 +72,17 @@
android:singleLine="true"/> android:singleLine="true"/>
</LinearLayout> </LinearLayout>
<LinearLayout
android:id="@+id/purchasable_items"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="40dp"
android:gravity="center"
android:orientation="vertical"/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp" />
</LinearLayout> </LinearLayout>
<Button
android:id="@+id/inapp_button"
android:text="@string/assistant_create_account"
android:background="@drawable/assistant_button"
style="@style/font8"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="40dp"/>
</LinearLayout> </LinearLayout>

View file

@ -37,5 +37,15 @@ max_calls=10
activation_code_length=4 activation_code_length=4
[in-app-purchase] [in-app-purchase]
server_url=https://www.linphone.org/xmlrpc.php server_url=http://sip3.linphone.org/inapp.php
purchasable_items_ids=test_account_subscription purchasable_items_ids=test_account_subscription
[assistant]
domain=sip.linphone.org
password_max_length=-1
password_min_length=1
username_length=-1
username_max_length=64
username_min_length=1
username_regex=^[a-z0-9_.\-]*$
xmlrpc_url=https://sip3.linphone.org:444/inapp.php

View file

@ -16,8 +16,10 @@
<bool name="replace_assistant_with_old_interface">false</bool> <bool name="replace_assistant_with_old_interface">false</bool>
<bool name="force_use_of_linphone_friends">false</bool> <bool name="force_use_of_linphone_friends">false</bool>
<bool name="in_app_purchase_in_settings">false</bool> <bool name="in_app_purchase_in_settings">false</bool>
<bool name="use_friendlist_subscription">true</bool>
<string name="wizard_url">https://sip3.linphone.org:444/inapp.php</string>
<string name="wizard_url">https://www.linphone.org/wizard.php</string>
<!-- Push notification settings --> <!-- Push notification settings -->
<bool name="enable_push_id">true</bool> <bool name="enable_push_id">true</bool>

View file

@ -100,6 +100,26 @@
<string name="select_your_country">Select your Country</string> <string name="select_your_country">Select your Country</string>
<string name="country_code">(%s)</string> <string name="country_code">(%s)</string>
<!-- Status -->
<string name="invalid_email">Invalid email</string>
<string name="account_already_exist">Account already exist</string>
<string name="invalid_username">Invalid username</string>
<string name="invalid_domain">Invalid domain</string>
<string name="invalid_route">Invalid route</string>
<string name="username_too_short">Username too short</string>
<string name="username_too_long">Username too long</string>
<string name="username_invalid_size">Username length invalid</string>
<string name="phone_number_too_long">Phone number too long</string>
<string name="phone_number_too_short">Phone number too short</string>
<string name="phone_number_invalid">Invalid phone number</string>
<string name="password_too_short">Password too short</string>
<string name="password_too_long">Password too long</string>
<string name="request_failed">Failed to query the server. Please try again later</string>
<string name="transport_unsupported">Unsupported transport</string>
<!-- In-app -->
<string name="inapp">in-app</string>
<!-- Dailer --> <!-- Dailer -->
<string name="address_bar_hint">Enter a number or an address</string> <string name="address_bar_hint">Enter a number or an address</string>

View file

@ -48,7 +48,11 @@ import org.linphone.core.LinphoneCoreListenerBase;
import org.linphone.core.LinphoneProxyConfig; import org.linphone.core.LinphoneProxyConfig;
import org.linphone.core.Reason; import org.linphone.core.Reason;
import org.linphone.mediastream.Log; import org.linphone.mediastream.Log;
import org.linphone.purchase.InAppPurchaseActivity;
import org.linphone.purchase.InAppPurchaseHelper;
import org.linphone.ui.AddressText; import org.linphone.ui.AddressText;
import org.linphone.xmlrpc.XmlRpcHelper;
import org.linphone.xmlrpc.XmlRpcListenerBase;
import android.Manifest; import android.Manifest;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
@ -174,7 +178,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
return; return;
} }
} }
if (getIntent() != null && getIntent().getExtras() != null) { if (getIntent() != null && getIntent().getExtras() != null) {
newProxyConfig = getIntent().getExtras().getBoolean("isNewProxyConfig"); newProxyConfig = getIntent().getExtras().getBoolean("isNewProxyConfig");
} }
@ -197,6 +201,10 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
initButtons(); initButtons();
initSideMenu(); initSideMenu();
//ifINAP
getTrialAccount();
getExpirationAccount();
currentFragment = FragmentsAvailable.EMPTY; currentFragment = FragmentsAvailable.EMPTY;
if (savedInstanceState == null) { if (savedInstanceState == null) {
changeCurrentFragment(FragmentsAvailable.DIALER, getIntent().getExtras()); changeCurrentFragment(FragmentsAvailable.DIALER, getIntent().getExtras());
@ -348,9 +356,9 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
} catch (Exception e) { } catch (Exception e) {
} }
} }
fragment = null; fragment = null;
switch (newFragmentType) { switch (newFragmentType) {
case HISTORY_LIST: case HISTORY_LIST:
fragment = new HistoryListFragment(); fragment = new HistoryListFragment();
@ -619,6 +627,10 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
startActivity(new Intent(LinphoneActivity.this, AssistantActivity.class)); startActivity(new Intent(LinphoneActivity.this, AssistantActivity.class));
} }
public void displayInapp() {
startActivity(new Intent(LinphoneActivity.this, InAppPurchaseActivity.class));
}
public int getUnreadMessageCount() { public int getUnreadMessageCount() {
int count = 0; int count = 0;
LinphoneChatRoom[] chats = LinphoneManager.getLc().getChatRooms(); LinphoneChatRoom[] chats = LinphoneManager.getLc().getChatRooms();
@ -1063,7 +1075,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
finish(); finish();
stopService(new Intent(Intent.ACTION_MAIN).setClass(this, LinphoneService.class)); stopService(new Intent(Intent.ACTION_MAIN).setClass(this, LinphoneService.class));
} }
@Override @Override
protected void onPostResume() { protected void onPostResume() {
super.onPostResume(); super.onPostResume();
@ -1114,7 +1126,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
if (lc != null) { if (lc != null) {
lc.removeListener(mListener); lc.removeListener(mListener);
} }
super.onPause(); super.onPause();
} }
@ -1139,7 +1151,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
} }
return true; return true;
} }
public boolean checkAndRequestOverlayPermission() { public boolean checkAndRequestOverlayPermission() {
Log.i("[Permission] Draw overlays permission is " + (Compatibility.canDrawOverlays(this) ? "granted" : "denied")); Log.i("[Permission] Draw overlays permission is " + (Compatibility.canDrawOverlays(this) ? "granted" : "denied"));
if (!Compatibility.canDrawOverlays(this)) { if (!Compatibility.canDrawOverlays(this)) {
@ -1150,7 +1162,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
} }
return true; return true;
} }
public void checkAndRequestReadExternalStoragePermission() { public void checkAndRequestReadExternalStoragePermission() {
checkAndRequestPermission(Manifest.permission.READ_EXTERNAL_STORAGE, 0); checkAndRequestPermission(Manifest.permission.READ_EXTERNAL_STORAGE, 0);
} }
@ -1158,39 +1170,39 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
public void checkAndRequestExternalStoragePermission() { public void checkAndRequestExternalStoragePermission() {
checkAndRequestPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, 0); checkAndRequestPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, 0);
} }
public void checkAndRequestCameraPermission() { public void checkAndRequestCameraPermission() {
checkAndRequestPermission(Manifest.permission.CAMERA, 0); checkAndRequestPermission(Manifest.permission.CAMERA, 0);
} }
public void checkAndRequestReadContactsPermission() { public void checkAndRequestReadContactsPermission() {
checkAndRequestPermission(Manifest.permission.READ_CONTACTS, PERMISSIONS_REQUEST_CONTACTS); checkAndRequestPermission(Manifest.permission.READ_CONTACTS, PERMISSIONS_REQUEST_CONTACTS);
} }
private boolean willContactsPermissionBeAsked() { private boolean willContactsPermissionBeAsked() {
return LinphonePreferences.instance().firstTimeAskingForPermission(Manifest.permission.READ_CONTACTS) || ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_CONTACTS); return LinphonePreferences.instance().firstTimeAskingForPermission(Manifest.permission.READ_CONTACTS) || ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_CONTACTS);
} }
public void checkAndRequestWriteContactsPermission() { public void checkAndRequestWriteContactsPermission() {
checkAndRequestPermission(Manifest.permission.WRITE_CONTACTS, 0); checkAndRequestPermission(Manifest.permission.WRITE_CONTACTS, 0);
} }
public void checkAndRequestRecordAudioPermissionForEchoCanceller() { public void checkAndRequestRecordAudioPermissionForEchoCanceller() {
checkAndRequestPermission(Manifest.permission.RECORD_AUDIO, PERMISSIONS_RECORD_AUDIO_ECHO_CANCELLER); checkAndRequestPermission(Manifest.permission.RECORD_AUDIO, PERMISSIONS_RECORD_AUDIO_ECHO_CANCELLER);
} }
public void checkAndRequestReadExternalStoragePermissionForDeviceRingtone() { public void checkAndRequestReadExternalStoragePermissionForDeviceRingtone() {
checkAndRequestPermission(Manifest.permission.READ_EXTERNAL_STORAGE, PERMISSIONS_READ_EXTERNAL_STORAGE_DEVICE_RINGTONE); checkAndRequestPermission(Manifest.permission.READ_EXTERNAL_STORAGE, PERMISSIONS_READ_EXTERNAL_STORAGE_DEVICE_RINGTONE);
} }
public void checkAndRequestPermissionsToSendImage() { public void checkAndRequestPermissionsToSendImage() {
ArrayList<String> permissionsList = new ArrayList<String>(); ArrayList<String> permissionsList = new ArrayList<String>();
int readExternalStorage = getPackageManager().checkPermission(Manifest.permission.READ_EXTERNAL_STORAGE, getPackageName()); int readExternalStorage = getPackageManager().checkPermission(Manifest.permission.READ_EXTERNAL_STORAGE, getPackageName());
Log.i("[Permission] Read external storage permission is " + (readExternalStorage == PackageManager.PERMISSION_GRANTED ? "granted" : "denied")); Log.i("[Permission] Read external storage permission is " + (readExternalStorage == PackageManager.PERMISSION_GRANTED ? "granted" : "denied"));
int camera = getPackageManager().checkPermission(Manifest.permission.CAMERA, getPackageName()); int camera = getPackageManager().checkPermission(Manifest.permission.CAMERA, getPackageName());
Log.i("[Permission] Camera permission is " + (camera == PackageManager.PERMISSION_GRANTED ? "granted" : "denied")); Log.i("[Permission] Camera permission is " + (camera == PackageManager.PERMISSION_GRANTED ? "granted" : "denied"));
if (readExternalStorage != PackageManager.PERMISSION_GRANTED) { if (readExternalStorage != PackageManager.PERMISSION_GRANTED) {
if (LinphonePreferences.instance().firstTimeAskingForPermission(Manifest.permission.READ_EXTERNAL_STORAGE) || ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_EXTERNAL_STORAGE)) { if (LinphonePreferences.instance().firstTimeAskingForPermission(Manifest.permission.READ_EXTERNAL_STORAGE) || ActivityCompat.shouldShowRequestPermissionRationale(this, Manifest.permission.READ_EXTERNAL_STORAGE)) {
Log.i("[Permission] Asking for read external storage"); Log.i("[Permission] Asking for read external storage");
@ -1209,7 +1221,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
ActivityCompat.requestPermissions(this, permissions, 0); ActivityCompat.requestPermissions(this, permissions, 0);
} }
} }
private void checkSyncPermission() { private void checkSyncPermission() {
checkAndRequestPermission(Manifest.permission.WRITE_SYNC_SETTINGS, PERMISSIONS_REQUEST_SYNC); checkAndRequestPermission(Manifest.permission.WRITE_SYNC_SETTINGS, PERMISSIONS_REQUEST_SYNC);
} }
@ -1217,7 +1229,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
public void checkAndRequestPermission(String permission, int result) { public void checkAndRequestPermission(String permission, int result) {
int permissionGranted = getPackageManager().checkPermission(permission, getPackageName()); int permissionGranted = getPackageManager().checkPermission(permission, getPackageName());
Log.i("[Permission] " + permission + " is " + (permissionGranted == PackageManager.PERMISSION_GRANTED ? "granted" : "denied")); Log.i("[Permission] " + permission + " is " + (permissionGranted == PackageManager.PERMISSION_GRANTED ? "granted" : "denied"));
if (permissionGranted != PackageManager.PERMISSION_GRANTED) { if (permissionGranted != PackageManager.PERMISSION_GRANTED) {
if (LinphonePreferences.instance().firstTimeAskingForPermission(permission) || ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) { if (LinphonePreferences.instance().firstTimeAskingForPermission(permission) || ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) {
Log.i("[Permission] Asking for " + permission); Log.i("[Permission] Asking for " + permission);
@ -1231,7 +1243,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
for (int i = 0; i < permissions.length; i++) { for (int i = 0; i < permissions.length; i++) {
Log.i("[Permission] " + permissions[i] + " is " + (grantResults[i] == PackageManager.PERMISSION_GRANTED ? "granted" : "denied")); Log.i("[Permission] " + permissions[i] + " is " + (grantResults[i] == PackageManager.PERMISSION_GRANTED ? "granted" : "denied"));
} }
switch (requestCode) { switch (requestCode) {
case PERMISSIONS_REQUEST_SYNC: case PERMISSIONS_REQUEST_SYNC:
if (grantResults[0] == PackageManager.PERMISSION_GRANTED) { if (grantResults[0] == PackageManager.PERMISSION_GRANTED) {
@ -1259,14 +1271,14 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
break; break;
} }
} }
@Override @Override
protected void onStart() { protected void onStart() {
super.onStart(); super.onStart();
int contacts = getPackageManager().checkPermission(Manifest.permission.READ_CONTACTS, getPackageName()); int contacts = getPackageManager().checkPermission(Manifest.permission.READ_CONTACTS, getPackageName());
Log.i("[Permission] Contacts permission is " + (contacts == PackageManager.PERMISSION_GRANTED ? "granted" : "denied")); Log.i("[Permission] Contacts permission is " + (contacts == PackageManager.PERMISSION_GRANTED ? "granted" : "denied"));
if (contacts == PackageManager.PERMISSION_GRANTED && !fetchedContactsOnce) { if (contacts == PackageManager.PERMISSION_GRANTED && !fetchedContactsOnce) {
ContactsManager.getInstance().enableContactsAccess(); ContactsManager.getInstance().enableContactsAccess();
ContactsManager.getInstance().fetchContactsAsync(); ContactsManager.getInstance().fetchContactsAsync();
@ -1278,7 +1290,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
checkAndRequestReadContactsPermission(); checkAndRequestReadContactsPermission();
} }
} }
@Override @Override
protected void onSaveInstanceState(Bundle outState) { protected void onSaveInstanceState(Bundle outState) {
outState.putSerializable("currentFragment", currentFragment); outState.putSerializable("currentFragment", currentFragment);
@ -1288,16 +1300,16 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
@Override @Override
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
if (!LinphoneService.isReady()) { if (!LinphoneService.isReady()) {
startService(new Intent(Intent.ACTION_MAIN).setClass(this, LinphoneService.class)); startService(new Intent(Intent.ACTION_MAIN).setClass(this, LinphoneService.class));
} }
LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull(); LinphoneCore lc = LinphoneManager.getLcIfManagerNotDestroyedOrNull();
if (lc != null) { if (lc != null) {
lc.addListener(mListener); lc.addListener(mListener);
} }
if (isTablet()) { if (isTablet()) {
LinearLayout ll = (LinearLayout) findViewById(R.id.fragmentContainer2); LinearLayout ll = (LinearLayout) findViewById(R.id.fragmentContainer2);
if (currentFragment == FragmentsAvailable.DIALER) { if (currentFragment == FragmentsAvailable.DIALER) {
@ -1320,7 +1332,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
if (LinphoneManager.getLc().getCalls().length > 0) { if (LinphoneManager.getLc().getCalls().length > 0) {
LinphoneCall call = LinphoneManager.getLc().getCalls()[0]; LinphoneCall call = LinphoneManager.getLc().getCalls()[0];
LinphoneCall.State callState = call.getState(); LinphoneCall.State callState = call.getState();
if (callState == State.IncomingReceived) { if (callState == State.IncomingReceived) {
startActivity(new Intent(this, CallIncomingActivity.class)); startActivity(new Intent(this, CallIncomingActivity.class));
} else if (callState == State.OutgoingInit || callState == State.OutgoingProgress || callState == State.OutgoingRinging) { } else if (callState == State.OutgoingInit || callState == State.OutgoingProgress || callState == State.OutgoingRinging) {
@ -1366,7 +1378,7 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
@Override @Override
protected void onNewIntent(Intent intent) { protected void onNewIntent(Intent intent) {
super.onNewIntent(intent); super.onNewIntent(intent);
Bundle extras = intent.getExtras(); Bundle extras = intent.getExtras();
if (extras != null && extras.getBoolean("GoToChat", false)) { if (extras != null && extras.getBoolean("GoToChat", false)) {
LinphoneService.instance().removeMessageNotification(); LinphoneService.instance().removeMessageNotification();
@ -1438,8 +1450,9 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
} }
public void initSideMenu() { public void initSideMenu() {
sideMenu = (DrawerLayout) findViewById(R.id.side_menu); sideMenu = (DrawerLayout) findViewById(R.id.side_menu);
sideMenuItems = new String[]{getResources().getString(R.string.menu_assistant),getResources().getString(R.string.menu_settings),getResources().getString(R.string.menu_about)}; sideMenuItems = new String[]{getResources().getString(R.string.menu_assistant),getResources().getString(R.string.menu_settings),getResources().getString(R.string.menu_about),"Inapp"};
sideMenuContent = (RelativeLayout) findViewById(R.id.side_menu_content); sideMenuContent = (RelativeLayout) findViewById(R.id.side_menu_content);
sideMenuItemList = (ListView)findViewById(R.id.item_list); sideMenuItemList = (ListView)findViewById(R.id.item_list);
menu = (ImageView) findViewById(R.id.side_menu_button); menu = (ImageView) findViewById(R.id.side_menu_button);
@ -1448,15 +1461,18 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
sideMenuItemList.setOnItemClickListener(new AdapterView.OnItemClickListener() { sideMenuItemList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override @Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
if(sideMenuItemList.getAdapter().getItem(i).toString().equals(getString(R.string.menu_settings))){ if (sideMenuItemList.getAdapter().getItem(i).toString().equals(getString(R.string.menu_settings))) {
LinphoneActivity.instance().displaySettings(); LinphoneActivity.instance().displaySettings();
} }
if(sideMenuItemList.getAdapter().getItem(i).toString().equals(getString(R.string.menu_about))){ if (sideMenuItemList.getAdapter().getItem(i).toString().equals(getString(R.string.menu_about))) {
LinphoneActivity.instance().displayAbout(); LinphoneActivity.instance().displayAbout();
} }
if(sideMenuItemList.getAdapter().getItem(i).toString().equals(getString(R.string.menu_assistant))){ if (sideMenuItemList.getAdapter().getItem(i).toString().equals(getString(R.string.menu_assistant))) {
LinphoneActivity.instance().displayAssistant(); LinphoneActivity.instance().displayAssistant();
} }
if (sideMenuItemList.getAdapter().getItem(i).toString().equals("Inapp")) {
LinphoneActivity.instance().displayInapp();
}
openOrCloseSideMenu(false); openOrCloseSideMenu(false);
} }
}); });
@ -1538,6 +1554,8 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
} }
} }
public void refreshAccounts(){ public void refreshAccounts(){
if (LinphoneManager.getLc().getProxyConfigList().length > 1) { if (LinphoneManager.getLc().getProxyConfigList().length > 1) {
accountsList.setVisibility(View.VISIBLE); accountsList.setVisibility(View.VISIBLE);
@ -1628,6 +1646,66 @@ public class LinphoneActivity extends Activity implements OnClickListener, Conta
return view; return view;
} }
} }
//Inapp Purchase
private void getTrialAccount() {
if(LinphoneManager.getLc().getDefaultProxyConfig() != null) {
XmlRpcHelper helper = new XmlRpcHelper();
helper.isTrialAccountAsync(new XmlRpcListenerBase() {
@Override
public void onTrialAccountFetched(boolean isTrial) {
if(isTrial){
displayInappDialog();
}
}
}, LinphonePreferences.instance().getAccountUsername(0), LinphonePreferences.instance().getAccountHa1(0));
}
}
private void getExpirationAccount() {
if(LinphoneManager.getLc().getDefaultProxyConfig() != null) {
XmlRpcHelper helper = new XmlRpcHelper();
helper.getAccountExpireAsync(new XmlRpcListenerBase() {
@Override
public void onAccountExpireFetched(String result) {
Log.w("RESULT " + result);
}
}, LinphonePreferences.instance().getAccountUsername(0), LinphonePreferences.instance().getAccountHa1(0));
}
}
public Dialog displayInappDialog(){
final Dialog dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
Drawable d = new ColorDrawable(ContextCompat.getColor(this, R.color.colorC));
d.setAlpha(200);
dialog.setContentView(R.layout.input_dialog);
dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
dialog.getWindow().setBackgroundDrawable(d);
TextView customText = (TextView) dialog.findViewById(R.id.customText);
customText.setText(getString(R.string.error_bad_credentials));
Button retry = (Button) dialog.findViewById(R.id.retry);
Button cancel = (Button) dialog.findViewById(R.id.cancel);
retry.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
}
});
cancel.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
return dialog;
}
} }
interface ContactPicked { interface ContactPicked {

View file

@ -419,7 +419,6 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
friend.edit(); friend.edit();
friend.setFamilyName(lastName); friend.setFamilyName(lastName);
friend.setGivenName(firstName); friend.setGivenName(firstName);
friend.setName(fullName);
for (LinphoneAddress address : friend.getAddresses()) { for (LinphoneAddress address : friend.getAddresses()) {
friend.removeAddress(address); friend.removeAddress(address);
@ -444,17 +443,24 @@ public class LinphoneContact implements Serializable, Comparable<LinphoneContact
friend.addPhoneNumber(noa.getValue()); friend.addPhoneNumber(noa.getValue());
} }
} }
if (friend.getAddress() != null) {
friend.setName(fullName);
}
friend.done(); friend.done();
try { if (friend.getAddress() != null) {
LinphoneManager.getLcIfManagerNotDestroyedOrNull().addFriend(friend); if (lc.findFriendByAddress(friend.getAddress().asString()) == null) {
if (!ContactsManager.getInstance().hasContactsAccess()) { try {
// This refresh is only needed if app has no contacts permission to refresh the list of LinphoneFriends. lc.addFriend(friend);
// Otherwise contacts will be refreshed due to changes in native contact and the handler in ContactsManager if (!ContactsManager.getInstance().hasContactsAccess()) {
ContactsManager.getInstance().fetchContactsAsync(); // This refresh is only needed if app has no contacts permission to refresh the list of LinphoneFriends.
// Otherwise contacts will be refreshed due to changes in native contact and the handler in ContactsManager
ContactsManager.getInstance().fetchContactsAsync();
}
} catch (LinphoneCoreException e) {
Log.e(e);
}
} }
} catch (LinphoneCoreException e) {
Log.e(e);
} }
} }

View file

@ -26,6 +26,8 @@ import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.util.ArrayList; import java.util.ArrayList;
import org.linphone.core.LinphoneAccountCreator;
import org.linphone.core.LinphoneAccountCreatorImpl;
import org.linphone.core.LinphoneAddress; import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneAddress.TransportType; import org.linphone.core.LinphoneAddress.TransportType;
import org.linphone.core.LinphoneAuthInfo; import org.linphone.core.LinphoneAuthInfo;
@ -192,6 +194,11 @@ public class LinphonePreferences {
getLc().addAuthInfo(authInfo); getLc().addAuthInfo(authInfo);
} }
public LinphoneAccountCreator AccountCreator(LinphoneCore lc, String server_url) {
return new LinphoneAccountCreatorImpl(lc, server_url);
}
public static class AccountBuilder { public static class AccountBuilder {
private LinphoneCore lc; private LinphoneCore lc;
private String tempUsername; private String tempUsername;
@ -537,6 +544,12 @@ public class LinphonePreferences {
LinphoneAuthInfo authInfo = getAuthInfo(n); LinphoneAuthInfo authInfo = getAuthInfo(n);
return authInfo == null ? null : authInfo.getPassword(); return authInfo == null ? null : authInfo.getPassword();
} }
public String getAccountHa1(int n) {
LinphoneAuthInfo authInfo = getAuthInfo(n);
return authInfo == null ? null : authInfo.getHa1();
}
public void setAccountDomain(int n, String domain) { public void setAccountDomain(int n, String domain) {
String identity = "sip:" + getAccountUsername(n) + "@" + domain; String identity = "sip:" + getAccountUsername(n) + "@" + domain;
LinphoneAuthInfo old_info = getAuthInfo(n); LinphoneAuthInfo old_info = getAuthInfo(n);

View file

@ -25,6 +25,8 @@ import org.linphone.LinphoneUtils;
import org.linphone.LinphonePreferences.AccountBuilder; import org.linphone.LinphonePreferences.AccountBuilder;
import org.linphone.R; import org.linphone.R;
import org.linphone.StatusFragment; import org.linphone.StatusFragment;
import org.linphone.core.LinphoneAccountCreator;
import org.linphone.core.LinphoneAccountCreatorImpl;
import org.linphone.core.LinphoneAddress; import org.linphone.core.LinphoneAddress;
import org.linphone.core.LinphoneAddress.TransportType; import org.linphone.core.LinphoneAddress.TransportType;
import org.linphone.core.LinphoneCore; import org.linphone.core.LinphoneCore;
@ -112,8 +114,6 @@ private static AssistantActivity instance;
} }
mPrefs = LinphonePreferences.instance(); mPrefs = LinphonePreferences.instance();
status.enableSideMenu(false); status.enableSideMenu(false);
checkAndRequestReadPhoneState();
mListener = new LinphoneCoreListenerBase() { mListener = new LinphoneCoreListenerBase() {
@Override @Override
@ -269,7 +269,7 @@ private static AssistantActivity instance;
if (permissionGranted != PackageManager.PERMISSION_GRANTED) { if (permissionGranted != PackageManager.PERMISSION_GRANTED) {
if (LinphonePreferences.instance().firstTimeAskingForPermission(permission) || ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) { if (LinphonePreferences.instance().firstTimeAskingForPermission(permission) || ActivityCompat.shouldShowRequestPermissionRationale(this, permission)) {
Log.i("[Permission] Asking for " + permission); Log.i("[Permission] Asking for " + permission);
ActivityCompat.requestPermissions(this, new String[] { permission }, result); ActivityCompat.requestPermissions(this, new String[]{permission}, result);
} }
} }
} }
@ -464,7 +464,8 @@ private static AssistantActivity instance;
.setQualityReportingInterval(180) .setQualityReportingInterval(180)
.setRealm("sip.linphone.org") .setRealm("sip.linphone.org")
.setNoDefault(false); .setNoDefault(false);
mPrefs.enabledFriendlistSubscription(getResources().getBoolean(R.bool.use_friendlist_subscription));
mPrefs.setStunServer(getString(R.string.default_stun)); mPrefs.setStunServer(getString(R.string.default_stun));
mPrefs.setIceEnabled(true); mPrefs.setIceEnabled(true);

View file

@ -23,6 +23,8 @@ import java.util.regex.Pattern;
import org.linphone.LinphoneManager; import org.linphone.LinphoneManager;
import org.linphone.R; import org.linphone.R;
import org.linphone.core.LinphoneAccountCreator;
import org.linphone.core.LinphoneAccountCreatorImpl;
import org.linphone.core.LinphoneProxyConfig; import org.linphone.core.LinphoneProxyConfig;
import org.linphone.core.LinphoneXmlRpcRequest; import org.linphone.core.LinphoneXmlRpcRequest;
import org.linphone.core.LinphoneXmlRpcRequest.LinphoneXmlRpcRequestListener; import org.linphone.core.LinphoneXmlRpcRequest.LinphoneXmlRpcRequestListener;
@ -30,6 +32,7 @@ import org.linphone.core.LinphoneXmlRpcRequestImpl;
import org.linphone.core.LinphoneXmlRpcSession; import org.linphone.core.LinphoneXmlRpcSession;
import org.linphone.core.LinphoneXmlRpcSessionImpl; import org.linphone.core.LinphoneXmlRpcSessionImpl;
import org.linphone.xmlrpc.XmlRpcHelper; import org.linphone.xmlrpc.XmlRpcHelper;
import org.linphone.mediastream.Log;
import android.Manifest; import android.Manifest;
import android.accounts.Account; import android.accounts.Account;
@ -54,10 +57,13 @@ import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.TextView; import android.widget.TextView;
import static org.linphone.core.LinphoneAccountCreator.*;
/** /**
* @author Sylvain Berfini * @author Sylvain Berfini
*/ */
public class CreateAccountFragment extends Fragment implements CompoundButton.OnCheckedChangeListener, OnClickListener { public class CreateAccountFragment extends Fragment implements CompoundButton.OnCheckedChangeListener, OnClickListener, LinphoneAccountCreatorListener {
private Handler mHandler = new Handler(); private Handler mHandler = new Handler();
private EditText phoneNumberEdit, usernameEdit, passwordEdit, passwordConfirmEdit, emailEdit, dialCode; private EditText phoneNumberEdit, usernameEdit, passwordEdit, passwordConfirmEdit, emailEdit, dialCode;
private TextView phoneNumberError, usernameError, passwordError, passwordConfirmError, emailError, sipUri; private TextView phoneNumberError, usernameError, passwordError, passwordConfirmError, emailError, sipUri;
@ -73,6 +79,8 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
private final Pattern UPPER_CASE_REGEX = Pattern.compile("[A-Z]"); private final Pattern UPPER_CASE_REGEX = Pattern.compile("[A-Z]");
private LinphoneXmlRpcSession xmlRpcSession; private LinphoneXmlRpcSession xmlRpcSession;
private CountryListFragment.Country country; private CountryListFragment.Country country;
private LinphoneAccountCreator accountCreator;
private String getUsername() { private String getUsername() {
String username = usernameEdit.getText().toString(); String username = usernameEdit.getText().toString();
@ -93,6 +101,9 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.assistant_account_creation, container, false); View view = inflater.inflate(R.layout.assistant_account_creation, container, false);
accountCreator = new LinphoneAccountCreatorImpl(LinphoneManager.getLc(), getResources().getString(R.string.wizard_url));
accountCreator.setListener(this);
phoneNumberError = (TextView) view.findViewById(R.id.phone_number_error); phoneNumberError = (TextView) view.findViewById(R.id.phone_number_error);
phoneNumberEdit = (EditText) view.findViewById(R.id.phone_number); phoneNumberEdit = (EditText) view.findViewById(R.id.phone_number);
phoneNumberEdit.addTextChangedListener(new TextWatcher() { phoneNumberEdit.addTextChangedListener(new TextWatcher() {
@ -107,7 +118,7 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
public void afterTextChanged(Editable s) {} public void afterTextChanged(Editable s) {}
}); });
phoneNumberLayout = (LinearLayout) view.findViewById(R.id.phone_number_layout); phoneNumberLayout = (LinearLayout) view.findViewById(R.id.phone_number_layout);
addXMLRPCPhoneNumberHandler(phoneNumberEdit, null); addPhoneNumberHandler(phoneNumberEdit, null);
selectCountry = (Button) view.findViewById(R.id.select_country); selectCountry = (Button) view.findViewById(R.id.select_country);
selectCountry.setOnClickListener(this); selectCountry.setOnClickListener(this);
@ -144,7 +155,7 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
public void afterTextChanged(Editable s) {} public void afterTextChanged(Editable s) {}
}); });
usernameLayout = (LinearLayout) view.findViewById(R.id.username_layout); usernameLayout = (LinearLayout) view.findViewById(R.id.username_layout);
addXMLRPCUsernameHandler(usernameEdit, null); addUsernameHandler(usernameEdit, null);
} }
if(getResources().getBoolean(R.bool.isTablet)){ if(getResources().getBoolean(R.bool.isTablet)){
@ -331,60 +342,6 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
xmlRpcRequest.addStringArg(username); xmlRpcRequest.addStringArg(username);
xmlRpcSession.sendRequest(xmlRpcRequest); xmlRpcSession.sendRequest(xmlRpcRequest);
} }
private void isPhoneNumberRegistred(final String username, final ImageView icon) {
final Runnable runOk = new Runnable() {
public void run() {
phoneNumberOk = false;
displayError(phoneNumberOk, phoneNumberError, phoneNumberEdit, LinphoneManager.getInstance().getContext().getString(R.string.assistant_phone_number_unavailable));
//createAccount.setEnabled(phoneNumberOk);
}
};
final Runnable runNotOk = new Runnable() {
public void run() {
phoneNumberOk = true;
displayError(phoneNumberOk, phoneNumberError, phoneNumberEdit, "");
createAccount.setEnabled(phoneNumberOk);
}
};
final Runnable runNotReachable = new Runnable() {
public void run() {
phoneNumberOk = false;
displayError(phoneNumberOk, phoneNumberError, phoneNumberEdit, LinphoneManager.getInstance().getContext().getString(R.string.wizard_server_unavailable));
createAccount.setEnabled(phoneNumberOk);
}
};
LinphoneXmlRpcRequest xmlRpcRequest = new LinphoneXmlRpcRequestImpl("is_phone_number_used", LinphoneXmlRpcRequest.ArgType.String);
xmlRpcRequest.setListener(new LinphoneXmlRpcRequestListener() {
@Override
public void onXmlRpcRequestResponse(LinphoneXmlRpcRequest request) {
if (request.getStatus() == LinphoneXmlRpcRequest.Status.Ok) {
final String response = request.getStringResponse();
if (response.equals(XmlRpcHelper.SERVER_RESPONSE_OK)) {
mHandler.post(runOk);
} else {
if(response.startsWith("ERROR")){
mHandler.post(new Runnable() {
@Override
public void run() {
phoneNumberOk = false;
displayError(phoneNumberOk, phoneNumberError, phoneNumberEdit, response);
//createAccount.setEnabled(phoneNumberOk);
}
});
} else {
mHandler.post(runNotOk);
}
}
} else if (request.getStatus() == LinphoneXmlRpcRequest.Status.Failed) {
mHandler.post(runNotReachable);
}
}
});
xmlRpcRequest.addStringArg(username);
xmlRpcSession.sendRequest(xmlRpcRequest);
}
private boolean isEmailCorrect(String email) { private boolean isEmailCorrect(String email) {
Pattern emailPattern = Patterns.EMAIL_ADDRESS; Pattern emailPattern = Patterns.EMAIL_ADDRESS;
@ -477,29 +434,36 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
xmlRpcSession.sendRequest(xmlRpcRequest); xmlRpcSession.sendRequest(xmlRpcRequest);
} }
private void addXMLRPCPhoneNumberHandler(final EditText field, final ImageView icon) { private void addPhoneNumberHandler(final EditText field, final ImageView icon) {
field.addTextChangedListener(new TextWatcher() { field.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
if (s.length() > 0) { if (s.length() > 0) {
phoneNumberOk = false; phoneNumberOk = false;
String phoneNumber = getPhoneNumber(); String phoneNumber = getPhoneNumber();
if (LinphoneManager.getLc().createProxyConfig().isPhoneNumber(phoneNumber)) { String countryCode = dialCode.getText().toString();
isPhoneNumberRegistred(phoneNumber, icon); if(countryCode != null && countryCode.startsWith("+")) {
countryCode = countryCode.substring(1);
}
Status status = accountCreator.setPhoneNumber(phoneNumberEdit.getText().toString(), countryCode);
if(status.equals(Status.Ok)){
accountCreator.isAccountUsed();
} else { } else {
displayError(phoneNumberOk, phoneNumberError, phoneNumberEdit, getResources().getString(R.string.wizard_username_incorrect)); displayError(phoneNumberOk, phoneNumberError, phoneNumberEdit, errorForStatus(status));
} }
} else { } else {
displayError(phoneNumberOk, phoneNumberError, phoneNumberEdit, ""); displayError(phoneNumberOk, phoneNumberError, phoneNumberEdit, "");
} }
} }
public void beforeTextChanged(CharSequence s, int start, int count, int after) {} public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int count, int after) {} public void onTextChanged(CharSequence s, int start, int count, int after) {
}
}); });
} }
private void addXMLRPCUsernameHandler(final EditText field, final ImageView icon) { private void addUsernameHandler(final EditText field, final ImageView icon) {
field.addTextChangedListener(new TextWatcher() { field.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
Matcher matcher = UPPER_CASE_REGEX.matcher(s); Matcher matcher = UPPER_CASE_REGEX.matcher(s);
@ -510,30 +474,22 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
} }
public void beforeTextChanged(CharSequence s, int start, int count, int after) { public void beforeTextChanged(CharSequence s, int start, int count, int after) {
} }
public void onTextChanged(CharSequence s, int start, int count, int after) { public void onTextChanged(CharSequence s, int start, int count, int after) {
field.setOnFocusChangeListener(new View.OnFocusChangeListener() { if(s.length() > 0){
@Override usernameOk = false;
public void onFocusChange(View v, boolean hasFocus) { Status status = accountCreator.setUsername(field.getText().toString());
if (!hasFocus) { if(status.equals(Status.Ok)){
usernameOk = false; accountCreator.setPhoneNumber(null,null);
String username = field.getText().toString(); accountCreator.isAccountUsed();
if (isUsernameCorrect(username)) { } else {
if (getResources().getBoolean(R.bool.allow_only_phone_numbers_in_wizard)) { displayError(usernameOk, usernameError, usernameEdit, errorForStatus(status));
LinphoneProxyConfig lpc = LinphoneManager.getLc().createProxyConfig();
username = lpc.normalizePhoneNumber(username);
}
isUsernameRegistred(username, icon);
} else {
displayError(usernameOk, usernameError, usernameEdit, getResources().getString(R.string.wizard_username_incorrect));
}
} else {
displayError(true, usernameError, usernameEdit, "");
}
} }
}); } else {
displayError(true, usernameError, usernameEdit, "");
}
} }
}); });
} }
@ -631,4 +587,96 @@ public class CreateAccountFragment extends Fragment implements CompoundButton.On
field1.addTextChangedListener(passwordListener); field1.addTextChangedListener(passwordListener);
field2.addTextChangedListener(passwordListener); field2.addTextChangedListener(passwordListener);
} }
String errorForStatus(Status status) {
boolean isPhoneNumber = (phoneNumberEdit.getText().length() > 0);
if (status.equals(Status.EmailInvalid))
return getString(R.string.invalid_email);
if (status.equals(Status.UsernameInvalid)){
return getString(R.string.invalid_username);
}
if (status.equals(Status.UsernameTooShort)){
return getString(R.string.username_too_short);
}
if (status.equals(Status.UsernameTooLong)){
return getString(R.string.username_too_long);
}
if (status.equals(Status.UsernameInvalidSize))
return getString(R.string.username_invalid_size);
if (status.equals(Status.PhoneNumberTooShort))
return getString(R.string.phone_number_too_short);
if (status.equals(Status.PhoneNumberTooLong))
return getString(R.string.phone_number_too_long);
if (status.equals(Status.PhoneNumberInvalid))
return getString(R.string.phone_number_invalid);
if (status.equals(Status.PasswordTooShort))
return getString(R.string.username_too_short);
if (status.equals(Status.PasswordTooLong))
return getString(R.string.username_too_long);
if (status.equals(Status.DomainInvalid))
return getString(R.string.invalid_domain);
if (status.equals(Status.RouteInvalid))
return getString(R.string.invalid_route);
if (status.equals(Status.DisplayNameInvalid))
return getString(R.string.invalid_route);
if (status.equals(Status.Failed))
return getString(R.string.request_failed);
if (status.equals(Status.TransportNotSupported))
return getString(R.string.transport_unsupported);
if (status.equals(Status.AccountExist))
return getString(R.string.account_already_exist);
if (status.equals(Status.AccountCreated)
|| status.equals(Status.AccountNotCreated)
|| status.equals(Status.AccountNotExist)
|| status.equals(Status.AccountNotActivated)
|| status.equals(Status.AccountAlreadyActivated)
|| status.equals(Status.AccountActivated)
|| status.equals(Status.Ok)){
return "";
}
return null;
}
@Override
public void onAccountCreatorIsAccountUsed(LinphoneAccountCreator accountCreator, final Status status) {
if(useUsername.isChecked()){
if (status.equals(Status.AccountNotExist)) {
usernameOk = true;
displayError(usernameOk, usernameError, usernameEdit, errorForStatus(status));
} else {
usernameOk = false;
displayError(usernameOk, usernameError, usernameEdit, errorForStatus(status));
}
createAccount.setEnabled(usernameOk && phoneNumberOk);
} else {
if (status.equals(Status.AccountNotExist)) {
phoneNumberOk = true;
displayError(phoneNumberOk, phoneNumberError, phoneNumberEdit, errorForStatus(status));
} else {
phoneNumberOk = true;
displayError(phoneNumberOk, phoneNumberError, phoneNumberEdit, errorForStatus(status));
}
createAccount.setEnabled(phoneNumberOk);
}
}
@Override
public void onAccountCreatorAccountCreated(LinphoneAccountCreator accountCreator, Status status) {
}
@Override
public void onAccountCreatorAccountActivated(LinphoneAccountCreator accountCreator, Status status) {
}
@Override
public void onAccountCreatorAccountLinkedWithPhoneNumber(LinphoneAccountCreator accountCreator, Status status) {
}
@Override
public void onAccountCreatorPhoneNumberLinkActivated(LinphoneAccountCreator accountCreator, Status status) {
}
@Override
public void onAccountCreatorIsAccountActivated(LinphoneAccountCreator accountCreator, Status status) {
}
} }

View file

@ -19,92 +19,141 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Locale; import java.util.List;
import org.linphone.LinphoneManager; import org.linphone.LinphonePreferences;
import org.linphone.R; import org.linphone.R;
import org.linphone.core.LinphoneProxyConfig;
import org.linphone.mediastream.Log; import org.linphone.mediastream.Log;
import org.linphone.xmlrpc.XmlRpcHelper; import org.linphone.xmlrpc.XmlRpcHelper;
import org.linphone.xmlrpc.XmlRpcListenerBase; import org.linphone.xmlrpc.XmlRpcListenerBase;
import android.app.Activity; import android.app.Activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.View.OnClickListener; import android.view.View.OnClickListener;
import android.widget.Button; import android.widget.ImageView;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
/** /**
* @author Sylvain Berfini * @author Sylvain Berfini
*/ */
public class InAppPurchaseActivity extends Activity implements InAppPurchaseListener, OnClickListener { public class InAppPurchaseActivity extends Activity implements InAppPurchaseListener, OnClickListener {
private static InAppPurchaseActivity instance;
private InAppPurchaseHelper inAppPurchaseHelper; private InAppPurchaseHelper inAppPurchaseHelper;
private LinearLayout purchasableItemsLayout; private ImageView cancel, back;
private ArrayList<Purchasable> purchasedItems;
private Button buyItemButton, recoverAccountButton; private List<Purchasable> purchasedItems;
private Fragment fragment;
private Handler mHandler = new Handler(); private Handler mHandler = new Handler();
private EditText username, email;
private TextView errorMessage;
private boolean usernameOk = false;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
inAppPurchaseHelper = new InAppPurchaseHelper(this, this); inAppPurchaseHelper = new InAppPurchaseHelper(this, this);
setContentView(R.layout.in_app);
setContentView(R.layout.in_app_store);
purchasableItemsLayout = (LinearLayout) findViewById(R.id.purchasable_items); back = (ImageView) findViewById(R.id.back);
back.setOnClickListener(this);
username = (EditText) findViewById(R.id.username); back.setVisibility(View.INVISIBLE);
email = (EditText) findViewById(R.id.email); cancel = (ImageView) findViewById(R.id.cancel);
errorMessage = (TextView) findViewById(R.id.username_error); cancel.setOnClickListener(this);
addUsernameHandler(username, errorMessage);
instance = this;
} }
private void changeFragment(Fragment newFragment) {
FragmentTransaction transaction = getFragmentManager().beginTransaction();
transaction.replace(R.id.fragment_container, newFragment);
transaction.commitAllowingStateLoss();
}
public void displayInappList() {
fragment = new InAppPurchaseListFragment();
changeFragment(fragment);
}
public void displayStore(Purchasable item) {
Bundle extra = new Bundle();
extra.putString("item_id",item.getId());
fragment = new InAppPurchaseFragment();
fragment.setArguments(extra);
changeFragment(fragment);
}
public void buyInapp(String username, Purchasable item){
LinphonePreferences.instance().setInAppPurchasedItem(item);
inAppPurchaseHelper.purchaseItemAsync(item.getId(), username);
}
public String getGmailAccount() {
return inAppPurchaseHelper.getGmailAccount();
}
@Override @Override
protected void onDestroy() { protected void onDestroy() {
instance = null;
inAppPurchaseHelper.destroy(); inAppPurchaseHelper.destroy();
super.onDestroy(); super.onDestroy();
} }
public List<Purchasable> getPurchasedItems() {
if (purchasedItems == null || purchasedItems.size() == 0) {
Log.w("nul");
}
return purchasedItems;
}
public Purchasable getPurchasedItem(String id) {
for(Purchasable item : purchasedItems){
if (item.getId().equals(id)){
return item;
}
}
return null;
}
public static InAppPurchaseActivity instance() {
return instance;
}
@Override @Override
public void onServiceAvailableForQueries() { public void onServiceAvailableForQueries() {
email.setText(inAppPurchaseHelper.getGmailAccount()); //email.setText(inAppPurchaseHelper.getGmailAccount());
email.setEnabled(false); //email.setEnabled(false);
inAppPurchaseHelper.getPurchasedItemsAsync(); //inAppPurchaseHelper.getPurchasedItemsAsync();
inAppPurchaseHelper.getAvailableItemsForPurchaseAsync();
} }
@Override @Override
public void onAvailableItemsForPurchaseQueryFinished(ArrayList<Purchasable> items) { public void onAvailableItemsForPurchaseQueryFinished(ArrayList<Purchasable> items) {
purchasableItemsLayout.removeAllViews(); //purchasableItemsLayout.removeAllViews();
purchasedItems = new ArrayList<Purchasable>();
for (Purchasable item : items) { for (Purchasable item : items) {
displayBuySubscriptionButton(item); purchasedItems.add(item);
} }
displayInappList();
} }
@Override @Override
public void onPurchasedItemsQueryFinished(ArrayList<Purchasable> items) { public void onPurchasedItemsQueryFinished(ArrayList<Purchasable> items) {
purchasedItems = items; purchasedItems = items;
if (items == null || items.size() == 0) { if (items == null || items.size() == 0) {
inAppPurchaseHelper.getAvailableItemsForPurchaseAsync(); inAppPurchaseHelper.getAvailableItemsForPurchaseAsync();
} else { } else {
for (Purchasable purchasedItem : purchasedItems) { for (Purchasable purchasedItem : purchasedItems) {
Log.d("[In-app purchase] Found already bought item, expires " + purchasedItem.getExpireDate()); Log.d("[In-app purchase] Found already bought item, expires " + purchasedItem.getExpireDate());
displayRecoverAccountButton(purchasedItem); //displayRecoverAccountButton(purchasedItem);
} }
} }
} }
@ -113,28 +162,26 @@ public class InAppPurchaseActivity extends Activity implements InAppPurchaseList
public void onPurchasedItemConfirmationQueryFinished(boolean success) { public void onPurchasedItemConfirmationQueryFinished(boolean success) {
if (success) { if (success) {
XmlRpcHelper xmlRpcHelper = new XmlRpcHelper(); XmlRpcHelper xmlRpcHelper = new XmlRpcHelper();
xmlRpcHelper.createAccountAsync(new XmlRpcListenerBase() {
Purchasable item = LinphonePreferences.instance().getInAppPurchasedItem();
xmlRpcHelper.updateAccountExpireAsync(new XmlRpcListenerBase() {
@Override @Override
public void onAccountCreated(String result) { public void onAccountExpireUpdated(String result) {
//TODO //TODO
} }
}, getUsername(), email.getText().toString(), null); }, LinphonePreferences.instance().getAccountUsername(0), LinphonePreferences.instance().getAccountHa1(0), getString(R.string.default_domain), item.getPayload(), item.getPayloadSignature());
} }
} }
@Override @Override
public void onClick(View v) { public void onClick(View v) {
Purchasable item = (Purchasable) v.getTag(); int id = v.getId();
if (v.equals(recoverAccountButton)) {
XmlRpcHelper xmlRpcHelper = new XmlRpcHelper(); if (id == R.id.cancel) {
xmlRpcHelper.createAccountAsync(new XmlRpcListenerBase() { finish();
@Override } else if (id == R.id.back) {
public void onAccountCreated(String result) { onBackPressed();
//TODO
}
}, getUsername(), email.getText().toString(), null);
} else {
inAppPurchaseHelper.purchaseItemAsync(item.getId(), getUsername());
} }
} }
@ -145,12 +192,6 @@ public class InAppPurchaseActivity extends Activity implements InAppPurchaseList
@Override @Override
public void onRecoverAccountSuccessful(boolean success) { public void onRecoverAccountSuccessful(boolean success) {
mHandler.post(new Runnable() {
@Override
public void run() {
recoverAccountButton.setEnabled(false);
}
});
} }
@Override @Override
@ -170,70 +211,4 @@ public class InAppPurchaseActivity extends Activity implements InAppPurchaseList
Log.d("[In-app purchase] Account activated"); Log.d("[In-app purchase] Account activated");
} }
} }
private void displayBuySubscriptionButton(Purchasable item) {
View layout = LayoutInflater.from(this).inflate(R.layout.in_app_purchasable, purchasableItemsLayout);
Button button = (Button) layout.findViewById(R.id.inapp_button);
button.setText("Buy account (" + item.getPrice() + ")");
button.setTag(item);
button.setOnClickListener(this);
XmlRpcHelper xmlRpcHelper = new XmlRpcHelper();
xmlRpcHelper.createAccountAsync(new XmlRpcListenerBase() {
@Override
public void onAccountCreated(String result) {
//TODO
}
}, getUsername(), email.getText().toString(), null);
buyItemButton = button;
buyItemButton.setEnabled(usernameOk);
}
private void displayRecoverAccountButton(Purchasable item) {
View layout = LayoutInflater.from(this).inflate(R.layout.in_app_purchasable, purchasableItemsLayout);
Button button = (Button) layout.findViewById(R.id.inapp_button);
button.setText("Recover account");
button.setTag(item);
button.setOnClickListener(this);
recoverAccountButton = button;
recoverAccountButton.setEnabled(usernameOk);
}
private String getUsername() {
String username = this.username.getText().toString();
LinphoneProxyConfig lpc = LinphoneManager.getLc().createProxyConfig();
username = lpc.normalizePhoneNumber(username);
return username.toLowerCase(Locale.getDefault());
}
private boolean isUsernameCorrect(String username) {
LinphoneProxyConfig lpc = LinphoneManager.getLc().createProxyConfig();
return lpc.isPhoneNumber(username);
}
private void addUsernameHandler(final EditText field, final TextView errorMessage) {
field.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int count, int after) {
usernameOk = false;
String username = s.toString();
if (isUsernameCorrect(username)) {
usernameOk = true;
errorMessage.setText("");
} else {
errorMessage.setText(R.string.wizard_username_incorrect);
}
if (buyItemButton != null) buyItemButton.setEnabled(usernameOk);
if (recoverAccountButton != null) recoverAccountButton.setEnabled(usernameOk);
}
});
}
} }

View file

@ -0,0 +1,150 @@
package org.linphone.purchase;
/*
InAppPurchaseFragment.java
Copyright (C) 2016 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import android.app.Fragment;
import android.os.Bundle;
import android.os.Handler;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import org.linphone.LinphoneManager;
import org.linphone.LinphonePreferences;
import org.linphone.R;
import org.linphone.mediastream.Log;
import org.linphone.core.LinphoneProxyConfig;
import org.linphone.xmlrpc.XmlRpcHelper;
import org.linphone.xmlrpc.XmlRpcListenerBase;
import java.util.Locale;
public class InAppPurchaseFragment extends Fragment implements View.OnClickListener {
private EditText username, email;
private TextView errorMessage;
private boolean usernameOk = false;
private Handler mHandler = new Handler();
private Button buyItemButton, recoverAccountButton;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LayoutInflater mInflater = inflater;
View view = inflater.inflate(R.layout.in_app_store, container, false);
String id = getArguments().getString("item_id");
Purchasable item = InAppPurchaseActivity.instance().getPurchasedItem(id);
Log.w("Item store " + item.getDescription());
buyItemButton = (Button) view.findViewById(R.id.inapp_button);
displayBuySubscriptionButton(item);
username = (EditText) view.findViewById(R.id.username);
username.setText(LinphonePreferences.instance().getAccountUsername(0));
email = (EditText) view.findViewById(R.id.email);
email.setText(InAppPurchaseActivity.instance().getGmailAccount());
errorMessage = (TextView) view.findViewById(R.id.username_error);
addUsernameHandler(username, errorMessage);
return view;
}
private void addUsernameHandler(final EditText field, final TextView errorMessage) {
field.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable s) {
}
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
public void onTextChanged(CharSequence s, int start, int count, int after) {
usernameOk = false;
String username = s.toString();
if (isUsernameCorrect(username)) {
usernameOk = true;
errorMessage.setText("");
} else {
errorMessage.setText(R.string.wizard_username_incorrect);
}
if (buyItemButton != null) buyItemButton.setEnabled(usernameOk);
if (recoverAccountButton != null) recoverAccountButton.setEnabled(usernameOk);
}
});
}
private boolean isUsernameCorrect(String username) {
LinphoneProxyConfig lpc = LinphoneManager.getLc().createProxyConfig();
return lpc.isPhoneNumber(username);
}
private void displayBuySubscriptionButton(Purchasable item) {
//View layout = LayoutInflater.from(this).inflate(R.layout.in_app_purchasable, purchasableItemsLayout);
//Button button = (Button) layout.findViewById(R.id.inapp_button);
buyItemButton.setText("Buy account (" + item.getPrice() + ")");
buyItemButton.setTag(item);
buyItemButton.setOnClickListener(this);
/*XmlRpcHelper xmlRpcHelper = new XmlRpcHelper();
xmlRpcHelper.createAccountAsync(new XmlRpcListenerBase() {
@Override
public void onAccountCreated(String result) {
//TODO
}
}, getUsername(), email.getText().toString(), null);*/
buyItemButton.setEnabled(usernameOk);
}
@Override
public void onClick(View v) {
Purchasable item = (Purchasable) v.getTag();
if (v.equals(recoverAccountButton)) {
//XmlRpcHelper xmlRpcHelper = new XmlRpcHelper();
/*xmlRpcHelper.createAccountAsync(new XmlRpcListenerBase() {
@Override
public void onAccountCreated(String result) {
//TODO
}
}, getUsername(), email.getText().toString(), null);*/
} else {
InAppPurchaseActivity.instance().buyInapp(getUsername(), item);
}
}
private String getUsername() {
String username = this.username.getText().toString();
LinphoneProxyConfig lpc = LinphoneManager.getLc().createProxyConfig();
username = lpc.normalizePhoneNumber(username);
return username.toLowerCase(Locale.getDefault());
}
}

View file

@ -126,15 +126,20 @@ public class InAppPurchaseHelper {
mContext = context; mContext = context;
mListener = listener; mListener = listener;
mGmailAccount = getGmailAccount(); mGmailAccount = getGmailAccount();
Log.d("[In-app purchase] creating InAppPurchaseHelper for context "+context.getLocalClassName());
mServiceConn = new ServiceConnection() { mServiceConn = new ServiceConnection() {
@Override @Override
public void onServiceDisconnected(ComponentName name) { public void onServiceDisconnected(ComponentName name) {
Log.d("[In-app purchase] onServiceDisconnected!");
mService = null; mService = null;
} }
@Override @Override
public void onServiceConnected(ComponentName name, IBinder service) { public void onServiceConnected(ComponentName name, IBinder service) {
Log.d("[In-app purchase] onServiceConnected!");
mService = IInAppBillingService.Stub.asInterface(service); mService = IInAppBillingService.Stub.asInterface(service);
String packageName = mContext.getPackageName(); String packageName = mContext.getPackageName();
try { try {
@ -150,7 +155,7 @@ public class InAppPurchaseHelper {
} }
} }
}; };
Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND"); Intent serviceIntent = new Intent("com.android.vending.billing.InAppBillingService.BIND");
serviceIntent.setPackage("com.android.vending"); serviceIntent.setPackage("com.android.vending");
if (!mContext.getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty()) { if (!mContext.getPackageManager().queryIntentServices(serviceIntent, 0).isEmpty()) {
@ -177,7 +182,7 @@ public class InAppPurchaseHelper {
} catch (RemoteException e) { } catch (RemoteException e) {
Log.e(e); Log.e(e);
} }
if (skuDetails != null) { if (skuDetails != null) {
int response = skuDetails.getInt(RESPONSE_CODE); int response = skuDetails.getInt(RESPONSE_CODE);
if (response == RESPONSE_RESULT_OK) { if (response == RESPONSE_RESULT_OK) {
@ -191,6 +196,7 @@ public class InAppPurchaseHelper {
String desc = object.getString(SKU_DETAILS_DESC); String desc = object.getString(SKU_DETAILS_DESC);
Purchasable purchasable = new Purchasable(id).setTitle(title).setDescription(desc).setPrice(price); Purchasable purchasable = new Purchasable(id).setTitle(title).setDescription(desc).setPrice(price);
Log.w("Purchasable item " + purchasable.getDescription());
products.add(purchasable); products.add(purchasable);
} catch (JSONException e) { } catch (JSONException e) {
Log.e(e); Log.e(e);
@ -276,6 +282,10 @@ public class InAppPurchaseHelper {
if (resultCode == Activity.RESULT_OK && responseCode == RESPONSE_RESULT_OK) { if (resultCode == Activity.RESULT_OK && responseCode == RESPONSE_RESULT_OK) {
String payload = data.getStringExtra(RESPONSE_INAPP_PURCHASE_DATA); String payload = data.getStringExtra(RESPONSE_INAPP_PURCHASE_DATA);
String signature = data.getStringExtra(RESPONSE_INAPP_SIGNATURE); String signature = data.getStringExtra(RESPONSE_INAPP_SIGNATURE);
Purchasable item = LinphonePreferences.instance().getInAppPurchasedItem();
item.setPayloadAndSignature(payload, signature);
LinphonePreferences.instance().setInAppPurchasedItem(item);
XmlRpcHelper xmlRpcHelper = new XmlRpcHelper(); XmlRpcHelper xmlRpcHelper = new XmlRpcHelper();
xmlRpcHelper.verifySignatureAsync(new XmlRpcListenerBase() { xmlRpcHelper.verifySignatureAsync(new XmlRpcListenerBase() {

View file

@ -0,0 +1,100 @@
package org.linphone.purchase;
/*
InAppPurchaseListFragment.java
Copyright (C) 2016 Belledonne Communications, Grenoble, France
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
import android.widget.AdapterView;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ListView;
import android.widget.TextView;
import org.linphone.R;
import org.linphone.mediastream.Log;
import java.util.List;
public class InAppPurchaseListFragment extends Fragment implements AdapterView.OnItemClickListener{
private ListView inappList;
private LayoutInflater mInflater;
private List<Purchasable> mPurchasableItems;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
mInflater = inflater;
View view = inflater.inflate(R.layout.in_app_list, container, false);
mPurchasableItems = InAppPurchaseActivity.instance().getPurchasedItems();
inappList = (ListView) view.findViewById(R.id.inapp_list);
if(mPurchasableItems != null){
inappList.setAdapter(new InAppListAdapter());
inappList.setOnItemClickListener(this);
}
return view;
}
class InAppListAdapter extends BaseAdapter {
InAppListAdapter() {}
public int getCount() {
return mPurchasableItems.size();
}
public Object getItem(int position) {
return mPurchasableItems.get(position);
}
public long getItemId(int position) {
return position;
}
public View getView(final int position, View convertView, ViewGroup parent) {
View view = null;
if (convertView != null) {
view = convertView;
} else {
view = mInflater.inflate(R.layout.in_app_purchase_item, parent, false);
}
final Purchasable item = mPurchasableItems.get(position);
TextView itemTitle = (TextView) view.findViewById(R.id.purchase_title);
TextView itemDesc = (TextView) view.findViewById(R.id.purchase_description);
TextView itemPrice = (TextView) view.findViewById(R.id.purchase_price);
itemTitle.setText(item.getTitle());
itemDesc.setText(item.getDescription());
itemPrice.setText(item.getPrice());
view.setTag(item);
return view;
}
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Purchasable item = (Purchasable) view.getTag();
InAppPurchaseActivity.instance().displayStore(item);
}
}

View file

@ -56,7 +56,7 @@ public class XmlRpcHelper {
} }
public void getAccountExpireAsync(final XmlRpcListener listener, String username, String password) { public void getAccountExpireAsync(final XmlRpcListener listener, String username, String password) {
LinphoneXmlRpcRequest xmlRpcRequest = new LinphoneXmlRpcRequestImpl("get_expiration_for_account", LinphoneXmlRpcRequest.ArgType.String); LinphoneXmlRpcRequest xmlRpcRequest = new LinphoneXmlRpcRequestImpl("get_account_expiration", LinphoneXmlRpcRequest.ArgType.String);
xmlRpcRequest.setListener(new LinphoneXmlRpcRequestListener() { xmlRpcRequest.setListener(new LinphoneXmlRpcRequestListener() {
@Override @Override
public void onXmlRpcRequestResponse(LinphoneXmlRpcRequest request) { public void onXmlRpcRequestResponse(LinphoneXmlRpcRequest request) {
@ -79,7 +79,7 @@ public class XmlRpcHelper {
xmlRpcSession.sendRequest(xmlRpcRequest); xmlRpcSession.sendRequest(xmlRpcRequest);
} }
public void updateAccountExpireAsync(final XmlRpcListener listener, String username, String password, String payload, String signature) { public void updateAccountExpireAsync(final XmlRpcListener listener, String username, String password, String domain, String payload, String signature) {
LinphoneXmlRpcRequest xmlRpcRequest = new LinphoneXmlRpcRequestImpl("update_expiration_date", LinphoneXmlRpcRequest.ArgType.String); LinphoneXmlRpcRequest xmlRpcRequest = new LinphoneXmlRpcRequestImpl("update_expiration_date", LinphoneXmlRpcRequest.ArgType.String);
xmlRpcRequest.setListener(new LinphoneXmlRpcRequestListener() { xmlRpcRequest.setListener(new LinphoneXmlRpcRequestListener() {
@Override @Override
@ -100,6 +100,7 @@ public class XmlRpcHelper {
}); });
xmlRpcRequest.addStringArg(username); xmlRpcRequest.addStringArg(username);
xmlRpcRequest.addStringArg(password); xmlRpcRequest.addStringArg(password);
xmlRpcRequest.addStringArg(domain);
xmlRpcRequest.addStringArg(payload); xmlRpcRequest.addStringArg(payload);
xmlRpcRequest.addStringArg(signature); xmlRpcRequest.addStringArg(signature);
xmlRpcSession.sendRequest(xmlRpcRequest); xmlRpcSession.sendRequest(xmlRpcRequest);
@ -164,7 +165,7 @@ public class XmlRpcHelper {
if (!"NOK".equals(result) && !"OK".equals(result)) { if (!"NOK".equals(result) && !"OK".equals(result)) {
listener.onError(result); listener.onError(result);
} }
listener.onAccountFetched("OK".equals(result)); listener.onTrialAccountFetched("OK".equals(result));
} else if (request.getStatus() == LinphoneXmlRpcRequest.Status.Failed) { } else if (request.getStatus() == LinphoneXmlRpcRequest.Status.Failed) {
Log.e(result); Log.e(result);
listener.onError(result); listener.onError(result);
@ -352,12 +353,13 @@ public class XmlRpcHelper {
} }
public void verifySignatureAsync(final XmlRpcListener listener, String payload, String signature) { public void verifySignatureAsync(final XmlRpcListener listener, String payload, String signature) {
LinphoneXmlRpcRequest xmlRpcRequest = new LinphoneXmlRpcRequestImpl("verify_payload_signature", LinphoneXmlRpcRequest.ArgType.String); LinphoneXmlRpcRequest xmlRpcRequest = new LinphoneXmlRpcRequestImpl("check_payload_signature", LinphoneXmlRpcRequest.ArgType.String);
xmlRpcRequest.setListener(new LinphoneXmlRpcRequestListener() { xmlRpcRequest.setListener(new LinphoneXmlRpcRequestListener() {
@Override @Override
public void onXmlRpcRequestResponse(LinphoneXmlRpcRequest request) { public void onXmlRpcRequestResponse(LinphoneXmlRpcRequest request) {
String result = request.getStringResponse(); String result = request.getStringResponse();
if (request.getStatus() == LinphoneXmlRpcRequest.Status.Ok) { if (request.getStatus() == LinphoneXmlRpcRequest.Status.Ok) {
Log.w(result);
if (result.startsWith("ERROR_")) { if (result.startsWith("ERROR_")) {
Log.e(result); Log.e(result);
listener.onError(result); listener.onError(result);