Added remote provisioning login view

This commit is contained in:
Sylvain Berfini 2014-03-03 15:27:17 +01:00
parent a029157a4a
commit 53755012df
10 changed files with 299 additions and 9 deletions

View file

@ -94,6 +94,14 @@
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity android:name="org.linphone.setup.RemoteProvisioningLoginActivity"
android:theme="@style/NoTitle"
android:screenOrientation="nosensor">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<service android:name="org.linphone.LinphoneService"
android:label="@string/service_name"

View file

@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:color="@android:color/darker_gray" />
<item android:color="@android:color/black"/>
</selector>

View file

@ -0,0 +1,132 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="@drawable/background"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/mark"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<ImageView
android:contentDescription="@string/content_description_mark"
android:visibility="invisible"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/setup_mark"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:layout_weight="0.5"/>
<ImageView
android:contentDescription="@string/content_description_mark"
android:visibility="invisible"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@drawable/setup_mark"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:layout_weight="0.5"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
android:padding="20dp"
android:layout_above="@id/mark"
android:orientation="vertical">
<ImageView
android:contentDescription="@string/content_description_welcome"
android:paddingTop="40dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/setup_title_assistant"/>
<TextView
android:paddingTop="10dp"
android:gravity="center"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/setup_remote_provisioning_login_hint"
android:textColor="@android:color/black"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="40dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:gravity="center"
android:orientation="vertical">
<EditText
android:textCursorDrawable="@null"
android:id="@+id/setup_username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/setup_username_hint"
android:inputType="textEmailAddress"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:textColor="@color/edittextcolor"
android:background="@drawable/setup_field_background" />
<EditText
android:textCursorDrawable="@null"
android:id="@+id/setup_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/setup_password_hint"
android:inputType="textPassword"
android:layout_marginTop="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:textColor="@color/edittextcolor"
android:background="@drawable/setup_field_background" />
<EditText
android:textCursorDrawable="@null"
android:id="@+id/setup_domain"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/setup_domain_hint"
android:inputType="textEmailAddress"
android:layout_marginTop="5dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:singleLine="true"
android:textColor="@color/edittextcolor"
android:background="@drawable/setup_field_background" />
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/menu"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<include layout="@layout/setup_cancel_button" />
<include layout="@layout/setup_next_button" />
</LinearLayout>
</RelativeLayout>

View file

@ -29,7 +29,7 @@
<bool name="hide_linphone_accounts_wizard">false</bool>
<bool name="hide_generic_accounts_wizard">false</bool>
<bool name="hide_remote_provisioning_in_wizard">false</bool>
<bool name="show_login_wizard_after_remote_provisioning_without_credentials">true</bool>
<bool name="allow_cancel_remote_provisioning_login_activity">true</bool>
<bool name="hide_accounts">false</bool>
<bool name="display_account_wizard_at_first_start">true</bool>
<bool name="use_linphone_server_ports">true</bool>

View file

@ -437,6 +437,7 @@
<string name="setup_remote_provisioning">Download provisioning</string>
<string name="setup_remote_provisioning_hint">This assistant will download an existing configuration.</string>
<string name="setup_remote_provisioning_url_hint">provisioning url</string>
<string name="setup_remote_provisioning_login_hint">The configuration you downloaded doesn\'t include your account. Please fill it in.</string>
<string name="setup_confirm_username">Your username will be %s (uppercase characters are not allowed). Do you accept ?</string>
<string name="zrtp_accept">Accept</string>

View file

