From b33817bcc9f08a2d3b1b3da4b5a06f0fe9afa36e Mon Sep 17 00:00:00 2001 From: seven332 Date: Tue, 21 Oct 2014 16:26:56 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=AF=B9=E8=AF=9D=E6=A1=86?= =?UTF-8?q?=E9=A3=8E=E6=A0=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .project | 8 + AndroidManifest.xml | 2 +- .../ehviewer/ui/GalleryListActivity.java | 745 +++++++----------- .../hippo/ehviewer/ui/SettingsActivity.java | 376 ++++----- src/com/hippo/ehviewer/util/DialogUtils.java | 33 + .../ehviewer/widget/SuperDialogUtil.java | 44 -- 6 files changed, 479 insertions(+), 729 deletions(-) create mode 100644 src/com/hippo/ehviewer/util/DialogUtils.java delete mode 100644 src/com/hippo/ehviewer/widget/SuperDialogUtil.java diff --git a/.project b/.project index 646cc5906..8fc7b3d54 100644 --- a/.project +++ b/.project @@ -21,6 +21,10 @@ org.eclipse.cdt.make.core.append_environment true + + org.eclipse.cdt.make.core.autoBuildTarget + + org.eclipse.cdt.make.core.buildArguments NDK_DEBUG=0 @@ -49,6 +53,10 @@ org.eclipse.cdt.make.core.enableFullBuild true + + org.eclipse.cdt.make.core.fullBuildTarget + + org.eclipse.cdt.make.core.stopOnError true diff --git a/AndroidManifest.xml b/AndroidManifest.xml index af79310df..9897f4c92 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -17,7 +17,7 @@ + android:versionName="0.6.6" > = getPageNum()) + 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); + MaterialToast.showToast(R.string.toast_invalid_page); return false; } jumpTo(targetPage); @@ -676,30 +609,25 @@ public class GalleryListActivity extends AbsGalleryActivity implements * 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); if (hint != null) et.setText(hint); - return new MaterialAlertDialog.Builder(this).setTitle(R.string.add_tag) - .setView(view, true).setPositiveButton(android.R.string.ok) - .setNegativeButton(android.R.string.cancel) + return new MaterialAlertDialog.Builder(this).setTitle(R.string.add_tag).setView(view, true) + .setPositiveButton(android.R.string.ok).setNegativeButton(android.R.string.cancel) .setButtonListener(new MaterialAlertDialog.OnClickListener() { @Override public boolean onClick(MaterialAlertDialog dialog, int which) { 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) { @@ -725,16 +653,12 @@ public class GalleryListActivity extends AbsGalleryActivity implements ListUrls listUrls = mData.getTag(position); setFilterView(view, listUrls); - 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) + 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) { @@ -750,44 +674,32 @@ public class GalleryListActivity extends AbsGalleryActivity implements 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: @@ -813,8 +725,7 @@ public class GalleryListActivity extends AbsGalleryActivity implements searchTag.setVisibility(View.GONE); int category = listUrls.getCategory(); - CategoryTable ct = (CategoryTable) view - .findViewById(R.id.category_table); + CategoryTable ct = (CategoryTable) view.findViewById(R.id.category_table); ct.setCategory(category); EditText et = (EditText) view.findViewById(R.id.search_text); @@ -824,22 +735,14 @@ public class GalleryListActivity extends AbsGalleryActivity implements CheckBox cb = (CheckBox) view.findViewById(R.id.checkbox_advance); cb.setChecked(listUrls.isAdvance()); - CheckBox checkImageSname = (CheckBox) view - .findViewById(R.id.checkbox_sname); - CheckBox checkImageStags = (CheckBox) view - .findViewById(R.id.checkbox_stags); - CheckBox checkImageSdesc = (CheckBox) view - .findViewById(R.id.checkbox_sdesc); - CheckBox checkImageStorr = (CheckBox) view - .findViewById(R.id.checkbox_storr); - CheckBox checkImageSto = (CheckBox) view - .findViewById(R.id.checkbox_sto); - CheckBox checkImageSdt1 = (CheckBox) view - .findViewById(R.id.checkbox_sdt1); - CheckBox checkImageSdt2 = (CheckBox) view - .findViewById(R.id.checkbox_sdt2); - CheckBox checkImageSh = (CheckBox) view - .findViewById(R.id.checkbox_sh); + CheckBox checkImageSname = (CheckBox) view.findViewById(R.id.checkbox_sname); + CheckBox checkImageStags = (CheckBox) view.findViewById(R.id.checkbox_stags); + CheckBox checkImageSdesc = (CheckBox) view.findViewById(R.id.checkbox_sdesc); + CheckBox checkImageStorr = (CheckBox) view.findViewById(R.id.checkbox_storr); + CheckBox checkImageSto = (CheckBox) view.findViewById(R.id.checkbox_sto); + CheckBox checkImageSdt1 = (CheckBox) view.findViewById(R.id.checkbox_sdt1); + CheckBox checkImageSdt2 = (CheckBox) view.findViewById(R.id.checkbox_sdt2); + CheckBox checkImageSh = (CheckBox) view.findViewById(R.id.checkbox_sh); int advType = listUrls.getAdvanceType(); if (advType != -1) { @@ -877,14 +780,12 @@ public class GalleryListActivity extends AbsGalleryActivity implements checkImageSh.setChecked(true); // MinRating - CheckBox checkImageSr = (CheckBox) view - .findViewById(R.id.checkbox_sr); + CheckBox checkImageSr = (CheckBox) view.findViewById(R.id.checkbox_sr); if (listUrls.isMinRating()) checkImageSr.setChecked(true); else checkImageSr.setChecked(false); - Spinner spinnerMinRating = (Spinner) view - .findViewById(R.id.spinner_min_rating); + Spinner spinnerMinRating = (Spinner) view.findViewById(R.id.spinner_min_rating); int index; if (listUrls.getMinRating() == -1) index = 0; @@ -911,8 +812,7 @@ public class GalleryListActivity extends AbsGalleryActivity implements 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); } @@ -939,8 +839,7 @@ public class GalleryListActivity extends AbsGalleryActivity implements 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; @@ -949,8 +848,7 @@ public class GalleryListActivity extends AbsGalleryActivity implements case ListUrls.MODE_IMAGE_SEARCH: lus = new ListUrls(); - lus.setSearchImage(intent.getStringExtra(KEY_IMAGE_KEY), - intent.getStringExtra(KEY_IMAGE_URL), + lus.setSearchImage(intent.getStringExtra(KEY_IMAGE_KEY), intent.getStringExtra(KEY_IMAGE_URL), EhClient.IMAGE_SEARCH_USE_SIMILARITY_SCAN); mTitle = getString(R.string.similar_content); setTitle(mTitle); @@ -958,8 +856,7 @@ public class GalleryListActivity extends AbsGalleryActivity implements 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); @@ -1026,14 +923,12 @@ public class GalleryListActivity extends AbsGalleryActivity implements 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); + 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); @@ -1061,8 +956,7 @@ public class GalleryListActivity extends AbsGalleryActivity implements 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); @@ -1097,19 +991,14 @@ public class GalleryListActivity extends AbsGalleryActivity implements // 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, - 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 }; + 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 }; itemListMenu.setSelector(new ColorDrawable(Color.TRANSPARENT)); itemListMenu.setClipToPadding(false); @@ -1133,9 +1022,8 @@ public class GalleryListActivity extends AbsGalleryActivity implements 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; } @@ -1149,8 +1037,7 @@ public class GalleryListActivity extends AbsGalleryActivity implements }); itemListMenu.setOnItemClickListener(new OnItemClickListener() { @Override - public void onItemClick(AdapterView parent, View view, - int position, long id) { + public void onItemClick(AdapterView parent, View view, int position, long id) { Intent intent; switch (position) { case 0: // Home page @@ -1170,8 +1057,7 @@ public class GalleryListActivity extends AbsGalleryActivity implements break; case 3: // Favourite - intent = new Intent(GalleryListActivity.this, - FavouriteActivity.class); + intent = new Intent(GalleryListActivity.this, FavouriteActivity.class); startActivity(intent); break; @@ -1185,14 +1071,12 @@ public class GalleryListActivity extends AbsGalleryActivity implements break; case 5: // Download - intent = new Intent(GalleryListActivity.this, - DownloadActivity.class); + intent = new Intent(GalleryListActivity.this, DownloadActivity.class); startActivity(intent); break; case 6: // Settings - intent = new Intent(GalleryListActivity.this, - SettingsActivity.class); + intent = new Intent(GalleryListActivity.this, SettingsActivity.class); startActivity(intent); break; } @@ -1204,16 +1088,15 @@ public class GalleryListActivity extends AbsGalleryActivity implements 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 @@ -1223,8 +1106,7 @@ public class GalleryListActivity extends AbsGalleryActivity implements tagListMenu.setChoiceMode(ListView.CHOICE_MODE_SINGLE); tagListMenu.setOnItemClickListener(new OnItemClickListener() { @Override - public void onItemClick(AdapterView arg0, View arg1, - int position, long arg3) { + public void onItemClick(AdapterView arg0, View arg1, int position, long arg3) { lus = mData.getTag(position); refresh(); showContent(); @@ -1263,29 +1145,24 @@ public class GalleryListActivity extends AbsGalleryActivity implements mStaggeredGridView.setAdapter(mAdapter); mStaggeredGridView.setOnItemClickListener(new OnItemClickListener() { @Override - public void onItemClick(AdapterView arg0, View arg1, - int position, long arg3) { - Intent intent = new Intent(GalleryListActivity.this, - GalleryDetailActivity.class); + public void onItemClick(AdapterView arg0, View arg1, int position, long arg3) { + Intent intent = new Intent(GalleryListActivity.this, GalleryDetailActivity.class); GalleryInfo gi = getGalleryInfo(position); intent.putExtra(GalleryDetailActivity.KEY_G_INFO, gi); 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(); @@ -1327,11 +1204,10 @@ public class GalleryListActivity extends AbsGalleryActivity implements } 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(); + new MaterialAlertDialog.Builder(this).setTitle("注意").setMessage("正體中文的翻譯由 OpenCC 自動完成,若有任何錯誤或不妥之處歡迎指出。") + .show(); } } @@ -1343,26 +1219,21 @@ public class GalleryListActivity extends AbsGalleryActivity implements mStaggeredGridView.setColumnCountLandscape(2); break; case LIST_MODE_THUMB: - mStaggeredGridView.setColumnCountPortrait(Config - .getListThumbColumnsPortrait()); - mStaggeredGridView.setColumnCountLandscape(Config - .getListThumbColumnsLandscape()); + mStaggeredGridView.setColumnCountPortrait(Config.getListThumbColumnsPortrait()); + mStaggeredGridView.setColumnCountLandscape(Config.getListThumbColumnsLandscape()); } } } @Override 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); - tagListMenu.setPadding(tagListMenu.getPaddingLeft(), paddingTop, - tagListMenu.getPaddingRight(), paddingBottom); - mStaggeredGridView - .setPadding(mStaggeredGridView.getPaddingLeft(), paddingTop, - mStaggeredGridView.getPaddingRight(), paddingBottom); + mUserPanel.setPadding(mUserPanel.getPaddingLeft(), paddingTop, mUserPanel.getPaddingRight(), + mUserPanel.getPaddingBottom()); + 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); } @Override @@ -1408,25 +1279,19 @@ public class GalleryListActivity extends AbsGalleryActivity implements 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) { + if (searchTextID > 0 && (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"); + Field f = Class.forName("android.widget.TextView").getDeclaredField("mCursorDrawableRes"); f.setAccessible(true); f.setInt(searchText, searchCursorID); } catch (Exception e) { @@ -1436,55 +1301,41 @@ public class GalleryListActivity extends AbsGalleryActivity implements 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) { + 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); + if (plateRightViewID > 0 && (plateRightView = mSearchView.findViewById(plateRightViewID)) != null) { + 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 + if (closeViewID > 0 && (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); - if (voiceViewID > 0 - && (voiceView = (ImageView) mSearchView - .findViewById(voiceViewID)) != null + Drawable voiceImage = mResources.getDrawable(R.drawable.ic_voice_search); + if (voiceViewID > 0 && (voiceView = (ImageView) mSearchView.findViewById(voiceViewID)) != null && voiceImage != null) { voiceView.setImageDrawable(voiceImage); } @@ -1567,51 +1418,39 @@ public class GalleryListActivity extends AbsGalleryActivity implements } 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() { - @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(); - } + 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 = DialogUtils.createUpdateDialog(GalleryListActivity.this, version, sizeStr, + info, new MaterialAlertDialog.OnClickListener() { + @Override + public boolean onClick(MaterialAlertDialog dialog, int which) { + if (which == MaterialAlertDialog.POSITIVE) { + HttpHelper hh = new HttpHelper(GalleryListActivity.this); + hh.downloadInThread(url, new File(Config.getDownloadPath()), fileName, + false, null, new UpdateHelper.UpdateListener( + GalleryListActivity.this, fileName)); + } + return true; + } + }).create(); + if (!GalleryListActivity.this.isFinishing()) + dialog.show(); + } - @Override - public void onNoUpdate() { - UpdateHelper.setEnabled(true); - } + @Override + public void onNoUpdate() { + UpdateHelper.setEnabled(true); + } - @Override - public void onFailure(String eMsg) { - UpdateHelper.setEnabled(true); - } - }).autoCheckUpdate(); + @Override + public void onFailure(String eMsg) { + UpdateHelper.setEnabled(true); + } + }).autoCheckUpdate(); } private static final int LOGIN = 0x0; @@ -1663,74 +1502,52 @@ public class GalleryListActivity extends AbsGalleryActivity implements } @Override - protected void doGetGallerys(String url, final long taskStamp, - final OnGetListListener listener) { + protected void doGetGallerys(String url, final long taskStamp, final OnGetListListener listener) { if (lus.getMode() == ListUrls.MODE_IMAGE_SEARCH) { if (url == null) { // No result url if (lus.getSearchFile() == null) { - ImageLoader.getInstance(GalleryListActivity.this).add( - lus.getSearchImageUrl(), lus.getSearchImageKey(), - new ImageLoader.OnGetImageListener() { + 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, + mClient.getGListFromImageSearch(bmp, lus.getImageSearchMode(), taskStamp, new EhClient.OnGetGListFromImageSearchListener() { @Override - public void onSuccess( - Object checkFlag, - List giList, - int maxPage, - String newUrl) { + 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); + listener.onSuccess(mAdapter, taskStamp, giList, maxPage); } @Override - public void onFailure( - Object checkFlag, - String eMsg) { - listener.onFailure( - mAdapter, - taskStamp, eMsg); // TODO + public void onFailure(Object checkFlag, String eMsg) { + listener.onFailure(mAdapter, taskStamp, eMsg); // TODO } }); } else { - listener.onFailure(mAdapter, taskStamp, - "~~~~~~~~~~"); // TODO + 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, + public void onSuccess(Object checkFlag, List giList, int maxPage, String newUrl) { lus.setSearchResult(newUrl); - listener.onSuccess(mAdapter, taskStamp, - giList, maxPage); + listener.onSuccess(mAdapter, taskStamp, giList, maxPage); } @Override - public void onFailure(Object checkFlag, - String eMsg) { - listener.onFailure(mAdapter, taskStamp, - eMsg); + public void onFailure(Object checkFlag, String eMsg) { + listener.onFailure(mAdapter, taskStamp, eMsg); } }); } @@ -1738,10 +1555,8 @@ public class GalleryListActivity extends AbsGalleryActivity implements // 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 @@ -1754,12 +1569,10 @@ public class GalleryListActivity extends AbsGalleryActivity implements 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))); } @@ -1771,8 +1584,7 @@ public class GalleryListActivity extends AbsGalleryActivity implements } 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); } @@ -1829,44 +1641,30 @@ public class GalleryListActivity extends AbsGalleryActivity implements ViewHolder viewHolder = new ViewHolder(); switch (mListMode) { case LIST_MODE_DETAIL: - convertView = LayoutInflater.from(GalleryListActivity.this) - .inflate(R.layout.gallery_list_detail_item, parent, - false); + 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); + 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); ViewGroup.LayoutParams lp = viewHolder.thumb.getLayoutParams(); lp.width = mListDetailThumbWidth; lp.height = mListDetailThumbHeight; - 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); + 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); + convertView = LayoutInflater.from(GalleryListActivity.this).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; } @@ -1879,8 +1677,7 @@ public class GalleryListActivity extends AbsGalleryActivity implements 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/ui/SettingsActivity.java b/src/com/hippo/ehviewer/ui/SettingsActivity.java index 549c20d3c..76e7269f6 100644 --- a/src/com/hippo/ehviewer/ui/SettingsActivity.java +++ b/src/com/hippo/ehviewer/ui/SettingsActivity.java @@ -67,18 +67,17 @@ import com.hippo.ehviewer.network.HttpHelper; import com.hippo.ehviewer.preference.ListPreference; import com.hippo.ehviewer.util.BgThread; import com.hippo.ehviewer.util.Config; +import com.hippo.ehviewer.util.DialogUtils; import com.hippo.ehviewer.util.EhUtils; 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.widget.AlertButton; import com.hippo.ehviewer.widget.CategoryTable; import com.hippo.ehviewer.widget.FileExplorerView; import com.hippo.ehviewer.widget.MaterialToast; import com.hippo.ehviewer.widget.ProgressDialogBulider; import com.hippo.ehviewer.widget.SuggestionHelper; -import com.hippo.ehviewer.widget.SuperDialogUtil; public class SettingsActivity extends AbsPreferenceActivity { @SuppressWarnings("unused") @@ -88,8 +87,7 @@ public class SettingsActivity extends AbsPreferenceActivity { private ListView mListView; public void adjustPadding(int paddingTop, int paddingBottom) { - mListView.setPadding(mListView.getPaddingLeft(), paddingTop, - mListView.getPaddingRight(), paddingBottom); + mListView.setPadding(mListView.getPaddingLeft(), paddingTop, mListView.getPaddingRight(), paddingBottom); } @Override @@ -145,28 +143,19 @@ public class SettingsActivity extends AbsPreferenceActivity { loadHeadersFromResource(R.xml.settings_headers, target); } - private static final String[] ENTRY_FRAGMENTS = { - DisplayFragment.class.getName(), - EhFragment.class.getName(), - ReadFragment.class.getName(), - DownloadFragment.class.getName(), - AdvancedFragment.class.getName(), - AboutFragment.class.getName() - }; + private static final String[] ENTRY_FRAGMENTS = { DisplayFragment.class.getName(), EhFragment.class.getName(), + ReadFragment.class.getName(), DownloadFragment.class.getName(), AdvancedFragment.class.getName(), + AboutFragment.class.getName() }; - private static final int[] FRAGMENT_ICONS = { - R.drawable.ic_setting_display, - R.drawable.ic_action_panda, - R.drawable.ic_setting_read, - R.drawable.ic_setting_download, - R.drawable.ic_setting_advanced, - R.drawable.ic_setting_about - }; + private static final int[] FRAGMENT_ICONS = { R.drawable.ic_setting_display, R.drawable.ic_action_panda, + R.drawable.ic_setting_read, R.drawable.ic_setting_download, R.drawable.ic_setting_advanced, + R.drawable.ic_setting_about }; @Override protected boolean isValidFragment(String fragmentName) { for (int i = 0; i < ENTRY_FRAGMENTS.length; i++) { - if (ENTRY_FRAGMENTS[i].equals(fragmentName)) return true; + if (ENTRY_FRAGMENTS[i].equals(fragmentName)) + return true; } return false; } @@ -179,7 +168,7 @@ public class SettingsActivity extends AbsPreferenceActivity { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - mActivity = (SettingsActivity)getActivity(); + mActivity = (SettingsActivity) getActivity(); String fragmentName = getClass().getName(); int fragmentIndex = -1; @@ -190,20 +179,18 @@ public class SettingsActivity extends AbsPreferenceActivity { } } if (fragmentIndex >= 0) - mActivity.getActionBar().setIcon( - FRAGMENT_ICONS[fragmentIndex]); + mActivity.getActionBar().setIcon(FRAGMENT_ICONS[fragmentIndex]); } @Override public void onViewCreated(View view, Bundle savedInstanceState) { - SettingsActivity activity = (SettingsActivity)getActivity(); + SettingsActivity activity = (SettingsActivity) getActivity(); activity.getFragments().add(this); View child; - if (view instanceof ViewGroup - && (child = ((ViewGroup)view).getChildAt(0)) != null + if (view instanceof ViewGroup && (child = ((ViewGroup) view).getChildAt(0)) != null && child instanceof ListView) { - mListView = (ListView)child; + mListView = (ListView) child; mListView.setClipToPadding(false); int[] padding = new int[2]; @@ -213,13 +200,12 @@ public class SettingsActivity extends AbsPreferenceActivity { } public void adjustPadding(int paddingTop, int paddingBottom) { - mListView.setPadding(mListView.getPaddingLeft(), paddingTop, - mListView.getPaddingRight(), paddingBottom); + mListView.setPadding(mListView.getPaddingLeft(), paddingTop, mListView.getPaddingRight(), paddingBottom); } } - public static class DisplayFragment extends TranslucentPreferenceFragment - implements Preference.OnPreferenceChangeListener { + public static class DisplayFragment extends TranslucentPreferenceFragment implements + Preference.OnPreferenceChangeListener { private static final String KEY_SCREEN_ORIENTATION = "screen_orientation"; private static final String KEY_RANDOM_THEME_COLOR = "random_theme_color"; @@ -234,9 +220,9 @@ public class SettingsActivity extends AbsPreferenceActivity { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.display_settings); - mScreenOrientation = (ListPreference)findPreference(KEY_SCREEN_ORIENTATION); + mScreenOrientation = (ListPreference) findPreference(KEY_SCREEN_ORIENTATION); mScreenOrientation.setOnPreferenceChangeListener(this); - mRandomThemeColor = (CheckBoxPreference)findPreference(KEY_RANDOM_THEME_COLOR); + mRandomThemeColor = (CheckBoxPreference) findPreference(KEY_RANDOM_THEME_COLOR); mRandomThemeColor.setOnPreferenceChangeListener(this); mThemeColor = findPreference(KEY_THEME_COLOR); @@ -247,63 +233,45 @@ public class SettingsActivity extends AbsPreferenceActivity { public boolean onPreferenceChange(Preference preference, Object newValue) { final String key = preference.getKey(); if (KEY_SCREEN_ORIENTATION.equals(key)) { - mActivity.setRequestedOrientation( - Config.screenOriPre2Value(Integer.parseInt((String) newValue))); + mActivity.setRequestedOrientation(Config.screenOriPre2Value(Integer.parseInt((String) newValue))); } else if (KEY_RANDOM_THEME_COLOR.equals(key)) { MaterialToast.showToast(R.string.restart_to_take_effect); - mThemeColor.setEnabled(!(Boolean)newValue); + mThemeColor.setEnabled(!(Boolean) newValue); } return true; } } - public static class EhFragment extends TranslucentPreferenceFragment - implements Preference.OnPreferenceChangeListener, - Preference.OnPreferenceClickListener { + public static class EhFragment extends TranslucentPreferenceFragment implements + Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener { - private static final int[] EXCULDE_TAG_GROUP_RESID = { - R.id.tag_group_reclass, - R.id.tag_group_language, - R.id.tag_group_parody, - R.id.tag_group_character, - R.id.tag_group_group, - R.id.tag_group_artist, - R.id.tag_group_male, - R.id.tag_group_female - }; + private static final int[] EXCULDE_TAG_GROUP_RESID = { R.id.tag_group_reclass, R.id.tag_group_language, + R.id.tag_group_parody, R.id.tag_group_character, R.id.tag_group_group, R.id.tag_group_artist, + R.id.tag_group_male, R.id.tag_group_female }; - private static final int[] EXCULDE_TAG_GROUP_ID = { - 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80 - }; + private static final int[] EXCULDE_TAG_GROUP_ID = { 0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80 }; - private static final int[] EXCULDE_LANGUAGE_RESID = { - R.id.el_japanese_translated, R.id.el_japanese_rewrite, - R.id.el_english_original, R.id.el_english_translated, R.id.el_english_rewrite, - R.id.el_chinese_original, R.id.el_chinese_translated, R.id.el_chinese_rewrite, - R.id.el_dutch_original, R.id.el_dutch_translated, R.id.el_dutch_rewrite, - R.id.el_french_original, R.id.el_french_translated, R.id.el_french_rewrite, - R.id.el_german_original, R.id.el_german_translated, R.id.el_german_rewrite, - R.id.el_hungarian_original, R.id.el_hungarian_translated, R.id.el_hungarian_rewrite, - R.id.el_italian_original, R.id.el_italian_translated, R.id.el_italian_rewrite, - R.id.el_korean_original, R.id.el_korean_translated, R.id.el_korean_rewrite, - R.id.el_polish_original, R.id.el_polish_translated, R.id.el_polish_rewrite, - R.id.el_portuguese_original, R.id.el_portuguese_translated, R.id.el_portuguese_rewrite, - R.id.el_russian_original, R.id.el_russian_translated, R.id.el_russian_rewrite, - R.id.el_spanish_original, R.id.el_spanish_translated, R.id.el_spanish_rewrite, - R.id.el_thai_original, R.id.el_thai_translated, R.id.el_thai_rewrite, - R.id.el_vietnamese_original, R.id.el_vietnamese_translated, R.id.el_vietnamese_rewrite, - R.id.el_other_original, R.id.el_other_translated, R.id.el_other_rewrite, - }; + private static final int[] EXCULDE_LANGUAGE_RESID = { R.id.el_japanese_translated, R.id.el_japanese_rewrite, + R.id.el_english_original, R.id.el_english_translated, R.id.el_english_rewrite, + R.id.el_chinese_original, R.id.el_chinese_translated, R.id.el_chinese_rewrite, R.id.el_dutch_original, + R.id.el_dutch_translated, R.id.el_dutch_rewrite, R.id.el_french_original, R.id.el_french_translated, + R.id.el_french_rewrite, R.id.el_german_original, R.id.el_german_translated, R.id.el_german_rewrite, + R.id.el_hungarian_original, R.id.el_hungarian_translated, R.id.el_hungarian_rewrite, + R.id.el_italian_original, R.id.el_italian_translated, R.id.el_italian_rewrite, R.id.el_korean_original, + R.id.el_korean_translated, R.id.el_korean_rewrite, R.id.el_polish_original, R.id.el_polish_translated, + R.id.el_polish_rewrite, R.id.el_portuguese_original, R.id.el_portuguese_translated, + R.id.el_portuguese_rewrite, R.id.el_russian_original, R.id.el_russian_translated, + R.id.el_russian_rewrite, R.id.el_spanish_original, R.id.el_spanish_translated, R.id.el_spanish_rewrite, + R.id.el_thai_original, R.id.el_thai_translated, R.id.el_thai_rewrite, R.id.el_vietnamese_original, + R.id.el_vietnamese_translated, R.id.el_vietnamese_rewrite, R.id.el_other_original, + R.id.el_other_translated, R.id.el_other_rewrite, }; - private static final String[] EXCULDE_LANGUAGE_ID = { - "1024", "2048", "1", "1025", "2049", "10", "1034", "2058", "20", "1044", "2068", - "30", "1054", "2078", "40", "1064", "2088", "50", "1074", "2098", - "60", "1084", "2108", "70", "1094", "2118", "80", "1104", "2128", - "90", "1114", "2138", "100", "1124", "2148", "110", "1134", "2158", - "120", "1144", "2168", "130", "1154", "2178", "255", "1279", "2303" - }; + private static final String[] EXCULDE_LANGUAGE_ID = { "1024", "2048", "1", "1025", "2049", "10", "1034", + "2058", "20", "1044", "2068", "30", "1054", "2078", "40", "1064", "2088", "50", "1074", "2098", "60", + "1084", "2108", "70", "1094", "2118", "80", "1104", "2128", "90", "1114", "2138", "100", "1124", + "2148", "110", "1134", "2158", "120", "1144", "2168", "130", "1154", "2178", "255", "1279", "2303" }; private static final String KEY_LIST_DEFAULT_CATEGORY = "list_default_category"; private static final String KEY_EXCULDE_TAG_GROUP = "exculde_tag_group"; @@ -332,9 +300,9 @@ public class SettingsActivity extends AbsPreferenceActivity { mExculdeLanguage.setOnPreferenceClickListener(this); mClearSuggestions = findPreference(KEY_CLEAR_SUGGESTIONS); mClearSuggestions.setOnPreferenceClickListener(this); - mPreviewMode = (ListPreference)findPreference(KEY_PREVIEW_MODE); + mPreviewMode = (ListPreference) findPreference(KEY_PREVIEW_MODE); mPreviewMode.setOnPreferenceChangeListener(this); - mDefaultFavorite = (ListPreference)findPreference(KEY_DEFAULT_FAVORITE); + mDefaultFavorite = (ListPreference) findPreference(KEY_DEFAULT_FAVORITE); int i = 0; String[] entrise = new String[Favorite.FAVORITE_TITLES.length + 1]; @@ -348,7 +316,7 @@ public class SettingsActivity extends AbsPreferenceActivity { public boolean onPreferenceChange(Preference preference, Object newValue) { final String key = preference.getKey(); if (KEY_PREVIEW_MODE.equals(key)) { - String newPreviewMode = (String)newValue; + String newPreviewMode = (String) newValue; EhInfo.getInstance(mActivity).setPreviewMode(newPreviewMode); } return true; @@ -363,8 +331,7 @@ public class SettingsActivity extends AbsPreferenceActivity { final CategoryTable ct = new CategoryTable(mActivity); ct.setCategory(defaultCat); - new MaterialAlertDialog.Builder(mActivity) - .setTitle(R.string.list_default_category_title) + new MaterialAlertDialog.Builder(mActivity).setTitle(R.string.list_default_category_title) .setView(ct, true).setPositiveButton(android.R.string.ok) .setNegativeButton(android.R.string.cancel) .setButtonListener(new MaterialAlertDialog.OnClickListener() { @@ -381,17 +348,14 @@ public class SettingsActivity extends AbsPreferenceActivity { } else if (KEY_EXCULDE_TAG_GROUP.equals(key)) { LayoutInflater inflater = LayoutInflater.from(mActivity); - final TableLayout tl = (TableLayout)inflater.inflate(R.layout.exculde_tag_group, null); + final TableLayout tl = (TableLayout) inflater.inflate(R.layout.exculde_tag_group, null); setExculdeTagGroup(tl, Config.getExculdeTagGroup()); - new MaterialAlertDialog.Builder(mActivity) - .setTitle(R.string.exculde_tag_group_title) - .setView(tl, true).setPositiveButton(android.R.string.ok) - .setNegativeButton(android.R.string.cancel) + new MaterialAlertDialog.Builder(mActivity).setTitle(R.string.exculde_tag_group_title).setView(tl, true) + .setPositiveButton(android.R.string.ok).setNegativeButton(android.R.string.cancel) .setButtonListener(new MaterialAlertDialog.OnClickListener() { @Override - public boolean onClick(MaterialAlertDialog dialog, - int which) { + public boolean onClick(MaterialAlertDialog dialog, int which) { int newValue = getExculdeTagGroup(tl); Config.setExculdeTagGroup(newValue); EhInfo.getInstance(mActivity).setExculdeTagGroup(newValue); @@ -401,17 +365,14 @@ public class SettingsActivity extends AbsPreferenceActivity { } else if (KEY_EXCULDE_LANGUAGE.equals(key)) { LayoutInflater inflater = LayoutInflater.from(mActivity); - final TableLayout tl = (TableLayout)inflater.inflate(R.layout.exculde_language, null); + final TableLayout tl = (TableLayout) inflater.inflate(R.layout.exculde_language, null); setExculdeLanguage(tl, Config.getExculdeLanguage()); - new MaterialAlertDialog.Builder(mActivity) - .setTitle(R.string.exculde_language_title) - .setView(tl, true).setPositiveButton(android.R.string.ok) - .setNegativeButton(android.R.string.cancel) + new MaterialAlertDialog.Builder(mActivity).setTitle(R.string.exculde_language_title).setView(tl, true) + .setPositiveButton(android.R.string.ok).setNegativeButton(android.R.string.cancel) .setButtonListener(new MaterialAlertDialog.OnClickListener() { @Override - public boolean onClick(MaterialAlertDialog dialog, - int which) { + public boolean onClick(MaterialAlertDialog dialog, int which) { String newValue = getExculdeLanguage(tl); Config.setExculdeLanguage(newValue); EhInfo.getInstance(mActivity).setExculdeLanguage(newValue); @@ -420,9 +381,8 @@ public class SettingsActivity extends AbsPreferenceActivity { }).show(); } else if (KEY_CLEAR_SUGGESTIONS.equals(key)) { - SearchRecentSuggestions suggestions = SuggestionHelper.getInstance ( - mActivity, SimpleSuggestionProvider.AUTHORITY, - SimpleSuggestionProvider.MODE); + SearchRecentSuggestions suggestions = SuggestionHelper.getInstance(mActivity, + SimpleSuggestionProvider.AUTHORITY, SimpleSuggestionProvider.MODE); suggestions.clearHistory(); } return true; @@ -430,7 +390,7 @@ public class SettingsActivity extends AbsPreferenceActivity { private static void setExculdeTagGroup(TableLayout tl, int value) { for (int i = 0; i < EXCULDE_TAG_GROUP_RESID.length; i++) { - CheckBox cb = (CheckBox)tl.findViewById(EXCULDE_TAG_GROUP_RESID[i]); + CheckBox cb = (CheckBox) tl.findViewById(EXCULDE_TAG_GROUP_RESID[i]); cb.setChecked(Utils.int2boolean(value & EXCULDE_TAG_GROUP_ID[i])); } } @@ -438,8 +398,9 @@ public class SettingsActivity extends AbsPreferenceActivity { private static int getExculdeTagGroup(TableLayout tl) { int newValue = 0; for (int i = 0; i < EXCULDE_TAG_GROUP_RESID.length; i++) { - CheckBox cb = (CheckBox)tl.findViewById(EXCULDE_TAG_GROUP_RESID[i]); - if (cb.isChecked()) newValue |= EXCULDE_TAG_GROUP_ID[i]; + CheckBox cb = (CheckBox) tl.findViewById(EXCULDE_TAG_GROUP_RESID[i]); + if (cb.isChecked()) + newValue |= EXCULDE_TAG_GROUP_ID[i]; } return newValue; } @@ -456,7 +417,8 @@ public class SettingsActivity extends AbsPreferenceActivity { String[] items = value.split("x"); for (String item : items) { int resId = getLanguage(item); - if (resId != 0) ((CheckBox)tl.findViewById(resId)).setChecked(true); + if (resId != 0) + ((CheckBox) tl.findViewById(resId)).setChecked(true); } } @@ -464,8 +426,11 @@ public class SettingsActivity extends AbsPreferenceActivity { StringBuilder sb = new StringBuilder(); boolean isFirst = true; for (int i = 0; i < EXCULDE_LANGUAGE_RESID.length; i++) { - if (((CheckBox)tl.findViewById(EXCULDE_LANGUAGE_RESID[i])).isChecked()) { - if (isFirst) isFirst = false; else sb.append('x'); + if (((CheckBox) tl.findViewById(EXCULDE_LANGUAGE_RESID[i])).isChecked()) { + if (isFirst) + isFirst = false; + else + sb.append('x'); sb.append(EXCULDE_LANGUAGE_ID[i]); } } @@ -473,8 +438,8 @@ public class SettingsActivity extends AbsPreferenceActivity { } } - public static class ReadFragment extends TranslucentPreferenceFragment - implements Preference.OnPreferenceClickListener { + public static class ReadFragment extends TranslucentPreferenceFragment implements + Preference.OnPreferenceClickListener { private static final String KEY_CUSTOM_CODEC = "custom_codec"; private static final String KEY_CLEAN_REDUNDANCY = "clean_redundancy"; @@ -607,7 +572,8 @@ public class SettingsActivity extends AbsPreferenceActivity { handler.post(new CleanResponder(CleanResponder.STATE_DOING, targetDirList.size(), i + 1)); } // Close windows - handler.post(new CleanResponder(CleanResponder.STATE_DONE, targetDirList.size(), targetDirList.size())); + handler.post(new CleanResponder(CleanResponder.STATE_DONE, targetDirList.size(), targetDirList + .size())); } }.start(); } @@ -615,9 +581,8 @@ public class SettingsActivity extends AbsPreferenceActivity { } } - public static class DownloadFragment extends TranslucentPreferenceFragment - implements Preference.OnPreferenceChangeListener, - Preference.OnPreferenceClickListener { + public static class DownloadFragment extends TranslucentPreferenceFragment implements + Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener { private static final String KEY_DOWNLOAD_PATH = "download_path"; private static final String KEY_MEDIA_SCAN = "media_scan"; @@ -639,7 +604,7 @@ public class SettingsActivity extends AbsPreferenceActivity { mDownloadPath = findPreference(KEY_DOWNLOAD_PATH); mDownloadPath.setOnPreferenceClickListener(this); - mMediaScan = (CheckBoxPreference)findPreference(KEY_MEDIA_SCAN); + mMediaScan = (CheckBoxPreference) findPreference(KEY_MEDIA_SCAN); mMediaScan.setOnPreferenceChangeListener(this); mDownloadThread = findPreference(KEY_DOWNLOAD_THREAD); mDownloadThread.setOnPreferenceChangeListener(this); @@ -651,22 +616,23 @@ public class SettingsActivity extends AbsPreferenceActivity { public boolean onPreferenceChange(Preference preference, Object newValue) { final String key = preference.getKey(); if (KEY_MEDIA_SCAN.equals(key)) { - boolean value = (Boolean)newValue; + boolean value = (Boolean) newValue; File nomedia = new File(Config.getDownloadPath(), ".nomedia"); if (value) { nomedia.delete(); } else { try { nomedia.createNewFile(); - } catch (IOException e) {} + } catch (IOException e) { + } } } else if (KEY_DOWNLOAD_THREAD.equals(key)) { - String value = (String)newValue; + String value = (String) newValue; try { int num = Integer.parseInt(value); if (num < MIN_THREAD_NUM || num > MAX_THREAD_NUM) throw new Throwable(); - } catch(Throwable e){ + } catch (Throwable e) { MaterialToast.showToast(R.string.invalid_input); return false; } @@ -680,20 +646,15 @@ public class SettingsActivity extends AbsPreferenceActivity { public boolean onPreferenceClick(Preference preference) { final String key = preference.getKey(); if (KEY_DOWNLOAD_PATH.equals(key)) { - View view = LayoutInflater.from(mActivity) - .inflate(R.layout.dir_selection, null); - final FileExplorerView fileExplorerView = - (FileExplorerView)view.findViewById(R.id.file_list); - final TextView warning = - (TextView)view.findViewById(R.id.warning); + View view = LayoutInflater.from(mActivity).inflate(R.layout.dir_selection, null); + final FileExplorerView fileExplorerView = (FileExplorerView) view.findViewById(R.id.file_list); + final TextView warning = (TextView) view.findViewById(R.id.warning); String downloadPath = Config.getDownloadPath(); fileExplorerView.setPath(downloadPath); - fileExplorerView.setOnItemClickListener( - new AdapterView.OnItemClickListener() { + fileExplorerView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override - public void onItemClick(AdapterView parent, View view, - int position, long id) { + public void onItemClick(AdapterView parent, View view, int position, long id) { fileExplorerView.onItemClick(parent, view, position, id); mDirSelectDialog.setTitle(fileExplorerView.getCurPath()); if (fileExplorerView.canWrite()) @@ -707,10 +668,11 @@ public class SettingsActivity extends AbsPreferenceActivity { else warning.setVisibility(View.VISIBLE); - mDirSelectDialog = new MaterialAlertDialog.Builder(mActivity).setTitle(downloadPath) - .setView(view, false, new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT, Ui.dp2pix(360))).setActionButton(R.string._new) - .setPositiveButton(android.R.string.ok) + mDirSelectDialog = new MaterialAlertDialog.Builder(mActivity) + .setTitle(downloadPath) + .setView(view, false, + new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, Ui.dp2pix(360))) + .setActionButton(R.string._new).setPositiveButton(android.R.string.ok) .setNegativeButton(android.R.string.cancel) .setButtonListener(new MaterialAlertDialog.OnClickListener() { @Override @@ -728,17 +690,14 @@ public class SettingsActivity extends AbsPreferenceActivity { lp.topMargin = x; lp.bottomMargin = x; new MaterialAlertDialog.Builder(mActivity).setTitle(R.string.new_folder) - .setView(et, true, lp) - .setPositiveButton(R.string._new) + .setView(et, true, lp).setPositiveButton(R.string._new) .setNegativeButton(android.R.string.cancel) .setButtonListener(new MaterialAlertDialog.OnClickListener() { @Override - public boolean onClick( - MaterialAlertDialog dialog, - int which) { + public boolean onClick(MaterialAlertDialog dialog, int which) { if (which == MaterialAlertDialog.POSITIVE) { - File dir = new File(fileExplorerView.getCurPath(), - et.getText().toString()); + File dir = new File(fileExplorerView.getCurPath(), et.getText() + .toString()); dir.mkdirs(); fileExplorerView.refresh(); } @@ -753,11 +712,13 @@ public class SettingsActivity extends AbsPreferenceActivity { } String downloadPath = fileExplorerView.getCurPath(); // Update .nomedia file - // TODO Should I delete .nomedia in old download dir ? + // TODO Should I delete .nomedia in old + // download dir ? if (!Config.getMediaScan()) { try { new File(Config.getDownloadPath(), ".nomedia").createNewFile(); - } catch (IOException e) {} + } catch (IOException e) { + } } Config.setDownloadPath(downloadPath); mDownloadPath.setSummary(downloadPath); @@ -775,9 +736,8 @@ public class SettingsActivity extends AbsPreferenceActivity { } } - public static class AdvancedFragment extends TranslucentPreferenceFragment - implements Preference.OnPreferenceChangeListener, - Preference.OnPreferenceClickListener { + public static class AdvancedFragment extends TranslucentPreferenceFragment implements + Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener { private static final String KEY_HTTP_RETRY = "http_retry"; private static final String KEY_HTTP_CONNECT_TIMEOUT = "http_connect_timeout"; @@ -812,42 +772,42 @@ public class SettingsActivity extends AbsPreferenceActivity { public boolean onPreferenceChange(Preference preference, Object newValue) { final String key = preference.getKey(); if (KEY_HTTP_RETRY.equals(key)) { - String value = (String)newValue; + String value = (String) newValue; try { int num = Integer.parseInt(value); if (num < 1 || num > 10) throw new Throwable(); - } catch(Throwable e){ + } catch (Throwable e) { MaterialToast.showToast(R.string.invalid_input); return false; } } else if (KEY_HTTP_CONNECT_TIMEOUT.equals(key)) { - String value = (String)newValue; + String value = (String) newValue; try { int num = Integer.parseInt(value); if (num < 1) throw new Throwable(); - } catch(Throwable e){ + } catch (Throwable e) { MaterialToast.showToast(R.string.invalid_input); return false; } - } else if (KEY_HTTP_READ_TIMEOUT.equals(key)) { - String value = (String)newValue; + } else if (KEY_HTTP_READ_TIMEOUT.equals(key)) { + String value = (String) newValue; try { int num = Integer.parseInt(value); if (num < 1) throw new Throwable(); - } catch(Throwable e){ + } catch (Throwable e) { MaterialToast.showToast(R.string.invalid_input); return false; } - } else if (KEY_EH_MIN_INTERVAL.equals(key)) { - String value = (String)newValue; + } else if (KEY_EH_MIN_INTERVAL.equals(key)) { + String value = (String) newValue; try { int num = Integer.parseInt(value); if (num < 0) throw new Throwable(); - } catch(Throwable e){ + } catch (Throwable e) { MaterialToast.showToast(R.string.invalid_input); return false; } @@ -869,8 +829,9 @@ public class SettingsActivity extends AbsPreferenceActivity { String[] list = downloadDir.list(); if (list != null) { - for (String str: list) { - if (str.contains("-")) continue; + for (String str : list) { + if (str.contains("-")) + continue; File dir = new File(downloadDir, str); if (new File(dir, EhUtils.EH_DOWNLOAD_FILENAME).exists()) targetDirList.add(dir); @@ -907,8 +868,7 @@ public class SettingsActivity extends AbsPreferenceActivity { int gid; String token; try { - is = new BufferedInputStream(new FileInputStream(info), - 128); + is = new BufferedInputStream(new FileInputStream(info), 128); // skip read index Utils.readAsciiLine(is); gid = Integer.parseInt(Utils.readAsciiLine(is)); @@ -957,9 +917,8 @@ public class SettingsActivity extends AbsPreferenceActivity { } } - public static class AboutFragment extends TranslucentPreferenceFragment - implements Preference.OnPreferenceClickListener, - Preference.OnPreferenceChangeListener { + public static class AboutFragment extends TranslucentPreferenceFragment implements + Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener { private static final String KEY_AUTHOR = "author"; private static final String KEY_TWITTER = "twitter"; @@ -1004,7 +963,7 @@ public class SettingsActivity extends AbsPreferenceActivity { mCheckUpdate.setOnPreferenceClickListener(this); mCloudDrive = findPreference(KEY_CLOUD_DRIVE); mCloudDrive.setOnPreferenceClickListener(this); - mAllowAnalyics = (CheckBoxPreference)findPreference(KEY_ALLOW_ANALYICS); + mAllowAnalyics = (CheckBoxPreference) findPreference(KEY_ALLOW_ANALYICS); mAllowAnalyics.setOnPreferenceChangeListener(this); mAboutAnalyics = findPreference(KEY_ABOUT_ANALYICS); mAboutAnalyics.setOnPreferenceClickListener(this); @@ -1020,42 +979,41 @@ public class SettingsActivity extends AbsPreferenceActivity { startActivity(i); } else if (KEY_TWITTER.equals(key)) { - new MaterialAlertDialog.Builder(mActivity).setTitle(R.string.twitter_title) - .setItems(new CharSequence[]{"@EhViewer", "@jkjvinn"}, new MaterialAlertDialog.OnClickListener() { - @Override - public boolean onClick(MaterialAlertDialog dialog, int which) { - Uri uri = null; - switch (which) { - case 0: - uri = Uri.parse("https://twitter.com/EhViewer"); - break; - case 1: - uri = Uri.parse("https://twitter.com/jkjvinn"); - break; - } - if (uri != null) { - Intent intent = new Intent(Intent.ACTION_VIEW, uri); - startActivity(intent); - } - return true; - } - }).setNegativeButton(android.R.string.cancel).show(); + new MaterialAlertDialog.Builder(mActivity) + .setTitle(R.string.twitter_title) + .setItems(new CharSequence[] { "@EhViewer", "@jkjvinn" }, + new MaterialAlertDialog.OnClickListener() { + @Override + public boolean onClick(MaterialAlertDialog dialog, int which) { + Uri uri = null; + switch (which) { + case 0: + uri = Uri.parse("https://twitter.com/EhViewer"); + break; + case 1: + uri = Uri.parse("https://twitter.com/jkjvinn"); + break; + } + if (uri != null) { + Intent intent = new Intent(Intent.ACTION_VIEW, uri); + startActivity(intent); + } + return true; + } + }).setNegativeButton(android.R.string.cancel).show(); } else if (KEY_CHANGELOG.equals(key)) { - InputStream is = mActivity.getResources() - .openRawResource(R.raw.change_log); + InputStream is = mActivity.getResources().openRawResource(R.raw.change_log); new MaterialAlertDialog.Builder(mActivity).setTitle(R.string.changelog) - .setMessage(Utils.InputStream2String(is, "utf-8")) - .setNegativeButton(android.R.string.cancel).show(); + .setMessage(Utils.InputStream2String(is, "utf-8")).setNegativeButton(android.R.string.cancel) + .show(); } else if (KEY_THANKS.equals(key)) { - InputStream is = mActivity.getResources() - .openRawResource(R.raw.thanks); + InputStream is = mActivity.getResources().openRawResource(R.raw.thanks); final WebView webView = new WebView(mActivity); webView.loadData(Utils.InputStream2String(is, "utf-8"), "text/html; charset=UTF-8", null); - new MaterialAlertDialog.Builder(mActivity)//.setTitle(R.string.thanks) - .setView(webView, true).setNegativeButton(android.R.string.cancel) - .show(); + new MaterialAlertDialog.Builder(mActivity)// .setTitle(R.string.thanks) + .setView(webView, true).setNegativeButton(android.R.string.cancel).show(); } else if (KEY_WEBSITE.equals(key)) { Uri uri = Uri.parse("http://www.ehviewer.com"); @@ -1070,26 +1028,26 @@ public class SettingsActivity extends AbsPreferenceActivity { } else if (KEY_CHECK_UPDATE.equals(key)) { mCheckUpdate.setSummary(R.string.checking_update); mCheckUpdate.setEnabled(false); - new UpdateHelper((AppContext)mActivity.getApplication()) - .SetOnCheckUpdateListener(new UpdateHelper.OnCheckUpdateListener() { + new UpdateHelper((AppContext) mActivity.getApplication()).SetOnCheckUpdateListener( + new UpdateHelper.OnCheckUpdateListener() { @Override - public void onSuccess(String version, long size, - final String url, final String fileName, String info) { + public void onSuccess(String version, long size, final String url, final String fileName, + String info) { mCheckUpdate.setSummary(R.string.found_update); String sizeStr = Utils.sizeToString(size); - AlertDialog dialog = SuperDialogUtil.createUpdateDialog( - mActivity, version, sizeStr, info, - new View.OnClickListener() { + AlertDialog dialog = DialogUtils.createUpdateDialog(mActivity, version, sizeStr, info, + new MaterialAlertDialog.OnClickListener() { @Override - public void onClick(View v) { - ((AlertButton)v).dialog.dismiss(); - // TODO - HttpHelper hh = new HttpHelper(mActivity); - hh.downloadInThread(url, new File(Config.getDownloadPath()), fileName, false, null, - new UpdateHelper.UpdateListener(mActivity, fileName)); - mCheckUpdate.setEnabled(true); + public boolean onClick(MaterialAlertDialog dialog, int which) { + if (which == MaterialAlertDialog.POSITIVE) { + HttpHelper hh = new HttpHelper(mActivity); + hh.downloadInThread(url, new File(Config.getDownloadPath()), + fileName, false, null, new UpdateHelper.UpdateListener( + mActivity, fileName)); + } + return true; } - }); + }).create(); if (!mActivity.isFinishing()) dialog.show(); } @@ -1116,10 +1074,8 @@ public class SettingsActivity extends AbsPreferenceActivity { } else if (KEY_ABOUT_ANALYICS.equals(key)) { new MaterialAlertDialog.Builder(mActivity).setTitle(R.string.about_analyics_title) - .setMessageAutoLink(Linkify.WEB_URLS) - .setMessage(R.string.about_analyics_comment) - .setNegativeButton(android.R.string.cancel) - .show(); + .setMessageAutoLink(Linkify.WEB_URLS).setMessage(R.string.about_analyics_comment) + .setNegativeButton(android.R.string.cancel).show(); } return true; @@ -1129,7 +1085,7 @@ public class SettingsActivity extends AbsPreferenceActivity { public boolean onPreferenceChange(Preference preference, Object newValue) { final String key = preference.getKey(); if (KEY_ALLOW_ANALYICS.equals(key)) { - if (!(Boolean)newValue) + if (!(Boolean) newValue) Config.setPopularWarning(true); } return true; diff --git a/src/com/hippo/ehviewer/util/DialogUtils.java b/src/com/hippo/ehviewer/util/DialogUtils.java new file mode 100644 index 000000000..d3f06805f --- /dev/null +++ b/src/com/hippo/ehviewer/util/DialogUtils.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2014 Hippo Seven + * + * 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.ehviewer.util; + +import android.content.Context; + +import com.hippo.ehviewer.R; +import com.hippo.ehviewer.app.MaterialAlertDialog; + +public class DialogUtils { + + public static MaterialAlertDialog.Builder createUpdateDialog(Context context, String version, String size, + String info, MaterialAlertDialog.OnClickListener l) { + + return new MaterialAlertDialog.Builder(context).setTitle(R.string.update).setCancelable(false) + .setMessage(String.format(context.getString(R.string.update_message), version, size, info)) + .setPositiveButton(android.R.string.ok).setNegativeButton(android.R.string.cancel).setButtonListener(l); + } +} diff --git a/src/com/hippo/ehviewer/widget/SuperDialogUtil.java b/src/com/hippo/ehviewer/widget/SuperDialogUtil.java deleted file mode 100644 index 16612598b..000000000 --- a/src/com/hippo/ehviewer/widget/SuperDialogUtil.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (C) 2014 Hippo Seven - * - * 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.ehviewer.widget; - -import com.hippo.ehviewer.R; - -import android.app.AlertDialog; -import android.content.Context; -import android.view.View; -import android.widget.TextView; - -public class SuperDialogUtil { - - public static void setTitle(AlertDialog dialog, String title) { - TextView titleView = (TextView)dialog.findViewById(R.id.title); - titleView.setVisibility(View.VISIBLE); - titleView.setText(title); - } - - - public static AlertDialog createUpdateDialog(Context context, String version, - String size, String info, View.OnClickListener positiveListener) { - - return new DialogBuilder(context).setTitle(R.string.update).setCancelable(false) - .setMessage(String.format(context.getString(R.string.update_message), version, size, info)) - .setPositiveButton(android.R.string.ok, positiveListener) - .setSimpleNegativeButton() - .create(); - } -}