ui: change the wizard layout in landscape

The profile layout is modified in landscape mode. The profile photo is
next to the fullname and margins are larger.

Change-Id: I781153ec4850dc6a49f00106de99afddb7661106
Tuleap: #1429
diff --git a/ring-android/app/src/main/AndroidManifest.xml b/ring-android/app/src/main/AndroidManifest.xml
index a752f6f..fbfb845 100644
--- a/ring-android/app/src/main/AndroidManifest.xml
+++ b/ring-android/app/src/main/AndroidManifest.xml
@@ -138,7 +138,8 @@
         </activity>
         <activity
             android:name=".client.AccountWizard"
-            android:configChanges="orientation|screenSize|screenLayout|smallestScreenSize"
+            android:configChanges="screenSize|screenLayout|smallestScreenSize"
+
             android:screenOrientation="fullUser"
             android:theme="@style/AppThemeBase">
             <meta-data
diff --git a/ring-android/app/src/main/java/cx/ring/client/AccountWizard.java b/ring-android/app/src/main/java/cx/ring/client/AccountWizard.java
index be42df2..f18a60c 100644
--- a/ring-android/app/src/main/java/cx/ring/client/AccountWizard.java
+++ b/ring-android/app/src/main/java/cx/ring/client/AccountWizard.java
@@ -29,6 +29,7 @@
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
+import android.content.pm.ActivityInfo;
 import android.content.res.Configuration;
 import android.graphics.Bitmap;
 import android.os.AsyncTask;
@@ -93,6 +94,8 @@
     private Account mAccount;
     private String mCreatedAccountId;
 
+    public static final String PROFILE_TAG = "Profile";
+
     @Inject
     AccountService mAccountService;
 
@@ -106,6 +109,12 @@
     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
+        if (savedInstanceState != null) {
+            mProfileFragment = (ProfileCreationFragment) getFragmentManager().getFragment(savedInstanceState, PROFILE_TAG);
+            mFullname = savedInstanceState.getString("mFullname");
+            mPhotoProfile = savedInstanceState.getParcelable("mPhotoProfile");
+            mLinkAccount = savedInstanceState.getBoolean("mLinkAccount");
+        }
         setContentView(R.layout.activity_wizard);
         ButterKnife.bind(this);
 
@@ -134,6 +143,15 @@
     }
 
     @Override
+    protected void onSaveInstanceState(Bundle outState) {
+        super.onSaveInstanceState(outState);
+        getFragmentManager().putFragment(outState, PROFILE_TAG, mProfileFragment);
+        outState.putString("mFullname", mFullname);
+        outState.putParcelable("mPhotoProfile", mPhotoProfile);
+        outState.putBoolean("mLinkAccount", mLinkAccount);
+    }
+
+    @Override
     protected void onResume() {
         super.onResume();
         mAccountService.addObserver(this);
@@ -370,6 +388,8 @@
                                 @Override
                                 public void onDismiss(DialogInterface dialogInterface) {
                                     setResult(Activity.RESULT_OK, new Intent());
+                                    //unlock the screen orientation
+                                    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
                                     finish();
                                 }
                             });
@@ -510,6 +530,8 @@
         mCreatingAccount = true;
         mCreationError = false;
 
+        //orientation is locked during the create of account to avoid the destruction of the thread
+        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED);
         //noinspection unchecked
         new CreateAccountTask(this).execute(accountDetails);
     }
@@ -539,7 +561,9 @@
         WizardPagerAdapter(FragmentManager fm) {
             super(fm);
             mHomeFragment = new HomeAccountCreationFragment();
-            mProfileFragment = new ProfileCreationFragment();
+            if (mProfileFragment == null) {
+                mProfileFragment = new ProfileCreationFragment();
+            }
         }
 
         @Override
diff --git a/ring-android/app/src/main/java/cx/ring/fragments/ProfileCreationFragment.java b/ring-android/app/src/main/java/cx/ring/fragments/ProfileCreationFragment.java
index 152ea2c..c28d003 100644
--- a/ring-android/app/src/main/java/cx/ring/fragments/ProfileCreationFragment.java
+++ b/ring-android/app/src/main/java/cx/ring/fragments/ProfileCreationFragment.java
@@ -61,6 +61,8 @@
     public static final int REQUEST_PERMISSION_CAMERA = 3;
     public static final int REQUEST_PERMISSION_READ_STORAGE = 4;
 
+    public static final String PHOTO_TAG = "Photo";
+
     @Inject
     DeviceRuntimeService mDeviceRuntimeService;
 
