src\MyApplication\.idea\compiler.xml
src\MyApplication\.idea\gradle.xml src\MyApplication\.idea\misc.xml src\MyApplication\.idea\modules.xml src\MyApplication\.idea\runConfigurations.xml src\MyApplication\app\build.gradle src\MyApplication\app\src\main\AndroidManifest.xml src\MyApplication\app\src\main\java\com\example\administrator\myapplication\adapter\BgPicGridAdapter.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\adapter\NotebookAdapter.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\app\BaseApplication.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\db\DatabaseHelper.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\db\NoteDatabase.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\entity\BgPicEntity.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\entity\NotebookData.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\entity\OnResponseListener.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\entity\Response.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\entity\UpdataEvent.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\entity\User.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\ui\AboutAppFragment.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\ui\AlarmAlertActivity.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\ui\ChangeBgFragment.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\ui\DateTimePicker.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\ui\DateTimePickerDialog.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\ui\LoginActivity.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\ui\MainActivity.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\ui\NoteBookFragment.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\ui\NoteEditActivity.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\ui\NoteEditFragment.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\ui\RegisterActivity.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\ui\SetLockActivity.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\ui\SettingFragment.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\ui\UnLockActivity.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\ui\UserInfoActivity.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\ui\WelcomeActivity.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\ui\app_bar_activity.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\utils\AccountUtils.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\utils\BmobConstants.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\utils\SystemUtils.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\widget\CircleImageView.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\widget\HTQDragGridView.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\widget\NoteItemCircleView.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\widget\ToggleButton.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\widget\patternlock\LockPatternView.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\widget\patternlock\Point.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\widget\patternlock\RotateDegrees.java src\MyApplication\app\src\main\res\anim\grow_from_bottom.xml src\MyApplication\app\src\main\res\anim\shrink_from_top.xml src\MyApplication\app\src\main\res\drawable-v21\btn_dark_blue_background.xml src\MyApplication\app\src\main\res\drawable-v21\btn_orange_background.xml src\MyApplication\app\src\main\res\drawable-v21\ic_menu_camera.xml src\MyApplication\app\src\main\res\drawable-v21\ic_menu_gallery.xml src\MyApplication\app\src\main\res\drawable-v21\ic_menu_manage.xml src\MyApplication\app\src\main\res\drawable-v21\ic_menu_send.xml src\MyApplication\app\src\main\res\drawable-v21\ic_menu_share.xml src\MyApplication\app\src\main\res\drawable-v21\ic_menu_slideshow.xml src\MyApplication\app\src\main\res\drawable-v21\login_divider_line.xml src\MyApplication\app\src\main\res\drawable-v21\login_et_background.xml src\MyApplication\app\src\main\res\drawable-v21\login_ll_background.xml src\MyApplication\app\src\main\res\drawable\btn_login_selector.xml src\MyApplication\app\src\main\res\drawable\ic_info_black_24dp.xml src\MyApplication\app\src\main\res\drawable\ic_notifications_black_24dp.xml src\MyApplication\app\src\main\res\drawable\ic_sync_black_24dp.xml src\MyApplication\app\src\main\res\drawable\side_nav_bar.xml src\MyApplication\app\src\main\res\drawable\skin_img_item_background.xml src\MyApplication\app\src\main\res\layout\about_me_fragment.xml src\MyApplication\app\src\main\res\layout\activity_login.xml src\MyApplication\app\src\main\res\layout\activity_main.xml src\MyApplication\app\src\main\res\layout\activity_note_edit.xml src\MyApplication\app\src\main\res\layout\activity_register.xml src\MyApplication\app\src\main\res\layout\activity_set_lock.xml src\MyApplication\app\src\main\res\layout\activity_unlock.xml src\MyApplication\app\src\main\res\layout\activity_user_info.xml src\MyApplication\app\src\main\res\layout\activity_welcome.xml src\MyApplication\app\src\main\res\layout\app_bar_main.xml src\MyApplication\app\src\main\res\layout\bg_pic_grid_item.xml src\MyApplication\app\src\main\res\layout\change_info_dialog_layout.xml src\MyApplication\app\src\main\res\layout\content_main.xml src\MyApplication\app\src\main\res\layout\datetime_picker.xml src\MyApplication\app\src\main\res\layout\fragment_change_background.xml src\MyApplication\app\src\main\res\layout\fragment_note.xml src\MyApplication\app\src\main\res\layout\fragment_setting.xml src\MyApplication\app\src\main\res\layout\item_notebook.xml src\MyApplication\app\src\main\res\layout\layout_note_detail_menu.xml src\MyApplication\app\src\main\res\layout\main_fragment.xml src\MyApplication\app\src\main\res\layout\nav_header_main.xml src\MyApplication\app\src\main\res\layout\note_edit_activity_fraglayout.xml src\MyApplication\app\src\main\res\layout\note_edit_fraglayout.xml src\MyApplication\app\src\main\res\layout\pop_showavator.xml src\MyApplication\app\src\main\res\layout\popupwindow_choose_layout.xml src\MyApplication\app\src\main\res\layout\widget_lock_view.xml src\MyApplication\app\src\main\res\menu\activity_main_drawer.xml src\MyApplication\app\src\main\res\menu\main.xml src\MyApplication\app\src\main\res\menu\notebook_edit_menu.xml src\MyApplication\app\src\main\res\values-v21\attrs.xml src\MyApplication\app\src\main\res\values-v21\styles.xml src\MyApplication\app\src\main\res\values-w820dp\dimens.xml src\MyApplication\app\src\main\res\values\attrs.xml src\MyApplication\app\src\main\res\values\colors.xml src\MyApplication\app\src\main\res\values\dimens.xml src\MyApplication\app\src\main\res\values\drawables.xml src\MyApplication\app\src\main\res\values\strings.xml src\MyApplication\app\src\main\res\values\styles.xml src\MyApplication\gradlew src\MyApplication\libs\BmobSDKDemo_v3.6.0\BmobDemo\.idea\compiler.xml src\MyApplication\libs\BmobSDKDemo_v3.6.0\BmobDemo\.idea\encodings.xml src\MyApplication\libs\BmobSDKDemo_v3.6.0\BmobDemo\.idea\gradle.xml src\MyApplication\libs\BmobSDKDemo_v3.6.0\BmobDemo\.idea\misc.xml src\MyApplication\libs\BmobSDKDemo_v3.6.0\BmobDemo\.idea\modules.xml src\MyApplication\libs\BmobSDKDemo_v3.6.0\BmobDemo\.idea\runConfigurations.xml src\MyApplication\libs\BmobSDKDemo_v3.6.0\BmobDemo\app\src\main\java\cn\bmob\sdkdemo\BmobApplication.java src\MyApplication\libs\BmobSDKDemo_v3.6.0\BmobDemo\app\src\main\java\cn\bmob\sdkdemo\autoupdate\ActAutoUpdate.java src\MyApplication\libs\BmobSDKDemo_v3.6.0\BmobDemo\app\src\main\java\cn\bmob\sdkdemo\push\ActBmobPush.java src\MyApplication\libs\BmobSDKDemo_v3.6.0\BmobDemo\gradle\wrapper\gradle-wrapper.properties src\MyApplication\libs\BmobSDKDemo_v3.6.0\BmobDemo\gradlew src\MyApplication\libs\BmobSDKDemo_v3.6.0\更新日志.txt src\MyApplication\settings.gradle src\MyApplication\.idea\codeStyleSettings.xml src\MyApplication\.idea\encodings.xml src\MyApplication\.idea\inspectionProfiles\Project_Default.xml src\MyApplication\.idea\inspectionProfiles\profiles_settings.xml src\MyApplication\.idea\sonarlint\issuestore\0\c\0c2f607fe7104db4aff5a972f67db47c8fc3a01a src\MyApplication\.idea\sonarlint\issuestore\1\4\14d85ff7ad98d57e0b3d3d1342692c5fb59955a4 src\MyApplication\.idea\sonarlint\issuestore\1\e\1e127e509da20f358c272f78cfdaea4346e9199b src\MyApplication\.idea\sonarlint\issuestore\7\7\77b0e160fe3b756580b20d005c789ac79935523a src\MyApplication\.idea\sonarlint\issuestore\8\2\824db7b1941b2ab3f719e805a0d5d84f175b9127 src\MyApplication\.idea\sonarlint\issuestore\8\2\82d2fb9785192ddc21561f59fc59fc0e07e8a84c src\MyApplication\.idea\sonarlint\issuestore\9\a\9a3b018c7a5556301c9f2b82bea49b0b3ceb2613 src\MyApplication\.idea\sonarlint\issuestore\f\0\f07866736216be0ee2aba49e392191aeae700a35 src\MyApplication\.idea\sonarlint\issuestore\f\6\f694bbb1d0ede28a56fa9364fe5df7136cda2823 src\MyApplication\.idea\sonarlint\issuestore\f\d\fd468597b3276a6c77a10eb393b17d78086669ae src\MyApplication\.idea\sonarlint\issuestore\index.pb src\MyApplication\app\src\main\java\com\example\administrator\myapplication\ui\FloatWindowActivity.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\utils\CommonUtils.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\utils\Constants.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\utils\DialogHelp.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\utils\HTQAnimations.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\utils\ImageLoadOptions.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\utils\MD5Util.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\utils\PhotoUtil.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\utils\ResourceParser.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\utils\SPUtils.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\utils\StringUtils.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\utils\TimeZoneUtil.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\webview\APIWebViewActivity.java src\MyApplication\app\src\main\java\com\example\administrator\myapplication\webview\WebActivity.java src\MyApplication\app\src\main\res\drawable\app_bar_menu.png src\MyApplication\app\src\main\res\drawable\app_bar_search.png src\MyApplication\app\src\main\res\layout\activity_api_webview.xml src\MyApplication\app\src\main\res\layout\activity_float_window.xml src\MyApplication\app\src\main\res\layout\activity_web.xml src\MyApplication\app\src\main\res\xml\provider_paths.xml src\MyApplication\library\.gitignore src\MyApplication\library\build.gradle src\MyApplication\library\proguard-rules.pro src\MyApplication\library\src\main\AndroidManifest.xml src\MyApplication\library\src\main\java\com\shuyu\action\web\ActionSelectListener.java src\MyApplication\library\src\main\java\com\shuyu\action\web\CustomActionWebView.java src\MyApplication\library\src\main\res\values\strings.xml
This commit is contained in:
parent
4ed803ccb7
commit
ab6d2dd6d0
|
@ -0,0 +1,228 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ProjectCodeStyleSettingsManager">
|
||||
<option name="PER_PROJECT_SETTINGS">
|
||||
<value>
|
||||
<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
|
||||
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="99" />
|
||||
<option name="PACKAGES_TO_USE_IMPORT_ON_DEMAND">
|
||||
<value />
|
||||
</option>
|
||||
<option name="IMPORT_LAYOUT_TABLE">
|
||||
<value>
|
||||
<package name="android" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="com" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="junit" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="net" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="org" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="java" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="javax" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="" withSubpackages="true" static="false" />
|
||||
<emptyLine />
|
||||
<package name="" withSubpackages="true" static="true" />
|
||||
<emptyLine />
|
||||
</value>
|
||||
</option>
|
||||
<option name="RIGHT_MARGIN" value="100" />
|
||||
<AndroidXmlCodeStyleSettings>
|
||||
<option name="USE_CUSTOM_SETTINGS" value="true" />
|
||||
</AndroidXmlCodeStyleSettings>
|
||||
<Objective-C-extensions>
|
||||
<file>
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Import" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Macro" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Typedef" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Enum" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Constant" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Global" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Struct" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="FunctionPredecl" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Function" />
|
||||
</file>
|
||||
<class>
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Property" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="Synthesize" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InitMethod" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="StaticMethod" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="InstanceMethod" />
|
||||
<option name="com.jetbrains.cidr.lang.util.OCDeclarationKind" value="DeallocMethod" />
|
||||
</class>
|
||||
<extensions>
|
||||
<pair source="cpp" header="h" />
|
||||
<pair source="c" header="h" />
|
||||
</extensions>
|
||||
</Objective-C-extensions>
|
||||
<XML>
|
||||
<option name="XML_KEEP_LINE_BREAKS" value="false" />
|
||||
<option name="XML_ALIGN_ATTRIBUTES" value="false" />
|
||||
<option name="XML_SPACE_INSIDE_EMPTY_TAG" value="true" />
|
||||
</XML>
|
||||
<codeStyleSettings language="XML">
|
||||
<option name="FORCE_REARRANGE_MODE" value="1" />
|
||||
<indentOptions>
|
||||
<option name="CONTINUATION_INDENT_SIZE" value="4" />
|
||||
</indentOptions>
|
||||
<arrangement>
|
||||
<rules>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:android</NAME>
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>xmlns:.*</NAME>
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:id</NAME>
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:name</NAME>
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>name</NAME>
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>style</NAME>
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_NAMESPACE>^$</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:layout_width</NAME>
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:layout_height</NAME>
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:layout_.*</NAME>
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:width</NAME>
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*:height</NAME>
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_NAMESPACE>http://schemas.android.com/apk/res/android</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
<section>
|
||||
<rule>
|
||||
<match>
|
||||
<AND>
|
||||
<NAME>.*</NAME>
|
||||
<XML_NAMESPACE>.*</XML_NAMESPACE>
|
||||
</AND>
|
||||
</match>
|
||||
<order>BY_NAME</order>
|
||||
</rule>
|
||||
</section>
|
||||
</rules>
|
||||
</arrangement>
|
||||
</codeStyleSettings>
|
||||
</value>
|
||||
</option>
|
||||
<option name="PREFERRED_PROJECT_CODE_STYLE" value="glandroid" />
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="Encoding" defaultCharsetForPropertiesFiles="UTF-8">
|
||||
<file url="PROJECT" charset="UTF-8" />
|
||||
</component>
|
||||
</project>
|
|
@ -9,6 +9,7 @@
|
|||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
<option value="$PROJECT_DIR$/app" />
|
||||
<option value="$PROJECT_DIR$/library" />
|
||||
</set>
|
||||
</option>
|
||||
<option name="resolveModulePerSourceSet" value="false" />
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<inspection_tool class="AndroidLintLintBaseline" enabled="false" level="INFO" enabled_by_default="false" />
|
||||
<inspection_tool class="LoggerInitializedWithForeignClass" enabled="false" level="WARNING" enabled_by_default="false">
|
||||
<option name="loggerClassName" value="org.apache.log4j.Logger,org.slf4j.LoggerFactory,org.apache.commons.logging.LogFactory,java.util.logging.Logger" />
|
||||
<option name="loggerFactoryMethodName" value="getLogger,getLogger,getLog,getLogger" />
|
||||
</inspection_tool>
|
||||
</profile>
|
||||
</component>
|
|
@ -0,0 +1,7 @@
|
|||
<component name="InspectionProjectProfileManager">
|
||||
<settings>
|
||||
<option name="PROJECT_PROFILE" value="Project Default" />
|
||||
<option name="USE_PROJECT_PROFILE" value="true" />
|
||||
<version value="1.0" />
|
||||
</settings>
|
||||
</component>
|
|
@ -4,6 +4,7 @@
|
|||
<modules>
|
||||
<module fileurl="file://$PROJECT_DIR$/MyApplication.iml" filepath="$PROJECT_DIR$/MyApplication.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/app/app.iml" filepath="$PROJECT_DIR$/app/app.iml" />
|
||||
<module fileurl="file://$PROJECT_DIR$/library/my_library.iml" filepath="$PROJECT_DIR$/library/my_library.iml" />
|
||||
</modules>
|
||||
</component>
|
||||
</project>
|
|
@ -0,0 +1,11 @@
|
|||
|
||||
gsquid:S3776"RRefactor this method to reduce its Cognitive Complexity from 20 to the 15 allowed.(Æ¿ú„
|
||||
Gsquid:S1135"2Complete the task associated to this TODO comment.(ž¼í
|
||||
Isquid:S1066"/Merge this if statement with the enclosing one.(¿±Ïßüÿÿÿÿ
|
||||
Gsquid:S1135"2Complete the task associated to this TODO comment.(Ö¾ã¯
|
||||
Gsquid:S1135"2Complete the task associated to this TODO comment.(Àó‚´
|
||||
Lsquid:S1135"2Complete the task associated to this TODO comment.(ÉÓÈìýÿÿÿÿ
|
||||
[squid:S2142"FEither re-interrupt this method or rethrow the "InterruptedException".(ä ¹€
|
||||
_squid:CommentedOutCodeLine"<This block of commented-out lines of code should be removed.( àˆ{
|
||||
Gsquid:S1135"2Complete the task associated to this TODO comment.(ž¼í
|
||||
›squid:S1186"€Add a nested comment explaining why this method is empty, throw an UnsupportedOperationException or complete the implementation.(ô¬ý¶ùÿÿÿÿ
|
|
@ -0,0 +1,3 @@
|
|||
|
||||
<
|
||||
build.gradle,f\0\f07866736216be0ee2aba49e392191aeae700a35
|
|
@ -7,7 +7,7 @@ android {
|
|||
useLibrary 'org.apache.http.legacy'
|
||||
defaultConfig {
|
||||
applicationId "com.example.administrator.myapplication"
|
||||
minSdkVersion 15
|
||||
minSdkVersion 17
|
||||
targetSdkVersion 26
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
@ -41,6 +41,7 @@ android {
|
|||
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
compile project(':my_library')
|
||||
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
|
||||
exclude group: 'com.android.support', module: 'support-annotations'
|
||||
})
|
||||
|
|
|
@ -4,25 +4,25 @@
|
|||
android:versionCode="1"
|
||||
android:versionName="2.1.0">
|
||||
|
||||
<uses-permission android:name="android.permission.VIBRATE" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<!--获取GSM(2g)、WCDMA(联通3g)等网络状态的信息 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<!--获取wifi网络状态的信息 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<!--允许读取手机状态 用于创建BmobInstallation-->
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
||||
<uses-permission android:name="android.permission.VIBRATE"/>
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<!-- 获取GSM(2g)、WCDMA(联通3g)等网络状态的信息 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
|
||||
<!-- 获取wifi网络状态的信息 -->
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
|
||||
<!-- 允许读取手机状态 用于创建BmobInstallation -->
|
||||
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||
<uses-permission android:name="android.permission.KILL_BACKGROUND_PROCESSES"/>
|
||||
|
||||
<!--获取sd卡写的权限,用于文件上传和下载-->
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<!-- 获取sd卡写的权限,用于文件上传和下载 -->
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
|
||||
<!-- UIL框架所需的权限 -->
|
||||
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
|
||||
<uses-permission android:name="android.permission.READ_LOGS" />
|
||||
|
||||
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
|
||||
<uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS"/>
|
||||
<uses-permission android:name="android.permission.READ_LOGS"/>
|
||||
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/app_icon"
|
||||
|
@ -30,61 +30,75 @@
|
|||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity
|
||||
android:name="com.example.administrator.myapplication.ui.WelcomeActivity"
|
||||
android:name=".ui.WelcomeActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity><!-- ATTENTION: This was auto-generated to add Google Play services to your project for
|
||||
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. -->
|
||||
</activity>
|
||||
<!--
|
||||
ATTENTION: This was auto-generated to add Google Play services to your project for
|
||||
App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information.
|
||||
-->
|
||||
<meta-data
|
||||
android:name="com.google.android.gms.version"
|
||||
android:value="@integer/google_play_services_version" />
|
||||
<activity
|
||||
android:name="com.example.administrator.myapplication.ui.NoteEditActivity">
|
||||
android:value="@integer/google_play_services_version"/>
|
||||
|
||||
<activity android:name=".ui.NoteEditActivity">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<data android:mimeType="vnd.android.cursor.item/text_note" />
|
||||
<data android:mimeType="vnd.android.cursor.item/call_note" />
|
||||
<action android:name="android.intent.action.VIEW"/>
|
||||
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
|
||||
<data android:mimeType="vnd.android.cursor.item/text_note"/>
|
||||
<data android:mimeType="vnd.android.cursor.item/call_note"/>
|
||||
</intent-filter>
|
||||
|
||||
</activity>
|
||||
<activity android:name=".ui.SetLockActivity"/>
|
||||
<activity
|
||||
android:name=".ui.MainActivity"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/AppTheme.NoActionBar"/>
|
||||
<activity
|
||||
android:name=".ui.UnLockActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.example.administrator.myapplication.ui.SetLockActivity"></activity>
|
||||
android:name=".ui.LoginActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.example.administrator.myapplication.ui.MainActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:label="@string/app_name"></activity>
|
||||
android:name=".ui.UserInfoActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.example.administrator.myapplication.ui.UnLockActivity"
|
||||
android:name=".ui.RegisterActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".ui.AlarmAlertActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
</activity>
|
||||
|
||||
<activity
|
||||
android:name="com.example.administrator.myapplication.ui.LoginActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.example.administrator.myapplication.ui.UserInfoActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.example.administrator.myapplication.ui.RegisterActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.example.administrator.myapplication.ui.AlarmAlertActivity"
|
||||
android:theme="@style/AppTheme.NoActionBar">
|
||||
</activity>
|
||||
<provider
|
||||
android:name="android.support.v4.content.FileProvider"
|
||||
android:authorities="com.example.administrator.myapplication.provider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/provider_paths"/>
|
||||
</provider>
|
||||
|
||||
<receiver
|
||||
android:name="com.example.administrator.myapplication.ui.NoteEditFragment$AlarmReceiver"
|
||||
android:process=":remote" >
|
||||
android:name=".ui.NoteEditFragment$AlarmReceiver"
|
||||
android:process=":remote">
|
||||
</receiver>
|
||||
|
||||
<activity android:name=".ui.FloatWindowActivity">
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
<!-- android:theme="@style/AppTheme.NoActionBar"-->
|
||||
</manifest> <!-- android:theme="@style/AppTheme.NoActionBar" -->
|
||||
|
|
|
@ -35,22 +35,26 @@ public class BgPicGridAdapter extends BaseAdapter {
|
|||
|
||||
@Override
|
||||
public int getCount() {
|
||||
// TODO Auto-generated method stub
|
||||
return bgList.size();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getItem(int position) {
|
||||
// TODO Auto-generated method stub
|
||||
return bgList.get(position);
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getItemId(int position) {
|
||||
// TODO Auto-generated method stub
|
||||
return position;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
// TODO Auto-generated method stub
|
||||
ViewHolder viewHolder;
|
||||
if (convertView == null) {
|
||||
viewHolder = new ViewHolder();
|
||||
|
|
|
@ -29,7 +29,7 @@ public class BaseApplication extends Application {
|
|||
super.onCreate();
|
||||
initImageLoader(this);
|
||||
Bmob.initialize(this, ApplicationId);
|
||||
|
||||
// android 7.0系统解决拍照的问题
|
||||
}
|
||||
|
||||
/** 初始化ImageLoader */
|
||||
|
|
|
@ -6,9 +6,9 @@ import android.database.sqlite.SQLiteOpenHelper;
|
|||
|
||||
public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
|
||||
public static final String COOLNOTE_DATABASE_NAME = "coolnote";
|
||||
public static final String COOLNOTE_DATABASE_NAME = "soucang";
|
||||
|
||||
public static final String NOTE_TABLE_NAME = "htq_Notebook";
|
||||
public static final String NOTE_TABLE_NAME = "sc_Notebook";
|
||||
|
||||
public static final String CREATE_NOTE_TABLE = "create table "
|
||||
+ NOTE_TABLE_NAME
|
||||
|
|
|
@ -11,9 +11,7 @@ import android.widget.TextView;
|
|||
|
||||
import com.example.administrator.myapplication.R;
|
||||
|
||||
/**
|
||||
* Created by htq on 2016/8/11.
|
||||
*/
|
||||
|
||||
public class AboutAppFragment extends Fragment {
|
||||
private View baseView;
|
||||
|
||||
|
|
|
@ -104,12 +104,16 @@ public class AlarmAlertActivity extends Activity implements OnClickListener, OnD
|
|||
mPlayer.setLooping(true);
|
||||
mPlayer.start();
|
||||
} catch (IllegalArgumentException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (SecurityException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IllegalStateException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -73,6 +73,7 @@ public class ChangeBgFragment extends Fragment {
|
|||
|
||||
@Override
|
||||
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
|
||||
// TODO Auto-generated method stub
|
||||
String path = ((BgPicEntity) mBgPicAdapter.getItem(position)).path;
|
||||
|
||||
systemUtils = new SystemUtils(getActivity());
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
package com.example.administrator.myapplication.ui;
|
||||
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.example.administrator.myapplication.R;
|
||||
|
||||
public class FloatWindowActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_float_window);
|
||||
}
|
||||
}
|
|
@ -25,9 +25,7 @@ import butterknife.OnClick;
|
|||
import cn.bmob.v3.BmobUser;
|
||||
import cn.bmob.v3.listener.SaveListener;
|
||||
|
||||
/**
|
||||
* Created by htq on 2016/9/3.
|
||||
*/
|
||||
|
||||
public class LoginActivity extends AppCompatActivity implements View.OnClickListener {
|
||||
|
||||
@BindView(R.id.btn_login)
|
||||
|
|
|
@ -50,9 +50,7 @@ import butterknife.BindView;
|
|||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
|
||||
/**
|
||||
* Created by htq on 2016/8/8.
|
||||
*/
|
||||
|
||||
public class NoteEditFragment extends Fragment implements View.OnClickListener,View.OnTouchListener {
|
||||
@BindView(R.id.note_detail_edit)
|
||||
EditText mEtContent;
|
||||
|
|
|
@ -20,7 +20,9 @@ import butterknife.ButterKnife;
|
|||
import butterknife.OnClick;
|
||||
import cn.bmob.v3.listener.SaveListener;
|
||||
|
||||
|
||||
/**
|
||||
* Created by htq on 2016/9/4.
|
||||
*/
|
||||
public class RegisterActivity extends AppCompatActivity {
|
||||
|
||||
@BindView(R.id.et_username)
|
||||
|
@ -94,6 +96,7 @@ public class RegisterActivity extends AppCompatActivity {
|
|||
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
// TODO Auto-generated method stub
|
||||
progress.dismiss();
|
||||
Snackbar.make(registerBtn,"注册成功", Snackbar.LENGTH_LONG).show();
|
||||
// 将设备与username进行绑定
|
||||
|
@ -107,6 +110,7 @@ public class RegisterActivity extends AppCompatActivity {
|
|||
}
|
||||
@Override
|
||||
public void onFailure(int arg0, String arg1) {
|
||||
// TODO Auto-generated method stub
|
||||
Snackbar.make(registerBtn,"注册失败:", Snackbar.LENGTH_LONG).show();
|
||||
progress.dismiss();
|
||||
}
|
||||
|
|
|
@ -215,6 +215,7 @@ public class UserInfoActivity extends AppCompatActivity {
|
|||
@Override
|
||||
public void onClick(View arg0) {
|
||||
|
||||
// TODO Auto-generated method stub
|
||||
layout_choose.setBackgroundColor(getResources().getColor(
|
||||
R.color.base_color_text_white));
|
||||
layout_photo.setBackgroundDrawable(getResources().getDrawable(
|
||||
|
@ -239,6 +240,7 @@ public class UserInfoActivity extends AppCompatActivity {
|
|||
|
||||
@Override
|
||||
public void onClick(View arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
// ShowLog("点击相册");
|
||||
layout_photo.setBackgroundColor(getResources().getColor(
|
||||
R.color.base_color_text_white));
|
||||
|
@ -310,6 +312,7 @@ public class UserInfoActivity extends AppCompatActivity {
|
|||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
// TODO Auto-generated method stub
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
switch (requestCode) {
|
||||
case BmobConstants.REQUESTCODE_UPLOADAVATAR_CAMERA:// 拍照修改头像
|
||||
|
@ -352,6 +355,7 @@ public class UserInfoActivity extends AppCompatActivity {
|
|||
|
||||
break;
|
||||
case BmobConstants.REQUESTCODE_UPLOADAVATAR_CROP:// 裁剪头像返回
|
||||
// TODO sent to crop
|
||||
if (avatorPop != null) {
|
||||
avatorPop.dismiss();
|
||||
}
|
||||
|
@ -384,6 +388,7 @@ public class UserInfoActivity extends AppCompatActivity {
|
|||
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
// TODO Auto-generated method stub
|
||||
String url = bmobFile.getFileUrl(UserInfoActivity.this);
|
||||
updateUserAvatar(url);
|
||||
AccountUtils.saveUserHeadUrl(UserInfoActivity.this,url);
|
||||
|
@ -392,12 +397,14 @@ public class UserInfoActivity extends AppCompatActivity {
|
|||
|
||||
@Override
|
||||
public void onProgress(Integer arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onFailure(int arg0, String msg) {
|
||||
// TODO Auto-generated method stub
|
||||
Snackbar.make(exitBtn,"头像上传失败:" + msg+ String.valueOf(arg0), Snackbar.LENGTH_LONG).show();
|
||||
// ShowToast("头像上传失败:" + msg+String.valueOf(arg0));
|
||||
}
|
||||
|
@ -410,6 +417,7 @@ public class UserInfoActivity extends AppCompatActivity {
|
|||
updateUserData(u,new UpdateListener() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
// TODO Auto-generated method stub
|
||||
Snackbar.make(exitBtn,"头像更新成功!", Snackbar.LENGTH_SHORT).show();
|
||||
//ShowToast();
|
||||
// 更新头像
|
||||
|
@ -418,6 +426,7 @@ public class UserInfoActivity extends AppCompatActivity {
|
|||
|
||||
@Override
|
||||
public void onFailure(int code, String msg) {
|
||||
// TODO Auto-generated method stub
|
||||
Snackbar.make(exitBtn,"头像更新失败:" + msg+ String.valueOf(code), Snackbar.LENGTH_SHORT).show();
|
||||
//ShowToast();
|
||||
}
|
||||
|
|
|
@ -1,14 +1,16 @@
|
|||
package com.example.administrator.myapplication.ui;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.TabLayout;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.example.administrator.myapplication.R;
|
||||
|
||||
/**
|
||||
* Created by Administrator on 2018/5/14 0014.
|
||||
* Created by Administrator on 2018/5/15 0015.
|
||||
*/
|
||||
|
||||
public class app_bar_activity extends AppCompatActivity{
|
||||
public class app_bar_activity extends AppCompatActivity {
|
||||
private TabLayout mTabLayout;
|
||||
|
||||
@Override
|
||||
|
@ -17,7 +19,7 @@ public class app_bar_activity extends AppCompatActivity{
|
|||
setContentView(R.layout.app_bar_main);
|
||||
|
||||
mTabLayout = (TabLayout) findViewById(R.id.app_bar_tablayout);
|
||||
mTabLayout.addTab(mTabLayout.newTab().setText("文章"));
|
||||
mTabLayout.addTab(mTabLayout.newTab().setText("图片"));
|
||||
mTabLayout.addTab(mTabLayout.newTab().setText("A"));
|
||||
mTabLayout.addTab(mTabLayout.newTab().setText("B"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package com.example.administrator.myapplication.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.NetworkInfo;
|
||||
|
||||
public class CommonUtils {
|
||||
|
||||
/** <20><><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> */
|
||||
public static boolean isNetworkAvailable(Context context) {
|
||||
NetworkInfo info = getNetworkInfo(context);
|
||||
if (info != null) {
|
||||
return info.isAvailable();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** <20><><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD>WIFI */
|
||||
public static boolean isWifi(Context context) {
|
||||
NetworkInfo info = getNetworkInfo(context);
|
||||
if (info != null) {
|
||||
if (info.getType() == ConnectivityManager.TYPE_WIFI)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** <20><><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD><EFBFBD><EFBFBD> */
|
||||
public static boolean isMobile(Context context) {
|
||||
NetworkInfo info = getNetworkInfo(context);
|
||||
if (info != null) {
|
||||
if (info.getType() == ConnectivityManager.TYPE_MOBILE)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static NetworkInfo getNetworkInfo(Context context) {
|
||||
|
||||
ConnectivityManager cm = (ConnectivityManager) context
|
||||
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
return cm.getActiveNetworkInfo();
|
||||
}
|
||||
|
||||
/** <20><><EFBFBD>SD<53><44><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD> */
|
||||
public static boolean checkSdCard() {
|
||||
if (android.os.Environment.getExternalStorageState().equals(
|
||||
android.os.Environment.MEDIA_MOUNTED))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
package com.example.administrator.myapplication.utils;
|
||||
|
||||
/**
|
||||
* Created by htq on 2016/8/10.
|
||||
*/
|
||||
public class Constants {
|
||||
public final static String BUNDLE_KEY_PAGE = "BUNDLE_KEY_PAGE";
|
||||
public final static String BUNDLE_KEY_ARGS = "BUNDLE_KEY_ARGS";
|
||||
public static final String ALART_CONTENT="alart_content";
|
||||
public static final String TEXT_SIZE="text_size";
|
||||
public static final int TEXT_SMALL = 0;
|
||||
public static final int TEXT_MEDIUM = 1;
|
||||
public static final int TEXT_LARGE = 2;
|
||||
public static final int TEXT_SUPER = 3;
|
||||
}
|
|
@ -0,0 +1,124 @@
|
|||
package com.example.administrator.myapplication.utils;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.text.Html;
|
||||
import android.text.TextUtils;
|
||||
|
||||
|
||||
public class DialogHelp {
|
||||
|
||||
/***
|
||||
* 获取一个dialog
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
public static AlertDialog.Builder getDialog(Context context) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
return builder;
|
||||
}
|
||||
|
||||
/***
|
||||
* 获取一个耗时等待对话框
|
||||
* @param context
|
||||
* @param message
|
||||
* @return
|
||||
*/
|
||||
public static ProgressDialog getWaitDialog(Context context, String message) {
|
||||
ProgressDialog waitDialog = new ProgressDialog(context);
|
||||
if (!TextUtils.isEmpty(message)) {
|
||||
waitDialog.setMessage(message);
|
||||
}
|
||||
return waitDialog;
|
||||
}
|
||||
|
||||
/***
|
||||
* 获取一个信息对话框,注意需要自己手动调用show方法显示
|
||||
* @param context
|
||||
* @param message
|
||||
* @param onClickListener
|
||||
* @return
|
||||
*/
|
||||
public static AlertDialog.Builder getMessageDialog(Context context, String message, DialogInterface.OnClickListener onClickListener) {
|
||||
AlertDialog.Builder builder = getDialog(context);
|
||||
builder.setMessage(message);
|
||||
builder.setPositiveButton("确定", onClickListener);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static AlertDialog.Builder getMessageDialog(Context context, String message) {
|
||||
return getMessageDialog(context, message, null);
|
||||
}
|
||||
|
||||
public static AlertDialog.Builder getConfirmDialog(Context context, String message, DialogInterface.OnClickListener onClickListener) {
|
||||
AlertDialog.Builder builder = getDialog(context);
|
||||
builder.setMessage(Html.fromHtml(message));
|
||||
builder.setPositiveButton("确定", onClickListener);
|
||||
builder.setNegativeButton("取消", null);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static AlertDialog.Builder getConfirmDialog(Context context, String message, DialogInterface.OnClickListener onOkClickListener, DialogInterface.OnClickListener onCancleClickListener) {
|
||||
AlertDialog.Builder builder = getDialog(context);
|
||||
builder.setMessage(message);
|
||||
builder.setPositiveButton("确定", onOkClickListener);
|
||||
builder.setNegativeButton("取消", onCancleClickListener);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static AlertDialog.Builder getConfirmDialog(Context context,
|
||||
String message,
|
||||
String okString,
|
||||
String cancleString,
|
||||
DialogInterface.OnClickListener onOkClickListener,
|
||||
DialogInterface.OnClickListener onCancleClickListener) {
|
||||
return getConfirmDialog(context, "", message, okString, cancleString, onOkClickListener, onCancleClickListener);
|
||||
}
|
||||
|
||||
public static AlertDialog.Builder getConfirmDialog(Context context,
|
||||
String title,
|
||||
String message,
|
||||
String okString,
|
||||
String cancleString,
|
||||
DialogInterface.OnClickListener onOkClickListener,
|
||||
DialogInterface.OnClickListener onCancleClickListener) {
|
||||
AlertDialog.Builder builder = getDialog(context);
|
||||
if (!TextUtils.isEmpty(title)) {
|
||||
builder.setTitle(title);
|
||||
}
|
||||
builder.setMessage(message);
|
||||
builder.setPositiveButton(okString, onOkClickListener);
|
||||
builder.setNegativeButton(cancleString, onCancleClickListener);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static AlertDialog.Builder getSelectDialog(Context context, String title, String[] arrays, DialogInterface.OnClickListener onClickListener) {
|
||||
AlertDialog.Builder builder = getDialog(context);
|
||||
builder.setItems(arrays, onClickListener);
|
||||
if (!TextUtils.isEmpty(title)) {
|
||||
builder.setTitle(title);
|
||||
}
|
||||
builder.setPositiveButton("取消", null);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static AlertDialog.Builder getSelectDialog(Context context, String[] arrays, DialogInterface.OnClickListener onClickListener) {
|
||||
return getSelectDialog(context, "", arrays, onClickListener);
|
||||
}
|
||||
|
||||
public static AlertDialog.Builder getSingleChoiceDialog(Context context, String title, String[] arrays, int selectIndex, DialogInterface.OnClickListener onClickListener) {
|
||||
AlertDialog.Builder builder = getDialog(context);
|
||||
builder.setSingleChoiceItems(arrays, selectIndex, onClickListener);
|
||||
if (!TextUtils.isEmpty(title)) {
|
||||
builder.setTitle(title);
|
||||
}
|
||||
builder.setNegativeButton("取消", null);
|
||||
return builder;
|
||||
}
|
||||
|
||||
public static AlertDialog.Builder getSingleChoiceDialog(Context context, String[] arrays, int selectIndex, DialogInterface.OnClickListener onClickListener) {
|
||||
return getSingleChoiceDialog(context, "", arrays, selectIndex, onClickListener);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,189 @@
|
|||
package com.example.administrator.myapplication.utils;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.animation.AlphaAnimation;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.AnimationSet;
|
||||
import android.view.animation.AnticipateInterpolator;
|
||||
import android.view.animation.OvershootInterpolator;
|
||||
import android.view.animation.RotateAnimation;
|
||||
import android.view.animation.ScaleAnimation;
|
||||
import android.view.animation.TranslateAnimation;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.RelativeLayout;
|
||||
|
||||
/**
|
||||
* 录音动画类
|
||||
*/
|
||||
public class HTQAnimations {
|
||||
|
||||
/**
|
||||
* 旋转 Rotate
|
||||
*/
|
||||
public static Animation getRotateAnimation(float fromDegrees,
|
||||
float toDegrees, long durationMillis) {
|
||||
RotateAnimation rotate = new RotateAnimation(fromDegrees, toDegrees,
|
||||
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
|
||||
0.5f);
|
||||
rotate.setDuration(durationMillis);
|
||||
rotate.setFillAfter(true);
|
||||
return rotate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 透明度 Alpha
|
||||
*/
|
||||
public static Animation getAlphaAnimation(float fromAlpha, float toAlpha,
|
||||
long durationMillis) {
|
||||
AlphaAnimation alpha = new AlphaAnimation(fromAlpha, toAlpha);
|
||||
alpha.setDuration(durationMillis);
|
||||
alpha.setFillAfter(true);
|
||||
return alpha;
|
||||
}
|
||||
|
||||
/**
|
||||
* 缩放 Scale
|
||||
*/
|
||||
public static Animation getScaleAnimation(float scaleXY, long durationMillis) {
|
||||
ScaleAnimation scale = new ScaleAnimation(1.0f, scaleXY, 1.0f, scaleXY,
|
||||
Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
|
||||
0.5f);
|
||||
scale.setDuration(durationMillis);
|
||||
return scale;
|
||||
}
|
||||
|
||||
/**
|
||||
* 位移 Translate
|
||||
*/
|
||||
public static Animation getTranslateAnimation(float fromXDelta,
|
||||
float toXDelta, float fromYDelta, float toYDelta,
|
||||
long durationMillis) {
|
||||
TranslateAnimation translate = new TranslateAnimation(fromXDelta,
|
||||
toXDelta, fromYDelta, toYDelta);
|
||||
translate.setDuration(durationMillis);
|
||||
translate.setFillAfter(true);
|
||||
return translate;
|
||||
}
|
||||
|
||||
public static Animation clickAnimation(float scaleXY, long durationMillis) {
|
||||
AnimationSet set = new AnimationSet(true);
|
||||
set.addAnimation(getScaleAnimation(scaleXY, durationMillis));
|
||||
set.setDuration(durationMillis);
|
||||
return set;
|
||||
}
|
||||
|
||||
public static Animation shakeAnimation(int X) {
|
||||
AnimationSet set = new AnimationSet(true);
|
||||
Animation anim1 = getTranslateAnimation(0, -200, 0, 0, 100);
|
||||
anim1.setStartOffset(100);
|
||||
set.addAnimation(anim1);
|
||||
Animation anim2 = getTranslateAnimation(-200, 400, 0, 0, 200);
|
||||
anim2.setStartOffset(300);
|
||||
set.addAnimation(anim2);
|
||||
Animation anim3 = getTranslateAnimation(400, -200, 0, 0, 200);
|
||||
anim3.setStartOffset(500);
|
||||
set.addAnimation(anim3);
|
||||
Animation anim4 = getTranslateAnimation(-200, 0, 0, 0, 100);
|
||||
anim4.setStartOffset(600);
|
||||
set.addAnimation(anim4);
|
||||
set.setFillAfter(true);
|
||||
set.setDuration(640);
|
||||
return set;
|
||||
}
|
||||
|
||||
/**
|
||||
* 打开的动画
|
||||
*
|
||||
* @param relativeLayout
|
||||
* 子菜单容器
|
||||
* @param background
|
||||
* 子菜单背景
|
||||
* @param menu
|
||||
* 菜单按钮
|
||||
* @param durationMillis
|
||||
* 动画时间
|
||||
*/
|
||||
public static void openAnimation(RelativeLayout relativeLayout,
|
||||
ImageView menu, long durationMillis) {
|
||||
relativeLayout.setVisibility(View.VISIBLE);
|
||||
for (int i = 1; i < relativeLayout.getChildCount(); i++) {
|
||||
ImageView imageView = null;
|
||||
if (relativeLayout.getChildAt(i) instanceof ImageView) {
|
||||
imageView = (ImageView) relativeLayout.getChildAt(i);
|
||||
} else {
|
||||
continue;
|
||||
|
||||
}
|
||||
|
||||
int top = imageView.getTop();
|
||||
int left = imageView.getLeft();
|
||||
if (top == 0) {
|
||||
top = (menu.getHeight() + 50) * i;
|
||||
}
|
||||
if (left == 0) {
|
||||
left = menu.getLeft();
|
||||
}
|
||||
AnimationSet set = new AnimationSet(true);
|
||||
set.addAnimation(getRotateAnimation(-360, 0, durationMillis));
|
||||
set.addAnimation(getAlphaAnimation(0.5f, 1.0f, durationMillis));
|
||||
set.addAnimation(getTranslateAnimation(menu.getLeft() - left, 0,
|
||||
menu.getTop() - top + 30, 0, durationMillis));// 加30是由于图片上部有一些透明高度
|
||||
set.setFillAfter(true);
|
||||
set.setDuration(durationMillis);
|
||||
set.setStartOffset((i * 100)
|
||||
/ (-1 + relativeLayout.getChildCount()));
|
||||
set.setInterpolator(new OvershootInterpolator(1f));
|
||||
imageView.startAnimation(set);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭的动画
|
||||
*
|
||||
* @param relativeLayout
|
||||
* 子菜单容器
|
||||
* @param background
|
||||
* 子菜单背景
|
||||
* @param menu
|
||||
* 菜单按钮
|
||||
* @param durationMillis
|
||||
* 动画时间
|
||||
*/
|
||||
public static void closeAnimation(final RelativeLayout relativeLayout,
|
||||
final ImageView menu, long durationMillis) {
|
||||
for (int i = 1; i < relativeLayout.getChildCount(); i++) {
|
||||
ImageView imageView = null;
|
||||
if (relativeLayout.getChildAt(i) instanceof ImageView) {
|
||||
imageView = (ImageView) relativeLayout.getChildAt(i);
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
|
||||
AnimationSet set = new AnimationSet(true);
|
||||
set.addAnimation(getRotateAnimation(0, -360, durationMillis));
|
||||
set.addAnimation(getAlphaAnimation(1.0f, 0.5f, durationMillis));
|
||||
set.addAnimation(getTranslateAnimation(0, menu.getLeft()
|
||||
- imageView.getLeft(), 0,
|
||||
menu.getTop() - imageView.getTop() + 30, durationMillis));// 加30是由于图片上部有一些透明高度
|
||||
set.setFillAfter(true);
|
||||
set.setDuration(durationMillis);
|
||||
set.setStartOffset(((relativeLayout.getChildCount() - i) * 100)
|
||||
/ (-1 + relativeLayout.getChildCount()));
|
||||
set.setInterpolator(new AnticipateInterpolator(1f));
|
||||
set.setAnimationListener(new Animation.AnimationListener() {
|
||||
@Override
|
||||
public void onAnimationStart(Animation arg0) {}
|
||||
|
||||
@Override
|
||||
public void onAnimationRepeat(Animation arg0) {}
|
||||
|
||||
@Override
|
||||
public void onAnimationEnd(Animation arg0) {
|
||||
relativeLayout.setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
imageView.startAnimation(set);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
package com.example.administrator.myapplication.utils;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
|
||||
import com.nostra13.universalimageloader.core.DisplayImageOptions;
|
||||
import com.nostra13.universalimageloader.core.assist.ImageScaleType;
|
||||
import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer;
|
||||
|
||||
public class ImageLoadOptions {
|
||||
|
||||
public static DisplayImageOptions getOptions() {
|
||||
DisplayImageOptions options = new DisplayImageOptions.Builder()
|
||||
// // <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڼ<EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ͼƬ
|
||||
// .showImageOnLoading(R.drawable.small_image_holder_listpage)
|
||||
// // <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬUriΪ<EFBFBD>ջ<EFBFBD><EFBFBD>Ǵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ͼƬ
|
||||
// .showImageForEmptyUri(R.drawable.small_image_holder_listpage)
|
||||
// // <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>/<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>ͼƬ
|
||||
// .showImageOnFail(R.drawable.small_image_holder_listpage)
|
||||
.cacheInMemory(true)
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>ͼƬ<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڴ<EFBFBD><EFBFBD><EFBFBD>
|
||||
.cacheOnDisc(true)
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD>ͼƬ<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD>SD<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
.considerExifParams(true)
|
||||
.imageScaleType(ImageScaleType.EXACTLY)// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>εı<EFBFBD><EFBFBD>뷽ʽ<EFBFBD><EFBFBD>ʾ
|
||||
.bitmapConfig(Bitmap.Config.RGB_565)// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ<EFBFBD>Ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// .decodingOptions(android.graphics.BitmapFactory.Options
|
||||
// decodingOptions)//<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ<EFBFBD>Ľ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
.considerExifParams(true)
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD>
|
||||
// .delayBeforeLoading(int delayInMillis)//int
|
||||
// delayInMillisΪ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD><EFBFBD>ӳ<EFBFBD>ʱ<EFBFBD><EFBFBD>
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ<EFBFBD><EFBFBD><EFBFBD>뻺<EFBFBD><EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>bitmap<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
// <EFBFBD><EFBFBD>preProcessor(BitmapProcessor preProcessor)
|
||||
.resetViewBeforeLoading(true)// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ǰ<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><EFBFBD><EFBFBD>λ
|
||||
// .displayer(new RoundedBitmapDisplayer(20))//<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ΪԲ<EFBFBD>ǣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
.displayer(new FadeInBitmapDisplayer(100))// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
.build();
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,46 @@
|
|||
package com.example.administrator.myapplication.utils;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
|
||||
|
||||
public class MD5Util {
|
||||
public static String MD5(String str) {
|
||||
MessageDigest md5 = null;
|
||||
try {
|
||||
md5 = MessageDigest.getInstance("MD5");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return "";
|
||||
}
|
||||
|
||||
char[] charArray = str.toCharArray();
|
||||
byte[] byteArray = new byte[charArray.length];
|
||||
|
||||
for (int i = 0; i < charArray.length; i++) {
|
||||
byteArray[i] = (byte) charArray[i];
|
||||
}
|
||||
byte[] md5Bytes = md5.digest(byteArray);
|
||||
|
||||
StringBuffer hexValue = new StringBuffer();
|
||||
for (int i = 0; i < md5Bytes.length; i++) {
|
||||
int val = ((int) md5Bytes[i]) & 0xff;
|
||||
if (val < 16) {
|
||||
hexValue.append("0");
|
||||
}
|
||||
hexValue.append(Integer.toHexString(val));
|
||||
}
|
||||
return hexValue.toString();
|
||||
}
|
||||
|
||||
// 可逆的加密算法
|
||||
public static String encryptmd5(String str) {
|
||||
char[] a = str.toCharArray();
|
||||
for (int i = 0; i < a.length; i++) {
|
||||
a[i] = (char) (a[i] ^ 'l');
|
||||
}
|
||||
String s = new String(a);
|
||||
return s;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,300 @@
|
|||
package com.example.administrator.myapplication.utils;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Bitmap.Config;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff.Mode;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.media.ExifInterface;
|
||||
import android.media.ThumbnailUtils;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
public class PhotoUtil {
|
||||
|
||||
/**
|
||||
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> recycle
|
||||
*
|
||||
* @throws
|
||||
*/
|
||||
public static void recycle(Bitmap bitmap) {
|
||||
// <EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
if (bitmap != null && !bitmap.isRecycled()) {
|
||||
// <EFBFBD><EFBFBD><EFBFBD>ղ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊnull
|
||||
bitmap.recycle();
|
||||
bitmap = null;
|
||||
}
|
||||
System.gc();
|
||||
}
|
||||
|
||||
/**
|
||||
* <EFBFBD><EFBFBD>ȡָ<EFBFBD><EFBFBD>·<EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>ͼƬ<EFBFBD><EFBFBD>ָ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>С<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ getImageThumbnail
|
||||
*
|
||||
* @return Bitmap
|
||||
* @throws
|
||||
*/
|
||||
public static Bitmap getImageThumbnail(String imagePath, int width,
|
||||
int height) {
|
||||
Bitmap bitmap = null;
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inJustDecodeBounds = true;
|
||||
// <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD>ͼƬ<EFBFBD>Ŀ<EFBFBD>ߣ<EFBFBD>ע<EFBFBD><EFBFBD>˴<EFBFBD><EFBFBD><EFBFBD>bitmapΪnull
|
||||
bitmap = BitmapFactory.decodeFile(imagePath, options);
|
||||
options.inJustDecodeBounds = false; // <EFBFBD><EFBFBD>Ϊ false
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ű<EFBFBD>
|
||||
int h = options.outHeight;
|
||||
int w = options.outWidth;
|
||||
int beWidth = w / width;
|
||||
int beHeight = h / height;
|
||||
int be = 1;
|
||||
if (beWidth < beHeight) {
|
||||
be = beWidth;
|
||||
} else {
|
||||
be = beHeight;
|
||||
}
|
||||
if (be <= 0) {
|
||||
be = 1;
|
||||
}
|
||||
options.inSampleSize = be;
|
||||
// <EFBFBD><EFBFBD><EFBFBD>¶<EFBFBD><EFBFBD><EFBFBD>ͼƬ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD>ź<EFBFBD><EFBFBD>bitmap<EFBFBD><EFBFBD>ע<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>options.inJustDecodeBounds <EFBFBD><EFBFBD>Ϊ false
|
||||
bitmap = BitmapFactory.decodeFile(imagePath, options);
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ThumbnailUtils<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫָ<EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD>Bitmap<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
bitmap = ThumbnailUtils.extractThumbnail(bitmap, width, height,
|
||||
ThumbnailUtils.OPTIONS_RECYCLE_INPUT);
|
||||
return bitmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* saveBitmap
|
||||
*
|
||||
* @param @param filename---<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽ-<EFBFBD><EFBFBD>Ŀ¼<EFBFBD>Լ<EFBFBD><EFBFBD>ļ<EFBFBD><EFBFBD><EFBFBD>
|
||||
* @param @param bitmap
|
||||
* @param @param isDelete --<EFBFBD>Ƿ<EFBFBD>ֻ<EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>
|
||||
* @return void
|
||||
* @throws
|
||||
*/
|
||||
public static void saveBitmap(String dirpath, String filename,
|
||||
Bitmap bitmap, boolean isDelete) {
|
||||
File dir = new File(dirpath);
|
||||
if (!dir.exists()) {
|
||||
dir.mkdirs();
|
||||
}
|
||||
|
||||
File file = new File(dirpath, filename);
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڼ<EFBFBD>ɾ<EFBFBD><EFBFBD>-Ĭ<EFBFBD><EFBFBD>ֻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD>
|
||||
if (isDelete) {
|
||||
if (file.exists()) {
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
if (!file.exists()) {
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
FileOutputStream out = null;
|
||||
try {
|
||||
out = new FileOutputStream(file);
|
||||
if (bitmap.compress(Bitmap.CompressFormat.PNG, 100, out)) {
|
||||
out.flush();
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
if (out != null) {
|
||||
try {
|
||||
out.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static File getFilePath(String filePath, String fileName) {
|
||||
File file = null;
|
||||
makeRootDirectory(filePath);
|
||||
try {
|
||||
file = new File(filePath + fileName);
|
||||
if (!file.exists()) {
|
||||
file.createNewFile();
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return file;
|
||||
}
|
||||
|
||||
public static void makeRootDirectory(String filePath) {
|
||||
File file = null;
|
||||
try {
|
||||
file = new File(filePath);
|
||||
if (!file.exists()) {
|
||||
file.mkdirs();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* <EFBFBD><EFBFBD>ȡͼƬ<EFBFBD><EFBFBD><EFBFBD>ԣ<EFBFBD><EFBFBD><EFBFBD>ת<EFBFBD>ĽǶ<EFBFBD>
|
||||
* @param path ͼƬ<EFBFBD><EFBFBD><EFBFBD>·<EFBFBD><EFBFBD>
|
||||
* @return degree<EFBFBD><EFBFBD>ת<EFBFBD>ĽǶ<EFBFBD>
|
||||
*/
|
||||
|
||||
public static int readPictureDegree(String path) {
|
||||
int degree = 0;
|
||||
try {
|
||||
ExifInterface exifInterface = new ExifInterface(path);
|
||||
int orientation = exifInterface.getAttributeInt(
|
||||
ExifInterface.TAG_ORIENTATION,
|
||||
ExifInterface.ORIENTATION_NORMAL);
|
||||
switch (orientation) {
|
||||
case ExifInterface.ORIENTATION_ROTATE_90:
|
||||
degree = 90;
|
||||
break;
|
||||
case ExifInterface.ORIENTATION_ROTATE_180:
|
||||
degree = 180;
|
||||
break;
|
||||
case ExifInterface.ORIENTATION_ROTATE_270:
|
||||
degree = 270;
|
||||
break;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return degree;
|
||||
|
||||
}
|
||||
|
||||
/** <EFBFBD><EFBFBD>תͼƬһ<EFBFBD><EFBFBD><EFBFBD>Ƕ<EFBFBD>
|
||||
* rotaingImageView
|
||||
* @return Bitmap
|
||||
* @throws
|
||||
*/
|
||||
public static Bitmap rotaingImageView(int angle, Bitmap bitmap) {
|
||||
// <EFBFBD><EFBFBD>תͼƬ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
Matrix matrix = new Matrix();
|
||||
matrix.postRotate(angle);
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD>ͼƬ
|
||||
Bitmap resizedBitmap = Bitmap.createBitmap(bitmap, 0, 0,
|
||||
bitmap.getWidth(), bitmap.getHeight(), matrix, true);
|
||||
return resizedBitmap;
|
||||
}
|
||||
|
||||
/**
|
||||
* <EFBFBD><EFBFBD>ͼƬ<EFBFBD><EFBFBD>ΪԲ<EFBFBD><EFBFBD>
|
||||
*
|
||||
* @param bitmap
|
||||
* ԭBitmapͼƬ
|
||||
* @param pixels
|
||||
* ͼƬԲ<EFBFBD>ǵĻ<EFBFBD><EFBFBD><EFBFBD>(<EFBFBD><EFBFBD>λ:<EFBFBD><EFBFBD><EFBFBD><EFBFBD>(px))
|
||||
* @return <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Բ<EFBFBD>ǵ<EFBFBD>ͼƬ(Bitmap <EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
||||
*/
|
||||
public static Bitmap toRoundCorner(Bitmap bitmap, int pixels) {
|
||||
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
|
||||
bitmap.getHeight(), Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(output);
|
||||
|
||||
final int color = 0xff424242;
|
||||
final Paint paint = new Paint();
|
||||
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
|
||||
final RectF rectF = new RectF(rect);
|
||||
final float roundPx = pixels;
|
||||
|
||||
paint.setAntiAlias(true);
|
||||
canvas.drawARGB(0, 0, 0, 0);
|
||||
paint.setColor(color);
|
||||
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
|
||||
|
||||
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
|
||||
canvas.drawBitmap(bitmap, rect, rect, paint);
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
/**
|
||||
* <EFBFBD><EFBFBD>ͼƬת<EFBFBD><EFBFBD>ΪԲ<EFBFBD><EFBFBD>ͷ<EFBFBD><EFBFBD>
|
||||
*
|
||||
* @Title: toRoundBitmap
|
||||
* @throws
|
||||
*/
|
||||
public static Bitmap toRoundBitmap(Bitmap bitmap) {
|
||||
int width = bitmap.getWidth();
|
||||
int height = bitmap.getHeight();
|
||||
float roundPx;
|
||||
float left, top, right, bottom, dst_left, dst_top, dst_right, dst_bottom;
|
||||
if (width <= height) {
|
||||
roundPx = width / 2;
|
||||
|
||||
left = 0;
|
||||
top = 0;
|
||||
right = width;
|
||||
bottom = width;
|
||||
|
||||
height = width;
|
||||
|
||||
dst_left = 0;
|
||||
dst_top = 0;
|
||||
dst_right = width;
|
||||
dst_bottom = width;
|
||||
} else {
|
||||
roundPx = height / 2;
|
||||
|
||||
float clip = (width - height) / 2;
|
||||
|
||||
left = clip;
|
||||
right = width - clip;
|
||||
top = 0;
|
||||
bottom = height;
|
||||
width = height;
|
||||
|
||||
dst_left = 0;
|
||||
dst_top = 0;
|
||||
dst_right = height;
|
||||
dst_bottom = height;
|
||||
}
|
||||
|
||||
Bitmap output = Bitmap.createBitmap(width, height, Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(output);
|
||||
|
||||
final Paint paint = new Paint();
|
||||
final Rect src = new Rect((int) left, (int) top, (int) right,
|
||||
(int) bottom);
|
||||
final Rect dst = new Rect((int) dst_left, (int) dst_top,
|
||||
(int) dst_right, (int) dst_bottom);
|
||||
final RectF rectF = new RectF(dst);
|
||||
|
||||
paint.setAntiAlias(true);// <EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
|
||||
canvas.drawARGB(0, 0, 0, 0); // <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Canvas
|
||||
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Բ,drawRounRect<EFBFBD><EFBFBD>drawCircle
|
||||
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);// <EFBFBD><EFBFBD>Բ<EFBFBD>Ǿ<EFBFBD><EFBFBD>Σ<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊͼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><EFBFBD><EFBFBD>ˮƽԲ<EFBFBD>ǰ뾶<EFBFBD>ʹ<EFBFBD>ֱԲ<EFBFBD>ǰ뾶<EFBFBD><EFBFBD>
|
||||
// canvas.drawCircle(roundPx, roundPx, roundPx, paint);
|
||||
|
||||
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͼƬ<EFBFBD>ཻʱ<EFBFBD><EFBFBD>ģʽ,<EFBFBD>ο<EFBFBD>http://trylovecatch.iteye.com/blog/1189452
|
||||
canvas.drawBitmap(bitmap, src, dst, paint); // <EFBFBD><EFBFBD>Mode.SRC_INģʽ<EFBFBD>ϲ<EFBFBD>bitmap<EFBFBD><EFBFBD><EFBFBD>Ѿ<EFBFBD>draw<EFBFBD>˵<EFBFBD>Circle
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package com.example.administrator.myapplication.utils;
|
||||
|
||||
import com.example.administrator.myapplication.R;
|
||||
|
||||
/**
|
||||
* Created by htq on 2016/9/15.
|
||||
*/
|
||||
public class ResourceParser {
|
||||
public static final int TEXT_SMALL = 0;
|
||||
public static final int TEXT_MEDIUM = 1;
|
||||
public static final int TEXT_LARGE = 2;
|
||||
public static final int TEXT_SUPER = 3;
|
||||
|
||||
public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM;
|
||||
|
||||
public static class TextAppearanceResources {
|
||||
private final static int [] TEXTAPPEARANCE_RESOURCES = new int [] {
|
||||
R.style.TextAppearanceNormal,
|
||||
R.style.TextAppearanceMedium,
|
||||
R.style.TextAppearanceLarge,
|
||||
R.style.TextAppearanceSuper
|
||||
};
|
||||
|
||||
public static int getTexAppearanceResource(int id) {
|
||||
/**
|
||||
* HACKME: Fix bug of store the resource id in shared preference.
|
||||
* The id may larger than the length of resources, in this case,
|
||||
* return the {@link ResourceParser#BG_DEFAULT_FONT_SIZE}
|
||||
*/
|
||||
if (id >= TEXTAPPEARANCE_RESOURCES.length) {
|
||||
return BG_DEFAULT_FONT_SIZE;
|
||||
}
|
||||
return TEXTAPPEARANCE_RESOURCES[id];
|
||||
}
|
||||
|
||||
public static int getResourcesSize() {
|
||||
return TEXTAPPEARANCE_RESOURCES.length;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,195 @@
|
|||
package com.example.administrator.myapplication.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by Wentong WANG on 2016/6/6.
|
||||
*/
|
||||
public class SPUtils {
|
||||
/**
|
||||
* 保存在手机里面的文件名
|
||||
*/
|
||||
public static final String FILE_NAME = "user_data";
|
||||
|
||||
/**
|
||||
* 保存数据的方法,我们需要拿到保存数据的具体类型,然后根据类型调用不同的保存方法
|
||||
*
|
||||
* @param context
|
||||
* @param key
|
||||
* @param object
|
||||
*/
|
||||
public static void put(Context context, String key, Object object)
|
||||
{
|
||||
|
||||
SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
|
||||
Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
|
||||
if (object instanceof String)
|
||||
{
|
||||
editor.putString(key, (String) object);
|
||||
} else if (object instanceof Integer)
|
||||
{
|
||||
editor.putInt(key, (Integer) object);
|
||||
} else if (object instanceof Boolean)
|
||||
{
|
||||
editor.putBoolean(key, (Boolean) object);
|
||||
} else if (object instanceof Float)
|
||||
{
|
||||
editor.putFloat(key, (Float) object);
|
||||
} else if (object instanceof Long)
|
||||
{
|
||||
editor.putLong(key, (Long) object);
|
||||
} else
|
||||
{
|
||||
editor.putString(key, object.toString());
|
||||
}
|
||||
|
||||
SharedPreferencesCompat.apply(editor);
|
||||
}
|
||||
|
||||
/**
|
||||
* 得到保存数据的方法,我们根据默认值得到保存的数据的具体类型,然后调用相对于的方法获取值
|
||||
*
|
||||
* @param context
|
||||
* @param key
|
||||
* @param defaultObject
|
||||
* @return
|
||||
*/
|
||||
public static Object get(Context context, String key, Object defaultObject)
|
||||
{
|
||||
SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
|
||||
Context.MODE_PRIVATE);
|
||||
|
||||
if (defaultObject instanceof String)
|
||||
{
|
||||
return sp.getString(key, (String) defaultObject);
|
||||
} else if (defaultObject instanceof Integer)
|
||||
{
|
||||
return sp.getInt(key, (Integer) defaultObject);
|
||||
} else if (defaultObject instanceof Boolean)
|
||||
{
|
||||
return sp.getBoolean(key, (Boolean) defaultObject);
|
||||
} else if (defaultObject instanceof Float)
|
||||
{
|
||||
return sp.getFloat(key, (Float) defaultObject);
|
||||
} else if (defaultObject instanceof Long)
|
||||
{
|
||||
return sp.getLong(key, (Long) defaultObject);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 移除某个key值已经对应的值
|
||||
* @param context
|
||||
* @param key
|
||||
*/
|
||||
public static void remove(Context context, String key)
|
||||
{
|
||||
SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
|
||||
Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
editor.remove(key);
|
||||
SharedPreferencesCompat.apply(editor);
|
||||
}
|
||||
|
||||
/**
|
||||
* 清除所有数据
|
||||
* @param context
|
||||
*/
|
||||
public static void clear(Context context)
|
||||
{
|
||||
SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
|
||||
Context.MODE_PRIVATE);
|
||||
SharedPreferences.Editor editor = sp.edit();
|
||||
editor.clear();
|
||||
SharedPreferencesCompat.apply(editor);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询某个key是否已经存在
|
||||
* @param context
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public static boolean contains(Context context, String key)
|
||||
{
|
||||
SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
|
||||
Context.MODE_PRIVATE);
|
||||
return sp.contains(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回所有的键值对
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, ?> getAll(Context context)
|
||||
{
|
||||
SharedPreferences sp = context.getSharedPreferences(FILE_NAME,
|
||||
Context.MODE_PRIVATE);
|
||||
return sp.getAll();
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个解决SharedPreferencesCompat.apply方法的一个兼容类
|
||||
*
|
||||
* @author zhy
|
||||
*
|
||||
*/
|
||||
private static class SharedPreferencesCompat
|
||||
{
|
||||
private static final Method sApplyMethod = findApplyMethod();
|
||||
|
||||
/**
|
||||
* 反射查找apply的方法
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
private static Method findApplyMethod()
|
||||
{
|
||||
try
|
||||
{
|
||||
Class clz = SharedPreferences.Editor.class;
|
||||
return clz.getMethod("apply");
|
||||
} catch (NoSuchMethodException e)
|
||||
{
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 如果找到则使用apply执行,否则使用commit
|
||||
*
|
||||
* @param editor
|
||||
*/
|
||||
public static void apply(SharedPreferences.Editor editor)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (sApplyMethod != null)
|
||||
{
|
||||
sApplyMethod.invoke(editor);
|
||||
return;
|
||||
}
|
||||
} catch (IllegalArgumentException e)
|
||||
{
|
||||
} catch (IllegalAccessException e)
|
||||
{
|
||||
} catch (InvocationTargetException e)
|
||||
{
|
||||
}
|
||||
editor.commit();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,598 @@
|
|||
package com.example.administrator.myapplication.utils;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* 字符串操作工具包
|
||||
*
|
||||
* @author liux (http://my.oschina.net/liux)
|
||||
* @version 1.0
|
||||
* @created 2012-3-21
|
||||
*/
|
||||
public class StringUtils {
|
||||
private final static Pattern emailer = Pattern
|
||||
.compile("\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*");
|
||||
|
||||
private final static Pattern IMG_URL = Pattern
|
||||
.compile(".*?(gif|jpeg|png|jpg|bmp)");
|
||||
|
||||
private final static Pattern URL = Pattern
|
||||
.compile("^(https|http)://.*?$(net|com|.com.cn|org|me|)");
|
||||
|
||||
private final static ThreadLocal<SimpleDateFormat> dateFormater = new ThreadLocal<SimpleDateFormat>() {
|
||||
@Override
|
||||
protected SimpleDateFormat initialValue() {
|
||||
return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||
}
|
||||
};
|
||||
|
||||
private final static ThreadLocal<SimpleDateFormat> dateFormater2 = new ThreadLocal<SimpleDateFormat>() {
|
||||
@Override
|
||||
protected SimpleDateFormat initialValue() {
|
||||
return new SimpleDateFormat("yyyy-MM-dd");
|
||||
}
|
||||
};
|
||||
|
||||
private final static ThreadLocal<SimpleDateFormat> dateFormat3 = new ThreadLocal<SimpleDateFormat>() {
|
||||
@Override
|
||||
protected SimpleDateFormat initialValue() {
|
||||
return new SimpleDateFormat("yyyy-MM-dd HH:mm");
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 将字符串转位日期类型
|
||||
*
|
||||
* @param sdate
|
||||
* @return
|
||||
*/
|
||||
public static Date toDate(String sdate) {
|
||||
return toDate(sdate, dateFormater.get());
|
||||
}
|
||||
|
||||
public static Date toDate(String sdate, SimpleDateFormat dateFormater) {
|
||||
try {
|
||||
return dateFormater.parse(sdate);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static String getDateString(Date date) {
|
||||
return dateFormater.get().format(date);
|
||||
}
|
||||
|
||||
public static String getDateString(String sdate) {
|
||||
return dateFormat3.get().format(toDate(sdate));
|
||||
}
|
||||
|
||||
/**
|
||||
* 以友好的方式显示时间
|
||||
*
|
||||
* @param sdate
|
||||
* @return
|
||||
*/
|
||||
public static String friendly_time(String sdate) {
|
||||
Date time = null;
|
||||
|
||||
if (TimeZoneUtil.isInEasternEightZones())
|
||||
time = toDate(sdate);
|
||||
else
|
||||
time = TimeZoneUtil.transformTime(toDate(sdate),
|
||||
TimeZone.getTimeZone("GMT+08"), TimeZone.getDefault());
|
||||
|
||||
if (time == null) {
|
||||
return "Unknown";
|
||||
}
|
||||
String ftime = "";
|
||||
Calendar cal = Calendar.getInstance();
|
||||
|
||||
// 判断是否是同一天
|
||||
String curDate = dateFormater2.get().format(cal.getTime());
|
||||
String paramDate = dateFormater2.get().format(time);
|
||||
if (curDate.equals(paramDate)) {
|
||||
int hour = (int) ((cal.getTimeInMillis() - time.getTime()) / 3600000);
|
||||
if (hour == 0)
|
||||
ftime = Math.max(
|
||||
(cal.getTimeInMillis() - time.getTime()) / 60000, 1)
|
||||
+ "分钟前";
|
||||
else
|
||||
ftime = hour + "小时前";
|
||||
return ftime;
|
||||
}
|
||||
|
||||
long lt = time.getTime() / 86400000;
|
||||
long ct = cal.getTimeInMillis() / 86400000;
|
||||
int days = (int) (ct - lt);
|
||||
if (days == 0) {
|
||||
int hour = (int) ((cal.getTimeInMillis() - time.getTime()) / 3600000);
|
||||
if (hour == 0)
|
||||
ftime = Math.max(
|
||||
(cal.getTimeInMillis() - time.getTime()) / 60000, 1)
|
||||
+ "分钟前";
|
||||
else
|
||||
ftime = hour + "小时前";
|
||||
} else if (days == 1) {
|
||||
ftime = "昨天";
|
||||
} else if (days == 2) {
|
||||
ftime = "前天 ";
|
||||
} else if (days > 2 && days < 31) {
|
||||
ftime = days + "天前";
|
||||
} else if (days >= 31 && days <= 2 * 31) {
|
||||
ftime = "一个月前";
|
||||
} else if (days > 2 * 31 && days <= 3 * 31) {
|
||||
ftime = "2个月前";
|
||||
} else if (days > 3 * 31 && days <= 4 * 31) {
|
||||
ftime = "3个月前";
|
||||
} else {
|
||||
ftime = dateFormater2.get().format(time);
|
||||
}
|
||||
return ftime;
|
||||
}
|
||||
|
||||
public static String friendly_time2(String sdate) {
|
||||
String res = "";
|
||||
if (isEmpty(sdate))
|
||||
return "";
|
||||
|
||||
String[] weekDays = {"星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"};
|
||||
String currentData = StringUtils.getDataTime("MM-dd");
|
||||
int currentDay = toInt(currentData.substring(3));
|
||||
int currentMoth = toInt(currentData.substring(0, 2));
|
||||
|
||||
int sMoth = toInt(sdate.substring(5, 7));
|
||||
int sDay = toInt(sdate.substring(8, 10));
|
||||
int sYear = toInt(sdate.substring(0, 4));
|
||||
Date dt = new Date(sYear, sMoth - 1, sDay - 1);
|
||||
|
||||
if (sDay == currentDay && sMoth == currentMoth) {
|
||||
res = "今天 / " + weekDays[getWeekOfDate(new Date())];
|
||||
} else if (sDay == currentDay + 1 && sMoth == currentMoth) {
|
||||
res = "昨天 / " + weekDays[(getWeekOfDate(new Date()) + 6) % 7];
|
||||
} else {
|
||||
if (sMoth < 10) {
|
||||
res = "0";
|
||||
}
|
||||
res += sMoth + "/";
|
||||
if (sDay < 10) {
|
||||
res += "0";
|
||||
}
|
||||
res += sDay + " / " + weekDays[getWeekOfDate(dt)];
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 智能格式化
|
||||
*/
|
||||
public static String friendly_time3(String sdate) {
|
||||
String res = "";
|
||||
if (isEmpty(sdate))
|
||||
return "";
|
||||
|
||||
Date date = StringUtils.toDate(sdate);
|
||||
if (date == null)
|
||||
return sdate;
|
||||
|
||||
SimpleDateFormat format = dateFormater2.get();
|
||||
|
||||
if (isToday(date.getTime())) {
|
||||
format.applyPattern(isMorning(date.getTime()) ? "上午 hh:mm" : "下午 hh:mm");
|
||||
res = format.format(date);
|
||||
} else if (isYesterday(date.getTime())) {
|
||||
format.applyPattern(isMorning(date.getTime()) ? "昨天 上午 hh:mm" : "昨天 下午 hh:mm");
|
||||
res = format.format(date);
|
||||
} else if (isCurrentYear(date.getTime())) {
|
||||
format.applyPattern(isMorning(date.getTime()) ? "MM-dd 上午 hh:mm" : "MM-dd 下午 hh:mm");
|
||||
res = format.format(date);
|
||||
} else {
|
||||
format.applyPattern(isMorning(date.getTime()) ? "yyyy-MM-dd 上午 hh:mm" : "yyyy-MM-dd 下午 hh:mm");
|
||||
res = format.format(date);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 判断一个时间是不是上午
|
||||
*/
|
||||
public static boolean isMorning(long when) {
|
||||
android.text.format.Time time = new android.text.format.Time();
|
||||
time.set(when);
|
||||
|
||||
int hour = time.hour;
|
||||
return (hour >= 0) && (hour < 12);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 判断一个时间是不是今天
|
||||
*/
|
||||
public static boolean isToday(long when) {
|
||||
android.text.format.Time time = new android.text.format.Time();
|
||||
time.set(when);
|
||||
|
||||
int thenYear = time.year;
|
||||
int thenMonth = time.month;
|
||||
int thenMonthDay = time.monthDay;
|
||||
|
||||
time.set(System.currentTimeMillis());
|
||||
return (thenYear == time.year)
|
||||
&& (thenMonth == time.month)
|
||||
&& (thenMonthDay == time.monthDay);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 判断一个时间是不是昨天
|
||||
*/
|
||||
public static boolean isYesterday(long when) {
|
||||
android.text.format.Time time = new android.text.format.Time();
|
||||
time.set(when);
|
||||
|
||||
int thenYear = time.year;
|
||||
int thenMonth = time.month;
|
||||
int thenMonthDay = time.monthDay;
|
||||
|
||||
time.set(System.currentTimeMillis());
|
||||
return (thenYear == time.year)
|
||||
&& (thenMonth == time.month)
|
||||
&& (time.monthDay - thenMonthDay == 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 判断一个时间是不是今年
|
||||
*/
|
||||
public static boolean isCurrentYear(long when) {
|
||||
android.text.format.Time time = new android.text.format.Time();
|
||||
time.set(when);
|
||||
|
||||
int thenYear = time.year;
|
||||
|
||||
time.set(System.currentTimeMillis());
|
||||
return (thenYear == time.year);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前日期是星期几<br>
|
||||
*
|
||||
* @param dt
|
||||
* @return 当前日期是星期几
|
||||
*/
|
||||
public static int getWeekOfDate(Date dt) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTime(dt);
|
||||
int w = cal.get(Calendar.DAY_OF_WEEK) - 1;
|
||||
if (w < 0)
|
||||
w = 0;
|
||||
return w;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断给定字符串时间是否为今日
|
||||
*
|
||||
* @param sdate
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isToday(String sdate) {
|
||||
boolean b = false;
|
||||
Date time = toDate(sdate);
|
||||
Date today = new Date();
|
||||
if (time != null) {
|
||||
String nowDate = dateFormater2.get().format(today);
|
||||
String timeDate = dateFormater2.get().format(time);
|
||||
if (nowDate.equals(timeDate)) {
|
||||
b = true;
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* 是否是相同的一天
|
||||
* @param sDate1 sDate1
|
||||
* @param sDate2 sDate2
|
||||
* @return
|
||||
*/
|
||||
public static boolean isSameDay(String sDate1,String sDate2){
|
||||
if(TextUtils.isEmpty(sDate1) || TextUtils.isEmpty(sDate2)){
|
||||
return false;
|
||||
}
|
||||
boolean b = false;
|
||||
Date date1 = toDate(sDate1);
|
||||
Date date2 = toDate(sDate2);
|
||||
if(date1!= null && date2 != null){
|
||||
String d1 = dateFormater2.get().format(date1);
|
||||
String d2 = dateFormater2.get().format(date2);
|
||||
if (d1.equals(d2)) {
|
||||
b = true;
|
||||
}
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回long类型的今天的日期
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static long getToday() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
String curDate = dateFormater2.get().format(cal.getTime());
|
||||
curDate = curDate.replace("-", "");
|
||||
return Long.parseLong(curDate);
|
||||
}
|
||||
|
||||
public static String getCurTimeStr() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
String curDate = dateFormater.get().format(cal.getTime());
|
||||
return curDate;
|
||||
}
|
||||
|
||||
/***
|
||||
* 计算两个时间差,返回的是的秒s
|
||||
*
|
||||
* @param dete1
|
||||
* @param date2
|
||||
* @return
|
||||
* @author 火蚁 2015-2-9 下午4:50:06
|
||||
*/
|
||||
public static long calDateDifferent(String dete1, String date2) {
|
||||
|
||||
long diff = 0;
|
||||
|
||||
Date d1 = null;
|
||||
Date d2 = null;
|
||||
|
||||
try {
|
||||
d1 = dateFormater.get().parse(dete1);
|
||||
d2 = dateFormater.get().parse(date2);
|
||||
|
||||
// 毫秒ms
|
||||
diff = d2.getTime() - d1.getTime();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return diff / 1000;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断给定字符串是否空白串。 空白串是指由空格、制表符、回车符、换行符组成的字符串 若输入字符串为null或空字符串,返回true
|
||||
*
|
||||
* @param input
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isEmpty(String input) {
|
||||
if (input == null || "".equals(input))
|
||||
return true;
|
||||
|
||||
for (int i = 0; i < input.length(); i++) {
|
||||
char c = input.charAt(i);
|
||||
if (c != ' ' && c != '\t' && c != '\r' && c != '\n') {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是不是一个合法的电子邮件地址
|
||||
*
|
||||
* @param email
|
||||
* @return
|
||||
*/
|
||||
public static boolean isEmail(String email) {
|
||||
if (email == null || email.trim().length() == 0)
|
||||
return false;
|
||||
return emailer.matcher(email).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断一个url是否为图片url
|
||||
*
|
||||
* @param url
|
||||
* @return
|
||||
*/
|
||||
public static boolean isImgUrl(String url) {
|
||||
if (url == null || url.trim().length() == 0)
|
||||
return false;
|
||||
return IMG_URL.matcher(url).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为一个合法的url地址
|
||||
*
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static boolean isUrl(String str) {
|
||||
if (str == null || str.trim().length() == 0)
|
||||
return false;
|
||||
return URL.matcher(str).matches();
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转整数
|
||||
*
|
||||
* @param str
|
||||
* @param defValue
|
||||
* @return
|
||||
*/
|
||||
public static int toInt(String str, int defValue) {
|
||||
try {
|
||||
return Integer.parseInt(str);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return defValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象转整数
|
||||
*
|
||||
* @param obj
|
||||
* @return 转换异常返回 0
|
||||
*/
|
||||
public static int toInt(Object obj) {
|
||||
if (obj == null)
|
||||
return 0;
|
||||
return toInt(obj.toString(), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象转整数
|
||||
*
|
||||
* @param obj
|
||||
* @return 转换异常返回 0
|
||||
*/
|
||||
public static long toLong(String obj) {
|
||||
try {
|
||||
return Long.parseLong(obj);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 字符串转布尔值
|
||||
*
|
||||
* @param b
|
||||
* @return 转换异常返回 false
|
||||
*/
|
||||
public static boolean toBool(String b) {
|
||||
try {
|
||||
return Boolean.parseBoolean(b);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String getString(String s) {
|
||||
return s == null ? "" : s;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将一个InputStream流转换成字符串
|
||||
*
|
||||
* @param is
|
||||
* @return
|
||||
*/
|
||||
public static String toConvertString(InputStream is) {
|
||||
StringBuffer res = new StringBuffer();
|
||||
InputStreamReader isr = new InputStreamReader(is);
|
||||
BufferedReader read = new BufferedReader(isr);
|
||||
try {
|
||||
String line;
|
||||
line = read.readLine();
|
||||
while (line != null) {
|
||||
res.append(line + "<br>");
|
||||
line = read.readLine();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (null != isr) {
|
||||
isr.close();
|
||||
isr.close();
|
||||
}
|
||||
if (null != read) {
|
||||
read.close();
|
||||
read = null;
|
||||
}
|
||||
if (null != is) {
|
||||
is.close();
|
||||
is = null;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
}
|
||||
}
|
||||
return res.toString();
|
||||
}
|
||||
|
||||
/***
|
||||
* 截取字符串
|
||||
*
|
||||
* @param start 从那里开始,0算起
|
||||
* @param num 截取多少个
|
||||
* @param str 截取的字符串
|
||||
* @return
|
||||
*/
|
||||
public static String getSubString(int start, int num, String str) {
|
||||
if (str == null) {
|
||||
return "";
|
||||
}
|
||||
int leng = str.length();
|
||||
if (start < 0) {
|
||||
start = 0;
|
||||
}
|
||||
if (start > leng) {
|
||||
start = leng;
|
||||
}
|
||||
if (num < 0) {
|
||||
num = 1;
|
||||
}
|
||||
int end = start + num;
|
||||
if (end > leng) {
|
||||
end = leng;
|
||||
}
|
||||
return str.substring(start, end);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前时间为每年第几周
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static int getWeekOfYear() {
|
||||
return getWeekOfYear(new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前时间为每年第几周
|
||||
*
|
||||
* @param date
|
||||
* @return
|
||||
*/
|
||||
public static int getWeekOfYear(Date date) {
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.setFirstDayOfWeek(Calendar.MONDAY);
|
||||
c.setTime(date);
|
||||
int week = c.get(Calendar.WEEK_OF_YEAR) - 1;
|
||||
week = week == 0 ? 52 : week;
|
||||
return week > 0 ? week : 1;
|
||||
}
|
||||
|
||||
public static int[] getCurrentDate() {
|
||||
int[] dateBundle = new int[3];
|
||||
String[] temp = getDataTime("yyyy-MM-dd").split("-");
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
try {
|
||||
dateBundle[i] = Integer.parseInt(temp[i]);
|
||||
} catch (Exception e) {
|
||||
dateBundle[i] = 0;
|
||||
}
|
||||
}
|
||||
return dateBundle;
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回当前系统时间
|
||||
*/
|
||||
public static String getDataTime(String format) {
|
||||
SimpleDateFormat df = new SimpleDateFormat(format);
|
||||
return df.format(new Date());
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,40 @@
|
|||
package com.example.administrator.myapplication.utils;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* @author HuangWenwei
|
||||
*
|
||||
* @date 2014年10月9日
|
||||
*/
|
||||
public class TimeZoneUtil {
|
||||
|
||||
/**
|
||||
* 判断用户的设备时区是否为东八区(中国) 2014年7月31日
|
||||
* @return
|
||||
*/
|
||||
public static boolean isInEasternEightZones() {
|
||||
boolean defaultVaule = true;
|
||||
if (TimeZone.getDefault() == TimeZone.getTimeZone("GMT+08"))
|
||||
defaultVaule = true;
|
||||
else
|
||||
defaultVaule = false;
|
||||
return defaultVaule;
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据不同时区,转换时间 2014年7月31日
|
||||
* @param time
|
||||
* @return
|
||||
*/
|
||||
public static Date transformTime(Date date, TimeZone oldZone, TimeZone newZone) {
|
||||
Date finalDate = null;
|
||||
if (date != null) {
|
||||
int timeOffset = oldZone.getOffset(date.getTime())
|
||||
- newZone.getOffset(date.getTime());
|
||||
finalDate = new Date(date.getTime() - timeOffset);
|
||||
}
|
||||
return finalDate;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,385 @@
|
|||
package com.example.administrator.myapplication.webview;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.graphics.Bitmap;
|
||||
import android.net.Uri;
|
||||
import android.net.http.SslError;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.webkit.DownloadListener;
|
||||
import android.webkit.JavascriptInterface;
|
||||
import android.webkit.JsPromptResult;
|
||||
import android.webkit.JsResult;
|
||||
import android.webkit.SslErrorHandler;
|
||||
import android.webkit.ValueCallback;
|
||||
import android.webkit.WebChromeClient;
|
||||
import android.webkit.WebResourceError;
|
||||
import android.webkit.WebResourceRequest;
|
||||
import android.webkit.WebResourceResponse;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.Button;
|
||||
import android.widget.FrameLayout;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.administrator.myapplication.R;
|
||||
|
||||
/**
|
||||
* 演示WebView中的Api说明、js交互的方法,还有注意事项
|
||||
* <p>
|
||||
* 1、内存泄漏防备
|
||||
* 2、配置webView
|
||||
* 3、页面加载开始,错误,拦截请求,接受Error等
|
||||
* 4、页面加载进度,title,图标,js弹框等
|
||||
* 5、js交互与安全
|
||||
*/
|
||||
public class APIWebViewActivity extends AppCompatActivity implements View.OnClickListener {
|
||||
|
||||
FrameLayout mRootLayout;
|
||||
WebView mWebView;
|
||||
Button mButton;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_api_webview);
|
||||
|
||||
findViewById(R.id.call_js_function).setOnClickListener(this);
|
||||
|
||||
//添加webView到布局中
|
||||
addWebViewToLayout();
|
||||
|
||||
//set webView Setting
|
||||
setWebView();
|
||||
|
||||
//set webView Client
|
||||
setWebClient();
|
||||
|
||||
//set webView chrome
|
||||
setWebViewChromeClient();
|
||||
|
||||
//load web
|
||||
loadUrl();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 主动清空销毁来避免内存泄漏
|
||||
*/
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
if (mWebView != null) {
|
||||
mWebView.loadDataWithBaseURL(null, "", "text/html", "utf-8", null);
|
||||
mWebView.clearHistory();
|
||||
((ViewGroup) mWebView.getParent()).removeView(mWebView);
|
||||
mWebView.destroy();
|
||||
mWebView = null;
|
||||
}
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 1、不在xml中定义Webview,而是在需要的时候在Activity中创建
|
||||
* 使用getApplicationgContext(),避免内存泄漏。
|
||||
* <p>
|
||||
* 2、当然,你也可以配置webView所在Activity,
|
||||
* 在AndroidManifest中的进程为:android:process=":remote"
|
||||
* 避免泄漏影响主进程
|
||||
**/
|
||||
void addWebViewToLayout() {
|
||||
mRootLayout = (FrameLayout) findViewById(R.id.js_root_layout);
|
||||
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
mWebView = new WebView(getApplicationContext());
|
||||
mWebView.setLayoutParams(params);
|
||||
mRootLayout.addView(mWebView);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 配置webView
|
||||
*/
|
||||
void setWebView() {
|
||||
//声明WebSettings子类
|
||||
WebSettings webSettings = mWebView.getSettings();
|
||||
|
||||
//支持Javascript交互
|
||||
webSettings.setJavaScriptEnabled(true);
|
||||
|
||||
|
||||
//设置自适应屏幕,两者合用
|
||||
webSettings.setUseWideViewPort(true); //将图片调整到适合webview的大小
|
||||
webSettings.setLoadWithOverviewMode(true); // 缩放至屏幕的大小
|
||||
|
||||
//缩放操作
|
||||
webSettings.setSupportZoom(true); //支持缩放,默认为true。是下面那个的前提。
|
||||
webSettings.setBuiltInZoomControls(true); //设置内置的缩放控件。若为false,则该WebView不可缩放
|
||||
webSettings.setDisplayZoomControls(false); //隐藏原生的缩放控件
|
||||
|
||||
//其他细节操作
|
||||
//webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); //关闭webview中缓存
|
||||
webSettings.setAllowFileAccess(true); //设置可以访问文件
|
||||
|
||||
//对于不需要使用 file 协议的应用,禁用 file 协议;防止文件泄密,file协议即是file://
|
||||
//webSettings.setAllowFileAccess(false);
|
||||
//webSettings.setAllowFileAccessFromFileURLs(false);
|
||||
//webSettings.setAllowUniversalAccessFromFileURLs(false);
|
||||
|
||||
|
||||
|
||||
webSettings.setJavaScriptCanOpenWindowsAutomatically(true); //支持通过JS打开新窗口
|
||||
webSettings.setLoadsImagesAutomatically(true); //支持自动加载图片
|
||||
webSettings.setDefaultTextEncodingName("utf-8");//设置编码格式
|
||||
|
||||
mWebView.setDownloadListener(new DownloadListener() {
|
||||
@Override
|
||||
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
|
||||
//网页中触发下载动作
|
||||
}
|
||||
});
|
||||
|
||||
//增加js交互接口
|
||||
mWebView.addJavascriptInterface(new JsCallAndroidInterface(), "JSCallBackInterface");
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置webView的Client,如页面加载开始,错误,拦截请求,接受Error等
|
||||
*/
|
||||
void setWebClient() {
|
||||
mWebView.setWebViewClient(new WebViewClient() {
|
||||
|
||||
//拦截页面中的url加载,21以下的
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
||||
if (resolveShouldLoadLogic(url)) {
|
||||
return true;
|
||||
}
|
||||
return super.shouldOverrideUrlLoading(view, url);
|
||||
}
|
||||
|
||||
//拦截页面中的url加载,21以上的
|
||||
@TargetApi(21)
|
||||
@Override
|
||||
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
|
||||
if (resolveShouldLoadLogic(request.getUrl().toString())) {
|
||||
return true;
|
||||
}
|
||||
return super.shouldOverrideUrlLoading(view, request);
|
||||
}
|
||||
|
||||
//页面开始加载
|
||||
@Override
|
||||
public void onPageStarted(WebView view, String url, Bitmap favicon) {
|
||||
super.onPageStarted(view, url, favicon);
|
||||
}
|
||||
|
||||
//页面加载完成
|
||||
@Override
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
super.onPageFinished(view, url);
|
||||
}
|
||||
|
||||
//页面加载每一个资源,如图片
|
||||
@Override
|
||||
public void onLoadResource(WebView view, String url) {
|
||||
super.onLoadResource(view, url);
|
||||
}
|
||||
|
||||
//监听WebView发出的请求并做相应的处理
|
||||
//浏览器的渲染以及资源加载都是在一个线程中,如果在shouldInterceptRequest处理时间过长,WebView界面就会阻塞
|
||||
//21以下的
|
||||
@Override
|
||||
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
|
||||
return super.shouldInterceptRequest(view, url);
|
||||
}
|
||||
|
||||
//监听WebView发出的请求并做相应的处理
|
||||
//浏览器的渲染以及资源加载都是在一个线程中,如果在shouldInterceptRequest处理时间过长,WebView界面就会阻塞
|
||||
//21以上的
|
||||
@Override
|
||||
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
|
||||
return super.shouldInterceptRequest(view, request);
|
||||
}
|
||||
|
||||
//页面加载出现错误,23以下的
|
||||
@Override
|
||||
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
|
||||
super.onReceivedError(view, errorCode, description, failingUrl);
|
||||
switch (errorCode) {
|
||||
case 404:
|
||||
//view.loadUrl("加载一个错误页面提示,优化体验");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//页面加载出现错误,23以上的
|
||||
@TargetApi(23)
|
||||
@Override
|
||||
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
|
||||
super.onReceivedError(view, request, error);
|
||||
switch (error.getErrorCode()) {
|
||||
case 404:
|
||||
//view.loadUrl("加载一个错误页面提示,优化体验");
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//https错误
|
||||
@Override
|
||||
public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
|
||||
super.onReceivedSslError(view, handler, error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置webView的辅助功能,如页面加载进度,title,图标,js弹框等
|
||||
*/
|
||||
void setWebViewChromeClient() {
|
||||
mWebView.setWebChromeClient(new WebChromeClient() {
|
||||
|
||||
//页面加载进度
|
||||
@Override
|
||||
public void onProgressChanged(WebView view, int newProgress) {
|
||||
super.onProgressChanged(view, newProgress);
|
||||
}
|
||||
|
||||
//获取标题
|
||||
@Override
|
||||
public void onReceivedTitle(WebView view, String title) {
|
||||
super.onReceivedTitle(view, title);
|
||||
}
|
||||
|
||||
//获取图标
|
||||
@Override
|
||||
public void onReceivedIcon(WebView view, Bitmap icon) {
|
||||
super.onReceivedIcon(view, icon);
|
||||
}
|
||||
|
||||
//是否支持页面中的js警告弹出框
|
||||
@Override
|
||||
public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
|
||||
|
||||
Toast.makeText(APIWebViewActivity.this, message, Toast.LENGTH_SHORT).show();
|
||||
|
||||
return super.onJsAlert(view, url, message, result);
|
||||
}
|
||||
|
||||
//是否支持页面中的js确定弹出框
|
||||
@Override
|
||||
public boolean onJsConfirm(WebView view, String url, String message, JsResult result) {
|
||||
return super.onJsConfirm(view, url, message, result);
|
||||
}
|
||||
|
||||
//是否支持页面中的js输入弹出框
|
||||
@Override
|
||||
public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) {
|
||||
/**
|
||||
* 有时候,为了安全考虑,js的参数回调,会通过这类地方回调回来,然后不弹出框。
|
||||
*/
|
||||
if(resolveJSPrompt(message)) {
|
||||
return true;
|
||||
}
|
||||
return super.onJsPrompt(view, url, message, defaultValue, result);
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 加载url
|
||||
*/
|
||||
void loadUrl() {
|
||||
// 格式规定为:file:///android_asset/文件名.html
|
||||
mWebView.loadUrl("file:///android_asset/localHtml.html");
|
||||
//方式1. 加载远程网页:
|
||||
//mWebView.loadUrl("http://www.baidu.com/");
|
||||
//方式2:加载asset的html页面
|
||||
//mWebView.loadUrl("file:///android_asset/localHtml.html");
|
||||
//方式3:加载手机SD的html页面
|
||||
//mWebView.loadUrl("file:///mnt/sdcard/database/taobao.html");
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行网页中的js方法
|
||||
*/
|
||||
void callJsFunction() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
mWebView.evaluateJavascript("javascript:callJS()", new ValueCallback<String>() {
|
||||
@Override
|
||||
public void onReceiveValue(String value) {
|
||||
//接受返回值
|
||||
}
|
||||
});
|
||||
} else {
|
||||
mWebView.loadUrl("javascript:callJS()");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* js与web交互1
|
||||
* js 与 原生交互接口
|
||||
*/
|
||||
private class JsCallAndroidInterface {
|
||||
|
||||
//@JavascriptInterface注解方法,js端调用,4.2以后安全
|
||||
//4.2以前,当JS拿到Android这个对象后,就可以调用这个Android对象中所有的方法,包括系统类(java.lang.Runtime 类),从而进行任意代码执行。
|
||||
@JavascriptInterface
|
||||
public void callback(String msg) {
|
||||
Toast.makeText(APIWebViewActivity.this, "JS方法回调到web了 :" + msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* js与web交互2
|
||||
* 通过 shouldOverrideUrlLoading 与 js交互
|
||||
*/
|
||||
private boolean resolveShouldLoadLogic(String url) {
|
||||
Uri uri = Uri.parse(url);
|
||||
//解析协议
|
||||
if (uri.getScheme().equals("js")) {
|
||||
if (uri.getAuthority().equals("Authority")) {
|
||||
//你还可以继续接续参数
|
||||
//Set<String> collection = uri.getQueryParameterNames();
|
||||
Toast.makeText(APIWebViewActivity.this, "JS 2方法回调到web了", Toast.LENGTH_SHORT).show();
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* js与web交互3
|
||||
* 通过 onJsPrompt 与 js交互
|
||||
*/
|
||||
private boolean resolveJSPrompt(String message) {
|
||||
Uri uri = Uri.parse(message);
|
||||
if ( uri.getScheme().equals("js")) {
|
||||
if (uri.getAuthority().equals("Authority")) {
|
||||
|
||||
//Set<String> collection = uri.getQueryParameterNames();
|
||||
//参数result:代表消息框的返回值(输入值)
|
||||
//result.confirm("JS 3方法回调到web");
|
||||
Toast.makeText(APIWebViewActivity.this, "JS 3方法回调到web了", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
switch (v.getId()) {
|
||||
case R.id.call_js_function:
|
||||
callJsFunction();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
package com.example.administrator.myapplication.webview;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.View;
|
||||
import android.webkit.WebResourceError;
|
||||
import android.webkit.WebResourceRequest;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.example.administrator.myapplication.R;
|
||||
import com.shuyu.action.web.ActionSelectListener;
|
||||
import com.shuyu.action.web.CustomActionWebView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class WebActivity extends AppCompatActivity {
|
||||
|
||||
|
||||
View mLadingView;
|
||||
CustomActionWebView mCustomActionWebView;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_web);
|
||||
|
||||
mLadingView = findViewById(R.id.loadingView);
|
||||
mCustomActionWebView = (CustomActionWebView)findViewById(R.id.customActionWebView);
|
||||
|
||||
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add("复制");
|
||||
list.add("粘贴");
|
||||
list.add("一键嗖藏");
|
||||
|
||||
mCustomActionWebView.setWebViewClient(new CustomWebViewClient());
|
||||
|
||||
//设置item
|
||||
mCustomActionWebView.setActionList(list);
|
||||
|
||||
//链接js注入接口,使能选中返回数据
|
||||
mCustomActionWebView.linkJSInterface();
|
||||
|
||||
mCustomActionWebView.getSettings().setBuiltInZoomControls(true);
|
||||
mCustomActionWebView.getSettings().setDisplayZoomControls(false);
|
||||
//使用javascript
|
||||
mCustomActionWebView.getSettings().setJavaScriptEnabled(true);
|
||||
mCustomActionWebView.getSettings().setDomStorageEnabled(true);
|
||||
|
||||
|
||||
//增加点击回调
|
||||
mCustomActionWebView.setActionSelectListener(new ActionSelectListener() {
|
||||
@Override
|
||||
public void onClick(String title, String selectText) {
|
||||
if(title.equals("一键嗖藏")) {
|
||||
Toast.makeText(WebActivity.this, "Click Item: " + title + "。\n\nValue: " + selectText, Toast.LENGTH_LONG).show();
|
||||
|
||||
return;
|
||||
}
|
||||
//System.out.println(title + selectText);
|
||||
Toast.makeText(WebActivity.this, "Click Item: " + title + "。\n\nValue: " + selectText, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
|
||||
//加载url
|
||||
mCustomActionWebView.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mCustomActionWebView.loadUrl("https://www.cnblogs.com/joy99/p/6343237.html");
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
if(mCustomActionWebView != null) {
|
||||
mCustomActionWebView.dismissAction();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
}
|
||||
|
||||
private class CustomWebViewClient extends WebViewClient {
|
||||
|
||||
private boolean mLastLoadFailed = false;
|
||||
|
||||
@Override
|
||||
public void onPageFinished(WebView webView, String url) {
|
||||
super.onPageFinished(webView, url);
|
||||
if (!mLastLoadFailed) {
|
||||
CustomActionWebView customActionWebView = (CustomActionWebView) webView;
|
||||
customActionWebView.linkJSInterface();
|
||||
mLadingView.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageStarted(WebView webView, String url, Bitmap favicon) {
|
||||
super.onPageStarted(webView, url, favicon);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
|
||||
super.onReceivedError(view, request, error);
|
||||
mLastLoadFailed = true;
|
||||
mLadingView.setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 84 B |
Binary file not shown.
After Width: | Height: | Size: 225 B |
|
@ -0,0 +1,28 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<FrameLayout
|
||||
android:id="@+id/js_root_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_gravity="bottom"
|
||||
android:layout_margin="10dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<Button
|
||||
android:id="@+id/call_js_function"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="调用js方法"
|
||||
/>
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</FrameLayout>
|
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.constraint.ConstraintLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="com.example.administrator.myapplication.ui.FloatWindowActivity">
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
<com.shuyu.action.web.CustomActionWebView
|
||||
android:id="@+id/customActionWebView"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
/>
|
||||
|
||||
<ProgressBar
|
||||
android:id="@+id/loadingView"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="60dp"
|
||||
android:layout_gravity="center"
|
||||
/>
|
||||
|
||||
</FrameLayout>
|
|
@ -32,9 +32,9 @@
|
|||
android:text="@string/slogan"
|
||||
android:gravity="center"
|
||||
android:id="@+id/textView4"
|
||||
android:layout_marginBottom="89dp"
|
||||
android:layout_above="@+id/textView5"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginBottom="87dp"/>
|
||||
android:layout_centerHorizontal="true"/>
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -7,20 +7,6 @@
|
|||
android:fitsSystemWindows="true"
|
||||
tools:context="com.example.administrator.myapplication.ui.MainActivity">
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/AppTheme.AppBarOverlay">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary"
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay" />
|
||||
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
|
||||
<include layout="@layout/content_main" />
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
|
@ -34,4 +20,48 @@
|
|||
app:rippleColor="@android:color/transparent"
|
||||
android:src="@drawable/actionbar_icon_add" />
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/AppTheme.AppBarOverlay">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@color/black"
|
||||
>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/app_bar_menubt"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/app_bar_menu"
|
||||
/>
|
||||
|
||||
<android.support.design.widget.TabLayout
|
||||
android:id="@+id/app_bar_tablayout"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="30dp"
|
||||
>
|
||||
</android.support.design.widget.TabLayout>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/app_bar_menu"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="1dp"
|
||||
android:src="@drawable/app_bar_search"/>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary"
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay"/>
|
||||
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<external-path name="external_files" path="."/>
|
||||
</paths>
|
|
@ -0,0 +1 @@
|
|||
/build
|
|
@ -0,0 +1,24 @@
|
|||
apply plugin: 'com.android.library'
|
||||
|
||||
android {
|
||||
compileSdkVersion 25
|
||||
buildToolsVersion "25.0.3"
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion 17
|
||||
targetSdkVersion 25
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
compile fileTree(dir: 'libs', include: ['*.jar'])
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
# Add project specific ProGuard rules here.
|
||||
# By default, the flags in this file are appended to flags specified
|
||||
# in /Users/guoshuyu/Library/Android/sdk/tools/proguard/proguard-android.txt
|
||||
# You can edit the include path and order by changing the proguardFiles
|
||||
# directive in build.gradle.
|
||||
#
|
||||
# For more details, see
|
||||
# http://developer.android.com/guide/developing/tools/proguard.html
|
||||
|
||||
# Add any project specific keep options here:
|
||||
|
||||
# If your project uses WebView with JS, uncomment the following
|
||||
# and specify the fully qualified class name to the JavaScript interface
|
||||
# class:
|
||||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
||||
# public *;
|
||||
#}
|
||||
|
||||
# Uncomment this to preserve the line number information for
|
||||
# debugging stack traces.
|
||||
#-keepattributes SourceFile,LineNumberTable
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
|
@ -0,0 +1,10 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
|
||||
package="com.shuyu.action.web">
|
||||
|
||||
<application android:allowBackup="true" android:label="@string/app_name"
|
||||
android:supportsRtl="true">
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
|
@ -0,0 +1,9 @@
|
|||
package com.shuyu.action.web;
|
||||
|
||||
/**
|
||||
* Created by guoshuyu on 2017/6/17.
|
||||
*/
|
||||
|
||||
public interface ActionSelectListener {
|
||||
void onClick(String title, String selectText);
|
||||
}
|
|
@ -0,0 +1,159 @@
|
|||
package com.shuyu.action.web;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.ActionMode;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.webkit.JavascriptInterface;
|
||||
import android.webkit.WebView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class CustomActionWebView extends WebView {
|
||||
|
||||
static String TAG = "CustomActionWebView";
|
||||
|
||||
ActionMode mActionMode;
|
||||
|
||||
List<String> mActionList = new ArrayList<>();
|
||||
|
||||
ActionSelectListener mActionSelectListener;
|
||||
|
||||
public CustomActionWebView(Context context) {
|
||||
super(context);
|
||||
}
|
||||
|
||||
public CustomActionWebView(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
}
|
||||
|
||||
public CustomActionWebView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 处理item,处理点击
|
||||
* @param actionMode
|
||||
*/
|
||||
private ActionMode resolveActionMode(ActionMode actionMode) {
|
||||
if (actionMode != null) {
|
||||
final Menu menu = actionMode.getMenu();
|
||||
mActionMode = actionMode;
|
||||
menu.clear();
|
||||
for (int i = 0; i < mActionList.size(); i++) {
|
||||
menu.add(mActionList.get(i));
|
||||
}
|
||||
for (int i = 0; i < menu.size(); i++) {
|
||||
MenuItem menuItem = menu.getItem(i);
|
||||
menuItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
||||
@Override
|
||||
public boolean onMenuItemClick(MenuItem item) {
|
||||
getSelectedData((String) item.getTitle());
|
||||
releaseAction();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
mActionMode = actionMode;
|
||||
return actionMode;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionMode startActionMode(ActionMode.Callback callback) {
|
||||
ActionMode actionMode = super.startActionMode(callback);
|
||||
return resolveActionMode(actionMode);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActionMode startActionMode(ActionMode.Callback callback, int type) {
|
||||
ActionMode actionMode = super.startActionMode(callback, type);
|
||||
return resolveActionMode(actionMode);
|
||||
}
|
||||
|
||||
private void releaseAction() {
|
||||
if (mActionMode != null) {
|
||||
mActionMode.finish();
|
||||
mActionMode = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 点击的时候,获取网页中选择的文本,回掉到原生中的js接口
|
||||
* @param title 传入点击的item文本,一起通过js返回给原生接口
|
||||
*/
|
||||
private void getSelectedData(String title) {
|
||||
|
||||
String js = "(function getSelectedText() {" +
|
||||
"var txt;" +
|
||||
"var title = \"" + title + "\";" +
|
||||
"if (window.getSelection) {" +
|
||||
"txt = window.getSelection().toString();" +
|
||||
"} else if (window.document.getSelection) {" +
|
||||
"txt = window.document.getSelection().toString();" +
|
||||
"} else if (window.document.selection) {" +
|
||||
"txt = window.document.selection.createRange().text;" +
|
||||
"}" +
|
||||
"JSInterface.callback(txt,title);" +
|
||||
"})()";
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
evaluateJavascript("javascript:" + js, null);
|
||||
//System.out.println(123);
|
||||
} else {
|
||||
loadUrl("javascript:" + js);
|
||||
//System.out.println(456);
|
||||
}
|
||||
}
|
||||
|
||||
public void linkJSInterface() {
|
||||
addJavascriptInterface(new ActionSelectInterface(this), "JSInterface");
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置弹出action列表
|
||||
* @param actionList
|
||||
*/
|
||||
public void setActionList(List<String> actionList) {
|
||||
mActionList = actionList;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置点击回掉
|
||||
* @param actionSelectListener
|
||||
*/
|
||||
public void setActionSelectListener(ActionSelectListener actionSelectListener) {
|
||||
this.mActionSelectListener = actionSelectListener;
|
||||
}
|
||||
|
||||
/**
|
||||
* 隐藏消失Action
|
||||
*/
|
||||
public void dismissAction() {
|
||||
releaseAction();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* js选中的回掉接口
|
||||
*/
|
||||
private class ActionSelectInterface {
|
||||
|
||||
CustomActionWebView mContext;
|
||||
|
||||
ActionSelectInterface(CustomActionWebView c) {
|
||||
mContext = c;
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void callback(final String value, final String title) {
|
||||
if(mActionSelectListener != null) {
|
||||
mActionSelectListener.onClick(title, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
<resources>
|
||||
<string name="app_name">library</string>
|
||||
</resources>
|
|
@ -26,6 +26,7 @@ public class ActAutoUpdate extends BaseActivity {
|
|||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
// TODO Auto-generated method stub
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
package cn.bmob.sdkdemo.push;
|
||||
|
||||
import android.os.Bundle;
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
include ':app'
|
||||
include ':app', ':my_library'
|
||||
project(':my_library').projectDir = new File('library')
|
Loading…
Reference in New Issue