Skip to content
This repository has been archived by the owner on Feb 25, 2022. It is now read-only.

Commit

Permalink
Add guide for double click toolbar to refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
seven332 committed Sep 28, 2015
1 parent 9a9b9ce commit b923232
Show file tree
Hide file tree
Showing 12 changed files with 223 additions and 370 deletions.
109 changes: 109 additions & 0 deletions app/src/main/java/com/hippo/drawable/RoundRectDrawable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Copyright (C) 2014 The Android Open Source Project
*
* 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;

import android.annotation.TargetApi;
import android.graphics.Canvas;
import android.graphics.ColorFilter;
import android.graphics.Outline;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.NonNull;

/**
* Very simple drawable that draws a rounded rectangle background with arbitrary corners and also
* reports proper outline for L.
* <p>
* Simpler and uses less resources compared to GradientDrawable or ShapeDrawable.
*/
public class RoundRectDrawable extends Drawable {

private float mRadius;
private final Paint mPaint;
private final RectF mBoundsF;
private final Rect mBoundsI;

public RoundRectDrawable(int backgroundColor, float radius) {
mRadius = radius;
mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
mPaint.setColor(backgroundColor);
mBoundsF = new RectF();
mBoundsI = new Rect();
}

@Override
public void draw(Canvas canvas) {
canvas.drawRoundRect(mBoundsF, mRadius, mRadius, mPaint);
}

private void updateBounds(Rect bounds) {
if (bounds == null) {
bounds = getBounds();
}
mBoundsF.set(bounds.left, bounds.top, bounds.right, bounds.bottom);
mBoundsI.set(bounds);
}

@Override
protected void onBoundsChange(Rect bounds) {
super.onBoundsChange(bounds);
updateBounds(bounds);
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void getOutline(@NonNull Outline outline) {
outline.setRoundRect(mBoundsI, mRadius);
}

void setRadius(float radius) {
if (radius == mRadius) {
return;
}
mRadius = radius;
updateBounds(null);
invalidateSelf();
}

@Override
public void setAlpha(int alpha) {
// not supported because older versions do not support
}

@Override
public void setColorFilter(ColorFilter cf) {
// not supported because older versions do not support
}

@Override
public int getOpacity() {
return PixelFormat.TRANSLUCENT;
}

public float getRadius() {
return mRadius;
}

public void setColor(int color) {
mPaint.setColor(color);
invalidateSelf();
}
}
29 changes: 7 additions & 22 deletions app/src/main/java/com/hippo/nimingban/GuideHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,9 @@ public static class Builder {

private Activity mActivity;
private int mPadding;
private int mGesture;
private int mColor;
private int mGravity = Gravity.NO_GRAVITY;
private int mX;
private int mY;
@GuideView.MessagePosition
private int mMessagePosition = Gravity.TOP;
private int mBackgroundColor;
private CharSequence mMessage;
private CharSequence mButton;
Expand All @@ -59,29 +57,18 @@ public Builder setPadding(int padding) {
return this;
}

public Builder setGesture(int gesture) {
mGesture = gesture;
return this;
}

public Builder setColor(int color) {
mColor = color;
return this;
}

public Builder setGesturePosition(int gravity) {
mGravity = gravity;
return this;
}

public Builder setGesturePosition(int x, int y) {
mX = x;
mY = y;
public Builder setBackgroundColor(int backgroundColor) {
mBackgroundColor = backgroundColor;
return this;
}

public Builder setBackgroundColor(int backgroundColor) {
mBackgroundColor = backgroundColor;
public Builder setMessagePosition(@GuideView.MessagePosition int position) {
mMessagePosition = position;
return this;
}

Expand All @@ -103,12 +90,10 @@ public Builder setOnDissmisListener(View.OnClickListener listener) {
public void show() {
ViewGroup parent = getParent(mActivity);
GuideView guideView = new GuideView(mActivity);
guideView.setGesture(mGesture);
guideView.setColor(mColor);
guideView.setPadding(mPadding, mPadding, mPadding, mPadding);
guideView.setGesturePosition(mGravity);
guideView.setGesturePosition(mX, mY);
guideView.setBackgroundColor(mBackgroundColor);
guideView.setMessagePosition(mMessagePosition);
guideView.setMessage(mMessage);
guideView.setButton(mButton);
guideView.setOnDissmisListener(mOnDissmisListener);
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/com/hippo/nimingban/NMBApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ private void update() throws PackageManager.NameNotFoundException {
if (oldVersionCode < 6) {
updateCookies(this);
}

if (oldVersionCode < 14) {
Settings.putGuideListActivity(true);
}
}

public static void updateCookies(Context context) {
Expand Down
28 changes: 21 additions & 7 deletions app/src/main/java/com/hippo/nimingban/ui/ListActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@
import com.hippo.nimingban.util.ReadableTime;
import com.hippo.nimingban.util.Settings;
import com.hippo.nimingban.widget.ContentLayout;
import com.hippo.nimingban.widget.GestureView;
import com.hippo.nimingban.widget.LeftDrawer;
import com.hippo.nimingban.widget.LoadImageView;
import com.hippo.nimingban.widget.RightDrawer;
Expand Down Expand Up @@ -293,12 +292,12 @@ public void onDrawerOpened(View view) {

private void showLeftDrawerGuide() {
new GuideHelper.Builder(this)
.setGesture(GestureView.GESTURE_SWIPE_RIGHT)
.setColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimary))
.setGesturePosition(Gravity.LEFT | Gravity.CENTER_VERTICAL)
.setPadding(LayoutUtils.dp2pix(this, 16))
.setMessagePosition(Gravity.LEFT)
.setMessage(getString(R.string.swipe_right_open_menu))
.setButton(getString(R.string.get_it))
.setBackgroundColor(0x73000000)
.setOnDissmisListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand All @@ -309,19 +308,34 @@ public void onClick(View v) {

private void showRightDrawerGuide() {
new GuideHelper.Builder(this)
.setGesture(GestureView.GESTURE_SWIPE_LEFT)
.setColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimary))
.setGesturePosition(Gravity.RIGHT | Gravity.CENTER_VERTICAL)
.setPadding(LayoutUtils.dp2pix(this, 16))
.setMessagePosition(Gravity.RIGHT)
.setMessage(getString(R.string.swipe_left_open_forum_list))
.setButton(getString(R.string.get_it))
.setBackgroundColor(0x73000000)
.setOnDissmisListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showToolbarGuide();
}
}).show();
}

private void showToolbarGuide() {
new GuideHelper.Builder(this)
.setColor(ResourcesUtils.getAttrColor(this, R.attr.colorPrimary))
.setPadding(LayoutUtils.dp2pix(this, 16))
.setMessagePosition(Gravity.TOP)
.setMessage(getString(R.string.double_click_toolbar_refresh))
.setButton(getString(R.string.get_it))
.setBackgroundColor(0x73000000)
.setOnDissmisListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Settings.putGuideListActivity(false);
}
})
.show();
}).show();
}

@Override
Expand Down
149 changes: 0 additions & 149 deletions app/src/main/java/com/hippo/nimingban/widget/GestureView.java

This file was deleted.

Loading

0 comments on commit b923232

Please sign in to comment.