@@ -86,6 +88,11 @@
 
     @Override
     public View onCreateView(LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
+
+        if (savedInstanceState != null) {
+            mSourcePhoto = savedInstanceState.getParcelable(PHOTO_TAG);
+        }
+
         final View view = inflater.inflate(R.layout.frag_acc_profile_create, parent, false);
         ButterKnife.bind(this, view);
 
@@ -105,6 +112,12 @@
         return view;
     }
 
+    @Override
+    public void onSaveInstanceState(Bundle outState) {
+        super.onSaveInstanceState(outState);
+        outState.putParcelable(PHOTO_TAG, mSourcePhoto);
+    }
+
     private void initProfile() {
         //~ Checking the state of the READ_CONTACTS permission
         boolean hasReadContactsPermission = mDeviceRuntimeService.hasContactPermission();
diff --git a/ring-android/app/src/main/java/cx/ring/fragments/RingAccountCreationFragment.java b/ring-android/app/src/main/java/cx/ring/fragments/RingAccountCreationFragment.java
index 34892ca..bd320cc 100644
--- a/ring-android/app/src/main/java/cx/ring/fragments/RingAccountCreationFragment.java
+++ b/ring-android/app/src/main/java/cx/ring/fragments/RingAccountCreationFragment.java
@@ -159,8 +159,11 @@
         // dependency injection
         ((RingApplication) getActivity().getApplication()).getRingInjectionComponent().inject(this);
 
-        BlockchainUtils.attachUsernameTextFilter(mUsernameTxt);
+        if (savedInstanceState != null) {
+            checkNextState();
+        }
 
+        BlockchainUtils.attachUsernameTextFilter(mUsernameTxt);
         if (isAdded()) {
             mUsernameTextWatcher = BlockchainUtils.attachUsernameTextWatcher(getActivity(), mAccountService, mUsernameTxtBox, mUsernameTxt);
         }
@@ -216,6 +219,11 @@
         return false;
     }
 
+    @OnTextChanged(R.id.ring_username)
+    public void onUsernameTextChanged(CharSequence s, int start, int before, int count) {
+        mCreateAccountButton.setEnabled(false);
+    }
+
     private boolean isValidUsername() {
         return mUsernameTxtBox.getError() == null;
     }
@@ -304,6 +312,7 @@
         if (actualName.isEmpty()) {
             mUsernameTxtBox.setErrorEnabled(false);
             mUsernameTxtBox.setError(null);
+            checkNextState();
             return;
         }
 
@@ -325,6 +334,7 @@
                     mUsernameTxtBox.setError(null);
                     break;
             }
+            checkNextState();
         }
     }
 }
