Commit 3f7e8d947039e5ff0e5680e8cbb8c33cace29f8d
1 parent
998b6613
6.0 用户管理配置补全
Showing
7 changed files
with
207 additions
and
4 deletions
app/src/main/AndroidManifest.xml
| ... | ... | @@ -93,6 +93,18 @@ |
| 93 | 93 | android:theme="@style/Theme.AppCompat.Light.NoActionBar" /> |
| 94 | 94 | |
| 95 | 95 | <service |
| 96 | + android:name=".user.auth.UserAccountService" | |
| 97 | + tools:ignore="ExportedService"> | |
| 98 | + <intent-filter> | |
| 99 | + <action android:name="android.accounts.AccountAuthenticator" /> | |
| 100 | + </intent-filter> | |
| 101 | + | |
| 102 | + <meta-data | |
| 103 | + android:name="android.accounts.AccountAuthenticator" | |
| 104 | + android:resource="@xml/authenticator" /> | |
| 105 | + </service> | |
| 106 | + | |
| 107 | + <service | |
| 96 | 108 | android:name="io.rong.imlib.ipc.RongService" |
| 97 | 109 | android:exported="true" |
| 98 | 110 | android:process=":ipc" /> | ... | ... |
app/src/main/java/com/cnlive/gundam/user/activity/LoginActivity.java
| ... | ... | @@ -3,12 +3,12 @@ package com.cnlive.gundam.user.activity; |
| 3 | 3 | import android.content.Context; |
| 4 | 4 | import android.databinding.DataBindingUtil; |
| 5 | 5 | import android.os.Bundle; |
| 6 | -import android.support.v7.app.AppCompatActivity; | |
| 7 | 6 | import android.view.MotionEvent; |
| 8 | 7 | import android.view.View; |
| 9 | 8 | import android.view.inputmethod.InputMethodManager; |
| 10 | 9 | |
| 11 | 10 | import com.cnlive.gundam.R; |
| 11 | +import com.cnlive.gundam.user.auth.AccountAuthenticatorActivity; | |
| 12 | 12 | import com.cnlive.gundam.user.fragment.LoginFragment; |
| 13 | 13 | import com.cnlive.gundam.user.util.DevilUtil; |
| 14 | 14 | |
| ... | ... | @@ -17,7 +17,7 @@ import com.cnlive.gundam.user.util.DevilUtil; |
| 17 | 17 | * Created by luxiaoman on 2017/6/2. |
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | -public class LoginActivity extends AppCompatActivity { | |
| 20 | +public class LoginActivity extends AccountAuthenticatorActivity { | |
| 21 | 21 | |
| 22 | 22 | @Override |
| 23 | 23 | protected void onCreate(Bundle savedInstanceState) { | ... | ... |
app/src/main/java/com/cnlive/gundam/user/auth/AccountAuthenticatorActivity.java
0 → 100644
| 1 | +/* | |
| 2 | + * Copyright (C) 2009 The Android Open Source Project | |
| 3 | + * | |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | + * you may not use this file except in compliance with the License. | |
| 6 | + * You may obtain a copy of the License at | |
| 7 | + * | |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 | |
| 9 | + * | |
| 10 | + * Unless required by applicable law or agreed to in writing, software | |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| 13 | + * See the License for the specific language governing permissions and | |
| 14 | + * limitations under the License. | |
| 15 | + */ | |
| 16 | + | |
| 17 | +package com.cnlive.gundam.user.auth; | |
| 18 | + | |
| 19 | +import android.accounts.AccountAuthenticatorResponse; | |
| 20 | +import android.accounts.AccountManager; | |
| 21 | +import android.os.Bundle; | |
| 22 | +import android.support.v7.app.AppCompatActivity; | |
| 23 | + | |
| 24 | +/** | |
| 25 | + * Base class for implementing an Activity that is used to help implement an | |
| 26 | + * AbstractAccountAuthenticator. If the AbstractAccountAuthenticator needs to use an activity | |
| 27 | + * to handle the request then it can have the activity extend AccountAuthenticatorActivity. | |
| 28 | + * The AbstractAccountAuthenticator passes in the response to the intent using the following: | |
| 29 | + * <pre> | |
| 30 | + * intent.putExtra({@link AccountManager#KEY_ACCOUNT_AUTHENTICATOR_RESPONSE}, response); | |
| 31 | + * </pre> | |
| 32 | + * The activity then sets the result that is to be handed to the response via | |
| 33 | + * {@link #setAccountAuthenticatorResult(Bundle)}. | |
| 34 | + * This result will be sent as the result of the request when the activity finishes. If this | |
| 35 | + * is never set or if it is set to null then error {@link AccountManager#ERROR_CODE_CANCELED} | |
| 36 | + * will be called on the response. | |
| 37 | + */ | |
| 38 | +public class AccountAuthenticatorActivity extends AppCompatActivity { | |
| 39 | + private AccountAuthenticatorResponse mAccountAuthenticatorResponse = null; | |
| 40 | + private Bundle mResultBundle = null; | |
| 41 | + | |
| 42 | + /** | |
| 43 | + * Set the result that is to be sent as the result of the request that caused this | |
| 44 | + * Activity to be launched. If result is null or this method is never called then | |
| 45 | + * the request will be canceled. | |
| 46 | + * | |
| 47 | + * @param result this is returned as the result of the AbstractAccountAuthenticator request | |
| 48 | + */ | |
| 49 | + public final void setAccountAuthenticatorResult(Bundle result) { | |
| 50 | + mResultBundle = result; | |
| 51 | + } | |
| 52 | + | |
| 53 | + /** | |
| 54 | + * Retreives the AccountAuthenticatorResponse from either the intent of the icicle, if the | |
| 55 | + * icicle is non-zero. | |
| 56 | + * | |
| 57 | + * @param icicle the save instance data of this Activity, may be null | |
| 58 | + */ | |
| 59 | + protected void onCreate(Bundle icicle) { | |
| 60 | + super.onCreate(icicle); | |
| 61 | + | |
| 62 | + mAccountAuthenticatorResponse = | |
| 63 | + getIntent().getParcelableExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE); | |
| 64 | + | |
| 65 | + if (mAccountAuthenticatorResponse != null) { | |
| 66 | + mAccountAuthenticatorResponse.onRequestContinued(); | |
| 67 | + } | |
| 68 | + } | |
| 69 | + | |
| 70 | + /** | |
| 71 | + * Sends the result or a Constants.ERROR_CODE_CANCELED error if a result isn't present. | |
| 72 | + */ | |
| 73 | + public void finish() { | |
| 74 | + if (mAccountAuthenticatorResponse != null) { | |
| 75 | + // send the result bundle back if set, otherwise send an error. | |
| 76 | + if (mResultBundle != null) { | |
| 77 | + mAccountAuthenticatorResponse.onResult(mResultBundle); | |
| 78 | + } else { | |
| 79 | + mAccountAuthenticatorResponse.onError(AccountManager.ERROR_CODE_CANCELED, | |
| 80 | + "canceled"); | |
| 81 | + } | |
| 82 | + mAccountAuthenticatorResponse = null; | |
| 83 | + } | |
| 84 | + super.finish(); | |
| 85 | + } | |
| 86 | +} | ... | ... |
app/src/main/java/com/cnlive/gundam/user/auth/UserAccountAuthenticator.java
0 → 100644
| 1 | +package com.cnlive.gundam.user.auth; | |
| 2 | + | |
| 3 | +import android.accounts.AbstractAccountAuthenticator; | |
| 4 | +import android.accounts.Account; | |
| 5 | +import android.accounts.AccountAuthenticatorResponse; | |
| 6 | +import android.accounts.AccountManager; | |
| 7 | +import android.accounts.NetworkErrorException; | |
| 8 | +import android.content.Context; | |
| 9 | +import android.content.Intent; | |
| 10 | +import android.os.Bundle; | |
| 11 | +import android.util.Log; | |
| 12 | + | |
| 13 | +import com.cnlive.gundam.user.activity.LoginActivity; | |
| 14 | + | |
| 15 | + | |
| 16 | +public class UserAccountAuthenticator extends AbstractAccountAuthenticator { | |
| 17 | + private String _tag = "UserAccountAuthenticator"; | |
| 18 | + private Context _context; | |
| 19 | + | |
| 20 | + public UserAccountAuthenticator(Context context) { | |
| 21 | + super(context); | |
| 22 | + _context = context; | |
| 23 | + } | |
| 24 | + | |
| 25 | + public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) | |
| 26 | + throws NetworkErrorException { | |
| 27 | + Log.e("UserAccount", accountType + " - " + authTokenType); | |
| 28 | + Bundle ret = new Bundle(); | |
| 29 | + | |
| 30 | + Intent intent = new Intent(_context, LoginActivity.class); | |
| 31 | + intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response); | |
| 32 | + | |
| 33 | + ret.putParcelable(AccountManager.KEY_INTENT, intent); | |
| 34 | + return ret; | |
| 35 | + } | |
| 36 | + | |
| 37 | + | |
| 38 | + @Override | |
| 39 | + public Bundle confirmCredentials(AccountAuthenticatorResponse response, Account account, Bundle options) { | |
| 40 | + Log.e("UserAccount",".confirmCredentials"); | |
| 41 | + return null; | |
| 42 | + } | |
| 43 | + | |
| 44 | + | |
| 45 | + @Override | |
| 46 | + public Bundle editProperties(AccountAuthenticatorResponse response, String accountType) { | |
| 47 | + Log.e("UserAccount",".editProperties"); | |
| 48 | + return null; | |
| 49 | + } | |
| 50 | + | |
| 51 | + | |
| 52 | + @Override | |
| 53 | + public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle loginOptions) throws NetworkErrorException { | |
| 54 | + Log.e("UserAccount",".getAuthToken"); | |
| 55 | + return null; | |
| 56 | + } | |
| 57 | + | |
| 58 | + | |
| 59 | + @Override | |
| 60 | + public String getAuthTokenLabel(String authTokenType) { | |
| 61 | + Log.e("UserAccount",".getAuthTokenLabel"); | |
| 62 | + return null; | |
| 63 | + } | |
| 64 | + | |
| 65 | + | |
| 66 | + @Override | |
| 67 | + public Bundle hasFeatures(AccountAuthenticatorResponse response, Account account, String[] features) throws NetworkErrorException { | |
| 68 | + Log.e("UserAccount",".hasFeatures"); | |
| 69 | + return null; | |
| 70 | + } | |
| 71 | + | |
| 72 | + | |
| 73 | + @Override | |
| 74 | + public Bundle updateCredentials(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle loginOptions) { | |
| 75 | + Log.e("UserAccount",".updateCredentials"); | |
| 76 | + return null; | |
| 77 | + } | |
| 78 | + | |
| 79 | +} | ... | ... |
app/src/main/java/com/cnlive/gundam/user/auth/UserAccountService.java
0 → 100644
| 1 | +package com.cnlive.gundam.user.auth; | |
| 2 | + | |
| 3 | +import android.app.Service; | |
| 4 | +import android.content.Intent; | |
| 5 | +import android.os.IBinder; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * Created by vclub on 14-8-8. | |
| 9 | + */ | |
| 10 | +public class UserAccountService extends Service { | |
| 11 | + private UserAccountAuthenticator _saa; | |
| 12 | + | |
| 13 | + @Override | |
| 14 | + public IBinder onBind(Intent intent) { | |
| 15 | + IBinder ret = null; | |
| 16 | + if (intent.getAction().equals(android.accounts.AccountManager.ACTION_AUTHENTICATOR_INTENT)) | |
| 17 | + ret = getMovieAuthenticator().getIBinder(); | |
| 18 | + return ret; | |
| 19 | + } | |
| 20 | + | |
| 21 | + private UserAccountAuthenticator getMovieAuthenticator() { | |
| 22 | + if (_saa == null) | |
| 23 | + _saa = new UserAccountAuthenticator(this); | |
| 24 | + return _saa; | |
| 25 | + } | |
| 26 | +} | ... | ... |
app/src/main/java/com/cnlive/gundam/user/model/User.java
| ... | ... | @@ -6,7 +6,7 @@ import com.cnlive.gundam.user.model.base.ErrorMessage; |
| 6 | 6 | import java.io.Serializable; |
| 7 | 7 | |
| 8 | 8 | public class User extends ErrorMessage implements Serializable { |
| 9 | - public static final String ACCOUNT_TYPE="com.cnlive.libs.AccountType"; | |
| 9 | + public static final String ACCOUNT_TYPE="com.cnlive.gundam.AccountType"; | |
| 10 | 10 | |
| 11 | 11 | /** |
| 12 | 12 | * uid : 201601211717200000000000002308 | ... | ... |
user/src/main/res/values/strings.xml
| ... | ... | @@ -36,7 +36,7 @@ |
| 36 | 36 | <string name="find_password_hint">请确认密码:6–20位字母或数字</string> |
| 37 | 37 | <string name="save_btn">保存</string> |
| 38 | 38 | |
| 39 | - <string name="ACCOUNT_TYPE">com.cnlive.libs.AccountType</string> | |
| 39 | + <string name="ACCOUNT_TYPE">com.cnlive.gundam.AccountType</string> | |
| 40 | 40 | <string name="ACCOUNT_LABEL">@string/app_name</string> |
| 41 | 41 | |
| 42 | 42 | ... | ... |