Browse Source

Change out arrow drawable for an icon that displays current number of tabs

master
Anthony Restaino 9 years ago
parent
commit
b81d9a0ed8
  1. 89
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 21
      app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java
  3. 2
      app/src/main/java/acr/browser/lightning/browser/BrowserView.java
  4. 52
      app/src/main/java/acr/browser/lightning/utils/DrawableUtils.java
  5. 5
      app/src/main/java/acr/browser/lightning/utils/ThemeUtils.java
  6. 2
      app/src/main/java/acr/browser/lightning/utils/Utils.java

89
app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java

@ -42,7 +42,6 @@ import android.support.v4.widget.DrawerLayout.DrawerListener; @@ -42,7 +42,6 @@ import android.support.v4.widget.DrawerLayout.DrawerListener;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.graphics.Palette;
import android.support.v7.graphics.drawable.DrawerArrowDrawable;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.KeyEvent;
@ -60,7 +59,6 @@ import android.view.ViewGroup.LayoutParams; @@ -60,7 +59,6 @@ import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Transformation;
import android.view.inputmethod.EditorInfo;
@ -82,6 +80,7 @@ import android.widget.TextView; @@ -82,6 +80,7 @@ import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import android.widget.VideoView;
import com.anthonycr.grant.PermissionsManager;
import com.squareup.otto.Bus;
import com.squareup.otto.Subscribe;
@ -110,13 +109,10 @@ import acr.browser.lightning.dialog.LightningDialogBuilder; @@ -110,13 +109,10 @@ import acr.browser.lightning.dialog.LightningDialogBuilder;
import acr.browser.lightning.fragment.BookmarksFragment;
import acr.browser.lightning.fragment.TabsFragment;
import acr.browser.lightning.object.SearchAdapter;
import acr.browser.lightning.react.OnSubscribe;
import acr.browser.lightning.react.Observable;
import acr.browser.lightning.react.Schedulers;
import acr.browser.lightning.receiver.NetworkReceiver;
import com.anthonycr.grant.PermissionsManager;
import acr.browser.lightning.react.Observable;
import acr.browser.lightning.utils.DrawableUtils;
import acr.browser.lightning.utils.ProxyUtils;
import acr.browser.lightning.utils.ThemeUtils;
import acr.browser.lightning.utils.UrlUtils;
@ -201,7 +197,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -201,7 +197,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
private Bitmap mWebpageBitmap;
private final ColorDrawable mBackground = new ColorDrawable();
private Drawable mDeleteIcon, mRefreshIcon, mClearIcon, mIcon;
private DrawerArrowDrawable mArrowDrawable;
private BrowserPresenter mPresenter;
@ -319,9 +314,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -319,9 +314,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
FrameLayout arrowButton = (FrameLayout) customView.findViewById(R.id.arrow_button);
if (mShowTabsInDrawer) {
// Use hardware acceleration for the animation
mArrowDrawable = new DrawerArrowDrawable(this);
mArrowImage.setLayerType(View.LAYER_TYPE_HARDWARE, null);
mArrowImage.setImageDrawable(mArrowDrawable);
if (mArrowImage.getWidth() <= 0) {
mArrowImage.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
}
updateTabNumber(0);
} else {
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED, mDrawerLeft);
mArrowImage.setImageResource(R.drawable.ic_action_home);
@ -359,19 +356,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -359,19 +356,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath());
}
mTabsManager.initializeTabs(this, getIntent(), isIncognito())
.subscribe(new OnSubscribe<Void>() {
@Override
public void onNext(Void item) {}
@Override
public void onComplete() {
// At this point we always have at least a tab in the tab manager
showTab(mTabsManager.last());
mProxyUtils.checkForProxy(BrowserActivity.this);
}
});
mPresenter.setupTabs(getIntent(), isIncognito());
mProxyUtils.checkForProxy(BrowserActivity.this);
}
private class SearchListenerClass implements OnKeyListener, OnEditorActionListener, OnFocusChangeListener, OnTouchListener {
@ -434,55 +420,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -434,55 +420,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
mIcon = mClearIcon;
mSearch.setCompoundDrawables(null, null, mClearIcon, null);
}
final Animation anim = new Animation() {
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
if (!hasFocus) {
mArrowDrawable.setProgress(1.0f - interpolatedTime);
} else {
mArrowDrawable.setProgress(interpolatedTime);
}
}
@Override
public boolean willChangeBounds() {
return true;
}
};
anim.setDuration(300);
anim.setInterpolator(new DecelerateInterpolator());
anim.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
if (!hasFocus) {
mArrowDrawable.setProgress(0.0f);
} else {
mArrowDrawable.setProgress(1.0f);
}
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
if (mArrowDrawable != null) {
mArrowImage.startAnimation(anim);
}
}
}, 100);
if (!hasFocus) {
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
@ -1303,6 +1240,14 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1303,6 +1240,14 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
}
}
@Override
public void updateTabNumber(int number) {
if (mArrowImage != null) {
mArrowImage.setImageBitmap(DrawableUtils.getRoundedNumberImage(number, Utils.dpToPx(24),
Utils.dpToPx(24), ThemeUtils.getIconThemeColor(this, mDarkTheme), Utils.dpToPx(2)));
}
}
@Override
public void updateProgress(int n) {
setIsLoading(n < 100);

21
app/src/main/java/acr/browser/lightning/browser/BrowserPresenter.java

@ -17,6 +17,7 @@ import acr.browser.lightning.app.BrowserApp; @@ -17,6 +17,7 @@ import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.bus.BrowserEvents;
import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.react.OnSubscribe;
import acr.browser.lightning.utils.UrlUtils;
import acr.browser.lightning.view.LightningView;
@ -45,6 +46,21 @@ public class BrowserPresenter { @@ -45,6 +46,21 @@ public class BrowserPresenter {
mIsIncognito = isIncognito;
}
public void setupTabs(Intent intent, boolean isIncognito) {
mTabsModel.initializeTabs((Activity) mView, intent, isIncognito)
.subscribe(new OnSubscribe<Void>() {
@Override
public void onNext(Void item) {}
@Override
public void onComplete() {
// At this point we always have at least a tab in the tab manager
tabChanged(mTabsModel.last());
mView.updateTabNumber(mTabsModel.size());
}
});
}
private void onTabChanged(@Nullable LightningView newTab) {
Log.d(TAG, "On tab changed");
if (newTab == null) {
@ -135,6 +151,8 @@ public class BrowserPresenter { @@ -135,6 +151,8 @@ public class BrowserPresenter {
mView.closeActivity();
}
mView.updateTabNumber(mTabsModel.size());
Log.d(Constants.TAG, "deleted tab");
}
@ -195,6 +213,7 @@ public class BrowserPresenter { @@ -195,6 +213,7 @@ public class BrowserPresenter {
mView.showSnackbar(R.string.max_tabs);
return false;
}
mIsNewIntent = false;
LightningView startingTab = mTabsModel.newTab((Activity) mView, url, mIsIncognito);
if (mTabsModel.size() == 1) {
@ -214,6 +233,8 @@ public class BrowserPresenter { @@ -214,6 +233,8 @@ public class BrowserPresenter {
// }
// }, 300);
mView.updateTabNumber(mTabsModel.size());
return true;
}

2
app/src/main/java/acr/browser/lightning/browser/BrowserView.java

@ -15,6 +15,8 @@ public interface BrowserView { @@ -15,6 +15,8 @@ public interface BrowserView {
void updateProgress(int progress);
void updateTabNumber(int number);
void closeBrowser();
void closeActivity();

52
app/src/main/java/acr/browser/lightning/utils/DrawableUtils.java

@ -0,0 +1,52 @@ @@ -0,0 +1,52 @@
package acr.browser.lightning.utils;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
public class DrawableUtils {
public static Bitmap getRoundedNumberImage(int number, int width, int height, int color, int thickness) {
String text;
if (number > 99) {
text = "\u221E";
} else {
text = String.valueOf(number);
}
Bitmap image = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(image);
Paint paint = new Paint();
paint.setColor(color);
paint.setTextSize(Utils.dpToPx(14));
paint.setFakeBoldText(true);
paint.setAntiAlias(true);
paint.setTextAlign(Paint.Align.CENTER);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
int radius = Utils.dpToPx(2);
RectF outer = new RectF(0, 0, canvas.getWidth(), canvas.getHeight());
canvas.drawRoundRect(outer, radius, radius, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
radius--;
RectF inner = new RectF(thickness, thickness, canvas.getWidth() - thickness, canvas.getHeight() - thickness);
canvas.drawRoundRect(inner, radius, radius, paint);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
int xPos = (canvas.getWidth() / 2);
int yPos = (int) ((canvas.getHeight() / 2) - ((paint.descent() + paint.ascent()) / 2));
canvas.drawText(String.valueOf(text), xPos, yPos, paint);
return image;
}
}

5
app/src/main/java/acr/browser/lightning/utils/ThemeUtils.java

@ -54,6 +54,11 @@ public class ThemeUtils { @@ -54,6 +54,11 @@ public class ThemeUtils {
return ContextCompat.getColor(context, R.color.icon_dark_theme);
}
@ColorInt
public static int getIconThemeColor(@NonNull Context context, boolean dark) {
return (dark) ? getIconDarkThemeColor(context) : getIconLightThemeColor(context);
}
public static void themeImageView(@NonNull ImageView icon, @NonNull Context context, boolean dark) {
int color = dark ? getIconDarkThemeColor(context) : getIconLightThemeColor(context);
icon.setColorFilter(color, PorterDuff.Mode.SRC_IN);

2
app/src/main/java/acr/browser/lightning/utils/Utils.java

@ -157,7 +157,7 @@ public final class Utils { @@ -157,7 +157,7 @@ public final class Utils {
* @param dp the number of density pixels to convert.
* @return the number of pixels that the conversion generates.
*/
public static int dpToPx(int dp) {
public static int dpToPx(float dp) {
DisplayMetrics metrics = Resources.getSystem().getDisplayMetrics();
return (int) (dp * metrics.density + 0.5f);
}

Loading…
Cancel
Save