From ee0ffc48d22957147e551da413cd3371e3220a06 Mon Sep 17 00:00:00 2001 From: seven332 Date: Fri, 21 Jun 2019 13:41:37 +0800 Subject: [PATCH] Remove recaptcha --- .../java/com/hippo/drawable/TextDrawable.java | 140 -------------- .../com/hippo/ehviewer/client/EhClient.java | 2 +- .../com/hippo/ehviewer/client/EhEngine.java | 6 +- .../hippo/ehviewer/ui/scene/SignInScene.java | 10 +- .../hippo/ehviewer/widget/RecaptchaView.java | 183 ------------------ app/src/main/res/layout/scene_login.xml | 29 +-- 6 files changed, 4 insertions(+), 366 deletions(-) delete mode 100644 app/src/main/java/com/hippo/drawable/TextDrawable.java delete mode 100644 app/src/main/java/com/hippo/ehviewer/widget/RecaptchaView.java diff --git a/app/src/main/java/com/hippo/drawable/TextDrawable.java b/app/src/main/java/com/hippo/drawable/TextDrawable.java deleted file mode 100644 index 45f14d6bc..000000000 --- a/app/src/main/java/com/hippo/drawable/TextDrawable.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright 2017 Hippo Seven - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.hippo.drawable; - -/* - * Created by Hippo on 2017/9/6. - */ - -import android.graphics.Canvas; -import android.graphics.Color; -import android.graphics.ColorFilter; -import android.graphics.Paint; -import android.graphics.PixelFormat; -import android.graphics.Rect; -import android.graphics.drawable.Drawable; -import android.text.TextUtils; -import androidx.annotation.IntRange; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -public class TextDrawable extends Drawable { - - private static final float STANDARD_TEXT_SIZE = 1000.0f; - private static final Paint STANDARD_PAINT = new Paint(); - - static { - STANDARD_PAINT.setTextSize(STANDARD_TEXT_SIZE); - } - - private String text; - private float contentPercent; - - private Paint backgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG); - private Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG); - - private int textColor = Color.BLACK; - private int backgroundColor = Color.BLACK; - - private float x = 0.0f; - private float y = 0.0f; - private boolean textSizeDirty = false; - private Rect textBounds = new Rect(); - - public TextDrawable(String text, float contentPercent) { - this.text = text; - this.contentPercent = contentPercent; - STANDARD_PAINT.getTextBounds(text, 0, text.length(), textBounds); - } - - public int getTextColor() { - return textColor; - } - - public void setTextColor(int textColor) { - if (this.textColor != textColor) { - this.textColor = textColor; - invalidateSelf(); - } - } - - public int getBackgroundColor() { - return backgroundColor; - } - - public void setBackgroundColor(int backgroundColor) { - if (this.backgroundColor != backgroundColor) { - this.backgroundColor = backgroundColor; - invalidateSelf(); - } - } - - @Override - protected void onBoundsChange(Rect bounds) { - super.onBoundsChange(bounds); - textSizeDirty = true; - } - - private void updateTextSizeIfDirty(Rect bounds) { - if (!textSizeDirty) { - return; - } - textSizeDirty = false; - - int contentWidth = (int) (bounds.width() * contentPercent); - int contentHeight = (int) (bounds.height() * contentPercent); - float widthRatio = (float) contentWidth / (float) textBounds.width(); - float heightRatio = (float) contentHeight / (float) textBounds.height(); - float ratio = Math.min(widthRatio, heightRatio); - float textSize = STANDARD_TEXT_SIZE * ratio; - textPaint.setTextSize(textSize); - x = (bounds.width() - textBounds.width() * ratio) / 2 - textBounds.left * ratio; - y = (bounds.height() - textBounds.height() * ratio) / 2 - textBounds.top * ratio; - } - - @Override - public void draw(@NonNull Canvas canvas) { - Rect bounds = getBounds(); - if (!bounds.isEmpty()) { - // Draw background - backgroundPaint.setColor(backgroundColor); - canvas.drawRect(bounds, backgroundPaint); - - if (!TextUtils.isEmpty(text)) { - // Draw text - updateTextSizeIfDirty(bounds); - textPaint.setColor(textColor); - canvas.drawText(text, x, y, textPaint); - } - } - } - - @Override - public void setAlpha(@IntRange(from = 0, to = 255) int alpha) {} - - @Override - public void setColorFilter(@Nullable ColorFilter colorFilter) { - backgroundPaint.setColorFilter(colorFilter); - textPaint.setColorFilter(colorFilter); - invalidateSelf(); - } - - @Override - public int getOpacity() { - return PixelFormat.TRANSLUCENT; - } -} diff --git a/app/src/main/java/com/hippo/ehviewer/client/EhClient.java b/app/src/main/java/com/hippo/ehviewer/client/EhClient.java index 327ca93c3..32d06f287 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhClient.java +++ b/app/src/main/java/com/hippo/ehviewer/client/EhClient.java @@ -138,7 +138,7 @@ public class EhClient { try { switch (mMethod) { case METHOD_SIGN_IN: - return EhEngine.signIn(this, mOkHttpClient, (String) params[0], (String) params[1], (String) params[2], (String) params[3]); + return EhEngine.signIn(this, mOkHttpClient, (String) params[0], (String) params[1]); case METHOD_GET_GALLERY_LIST: return EhEngine.getGalleryList(this, mOkHttpClient, (String) params[0]); case METHOD_GET_GALLERY_DETAIL: diff --git a/app/src/main/java/com/hippo/ehviewer/client/EhEngine.java b/app/src/main/java/com/hippo/ehviewer/client/EhEngine.java index 7dc2b4d09..6e728c587 100644 --- a/app/src/main/java/com/hippo/ehviewer/client/EhEngine.java +++ b/app/src/main/java/com/hippo/ehviewer/client/EhEngine.java @@ -134,17 +134,13 @@ public class EhEngine { } public static String signIn(@Nullable EhClient.Task task, OkHttpClient okHttpClient, - String username, String password, String recaptchaChallenge, String recaptchaResponse) throws Throwable { + String username, String password) throws Throwable { FormBody.Builder builder = new FormBody.Builder() .add("UserName", username) .add("PassWord", password) .add("submit", "Log me in") .add("CookieDate", "1") .add("temporary_https", "off"); - if (!TextUtils.isEmpty(recaptchaChallenge) && !TextUtils.isEmpty(recaptchaResponse)) { - builder.add("recaptcha_challenge_field", recaptchaChallenge); - builder.add("recaptcha_response_field", recaptchaResponse); - } String url = EhUrl.API_SIGN_IN; String referer = "https://forums.e-hentai.org/index.php?act=Login&CODE=00"; String origin = "https://forums.e-hentai.org"; diff --git a/app/src/main/java/com/hippo/ehviewer/ui/scene/SignInScene.java b/app/src/main/java/com/hippo/ehviewer/ui/scene/SignInScene.java index bacc573f1..1ca1bcdd0 100644 --- a/app/src/main/java/com/hippo/ehviewer/ui/scene/SignInScene.java +++ b/app/src/main/java/com/hippo/ehviewer/ui/scene/SignInScene.java @@ -39,7 +39,6 @@ import com.hippo.ehviewer.client.EhUrl; import com.hippo.ehviewer.client.EhUtils; import com.hippo.ehviewer.client.parser.ProfileParser; import com.hippo.ehviewer.ui.MainActivity; -import com.hippo.ehviewer.widget.RecaptchaView; import com.hippo.scene.Announcer; import com.hippo.scene.SceneFragment; import com.hippo.util.ExceptionUtils; @@ -68,8 +67,6 @@ public final class SignInScene extends SolidScene implements EditText.OnEditorAc private EditText mUsername; @Nullable private EditText mPassword; - private EditText mRecaptcha; - private RecaptchaView mRecaptchaView; @Nullable private View mRegister; @Nullable @@ -127,8 +124,6 @@ public final class SignInScene extends SolidScene implements EditText.OnEditorAc mPasswordLayout = (TextInputLayout) ViewUtils.$$(loginForm, R.id.password_layout); mPassword = mPasswordLayout.getEditText(); AssertUtils.assertNotNull(mPassword); - mRecaptcha = (EditText) ViewUtils.$$(loginForm, R.id.recaptcha); - mRecaptchaView = (RecaptchaView) ViewUtils.$$(loginForm, R.id.recaptcha_image); mRegister = ViewUtils.$$(loginForm, R.id.register); mSignIn = ViewUtils.$$(loginForm, R.id.sign_in); mSignInViaWebView = (TextView) ViewUtils.$$(loginForm, R.id.sign_in_via_webview); @@ -284,15 +279,12 @@ public final class SignInScene extends SolidScene implements EditText.OnEditorAc // Clean up for sign in EhUtils.signOut(context); - String challenge = mRecaptchaView.getChallenge(); - String response = mRecaptcha.getText().toString(); - EhCallback callback = new SignInListener(context, activity.getStageId(), getTag()); mRequestId = ((EhApplication) context.getApplicationContext()).putGlobalStuff(callback); EhRequest request = new EhRequest() .setMethod(EhClient.METHOD_SIGN_IN) - .setArgs(username, password, challenge, response) + .setArgs(username, password) .setCallback(callback); EhApplication.getEhClient(context).execute(request); diff --git a/app/src/main/java/com/hippo/ehviewer/widget/RecaptchaView.java b/app/src/main/java/com/hippo/ehviewer/widget/RecaptchaView.java deleted file mode 100644 index 181097a6a..000000000 --- a/app/src/main/java/com/hippo/ehviewer/widget/RecaptchaView.java +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright 2017 Hippo Seven - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.hippo.ehviewer.widget; - -/* - * Created by Hippo on 2017/8/20. - */ - -import android.content.Context; -import android.graphics.Color; -import android.os.Parcel; -import android.os.Parcelable; -import android.text.TextUtils; -import android.util.AttributeSet; -import android.view.View; -import androidx.annotation.NonNull; -import com.hippo.android.recaptcha.RecaptchaV1; -import com.hippo.drawable.TextDrawable; -import com.hippo.ehviewer.R; -import com.hippo.widget.LoadImageView; -import com.hippo.yorozuya.SimpleHandler; - -public class RecaptchaView extends LoadImageView implements RecaptchaV1.RecaptchaCallback, View.OnClickListener { - - private static final String CHALLENGE = "6LdtfgYAAAAAALjIPPiCgPJJah8MhAUpnHcKF8u_"; - - private boolean loading = false; - private String challenge; - private String image; - - private TextDrawable waitingDrawable; - private TextDrawable loadingDrawable; - private TextDrawable failureDrawable; - - public RecaptchaView(Context context) { - super(context); - init(); - } - - public RecaptchaView(Context context, AttributeSet attrs) { - super(context, attrs); - init(); - } - - private void init() { - setOnClickListener(this); - if (waitingDrawable == null) { - waitingDrawable = new TextDrawable(getContext().getString(R.string.recaptcha_none), 0.6f); - waitingDrawable.setBackgroundColor(Color.GRAY); - waitingDrawable.setTextColor(Color.WHITE); - } - load(waitingDrawable); - } - - public String getChallenge() { - return challenge; - } - - public void load() { - if (loading) { - return; - } - loading = false; - challenge = null; - image = null; - - if (loadingDrawable == null) { - loadingDrawable = new TextDrawable(getContext().getString(R.string.recaptcha_loading), 0.6f); - loadingDrawable.setBackgroundColor(Color.GRAY); - loadingDrawable.setTextColor(Color.WHITE); - } - load(loadingDrawable); - - RecaptchaV1.recaptcha(getContext(), CHALLENGE, SimpleHandler.getInstance(), this); - } - - @Override - public void onClick(@NonNull View v) { - load(); - } - - @Override - public void onSuccess(@NonNull String challenge, @NonNull String image) { - this.loading = false; - this.challenge = challenge; - this.image = image; - - load(image, image); - } - - @Override - public void onFailure() { - this.loading = false; - this.challenge = null; - this.image = null; - - if (failureDrawable == null) { - failureDrawable = new TextDrawable(getContext().getString(R.string.recaptcha_failure), 0.6f); - failureDrawable.setBackgroundColor(Color.GRAY); - failureDrawable.setTextColor(Color.WHITE); - } - load(failureDrawable); - } - - @Override - protected Parcelable onSaveInstanceState() { - SavedState ss = new SavedState(super.onSaveInstanceState()); - ss.loading = loading; - ss.challenge = challenge; - ss.image = image; - return ss; - } - - @Override - protected void onRestoreInstanceState(Parcelable state) { - if (!(state instanceof SavedState)) { - super.onRestoreInstanceState(state); - return; - } - - SavedState ss = (SavedState) state; - super.onRestoreInstanceState(ss.getSuperState()); - - if (ss.loading) { - load(); - } else if (!TextUtils.isEmpty(ss.challenge) && !TextUtils.isEmpty(ss.image)) { - onSuccess(ss.challenge, ss.image); - } - } - - private static class SavedState extends BaseSavedState { - - private boolean loading; - private String challenge; - private String image; - - public SavedState(Parcelable superState) { - super(superState); - } - - @Override - public void writeToParcel(Parcel out, int flags) { - super.writeToParcel(out, flags); - out.writeByte(loading ? (byte) 1 : (byte) 0); - out.writeString(challenge); - out.writeString(image); - } - - public static final Parcelable.Creator CREATOR - = new Parcelable.Creator() { - @Override - public SavedState createFromParcel(Parcel in) { - return new SavedState(in); - } - - @Override - public SavedState[] newArray(int size) { - return new SavedState[size]; - } - }; - - public SavedState(Parcel source) { - super(source); - loading = source.readByte() != 0; - challenge = source.readString(); - image = source.readString(); - } - } -} diff --git a/app/src/main/res/layout/scene_login.xml b/app/src/main/res/layout/scene_login.xml index 89dd35ca3..37ac255c8 100644 --- a/app/src/main/res/layout/scene_login.xml +++ b/app/src/main/res/layout/scene_login.xml @@ -73,40 +73,13 @@ android:id="@+id/password" android:layout_width="match_parent" android:layout_height="wrap_content" - android:imeOptions="actionNext" + android:imeOptions="actionDone" android:inputType="textPassword" android:maxLines="1" android:singleLine="true"/> - - - - - - - -