diff --git a/res/layout/test_gallery_list_detail_thumb.xml b/res/layout/test_gallery_list_detail_thumb.xml new file mode 100644 index 000000000..58287b7e0 --- /dev/null +++ b/res/layout/test_gallery_list_detail_thumb.xml @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + diff --git a/src/com/hippo/ehviewer/ui/GalleryListActivity.java b/src/com/hippo/ehviewer/ui/GalleryListActivity.java index caf956c0d..7e809a383 100644 --- a/src/com/hippo/ehviewer/ui/GalleryListActivity.java +++ b/src/com/hippo/ehviewer/ui/GalleryListActivity.java @@ -88,6 +88,7 @@ import com.hippo.ehviewer.util.Favorite; import com.hippo.ehviewer.util.Theme; import com.hippo.ehviewer.util.Ui; import com.hippo.ehviewer.util.Utils; +import com.hippo.ehviewer.util.ViewUtils; import com.hippo.ehviewer.widget.AlertButton; import com.hippo.ehviewer.widget.CategoryTable; import com.hippo.ehviewer.widget.LoadImageView; @@ -119,14 +120,13 @@ import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu; * getList */ - /** * Make sure when getting list pulllistview is refreshing * * @author Hippo */ -public class GalleryListActivity extends AbsGalleryActivity - implements View.OnClickListener, SearchView.OnQueryTextListener, +public class GalleryListActivity extends AbsGalleryActivity implements + View.OnClickListener, SearchView.OnQueryTextListener, SearchView.OnFocusChangeListener, SlidingMenu.OnOpenedListener, SlidingMenu.OnClosedListener, EhClient.OnLoginListener { @@ -199,11 +199,15 @@ public class GalleryListActivity extends AbsGalleryActivity private final DownloadServiceConnection mServiceConn = new DownloadServiceConnection(); private int mListMode; - //private int mListModeThumbHeight; + + private int mListDetailThumbWidth; + private int mListDetailThumbHeight; + + // private int mListModeThumbHeight; private void toRegister() { Uri uri = Uri.parse("http://forums.e-hentai.org/index.php?act=Reg"); - Intent intent = new Intent(Intent.ACTION_VIEW,uri); + Intent intent = new Intent(Intent.ACTION_VIEW, uri); startActivity(intent); } @@ -247,8 +251,7 @@ public class GalleryListActivity extends AbsGalleryActivity View view = inflater.inflate(R.layout.login, null); return new MaterialAlertDialog.Builder(this).setCancelable(false) - .setTitle(R.string.login) - .setView(view, true) + .setTitle(R.string.login).setView(view, true) .setPositiveButton(android.R.string.ok) .setNegativeButton(android.R.string.cancel) .setNeutralButton(R.string.register) @@ -258,9 +261,14 @@ public class GalleryListActivity extends AbsGalleryActivity switch (which) { case MaterialAlertDialog.POSITIVE: setUserPanel(WAIT); - String username = ((EditText) loginDialog.findViewById(R.id.username)).getText().toString(); - String password = ((EditText) loginDialog.findViewById(R.id.password)).getText().toString(); - mClient.login(username, password, GalleryListActivity.this); + String username = ((EditText) loginDialog + .findViewById(R.id.username)).getText() + .toString(); + String password = ((EditText) loginDialog + .findViewById(R.id.password)).getText() + .toString(); + mClient.login(username, password, + GalleryListActivity.this); return true; case MaterialAlertDialog.NEGATIVE: setUserPanel(); @@ -278,15 +286,16 @@ public class GalleryListActivity extends AbsGalleryActivity @SuppressLint("InflateParams") private AlertDialog createModeDialog() { - LayoutInflater inflater = (LayoutInflater) getSystemService( - Context.LAYOUT_INFLATER_SERVICE); + LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View cv = inflater.inflate(R.layout.select_mode, null); final Spinner modeSpinner = (Spinner) cv.findViewById(R.id.mode_list); modeSpinner.setSelection(Config.getMode()); - final Spinner apiModeSpinner = (Spinner) cv.findViewById(R.id.api_mode_list); + final Spinner apiModeSpinner = (Spinner) cv + .findViewById(R.id.api_mode_list); apiModeSpinner.setSelection(Config.getApiMode()); - final Spinner lofiResolutionSpinner = (Spinner) cv.findViewById(R.id.lofi_resolution_list); + final Spinner lofiResolutionSpinner = (Spinner) cv + .findViewById(R.id.lofi_resolution_list); lofiResolutionSpinner.setSelection(Config.getLofiResolution() - 1); return new MaterialAlertDialog.Builder(this).setTitle(R.string.mode) @@ -296,9 +305,12 @@ public class GalleryListActivity extends AbsGalleryActivity @Override public boolean onClick(MaterialAlertDialog dialog, int which) { if (which == MaterialAlertDialog.POSITIVE) { - Config.setMode(modeSpinner.getSelectedItemPosition()); - Config.setApiMode(apiModeSpinner.getSelectedItemPosition()); - Config.setLofiResolution(lofiResolutionSpinner.getSelectedItemPosition() + 1); + Config.setMode(modeSpinner + .getSelectedItemPosition()); + Config.setApiMode(apiModeSpinner + .getSelectedItemPosition()); + Config.setLofiResolution(lofiResolutionSpinner + .getSelectedItemPosition() + 1); } return true; } @@ -309,7 +321,8 @@ public class GalleryListActivity extends AbsGalleryActivity protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); - if (requestCode == RESULT_LOAD_SEARCH_IMAGE && resultCode == RESULT_OK && null != data) { + if (requestCode == RESULT_LOAD_SEARCH_IMAGE && resultCode == RESULT_OK + && null != data) { Uri selectedImage = data.getData(); String[] filePathColumn = { MediaStore.Images.Media.DATA }; @@ -328,25 +341,28 @@ public class GalleryListActivity extends AbsGalleryActivity } private void handleSearchView(View view) { - final SuggestionTextView pet = (SuggestionTextView)view.findViewById(R.id.search_text); + final SuggestionTextView pet = (SuggestionTextView) view + .findViewById(R.id.search_text); pet.setSuggestionHelper(mSuggestions); - CheckBox uploaderCb = (CheckBox)view.findViewById(R.id.checkbox_uploader); - uploaderCb.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() { - @Override - public void onCheckedChanged(CompoundButton buttonView, - boolean isChecked) { - if (isChecked) { - pet.setPrefix("uploader:"); - pet.setSuggestionHelper(null); - } else { - pet.setPrefix(null); - pet.setSuggestionHelper(mSuggestions); - } - } - }); + CheckBox uploaderCb = (CheckBox) view + .findViewById(R.id.checkbox_uploader); + uploaderCb + .setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() { + @Override + public void onCheckedChanged(CompoundButton buttonView, + boolean isChecked) { + if (isChecked) { + pet.setPrefix("uploader:"); + pet.setSuggestionHelper(null); + } else { + pet.setPrefix(null); + pet.setSuggestionHelper(mSuggestions); + } + } + }); final View advance = view.findViewById(R.id.filter_advance); - CheckBox cb = (CheckBox)view.findViewById(R.id.checkbox_advance); + CheckBox cb = (CheckBox) view.findViewById(R.id.checkbox_advance); cb.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, @@ -362,7 +378,8 @@ public class GalleryListActivity extends AbsGalleryActivity selectImage.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { - Intent i = new Intent(Intent.ACTION_PICK, + Intent i = new Intent( + Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(i, RESULT_LOAD_SEARCH_IMAGE); } @@ -376,17 +393,19 @@ public class GalleryListActivity extends AbsGalleryActivity final View searchNormal = view.findViewById(R.id.search_normal); final View searchTag = view.findViewById(R.id.search_tag); final View searchImage = view.findViewById(R.id.search_image); - mSearchImageText = (TextView)view.findViewById(R.id.target_image); + mSearchImageText = (TextView) view.findViewById(R.id.target_image); handleSearchView(view); - return new MaterialAlertDialog.Builder(this).setTitle(android.R.string.search_go) - .setView(view, true).setActionButton(R.string.mode) + return new MaterialAlertDialog.Builder(this) + .setTitle(android.R.string.search_go).setView(view, true) + .setActionButton(R.string.mode) .setPositiveButton(android.R.string.ok) .setNegativeButton(android.R.string.cancel) .setNeutralButton(R.string.add) .setButtonListener(new MaterialAlertDialog.OnClickListener() { @Override - public boolean onClick(final MaterialAlertDialog dialog, int which) { + public boolean onClick(final MaterialAlertDialog dialog, + int which) { switch (which) { case MaterialAlertDialog.ACTION: if (searchNormal.getVisibility() == View.VISIBLE) { @@ -411,7 +430,7 @@ public class GalleryListActivity extends AbsGalleryActivity // Get title String search = lus.getSearch(); - switch(lus.getMode()) { + switch (lus.getMode()) { case ListUrls.MODE_IMAGE_SEARCH: mTitle = getString(R.string.image_search); break; @@ -436,17 +455,20 @@ public class GalleryListActivity extends AbsGalleryActivity case MaterialAlertDialog.NEUTRAL: if (searchImage.getVisibility() == View.VISIBLE) return false; - createSetNameDialog(null, null, new OnSetNameListener() { - @Override - public void onSetVaildName(String newName) { - mData.addTag(new Tag(newName, getLus(mSearchDialog))); - listMenuTag.add(newName); - tagsAdapter.addId(newName); - tagsAdapter.notifyDataSetChanged(); + createSetNameDialog(null, null, + new OnSetNameListener() { + @Override + public void onSetVaildName( + String newName) { + mData.addTag(new Tag(newName, + getLus(mSearchDialog))); + listMenuTag.add(newName); + tagsAdapter.addId(newName); + tagsAdapter.notifyDataSetChanged(); - dialog.dismiss(); - } - }).show(); + dialog.dismiss(); + } + }).show(); return false; default: return true; @@ -471,15 +493,16 @@ public class GalleryListActivity extends AbsGalleryActivity CategoryTable ct = (CategoryTable) view .findViewById(R.id.category_table); type = ct.getCategory(); - EditText et = (EditText)view.findViewById(R.id.search_text); + EditText et = (EditText) view.findViewById(R.id.search_text); lus = new ListUrls(type, et.getText().toString()); - CheckBox uploaderCb = (CheckBox)view.findViewById(R.id.checkbox_uploader); + CheckBox uploaderCb = (CheckBox) view + .findViewById(R.id.checkbox_uploader); if (uploaderCb.isChecked()) { lus.setMode(ListUrls.MODE_UPLOADER); } - CheckBox cb = (CheckBox)view.findViewById(R.id.checkbox_advance); + CheckBox cb = (CheckBox) view.findViewById(R.id.checkbox_advance); if (cb.isChecked()) { CheckBox checkImageSname = (CheckBox) view .findViewById(R.id.checkbox_sname); @@ -528,13 +551,13 @@ public class GalleryListActivity extends AbsGalleryActivity // For tag search } else if (searchTag.getVisibility() == View.VISIBLE) { - EditText et = (EditText)view.findViewById(R.id.search_tag_text); + EditText et = (EditText) view.findViewById(R.id.search_tag_text); lus = new ListUrls(); lus.setTag(et.getText().toString()); // For image search } else if (searchImage.getVisibility() == View.VISIBLE) { - String filePath = (String)mSearchImageText.getText(); + String filePath = (String) mSearchImageText.getText(); File file = new File(filePath); if (!file.exists()) { MaterialToast.showToast(R.string.image_not_exist); @@ -543,14 +566,22 @@ public class GalleryListActivity extends AbsGalleryActivity MaterialToast.showToast(R.string.image_not_readable); } else { - CheckBox similar = (CheckBox)view.findViewById(R.id.checkboxSimilar); - CheckBox covers = (CheckBox)view.findViewById(R.id.checkboxCovers); - CheckBox exp = (CheckBox)view.findViewById(R.id.checkboxExp); + CheckBox similar = (CheckBox) view + .findViewById(R.id.checkboxSimilar); + CheckBox covers = (CheckBox) view + .findViewById(R.id.checkboxCovers); + CheckBox exp = (CheckBox) view + .findViewById(R.id.checkboxExp); lus = new ListUrls(); - lus.setSearchFile(file, (similar.isChecked() ? EhClient.IMAGE_SEARCH_USE_SIMILARITY_SCAN : 0) | - (covers.isChecked() ? EhClient.IMAGE_SEARCH_ONLY_SEARCH_COVERS : 0) | - (exp.isChecked() ? EhClient.IMAGE_SEARCH_SHOW_EXPUNGED : 0)); + lus.setSearchFile( + file, + (similar.isChecked() ? EhClient.IMAGE_SEARCH_USE_SIMILARITY_SCAN + : 0) + | (covers.isChecked() ? EhClient.IMAGE_SEARCH_ONLY_SEARCH_COVERS + : 0) + | (exp.isChecked() ? EhClient.IMAGE_SEARCH_SHOW_EXPUNGED + : 0)); } } } @@ -559,38 +590,48 @@ public class GalleryListActivity extends AbsGalleryActivity } private AlertDialog createLongClickDialog() { - return new MaterialAlertDialog.Builder(this).setTitle(R.string.what_to_do) - .setItems(R.array.list_item_long_click, new MaterialAlertDialog.OnClickListener() { - @Override - public boolean onClick(MaterialAlertDialog dialog, int position) { - final GalleryInfo gi = getGalleryInfo(longClickItemIndex); - switch (position) { - case 0: // Add favourite item - Favorite.addToFavorite(GalleryListActivity.this, gi); - break; - case 1: - Intent it = new Intent(GalleryListActivity.this, DownloadService.class); - startService(it); - mServiceConn.getService().add(gi); - MaterialToast.showToast(R.string.toast_add_download); - break; - } - return true; - } - }).setNegativeButton(android.R.string.cancel).create(); + return new MaterialAlertDialog.Builder(this) + .setTitle(R.string.what_to_do) + .setItems(R.array.list_item_long_click, + new MaterialAlertDialog.OnClickListener() { + @Override + public boolean onClick(MaterialAlertDialog dialog, + int position) { + final GalleryInfo gi = getGalleryInfo(longClickItemIndex); + switch (position) { + case 0: // Add favourite item + Favorite.addToFavorite( + GalleryListActivity.this, gi); + break; + case 1: + Intent it = new Intent( + GalleryListActivity.this, + DownloadService.class); + startService(it); + mServiceConn.getService().add(gi); + MaterialToast + .showToast(R.string.toast_add_download); + break; + } + return true; + } + }).setNegativeButton(android.R.string.cancel).create(); } @SuppressLint("InflateParams") private AlertDialog createJumpDialog() { LayoutInflater inflater = this.getLayoutInflater(); View view = inflater.inflate(R.layout.jump, null); - TextView tv = (TextView)view.findViewById(R.id.list_jump_sum); + TextView tv = (TextView) view.findViewById(R.id.list_jump_sum); // For lofi, can not get page num, so use Integer.MAX_VALUE - tv.setText(String.format(getString(R.string.jump_summary), getCurPage() + 1, - getPageNum() == Integer.MAX_VALUE ? getString(R.string._unknown) : String.valueOf(getPageNum()))); - tv = (TextView)view.findViewById(R.id.list_jump_to); + tv.setText(String + .format(getString(R.string.jump_summary), + getCurPage() + 1, + getPageNum() == Integer.MAX_VALUE ? getString(R.string._unknown) + : String.valueOf(getPageNum()))); + tv = (TextView) view.findViewById(R.id.list_jump_to); tv.setText(R.string.jump_to); - final EditText et = (EditText)view.findViewById(R.id.list_jump_edit); + final EditText et = (EditText) view.findViewById(R.id.list_jump_edit); return new MaterialAlertDialog.Builder(this).setTitle(R.string.jump) .setView(view, true).setPositiveButton(android.R.string.ok) @@ -600,12 +641,15 @@ public class GalleryListActivity extends AbsGalleryActivity public boolean onClick(MaterialAlertDialog dialog, int which) { if (which == MaterialAlertDialog.POSITIVE) { int targetPage; - try{ - targetPage = Integer.parseInt(et.getText().toString()) - 1; - if (targetPage < 0 || targetPage >= getPageNum()) + try { + targetPage = Integer.parseInt(et.getText() + .toString()) - 1; + if (targetPage < 0 + || targetPage >= getPageNum()) throw new Exception(); - } catch(Exception e) { - MaterialToast.showToast(R.string.toast_invalid_page); + } catch (Exception e) { + MaterialToast + .showToast(R.string.toast_invalid_page); return false; } jumpTo(targetPage); @@ -624,15 +668,19 @@ public class GalleryListActivity extends AbsGalleryActivity /** * Create a set name dialog * - * @param hint Text to set in edittext first - * @param oldStr string can be oldstr, even it is in listMenuTitle - * @param listener what to do when set right text + * @param hint + * Text to set in edittext first + * @param oldStr + * string can be oldstr, even it is in listMenuTitle + * @param listener + * what to do when set right text */ @SuppressLint("InflateParams") - private AlertDialog createSetNameDialog(final String hint, final String oldStr, final OnSetNameListener listener) { + private AlertDialog createSetNameDialog(final String hint, + final String oldStr, final OnSetNameListener listener) { LayoutInflater inflater = this.getLayoutInflater(); View view = inflater.inflate(R.layout.set_name, null); - final EditText et = (EditText)view.findViewById(R.id.set_name_edit); + final EditText et = (EditText) view.findViewById(R.id.set_name_edit); if (hint != null) et.setText(hint); @@ -645,10 +693,13 @@ public class GalleryListActivity extends AbsGalleryActivity if (which == MaterialAlertDialog.POSITIVE) { String key = et.getText().toString(); if (key.length() == 0) { - MaterialToast.showToast(R.string.tag_name_empty); + MaterialToast + .showToast(R.string.tag_name_empty); return false; - } else if (listMenuTag.contains(key) && !key.equals(oldStr)) { - MaterialToast.showToast(R.string.tag_name_empty); + } else if (listMenuTag.contains(key) + && !key.equals(oldStr)) { + MaterialToast + .showToast(R.string.tag_name_empty); return false; } else { if (listener != null) { @@ -674,14 +725,16 @@ public class GalleryListActivity extends AbsGalleryActivity ListUrls listUrls = mData.getTag(position); setFilterView(view, listUrls); - return new MaterialAlertDialog.Builder(this).setTitle(listMenuTag.get(position)) - .setView(view, true).setActionButton(R.string.mode) + return new MaterialAlertDialog.Builder(this) + .setTitle(listMenuTag.get(position)).setView(view, true) + .setActionButton(R.string.mode) .setPositiveButton(android.R.string.ok) .setNegativeButton(android.R.string.cancel) .setNeutralButton(R.string.tag_change_name) .setButtonListener(new MaterialAlertDialog.OnClickListener() { @Override - public boolean onClick(final MaterialAlertDialog dialog, int which) { + public boolean onClick(final MaterialAlertDialog dialog, + int which) { switch (which) { case MaterialAlertDialog.ACTION: if (searchNormal.getVisibility() == View.GONE) { @@ -697,28 +750,44 @@ public class GalleryListActivity extends AbsGalleryActivity case MaterialAlertDialog.POSITIVE: ListUrls listUrls = getLus(view); if (newTagName != null) { - mData.setTag(position, new Tag(newTagName, listUrls)); - tagsAdapter.set(listMenuTag.get(position), newTagName); + mData.setTag(position, new Tag(newTagName, + listUrls)); + tagsAdapter.set(listMenuTag.get(position), + newTagName); listMenuTag.set(position, newTagName); tagsAdapter.notifyDataSetChanged(); newTagName = null; } else { - mData.setTag(position, new Tag(listMenuTag.get(position), listUrls)); + mData.setTag(position, + new Tag(listMenuTag.get(position), + listUrls)); } return true; case MaterialAlertDialog.NEUTRAL: - String hint = newTagName == null ? listMenuTag.get(position) : newTagName; - createSetNameDialog(hint, listMenuTag.get(position), new OnSetNameListener(){ - @Override - public void onSetVaildName(String newName) { - if (newName.equals(listMenuTag.get(position))) { // If new is old name - dialog.setTitle(listMenuTag.get(position)); - } else { - newTagName = newName; - dialog.setTitle(String.format(getString(R.string.new_tag_name), newTagName)); - } - } - }).show(); + String hint = newTagName == null ? listMenuTag + .get(position) : newTagName; + createSetNameDialog(hint, + listMenuTag.get(position), + new OnSetNameListener() { + @Override + public void onSetVaildName( + String newName) { + if (newName.equals(listMenuTag + .get(position))) { // If + // new + // is + // old + // name + dialog.setTitle(listMenuTag + .get(position)); + } else { + newTagName = newName; + dialog.setTitle(String + .format(getString(R.string.new_tag_name), + newTagName)); + } + } + }).show(); return false; case MaterialAlertDialog.NEGATIVE: default: @@ -737,7 +806,7 @@ public class GalleryListActivity extends AbsGalleryActivity searchNormal.setVisibility(View.GONE); searchTag.setVisibility(View.VISIBLE); - EditText et = (EditText)view.findViewById(R.id.search_tag_text); + EditText et = (EditText) view.findViewById(R.id.search_tag_text); et.setText(listUrls.getTag()); } else { searchNormal.setVisibility(View.VISIBLE); @@ -748,11 +817,11 @@ public class GalleryListActivity extends AbsGalleryActivity .findViewById(R.id.category_table); ct.setCategory(category); - EditText et = (EditText)view.findViewById(R.id.search_text); + EditText et = (EditText) view.findViewById(R.id.search_text); et.setText(listUrls.getSearch()); // Advance - CheckBox cb = (CheckBox)view.findViewById(R.id.checkbox_advance); + CheckBox cb = (CheckBox) view.findViewById(R.id.checkbox_advance); cb.setChecked(listUrls.isAdvance()); CheckBox checkImageSname = (CheckBox) view @@ -842,24 +911,25 @@ public class GalleryListActivity extends AbsGalleryActivity public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); if (mShowDrawer) - mSlidingMenu.setBehindWidth( - mResources.getDimensionPixelOffset(R.dimen.menu_width)); + mSlidingMenu.setBehindWidth(mResources + .getDimensionPixelOffset(R.dimen.menu_width)); else mSlidingMenu.setBehindWidth(0); } /** * Get + * * @param intent */ private void handleIntent(Intent intent) { String action = intent != null ? intent.getAction() : null; if (Intent.ACTION_SEARCH.equals(action)) { - String query = intent.getStringExtra(SearchManager.QUERY); - mSearchView.setQuery(query, true); + String query = intent.getStringExtra(SearchManager.QUERY); + mSearchView.setQuery(query, true); } else if (ACTION_GALLERY_LIST.equals(action)) { int mode = intent.getIntExtra(GalleryListActivity.KEY_MODE, -1); - switch(mode) { + switch (mode) { case ListUrls.MODE_TAG: lus = new ListUrls(); String tag = intent.getStringExtra(KEY_TAG); @@ -869,7 +939,8 @@ public class GalleryListActivity extends AbsGalleryActivity break; case ListUrls.MODE_UPLOADER: - String uploader = "uploader:" + intent.getStringExtra(KEY_UPLOADER); + String uploader = "uploader:" + + intent.getStringExtra(KEY_UPLOADER); lus = new ListUrls(ListUrls.ALL_CATEGORT, uploader); lus.setMode(ListUrls.MODE_UPLOADER); mTitle = uploader; @@ -887,7 +958,8 @@ public class GalleryListActivity extends AbsGalleryActivity case ListUrls.MODE_NORMAL: // Target is category - int category = intent.getIntExtra(KEY_CATEGORY, ListUrls.ALL_CATEGORT); + int category = intent.getIntExtra(KEY_CATEGORY, + ListUrls.ALL_CATEGORT); lus = new ListUrls(category); mTitle = Ui.getCategoryText(category); setTitle(mTitle); @@ -954,10 +1026,21 @@ public class GalleryListActivity extends AbsGalleryActivity mResources = getResources(); mWindowsAnimate = new WindowsAnimate(); mWindowsAnimate.init(this); - mSuggestions = SuggestionHelper.getInstance ( - GalleryListActivity.this, SimpleSuggestionProvider.AUTHORITY, + mSuggestions = SuggestionHelper.getInstance(GalleryListActivity.this, + SimpleSuggestionProvider.AUTHORITY, SimpleSuggestionProvider.MODE); + // Caculate gallery detail height + LayoutInflater inflater = LayoutInflater.from(this); + View v = inflater + .inflate(R.layout.test_gallery_list_detail_thumb, null); + ((TextView) v.findViewById(R.id.title)).setText("haha\nhaha"); + ((TextView) v.findViewById(R.id.uploader)).setText("haha"); + ((RatingView) v.findViewById(R.id.rate)).setRating(2.3f); + ((TextView) v.findViewById(R.id.category)).setText("haha"); + ViewUtils.measureView(v); + v.getMeasuredHeight(); + handleIntent(getIntent()); // Check show drawer or not if (ACTION_GALLERY_LIST.equals(getIntent().getAction())) @@ -977,8 +1060,8 @@ public class GalleryListActivity extends AbsGalleryActivity mSlidingMenu.setOnOpenedListener(this); mSlidingMenu.setOnClosedListener(this); if (mShowDrawer) - mSlidingMenu.setBehindWidth( - mResources.getDimensionPixelOffset(R.dimen.menu_width)); + mSlidingMenu.setBehindWidth(mResources + .getDimensionPixelOffset(R.dimen.menu_width)); else mSlidingMenu.setBehindWidth(0); @@ -993,17 +1076,17 @@ public class GalleryListActivity extends AbsGalleryActivity // Get View mMenuLeft = findViewById(R.id.list_menu_left); - mUserPanel = (LinearLayout)findViewById(R.id.user_panel); + mUserPanel = (LinearLayout) findViewById(R.id.user_panel); itemListMenu = (ListView) findViewById(R.id.list_menu_item_list); tagListMenu = (TagListView) findViewById(R.id.list_menu_tag_list); - avatar = (ImageView)mUserPanel.findViewById(R.id.avatar); - userView = (TextView)mUserPanel.findViewById(R.id.user); - loginButton = (Button)mUserPanel.findViewById(R.id.login); - registerButton = (Button)mUserPanel.findViewById(R.id.register); - logoutButton = (Button)mUserPanel.findViewById(R.id.logout); + avatar = (ImageView) mUserPanel.findViewById(R.id.avatar); + userView = (TextView) mUserPanel.findViewById(R.id.user); + loginButton = (Button) mUserPanel.findViewById(R.id.login); + registerButton = (Button) mUserPanel.findViewById(R.id.register); + logoutButton = (Button) mUserPanel.findViewById(R.id.logout); waitloginoutView = mUserPanel.findViewById(R.id.wait); mQuickSearchTip = findViewById(R.id.tip_text); - mStaggeredGridView = (StaggeredGridView)getContentView(); + mStaggeredGridView = (StaggeredGridView) getContentView(); loginButton.setOnClickListener(this); registerButton.setOnClickListener(this); @@ -1013,29 +1096,31 @@ public class GalleryListActivity extends AbsGalleryActivity // Drawer ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); - if (mShowDrawer && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) - actionBar.setHomeAsUpIndicator(mResources.getDrawable(R.drawable.ic_navigation_drawer)); + if (mShowDrawer + && Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) + actionBar.setHomeAsUpIndicator(mResources + .getDrawable(R.drawable.ic_navigation_drawer)); // leftDrawer - final int[] data = {R.drawable.ic_action_home, R.string.homepage, + final int[] data = { R.drawable.ic_action_home, R.string.homepage, R.drawable.ic_action_panda, R.string.mode, R.drawable.ic_action_search, android.R.string.search_go, R.drawable.ic_action_favorite, R.string.favourite, R.drawable.ic_action_popular, R.string.popular, R.drawable.ic_setting_download, R.string.download, - R.drawable.ic_action_settings, R.string.action_settings}; + R.drawable.ic_action_settings, R.string.action_settings }; itemListMenu.setSelector(new ColorDrawable(Color.TRANSPARENT)); itemListMenu.setClipToPadding(false); itemListMenu.setAdapter(new BaseAdapter() { @Override public int getCount() { - return data.length/2; + return data.length / 2; } @Override public Object getItem(int position) { - return new int[]{data[position * 2], data[position * 2 + 1]}; + return new int[] { data[position * 2], data[position * 2 + 1] }; } @Override @@ -1047,9 +1132,11 @@ public class GalleryListActivity extends AbsGalleryActivity public View getView(int position, View convertView, ViewGroup parent) { TextView tv; if (convertView == null) { - tv = (TextView)LayoutInflater.from(GalleryListActivity.this).inflate(R.layout.menu_item, parent, false); + tv = (TextView) LayoutInflater.from( + GalleryListActivity.this).inflate( + R.layout.menu_item, parent, false); } else { - tv = (TextView)convertView; + tv = (TextView) convertView; } Drawable d = mResources.getDrawable(data[position * 2]); d.setBounds(0, 0, Ui.dp2pix(36), Ui.dp2pix(36)); @@ -1116,15 +1203,16 @@ public class GalleryListActivity extends AbsGalleryActivity for (int i = 0; i < keys.size(); i++) listMenuTag.add(keys.get(i)); tagsAdapter = new TagsAdapter(this, R.layout.menu_tag, listMenuTag); - tagsAdapter.setOnDataSetChangedListener(new TagsAdapter.OnDataSetChangedListener() { - @Override - public void OnDataSetChanged() { - if (listMenuTag.size() == 0) - mQuickSearchTip.setVisibility(View.VISIBLE); - else - mQuickSearchTip.setVisibility(View.GONE); - } - }); + tagsAdapter + .setOnDataSetChangedListener(new TagsAdapter.OnDataSetChangedListener() { + @Override + public void OnDataSetChanged() { + if (listMenuTag.size() == 0) + mQuickSearchTip.setVisibility(View.VISIBLE); + else + mQuickSearchTip.setVisibility(View.GONE); + } + }); if (listMenuTag.size() == 0) mQuickSearchTip.setVisibility(View.VISIBLE); else @@ -1143,7 +1231,7 @@ public class GalleryListActivity extends AbsGalleryActivity setTitle(mTitle); } }); - tagListMenu.setOnModifyListener(new TagListView.OnModifyListener(){ + tagListMenu.setOnModifyListener(new TagListView.OnModifyListener() { @Override public void onModify(int position) { createModifyTagDialog(position).show(); @@ -1183,18 +1271,20 @@ public class GalleryListActivity extends AbsGalleryActivity startActivity(intent); } }); - mStaggeredGridView.setOnItemLongClickListener(new OnItemLongClickListener() { - @Override - public boolean onItemLongClick(AdapterView arg0, View arg1, - int position, long arg3) { - longClickItemIndex = position; - longClickDialog.show(); - return true; - } - }); + mStaggeredGridView + .setOnItemLongClickListener(new OnItemLongClickListener() { + @Override + public boolean onItemLongClick(AdapterView arg0, + View arg1, int position, long arg3) { + longClickItemIndex = position; + longClickDialog.show(); + return true; + } + }); // Set random color - int color = Config.getRandomThemeColor() ? Theme.getRandomDarkColor() : Config.getThemeColor(); + int color = Config.getRandomThemeColor() ? Theme.getRandomDarkColor() + : Config.getThemeColor(); color = color & 0x00ffffff | 0xdd000000; Drawable drawable = new ColorDrawable(color); actionBar = getActionBar(); @@ -1236,12 +1326,11 @@ public class GalleryListActivity extends AbsGalleryActivity } String country = Locale.getDefault().getCountry(); - if (Config.getTraditionalChineseWarning() && - (country.equals("HK") || country.equals("TW"))) { + if (Config.getTraditionalChineseWarning() + && (country.equals("HK") || country.equals("TW"))) { Config.setTraditionalChineseWarning(false); new MaterialAlertDialog.Builder(this).setTitle("注意") - .setMessage("正體中文的翻譯由 OpenCC 自動完成,若有任何錯誤或不妥之處歡迎指出。") - .show(); + .setMessage("正體中文的翻譯由 OpenCC 自動完成,若有任何錯誤或不妥之處歡迎指出。").show(); } } @@ -1253,8 +1342,10 @@ public class GalleryListActivity extends AbsGalleryActivity mStaggeredGridView.setColumnCountLandscape(2); break; case LIST_MODE_THUMB: - mStaggeredGridView.setColumnCountPortrait(Config.getListThumbColumnsPortrait()); - mStaggeredGridView.setColumnCountLandscape(Config.getListThumbColumnsLandscape()); + mStaggeredGridView.setColumnCountPortrait(Config + .getListThumbColumnsPortrait()); + mStaggeredGridView.setColumnCountLandscape(Config + .getListThumbColumnsLandscape()); } } } @@ -1263,12 +1354,14 @@ public class GalleryListActivity extends AbsGalleryActivity public void onOrientationChanged(int paddingTop, int paddingBottom) { mUserPanel.setPadding(mUserPanel.getPaddingLeft(), paddingTop, mUserPanel.getPaddingRight(), mUserPanel.getPaddingBottom()); - itemListMenu.setPadding(itemListMenu.getPaddingLeft(), itemListMenu.getPaddingTop(), - itemListMenu.getPaddingRight(), paddingBottom); + itemListMenu.setPadding(itemListMenu.getPaddingLeft(), + itemListMenu.getPaddingTop(), itemListMenu.getPaddingRight(), + paddingBottom); tagListMenu.setPadding(tagListMenu.getPaddingLeft(), paddingTop, tagListMenu.getPaddingRight(), paddingBottom); - mStaggeredGridView.setPadding(mStaggeredGridView.getPaddingLeft(), paddingTop, - mStaggeredGridView.getPaddingRight(), paddingBottom); + mStaggeredGridView + .setPadding(mStaggeredGridView.getPaddingLeft(), paddingTop, + mStaggeredGridView.getPaddingRight(), paddingBottom); } @Override @@ -1306,78 +1399,91 @@ public class GalleryListActivity extends AbsGalleryActivity @Override public boolean onCreateOptionsMenu(Menu menu) { // Do not show menu when mSlidingMenu is shown - if (mSlidingMenu!= null && mSlidingMenu.isMenuShowing()) + if (mSlidingMenu != null && mSlidingMenu.isMenuShowing()) return true; getMenuInflater().inflate(R.menu.main, menu); - SearchManager searchManager = - (SearchManager) getSystemService(Context.SEARCH_SERVICE); + SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); mSearchItem = menu.findItem(R.id.action_search); mSearchView = (SearchView) mSearchItem.getActionView(); - mSearchView.setSearchableInfo( - searchManager.getSearchableInfo(getComponentName())); + mSearchView.setSearchableInfo(searchManager + .getSearchableInfo(getComponentName())); mSearchView.setOnQueryTextListener(this); mSearchView.setOnQueryTextFocusChangeListener(this); // Make search view custom look - int searchTextID = mResources.getIdentifier("android:id/search_src_text", null, null); + int searchTextID = mResources.getIdentifier( + "android:id/search_src_text", null, null); AutoCompleteTextView searchText = null; if (searchTextID > 0 - && (searchText = (AutoCompleteTextView)mSearchView.findViewById(searchTextID)) != null) { + && (searchText = (AutoCompleteTextView) mSearchView + .findViewById(searchTextID)) != null) { - int searchCursorID = mResources.getIdentifier("android:drawable/text_cursor_holo_dark", null, null); + int searchCursorID = mResources.getIdentifier( + "android:drawable/text_cursor_holo_dark", null, null); if (searchCursorID > 0) { try { Field f = Class.forName("android.widget.TextView") .getDeclaredField("mCursorDrawableRes"); f.setAccessible(true); f.setInt(searchText, searchCursorID); - } catch (Exception e) {} + } catch (Exception e) { + } } searchText.setTextColor(Color.WHITE); searchText.setHintTextColor(Color.WHITE); - Drawable searchImage = mResources.getDrawable(R.drawable.ic_action_search); + Drawable searchImage = mResources + .getDrawable(R.drawable.ic_action_search); if (searchImage != null) { SpannableStringBuilder ssb = new SpannableStringBuilder(" "); ssb.append(getString(R.string.advance_search_left)); int textSize = (int) (searchText.getTextSize() * 1.25); searchImage.setBounds(0, 0, textSize, textSize); - ssb.setSpan(new ImageSpan(searchImage), 1, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + ssb.setSpan(new ImageSpan(searchImage), 1, 2, + Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); searchText.setHint(ssb); } } - int plateViewID = mResources.getIdentifier("android:id/search_plate", null, null); + int plateViewID = mResources.getIdentifier("android:id/search_plate", + null, null); View plateView = null; if (plateViewID > 0 && (plateView = mSearchView.findViewById(plateViewID)) != null) { plateView.setBackgroundResource(R.drawable.textfield_searchview); } - int plateRightViewID = mResources.getIdentifier("android:id/submit_area", null, null); + int plateRightViewID = mResources.getIdentifier( + "android:id/submit_area", null, null); View plateRightView = null; if (plateRightViewID > 0 && (plateRightView = mSearchView.findViewById(plateRightViewID)) != null) { - plateRightView.setBackgroundResource(R.drawable.textfield_searchview_right); + plateRightView + .setBackgroundResource(R.drawable.textfield_searchview_right); } - int closeViewID = mResources.getIdentifier("android:id/search_close_btn", null, null); + int closeViewID = mResources.getIdentifier( + "android:id/search_close_btn", null, null); ImageView closeView = null; Drawable closeImage = mResources.getDrawable(R.drawable.ic_clear); if (closeViewID > 0 - && (closeView = (ImageView)mSearchView.findViewById(closeViewID)) != null + && (closeView = (ImageView) mSearchView + .findViewById(closeViewID)) != null && closeImage != null) { closeView.setImageDrawable(closeImage); } - int voiceViewID = mResources.getIdentifier("android:id/search_voice_btn", null, null); + int voiceViewID = mResources.getIdentifier( + "android:id/search_voice_btn", null, null); ImageView voiceView = null; - Drawable voiceImage = mResources.getDrawable(R.drawable.ic_voice_search); + Drawable voiceImage = mResources + .getDrawable(R.drawable.ic_voice_search); if (voiceViewID > 0 - && (voiceView = (ImageView)mSearchView.findViewById(voiceViewID)) != null + && (voiceView = (ImageView) mSearchView + .findViewById(voiceViewID)) != null && voiceImage != null) { voiceView.setImageDrawable(voiceImage); } @@ -1460,35 +1566,51 @@ public class GalleryListActivity extends AbsGalleryActivity } private void checkUpdate() { - new UpdateHelper((AppContext)getApplication()) - .SetOnCheckUpdateListener(new UpdateHelper.OnCheckUpdateListener() { - @Override - public void onSuccess(String version, long size, - final String url, final String fileName, String info) { - String sizeStr = Utils.sizeToString(size); - AlertDialog dialog = SuperDialogUtil.createUpdateDialog(GalleryListActivity.this, - version, sizeStr, info, - new View.OnClickListener() { + new UpdateHelper((AppContext) getApplication()) + .SetOnCheckUpdateListener( + new UpdateHelper.OnCheckUpdateListener() { @Override - public void onClick(View v) { - ((AlertButton)v).dialog.dismiss(); - HttpHelper hh = new HttpHelper(GalleryListActivity.this); - hh.downloadInThread(url, new File(Config.getDownloadPath()), fileName, false, null, - new UpdateHelper.UpdateListener(GalleryListActivity.this, fileName)); + public void onSuccess(String version, long size, + final String url, final String fileName, + String info) { + String sizeStr = Utils.sizeToString(size); + AlertDialog dialog = SuperDialogUtil + .createUpdateDialog( + GalleryListActivity.this, + version, sizeStr, info, + new View.OnClickListener() { + @Override + public void onClick(View v) { + ((AlertButton) v).dialog + .dismiss(); + HttpHelper hh = new HttpHelper( + GalleryListActivity.this); + hh.downloadInThread( + url, + new File( + Config.getDownloadPath()), + fileName, + false, + null, + new UpdateHelper.UpdateListener( + GalleryListActivity.this, + fileName)); + } + }); + if (!GalleryListActivity.this.isFinishing()) + dialog.show(); } - }); - if (!GalleryListActivity.this.isFinishing()) - dialog.show(); - } - @Override - public void onNoUpdate() { - UpdateHelper.setEnabled(true); - } - @Override - public void onFailure(String eMsg) { - UpdateHelper.setEnabled(true); - } - }).autoCheckUpdate(); + + @Override + public void onNoUpdate() { + UpdateHelper.setEnabled(true); + } + + @Override + public void onFailure(String eMsg) { + UpdateHelper.setEnabled(true); + } + }).autoCheckUpdate(); } private static final int LOGIN = 0x0; @@ -1546,60 +1668,81 @@ public class GalleryListActivity extends AbsGalleryActivity if (url == null) { // No result url if (lus.getSearchFile() == null) { - ImageLoader.getInstance(GalleryListActivity.this).add(lus.getSearchImageUrl(), - lus.getSearchImageKey(), new ImageLoader.OnGetImageListener() { - @Override - public void onGetImage(String key, Bitmap bmp) { - if (bmp != null) { - mClient.getGListFromImageSearch(bmp, lus.getImageSearchMode(), taskStamp, - new EhClient.OnGetGListFromImageSearchListener() { - @Override - public void onSuccess( - Object checkFlag, - List giList, - int maxPage, String newUrl) { + ImageLoader.getInstance(GalleryListActivity.this).add( + lus.getSearchImageUrl(), lus.getSearchImageKey(), + new ImageLoader.OnGetImageListener() { + @Override + public void onGetImage(String key, Bitmap bmp) { + if (bmp != null) { + mClient.getGListFromImageSearch( + bmp, + lus.getImageSearchMode(), + taskStamp, + new EhClient.OnGetGListFromImageSearchListener() { + @Override + public void onSuccess( + Object checkFlag, + List giList, + int maxPage, + String newUrl) { - System.out.println(giList.size()); + System.out.println(giList + .size()); - lus.setSearchResult(newUrl); - listener.onSuccess(mAdapter, taskStamp, giList, maxPage); - } - @Override - public void onFailure( - Object checkFlag, - String eMsg) { - listener.onFailure(mAdapter, taskStamp, eMsg); // TODO - } - }); - } else { - listener.onFailure(mAdapter, taskStamp, "~~~~~~~~~~"); // TODO - } - } - }); + lus.setSearchResult(newUrl); + listener.onSuccess( + mAdapter, + taskStamp, + giList, maxPage); + } + + @Override + public void onFailure( + Object checkFlag, + String eMsg) { + listener.onFailure( + mAdapter, + taskStamp, eMsg); // TODO + } + }); + } else { + listener.onFailure(mAdapter, taskStamp, + "~~~~~~~~~~"); // TODO + } + } + }); } else { // File search - mClient.getGListFromImageSearch(lus.getSearchFile(), lus.getImageSearchMode(), taskStamp, + mClient.getGListFromImageSearch(lus.getSearchFile(), + lus.getImageSearchMode(), taskStamp, new EhClient.OnGetGListFromImageSearchListener() { - @Override - public void onSuccess(Object checkFlag, List giList, - int maxPage, String newUrl) { - lus.setSearchResult(newUrl); - listener.onSuccess(mAdapter, taskStamp, giList, maxPage); - } - @Override - public void onFailure(Object checkFlag, String eMsg) { - listener.onFailure(mAdapter, taskStamp, eMsg); - } - }); + @Override + public void onSuccess(Object checkFlag, + List giList, int maxPage, + String newUrl) { + lus.setSearchResult(newUrl); + listener.onSuccess(mAdapter, taskStamp, + giList, maxPage); + } + + @Override + public void onFailure(Object checkFlag, + String eMsg) { + listener.onFailure(mAdapter, taskStamp, + eMsg); + } + }); } } else { // Get result url mClient.getGList(url, null, new EhClient.OnGetGListListener() { @Override - public void onSuccess(Object checkFlag, List lmdArray, - int pageNum) { - listener.onSuccess(mAdapter, taskStamp, lmdArray, pageNum); + public void onSuccess(Object checkFlag, + List lmdArray, int pageNum) { + listener.onSuccess(mAdapter, taskStamp, lmdArray, + pageNum); } + @Override public void onFailure(Object checkFlag, String eMsg) { listener.onFailure(mAdapter, taskStamp, eMsg); @@ -1610,12 +1753,15 @@ public class GalleryListActivity extends AbsGalleryActivity mClient.getPopular(new EhClient.OnGetPopularListener() { @Override public void onSuccess(List gis, long timeStamp) { - listener.onSuccess(mAdapter, taskStamp, gis, gis.size() == 0 ? 0 : 1); + listener.onSuccess(mAdapter, taskStamp, gis, + gis.size() == 0 ? 0 : 1); // Show update time if (timeStamp != -1 && Config.getShowPopularUpdateTime()) - MaterialToast.showToast(String.format(getString(R.string.popular_update_time), + MaterialToast.showToast(String.format( + getString(R.string.popular_update_time), Utils.sDate.format(timeStamp))); } + @Override public void onFailure(String eMsg) { listener.onFailure(mAdapter, taskStamp, eMsg); @@ -1624,10 +1770,11 @@ public class GalleryListActivity extends AbsGalleryActivity } else { mClient.getGList(url, null, new EhClient.OnGetGListListener() { @Override - public void onSuccess(Object checkFlag, List lmdArray, - int pageNum) { + public void onSuccess(Object checkFlag, + List lmdArray, int pageNum) { listener.onSuccess(mAdapter, taskStamp, lmdArray, pageNum); } + @Override public void onFailure(Object checkFlag, String eMsg) { listener.onFailure(mAdapter, taskStamp, eMsg); @@ -1652,17 +1799,19 @@ public class GalleryListActivity extends AbsGalleryActivity public ListAdapter(Context context, List gilist) { mGiList = gilist; - mImageLoader =ImageLoader.getInstance(GalleryListActivity.this); + mImageLoader = ImageLoader.getInstance(GalleryListActivity.this); } @Override public int getCount() { return mGiList.size(); } + @Override public Object getItem(int position) { return mGiList == null ? 0 : mGiList.get(position); } + @Override public long getItemId(int position) { return position; @@ -1670,51 +1819,64 @@ public class GalleryListActivity extends AbsGalleryActivity @Override public View getView(int position, View convertView, ViewGroup parent) { - GalleryInfo gi= mGiList.get(position); + GalleryInfo gi = mGiList.get(position); - if (convertView == null || - (mListMode == LIST_MODE_DETAIL && convertView.getId() != R.id.gallery_list_detail) || - (mListMode == LIST_MODE_THUMB && convertView.getId() != R.id.gallery_list_thumb)) { + if (convertView == null + || (mListMode == LIST_MODE_DETAIL && convertView.getId() != R.id.gallery_list_detail) + || (mListMode == LIST_MODE_THUMB && convertView.getId() != R.id.gallery_list_thumb)) { // Get new view ViewHolder viewHolder = new ViewHolder(); switch (mListMode) { case LIST_MODE_DETAIL: convertView = LayoutInflater.from(GalleryListActivity.this) - .inflate(R.layout.gallery_list_detail_item, parent, false); - CardViewSalon.reformWithShadow(convertView, new int[][]{ - new int[]{android.R.attr.state_pressed}, - new int[]{android.R.attr.state_activated}, - new int[]{}}, - new int[]{0xff84cae4, 0xff33b5e5, 0xFFFAFAFA}, null, false); // TODO - viewHolder.thumb = (LoadImageView)convertView.findViewById(R.id.thumb); - viewHolder.category = (TextView)convertView.findViewById(R.id.category); - viewHolder.simpleLanguage = (TextView)convertView.findViewById(R.id.simple_language); - viewHolder.title = (TextView)convertView.findViewById(R.id.title); - viewHolder.uploader = (TextView)convertView.findViewById(R.id.uploader); - viewHolder.rate = (RatingView)convertView.findViewById(R.id.rate); - viewHolder.posted = (TextView) convertView.findViewById(R.id.posted); + .inflate(R.layout.gallery_list_detail_item, parent, + false); + CardViewSalon.reformWithShadow(convertView, new int[][] { + new int[] { android.R.attr.state_pressed }, + new int[] { android.R.attr.state_activated }, + new int[] {} }, new int[] { 0xff84cae4, 0xff33b5e5, + 0xFFFAFAFA }, null, false); // TODO + viewHolder.thumb = (LoadImageView) convertView + .findViewById(R.id.thumb); + viewHolder.category = (TextView) convertView + .findViewById(R.id.category); + viewHolder.simpleLanguage = (TextView) convertView + .findViewById(R.id.simple_language); + viewHolder.title = (TextView) convertView + .findViewById(R.id.title); + viewHolder.uploader = (TextView) convertView + .findViewById(R.id.uploader); + viewHolder.rate = (RatingView) convertView + .findViewById(R.id.rate); + viewHolder.posted = (TextView) convertView + .findViewById(R.id.posted); convertView.setTag(viewHolder); break; case LIST_MODE_THUMB: convertView = LayoutInflater.from(GalleryListActivity.this) - .inflate(R.layout.gallery_list_thumb_item, parent, false); + .inflate(R.layout.gallery_list_thumb_item, parent, + false); TileSalon.reform(convertView, 0xFFFAFAFA); // TODO - viewHolder.thumb = (LoadImageView)convertView.findViewById(R.id.thumb); - viewHolder.category = (TextView)convertView.findViewById(R.id.category); - viewHolder.simpleLanguage = (TextView)convertView.findViewById(R.id.simple_language); + viewHolder.thumb = (LoadImageView) convertView + .findViewById(R.id.thumb); + viewHolder.category = (TextView) convertView + .findViewById(R.id.category); + viewHolder.simpleLanguage = (TextView) convertView + .findViewById(R.id.simple_language); convertView.setTag(viewHolder); break; } } - ViewHolder viewHolder = (ViewHolder)convertView.getTag(); + ViewHolder viewHolder = (ViewHolder) convertView.getTag(); final LoadImageView thumb = viewHolder.thumb; if (!String.valueOf(gi.gid).equals(thumb.getKey())) { // Set new thumb thumb.setImageDrawable(null); thumb.setLoadInfo(gi.thumb, String.valueOf(gi.gid)); mImageLoader.add(gi.thumb, String.valueOf(gi.gid), - new LoadImageView.SimpleImageGetListener(thumb).setFixScaleType(true)); + new LoadImageView.SimpleImageGetListener(thumb) + .setFixScaleType(true)); } // Set category TextView category = viewHolder.category; diff --git a/src/com/hippo/ehviewer/util/ViewUtils.java b/src/com/hippo/ehviewer/util/ViewUtils.java index 58ad83f83..d8789528f 100644 --- a/src/com/hippo/ehviewer/util/ViewUtils.java +++ b/src/com/hippo/ehviewer/util/ViewUtils.java @@ -20,6 +20,7 @@ import android.graphics.Bitmap; import android.graphics.Canvas; import android.view.MotionEvent; import android.view.View; +import android.view.View.MeasureSpec; import android.view.ViewGroup; import android.view.ViewParent; @@ -45,7 +46,8 @@ public final class ViewUtils { */ public static void getLocationInWindow(View view, int[] location) { if (location == null || location.length < 2) { - throw new IllegalArgumentException("location must be an array of two integers"); + throw new IllegalArgumentException( + "location must be an array of two integers"); } float[] position = new float[2]; @@ -55,7 +57,7 @@ public final class ViewUtils { ViewParent viewParent = view.getParent(); while (viewParent instanceof View) { - view = (View)viewParent; + view = (View) viewParent; if (view.getId() == android.R.id.content) { break; } @@ -67,7 +69,7 @@ public final class ViewUtils { position[1] += view.getTop(); viewParent = view.getParent(); - } + } location[0] = (int) (position[0] + 0.5f); location[1] = (int) (position[1] + 0.5f); @@ -86,11 +88,13 @@ public final class ViewUtils { /** * Returns a bitmap showing a screenshot of the view passed in. + * * @param v * @return */ public static Bitmap getBitmapFromView(View v) { - Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), Bitmap.Config.ARGB_8888); + Bitmap bitmap = Bitmap.createBitmap(v.getWidth(), v.getHeight(), + Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); // TODO I need to know why I need it, when ScrollView canvas.translate(-v.getScrollX(), -v.getScrollY()); @@ -100,32 +104,49 @@ public final class ViewUtils { public static boolean isClickAction(MotionEvent event) { // TODO bad idea to check click - return event.getAction() == MotionEvent.ACTION_UP && - System.nanoTime() / 1000000 - event.getDownTime() < 200; + return event.getAction() == MotionEvent.ACTION_UP + && System.nanoTime() / 1000000 - event.getDownTime() < 200; } public static void removeFromParent(View view) { ViewParent vp = view.getParent(); if (vp instanceof ViewGroup) - ((ViewGroup)vp).removeView(view); + ((ViewGroup) vp).removeView(view); } /** - * Method that removes the support for HardwareAcceleration from a {@link View}.
+ * Method that removes the support for HardwareAcceleration from a + * {@link View}.
*
* Check AOSP notice:
+ * *
      * 'ComposeShader can only contain shaders of different types (a BitmapShader and a
      * LinearGradient for instance, but not two instances of BitmapShader)'. But, 'If your
      * application is affected by any of these missing features or limitations, you can turn
      * off hardware acceleration for just the affected portion of your application by calling
-     * setLayerType(View.LAYER_TYPE_SOFTWARE, null).'
+ * setLayerType(View.LAYER_TYPE_SOFTWARE, null).' + * * - * @param v The view + * @param v + * The view */ public static void removeHardwareAccelerationSupport(View v) { if (v.getLayerType() != View.LAYER_TYPE_SOFTWARE) { v.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } } + + public static void measureView(View v) { + ViewGroup.LayoutParams oldLp = v.getLayoutParams(); + ViewGroup.LayoutParams newLp = new ViewGroup.LayoutParams( + ViewGroup.LayoutParams.WRAP_CONTENT, + ViewGroup.LayoutParams.WRAP_CONTENT); + v.setLayoutParams(newLp); + int measureSpec = MeasureSpec.makeMeasureSpec(0, + MeasureSpec.UNSPECIFIED); + v.measure(measureSpec, measureSpec); + if (oldLp != null) + v.setLayoutParams(oldLp); + } }