@ -44,6 +44,7 @@ import org.linphone.core.LinphoneCoreException;
import org.linphone.core.LinphoneCoreFactory;
import org.linphone.core.LinphoneFriend;
import org.linphone.mediastream.Log;
import org.linphone.setup.RemoteProvisioningLoginActivity;
import org.linphone.setup.SetupActivity;
import org.linphone.ui.AddressText;
@ -92,6 +93,7 @@ public class LinphoneActivity extends FragmentActivity implements
public static final String PREF_FIRST_LAUNCH = "pref_first_launch";
private static final int SETTINGS_ACTIVITY = 123;
private static final int FIRST_LOGIN_ACTIVITY = 101;
private static final int REMOTE_PROVISIONING_LOGIN_ACTIVITY = 102;
private static final int CALL_ACTIVITY = 19;
private static LinphoneActivity instance;
@ -138,16 +140,21 @@ public class LinphoneActivity extends FragmentActivity implements
startActivity(getIntent().setClass(this, LinphoneLauncherActivity.class));
return;
}
boolean useFirstLoginActivity = getResources().getBoolean(R.bool.display_account_wizard_at_first_start);
if (useFirstLoginActivity && LinphonePreferences.instance().isFirstLaunch()) {
if (LinphonePreferences.instance().isProvisioningLoginViewEnabled()) {
Intent wizard = new Intent();
wizard.setClass(this, RemoteProvisioningLoginActivity.class);
wizard.putExtra("Domain", LinphoneManager.getInstance().wizardLoginViewDomain);
startActivityForResult(wizard, REMOTE_PROVISIONING_LOGIN_ACTIVITY);
} else if (useFirstLoginActivity && LinphonePreferences.instance().isFirstLaunch()) {
if (LinphonePreferences.instance().getAccountCount() > 0) {
LinphonePreferences.instance().firstLaunchSuccessful();
} else {
startActivityForResult(new Intent().setClass(this, SetupActivity.class), FIRST_LOGIN_ACTIVITY);
}
}
setContentView(R.layout.main);
instance = this;
fragmentsHistory = new ArrayList<FragmentsAvailable>();

View file

@ -156,6 +156,8 @@ public class LinphoneManager implements LinphoneCoreListener {
public boolean isUsingBluetoothAudioRoute;
private boolean mBluetoothStarted;
public String wizardLoginViewDomain = null;
private static List<LinphoneSimpleListener> simpleListeners = new ArrayList<LinphoneSimpleListener>();
public static void addListener(LinphoneSimpleListener listener) {
if (!simpleListeners.contains(listener)) {
@ -881,12 +883,12 @@ public class LinphoneManager implements LinphoneCoreListener {
mListenerDispatcher.onDisplayStatus(message);
}
public void globalState(final LinphoneCore lc, final LinphoneCore.GlobalState state, final String message) {
public void globalState(final LinphoneCore lc, final GlobalState state, final String message) {
Log.i("new state [",state,"]");
mListenerDispatcher.onGlobalStateChanged(state, message);
}
public void registrationState(final LinphoneCore lc, final LinphoneProxyConfig cfg,final LinphoneCore.RegistrationState state,final String message) {
public void registrationState(final LinphoneCore lc, final LinphoneProxyConfig cfg,final RegistrationState state,final String message) {
Log.i("new state ["+state+"]");
mListenerDispatcher.onRegistrationStateChanged(state, message);
}
@ -1466,8 +1468,14 @@ public class LinphoneManager implements LinphoneCoreListener {
Log.d("Remote provisioning status = " + state.toString() + " (" + message + ")");
if (state == RemoteProvisioningState.ConfiguringSuccessful) {
if (mR.getBoolean(R.bool.show_login_wizard_after_remote_provisioning_without_credentials)) {
if (LinphonePreferences.instance().isProvisioningLoginViewEnabled()) {
LinphoneProxyConfig proxyConfig = lc.createProxyConfig();
try {
LinphoneAddress addr = LinphoneCoreFactory.instance().createLinphoneAddress(proxyConfig.getIdentity());
wizardLoginViewDomain = addr.getDomain();
} catch (LinphoneCoreException e) {
wizardLoginViewDomain = null;
}
}
}
}

View file

@ -833,4 +833,16 @@ public class LinphonePreferences {
LinphoneManager.getInstance().initTunnelFromConf();
}
// End of tunnel settings
public boolean isProvisioningLoginViewEnabled() {
return getConfig().getBool("app", "show_login_view", false);
}
public void disableProvisioningLoginView() {
if (isProvisioningLoginViewEnabled()) { // Only do it if it was previously enabled
getConfig().setBool("app", "show_login_view", false);
} else {
Log.w("Remote provisioning login view wasn't enabled, ignoring");
}
}
}

View file

@ -0,0 +1,117 @@
package org.linphone.setup;
/*
RemoteProvisioningLoginActivity.java
Copyright (C) 2014 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
import org.linphone.LinphoneManager;
import org.linphone.LinphonePreferences;
import org.linphone.R;
import org.linphone.core.LinphoneAuthInfo;
import org.linphone.core.LinphoneCore;
import org.linphone.core.LinphoneCoreException;
import org.linphone.core.LinphoneCoreFactory;
import org.linphone.core.LinphoneProxyConfig;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import android.widget.RelativeLayout;
import android.widget.Toast;
/**
* @author Sylvain Berfini
*/
public class RemoteProvisioningLoginActivity extends Activity implements OnClickListener {
private EditText login, password, domain;
private RelativeLayout next, cancel;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.setup_remote_provisioning_login);
login = (EditText) findViewById(R.id.setup_username);
password = (EditText) findViewById(R.id.setup_password);
domain = (EditText) findViewById(R.id.setup_domain);
next = (RelativeLayout) findViewById(R.id.setup_next);
next.setOnClickListener(this);
cancel = (RelativeLayout) findViewById(R.id.setup_cancel);
cancel.setOnClickListener(this);
String defaultDomain = getIntent().getStringExtra("Domain");
if (defaultDomain != null) {
domain.setText(defaultDomain);
domain.setEnabled(false);
}
}
private void cancelWizard(boolean bypassCheck) {
if (bypassCheck || getResources().getBoolean(R.bool.allow_cancel_remote_provisioning_login_activity)) {
LinphonePreferences.instance().disableProvisioningLoginView();
setResult(bypassCheck ? Activity.RESULT_OK : Activity.RESULT_CANCELED);
finish();
}
}
private boolean storeAccount(String username, String password, String domain) {
LinphoneCore lc = LinphoneManager.getLc();
String identity = "sip:" + username + "@" + domain;
LinphoneProxyConfig prxCfg = lc.createProxyConfig();
try {
prxCfg.setIdentity(identity);
lc.addProxyConfig(prxCfg);
} catch (LinphoneCoreException e) {
e.printStackTrace();
return false;
}
LinphoneAuthInfo authInfo = LinphoneCoreFactory.instance().createAuthInfo(username, null, password, null, null, domain);
lc.addAuthInfo(authInfo);
if (LinphonePreferences.instance().getAccountCount() == 1)
lc.setDefaultProxyConfig(prxCfg);
return true;
}
@Override
public void onClick(View v) {
int id = v.getId();
if (id == R.id.setup_next) {
if (login.getText() == null || login.length() == 0 || password.getText() == null || password.length() == 0 || domain.getText() == null || domain.length() == 0) {
Toast.makeText(this, getString(R.string.first_launch_no_login_password), Toast.LENGTH_LONG).show();
return;
}
storeAccount(login.getText().toString(), password.getText().toString(), domain.getText().toString());
cancelWizard(true);
} else if (id == R.id.setup_cancel) {
cancelWizard(false);
}
}
@Override
public void onBackPressed() {
cancelWizard(false);
}
}

@ -1 +1 @@
Subproject commit 028f4c550b267c2801cfc7fd93dcb3c8d237a84d
Subproject commit 7d64dedf12c4a7795d2ffe204416543025055de2