Skip to content

Commit

Permalink
增加ClickableImageView控件
Browse files Browse the repository at this point in the history
  • Loading branch information
wecodexyz committed Oct 27, 2017
1 parent 54e5e19 commit 52c188b
Show file tree
Hide file tree
Showing 16 changed files with 187 additions and 38 deletions.
20 changes: 0 additions & 20 deletions app/src/main/java/net/angrycode/componentization/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,9 @@

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

import net.angrycode.core.network.SimpleTextRequest;
import net.angrycode.data.*;
import net.angrycode.data.repository.Data;
import net.angrycode.data.repository.RepositoryFactory;
import net.angrycode.data.repository.local.LocalRepository;
import net.angrycode.data.repository.remote.RemoteRepository;
import net.angrycode.toolkit.view.SimpleDrawingView;

import org.reactivestreams.Publisher;

import java.util.List;
import java.util.concurrent.Callable;

import io.reactivex.Flowable;
import io.reactivex.Scheduler;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;
import io.reactivex.schedulers.Schedulers;

public class MainActivity extends AppCompatActivity {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package net.angrycode.core.network;

import android.content.Context;

import java.io.File;

import okhttp3.MediaType;
import okhttp3.MultipartBody;
import okhttp3.RequestBody;

/**
* Created by wecodexyz@gmail.com on 2017/10/26 上午11:07.
* GitHub - https://github.com/wecodexyz
* Description:
*/

public abstract class BaseMultipartRequest<T> extends RequestWrapper {
private static final MediaType MEDIA_TYPE_PNG = MediaType.parse("image/png");

public BaseMultipartRequest(Context context) {
super(context);
}

protected RequestBody requestBody() {
MultipartBody.Builder builder = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addPart(super.requestBody())
.addFormDataPart(getName(), getFileName(),
RequestBody.create(MEDIA_TYPE_PNG, new File(getFilePath())));
return builder.build();
}

protected abstract String getFilePath();

protected abstract String getName();

protected abstract String getFileName();

@Override
public HttpMethod getHttpMethod() {
return HttpMethod.POST;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ public boolean isSupportCache() {

protected abstract T onRequestError(int code, String message);

public interface OnRequestCallback<T> {
void callback(T t);

void onError(Exception e);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package net.angrycode.core.network;

public interface OnRequestCallback<T> {
void callback(T t);

void onError(Exception e);
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import okhttp3.FormBody;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.MultipartBody;
import okhttp3.OkHttpClient;
import okhttp3.RequestBody;
import okhttp3.Response;
Expand Down Expand Up @@ -78,19 +79,20 @@ public Pair<Integer, String> doRequest() {
} else {
result = new Pair<>(response.code(), response.message());
}
Log.d("Network", "request url - " + getUrlWithParams());
Log.d("Network", "response json - " + result.second);

} catch (IOException e) {
Log.e("Network", "" + e.getMessage());
Log.d(TAG, "" + e.getMessage());
}
Log.d(TAG, "request url - " + getUrlWithParams());
Log.d(TAG, "response result - " + result.second);
return result;
}

public boolean isSuccessful(int code) {
return code >= 200 && code < 300;
}

private RequestBody requestBody() {
protected RequestBody requestBody() {
FormBody.Builder builder = new FormBody.Builder();
for (String key : mParams.keySet()) {
builder.add(key, mParams.get(key));
Expand All @@ -111,7 +113,9 @@ public void setProxy(String host, int port) {
mProxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port));
}

public @Nullable Context getContext() {
public
@Nullable
Context getContext() {
return mContextRef.get();
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/net/angrycode/toolkit/PhoneUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
public class PhoneUtils {
/**
* <uses-permission android:name="android.permission.CALL_PHONE" />
*
* do not use it
* @param context
* @param phoneNumber
*/
public static void call(Context context, String phoneNumber) {
private static void call(Context context, String phoneNumber) {
Intent callIntent = new Intent(Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:" + phoneNumber));
if (callIntent.resolveActivity(context.getPackageManager()) != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.angrycode.toolkit.view;
package net.angrycode.toolkit.widget;

import android.content.Context;
import android.content.res.TypedArray;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package net.angrycode.toolkit.widget;

import android.content.Context;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.support.v7.widget.AppCompatImageView;
import android.util.AttributeSet;
import android.view.MotionEvent;


/**
* Created by wecodexyz@gmail.com on 2017/10/27 上午11:29.
* GitHub - https://github.com/wecodexyz
* Description:
*/

public class ClickableImageView extends AppCompatImageView {

private int mColorSelected;
private int mColorTransparent;

public ClickableImageView(Context context) {
super(context);
init();
}

public ClickableImageView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}

public ClickableImageView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}

private void init() {
setClickable(true);
mColorSelected = Color.parseColor("#33555555");
mColorTransparent = Color.TRANSPARENT;
}

@Override
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction()) {
case MotionEvent.ACTION_DOWN:
setColorFilter(mColorSelected, PorterDuff.Mode.SRC_ATOP);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_HOVER_MOVE:
case MotionEvent.ACTION_CANCEL:
setColorFilter(mColorTransparent, PorterDuff.Mode.SRC_ATOP);
break;
}
return super.onTouchEvent(event);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.angrycode.toolkit.view;
package net.angrycode.toolkit.widget;

import android.app.Activity;
import android.content.Context;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.angrycode.toolkit.view;
package net.angrycode.toolkit.widget;

import android.content.Context;
import android.graphics.Color;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.angrycode.toolkit.view;
package net.angrycode.toolkit.widget;

import android.content.Context;
import android.content.res.TypedArray;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.angrycode.toolkit.view;
package net.angrycode.toolkit.widget;

import android.annotation.TargetApi;
import android.content.Context;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.angrycode.toolkit.view;
package net.angrycode.toolkit.widget;

import android.text.Editable;
import android.text.TextWatcher;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package net.angrycode.toolkit.widget;

import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.ImageView;

import net.angrycode.core.R;


/**
* https://gist.github.com/tylerchesley/5d15d859be4f3ce31213
*/
public class TintableImageView extends ImageView {

private ColorStateList tint;

public TintableImageView(Context context) {
super(context);
}

public TintableImageView(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs, 0);
}

public TintableImageView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
init(context, attrs, defStyle);
}

private void init(Context context, AttributeSet attrs, int defStyle) {
TypedArray a = context.obtainStyledAttributes(
attrs, R.styleable.TintableImageView, defStyle, 0);
tint = a.getColorStateList(
R.styleable.TintableImageView_tintColor);
a.recycle();
}

@Override
protected void drawableStateChanged() {
super.drawableStateChanged();
if (tint != null && tint.isStateful()) {
updateTintColor();
}
}

public void setColorFilter(ColorStateList tint) {
this.tint = tint;
super.setColorFilter(tint.getColorForState(getDrawableState(), 0));
}

private void updateTintColor() {
int color = tint.getColorForState(getDrawableState(), 0);
setColorFilter(color);
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package net.angrycode.toolkit.view;
package net.angrycode.toolkit.widget;

import android.app.Activity;
import android.content.Context;
Expand Down
3 changes: 3 additions & 0 deletions core/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@
<!--清除按钮图标-->
<attr name="quickClearIcon" format="reference" />
</declare-styleable>
<declare-styleable name="TintableImageView">
<attr name="tintColor" format="reference|color" />
</declare-styleable>
</resources>

0 comments on commit 52c188b

Please sign in to comment.