Browse Source

Bugfixes, code clean up

master
Anthony Restaino 10 years ago
parent
commit
8c29cb4450
  1. 44
      src/acr/browser/lightning/BrowserActivity.java
  2. 14
      src/acr/browser/lightning/SearchAdapter.java

44
src/acr/browser/lightning/BrowserActivity.java

@ -18,6 +18,7 @@ import android.database.sqlite.SQLiteException;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorMatrix; import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter; import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint; import android.graphics.Paint;
@ -75,7 +76,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
private DrawerLayout mDrawerLayout; private DrawerLayout mDrawerLayout;
private ListView mDrawerListLeft, mDrawerListRight; private ListView mDrawerListLeft, mDrawerListRight;
private LinearLayout mDrawerLeft, mDrawerRight, mPageLayout, mUiLayout, mToolbarLayout; private LinearLayout mDrawerLeft, mDrawerRight, mUiLayout, mToolbarLayout;
private RelativeLayout mNewTab, mSearchBar; private RelativeLayout mNewTab, mSearchBar;
private List<LightningView> mWebViews = new ArrayList<LightningView>(); private List<LightningView> mWebViews = new ArrayList<LightningView>();
private LightningView mCurrentView; private LightningView mCurrentView;
@ -114,6 +115,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
private static LayoutParams mMatchParent = new LayoutParams(LayoutParams.MATCH_PARENT, private static LayoutParams mMatchParent = new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT); LayoutParams.MATCH_PARENT);
private BookmarkManager mBookmarkManager; private BookmarkManager mBookmarkManager;
private ColorDrawable mBackground = new ColorDrawable();
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -125,7 +127,6 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private synchronized void initialize() { private synchronized void initialize() {
setContentView(R.layout.activity_main); setContentView(R.layout.activity_main);
getWindow().setBackgroundDrawable(null);
mToolbar = (Toolbar) findViewById(R.id.toolbar); mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar); setSupportActionBar(mToolbar);
@ -149,7 +150,14 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
mClickHandler = new ClickHandler(this); mClickHandler = new ClickHandler(this);
mBrowserFrame = (FrameLayout) findViewById(R.id.content_frame); mBrowserFrame = (FrameLayout) findViewById(R.id.content_frame);
mToolbarLayout = (LinearLayout) findViewById(R.id.toolbar_layout); mToolbarLayout = (LinearLayout) findViewById(R.id.toolbar_layout);
mPageLayout = (LinearLayout) findViewById(R.id.main_layout); // initialize background ColorDrawable
mBackground.setColor(((ColorDrawable) mToolbarLayout.getBackground()).getColor());
LinearLayout background = (LinearLayout) findViewById(R.id.main_layout);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
background.setBackground(null);
} else {
background.setBackgroundDrawable(null);
}
mUiLayout = (LinearLayout) findViewById(R.id.ui_layout); mUiLayout = (LinearLayout) findViewById(R.id.ui_layout);
mProgressBar = (AnimatedProgressBar) findViewById(R.id.progress_view); mProgressBar = (AnimatedProgressBar) findViewById(R.id.progress_view);
mNewTab = (RelativeLayout) findViewById(R.id.new_tab_button); mNewTab = (RelativeLayout) findViewById(R.id.new_tab_button);
@ -1429,12 +1437,14 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
Paint paint; Paint paint;
int layoutResourceId; int layoutResourceId;
List<LightningView> data = null; List<LightningView> data = null;
CloseTabListener mExitListener;
public LightningViewAdapter(Context context, int layoutResourceId, List<LightningView> data) { public LightningViewAdapter(Context context, int layoutResourceId, List<LightningView> data) {
super(context, layoutResourceId, data); super(context, layoutResourceId, data);
this.layoutResourceId = layoutResourceId; this.layoutResourceId = layoutResourceId;
this.context = context; this.context = context;
this.data = data; this.data = data;
this.mExitListener = new CloseTabListener();
} }
@Override @Override
@ -1455,14 +1465,8 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
holder = (LightningViewHolder) row.getTag(); holder = (LightningViewHolder) row.getTag();
} }
holder.exit.setOnClickListener(new OnClickListener() { holder.exit.setTag(position);
holder.exit.setOnClickListener(mExitListener);
@Override
public void onClick(View view) {
deleteTab(position);
}
});
ViewCompat.jumpDrawablesToCurrentState(holder.exit); ViewCompat.jumpDrawablesToCurrentState(holder.exit);
@ -1500,15 +1504,21 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
} }
class LightningViewHolder { class LightningViewHolder {
TextView txtTitle; TextView txtTitle;
ImageView favicon; ImageView favicon;
ImageView exit; ImageView exit;
} }
} }
private class CloseTabListener implements OnClickListener{
@Override
public void onClick(View v) {
deleteTab((int) v.getTag());
}
}
private void changeToolbarBackground(Bitmap favicon) { private void changeToolbarBackground(Bitmap favicon) {
android.support.v7.graphics.Palette.generateAsync(favicon, android.support.v7.graphics.Palette.generateAsync(favicon,
new android.support.v7.graphics.Palette.PaletteAsyncListener() { new android.support.v7.graphics.Palette.PaletteAsyncListener() {
@ -1529,16 +1539,16 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
finalColor = color; finalColor = color;
} }
ColorDrawable draw = (ColorDrawable) mPageLayout.getBackground();
ValueAnimator anim = ValueAnimator.ofObject(new ArgbEvaluator(), ValueAnimator anim = ValueAnimator.ofObject(new ArgbEvaluator(),
draw.getColor(), finalColor); mBackground.getColor(), finalColor);
anim.addUpdateListener(new AnimatorUpdateListener() { anim.addUpdateListener(new AnimatorUpdateListener() {
@Override @Override
public void onAnimationUpdate(ValueAnimator animation) { public void onAnimationUpdate(ValueAnimator animation) {
int color = (Integer) animation.getAnimatedValue(); int color = (Integer) animation.getAnimatedValue();
mPageLayout.setBackgroundColor(color); mBackground.setColor(color);
getWindow().setBackgroundDrawable(mBackground);
mToolbarLayout.setBackgroundColor(color); mToolbarLayout.setBackgroundColor(color);
} }

14
src/acr/browser/lightning/SearchAdapter.java

@ -53,11 +53,10 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
private BookmarkManager mBookmarkManager; private BookmarkManager mBookmarkManager;
private static final String ENCODING = "ISO-8859-1"; private static final String ENCODING = "ISO-8859-1";
private static final long INTERVAL_DAY = 86400000; private static final long INTERVAL_DAY = 86400000;
private XmlPullParserFactory mFactory;
private XmlPullParser mXpp;
private String mSearchSubtitle; private String mSearchSubtitle;
private static final int API = Build.VERSION.SDK_INT; private static final int API = Build.VERSION.SDK_INT;
private Theme mTheme; private Theme mTheme;
private SearchFilter mFilter;
public SearchAdapter(Context context, boolean dark) { public SearchAdapter(Context context, boolean dark) {
mDatabaseHandler = HistoryDatabase.getInstance(context); mDatabaseHandler = HistoryDatabase.getInstance(context);
@ -213,7 +212,10 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
@Override @Override
public Filter getFilter() { public Filter getFilter() {
return new SearchFilter(); if (mFilter == null) {
mFilter = new SearchFilter();
}
return mFilter;
} }
public class SearchFilter extends Filter { public class SearchFilter extends Filter {
@ -268,16 +270,16 @@ public class SearchAdapter extends BaseAdapter implements Filterable {
} }
private class SuggestionHolder { private class SuggestionHolder {
ImageView mImage; ImageView mImage;
TextView mTitle; TextView mTitle;
TextView mUrl; TextView mUrl;
} }
private class RetrieveSearchSuggestions extends AsyncTask<String, Void, List<HistoryItem>> { private class RetrieveSearchSuggestions extends AsyncTask<String, Void, List<HistoryItem>> {
private XmlPullParserFactory mFactory;
private XmlPullParser mXpp;
@Override @Override
protected List<HistoryItem> doInBackground(String... arg0) { protected List<HistoryItem> doInBackground(String... arg0) {
mIsExecuting = true; mIsExecuting = true;

Loading…
Cancel
Save