1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.exoplatform.accountswitcher;
20
21 import org.exoplatform.R;
22 import org.exoplatform.accountswitcher.AccountSwitcherProxy.AccountSwitcherListener;
23 import org.exoplatform.model.ExoAccount;
24
25 import android.os.Bundle;
26 import android.support.v4.app.Fragment;
27 import android.view.LayoutInflater;
28 import android.view.View;
29 import android.view.View.OnClickListener;
30 import android.view.ViewGroup;
31 import android.widget.Button;
32 import android.widget.TextView;
33 import android.widget.Toast;
34
35
36
37
38
39
40
41 public class SignInFragment extends Fragment implements AccountSwitcherListener {
42
43 private ExoAccount mCurrentAccount;
44
45 private TextView mPassword;
46
47 private final String EXO_ACCOUNT = "exo_account";
48
49 private OnClickListener mSignInListener = new OnClickListener() {
50 @Override
51 public void onClick(View v) {
52 String password = mPassword.getText().toString();
53 if (!password.isEmpty()) {
54 mCurrentAccount.password = password;
55 switchToAccount();
56 } else {
57 Toast.makeText(getActivity(), R.string.NoPasswordEnter, Toast.LENGTH_LONG)
58 .show();
59 }
60 }
61 };
62
63 public static final String FRAGMENT_TAG = "account_switcher_signin_fragment";
64
65 public static final String TAG = "eXo____AccountSwitcherSignInFragment____";
66
67 public SignInFragment() {
68 super();
69 }
70
71 public SignInFragment(ExoAccount account) {
72 mCurrentAccount = account;
73 }
74
75 @Override
76 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
77
78 if (savedInstanceState != null && savedInstanceState.containsKey(EXO_ACCOUNT)) {
79 mCurrentAccount = (ExoAccount) savedInstanceState.getParcelable(EXO_ACCOUNT);
80 }
81
82 View layout = inflater.inflate(R.layout.account_switcher_signin_fragment, container, false);
83
84
85 Button signInBtn = (Button) layout.findViewById(R.id.account_switcher_signin_btn);
86 signInBtn.setOnClickListener(mSignInListener);
87
88 TextView username = (TextView) layout.findViewById(R.id.account_switcher_signin_user_edit_txt);
89 username.setText(mCurrentAccount.username);
90
91 mPassword = (TextView) layout.findViewById(R.id.account_switcher_signin_pass_edit_txt);
92
93 return layout;
94 }
95
96 @Override
97 public void onSaveInstanceState(Bundle outState) {
98 if (mCurrentAccount != null)
99 outState.putParcelable(EXO_ACCOUNT, mCurrentAccount);
100 super.onSaveInstanceState(outState);
101 }
102
103
104
105
106 private void switchToAccount() {
107 AccountSwitcherProxy controller = new AccountSwitcherProxy(getActivity(), this, true);
108 controller.switchToAccount(mCurrentAccount);
109 }
110
111 @Override
112 public void onSwitchAccountFinished(boolean result) {
113 AccountSwitcherActivity parentActivity = (AccountSwitcherActivity) getActivity();
114 if (result)
115
116 parentActivity.redirectToHomeScreenAndFinish();
117 else
118
119 parentActivity.redirectToLoginScreenAndFinish();
120 }
121
122 @Override
123 public void onMissingPassword(ExoAccount account) {
124
125 }
126
127 @Override
128 public void onAccountInvalid(ExoAccount account) {
129
130 }
131 }