\ No newline at end of file
diff --git a/ring-android/app/src/main/res/layout-land/frag_acc_profile_create.xml b/ring-android/app/src/main/res/layout-land/frag_acc_profile_create.xml
new file mode 100644
index 0000000..c86cfdf
--- /dev/null
+++ b/ring-android/app/src/main/res/layout-land/frag_acc_profile_create.xml
@@ -0,0 +1,166 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    xmlns:app="http://schemas.android.com/apk/res-auto"
+    xmlns:tools="http://schemas.android.com/tools"
+    android:layout_width="match_parent"
+    android:layout_height="match_parent"
+    android:theme="@style/Wizard">
+
+    <ScrollView
+        android:layout_width="match_parent"
+        android:layout_height="match_parent"
+        android:layout_above="@+id/add_action_panel">
+
+        <LinearLayout
+            android:layout_width="match_parent"
+            android:layout_height="wrap_content"
+            android:layout_gravity="center"
+            android:gravity="center"
+            android:orientation="vertical"
+            android:paddingBottom="@dimen/activity_vertical_margin"
+            android:paddingLeft="@dimen/activity_horizontal_margin"
+            android:paddingRight="@dimen/activity_horizontal_margin"
+            android:paddingTop="@dimen/activity_vertical_margin">
+
+            <TextView
+                android:id="@+id/title"
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginBottom="@dimen/activity_vertical_margin"
+                android:layout_marginTop="@dimen/activity_vertical_margin"
+                android:gravity="center"
+                android:text="@string/account_creation_profile"
+                android:textSize="24sp" />
+
+            <TextView
+                android:layout_width="match_parent"
+                android:layout_height="wrap_content"
+                android:layout_marginBottom="@dimen/activity_vertical_margin"
+                android:layout_marginTop="@dimen/activity_vertical_margin"
+                android:gravity="center_horizontal"
+                android:text="@string/profile_message_warning" />
+
+            <LinearLayout
+                android:layout_width="match_parent"
+                android:layout_height="match_parent"
+                android:layout_gravity="center"
+                android:gravity="center"
+                android:orientation="horizontal">
+
+                <RelativeLayout
+                    android:layout_width="0dp"
+                    android:layout_height="wrap_content"
+                    android:layout_weight="0.5"
+                    android:gravity="center">
+
+                    <RelativeLayout
+                        android:id="@+id/profile_container"
+                        android:layout_width="150dp"
+                        android:layout_height="180dp"
+                        android:layout_gravity="center">
+
+                        <ImageView
+                            android:id="@+id/profile_photo"
+                            android:layout_width="120dp"
+                            android:layout_height="120dp"
+                            android:layout_alignParentTop="true"
+                            android:layout_centerHorizontal="true"
+                            android:layout_margin="10dp"
+                            android:scaleType="fitCenter"
+                            tools:src="@drawable/ic_contact_picture" />
+
+                        <android.support.design.widget.FloatingActionButton
+                            android:id="@+id/camera"
+                            android:layout_width="wrap_content"
+                            android:layout_height="wrap_content"
+                            android:layout_alignTop="@+id/anchor"
+                            android:layout_toRightOf="@+id/anchor"
+                            android:contentDescription="@string/take_a_photo"
+                            android:src="@drawable/ic_photo_camera"
+                            android:text="@string/take_a_photo"
+                            app:backgroundTint="@color/light"
+                            app:rippleColor="@android:color/white" />
+
+                        <View
+                            android:id="@+id/anchor"
+                            android:layout_width="20dp"
+                            android:layout_height="20dp"
+                            android:layout_alignBottom="@+id/profile_photo"
+                            android:layout_centerHorizontal="true"
+                            android:background="@color/zxing_transparent" />
+
+                        <android.support.design.widget.FloatingActionButton
+                            android:id="@+id/gallery"
+                            android:layout_width="wrap_content"
+                            android:layout_height="wrap_content"
+                            android:layout_alignTop="@+id/anchor"
+                            android:layout_toLeftOf="@+id/anchor"
+                            android:contentDescription="@string/open_the_gallery"
+                            android:src="@drawable/ic_insert_photo"
+                            android:text="@string/open_the_gallery"
+                            app:backgroundTint="@color/light"
+                            app:rippleColor="@android:color/white" />
+
+                    </RelativeLayout>
+                </RelativeLayout>
+
+                <RelativeLayout
+                    android:layout_width="0dp"
+                    android:layout_height="wrap_content"
+                    android:layout_weight="0.5">
+
+                    <cx.ring.views.BoundedRelativeLayout
+                        android:layout_width="match_parent"
+                        android:layout_height="wrap_content"
+                        app:bounded_width="500dp">
+
+                        <EditText
+                            android:id="@+id/user_name"
+                            android:layout_width="match_parent"
+                            android:layout_height="wrap_content"
+                            android:layout_marginLeft="24dp"
+                            android:layout_marginRight="24dp"
+                            android:hint="@string/unknowm_if_empty"
+                            android:inputType="textCapWords"
+                            android:maxLines="1"
+                            android:textAlignment="center"
+                            android:textColor="@color/text_color_primary_dark"
+                            android:textColorHint="@color/text_color_secondary_dark"
+                            tools:text="Username" />
+
+                    </cx.ring.views.BoundedRelativeLayout>
+
+                </RelativeLayout>
+
+            </LinearLayout>
+
+        </LinearLayout>
+
+    </ScrollView>
+
+    <RelativeLayout
+        android:id="@+id/add_action_panel"
+        android:layout_width="match_parent"
+        android:layout_height="50dp"
+        android:layout_alignParentBottom="true"
+        android:background="@color/color_primary_light">
+
+        <Button
+            android:id="@+id/last_create_account"
+            style="@style/Widget.AppCompat.Button.Borderless.Colored"
+            android:layout_width="100dp"
+            android:layout_height="match_parent"
+            android:layout_alignParentLeft="true"
+            android:text="@string/wizard_back" />
+
+        <Button
+            android:id="@+id/next_create_account"
+            style="@style/Widget.AppCompat.Button.Borderless.Colored"
+            android:layout_width="100dp"
+            android:layout_height="match_parent"
+            android:layout_alignParentRight="true"
+            android:text="@string/wizard_next" />
+
+    </RelativeLayout>
+
+</RelativeLayout>
\ No newline at end of file
diff --git a/ring-android/app/src/main/res/values-h500dp-land/dimens.xml b/ring-android/app/src/main/res/values-h500dp-land/dimens.xml
new file mode 100644
index 0000000..d483310
--- /dev/null
+++ b/ring-android/app/src/main/res/values-h500dp-land/dimens.xml
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <dimen name="activity_vertical_margin">24dp</dimen>
+</resources>
\ No newline at end of file