diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000000..be97a2033d
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,892 @@
+[*]
+charset = utf-8
+end_of_line = crlf
+indent_size = 4
+indent_style = space
+insert_final_newline = false
+max_line_length = 100
+tab_width = 4
+ij_continuation_indent_size = 8
+ij_formatter_off_tag = @formatter:off
+ij_formatter_on_tag = @formatter:on
+ij_formatter_tags_enabled = false
+ij_smart_tabs = false
+ij_wrap_on_typing = false
+
+[*.dart]
+max_line_length = 80
+
+[*.java]
+ij_java_align_consecutive_assignments = true
+ij_java_align_consecutive_variable_declarations = true
+ij_java_align_group_field_declarations = true
+ij_java_align_multiline_annotation_parameters = false
+ij_java_align_multiline_array_initializer_expression = false
+ij_java_align_multiline_assignment = false
+ij_java_align_multiline_binary_operation = false
+ij_java_align_multiline_chained_methods = false
+ij_java_align_multiline_extends_list = false
+ij_java_align_multiline_for = true
+ij_java_align_multiline_method_parentheses = false
+ij_java_align_multiline_parameters = true
+ij_java_align_multiline_parameters_in_calls = false
+ij_java_align_multiline_parenthesized_expression = false
+ij_java_align_multiline_records = false
+ij_java_align_multiline_resources = true
+ij_java_align_multiline_ternary_operation = false
+ij_java_align_multiline_text_blocks = true
+ij_java_align_multiline_throws_list = true
+ij_java_align_subsequent_simple_methods = true
+ij_java_align_throws_keyword = false
+ij_java_annotation_parameter_wrap = off
+ij_java_array_initializer_new_line_after_left_brace = false
+ij_java_array_initializer_right_brace_on_new_line = false
+ij_java_array_initializer_wrap = off
+ij_java_assert_statement_colon_on_next_line = false
+ij_java_assert_statement_wrap = off
+ij_java_assignment_wrap = off
+ij_java_binary_operation_sign_on_next_line = false
+ij_java_binary_operation_wrap = off
+ij_java_blank_lines_after_anonymous_class_header = 0
+ij_java_blank_lines_after_class_header = 0
+ij_java_blank_lines_after_imports = 1
+ij_java_blank_lines_after_package = 1
+ij_java_blank_lines_around_class = 1
+ij_java_blank_lines_around_field = 0
+ij_java_blank_lines_around_field_in_interface = 0
+ij_java_blank_lines_around_initializer = 1
+ij_java_blank_lines_around_method = 1
+ij_java_blank_lines_around_method_in_interface = 1
+ij_java_blank_lines_before_class_end = 0
+ij_java_blank_lines_before_imports = 1
+ij_java_blank_lines_before_method_body = 0
+ij_java_blank_lines_before_package = 0
+ij_java_block_brace_style = end_of_line
+ij_java_block_comment_at_first_column = true
+ij_java_call_parameters_new_line_after_left_paren = false
+ij_java_call_parameters_right_paren_on_new_line = false
+ij_java_call_parameters_wrap = off
+ij_java_case_statement_on_separate_line = true
+ij_java_catch_on_new_line = false
+ij_java_class_annotation_wrap = split_into_lines
+ij_java_class_brace_style = end_of_line
+ij_java_class_count_to_use_import_on_demand = 99
+ij_java_class_names_in_javadoc = 1
+ij_java_do_not_indent_top_level_class_members = false
+ij_java_do_not_wrap_after_single_annotation = false
+ij_java_do_while_brace_force = always
+ij_java_doc_add_blank_line_after_description = true
+ij_java_doc_add_blank_line_after_param_comments = false
+ij_java_doc_add_blank_line_after_return = false
+ij_java_doc_add_p_tag_on_empty_lines = true
+ij_java_doc_align_exception_comments = true
+ij_java_doc_align_param_comments = true
+ij_java_doc_do_not_wrap_if_one_line = false
+ij_java_doc_enable_formatting = true
+ij_java_doc_enable_leading_asterisks = true
+ij_java_doc_indent_on_continuation = false
+ij_java_doc_keep_empty_lines = true
+ij_java_doc_keep_empty_parameter_tag = true
+ij_java_doc_keep_empty_return_tag = true
+ij_java_doc_keep_empty_throws_tag = true
+ij_java_doc_keep_invalid_tags = true
+ij_java_doc_param_description_on_new_line = false
+ij_java_doc_preserve_line_breaks = false
+ij_java_doc_use_throws_not_exception_tag = true
+ij_java_else_on_new_line = false
+ij_java_enum_constants_wrap = split_into_lines
+ij_java_extends_keyword_wrap = split_into_lines
+ij_java_extends_list_wrap = split_into_lines
+ij_java_field_annotation_wrap = split_into_lines
+ij_java_finally_on_new_line = false
+ij_java_for_brace_force = always
+ij_java_for_statement_new_line_after_left_paren = false
+ij_java_for_statement_right_paren_on_new_line = false
+ij_java_for_statement_wrap = off
+ij_java_generate_final_locals = false
+ij_java_generate_final_parameters = false
+ij_java_if_brace_force = if_multiline
+ij_java_imports_layout = android.**, |, androidx.**, |, com.**, |, junit.**, |, net.**, |, org.**, |, java.**, |, javax.**, |, *, |, $*, |
+ij_java_indent_case_from_switch = true
+ij_java_insert_inner_class_imports = false
+ij_java_insert_override_annotation = true
+ij_java_keep_blank_lines_before_right_brace = 2
+ij_java_keep_blank_lines_between_package_declaration_and_header = 2
+ij_java_keep_blank_lines_in_code = 2
+ij_java_keep_blank_lines_in_declarations = 2
+ij_java_keep_control_statement_in_one_line = true
+ij_java_keep_first_column_comment = true
+ij_java_keep_indents_on_empty_lines = false
+ij_java_keep_line_breaks = true
+ij_java_keep_multiple_expressions_in_one_line = false
+ij_java_keep_simple_blocks_in_one_line = false
+ij_java_keep_simple_classes_in_one_line = true
+ij_java_keep_simple_lambdas_in_one_line = true
+ij_java_keep_simple_methods_in_one_line = false
+ij_java_label_indent_absolute = false
+ij_java_label_indent_size = 0
+ij_java_lambda_brace_style = end_of_line
+ij_java_layout_static_imports_separately = true
+ij_java_line_comment_add_space = false
+ij_java_line_comment_at_first_column = true
+ij_java_method_annotation_wrap = split_into_lines
+ij_java_method_brace_style = end_of_line
+ij_java_method_call_chain_wrap = off
+ij_java_method_parameters_new_line_after_left_paren = true
+ij_java_method_parameters_right_paren_on_new_line = true
+ij_java_method_parameters_wrap = split_into_lines
+ij_java_modifier_list_wrap = false
+ij_java_names_count_to_use_import_on_demand = 99
+ij_java_new_line_after_lparen_in_record_header = false
+ij_java_parameter_annotation_wrap = off
+ij_java_parentheses_expression_new_line_after_left_paren = false
+ij_java_parentheses_expression_right_paren_on_new_line = false
+ij_java_place_assignment_sign_on_next_line = false
+ij_java_prefer_longer_names = true
+ij_java_prefer_parameters_wrap = false
+ij_java_record_components_wrap = off
+ij_java_repeat_synchronized = true
+ij_java_replace_instanceof_and_cast = false
+ij_java_replace_null_check = true
+ij_java_replace_sum_lambda_with_method_ref = true
+ij_java_resource_list_new_line_after_left_paren = true
+ij_java_resource_list_right_paren_on_new_line = true
+ij_java_resource_list_wrap = off
+ij_java_rparen_on_new_line_in_record_header = false
+ij_java_space_after_closing_angle_bracket_in_type_argument = false
+ij_java_space_after_colon = true
+ij_java_space_after_comma = true
+ij_java_space_after_comma_in_type_arguments = true
+ij_java_space_after_for_semicolon = true
+ij_java_space_after_quest = true
+ij_java_space_after_type_cast = true
+ij_java_space_before_annotation_array_initializer_left_brace = false
+ij_java_space_before_annotation_parameter_list = false
+ij_java_space_before_array_initializer_left_brace = false
+ij_java_space_before_catch_keyword = true
+ij_java_space_before_catch_left_brace = true
+ij_java_space_before_catch_parentheses = true
+ij_java_space_before_class_left_brace = true
+ij_java_space_before_colon = true
+ij_java_space_before_colon_in_foreach = true
+ij_java_space_before_comma = false
+ij_java_space_before_do_left_brace = true
+ij_java_space_before_else_keyword = true
+ij_java_space_before_else_left_brace = true
+ij_java_space_before_finally_keyword = true
+ij_java_space_before_finally_left_brace = true
+ij_java_space_before_for_left_brace = true
+ij_java_space_before_for_parentheses = true
+ij_java_space_before_for_semicolon = false
+ij_java_space_before_if_left_brace = true
+ij_java_space_before_if_parentheses = true
+ij_java_space_before_method_call_parentheses = false
+ij_java_space_before_method_left_brace = true
+ij_java_space_before_method_parentheses = false
+ij_java_space_before_opening_angle_bracket_in_type_parameter = false
+ij_java_space_before_quest = true
+ij_java_space_before_switch_left_brace = true
+ij_java_space_before_switch_parentheses = true
+ij_java_space_before_synchronized_left_brace = true
+ij_java_space_before_synchronized_parentheses = true
+ij_java_space_before_try_left_brace = true
+ij_java_space_before_try_parentheses = true
+ij_java_space_before_type_parameter_list = false
+ij_java_space_before_while_keyword = true
+ij_java_space_before_while_left_brace = true
+ij_java_space_before_while_parentheses = true
+ij_java_space_inside_one_line_enum_braces = false
+ij_java_space_within_empty_array_initializer_braces = false
+ij_java_space_within_empty_method_call_parentheses = false
+ij_java_space_within_empty_method_parentheses = false
+ij_java_spaces_around_additive_operators = true
+ij_java_spaces_around_assignment_operators = true
+ij_java_spaces_around_bitwise_operators = true
+ij_java_spaces_around_equality_operators = true
+ij_java_spaces_around_lambda_arrow = true
+ij_java_spaces_around_logical_operators = true
+ij_java_spaces_around_method_ref_dbl_colon = false
+ij_java_spaces_around_multiplicative_operators = true
+ij_java_spaces_around_relational_operators = true
+ij_java_spaces_around_shift_operators = true
+ij_java_spaces_around_type_bounds_in_type_parameters = true
+ij_java_spaces_around_unary_operator = false
+ij_java_spaces_within_angle_brackets = false
+ij_java_spaces_within_annotation_parentheses = false
+ij_java_spaces_within_array_initializer_braces = false
+ij_java_spaces_within_braces = false
+ij_java_spaces_within_brackets = false
+ij_java_spaces_within_cast_parentheses = false
+ij_java_spaces_within_catch_parentheses = false
+ij_java_spaces_within_for_parentheses = false
+ij_java_spaces_within_if_parentheses = false
+ij_java_spaces_within_method_call_parentheses = false
+ij_java_spaces_within_method_parentheses = false
+ij_java_spaces_within_parentheses = false
+ij_java_spaces_within_switch_parentheses = false
+ij_java_spaces_within_synchronized_parentheses = false
+ij_java_spaces_within_try_parentheses = false
+ij_java_spaces_within_while_parentheses = false
+ij_java_special_else_if_treatment = true
+ij_java_subclass_name_suffix = Impl
+ij_java_ternary_operation_signs_on_next_line = false
+ij_java_ternary_operation_wrap = off
+ij_java_test_name_suffix = Test
+ij_java_throws_keyword_wrap = split_into_lines
+ij_java_throws_list_wrap = normal
+ij_java_use_external_annotations = false
+ij_java_use_fq_class_names = false
+ij_java_use_relative_indents = false
+ij_java_use_single_class_imports = true
+ij_java_variable_annotation_wrap = off
+ij_java_visibility = public
+ij_java_while_brace_force = always
+ij_java_while_on_new_line = false
+ij_java_wrap_comments = false
+ij_java_wrap_first_method_in_call_chain = false
+ij_java_wrap_long_lines = false
+
+[*.properties]
+ij_properties_align_group_field_declarations = false
+ij_properties_keep_blank_lines = true
+ij_properties_key_value_delimiter = equals
+ij_properties_spaces_around_key_value_delimiter = false
+
+[.editorconfig]
+ij_editorconfig_align_group_field_declarations = false
+ij_editorconfig_space_after_colon = false
+ij_editorconfig_space_after_comma = true
+ij_editorconfig_space_before_colon = false
+ij_editorconfig_space_before_comma = false
+ij_editorconfig_spaces_around_assignment_operators = true
+
+[{*.ant, *.fxml, *.jhm, *.jnlp, *.jrxml, *.rng, *.tld, *.wsdl, *.xml, *.xsd, *.xsl, *.xslt, *.xul}]
+ij_continuation_indent_size = 4
+ij_xml_align_attributes = false
+ij_xml_align_text = false
+ij_xml_attribute_wrap = normal
+ij_xml_block_comment_at_first_column = true
+ij_xml_keep_blank_lines = 2
+ij_xml_keep_indents_on_empty_lines = false
+ij_xml_keep_line_breaks = false
+ij_xml_keep_line_breaks_in_text = true
+ij_xml_keep_whitespaces = false
+ij_xml_keep_whitespaces_around_cdata = preserve
+ij_xml_keep_whitespaces_inside_cdata = false
+ij_xml_line_comment_at_first_column = true
+ij_xml_space_after_tag_name = false
+ij_xml_space_around_equals_in_attribute = false
+ij_xml_space_inside_empty_tag = true
+ij_xml_text_wrap = normal
+ij_xml_use_custom_settings = true
+
+[{*.bash, *.sh, *.zsh}]
+indent_size = 2
+tab_width = 2
+ij_shell_binary_ops_start_line = false
+ij_shell_keep_column_alignment_padding = false
+ij_shell_minify_program = false
+ij_shell_redirect_followed_by_space = false
+ij_shell_switch_cases_indented = false
+
+[{*.c, *.c++, *.cc, *.cp, *.cpp, *.cu, *.cuh, *.cxx, *.h, *.h++, *.hh, *.hp, *.hpp, *.hxx, *.i, *.icc, *.ii, *.inl, *.ino, *.ipp, *.m, *.mm, *.pch, *.tcc, *.tpp}]
+ij_c_add_brief_tag = false
+ij_c_add_getter_prefix = true
+ij_c_add_setter_prefix = true
+ij_c_align_dictionary_pair_values = false
+ij_c_align_group_field_declarations = false
+ij_c_align_init_list_in_columns = true
+ij_c_align_multiline_array_initializer_expression = true
+ij_c_align_multiline_assignment = true
+ij_c_align_multiline_binary_operation = true
+ij_c_align_multiline_chained_methods = false
+ij_c_align_multiline_for = true
+ij_c_align_multiline_ternary_operation = true
+ij_c_array_initializer_comma_on_next_line = false
+ij_c_array_initializer_new_line_after_left_brace = false
+ij_c_array_initializer_right_brace_on_new_line = false
+ij_c_array_initializer_wrap = normal
+ij_c_assignment_wrap = off
+ij_c_binary_operation_sign_on_next_line = false
+ij_c_binary_operation_wrap = normal
+ij_c_blank_lines_after_class_header = 0
+ij_c_blank_lines_after_imports = 1
+ij_c_blank_lines_around_class = 1
+ij_c_blank_lines_around_field = 0
+ij_c_blank_lines_around_field_in_interface = 0
+ij_c_blank_lines_around_method = 1
+ij_c_blank_lines_around_method_in_interface = 1
+ij_c_blank_lines_around_namespace = 0
+ij_c_blank_lines_around_properties_in_declaration = 0
+ij_c_blank_lines_around_properties_in_interface = 0
+ij_c_blank_lines_before_imports = 1
+ij_c_blank_lines_before_method_body = 0
+ij_c_block_brace_placement = end_of_line
+ij_c_block_brace_style = end_of_line
+ij_c_block_comment_at_first_column = true
+ij_c_catch_on_new_line = false
+ij_c_class_brace_style = end_of_line
+ij_c_class_constructor_init_list_align_multiline = true
+ij_c_class_constructor_init_list_comma_on_next_line = false
+ij_c_class_constructor_init_list_new_line_after_colon = never
+ij_c_class_constructor_init_list_new_line_before_colon = if_long
+ij_c_class_constructor_init_list_wrap = normal
+ij_c_copy_is_deep = false
+ij_c_create_interface_for_categories = true
+ij_c_declare_generated_methods = true
+ij_c_description_include_member_names = true
+ij_c_discharged_short_ternary_operator = false
+ij_c_do_not_add_breaks = false
+ij_c_do_while_brace_force = never
+ij_c_else_on_new_line = false
+ij_c_enum_constants_comma_on_next_line = false
+ij_c_enum_constants_wrap = on_every_item
+ij_c_for_brace_force = never
+ij_c_for_statement_new_line_after_left_paren = false
+ij_c_for_statement_right_paren_on_new_line = false
+ij_c_for_statement_wrap = off
+ij_c_function_brace_placement = end_of_line
+ij_c_function_call_arguments_align_multiline = true
+ij_c_function_call_arguments_align_multiline_pars = false
+ij_c_function_call_arguments_comma_on_next_line = false
+ij_c_function_call_arguments_new_line_after_lpar = false
+ij_c_function_call_arguments_new_line_before_rpar = false
+ij_c_function_call_arguments_wrap = normal
+ij_c_function_non_top_after_return_type_wrap = normal
+ij_c_function_parameters_align_multiline = true
+ij_c_function_parameters_align_multiline_pars = false
+ij_c_function_parameters_comma_on_next_line = false
+ij_c_function_parameters_new_line_after_lpar = false
+ij_c_function_parameters_new_line_before_rpar = false
+ij_c_function_parameters_wrap = normal
+ij_c_function_top_after_return_type_wrap = normal
+ij_c_generate_additional_eq_operators = true
+ij_c_generate_additional_rel_operators = true
+ij_c_generate_class_constructor = true
+ij_c_generate_comparison_operators_use_std_tie = false
+ij_c_generate_instance_variables_for_properties = ask
+ij_c_generate_operators_as_members = true
+ij_c_header_guard_style_pattern = ${PROJECT_NAME}_${FILE_NAME}_${EXT}
+ij_c_if_brace_force = never
+ij_c_in_line_short_ternary_operator = true
+ij_c_indent_block_comment = true
+ij_c_indent_c_struct_members = 4
+ij_c_indent_case_from_switch = true
+ij_c_indent_class_members = 4
+ij_c_indent_directive_as_code = false
+ij_c_indent_implementation_members = 0
+ij_c_indent_inside_code_block = 4
+ij_c_indent_interface_members = 0
+ij_c_indent_interface_members_except_ivars_block = false
+ij_c_indent_namespace_members = 4
+ij_c_indent_preprocessor_directive = 0
+ij_c_indent_visibility_keywords = 0
+ij_c_insert_override = true
+ij_c_insert_virtual_with_override = false
+ij_c_introduce_auto_vars = false
+ij_c_introduce_const_params = false
+ij_c_introduce_const_vars = false
+ij_c_introduce_generate_property = false
+ij_c_introduce_generate_synthesize = true
+ij_c_introduce_globals_to_header = true
+ij_c_introduce_prop_to_private_category = false
+ij_c_introduce_static_consts = true
+ij_c_introduce_use_ns_types = false
+ij_c_ivars_prefix = _
+ij_c_keep_blank_lines_before_end = 2
+ij_c_keep_blank_lines_before_right_brace = 2
+ij_c_keep_blank_lines_in_code = 2
+ij_c_keep_blank_lines_in_declarations = 2
+ij_c_keep_case_expressions_in_one_line = false
+ij_c_keep_control_statement_in_one_line = true
+ij_c_keep_directive_at_first_column = true
+ij_c_keep_first_column_comment = true
+ij_c_keep_line_breaks = true
+ij_c_keep_nested_namespaces_in_one_line = false
+ij_c_keep_simple_blocks_in_one_line = true
+ij_c_keep_simple_methods_in_one_line = true
+ij_c_keep_structures_in_one_line = false
+ij_c_lambda_capture_list_align_multiline = false
+ij_c_lambda_capture_list_align_multiline_bracket = false
+ij_c_lambda_capture_list_comma_on_next_line = false
+ij_c_lambda_capture_list_new_line_after_lbracket = false
+ij_c_lambda_capture_list_new_line_before_rbracket = false
+ij_c_lambda_capture_list_wrap = off
+ij_c_line_comment_add_space = false
+ij_c_line_comment_at_first_column = true
+ij_c_method_brace_placement = end_of_line
+ij_c_method_call_arguments_align_by_colons = true
+ij_c_method_call_arguments_align_multiline = false
+ij_c_method_call_arguments_special_dictionary_pairs_treatment = true
+ij_c_method_call_arguments_wrap = off
+ij_c_method_call_chain_wrap = off
+ij_c_method_parameters_align_by_colons = true
+ij_c_method_parameters_align_multiline = false
+ij_c_method_parameters_wrap = off
+ij_c_namespace_brace_placement = end_of_line
+ij_c_parentheses_expression_new_line_after_left_paren = false
+ij_c_parentheses_expression_right_paren_on_new_line = false
+ij_c_place_assignment_sign_on_next_line = false
+ij_c_property_nonatomic = true
+ij_c_put_ivars_to_implementation = true
+ij_c_refactor_compatibility_aliases_and_classes = true
+ij_c_refactor_properties_and_ivars = true
+ij_c_release_style = ivar
+ij_c_retain_object_parameters_in_constructor = true
+ij_c_semicolon_after_method_signature = false
+ij_c_shift_operation_align_multiline = true
+ij_c_shift_operation_wrap = normal
+ij_c_show_non_virtual_functions = false
+ij_c_space_after_colon = true
+ij_c_space_after_colon_in_selector = false
+ij_c_space_after_comma = true
+ij_c_space_after_cup_in_blocks = false
+ij_c_space_after_dictionary_literal_colon = true
+ij_c_space_after_for_semicolon = true
+ij_c_space_after_init_list_colon = true
+ij_c_space_after_method_parameter_type_parentheses = false
+ij_c_space_after_method_return_type_parentheses = false
+ij_c_space_after_pointer_in_declaration = false
+ij_c_space_after_quest = true
+ij_c_space_after_reference_in_declaration = false
+ij_c_space_after_reference_in_rvalue = false
+ij_c_space_after_structures_rbrace = true
+ij_c_space_after_superclass_colon = true
+ij_c_space_after_type_cast = true
+ij_c_space_after_visibility_sign_in_method_declaration = true
+ij_c_space_before_autorelease_pool_lbrace = true
+ij_c_space_before_catch_keyword = true
+ij_c_space_before_catch_left_brace = true
+ij_c_space_before_catch_parentheses = true
+ij_c_space_before_category_parentheses = true
+ij_c_space_before_chained_send_message = true
+ij_c_space_before_class_left_brace = true
+ij_c_space_before_colon = true
+ij_c_space_before_comma = false
+ij_c_space_before_dictionary_literal_colon = false
+ij_c_space_before_do_left_brace = true
+ij_c_space_before_else_keyword = true
+ij_c_space_before_else_left_brace = true
+ij_c_space_before_for_left_brace = true
+ij_c_space_before_for_parentheses = true
+ij_c_space_before_for_semicolon = false
+ij_c_space_before_if_left_brace = true
+ij_c_space_before_if_parentheses = true
+ij_c_space_before_init_list = false
+ij_c_space_before_init_list_colon = true
+ij_c_space_before_method_call_parentheses = false
+ij_c_space_before_method_left_brace = true
+ij_c_space_before_method_parentheses = false
+ij_c_space_before_namespace_lbrace = true
+ij_c_space_before_pointer_in_declaration = true
+ij_c_space_before_property_attributes_parentheses = false
+ij_c_space_before_protocols_brackets = true
+ij_c_space_before_quest = true
+ij_c_space_before_reference_in_declaration = true
+ij_c_space_before_superclass_colon = true
+ij_c_space_before_switch_left_brace = true
+ij_c_space_before_switch_parentheses = true
+ij_c_space_before_template_call_lt = false
+ij_c_space_before_template_declaration_lt = false
+ij_c_space_before_try_left_brace = true
+ij_c_space_before_while_keyword = true
+ij_c_space_before_while_left_brace = true
+ij_c_space_before_while_parentheses = true
+ij_c_space_between_adjacent_brackets = false
+ij_c_space_between_operator_and_punctuator = false
+ij_c_space_within_empty_array_initializer_braces = false
+ij_c_spaces_around_additive_operators = true
+ij_c_spaces_around_assignment_operators = true
+ij_c_spaces_around_bitwise_operators = true
+ij_c_spaces_around_equality_operators = true
+ij_c_spaces_around_lambda_arrow = true
+ij_c_spaces_around_logical_operators = true
+ij_c_spaces_around_multiplicative_operators = true
+ij_c_spaces_around_pm_operators = false
+ij_c_spaces_around_relational_operators = true
+ij_c_spaces_around_shift_operators = true
+ij_c_spaces_around_unary_operator = false
+ij_c_spaces_within_array_initializer_braces = false
+ij_c_spaces_within_braces = true
+ij_c_spaces_within_brackets = false
+ij_c_spaces_within_cast_parentheses = false
+ij_c_spaces_within_catch_parentheses = false
+ij_c_spaces_within_category_parentheses = false
+ij_c_spaces_within_empty_braces = false
+ij_c_spaces_within_empty_function_call_parentheses = false
+ij_c_spaces_within_empty_function_declaration_parentheses = false
+ij_c_spaces_within_empty_lambda_capture_list_bracket = false
+ij_c_spaces_within_empty_template_call_ltgt = false
+ij_c_spaces_within_empty_template_declaration_ltgt = false
+ij_c_spaces_within_for_parentheses = false
+ij_c_spaces_within_function_call_parentheses = false
+ij_c_spaces_within_function_declaration_parentheses = false
+ij_c_spaces_within_if_parentheses = false
+ij_c_spaces_within_lambda_capture_list_bracket = false
+ij_c_spaces_within_method_parameter_type_parentheses = false
+ij_c_spaces_within_method_return_type_parentheses = false
+ij_c_spaces_within_parentheses = false
+ij_c_spaces_within_property_attributes_parentheses = false
+ij_c_spaces_within_protocols_brackets = false
+ij_c_spaces_within_send_message_brackets = false
+ij_c_spaces_within_switch_parentheses = false
+ij_c_spaces_within_template_call_ltgt = false
+ij_c_spaces_within_template_declaration_ltgt = false
+ij_c_spaces_within_template_double_gt = true
+ij_c_spaces_within_while_parentheses = false
+ij_c_special_else_if_treatment = true
+ij_c_superclass_list_after_colon = never
+ij_c_superclass_list_align_multiline = true
+ij_c_superclass_list_before_colon = if_long
+ij_c_superclass_list_comma_on_next_line = false
+ij_c_superclass_list_wrap = on_every_item
+ij_c_tag_prefix_of_block_comment = at
+ij_c_tag_prefix_of_line_comment = back_slash
+ij_c_template_call_arguments_align_multiline = false
+ij_c_template_call_arguments_align_multiline_pars = false
+ij_c_template_call_arguments_comma_on_next_line = false
+ij_c_template_call_arguments_new_line_after_lt = false
+ij_c_template_call_arguments_new_line_before_gt = false
+ij_c_template_call_arguments_wrap = off
+ij_c_template_declaration_function_body_indent = false
+ij_c_template_declaration_function_wrap = split_into_lines
+ij_c_template_declaration_struct_body_indent = false
+ij_c_template_declaration_struct_wrap = split_into_lines
+ij_c_template_parameters_align_multiline = false
+ij_c_template_parameters_align_multiline_pars = false
+ij_c_template_parameters_comma_on_next_line = false
+ij_c_template_parameters_new_line_after_lt = false
+ij_c_template_parameters_new_line_before_gt = false
+ij_c_template_parameters_wrap = off
+ij_c_ternary_operation_signs_on_next_line = true
+ij_c_ternary_operation_wrap = normal
+ij_c_type_qualifiers_placement = before
+ij_c_use_modern_casts = true
+ij_c_use_setters_in_constructor = true
+ij_c_while_brace_force = never
+ij_c_while_on_new_line = false
+ij_c_wrap_property_declaration = off
+
+[{*.cmake, CMakeLists.txt}]
+ij_cmake_align_multiline_parameters_in_calls = false
+ij_cmake_force_commands_case = 2
+ij_cmake_keep_blank_lines_in_code = 2
+ij_cmake_space_before_for_parentheses = true
+ij_cmake_space_before_if_parentheses = true
+ij_cmake_space_before_method_call_parentheses = false
+ij_cmake_space_before_method_parentheses = false
+ij_cmake_space_before_while_parentheses = true
+ij_cmake_spaces_within_for_parentheses = false
+ij_cmake_spaces_within_if_parentheses = false
+ij_cmake_spaces_within_method_call_parentheses = false
+ij_cmake_spaces_within_method_parentheses = false
+ij_cmake_spaces_within_while_parentheses = false
+
+[{*.gant, *.gradle, *.groovy, *.gy}]
+ij_groovy_align_group_field_declarations = true
+ij_groovy_align_multiline_array_initializer_expression = false
+ij_groovy_align_multiline_assignment = false
+ij_groovy_align_multiline_binary_operation = false
+ij_groovy_align_multiline_chained_methods = false
+ij_groovy_align_multiline_extends_list = false
+ij_groovy_align_multiline_for = true
+ij_groovy_align_multiline_list_or_map = true
+ij_groovy_align_multiline_method_parentheses = false
+ij_groovy_align_multiline_parameters = true
+ij_groovy_align_multiline_parameters_in_calls = false
+ij_groovy_align_multiline_resources = true
+ij_groovy_align_multiline_ternary_operation = false
+ij_groovy_align_multiline_throws_list = true
+ij_groovy_align_named_args_in_map = true
+ij_groovy_align_throws_keyword = false
+ij_groovy_array_initializer_new_line_after_left_brace = false
+ij_groovy_array_initializer_right_brace_on_new_line = false
+ij_groovy_array_initializer_wrap = off
+ij_groovy_assert_statement_wrap = split_into_lines
+ij_groovy_assignment_wrap = off
+ij_groovy_binary_operation_wrap = off
+ij_groovy_blank_lines_after_class_header = 0
+ij_groovy_blank_lines_after_imports = 1
+ij_groovy_blank_lines_after_package = 1
+ij_groovy_blank_lines_around_class = 1
+ij_groovy_blank_lines_around_field = 0
+ij_groovy_blank_lines_around_field_in_interface = 0
+ij_groovy_blank_lines_around_method = 1
+ij_groovy_blank_lines_around_method_in_interface = 1
+ij_groovy_blank_lines_before_imports = 1
+ij_groovy_blank_lines_before_method_body = 0
+ij_groovy_blank_lines_before_package = 0
+ij_groovy_block_brace_style = end_of_line
+ij_groovy_block_comment_at_first_column = true
+ij_groovy_call_parameters_new_line_after_left_paren = false
+ij_groovy_call_parameters_right_paren_on_new_line = false
+ij_groovy_call_parameters_wrap = off
+ij_groovy_catch_on_new_line = false
+ij_groovy_class_annotation_wrap = split_into_lines
+ij_groovy_class_brace_style = end_of_line
+ij_groovy_class_count_to_use_import_on_demand = 5
+ij_groovy_do_while_brace_force = always
+ij_groovy_else_on_new_line = false
+ij_groovy_enum_constants_wrap = split_into_lines
+ij_groovy_extends_keyword_wrap = split_into_lines
+ij_groovy_extends_list_wrap = split_into_lines
+ij_groovy_field_annotation_wrap = split_into_lines
+ij_groovy_finally_on_new_line = false
+ij_groovy_for_brace_force = always
+ij_groovy_for_statement_new_line_after_left_paren = false
+ij_groovy_for_statement_right_paren_on_new_line = false
+ij_groovy_for_statement_wrap = off
+ij_groovy_if_brace_force = if_multiline
+ij_groovy_import_annotation_wrap = 2
+ij_groovy_imports_layout = *, |, javax.**, java.**, |, $*
+ij_groovy_indent_case_from_switch = true
+ij_groovy_indent_label_blocks = true
+ij_groovy_insert_inner_class_imports = false
+ij_groovy_keep_blank_lines_before_right_brace = 2
+ij_groovy_keep_blank_lines_in_code = 2
+ij_groovy_keep_blank_lines_in_declarations = 2
+ij_groovy_keep_control_statement_in_one_line = true
+ij_groovy_keep_first_column_comment = true
+ij_groovy_keep_indents_on_empty_lines = false
+ij_groovy_keep_line_breaks = true
+ij_groovy_keep_multiple_expressions_in_one_line = false
+ij_groovy_keep_simple_blocks_in_one_line = false
+ij_groovy_keep_simple_classes_in_one_line = true
+ij_groovy_keep_simple_lambdas_in_one_line = true
+ij_groovy_keep_simple_methods_in_one_line = false
+ij_groovy_label_indent_absolute = false
+ij_groovy_label_indent_size = 0
+ij_groovy_lambda_brace_style = end_of_line
+ij_groovy_layout_static_imports_separately = true
+ij_groovy_line_comment_add_space = false
+ij_groovy_line_comment_at_first_column = true
+ij_groovy_method_annotation_wrap = split_into_lines
+ij_groovy_method_brace_style = end_of_line
+ij_groovy_method_call_chain_wrap = off
+ij_groovy_method_parameters_new_line_after_left_paren = true
+ij_groovy_method_parameters_right_paren_on_new_line = true
+ij_groovy_method_parameters_wrap = split_into_lines
+ij_groovy_modifier_list_wrap = false
+ij_groovy_names_count_to_use_import_on_demand = 3
+ij_groovy_parameter_annotation_wrap = off
+ij_groovy_parentheses_expression_new_line_after_left_paren = false
+ij_groovy_parentheses_expression_right_paren_on_new_line = false
+ij_groovy_prefer_parameters_wrap = false
+ij_groovy_resource_list_new_line_after_left_paren = true
+ij_groovy_resource_list_right_paren_on_new_line = true
+ij_groovy_resource_list_wrap = off
+ij_groovy_space_after_assert_separator = true
+ij_groovy_space_after_colon = true
+ij_groovy_space_after_comma = true
+ij_groovy_space_after_comma_in_type_arguments = true
+ij_groovy_space_after_for_semicolon = true
+ij_groovy_space_after_quest = true
+ij_groovy_space_after_type_cast = true
+ij_groovy_space_before_annotation_parameter_list = false
+ij_groovy_space_before_array_initializer_left_brace = false
+ij_groovy_space_before_assert_separator = false
+ij_groovy_space_before_catch_keyword = true
+ij_groovy_space_before_catch_left_brace = true
+ij_groovy_space_before_catch_parentheses = true
+ij_groovy_space_before_class_left_brace = true
+ij_groovy_space_before_closure_left_brace = true
+ij_groovy_space_before_colon = true
+ij_groovy_space_before_comma = false
+ij_groovy_space_before_do_left_brace = true
+ij_groovy_space_before_else_keyword = true
+ij_groovy_space_before_else_left_brace = true
+ij_groovy_space_before_finally_keyword = true
+ij_groovy_space_before_finally_left_brace = true
+ij_groovy_space_before_for_left_brace = true
+ij_groovy_space_before_for_parentheses = true
+ij_groovy_space_before_for_semicolon = false
+ij_groovy_space_before_if_left_brace = true
+ij_groovy_space_before_if_parentheses = true
+ij_groovy_space_before_method_call_parentheses = false
+ij_groovy_space_before_method_left_brace = true
+ij_groovy_space_before_method_parentheses = false
+ij_groovy_space_before_quest = true
+ij_groovy_space_before_switch_left_brace = true
+ij_groovy_space_before_switch_parentheses = true
+ij_groovy_space_before_synchronized_left_brace = true
+ij_groovy_space_before_synchronized_parentheses = true
+ij_groovy_space_before_try_left_brace = true
+ij_groovy_space_before_try_parentheses = true
+ij_groovy_space_before_while_keyword = true
+ij_groovy_space_before_while_left_brace = true
+ij_groovy_space_before_while_parentheses = true
+ij_groovy_space_in_named_argument = true
+ij_groovy_space_in_named_argument_before_colon = false
+ij_groovy_space_within_empty_array_initializer_braces = false
+ij_groovy_space_within_empty_method_call_parentheses = false
+ij_groovy_spaces_around_additive_operators = true
+ij_groovy_spaces_around_assignment_operators = true
+ij_groovy_spaces_around_bitwise_operators = true
+ij_groovy_spaces_around_equality_operators = true
+ij_groovy_spaces_around_lambda_arrow = true
+ij_groovy_spaces_around_logical_operators = true
+ij_groovy_spaces_around_multiplicative_operators = true
+ij_groovy_spaces_around_regex_operators = true
+ij_groovy_spaces_around_relational_operators = true
+ij_groovy_spaces_around_shift_operators = true
+ij_groovy_spaces_within_annotation_parentheses = false
+ij_groovy_spaces_within_array_initializer_braces = false
+ij_groovy_spaces_within_braces = true
+ij_groovy_spaces_within_brackets = false
+ij_groovy_spaces_within_cast_parentheses = false
+ij_groovy_spaces_within_catch_parentheses = false
+ij_groovy_spaces_within_for_parentheses = false
+ij_groovy_spaces_within_gstring_injection_braces = false
+ij_groovy_spaces_within_if_parentheses = false
+ij_groovy_spaces_within_list_or_map = false
+ij_groovy_spaces_within_method_call_parentheses = false
+ij_groovy_spaces_within_method_parentheses = false
+ij_groovy_spaces_within_parentheses = false
+ij_groovy_spaces_within_switch_parentheses = false
+ij_groovy_spaces_within_synchronized_parentheses = false
+ij_groovy_spaces_within_try_parentheses = false
+ij_groovy_spaces_within_tuple_expression = false
+ij_groovy_spaces_within_while_parentheses = false
+ij_groovy_special_else_if_treatment = true
+ij_groovy_ternary_operation_wrap = off
+ij_groovy_throws_keyword_wrap = split_into_lines
+ij_groovy_throws_list_wrap = normal
+ij_groovy_use_flying_geese_braces = false
+ij_groovy_use_fq_class_names = false
+ij_groovy_use_fq_class_names_in_javadoc = true
+ij_groovy_use_relative_indents = false
+ij_groovy_use_single_class_imports = true
+ij_groovy_variable_annotation_wrap = off
+ij_groovy_while_brace_force = always
+ij_groovy_while_on_new_line = false
+ij_groovy_wrap_long_lines = false
+
+[{*.gradle.kts, *.kt, *.kts, *.main.kts}]
+ij_kotlin_align_in_columns_case_branch = false
+ij_kotlin_align_multiline_binary_operation = false
+ij_kotlin_align_multiline_extends_list = false
+ij_kotlin_align_multiline_method_parentheses = false
+ij_kotlin_align_multiline_parameters = true
+ij_kotlin_align_multiline_parameters_in_calls = false
+ij_kotlin_allow_trailing_comma = false
+ij_kotlin_allow_trailing_comma_on_call_site = false
+ij_kotlin_assignment_wrap = normal
+ij_kotlin_blank_lines_after_class_header = 0
+ij_kotlin_blank_lines_around_block_when_branches = 0
+ij_kotlin_blank_lines_before_declaration_with_comment_or_annotation_on_separate_line = 1
+ij_kotlin_block_comment_at_first_column = true
+ij_kotlin_call_parameters_new_line_after_left_paren = true
+ij_kotlin_call_parameters_right_paren_on_new_line = true
+ij_kotlin_call_parameters_wrap = on_every_item
+ij_kotlin_catch_on_new_line = false
+ij_kotlin_class_annotation_wrap = split_into_lines
+ij_kotlin_code_style_defaults = KOTLIN_OFFICIAL
+ij_kotlin_continuation_indent_for_chained_calls = false
+ij_kotlin_continuation_indent_for_expression_bodies = false
+ij_kotlin_continuation_indent_in_argument_lists = false
+ij_kotlin_continuation_indent_in_elvis = false
+ij_kotlin_continuation_indent_in_if_conditions = false
+ij_kotlin_continuation_indent_in_parameter_lists = false
+ij_kotlin_continuation_indent_in_supertype_lists = false
+ij_kotlin_else_on_new_line = false
+ij_kotlin_enum_constants_wrap = split_into_lines
+ij_kotlin_extends_list_wrap = split_into_lines
+ij_kotlin_field_annotation_wrap = split_into_lines
+ij_kotlin_finally_on_new_line = false
+ij_kotlin_if_rparen_on_new_line = true
+ij_kotlin_import_nested_classes = false
+ij_kotlin_imports_layout = *, java.**, javax.**, kotlin.**, ^
+ij_kotlin_insert_whitespaces_in_simple_one_line_method = true
+ij_kotlin_keep_blank_lines_before_right_brace = 2
+ij_kotlin_keep_blank_lines_in_code = 2
+ij_kotlin_keep_blank_lines_in_declarations = 2
+ij_kotlin_keep_first_column_comment = true
+ij_kotlin_keep_indents_on_empty_lines = false
+ij_kotlin_keep_line_breaks = true
+ij_kotlin_lbrace_on_next_line = false
+ij_kotlin_line_comment_add_space = false
+ij_kotlin_line_comment_at_first_column = true
+ij_kotlin_method_annotation_wrap = split_into_lines
+ij_kotlin_method_call_chain_wrap = normal
+ij_kotlin_method_parameters_new_line_after_left_paren = true
+ij_kotlin_method_parameters_right_paren_on_new_line = true
+ij_kotlin_method_parameters_wrap = split_into_lines
+ij_kotlin_name_count_to_use_star_import = 5
+ij_kotlin_name_count_to_use_star_import_for_members = 3
+ij_kotlin_packages_to_use_import_on_demand = java.util.*, kotlinx.android.synthetic.**, io.ktor.**
+ij_kotlin_parameter_annotation_wrap = off
+ij_kotlin_space_after_comma = true
+ij_kotlin_space_after_extend_colon = true
+ij_kotlin_space_after_type_colon = true
+ij_kotlin_space_before_catch_parentheses = true
+ij_kotlin_space_before_comma = false
+ij_kotlin_space_before_extend_colon = true
+ij_kotlin_space_before_for_parentheses = true
+ij_kotlin_space_before_if_parentheses = true
+ij_kotlin_space_before_lambda_arrow = true
+ij_kotlin_space_before_type_colon = false
+ij_kotlin_space_before_when_parentheses = true
+ij_kotlin_space_before_while_parentheses = true
+ij_kotlin_spaces_around_additive_operators = true
+ij_kotlin_spaces_around_assignment_operators = true
+ij_kotlin_spaces_around_equality_operators = true
+ij_kotlin_spaces_around_function_type_arrow = true
+ij_kotlin_spaces_around_logical_operators = true
+ij_kotlin_spaces_around_multiplicative_operators = true
+ij_kotlin_spaces_around_range = false
+ij_kotlin_spaces_around_relational_operators = true
+ij_kotlin_spaces_around_unary_operator = false
+ij_kotlin_spaces_around_when_arrow = true
+ij_kotlin_variable_annotation_wrap = off
+ij_kotlin_while_on_new_line = false
+ij_kotlin_wrap_elvis_expressions = 1
+ij_kotlin_wrap_expression_body_functions = 1
+ij_kotlin_wrap_first_method_in_call_chain = false
+
+[{*.har, *.json}]
+ij_json_keep_blank_lines_in_code = 0
+ij_json_keep_indents_on_empty_lines = false
+ij_json_keep_line_breaks = true
+ij_json_space_after_colon = true
+ij_json_space_after_comma = true
+ij_json_space_before_colon = true
+ij_json_space_before_comma = false
+ij_json_spaces_within_braces = false
+ij_json_spaces_within_brackets = false
+ij_json_wrap_long_lines = false
+
+[{*.htm, *.html, *.sht, *.shtm, *.shtml}]
+ij_html_add_new_line_before_tags = body, div, p, form, h1, h2, h3
+ij_html_align_attributes = true
+ij_html_align_text = false
+ij_html_attribute_wrap = normal
+ij_html_block_comment_at_first_column = true
+ij_html_do_not_align_children_of_min_lines = 0
+ij_html_do_not_break_if_inline_tags = title, h1, h2, h3, h4, h5, h6, p
+ij_html_do_not_indent_children_of_tags = html, body, thead, tbody, tfoot
+ij_html_enforce_quotes = false
+ij_html_inline_tags = a, abbr, acronym, b, basefont, bdo, big, br, cite, cite, code, dfn, em, font, i, img, input, kbd, label, q, s, samp, select, small, span, strike, strong, sub, sup, textarea, tt, u, var
+ij_html_keep_blank_lines = 2
+ij_html_keep_indents_on_empty_lines = false
+ij_html_keep_line_breaks = true
+ij_html_keep_line_breaks_in_text = true
+ij_html_keep_whitespaces = false
+ij_html_keep_whitespaces_inside = span, pre, textarea
+ij_html_line_comment_at_first_column = true
+ij_html_new_line_after_last_attribute = never
+ij_html_new_line_before_first_attribute = never
+ij_html_quote_style = double
+ij_html_remove_new_line_before_tags = br
+ij_html_space_after_tag_name = false
+ij_html_space_around_equality_in_attribute = false
+ij_html_space_inside_empty_tag = false
+ij_html_text_wrap = normal
+ij_html_uniform_ident = false
+
+[{*.yaml, *.yml, .analysis_options}]
+indent_size = 2
+ij_yaml_keep_indents_on_empty_lines = false
+ij_yaml_keep_line_breaks = true
+ij_yaml_space_before_colon = true
+ij_yaml_spaces_within_braces = true
+ij_yaml_spaces_within_brackets = true
diff --git a/.gitignore b/.gitignore
index 39fb081a42..41687a8067 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,9 +1,11 @@
*.iml
.gradle
-/local.properties
-/.idea/workspace.xml
-/.idea/libraries
+local.properties
+bintray.properties
+sonatype.properties
+.idea
.DS_Store
/build
/captures
.externalNativeBuild
+/reports
\ No newline at end of file
diff --git a/.idea/encodings.xml b/.idea/encodings.xml
deleted file mode 100644
index 4987ecabe8..0000000000
--- a/.idea/encodings.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/gradle.xml b/.idea/gradle.xml
deleted file mode 100644
index 08663fae31..0000000000
--- a/.idea/gradle.xml
+++ /dev/null
@@ -1,19 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index 13c46297a6..0000000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,49 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- 1.8
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
deleted file mode 100644
index 1c811baddb..0000000000
--- a/.idea/modules.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml
deleted file mode 100644
index 7f68460d8b..0000000000
--- a/.idea/runConfigurations.xml
+++ /dev/null
@@ -1,12 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/DevLibUtils/.gitignore b/DevLibUtils/.gitignore
deleted file mode 100644
index 796b96d1c4..0000000000
--- a/DevLibUtils/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/build
diff --git a/DevLibUtils/README.md b/DevLibUtils/README.md
deleted file mode 100644
index ce976bd73d..0000000000
--- a/DevLibUtils/README.md
+++ /dev/null
@@ -1,1007 +0,0 @@
-## 使用
-
-> ##### 只需要在 Application 中调用 `DevUtils.init()` 进行初始化就行
-
-## 目录结构
-
-```
-- dev.utils | 根目录
- - app | app相关工具类
- - anim | 动画相关
- - assist | 辅助类, 如 Camera,ScreenSensor
- - cache | 缓存工具类
- - image | 图片相关处理
- - info | App信息, PackageInfo 等
- - logger | 日志库 DevLogger
- - share | SharedPreferences 封装
- - toast | Toast、Toasty
- - wifi | wifi、热点
- - common | java工具类, 不依赖android api
- - assist | 各种快捷辅助类
- - cipher | 编/解码工具类
- - encrypt | 加密工具类
- - thread | 线程相关
- - validator | 数据校验工具类
-```
-
-## 事项
-
-- 内部存在两个日志工具类
-```java
-// dev.utils.app - App 打印日志工具类
-LogPrintUtils
-// dev.utils.common - Java Common 日志打印工具类
-JCLogUtils
-```
-
-- 需要开启日志, 单独调用
-```java
-// 打开 lib 内部日志
-DevUtils.openLog();
-// 标示 debug 模式
-DevUtils.openDebug();
-```
-
-- 部分api更新不及时或有遗漏等,`具体以对应的工具类为准`
-
-## API
-
-### `dev.utils.app.wifi`
-
-* **Wifi 热点工具类(兼容到Android 8.0) ->** [WifiHotUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/wifi/WifiHotUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| createWifiConfigToAp | 创建Wifi配置信息(无其他操作,单独返回WifiConfig) |
-| stratWifiAp | 开启Wifi热点 |
-| closeWifiAp | 关闭Wifi热点 |
-| getWifiApState | 获取Wifi热点状态 |
-| getWifiApConfiguration | 获取Wifi热点配置信息 |
-| setWifiApConfiguration | 设置Wifi热点配置信息 |
-| isOpenWifiAp | 判断是否打开Wifi热点 |
-| closeWifiApCheck | 关闭Wifi热点(判断当前状态) |
-| isConnectHot | 是否有连接热点的设备 |
-| getHotspotServiceIp | 获取热点主机ip地址 |
-| getHotspotAllotIp | 获取连接上的子网关热点IP(一个) |
-| getHotspotSplitIpMask | 获取热点拼接后的ip网关掩码 |
-| intToString | 转换ip地址 |
-| getApWifiSSID | 获取Wifi 热点名 |
-| getApWifiPwd | 获取Wifi 热点密码 |
-| setOnWifiAPListener | 设置Android Wifi监听(Android 8.0) |
-
-
-* **wifi工具类 ->** [WifiHotUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/wifi/WifiUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| getWifiManager | 获取wifi管理对象 |
-| isOpenWifi | 判断是否打开wifi |
-| openWifi | 打开WIFI |
-| closeWifi | 关闭WIFI |
-| toggleWifiEnabled | 自动切换wifi开关状态 |
-| getWifiState | 获取当前WIFI连接状态 |
-| startScan | 开始扫描wifi |
-| getConfiguration | 获取已配置的网络 |
-| getWifiList | 获取wifi网络列表 |
-| getWifiInfo | 获取WifiInfo对象 |
-| getMacAddress | 获取MAC地址 |
-| getBSSID | 获取接入点的BSSID |
-| getIPAddress | 获取IP地址 |
-| getNetworkId | 获取连接的ID |
-| getSSID | 获取SSID |
-| formatSSID | 判断是否存在\"ssid\",存在则裁剪返回 |
-| getPassword | 获取密码(经过处理) |
-| getWifiType | 获取加密类型(int常量) - 判断String |
-| getWifiTypeInt | 获取加密类型(int常量) - 判断int(String) |
-| getWifiType | 获取加密类型(int常量) |
-| getWifiTypeStr | 获取加密类型(String) |
-| isConnNull | 判断是否连接为null - |
-| isConnectAphot | 判断是否连接上Wifi(非连接中) |
-| getSecurity | 获取Wifi配置,加密类型 |
-| isExsitsPwd | 获知Wifi配置,是否属于密码加密类型 |
-| isExsits | 查看以前是否也配置过这个网络 |
-| delWifiConfig | 删除指定的 Wifi(SSID) 配置信息 |
-| quickConnWifi | 快速连接Wifi(不使用静态ip方式) |
-| createWifiConfig | 创建Wifi配置信息(无其他操作,单独返回WifiConfig) |
-| removeWifiConfig | 移除某个Wifi配置信息 |
-| disconnectWifi | 断开指定ID的网络 |
-| setStaticWifiConfig | 设置静态Wifi信息 |
-| setDNS | 设置DNS |
-| setGateway | 设置网关 |
-| setIpAddress | 设置Ip地址 |
-| setStaticIpConfig | 设置Ip地址、网关、DNS(5.0之后) |
-
-### `dev.utils.app`
-
-* **无障碍功能工具类 ->** [AccessibilityUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/AccessibilityUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| checkAccessibility | 检查是否开启无障碍功能 |
-| isAccessibilitySettingsOn | 判断是否开启无障碍功能 |
-| printAccessibilityEvent | 打印Event 日志 |
-
-
-* **Acitivty 工具类 ->** [ActivityUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/ActivityUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| isActivityExists | 判断是否存在指定的Activity |
-| startHomeActivity | 回到桌面 -> 同点击Home键效果 |
-| getLauncherActivity | 跳转到桌面 |
-| getActivityIcon | 返回Activity 对应的图标 |
-| getActivityLogo | 返回Activity 对应的Logo |
-
-
-* **AlarmManager (全局定时器/闹钟)指定时长或以周期形式执行某项操作 ->** [AlarmUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/AlarmUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| startAlarmIntent | 开启定时器 |
-| stopAlarmIntent | 关闭定时器 |
-| startAlarmService | 开启轮询服务 |
-| stopAlarmService | 停止启轮询服务 |
-
-
-* **分析记录工具类 ->** [AnalysisRecordUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/AnalysisRecordUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| init | 初始化操作 |
-| record | 日志记录 |
-| isHandler | 是否处理日志记录 |
-| setHandler | 设置是否处理日志记录 |
-| getLogFolderName | 获取文件日志名 |
-| setLogFolderName | 设置日志文件夹名 |
-| getLogStoragePath | 获取日志存储路径 |
-| setLogStoragePath | 设置日志存储路径 |
-| getStoragePath | getStoragePath |
-| getFileName | getFileName |
-| getFileFunction | getFileFunction |
-| getFileIntervalTime | getFileIntervalTime |
-| getFolderName | getFolderName |
-| obtain | 获取记录分析文件信息 |
-| getLogPath | 获取日志地址 |
-| getIntervalTimeFolder | 获取时间间隔 - 文件夹 |
-
-
-* **App通用工具类 ->** [AppCommonUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/AppCommonUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| getUUID | 获取设备唯一id |
-| getRandomUUID | 获取随机数 唯一id |
-| isFroyo | 是否在2.2版本及以上 |
-| isGingerbread | 是否在2.3版本及以上 |
-| isGingerbreadMR1 | 是否在2.3.3版本及以上 |
-| isHoneycomb | 是否在3.0版本及以上 |
-| isHoneycombMR1 | 是否在3.1版本及以上 |
-| isIceCreamSandwich | 是否在4.0版本及以上 |
-| isIceCreamSandwichMR1 | 是否在4.0.3版本及以上 |
-| isJellyBean | 是否在4.1版本及以上 |
-| isKitkat | 是否在4.4.2版本及以上 |
-| isLollipop | 是否在5.0.1版本及以上 |
-| isM | 是否在6.0版本及以上 |
-| isN | 是否在7.0版本及以上 |
-| isN_MR1 | 是否在7.1.1版本及以上 |
-| isO | 是否在8.0版本及以上 |
-| convertSDKVersion | 转换SDK版本 |
-
-
-* **App(Android 工具类) ->** [AppUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/AppUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| getWindowManager | 通过上下文获取 WindowManager |
-| getMetaData | 获取 Manifest Meta Data |
-| getView | 获取View |
-| getResources | getResources |
-| getString | getString |
-| getTheme | getTheme |
-| getAssets | getAssets |
-| getDrawable | getDrawable |
-| getColor | getColor |
-| getColorStateList | getColorStateList |
-| getSystemService | getSystemService |
-| getPackageManager | getPackageManager |
-| getConfiguration | getConfiguration |
-| getDisplayMetrics | getDisplayMetrics |
-| getContentResolver | getContentResolver |
-| getAppIcon | 获取app的图标 |
-| getAppPackageName | 获取app 包名 |
-| getAppName | 获取app 名 |
-| getAppVersionName | 获取app版本名 - 对外显示 |
-| getAppVersionCode | 获取app版本号 - 内部判断 |
-| setLanguage | 对内设置指定语言 (app 多语言,单独改变app语言) |
-| installApp | 安装 App(支持 8.0)的意图 |
-| installAppSilent | 静默安装app |
-| uninstallApp | 卸载 App |
-| uninstallAppSilent | 静默卸载 App |
-| isAppInstalled | 判断是否安装了应用 |
-| isInstalledApp | 判断是否安装指定包名的APP |
-| isAppRoot | 判断是否存在root 权限 |
-| isAppDebug | 判断是否app 是否debug模式 |
-| isAppSystem | 判断app 是否系统app |
-| isAppForeground | 判断app 是否在前台 |
-| launchApp | 打开app |
-| launchAppDetailsSettings | 跳转到 专门的APP 设置详情页面 |
-| launchAppDetails | 跳转到 专门的APP 应用商城详情页面 |
-| getAppPath | 获取app 路径 /data/data/包名/.apk |
-| getAppSignature | 获取app 签名 |
-| getAppSignatureSHA1 | 获取 app sha1值 |
-| openPDFFile | 启动本地应用打开PDF |
-| openWordFile | 启动本地应用打开PDF |
-| openOfficeByWPS | 调用WPS打开office文档 |
-
-
-* **状态栏相关工具类 ->** [BarUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/BarUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| getStatusBarHeight | 获取状态栏高度 |
-| setStatusBarVisibility | 设置状态栏是否显示 |
-| isStatusBarVisible | 判断状态栏是否显示 |
-| setStatusBarLightMode | 设置状态是否高亮模式 |
-| addMarginTopEqualStatusBarHeight | 添加状态栏同等高度到View的顶部 |
-| subtractMarginTopEqualStatusBarHeight | 减去状态栏同等高度 |
-| setStatusBarColor | 设置状态栏颜色 |
-| setStatusBarAlpha | 设置状态栏透明度 |
-| setStatusBarColor4Drawer | 设置状态栏的颜色 |
-| setStatusBarAlpha4Drawer | 设置状态栏透明度 |
-| getActionBarHeight | 返回 ActionBase 高度 |
-| setNotificationBarVisibility | 设置通知栏是否显示 |
-| getNavBarHeight | 获取 NavigationView 高度 |
-| setNavBarVisibility | 设置导航栏是否可见(图标显示) |
-| setNavBarImmersive | 设置沉浸模式 |
-| isNavBarVisible | 判断顶部状态栏(图标)是否显示 |
-| setNavBar | 设置是否显示状态栏图标等 |
-
-
-* **亮度相关工具类 ->** [BrightnessUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/BrightnessUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| isAutoBrightnessEnabled | 判断是否开启自动调节亮度 |
-| setAutoBrightnessEnabled | 设置是否开启自动调节亮度 |
-| getBrightness | 获取屏幕亮度 |
-| setBrightness | 设置屏幕亮度 |
-| setWindowBrightness | 设置窗口亮度 |
-| getWindowBrightness | 获取窗口亮度 |
-
-
-* **摄像头相关工具类 ->** [CameraUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/CameraUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| isSupportReverse | 判断是否支持反转摄像头(是否存在前置摄像头) |
-| checkCameraFacing | 检查是否有摄像头 |
-| isFrontCamera | 判断是否使用前置摄像头 |
-| isBackCamera | 判断是否使用后置摄像头 |
-| isUseCameraFacing | 判断使用的视像头 |
-| freeCameraResource | 释放摄像头资源 |
-| initCamera | 初始化摄像头 |
-| open | 打开摄像头 |
-
-
-* ** ->** [CleanUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/CleanUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| cleanInternalCache | 清除本应用内部缓存(/data/data/com.xxx.xxx/cache) |
-| cleanDatabases | 清除本应用所有数据库(/data/data/com.xxx.xxx/databases) |
-| cleanSharedPreference | 清除本应用SharedPreference(/data/data/com.xxx.xxx/shared_prefs) |
-| cleanDatabaseByName | 按名字清除本应用数据库 |
-| cleanFiles | 清除/data/data/com.xxx.xxx/files下的内容 |
-| cleanExternalCache | 清除外部cache下的内容(/mnt/sdcard/android/data/com.xxx.xxx/cache) |
-| cleanCustomCache | 清除自定义路径下的文件,使用需小心,请不要误删。而且只支持目录下的文件删除 |
-| cleanApplicationData | 清除本应用所有的数据 |
-| getFolderSize | 获取文件夹大小 |
-| getCacheSize | 获取缓存文件大小 |
-| getFormatSize | 格式化单位 |
-
-
-* **点击工具类 ->** [ClickUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/ClickUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| isFastDoubleClick | 判断两次点击的间隔 小于默认间隔时间(1秒), 则认为是多次无效点击 |
-| initConfig | 初始化配置信息 |
-| putConfig | 添加配置信息 |
-| removeConfig | 移除配置信息 |
-
-
-* **剪贴板相关工具类 ->** [ClipboardUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/ClipboardUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| copyText | 复制文本到剪贴板 |
-| getText | 获取剪贴板的文本 |
-| copyUri | 复制uri到剪贴板 |
-| getUri | 获取剪贴板的uri |
-| copyIntent | 复制意图到剪贴板 |
-| getIntent | 获取剪贴板的意图 |
-
-
-* **ContentResolver 工具类 ->** [ContentResolverUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/ContentResolverUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| notifyMediaStore | 通知刷新本地资源 |
-| insertImageIntoMediaStore | 添加图片到系统相册(包含原图、相册图, 会存在两张) - 想要一张, 直接调用 notifyMediaStore() |
-| insertVideoIntoMediaStore | 添加视频到系统相册 |
-| insertIntoMediaStore | 保存到系统相册 |
-
-
-* **获取CPU信息工具类 ->** [CPUUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/CPUUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| getProcessorsCount | 获取处理器的Java虚拟机的数量 |
-| getSysCPUSerialNum | 获取手机CPU序列号 |
-| getCpuInfo | 获取CPU 信息 |
-| getCpuModel | 获取CPU 型号 |
-| getMaxCpuFreq | 获取 CPU 最大频率(单位KHZ) |
-| getMinCpuFreq | 获取 CPU 最小频率(单位KHZ) |
-| getCurCpuFreq | 实时获取 CPU 当前频率(单位KHZ) |
-| getCoresNumbers | 获取 CPU 几核 |
-| getCpuName | 获取CPU名字 |
-| getCMDOutputString | 获取 CMD 指令回调数据 |
-
-
-* **数据库工具类 (导入导出等) ->** [DBUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/DBUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| startExportDatabase | 导出数据库 |
-| startImportDatabase | 导入数据库 |
-| getDBPath | 获取数据库路径 |
-
-
-* **设备相关工具类 ->** [DeviceUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/DeviceUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| getSysLanguage | 获取当前操作系统的语言 |
-| getDeviceInfo | 获取设备信息 |
-| getDeviceInfo2 | 获取设备信息 |
-| handleDeviceInfo | 处理设备信息 |
-| getSDKVersionName | 获取设备系统版本号 |
-| getSDKVersion | 获取当前SDK 版本号 |
-| getAndroidId | 获取Android id |
-| isDeviceRooted | 判断设备是否 root |
-| getMacAddress | 获取设备 MAC 地址 |
-| getManufacturer | 获取设备厂商 如 Xiaomi |
-| getModel | 获取设备型号 如 RedmiNote4X |
-| shutdown | 关机 需要 root 权限或者系统权限 |
-| reboot | 重启 需要 root 权限或者系统权限 |
-| reboot2Recovery | 重启到 recovery 需要 root 权限 |
-| reboot2Bootloader | 重启到 bootloader 需要 root 权限 |
-| getBaseband_Ver | BASEBAND-VER 基带版本 |
-| getLinuxCore_Ver | CORE-VER 内核版本 |
-
-
-* **Dialog 操作相关工具类 ->** [DialogUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/DialogUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| closeDialog | 关闭Dialog |
-| closeDialogs | 关闭多个Dialog |
-| closePopupWindow | 关闭PopupWindow |
-| closePopupWindows | 关闭多个PopupWindow |
-| creDialog | 创建加载 Dialog |
-| creAutoCloseDialog | 创建自动关闭dialog |
-
-
-* **EditText 工具类 ->** [EditTextUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/EditTextUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| setMaxLengthAnText | 设置长度限制,并且设置内容 |
-| setMaxLength | 设置长度限制 |
-| getSelectionStart | 获取光标位置 |
-| getText | 获取输入的内容 |
-| getTextLength | 获取输入的内容长度 |
-| setText | 设置内容 |
-| insert | 追加内容 - 当前光标位置追加 |
-| setSelectTop | 设置光标在第一位 |
-| setSelectBottom | 设置光标在最后一位 |
-| setSelect | 设置光标位置 |
-| setKeyListener | 设置输入限制 |
-| getNumberAndEnglishKeyListener | 限制只能输入字母和数字,默认弹出英文输入法 |
-| getNumberKeyListener | 限制只能输入数字,默认弹出数字列表 |
-| getMarkId | getMarkId |
-| isOperate | isOperate |
-| setOperate | setOperate |
-| getOperateState | getOperateState |
-| setOperateState | setOperateState |
-| beforeTextChanged | 在文本变化前调用 |
-| onTextChanged | 在文本变化后调用 |
-| afterTextChanged | 在文本变化后调用 |
-
-
-* **编码工具类 ->** [EncodeUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/EncodeUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| urlEncode | url编码 - UTF-8 |
-| urlDecode | url 解码 - UTF-8 |
-| base64Encode | base64 编码 => 去除\n 替换 + 和 - 号 |
-| base64Encode2String | base64 编码 |
-| base64Decode | base64 解码 |
-| base64DecodeToString | base64 解码 |
-| htmlEncode | html编码 |
-| htmlDecode | html解码 |
-
-
-* **错误信息处理工具类 ->** [ErrorUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/ErrorUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| getErrorMsg | 获取错误信息 |
-| getThrowableMsg | 将异常栈信息转为字符串 |
-| getThrowableNewLinesMsg | 获取错误信息(有换行) |
-
-
-* **App 文件记录工具类 ->** [FileRecordUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/FileRecordUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| appInit | App初始化调用方法 |
-| saveErrorLog | 保存app错误日志 |
-| saveLog | 保存app日志 |
-| handleVariable | 处理可变参数 |
-
-
-* **手电筒工具类 ->** [FlashlightUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/FlashlightUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| getInstance | getInstance |
-| register | 注册摄像头 |
-| unregister | 注销摄像头 |
-| setFlashlightOn | 打开闪光灯 |
-| setFlashlightOff | 关闭闪光灯 |
-| isFlashlightOn | 是否打开闪光灯 |
-| isFlashlightEnable | 是否支持手机闪光灯 |
-
-
-* **Handler 工具类, 默认开启一个 Handler,方便在各个地方随时执行主线程任务 ->** [HandlerUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/HandlerUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| init | 初始化操作 |
-| getMainHandler | 获取主线程 Handler |
-| postRunnable | 在主线程 Handler 中执行任务 |
-| removeRunnable | 在主线程 Handler 中清除任务 |
-
-
-* **Html 工具类 ->** [HtmlUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/HtmlUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| setHtmlText | 设置内容, 最终做处理 |
-| addHtmlColor | 为给定的字符串添加HTML颜色标记 |
-| addHtmlBold | 为给定的字符串添加HTML加粗标记 |
-| addHtmlColorAndBlod | 为给定的字符串添加HTML颜色标记,以及加粗 |
-| addHtmlUnderline | 为给定的字符串添加HTML下划线 |
-| addHtmlIncline | 为给定的字符串添加HTML 字体倾斜 |
-| keywordMadeRed | 将给定的字符串中所有给定的关键字标色 |
-| keywordReplaceAll | 将给定的字符串中所有给定的关键字进行替换内容 |
-
-
-* **Intent(意图) 相关工具类 ->** [IntentUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/IntentUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| getInstallAppIntent | 获取安装 App(支持 8.0)的意图 |
-| getUninstallAppIntent | 获取卸载 App 的意图 |
-| getLaunchAppIntent | 获取打开 App 的意图 |
-| getLaunchAppDetailsSettingsIntent | 获取 App 具体设置的意图 |
-| getlaunchAppDetailIntent | 获取 到应用商店app详情界面的意图 |
-| getShareTextIntent | 获取分享文本的意图 |
-| getShareImageIntent | 获取分享图片的意图 |
-| getComponentIntent | 获取其他应用组件的意图 |
-| getShutdownIntent | 获取关机的意图 |
-| getDialIntent | 获取跳至拨号界面意图 |
-| getCallIntent | 获取拨打电话意图 |
-| getSendSmsIntent | 获取发送短信界面的意图 |
-| getCaptureIntent | 获取拍照的意图 |
-| startSysSetting | 跳转到系统设置页面 |
-| openWirelessSettings | 打开网络设置界面 - 3.0以下打开设置界面 |
-
-
-* **软键盘相关辅助类 ->** [KeyBoardUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/KeyBoardUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| setDelayMillis | 设置延迟时间 |
-| openKeyboard | 打开软键盘 |
-| closeKeyboard | 关闭软键盘 |
-| closeKeyBoardSpecial | 关闭软键盘 - 特殊处理 |
-| toggleKeyboard | 自动切换键盘状态,如果键盘显示了则隐藏,隐藏着显示 |
-| judgeView | 某个View里面的子View的View判断 |
-| isSoftInputVisible | 判断软键盘是否可见 |
-| registerSoftInputChangedListener | 注册软键盘改变监听器 |
-| registerSoftInputChangedListener2 | 注册软键盘改变监听器 |
-| fixSoftInputLeaks | 修复软键盘内存泄漏 在 Activity.onDestroy() 中使用 |
-| onSoftInputChanged | onSoftInputChanged |
-
-
-* **锁屏工具类 - 锁屏管理, 锁屏、禁用锁屏,判断是否锁屏 ->** [KeyguardUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/KeyguardUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| getInstance | 获取 KeyguardUtils 实例 ,单例模式 |
-| isKeyguardLocked | 是否锁屏 - android 4.1以上支持 |
-| isKeyguardSecure | 是否有锁屏密码 - android 4.1以上支持 |
-| inKeyguardRestrictedInputMode | 是否锁屏 - android 4.1 之前 |
-| getKeyguardManager | getKeyguardManager |
-| setKeyguardManager | setKeyguardManager |
-| disableKeyguard | 屏蔽系统的屏保 |
-| reenableKeyguard | 使能显示锁屏界面,如果你之前调用了disableKeyguard()方法取消锁屏界面,那么会马上显示锁屏界面。 |
-| release | 释放资源 |
-| newKeyguardLock | newKeyguardLock |
-| getKeyguardLock | getKeyguardLock |
-| setKeyguardLock | setKeyguardLock |
-
-
-* **事件工具类 => AppReflectUtils(可以删除) ->** [ListenerUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/ListenerUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| getTouchListener | 获取 View 设置的 OnTouchListener |
-| getListenerInfo | 获取 View ListenerInfo 对象(内部类) |
-| getListenerInfoListener | 获取 View ListenerInfo 对象内部事件对象 |
-| setOnClicks | 设置点击事件 |
-
-
-* **定位相关工具类 ->** [LocationUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/LocationUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| getLocation | 获取位置, 需要先判断是否开启了定位 |
-| isGpsEnabled | 判断Gps是否可用 |
-| isLocationEnabled | 判断定位是否可用 |
-| openGpsSettings | 打开Gps设置界面 |
-| register | 注册 |
-| unregister | 注销 |
-| getAddress | 根据经纬度获取地理位置 |
-| getCountryName | 根据经纬度获取所在国家 |
-| getLocality | 根据经纬度获取所在地 |
-| getStreet | 根据经纬度获取所在街道 |
-| isBetterLocation | 是否更好的位置 |
-| isSameProvider | 是否相同的提供者 |
-| getLastKnownLocation | 获取最后一次保留的坐标 |
-| onLocationChanged | 当坐标改变时触发此函数,如果Provider传进相同的坐标,它就不会被触发 |
-| onStatusChanged | provider的在可用、暂时不可用和无服务三个状态直接切换时触发此函数 |
-
-
-* **Android Manifest工具类 ->** [ManifestUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/ManifestUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| getMetaData | 获取 Manifest Meta Data |
-| getAppVersion | 获取app版本信息 |
-| getAppVersionCode | 获取app版本号 |
-| getAppVersionName | 获取app版本信息 |
-
-
-* **获取内存信息 ->** [MemoryUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/MemoryUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| getMemoryInfo | 获取内存信息 |
-| printMemoryInfo | Print Memory info. |
-| getAvailMemory | Get available memory info. |
-| getTotalMemory | 获取总内存大小 |
-| getMemoryAvailable | 获取可用内存大小 |
-| getMemInfoIype | 获取 type info |
-
-
-* **网络管理工具类 ->** [NetWorkUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/NetWorkUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| getMobileDataEnabled | 获取移动网络打开状态(默认属于未打开) |
-| setMobileDataEnabled | 设置移动网络开关(无判断是否已开启移动网络) - 实际无效果, 非系统应用无权限 |
-| isConnect | 判断是否连接了网络 |
-| getConnectType | 获取连接的网络类型 |
-| isConnWifi | 判断是否连接Wifi(连接上、连接中) |
-| isConnMobileData | 判断是否连接移动网络(连接上、连接中) |
-| isAvailable | 判断网络是否可用 |
-| is4G | 判断是否4G网络 |
-| getWifiEnabled | 判断wifi是否打开 |
-| isWifiAvailable | 判断wifi数据是否可用 |
-| getNetworkOperatorName | 获取网络运营商名称 - 中国移动、如中国联通、中国电信 |
-| getNetworkType | 获取当前网络类型 |
-| getDomainAddress | 获取域名ip地址 |
-| getIPAddress | 获取IP地址 |
-
-
-* **通知栏管理类 ->** [NotificationUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/NotificationUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| getNotificationManager | 获取通知栏管理类 |
-| cancelAll | 移除通知 - 移除所有通知(只是针对当前Context下的Notification) |
-| cancel | 移除通知 - 移除标记为id的通知 (只是针对当前Context下的所有Notification) |
-| notify | 进行通知 |
-| crePendingIntent | 获取跳转id |
-| creNotification | 创建通知栏对象 |
-| obtain | 获取 Led 配置参数 |
-| isEmpty | 判断是否为null |
-
-
-* **工具类: OS 系统相关 ->** [OSUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/OSUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| getRomType | 获取 ROM 类型 |
-| getBaseVersion | getBaseVersion |
-| getVersion | getVersion |
-
-
-* **路径相关工具类 ->** [PathUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/PathUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| getRootPath | 获取 Android 系统根目录 path: /system |
-| getDataPath | 获取 data 目录 path: /data |
-| getIntDownloadCachePath | 获取缓存目录 path: data/cache |
-| getAppIntCachePath | 获取此应用的缓存目录 path: /data/data/package/cache |
-| getAppIntFilesPath | 获取此应用的文件目录 path: /data/data/package/files |
-| getAppIntDbPath | 获取此应用的数据库文件目录 path: /data/data/package/databases/name |
-| getExtStoragePath | 获取 Android 外置储存的根目录 path: /storage/emulated/0 |
-| getExtAlarmsPath | 获取闹钟铃声目录 path: /storage/emulated/0/Alarms |
-| getExtDcimPath | 获取相机拍摄的照片和视频的目录 path: /storage/emulated/0/DCIM |
-| getExtDocumentsPath | 获取文档目录 path: /storage/emulated/0/Documents |
-| getExtDownloadsPath | 获取下载目录 path: /storage/emulated/0/Download |
-| getExtMoviesPath | 获取视频目录 path: /storage/emulated/0/Movies |
-| getExtMusicPath | 获取音乐目录 path: /storage/emulated/0/Music |
-| getExtNotificationsPath | 获取提示音目录 path: /storage/emulated/0/Notifications |
-| getExtPicturesPath | 获取图片目录 path: /storage/emulated/0/Pictures |
-| getExtPodcastsPath | 获取 Podcasts 目录 path: /storage/emulated/0/Podcasts |
-| getExtRingtonesPath | 获取铃声目录 path: /storage/emulated/0/Ringtones |
-| getAppExtCachePath | 获取此应用在外置储存中的缓存目录 path: /storage/emulated/0/Android/data/package/cache |
-| getAppExtFilePath | 获取此应用在外置储存中的文件目录 path: /storage/emulated/0/Android/data/package/files |
-| getAppExtAlarmsPath | 获取此应用在外置储存中的闹钟铃声目录 path: /storage/emulated/0/Android/data/package/files/Alarms |
-| getAppExtDcimPath | 获取此应用在外置储存中的相机目录 path: /storage/emulated/0/Android/data/package/files/DCIM |
-| getAppExtDocumentsPath | 获取此应用在外置储存中的文档目录 path: /storage/emulated/0/Android/data/package/files/Documents |
-| getAppExtDownloadPath | 获取此应用在外置储存中的闹钟目录 path: /storage/emulated/0/Android/data/package/files/Download |
-| getAppExtMoviesPath | 获取此应用在外置储存中的视频目录 path: /storage/emulated/0/Android/data/package/files/Movies |
-| getAppExtMusicPath | 获取此应用在外置储存中的音乐目录 path: /storage/emulated/0/Android/data/package/files/Music |
-| getAppExtNotificationsPath | 获取此应用在外置储存中的提示音目录 path: /storage/emulated/0/Android/data/package/files/Notifications |
-| getAppExtPicturesPath | 获取此应用在外置储存中的图片目录 path: /storage/emulated/0/Android/data/package/files/Pictures |
-| getAppExtPodcastsPath | 获取此应用在外置储存中的 Podcasts 目录 path: /storage/emulated/0/Android/data/package/files/Podcasts |
-| getAppExtRingtonesPath | 获取此应用在外置储存中的铃声目录 path: /storage/emulated/0/Android/data/package/files/Ringtones |
-| getObbPath | 获取此应用的 Obb 目录 path: /storage/emulated/0/Android/obb/package 一般用来存放游戏数据包 |
-| getFilePathByUri | getFilePathByUri |
-
-
-* **权限请求工具类 ->** [PermissionUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/PermissionUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| isGranted | 判断是否授予了权限 |
-| shouldShowRequestPermissionRationale | 是否拒绝了权限 - 拒绝过一次, 再次申请时, 弹出选择不再提醒并拒绝才会触发 true |
-| permission | 申请权限初始化 |
-| callBack | 设置回调方法 |
-| request | 请求权限 |
-| onRequestPermissionsResult | 请求权限回调 - 需要在 onRequestPermissionsResult 回调里面调用 |
-| onGranted | 授权通过权限 |
-| onDenied | 授权未通过权限 |
-| start | start |
-| onCreate | onCreate |
-
-
-* **手机相关工具类 ->** [PhoneUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/PhoneUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| isSimReady | 判断是否装载sim卡 |
-| getUserCountry | 获取Sim卡所属地区,非国内地区暂不支持播放 |
-| judgeArea | 判断地区,是否属于国内 |
-| isPhone | 判断设备是否是手机 |
-| getIMEI | 获取 IMEI 码 |
-| getIMSI | 获取 IMSI 码 |
-| getIMSIIDName | 获取IMSI处理过后的简称 |
-| getPhoneType | 获取移动终端类型 |
-| isSimCardReady | 判断 sim 卡是否准备好 |
-| getSimOperatorName | 获取 Sim 卡运营商名称 => 中国移动、如中国联通、中国电信 |
-| getSimOperatorByMnc | 获取 Sim 卡运营商名称 => 中国移动、如中国联通、中国电信 |
-| getDeviceId | 获取设备id |
-| getSerialNumber | 返回设备序列化 |
-| getAndroidId | 获取Android id |
-| getUUID | 获取设备唯一id |
-| getPhoneStatus | 获取手机状态信息 |
-| dial | 跳至拨号界面 |
-| call | 拨打电话 |
-| sendSms | 跳至发送短信界面 |
-| sendSmsSilent | 发送短信 |
-| getAllContactInfo | 获取手机联系人 |
-| getAllContactInfo2 | 获取手机联系人 |
-| getContactNum | 打开手机联系人界面点击联系人后便获取该号码 |
-| getAllSMS | 获取手机短信并保存到 xml 中 |
-| getMtkTeleInfo | MTK Phone. 获取 MTK 神机的双卡 IMSI、IMSI 信息 |
-| getMtkTeleInfo2 | MTK Phone. 获取 MTK 神机的双卡 IMSI、IMSI 信息 |
-| getQualcommTeleInfo | Qualcomm Phone. 获取 高通 神机的双卡 IMSI、IMSI 信息 |
-| getSpreadtrumTeleInfo | Spreadtrum Phone. 获取 展讯 神机的双卡 IMSI、IMSI 信息 |
-| toString | toString |
-
-
-* **轮询工具类 ->** [PollingUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/PollingUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| startPolling | 开启轮询 |
-| stopPolling | 停止轮询 |
-| startPollingService | 开启轮询服务 |
-| stopPollingService | 停止启轮询服务 |
-
-
-* **电源管理工具类 ->** [PowerManagerUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/PowerManagerUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| getInstance | 获取 PowerManagerUtils 实例 ,单例模式 |
-| isScreenOn | 屏幕是否打开(亮屏) |
-| turnScreenOn | 唤醒屏幕/点亮亮屏 |
-| turnScreenOff | 释放屏幕锁, 允许休眠时间自动黑屏 |
-| getWakeLock | getWakeLock |
-| setWakeLock | setWakeLock |
-| getPowerManager | getPowerManager |
-| setPowerManager | setPowerManager |
-| setBright | 设置屏幕常亮 |
-| setWakeLockToBright | 设置WakeLock 常亮 |
-
-
-* **进程相关工具类 ->** [ProcessUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/ProcessUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| getProcessName | 获取进程号对应的进程名 |
-| getCurProcessName | 获得当前进程的名字 |
-| getForegroundProcessName | 获取前台线程包名 |
-| getAllBackgroundProcesses | 获取后台服务进程 |
-| killAllBackgroundProcesses | 杀死所有的后台服务进程 |
-| killBackgroundProcesses | 杀死后台服务进程 |
-
-
-* **资源文件工具类 ->** [ResourceUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/ResourceUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| getString | 获得字符串 |
-| getColor | 获得颜色 |
-| getDrawable | 获得Drawable |
-| getResourceId | 根据资源名获得资源id |
-| getDrawableId2 | 获取资源id |
-| getLayoutId | 获取 layout 布局文件 |
-| getStringId | 获取 string 值 |
-| getDrawableId | 获取 drawable |
-| getMipmapId | 获取 mipmap |
-| getStyleId | 获取 style |
-| getStyleableId | 获取 styleable |
-| getAnimId | 获取 anim |
-| getId | 获取 id |
-| getColorId | color |
-| readBytesFromAssets | 获取 Assets 资源文件数据 |
-| readStringFromAssets | 读取字符串 来自 Assets文件 |
-| readBytesFromRaw | 从res/raw 中获取内容。 |
-| readStringFromRaw | 读取字符串 来自Raw 文件 |
-| geFileToListFromAssets | 获取 Assets 资源文件数据(返回ArrayList 一行的全部内容属于一个索引) |
-| geFileToListFromRaw | 从res/raw 中获取内容。(返回ArrayList 一行的全部内容属于一个索引) |
-| saveAssetsFormFile | 从Assets 资源中获取内容并保存到本地 |
-| saveRawFormFile | 从res/raw 中获取内容并保存到本地 |
-
-
-* **屏幕相关工具类 ->** [ScreenUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/ScreenUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| getScreenWidth | 获取屏幕的宽度(单位:px) |
-| getScreenHeight | 获取屏幕的高度(单位:px) |
-| getScreenWidthHeightToPoint | 通过上下文获取屏幕宽度高度 |
-| getScreenWidthHeight | 通过上下文获取屏幕宽度高度 |
-| getScreenSize | 获取屏幕分辨率 |
-| getScreenSizeOfDevice | 获取屏幕英寸 例5.5英寸 |
-| getDensity | 通过上下文获取屏幕密度 |
-| getDensityDpi | 通过上下文获取屏幕密度Dpi |
-| getScaledDensity | 通过上下文获取屏幕缩放密度 |
-| getXDpi | 获取 X轴 dpi |
-| getYDpi | 获取 Y轴 dpi |
-| getWidthDpi | 获取 宽度比例 dpi 基准 |
-| getHeightDpi | 获取 高度比例 dpi 基准 |
-| getScreenInfo | 获取屏幕信息 |
-| setFullScreen | 设置屏幕为全屏 |
-| setLandscape | 设置屏幕为横屏 |
-| setPortrait | 设置屏幕为竖屏 |
-| isLandscape | 判断是否横屏 |
-| isPortrait | 判断是否竖屏 |
-| getScreenRotation | 获取屏幕旋转角度 |
-| isScreenLock | 判断是否锁屏 |
-| isTablet | 判断是否是平板 |
-| getStatusHeight | 获得状态栏的高度(无关 android:theme 获取状态栏高度) |
-| getStatusBarHeight | 获取应用区域 TitleBar 高度 (顶部灰色TitleBar高度,没有设置 android:theme 的 NoTitleBar 时会显示) |
-| setSleepDuration | 设置进入休眠时长 - 需添加权限 |
-| getSleepDuration | 获取进入休眠时长 |
-| snapShotWithStatusBar | 获取当前屏幕截图,包含状态栏 (顶部灰色TitleBar高度,没有设置 android:theme 的 NoTitleBar 时会显示) |
-| snapShotWithoutStatusBar | 获取当前屏幕截图,不包含状态栏 (如果 android:theme 全屏了,则截图无状态栏) |
-| getNavigationBarHeight | 获取底部导航栏高度 |
-| checkDeviceHasNavigationBar | 检测是否具有底部导航栏 |
-
-
-* **SD卡相关辅助类 ->** [SDCardUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/SDCardUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| isSDCardEnable | 判断SDCard是否正常挂载 |
-| getSDCardFile | 获取SD卡路径(File对象) |
-| getSDCardPath | 获取SD卡路径(无添加 -> / -> File.separator) |
-| isSDCardEnablePath | 判断 SD 卡是否可用 |
-| getSDCardPaths | 获取 SD 卡路径 |
-| getAllBlockSize | 返回对应路径的空间总大小 |
-| getAvailableBlocks | 返回对应路径的空闲空间(byte 字节大小) |
-| getAlreadyBlock | 返回对应路径,已使用的空间大小 |
-| getBlockSizeInfos | 返回对应路径的空间大小信息 |
-| getSDTotalSize | 获得 SD 卡总大小 |
-| getSDAvailableSize | 获得 SD 卡剩余容量,即可用大小 |
-| getRomTotalSize | 获得机身内存总大小 |
-| getRomAvailableSize | 获得机身可用内存 |
-| getDiskCacheDir | 获取缓存地址 |
-| getCacheFile | 获取缓存资源地址 |
-| getCachePath | 获取缓存资源地址 |
-
-
-* **服务相关工具类 ->** [ServiceUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/ServiceUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| isServiceRunning | 判断服务是否运行 |
-| getAllRunningService | 获取所有运行的服务 |
-| startService | 启动服务 |
-| stopService | 停止服务 |
-| bindService | 绑定服务 |
-| unbindService | 解绑服务 |
-
-
-* **Shape 工具类 ->** [ShapeUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/ShapeUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| getDrawable | getDrawable |
-| setDrawable | setDrawable |
-| newBuilder | 创建新的 Shape Builder 对象 |
-| newBuilderToLeft | 创建新的 Shape Builder 对象 |
-| newBuilderToRight | 创建新的 Shape Builder 对象 |
-| newBuilderToGradient | 创建渐变的 Shape Builder 对象 |
-| build | 获取 Shape 工具类 |
-| setRadius | 设置圆角 |
-| setRadiusLeft | 设置圆角 |
-| setRadiusRight | 设置圆角 |
-| setCornerRadii | 内部处理方法 |
-| setColor | 设置背景色(填充铺满) |
-| setStroke | 设置边框颜色 |
-| setSize | 设置大小 |
-
-
-* **Shell 相关工具类 ->** [ShellUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/ShellUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| execCmd | 是否是在 root 下执行命令 |
-
-
-* **创建删除快捷图标工具类 ->** [ShortCutUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/ShortCutUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| hasShortcut | 检测是否存在桌面快捷方式 |
-| addShortcut | 为程序创建桌面快捷方式 |
-| delShortcut | 删除程序的快捷方式 |
-
-
-* **签名工具类(获取app,签名信息) ->** [SignaturesUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/SignaturesUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| toHexString | 进行转换 |
-| signatureMD5 | 返回MD5 |
-| signatureSHA1 | SHA1 |
-| signatureSHA256 | SHA256 |
-| isDebuggable | 判断签名是debug签名还是release签名 |
-| getX509Certificate | 获取App 证书对象 |
-| printSignatureName | 打印签名信息 |
-| getSignaturesFromApk | 从APK中读取签名 |
-| getCertificateFromApk | 从APK中读取签名 |
-
-
-* **dp,px,sp转换、View获取宽高等 ->** [SizeUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/SizeUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| dipConvertPx | 根据手机的分辨率从 dp 的单位 转成为 px(像素) |
-| pxConvertDip | 根据手机的分辨率从 px(像素) 的单位 转成为 dp |
-| pxConvertSp | 根据手机的分辨率从 px(像素) 的单位 转成为 sp |
-| spConvertPx | 根据手机的分辨率从 sp 的单位 转成为 px |
-| dipConvertPx2 | 根据手机的分辨率从 dp 的单位 转成为 px(像素) 第二种 |
-| spConvertPx2 | 根据手机的分辨率从 sp 的单位 转成为 px 第二种 |
-| applyDimension | 各种单位转换 - 该方法存在于 TypedValue |
-| forceGetViewSize | 获取视图的尺寸 |
-| measureView | 测量视图尺寸 |
-| getMeasuredWidth | 获取测量视图宽度 |
-| getMeasuredHeight | 获取测量视图高度 |
-| onGetSize | onGetSize |
-
-
-* **颜色状态列表 工具类 ->** [StateListUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/StateListUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| getColorStateList | 通过上下文获取 |
-| createColorStateList | 创建 颜色状态列表 => createColorStateList("#ffffffff", "#ff44e6ff") |
-| newSelector | 创建 Drawable选择切换 list => view.setBackground(Drawable) |
-
-
-* **TextView 工具类 ->** [TextViewUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/TextViewUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| getTextView | 获取TextView |
-| getText | 获取文本 |
-| setTextColor | 设置字体颜色 |
-| setText | 设置内容 |
-| setHtmlText | 设置 Html 内容 |
-| setTVUnderLine | 给TextView设置下划线 |
-| getTextHeight | 获取字体高度 |
-| getTextTopOffsetHeight | 获取字体顶部偏移高度 |
-| getTextWidth | 计算字体宽度 |
-| getCenterRectY | 获取画布中间居中位置 |
-| reckonTextSize | 通过需要的高度, 计算字体大小 |
-| calcTextWidth | 计算第几位超过宽度 |
-
-
-* **Uri 工具类 ->** [UriUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/UriUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| getUriForFileToName | 返回处理后的Uri, 单独传递名字, 自动添加包名 ${applicationId} |
-| getUriForFile | Return a content URI for a given file. |
-
-
-* **震动相关工具类 ->** [VibrationUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/VibrationUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| vibrate | 震动 |
-| cancel | 取消振动 |
-
-
-* **View 操作相关工具类 ->** [ViewUtils.java](https://github.com/afkT/DevUtils/blob/master/DevLibUtils/src/main/java/dev/utils/app/ViewUtils.java)
-
-| 方法 | 注释 |
-| :-: | :-: |
-| getContext | 获取上下文 |
-| isEmpty | 判断View 是否为null |
-| isVisibility | 判断View 是否显示 |
-| isVisibilitys | 判断 View 是否都显示显示 |
-| isVisibilityIN | 判断View 是否隐藏占位 |
-| isVisibilityGone | 判断View 是否隐藏 |
-| getVisibility | 获取显示的状态 (View.VISIBLE : View.GONE) |
-| getVisibilityIN | 获取显示的状态 (View.VISIBLE : View.INVISIBLE) |
-| setVisibility | 设置View显示状态 |
-| setVisibilitys | 设置View 显示的状态 |
-| toggleVisibilitys | 切换View 显示的状态 |
-| toogleView | 切换View状态 |
-| setViewImageRes | 设置View 图片资源 |
-| findViewById | 初始化View |
-| removeSelfFromParent | 把自身从父View中移除 |
-| isTouchInView | 判断触点是否落在该View上 |
-| requestLayoutParent | View 改变请求 |
-| measureView | 测量 view |
-| getViewWidth | 获取view的宽度 |
-| getViewHeight | 获取view的高度 |
-| getActivity | 获取view的上下文 |
-| calcListViewItemHeight | 计算ListView Item 高度 |
-| calcGridViewItemHeight | 计算GridView Item 高度 |
-| getItemHeighet | 获取单独一个Item 高度 |
\ No newline at end of file
diff --git a/DevLibUtils/build.gradle b/DevLibUtils/build.gradle
deleted file mode 100644
index 7084b5e1df..0000000000
--- a/DevLibUtils/build.gradle
+++ /dev/null
@@ -1,115 +0,0 @@
-apply plugin: 'com.android.library'
-
-def dev_utils_version = "1.0.0";
-
-android {
- compileSdkVersion 27
- buildToolsVersion "27.0.3"
-
- defaultConfig {
- minSdkVersion 19
- targetSdkVersion 27
- versionCode 1
- versionName dev_utils_version
-
- /**
-
-
- */
- manifestPlaceholders = [ dev_utils_version : dev_utils_version ]
- }
-
-
- buildTypes {
-
- release {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
- }
- debug {
- minifyEnabled false
- proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
- }
- }
- lintOptions {
- abortOnError false
- }
-}
-
-dependencies {
- compile fileTree(include: ['*.jar'], dir: 'libs')
- implementation 'com.android.support:appcompat-v7:27.1.1'
- implementation 'com.android.support:support-v4:27.1.1'
-}
-
-// == 打包, 包含注释 ==
-
-// 指定编码
-tasks.withType(JavaCompile) {
- options.encoding = "UTF-8"
-}
-
-// 打包源码
-task sourcesJar(type: Jar) {
- from android.sourceSets.main.java.srcDirs
- classifier = 'sources'
-}
-
-task javadoc(type: Javadoc) {
- failOnError false
- source = android.sourceSets.main.java.sourceFiles
- classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
- classpath += configurations.compile
-}
-
-// 制作文档(Javadoc)
-task javadocJar(type: Jar, dependsOn: javadoc) {
- classifier = 'javadoc'
- from javadoc.destinationDir
-}
-
-artifacts {
- archives sourcesJar
- archives javadocJar
-}
-
-// https://www.jianshu.com/p/44f2d0ee32c8
-
-// https://www.jianshu.com/p/1777a634db5e
-
-// https://www.cnblogs.com/xinaixia/p/7660173.html
-
-// ==== 项目打包 aar =====
-
-// 将被嵌入的应用打包成 aar 包,这也是 Android Studio 的一种新特性,可以将应用所使用的资源性文件一起打包。编译即可打包生成 aar 包,而且也不用担心漏掉资源问题。
-// 直接使用aar, 内部包含 jar
-// build\outputs\aar\DevLibUtils-debug.aar, DevLibUtils-release.aar
-
-// ==== 项目打包 jar =====
-
-// Terminal 输入 gradlew makeJar
-
-// 方式 A :点击 Android Studio 右侧(一般在这个位置)的 Gradle 面板,在项目或者该类库的目录中找到 Tasks -> other -> makeJar 命令,双击这个makeJar之后等一会就会编译好jar包。
-
-// DevLibUtils.jar
-// DevLibUtils_v1.0.jar
-
-def _BASENAME = "DevLibUtils";
-def _VERSION = "_v" + android.defaultConfig.versionName;
-def _DestinationPath = "build"; //生成jar包的位置
-def zipFile = file('build/intermediates/bundles/debug/classes.jar'); //待打包文件位置
-
-task deleteBuild(type:Delete){
- delete _DestinationPath + _BASENAME + _VERSION + ".jar"
-}
-
-task makeJar(type:Jar){
- from zipTree(zipFile)
- from fileTree(dir:'src/main',includes:['assets/**']) //将assets目录打入jar包
- baseName = _BASENAME + _VERSION
- destinationDir = file(_DestinationPath)
-}
-
-makeJar.dependsOn(deleteBuild, build)
\ No newline at end of file
diff --git a/DevLibUtils/proguard-rules.pro b/DevLibUtils/proguard-rules.pro
deleted file mode 100644
index f1b424510d..0000000000
--- a/DevLibUtils/proguard-rules.pro
+++ /dev/null
@@ -1,21 +0,0 @@
-# Add project specific ProGuard rules here.
-# You can control the set of applied configuration files using the
-# proguardFiles setting in build.gradle.
-#
-# For more details, see
-# http://developer.android.com/guide/developing/tools/proguard.html
-
-# 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
diff --git a/DevLibUtils/src/main/AndroidManifest.xml b/DevLibUtils/src/main/AndroidManifest.xml
deleted file mode 100644
index 50c5b4e4d4..0000000000
--- a/DevLibUtils/src/main/AndroidManifest.xml
+++ /dev/null
@@ -1,13 +0,0 @@
-
-
-
-
-
-
-
-
diff --git a/DevLibUtils/src/main/java/dev/DevUtils.java b/DevLibUtils/src/main/java/dev/DevUtils.java
deleted file mode 100644
index b8fcb54e16..0000000000
--- a/DevLibUtils/src/main/java/dev/DevUtils.java
+++ /dev/null
@@ -1,298 +0,0 @@
-package dev;
-
-import android.app.Activity;
-import android.app.Application;
-import android.content.Context;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.Looper;
-
-import dev.utils.BuildConfig;
-import dev.utils.JCLogUtils;
-import dev.utils.LogPrintUtils;
-import dev.utils.app.AnalysisRecordUtils;
-import dev.utils.app.FileRecordUtils;
-import dev.utils.app.HandlerUtils;
-import dev.utils.app.cache.DevCache;
-import dev.utils.app.logger.DevLoggerUtils;
-import dev.utils.app.share.SharedUtils;
-
-/**
- * detail: 开发工具类
- * Created by Ttt
- */
-public final class DevUtils {
-
- /** 禁止构造对象,保证只有一个实例 */
- private DevUtils() {
- }
-
-// // DevUtils 实例
-// private static DevUtils INSTANCE = new DevUtils();
-//
-// /** 获取 DevUtils 实例 ,单例模式 */
-// public static DevUtils getInstance() {
-// return INSTANCE;
-// }
-
- // ---
-
- /** 全局 Application 对象 */
- private static Application sApplication;
- /** 全局上下文 - getApplicationContext() */
- private static Context sContext;
- /** 获取当前线程,主要判断是否属于主线程 */
- private static Thread sUiThread;
- /** 全局Handler,便于子线程快捷操作等 */
- private static Handler sHandler;
- /** 是否内部debug模式 */
- private static boolean debug = false;
-
- /**
- * 默认初始化方法 - 必须调用 - Application.onCreate 中调用
- * @param context 上下文
- */
- public static void init(Context context) {
- // 设置全局上下文
- initContext(context);
- // 初始化全局 Application
- initApplication(context);
- // 初始化Shared 工具类
- SharedUtils.init(context);
- // 初始化记录文件配置
- FileRecordUtils.appInit();
- // 初始化记录工具类
- AnalysisRecordUtils.init(context);
- // 初始化 DevLogger 配置
- DevLoggerUtils.appInit(context);
- // 初始化Handler工具类
- HandlerUtils.init(context);
- // 初始化缓存类
- DevCache.get(context);
- // 保存当前线程信息
- sUiThread = Thread.currentThread();
- // 初始化全局Handler - 主线程
- sHandler = new Handler(Looper.getMainLooper());
- // 注册 Activity 生命周期监听
- registerActivityLifecycleCallbacks(sApplication);
- }
-
- /**
- * 初始化全局上下文
- * @param context
- */
- private static void initContext(Context context) {
- // 如果为null, 才进行判断处理
- if (DevUtils.sContext == null){
- // 防止传进来的为null
- if (context == null) {
- return;
- }
- DevUtils.sContext = context.getApplicationContext();
- }
- }
-
- /**
- * 初始化全局 Application
- * @param context
- */
- private static void initApplication(Context context) {
- // 如果为null, 才进行判断处理
- if (DevUtils.sApplication == null){
- if (context == null){
- return;
- }
- Application mApplication = null;
- try {
- mApplication = (Application) context.getApplicationContext();
- } catch (Exception e){
- }
- // 防止传进来的为null
- if (mApplication == null) {
- return;
- }
- DevUtils.sApplication = mApplication;
- }
- }
-
- /**
- * 获取全局上下文
- * @return
- */
- public static Context getContext() {
- return DevUtils.sContext;
- }
-
- /**
- * 获取上下文(判断null,视情况返回全局上下文)
- * @param context
- */
- public static Context getContext(Context context) {
- // 进行判断
- if (context != null){
- return context;
- }
- return DevUtils.sContext;
- }
-
- /**
- * 获取全局 Application
- * @return
- */
- public static Application getApplication(){
- return DevUtils.sApplication;
- }
-
- /**
- * 获取Handler
- * @return
- */
- public static Handler getHandler(){
- if (sHandler == null){
- // 初始化全局Handler - 主线程
- sHandler = new Handler(Looper.getMainLooper()); //Looper.myLooper();
- }
- return sHandler;
- }
-
- /**
- * 执行UI 线程任务 => Activity 的 runOnUiThread(Runnable)
- * @param action 若当前非UI线程则切换到UI线程执行
- */
- public static void runOnUiThread(Runnable action) {
- if (Thread.currentThread() != sUiThread) {
- sHandler.post(action);
- } else {
- action.run();
- }
- }
-
- /**
- * 执行UI 线程任务 => 延时执行
- * @param action
- * @param delayMillis
- */
- public static void runOnUiThread(Runnable action, long delayMillis){
- sHandler.postDelayed(action, delayMillis);
- }
-
- /**
- * 打开日志
- */
- public static void openLog() {
- // 专门打印 Android 日志信息
- LogPrintUtils.setPrintLog(true);
- // 专门打印 Java 日志信息
- JCLogUtils.setPrintLog(true);
- }
-
- /**
- * 标记debug模式
- */
- public static void openDebug() {
- DevUtils.debug = true;
- }
-
- /**
- * 判断是否Debug模式
- * @return
- */
- public static boolean isDebug() {
- return debug;
- }
-
- // ==================
- // ==== Activity ====
- // ==================
-
- /**
- * 注册绑定Activity 生命周期事件处理
- * @param application
- */
- private static void registerActivityLifecycleCallbacks(Application application){
- if (application != null){
- // 先移除旧的监听
- application.unregisterActivityLifecycleCallbacks(lifecycleCallbacks);
- // 绑定新的监听
- application.registerActivityLifecycleCallbacks(lifecycleCallbacks);
- }
- }
-
- /** 保留当前(前台) Activity */
- private static Activity sCurActivity = null;
-
- /**
- * 对Activity的生命周期事件进行集中处理。
- * http://blog.csdn.net/tongcpp/article/details/40344871
- */
- private static Application.ActivityLifecycleCallbacks lifecycleCallbacks = new Application.ActivityLifecycleCallbacks() {
- @Override
- public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
-
- }
-
- @Override
- public void onActivityStarted(Activity activity) {
-
- }
-
- @Override
- public void onActivityResumed(Activity activity) {
- // 保存当前Activity
- DevUtils.sCurActivity = activity;
- }
-
- @Override
- public void onActivityPaused(Activity activity) {
-
- }
-
- @Override
- public void onActivityStopped(Activity activity) {
-
- }
-
- @Override
- public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
-
- }
-
- @Override
- public void onActivityDestroyed(Activity activity) {
-
- }
- };
-
- /**
- * 获取当前Activity
- * @return
- */
- public static Activity getCurActivity(){
- return DevUtils.sCurActivity;
- }
-
- /**
- * 判断是否相同的 Activity
- * @param activity
- * @return
- */
- public static boolean isSameActivity(Activity activity){
- if (activity != null && DevUtils.sCurActivity != null){
- try {
- return DevUtils.sCurActivity.getClass().getName().equals(activity.getClass().getName());
- } catch (Exception e){
- }
- }
- return false;
- }
-
- // == 工具类版本 ==
-
- /**
- * 获取工具类版本
- * @return
- */
- public static String getUtilsVersion(){
- return BuildConfig.VERSION_NAME;
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/JCLogUtils.java b/DevLibUtils/src/main/java/dev/utils/JCLogUtils.java
deleted file mode 100644
index eb43dfb6d1..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/JCLogUtils.java
+++ /dev/null
@@ -1,289 +0,0 @@
-package dev.utils;
-
-import org.json.JSONArray;
-import org.json.JSONObject;
-
-import java.io.StringReader;
-import java.io.StringWriter;
-
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
-
-/**
- * detail: Java Common 日志打印工具类(简化版) - 项目内部使用 - 主要打印非 Android 日志
- * Created by Ttt
- */
-public final class JCLogUtils {
-
- private JCLogUtils(){
- }
-
- // 普通信息模式
- public static final int INFO = 0;
- // DEBUG模式
- public static final int DEBUG = 1;
- // ERROR模式
- public static final int ERROR = 2;
-
- // =
-
- /** JSON格式内容缩进 */
- private static final int JSON_INDENT = 4;
- /** 是否打印日志 上线 = false,开发、debug = true*/
- private static boolean JUDGE_PRINT_LOG = false;
- /** 默认DEFAULT_TAG */
- private static final String DEFAULT_DEFAULT_TAG = JCLogUtils.class.getSimpleName();
-
- /**
- * 判断是否打印日志
- * @return
- */
- public static boolean isPrintLog() {
- return JUDGE_PRINT_LOG;
- }
-
- /**
- * 设置是否打印日志
- * @param judgePrintLog
- */
- public static void setPrintLog(boolean judgePrintLog) {
- JUDGE_PRINT_LOG = judgePrintLog;
- }
-
- /**
- * 判断是否为null
- * @param str
- * @return
- */
- private static boolean isEmpty(String str) {
- return (str == null || str.length() == 0);
- }
-
- // =
-
- /**
- * 最终打印日志方法(全部调用此方法)
- * @param logType 打印日志类型
- * @param tag 打印Tag
- * @param msg 打印消息
- */
- private static void printLog(int logType, String tag, String msg) {
- switch (logType) {
- case INFO:
- LogPrintUtils.iTag(tag, msg);
- case ERROR:
- LogPrintUtils.eTag(tag, msg);
- break;
- case DEBUG:
- default:
- LogPrintUtils.dTag(tag, msg);
- break;
- }
- // 打印信息
- if (isEmpty(tag)){
- System.out.println(msg);
- } else {
- System.out.println(tag + " : " + msg);
- }
- }
-
- /**
- * 处理信息
- * @param message 打印信息
- * @param args 占位符替换
- * @return
- */
- private static String createMessage(String message, Object... args) {
- String result = null;
- try {
- if(message != null){
- if(args == null){
- // 动态参数为null
- result = "params is null";
- } else {
- // 格式化字符串
- result = (args.length == 0 ? message : String.format(message, args));
- }
- } else {
- // 打印内容为null
- result = "message is null";
- }
- } catch (Exception e) {
- // 出现异常
- result = e.toString();
- }
- return result;
- }
-
- /**
- * 拼接错误信息
- * @param throwable 错误异常
- * @param message 需要打印的消息
- * @param args 动态参数
- * @return
- */
- private static String splitErrorMessage(Throwable throwable, String message, Object... args) {
- String result = null;
- try {
- if(throwable != null){
- if(message != null){
- result = createMessage(message, args) + " : " + throwable.toString();
- } else {
- result = throwable.toString();
- }
- } else {
- result = createMessage(message, args);
- }
- } catch (Exception e) {
- result = e.toString();
- }
- return result;
- }
-
- // =================== 对外公开方法 =========================
-
- // ========= 使用默认TAG =========
-
- public static void d(String message, Object... args) {
- dTag(DEFAULT_DEFAULT_TAG, message, args);
- }
-
- public static void e(Throwable throwable) {
- eTag(DEFAULT_DEFAULT_TAG, throwable);
- }
-
- public void e(String message, Object... args) {
- e(null, message, args);
- }
-
- public static void e(Throwable throwable, String message, Object... args) {
- eTag(DEFAULT_DEFAULT_TAG, throwable, message, args);
- }
-
- public static void i(String message, Object... args) {
- iTag(DEFAULT_DEFAULT_TAG, message, args);
- }
-
- public static void json(String json) {
- jsonTag(DEFAULT_DEFAULT_TAG, json);
- }
-
- public static void xml(String xml) {
- xmlTag(DEFAULT_DEFAULT_TAG, xml);
- }
-
- // -- 日志打印方法 --
-
- public static void dTag(String tag, String message, Object... args) {
- if (JUDGE_PRINT_LOG){
- printLog(DEBUG, tag, createMessage(message, args));
- }
- }
-
- public static void eTag(String tag, String message, Object... args) {
- if(JUDGE_PRINT_LOG){
- printLog(ERROR, tag, createMessage(message, args));
- }
- }
-
- public static void eTag(String tag, Throwable throwable) {
- if(JUDGE_PRINT_LOG){
- printLog(ERROR, tag, splitErrorMessage(throwable, null));
- }
- }
-
- public static void eTag(String tag, Throwable throwable, String message, Object... args) {
- if(JUDGE_PRINT_LOG){
- printLog(ERROR, tag, splitErrorMessage(throwable, message, args));
- }
- }
-
- public static void iTag(String tag, String message, Object... args) {
- if(JUDGE_PRINT_LOG){
- printLog(INFO, tag, createMessage(message, args));
- }
- }
-
- public static void jsonTag(String tag, String json) {
- if (JUDGE_PRINT_LOG){
- // 判断传入JSON格式信息是否为null
- if (isEmpty(json)) {
- printLog(ERROR, tag, "Empty/Null json content");
- return;
- }
- try {
- // 属于对象的JSON格式信息
- if (json.startsWith("{")) {
- JSONObject jsonObject = new JSONObject(json);
- // 进行缩进
- String message = jsonObject.toString(JSON_INDENT);
- // 打印信息
- printLog(DEBUG, tag, message);
- } else if (json.startsWith("[")) {
- // 属于数据的JSON格式信息
- JSONArray jsonArray = new JSONArray(json);
- // 进行缩进
- String message = jsonArray.toString(JSON_INDENT);
- // 打印信息
- printLog(DEBUG, tag, message);
- }
- } catch (Exception e) {
- String eHint = "null";
- if (e != null){
- Throwable throwable = e.getCause();
- if (throwable != null){
- eHint = throwable.getMessage();
- } else {
- try {
- eHint = e.getMessage();
- } catch (Exception e1){
- eHint = e1.getMessage();
- }
- }
- }
- printLog(ERROR, tag, eHint + "\n" + json);
- }
- }
- }
-
- public static void xmlTag(String tag, String xml) {
- if (JUDGE_PRINT_LOG){
- // 判断传入XML格式信息是否为null
- if (isEmpty(xml)) {
- printLog(ERROR, tag, "Empty/Null xml content");
- return;
- }
- try {
- Source xmlInput = new StreamSource(new StringReader(xml));
- StreamResult xmlOutput = new StreamResult(new StringWriter());
- Transformer transformer = TransformerFactory.newInstance().newTransformer();
- transformer.setOutputProperty(OutputKeys.INDENT, "yes");
- transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
- transformer.transform(xmlInput, xmlOutput);
- // 获取打印消息
- String message = xmlOutput.getWriter().toString().replaceFirst(">", ">\n");
- // 打印信息
- printLog(DEBUG, tag, message);
- } catch (Exception e) {
- String eHint = "null";
- if (e != null){
- Throwable throwable = e.getCause();
- if (throwable != null){
- eHint = throwable.getMessage();
- } else {
- try {
- eHint = e.getMessage();
- } catch (Exception e1){
- eHint = e1.getMessage();
- }
- }
- }
- printLog(ERROR, tag, eHint + "\n" + xml);
- }
- }
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/LogPrintUtils.java b/DevLibUtils/src/main/java/dev/utils/LogPrintUtils.java
deleted file mode 100644
index f5daf7b262..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/LogPrintUtils.java
+++ /dev/null
@@ -1,310 +0,0 @@
-package dev.utils;
-
-import android.text.TextUtils;
-import android.util.Log;
-
-import org.json.JSONArray;
-import org.json.JSONObject;
-
-import java.io.StringReader;
-import java.io.StringWriter;
-
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.Source;
-import javax.xml.transform.Transformer;
-import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.stream.StreamResult;
-import javax.xml.transform.stream.StreamSource;
-
-/**
- * detail: 日志打印工具类(简化版) - 项目内部使用
- * Created by Ttt
- */
-public final class LogPrintUtils {
-
- private LogPrintUtils(){
- }
-
- /** JSON格式内容缩进 */
- private static final int JSON_INDENT = 4;
- /** 是否打印日志 上线 = false,开发、debug = true*/
- private static boolean JUDGE_PRINT_LOG = false;
- /** 默认DEFAULT_TAG */
- private static final String DEFAULT_DEFAULT_TAG = LogPrintUtils.class.getSimpleName();
-
- /**
- * 判断是否打印日志
- * @return
- */
- public static boolean isPrintLog() {
- return JUDGE_PRINT_LOG;
- }
-
- /**
- * 设置是否打印日志
- * @param judgePrintLog
- */
- public static void setPrintLog(boolean judgePrintLog) {
- JUDGE_PRINT_LOG = judgePrintLog;
- }
-
- // =
-
- /**
- * 最终打印日志方法(全部调用此方法)
- * @param logType 打印日志类型
- * @param tag 打印Tag
- * @param msg 打印消息
- */
- private static void printLog(int logType, String tag, String msg) {
- switch (logType) {
- case Log.ERROR:
- Log.e(tag, msg);
- break;
- case Log.INFO:
- Log.i(tag, msg);
- break;
- case Log.VERBOSE:
- Log.v(tag, msg);
- break;
- case Log.WARN:
- Log.w(tag, msg);
- break;
- case Log.ASSERT:
- Log.wtf(tag, msg);
- break;
- case Log.DEBUG:
- Log.d(tag, msg);
- break;
- default:
- Log.d(tag, msg);
- break;
- }
- }
-
- /**
- * 处理信息
- * @param message 打印信息
- * @param args 占位符替换
- * @return
- */
- private static String createMessage(String message, Object... args) {
- String result = null;
- try {
- if(message != null){
- if(args == null){
- // 动态参数为null
- result = "params is null";
- } else {
- // 格式化字符串
- result = (args.length == 0 ? message : String.format(message, args));
- }
- } else {
- // 打印内容为null
- result = "message is null";
- }
- } catch (Exception e) {
- // 出现异常
- result = e.toString();
- }
- return result;
- }
-
- /**
- * 拼接错误信息
- * @param throwable 错误异常
- * @param message 需要打印的消息
- * @param args 动态参数
- * @return
- */
- private static String splitErrorMessage(Throwable throwable, String message, Object... args) {
- String result = null;
- try {
- if(throwable != null){
- if(message != null){
- result = createMessage(message, args) + " : " + throwable.toString();
- } else {
- result = throwable.toString();
- }
- } else {
- result = createMessage(message, args);
- }
- } catch (Exception e) {
- result = e.toString();
- }
- return result;
- }
-
- // =================== 对外公开方法 =========================
-
- // ========= 使用默认TAG =========
-
- public static void d(String message, Object... args) {
- dTag(DEFAULT_DEFAULT_TAG, message, args);
- }
-
- public static void e(Throwable throwable) {
- eTag(DEFAULT_DEFAULT_TAG, throwable, null);
- }
-
- public void e(String message, Object... args) {
- e(null, message, args);
- }
-
- public static void e(Throwable throwable, String message, Object... args) {
- eTag(DEFAULT_DEFAULT_TAG, throwable, message, args);
- }
-
- public static void w(String message, Object... args) {
- wTag(DEFAULT_DEFAULT_TAG, message, args);
- }
-
- public static void i(String message, Object... args) {
- iTag(DEFAULT_DEFAULT_TAG, message, args);
- }
-
- public static void v(String message, Object... args) {
- vTag(DEFAULT_DEFAULT_TAG, message, args);
- }
-
- public static void wtf(String message, Object... args) {
- wtfTag(DEFAULT_DEFAULT_TAG, message, args);
- }
-
- public static void json(String json) {
- jsonTag(DEFAULT_DEFAULT_TAG, json);
- }
-
- public static void xml(String xml) {
- xmlTag(DEFAULT_DEFAULT_TAG, xml);
- }
-
- // -- 日志打印方法 --
-
- public static void dTag(String tag, String message, Object... args) {
- if (JUDGE_PRINT_LOG){
- printLog(Log.DEBUG, tag, createMessage(message, args));
- }
- }
-
- public static void eTag(String tag, String message, Object... args) {
- if(JUDGE_PRINT_LOG){
- printLog(Log.ERROR, tag, createMessage(message, args));
- }
- }
-
- public static void eTag(String tag, Throwable throwable) {
- if(JUDGE_PRINT_LOG){
- printLog(Log.ERROR, tag, splitErrorMessage(throwable, null));
- }
- }
-
- public static void eTag(String tag, Throwable throwable, String message, Object... args) {
- if(JUDGE_PRINT_LOG){
- printLog(Log.ERROR, tag, splitErrorMessage(throwable, message, args));
- }
- }
-
- public static void wTag(String tag, String message, Object... args) {
- if(JUDGE_PRINT_LOG){
- printLog(Log.WARN, tag, createMessage(message, args));
- }
- }
-
- public static void iTag(String tag, String message, Object... args) {
- if(JUDGE_PRINT_LOG){
- printLog(Log.INFO, tag, createMessage(message, args));
- }
- }
-
- public static void vTag(String tag, String message, Object... args) {
- if(JUDGE_PRINT_LOG){
- printLog(Log.VERBOSE, tag, createMessage(message, args));
- }
- }
-
- public static void wtfTag(String tag, String message, Object... args) {
- if(JUDGE_PRINT_LOG){
- printLog(Log.ASSERT, tag, createMessage(message, args));
- }
- }
-
- public static void jsonTag(String tag, String json) {
- if (JUDGE_PRINT_LOG){
- // 判断传入JSON格式信息是否为null
- if (TextUtils.isEmpty(json)) {
- printLog(Log.ERROR, tag, "Empty/Null json content");
- return;
- }
- try {
- // 属于对象的JSON格式信息
- if (json.startsWith("{")) {
- JSONObject jsonObject = new JSONObject(json);
- // 进行缩进
- String message = jsonObject.toString(JSON_INDENT);
- // 打印信息
- printLog(Log.DEBUG, tag, message);
- } else if (json.startsWith("[")) {
- // 属于数据的JSON格式信息
- JSONArray jsonArray = new JSONArray(json);
- // 进行缩进
- String message = jsonArray.toString(JSON_INDENT);
- // 打印信息
- printLog(Log.DEBUG, tag, message);
- }
- } catch (Exception e) {
- String eHint = "null";
- if (e != null){
- Throwable throwable = e.getCause();
- if (throwable != null){
- eHint = throwable.getMessage();
- } else {
- try {
- eHint = e.getMessage();
- } catch (Exception e1){
- eHint = e1.getMessage();
- }
- }
- }
- printLog(Log.ERROR, tag, eHint + "\n" + json);
- }
- }
- }
-
- public static void xmlTag(String tag, String xml) {
- if (JUDGE_PRINT_LOG){
- // 判断传入XML格式信息是否为null
- if (TextUtils.isEmpty(xml)) {
- printLog(Log.ERROR, tag, "Empty/Null xml content");
- return;
- }
- try {
- Source xmlInput = new StreamSource(new StringReader(xml));
- StreamResult xmlOutput = new StreamResult(new StringWriter());
- Transformer transformer = TransformerFactory.newInstance().newTransformer();
- transformer.setOutputProperty(OutputKeys.INDENT, "yes");
- transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
- transformer.transform(xmlInput, xmlOutput);
- // 获取打印消息
- String message = xmlOutput.getWriter().toString().replaceFirst(">", ">\n");
- // 打印信息
- printLog(Log.DEBUG, tag, message);
- } catch (Exception e) {
- String eHint = "null";
- if (e != null){
- Throwable throwable = e.getCause();
- if (throwable != null){
- eHint = throwable.getMessage();
- } else {
- try {
- eHint = e.getMessage();
- } catch (Exception e1){
- eHint = e1.getMessage();
- }
- }
- }
- printLog(Log.ERROR, tag, eHint + "\n" + xml);
- }
- }
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/AccessibilityUtils.java b/DevLibUtils/src/main/java/dev/utils/app/AccessibilityUtils.java
deleted file mode 100644
index 5f81c2ae9a..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/AccessibilityUtils.java
+++ /dev/null
@@ -1,246 +0,0 @@
-package dev.utils.app;
-
-import android.accessibilityservice.AccessibilityService;
-import android.content.Intent;
-import android.provider.Settings;
-import android.view.accessibility.AccessibilityEvent;
-import android.view.accessibility.AccessibilityNodeInfo;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import dev.DevUtils;
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: 无障碍功能工具类
- * Created by Ttt
- * https://www.jianshu.com/p/981e7de2c7be
- * https://www.jianshu.com/p/65afab3d1e2a
- * https://www.jianshu.com/p/f67e950d84f7
- * https://blog.csdn.net/nishitouzhuma/article/details/51584606
- * https://blog.csdn.net/jw_66666/article/details/76571897
- * https://blog.csdn.net/dd864140130/article/details/51794318
- * ====
- * AccessibilityService 在 API < 18 的时候使用 AccessibilityService
- *
- */
-public final class AccessibilityUtils {
-
- private AccessibilityUtils() {
- }
-
- // 日志TAG
- private static final String TAG = AccessibilityUtils.class.getSimpleName();
-
- /**
- * 检查是否开启无障碍功能
- * @return
- */
- public static boolean checkAccessibility(){
- return checkAccessibility(DevUtils.getContext().getPackageName());
- }
-
- /**
- * 检查是否开启无障碍功能
- * @param pkgName
- * @return
- */
- public static boolean checkAccessibility(String pkgName) {
- // 判断辅助功能是否开启
- if (!AccessibilityUtils.isAccessibilitySettingsOn(pkgName)) {
- // 引导至辅助功能设置页面
- DevUtils.getContext().startActivity(new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
- return false;
- }
- return true;
- }
-
- /**
- * 判断是否开启无障碍功能
- * @param pkgName
- * @return
- */
- public static boolean isAccessibilitySettingsOn(String pkgName) {
- int accessibilityEnabled = 0;
- try {
- accessibilityEnabled = Settings.Secure.getInt(DevUtils.getContext().getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED);
- } catch (Settings.SettingNotFoundException e) {
- LogPrintUtils.eTag(TAG, e, "isAccessibilitySettingsOn - Settings.Secure.ACCESSIBILITY_ENABLED");
- }
- if (accessibilityEnabled == 1) {
- try {
- String services = Settings.Secure.getString(DevUtils.getContext().getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
- if (services != null) {
- return services.toLowerCase().contains(pkgName.toLowerCase());
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "isAccessibilitySettingsOn - Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES");
- }
- }
- return false;
- }
-
- // == 快捷方法 ==
-
- /**
- * 打印Event 日志
- * @param event
- */
- public static void printAccessibilityEvent(AccessibilityEvent event){
- printAccessibilityEvent(event, TAG);
- }
-
- /**
- * 打印Event 日志
- * @param event
- * @param tag
- */
- public static void printAccessibilityEvent(AccessibilityEvent event, String tag){
- if (!LogPrintUtils.isPrintLog()){
- return;
- }
- LogPrintUtils.dTag(tag,"-------------------------------------------------------------");
-
- int eventType = event.getEventType();//事件类型
- LogPrintUtils.dTag(tag, "packageName:" + event.getPackageName() + "");//响应事件的包名,也就是哪个应用才响应了这个事件
- LogPrintUtils.dTag(tag, "source:" + event.getSource() + "");//事件源信息
- LogPrintUtils.dTag(tag, "source class:" + event.getClassName() + "");//事件源的类名,比如android.widget.TextView
- LogPrintUtils.dTag(tag, "event type(int):" + eventType + "");
-
- switch (eventType) {
- case AccessibilityEvent.TYPE_NOTIFICATION_STATE_CHANGED:// 通知栏事件
- LogPrintUtils.dTag(tag, "event type:TYPE_NOTIFICATION_STATE_CHANGED");
- break;
- case AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED://窗体状态改变
- LogPrintUtils.dTag(tag, "event type:TYPE_WINDOW_STATE_CHANGED");
- break;
- case AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUSED://View获取到焦点
- LogPrintUtils.dTag(tag, "event type:TYPE_VIEW_ACCESSIBILITY_FOCUSED");
- break;
- case AccessibilityEvent.TYPE_GESTURE_DETECTION_START:
- LogPrintUtils.dTag(tag, "event type:TYPE_VIEW_ACCESSIBILITY_FOCUSED");
- break;
- case AccessibilityEvent.TYPE_GESTURE_DETECTION_END:
- LogPrintUtils.dTag(tag, "event type:TYPE_GESTURE_DETECTION_END");
- break;
- case AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED:
- LogPrintUtils.dTag(tag, "event type:TYPE_WINDOW_CONTENT_CHANGED");
- break;
- case AccessibilityEvent.TYPE_VIEW_CLICKED:
- LogPrintUtils.dTag(tag, "event type:TYPE_VIEW_CLICKED");
- break;
- case AccessibilityEvent.TYPE_VIEW_TEXT_CHANGED:
- LogPrintUtils.dTag(tag, "event type:TYPE_VIEW_TEXT_CHANGED");
- break;
- case AccessibilityEvent.TYPE_VIEW_SCROLLED:
- LogPrintUtils.dTag(tag, "event type:TYPE_VIEW_SCROLLED");
- break;
- case AccessibilityEvent.TYPE_VIEW_TEXT_SELECTION_CHANGED:
- LogPrintUtils.dTag(tag, "event type:TYPE_VIEW_TEXT_SELECTION_CHANGED");
- break;
- }
-
- for (CharSequence txt : event.getText()) {
- LogPrintUtils.dTag(tag, "text:" + txt);//输出当前事件包含的文本信息
- }
- LogPrintUtils.dTag(tag, "-------------------------------------------------------------");
- }
-
- // === 其他处理 ===
-
- /**
- * 查找符合条件的节点
- * @param service
- * @param text
- * @return
- */
- private List findAccessibilityNodeInfosByText(AccessibilityService service, String text) {
- // 获取根节点
- AccessibilityNodeInfo accessibilityNodeInfo = service.getRootInActiveWindow();
- // 取得当前激活窗体的根节点
- if (accessibilityNodeInfo == null)
- return null;
- // 通过文字找到当前的节点
- return accessibilityNodeInfo.findAccessibilityNodeInfosByText(text);
- }
-
- /**
- * 查找符合条件的节点
- * @param service
- * @param id
- * @return
- */
- private List findAccessibilityNodeInfosByViewId(AccessibilityService service, String id) {
- // 获取根节点
- AccessibilityNodeInfo accessibilityNodeInfo = service.getRootInActiveWindow();
- // 取得当前激活窗体的根节点
- if (accessibilityNodeInfo == null)
- return null;
- // 通过文字找到当前的节点
- return accessibilityNodeInfo.findAccessibilityNodeInfosByViewId(id);
- }
-
- /**
- * 查找符合条件的节点
- * @param service
- * @param text
- * @param claName
- * @return
- */
- private ArrayList findAccessibilityNodeInfosByText(AccessibilityService service, String text, String claName) {
- ArrayList lists = new ArrayList<>();
- // 获取根节点
- AccessibilityNodeInfo accessibilityNodeInfo = service.getRootInActiveWindow();
- // 取得当前激活窗体的根节点
- if (accessibilityNodeInfo == null)
- return lists;
- // 通过文字找到当前的节点
- List nodes = accessibilityNodeInfo.findAccessibilityNodeInfosByText(text);
- for (int i = 0; i < nodes.size(); i++) {
- AccessibilityNodeInfo node = nodes.get(i);
- // 判断是否符合的类型
- if (node.getClassName().equals(claName) && node.isEnabled()) {
- // 保存符合条件
- lists.add(node);
- }
- }
- return lists;
- }
-
-// //获取根节点
-// AccessibilityNodeInfo rootNode = getRootInActiveWindow();
-// //匹配Text获取节点
-// List list1 = rootNode.findAccessibilityNodeInfosByText("match_text");
-// //匹配id获取节点
-// List list2 = rootNode.findAccessibilityNodeInfosByViewId("match_id");
-// //获取子节点
-// AccessibilityNodeInfo infoNode = rootNode.getChild(index);
-
-// //模拟点击事件
-// target.performAction(AccessibilityNodeInfo.ACTION_CLICK);
-// //模拟输入内容
-// ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
-// ClipData clip = ClipData.newPlainText("label", "");
-// clipboard.setPrimaryClip(clip);
-// target.performAction(AccessibilityNodeInfo.ACTION_PASTE);
-
-// //后退键
-// performGlobalAction(AccessibilityService.GLOBAL_ACTION_BACK);
-// //Home键
-// performGlobalAction(AccessibilityService.GLOBAL_ACTION_HOME);
-// //模拟左滑
-// performGlobalAction(AccessibilityService.GESTURE_SWIPE_LEFT);
-
-
-// disableSelf() 禁用当前服务,也就是在服务可以通过该方法停止运行
-// findFoucs(int falg) 查找拥有特定焦点类型的控件
-// getRootInActiveWindow() 如果配置能够获取窗口内容,则会返回当前活动窗口的根结点
-// getSeviceInfo() 获取当前服务的配置信息
-// onAccessibilityEvent(AccessibilityEvent event) 有关AccessibilityEvent事件的回调函数.系统通过sendAccessibiliyEvent()不断的发送AccessibilityEvent到此处
-// performGlobalAction(int action) 执行全局操作,比如返回,回到主页,打开最近等操作
-// setServiceInfo(AccessibilityServiceInfo info) 设置当前服务的配置信息
-// getSystemService(String name) 获取系统服务
-// onKeyEvent(KeyEvent event) 如果允许服务监听按键操作,该方法是按键事件的回调,需要注意,这个过程发生了系统处理按键事件之前
-// onServiceConnected() 系统成功绑定该服务时被触发,也就是当你在设置中开启相应的服务,系统成功的绑定了该服务时会触发,通常我们可以在这里做一些初始化操作
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/ActivityUtils.java b/DevLibUtils/src/main/java/dev/utils/app/ActivityUtils.java
deleted file mode 100644
index 45d88a48bd..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/ActivityUtils.java
+++ /dev/null
@@ -1,178 +0,0 @@
-package dev.utils.app;
-
-import android.app.Activity;
-import android.content.ComponentName;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.graphics.drawable.Drawable;
-import android.os.Build;
-import android.os.Bundle;
-import android.support.annotation.NonNull;
-import android.support.v4.app.ActivityOptionsCompat;
-import android.support.v4.util.Pair;
-import android.view.View;
-
-import java.util.List;
-
-import dev.DevUtils;
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: Acitivty 工具类
- * Created by Ttt
- */
-public final class ActivityUtils {
-
- private ActivityUtils() {
- }
-
- // 日志TAG
- private static final String TAG = ActivityUtils.class.getSimpleName();
-
- /**
- * 判断是否存在指定的Activity
- * @param context 上下文
- * @param packageName 包名
- * @param className activity全路径类名
- * @return
- */
- public static boolean isActivityExists(Context context, String packageName, String className) {
- boolean result = true;
- try {
- Intent intent = new Intent();
- intent.setClassName(packageName, className);
- if (context.getPackageManager().resolveActivity(intent, 0) == null) {
- result = false;
- } else if (intent.resolveActivity(context.getPackageManager()) == null) {
- result = false;
- } else {
- List list = context.getPackageManager().queryIntentActivities(intent, 0);
- if (list.size() == 0) {
- result = false;
- }
- }
- } catch (Exception e){
- result = false;
- LogPrintUtils.eTag(TAG, e, "isActivityExists");
- }
- return result;
- }
-
- /**
- * 回到桌面 -> 同点击Home键效果
- */
- public static void startHomeActivity() {
- Intent homeIntent = new Intent(Intent.ACTION_MAIN);
- homeIntent.addCategory(Intent.CATEGORY_HOME);
- DevUtils.getContext().startActivity(homeIntent);
- }
-
- /**
- * 跳转到桌面
- * @return
- */
- public static String getLauncherActivity() {
- return getLauncherActivity(DevUtils.getContext().getPackageName());
- }
-
- /**
- * 跳转到桌面
- * @param pkg
- * @return
- */
- public static String getLauncherActivity(@NonNull final String pkg) {
- Intent intent = new Intent(Intent.ACTION_MAIN, null);
- intent.addCategory(Intent.CATEGORY_LAUNCHER);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- PackageManager pm = DevUtils.getContext().getPackageManager();
- List info = pm.queryIntentActivities(intent, 0);
- for (ResolveInfo aInfo : info) {
- if (aInfo.activityInfo.packageName.equals(pkg)) {
- return aInfo.activityInfo.name;
- }
- }
- return null;
- }
-
- /**
- * 返回Activity 对应的图标
- * @param clz
- * @return
- */
- public static Drawable getActivityIcon(final Class> clz) {
- return getActivityIcon(new ComponentName(DevUtils.getContext(), clz));
- }
-
- /**
- * 返回Activity 对应的图标
- * @param activityName
- * @return
- */
- public static Drawable getActivityIcon(final ComponentName activityName) {
- try {
- return DevUtils.getContext().getPackageManager().getActivityIcon(activityName);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getActivityIcon");
- return null;
- }
- }
-
- /**
- * 返回Activity 对应的Logo
- * @param clz
- * @return
- */
- public static Drawable getActivityLogo(final Class> clz) {
- return getActivityLogo(new ComponentName(DevUtils.getContext(), clz));
- }
-
- /**
- * 返回Activity 对应的Logo
- * @param activityName
- * @return
- */
- public static Drawable getActivityLogo(final ComponentName activityName) {
- try {
- return DevUtils.getContext().getPackageManager().getActivityLogo(activityName);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getActivityLogo");
- return null;
- }
- }
-
- // == 以下方法使用介绍 ==
- // https://www.cnblogs.com/tianzhijiexian/p/4087917.html
- // ActivityOptionsCompat.makeScaleUpAnimation(source, startX, startY, startWidth, startHeight)
-
- /**
- * 设置跳转动画
- * @param context
- * @param enterAnim
- * @param exitAnim
- * @return
- */
- private static Bundle getOptionsBundle(final Context context, final int enterAnim, final int exitAnim) {
- return ActivityOptionsCompat.makeCustomAnimation(context, enterAnim, exitAnim).toBundle();
- }
-
- /**
- * 设置跳转动画
- * @param activity
- * @param sharedElements
- * @return
- */
- private static Bundle getOptionsBundle(final Activity activity, final View[] sharedElements) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- int len = sharedElements.length;
- @SuppressWarnings("unchecked")
- Pair[] pairs = new Pair[len];
- for (int i = 0; i < len; i++) {
- pairs[i] = Pair.create(sharedElements[i], sharedElements[i].getTransitionName());
- }
- return ActivityOptionsCompat.makeSceneTransitionAnimation(activity, pairs).toBundle();
- }
- return ActivityOptionsCompat.makeSceneTransitionAnimation(activity, null, null).toBundle();
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/AlarmUtils.java b/DevLibUtils/src/main/java/dev/utils/app/AlarmUtils.java
deleted file mode 100644
index 672d675e5a..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/AlarmUtils.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package dev.utils.app;
-
-import android.annotation.TargetApi;
-import android.app.AlarmManager;
-import android.app.PendingIntent;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Build;
-
-/**
- * detail: AlarmManager (全局定时器/闹钟)指定时长或以周期形式执行某项操作
- * @author MaTianyu
- * https://www.cnblogs.com/zyw-205520/p/4040923.html
- */
-public final class AlarmUtils {
-
- private AlarmUtils(){
- }
-
- /**
- * 开启定时器
- */
- @TargetApi(Build.VERSION_CODES.CUPCAKE)
- public static void startAlarmIntent(Context context, int triggerAtMillis, PendingIntent pendingIntent) {
- AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
- manager.set(AlarmManager.RTC_WAKEUP,triggerAtMillis, pendingIntent);
- }
-
- /**
- * 关闭定时器
- */
- @TargetApi(Build.VERSION_CODES.CUPCAKE)
- public static void stopAlarmIntent(Context context, PendingIntent pendingIntent) {
- AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
- manager.cancel(pendingIntent);
- }
-
- /**
- * 开启轮询服务
- */
- @TargetApi(Build.VERSION_CODES.CUPCAKE)
- public static void startAlarmService(Context context, int triggerAtMillis, Class> cls, String action) {
- Intent intent = new Intent(context, cls);
- intent.setAction(action);
- PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
- startAlarmIntent(context, triggerAtMillis,pendingIntent);
- }
-
- /**
- * 停止启轮询服务
- */
- @TargetApi(Build.VERSION_CODES.CUPCAKE)
- public static void stopAlarmService(Context context, Class> cls, String action) {
- Intent intent = new Intent(context, cls);
- intent.setAction(action);
- PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
- stopAlarmIntent(context, pendingIntent);
- }
-
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/AnalysisRecordUtils.java b/DevLibUtils/src/main/java/dev/utils/app/AnalysisRecordUtils.java
deleted file mode 100644
index 7488589a10..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/AnalysisRecordUtils.java
+++ /dev/null
@@ -1,706 +0,0 @@
-package dev.utils.app;
-
-import android.content.Context;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.os.Build;
-import android.os.Environment;
-import android.support.annotation.IntDef;
-import android.text.TextUtils;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.reflect.Field;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: 分析记录工具类
- * Created by Ttt
- */
-public final class AnalysisRecordUtils {
-
- private AnalysisRecordUtils() {
- }
-
- // 日志TAG
- private static final String TAG = AnalysisRecordUtils.class.getSimpleName();
-
- // 上下文
- private static Context sContext;
- // 日志文件夹名字(目录名)
- private static String logFolderName = "LogRecord";
- // 日志存储路径
- private static String logStoragePath;
- // 是否处理保存
- private static boolean isHandler = true;
-
- /**
- * 初始化操作
- * @param context
- */
- public static void init(Context context) {
- if (context != null) {
- sContext = context.getApplicationContext();
- }
- // 初始化设备信息
- getDeviceInfo();
- // 初始化 App 信息
- getAppInfo();
- // 如果为null, 才设置
- if (TextUtils.isEmpty(logStoragePath)){
- // 获取根路径
- logStoragePath = FileInfo.getDiskCacheDir(sContext);
- }
- }
-
- // === 对外提供方法 ===
-
- /**
- * 日志记录
- * @param fileInfo
- * @param args
- * @return log 直接打印
- */
- public static String record(FileInfo fileInfo, String... args) {
- // 如果不处理, 则直接跳过
- if (!isHandler){
- return "record not handler";
- }
- if (fileInfo != null) {
- if (args != null && args.length != 0) {
- return saveLogRecord(fileInfo, args);
- }
- // 无数据记录
- return "no data record";
- }
- // 信息为null
- return "info is null";
- }
-
- /**
- * 是否处理日志记录
- * @return
- */
- public static boolean isHandler() {
- return isHandler;
- }
-
- /**
- * 设置是否处理日志记录
- * @param isHandler
- */
- public static void setHandler(boolean isHandler) {
- AnalysisRecordUtils.isHandler = isHandler;
- }
-
- /**
- * 获取文件日志名
- * @return
- */
- public static String getLogFolderName() {
- return logFolderName;
- }
-
- /**
- * 设置日志文件夹名
- * @param logFolderName
- */
- public static void setLogFolderName(String logFolderName) {
- AnalysisRecordUtils.logFolderName = logFolderName;
- }
-
- /**
- * 获取日志存储路径
- * @return
- */
- public static String getLogStoragePath() {
- return logStoragePath;
- }
-
- /**
- * 设置日志存储路径
- * @param logStoragePath
- */
- public static void setLogStoragePath(String logStoragePath) {
- AnalysisRecordUtils.logStoragePath = logStoragePath;
- }
-
- // ===== 内部方法 =====
-
- /**
- * 最终保存方法
- * @param fileInfo
- * @param args
- */
- private static String saveLogRecord(FileInfo fileInfo, String... args) {
- // 如果不处理, 则直接跳过
- if (!isHandler){
- return "record not handler";
- }
- // 文件信息为null, 则不处理
- if (fileInfo == null){
- return "info is null";
- }
- // 如果文件地址为null, 则不处理
- if (TextUtils.isEmpty(fileInfo.getFileName())){
- // 文件名为null
- return "fileName is null";
- }
- // 获取文件名
- String fName = fileInfo.getFileName();
- // 获取文件提示
- String fHint = fileInfo.getFileFunction();
- try {
- // 获取处理的日志
- String logContent = splitLog(args);
- // 日志保存路径
- String logPath = fileInfo.getLogPath();
- // 获取日志地址
- String logFile = logPath + File.separator + fName;
- // 返回地址
- File file = new File(logFile);
- // 判断是否存在
- if (file.exists()) {
- // 追加内容
- appendFile(logFile, logContent);
- } else {
- // ==== 首次则保存设备、App 信息 ====
- StringBuffer sBuffer = new StringBuffer();
- sBuffer.append("【设备信息】");
- sBuffer.append(NEW_LINE_STR);
- sBuffer.append("===========================");
- sBuffer.append(NEW_LINE_STR);
- sBuffer.append(getDeviceInfo());
- sBuffer.append("===========================");
- sBuffer.append(NEW_LINE_STR);
-
- sBuffer.append(NEW_LINE_STR);
- sBuffer.append(NEW_LINE_STR);
- sBuffer.append("【版本信息】");
- sBuffer.append(NEW_LINE_STR);
- sBuffer.append("===========================");
- sBuffer.append(NEW_LINE_STR);
- sBuffer.append(getAppInfo());
- sBuffer.append(NEW_LINE_STR);
- sBuffer.append("===========================");
- sBuffer.append(NEW_LINE_STR);
-
- sBuffer.append(NEW_LINE_STR);
- sBuffer.append(NEW_LINE_STR);
- sBuffer.append("【文件信息】");
- sBuffer.append(NEW_LINE_STR);
- sBuffer.append("===========================");
- sBuffer.append(NEW_LINE_STR);
- sBuffer.append(fHint);
- sBuffer.append(NEW_LINE_STR);
- sBuffer.append("===========================");
- sBuffer.append(NEW_LINE_STR);
- // 创建文件夹,并且进行处理
- saveFile(sBuffer.toString(), logPath, fName);
- // 追加内容
- appendFile(logFile, logContent);
- }
- // 返回打印日志
- return logContent;
- } catch (Exception ignore) {
- // 捕获异常
- return "catch error";
- }
- }
-
- /**
- * 拼接日志
- * @param args
- * @return
- */
- private static String splitLog(String... args) {
- StringBuffer sBuffer = new StringBuffer();
- // 增加换行
- sBuffer.append(NEW_LINE_STR);
- sBuffer.append(NEW_LINE_STR);
- // 获取保存时间
- sBuffer.append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
- // 追加个边距
- sBuffer.append(" => ");
- // 循环追加内容
- for (int i = 0, c = args.length; i < c; i++) {
- // 追加保存内容
- sBuffer.append(args[i]);
- }
- return sBuffer.toString();
- }
-
- // === 设备信息统计 ====
-
- // app 信息
- private static String APP_INFO_STR = null;
- // 设备信息
- private static String DEVICE_INFO_STR = null;
- // 用来存储设备信息
- private static HashMap DEVICE_INFO_MAPS = new HashMap<>();
- // 换行字符串
- private static final String NEW_LINE_STR = System.getProperty("line.separator");
-
- /**
- * 获取设备信息
- * @return
- */
- private static String getDeviceInfo() {
- if (DEVICE_INFO_STR != null) {
- return DEVICE_INFO_STR;
- }
- // 获取设备信息
- getDeviceInfo(DEVICE_INFO_MAPS);
- // 转换设备信息
- handleDeviceInfo("获取设备信息失败");
- // 返回设备信息
- return DEVICE_INFO_STR;
- }
-
- /**
- * 获取设备信息
- * @param dInfoMaps 传入设备信息传出HashMap
- */
- private static void getDeviceInfo(HashMap dInfoMaps) {
- // 获取设备信息类的所有申明的字段,即包括public、private和proteced, 但是不包括父类的申明字段。
- Field[] fields = Build.class.getDeclaredFields();
- // 遍历字段
- for (Field field : fields) {
- try {
- // 取消java的权限控制检查
- field.setAccessible(true);
- // 获取类型对应字段的数据,并保存
- dInfoMaps.put(field.getName(), field.get(null).toString());
- } catch (Exception e) {
- }
- }
- }
-
- /**
- * 处理设备信息
- * @param eHint 错误提示,如获取设备信息失败
- */
- private static String handleDeviceInfo(String eHint) {
- try {
- // 如果不为null,则直接返回之前的信息
- if (!TextUtils.isEmpty(DEVICE_INFO_STR)) {
- return DEVICE_INFO_STR;
- }
- // 初始化 StringBuffer,拼接字符串
- StringBuffer sBuffer = new StringBuffer();
- // 获取设备信息
- Iterator> mapIter = DEVICE_INFO_MAPS.entrySet().iterator();
- // 遍历设备信息
- while (mapIter.hasNext()) {
- // 获取对应的key-value
- Map.Entry rnEntry = mapIter.next();
- String rnKey = rnEntry.getKey(); // key
- String rnValue = rnEntry.getValue(); // value
- // 保存设备信息
- sBuffer.append(rnKey);
- sBuffer.append(" = ");
- sBuffer.append(rnValue);
- sBuffer.append(NEW_LINE_STR);
- }
- // 保存设备信息
- DEVICE_INFO_STR = sBuffer.toString();
- // 返回设备信息
- return DEVICE_INFO_STR;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "handleDeviceInfo");
- }
- return eHint;
- }
-
- /**
- * 获取app 信息
- * @return
- */
- private static String getAppInfo() {
- // 如果不为null,则直接返回之前的信息
- if (!TextUtils.isEmpty(APP_INFO_STR)) {
- return APP_INFO_STR;
- }
- try {
- StringBuffer sBuffer = new StringBuffer();
- // -
- PackageManager pm = sContext.getPackageManager();
- PackageInfo pi = pm.getPackageInfo(sContext.getPackageName(), PackageManager.GET_ACTIVITIES);
- if (pi != null) {
- String versionName = pi.versionName == null ? "null" : pi.versionName;
- String versionCode = pi.versionCode + "";
- // 保存版本信息
- sBuffer.append("versionName: " + versionName);
- sBuffer.append("\nversionCode: " + versionCode);
- // 保存其他信息
- sBuffer.append("\npackageName: " + pi.packageName); // 保存包名
- // 赋值版本信息
- APP_INFO_STR = sBuffer.toString();
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getAppInfo");
- }
- return APP_INFO_STR;
- }
-
- // == 日志保存时间 ==
- // DEFAULT - 默认天,在根目录下
- public static final int DEFAULT = 0;
- // 小时
- public static final int HH = 1;
- // 分钟
- public static final int MM = 2;
- // 秒
- public static final int SS = 3;
-
- //用 @IntDef "包住" 常量;
- // @Retention 定义策略
- // 声明构造器
- @IntDef({ DEFAULT, HH, MM, SS})
- @Retention(RetentionPolicy.SOURCE)
- public @interface TIME {}
-
- /**
- * detail: 记录文件信息实体类
- * Created by Ttt
- */
- public static class FileInfo {
-
- // 存储路径
- private String storagePath;
-
- // 文件夹名
- private String folderName;
-
- // 文件名 如: xxx.txt
- private String fileName;
-
- // 文件记录的功能
- private String fileFunction;
-
- // 文件记录间隔时间 如: HH
- private @TIME int fileIntervalTime = DEFAULT;
-
- // = 构造函数 =
-
- private FileInfo(String storagePath, String folderName, String fileName, String fileFunction, @TIME int fileIntervalTime) {
- this.storagePath = storagePath;
- this.folderName = folderName;
- this.fileName = fileName;
- this.fileFunction = fileFunction;
- this.fileIntervalTime = fileIntervalTime;
- }
-
- // = get/set 方法 =
-
- public String getStoragePath() {
- if (TextUtils.isEmpty(storagePath)){
- return storagePath = getLogStoragePath();
- }
- return storagePath;
- }
-
- public String getFileName() {
- return fileName;
- }
-
- public String getFileFunction() {
- return fileFunction;
- }
-
- public int getFileIntervalTime() {
- return fileIntervalTime;
- }
-
- public String getFolderName(){
- if (TextUtils.isEmpty(folderName)){
- return folderName = getLogFolderName();
- }
- return folderName;
- }
-
- /**
- * 获取记录分析文件信息
- * @param fileName
- * @param fileFunction
- * @return
- */
- public static FileInfo obtain(String fileName, String fileFunction) {
- return new FileInfo(null, null, fileName, fileFunction, DEFAULT);
- }
-
- /**
- * 获取记录分析文件信息
- * @param folderName
- * @param fileName
- * @param fileFunction
- * @return
- */
- public static FileInfo obtain(String folderName, String fileName, String fileFunction) {
- return new FileInfo(null, folderName, fileName, fileFunction, DEFAULT);
- }
-
- /**
- * 获取记录分析文件信息
- * @param storagePath
- * @param folderName
- * @param fileName
- * @param fileFunction
- * @return
- */
- public static FileInfo obtain(String storagePath, String folderName, String fileName, String fileFunction) {
- return new FileInfo(storagePath, folderName, fileName, fileFunction, DEFAULT);
- }
-
- // ==
-
- /**
- * 获取记录分析文件信息
- * @param fileName
- * @param fileFunction
- * @param fileIntervalTime
- * @return
- */
- public static FileInfo obtain(String fileName, String fileFunction, @TIME int fileIntervalTime) {
- return new FileInfo(null, null, fileName, fileFunction, fileIntervalTime);
- }
-
- /**
- * 获取记录分析文件信息
- * @param folderName
- * @param fileName
- * @param fileFunction
- * @param fileIntervalTime
- * @return
- */
- public static FileInfo obtain(String folderName, String fileName, String fileFunction, @TIME int fileIntervalTime) {
- return new FileInfo(null, folderName, fileName, fileFunction, fileIntervalTime);
- }
-
- /**
- * 获取记录分析文件信息
- * @param storagePath
- * @param folderName
- * @param fileName
- * @param fileFunction
- * @param fileIntervalTime
- * @return
- */
- public static FileInfo obtain(String storagePath, String folderName, String fileName, String fileFunction, @TIME int fileIntervalTime) {
- return new FileInfo(storagePath, folderName, fileName, fileFunction, fileIntervalTime);
- }
-
- // = 内部处理方法 =
-
- /**
- * 获取日志地址
- * @return
- */
- public String getLogPath() {
- // 返回拼接后的路径
- return getSavePath(getStoragePath(), logFolderName + File.separator + getDateNow("yyyy_MM_dd")) + getIntervalTimeFolder();
- }
-
- /**
- * 获取时间间隔 - 文件夹
- * @return
- */
- public String getIntervalTimeFolder() {
- // 文件夹
- String folder = File.separator + getFolderName() + File.separator;
- // 获取间隔时间
- int iTime = getFileIntervalTime();
- // 进行判断
- switch (iTime) {
- case DEFAULT:
- return folder;
- case HH:
- case MM:
- case SS:
- // 小时格式
- String hh_Foramt = getDateNow("HH");
- // 判断属于小时格式
- if (iTime == HH){
- // /folder/HH/HH_小时/ => /LogSpace/HH/HH_15/
- return folder + "HH/HH_" + hh_Foramt + File.separator;
- } else {
- // 分钟格式
- String mm_Foramt = getDateNow("mm");
- // 判断是否属于分钟
- if (iTime == MM){
- // /folder/HH/HH_小时/MM_分钟/ => /LogSpace/HH/HH_15/MM/MM_55/
- return folder + "HH/HH_" + hh_Foramt + "/MM/MM_" + mm_Foramt + File.separator;
- } else { // 属于秒
- // 秒格式
- String ss_Foramt = getDateNow("ss");
- // /folder/HH/HH_小时/MM_分钟/ => /LogSpace/HH/HH_15/MM/MM_55/SS_12/
- return folder + "HH/HH_" + hh_Foramt + "/MM/MM_" + mm_Foramt + "/SS_" + ss_Foramt + File.separator;
- }
- }
- }
- // 放到未知目录下
- return "/Unknown/";
- }
-
- /**
- * 获取当前日期的字符串
- * @param format 日期格式,譬如:HH, mm, ss
- * @return 字符串
- */
- private String getDateNow(String format) {
- try {
- Calendar cld = Calendar.getInstance();
- DateFormat df = new SimpleDateFormat(format);
- return df.format(cld.getTime());
- } catch (Exception e) {
- }
- return null;
- }
-
- // -
-
- /**
- * 获取保存地址
- * @param storagePath 存储路径
- * @param fPath 文件地址
- * @return
- */
- private String getSavePath(String storagePath, String fPath) {
- // 获取保存地址
- File file = new File(storagePath, fPath);
- // 防止不存在目录文件,自动创建
- createFolder(file);
- // 返回头像地址
- return file.getAbsolutePath();
- }
-
- /**
- * 获取缓存地址
- * @return
- */
- private static String getDiskCacheDir(Context context) {
- String cachePath;
- // 判断SDCard是否挂载
- if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
- cachePath = context.getExternalCacheDir().getPath();
- } else {
- cachePath = context.getCacheDir().getPath();
- }
- // 防止不存在目录文件,自动创建
- createFolder(new File(cachePath));
- // 返回文件存储地址
- return cachePath;
- }
-
- /**
- * 判断某个文件夹是否创建,未创建则创建(纯路径 - 无文件名)
- * @param file 文件夹路径 (无文件名字.后缀)
- */
- private static boolean createFolder(final File file) {
- if (file != null) {
- try {
- // 当这个文件夹不存在的时候则创建文件夹
- if (!file.exists()) {
- // 允许创建多级目录
- return file.mkdirs();
- // 这个无法创建多级目录
- // rootFile.mkdir();
- }
- return true;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "createFolder");
- }
- }
- return false;
- }
- }
-
- // = 内部处理方法 =
-
- /**
- * 追加文件:使用FileWriter
- * @param fPath 文件地址
- * @param text 追加内容
- */
- private static void appendFile(String fPath, String text) {
- if (fPath == null || text == null) {
- return;
- }
- File file = new File(fPath);
- if (!file.exists()) { // 如果文件不存在,则跳过
- return;
- }
- FileWriter writer = null;
- try {
- // 打开一个写文件器,构造函数中的第二个参数true表示以追加形式写文件
- writer = new FileWriter(file, true);
- writer.write(text);
- } catch (IOException e) {
- LogPrintUtils.eTag(TAG, e, "appendFile");
- } finally {
- if (writer != null) {
- try {
- writer.close();
- } catch (IOException e) {
- }
- }
- }
- }
-
- /**
- * 保存文件
- * @param txt 保存内容
- * @param fPath 保存路径
- * @param fName 文件名.后缀
- * @return 是否保存成功
- */
- private static boolean saveFile(String txt, String fPath, String fName) {
- try {
- // 防止文件没创建
- createFile(fPath);
- // 保存路径
- File sFile = new File(fPath, fName);
- // 保存内容到一个文件
- FileOutputStream fos = new FileOutputStream(sFile);
- fos.write(txt.getBytes());
- fos.close();
- return true;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "saveFile");
- }
- return false;
- }
-
- /**
- * 判断某个文件夹是否创建,未创建则创建(纯路径 - 无文件名)
- * @param fPath 文件夹路径
- */
- private static File createFile(String fPath) {
- try {
- File file = new File(fPath);
- // 当这个文件夹不存在的时候则创建文件夹
- if(!file.exists()) {
- // 允许创建多级目录
- file.mkdirs();
- // 这个无法创建多级目录
- // rootFile.mkdir();
- }
- return file;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "createFile");
- }
- return null;
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/AppCommonUtils.java b/DevLibUtils/src/main/java/dev/utils/app/AppCommonUtils.java
deleted file mode 100644
index 7b7231c51d..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/AppCommonUtils.java
+++ /dev/null
@@ -1,219 +0,0 @@
-package dev.utils.app;
-
-import android.os.Build;
-
-import java.util.Random;
-import java.util.UUID;
-
-/**
- * detail: App通用工具类
- * Created by Ttt
- */
-public final class AppCommonUtils {
-
- private AppCommonUtils(){
- }
-
- /**
- * 获取设备唯一id
- * @return
- */
- public String getUUID(){
- return PhoneUtils.getUUID();
- }
-
- /**
- * 获取随机数 唯一id
- * @return
- */
- public String getRandomUUID(){
- // 获取随机数
- String random1 = (900000 + new Random().nextInt(10000)) + "";
- // 获取随机数
- String random2 = (900000 + new Random().nextInt(10000)) + "";
- // 获取当前时间
- String cTime = Long.toString(System.currentTimeMillis()) + random1 + random2;
- // 生成唯一随机uuid cTime.hashCode(), random1.hashCode() | random2.hashCode()
- UUID randomUUID = new UUID(cTime.hashCode(), ((long) random1.hashCode() << 32) | random2.hashCode());
- // 获取uid
- return randomUUID.toString();
- }
-
- // == 版本判断处理 ==
-
- /**
- * 是否在2.2版本及以上
- * @return 是否在2.2版本及以上
- */
- public static boolean isFroyo() {
- return Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO;
- }
-
- /**
- * 是否在2.3版本及以上
- * @return 是否在2.3版本及以上
- */
- public static boolean isGingerbread() {
- return Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD;
- }
-
- /**
- * 是否在2.3.3版本及以上
- * @return 是否在2.3.3版本及以上
- */
- public static boolean isGingerbreadMR1() {
- return Build.VERSION.SDK_INT >= Build.VERSION_CODES.GINGERBREAD_MR1;
- }
-
- /**
- * 是否在3.0版本及以上
- * @return 是否在3.0版本及以上
- */
- public static boolean isHoneycomb() {
- return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB;
- }
-
- /**
- * 是否在3.1版本及以上
- * @return 是否在3.1版本及以上
- */
- public static boolean isHoneycombMR1() {
- return Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1;
- }
-
- /**
- * 是否在4.0版本及以上
- * @return 是否在4.0版本及以上
- */
- public static boolean isIceCreamSandwich() {
- return Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH;
- }
-
- /**
- * 是否在4.0.3版本及以上
- * @return 是否在4.0.3版本及以上
- */
- public static boolean isIceCreamSandwichMR1() {
- return Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1;
- }
-
- /**
- * 是否在4.1版本及以上
- * @return 是否在4.1版本及以上
- */
- public static boolean isJellyBean() {
- return Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN;
- }
-
- /**
- * 是否在4.4.2版本及以上
- * @return 是否在4.4.2版本及以上
- */
- public static boolean isKitkat() {
- return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
- }
-
- /**
- * 是否在5.0.1版本及以上
- * @return 是否在5.0.1版本及以上
- */
- public static boolean isLollipop() {
- return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
- }
-
- /**
- * 是否在6.0版本及以上
- * @return 是否在6.0版本及以上
- */
- public static boolean isM(){
- return Build.VERSION.SDK_INT >= Build.VERSION_CODES.M;
- }
-
- /**
- * 是否在7.0版本及以上
- * @return 是否在7.0版本及以上
- */
- public static boolean isN(){
- return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N;
- }
-
- /**
- * 是否在7.1.1版本及以上
- * @return 是否在7.1.1版本及以上
- */
- public static boolean isN_MR1(){
- return Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1;
- }
-
- /**
- * 是否在8.0版本及以上
- * @return 是否在8.0版本及以上
- */
- public static boolean isO(){
- return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
- }
-
- /**
- * 转换SDK版本
- * @param sdkVersion
- * @return
- */
- public static String convertSDKVersion(int sdkVersion){
- // https://www.cnblogs.com/maogefff/p/7819076.html
- switch (sdkVersion){
- case 1:
- return "Android 1.0";
- case 2:
- return "Android 1.1";
- case 3:
- return "Android 1.5";
- case 4:
- return "Android 1.6";
- case 5:
- return "Android 2.0";
- case 6:
- return "Android 2.0.1";
- case 7:
- return "Android 2.1.x";
- case 8:
- return "Android 2.2.x";
- case 9:
- return "Android 2.3.0-2";
- case 10:
- return "Android 2.3.3-4";
- case 11:
- return "Android 3.0.x";
- case 12:
- return "Android 3.1.x";
- case 13:
- return "Android 3.2";
- case 14:
- return "Android 4.0.0-2";
- case 15:
- return "Android 4.0.3-4";
- case 16:
- return "Android 4.1.x";
- case 17:
- return "Android 4.2.x";
- case 18:
- return "Android 4.3";
- case 19:
- return "Android 4.4";
- case 20:
- return "Android 4.4W";
- case 21:
- return "Android 5.0";
- case 22:
- return "Android 5.1";
- case 23:
- return "Android 6.0";
- case 24:
- return "Android 7.0";
- case 25:
- return "Android 7.1.1";
- case 26:
- return "Android 8.0";
- }
- return "unknown";
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/AppUtils.java b/DevLibUtils/src/main/java/dev/utils/app/AppUtils.java
deleted file mode 100644
index ae1b009e28..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/AppUtils.java
+++ /dev/null
@@ -1,970 +0,0 @@
-package dev.utils.app;
-
-import android.annotation.SuppressLint;
-import android.app.Activity;
-import android.app.ActivityManager;
-import android.content.ContentResolver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.content.pm.Signature;
-import android.content.res.AssetManager;
-import android.content.res.ColorStateList;
-import android.content.res.Configuration;
-import android.content.res.Resources;
-import android.graphics.drawable.Drawable;
-import android.net.Uri;
-import android.support.annotation.ColorRes;
-import android.support.annotation.DrawableRes;
-import android.support.annotation.LayoutRes;
-import android.support.annotation.NonNull;
-import android.support.annotation.StringRes;
-import android.support.v4.content.ContextCompat;
-import android.util.DisplayMetrics;
-import android.view.LayoutInflater;
-import android.view.View;
-import android.view.WindowManager;
-
-import java.io.File;
-import java.security.MessageDigest;
-import java.util.List;
-import java.util.Locale;
-
-import dev.DevUtils;
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: App(Android 工具类)
- * Created by Ttt
- */
-public final class AppUtils {
-
- private AppUtils() {
- }
-
- // 日志TAG
- private static final String TAG = AppUtils.class.getSimpleName();
-
- /**
- * 通过上下文获取 WindowManager
- * @return
- */
- public static WindowManager getWindowManager() {
- try {
- return (WindowManager) DevUtils.getContext().getSystemService(Context.WINDOW_SERVICE);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getWindowManager");
- }
- return null;
- }
-
-// /**
-// * 通过上下文获取 DisplayMetrics (获取关于显示的通用信息,如显示大小,分辨率和字体)
-// * @return
-// */
-// public static DisplayMetrics getDisplayMetrics() {
-// try {
-// WindowManager wManager = (WindowManager) DevUtils.getContext().getSystemService(Context.WINDOW_SERVICE);
-// if (wManager != null) {
-// DisplayMetrics dMetrics = new DisplayMetrics();
-// wManager.getDefaultDisplay().getMetrics(dMetrics);
-// return dMetrics;
-// }
-// } catch (Exception e) {
-// LogPrintUtils.eTag(TAG, e, "getDisplayMetrics");
-// }
-// return null;
-// }
-
- /**
- * 获取 Manifest Meta Data
- * @param metaKey
- * @return
- */
- public static String getMetaData(String metaKey) {
- try {
- ApplicationInfo appInfo = DevUtils.getContext().getPackageManager().getApplicationInfo(DevUtils.getContext().getPackageName(), PackageManager.GET_META_DATA);
- String data = appInfo.metaData.getString(metaKey);
- return data;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getMetaData");
- }
- return null;
- }
-
- // == 快捷获取方法 ==
-
- /**
- * 获取View
- * @param resource
- * @return
- */
- public static View getView(@LayoutRes int resource){
- return getView(DevUtils.getContext(), resource);
- }
-
- /**
- * 获取View
- * @param context
- * @param resource
- * @return
- */
- public static View getView(Context context, @LayoutRes int resource){
- try {
- return ((LayoutInflater) DevUtils.getContext(context).getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(resource, null);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getView");
- }
- return null;
- }
-
- public static Resources getResources() {
- try {
- return DevUtils.getContext().getResources();
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getResources");
- }
- return null;
- }
-
- public static String getString(@StringRes int id) {
- try {
- return DevUtils.getContext().getResources().getString(id);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getString");
- }
- return null;
- }
-
- public static Resources.Theme getTheme() {
- try {
- return DevUtils.getContext().getTheme();
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getTheme");
- }
- return null;
- }
-
- public static AssetManager getAssets() {
- try {
- return DevUtils.getContext().getAssets();
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getAssets");
- }
- return null;
- }
-
- public static Drawable getDrawable(@DrawableRes int id) {
- try {
- return ContextCompat.getDrawable(DevUtils.getContext(), id);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getDrawable");
- }
- return null;
- }
-
- public static int getColor( @ColorRes int id) {
- try {
- return ContextCompat.getColor(DevUtils.getContext(), id);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getColor");
- }
- return -1;
- }
-
- public static ColorStateList getColorStateList(int id) {
- try {
- return ContextCompat.getColorStateList(DevUtils.getContext(), id);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getColorStateList");
- }
- return null;
- }
-
- public static T getSystemService(String name){
- try {
- return (T) DevUtils.getContext().getSystemService(name);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getSystemService");
- }
- return null;
- }
-
- public static PackageManager getPackageManager(){
- try {
- return DevUtils.getContext().getPackageManager();
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getPackageManager");
- }
- return null;
- }
-
- public static Configuration getConfiguration() {
- try {
- return DevUtils.getContext().getResources().getConfiguration();
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getConfiguration");
- }
- return null;
- }
-
- public static DisplayMetrics getDisplayMetrics() {
- try {
- return DevUtils.getContext().getResources().getDisplayMetrics();
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getDisplayMetrics");
- }
- return null;
- }
-
- public static ContentResolver getContentResolver() {
- try {
- return DevUtils.getContext().getContentResolver();
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getContentResolver");
- }
- return null;
- }
-
- /**
- * 获取app的图标
- * @return
- */
- public static Drawable getAppIcon() {
- return getAppIcon(DevUtils.getContext().getPackageName());
- }
-
- /**
- * 获取app的图标
- * @param packageName
- * @return
- */
- public static Drawable getAppIcon(final String packageName) {
- if (isSpace(packageName)) return null;
- try {
- PackageManager pm = DevUtils.getContext().getPackageManager();
- PackageInfo pi = pm.getPackageInfo(packageName, 0);
- return pi == null ? null : pi.applicationInfo.loadIcon(pm);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getAppIcon");
- return null;
- }
- }
-
- /**
- * 获取app 包名
- * @return
- */
- public static String getAppPackageName() {
- return DevUtils.getContext().getPackageName();
- }
-
- /**
- * 获取app 名
- * @return
- */
- public static String getAppName() {
- return getAppName(DevUtils.getContext().getPackageName());
- }
-
- /**
- * 获取app 名
- * @param packageName
- * @return
- */
- public static String getAppName(final String packageName) {
- if (isSpace(packageName)) return null;
- try {
- PackageManager pm = DevUtils.getContext().getPackageManager();
- PackageInfo pi = pm.getPackageInfo(packageName, 0);
- return pi == null ? null : pi.applicationInfo.loadLabel(pm).toString();
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getAppName");
- return null;
- }
- }
-
- /**
- * 获取app版本名 - 对外显示
- * @return
- */
- public static String getAppVersionName() {
- return getAppVersionName(DevUtils.getContext().getPackageName());
- }
-
- /**
- * 获取app版本名 - 对外显示
- * @param packageName The name of the package.
- * @return
- */
- public static String getAppVersionName(final String packageName) {
- if (isSpace(packageName)) return null;
- try {
- PackageInfo pi = DevUtils.getContext().getPackageManager().getPackageInfo(packageName, 0);
- return pi == null ? null : pi.versionName;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getAppVersionName");
- return null;
- }
- }
-
- /**
- * 获取app版本号 - 内部判断
- * @return
- */
- public static int getAppVersionCode() {
- return getAppVersionCode(DevUtils.getContext().getPackageName());
- }
-
- /**
- * 获取app版本号 - 内部判断
- * @param packageName The name of the package.
- * @return
- */
- public static int getAppVersionCode(final String packageName) {
- if (isSpace(packageName)) return -1;
- try {
- PackageInfo pi = DevUtils.getContext().getPackageManager().getPackageInfo(packageName, 0);
- return pi == null ? -1 : pi.versionCode;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getAppVersionCode");
- return -1;
- }
- }
-
- // =
-
- /**
- * 对内设置指定语言 (app 多语言,单独改变app语言)
- * @param locale
- */
- public static void setLanguage(Locale locale) {
- try {
- // 获得res资源对象
- Resources resources = DevUtils.getContext().getResources();
- // 获得设置对象
- Configuration config = resources.getConfiguration();
- // 获得屏幕参数:主要是分辨率,像素等。
- DisplayMetrics dm = resources.getDisplayMetrics();
- // 语言
- config.locale = locale;
- // 更新语言
- resources.updateConfiguration(config, dm);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "setLanguage");
- }
- }
-
- // =
-
- /**
- * 安装 App(支持 8.0)的意图
- * @param filePath The path of file.
- * @param authority 7.0 及以上安装需要传入清单文件中的}的 authorities 属性
- * @return 是否可以跳转
- */
- public static boolean installApp(final String filePath, final String authority) {
- return installApp(getFileByPath(filePath), authority);
- }
-
- /**
- * 安装 App(支持 8.0)的意图
- * @param file The file.
- * @param authority 7.0 及以上安装需要传入清单文件中的}的 authorities 属性
- * @return 是否可以跳转
- */
- public static boolean installApp(final File file, final String authority) {
- if (!isFileExists(file)) return false;
- try {
- DevUtils.getContext().startActivity(IntentUtils.getInstallAppIntent(file, authority, true));
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "installApp");
- return false;
- }
- return true;
- }
-
- /**
- * 安装 App(支持 8.0)的意图 - 回传
- * @param activity
- * @param filePath
- * @param authority
- * @param requestCode
- * @return
- */
- public static boolean installApp(final Activity activity, final String filePath, final String authority, final int requestCode) {
- return installApp(activity, getFileByPath(filePath), authority, requestCode);
- }
-
- /**
- * 安装 App(支持 8.0)的意图 - 回传
- * @param activity
- * @param file
- * @param authority
- * @param requestCode
- * @return
- */
- public static boolean installApp(final Activity activity, final File file, final String authority, final int requestCode) {
- if (!isFileExists(file)) return false;
- try {
- activity.startActivityForResult(IntentUtils.getInstallAppIntent(file, authority), requestCode);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "installApp");
- return false;
- }
- return true;
- }
-
- /**
- * 静默安装app
- * @param filePath
- * @return
- */
- public static boolean installAppSilent(final String filePath) {
- return installAppSilent(getFileByPath(filePath));
- }
-
- /**
- * 静默安装app
- *
- * @param file The file.
- * @return true : success, false : fail
- */
- public static boolean installAppSilent(final File file) {
- if (!isFileExists(file)) return false;
- boolean isRoot = isDeviceRooted();
- String filePath = file.getAbsolutePath();
- String command = "LD_LIBRARY_PATH=/vendor/lib:/system/lib pm install " + filePath;
- ShellUtils.CommandResult commandResult = ShellUtils.execCmd(command, isRoot);
- if (commandResult.successMsg != null && commandResult.successMsg.toLowerCase().contains("success")) {
- return true;
- } else {
- command = "LD_LIBRARY_PATH=/vendor/lib:/system/lib64 pm install " + filePath;
- commandResult = ShellUtils.execCmd(command, isRoot, true);
- return commandResult.successMsg != null && commandResult.successMsg.toLowerCase().contains("success");
- }
- }
-
- /**
- * 卸载 App
- * @param packageName
- * @return 卸载 App 的意图
- * @param
- */
- public static boolean uninstallApp(final String packageName) {
- if (isSpace(packageName)) return false;
- try {
- DevUtils.getContext().startActivity(IntentUtils.getUninstallAppIntent(packageName, true));
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "uninstallApp");
- return false;
- }
- return true;
- }
-
- /**
- * 卸载 App
- * @param activity
- * @param packageName
- * @param requestCode
- */
- public static boolean uninstallApp(final Activity activity, final String packageName, final int requestCode) {
- if (isSpace(packageName)) return false;
- try {
- activity.startActivityForResult(IntentUtils.getUninstallAppIntent(packageName), requestCode);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "uninstallApp");
- return false;
- }
- return true;
- }
-
- /**
- * 静默卸载 App
- * @param packageName
- * @return
- */
- public static boolean uninstallAppSilent(final String packageName) {
- return uninstallAppSilent(packageName, false);
- }
-
- /**
- * 静默卸载 app
- * @param packageName
- * @param isKeepData
- * @return
- */
- public static boolean uninstallAppSilent(final String packageName, final boolean isKeepData) {
- if (isSpace(packageName)) return false;
- boolean isRoot = isDeviceRooted();
- String command = "LD_LIBRARY_PATH=/vendor/lib:/system/lib pm uninstall " + (isKeepData ? "-k " : "") + packageName;
- ShellUtils.CommandResult commandResult = ShellUtils.execCmd(command, isRoot, true);
- if (commandResult.successMsg != null && commandResult.successMsg.toLowerCase().contains("success")) {
- return true;
- } else {
- command = "LD_LIBRARY_PATH=/vendor/lib:/system/lib64 pm uninstall " + (isKeepData ? "-k " : "") + packageName;
- commandResult = ShellUtils.execCmd(command, isRoot, true);
- return commandResult.successMsg != null && commandResult.successMsg.toLowerCase().contains("success");
- }
- }
-
- /**
- * 判断是否安装了应用
- * @param action The Intent action, such as ACTION_VIEW.
- * @param category The desired category.
- * @return true : yes, false : no
- */
- public static boolean isAppInstalled(@NonNull final String action, @NonNull final String category) {
- try {
- Intent intent = new Intent(action);
- intent.addCategory(category);
- PackageManager pm = DevUtils.getContext().getPackageManager();
- ResolveInfo info = pm.resolveActivity(intent, 0);
- return info != null;
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "isAppInstalled");
- return false;
- }
- }
-
- /**
- * 判断是否安装了应用
- * @param packageName
- * @return true : yes, false : no
- */
- public static boolean isAppInstalled(@NonNull final String packageName) {
- return !isSpace(packageName) && IntentUtils.getLaunchAppIntent(packageName) != null;
- }
-
- /**
- * 判断是否安装指定包名的APP
- * @param context 上下文
- * @param packageName 包路径
- * @return
- */
- @SuppressWarnings("unused")
- public static boolean isInstalledApp(Context context, String packageName) {
- if (packageName == null || "".equals(packageName)) {
- return false;
- }
- try {
- ApplicationInfo info = context.getPackageManager().getApplicationInfo(packageName, PackageManager.GET_UNINSTALLED_PACKAGES);
- return true;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "isInstalledApp");
- return false;
- }
- }
-
- /**
- * 判断是否存在root 权限
- * @return true : yes, false : no
- */
- public static boolean isAppRoot() {
- ShellUtils.CommandResult result = ShellUtils.execCmd("echo root", true);
- if (result.result == 0) return true; // result.errorMsg => 失败错误消息
- return false;
- }
-
- /**
- * 判断是否app 是否debug模式
- * @return true : yes, false : no
- */
- public static boolean isAppDebug() {
- return isAppDebug(DevUtils.getContext().getPackageName());
- }
-
- /**
- * 判断是否app 是否debug模式
- * @param packageName
- * @return true : yes, false : no
- */
- public static boolean isAppDebug(final String packageName) {
- if (isSpace(packageName)) return false;
- try {
- ApplicationInfo ai = DevUtils.getContext().getPackageManager().getApplicationInfo(packageName, 0);
- return ai != null && (ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "isAppDebug");
- return false;
- }
- }
-
- /**
- * 判断app 是否系统app
- * @return true : yes, false : no
- */
- public static boolean isAppSystem() {
- return isAppSystem(DevUtils.getContext().getPackageName());
- }
-
- /**
- * 判断app 是否系统app
- * @param packageName
- * @return true : yes, false : no
- */
- public static boolean isAppSystem(final String packageName) {
- if (isSpace(packageName)) return false;
- try {
- ApplicationInfo ai = DevUtils.getContext().getPackageManager().getApplicationInfo(packageName, 0);
- return ai != null && (ai.flags & ApplicationInfo.FLAG_SYSTEM) != 0;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "isAppSystem");
- return false;
- }
- }
-
- /**
- * 判断app 是否在前台
- * @return true : yes, false : no
- */
- public static boolean isAppForeground() {
- try {
- ActivityManager manager = (ActivityManager) DevUtils.getContext().getSystemService(Context.ACTIVITY_SERVICE);
- List info = manager.getRunningAppProcesses();
- if (info == null || info.size() == 0) return false;
- for (ActivityManager.RunningAppProcessInfo aInfo : info) {
- if (aInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
- return aInfo.processName.equals(DevUtils.getContext().getPackageName());
- }
- }
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "isAppForeground");
- }
- return false;
- }
-
- /**
- * 判断app 是否在前台
- * => 属于系统权限
- * @param packageName
- * @return
- */
- public static boolean isAppForeground(@NonNull final String packageName) {
- return !isSpace(packageName) && packageName.equals(ProcessUtils.getForegroundProcessName());
- }
-
- /**
- * 打开app
- * @param packageName
- */
- public static boolean launchApp(final String packageName) {
- if (isSpace(packageName)) return false;
- try {
- DevUtils.getContext().startActivity(IntentUtils.getLaunchAppIntent(packageName, true));
- return true;
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "launchApp");
- }
- return false;
- }
-
- /**
- * 打开app, 并且回传
- * @param activity The activity.
- * @param packageName
- * @param requestCode
- */
- public static boolean launchApp(final Activity activity, final String packageName, final int requestCode) {
- if (isSpace(packageName)) return false;
- try {
- activity.startActivityForResult(IntentUtils.getLaunchAppIntent(packageName), requestCode);
- return true;
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "launchApp");
- }
- return false;
- }
-
- /** 跳转到 专门的APP 设置详情页面 */
- public static boolean launchAppDetailsSettings() {
- return launchAppDetailsSettings(DevUtils.getContext().getPackageName());
- }
-
- /**
- * 跳转到 专门的APP 设置详情页面
- * @param packageName
- */
- public static boolean launchAppDetailsSettings(final String packageName) {
- if (isSpace(packageName)) return false;
- try {
- DevUtils.getContext().startActivity(IntentUtils.getLaunchAppDetailsSettingsIntent(packageName, true));
- return true;
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "launchAppDetailsSettings");
- }
- return false;
- }
-
- /**
- * 跳转到 专门的APP 应用商城详情页面
- * @param marketPkg
- * @return
- */
- public static boolean launchAppDetails(final String marketPkg) {
- return launchAppDetails(DevUtils.getContext().getPackageName(), marketPkg);
- }
-
- /**
- * 跳转到 专门的APP 应用商城详情页面
- * @param marketPkg
- * @param marketPkg
- * @return
- */
- public static boolean launchAppDetails(final String packageName, final String marketPkg) {
- if (isSpace(packageName)) return false;
- try {
- DevUtils.getContext().startActivity(IntentUtils.getlaunchAppDetailIntent(packageName, marketPkg, true));
- return true;
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "launchAppDetails");
- }
- return false;
- }
-
- /**
- * 获取app 路径 /data/data/包名/.apk
- * @return
- */
- public static String getAppPath() {
- return getAppPath(DevUtils.getContext().getPackageName());
- }
-
- /**
- * 获取app 路径 /data/data/包名/.apk
- * @param packageName
- * @return
- */
- public static String getAppPath(final String packageName) {
- if (isSpace(packageName)) return null;
- try {
- PackageManager pm = DevUtils.getContext().getPackageManager();
- PackageInfo pi = pm.getPackageInfo(packageName, 0);
- return pi == null ? null : pi.applicationInfo.sourceDir;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getAppPath");
- return null;
- }
- }
-
- // ==
-
- /**
- * 获取app 签名
- * @return
- */
- public static Signature[] getAppSignature() {
- return getAppSignature(DevUtils.getContext().getPackageName());
- }
-
- /**
- * 获取app 签名
- * @param packageName
- * @return
- */
- public static Signature[] getAppSignature(final String packageName) {
- if (isSpace(packageName)) return null;
- try {
- PackageManager pm = DevUtils.getContext().getPackageManager();
- @SuppressLint("PackageManagerGetSignatures")
- PackageInfo pi = pm.getPackageInfo(packageName, PackageManager.GET_SIGNATURES);
- return pi == null ? null : pi.signatures;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getAppSignature");
- return null;
- }
- }
-
- /**
- * 获取 app sha1值
- * @return
- */
- public static String getAppSignatureSHA1() {
- return getAppSignatureSHA1(DevUtils.getContext().getPackageName());
- }
-
- /**
- * 获取 app sha1值
- * @param packageName
- * @return
- */
- public static String getAppSignatureSHA1(@NonNull final String packageName) {
- Signature[] signature = getAppSignature(packageName);
- if (signature == null || signature.length <= 0) return null;
- return encryptSHA1ToString(signature[0].toByteArray()).replaceAll("(?<=[0-9A-F]{2})[0-9A-F]{2}", ":$0");
- }
-
- // ==
-
- /**
- * 检查是否存在某个文件
- * @param file 文件路径
- * @return 是否存在文件
- */
- private static boolean isFileExists(final File file){
- return file != null && file.exists();
- }
-
- /**
- * 获取文件
- * @param filePath
- * @return
- */
- private static File getFileByPath(final String filePath){
- return filePath != null ? new File(filePath) : null;
- }
-
- /**
- * 判断字符串是否为 null 或全为空白字符
- * @param str 待校验字符串
- * @return
- */
- private static boolean isSpace(final String str) {
- if (str == null) return true;
- for (int i = 0, len = str.length(); i < len; ++i) {
- if (!Character.isWhitespace(str.charAt(i))) {
- return false;
- }
- }
- return true;
- }
-
- /**
- * 判断设备是否 root
- * @return
- */
- private static boolean isDeviceRooted() {
- String su = "su";
- String[] locations = { "/system/bin/", "/system/xbin/", "/sbin/", "/system/sd/xbin/",
- "/system/bin/failsafe/", "/data/local/xbin/", "/data/local/bin/", "/data/local/" };
- for (String location : locations) {
- if (new File(location + su).exists()) {
- return true;
- }
- }
- return false;
- }
-
- // 十六进制大写转换
- private static final char HEX_DIGITS[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
-
- /**
- * SHA1加密
- * @param data
- * @return
- */
- private static String encryptSHA1ToString(final byte[] data) {
- return bytes2HexString(encryptSHA1(data));
- }
-
- /**
- * SHA1加密
- * @param data
- * @return
- */
- private static byte[] encryptSHA1(final byte[] data) {
- if (data == null || data.length <= 0) return null;
- try {
- MessageDigest md = MessageDigest.getInstance("SHA1");
- md.update(data);
- return md.digest();
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "encryptSHA1");
- return null;
- }
- }
-
- /**
- * 数据加密转换16进制
- * @param bytes
- * @return
- */
- private static String bytes2HexString(final byte[] bytes) {
- if (bytes == null) return null;
- int len = bytes.length;
- if (len <= 0) return null;
- char[] ret = new char[len << 1];
- for (int i = 0, j = 0; i < len; i++) {
- ret[j++] = HEX_DIGITS[bytes[i] >>> 4 & 0x0f];
- ret[j++] = HEX_DIGITS[bytes[i] & 0x0f];
- }
- return new String(ret);
- }
-
- // == 其他功能 ==
-
- /**
- * 启动本地应用打开PDF
- * @param context 上下文
- * @param filePath 文件路径
- */
- public static boolean openPDFFile(Context context, String filePath) {
- try {
- File file = new File(filePath);
- if (file.exists()) {
- Uri path = Uri.fromFile(file);
- Intent intent = new Intent(Intent.ACTION_VIEW);
- intent.setDataAndType(path, "application/pdf");
- intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- context.startActivity(intent);
- return true;
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "openPDFFile");
- }
- return false;
- }
-
- /**
- * 启动本地应用打开PDF
- * @param context 上下文
- * @param filePath 文件路径
- */
- public static boolean openWordFile(Context context, String filePath) {
- try {
- File file = new File(filePath);
- if (file.exists()) {
- Uri path = Uri.fromFile(file);
- Intent intent = new Intent("android.intent.action.VIEW");
- intent.addCategory("android.intent.category.DEFAULT");
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.setDataAndType(path, "application/msword");
- context.startActivity(intent);
- return true;
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "openWordFile");
- }
- return false;
- }
-
- /**
- * 调用WPS打开office文档
- * @param context 上下文
- * @param filePath 文件路径
- */
- public static boolean openOfficeByWPS(Context context, String filePath) {
- try {
- // 检查是否安装WPS
- String wpsPackageEng = "cn.wps.moffice_eng";// 普通版与英文版一样
- // String wpsActivity = "cn.wps.moffice.documentmanager.PreStartActivity";
- String wpsActivity2 = "cn.wps.moffice.documentmanager.PreStartActivity2";// 默认第三方程序启动
-
- Intent intent = new Intent();
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.addCategory(Intent.CATEGORY_DEFAULT);
- intent.setClassName(wpsPackageEng, wpsActivity2);
-
- Uri uri = Uri.fromFile(new File(filePath));
- intent.setData(uri);
- context.startActivity(intent);
- return true;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "openOfficeByWPS");
- }
- return false;
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/BarUtils.java b/DevLibUtils/src/main/java/dev/utils/app/BarUtils.java
deleted file mode 100644
index 53b50df982..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/BarUtils.java
+++ /dev/null
@@ -1,623 +0,0 @@
-package dev.utils.app;
-
-import android.annotation.SuppressLint;
-import android.annotation.TargetApi;
-import android.app.Activity;
-import android.content.Context;
-import android.content.res.Resources;
-import android.graphics.Color;
-import android.os.Build;
-import android.support.annotation.ColorInt;
-import android.support.annotation.IntRange;
-import android.support.annotation.NonNull;
-import android.support.v4.widget.DrawerLayout;
-import android.util.TypedValue;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.ViewGroup.MarginLayoutParams;
-import android.view.Window;
-import android.view.WindowManager;
-import android.widget.LinearLayout;
-
-import java.lang.reflect.Method;
-
-import dev.DevUtils;
-
-/**
- * detail: 状态栏相关工具类
- * Created by Ttt
- */
-public final class BarUtils {
-
- private BarUtils() {
- }
-
- private static final int DEFAULT_ALPHA = 112;
- private static final String TAG_COLOR = "TAG_COLOR";
- private static final String TAG_ALPHA = "TAG_ALPHA";
- private static final int TAG_OFFSET = -123;
-
- /**
- * 获取状态栏高度
- * @return the status bar's height
- */
- public static int getStatusBarHeight() {
- Resources resources = DevUtils.getContext().getResources();
- int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
- return resources.getDimensionPixelSize(resourceId);
- }
-
- /**
- * 设置状态栏是否显示
- * @param activity The activity.
- * @param isVisible True to set status bar visible, false otherwise.
- */
- public static void setStatusBarVisibility(@NonNull final Activity activity, final boolean isVisible) {
- setStatusBarVisibility(activity.getWindow(), isVisible);
- }
-
- /**
- * 设置状态栏是否显示
- * @param window The window.
- * @param isVisible True to set status bar visible, false otherwise.
- */
- public static void setStatusBarVisibility(@NonNull final Window window, final boolean isVisible) {
- if (isVisible) {
- window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
- } else {
- window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
- }
- }
-
- /**
- * 判断状态栏是否显示
- * @param activity The activity.
- * @return true : yes, false : no
- */
- public static boolean isStatusBarVisible(@NonNull final Activity activity) {
- int flags = activity.getWindow().getAttributes().flags;
- return (flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0;
- }
-
- /**
- * 设置状态是否高亮模式
- * @param activity The activity.
- * @param isLightMode True to set status bar light mode, false otherwise.
- */
- public static void setStatusBarLightMode(@NonNull final Activity activity, final boolean isLightMode) {
- setStatusBarLightMode(activity.getWindow(), isLightMode);
- }
-
- /**
- * 设置状态是否高亮模式
- * @param window The window.
- * @param isLightMode True to set status bar light mode, false otherwise.
- */
- public static void setStatusBarLightMode(@NonNull final Window window, final boolean isLightMode) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
- View decorView = window.getDecorView();
- if (decorView != null) {
- int vis = decorView.getSystemUiVisibility();
- if (isLightMode) {
- window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
- vis |= View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
- } else {
- vis &= ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
- }
- decorView.setSystemUiVisibility(vis);
- }
- }
- }
-
- /**
- * 添加状态栏同等高度到View的顶部
- * @param view The view.
- */
- public static void addMarginTopEqualStatusBarHeight(@NonNull View view) {
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
- Object haveSetOffset = view.getTag(TAG_OFFSET);
- if (haveSetOffset != null && (Boolean) haveSetOffset) return;
- MarginLayoutParams layoutParams = (MarginLayoutParams) view.getLayoutParams();
- layoutParams.setMargins(layoutParams.leftMargin, layoutParams.topMargin + getStatusBarHeight(), layoutParams.rightMargin, layoutParams.bottomMargin);
- view.setTag(TAG_OFFSET, true);
- }
-
- /**
- * 减去状态栏同等高度
- * @param view The view.
- */
- public static void subtractMarginTopEqualStatusBarHeight(@NonNull View view) {
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
- Object haveSetOffset = view.getTag(TAG_OFFSET);
- if (haveSetOffset == null || !(Boolean) haveSetOffset) return;
- MarginLayoutParams layoutParams = (MarginLayoutParams) view.getLayoutParams();
- layoutParams.setMargins(layoutParams.leftMargin, layoutParams.topMargin - getStatusBarHeight(), layoutParams.rightMargin, layoutParams.bottomMargin);
- view.setTag(TAG_OFFSET, false);
- }
-
- /**
- * 设置状态栏颜色
- * @param activity The activity.
- * @param color The status bar's color.
- */
- public static void setStatusBarColor(@NonNull final Activity activity, @ColorInt final int color) {
- setStatusBarColor(activity, color, DEFAULT_ALPHA, false);
- }
-
- /**
- * 设置状态栏颜色
- * @param activity The activity.
- * @param color The status bar's color.
- * @param alpha The status bar's alpha which isn't the same as alpha in the color.
- */
- public static void setStatusBarColor(@NonNull final Activity activity, @ColorInt final int color, @IntRange(from = 0, to = 255) final int alpha) {
- setStatusBarColor(activity, color, alpha, false);
- }
-
- /**
- * 设置状态栏颜色
- * @param activity The activity.
- * @param color The status bar's color.
- * @param alpha The status bar's alpha which isn't the same as alpha in the color.
- * @param isDecor True to add fake status bar in DecorView,
- * false to add fake status bar in ContentView.
- */
- public static void setStatusBarColor(@NonNull final Activity activity, @ColorInt final int color, @IntRange(from = 0, to = 255) final int alpha, final boolean isDecor) {
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
- hideAlphaView(activity);
- transparentStatusBar(activity);
- addStatusBarColor(activity, color, alpha, isDecor);
- }
-
- /**
- * 设置状态栏颜色
- * @param fakeStatusBar The fake status bar view.
- * @param color The status bar's color.
- */
- public static void setStatusBarColor(@NonNull final View fakeStatusBar, @ColorInt final int color) {
- setStatusBarColor(fakeStatusBar, color, DEFAULT_ALPHA);
- }
-
- /**
- * 设置状态栏颜色
- * @param fakeStatusBar The fake status bar view.
- * @param color The status bar's color.
- * @param alpha The status bar's alpha which isn't the same as alpha in the color.
- */
- public static void setStatusBarColor(@NonNull final View fakeStatusBar, @ColorInt final int color, @IntRange(from = 0, to = 255) final int alpha) {
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
- fakeStatusBar.setVisibility(View.VISIBLE);
- transparentStatusBar((Activity) fakeStatusBar.getContext());
- ViewGroup.LayoutParams layoutParams = fakeStatusBar.getLayoutParams();
- layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
- layoutParams.height = BarUtils.getStatusBarHeight();
- fakeStatusBar.setBackgroundColor(getStatusBarColor(color, alpha));
- }
-
- /**
- * 设置状态栏透明度
- * @param activity The activity.
- */
- public static void setStatusBarAlpha(@NonNull final Activity activity) {
- setStatusBarAlpha(activity, DEFAULT_ALPHA, false);
- }
-
- /**
- * 设置状态栏透明度
- * @param activity The activity.
- * @param alpha The status bar's alpha.
- */
- public static void setStatusBarAlpha(@NonNull final Activity activity, @IntRange(from = 0, to = 255) final int alpha) {
- setStatusBarAlpha(activity, alpha, false);
- }
-
- /**
- * 设置状态栏透明度
- * @param activity The activity.
- * @param alpha The status bar's alpha.
- * @param isDecor True to add fake status bar in DecorView,
- * false to add fake status bar in ContentView.
- */
- public static void setStatusBarAlpha(@NonNull final Activity activity, @IntRange(from = 0, to = 255) final int alpha, final boolean isDecor) {
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
- hideColorView(activity);
- transparentStatusBar(activity);
- addStatusBarAlpha(activity, alpha, isDecor);
- }
-
- /**
- * 设置状态栏透明度
- * @param fakeStatusBar The fake status bar view.
- */
- public static void setStatusBarAlpha(@NonNull final View fakeStatusBar) {
- setStatusBarAlpha(fakeStatusBar, DEFAULT_ALPHA);
- }
-
- /**
- * 设置状态栏透明度
- * @param fakeStatusBar The fake status bar view.
- * @param alpha The status bar's alpha.
- */
- public static void setStatusBarAlpha(@NonNull final View fakeStatusBar, @IntRange(from = 0, to = 255) final int alpha) {
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
- fakeStatusBar.setVisibility(View.VISIBLE);
- transparentStatusBar((Activity) fakeStatusBar.getContext());
- ViewGroup.LayoutParams layoutParams = fakeStatusBar.getLayoutParams();
- layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT;
- layoutParams.height = BarUtils.getStatusBarHeight();
- fakeStatusBar.setBackgroundColor(Color.argb(alpha, 0, 0, 0));
- }
-
- /**
- * 设置状态栏的颜色
- * DrawLayout must add android:fitsSystemWindows="true"
- * @param activity The activity.
- * @param drawer The DrawLayout.
- * @param fakeStatusBar The fake status bar view.
- * @param color The status bar's color.
- * @param isTop True to set DrawerLayout at the top layer, false otherwise.
- */
- public static void setStatusBarColor4Drawer(@NonNull final Activity activity, @NonNull final DrawerLayout drawer, @NonNull final View fakeStatusBar, @ColorInt final int color, final boolean isTop) {
- setStatusBarColor4Drawer(activity, drawer, fakeStatusBar, color, DEFAULT_ALPHA, isTop);
- }
-
- /**
- * 设置状态栏的颜色
- * DrawLayout must add android:fitsSystemWindows="true"
- * @param activity The activity.
- * @param drawer The DrawLayout.
- * @param fakeStatusBar The fake status bar view.
- * @param color The status bar's color.
- * @param alpha The status bar's alpha which isn't the same as alpha in the color.
- * @param isTop True to set DrawerLayout at the top layer, false otherwise.
- */
- public static void setStatusBarColor4Drawer(@NonNull final Activity activity, @NonNull final DrawerLayout drawer, @NonNull final View fakeStatusBar, @ColorInt final int color,
- @IntRange(from = 0, to = 255) final int alpha, final boolean isTop) {
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
- drawer.setFitsSystemWindows(false);
- transparentStatusBar(activity);
- setStatusBarColor(fakeStatusBar, color, isTop ? alpha : 0);
- for (int i = 0, len = drawer.getChildCount(); i < len; i++) {
- drawer.getChildAt(i).setFitsSystemWindows(false);
- }
- if (isTop) {
- hideAlphaView(activity);
- } else {
- addStatusBarAlpha(activity, alpha, false);
- }
- }
-
- /**
- * 设置状态栏透明度
- * DrawLayout must add android:fitsSystemWindows="true"
- * @param activity The activity.
- * @param drawer drawerLayout
- * @param fakeStatusBar The fake status bar view.
- * @param isTop True to set DrawerLayout at the top layer, false otherwise.
- */
- public static void setStatusBarAlpha4Drawer(@NonNull final Activity activity, @NonNull final DrawerLayout drawer, @NonNull final View fakeStatusBar, final boolean isTop) {
- setStatusBarAlpha4Drawer(activity, drawer, fakeStatusBar, DEFAULT_ALPHA, isTop);
- }
-
- /**
- * 设置状态栏透明度
- * DrawLayout must add android:fitsSystemWindows="true"
- * @param activity The activity.
- * @param drawer drawerLayout
- * @param fakeStatusBar The fake status bar view.
- * @param alpha The status bar's alpha.
- * @param isTop True to set DrawerLayout at the top layer, false otherwise.
- */
- public static void setStatusBarAlpha4Drawer(@NonNull final Activity activity, @NonNull final DrawerLayout drawer, @NonNull final View fakeStatusBar,
- @IntRange(from = 0, to = 255) final int alpha, final boolean isTop) {
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
- drawer.setFitsSystemWindows(false);
- transparentStatusBar(activity);
- setStatusBarAlpha(fakeStatusBar, isTop ? alpha : 0);
- for (int i = 0, len = drawer.getChildCount(); i < len; i++) {
- drawer.getChildAt(i).setFitsSystemWindows(false);
- }
- if (isTop) {
- hideAlphaView(activity);
- } else {
- addStatusBarAlpha(activity, alpha, false);
- }
- }
-
- /**
- * 设置状态栏颜色
- * @param activity
- * @param color
- * @param alpha
- * @param isDecor
- */
- private static void addStatusBarColor(final Activity activity, final int color, final int alpha, boolean isDecor) {
- ViewGroup parent = isDecor ? (ViewGroup) activity.getWindow().getDecorView() : (ViewGroup) activity.findViewById(android.R.id.content);
- View fakeStatusBarView = parent.findViewWithTag(TAG_COLOR);
- if (fakeStatusBarView != null) {
- if (fakeStatusBarView.getVisibility() == View.GONE) {
- fakeStatusBarView.setVisibility(View.VISIBLE);
- }
- fakeStatusBarView.setBackgroundColor(getStatusBarColor(color, alpha));
- } else {
- parent.addView(createColorStatusBarView(parent.getContext(), color, alpha));
- }
- }
-
- /**
- * 设置状态栏透明度
- * @param activity
- * @param alpha
- * @param isDecor
- */
- private static void addStatusBarAlpha(final Activity activity, final int alpha, boolean isDecor) {
- ViewGroup parent = isDecor ? (ViewGroup) activity.getWindow().getDecorView() : (ViewGroup) activity.findViewById(android.R.id.content);
- View fakeStatusBarView = parent.findViewWithTag(TAG_ALPHA);
- if (fakeStatusBarView != null) {
- if (fakeStatusBarView.getVisibility() == View.GONE) {
- fakeStatusBarView.setVisibility(View.VISIBLE);
- }
- fakeStatusBarView.setBackgroundColor(Color.argb(alpha, 0, 0, 0));
- } else {
- parent.addView(createAlphaStatusBarView(parent.getContext(), alpha));
- }
- }
-
- /**
- * 隐藏颜色View
- * @param activity
- */
- private static void hideColorView(final Activity activity) {
- ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
- View fakeStatusBarView = decorView.findViewWithTag(TAG_COLOR);
- if (fakeStatusBarView == null) return;
- fakeStatusBarView.setVisibility(View.GONE);
- }
-
- /**
- * 隐藏透明度
- * @param activity
- */
- private static void hideAlphaView(final Activity activity) {
- ViewGroup decorView = (ViewGroup) activity.getWindow().getDecorView();
- View fakeStatusBarView = decorView.findViewWithTag(TAG_ALPHA);
- if (fakeStatusBarView == null) return;
- fakeStatusBarView.setVisibility(View.GONE);
- }
-
- /**
- * 获取状态栏颜色 = (传入颜色等,进行生成)
- * @param color
- * @param alpha
- * @return
- */
- private static int getStatusBarColor(final int color, final int alpha) {
- if (alpha == 0) return color;
- float a = 1 - alpha / 255f;
- int red = (color >> 16) & 0xff;
- int green = (color >> 8) & 0xff;
- int blue = color & 0xff;
- red = (int) (red * a + 0.5);
- green = (int) (green * a + 0.5);
- blue = (int) (blue * a + 0.5);
- return Color.argb(255, red, green, blue);
- }
-
- /**
- * 创建对应颜色的状态栏View
- * @param context
- * @param color
- * @param alpha
- * @return
- */
- private static View createColorStatusBarView(final Context context, final int color, final int alpha) {
- View statusBarView = new View(context);
- statusBarView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight()));
- statusBarView.setBackgroundColor(getStatusBarColor(color, alpha));
- statusBarView.setTag(TAG_COLOR);
- return statusBarView;
- }
-
- /**
- * 创建对应透明度的状态栏View
- * @param context
- * @param alpha
- * @return
- */
- private static View createAlphaStatusBarView(final Context context, final int alpha) {
- View statusBarView = new View(context);
- statusBarView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, getStatusBarHeight()));
- statusBarView.setBackgroundColor(Color.argb(alpha, 0, 0, 0));
- statusBarView.setTag(TAG_ALPHA);
- return statusBarView;
- }
-
- /**
- * 设置透明的状态栏
- * @param activity
- */
- private static void transparentStatusBar(final Activity activity) {
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return;
- Window window = activity.getWindow();
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
- int option = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
- window.getDecorView().setSystemUiVisibility(option);
- window.setStatusBarColor(Color.TRANSPARENT);
- } else {
- window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
- }
- }
-
- // ======================
- // ===== action bar =====
- // ======================
-
- /**
- * 返回 ActionBase 高度
- * @return the action bar's height
- */
- public static int getActionBarHeight() {
- TypedValue tv = new TypedValue();
- if (DevUtils.getContext().getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
- return TypedValue.complexToDimensionPixelSize(tv.data, DevUtils.getContext().getResources().getDisplayMetrics());
- }
- return 0;
- }
-
- // ========================
- // === notification bar ===
- // ========================
-
- /**
- * 设置通知栏是否显示
- *
- * @param isVisible True to set notification bar visible, false otherwise.
- */
- public static void setNotificationBarVisibility(final boolean isVisible) {
- String methodName;
- if (isVisible) {
- methodName = (Build.VERSION.SDK_INT <= 16) ? "expand" : "expandNotificationsPanel";
- } else {
- methodName = (Build.VERSION.SDK_INT <= 16) ? "collapse" : "collapsePanels";
- }
- invokePanels(methodName);
- }
-
- /**
- * 反射调用面板
- * @param methodName
- */
- private static void invokePanels(final String methodName) {
- try {
- @SuppressLint("WrongConstant")
- Object service = DevUtils.getContext().getSystemService("statusbar");
- @SuppressLint("PrivateApi")
- Class> statusBarManager = Class.forName("android.app.StatusBarManager");
- Method expand = statusBarManager.getMethod(methodName);
- expand.invoke(service);
- } catch (Exception ignore) {
- }
- }
-
- // ======================
- // === navigation bar ===
- // ======================
-
- /**
- * 获取 NavigationView 高度
- * @return the navigation bar's height
- */
- public static int getNavBarHeight() {
- Resources res = DevUtils.getContext().getResources();
- int resourceId = res.getIdentifier("navigation_bar_height", "dimen", "android");
- if (resourceId != 0) {
- return res.getDimensionPixelSize(resourceId);
- } else {
- return 0;
- }
- }
-
- /**
- * 设置导航栏是否可见(图标显示)
- * @param activity The activity.
- * @param isVisible True to set notification bar visible, false otherwise.
- */
- public static void setNavBarVisibility(@NonNull final Activity activity, boolean isVisible) {
- setNavBarVisibility(activity.getWindow(), isVisible);
- }
-
- /**
- * 设置导航栏是否可见(图标显示)
- * @param window The window.
- * @param isVisible True to set notification bar visible, false otherwise.
- */
- public static void setNavBarVisibility(@NonNull final Window window, boolean isVisible) {
- if (isVisible) {
- window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
- } else {
- window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
- View decorView = window.getDecorView();
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- int visibility = decorView.getSystemUiVisibility();
- decorView.setSystemUiVisibility(visibility & ~View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
- }
- }
- }
-
- /**
- * 设置沉浸模式
- * @param activity The activity.
- */
- @TargetApi(Build.VERSION_CODES.KITKAT)
- public static void setNavBarImmersive(@NonNull final Activity activity) {
- setNavBarImmersive(activity.getWindow());
- }
-
- /**
- * 设置顶部沉浸模式
- * @param window The window.
- */
- @TargetApi(Build.VERSION_CODES.KITKAT)
- public static void setNavBarImmersive(@NonNull final Window window) {
- View decorView = window.getDecorView();
- window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
- int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
- decorView.setSystemUiVisibility(uiOptions);
- }
-
- /**
- * 判断顶部状态栏(图标)是否显示
- * @param activity The activity.
- * @return true : yes, false : no
- */
- public static boolean isNavBarVisible(@NonNull final Activity activity) {
- return isNavBarVisible(activity.getWindow());
- }
-
- /**
- * 判断顶部状态栏(图标)是否显示
- * @param window The window.
- * @return true : yes, false : no
- */
- public static boolean isNavBarVisible(@NonNull final Window window) {
- boolean isNoLimits = (window.getAttributes().flags & WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS) != 0;
- if (isNoLimits) return false;
- View decorView = window.getDecorView();
- int visibility = decorView.getSystemUiVisibility();
- return (visibility & View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0;
- }
-
- // ==
-
- /**
- * 设置是否显示状态栏图标等
- * @param activity
- * @param isVisible
- */
- public static void setNavBar(Activity activity, boolean isVisible){
- setNavBar(activity.getWindow(), isVisible);
- }
-
- /**
- * 设置是否显示状态栏图标等
- * @param window The window.
- */
- @TargetApi(Build.VERSION_CODES.KITKAT)
- public static void setNavBar(@NonNull final Window window, boolean isVisible) {
- if (isVisible){
- // 显示状态栏
- WindowManager.LayoutParams params = window.getAttributes();
- params.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
- window.setAttributes(params);
- window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
- } else {
- // 隐藏状态栏
- WindowManager.LayoutParams params = window.getAttributes();
- params.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
- window.setAttributes(params);
- window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
- }
- }
-
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/BrightnessUtils.java b/DevLibUtils/src/main/java/dev/utils/app/BrightnessUtils.java
deleted file mode 100644
index 052f7bfd5d..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/BrightnessUtils.java
+++ /dev/null
@@ -1,134 +0,0 @@
-package dev.utils.app;
-
-import android.content.ContentResolver;
-import android.content.Intent;
-import android.net.Uri;
-import android.os.Build;
-import android.provider.Settings;
-import android.support.annotation.IntRange;
-import android.support.annotation.NonNull;
-import android.view.Window;
-import android.view.WindowManager;
-
-import dev.DevUtils;
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: 亮度相关工具类
- * Created by Ttt
- */
-public final class BrightnessUtils {
-
- private BrightnessUtils() {
- }
-
- // 日志TAG
- private static final String TAG = BrightnessUtils.class.getSimpleName();
-
- /**
- * 判断是否开启自动调节亮度
- * @return true : 是, false : 否
- */
- public static boolean isAutoBrightnessEnabled() {
- try {
- int mode = Settings.System.getInt(DevUtils.getContext().getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE);
- return mode == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "isAutoBrightnessEnabled");
- return false;
- }
- }
-
- /**
- * 设置是否开启自动调节亮度
- *
- * @param enabled true : 打开, false : 关闭
- * @return true : 成功, false : 失败
- */
- public static boolean setAutoBrightnessEnabled(final boolean enabled) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.System.canWrite(DevUtils.getContext())) {
- try {
- Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
- intent.setData(Uri.parse("package:" + DevUtils.getContext().getPackageName()));
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- DevUtils.getContext().startActivity(intent);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "setAutoBrightnessEnabled");
- }
- return false;
- }
- try {
- return Settings.System.putInt(DevUtils.getContext().getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE,
- enabled ? Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC : Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "setAutoBrightnessEnabled");
- }
- return false;
- }
-
- /**
- * 获取屏幕亮度
- * @return 屏幕亮度 0-255
- */
- public static int getBrightness() {
- try {
- return Settings.System.getInt(DevUtils.getContext().getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getBrightness");
- return 0;
- }
- }
-
- /**
- * 设置屏幕亮度
- *
- * @param brightness 亮度值
- */
- public static boolean setBrightness(@IntRange(from = 0, to = 255) final int brightness) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.System.canWrite(DevUtils.getContext())) {
- try {
- Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
- intent.setData(Uri.parse("package:" + DevUtils.getContext().getPackageName()));
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- DevUtils.getContext().startActivity(intent);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "setBrightness");
- }
- return false;
- }
- try {
- ContentResolver resolver = DevUtils.getContext().getContentResolver();
- boolean result = Settings.System.putInt(resolver, Settings.System.SCREEN_BRIGHTNESS, brightness);
- resolver.notifyChange(Settings.System.getUriFor("screen_brightness"), null);
- return result;
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "setBrightness");
- }
- return false;
- }
-
- /**
- * 设置窗口亮度
- * @param window 窗口
- * @param brightness 亮度值
- */
- public static void setWindowBrightness(@NonNull final Window window, @IntRange(from = 0, to = 255) final int brightness) {
- if (window == null) return;
- WindowManager.LayoutParams lp = window.getAttributes();
- lp.screenBrightness = brightness / 255f;
- window.setAttributes(lp);
- }
-
- /**
- * 获取窗口亮度
- * @param window 窗口
- * @return 屏幕亮度 0-255
- */
- public static int getWindowBrightness(final Window window) {
- if (window == null) return -1;
- WindowManager.LayoutParams lp = window.getAttributes();
- float brightness = lp.screenBrightness;
- if (brightness < 0) return getBrightness();
- return (int) (brightness * 255);
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/CPUUtils.java b/DevLibUtils/src/main/java/dev/utils/app/CPUUtils.java
deleted file mode 100644
index 30b6793a03..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/CPUUtils.java
+++ /dev/null
@@ -1,275 +0,0 @@
-package dev.utils.app;
-
-import android.text.format.Formatter;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileFilter;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.LineNumberReader;
-import java.util.regex.Pattern;
-
-import dev.DevUtils;
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: 获取CPU信息工具类
- * Created by Ttt
- */
-public final class CPUUtils {
-
- private CPUUtils(){
- }
-
- // 日志TAG
- private static final String TAG = CPUUtils.class.getSimpleName();
-
- /**
- * 获取处理器的Java虚拟机的数量
- */
- public static int getProcessorsCount() {
- return Runtime.getRuntime().availableProcessors();
- }
-
- /**
- * 获取手机CPU序列号
- * @return String cpu序列号(16位) 读取失败为"0000000000000000"
- */
- public static String getSysCPUSerialNum() {
- String str = "", strCPU = "", cpuSerialNum = "0000000000000000";
- try {
- //读取CPU信息
- Process pp = Runtime.getRuntime().exec("cat/proc/cpuinfo");
- InputStreamReader ir = new InputStreamReader(pp.getInputStream());
- LineNumberReader input = new LineNumberReader(ir);
- //查找CPU序列号
- for (int i = 1; i < 100; i++) {
- str = input.readLine();
- if (str != null) {
- //查找到序列号所在行
- if (str.indexOf("Serial") > -1) {
- //提取序列号
- strCPU = str.substring(str.indexOf(":") + 1,
- str.length());
- //去空格
- cpuSerialNum = strCPU.trim();
- break;
- }
- } else {
- break;
- }
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getSysCPUSerialNum");
- }
- return cpuSerialNum;
- }
-
- /**
- * 获取CPU 信息
- * @return
- */
- public static String getCpuInfo() {
- try {
- FileReader fr = new FileReader("/proc/cpuinfo");
- BufferedReader br = new BufferedReader(fr);
- return br.readLine();
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getCpuInfo");
- }
- return "";
- }
-
- /**
- * 获取CPU 型号
- * @return
- */
- public static String getCpuModel() {
- try {
- FileReader fr = new FileReader("/proc/cpuinfo");
- BufferedReader br = new BufferedReader(fr);
- String text = br.readLine();
- String[] array = text.split(":\\s+", 2);
- return array[1];
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getCpuModel");
- }
- return "";
- }
-
- /**
- * 获取 CPU 最大频率(单位KHZ)
- * @return
- */
- public static String getMaxCpuFreq() {
- String result = "";
- ProcessBuilder cmd;
- InputStream in = null;
- try {
- String[] args = {"/system/bin/cat", "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq"};
- cmd = new ProcessBuilder(args);
- Process process = cmd.start();
- in = process.getInputStream();
- byte[] re = new byte[24];
- while (in.read(re) != -1) {
- result = result + new String(re);
- }
- in.close();
- result = Formatter.formatFileSize(DevUtils.getContext(), Long.parseLong(result.trim()) * 1024) + " Hz";
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getMaxCpuFreq");
- result = "unknown";
- } finally {
- if (in != null){
- try {
- in.close();
- } catch (IOException e){
- }
- }
- }
- return result;
- }
-
- /**
- * 获取 CPU 最小频率(单位KHZ)
- * @return
- */
- public static String getMinCpuFreq() {
- String result = "";
- ProcessBuilder cmd;
- InputStream in = null;
- try {
- String[] args = {"/system/bin/cat", "/sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq"};
- cmd = new ProcessBuilder(args);
- Process process = cmd.start();
- in = process.getInputStream();
- byte[] re = new byte[24];
- while (in.read(re) != -1) {
- result = result + new String(re);
- }
- in.close();
- result = Formatter.formatFileSize(DevUtils.getContext(), Long.parseLong(result.trim()) * 1024) + " Hz";
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getMinCpuFreq");
- result = "unknown";
- } finally {
- if (in != null){
- try {
- in.close();
- } catch (IOException e){
- }
- }
- }
- return result;
- }
-
- /**
- * 实时获取 CPU 当前频率(单位KHZ)
- * @return
- */
- public static String getCurCpuFreq() {
- String result = "";
- try {
- FileReader fr = new FileReader("/sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq");
- BufferedReader br = new BufferedReader(fr);
- String text = br.readLine();
- result = Formatter.formatFileSize(DevUtils.getContext(), Long.parseLong(text.trim()) * 1024) + " Hz";
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getCurCpuFreq");
- result = "unknown";
- }
- return result;
- }
-
- /**
- * 获取 CPU 几核
- * @return
- */
- public static int getCoresNumbers() {
- // Private Class to display only CPU devices in the directory listing
- class CpuFilter implements FileFilter {
- @Override
- public boolean accept(File pathname) {
- //Check if filename is "cpu", followed by a single digit number
- if (Pattern.matches("cpu[0-9]+", pathname.getName())) {
- return true;
- }
- return false;
- }
- }
- // CPU 核心数
- int CPU_CORES = 0;
- try {
- //Get directory containing CPU info
- File dir = new File("/sys/devices/system/cpu/");
- //Filter to only list the devices we care about
- File[] files = dir.listFiles(new CpuFilter());
- //Return the number of cores (virtual CPU devices)
- CPU_CORES = files.length;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getCoresNumbers");
- }
- if (CPU_CORES < 1) {
- CPU_CORES = Runtime.getRuntime().availableProcessors();
- }
- if (CPU_CORES < 1) {
- CPU_CORES = 1;
- }
- return CPU_CORES;
- }
-
- /**
- * 获取CPU名字
- * @return
- */
- public static String getCpuName() {
- try {
- BufferedReader bufferedReader = new BufferedReader(new FileReader("/proc/cpuinfo"), 8192);
- String line = bufferedReader.readLine();
- bufferedReader.close();
- String[] array = line.split(":\\s+", 2);
- if (array.length > 1) {
- return array[1];
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getCpuName");
- }
- return null;
- }
-
- /**
- * 获取 CMD 指令回调数据
- * @param args
- * @return
- */
- public static String getCMDOutputString(String[] args) {
- InputStream in = null;
- try {
- ProcessBuilder cmd = new ProcessBuilder(args);
- Process process = cmd.start();
- in = process.getInputStream();
- StringBuilder sb = new StringBuilder();
- byte[] re = new byte[64];
- int len;
- while ((len = in.read(re)) != -1) {
- sb.append(new String(re, 0, len));
- }
- in.close();
- process.destroy();
- return sb.toString();
- } catch (IOException e) {
- LogPrintUtils.eTag(TAG, e, "getCMDOutputString");
- } finally {
- if (in != null){
- try {
- in.close();
- } catch (IOException e){
- }
- }
- }
- return null;
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/CameraUtils.java b/DevLibUtils/src/main/java/dev/utils/app/CameraUtils.java
deleted file mode 100644
index 0dd1fe628e..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/CameraUtils.java
+++ /dev/null
@@ -1,216 +0,0 @@
-package dev.utils.app;
-
-import android.hardware.Camera;
-
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: 摄像头相关工具类
- * Created by Ttt
- */
-public final class CameraUtils {
-
- private CameraUtils(){
- }
-
- // 日志Tag
- private static final String TAG = CameraUtils.class.getSimpleName();
-
- // == 摄像头快速处理 ==
-
- /**
- * 判断是否支持反转摄像头(是否存在前置摄像头)
- * @return
- */
- public static boolean isSupportReverse(){
- try {
- // 默认是不支持
- int isSupportReverse = 0;
- // 判断是否支持前置,支持则使用前置
- if (checkCameraFacing(Camera.CameraInfo.CAMERA_FACING_FRONT)) {
- isSupportReverse += 1;
- // -
- LogPrintUtils.dTag(TAG,"支持前置摄像头(手机屏幕)");
- }
- // 判断是否支持后置,是则使用后置
- if (checkCameraFacing(Camera.CameraInfo.CAMERA_FACING_BACK)) {
- isSupportReverse += 1;
- // -
- LogPrintUtils.dTag(TAG,"支持后置摄像头(手机背面)");
- }
- // 如果都支持才表示支持反转
- return isSupportReverse == 2;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "isSupportReverse");
- }
- // 默认不支持反转摄像头
- return false;
- }
-
- /**
- * 检查是否有摄像头
- * @param facing 前置还是后置
- * @return
- */
- public static boolean checkCameraFacing(int facing) {
- try {
- int cameraCount = Camera.getNumberOfCameras();
- Camera.CameraInfo info = new Camera.CameraInfo();
- for (int i = 0; i < cameraCount; i++) {
- Camera.getCameraInfo(i, info);
- if (facing == info.facing) {
- return true;
- }
- }
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "checkCameraFacing");
- }
- return false;
- }
-
- /**
- * 判断是否使用前置摄像头
- * @param facing
- * @return
- */
- public static boolean isFrontCamera(int facing){
- return facing == Camera.CameraInfo.CAMERA_FACING_FRONT;
- }
-
- /**
- * 判断是否使用后置摄像头
- * @param facing
- * @return
- */
- public static boolean isBackCamera(int facing){
- return facing == Camera.CameraInfo.CAMERA_FACING_BACK;
- }
-
- /**
- * 判断使用的视像头
- * @param isFrontCamera 是否前置摄像头
- * @return
- */
- public static int isUseCameraFacing(boolean isFrontCamera){
- // 默认使用后置摄像头
- int cameraFacing = Camera.CameraInfo.CAMERA_FACING_BACK;
- try {
- // 支持的摄像头 - 前置, 后置
- boolean[] cFacingArys = new boolean[] { false, false};
- // 判断是否支持前置
- cFacingArys[0] = checkCameraFacing(Camera.CameraInfo.CAMERA_FACING_FRONT);
- // 判断是否支持后置
- cFacingArys[1] = checkCameraFacing(Camera.CameraInfo.CAMERA_FACING_BACK);
- // 进行判断想要使用的是前置,还是后置
- if (isFrontCamera && cFacingArys[0]){ // 使用前置, 必须也支持前置
- // 表示使用前置摄像头
- cameraFacing = Camera.CameraInfo.CAMERA_FACING_FRONT;
- } else {
- // 表示使用后置摄像头
- cameraFacing = Camera.CameraInfo.CAMERA_FACING_BACK;
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "isUseCameraFacing");
- }
- return cameraFacing;
- }
-
- // ==
-
- /**
- * 释放摄像头资源
- * @param mCamera 摄像头对象
- */
- public static void freeCameraResource(android.hardware.Camera mCamera) {
- try {
- if (mCamera != null) {
- mCamera.setPreviewCallback(null);
- mCamera.stopPreview();
- mCamera.lock();
- mCamera.release();
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "freeCameraResource");
- } finally {
- mCamera = null;
- }
- }
-
- /**
- * 初始化摄像头
- * @param mCamera
- * @param isFrontCamera 是否前置摄像头 = true = 前置(屏幕面), false = 后置(手机背面) = 正常默认使用背面
- * @return 使用的摄像头
- */
- public static Camera initCamera(Camera mCamera, boolean isFrontCamera) {
- // 如果之前存在摄像头数据, 则释放资源
- if (mCamera != null) {
- freeCameraResource(mCamera);
- }
- try {
- // 进行判断想要使用的是前置,还是后置
- if (isFrontCamera && checkCameraFacing(Camera.CameraInfo.CAMERA_FACING_FRONT)){ // 使用前置, 必须也支持前置
- // 初始化前置摄像头
- mCamera = Camera.open(Camera.CameraInfo.CAMERA_FACING_FRONT);
- } else {
- // 初始化后置摄像头
- mCamera = Camera.open(Camera.CameraInfo.CAMERA_FACING_BACK);
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "initCamera");
- // 释放资源
- freeCameraResource(mCamera);
- }
- return mCamera;
- }
-
- /**
- * 打开摄像头
- * @param cameraId {@link Camera.CameraInfo } CAMERA_FACING_FRONT(前置), CAMERA_FACING_BACK(后置)
- * @return
- */
- public static Camera open(int cameraId){
- // 判断支持的摄像头数量
- int numCameras = Camera.getNumberOfCameras();
- if (numCameras == 0) {
- return null;
- }
- // 判断是否指定哪个摄像头
- boolean explicitRequest = cameraId >= 0;
-
- // 如果没指定, 则进行判断处理
- if (!explicitRequest) { // 默认使用 后置摄像头, 没有后置才用其他(前置)
- int index = 0;
- while (index < numCameras) {
- Camera.CameraInfo cameraInfo = new Camera.CameraInfo();
- Camera.getCameraInfo(index, cameraInfo);
- if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) {
- break;
- }
- index++;
- }
- cameraId = index;
- }
-
- Camera camera;
- if (cameraId < numCameras) {
- camera = Camera.open(cameraId);
- } else {
- if (explicitRequest) {
- camera = null;
- } else {
- // 默认使用后置
- camera = Camera.open(Camera.CameraInfo.CAMERA_FACING_BACK);
- }
- }
- return camera;
- }
-
- /**
- * 打开摄像头(默认后置摄像头)
- * @return
- */
- public static Camera open() {
- return open(-1); // Camera.CameraInfo.CAMERA_FACING_BACK
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/CleanUtils.java b/DevLibUtils/src/main/java/dev/utils/app/CleanUtils.java
deleted file mode 100644
index d7e6e7c79b..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/CleanUtils.java
+++ /dev/null
@@ -1,233 +0,0 @@
-package dev.utils.app;
-
-import android.os.Environment;
-
-import java.io.File;
-import java.math.BigDecimal;
-
-import dev.DevUtils;
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: 本应用数据清除管理器
- * Created by Ttt
- * 主要功能有清除内/外缓存,清除数据库,清除sharedPreference,清除files和清除自定义目录
- */
-public final class CleanUtils {
-
- private CleanUtils(){
- }
-
- // 日志TAG
- private static final String TAG = CleanUtils.class.getSimpleName();
-
-
- /**
- * 清除本应用内部缓存(/data/data/com.xxx.xxx/cache)
- */
- public static void cleanInternalCache() {
- try {
- deleteFilesByDirectory(DevUtils.getContext().getCacheDir());
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "cleanInternalCache");
- }
- }
-
- /**
- * 清除本应用所有数据库(/data/data/com.xxx.xxx/databases)
- */
- public static void cleanDatabases() {
- try {
- deleteFilesByDirectory(new File(DevUtils.getContext().getFilesDir().getPath() + DevUtils.getContext().getPackageName() + "/databases"));
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "cleanDatabases");
- }
- }
-
- /**
- * 清除本应用SharedPreference(/data/data/com.xxx.xxx/shared_prefs)
- */
- public static void cleanSharedPreference() {
- try {
- deleteFilesByDirectory(new File(DevUtils.getContext().getFilesDir().getPath() + DevUtils.getContext().getPackageName() + "/shared_prefs"));
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "cleanSharedPreference");
- }
- }
-
- /**
- * 按名字清除本应用数据库
- * @param dbName 数据库名称
- */
- public static void cleanDatabaseByName(String dbName) {
- try {
- DevUtils.getContext().deleteDatabase(dbName);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "cleanDatabaseByName");
- }
- }
-
- /**
- * 清除/data/data/com.xxx.xxx/files下的内容
- */
- public static void cleanFiles() {
- try {
- deleteFilesByDirectory(DevUtils.getContext().getFilesDir());
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "cleanFiles");
- }
- }
-
- /**
- * 清除外部cache下的内容(/mnt/sdcard/android/data/com.xxx.xxx/cache)
- */
- public static void cleanExternalCache() {
- try {
- if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
- deleteFilesByDirectory(DevUtils.getContext().getExternalCacheDir());
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "cleanExternalCache");
- }
- }
-
- /**
- * 清除自定义路径下的文件,使用需小心,请不要误删。而且只支持目录下的文件删除
- * @param filePath 文件路径
- */
- public static void cleanCustomCache(String filePath) {
- deleteFilesByDirectory(getFileByPath(filePath));
- }
-
- /**
- * 清除本应用所有的数据
- * @param filePaths 文件路径
- */
- public static void cleanApplicationData(String... filePaths) {
- cleanInternalCache();
- cleanExternalCache();
- cleanDatabases();
- cleanSharedPreference();
- cleanFiles();
- try {
- for (String fPath : filePaths) {
- cleanCustomCache(fPath);
- }
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "cleanApplicationData");
- }
- }
-
- /**
- * 删除方法 这里只会删除某个文件夹下的文件,如果传入的directory是个文件,将不做处理
- * @param directory 文件夹File对象
- */
- private static void deleteFilesByDirectory(File directory) {
- // 存在并且属于文件夹
- if (directory != null && directory.exists() && directory.isDirectory()) {
- try {
- // 获取文件列表
- File[] files = directory.listFiles();
- // 遍历删除文件
- for (File item : files) {
- // 删除文件
- item.delete();
- }
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "deleteFilesByDirectory");
- }
- }
- }
-
- /**
- * 获取文件夹大小
- * Context.getExternalFilesDir() --> SDCard/Android/data/你的应用的包名/files/ 目录,一般放一些长时间保存的数据
- * Context.getExternalCacheDir() --> SDCard/Android/data/你的应用包名/cache/目录,一般存放临时缓存数据
- * @param file
- * @return
- */
- public static long getFolderSize(File file) {
- long size = 0;
- try {
- File[] files = file.listFiles();
- for (int i = 0, len = files.length; i < len; i++) {
- // 如果下面还有文件
- if (files[i].isDirectory()) {
- size = size + getFolderSize(files[i]);
- } else {
- size = size + files[i].length();
- }
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getFolderSize");
- }
- return size;
- }
-
- /**
- * 获取缓存文件大小
- * @param file
- * @return
- */
- public static String getCacheSize(File file){
- return getFormatSize(getFolderSize(file));
- }
-
- /**
- * 格式化单位
- * @param size
- * @return
- */
- public static String getFormatSize(double size) {
- double kiloByte = size / 1024;
- if (kiloByte < 1) {
- return size + "Byte";
- }
-
- double megaByte = kiloByte / 1024;
- if (megaByte < 1) {
- BigDecimal result1 = new BigDecimal(Double.toString(kiloByte));
- return result1.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "KB";
- }
-
- double gigaByte = megaByte / 1024;
- if (gigaByte < 1) {
- BigDecimal result2 = new BigDecimal(Double.toString(megaByte));
- return result2.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "MB";
- }
-
- double teraBytes = gigaByte / 1024;
- if (teraBytes < 1) {
- BigDecimal result3 = new BigDecimal(Double.toString(gigaByte));
- return result3.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "GB";
- }
- BigDecimal result4 = new BigDecimal(teraBytes);
- return result4.setScale(2, BigDecimal.ROUND_HALF_UP).toPlainString() + "TB";
- }
-
- // ==
-
- /**
- * 获取文件
- * @param filePath
- * @return
- */
- private static File getFileByPath(final String filePath){
- return filePath != null ? new File(filePath) : null;
- }
-
- /**
- * 判断字符串是否为 null 或全为空白字符
- * @param str 待校验字符串
- * @return
- */
- private static boolean isSpace(final String str) {
- if (str == null) return true;
- for (int i = 0, len = str.length(); i < len; ++i) {
- if (!Character.isWhitespace(str.charAt(i))) {
- return false;
- }
- }
- return true;
- }
-}
\ No newline at end of file
diff --git a/DevLibUtils/src/main/java/dev/utils/app/ClickUtils.java b/DevLibUtils/src/main/java/dev/utils/app/ClickUtils.java
deleted file mode 100644
index e014e55d2c..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/ClickUtils.java
+++ /dev/null
@@ -1,185 +0,0 @@
-package dev.utils.app;
-
-import java.util.HashMap;
-
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: 点击工具类
- * Created by Ttt
- */
-public final class ClickUtils {
-
- private ClickUtils(){
- }
-
- // 日志TAG
- private static final String TAG = ClickUtils.class.getSimpleName();
-
- // 上一次点击的标识id = viewId 等
- private static int lastTagId = -1;
- /** 上次点击时间 */
- private static long lastClickTime = 0l; // 局限性是, 全局统一事件,如果上次点击后,立刻点击其他就无法点
- /** 默认间隔时间 */
- private static long DF_DIFF = 1000l; // 点击间隔1秒内
- /** 配置数据 */
- private static final HashMap mapConfig = new HashMap<>();
- /** 点击记录数据 */
- private static final HashMap mapRecords = new HashMap<>();
-
- // ===
-
- /**
- * 判断两次点击的间隔 小于默认间隔时间(1秒), 则认为是多次无效点击
- * @return
- */
- public static boolean isFastDoubleClick() {
- return isFastDoubleClick(-1, DF_DIFF);
- }
-
- /**
- * 判断两次点击的间隔 小于默认间隔时间(1秒), 则认为是多次无效点击
- * @param tagId
- * @return
- */
- public static boolean isFastDoubleClick(int tagId) {
- return isFastDoubleClick(tagId, DF_DIFF);
- }
-
- /**
- * 判断两次点击的间隔 小于间隔时间(diff), 则认为是多次无效点击
- * @param tagId
- * @param diff
- * @return
- */
- public static boolean isFastDoubleClick(int tagId, long diff) {
- long cTime = System.currentTimeMillis();
- long dTime = cTime - lastClickTime;
- // 判断时间是否超过
- if (lastTagId == tagId && lastClickTime > 0 && dTime < diff) {
- LogPrintUtils.dTag(TAG, "isFastDoubleClick 无效点击 => tagId: " + tagId + ", diff: " + diff);
- return true;
- }
- LogPrintUtils.dTag(TAG, "isFastDoubleClick 有效点击 => tagId: " + tagId + ", diff: " + diff);
- lastTagId = tagId;
- lastClickTime = cTime;
- return false;
- }
-
- // ===
-
- /**
- * 判断两次点击的间隔(根据默认Tag判断) 小于指定间隔时间, 则认为是多次无效点击
- * @param tag
- * @return
- */
- public static boolean isFastDoubleClick(String tag){
- // 获取配置时间
- Long config_time = mapConfig.get(tag);
- // 如果等于null, 则传入默认时间
- if (config_time == null){
- return isFastDoubleClick(tag, DF_DIFF);
- }
- return isFastDoubleClick(tag, config_time);
- }
-
- /**
- * 判断两次点击的间隔 小于间隔时间(diff), 则认为是多次无效点击
- * @param tag
- * @param diff
- * @return
- */
- public static boolean isFastDoubleClick(String tag, long diff){
- // 获取上次点击的时间
- Long lastTime = mapRecords.get(tag);
- if (lastTime == null){
- lastTime = 0l;
- }
- long cTime = System.currentTimeMillis();
- long dTime = cTime - lastTime;
- // 判断时间是否超过
- if (lastTime > 0 && dTime < diff) {
- LogPrintUtils.dTag(TAG, "isFastDoubleClick 无效点击 => tag: " + tag + ", diff: " + diff);
- return true;
- }
- LogPrintUtils.dTag(TAG, "isFastDoubleClick 有效点击 => tag: " + tag + ", diff: " + diff);
- // 保存上次点击时间
- mapRecords.put(tag, cTime);
- return false;
- }
-
- // ===
-
- /**
- * 判断两次点击的间隔(根据默认Tag判断) 小于指定间隔时间, 则认为是多次无效点击
- * @param obj
- * @return
- */
- public static boolean isFastDoubleClick(Object obj){
- // 获取TAG
- String tag = ((obj != null) ? ("obj_" + obj.hashCode()) : "obj_null");
- // 获取配置时间
- Long config_time = mapConfig.get(tag);
- // 如果等于null, 则传入默认时间
- if (config_time == null){
- return isFastDoubleClick(tag, DF_DIFF);
- }
- return isFastDoubleClick(tag, config_time);
- }
-
- /**
- * 判断两次点击的间隔 小于间隔时间(diff), 则认为是多次无效点击
- * @param obj
- * @param diff
- * @return
- */
- public static boolean isFastDoubleClick(Object obj, long diff){
- // 获取TAG
- String tag = ((obj != null) ? ("obj_" + obj.hashCode()) : "obj_null");
- // 获取上次点击的时间
- Long lastTime = mapRecords.get(tag);
- if (lastTime == null){
- lastTime = 0l;
- }
- long cTime = System.currentTimeMillis();
- long dTime = cTime - lastTime;
- // 判断时间是否超过
- if (lastTime > 0 && dTime < diff) {
- LogPrintUtils.dTag(TAG, "isFastDoubleClick 无效点击 => obj: " + obj + ", diff: " + diff);
- return true;
- }
- LogPrintUtils.dTag(TAG, "isFastDoubleClick 有效点击 => obj: " + obj + ", diff: " + diff);
- // 保存上次点击时间
- mapRecords.put(tag, cTime);
- return false;
- }
-
- // ===
-
- /**
- * 初始化配置信息
- * @param mapConfig
- */
- public static void initConfig(HashMap mapConfig){
- if (mapConfig != null){
- mapConfig.putAll(mapConfig);
- }
- }
-
- /**
- * 添加配置信息
- * @param key
- * @param val
- */
- public static void putConfig(String key, Long val){
- mapConfig.put(key, val);
- }
-
- /**
- * 移除配置信息
- * @param key
- */
- public static void removeConfig(String key){
- mapConfig.remove(key);
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/ClipboardUtils.java b/DevLibUtils/src/main/java/dev/utils/app/ClipboardUtils.java
deleted file mode 100644
index 9dc5d825e5..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/ClipboardUtils.java
+++ /dev/null
@@ -1,122 +0,0 @@
-package dev.utils.app;
-
-import android.content.ClipData;
-import android.content.ClipboardManager;
-import android.content.Context;
-import android.content.Intent;
-import android.net.Uri;
-
-import dev.DevUtils;
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: 剪贴板相关工具类
- * Created by Ttt
- */
-public final class ClipboardUtils {
-
- private ClipboardUtils() {
- }
-
- // 日志TAG
- private static final String TAG = ClipboardUtils.class.getSimpleName();
-
- /**
- * 复制文本到剪贴板
- * @param text
- */
- public static void copyText(final CharSequence text) {
- try {
- ClipboardManager clipManager = (ClipboardManager) DevUtils.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
- // 复制的数据
- ClipData clipData = ClipData.newPlainText("text", text);
- // 设置复制的数据
- clipManager.setPrimaryClip(clipData);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "copyText");
- }
- }
-
- /**
- * 获取剪贴板的文本
- * @return 剪贴板的文本
- */
- public static CharSequence getText() {
- try {
- ClipboardManager clipManager = (ClipboardManager) DevUtils.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
- ClipData clipData = clipManager.getPrimaryClip();
- if (clipData != null && clipData.getItemCount() > 0) {
- return clipData.getItemAt(0).coerceToText(DevUtils.getContext());
- }
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getText");
- }
- return null;
- }
-
- /**
- * 复制uri到剪贴板
- * @param uri
- */
- public static void copyUri(final Uri uri) {
- try {
- ClipboardManager clipManager = (ClipboardManager) DevUtils.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
- // 复制的数据
- ClipData clipData = ClipData.newUri(DevUtils.getContext().getContentResolver(), "", uri);
- // 设置复制的数据
- clipManager.setPrimaryClip(clipData);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "copyUri");
- }
- }
-
- /**
- * 获取剪贴板的uri
- * @return 剪贴板的uri
- */
- public static Uri getUri() {
- try {
- ClipboardManager clipManager = (ClipboardManager) DevUtils.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
- ClipData clipData = clipManager.getPrimaryClip();
- if (clipData != null && clipData.getItemCount() > 0) {
- return clipData.getItemAt(0).getUri();
- }
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getUri");
- }
- return null;
- }
-
- /**
- * 复制意图到剪贴板
- * @param intent 意图
- */
- public static void copyIntent(final Intent intent) {
- try {
- ClipboardManager clipManager = (ClipboardManager) DevUtils.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
- // 复制的数据
- ClipData clipData = ClipData.newIntent("intent", intent);
- // 设置复制的数据
- clipManager.setPrimaryClip(clipData);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "copyIntent");
- }
- }
-
- /**
- * 获取剪贴板的意图
- * @return 剪贴板的意图
- */
- public static Intent getIntent() {
- try {
- ClipboardManager clipManager = (ClipboardManager) DevUtils.getContext().getSystemService(Context.CLIPBOARD_SERVICE);
- ClipData clipData = clipManager.getPrimaryClip();
- if (clipData != null && clipData.getItemCount() > 0) {
- return clipData.getItemAt(0).getIntent();
- }
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getIntent");
- }
- return null;
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/ContentResolverUtils.java b/DevLibUtils/src/main/java/dev/utils/app/ContentResolverUtils.java
deleted file mode 100644
index ca8fcb7d5b..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/ContentResolverUtils.java
+++ /dev/null
@@ -1,124 +0,0 @@
-package dev.utils.app;
-
-import android.content.ContentResolver;
-import android.content.ContentValues;
-import android.content.Intent;
-import android.net.Uri;
-import android.provider.MediaStore;
-import android.text.TextUtils;
-
-import java.io.File;
-
-import dev.DevUtils;
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: ContentResolver 工具类
- * Created by Ttt
- */
-public final class ContentResolverUtils {
-
- // https://blog.csdn.net/lemon_blue/article/details/52353851
- // https://www.cnblogs.com/Sharley/p/7942142.html
-
- private ContentResolverUtils() {
- }
-
- // 日志TAG
- private static final String TAG = ContentResolverUtils.class.getSimpleName();
-
- // MediaStore.MediaColumns.MIME_TYPE, isVideo ? "video/3gp" : "image/jpeg"
-
- /**
- * 通知刷新本地资源
- * @param file
- * @return
- */
- public static boolean notifyMediaStore(File file){
- if (file != null){
- try {
- // 最后通知图库扫描更新
- DevUtils.getContext().sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(file)));
- // 通知成功
- return true;
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "notifyMediaStore");
- }
- }
- return false;
- }
-
- /**
- * 添加图片到系统相册(包含原图、相册图, 会存在两张) - 想要一张, 直接调用 notifyMediaStore()
- * @param file
- * @param fileName
- * @param isNotify
- * @return
- */
- public static boolean insertImageIntoMediaStore(File file, String fileName, boolean isNotify){
- if (file != null){
- try {
- // 添加到相册
- MediaStore.Images.Media.insertImage(DevUtils.getContext().getContentResolver(), file.getAbsolutePath(), TextUtils.isEmpty(fileName) ? file.getName() : fileName, null);
- if (isNotify){
- notifyMediaStore(file);
- }
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "insertImageIntoMediaStore");
- }
- }
- return false;
- }
-
- /**
- * 添加视频到系统相册
- * @param file
- * @return
- */
- public static boolean insertVideoIntoMediaStore(File file){
- return insertIntoMediaStore(file, -1, true, "video/3gp");
- }
-
- /**
- * 保存到系统相册
- * @param file
- * @param createTime
- * @param isVideo
- * @param mimeType
- */
- public static boolean insertIntoMediaStore(File file, long createTime, boolean isVideo, String mimeType) {
- if (file != null && !TextUtils.isEmpty(mimeType)) {
- try {
- ContentResolver mContentResolver = DevUtils.getContext().getContentResolver();
- // 防止创建时间为null
- if (createTime <= 0)
- createTime = System.currentTimeMillis();
-
- ContentValues values = new ContentValues();
- values.put(MediaStore.MediaColumns.TITLE, file.getName());
- values.put(MediaStore.MediaColumns.DISPLAY_NAME, file.getName());
- // 值一样,但是还是用常量区分对待
- values.put(isVideo ? MediaStore.Video.VideoColumns.DATE_TAKEN : MediaStore.Images.ImageColumns.DATE_TAKEN, createTime);
- values.put(MediaStore.MediaColumns.DATE_MODIFIED, System.currentTimeMillis());
- values.put(MediaStore.MediaColumns.DATE_ADDED, System.currentTimeMillis());
- if (!isVideo)
- values.put(MediaStore.Images.ImageColumns.ORIENTATION, 0);
- // 文件路径
- values.put(MediaStore.MediaColumns.DATA, file.getAbsolutePath());
- // 文件大小
- values.put(MediaStore.MediaColumns.SIZE, file.length());
- // 文件类型
- values.put(MediaStore.MediaColumns.MIME_TYPE, mimeType);
- // 生成所属的URI资源
- Uri uri = mContentResolver.insert(isVideo ? MediaStore.Video.Media.EXTERNAL_CONTENT_URI : MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
- // 最后通知图库更新
- DevUtils.getContext().sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri));
- // 表示成功
- return true;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "insertIntoMediaStore");
- }
- }
- return false;
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/DBUtils.java b/DevLibUtils/src/main/java/dev/utils/app/DBUtils.java
deleted file mode 100644
index 8684b62fe6..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/DBUtils.java
+++ /dev/null
@@ -1,111 +0,0 @@
-package dev.utils.app;
-
-import android.os.Environment;
-
-import java.io.InputStream;
-
-import dev.DevUtils;
-import dev.utils.LogPrintUtils;
-import dev.utils.common.FileUtils;
-
-/**
- * detail: 数据库工具类 (导入导出等)
- * Created by Ttt
- */
-public final class DBUtils {
-
- private DBUtils() {
- }
-
- // 日志TAG
- private static final String TAG = DBUtils.class.getSimpleName();
-
- /**
- * 导出数据库
- * @param targetFile 目标文件
- * @param dbName 数据库文件名
- * @return 是否倒出成功
- */
- public static boolean startExportDatabase(String targetFile, String dbName) {
- // 判断 SDCard 是否挂载
- if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
- return false;
- }
- try {
- // Database 文件地址
- String sourceFilePath = getDBPath() + dbName;
- // 获取结果
- boolean result = FileUtils.copyFile(sourceFilePath, targetFile, true);
- // 返回结果
- return result;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "startExportDatabase");
- }
- return false;
- }
-
- // ====
-
- /**
- * 导入数据库
- * @param srcFilePath 待复制的文件地址
- * @param destFilePath 目标文件地址
- * @return 是否倒出成功
- */
- public static boolean startImportDatabase(String srcFilePath, String destFilePath){
- // 判断 SDCard 是否挂载
- if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
- return false;
- }
- try {
- // 获取结果
- boolean result = FileUtils.copyFile(srcFilePath, destFilePath, true);
- // 返回结果
- return result;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "startImportDatabase");
- }
- return false;
- }
-
- /**
- * 导入数据库
- * @param inputStream 文件流(被复制)
- * @param destFilePath 目标文件地址
- * @return 是否倒出成功
- */
- public static boolean startImportDatabase(InputStream inputStream, String destFilePath){
- // 判断 SDCard 是否挂载
- if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) {
- return false;
- }
- try {
- // 获取结果
- boolean result = FileUtils.copyFile(inputStream, destFilePath, true);
- // 返回结果
- return result;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "startImportDatabase");
- }
- return false;
- }
-
- // ==
-
- /**
- * 获取数据库路径
- * @return
- */
- public static String getDBPath(){
- try {
- // Database 文件地址
- String dbPath = Environment.getDataDirectory() + "/data/" + DevUtils.getContext().getPackageName() + "/databases/";
- // 返回数据库路径
- return dbPath;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getDBPath");
- }
- return null;
- }
-
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/DeviceUtils.java b/DevLibUtils/src/main/java/dev/utils/app/DeviceUtils.java
deleted file mode 100644
index dc3ed1e512..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/DeviceUtils.java
+++ /dev/null
@@ -1,504 +0,0 @@
-package dev.utils.app;
-
-import android.annotation.SuppressLint;
-import android.content.Context;
-import android.content.Intent;
-import android.net.wifi.WifiInfo;
-import android.net.wifi.WifiManager;
-import android.os.Build;
-import android.os.PowerManager;
-import android.provider.Settings;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.net.InetAddress;
-import java.net.NetworkInterface;
-import java.util.Arrays;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Locale;
-import java.util.Map;
-
-import dev.DevUtils;
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: 设备相关工具类
- * Created by Ttt
- */
-public final class DeviceUtils {
-
- private DeviceUtils() {
- }
-
- // 日志TAG
- private static final String TAG = DBUtils.class.getSimpleName();
-
-// // http://blog.csdn.net/zhangcanyan/article/details/52817866
-// android.os.Build.BOARD:获取设备基板名称
-// android.os.Build.BOOTLOADER:获取设备引导程序版本号
-// android.os.Build.BRAND:获取设备品牌
-// android.os.Build.CPU_ABI:获取设备指令集名称(CPU的类型)
-// android.os.Build.CPU_ABI2:获取第二个指令集名称
-// android.os.Build.DEVICE:获取设备驱动名称
-// android.os.Build.DISPLAY:获取设备显示的版本包(在系统设置中显示为版本号)和ID一样
-// android.os.Build.FINGERPRINT:设备的唯一标识。由设备的多个信息拼接合成。
-// android.os.Build.HARDWARE:设备硬件名称,一般和基板名称一样(BOARD)
-// android.os.Build.HOST:设备主机地址
-// android.os.Build.ID:设备版本号。
-// android.os.Build.MODEL :获取手机的型号 设备名称。
-// android.os.Build.MANUFACTURER:获取设备制造商
-// android:os.Build.PRODUCT:整个产品的名称
-// android:os.Build.RADIO:无线电固件版本号,通常是不可用的 显示unknown
-// android.os.Build.TAGS:设备标签。如release-keys 或测试的 test-keys
-// android.os.Build.TIME:时间
-// android.os.Build.TYPE:设备版本类型 主要为"user" 或"eng".
-// android.os.Build.USER:设备用户名 基本上都为android-build
-// android.os.Build.VERSION.RELEASE:获取系统版本字符串。如4.1.2 或2.2 或2.3等
-// android.os.Build.VERSION.CODENAME:设备当前的系统开发代号,一般使用REL代替
-// android.os.Build.VERSION.INCREMENTAL:系统源代码控制值,一个数字或者git hash值
-// android.os.Build.VERSION.SDK:系统的API级别 一般使用下面大的SDK_INT 来查看
-// android.os.Build.VERSION.SDK_INT:系统的API级别 数字表示
-
- /** 换行字符串 */
- private static final String NEW_LINE_STR = System.getProperty("line.separator");
-
- /**
- * 获取当前操作系统的语言
- * @return String 系统语言
- */
- public static String getSysLanguage() {
- String language = Locale.getDefault().getLanguage();
- return language;
- }
-
- /**
- * 获取设备信息
- * @param dInfoMaps 传入设备信息传出HashMap
- */
- public static void getDeviceInfo(HashMap dInfoMaps) {
- // 获取设备信息类的所有申明的字段,即包括public、private和proteced, 但是不包括父类的申明字段。
- Field[] fields = Build.class.getDeclaredFields();
- // 遍历字段
- for (Field field : fields) {
- try {
- // 取消java的权限控制检查
- field.setAccessible(true);
- // 获取类型对应字段的数据,并保存
- dInfoMaps.put(field.getName(), field.get(null).toString());
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getDeviceInfo");
- }
- }
- }
-
- /**
- * 获取设备信息
- * @param dInfoMaps 传入设备信息传出HashMap
- */
- public static void getDeviceInfo2(HashMap dInfoMaps) {
- // 获取设备信息类的所有申明的字段,即包括public、private和proteced, 但是不包括父类的申明字段。
- Field[] fields = Build.class.getDeclaredFields();
- // 遍历字段
- for (Field field : fields) {
- try {
- // 取消java的权限控制检查
- field.setAccessible(true);
-
- if (field.getName().toLowerCase().equals("SUPPORTED_ABIS".toLowerCase())) {
- Object object = field.get(null);
- // 判断是否数组
- if (object instanceof String[]) {
- // 获取类型对应字段的数据,并保存 - 保存支持的指令集 [arm64-v8a, armeabi-v7a, armeabi]
- dInfoMaps.put(field.getName().toLowerCase(), Arrays.toString((String[]) object));
- continue;
- }
- }
- // 获取类型对应字段的数据,并保存
- dInfoMaps.put(field.getName().toLowerCase(), field.get(null).toString());
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getDeviceInfo2");
- }
- }
- }
-
- /**
- * 处理设备信息
- * @param dInfoMaps 设备信息
- * @param eHint 错误提示,如获取设备信息失败
- */
- public static String handleDeviceInfo(HashMap dInfoMaps, String eHint) {
- try {
- // 初始化StringBuilder,拼接字符串
- StringBuilder sBuilder = new StringBuilder();
- // 获取设备信息
- Iterator> mapIter = dInfoMaps.entrySet().iterator();
- // 遍历设备信息
- while (mapIter.hasNext()) {
- // 获取对应的key-value
- Map.Entry rnEntry = (Map.Entry) mapIter.next();
- String rnKey = (String) rnEntry.getKey(); // key
- String rnValue = (String) rnEntry.getValue(); // value
- // 保存设备信息
- sBuilder.append(rnKey);
- sBuilder.append(" = ");
- sBuilder.append(rnValue);
- sBuilder.append(NEW_LINE_STR);
- }
- return sBuilder.toString();
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "handleDeviceInfo");
- }
- return eHint;
- }
-
- /**
- * 获取设备系统版本号
- * @return 设备系统版本号
- */
- public static String getSDKVersionName() {
- return Build.VERSION.RELEASE;
- }
-
- /**
- * 获取当前SDK 版本号
- * @return
- */
- public static int getSDKVersion(){
- return Build.VERSION.SDK_INT;
- }
-
- /**
- * 获取Android id
- * hint:
- * 在设备首次启动时,系统会随机生成一个64位的数字,并把这个数字以16进制字符串的形式保存下来,这个16进制的字符串就是ANDROID_ID,当设备被wipe后该值会被重置。
- * @return
- */
- public static String getAndroidId(){
- // Android id 默认为null
- String androidId = null;
- try {
- androidId = Settings.Secure.getString(DevUtils.getContext().getContentResolver(), Settings.Secure.ANDROID_ID);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getAndroidId");
- }
- return androidId;
- }
-
- /**
- * 判断设备是否 root
- * @return
- */
- public static boolean isDeviceRooted() {
- String su = "su";
- String[] locations = { "/system/bin/", "/system/xbin/", "/sbin/", "/system/sd/xbin/",
- "/system/bin/failsafe/", "/data/local/xbin/", "/data/local/bin/", "/data/local/" };
- for (String location : locations) {
- if (new File(location + su).exists()) {
- return true;
- }
- }
- return false;
- }
-
- // ==
-
- /** 特殊mac地址用于判断是否获取失败 */
- private static final String CUSTOM_MAC = "02:00:00:00:00:00";
-
- /**
- * 获取设备 MAC 地址
- * hint:
- * 需添加权限
- * 需添加权限
- * @return
- */
- public static String getMacAddress() {
- String macAddress = getMacAddressByWifiInfo();
- if (!CUSTOM_MAC.equals(macAddress)) {
- return macAddress;
- }
- macAddress = getMacAddressByNetworkInterface();
- if (!CUSTOM_MAC.equals(macAddress)) {
- return macAddress;
- }
- macAddress = getMacAddressByInetAddress();
- if (!CUSTOM_MAC.equals(macAddress)) {
- return macAddress;
- }
- macAddress = getMacAddressByFile();
- if (!CUSTOM_MAC.equals(macAddress)) {
- return macAddress;
- }
- // 没有打开wifi, 获取 WLAN MAC 地址失败
- return null;
- }
-
- /**
- * 获取设备 MAC 地址
- * hint:
- * 需添加权限
- * @return
- */
- @SuppressLint({"HardwareIds", "MissingPermission"})
- private static String getMacAddressByWifiInfo() {
- try {
- @SuppressLint("WifiManagerLeak")
- WifiManager wifiManager = (WifiManager) DevUtils.getContext().getSystemService(Context.WIFI_SERVICE);
- if (wifiManager != null) {
- WifiInfo wifiInfo = wifiManager.getConnectionInfo();
- if (wifiInfo != null) return wifiInfo.getMacAddress();
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getMacAddressByWifiInfo");
- }
- return CUSTOM_MAC;
- }
-
- /**
- * 获取设备 MAC 地址
- * hint:
- * 需添加权限
- * @return
- */
- private static String getMacAddressByNetworkInterface() {
- try {
- Enumeration nis = NetworkInterface.getNetworkInterfaces();
- while (nis.hasMoreElements()) {
- NetworkInterface ni = nis.nextElement();
- if (ni == null || !ni.getName().equalsIgnoreCase("wlan0")) continue;
- byte[] macBytes = ni.getHardwareAddress();
- if (macBytes != null && macBytes.length > 0) {
- StringBuilder sb = new StringBuilder();
- for (byte b : macBytes) {
- sb.append(String.format("%02x:", b));
- }
- return sb.substring(0, sb.length() - 1);
- }
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getMacAddressByNetworkInterface");
- }
- return CUSTOM_MAC;
- }
-
- private static String getMacAddressByInetAddress() {
- try {
- InetAddress inetAddress = getInetAddress();
- if (inetAddress != null) {
- NetworkInterface ni = NetworkInterface.getByInetAddress(inetAddress);
- if (ni != null) {
- byte[] macBytes = ni.getHardwareAddress();
- if (macBytes != null && macBytes.length > 0) {
- StringBuilder sb = new StringBuilder();
- for (byte b : macBytes) {
- sb.append(String.format("%02x:", b));
- }
- return sb.substring(0, sb.length() - 1);
- }
- }
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getMacAddressByInetAddress");
- }
- return "02:00:00:00:00:00";
- }
-
- private static InetAddress getInetAddress() {
- try {
- Enumeration nis = NetworkInterface.getNetworkInterfaces();
- while (nis.hasMoreElements()) {
- NetworkInterface ni = nis.nextElement();
- // To prevent phone of xiaomi return "10.0.2.15"
- if (!ni.isUp()) continue;
- Enumeration addresses = ni.getInetAddresses();
- while (addresses.hasMoreElements()) {
- InetAddress inetAddress = addresses.nextElement();
- if (!inetAddress.isLoopbackAddress()) {
- String hostAddress = inetAddress.getHostAddress();
- if (hostAddress.indexOf(':') < 0) return inetAddress;
- }
- }
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getInetAddress");
- }
- return null;
- }
-
- /**
- * 获取设备 MAC 地址
- * @return MAC 地址
- */
- private static String getMacAddressByFile() {
- ShellUtils.CommandResult result = ShellUtils.execCmd("getprop wifi.interface", false);
- if (result.result == 0) {
- String name = result.successMsg;
- if (name != null) {
- result = ShellUtils.execCmd("cat /sys/class/net/" + name + "/address", false);
- if (result.result == 0) {
- String address = result.successMsg;
- if (address != null && address.length() > 0) {
- return address;
- }
- }
- }
- }
- return CUSTOM_MAC;
- }
-
- // ==
-
- /**
- * 获取设备厂商 如 Xiaomi
- * @return 设备厂商
- */
- public static String getManufacturer() {
- return Build.MANUFACTURER;
- }
-
- /**
- * 获取设备型号 如 RedmiNote4X
- * @return 设备型号
- */
- public static String getModel() {
- String model = Build.MODEL;
- if (model != null) {
- model = model.trim().replaceAll("\\s*", "");
- } else {
- model = "";
- }
- return model;
- }
-
- /**
- * 关机 需要 root 权限或者系统权限
- * @return
- */
- public static boolean shutdown() {
- try {
- ShellUtils.execCmd("reboot -p", true);
- Intent intent = new Intent("android.intent.action.ACTION_REQUEST_SHUTDOWN");
- intent.putExtra("android.intent.extra.KEY_CONFIRM", false);
- DevUtils.getContext().startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
- return true;
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "shutdown");
- }
- return false;
- }
-
- /**
- * 重启 需要 root 权限或者系统权限
- * @return
- */
- public static boolean reboot() {
- try {
- ShellUtils.execCmd("reboot", true);
- Intent intent = new Intent(Intent.ACTION_REBOOT);
- intent.putExtra("nowait", 1);
- intent.putExtra("interval", 1);
- intent.putExtra("window", 0);
- DevUtils.getContext().sendBroadcast(intent);
- return true;
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "reboot");
- }
- return false;
- }
-
- /**
- * 重启
- * 需系统权限
- * @param reason 传递给内核来请求特殊的引导模式,如"recovery"
- */
- public static void reboot(final String reason) {
- try {
- PowerManager mPowerManager = (PowerManager) DevUtils.getContext().getSystemService(Context.POWER_SERVICE);
- if (mPowerManager == null)
- return;
- mPowerManager.reboot(reason);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "reboot");
- }
- }
-
- /** 重启到 recovery 需要 root 权限 */
- public static void reboot2Recovery() {
- ShellUtils.execCmd("reboot recovery", true);
- }
-
- /** 重启到 bootloader 需要 root 权限 */
- public static void reboot2Bootloader() {
- ShellUtils.execCmd("reboot bootloader", true);
- }
-
- /**
- * BASEBAND-VER
- * 基带版本
- * return String
- */
- public static String getBaseband_Ver() {
- String Version = "";
- try {
- Class cl = Class.forName("android.os.SystemProperties");
- Object invoker = cl.newInstance();
- Method m = cl.getMethod("get", new Class[]{String.class, String.class});
- Object result = m.invoke(invoker, new Object[]{"gsm.version.baseband", "no message"});
- Version = (String) result;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getBaseband_Ver");
- }
- return Version;
- }
-
- /**
- * CORE-VER
- * 内核版本
- * return String
- */
- public static String getLinuxCore_Ver() {
- String kernelVersion = "";
- try {
- Process process = null;
- try {
- process = Runtime.getRuntime().exec("cat /proc/version");
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getLinuxCore_Ver - Process");
- }
- InputStream outs = process.getInputStream();
- InputStreamReader isrout = new InputStreamReader(outs);
- BufferedReader brout = new BufferedReader(isrout, 8 * 1024);
-
- String result = "";
- String line;
- try {
- while ((line = brout.readLine()) != null) {
- result += line;
- }
- } catch (IOException e) {
- LogPrintUtils.eTag(TAG, e, "getLinuxCore_Ver - readLine");
- }
- try {
- if (result != "") {
- String Keyword = "version ";
- int index = result.indexOf(Keyword);
- line = result.substring(index + Keyword.length());
- index = line.indexOf(" ");
- kernelVersion = line.substring(0, index);
- }
- } catch (IndexOutOfBoundsException e) {
- LogPrintUtils.eTag(TAG, e, "getLinuxCore_Ver - substring");
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getLinuxCore_Ver");
- }
- return kernelVersion;
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/DialogUtils.java b/DevLibUtils/src/main/java/dev/utils/app/DialogUtils.java
deleted file mode 100644
index f67edc7a4b..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/DialogUtils.java
+++ /dev/null
@@ -1,129 +0,0 @@
-package dev.utils.app;
-
-import android.app.Dialog;
-import android.app.ProgressDialog;
-import android.content.Context;
-import android.widget.PopupWindow;
-
-/**
- * detail: Dialog 操作相关工具类
- * Created by Ttt
- */
-public final class DialogUtils {
-
- private DialogUtils(){
- }
-
- // ======== Dialog 相关 ========
-
- /**
- * 关闭Dialog
- * @param dialog
- */
- public static void closeDialog(Dialog dialog){
- if (dialog != null && dialog.isShowing()){
- dialog.dismiss();
- }
- }
-
- /**
- * 关闭多个Dialog
- * @param dialogs
- */
- public static void closeDialogs(Dialog... dialogs){
- if (dialogs != null && dialogs.length != 0){
- for (int i = 0, len = dialogs.length; i < len; i++){
- // 获取Dialog
- Dialog dialog = dialogs[i];
- // 关闭Dialog
- if (dialog != null && dialog.isShowing()){
- dialog.dismiss();
- }
- }
- }
- }
-
- /**
- * 关闭PopupWindow
- * @param popupWindow
- */
- public static void closePopupWindow(PopupWindow popupWindow){
- if (popupWindow != null && popupWindow.isShowing()){
- popupWindow.dismiss();
- }
- }
-
- /**
- * 关闭多个PopupWindow
- * @param popupWindows
- */
- public static void closePopupWindows(PopupWindow... popupWindows){
- if (popupWindows != null && popupWindows.length != 0){
- for (int i = 0, len = popupWindows.length; i < len; i++){
- // 获取Dialog
- PopupWindow popupWindow = popupWindows[i];
- // 关闭Dialog
- if (popupWindow != null && popupWindow.isShowing()){
- popupWindow.dismiss();
- }
- }
- }
- }
-
- // ==
-
- /**
- * 创建加载 Dialog
- * @param context
- * @param title
- * @param content
- * @return
- */
- public static ProgressDialog creDialog(Context context, String title, String content){
- return creDialog(context, title, content, false);// 不可以使用返回键
- }
-
- /**
- * 创建加载 Dialog
- * @param context
- * @param title
- * @param content
- * @param isCancel
- * @return
- */
- public static ProgressDialog creDialog(Context context, String title, String content, boolean isCancel){
- ProgressDialog progressDialog = android.app.ProgressDialog.show(context, title, content);
- progressDialog.setCancelable(isCancel);
- return progressDialog;
- }
-
- /**
- * 创建自动关闭dialog
- * @param context
- * @param title
- * @param content
- * @return
- */
- public static ProgressDialog creAutoCloseDialog(Context context, String title, String content){
- final ProgressDialog progressDialog = android.app.ProgressDialog.show(context, title, content);
- progressDialog.setCancelable(false);
- Thread thread = new Thread(new Runnable() {
- @Override
- public void run() {
- try {
- // 显示10秒后,取消 ProgressDialog
- Thread.sleep(10000);
- } catch (InterruptedException e) {
- }
- try {
- if (progressDialog != null) {
- progressDialog.dismiss();
- }
- } catch (Exception e) {
- }
- }
- });
- thread.start();
- return progressDialog;
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/EditTextUtils.java b/DevLibUtils/src/main/java/dev/utils/app/EditTextUtils.java
deleted file mode 100644
index 7745d80fb1..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/EditTextUtils.java
+++ /dev/null
@@ -1,374 +0,0 @@
-package dev.utils.app;
-
-import android.text.Editable;
-import android.text.InputFilter;
-import android.text.InputType;
-import android.text.TextUtils;
-import android.text.TextWatcher;
-import android.text.method.DigitsKeyListener;
-import android.text.method.KeyListener;
-import android.widget.EditText;
-
-import java.util.UUID;
-
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: EditText 工具类
- * Created by Ttt
- */
-public final class EditTextUtils {
-
- private EditTextUtils(){
- }
-
- // 日志TAG
- private static final String TAG = EditTextUtils.class.getSimpleName();
-
- // https://blog.csdn.net/zhoujn90/article/details/44983905
-
- // 设置是否显示光标
- // editText.setCursorVisible(true);
-
- /**
- * 设置长度限制,并且设置内容
- * @param editText
- * @param content
- * @param maxLength
- * @return
- */
- public static EditText setMaxLengthAnText(EditText editText, String content, int maxLength){
- if (editText != null){
- // 设置长度限制, 并且设置内容
- setText(setMaxLength(editText, maxLength), content);
- }
- return editText;
- }
-
- /**
- * 设置长度限制
- * @param editText
- * @param maxLength
- * @return
- */
- public static EditText setMaxLength(EditText editText, int maxLength){
- if (editText != null){
- if (maxLength > 0){
- // 设置最大长度限制
- InputFilter[] filters = { new InputFilter.LengthFilter(maxLength) };
- editText.setFilters(filters);
- }
- }
- return editText;
- }
-
- /**
- * 获取光标位置
- * @param editText
- * @return
- */
- public static int getSelectionStart(EditText editText){
- if (editText != null){
- return editText.getSelectionStart();
- }
- return 0;
- }
-
- /**
- * 获取输入的内容
- * @param editText
- * @return
- */
- public static String getText(EditText editText){
- if (editText != null){
- return editText.getText().toString();
- }
- return "";
- }
-
- /**
- * 获取输入的内容长度
- * @param editText
- * @return
- */
- public static int getTextLength(EditText editText){
- return getText(editText).length();
- }
-
- // =
-
- /**
- * 设置内容
- * @param editText
- * @param content
- */
- public static EditText setText(EditText editText, String content){
- return setText(editText, content, true);
- }
-
- /**
- * 设置内容
- * @param editText
- * @param content
- * @param isSelect 是否设置光标
- */
- public static EditText setText(EditText editText, String content, boolean isSelect){
- if (editText != null){
- if (content != null){
- // 设置文本
- editText.setText(content);
- if (isSelect){
- // 设置光标
- editText.setSelection(editText.getText().toString().length());
- }
- }
- }
- return editText;
- }
-
- /**
- * 追加内容 - 当前光标位置追加
- * @param editText
- * @param content
- * @param isSelect
- * @return
- */
- public static EditText insert(EditText editText, String content, boolean isSelect){
- if (editText != null){
- return insert(editText, content, editText.getSelectionStart(), isSelect);
- }
- return editText;
- }
-
- /**
- * 追加内容
- * @param editText
- * @param content
- * @param start 开始添加的位置
- * @param isSelect
- * @return
- */
- public static EditText insert(EditText editText, String content, int start, boolean isSelect){
- if (editText != null){
- if (!TextUtils.isEmpty(content)){
- try {
- Editable editable = editText.getText();
- // 在指定位置 追加内容
- editable.insert(start, content);
- // 判断是否选中
- if (isSelect){
- // 设置光标
- editText.setSelection(editText.getText().toString().length());
- }
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "insert");
- }
- }
- }
- return editText;
- }
-
- // ==
-
- /**
- * 设置光标在第一位
- * @param editText
- * @return
- */
- public static EditText setSelectTop(EditText editText){
- return setSelect(editText, 0);
- }
-
- /**
- * 设置光标在最后一位
- * @param editText
- * @return
- */
- public static EditText setSelectBottom(EditText editText){
- if (editText != null){
- // 设置光标
- editText.setSelection(editText.getText().toString().length());
- }
- return editText;
- }
-
- /**
- * 设置光标位置
- * @param editText
- * @param select
- * @return
- */
- public static EditText setSelect(EditText editText, int select){
- if (editText != null){
- if (select >= 0){
- // 判断是否超过限制
- int length = editText.getText().toString().length();
- // 如果超过长度, 则设置最后
- if (select > length){
- // 设置光标
- editText.setSelection(length);
- } else {
- // 设置光标
- editText.setSelection(select);
- }
- }
- }
- return editText;
- }
-
- // =
-
- /**
- * 设置输入限制
- * @param editText
- * @param keyListener
- * @return
- * setKeyListener(editText, getNumberAndEnglishKeyListener());
- */
- public static EditText setKeyListener(EditText editText, KeyListener keyListener){
- if (editText != null){
- editText.setKeyListener(keyListener);
- }
- return editText;
- }
-
- /**
- * 设置输入限制
- * @param editText
- * @param digits 只能输入的内容 -> 1234567890
- * @return
- * setKeyListener(editText, "1234567890");
- */
- public static EditText setKeyListener(EditText editText, String digits){
- if (editText != null){
- if (TextUtils.isEmpty(digits)){
- editText.setKeyListener(null);
- } else {
- editText.setKeyListener(DigitsKeyListener.getInstance(digits));
- }
- }
- return editText;
- }
-
-
- // =============== 输入法Key Listener 快捷处理 ==========================
-
- /**
- * 限制只能输入字母和数字,默认弹出英文输入法
- * @return
- */
- public static DigitsKeyListener getNumberAndEnglishKeyListener() {
- /** 限制只能输入字母和数字,默认弹出英文输入法 */
- DigitsKeyListener digitsKeyListener = new DigitsKeyListener() {
- @Override
- public int getInputType() {
- return InputType.TYPE_TEXT_VARIATION_PASSWORD;
- }
-
- @Override
- protected char[] getAcceptedChars() {
- char[] data = "qwertyuioplkjhgfdsazxcvbnmQWERTYUIOPLKJHGFDSAZXCVBNM1234567890".toCharArray();
- return data;
- }
- };
- return digitsKeyListener;
- }
-
- /**
- * 限制只能输入数字,默认弹出数字列表
- * @return
- */
- public static DigitsKeyListener getNumberKeyListener() {
- /** 限制只能输入数字,默认弹出数字列表 */
- DigitsKeyListener digitsKeyListener = new DigitsKeyListener() {
- @Override
- public int getInputType() {
- return InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_NORMAL;
- }
-
- @Override
- protected char[] getAcceptedChars() {
- char[] data = "1234567890".toCharArray();
- return data;
- }
- };
- return digitsKeyListener;
- }
-
- // ==
-
- // https://blog.csdn.net/zhuwentao2150/article/details/51546773
-
- // editText.addTextChangedListener(DevTextWatcher);
-
- /**
- * detail: 开发输入监听抽象类
- * Created by Ttt
- */
- public static abstract class DevTextWatcher implements TextWatcher {
-
- // 标记id - 一定程度上唯一
- private final int markId;
- // 判断是否操作中 - 操作状态 -> 如果是否使用搜索数据等
- private boolean isOperate = false;
- // 标记状态, 特殊需求处理
- private int operateState = -1;
-
- public DevTextWatcher(){
- // 初始化id
- this.markId = UUID.randomUUID().hashCode();
- }
-
- public final int getMarkId() {
- return markId;
- }
-
- public final boolean isOperate() {
- return isOperate;
- }
-
- public final void setOperate(boolean operate) {
- isOperate = operate;
- }
-
- public final int getOperateState() {
- return operateState;
- }
-
- public final void setOperateState(int operateState) {
- this.operateState = operateState;
- }
-
- // == 回调接口 ==
-
- /**
- * 在文本变化前调用
- * @param s
- * @param start
- * @param count
- * @param after
- */
- @Override
- public void beforeTextChanged(CharSequence s, int start, int count, int after) {
- }
-
- /**
- * 在文本变化后调用
- * @param s
- * @param start
- * @param before
- * @param count
- */
- @Override
- public void onTextChanged(CharSequence s, int start, int before, int count) {
- }
-
- /**
- * 在文本变化后调用
- * @param s
- */
- @Override
- public void afterTextChanged(Editable s) {
- }
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/EncodeUtils.java b/DevLibUtils/src/main/java/dev/utils/app/EncodeUtils.java
deleted file mode 100644
index 403426b8e8..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/EncodeUtils.java
+++ /dev/null
@@ -1,192 +0,0 @@
-package dev.utils.app;
-
-import android.os.Build;
-import android.text.Html;
-import android.util.Base64;
-
-import java.net.URLDecoder;
-import java.net.URLEncoder;
-
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: 编码工具类
- * Created by Ttt
- */
-public final class EncodeUtils {
-
- private EncodeUtils() {
- }
-
- // 日志TAG
- private static final String TAG = EncodeUtils.class.getSimpleName();
-
- /**
- * url编码 - UTF-8
- * @param input The input.
- * @return the urlencoded string
- */
- public static String urlEncode(final String input) {
- return urlEncode(input, "UTF-8");
- }
-
- /**
- * url编码
- * @param input The input.
- * @param charsetName The name of charset.
- * @return the urlencoded string
- */
- public static String urlEncode(final String input, final String charsetName) {
- try {
- return URLEncoder.encode(input, charsetName);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "urlEncode");
- return null;
- }
- }
-
- /**
- * url 解码 - UTF-8
- * @param input The input.
- * @return the string of decode urlencoded string
- */
- public static String urlDecode(final String input) {
- return urlDecode(input, "UTF-8");
- }
-
- /**
- * url 解码
- * @param input The input.
- * @param charsetName The name of charset.
- * @return the string of decode urlencoded string
- */
- public static String urlDecode(final String input, final String charsetName) {
- try {
- return URLDecoder.decode(input, charsetName);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "urlDecode");
- return null;
- }
- }
-
-// CRLF 这个参数看起来比较眼熟,它就是Win风格的换行符,意思就是使用CR LF这一对作为一行的结尾而不是Unix风格的LF
-//
-// DEFAULT 这个参数是默认,使用默认的方法来加密
-//
-// NO_PADDING 这个参数是略去加密字符串最后的”=”
-//
-// NO_WRAP 这个参数意思是略去所有的换行符(设置后CRLF就没用了)
-//
-// URL_SAFE 这个参数意思是加密时不使用对URL和文件名有特殊意义的字符来作为加密字符,具体就是以-和_取代+和/
-
- /**
- * base64 编码 => 去除\n 替换 + 和 - 号
- * @param input The input.
- * @return Base64-encode bytes
- */
- public static byte[] base64Encode(final String input) {
- return base64Encode(input.getBytes());
- }
-
- /**
- * base64 编码
- * @param input The input.
- * @return Base64-encode bytes
- */
- public static byte[] base64Encode(final byte[] input) {
- return Base64.encode(input, Base64.NO_WRAP);
- }
-
- /**
- * base64 编码
- * @param input The input.
- * @return Base64-encode string
- */
- public static String base64Encode2String(final byte[] input) {
- return Base64.encodeToString(input, Base64.NO_WRAP);
- }
-
- /**
- * base64 解码
- * @param input The input.
- * @return the string of decode Base64-encode string
- */
- public static byte[] base64Decode(final String input) {
- return Base64.decode(input, Base64.NO_WRAP);
- }
-
- /**
- * base64 解码
- * @param input The input.
- * @return the bytes of decode Base64-encode bytes
- */
- public static byte[] base64Decode(final byte[] input) {
- return Base64.decode(input, Base64.NO_WRAP);
- }
-
- /**
- * base64 解码
- * @param input
- * @return
- */
- public static String base64DecodeToString(final byte[] input) {
- try {
- return new String(base64Decode(input));
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "base64DecodeToString");
- }
- return null;
- }
-
- /**
- * html编码
- * @param input The input.
- * @return html-encode string
- */
- public static String htmlEncode(final CharSequence input) {
- StringBuilder sb = new StringBuilder();
- char c;
- for (int i = 0, len = input.length(); i < len; i++) {
- c = input.charAt(i);
- switch (c) {
- case '<':
- sb.append("<"); //$NON-NLS-1$
- break;
- case '>':
- sb.append(">"); //$NON-NLS-1$
- break;
- case '&':
- sb.append("&"); //$NON-NLS-1$
- break;
- case '\'':
- //http://www.w3.org/TR/xhtml1
- // The named character reference ' (the apostrophe, U+0027) was
- // introduced in XML 1.0 but does not appear in HTML. Authors should
- // therefore use ' instead of ' to work as expected in HTML 4
- // user agents.
- sb.append("'"); //$NON-NLS-1$
- break;
- case '"':
- sb.append("""); //$NON-NLS-1$
- break;
- default:
- sb.append(c);
- }
- }
- return sb.toString();
- }
-
- /**
- * html解码
- * @param input The input.
- * @return the string of decode html-encode string
- */
- @SuppressWarnings("deprecation")
- public static CharSequence htmlDecode(final String input) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
- return Html.fromHtml(input, Html.FROM_HTML_MODE_LEGACY);
- } else {
- return Html.fromHtml(input);
- }
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/ErrorUtils.java b/DevLibUtils/src/main/java/dev/utils/app/ErrorUtils.java
deleted file mode 100644
index ff8ca24f5a..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/ErrorUtils.java
+++ /dev/null
@@ -1,133 +0,0 @@
-package dev.utils.app;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.io.Writer;
-
-/**
- * detail: 错误信息处理工具类
- * Created by Ttt
- */
-public final class ErrorUtils {
-
- private ErrorUtils(){
- }
-
- /** 换行字符串 */
- private static final String NEW_LINE_STR = System.getProperty("line.separator");
- /** 换行字符串 - 两行 */
- private static final String NEW_LINE_STR_X2 = NEW_LINE_STR + NEW_LINE_STR;
-
- /**
- * 获取错误信息
- * @param e
- * @return
- */
- public static String getErrorMsg(Exception e){
- try {
- if (e != null){
- return e.getMessage();
- }
- } catch (Exception ex){
- return ex.getMessage();
- }
- return "e(null)";
- }
-
- /**
- * 将异常栈信息转为字符串
- * @param e 字符串
- * @return 异常栈
- */
- public static String getThrowableMsg(Throwable e) {
- try {
- if (e != null) {
- StringWriter writer = new StringWriter();
- e.printStackTrace(new PrintWriter(writer));
- return writer.toString();
- }
- } catch (Exception ex){
- return ex.getMessage();
- }
- return "e(null)";
- }
-
- // ================== 异常信息处理 ===================
-
- /**
- * 获取错误信息(无换行)
- * @param eHint 获取失败提示
- * @param ex 错误信息
- * @return
- */
- public static String getThrowableMsg(String eHint, Throwable ex) {
- PrintWriter printWriter = null;
- try {
- if(ex != null) {
- // 初始化Writer,PrintWriter打印流
- Writer writer = new StringWriter();
- printWriter = new PrintWriter(writer);
- // 写入错误栈信息
- ex.printStackTrace(printWriter);
- // 关闭流
- printWriter.close();
- return writer.toString();
- }
- } catch (Exception e) {
- } finally {
- if(printWriter != null) {
- printWriter.close();
- }
- }
- return eHint;
- }
-
- /**
- * 获取错误信息(有换行)
- * @param ex 错误信息
- * @return 默认返回 ""
- */
- public static String getThrowableNewLinesMsg(Throwable ex) {
- return getThrowableNewLinesMsg("", ex);
- }
-
- /**
- * 获取错误信息(有换行)
- * @param eHint 获取失败提示
- * @param ex 错误信息
- * @return
- */
- public static String getThrowableNewLinesMsg(String eHint, Throwable ex) {
- PrintWriter printWriter = null;
- try {
- if(ex != null) {
- // 初始化Writer,PrintWriter打印流
- Writer writer = new StringWriter();
- printWriter = new PrintWriter(writer);
- // 获取错误栈信息
- StackTraceElement[] stElement = ex.getStackTrace();
- // 标题,提示属于什么异常
- printWriter.append(ex.toString());
- printWriter.append(NEW_LINE_STR);
- // 遍历错误栈信息,并且进行换行,缩进
- for(StackTraceElement st : stElement) {
- printWriter.append("\tat ");
- printWriter.append(st.toString());
- printWriter.append(NEW_LINE_STR);
- }
- // 关闭流
- printWriter.close();
- return writer.toString();
- }
- } catch (Exception e) {
- } finally {
- if(printWriter != null) {
- try {
- printWriter.close();
- } catch (Exception e) {
- }
- }
- }
- return eHint;
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/FileRecordUtils.java b/DevLibUtils/src/main/java/dev/utils/app/FileRecordUtils.java
deleted file mode 100644
index 9679193688..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/FileRecordUtils.java
+++ /dev/null
@@ -1,499 +0,0 @@
-package dev.utils.app;
-
-import android.annotation.SuppressLint;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-import android.os.Build;
-import android.text.TextUtils;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.lang.reflect.Field;
-import java.text.DateFormat;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
-import dev.DevUtils;
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: App 文件记录工具类
- * Created by Ttt
- */
-public final class FileRecordUtils {
-
- private FileRecordUtils(){
- }
-
- // 日志TAG
- private static final String TAG = FileRecordUtils.class.getSimpleName();
-
- // =================== 配置信息 =======================
-
- /** App版本(如1.0.01) 显示给用户看的 */
- static String APP_VERSION_NAME = "";
-
- /** android:versionCode——整数值,代表应用程序代码的相对版本,也就是版本更新过多少次。(不显示给用户看) */
- static String APP_VERSION_CODE = "";
-
- /** 设备信息 */
- static String DEVICE_INFO_STR = null;
-
- /** 用来存储设备信息 */
- static HashMap DEVICE_INFO_MAPS = new HashMap();
-
- /** 换行字符串 */
- static final String NEW_LINE_STR = System.getProperty("line.separator");
-
- /** 换行字符串 - 两行 */
- static final String NEW_LINE_STR_X2 = NEW_LINE_STR + NEW_LINE_STR;
-
- // ================== APP、设备信息处理 ===================
-
- /**
- * 获取app版本信息
- */
- static String[] getAppVersion() {
- String[] aVersion = null;
- try {
- PackageManager pm = DevUtils.getContext().getPackageManager();
- PackageInfo pi = pm.getPackageInfo(DevUtils.getContext().getPackageName(), PackageManager.GET_ACTIVITIES);
- if (pi != null) {
- String versionName = pi.versionName == null ? "null" : pi.versionName;
- String versionCode = pi.versionCode + "";
- // --
- aVersion = new String[]{versionName,versionCode};
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getAppVersion");
- }
- return aVersion;
- }
-
- /**
- * 获取设备信息
- * @param dInfoMaps 传入设备信息传出HashMap
- */
- static void getDeviceInfo(HashMap dInfoMaps) {
- // 获取设备信息类的所有申明的字段,即包括public、private和proteced, 但是不包括父类的申明字段。
- Field[] fields = Build.class.getDeclaredFields();
- // 遍历字段
- for (Field field : fields) {
- try {
- // 取消java的权限控制检查
- field.setAccessible(true);
- // 获取类型对应字段的数据,并保存
- dInfoMaps.put(field.getName(), field.get(null).toString());
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getDeviceInfo");
- }
- }
- }
-
- /**
- * 处理设备信息
- * @param eHint 错误提示,如获取设备信息失败
- */
- static String handleDeviceInfo(String eHint) {
- try {
- // 如果不为null,则直接返回之前的信息
- if(!TextUtils.isEmpty(DEVICE_INFO_STR)) {
- return DEVICE_INFO_STR;
- }
- // 初始化StringBuilder,拼接字符串
- StringBuilder sBuilder = new StringBuilder();
- // 获取设备信息
- Iterator> mapIter = DEVICE_INFO_MAPS.entrySet().iterator();
- // 遍历设备信息
- while (mapIter.hasNext()) {
- // 获取对应的key-value
- Map.Entry rnEntry = (Map.Entry) mapIter.next();
- String rnKey = (String) rnEntry.getKey(); // key
- String rnValue = (String) rnEntry.getValue(); // value
- // 保存设备信息
- sBuilder.append(rnKey);
- sBuilder.append(" = ");
- sBuilder.append(rnValue);
- sBuilder.append(NEW_LINE_STR);
- }
- // 保存设备信息
- DEVICE_INFO_STR = sBuilder.toString();
- // 返回设备信息
- return DEVICE_INFO_STR;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "handleDeviceInfo");
- }
- return eHint;
- }
-
- // ================== 时间格式化 ===================
-
- /** 日期格式类型 */
- static final String yyyyMMddHHmmss = "yyyy-MM-dd HH:mm:ss";
-
- /**
- * 获取当前日期的字符串
- * @return 字符串
- */
- @SuppressLint("SimpleDateFormat")
- static String getDateNow() {
- try {
- Calendar cld = Calendar.getInstance();
- DateFormat df = new SimpleDateFormat(yyyyMMddHHmmss);
- return df.format(cld.getTime());
- } catch (Exception e) {
- }
- return null;
- }
-
-
- // ================== 文件操作 ===================
-
- /**
- * 判断某个文件夹是否创建,未创建则创建(不能加入文件名)
- * @param fPath 文件夹路径
- */
- static File createFile(String fPath) {
- try {
- File file = new File(fPath);
- // 当这个文件夹不存在的时候则创建文件夹
- if(!file.exists()) {
- // 允许创建多级目录
- file.mkdirs();
- }
- return file;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "createFile");
- }
- return null;
- }
-
- /**
- * 保存文件
- * @param txt 保存内容
- * @param fUrl 保存路径(包含文件名.后缀)
- * @return 是否保存成功
- */
- static boolean saveFile(String txt, String fUrl) {
- try {
- // 保存内容到一个文件
- FileOutputStream fos = new FileOutputStream(fUrl);
- fos.write(txt.getBytes());
- fos.close();
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "saveFile");
- return false;
- }
- return true;
- }
-
-
- // ================== 异常信息处理 ===================
-
- /**
- * 获取错误信息(无换行)
- * @param eHint 获取失败提示
- * @param ex 错误信息
- * @return
- */
- static String getThrowableMsg(String eHint, Throwable ex) {
- PrintWriter printWriter = null;
- try {
- if(ex != null) {
- // 初始化Writer,PrintWriter打印流
- Writer writer = new StringWriter();
- printWriter = new PrintWriter(writer);
- // 写入错误栈信息
- ex.printStackTrace(printWriter);
- // 关闭流
- printWriter.close();
- return writer.toString();
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getThrowableMsg");
- } finally {
- if(printWriter != null) {
- printWriter.close();
- }
- }
- return eHint;
- }
-
- /**
- * 获取错误信息(有换行)
- * @param eHint 获取失败提示
- * @param ex 错误信息
- * @return
- */
- static String getThrowableNewLinesMsg(String eHint, Throwable ex) {
- PrintWriter printWriter = null;
- try {
- if(ex != null) {
- // 初始化Writer,PrintWriter打印流
- Writer writer = new StringWriter();
- printWriter = new PrintWriter(writer);
- // 获取错误栈信息
- StackTraceElement[] stElement = ex.getStackTrace();
- // 标题,提示属于什么异常
- printWriter.append(ex.toString());
- printWriter.append(NEW_LINE_STR);
- // 遍历错误栈信息,并且进行换行,缩进
- for(StackTraceElement st : stElement) {
- printWriter.append("\tat ");
- printWriter.append(st.toString());
- printWriter.append(NEW_LINE_STR);
- }
- // 关闭流
- printWriter.close();
- return writer.toString();
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getThrowableNewLinesMsg");
- } finally {
- if(printWriter != null) {
- try {
- printWriter.close();
- } catch (Exception e) {
- }
- }
- }
- return eHint;
- }
-
- // ================== 对外公开方法 ===================
-
- /**
- * App初始化调用方法
- */
- public static void appInit() {
- // 如果版本信息为null,才进行处理
- if (TextUtils.isEmpty(APP_VERSION_CODE) || TextUtils.isEmpty(APP_VERSION_NAME)) {
- // 获取app版本信息
- String[] aVersion = getAppVersion();
- // 保存app版本信息
- APP_VERSION_NAME = aVersion[0];
- APP_VERSION_CODE = aVersion[1];
- }
- // 判断是否存在设备信息
- if (DEVICE_INFO_MAPS.size() == 0) {
- // 获取设备信息
- getDeviceInfo(DEVICE_INFO_MAPS);
- // 转换字符串
- handleDeviceInfo("");
- }
- }
-
- // ========= 保存错误日志信息 ==========
-
- /**
- * 保存app错误日志
- * @param ex 错误信息
- * @param fPath 保存路径
- * @param fName 文件名(含后缀)
- * @param isNewLines 是否换行
- * @param printDevice 是否打印设备信息
- * @param eHint 错误提示(无设备信息、失败信息获取失败)
- * @return
- */
- public static boolean saveErrorLog(Throwable ex, String fPath, String fName, boolean isNewLines, boolean printDevice, String... eHint) {
- return saveErrorLog(ex, null, null, fPath, fName, isNewLines, printDevice, eHint);
- }
-
- /**
- * 保存app错误日志
- * @param ex 错误信息
- * @param head 顶部标题
- * @param bottom 底部内容
- * @param fPath 保存路径
- * @param fName 文件名(含后缀)
- * @param isNewLines 是否换行
- * @param printDevice 是否打印设备信息
- * @param eHint 错误提示(无设备信息、失败信息获取失败)
- * @return
- */
- public static boolean saveErrorLog(Throwable ex, String head, String bottom, String fPath, String fName, boolean isNewLines, boolean printDevice, String... eHint) {
- // 处理可变参数(错误提示)
- eHint = handleVariable(2, eHint);
- // 日志拼接
- StringBuilder sBuilder = new StringBuilder();
- // 防止文件夹不存在
- createFile(fPath);
- // 设备信息
- String dInfo = handleDeviceInfo(eHint[0]);
- // 如果存在顶部内容,则进行添加
- if(!TextUtils.isEmpty(head)) {
- sBuilder.append(head);
- sBuilder.append(NEW_LINE_STR_X2);
- sBuilder.append("============================");
- sBuilder.append(NEW_LINE_STR_X2);
- }
- // ============
- // 保存App信息
- sBuilder.append("date: " + getDateNow());
- sBuilder.append(NEW_LINE_STR);
- sBuilder.append("versionName: " + APP_VERSION_NAME);
- sBuilder.append(NEW_LINE_STR);
- sBuilder.append("versionCode: " + APP_VERSION_CODE);
- sBuilder.append(NEW_LINE_STR_X2);
- sBuilder.append("============================");
- sBuilder.append(NEW_LINE_STR_X2);
- // 如果需要打印设备信息
- if (printDevice) {
- // 保存设备信息
- sBuilder.append(dInfo);
- sBuilder.append(NEW_LINE_STR);
- sBuilder.append("============================");
- sBuilder.append(NEW_LINE_STR_X2);
- }
- // ============
- // 错误信息
- String eMsg = null;
- // 是否换行
- if(isNewLines) {
- eMsg = getThrowableNewLinesMsg(eHint[1], ex);
- } else {
- eMsg = getThrowableMsg(eHint[1], ex);
- }
- // 保存异常信息
- sBuilder.append(eMsg);
- // 如果存在顶部内容,则进行添加
- if(!TextUtils.isEmpty(bottom)) {
- sBuilder.append(NEW_LINE_STR);
- sBuilder.append("============================");
- sBuilder.append(NEW_LINE_STR_X2);
- sBuilder.append(bottom);
- }
- // 保存日志到文件
- return saveFile(sBuilder.toString(), fPath + File.separator + fName);
- }
-
- /**
- * 保存app日志
- * @param log 日志信息
- * @param fPath 保存路径
- * @param fName 文件名(含后缀)
- * @param printDevice 是否打印设备信息
- * @param eHint 错误提示(无设备信息、失败信息获取失败)
- * @return
- */
- public static boolean saveLog(String log, String fPath, String fName, boolean printDevice, String... eHint){
- return saveLog(log, null, null, fPath, fName, printDevice, eHint);
- }
-
- /**
- * 保存app日志
- * @param log 日志信息
- * @param head 顶部标题
- * @param bottom 底部内容
- * @param fPath 保存路径
- * @param fName 文件名(含后缀)
- * @param printDevice 是否打印设备信息
- * @param eHint 错误提示(无设备信息、失败信息获取失败)
- * @return
- */
- public static boolean saveLog(String log, String head, String bottom, String fPath, String fName, boolean printDevice, String... eHint){
- // 处理可变参数(错误提示)
- eHint = handleVariable(2, eHint);
- // 日志拼接
- StringBuilder sBuilder = new StringBuilder();
- // 防止文件夹不存在
- createFile(fPath);
- // 设备信息
- String dInfo = handleDeviceInfo(eHint[0]);
- // 如果存在顶部内容,则进行添加
- if(!TextUtils.isEmpty(head)) {
- sBuilder.append(head);
- sBuilder.append(NEW_LINE_STR_X2);
- sBuilder.append("============================");
- sBuilder.append(NEW_LINE_STR_X2);
- }
- // ============
- // 保存App信息
- sBuilder.append("date: " + getDateNow());
- sBuilder.append(NEW_LINE_STR);
- sBuilder.append("versionName: " + APP_VERSION_NAME);
- sBuilder.append(NEW_LINE_STR);
- sBuilder.append("versionCode: " + APP_VERSION_CODE);
- sBuilder.append(NEW_LINE_STR_X2);
- sBuilder.append("============================");
- sBuilder.append(NEW_LINE_STR_X2);
- // 如果需要打印设备信息
- if (printDevice) {
- // 保存设备信息
- sBuilder.append(dInfo);
- sBuilder.append(NEW_LINE_STR);
- sBuilder.append("============================");
- sBuilder.append(NEW_LINE_STR_X2);
- }
- // ============
- // 保存日志信息
- sBuilder.append(log);
- // 如果存在顶部内容,则进行添加
- if(!TextUtils.isEmpty(bottom)) {
- sBuilder.append(NEW_LINE_STR);
- sBuilder.append("============================");
- sBuilder.append(NEW_LINE_STR_X2);
- sBuilder.append(bottom);
- }
- // 保存日志到文件
- return saveFile(sBuilder.toString(), fPath + File.separator + fName);
- }
-
- // ==
-
- /**
- * 处理可变参数
- * @param length 保留长度
- * @param vArrays 可变参数数组
- * @return
- */
- public static String[] handleVariable(int length, String[] vArrays) {
- // 处理后的数据,
- String[] hArrays = new String[length];
- // 是否统一处理
- boolean isUnifiedHandler = true;
- try {
- if(vArrays != null) {
- // 获取可变参数数组长度
- int vLength = vArrays.length;
- // 如果长度超出预留长度
- if(vLength >= length) {
- for(int i = 0;i < length;i++) {
- if(vArrays[i] == null) {
- hArrays[i] = "";
- } else {
- hArrays[i] = vArrays[i];
- }
- }
- // 但可变参数长度,超过预留长度时,已经处理完毕,不需要再次处理,节省遍历资源
- isUnifiedHandler = false;
- } else {
- for(int i = 0;i < vLength;i++) {
- if(vArrays[i] == null) {
- hArrays[i] = "";
- } else {
- hArrays[i] = vArrays[i];
- }
- }
- }
- }
- if(isUnifiedHandler) {
- // 统一处理,如果数据未null,则设置为“”,防止拼接出现 "null"
- for(int i = 0;i < length;i++) {
- if(hArrays[i] == null) {
- hArrays[i] = "";
- }
- }
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "handleVariable");
- }
- return hArrays;
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/FlashlightUtils.java b/DevLibUtils/src/main/java/dev/utils/app/FlashlightUtils.java
deleted file mode 100644
index f759e88006..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/FlashlightUtils.java
+++ /dev/null
@@ -1,170 +0,0 @@
-package dev.utils.app;
-
-import android.content.pm.PackageManager;
-import android.graphics.SurfaceTexture;
-import android.hardware.Camera;
-
-import java.io.IOException;
-
-import dev.DevUtils;
-import dev.utils.LogPrintUtils;
-
-import static android.hardware.Camera.Parameters.FLASH_MODE_OFF;
-import static android.hardware.Camera.Parameters.FLASH_MODE_TORCH;
-
-/**
- * detail: 手电筒工具类
- * Created by Ttt
- */
-public final class FlashlightUtils {
-
- private FlashlightUtils() {
- }
-
- // 日志TAG
- private final String TAG = FileRecordUtils.class.getSimpleName();
-
- public static FlashlightUtils getInstance() {
- return LazyHolder.INSTANCE;
- }
-
- private static final class LazyHolder {
- private static final FlashlightUtils INSTANCE = new FlashlightUtils();
- }
-
- // =
-
- private Camera mCamera;
-
- /**
- * 注册摄像头
- * @return
- */
- public boolean register() {
- try {
- mCamera = Camera.open(0);
- } catch (Throwable t) {
- return false;
- }
- if (mCamera == null) {
- return false;
- }
- try {
- mCamera.setPreviewTexture(new SurfaceTexture(0));
- mCamera.startPreview();
- return true;
- } catch (IOException e) {
- LogPrintUtils.eTag(TAG, e, "register");
- return false;
- }
- }
-
- /**
- * 注销摄像头
- */
- public void unregister() {
- if (mCamera == null) return;
- mCamera.stopPreview();
- mCamera.release();
- }
-
- /**
- * 打开闪光灯
- */
- public void setFlashlightOn() {
- if (mCamera == null) {
- return;
- }
- Camera.Parameters parameters = mCamera.getParameters();
- if (!FLASH_MODE_TORCH.equals(parameters.getFlashMode())) {
- parameters.setFlashMode(FLASH_MODE_TORCH);
- mCamera.setParameters(parameters);
- }
- }
-
- /**
- * 关闭闪光灯
- */
- public void setFlashlightOff() {
- if (mCamera == null) {
- return;
- }
- Camera.Parameters parameters = mCamera.getParameters();
- if (FLASH_MODE_TORCH.equals(parameters.getFlashMode())) {
- parameters.setFlashMode(FLASH_MODE_OFF);
- mCamera.setParameters(parameters);
- }
- }
-
- /**
- * 是否打开闪光灯
- * @return
- */
- public boolean isFlashlightOn() {
- if (mCamera == null) {
- return false;
- }
- Camera.Parameters parameters = mCamera.getParameters();
- return FLASH_MODE_TORCH.equals(parameters.getFlashMode());
- }
-
- /**
- * 是否支持手机闪光灯
- * @return
- */
- public static boolean isFlashlightEnable() {
- return DevUtils.getContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
- }
-
- // =
-
- /**
- * 打开闪光灯
- * @param camera
- */
- public void setFlashlightOn(Camera camera) {
- if (camera != null) {
- try {
- Camera.Parameters parameter = camera.getParameters();
- parameter.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
- camera.setParameters(parameter);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "setFlashlightOn");
- }
- }
- }
-
- /**
- * 关闭闪光灯
- * @param camera
- */
- public void setFlashlightOff(Camera camera) {
- if (camera != null) {
- try {
- Camera.Parameters parameter = camera.getParameters();
- parameter.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
- camera.setParameters(parameter);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "setFlashlightOff");
- }
- }
- }
-
- /**
- * 是否打开了摄像头
- * @param camera
- * @return
- */
- public boolean isFlashlightOn(Camera camera) {
- if (camera == null) {
- return false;
- }
- try {
- Camera.Parameters parameters = camera.getParameters();
- return FLASH_MODE_TORCH.equals(parameters.getFlashMode());
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "isFlashlightOn");
- }
- return false;
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/HandlerUtils.java b/DevLibUtils/src/main/java/dev/utils/app/HandlerUtils.java
deleted file mode 100644
index fed98ae7c5..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/HandlerUtils.java
+++ /dev/null
@@ -1,80 +0,0 @@
-package dev.utils.app;
-
-import android.content.Context;
-import android.os.Handler;
-
-/**
- * detail: Handler 工具类, 默认开启一个 Handler,方便在各个地方随时执行主线程任务
- * Created by Ttt
- */
-public final class HandlerUtils {
-
- private HandlerUtils() {
- }
-
- /** 主线程 Handler */
- private static Handler mainHandler;
-
- /**
- * 初始化操作
- * @param context
- */
- public static void init(Context context) {
- if (mainHandler == null) mainHandler = new Handler(context.getMainLooper());
- }
-
- /**
- * 获取主线程 Handler
- * @return 主线程 Handler
- */
- public static Handler getMainHandler() {
- return mainHandler;
- }
-
- /**
- * 在主线程 Handler 中执行任务
- * @param runnable 可执行的任务
- */
- public static void postRunnable(Runnable runnable) {
- getMainHandler().post(runnable);
- }
-
- /**
- * 在主线程 Handler 中执行延迟任务
- * @param runnable 可执行的任务
- * @param delay 延迟时间
- */
- public static void postRunnable(Runnable runnable, long delay) {
- getMainHandler().postDelayed(runnable, delay);
- }
-
- /**
- * 在主线程 Handler 中执行延迟任务
- * @param runnable 可执行的任务
- * @param delay 延迟时间
- * @param times 轮询次数
- * @param interval 轮询时间
- */
- public static void postRunnable(final Runnable runnable, long delay, final int times, final int interval) {
- Runnable loop = new Runnable() {
- private int mTimes;
- @Override
- public void run() {
- if (mTimes < times) {
- runnable.run();
- getMainHandler().postDelayed(this, interval);
- }
- mTimes++;
- }
- };
- getMainHandler().postDelayed(loop, delay);
- }
-
- /**
- * 在主线程 Handler 中清除任务
- * @param runnable 需要清除的任务
- */
- public static void removeRunnable(Runnable runnable) {
- getMainHandler().removeCallbacks(runnable);
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/HtmlUtils.java b/DevLibUtils/src/main/java/dev/utils/app/HtmlUtils.java
deleted file mode 100644
index 24c67fb056..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/HtmlUtils.java
+++ /dev/null
@@ -1,120 +0,0 @@
-package dev.utils.app;
-
-import android.text.Html;
-import android.widget.TextView;
-
-/**
- * detail: Html 工具类
- * Created by Ttt
- */
-public final class HtmlUtils {
-
- private HtmlUtils() {
- }
-
- /**
- * 设置内容, 最终做处理
- * @param textView
- * @param content
- */
- public static void setHtmlText(TextView textView, String content){
- if (textView != null && content != null){
- textView.setText(Html.fromHtml(content));
- }
- }
-
- /**
- * 为给定的字符串添加HTML颜色标记
- * @param content 给定的字符串
- * @return 最后放在 Html.fromHtml();内
- */
- public static String addHtmlColor(String content, String color) {
- return "" + content + "";
- }
-
- /**
- * 为给定的字符串添加HTML颜色标记
- * @param content 给定的字符串
- * @param fString 格式化的内容
- * @return 最后放在 Html.fromHtml();内
- */
- public static String addHtmlColor(String content, String fString, String color) {
- return String.format(content, (""+ fString +""));
- }
-
- /**
- * 为给定的字符串添加HTML加粗标记
- * @param content 给定的字符串
- * @return 最后放在 Html.fromHtml();内
- * ======================
- * 这种方式也可以加粗,但是是所有字体加粗(非部分字体加粗)
- * android.text.TextPaint tp = textView.getPaint();
- * tp.setFakeBoldText(true);
- */
- public static String addHtmlBold(String content) {
- return "" + content + "";
- }
-
- /**
- * 为给定的字符串添加HTML颜色标记,以及加粗
- * @param content 给定的字符串
- * @return 最后放在 Html.fromHtml();内
- */
- public static String addHtmlColorAndBlod(String content, String color) {
- return "" + content + "";
- }
-
- /**
- * 为给定的字符串添加HTML下划线
- * @param content 给定的字符串
- * @return 最后放在 Html.fromHtml();内
- */
- public static String addHtmlUnderline(String content) {
- return "" + content + "";
- }
-
- /**
- * 为给定的字符串添加HTML 字体倾斜
- * @param content 给定的字符串
- * @return 最后放在 Html.fromHtml();内
- * =================================
- * 如果需要倾斜自定义角度,需要自定义TextView,在onDraw里面加上
- * - 倾斜度,上下左右居中
- * canvas.rotate(倾斜角度, getMeasuredWidth() / 3, getMeasuredHeight() / 3);
- */
- public static String addHtmlIncline(String content) {
- return "" + content + "";
- }
-
- /**
- * 将给定的字符串中所有给定的关键字标色
- * @param source 给定的字符串
- * @param keyword 给定的关键字
- * @param color 需要标记的颜色
- * @return
- */
- public static String keywordMadeRed(String source, String keyword, String color) {
- return keywordReplaceAll(source, keyword, ("" + keyword + ""));
- }
-
- /**
- * 将给定的字符串中所有给定的关键字进行替换内容
- * @param source 给定的字符串
- * @param keyword 给定的关键字
- * @param replacement 替换的内容
- * @return 返回的是带Html标签的字符串,在使用时要通过Html.fromHtml() 转换为Spanned对象再传递给TextView对象
- */
- public static String keywordReplaceAll(String source, String keyword, String replacement) {
- try {
- if(source != null && source.trim().length() != 0) {
- if (keyword != null && keyword.trim().length() != 0) {
- if(replacement != null && replacement.trim().length() != 0) {
- return source.replaceAll(keyword , replacement);
- }
- }
- }
- } catch (Exception e) {
- }
- return source;
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/IntentUtils.java b/DevLibUtils/src/main/java/dev/utils/app/IntentUtils.java
deleted file mode 100644
index 0002476e65..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/IntentUtils.java
+++ /dev/null
@@ -1,533 +0,0 @@
-package dev.utils.app;
-
-import android.app.Activity;
-import android.content.ComponentName;
-import android.content.Intent;
-import android.net.Uri;
-import android.os.Build;
-import android.os.Bundle;
-import android.provider.MediaStore;
-import android.provider.Settings;
-import android.support.v4.content.FileProvider;
-import android.text.TextUtils;
-
-import java.io.File;
-
-import dev.DevUtils;
-import dev.utils.common.FileUtils;
-
-/**
- * detail: Intent(意图) 相关工具类
- * Created by Ttt
- */
-public final class IntentUtils {
-
- private IntentUtils() {
- }
-
- /**
- * 获取安装 App(支持 8.0)的意图
- *
- * @param filePath The path of file.
- * @param authority 7.0 及以上安装需要传入清单文件中的}的 authorities 属性
- *
参看 https://developer.android.com/reference/android/support/v4/content/FileProvider.html
- * @return 安装 App(支持 8.0)的意图
- */
- public static Intent getInstallAppIntent(final String filePath, final String authority) {
- return getInstallAppIntent(FileUtils.getFileByPath(filePath), authority);
- }
-
- /**
- * 获取安装 App(支持 8.0)的意图
- *
- * @param file The file.
- * @param authority 7.0 及以上安装需要传入清单文件中的}的 authorities 属性
- *
参看 https://developer.android.com/reference/android/support/v4/content/FileProvider.html
- * @return 安装 App(支持 8.0)的意图
- */
- public static Intent getInstallAppIntent(final File file, final String authority) {
- return getInstallAppIntent(file, authority, false);
- }
-
- /**
- * 获取安装 App(支持 8.0)的意图
- *
- * @param file The file.
- * @param authority 7.0 及以上安装需要传入清单文件中的}的 authorities 属性
- *
参看 https://developer.android.com/reference/android/support/v4/content/FileProvider.html
- * @param isNewTask 是否开启新的任务栈
- * @return 安装 App(支持 8.0)的意图
- */
- public static Intent getInstallAppIntent(final File file, final String authority, final boolean isNewTask) {
- if (file == null) return null;
- Intent intent = new Intent(Intent.ACTION_VIEW);
- Uri data;
- String type = "application/vnd.android.package-archive";
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) {
- data = Uri.fromFile(file);
- } else {
- intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- data = FileProvider.getUriForFile(DevUtils.getContext(), authority, file);
- }
- intent.setDataAndType(data, type);
- return getIntent(intent, isNewTask);
- }
-
- /**
- * 获取卸载 App 的意图
- * @param packageName The name of the package.
- * @return 卸载 App 的意图
- */
- public static Intent getUninstallAppIntent(final String packageName) {
- return getUninstallAppIntent(packageName, false);
- }
-
- /**
- * 获取卸载 App 的意图
- * @param packageName The name of the package.
- * @param isNewTask 是否开启新的任务栈
- * @return 卸载 App 的意图
- */
- public static Intent getUninstallAppIntent(final String packageName, final boolean isNewTask) {
- Intent intent = new Intent(Intent.ACTION_DELETE);
- intent.setData(Uri.parse("package:" + packageName));
- return getIntent(intent, isNewTask);
- }
-
- /**
- * 获取打开 App 的意图
- * @param packageName The name of the package.
- * @return 打开 App 的意图
- */
- public static Intent getLaunchAppIntent(final String packageName) {
- return getLaunchAppIntent(packageName, false);
- }
-
- /**
- * 获取打开 App 的意图
- * @param packageName The name of the package.
- * @param isNewTask 是否开启新的任务栈
- * @return 打开 App 的意图
- */
- public static Intent getLaunchAppIntent(final String packageName, final boolean isNewTask) {
- Intent intent = DevUtils.getContext().getPackageManager().getLaunchIntentForPackage(packageName);
- if (intent == null) return null;
- return getIntent(intent, isNewTask);
- }
-
- /**
- * 获取 App 具体设置的意图
- * @param packageName The name of the package.
- * @return App 具体设置的意图
- */
- public static Intent getLaunchAppDetailsSettingsIntent(final String packageName) {
- return getLaunchAppDetailsSettingsIntent(packageName, false);
- }
-
- /**
- * 获取 App 具体设置的意图
- * @param packageName The name of the package.
- * @param isNewTask 是否开启新的任务栈
- * @return App 具体设置的意图
- */
- public static Intent getLaunchAppDetailsSettingsIntent(final String packageName, final boolean isNewTask) {
- Intent intent = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS");
- intent.setData(Uri.parse("package:" + packageName));
- return getIntent(intent, isNewTask);
- }
-
- /**
- * 获取 到应用商店app详情界面的意图
- * @param packageName 目标App的包名
- * @param marketPkg 应用商店包名 ,如果为""则由系统弹出应用商店列表供用户选择,否则调转到目标市场的应用详情界面,某些应用商店可能会失败
- */
- public static Intent getlaunchAppDetailIntent(final String packageName, final String marketPkg) {
- return getlaunchAppDetailIntent(packageName, marketPkg, false);
- }
-
- /**
- * 获取 到应用商店app详情界面的意图
- * @param packageName 目标App的包名
- * @param marketPkg 应用商店包名 ,如果为""则由系统弹出应用商店列表供用户选择,否则调转到目标市场的应用详情界面,某些应用商店可能会失败
- * @param isNewTask 是否开启新的任务栈
- */
- public static Intent getlaunchAppDetailIntent(final String packageName, final String marketPkg, final boolean isNewTask) {
- try {
- if (TextUtils.isEmpty(packageName)) return null;
-
- Uri uri = Uri.parse("market://details?id=" + packageName);
- Intent intent = new Intent(Intent.ACTION_VIEW, uri);
- if (!TextUtils.isEmpty(marketPkg)) {
- intent.setPackage(marketPkg);
- }
- return getIntent(intent, isNewTask);
- } catch (Exception e) {
- }
- return null;
- }
-
- /**
- * 获取分享文本的意图
- * @param content 分享文本
- * @return 分享文本的意图
- */
- public static Intent getShareTextIntent(final String content) {
- return getShareTextIntent(content, false);
- }
-
- /**
- * 获取分享文本的意图
- * @param content 分享文本
- * @param isNewTask 是否开启新的任务栈
- * @return 分享文本的意图
- */
-
- public static Intent getShareTextIntent(final String content, final boolean isNewTask) {
- Intent intent = new Intent(Intent.ACTION_SEND);
- intent.setType("text/plain");
- intent.putExtra(Intent.EXTRA_TEXT, content);
- return getIntent(intent, isNewTask);
- }
-
- /**
- * 获取分享图片的意图
- * @param content 文本
- * @param imagePath 图片文件路径
- * @return 分享图片的意图
- */
- public static Intent getShareImageIntent(final String content, final String imagePath) {
- return getShareImageIntent(content, imagePath, false);
- }
-
- /**
- * 获取分享图片的意图
- * @param content 文本
- * @param imagePath 图片文件路径
- * @param isNewTask 是否开启新的任务栈
- * @return 分享图片的意图
- */
- public static Intent getShareImageIntent(final String content, final String imagePath, final boolean isNewTask) {
- if (imagePath == null || imagePath.length() == 0) return null;
- return getShareImageIntent(content, new File(imagePath), isNewTask);
- }
-
- /**
- * 获取分享图片的意图
- * @param content 文本
- * @param image 图片文件
- * @return 分享图片的意图
- */
- public static Intent getShareImageIntent(final String content, final File image) {
- return getShareImageIntent(content, image, false);
- }
-
- /**
- * 获取分享图片的意图
- * @param content 文本
- * @param image 图片文件
- * @param isNewTask 是否开启新的任务栈
- * @return 分享图片的意图
- */
- public static Intent getShareImageIntent(final String content, final File image, final boolean isNewTask) {
- if (image != null && image.isFile()) return null;
- return getShareImageIntent(content, Uri.fromFile(image), isNewTask);
- }
-
- /**
- * 获取分享图片的意图
- * @param content 分享文本
- * @param uri 图片 uri
- * @return 分享图片的意图
- */
- public static Intent getShareImageIntent(final String content, final Uri uri) {
- return getShareImageIntent(content, uri, false);
- }
-
- /**
- * 获取分享图片的意图
- * @param content 分享文本
- * @param uri 图片 uri
- * @param isNewTask 是否开启新的任务栈
- * @return 分享图片的意图
- */
- public static Intent getShareImageIntent(final String content, final Uri uri, final boolean isNewTask) {
- Intent intent = new Intent(Intent.ACTION_SEND);
- intent.putExtra(Intent.EXTRA_TEXT, content);
- intent.putExtra(Intent.EXTRA_STREAM, uri);
- intent.setType("image/*");
- return getIntent(intent, isNewTask);
- }
-
- /**
- * 获取其他应用组件的意图
- * @param packageName The name of the package.
- * @param className 全类名
- * @return 其他应用组件的意图
- */
- public static Intent getComponentIntent(final String packageName, final String className) {
- return getComponentIntent(packageName, className, null, false);
- }
-
- /**
- * 获取其他应用组件的意图
- * @param packageName The name of the package.
- * @param className 全类名
- * @param isNewTask 是否开启新的任务栈
- * @return 其他应用组件的意图
- */
- public static Intent getComponentIntent(final String packageName, final String className, final boolean isNewTask) {
- return getComponentIntent(packageName, className, null, isNewTask);
- }
-
- /**
- * 获取其他应用组件的意图
- * @param packageName The name of the package.
- * @param className 全类名
- * @param bundle bundle
- * @return 其他应用组件的意图
- */
- public static Intent getComponentIntent(final String packageName, final String className, final Bundle bundle) {
- return getComponentIntent(packageName, className, bundle, false);
- }
-
- /**
- * 获取其他应用组件的意图
- * @param packageName The name of the package.
- * @param className 全类名
- * @param bundle bundle
- * @param isNewTask 是否开启新的任务栈
- * @return 其他应用组件的意图
- */
- public static Intent getComponentIntent(final String packageName, final String className, final Bundle bundle, final boolean isNewTask) {
- Intent intent = new Intent(Intent.ACTION_VIEW);
- if (bundle != null) intent.putExtras(bundle);
- ComponentName cn = new ComponentName(packageName, className);
- intent.setComponent(cn);
- return getIntent(intent, isNewTask);
- }
-
- /**
- * 获取关机的意图
- *
- * @return 关机的意图
- */
- public static Intent getShutdownIntent() {
- return getShutdownIntent(false);
- }
-
- /**
- * 获取关机的意图
- *
- * @param isNewTask 是否开启新的任务栈
- * @return 关机的意图
- */
- public static Intent getShutdownIntent(final boolean isNewTask) {
- Intent intent = new Intent(Intent.ACTION_SHUTDOWN);
- return getIntent(intent, isNewTask);
- }
-
- /**
- * 获取跳至拨号界面意图
- * @param phoneNumber 电话号码
- * @return 跳至拨号界面意图
- */
- public static Intent getDialIntent(final String phoneNumber) {
- return getDialIntent(phoneNumber, false);
- }
-
- /**
- * 获取跳至拨号界面意图
- * @param phoneNumber 电话号码
- * @param isNewTask 是否开启新的任务栈
- * @return 跳至拨号界面意图
- */
- public static Intent getDialIntent(final String phoneNumber, final boolean isNewTask) {
- Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + phoneNumber));
- return getIntent(intent, isNewTask);
- }
-
- /**
- * 获取拨打电话意图
- *
- * @param phoneNumber 电话号码
- * @return 拨打电话意图
- */
- public static Intent getCallIntent(final String phoneNumber) {
- return getCallIntent(phoneNumber, false);
- }
-
- /**
- * 获取拨打电话意图
- *
- * @param phoneNumber 电话号码
- * @param isNewTask 是否开启新的任务栈
- * @return 拨打电话意图
- */
- public static Intent getCallIntent(final String phoneNumber, final boolean isNewTask) {
- Intent intent = new Intent("android.intent.action.CALL", Uri.parse("tel:" + phoneNumber));
- return getIntent(intent, isNewTask);
- }
-
- /**
- * 获取发送短信界面的意图
- * @param phoneNumber 接收号码
- * @param content 短信内容
- * @return 发送短信界面的意图
- */
- public static Intent getSendSmsIntent(final String phoneNumber, final String content) {
- return getSendSmsIntent(phoneNumber, content, false);
- }
-
- /**
- * 获取跳至发送短信界面的意图
- * @param phoneNumber 接收号码
- * @param content 短信内容
- * @param isNewTask 是否开启新的任务栈
- * @return 发送短信界面的意图
- */
- public static Intent getSendSmsIntent(final String phoneNumber, final String content, final boolean isNewTask) {
- Uri uri = Uri.parse("smsto:" + phoneNumber);
- Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
- intent.putExtra("sms_body", content);
- return getIntent(intent, isNewTask);
- }
-
- /**
- * 获取拍照的意图
- * @param outUri 输出的 uri
- * @return 拍照的意图
- */
- public static Intent getCaptureIntent(final Uri outUri) {
- return getCaptureIntent(outUri, false);
- }
-
- /**
- * 获取拍照的意图
- * @param outUri 输出的 uri
- * @param isNewTask 是否开启新的任务栈
- * @return 拍照的意图
- */
- public static Intent getCaptureIntent(final Uri outUri, final boolean isNewTask) {
- Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
- intent.putExtra(MediaStore.EXTRA_OUTPUT, outUri);
- intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
- return getIntent(intent, isNewTask);
- }
-
- /**
- * 跳转到系统设置页面
- * @param activity
- */
- public static void startSysSetting(Activity activity) {
-// if(android.os.Build.VERSION.SDK_INT > 10 ) {
-// activity.startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS));
-// }else {
-// activity.startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS));
-// }
-// // 跳转到 无线和网络 设置页面(可以设置移动网络,sim卡1,2的移动网络)
-// Intent intent = new Intent(Settings.ACTION_AIRPLANE_MODE_SETTINGS);
-// Intent intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS);
-
- Intent intent = new Intent(Settings.ACTION_SETTINGS);
- activity.startActivity(intent);
- }
-
- /**
- * 跳转到系统设置页面
- * @param activity
- * @param requestCode 回传请求code
- */
- public static void startSysSetting(Activity activity, int requestCode) {
- Intent intent = new Intent(Settings.ACTION_SETTINGS);
- activity.startActivityForResult(intent, requestCode);
- }
-
- /**
- * 打开网络设置界面 - 3.0以下打开设置界面
- */
- public static void openWirelessSettings(Activity activity) {
- if (android.os.Build.VERSION.SDK_INT > 10) {
- activity.startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
- } else {
- activity.startActivity(new Intent(android.provider.Settings.ACTION_SETTINGS).setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
- }
- }
-
- // ==
-
- private static Intent getIntent(final Intent intent, final boolean isNewTask) {
- return isNewTask ? intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) : intent;
- }
-
-// /**
-// * 获取选择照片的 Intent
-// *
-// * @return
-// */
-// public static Intent getPickIntentWithGallery() {
-// Intent intent = new Intent(Intent.ACTION_PICK);
-// return intent.setType("image*//*");
-// }
-//
-// /**
-// * 获取从文件中选择照片的 Intent
-// *
-// * @return
-// */
-// public static Intent getPickIntentWithDocuments() {
-// Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
-// return intent.setType("image*//*");
-// }
-//
-//
-// public static Intent buildImageGetIntent(final Uri saveTo, final int outputX, final int outputY, final boolean returnData) {
-// return buildImageGetIntent(saveTo, 1, 1, outputX, outputY, returnData);
-// }
-//
-// public static Intent buildImageGetIntent(Uri saveTo, int aspectX, int aspectY,
-// int outputX, int outputY, boolean returnData) {
-// Intent intent = new Intent();
-// if (Build.VERSION.SDK_INT < 19) {
-// intent.setAction(Intent.ACTION_GET_CONTENT);
-// } else {
-// intent.setAction(Intent.ACTION_OPEN_DOCUMENT);
-// intent.addCategory(Intent.CATEGORY_OPENABLE);
-// }
-// intent.setType("image*//*");
-// intent.putExtra("output", saveTo);
-// intent.putExtra("aspectX", aspectX);
-// intent.putExtra("aspectY", aspectY);
-// intent.putExtra("outputX", outputX);
-// intent.putExtra("outputY", outputY);
-// intent.putExtra("scale", true);
-// intent.putExtra("return-data", returnData);
-// intent.putExtra("outputFormat", Bitmap.CompressFormat.PNG.toString());
-// return intent;
-// }
-//
-// public static Intent buildImageCropIntent(final Uri uriFrom, final Uri uriTo, final int outputX, final int outputY, final boolean returnData) {
-// return buildImageCropIntent(uriFrom, uriTo, 1, 1, outputX, outputY, returnData);
-// }
-//
-// public static Intent buildImageCropIntent(Uri uriFrom, Uri uriTo, int aspectX, int aspectY,
-// int outputX, int outputY, boolean returnData) {
-// Intent intent = new Intent("com.android.camera.action.CROP");
-// intent.setDataAndType(uriFrom, "image*//*");
-// intent.putExtra("crop", "true");
-// intent.putExtra("output", uriTo);
-// intent.putExtra("aspectX", aspectX);
-// intent.putExtra("aspectY", aspectY);
-// intent.putExtra("outputX", outputX);
-// intent.putExtra("outputY", outputY);
-// intent.putExtra("scale", true);
-// intent.putExtra("return-data", returnData);
-// intent.putExtra("outputFormat", Bitmap.CompressFormat.PNG.toString());
-// return intent;
-// }
-//
-// public static Intent buildImageCaptureIntent(final Uri uri) {
-// Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
-// intent.putExtra(MediaStore.EXTRA_OUTPUT, uri);
-// return intent;
-// }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/KeyBoardUtils.java b/DevLibUtils/src/main/java/dev/utils/app/KeyBoardUtils.java
deleted file mode 100644
index 64f032209c..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/KeyBoardUtils.java
+++ /dev/null
@@ -1,522 +0,0 @@
-package dev.utils.app;
-
-import android.app.Activity;
-import android.app.Dialog;
-import android.content.Context;
-import android.graphics.Rect;
-import android.os.Handler;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.ViewTreeObserver;
-import android.view.inputmethod.InputMethodManager;
-import android.widget.EditText;
-
-import java.lang.reflect.Field;
-
-import dev.DevUtils;
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: 软键盘相关辅助类
- * Created by Ttt
- */
-public final class KeyBoardUtils {
-
- private KeyBoardUtils() {
- }
-
- // 日志TAG
- private static final String TAG = KeyBoardUtils.class.getSimpleName();
-
- /** 默认延迟时间 */
- private static int DELAY_MILLIS = 300;
- /** 键盘显示 */
- public static final int KEYBOARD_DISPLAY = 930;
- /** 键盘隐藏 */
- public static final int KEYBOARD_HIDE = 931;
-
-
- /**
- * 避免输入法面板遮挡 manifest.xml 中 activity 中设置
- * android:windowSoftInputMode="adjustPan"
- * android:windowSoftInputMode="adjustUnspecified|stateHidden"
- */
-
- // == ----------------------------------------- ==
-
- /**
- * 设置延迟时间
- * @param delayMillis
- */
- public static void setDelayMillis(int delayMillis) {
- DELAY_MILLIS = delayMillis;
- }
-
- // ================
- // == 打开软键盘 ==
- // ================
-
- /**
- * 打开软键盘
- * @param mEditText 输入框
- */
- public static void openKeyboard(EditText mEditText) {
- if (mEditText != null) {
- try {
- InputMethodManager imm = (InputMethodManager) mEditText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.showSoftInput(mEditText, InputMethodManager.SHOW_FORCED);
- imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "openKeyboard");
- }
- }
- }
-
- /**
- * 打开软键盘
- * @param mEditText
- * @param vHandler
- */
- public static void openKeyboard(final EditText mEditText, Handler vHandler){
- openKeyboard(mEditText, vHandler, DELAY_MILLIS);
- }
-
- /**
- * 打开软键盘
- * @param mEditText
- * @param vHandler
- * @param delayMillis
- */
- public static void openKeyboard(final EditText mEditText, Handler vHandler, int delayMillis){
- if (vHandler != null && mEditText != null){
- // 延迟打开
- vHandler.postDelayed(new Runnable() {
- @Override
- public void run() {
- try {
- mEditText.requestFocus();
- mEditText.setSelection(mEditText.getText().toString().length());
- } catch (Exception e){
- }
- openKeyboard(mEditText);
- }
- }, delayMillis);
- }
- }
-
- // -
-
- /**
- * 打开软键盘
- */
- public static void openKeyboard() {
- try {
- InputMethodManager imm = (InputMethodManager) DevUtils.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "openKeyboard");
- }
- }
-
- /**
- * 打开软键盘
- * @param vHandler
- */
- public static void openKeyboard(Handler vHandler){
- openKeyboard(vHandler, DELAY_MILLIS);
- }
-
- /**
- * 打开软键盘
- * @param vHandler
- * @param delayMillis
- */
- public static void openKeyboard(Handler vHandler, int delayMillis){
- if (vHandler != null && DevUtils.getContext() != null){
- // 延迟打开
- vHandler.postDelayed(new Runnable() {
- @Override
- public void run() {
- openKeyboard();
- }
- }, delayMillis);
- }
- }
-
- // ================
- // == 关闭软键盘 ==
- // ================
-
- /**
- * 关闭软键盘
- * @param mEditText 输入框
- */
- public static void closeKeyboard(EditText mEditText) {
- if (mEditText != null) {
- try {
- InputMethodManager imm = (InputMethodManager) mEditText.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.hideSoftInputFromWindow(mEditText.getWindowToken(), 0);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "closeKeyboard");
- }
- }
- }
-
- /**
- * 关闭软键盘
- */
- public static void closeKeyboard() {
- if (DevUtils.getContext() != null) {
- try {
- InputMethodManager imm = (InputMethodManager) DevUtils.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.toggleSoftInput(0, InputMethodManager.HIDE_NOT_ALWAYS);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "closeKeyboard");
- }
- }
- }
-
- /**
- * 关闭软键盘
- * @param mActivity 当前页面
- */
- public static void closeKeyboard(Activity mActivity) {
- if (mActivity != null) {
- try {
- InputMethodManager imm = (InputMethodManager) mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.hideSoftInputFromWindow(mActivity.getWindow().peekDecorView().getWindowToken(), 0);
- //imm.hideSoftInputFromWindow(mActivity.getCurrentFocus().getWindowToken(), 0);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "closeKeyboard");
- }
- }
- }
-
- /**
- * 关闭dialog中打开的键盘
- * @param mDialog
- */
- public static void closeKeyboard(Dialog mDialog) {
- if (mDialog != null) {
- try {
- InputMethodManager imm = (InputMethodManager) mDialog.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.hideSoftInputFromWindow(mDialog.getWindow().peekDecorView().getWindowToken(), 0);
- //imm.hideSoftInputFromWindow(mDialog.getCurrentFocus().getWindowToken(), 0);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "closeKeyboard");
- }
- }
- }
-
- // ==
-
- /**
- * 关闭软键盘 - 特殊处理
- * @param mEditText
- * @param mDialog
- */
- public static void closeKeyBoardSpecial(EditText mEditText, Dialog mDialog){
- try {
- // 关闭输入法
- closeKeyboard();
- // 关闭输入法
- closeKeyboard(mEditText);
- // 关闭输入法
- closeKeyboard(mDialog);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "closeKeyBoardSpecial");
- }
- }
-
- public static void closeKeyBoardSpecial(final EditText mEditText, final Dialog mDialog, Handler vHandler){
- closeKeyBoardSpecial(mEditText, mDialog, vHandler, DELAY_MILLIS);
- }
-
- /**
- * 关闭软键盘 - 特殊处理(两个都关闭)
- * @param mEditText
- * @param mDialog
- * @param vHandler
- * @param delayMillis
- */
- public static void closeKeyBoardSpecial(final EditText mEditText, final Dialog mDialog, Handler vHandler, int delayMillis){
- if (vHandler != null){
- // 延迟打开
- vHandler.postDelayed(new Runnable() {
- @Override
- public void run() {
- closeKeyBoardSpecial(mEditText, mDialog);
- }
- }, delayMillis);
- }
- }
-
- // -
-
- public static void closeKeyboard(final EditText mEditText, Handler vHandler){
- closeKeyboard(mEditText, vHandler, DELAY_MILLIS);
- }
-
- /**
- * 关闭软键盘
- * @param mEditText
- * @param vHandler
- * @param delayMillis
- */
- public static void closeKeyboard(final EditText mEditText, Handler vHandler, int delayMillis){
- if (vHandler != null && mEditText != null){
- // 延迟打开
- vHandler.postDelayed(new Runnable() {
- @Override
- public void run() {
- closeKeyboard(mEditText);
- }
- }, delayMillis);
- }
- }
-
- public static void closeKeyboard(Handler vHandler){
- closeKeyboard(vHandler, DELAY_MILLIS);
- }
-
- /**
- * 关闭软键盘
- * @param vHandler
- * @param delayMillis
- */
- public static void closeKeyboard(Handler vHandler, int delayMillis){
- if (vHandler != null && DevUtils.getContext() != null){
- // 延迟打开
- vHandler.postDelayed(new Runnable() {
- @Override
- public void run() {
- closeKeyboard();
- }
- }, delayMillis);
- }
- }
-
- public static void closeKeyboard(final Activity mActivity, Handler vHandler){
- closeKeyboard(mActivity, vHandler, DELAY_MILLIS);
- }
-
- /**
- * 关闭软键盘
- * @param mActivity
- * @param vHandler
- * @param delayMillis
- */
- public static void closeKeyboard(final Activity mActivity, Handler vHandler, int delayMillis){
- if (vHandler != null && mActivity != null){
- // 延迟打开
- vHandler.postDelayed(new Runnable() {
- @Override
- public void run() {
- closeKeyboard(mActivity);
- }
- }, delayMillis);
- }
- }
-
- public static void closeKeyboard(final Dialog mDialog, Handler vHandler){
- closeKeyboard(mDialog, vHandler, DELAY_MILLIS);
- }
-
- /**
- * 关闭软键盘
- * @param mDialog
- * @param vHandler
- * @param delayMillis
- */
- public static void closeKeyboard(final Dialog mDialog, Handler vHandler, int delayMillis){
- if (vHandler != null && mDialog != null){
- // 延迟打开
- vHandler.postDelayed(new Runnable() {
- @Override
- public void run() {
- closeKeyboard(mDialog);
- }
- }, delayMillis);
- }
- }
-
- // == ----------------------------------------- ==
-
- // 下面暂时无法使用,缺少判断键盘是否显示,否则和自动切换无区别
- // InputMethodManager.isActive() (无法获取)
- // Activity.getWindow().getAttributes().softInputMode (有些版本可以,不适用)
- // ==----==
-
- /**
- * 自动切换键盘状态,如果键盘显示了则隐藏,隐藏着显示
- */
- public static void toggleKeyboard() {
- // 程序启动后,自动弹出软键盘,可以通过设置一个时间函数来实现,不能再onCreate里写
- try {
- InputMethodManager imm = (InputMethodManager) DevUtils.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
- imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "toggleKeyboard");
- }
- }
-
- // ========== 点击非EditText 则隐藏输入法 ===============
-
- /**
- * 某个View里面的子View的View判断
- * @param view
- */
- public static void judgeView(View view, final Activity activity) {
- if (!(view instanceof EditText)) {
- view.setOnTouchListener(new View.OnTouchListener() {
- public boolean onTouch(View v, MotionEvent event) {
- closeKeyboard(activity);
- return false;
- }
- });
- }
- // --
- if (view instanceof ViewGroup) {
- for (int i = 0; i < ((ViewGroup) view).getChildCount(); i++) {
- View innerView = ((ViewGroup) view).getChildAt(i);
- judgeView(innerView, activity);
- }
- }
- }
-
- // ========== 输入法隐藏显示 ===============
-
- /**
- * 判断软键盘是否可见
- * @param activity
- * @return true : 可见, false : 不可见
- */
- public static boolean isSoftInputVisible(final Activity activity) {
- return isSoftInputVisible(activity, 200);
- }
-
- /**
- * 判断软键盘是否可见
- * @param activity
- * @param minHeightOfSoftInput 软键盘最小高度
- * @return true : 可见, false : 不可见
- */
- public static boolean isSoftInputVisible(final Activity activity, final int minHeightOfSoftInput) {
- return getContentViewInvisibleHeight(activity) >= minHeightOfSoftInput;
- }
-
- /**
- * 计算View的宽度高度
- * @param activity
- * @return
- */
- private static int getContentViewInvisibleHeight(final Activity activity) {
- try {
- final View contentView = activity.findViewById(android.R.id.content);
- Rect rect = new Rect();
- contentView.getWindowVisibleDisplayFrame(rect);
- return contentView.getRootView().getHeight() - rect.height();
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getContentViewInvisibleHeight");
- return 0;
- }
- }
-
- /**
- * 注册软键盘改变监听器
- * @param activity
- * @param listener listener
- */
- public static void registerSoftInputChangedListener(final Activity activity, final OnSoftInputChangedListener listener) {
- try {
- // 获取根View
- final View contentView = activity.findViewById(android.R.id.content);
- // 添加事件
- contentView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
- @Override
- public void onGlobalLayout() {
- if (listener != null) {
- // 获取高度
- int height = getContentViewInvisibleHeight(activity);
- // 判断是否相同
- listener.onSoftInputChanged(height >= 200, height);
- }
- }
- });
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "registerSoftInputChangedListener");
- }
- }
-
- /**
- * 注册软键盘改变监听器
- * @param activity
- * @param listener listener
- */
- public static void registerSoftInputChangedListener2(final Activity activity, final OnSoftInputChangedListener listener) {
- final View decorView = activity.getWindow().getDecorView();
- decorView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
- @Override
- public void onGlobalLayout() {
- if (listener != null){
- try {
- Rect rect = new Rect();
- decorView.getWindowVisibleDisplayFrame(rect);
- // 计算出可见屏幕的高度
- int displayHight = rect.bottom - rect.top;
- // 获得屏幕整体的高度
- int hight = decorView.getHeight();
- // 获得键盘高度
- int keyboardHeight = hight - displayHight;
- // 计算一定比例
- boolean visible = (double) displayHight / hight < 0.8;
- // 判断是否显示
- listener.onSoftInputChanged(visible, keyboardHeight);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "registerSoftInputChangedListener2");
- }
- }
- }
- });
- }
-
- /** 输入法弹出、隐藏改变事件 */
- public interface OnSoftInputChangedListener {
-
- void onSoftInputChanged(boolean visible, int height);
- }
-
- // ==
-
- /**
- * 修复软键盘内存泄漏 在 Activity.onDestroy() 中使用
- * @param context
- */
- public static void fixSoftInputLeaks(final Context context) {
- if (context == null) return;
- try {
- InputMethodManager imm = (InputMethodManager) DevUtils.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
- String[] strArr = new String[]{"mCurRootView", "mServedView", "mNextServedView"};
- for (int i = 0; i < 3; i++) {
- try {
- Field declaredField = imm.getClass().getDeclaredField(strArr[i]);
- if (declaredField == null) continue;
- if (!declaredField.isAccessible()) {
- declaredField.setAccessible(true);
- }
- Object obj = declaredField.get(imm);
- if (obj == null || !(obj instanceof View)) continue;
- View view = (View) obj;
- if (view.getContext() == context) {
- declaredField.set(imm, null);
- } else {
- return;
- }
- } catch (Throwable th) {
- }
- }
- } catch (Exception e){
- }
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/KeyguardUtils.java b/DevLibUtils/src/main/java/dev/utils/app/KeyguardUtils.java
deleted file mode 100644
index 4caab7a7e0..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/KeyguardUtils.java
+++ /dev/null
@@ -1,120 +0,0 @@
-package dev.utils.app;
-
-import android.app.KeyguardManager;
-import android.content.Context;
-import android.os.Build;
-import android.support.annotation.RequiresApi;
-
-import dev.DevUtils;
-
-/**
- * detail: 锁屏工具类 - 锁屏管理, 锁屏、禁用锁屏,判断是否锁屏
- * Created by Ttt
- *
- */
-@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
-public final class KeyguardUtils {
-
- // KeyguardUtils 实例
- private static KeyguardUtils INSTANCE;
-
- /** 获取 KeyguardUtils 实例 ,单例模式 */
- public static KeyguardUtils getInstance() {
- if (INSTANCE == null){
- INSTANCE = new KeyguardUtils();
- }
- return INSTANCE;
- }
-
- // 锁屏管理类
- KeyguardManager keyguardManager;
- // android-26 开始过时
- KeyguardManager.KeyguardLock keyguardLock;
-
- /** 构造函数 */
- private KeyguardUtils() {
- // 获取系统服务
- keyguardManager = (KeyguardManager) DevUtils.getContext().getSystemService(Context.KEYGUARD_SERVICE);
- // 初始化锁
- keyguardLock = keyguardManager.newKeyguardLock("KeyguardUtils");
- }
-
- /**
- * 是否锁屏 - android 4.1以上支持
- * @return
- */
- public boolean isKeyguardLocked() {
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
- return false;
- } else {
- return keyguardManager.isKeyguardLocked();
- }
- }
-
- /**
- * 是否有锁屏密码 - android 4.1以上支持
- * @return
- */
- public boolean isKeyguardSecure() {
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
- return false;
- } else {
- return keyguardManager.isKeyguardSecure();
- }
- }
-
- /**
- * 是否锁屏 - android 4.1 之前
- * @return
- */
- public boolean inKeyguardRestrictedInputMode() {
- return keyguardManager.inKeyguardRestrictedInputMode();
- }
-
- public KeyguardManager getKeyguardManager() {
- return keyguardManager;
- }
-
- public void setKeyguardManager(KeyguardManager keyguardManager) {
- this.keyguardManager = keyguardManager;
- }
-
- // ==
-
- /**
- * 屏蔽系统的屏保
- * 利用 disableKeyguard 解锁, 解锁并不是真正的解锁, 只是把锁屏的界面隐藏掉而已
- */
- public void disableKeyguard() {
- keyguardLock.disableKeyguard();
- }
-
- /**
- * 使能显示锁屏界面,如果你之前调用了disableKeyguard()方法取消锁屏界面,那么会马上显示锁屏界面。
- */
- public void reenableKeyguard() {
- keyguardLock.reenableKeyguard();
- }
-
- /**
- * 释放资源
- */
- public void release() {
- if (keyguardLock != null) {
- // 禁用显示键盘锁定
- keyguardLock.reenableKeyguard();
- }
- }
-
- public void newKeyguardLock (String tag){
- keyguardLock = keyguardManager.newKeyguardLock(tag);
- }
-
- public KeyguardManager.KeyguardLock getKeyguardLock() {
- return keyguardLock;
- }
-
- public void setKeyguardLock(KeyguardManager.KeyguardLock keyguardLock) {
- this.keyguardLock = keyguardLock;
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/ListenerUtils.java b/DevLibUtils/src/main/java/dev/utils/app/ListenerUtils.java
deleted file mode 100644
index 18c514f20a..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/ListenerUtils.java
+++ /dev/null
@@ -1,152 +0,0 @@
-package dev.utils.app;
-
-import android.app.Activity;
-import android.view.View;
-import android.view.Window;
-
-import java.lang.reflect.Field;
-
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: 事件工具类 => AppReflectUtils(可以删除)
- * Created by Ttt
- */
-public final class ListenerUtils {
-
- private ListenerUtils() {
- }
-
- // 日志TAG
- private static final String TAG = ListenerUtils.class.getSimpleName();
-
- /**
- * 获取 View 设置的 OnTouchListener
- * @param view
- * @return
- */
- public static View.OnTouchListener getTouchListener(View view){
- return (View.OnTouchListener) getListenerInfoListener(view, "mOnTouchListener");
- }
-
- /**
- * 获取 View ListenerInfo 对象(内部类)
- * @param view
- * @return
- */
- public static Object getListenerInfo(View view){
- try {
- // 获取 ListenerInfo 对象
- Field infoField = View.class.getDeclaredField("mListenerInfo");
- infoField.setAccessible(true);
- return infoField.get(view);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getListenerInfo");
- }
- return null;
- }
-
- /**
- * 获取 View ListenerInfo 对象内部事件对象
- * @param view
- * @param listener
- * @return
- */
- public static Object getListenerInfoListener(View view, String listener){
- try {
- // 获取 ListenerInfo 对象
- Object listenerInfo = getListenerInfo(view);
- // 获取 ListenerInfo 对象中的 mOnTouchListener 属性
- Class infoClazz = Class.forName("android.view.View$ListenerInfo");
- Field listenerField = infoClazz.getDeclaredField(listener);
- listenerField.setAccessible(true);
- // 进行获取返回
- return listenerField.get(listenerInfo);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getListenerInfoListener");
- }
- return null;
- }
-
- // =
-
- /**
- * 设置点击事件
- * @param view
- * @param onClickListener
- * @param viewIds
- */
- public static void setOnClicks(final View view, final View.OnClickListener onClickListener, final int... viewIds){
- if (view != null && onClickListener != null && viewIds != null){
- for (int i = 0, len = viewIds.length; i < len; i++){
- View findView = findViewById(view, viewIds[i]);
- findView.setOnClickListener(onClickListener);
- }
- }
- }
-
- /**
- * 设置点击事件
- * @param activity
- * @param onClickListener
- * @param viewIds
- */
- public static void setOnClicks(final Activity activity, final View.OnClickListener onClickListener, final int... viewIds){
- if (activity != null && onClickListener != null && viewIds != null){
- for (int i = 0, len = viewIds.length; i < len; i++){
- View findView = findViewById(activity, viewIds[i]);
- findView.setOnClickListener(onClickListener);
- }
- }
- }
-
- /**
- * 设置点击事件
- * @param onClickListener
- * @param views
- */
- public static void setOnClicks(final View.OnClickListener onClickListener, final View... views){
- if (onClickListener != null && views != null){
- for (int i = 0, len = views.length; i < len; i++){
- if (views[i] != null) {
- views[i].setOnClickListener(onClickListener);
- }
- }
- }
- }
-
- // == 初始化View操作等 ==
-
- /**
- * 初始化View
- * @param view
- * @param id
- * @param
- * @return
- */
- private static T findViewById(View view, int id) {
- return view.findViewById(id);
- }
-
- /**
- * 初始化View
- * @param window
- * @param id
- * @param
- * @return
- */
- private static T findViewById(Window window, int id){
- return window.findViewById(id);
- }
-
- /**
- * 初始化View
- * @param activity
- * @param id
- * @param
- * @return
- */
- private static T findViewById(Activity activity, int id) {
- return activity.findViewById(id);
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/LocationUtils.java b/DevLibUtils/src/main/java/dev/utils/app/LocationUtils.java
deleted file mode 100644
index b7e869e7fa..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/LocationUtils.java
+++ /dev/null
@@ -1,363 +0,0 @@
-package dev.utils.app;
-
-import android.annotation.SuppressLint;
-import android.content.Context;
-import android.content.Intent;
-import android.location.Address;
-import android.location.Criteria;
-import android.location.Geocoder;
-import android.location.Location;
-import android.location.LocationListener;
-import android.location.LocationManager;
-import android.location.LocationProvider;
-import android.os.Bundle;
-import android.provider.Settings;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.Locale;
-
-import dev.DevUtils;
-import dev.utils.LogPrintUtils;
-
-import static android.content.Context.LOCATION_SERVICE;
-
-/**
- * detail: 定位相关工具类
- * Created by Ttt
- */
-public final class LocationUtils {
-
- private LocationUtils() {
- }
-
- // 日志TAG
- private static final String TAG = LocationUtils.class.getSimpleName();
-
- /** 时间常量 = 2分钟 */
- private static final int MINUTES_TWO = 1000 * 60 * 2;
- /** 定位改变通知事件 */
- private static OnLocationChangeListener mListener;
- /** 自定义定位事件 */
- private static CustomLocationListener myLocationListener;
- /** 定位管理对象 */
- private static LocationManager mLocationManager;
-
- /**
- * 获取位置, 需要先判断是否开启了定位
- *
- * @param context
- * @param listener
- * @param time 间隔时间
- * @param distance 间隔距离
- * @return {@code Location}
- */
- @SuppressLint("MissingPermission")
- public static Location getLocation(Context context, LocationListener listener, long time, float distance) {
- Location location = null;
- try {
- mLocationManager = (LocationManager) context.getSystemService(LOCATION_SERVICE);
- if (isLocationEnabled()) {
- mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, time, distance, listener);
- if (mLocationManager != null) {
- location = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
- if (location != null) {
- mLocationManager.removeUpdates(listener);
- return location;
- }
- }
- }
- //when GPS is enabled.
- if (isGpsEnabled()) {
- if (location == null) {
- mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, time, distance, listener);
- if (mLocationManager != null) {
- location = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
- if (location != null) {
- mLocationManager.removeUpdates(listener);
- return location;
- }
- }
- }
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e,"getLocation");
- }
- return location;
- }
-
- /**
- * 判断Gps是否可用
- * @return true : 是, false : 否
- */
- public static boolean isGpsEnabled() {
- LocationManager lm = (LocationManager) DevUtils.getContext().getSystemService(LOCATION_SERVICE);
- return lm != null && lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
- }
-
- /**
- * 判断定位是否可用
- * @return true : 是, false : 否
- */
- public static boolean isLocationEnabled() {
- LocationManager lm = (LocationManager) DevUtils.getContext().getSystemService(LOCATION_SERVICE);
- return lm != null && (lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER) || lm.isProviderEnabled(LocationManager.GPS_PROVIDER));
- }
-
- /**
- * 打开Gps设置界面
- */
- public static void openGpsSettings() {
- Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
- DevUtils.getContext().startActivity(intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
- }
-
- /**
- * 注册 - 使用完记得调用{@link #unregister()}
- * 需添加权限 {@code }
- * 需添加权限 {@code }
- * 需添加权限 {@code }
- * 如果{@code minDistance}为0,则通过{@code minTime}来定时更新;
- * {@code minDistance}不为0,则以{@code minDistance}为准;
- * 两者都为0,则随时刷新。
- * @param minTime 位置信息更新周期(单位:毫秒)
- * @param minDistance 位置变化最小距离:当位置距离变化超过此值时,将更新位置信息(单位:米)
- * @param listener 位置刷新的回调接口
- * @return true : 初始化成功, false : 初始化失败
- */
- @SuppressLint("MissingPermission")
- public static boolean register(long minTime, long minDistance, OnLocationChangeListener listener) {
- if (listener == null) return false;
- mLocationManager = (LocationManager) DevUtils.getContext().getSystemService(LOCATION_SERVICE);
- if (mLocationManager == null || (!mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)
- && !mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))) {
- return false;
- }
- mListener = listener;
- String provider = mLocationManager.getBestProvider(getCriteria(), true);
- Location location = mLocationManager.getLastKnownLocation(provider);
- if (location != null) listener.getLastKnownLocation(location);
- if (myLocationListener == null) myLocationListener = new CustomLocationListener();
- mLocationManager.requestLocationUpdates(provider, minTime, minDistance, myLocationListener);
- return true;
- }
-
- /**
- * 注销
- */
- @SuppressLint("MissingPermission")
- public static void unregister() {
- if (mLocationManager != null) {
- if (myLocationListener != null) {
- mLocationManager.removeUpdates(myLocationListener);
- myLocationListener = null;
- }
- mLocationManager = null;
- }
- if (mListener != null) {
- mListener = null;
- }
- }
-
- /**
- * 设置定位参数
- * @return {@link Criteria}
- */
- private static Criteria getCriteria() {
- Criteria criteria = new Criteria();
- // 设置定位精确度 Criteria.ACCURACY_COARSE比较粗略,Criteria.ACCURACY_FINE则比较精细
- criteria.setAccuracy(Criteria.ACCURACY_FINE);
- // 设置是否要求速度
- criteria.setSpeedRequired(false);
- // 设置是否允许运营商收费
- criteria.setCostAllowed(false);
- // 设置是否需要方位信息
- criteria.setBearingRequired(false);
- // 设置是否需要海拔信息
- criteria.setAltitudeRequired(false);
- // 设置对电源的需求
- criteria.setPowerRequirement(Criteria.POWER_LOW);
- return criteria;
- }
-
- /**
- * 根据经纬度获取地理位置
- * @param latitude 纬度
- * @param longitude 经度
- * @return {@link Address}
- */
- public static Address getAddress(double latitude, double longitude) {
- Geocoder geocoder = new Geocoder(DevUtils.getContext(), Locale.getDefault());
- try {
- List addresses = geocoder.getFromLocation(latitude, longitude, 1);
- if (addresses.size() > 0) return addresses.get(0);
- } catch (IOException e) {
- LogPrintUtils.eTag(TAG, e,"getAddress");
- }
- return null;
- }
-
- /**
- * 根据经纬度获取所在国家
- * @param latitude 纬度
- * @param longitude 经度
- * @return 所在国家
- */
- public static String getCountryName(double latitude, double longitude) {
- Address address = getAddress(latitude, longitude);
- return address == null ? "unknown" : address.getCountryName();
- }
-
- /**
- * 根据经纬度获取所在地
- * @param latitude 纬度
- * @param longitude 经度
- * @return 所在地
- */
- public static String getLocality(double latitude, double longitude) {
- Address address = getAddress(latitude, longitude);
- return address == null ? "unknown" : address.getLocality();
- }
-
- /**
- * 根据经纬度获取所在街道
- * @param latitude 纬度
- * @param longitude 经度
- * @return 所在街道
- */
- public static String getStreet(double latitude, double longitude) {
- Address address = getAddress(latitude, longitude);
- return address == null ? "unknown" : address.getAddressLine(0);
- }
-
- /**
- * 是否更好的位置
- * @param newLocation The new Location that you want to evaluate
- * @param currentBestLocation The current Location fix, to which you want to compare the new one
- * @return true : 是, false : 否
- */
- public static boolean isBetterLocation(Location newLocation, Location currentBestLocation) {
- if (currentBestLocation == null) {
- // A new location is always better than no location
- return true;
- }
- // 检查位置信息的时间间隔
- long timeDelta = newLocation.getTime() - currentBestLocation.getTime();
- boolean isSignificantlyNewer = timeDelta > MINUTES_TWO;
- boolean isSignificantlyOlder = timeDelta < -MINUTES_TWO;
- boolean isNewer = timeDelta > 0;
-
- // 如果时间超过2分钟, 则使用新的位置
- if (isSignificantlyNewer) {
- return true;
- } else if (isSignificantlyOlder) { // 时间超过两分钟
- return false;
- }
-
- // 检查新的位置时间
- int accuracyDelta = (int) (newLocation.getAccuracy() - currentBestLocation.getAccuracy());
- boolean isLessAccurate = accuracyDelta > 0;
- boolean isMoreAccurate = accuracyDelta < 0;
- boolean isSignificantlyLessAccurate = accuracyDelta > 200;
-
- // 检查旧位置和新位置是否来自同一提供者。
- boolean isFromSameProvider = isSameProvider(newLocation.getProvider(), currentBestLocation.getProvider());
-
- // 判断最新的位置
- if (isMoreAccurate) {
- return true;
- } else if (isNewer && !isLessAccurate) {
- return true;
- } else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider) {
- return true;
- }
- return false;
- }
-
- /**
- * 是否相同的提供者
- * @param provider0 提供者1
- * @param provider1 提供者2
- * @return true : 是, false : 否
- */
- public static boolean isSameProvider(String provider0, String provider1) {
- if (provider0 == null) {
- return provider1 == null;
- }
- return provider0.equals(provider1);
- }
-
- /**
- * 自定义定位监听事件
- */
- private static class CustomLocationListener implements LocationListener {
- /**
- * 当坐标改变时触发此函数,如果Provider传进相同的坐标,它就不会被触发
- * @param location 坐标
- */
- @Override
- public void onLocationChanged(Location location) {
- if (mListener != null) {
- mListener.onLocationChanged(location);
- }
- }
-
- /**
- * provider的在可用、暂时不可用和无服务三个状态直接切换时触发此函数
- * @param provider 提供者
- * @param status 状态
- * @param extras provider可选包
- */
- @Override
- public void onStatusChanged(String provider, int status, Bundle extras) {
- if (mListener != null) {
- mListener.onStatusChanged(provider, status, extras);
- }
- switch (status) {
- case LocationProvider.AVAILABLE:
- LogPrintUtils.dTag(TAG, "当前GPS状态为可见状态");
- break;
- case LocationProvider.OUT_OF_SERVICE:
- LogPrintUtils.dTag(TAG, "当前GPS状态为服务区外状态");
- break;
- case LocationProvider.TEMPORARILY_UNAVAILABLE:
- LogPrintUtils.dTag(TAG, "当前GPS状态为暂停服务状态");
- break;
- }
- }
-
- /** provider被enable时触发此函数,比如GPS被打开 */
- @Override
- public void onProviderEnabled(String provider) {
- }
-
- /** provider被disable时触发此函数,比如GPS被关闭 */
- @Override
- public void onProviderDisabled(String provider) {
- }
- }
-
- /** 定位改变事件 */
- public interface OnLocationChangeListener {
-
- /**
- * 获取最后一次保留的坐标
- * @param location 坐标
- */
- void getLastKnownLocation(Location location);
-
- /**
- * 当坐标改变时触发此函数,如果Provider传进相同的坐标,它就不会被触发
- * @param location 坐标
- */
- void onLocationChanged(Location location);
-
- /**
- * provider的在可用、暂时不可用和无服务三个状态直接切换时触发此函数
- * @param provider 提供者
- * @param status 状态
- * @param extras provider可选包
- */
- void onStatusChanged(String provider, int status, Bundle extras);//位置状态发生改变
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/ManifestUtils.java b/DevLibUtils/src/main/java/dev/utils/app/ManifestUtils.java
deleted file mode 100644
index 58b5e495aa..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/ManifestUtils.java
+++ /dev/null
@@ -1,147 +0,0 @@
-package dev.utils.app;
-
-import android.content.pm.ApplicationInfo;
-import android.content.pm.PackageInfo;
-import android.content.pm.PackageManager;
-
-import dev.DevUtils;
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: Android Manifest工具类
- * Created by Ttt
- */
-public final class ManifestUtils {
-
- private ManifestUtils(){
- }
-
- // 日志TAG
- private static final String TAG = ManifestUtils.class.getSimpleName();
-
- /**
- * 获取 Manifest Meta Data
- * @param metaKey
- * @return
- */
- public static String getMetaData(String metaKey) {
- try {
- ApplicationInfo appInfo = DevUtils.getContext().getPackageManager().getApplicationInfo(DevUtils.getContext().getPackageName(), PackageManager.GET_META_DATA);
- String data = appInfo.metaData.getString(metaKey);
- return data;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getMetaData");
- }
- return null;
- }
-
- // ==
-
- /**
- * 获取app版本信息
- * @return 0 = versionName , 1 = versionCode
- */
- public static String[] getAppVersion() {
- try {
- PackageManager pm = DevUtils.getContext().getPackageManager();
- PackageInfo pi = pm.getPackageInfo(DevUtils.getContext().getPackageName(), PackageManager.GET_ACTIVITIES);
- if (pi != null) {
- String versionName = pi.versionName == null ? "null" : pi.versionName;
- String versionCode = pi.versionCode + "";
-
- return new String[]{versionName,versionCode};
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getAppVersion");
- }
- return null;
- }
-
- /**
- * 获取app版本号
- * @return 当前版本Code
- */
- public static int getAppVersionCode() {
- try {
- PackageManager pm = DevUtils.getContext().getPackageManager();
- PackageInfo pi = pm.getPackageInfo(DevUtils.getContext().getPackageName(), PackageManager.GET_ACTIVITIES);
- if (pi != null) {
- return pi.versionCode;
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getAppVersionCode");
- }
- return -1;
- }
-
- /**
- * 获取app版本信息
- * @return 当前版本信息
- */
- public static String getAppVersionName() {
- try {
- PackageManager pm = DevUtils.getContext().getPackageManager();
- PackageInfo pi = pm.getPackageInfo(DevUtils.getContext().getPackageName(), PackageManager.GET_ACTIVITIES);
- if (pi != null) {
- return pi.versionName;
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getAppVersionName");
- }
- return null;
- }
-
- // =
-
- /**
- * 获取app版本号 - 内部判断
- * @param packageName
- * @return
- */
- public static int getAppVersionCode(final String packageName) {
- if (isSpace(packageName)) return -1;
- try {
- PackageManager pm = DevUtils.getContext().getPackageManager();
- PackageInfo pi = pm.getPackageInfo(packageName, 0);
- return pi == null ? -1 : pi.versionCode;
- } catch (PackageManager.NameNotFoundException e) {
- LogPrintUtils.eTag(TAG, e, "getAppVersionCode");
- return -1;
- }
- }
-
-
- /**
- * 获取app版本名 - 对外显示
- * @param packageName
- * @return
- */
- public static String getAppVersionName(final String packageName) {
- if (isSpace(packageName)) return null;
- try {
- PackageManager pm = DevUtils.getContext().getPackageManager();
- PackageInfo pi = pm.getPackageInfo(packageName, 0);
- return pi == null ? null : pi.versionName;
- } catch (PackageManager.NameNotFoundException e) {
- LogPrintUtils.eTag(TAG, e, "getAppVersionName");
- return null;
- }
- }
-
- // =
-
- /**
- * 判断字符串是否为 null 或全为空白字符
- * @param str 待校验字符串
- * @return
- */
- private static boolean isSpace(final String str) {
- if (str == null) return true;
- for (int i = 0, len = str.length(); i < len; ++i) {
- if (!Character.isWhitespace(str.charAt(i))) {
- return false;
- }
- }
- return true;
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/MemoryUtils.java b/DevLibUtils/src/main/java/dev/utils/app/MemoryUtils.java
deleted file mode 100644
index cd40be9c65..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/MemoryUtils.java
+++ /dev/null
@@ -1,179 +0,0 @@
-package dev.utils.app;
-
-import android.annotation.TargetApi;
-import android.app.ActivityManager;
-import android.content.Context;
-import android.os.Build;
-import android.text.format.Formatter;
-
-import java.io.BufferedReader;
-import java.io.FileReader;
-
-import dev.DevUtils;
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: 获取内存信息
- * Created by Ttt
- */
-public final class MemoryUtils {
-
- private MemoryUtils(){
- }
-
- // 日志TAG
- private static final String TAG = MemoryUtils.class.getSimpleName();
-
- /**
- * Print memory info. such as:
- * MemTotal: 1864292 kB
- * MemFree: 779064 kB
- * Buffers: 4540 kB
- * Cached: 185656 kB
- * SwapCached: 13160 kB
- * Active: 435588 kB
- * Inactive: 269312 kB
- * Active(anon): 386188 kB
- * Inactive(anon): 132576 kB
- * Active(file): 49400 kB
- * Inactive(file): 136736 kB
- * Unevictable: 2420 kB
- * Mlocked: 0 kB
- * HighTotal: 1437692 kB
- * HighFree: 520212 kB
- * LowTotal: 426600 kB
- * LowFree: 258852 kB
- * SwapTotal: 511996 kB
- * SwapFree: 171876 kB
- * Dirty: 412 kB
- * Writeback: 0 kB
- * AnonPages: 511924 kB
- * Mapped: 152368 kB
- * Shmem: 1636 kB
- * Slab: 109224 kB
- * SReclaimable: 75932 kB
- * SUnreclaim: 33292 kB
- * KernelStack: 13056 kB
- * PageTables: 28032 kB
- * NFS_Unstable: 0 kB
- * Bounce: 0 kB
- * WritebackTmp: 0 kB
- * CommitLimit: 1444140 kB
- * Committed_AS: 25977748 kB
- * VmallocTotal: 458752 kB
- * VmallocUsed: 123448 kB
- * VmallocChunk: 205828 kB
- */
- public static String printMemInfo() {
- try {
- FileReader fileReader = new FileReader(MEM_INFO_PATH);
- BufferedReader bufferedReader = new BufferedReader(fileReader, 4 * 1024);
- StringBuffer stringBuffer = new StringBuffer();
- String str;
- while ((str = bufferedReader.readLine()) != null) {
- // 追加保存内容
- stringBuffer.append(str);
- }
- bufferedReader.close();
- return stringBuffer.toString();
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "printMemInfo");
- }
- return "";
- }
-
- /**
- * 获取内存信息
- * @return
- */
- @TargetApi(Build.VERSION_CODES.CUPCAKE)
- public static ActivityManager.MemoryInfo getMemoryInfo() {
- ActivityManager am = (ActivityManager) DevUtils.getContext().getSystemService(Context.ACTIVITY_SERVICE);
- ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
- am.getMemoryInfo(mi);
- return mi;
- }
-
- /**
- * Print Memory info.
- */
- @TargetApi(Build.VERSION_CODES.CUPCAKE)
- public static ActivityManager.MemoryInfo printMemoryInfo(Context context) {
- ActivityManager.MemoryInfo mi = getMemoryInfo();
- StringBuilder sBuilder = new StringBuilder();
- sBuilder.append("_______ Memory : ");
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
- sBuilder.append("\ntotalMem :").append(mi.totalMem);
- }
- sBuilder.append("\navailMem :").append(mi.availMem);
- sBuilder.append("\nlowMemory :").append(mi.lowMemory);
- sBuilder.append("\nthreshold :").append(mi.threshold);
- return mi;
- }
-
- /**
- * Get available memory info.
- */
- @TargetApi(Build.VERSION_CODES.CUPCAKE)
- public static String getAvailMemory() {// 获取android 当前可用内存大小
- ActivityManager am = (ActivityManager) DevUtils.getContext().getSystemService(Context.ACTIVITY_SERVICE);
- ActivityManager.MemoryInfo mi = new ActivityManager.MemoryInfo();
- am.getMemoryInfo(mi); // mi.availMem; 当前系统的可用内存
- // 将获取的内存大小规格化
- return Formatter.formatFileSize(DevUtils.getContext(), mi.availMem);
- }
-
-
- // 内存信息文件地址
- private static final String MEM_INFO_PATH = "/proc/meminfo";
- // 获取内存总大小
- public static final String MEMTOTAL = "MemTotal";
- // 获取可用内存
- public static final String MEMAVAILABLE = "MemAvailable";
-
-
- /**
- * 获取总内存大小
- * @return
- */
- public static String getTotalMemory() {
- return getMemInfoIype(MEMTOTAL);
- }
-
- /**
- * 获取可用内存大小
- * @return
- */
- public static String getMemoryAvailable() {
- return getMemInfoIype(MEMAVAILABLE);
- }
-
- /**
- * 获取 type info
- * @param type
- * @return
- */
- public static String getMemInfoIype(String type) {
- try {
- FileReader fileReader = new FileReader(MEM_INFO_PATH);
- BufferedReader bufferedReader = new BufferedReader(fileReader, 4 * 1024);
- String str = null;
- while ((str = bufferedReader.readLine()) != null) {
- if (str.contains(type)) {
- break;
- }
- }
- bufferedReader.close();
- /* \\s表示 空格,回车,换行等空白符,
- +号表示一个或多个的意思 */
- String[] array = str.split("\\s+");
- // 获得系统总内存,单位是KB,乘以1024转换为Byte
- long length = Long.valueOf(array[1]).longValue() * 1024;
- return android.text.format.Formatter.formatFileSize(DevUtils.getContext(), length);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getMemInfoIype");
- }
- return "unknown";
- }
-
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/NetWorkUtils.java b/DevLibUtils/src/main/java/dev/utils/app/NetWorkUtils.java
deleted file mode 100644
index ffc4636fa2..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/NetWorkUtils.java
+++ /dev/null
@@ -1,398 +0,0 @@
-package dev.utils.app;
-
-import android.annotation.SuppressLint;
-import android.content.Context;
-import android.net.ConnectivityManager;
-import android.net.NetworkInfo;
-import android.net.NetworkInfo.State;
-import android.net.wifi.WifiManager;
-import android.os.Build;
-import android.support.annotation.RequiresPermission;
-import android.telephony.TelephonyManager;
-
-import java.lang.reflect.Method;
-import java.net.InetAddress;
-import java.net.NetworkInterface;
-import java.net.SocketException;
-import java.net.UnknownHostException;
-import java.util.Enumeration;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-
-import dev.DevUtils;
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: 网络管理工具类
- * Created by Ttt
- */
-public final class NetWorkUtils {
-
- private NetWorkUtils() {
- }
-
- // 日志TAG
- private static final String TAG = NetWorkUtils.class.getSimpleName();
-
- /**
- * 获取移动网络打开状态(默认属于未打开)
- * @return
- */
- public static boolean getMobileDataEnabled() {
- try {
- // 移动网络开关状态
- boolean mState;
- // 属于5.0以下的使用
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
- // 获取网络连接状态
- ConnectivityManager cManager = (ConnectivityManager) DevUtils.getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
- // 反射获取方法
- Method method = cManager.getClass().getMethod("getMobileDataEnabled");
- // 调用方法,获取状态
- mState = (Boolean) method.invoke(cManager);
- } else {
- TelephonyManager tm = (TelephonyManager) DevUtils.getContext().getSystemService(Context.TELEPHONY_SERVICE);
- // 反射获取方法
- Method method = tm.getClass().getDeclaredMethod("getDataEnabled");
- // 调用方法,获取状态
- mState = (Boolean) method.invoke(tm);
- }
- // 返回移动网络开关状态
- return mState;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getMobileDataEnabled");
- }
- return false;
- }
-
- /**
- * 设置移动网络开关(无判断是否已开启移动网络) - 实际无效果, 非系统应用无权限
- * @param isOpen 是否打开移动网络
- * @return 是否执行正常
- * hint:
- * 需系统应用、添加权限
- *
- */
- public static boolean setMobileDataEnabled(boolean isOpen) {
- try {
- // 属于5.0以下的使用
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
- // 获取网络连接状态
- ConnectivityManager cManager = (ConnectivityManager) DevUtils.getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
- // 通过反射设置移动网络
- Method mMethod = ConnectivityManager.class.getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE);
- // 设置移动网络
- mMethod.invoke(cManager, isOpen);
- } else { // 需要 android.Manifest.permission.MODIFY_PHONE_STATE 权限, 普通APP无法获取
- TelephonyManager tm = (TelephonyManager) DevUtils.getContext().getSystemService(Context.TELEPHONY_SERVICE);
- // 通过反射设置移动网络
- Method mMethod = tm.getClass().getDeclaredMethod("setDataEnabled", boolean.class);
- // 设置移动网络
- mMethod.invoke(tm, isOpen);
- }
- } catch (Exception e) { // 开启移动网络失败
- LogPrintUtils.eTag(TAG, e, "setMobileDataEnabled");
- return false;
- }
- return true;
- }
-
- /**
- * 判断是否连接了网络
- */
- @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
- public static boolean isConnect() {
- // 获取手机所有连接管理对象(包括对wi-fi,net等连接的管理)
- try {
- ConnectivityManager cManager = (ConnectivityManager) DevUtils.getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
- if (cManager != null) {
- // 获取网络连接管理的对象
- NetworkInfo nInfo = cManager.getActiveNetworkInfo();
- if (nInfo != null && nInfo.isConnected()) {
- // 判断当前网络是否已经连接
- if (nInfo.getState() == State.CONNECTED) {
- return true;
- }
- }
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "isConnect");
- }
- return false;
- }
-
- /**
- * 获取连接的网络类型
- * @return -1 = 等于未知 , 1 = Wifi, 2 = 移动网络
- */
- @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
- public static int getConnectType() {
- // 获取手机所有连接管理对象(包括对wi-fi,net等连接的管理)
- try {
- // 获取网络连接状态
- ConnectivityManager cManager = (ConnectivityManager) DevUtils.getContext().getSystemService(Context.CONNECTIVITY_SERVICE);
- // 判断连接的是否wifi
- State wifi = cManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).getState();
- // 判断是否连接上
- if (wifi == State.CONNECTED || wifi == State.CONNECTING) {
- return 1;
- } else {
- // 判断连接的是否移动网络
- State mobile = cManager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).getState();
- // 判断移动网络是否连接上
- if (mobile == State.CONNECTED || mobile == State.CONNECTING) {
- return 2;
- }
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getConnectType");
- }
- return -1;
- }
-
- /**
- * 判断是否连接Wifi(连接上、连接中)
- * @return
- */
- @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
- public static boolean isConnWifi() {
- return (getConnectType() == 1);
- }
-
- /**
- * 判断是否连接移动网络(连接上、连接中)
- * @return
- */
- @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
- public static boolean isConnMobileData() {
- return (getConnectType() == 2);
- }
-
- // ===
-
- /** 网络连接类型 */
- public enum NetworkType {
- NETWORK_WIFI,
- NETWORK_4G,
- NETWORK_3G,
- NETWORK_2G,
- NETWORK_UNKNOWN,
- NETWORK_NO
- }
-
- /**
- * 判断网络是否可用
- * @return true: 可用 false: 不可用
- */
- @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
- public static boolean isAvailable() {
- NetworkInfo info = getActiveNetworkInfo();
- return info != null && info.isAvailable();
- }
-
- /**
- * 获取活动网络信息
- * @return NetworkInfo
- */
- @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
- private static NetworkInfo getActiveNetworkInfo() {
- if (DevUtils.getContext() != null){
- try {
- return ((ConnectivityManager) DevUtils.getContext().getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getActiveNetworkInfo");
- }
- }
- return null;
- }
-
- // ==
-
- /**
- * 判断是否4G网络
- * @return
- */
- @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
- public static boolean is4G(){
- return getNetworkType() == NetworkType.NETWORK_4G;
- }
-
- /**
- * 判断wifi是否打开
- * @return
- */
- public static boolean getWifiEnabled() {
- try {
- @SuppressLint("WifiManagerLeak")
- WifiManager wifiManager = (WifiManager) DevUtils.getContext().getSystemService(Context.WIFI_SERVICE);
- return wifiManager.isWifiEnabled();
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getWifiEnabled");
- }
- return false;
- }
-
- /**
- * 判断wifi数据是否可用
- * @return
- */
- @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
- public static boolean isWifiAvailable() {
- return getWifiEnabled() && isAvailable();
- }
-
- /**
- * 获取网络运营商名称 - 中国移动、如中国联通、中国电信
- * @return 运营商名称
- */
- public static String getNetworkOperatorName() {
- try {
- TelephonyManager tm = (TelephonyManager) DevUtils.getContext().getSystemService(Context.TELEPHONY_SERVICE);
- return tm != null ? tm.getNetworkOperatorName() : null;
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getNetworkOperatorName");
- }
- return null;
- }
-
- // ==
-
- /**
- * 获取当前网络类型
- * @return DevUtils.getContext()
- * @return 网络类型
- */
- @RequiresPermission(android.Manifest.permission.ACCESS_NETWORK_STATE)
- public static NetworkType getNetworkType() {
- // 默认网络类型
- NetworkType netType = NetworkType.NETWORK_NO;
- // 获取网络信息
- NetworkInfo networkInfo = getActiveNetworkInfo();
- // 判断是否可用
- if (networkInfo != null && networkInfo.isAvailable()) { // 同 getNetworkClass 方法
- // 属于可用则修改为未知
- netType = NetworkType.NETWORK_UNKNOWN;
- // 获取类型
- switch (networkInfo.getType()){
- case ConnectivityManager.TYPE_WIFI: // 属于Wifi
- netType = NetworkType.NETWORK_WIFI;
- break;
- case ConnectivityManager.TYPE_MOBILE: // 属于手机网络
- switch (networkInfo.getSubtype()) {
- // == 2G网络 ==
- case TelephonyManager.NETWORK_TYPE_GSM:
- case TelephonyManager.NETWORK_TYPE_GPRS:
- case TelephonyManager.NETWORK_TYPE_CDMA:
- case TelephonyManager.NETWORK_TYPE_EDGE:
- case TelephonyManager.NETWORK_TYPE_1xRTT:
- case TelephonyManager.NETWORK_TYPE_IDEN:
- netType = NetworkType.NETWORK_2G;
- break;
- // == 3G网络 ==
- case TelephonyManager.NETWORK_TYPE_TD_SCDMA:
- case TelephonyManager.NETWORK_TYPE_EVDO_A:
- case TelephonyManager.NETWORK_TYPE_UMTS:
- case TelephonyManager.NETWORK_TYPE_EVDO_0:
- case TelephonyManager.NETWORK_TYPE_HSDPA:
- case TelephonyManager.NETWORK_TYPE_HSUPA:
- case TelephonyManager.NETWORK_TYPE_HSPA:
- case TelephonyManager.NETWORK_TYPE_EVDO_B:
- case TelephonyManager.NETWORK_TYPE_EHRPD:
- case TelephonyManager.NETWORK_TYPE_HSPAP:
- netType = NetworkType.NETWORK_3G;
- break;
- // == 4G网络 ==
- case TelephonyManager.NETWORK_TYPE_LTE:
- case TelephonyManager.NETWORK_TYPE_IWLAN:
- //case TelephonyManager.NETWORK_TYPE_LTE_CA: // 19
- case 19:
- netType = NetworkType.NETWORK_4G;
- break;
- default: // 其他判断
- try {
- // 判断子类名字
- String subtypeName = networkInfo.getSubtypeName();
- // == 3G 网络 ==
- if (subtypeName.equalsIgnoreCase("TD-SCDMA")
- || subtypeName.equalsIgnoreCase("WCDMA")
- || subtypeName.equalsIgnoreCase("CDMA2000")) {
- netType = NetworkType.NETWORK_3G;
- } else {
- netType = NetworkType.NETWORK_UNKNOWN;
- }
- } catch (Exception e) {
- // 保存未知
- netType = NetworkType.NETWORK_UNKNOWN;
- }
- break;
- }
- break;
- }
- }
- return netType;
- }
-
- /**
- * 获取域名ip地址
- * @param domain 域名 www.baidu.com 不需要加上http
- * @return ip地址
- */
- public static String getDomainAddress(final String domain) {
- try {
- ExecutorService exec = Executors.newCachedThreadPool();
- Future fs = exec.submit(new Callable() {
- @Override
- public String call() throws Exception {
- InetAddress inetAddress;
- try {
- inetAddress = InetAddress.getByName(domain);
- return inetAddress.getHostAddress();
- } catch (UnknownHostException e) {
- LogPrintUtils.eTag(TAG, e, "getDomainAddress");
- }
- return null;
- }
- });
- return fs.get();
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getDomainAddress");
- }
- return null;
- }
-
- /**
- * 获取IP地址
- * @param useIPv4 是否用IPv4
- * @return IP地址
- */
- public static String getIPAddress(boolean useIPv4) {
- try {
- Enumeration nis = NetworkInterface.getNetworkInterfaces();
- while (nis.hasMoreElements()) {
- NetworkInterface ni = nis.nextElement();
- // 防止小米手机返回10.0.2.15
- if (!ni.isUp()) continue;
- for (Enumeration addresses = ni.getInetAddresses(); addresses.hasMoreElements(); ) {
- InetAddress inetAddress = addresses.nextElement();
- if (!inetAddress.isLoopbackAddress()) {
- String hostAddress = inetAddress.getHostAddress();
- boolean isIPv4 = hostAddress.indexOf(':') < 0;
- if (useIPv4) {
- if (isIPv4) return hostAddress;
- } else {
- if (!isIPv4) {
- int index = hostAddress.indexOf('%');
- return index < 0 ? hostAddress.toUpperCase() : hostAddress.substring(0, index).toUpperCase();
- }
- }
- }
- }
- }
- } catch (SocketException e) {
- LogPrintUtils.eTag(TAG, e, "getIPAddress");
- }
- return null;
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/NotificationUtils.java b/DevLibUtils/src/main/java/dev/utils/app/NotificationUtils.java
deleted file mode 100644
index 43b22ed0fa..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/NotificationUtils.java
+++ /dev/null
@@ -1,300 +0,0 @@
-package dev.utils.app;
-
-import android.app.Notification;
-import android.app.NotificationManager;
-import android.app.PendingIntent;
-import android.content.Context;
-import android.content.Intent;
-import android.graphics.BitmapFactory;
-import android.graphics.Color;
-import android.os.Build;
-
-import dev.DevUtils;
-
-/**
- * detail: 通知栏管理类
- * Created by Ttt
- * https://blog.csdn.net/hss01248/article/details/55096553
- * https://www.jianshu.com/p/cf5f6c30019d
- */
-public final class NotificationUtils {
-
- private NotificationUtils(){
- }
-
- // 通知栏管理类
- private static NotificationManager mNotificationManager = null;
-
- /**
- * 获取通知栏管理类
- * @return
- */
- public static NotificationManager getNotificationManager() {
- if (mNotificationManager == null){
- mNotificationManager = (NotificationManager) DevUtils.getContext().getSystemService(Context.NOTIFICATION_SERVICE);
- }
- return mNotificationManager;
- }
-
- /**
- * 移除通知 - 移除所有通知(只是针对当前Context下的Notification)
- */
- public static void cancelAll(){
- if (getNotificationManager() != null){
- mNotificationManager.cancelAll();
- }
- }
-
- /**
- * 移除通知 - 移除标记为id的通知 (只是针对当前Context下的所有Notification)
- * @param args
- */
- public static void cancel(final int... args){
- if (getNotificationManager() != null && args != null){
- for (int id : args){
- mNotificationManager.cancel(id);
- }
- }
- }
-
- /**
- * 移除通知 - 移除标记为id的通知 (只是针对当前Context下的所有Notification)
- * @param tag
- * @param id
- */
- public static void cancel(final String tag, final int id){
- if (getNotificationManager() != null && tag != null){
- mNotificationManager.cancel(tag, id);
- }
- }
-
- /**
- * 进行通知
- * @param id
- * @param notification
- * @return
- */
- public static boolean notify(final int id, final Notification notification){
- if (getNotificationManager() != null && notification != null){
- mNotificationManager.notify(id, notification);
- return true;
- }
- return false;
- }
-
- /**
- * 进行通知
- * @param tag
- * @param id
- * @param notification
- * @return
- */
- public static boolean notify(final String tag, final int id, final Notification notification){
- if (getNotificationManager() != null && tag != null && notification != null){
- mNotificationManager.notify(tag, id, notification);
- return true;
- }
- return false;
- }
-
- // == 封装外部调用 ==
-
-// // 使用自定义View
-// RemoteViews remoteViews = new RemoteViews(mContext.getPackageName(), R.layout.xxx);
-// // 设置View
-// Notification.builder.setContent(remoteViews);
-
- /**
- * 获取跳转id
- * @param intent
- * @param id
- * @return
- */
- public static PendingIntent crePendingIntent(Intent intent, int id){
- /* 跳转Intent */
- PendingIntent pIntent = PendingIntent.getActivity(DevUtils.getContext(), id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
- return pIntent;
- }
-
- /**
- * 创建通知栏对象
- * @param icon
- * @param title
- * @param msg
- * @return
- */
- public static Notification creNotification(int icon, String title, String msg) {
- return creNotification(null, icon, title, title, msg, true, VibratePattern.obtain(0, 100, 300), LightPattern.obtain(Color.WHITE, 1000, 1000));
- }
-
- /**
- * 创建通知栏对象
- * @param icon
- * @param title
- * @param msg
- * @param vibratePattern
- * @param lightPattern
- * @return
- */
- public static Notification creNotification(int icon, String title, String msg, VibratePattern vibratePattern, LightPattern lightPattern) {
- return creNotification(null, icon, title, title, msg, true, vibratePattern, lightPattern);
- }
-
- /**
- * 创建通知栏对象
- * @param pendingIntent
- * @param icon
- * @param ticker
- * @param title
- * @param msg
- * @param isAutoCancel
- * @param vibratePattern
- * @param lightPattern
- * @return
- */
- public static Notification creNotification(PendingIntent pendingIntent, int icon, String ticker, String title, String msg, boolean isAutoCancel, VibratePattern vibratePattern, LightPattern lightPattern) {
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
- Notification.Builder builder = new Notification.Builder(DevUtils.getContext());
- // 点击通知执行intent
- builder.setContentIntent(pendingIntent);
- // 设置图标
- builder.setSmallIcon(icon);
- // 设置图标
- builder.setLargeIcon(BitmapFactory.decodeResource(DevUtils.getContext().getResources(), icon));
- // 指定通知的ticker内容,通知被创建的时候,在状态栏一闪而过,属于瞬时提示信息。
- builder.setTicker(ticker);
- // 设置标题
- builder.setContentTitle(title);
- // 设置内容
- builder.setContentText(msg);
- // 设置消息提醒,震动 | 声音
- builder.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND);
- // 将AutoCancel设为true后,当你点击通知栏的notification后,它会自动被取消消失
- builder.setAutoCancel(isAutoCancel);
- // 设置时间
- builder.setWhen(System.currentTimeMillis());
- // 设置震动参数
- if (vibratePattern != null && !vibratePattern.isEmpty()){
- builder.setVibrate(vibratePattern.vibrates);
- }
- // 设置 led 灯参数
- if (lightPattern != null){
- builder.setLights(lightPattern.argb, lightPattern.durationMS, lightPattern.startOffMS);
- }
- // = 初始化 Notification 对象 =
- Notification baseNF;
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
- baseNF = builder.getNotification();
- } else {
- baseNF = builder.build();
- }
- return baseNF;
- } else {
-// // https://www.cnblogs.com/Arture/p/5523695.html
-// // -- 初始化通知信息实体类 --
-// Notification notification = new Notification();
-// // 设置图标
-// notification.icon = icon;
-// // 设置图标
-// notification.largeIcon = BitmapFactory.decodeResource(DevUtils.getContext().getResources(), icon);
-// // 指定通知的ticker内容,通知被创建的时候,在状态栏一闪而过,属于瞬时提示信息。
-// notification.tickerText = title;
-// // 设置时间
-// notification.when = System.currentTimeMillis();
-// // 设置消息提醒,震动 | 声音
-// notification.defaults = Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND;
-// // 点击了此通知则取消该通知栏
-// if (isAutoCancel) {
-// notification.flags |= Notification.FLAG_AUTO_CANCEL;
-// }
-// // 设置震动参数
-// if (vibratePattern != null && !vibratePattern.isEmpty()){
-// notification.vibrate = vibratePattern.vibrates;
-// }
-// // 设置 led 灯参数
-// if (lightPattern != null){
-// try {
-// notification.ledARGB = lightPattern.argb; // 控制 LED 灯的颜色,一般有红绿蓝三种颜色可选
-// notification.ledOffMS = lightPattern.startOffMS; // 指定 LED 灯暗去的时长,也是以毫秒为单位
-// notification.ledOnMS = lightPattern.durationMS; // 指定 LED 灯亮起的时长,以毫秒为单位
-// notification.flags = Notification.FLAG_SHOW_LIGHTS;
-// } catch (Exception e){
-// }
-// }
-// // 设置标题内容等 - 已经移除, 现在都是支持 4.0以上, 不需要兼容处理
-// notification.setLatestEventInfo(DevUtils.getContext(), title, msg, pendingIntent);
-// return notification;
- }
- return null;
- }
-
- /**
- * detail: 设置通知栏 Led 灯参数实体类
- * Created by Ttt
- */
- public static class LightPattern {
- /**
- * 手机处于锁屏状态时, LED灯就会不停地闪烁, 提醒用户去查看手机,下面是绿色的灯光一 闪一闪的效果
- */
- private int argb = 0; // 控制 LED 灯的颜色,一般有红绿蓝三种颜色可选
- private int startOffMS = 0; // 指定 LED 灯暗去的时长,也是以毫秒为单位
- private int durationMS = 0; // 指定 LED 灯亮起的时长,以毫秒为单位
-
- private LightPattern(int argb, int startOffMS, int durationMS) {
- this.argb = argb;
- this.startOffMS = startOffMS;
- this.durationMS = durationMS;
- }
-
- /**
- * 获取 Led 配置参数
- * @param argb 颜色
- * @param startOffMS 开始时间
- * @param durationMS 持续时间
- * @return
- */
- public static LightPattern obtain(int argb, int startOffMS, int durationMS) {
- return new LightPattern(argb, startOffMS, durationMS);
- }
- }
-
- /**
- * detail: 设置通知栏 震动参数实体类
- * Created by Ttt
- */
- public static class VibratePattern {
- /**
- * vibrate 属性是一个长整型的数组,用于设置手机静止和振动的时长,以毫秒为单位。
- * 参数中下标为0的值表示手机静止的时长,下标为1的值表示手机振动的时长, 下标为2的值又表示手机静止的时长,以此类推。
- */
- // long[] vibrates = { 0, 1000, 1000, 1000 };
- private long[] vibrates = null;
-
- private VibratePattern(long[] vibrates) {
- this.vibrates = vibrates;
- }
-
- /**
- * 判断是否为null
- * @return
- */
- public boolean isEmpty(){
- if (vibrates != null){
- if (vibrates.length != 0){
- return false;
- }
- }
- return true;
- }
-
- /**
- * 获取 震动时间 配置参数
- * @param args
- * @return
- */
- public static VibratePattern obtain(long... args) {
- return new VibratePattern(args);
- }
- }
-
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/OSUtils.java b/DevLibUtils/src/main/java/dev/utils/app/OSUtils.java
deleted file mode 100644
index c37c46371e..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/OSUtils.java
+++ /dev/null
@@ -1,361 +0,0 @@
-package dev.utils.app;
-
-import android.os.Environment;
-import android.text.TextUtils;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.util.Properties;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: 工具类: OS 系统相关
- * Created by Ttt
- * 简介 : 由于国内定制系统的泛滥, 不同定制系统的一些功能或实现方法会有所不同, 如果需要做到足够好的适配工作, 需要 对不同的定制系统做一些专门的适配.
- * API : 获取 ROM 类型等
- */
-public final class OSUtils {
-
- private OSUtils() {
- }
-
- // 日志TAG
- private static final String TAG = OSUtils.class.getSimpleName();
-
- /** ROM 类型 */
- private static final ROM ROM_TYPE = initRomType();
-
- private static final String KEY_DISPLAY_ID = "ro.build.display.id";
- private static final String KEY_BASE_OS_VERSION = "ro.build.version.base_os";
- private static final String KEY_CLIENT_ID_BASE = "ro.com.google.clientidbase";
-
- // 小米 : MIUI
- private static final String KEY_MIUI_VERSION = "ro.build.version.incremental"; // "7.6.15"
- private static final String KEY_MIUI_VERSION_NANE = "ro.miui.ui.version.name"; // "V8"
- private static final String KEY_MIUI_VERSION_CODE = "ro.miui.ui.version.code"; // "6"
- private static final String VALUE_MIUI_CLIENT_ID_BASE = "android-xiaomi";
-
- // 华为 : EMUI
- private static final String KEY_EMUI_VERSION = "ro.build.version.emui"; // "EmotionUI_3.0"
- private static final String KEY_EMUI_API_LEVEL = "ro.build.hw_emui_api_level"; //
- private static final String KEY_EMUI_SYSTEM_VERSION = "ro.confg.hw_systemversion"; // "T1-A21wV100R001C233B008_SYSIMG"
-
- // 魅族 : Flyme
- private static final String KEY_FLYME_PUBLISHED = "ro.flyme.published"; // "true"
- private static final String KEY_FLYME_SETUP = "ro.meizu.setupwizard.flyme"; // "true"
- private static final String VALUE_FLYME_DISPLAY_ID_CONTAIN = "Flyme"; // "Flyme OS 4.5.4.2U"
-
- // OPPO : ColorOS
- private static final String KEY_COLOROS_VERSION = "ro.oppo.theme.version"; // "703"
- private static final String KEY_COLOROS_THEME_VERSION = "ro.oppo.version"; // ""
- private static final String KEY_COLOROS_ROM_VERSION = "ro.rom.different.version"; // "ColorOS2.1"
- private static final String VALUE_COLOROS_BASE_OS_VERSION_CONTAIN = "OPPO"; // "OPPO/R7sm/R7sm:5.1.1/LMY47V/1440928800:user/release-keys"
- private static final String VALUE_COLOROS_CLIENT_ID_BASE = "android-oppo";
-
- // vivo : FuntouchOS
- private static final String KEY_FUNTOUCHOS_BOARD_VERSION = "ro.vivo.board.version"; // "MD"
- private static final String KEY_FUNTOUCHOS_OS_NAME = "ro.vivo.os.name"; // "Funtouch"
- private static final String KEY_FUNTOUCHOS_OS_VERSION = "ro.vivo.os.version"; // "3.0"
- private static final String KEY_FUNTOUCHOS_DISPLAY_ID = "ro.vivo.os.build.display.id"; // "FuntouchOS_3.0"
- private static final String KEY_FUNTOUCHOS_ROM_VERSION = "ro.vivo.rom.version"; // "rom_3.1"
- private static final String VALUE_FUNTOUCHOS_CLIENT_ID_BASE = "android-vivo";
-
- // Samsung
- private static final String VALUE_SAMSUNG_BASE_OS_VERSION_CONTAIN = "samsung"; // "samsung/zeroltezc/zeroltechn:6.0.1/MMB29K/G9250ZCU2DQD1:user/release-keys"
- private static final String VALUE_SAMSUNG_CLIENT_ID_BASE = "android-samsung";
-
- // Sony
- private static final String KEY_SONY_PROTOCOL_TYPE = "ro.sony.irremote.protocol_type"; // "2"
- private static final String KEY_SONY_ENCRYPTED_DATA = "ro.sony.fota.encrypteddata"; // "supported"
- private static final String VALUE_SONY_CLIENT_ID_BASE = "android-sonyericsson";
-
- // 乐视 : eui
- private static final String KEY_EUI_VERSION = "ro.letv.release.version"; // "5.9.023S"
- private static final String KEY_EUI_VERSION_DATE = "ro.letv.release.version_date"; // "5.9.023S_03111"
- private static final String KEY_EUI_NAME = "ro.product.letv_name"; // "乐1s"
- private static final String KEY_EUI_MODEL = "ro.product.letv_model"; // "Letv X500"
-
- // 金立 : amigo
- private static final String KEY_AMIGO_ROM_VERSION = "ro.gn.gnromvernumber"; // "GIONEE ROM5.0.16"
- private static final String KEY_AMIGO_SYSTEM_UI_SUPPORT = "ro.gn.amigo.systemui.support"; // "yes"
- private static final String VALUE_AMIGO_DISPLAY_ID_CONTAIN = "amigo"; // "amigo3.5.1"
- private static final String VALUE_AMIGO_CLIENT_ID_BASE = "android-gionee";
-
- // 酷派 : yulong
- private static final String KEY_YULONG_VERSION_RELEASE = "ro.yulong.version.release"; // "5.1.046.P1.150921.8676_M01"
- private static final String KEY_YULONG_VERSION_TAG = "ro.yulong.version.tag"; // "LC"
- private static final String VALUE_YULONG_CLIENT_ID_BASE = "android-coolpad";
-
- // HTC : Sense
- private static final String KEY_SENSE_BUILD_STAGE = "htc.build.stage"; // "2"
- private static final String KEY_SENSE_BLUETOOTH_SAP = "ro.htc.bluetooth.sap"; // "true"
- private static final String VALUE_SENSE_CLIENT_ID_BASE = "android-htc-rev";
-
- // LG : LG
- private static final String KEY_LG_SW_VERSION = "ro.lge.swversion"; // "D85720b"
- private static final String KEY_LG_SW_VERSION_SHORT = "ro.lge.swversion_short"; // "V20b"
- private static final String KEY_LG_FACTORY_VERSION = "ro.lge.factoryversion"; // "LGD857AT-00-V20b-CUO-CN-FEB-17-2015+0"
-
- // 联想
- private static final String KEY_LENOVO_DEVICE = "ro.lenovo.device"; // "phone"
- private static final String KEY_LENOVO_PLATFORM = "ro.lenovo.platform"; // "qualcomm"
- private static final String KEY_LENOVO_ADB = "ro.lenovo.adb"; // "apkctl,speedup"
- private static final String VALUE_LENOVO_CLIENT_ID_BASE = "android-lenovo";
-
- /**
- * 获取 ROM 类型
- * @return ROM
- */
- public static ROM getRomType() {
- return ROM_TYPE;
- }
-
- /**
- * 初始化 ROM 类型
- */
- private static ROM initRomType() {
- ROM rom = ROM.Other;
- FileInputStream is = null;
- try {
- Properties buildProperties = new Properties();
- is = new FileInputStream(new File(Environment.getRootDirectory(), "build.prop"));
- buildProperties.load(is);
-
- if (buildProperties.containsKey(KEY_MIUI_VERSION_NANE) || buildProperties.containsKey(KEY_MIUI_VERSION_CODE)) {
- // MIUI
- rom = ROM.MIUI;
- if (buildProperties.containsKey(KEY_MIUI_VERSION_NANE)) {
- String versionName = buildProperties.getProperty(KEY_MIUI_VERSION_NANE);
- if (!TextUtils.isEmpty(versionName) && versionName.matches("[Vv]\\d+")) { // V8
- try {
- rom.setBaseVersion(Integer.parseInt(versionName.split("[Vv]")[1]));
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "initRomType");
- }
- }
- }
- if (buildProperties.containsKey(KEY_MIUI_VERSION)) {
- String versionStr = buildProperties.getProperty(KEY_MIUI_VERSION);
- if (!TextUtils.isEmpty(versionStr) && versionStr.matches("[\\d.]+")) {
- rom.setVersion(versionStr);
- }
- }
- } else if (buildProperties.containsKey(KEY_EMUI_VERSION) || buildProperties.containsKey(KEY_EMUI_API_LEVEL)
- || buildProperties.containsKey(KEY_EMUI_SYSTEM_VERSION)) {
- // EMUI
- rom = ROM.EMUI;
- if (buildProperties.containsKey(KEY_EMUI_VERSION)) {
- String versionStr = buildProperties.getProperty(KEY_EMUI_VERSION);
- Matcher matcher = Pattern.compile("EmotionUI_([\\d.]+)").matcher(versionStr); // EmotionUI_3.0
- if (!TextUtils.isEmpty(versionStr) && matcher.find()) {
- try {
- String version = matcher.group(1);
- rom.setVersion(version);
- rom.setBaseVersion(Integer.parseInt(version.split("\\.")[0]));
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "initRomType");
- }
- }
- }
- } else if (buildProperties.containsKey(KEY_FLYME_SETUP) || buildProperties.containsKey(KEY_FLYME_PUBLISHED)) {
- // Flyme
- rom = ROM.Flyme;
- if (buildProperties.containsKey(KEY_DISPLAY_ID)) {
- String versionStr = buildProperties.getProperty(KEY_DISPLAY_ID);
- Matcher matcher = Pattern.compile("Flyme[^\\d]*([\\d.]+)[^\\d]*").matcher(versionStr); // Flyme OS 4.5.4.2U
- if (!TextUtils.isEmpty(versionStr) && matcher.find()) {
- try {
- String version = matcher.group(1);
- rom.setVersion(version);
- rom.setBaseVersion(Integer.parseInt(version.split("\\.")[0]));
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "initRomType");
- }
- }
- }
- } else if (buildProperties.containsKey(KEY_COLOROS_VERSION) || buildProperties.containsKey(KEY_COLOROS_THEME_VERSION)
- || buildProperties.containsKey(KEY_COLOROS_ROM_VERSION)) {
- // ColorOS
- rom = ROM.ColorOS;
- if (buildProperties.containsKey(KEY_COLOROS_ROM_VERSION)) {
- String versionStr = buildProperties.getProperty(KEY_COLOROS_ROM_VERSION);
- Matcher matcher = Pattern.compile("ColorOS([\\d.]+)").matcher(versionStr); // ColorOS2.1
- if (!TextUtils.isEmpty(versionStr) && matcher.find()) {
- try {
- String version = matcher.group(1);
- rom.setVersion(version);
- rom.setBaseVersion(Integer.parseInt(version.split("\\.")[0]));
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "initRomType");
- }
- }
- }
- } else if (buildProperties.containsKey(KEY_FUNTOUCHOS_OS_NAME) || buildProperties.containsKey(KEY_FUNTOUCHOS_OS_VERSION)
- || buildProperties.containsKey(KEY_FUNTOUCHOS_DISPLAY_ID)) {
- // FuntouchOS
- rom = ROM.FuntouchOS;
- if (buildProperties.containsKey(KEY_FUNTOUCHOS_OS_VERSION)) {
- String versionStr = buildProperties.getProperty(KEY_FUNTOUCHOS_OS_VERSION);
- if (!TextUtils.isEmpty(versionStr) && versionStr.matches("[\\d.]+")) { // 3.0
- try {
- rom.setVersion(versionStr);
- rom.setBaseVersion(Integer.parseInt(versionStr.split("\\.")[0]));
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "initRomType");
- }
- }
- }
- } else if (buildProperties.containsKey(KEY_EUI_VERSION) || buildProperties.containsKey(KEY_EUI_NAME)
- || buildProperties.containsKey(KEY_EUI_MODEL)) {
- // EUI
- rom = ROM.EUI;
- if (buildProperties.containsKey(KEY_EUI_VERSION)) {
- String versionStr = buildProperties.getProperty(KEY_EUI_VERSION);
- Matcher matcher = Pattern.compile("([\\d.]+)[^\\d]*").matcher(versionStr); // 5.9.023S
- if (!TextUtils.isEmpty(versionStr) && matcher.find()) {
- try {
- String version = matcher.group(1);
- rom.setVersion(version);
- rom.setBaseVersion(Integer.parseInt(version.split("\\.")[0]));
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "initRomType");
- }
- }
- }
- } else if (buildProperties.containsKey(KEY_AMIGO_ROM_VERSION) || buildProperties.containsKey(KEY_AMIGO_SYSTEM_UI_SUPPORT)) {
- // amigo
- rom = ROM.AmigoOS;
- if (buildProperties.containsKey(KEY_DISPLAY_ID)) {
- String versionStr = buildProperties.getProperty(KEY_DISPLAY_ID);
- Matcher matcher = Pattern.compile("amigo([\\d.]+)[a-zA-Z]*").matcher(versionStr); // "amigo3.5.1"
- if (!TextUtils.isEmpty(versionStr) && matcher.find()) {
- try {
- String version = matcher.group(1);
- rom.setVersion(version);
- rom.setBaseVersion(Integer.parseInt(version.split("\\.")[0]));
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "initRomType");
- }
- }
- }
- } else if (buildProperties.containsKey(KEY_SONY_PROTOCOL_TYPE) || buildProperties.containsKey(KEY_SONY_ENCRYPTED_DATA)) {
- // Sony
- rom = ROM.Sony;
- } else if (buildProperties.containsKey(KEY_YULONG_VERSION_RELEASE) || buildProperties.containsKey(KEY_YULONG_VERSION_TAG)) {
- // YuLong
- rom = ROM.YuLong;
- } else if (buildProperties.containsKey(KEY_SENSE_BUILD_STAGE) || buildProperties.containsKey(KEY_SENSE_BLUETOOTH_SAP)) {
- // Sense
- rom = ROM.Sense;
- } else if (buildProperties.containsKey(KEY_LG_SW_VERSION) || buildProperties.containsKey(KEY_LG_SW_VERSION_SHORT)
- || buildProperties.containsKey(KEY_LG_FACTORY_VERSION)) {
- // LG
- rom = ROM.LG;
- } else if (buildProperties.containsKey(KEY_LENOVO_DEVICE) || buildProperties.containsKey(KEY_LENOVO_PLATFORM)
- || buildProperties.containsKey(KEY_LENOVO_ADB)) {
- // Lenovo
- rom = ROM.Lenovo;
- } else if (buildProperties.containsKey(KEY_DISPLAY_ID)) {
- String displayId = buildProperties.getProperty(KEY_DISPLAY_ID);
- if (!TextUtils.isEmpty(displayId)) {
- if (displayId.contains(VALUE_FLYME_DISPLAY_ID_CONTAIN)) {
- return ROM.Flyme;
- } else if (displayId.contains(VALUE_AMIGO_DISPLAY_ID_CONTAIN)) {
- return ROM.AmigoOS;
- }
- }
- } else if (buildProperties.containsKey(KEY_BASE_OS_VERSION)) {
- String baseOsVersion = buildProperties.getProperty(KEY_BASE_OS_VERSION);
- if (!TextUtils.isEmpty(baseOsVersion)) {
- if (baseOsVersion.contains(VALUE_COLOROS_BASE_OS_VERSION_CONTAIN)) {
- return ROM.ColorOS;
- } else if (baseOsVersion.contains(VALUE_SAMSUNG_BASE_OS_VERSION_CONTAIN)) {
- return ROM.SamSung;
- }
- }
- } else if (buildProperties.containsKey(KEY_CLIENT_ID_BASE)) {
- String clientIdBase = buildProperties.getProperty(KEY_CLIENT_ID_BASE);
- switch (clientIdBase) {
- case VALUE_MIUI_CLIENT_ID_BASE:
- return ROM.MIUI;
- case VALUE_COLOROS_CLIENT_ID_BASE:
- return ROM.ColorOS;
- case VALUE_FUNTOUCHOS_CLIENT_ID_BASE:
- return ROM.FuntouchOS;
- case VALUE_SAMSUNG_CLIENT_ID_BASE:
- return ROM.SamSung;
- case VALUE_SONY_CLIENT_ID_BASE:
- return ROM.Sony;
- case VALUE_YULONG_CLIENT_ID_BASE:
- return ROM.YuLong;
- case VALUE_SENSE_CLIENT_ID_BASE:
- return ROM.Sense;
- case VALUE_LENOVO_CLIENT_ID_BASE:
- return ROM.Lenovo;
- case VALUE_AMIGO_CLIENT_ID_BASE:
- return ROM.AmigoOS;
- default:
- break;
- }
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "initRomType");
- } finally {
- if (is != null) {
- try {
- is.close();
- } catch (Exception e) {
- }
- }
- }
- return rom;
- }
-
- public enum ROM {
- MIUI, // 小米
- Flyme, // 魅族
- EMUI, // 华为
- ColorOS, // OPPO
- FuntouchOS, // vivo
- SmartisanOS, // 锤子
- EUI, // 乐视
- Sense, // HTC
- AmigoOS, // 金立
- _360OS, // 奇酷360
- NubiaUI, // 努比亚
- H2OS, // 一加
- YunOS, // 阿里巴巴
- YuLong, // 酷派
-
- SamSung, // 三星
- Sony, // 索尼
- Lenovo, // 联想
- LG, // LG
-
- Google, // 原生
-
- Other; // CyanogenMod, Lewa OS, 百度云OS, Tencent OS, 深度OS, IUNI OS, Tapas OS, Mokee
-
- private int baseVersion = -1;
- private String version;
-
- void setVersion(String version) {
- this.version = version;
- }
-
- void setBaseVersion(int baseVersion) {
- this.baseVersion = baseVersion;
- }
-
- public int getBaseVersion() {
- return baseVersion;
- }
-
- public String getVersion() {
- return version;
- }
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/PathUtils.java b/DevLibUtils/src/main/java/dev/utils/app/PathUtils.java
deleted file mode 100644
index 4e7c2182c1..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/PathUtils.java
+++ /dev/null
@@ -1,360 +0,0 @@
-package dev.utils.app;
-
-import android.content.ContentResolver;
-import android.content.ContentUris;
-import android.content.Context;
-import android.database.Cursor;
-import android.net.Uri;
-import android.os.Build;
-import android.os.Environment;
-import android.provider.DocumentsContract;
-import android.provider.MediaStore;
-import android.support.annotation.RequiresApi;
-
-import dev.DevUtils;
-
-/**
- * detail: 路径相关工具类
- * @author: Blankj
- */
-public final class PathUtils {
-
- private PathUtils() {
- }
-
- /**
- * 获取 Android 系统根目录 - path: /system
- * @return 系统根目录
- */
- public static String getRootPath() {
- return Environment.getRootDirectory().getAbsolutePath();
- }
-
- /**
- * 获取 data 目录 - path: /data
- * @return data 目录
- */
- public static String getDataPath() {
- return Environment.getDataDirectory().getAbsolutePath();
- }
-
- /**
- * 获取缓存目录 - path: data/cache
- * @return 缓存目录
- */
- public static String getIntDownloadCachePath() {
- return Environment.getDownloadCacheDirectory().getAbsolutePath();
- }
-
- /**
- * 获取此应用的缓存目录 - path: /data/data/package/cache
- * @return 此应用的缓存目录
- */
- public static String getAppIntCachePath() {
- return DevUtils.getContext().getCacheDir().getAbsolutePath();
- }
-
- /**
- * 获取此应用的文件目录 - path: /data/data/package/files
- * @return 此应用的文件目录
- */
- public static String getAppIntFilesPath() {
- return DevUtils.getContext().getFilesDir().getAbsolutePath();
- }
-
- /**
- * 获取此应用的数据库文件目录 - path: /data/data/package/databases/name
- * @param name 数据库文件名
- * @return 数据库文件目录
- */
- public static String getAppIntDbPath(String name) {
- return DevUtils.getContext().getDatabasePath(name).getAbsolutePath();
- }
-
- /**
- * 获取 Android 外置储存的根目录 - path: /storage/emulated/0
- * @return 外置储存根目录
- */
- public static String getExtStoragePath() {
- return Environment.getExternalStorageDirectory().getAbsolutePath();
- }
-
- /**
- * 获取闹钟铃声目录 - path: /storage/emulated/0/Alarms
- * @return 闹钟铃声目录
- */
- public static String getExtAlarmsPath() {
- return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_ALARMS).getAbsolutePath();
- }
-
- /**
- * 获取相机拍摄的照片和视频的目录 - path: /storage/emulated/0/DCIM
- * @return 照片和视频目录
- */
- public static String getExtDcimPath() {
- return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM).getAbsolutePath();
- }
-
- /**
- * 获取文档目录 - path: /storage/emulated/0/Documents
- * @return 文档目录
- */
- @RequiresApi(api = Build.VERSION_CODES.KITKAT)
- public static String getExtDocumentsPath() {
- return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath();
- }
-
- /**
- * 获取下载目录 - path: /storage/emulated/0/Download
- * @return 下载目录
- */
- public static String getExtDownloadsPath() {
- return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
- }
-
- /**
- * 获取视频目录 - path: /storage/emulated/0/Movies
- * @return 视频目录
- */
- public static String getExtMoviesPath() {
- return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MOVIES).getAbsolutePath();
- }
-
- /**
- * 获取音乐目录 - path: /storage/emulated/0/Music
- * @return 音乐目录
- */
- public static String getExtMusicPath() {
- return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC).getAbsolutePath();
- }
-
- /**
- * 获取提示音目录 - path: /storage/emulated/0/Notifications
- * @return 提示音目录
- */
- public static String getExtNotificationsPath() {
- return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_NOTIFICATIONS).getAbsolutePath();
- }
-
- /**
- * 获取图片目录 - path: /storage/emulated/0/Pictures
- * @return 图片目录
- */
- public static String getExtPicturesPath() {
- return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getAbsolutePath();
- }
-
- /**
- * 获取 Podcasts 目录 - path: /storage/emulated/0/Podcasts
- * @return Podcasts 目录
- */
- public static String getExtPodcastsPath() {
- return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PODCASTS).getAbsolutePath();
- }
-
- /**
- * 获取铃声目录 - path: /storage/emulated/0/Ringtones
- * @return 下载目录
- */
- public static String getExtRingtonesPath() {
- return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_RINGTONES).getAbsolutePath();
- }
-
- /**
- * 获取此应用在外置储存中的缓存目录 - path: /storage/emulated/0/Android/data/package/cache
- * @return 此应用在外置储存中的缓存目录
- */
- public static String getAppExtCachePath() {
- return DevUtils.getContext().getExternalCacheDir().getAbsolutePath();
- }
-
- /**
- * 获取此应用在外置储存中的文件目录 - path: /storage/emulated/0/Android/data/package/files
- * @return 此应用在外置储存中的文件目录
- */
- public static String getAppExtFilePath() {
- return DevUtils.getContext().getExternalFilesDir(null).getAbsolutePath();
- }
-
- /**
- * 获取此应用在外置储存中的闹钟铃声目录 - path: /storage/emulated/0/Android/data/package/files/Alarms
- * @return 此应用在外置储存中的闹钟铃声目录
- */
- public static String getAppExtAlarmsPath() {
- return DevUtils.getContext().getExternalFilesDir(Environment.DIRECTORY_ALARMS).getAbsolutePath();
- }
-
- /**
- * 获取此应用在外置储存中的相机目录 - path: /storage/emulated/0/Android/data/package/files/DCIM
- * @return 此应用在外置储存中的相机目录
- */
- public static String getAppExtDcimPath() {
- return DevUtils.getContext().getExternalFilesDir(Environment.DIRECTORY_DCIM).getAbsolutePath();
- }
-
- /**
- * 获取此应用在外置储存中的文档目录 - path: /storage/emulated/0/Android/data/package/files/Documents
- * @return 此应用在外置储存中的文档目录
- */
- @RequiresApi(api = Build.VERSION_CODES.KITKAT)
- public static String getAppExtDocumentsPath() {
- return DevUtils.getContext().getExternalFilesDir(Environment.DIRECTORY_DOCUMENTS).getAbsolutePath();
- }
-
- /**
- * 获取此应用在外置储存中的闹钟目录 - path: /storage/emulated/0/Android/data/package/files/Download
- * @return 此应用在外置储存中的闹钟目录
- */
- public static String getAppExtDownloadPath() {
- return DevUtils.getContext().getExternalFilesDir(Environment.DIRECTORY_DOWNLOADS).getAbsolutePath();
- }
-
- /**
- * 获取此应用在外置储存中的视频目录 - path: /storage/emulated/0/Android/data/package/files/Movies
- * @return 此应用在外置储存中的视频目录
- */
- public static String getAppExtMoviesPath() {
- return DevUtils.getContext().getExternalFilesDir(Environment.DIRECTORY_MOVIES).getAbsolutePath();
- }
-
- /**
- * 获取此应用在外置储存中的音乐目录 - path: /storage/emulated/0/Android/data/package/files/Music
- * @return 此应用在外置储存中的音乐目录
- */
- public static String getAppExtMusicPath() {
- return DevUtils.getContext().getExternalFilesDir(Environment.DIRECTORY_MUSIC).getAbsolutePath();
- }
-
- /**
- * 获取此应用在外置储存中的提示音目录 - path: /storage/emulated/0/Android/data/package/files/Notifications
- * @return 此应用在外置储存中的提示音目录
- */
- public static String getAppExtNotificationsPath() {
- return DevUtils.getContext().getExternalFilesDir(Environment.DIRECTORY_NOTIFICATIONS).getAbsolutePath();
- }
-
- /**
- * 获取此应用在外置储存中的图片目录 - path: /storage/emulated/0/Android/data/package/files/Pictures
- * @return 此应用在外置储存中的图片目录
- */
- public static String getAppExtPicturesPath() {
- return DevUtils.getContext().getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath();
- }
-
- /**
- * 获取此应用在外置储存中的 Podcasts 目录 - path: /storage/emulated/0/Android/data/package/files/Podcasts
- * @return 此应用在外置储存中的 Podcasts 目录
- */
- public static String getAppExtPodcastsPath() {
- return DevUtils.getContext().getExternalFilesDir(Environment.DIRECTORY_PODCASTS).getAbsolutePath();
- }
-
- /**
- * 获取此应用在外置储存中的铃声目录 - path: /storage/emulated/0/Android/data/package/files/Ringtones
- * @return 此应用在外置储存中的铃声目录
- */
- public static String getAppExtRingtonesPath() {
- return DevUtils.getContext().getExternalFilesDir(Environment.DIRECTORY_RINGTONES).getAbsolutePath();
- }
-
- /**
- * 获取此应用的 Obb 目录 - path: /storage/emulated/0/Android/obb/package
- * 一般用来存放游戏数据包
- * @return 此应用的 Obb 目录
- */
- public static String getObbPath() {
- return DevUtils.getContext().getObbDir().getAbsolutePath();
- }
-
- public static String getFilePathByUri(Context context, Uri uri) {
- String path = null;
- // 以 file:// 开头的
- if (ContentResolver.SCHEME_FILE.equals(uri.getScheme())) {
- path = uri.getPath();
- return path;
- }
- // 以 content:// 开头的,比如 content://media/extenral/images/media/17766
- if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme()) && Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
- Cursor cursor = context.getContentResolver().query(uri, new String[]{MediaStore.Images.Media.DATA}, null, null, null);
- if (cursor != null) {
- if (cursor.moveToFirst()) {
- int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
- if (columnIndex > -1) {
- path = cursor.getString(columnIndex);
- }
- }
- cursor.close();
- }
- return path;
- }
- // 4.4及之后的 是以 content:// 开头的,比如 content://com.android.providers.media.documents/document/image%3A235700
- if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme()) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
- if (DocumentsContract.isDocumentUri(context, uri)) {
- if (isExternalStorageDocument(uri)) {
- // ExternalStorageProvider
- final String docId = DocumentsContract.getDocumentId(uri);
- final String[] split = docId.split(":");
- final String type = split[0];
- if ("primary".equalsIgnoreCase(type)) {
- path = Environment.getExternalStorageDirectory() + "/" + split[1];
- return path;
- }
- } else if (isDownloadsDocument(uri)) {
- // DownloadsProvider
- final String id = DocumentsContract.getDocumentId(uri);
- final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"),
- Long.valueOf(id));
- path = getDataColumn(context, contentUri, null, null);
- return path;
- } else if (isMediaDocument(uri)) {
- // MediaProvider
- final String docId = DocumentsContract.getDocumentId(uri);
- final String[] split = docId.split(":");
- final String type = split[0];
- Uri contentUri = null;
- if ("image".equals(type)) {
- contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
- } else if ("video".equals(type)) {
- contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
- } else if ("audio".equals(type)) {
- contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
- }
- final String selection = "_id=?";
- final String[] selectionArgs = new String[]{split[1]};
- path = getDataColumn(context, contentUri, selection, selectionArgs);
- return path;
- }
- }
- }
- return null;
- }
-
- private static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
- Cursor cursor = null;
- final String column = "_data";
- final String[] projection = {column};
- try {
- cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);
- if (cursor != null && cursor.moveToFirst()) {
- final int column_index = cursor.getColumnIndexOrThrow(column);
- return cursor.getString(column_index);
- }
- } finally {
- if (cursor != null)
- cursor.close();
- }
- return null;
- }
-
- private static boolean isExternalStorageDocument(Uri uri) {
- return "com.android.externalstorage.documents".equals(uri.getAuthority());
- }
-
- private static boolean isDownloadsDocument(Uri uri) {
- return "com.android.providers.downloads.documents".equals(uri.getAuthority());
- }
-
- private static boolean isMediaDocument(Uri uri) {
- return "com.android.providers.media.documents".equals(uri.getAuthority());
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/PermissionUtils.java b/DevLibUtils/src/main/java/dev/utils/app/PermissionUtils.java
deleted file mode 100644
index 5950762201..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/PermissionUtils.java
+++ /dev/null
@@ -1,383 +0,0 @@
-package dev.utils.app;
-
-import android.Manifest;
-import android.app.Activity;
-import android.app.Fragment;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.os.Build;
-import android.os.Bundle;
-import android.os.Handler;
-import android.os.Looper;
-import android.support.annotation.NonNull;
-import android.support.annotation.Nullable;
-import android.support.annotation.RequiresApi;
-import android.support.v4.app.ActivityCompat;
-import android.support.v4.content.ContextCompat;
-
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import dev.DevUtils;
-
-/**
- * detail: 权限请求工具类
- * Created by Ttt
- * hint:
- * -
- * 参考:
- * https://github.com/anthonycr/Grant
- * compile 'com.anthonycr.grant:permissions:1.0'
- * -
- * 权限介绍
- * https://www.cnblogs.com/mengdd/p/4892856.html
- * -
- * 第三方库:
- * PermissionsDispatcher: https://github.com/hotchemi/PermissionsDispatcher
- * RxPermissions: https://github.com/tbruyelle/RxPermissions
- * Grant: https://github.com/anthonycr/Grant
- * -
- * 使用方法
- * // 第一种请求方式
- * PermissionUtils.permission("").callBack(null).request();
- * // 第二种请求方式 - 需要在 onRequestPermissionsResult 中通知调用
- * PermissionUtils.permission("").callBack(null).request(Activity);
- * ======
- * 注意事项: 需要注意在onResume 中调用
- * 不管是第一种方式, 跳自定义的Activity, 还是第二种 系统内部跳转授权页面, 都会多次触发onResume
- * https://www.aliyun.com/jiaocheng/8030.html
- * 尽量避免在 onResume中调用
- * com.anthonycr.grant:permissions:1.0 也是会触发onResume 只是 通过 Set mPendingRequests 来控制请求过的权限
- * 拒绝后在onResume 方法内再次请求, 直接触发授权成功, 如果需要清空通过调用 notifyPermissionsChange 通知改变, 否则一直调用获取权限,拒绝过后,都会认为是请求通过
- */
-public final class PermissionUtils {
-
- /** Permission 请求Code */
- public static final int P_REQUEST_CODE = 100;
- /** 全部权限 */
- private final static Set mAllPermissions = new HashSet<>(1);
- // 判断是否请求过
- private boolean isRequest = false;
- /** 申请的权限 */
- private List mPermissions = new ArrayList<>();
- /** 准备请求的权限 */
- private List mPermissionsRequest = new ArrayList<>();
- /** 申请通过的权限 */
- private List mPermissionsGranted = new ArrayList<>();
- /** 申请未通过的权限 */
- private List mPermissionsDenied = new ArrayList<>();
- /** 申请未通过的权限 - 永久拒绝 */
- private List mPermissionsDeniedForever = new ArrayList<>();
- /** 查询不到的权限 */
- private List mPermissionsNotFound = new ArrayList<>();
- /** 操作回调 */
- private PermissionCallBack mCallBack;
- /** 回调方法 */
- private Looper mLooper = Looper.getMainLooper();
-
- static {
- // 初始化权限数据
- initializePermissionsMap();
- }
-
- /** 初始化遍历保存全部权限 */
- private static synchronized void initializePermissionsMap() {
- Field[] fields = Manifest.permission.class.getFields();
- for (Field field : fields) {
- String name = null;
- try {
- name = (String) field.get("");
- } catch (IllegalAccessException e) {
- }
- mAllPermissions.add(name);
- }
- }
-
- // =
-
- /**
- * 构造函数
- * @param permissions
- */
- private PermissionUtils(final String... permissions){
- mPermissions.clear();
- // 防止数据为null
- if (permissions != null && permissions.length != 0){
- // 遍历全部需要申请的权限
- for (String permission : permissions){
- mPermissions.add(permission);
- }
- }
- }
-
- // ==
-
- /**
- * 判断是否授予了权限
- * @param permissions
- * @return
- */
- public static boolean isGranted(final String... permissions) {
- // 防止数据为null
- if (permissions != null && permissions.length != 0) {
- // 遍历全部需要申请的权限
- for (String permission : permissions) {
- if (!isGranted(DevUtils.getContext(), permission)) {
- return false;
- }
- }
- }
- return true;
- }
-
- /**
- * 判断是否授予了权限
- * @param context
- * @param permission
- * @return
- */
- private static boolean isGranted(final Context context, final String permission) {
- // SDK 版本小于 23 则表示直接通过 || 检查是否通过权限
- return Build.VERSION.SDK_INT < Build.VERSION_CODES.M || PackageManager.PERMISSION_GRANTED == ContextCompat.checkSelfPermission(context, permission);
- }
-
- /**
- * 是否拒绝了权限 - 拒绝过一次, 再次申请时, 弹出选择不再提醒并拒绝才会触发 true
- * @param activity
- * @param permission
- * @return
- */
- public static boolean shouldShowRequestPermissionRationale(Activity activity, final String permission){
- return ActivityCompat.shouldShowRequestPermissionRationale(activity, permission);
- }
-
- // == 使用方法 ==
-
- /**
- * 申请权限初始化
- * @param permissions
- * @return
- */
- public static PermissionUtils permission(final String... permissions){
- return new PermissionUtils(permissions);
- }
-
- /**
- * 设置回调方法
- * @param callBack
- */
- public PermissionUtils callBack(PermissionCallBack callBack){
- if (isRequest){
- return this;
- }
- this.mCallBack = callBack;
- return this;
- }
-
- /**
- * 权限判断处理
- * @return -1 已经请求过, 0 = 不处理, 1 = 需要请求
- */
- private int checkPermissions(){
- if (isRequest){
- return -1; // 已经申请过
- }
- isRequest = true;
- // 如果 SDK 版本小于 23 则直接通过
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
- // 表示全部权限都通过
- mPermissionsGranted.addAll(mPermissions);
- // 处理请求回调
- requestCallback();
- } else {
- for (String permission : mPermissions){
- // 首先判断是否存在
- if (mAllPermissions.contains(permission)){
- // 判断是否通过请求
- if (isGranted(DevUtils.getContext(), permission)){
- mPermissionsGranted.add(permission); // 权限允许通过
- } else {
- mPermissionsRequest.add(permission); // 准备请求权限
- }
- } else {
- // 保存到没找到的权限集合
- mPermissionsNotFound.add(permission);
- }
- }
- // 判断是否存在等待请求的权限
- if (mPermissionsRequest.isEmpty()){
- // 处理请求回调
- requestCallback();
- } else { // 表示需要申请
- return 1;
- }
- }
- // 表示不需要申请
- return 0;
- }
-
- /**
- * 请求权限
- * --
- * 内部自动调用 PermissionUtils.isGranted, 并且进行判断处理
- * 无需调用以下代码判断
- * boolean isGranted = PermissionUtils.isGranted(Manifest.permission.xx);
- */
- public void request(){
- if (checkPermissions() == 1){
- // 如果 SDK 版本大于 23 才请求
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
- sInstance = this;
- // 自定义Activity
- PermissionUtils.PermissionActivity.start(DevUtils.getContext());
- }
- }
- }
-
- /**
- * 请求权限
- * @param activity {@link Fragment#getActivity()}
- */
- public void request(Activity activity){
- request(activity, P_REQUEST_CODE);
- }
-
- /**
- * 请求权限 - 需要在Activity 的 onRequestPermissionsResult 回调中 调用 PermissionUtils.onRequestPermissionsResult(this);
- * @param activity {@link Fragment#getActivity()}
- * @param requestCode
- */
- public void request(Activity activity, int requestCode){
- if (checkPermissions() == 1 && activity != null){
- // 如果 SDK 版本大于 23 才请求
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
- sInstance = this;
- // 请求权限
- String[] permissions = mPermissionsRequest.toArray(new String[mPermissionsRequest.size()]);
- // 请求权限
- ActivityCompat.requestPermissions(activity, permissions, requestCode);
- }
- }
- }
-
- // == 请求权限回调 ==
-
- public interface PermissionCallBack {
- /**
- * 授权通过权限
- * @param permissionUtils
- */
- void onGranted(PermissionUtils permissionUtils);
-
- /**
- * 授权未通过权限
- * @param permissionUtils
- */
- void onDenied(PermissionUtils permissionUtils);
- }
-
- // == 内部Activity ==
-
- // 内部持有对象
- private static PermissionUtils sInstance;
-
- // 实现Activity的透明效果
- // https://blog.csdn.net/u014434080/article/details/52260407
- @RequiresApi(api = Build.VERSION_CODES.M)
- public static class PermissionActivity extends Activity {
-
- public static void start(final Context context) {
- Intent starter = new Intent(context, PermissionActivity.class);
- starter.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- context.startActivity(starter);
- }
-
- @Override
- protected void onCreate(@Nullable Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- // 请求权限
- int size = sInstance.mPermissionsRequest.size();
- requestPermissions(sInstance.mPermissionsRequest.toArray(new String[size]), 1);
- }
-
- @Override
- public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
- sInstance.onRequestPermissionsResultCommon(this); // 处理回调
- finish(); // 关闭当前页面
- }
- }
-
- // == 内部处理方法 ==
-
- /** 内部请求回调, 统一处理方法 */
- private void requestCallback() {
- if (mCallBack != null){
- // 判断是否允许全部权限
- boolean isGrantedAll = (mPermissions.size() == mPermissionsGranted.size());
- // 允许则触发回调
- if (isGrantedAll){
- new Handler(mLooper).post(new Runnable() {
- @Override
- public void run() {
- mCallBack.onGranted(PermissionUtils.this);
- }
- });
- } else {
- new Handler(mLooper).post(new Runnable() {
- @Override
- public void run() {
- mCallBack.onDenied(PermissionUtils.this);
- }
- });
- }
- }
- }
-
- /**
- * 请求回调权限回调处理 - 通用
- * @param activity
- */
- private void onRequestPermissionsResultCommon(final Activity activity) {
- // 获取权限状态
- getPermissionsStatus(activity);
- // 判断请求结果
- requestCallback();
- }
-
- /**
- * 获取权限状态
- * @param activity
- */
- private void getPermissionsStatus(final Activity activity) {
- for (String permission : mPermissionsRequest) {
- // 判断是否通过请求
- if (isGranted(activity, permission)){
- mPermissionsGranted.add(permission);
- } else {
- // 未授权
- mPermissionsDenied.add(permission);
- // 拒绝权限
- if (!shouldShowRequestPermissionRationale(activity, permission)) {
- mPermissionsDeniedForever.add(permission);
- }
- }
- }
- }
-
- // == 通过传入Activity 方式 ==
-
- /**
- * 请求权限回调 - 需要在 onRequestPermissionsResult 回调里面调用
- * @param activity
- */
- public static void onRequestPermissionsResult(Activity activity){
- if (activity != null && sInstance != null){
- // 触发回调
- sInstance.onRequestPermissionsResultCommon(activity);
- }
- }
-}
\ No newline at end of file
diff --git a/DevLibUtils/src/main/java/dev/utils/app/PhoneUtils.java b/DevLibUtils/src/main/java/dev/utils/app/PhoneUtils.java
deleted file mode 100644
index ca38436017..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/PhoneUtils.java
+++ /dev/null
@@ -1,808 +0,0 @@
-package dev.utils.app;
-
-import android.annotation.SuppressLint;
-import android.app.Activity;
-import android.app.PendingIntent;
-import android.content.ContentResolver;
-import android.content.Context;
-import android.content.Intent;
-import android.database.Cursor;
-import android.net.Uri;
-import android.os.SystemClock;
-import android.provider.ContactsContract;
-import android.provider.Settings;
-import android.telephony.SmsManager;
-import android.telephony.TelephonyManager;
-import android.text.TextUtils;
-import android.util.Xml;
-
-import org.xmlpull.v1.XmlSerializer;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.UUID;
-
-import dev.DevUtils;
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: 手机相关工具类
- * Created by Ttt
- */
-public final class PhoneUtils {
-
- private PhoneUtils() {
- }
-
- // 日志TAG
- private static final String TAG = PhoneUtils.class.getSimpleName();
-
- /**
- * 判断是否装载sim卡
- * @return
- */
- public static boolean isSimReady() {
- try {
- // 获取电话管理类
- TelephonyManager tpManager = (TelephonyManager) DevUtils.getContext().getSystemService(Context.TELEPHONY_SERVICE);
- // 是否准备完毕
- if(tpManager != null && tpManager.getSimState() == TelephonyManager.SIM_STATE_READY) {
- return true;
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "isSimReady");
- }
- return false;
- }
-
- /**
- * 获取Sim卡所属地区,非国内地区暂不支持播放
- * @return 返回SIM的地区码
- */
- public static String getUserCountry() {
- try {
- TelephonyManager tpManager = (TelephonyManager) DevUtils.getContext().getSystemService(Context.TELEPHONY_SERVICE);
- String simCountry = tpManager.getSimCountryIso();
- if (simCountry != null && simCountry.length() == 2) {
- // SIM country code is available
- return simCountry.toLowerCase(Locale.CHINA);
- } else if (tpManager.getPhoneType() != TelephonyManager.PHONE_TYPE_CDMA) {
- // device is not 3G (would be unreliable)
- String networkCountry = tpManager.getNetworkCountryIso();
- if (networkCountry != null && networkCountry.length() == 2) {
- // network country code is available
- return networkCountry.toLowerCase(Locale.CHINESE);
- }
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getUserCountry");
- }
- return null;
- }
-
- /**
- * 判断地区,是否属于国内
- * @return 状态码 1 属于国内(中国),2 属于 国外,3 属于无SIM卡
- */
- public static int judgeArea() {
- // 默认属于无sim卡
- int state = 3;
- try {
- String countryCode = getUserCountry();
- // 不等于null,表示属于存在SIM卡
- if (countryCode != null) {
- // zh_CN Locale.SIMPLIFIED_CHINESE
- // 截取前面两位属于zh表示属于中国
- String country = countryCode.substring(0, 2);
- // 如果属于ch开头表示属于中国
- if (country.toLowerCase().equals("cn")) {
- state = 1;
- } else {
- state = 2;
- }
- } else { // 不存在sim卡
- String localCountry = Locale.getDefault().getCountry();
- // 如果属于ch开头表示属于中国
- if (localCountry.toLowerCase().equals("cn")) {
- return 1;
- } else {
- return 2;
- }
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "judgeArea");
- }
- return state;
- }
-
- /**
- * 判断设备是否是手机
- * @return true : 是, false : 否
- */
- public static boolean isPhone() {
- try {
- TelephonyManager telephonyManager = (TelephonyManager) DevUtils.getContext().getSystemService(Context.TELEPHONY_SERVICE);
- return telephonyManager != null && telephonyManager.getPhoneType() != TelephonyManager.PHONE_TYPE_NONE;
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "isPhone");
- }
- return false;
- }
-
- /**
- * 获取 IMEI 码
- *
- * @return IMEI 码
- * ==========
- * IMEI是International Mobile Equipment Identity (国际移动设备标识)的简称
- * IMEI由15位数字组成的”电子串号”,它与每台手机一一对应,而且该码是全世界唯一的
- * 其组成为:
- * 1. 前6位数(TAC)是”型号核准号码”,一般代表机型
- * 2. 接着的2位数(FAC)是”最后装配号”,一般代表产地
- * 3. 之后的6位数(SNR)是”串号”,一般代表生产顺序号
- * 4. 最后1位数(SP)通常是”0″,为检验码,目前暂备用
- */
- @SuppressLint({"HardwareIds", "MissingPermission"})
- public static String getIMEI() {
- try {
- TelephonyManager telephonyManager = (TelephonyManager) DevUtils.getContext().getSystemService(Context.TELEPHONY_SERVICE);
- return telephonyManager != null ? telephonyManager.getDeviceId() : null;
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getIMEI");
- }
- return null;
- }
-
- /**
- * 获取 IMSI 码
- *
- * @return IMSI 码
- * =========
- * IMSI是国际移动用户识别码的简称(International Mobile Subscriber Identity)
- * IMSI共有15位,其结构如下:
- * MCC+MNC+MIN
- * MCC:Mobile Country Code,移动国家码,共3位,中国为460;
- * MNC:Mobile NetworkCode,移动网络码,共2位
- * 在中国,移动的代码为电00和02,联通的代码为01,电信的代码为03
- * 合起来就是(也是Android手机中APN配置文件中的代码):
- * 中国移动:46000 46002
- * 中国联通:46001
- * 中国电信:46003
- * 举例,一个典型的IMSI号码为460030912121001
- */
- @SuppressLint({"HardwareIds", "MissingPermission"})
- public static String getIMSI() {
- try {
- TelephonyManager telephonyManager = (TelephonyManager) DevUtils.getContext().getSystemService(Context.TELEPHONY_SERVICE);
- return telephonyManager != null ? telephonyManager.getSubscriberId() : null;
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getIMSI");
- }
- return null;
- }
-
- /**
- * 获取IMSI处理过后的简称
- * @param IMSI
- * @return
- */
- public static String getIMSIIDName(String IMSI){
- if (IMSI != null) {
- if (IMSI.startsWith("46000") || IMSI.startsWith("46002")) {
- return "中国移动";
- } else if (IMSI.startsWith("46001")) {
- return "中国联通";
- } else if (IMSI.startsWith("46003")) {
- return "中国电信";
- }
- }
- return null;
- }
-
- /**
- * 获取移动终端类型
- * @return 手机制式
- * {@link TelephonyManager#PHONE_TYPE_NONE } : 0 手机制式未知
- * {@link TelephonyManager#PHONE_TYPE_GSM } : 1 手机制式为 GSM,移动和联通
- * {@link TelephonyManager#PHONE_TYPE_CDMA } : 2 手机制式为 CDMA,电信
- * {@link TelephonyManager#PHONE_TYPE_SIP } : 3
- */
- public static int getPhoneType() {
- try {
- TelephonyManager telephonyManager = (TelephonyManager) DevUtils.getContext().getSystemService(Context.TELEPHONY_SERVICE);
- return telephonyManager != null ? telephonyManager.getPhoneType() : -1;
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getPhoneType");
- }
- return -1;
- }
-
- /**
- * 判断 sim 卡是否准备好
- * @return true : 是, false : 否
- */
- public static boolean isSimCardReady() {
- try {
- TelephonyManager telephonyManager = (TelephonyManager) DevUtils.getContext().getSystemService(Context.TELEPHONY_SERVICE);
- return telephonyManager != null && telephonyManager.getSimState() == TelephonyManager.SIM_STATE_READY;
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "isSimCardReady");
- }
- return false;
- }
-
- /**
- * 获取 Sim 卡运营商名称 => 中国移动、如中国联通、中国电信
- * @return sim 卡运营商名称
- */
- public static String getSimOperatorName() {
- try {
- TelephonyManager telephonyManager = (TelephonyManager) DevUtils.getContext().getSystemService(Context.TELEPHONY_SERVICE);
- return telephonyManager != null ? telephonyManager.getSimOperatorName() : null;
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getSimOperatorName");
- }
- return null;
- }
-
- /**
- * 获取 Sim 卡运营商名称 => 中国移动、如中国联通、中国电信
- * @return 移动网络运营商名称
- */
- public static String getSimOperatorByMnc() {
- try {
- TelephonyManager telephonyManager = (TelephonyManager) DevUtils.getContext().getSystemService(Context.TELEPHONY_SERVICE);
- String operator = telephonyManager != null ? telephonyManager.getSimOperator() : null;
- if (operator == null) return null;
- switch (operator) {
- case "46000":
- case "46002":
- case "46007":
- return "中国移动";
- case "46001":
- return "中国联通";
- case "46003":
- return "中国电信";
- default:
- return operator;
- }
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getSimOperatorByMnc");
- }
- return null;
- }
-
- /**
- * 获取设备id
- *
- * @return
- */
- @SuppressLint({"HardwareIds", "MissingPermission"})
- public static String getDeviceId(){
- try {
- TelephonyManager telephonyManager = (TelephonyManager) DevUtils.getContext().getSystemService(Context.TELEPHONY_SERVICE);
- if (telephonyManager == null) return "";
- return telephonyManager.getDeviceId();
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getDeviceId");
- }
- return null;
- }
-
- /**
- * 返回设备序列化
- * @return
- */
- public static String getSerialNumber(){
- return android.os.Build.SERIAL;
- }
-
- /**
- * 获取Android id
- * @return
- */
- public static String getAndroidId() {
- try {
- // 在设备首次启动时,系统会随机生成一个64位的数字,并把这个数字以16进制字符串的形式保存下来,这个16进制的字符串就是ANDROID_ID,当设备被wipe后该值会被重置。
- String androidId = Settings.Secure.getString(DevUtils.getContext().getContentResolver(), Settings.Secure.ANDROID_ID);
- return androidId;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getAndroidId");
- }
- return null;
- }
-
- /**
- * 获取设备唯一id
- * @return
- */
- public static String getUUID(){
- String androidId = getAndroidId() + "";
- String deviceId = getDeviceId() + "";
- String serialNumber = getSerialNumber() + "";
- // 生成唯一关联uuid androidId.hashCode(), deviceId.hashCode() | serialNumber.hashCode()
- UUID deviceUuid = new UUID(androidId.hashCode(), ((long) deviceId.hashCode() << 32) | serialNumber.hashCode());
- // 获取uid
- return deviceUuid.toString();
- }
-
- /**
- * 获取手机状态信息
- *
- * @return DeviceId(IMEI) = 99000311726612
- * DeviceSoftwareVersion = 00
- * Line1Number =
- * NetworkCountryIso = cn
- * NetworkOperator = 46003
- * NetworkOperatorName = 中国电信
- * NetworkType = 6
- * PhoneType = 2
- * SimCountryIso = cn
- * SimOperator = 46003
- * SimOperatorName = 中国电信
- * SimSerialNumber = 89860315045710604022
- * SimState = 5
- * SubscriberId(IMSI) = 460030419724900
- * VoiceMailNumber = *86
- */
- @SuppressLint({"HardwareIds", "MissingPermission"})
- public static String getPhoneStatus() {
- try {
- TelephonyManager telephonyManager = (TelephonyManager) DevUtils.getContext().getSystemService(Context.TELEPHONY_SERVICE);
- if (telephonyManager == null) return "";
- StringBuffer stringBuffer = new StringBuffer();
- stringBuffer.append("DeviceId(IMEI) = " + telephonyManager.getDeviceId() + "\n");
- stringBuffer.append("DeviceSoftwareVersion = " + telephonyManager.getDeviceSoftwareVersion() + "\n");
- stringBuffer.append("Line1Number = " + telephonyManager.getLine1Number() + "\n");
- stringBuffer.append("NetworkCountryIso = " + telephonyManager.getNetworkCountryIso() + "\n");
- stringBuffer.append("NetworkOperator = " + telephonyManager.getNetworkOperator() + "\n");
- stringBuffer.append("NetworkOperatorName = " + telephonyManager.getNetworkOperatorName() + "\n");
- stringBuffer.append("NetworkType = " + telephonyManager.getNetworkType() + "\n");
- stringBuffer.append("PhoneType = " + telephonyManager.getPhoneType() + "\n");
- stringBuffer.append("SimCountryIso = " + telephonyManager.getSimCountryIso() + "\n");
- stringBuffer.append("SimOperator = " + telephonyManager.getSimOperator() + "\n");
- stringBuffer.append("SimOperatorName = " + telephonyManager.getSimOperatorName() + "\n");
- stringBuffer.append("SimSerialNumber = " + telephonyManager.getSimSerialNumber() + "\n");
- stringBuffer.append("SimState = " + telephonyManager.getSimState() + "\n");
- stringBuffer.append("SubscriberId(IMSI) = " + telephonyManager.getSubscriberId() + "(" + getIMSIIDName(telephonyManager.getSubscriberId()) + ")"+ "\n");
- stringBuffer.append("VoiceMailNumber = " + telephonyManager.getVoiceMailNumber() + "\n");
- return stringBuffer.toString();
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getPhoneStatus");
- }
- return "";
- }
-
- /**
- * 跳至拨号界面
- * @param phoneNumber 电话号码
- */
- public static void dial(final String phoneNumber) {
- DevUtils.getContext().startActivity(IntentUtils.getDialIntent(phoneNumber, true));
- }
-
- /**
- * 拨打电话
- *
- * @param phoneNumber 电话号码
- */
- public static void call(final String phoneNumber) {
- DevUtils.getContext().startActivity(IntentUtils.getCallIntent(phoneNumber, true));
- }
-
- /**
- * 跳至发送短信界面
- * @param phoneNumber 接收号码
- * @param content 短信内容
- */
- public static void sendSms(final String phoneNumber, final String content) {
- DevUtils.getContext().startActivity(IntentUtils.getSendSmsIntent(phoneNumber, content, true));
- }
-
- /**
- * 发送短信
- *
- * @param phoneNumber 接收号码
- * @param content 短信内容
- */
- public static void sendSmsSilent(final String phoneNumber, final String content) {
- if (TextUtils.isEmpty(content)) return;
- PendingIntent sentIntent = PendingIntent.getBroadcast(DevUtils.getContext(), 0, new Intent(), 0);
- SmsManager smsManager = SmsManager.getDefault();
- if (content.length() >= 70) {
- List ms = smsManager.divideMessage(content);
- for (String str : ms) {
- smsManager.sendTextMessage(phoneNumber, null, str, sentIntent, null);
- }
- } else {
- smsManager.sendTextMessage(phoneNumber, null, content, sentIntent, null);
- }
- }
-
- /**
- * 获取手机联系人
- *
- *
- * return
- */
- public static ArrayList> getAllContactInfo() {
- ArrayList> list = new ArrayList<>();
- // 1.获取内容解析者
- ContentResolver resolver = DevUtils.getContext().getContentResolver();
- // 2.获取内容提供者的地址:com.android.contacts
- // raw_contacts 表的地址 :raw_contacts
- // view_data 表的地址 : data
- // 3.生成查询地址
- Uri raw_uri = Uri.parse("content://com.android.contacts/raw_contacts");
- Uri date_uri = Uri.parse("content://com.android.contacts/data");
- // 4.查询操作,先查询 raw_contacts,查询 contact_id
- // projection : 查询的字段
- Cursor cursor = resolver.query(raw_uri, new String[]{"contact_id"}, null, null, null);
- try {
- // 5.解析 cursor
- if (cursor != null) {
- while (cursor.moveToNext()) {
- // 6.获取查询的数据
- String contact_id = cursor.getString(0);
- // cursor.getString(cursor.getColumnIndex("contact_id"));//getColumnIndex
- // : 查询字段在 cursor 中索引值,一般都是用在查询字段比较多的时候
- // 判断 contact_id 是否为空
- if (!TextUtils.isEmpty(contact_id)) {//null ""
- // 7.根据 contact_id 查询 view_data 表中的数据
- // selection : 查询条件
- // selectionArgs :查询条件的参数
- // sortOrder : 排序
- // 空指针: 1.null.方法 2.参数为 null
- Cursor c = resolver.query(date_uri, new String[]{"data1", "mimetype"}, "raw_contact_id=?", new String[]{contact_id}, null);
- HashMap map = new HashMap();
- // 8.解析 c
- if (c != null) {
- while (c.moveToNext()) {
- // 9.获取数据
- String data1 = c.getString(0);
- String mimetype = c.getString(1);
- // 10.根据类型去判断获取的 data1 数据并保存
- if (mimetype.equals("vnd.android.cursor.item/phone_v2")) {
- map.put("phone", data1); // 电话
- } else if (mimetype.equals("vnd.android.cursor.item/name")) {
- map.put("name", data1); // 姓名
- }
- }
- }
- // 11.添加到集合中数据
- list.add(map);
- // 12.关闭 cursor
- if (c != null) {
- c.close();
- }
- }
- }
- }
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getAllContactInfo");
- } finally {
- // 12.关闭 cursor
- if (cursor != null) {
- cursor.close();
- }
- }
- return list;
- }
-
- /**
- * 获取手机联系人
- * @return
- */
- public static ArrayList> getAllContactInfo2() {
- ArrayList> list = new ArrayList<>();
- try {
- Cursor cursor = DevUtils.getContext().getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
- while (cursor.moveToNext()) {
- HashMap map = new HashMap<>();
- // 电话号码
- String phoneNumber = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)).trim().replaceAll(" ", "");
- // 手机联系人名字
- String phoneName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME)).trim();
- // 保存手机号
- map.put("phone", phoneNumber);
- // 保存名字
- map.put("name", phoneName);
- // ==
- list.add(map);
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getAllContactInfo2");
- }
- // 返回数据
- return list;
- }
-
- /**
- * 打开手机联系人界面点击联系人后便获取该号码
- */
- public static void getContactNum() {
- Intent intent = new Intent();
- intent.setAction("android.intent.action.PICK");
- intent.setType("vnd.android.cursor.dir/phone_v2");
- ((Activity) DevUtils.getContext()).startActivityForResult(intent, 0);
-
-// @Override
-// protected void onActivityResult ( int requestCode, int resultCode, Intent data){
-// super.onActivityResult(requestCode, resultCode, data);
-// if (data != null) {
-// Uri uri = data.getData();
-// String num = null;
-// // 创建内容解析者
-// ContentResolver contentResolver = getContentResolver();
-// Cursor cursor = contentResolver.query(uri,
-// null, null, null, null);
-// while (cursor.moveToNext()) {
-// num = cursor.getString(cursor.getColumnIndex("data1"));
-// }
-// cursor.close();
-// num = num.replaceAll("-", "");//替换的操作,555-6 -> 5556
-// }
-// }
- }
-
- /**
- * 获取手机短信并保存到 xml 中
- *
- *
- */
- public static void getAllSMS() {
- // 1.获取短信
- // 1.1获取内容解析者
- ContentResolver resolver = DevUtils.getContext().getContentResolver();
- // 1.2获取内容提供者地址 sms,sms表的地址:null 不写
- // 1.3获取查询路径
- Uri uri = Uri.parse("content://sms");
- // 1.4.查询操作
- // projection : 查询的字段
- // selection : 查询的条件
- // selectionArgs : 查询条件的参数
- // sortOrder : 排序
- Cursor cursor = resolver.query(uri,
- new String[]{"address", "date", "type", "body"},
- null,
- null,
- null
- );
- // 设置最大进度
- int count = cursor.getCount();//获取短信的个数
- // 2.备份短信
- // 2.1获取xml序列器
- XmlSerializer xmlSerializer = Xml.newSerializer();
- try {
- // 2.2设置xml文件保存的路径
- // os : 保存的位置
- // encoding : 编码格式
- xmlSerializer.setOutput(new FileOutputStream(new File("/mnt/sdcard/backupsms.xml")), "utf-8");
- // 2.3设置头信息
- // standalone : 是否独立保存
- xmlSerializer.startDocument("utf-8", true);
- // 2.4设置根标签
- xmlSerializer.startTag(null, "smss");
- // 1.5.解析cursor
- while (cursor.moveToNext()) {
- SystemClock.sleep(1000);
- // 2.5设置短信的标签
- xmlSerializer.startTag(null, "sms");
- // 2.6设置文本内容的标签
- xmlSerializer.startTag(null, "address");
- String address = cursor.getString(0);
- // 2.7设置文本内容
- xmlSerializer.text(address);
- xmlSerializer.endTag(null, "address");
- xmlSerializer.startTag(null, "date");
- String date = cursor.getString(1);
- xmlSerializer.text(date);
- xmlSerializer.endTag(null, "date");
- xmlSerializer.startTag(null, "type");
- String type = cursor.getString(2);
- xmlSerializer.text(type);
- xmlSerializer.endTag(null, "type");
- xmlSerializer.startTag(null, "body");
- String body = cursor.getString(3);
- xmlSerializer.text(body);
- xmlSerializer.endTag(null, "body");
- xmlSerializer.endTag(null, "sms");
- }
- xmlSerializer.endTag(null, "smss");
- xmlSerializer.endDocument();
- // 2.8将数据刷新到文件中
- xmlSerializer.flush();
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getAllSMS");
- }
- }
-
- // ================
- // === 双卡模块 ===
- // ================
-
- // 双卡双待系统IMEI和IMSI方案
- // http://benson37.iteye.com/blog/1923946
-
- /**
- * 双卡双待神机IMSI、IMSI、PhoneType信息
- *
- */
- public static class TeleInfo {
- public String imsi_1;
- public String imsi_2;
- public String imei_1;
- public String imei_2;
- public int phoneType_1;
- public int phoneType_2;
-
- @Override
- public String toString() {
- return "TeleInfo{" +
- "imsi_1='" + imsi_1 + '\'' +
- ", imsi_2='" + imsi_2 + '\'' +
- ", imei_1='" + imei_1 + '\'' +
- ", imei_2='" + imei_2 + '\'' +
- ", phoneType_1=" + phoneType_1 +
- ", phoneType_2=" + phoneType_2 +
- '}';
- }
- }
-
- /**
- * MTK Phone.
- * 获取 MTK 神机的双卡 IMSI、IMSI 信息
- */
- public static TeleInfo getMtkTeleInfo(Context context) {
- TeleInfo teleInfo = new TeleInfo();
- try {
- Class> phone = Class.forName("com.android.internal.telephony.Phone");
-
- Field fields1 = phone.getField("GEMINI_SIM_1");
- fields1.setAccessible(true);
- int simId_1 = (Integer) fields1.get(null);
-
- Field fields2 = phone.getField("GEMINI_SIM_2");
- fields2.setAccessible(true);
- int simId_2 = (Integer) fields2.get(null);
-
- TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
- Method getSubscriberIdGemini = TelephonyManager.class.getDeclaredMethod("getSubscriberIdGemini", int.class);
- String imsi_1 = (String) getSubscriberIdGemini.invoke(tm, simId_1);
- String imsi_2 = (String) getSubscriberIdGemini.invoke(tm, simId_2);
- teleInfo.imsi_1 = imsi_1;
- teleInfo.imsi_2 = imsi_2;
-
- Method getDeviceIdGemini = TelephonyManager.class.getDeclaredMethod("getDeviceIdGemini", int.class);
- String imei_1 = (String) getDeviceIdGemini.invoke(tm, simId_1);
- String imei_2 = (String) getDeviceIdGemini.invoke(tm, simId_2);
-
- teleInfo.imei_1 = imei_1;
- teleInfo.imei_2 = imei_2;
-
- Method getPhoneTypeGemini = TelephonyManager.class.getDeclaredMethod("getPhoneTypeGemini", int.class);
- int phoneType_1 = (Integer) getPhoneTypeGemini.invoke(tm, simId_1);
- int phoneType_2 = (Integer) getPhoneTypeGemini.invoke(tm, simId_2);
- teleInfo.phoneType_1 = phoneType_1;
- teleInfo.phoneType_2 = phoneType_2;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getMtkTeleInfo");
- }
- return teleInfo;
- }
-
- /**
- * MTK Phone.
- * 获取 MTK 神机的双卡 IMSI、IMSI 信息
- */
- public static TeleInfo getMtkTeleInfo2(Context context) {
- TeleInfo teleInfo = new TeleInfo();
- try {
- TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
- Class> phone = Class.forName("com.android.internal.telephony.Phone");
- Field fields1 = phone.getField("GEMINI_SIM_1");
- fields1.setAccessible(true);
- int simId_1 = (Integer) fields1.get(null);
- Field fields2 = phone.getField("GEMINI_SIM_2");
- fields2.setAccessible(true);
- int simId_2 = (Integer) fields2.get(null);
-
- Method getDefault = TelephonyManager.class.getMethod("getDefault", int.class);
- TelephonyManager tm1 = (TelephonyManager) getDefault.invoke(tm, simId_1);
- TelephonyManager tm2 = (TelephonyManager) getDefault.invoke(tm, simId_2);
-
- String imsi_1 = tm1.getSubscriberId();
- String imsi_2 = tm2.getSubscriberId();
- teleInfo.imsi_1 = imsi_1;
- teleInfo.imsi_2 = imsi_2;
-
- String imei_1 = tm1.getDeviceId();
- String imei_2 = tm2.getDeviceId();
- teleInfo.imei_1 = imei_1;
- teleInfo.imei_2 = imei_2;
-
- int phoneType_1 = tm1.getPhoneType();
- int phoneType_2 = tm2.getPhoneType();
- teleInfo.phoneType_1 = phoneType_1;
- teleInfo.phoneType_2 = phoneType_2;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getMtkTeleInfo2");
- }
- return teleInfo;
- }
-
- /**
- * Qualcomm Phone.
- * 获取 高通 神机的双卡 IMSI、IMSI 信息
- */
- public static TeleInfo getQualcommTeleInfo(Context context) {
- TeleInfo teleInfo = new TeleInfo();
- try {
- TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
- Class> simTMclass = Class.forName("android.telephony.MSimTelephonyManager");
- Object sim = context.getSystemService("phone_msim");
- int simId_1 = 0;
- int simId_2 = 1;
-
- Method getSubscriberId = simTMclass.getMethod("getSubscriberId", int.class);
- String imsi_1 = (String) getSubscriberId.invoke(sim, simId_1);
- String imsi_2 = (String) getSubscriberId.invoke(sim, simId_2);
- teleInfo.imsi_1 = imsi_1;
- teleInfo.imsi_2 = imsi_2;
-
- Method getDeviceId = simTMclass.getMethod("getDeviceId", int.class);
- String imei_1 = (String) getDeviceId.invoke(sim, simId_1);
- String imei_2 = (String) getDeviceId.invoke(sim, simId_2);
- teleInfo.imei_1 = imei_1;
- teleInfo.imei_2 = imei_2;
-
- Method getDataState = simTMclass.getMethod("getDataState");
- int phoneType_1 = tm.getDataState();
- int phoneType_2 = (Integer) getDataState.invoke(sim);
- teleInfo.phoneType_1 = phoneType_1;
- teleInfo.phoneType_2 = phoneType_2;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getQualcommTeleInfo");
- }
- return teleInfo;
- }
-
- /**
- * Spreadtrum Phone.
- * 获取 展讯 神机的双卡 IMSI、IMSI 信息
- */
- public static TeleInfo getSpreadtrumTeleInfo() {
- TeleInfo teleInfo = new TeleInfo();
- try {
- TelephonyManager tm1 = (TelephonyManager) DevUtils.getContext().getSystemService(Context.TELEPHONY_SERVICE);
- String imsi_1 = tm1.getSubscriberId();
- String imei_1 = tm1.getDeviceId();
- int phoneType_1 = tm1.getPhoneType();
- teleInfo.imsi_1 = imsi_1;
- teleInfo.imei_1 = imei_1;
- teleInfo.phoneType_1 = phoneType_1;
-
- Class> phoneFactory = Class.forName("com.android.internal.telephony.PhoneFactory");
- Method getServiceName = phoneFactory.getMethod("getServiceName", String.class, int.class);
- getServiceName.setAccessible(true);
- String spreadTmService = (String) getServiceName.invoke(phoneFactory, Context.TELEPHONY_SERVICE, 1);
-
- TelephonyManager tm2 = (TelephonyManager) DevUtils.getContext().getSystemService(spreadTmService);
- String imsi_2 = tm2.getSubscriberId();
- String imei_2 = tm2.getDeviceId();
- int phoneType_2 = tm2.getPhoneType();
- teleInfo.imsi_2 = imsi_2;
- teleInfo.imei_2 = imei_2;
- teleInfo.phoneType_2 = phoneType_2;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getSpreadtrumTeleInfo");
- }
- return teleInfo;
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/PollingUtils.java b/DevLibUtils/src/main/java/dev/utils/app/PollingUtils.java
deleted file mode 100644
index 66fc5cf046..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/PollingUtils.java
+++ /dev/null
@@ -1,60 +0,0 @@
-package dev.utils.app;
-
-import android.annotation.TargetApi;
-import android.app.AlarmManager;
-import android.app.PendingIntent;
-import android.content.Context;
-import android.content.Intent;
-import android.os.Build;
-import android.os.SystemClock;
-
-/**
- * detail: 轮询工具类
- * @author MaTianyu
- */
-public final class PollingUtils {
-
- private PollingUtils(){
- }
-
- /**
- * 开启轮询
- */
- @TargetApi(Build.VERSION_CODES.CUPCAKE)
- public static void startPolling(Context context, int mills, PendingIntent pendingIntent) {
- AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
- manager.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(), mills, pendingIntent);
- }
-
- /**
- * 停止轮询
- */
- @TargetApi(Build.VERSION_CODES.CUPCAKE)
- public static void stopPolling(Context context, PendingIntent pendingIntent) {
- AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
- manager.cancel(pendingIntent);
- }
-
- /**
- * 开启轮询服务
- */
- @TargetApi(Build.VERSION_CODES.CUPCAKE)
- public static void startPollingService(Context context, int mills, Class> cls, String action) {
- Intent intent = new Intent(context, cls);
- intent.setAction(action);
- PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
- startPolling(context, mills, pendingIntent);
- }
-
- /**
- * 停止启轮询服务
- */
- @TargetApi(Build.VERSION_CODES.CUPCAKE)
- public static void stopPollingService(Context context, Class> cls, String action) {
- Intent intent = new Intent(context, cls);
- intent.setAction(action);
- PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
- stopPolling(context, pendingIntent);
- }
-
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/PowerManagerUtils.java b/DevLibUtils/src/main/java/dev/utils/app/PowerManagerUtils.java
deleted file mode 100644
index 6fc0249400..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/PowerManagerUtils.java
+++ /dev/null
@@ -1,128 +0,0 @@
-package dev.utils.app;
-
-import android.app.Activity;
-import android.content.Context;
-import android.os.Build;
-import android.os.PowerManager;
-import android.view.Window;
-import android.view.WindowManager;
-
-import dev.DevUtils;
-
-/**
- * detail: 电源管理工具类
- * Created by Ttt
- *
- */
-public final class PowerManagerUtils {
-
- // PowerManagerUtils 实例
- private static PowerManagerUtils INSTANCE;
-
- /** 获取 PowerManagerUtils 实例 ,单例模式 */
- public static PowerManagerUtils getInstance() {
- if (INSTANCE == null){
- INSTANCE = new PowerManagerUtils();
- }
- return INSTANCE;
- }
-
- /** 电源管理类 */
- PowerManager powerManager;
- // 电源管理锁
- PowerManager.WakeLock wakeLock;
-
- /** 构造函数 */
- private PowerManagerUtils() {
- // 获取系统服务
- powerManager = (PowerManager) DevUtils.getContext().getSystemService(Context.POWER_SERVICE);
- // 电源管理锁
- wakeLock = powerManager.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.FULL_WAKE_LOCK, "PowerManagerUtils");
- }
-
- /**
- * 屏幕是否打开(亮屏)
- * @return
- */
- public boolean isScreenOn() {
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ECLAIR_MR1) {
- return false;
- } else {
- return powerManager.isScreenOn();
- }
- }
-
- /**
- * 唤醒屏幕/点亮亮屏
- */
- public void turnScreenOn() {
- if (wakeLock != null && !wakeLock.isHeld()) {
- wakeLock.acquire();
- }
- }
-
- /**
- * 释放屏幕锁, 允许休眠时间自动黑屏
- */
- public void turnScreenOff() {
- if (wakeLock != null && wakeLock.isHeld()) {
- try {
- wakeLock.release();
- } catch (Exception e) {
- }
- }
- }
-
- public PowerManager.WakeLock getWakeLock() {
- return wakeLock;
- }
-
- public void setWakeLock(PowerManager.WakeLock wakeLock) {
- this.wakeLock = wakeLock;
- }
-
- public PowerManager getPowerManager() {
- return powerManager;
- }
-
- public void setPowerManager(PowerManager powerManager) {
- this.powerManager = powerManager;
- }
-
- /**
- * 设置屏幕常亮
- * @param activity
- */
- public static void setBright(Activity activity){
- if (activity != null){
- setBright(activity.getWindow());
- }
- }
-
- /**
- * 设置屏幕常亮
- * @param window {@link Activity#getWindow()}
- */
- public static void setBright(Window window){
- if (window != null) {
- window.setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
- }
- }
-
- /**
- * 设置WakeLock 常亮
- * @return
- * run: {@link Activity#onResume()}
- */
- public static PowerManager.WakeLock setWakeLockToBright(){
- // onResume()
- PowerManager.WakeLock mWakeLock = PowerManagerUtils.getInstance().getPowerManager().newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ON_AFTER_RELEASE, "setWakeLockToBright");
- mWakeLock.acquire(); // 常量, 持有不黑屏
-
-// // onPause()
-// if (mWakeLock != null){
-// mWakeLock.release(); // 释放资源, 到休眠时间自动黑屏
-// }
- return mWakeLock;
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/ProcessUtils.java b/DevLibUtils/src/main/java/dev/utils/app/ProcessUtils.java
deleted file mode 100644
index d41f53bf66..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/ProcessUtils.java
+++ /dev/null
@@ -1,209 +0,0 @@
-package dev.utils.app;
-
-import android.annotation.SuppressLint;
-import android.app.ActivityManager;
-import android.app.usage.UsageStats;
-import android.app.usage.UsageStatsManager;
-import android.content.Context;
-import android.content.Intent;
-import android.content.pm.PackageManager;
-import android.content.pm.ResolveInfo;
-import android.provider.Settings;
-import android.support.annotation.NonNull;
-import android.text.TextUtils;
-
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import dev.DevUtils;
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: 进程相关工具类
- * Created by Ttt
- */
-public final class ProcessUtils {
-
- private ProcessUtils() {
- }
-
- // 日志TAG
- private static final String TAG = ProcessUtils.class.getSimpleName();
-
- /**
- * 获取进程号对应的进程名
- * @param pid 进程号 => android.os.Process.myPid()
- * @return 进程名
- */
- public static String getProcessName(int pid) {
- BufferedReader reader = null;
- try {
- reader = new BufferedReader(new FileReader("/proc/" + pid + "/cmdline"));
- String processName = reader.readLine();
- if (!TextUtils.isEmpty(processName)) {
- processName = processName.trim();
- }
- return processName;
- } catch (Throwable throwable) {
- LogPrintUtils.eTag(TAG, throwable, "getProcessName");
- } finally {
- if (reader != null) {
- try {
- reader.close();
- } catch (IOException e) {
- }
- }
- }
- return null;
- }
-
- /**
- * 获得当前进程的名字
- * hit: 获取当前进程 DevUtils.getContext().getApplicationInfo().packageName
- * @return 进程号
- */
- public static String getCurProcessName() {
- int pid = android.os.Process.myPid();
- ActivityManager activityManager = (ActivityManager) DevUtils.getContext().getSystemService(Context.ACTIVITY_SERVICE);
- for (ActivityManager.RunningAppProcessInfo appProcess : activityManager.getRunningAppProcesses()) {
- if (appProcess.pid == pid) {
- return appProcess.processName;
- }
- }
- return null;
- }
-
- /**
- * 获取前台线程包名
- * => 属于系统权限
- * @return 前台应用包名
- */
- public static String getForegroundProcessName() {
- if (DevUtils.getContext() == null){
- return null;
- }
- ActivityManager activityManager = (ActivityManager) DevUtils.getContext().getSystemService(Context.ACTIVITY_SERVICE);
- if (activityManager == null) return null;
- List listInfos = activityManager.getRunningAppProcesses();
- if (listInfos != null && listInfos.size() > 0) {
- for (ActivityManager.RunningAppProcessInfo apInfo : listInfos) {
- if (apInfo.importance == ActivityManager.RunningAppProcessInfo.IMPORTANCE_FOREGROUND) {
- return apInfo.processName;
- }
- }
- }
- // SDK 大于 21 时
- if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.LOLLIPOP) {
- PackageManager packageManager = DevUtils.getContext().getPackageManager();
- Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
- List listResolves = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
- // 无权限
- if (listResolves.size() <= 0) {
- return null;
- }
- try {
- UsageStatsManager usageStatsManager = (UsageStatsManager) DevUtils.getContext().getSystemService(Context.USAGE_STATS_SERVICE);
- List listUsageStats = null;
- if (usageStatsManager != null) {
- long endTime = System.currentTimeMillis();
- long beginTime = endTime - 86400000 * 7;
- listUsageStats = usageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_BEST, beginTime, endTime);
- }
- if (listUsageStats == null || listUsageStats.isEmpty()) return null;
- UsageStats recentStats = null;
- for (UsageStats usageStats : listUsageStats) {
- if (recentStats == null || usageStats.getLastTimeUsed() > recentStats.getLastTimeUsed()) {
- recentStats = usageStats;
- }
- }
- return recentStats == null ? null : recentStats.getPackageName();
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getForegroundProcessName");
- }
- }
- return null;
- }
-
- /**
- * 获取后台服务进程
- *
- * @return 后台服务进程
- */
- public static Set getAllBackgroundProcesses() {
- if (DevUtils.getContext() == null){
- return Collections.emptySet();
- }
- ActivityManager activityManager = (ActivityManager) DevUtils.getContext().getSystemService(Context.ACTIVITY_SERVICE);
- if (activityManager == null) return Collections.emptySet();
- List listInfos = activityManager.getRunningAppProcesses();
- Set set = new HashSet<>();
- if (listInfos != null) {
- for (ActivityManager.RunningAppProcessInfo apInfo : listInfos) {
- Collections.addAll(set, apInfo.pkgList);
- }
- }
- return set;
- }
-
- /**
- * 杀死所有的后台服务进程
- *
- * @return 被暂时杀死的服务集合
- */
- @SuppressLint("MissingPermission")
- public static Set killAllBackgroundProcesses() {
- if (DevUtils.getContext() == null){
- return null;
- }
- ActivityManager activityManager = (ActivityManager) DevUtils.getContext().getSystemService(Context.ACTIVITY_SERVICE);
- if (activityManager == null) return Collections.emptySet();
- List listInfos = activityManager.getRunningAppProcesses();
- Set set = new HashSet<>();
- for (ActivityManager.RunningAppProcessInfo apInfo : listInfos) {
- for (String pkg : apInfo.pkgList) {
- activityManager.killBackgroundProcesses(pkg);
- set.add(pkg);
- }
- }
- listInfos = activityManager.getRunningAppProcesses();
- for (ActivityManager.RunningAppProcessInfo aInfo : listInfos) {
- for (String pkg : aInfo.pkgList) {
- set.remove(pkg);
- }
- }
- return set;
- }
-
- /**
- * 杀死后台服务进程
- *
- * @param packageName The name of the package.
- * @return true : 杀死成功, false : 杀死失败
- */
- @SuppressLint("MissingPermission")
- public static boolean killBackgroundProcesses(@NonNull final String packageName) {
- ActivityManager activityManager = (ActivityManager) DevUtils.getContext().getSystemService(Context.ACTIVITY_SERVICE);
- if (activityManager == null) return false;
- List listInfos = activityManager.getRunningAppProcesses();
- if (listInfos == null || listInfos.size() == 0) return true;
- for (ActivityManager.RunningAppProcessInfo apInfo : listInfos) {
- if (Arrays.asList(apInfo.pkgList).contains(packageName)) {
- activityManager.killBackgroundProcesses(packageName);
- }
- }
- listInfos = activityManager.getRunningAppProcesses();
- if (listInfos == null || listInfos.size() == 0) return true;
- for (ActivityManager.RunningAppProcessInfo aInfo : listInfos) {
- if (Arrays.asList(aInfo.pkgList).contains(packageName)) {
- return false;
- }
- }
- return true;
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/ResourceUtils.java b/DevLibUtils/src/main/java/dev/utils/app/ResourceUtils.java
deleted file mode 100644
index 7a2ba5ca79..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/ResourceUtils.java
+++ /dev/null
@@ -1,498 +0,0 @@
-package dev.utils.app;
-
-import android.content.res.Resources;
-import android.graphics.drawable.Drawable;
-import android.text.TextUtils;
-
-import java.io.BufferedReader;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.lang.reflect.Field;
-import java.util.ArrayList;
-import java.util.List;
-
-import dev.DevUtils;
-import dev.utils.LogPrintUtils;
-import dev.utils.R;
-
-/**
- * detail: 资源文件工具类
- * Created by Ttt
- */
-public final class ResourceUtils {
-
- private ResourceUtils() {
- }
-
- // 日志TAG
- private static final String TAG = ResourceUtils.class.getSimpleName();
-
- public static final String LAYTOUT = "layout";
- public static final String DRAWABLE = "drawable";
- public static final String MIPMAP = "mipmap";
- public static final String MENU = "menu";
- public static final String RAW = "raw";
- public static final String ANIM = "anim";
- public static final String STRING = "string";
- public static final String STYLE = "style";
- public static final String STYLEABLE = "styleable";
- public static final String INTEGER = "integer";
- public static final String ID = "id";
- public static final String DIMEN = "dimen";
- public static final String COLOR = "color";
- public static final String BOOL = "bool";
- public static final String ATTR = "attr";
-
- /**
- * 获得字符串
- * @param strId 字符串id
- * @return 字符串
- */
- public static String getString(int strId) {
- try {
- return DevUtils.getContext().getResources().getString(strId);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getString");
- }
- return "";
- }
-
- /**
- * 获得颜色
- * @param colorId 颜色id
- * @return 颜色
- */
- public static int getColor(int colorId) {
- try {
- return DevUtils.getContext().getResources().getColor(colorId);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getColor");
- }
- return -1;
- }
-
- /**
- * 获得Drawable
- * @param drawableId Drawable的id
- * @return Drawable
- */
- public static Drawable getDrawable(int drawableId) {
- try {
- return DevUtils.getContext().getResources().getDrawable(drawableId);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getDrawable");
- }
- return null;
- }
-
- /**
- * 根据资源名获得资源id
- * @param name 资源名
- * @param type 资源类型
- * @return 资源id,找不到返回0
- */
- public static int getResourceId(String name, String type) {
- try {
- //PackageManager pm = DevUtils.getContext().getPackageManager();
- Resources resources = DevUtils.getContext().getResources();
- return resources.getIdentifier(name, type, DevUtils.getContext().getPackageName());
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getResourceId");
- }
- return 0;
- }
-
- /**
- * 获取资源id
- * @param imageName
- * @return
- */
- public static int getDrawableId2(String imageName){
- Class mipmap = R.drawable.class;
- try {
- Field field = mipmap.getField(imageName);
- int resId = field.getInt(imageName);
- return resId;
- } catch (NoSuchFieldException e) { // 如果没有在"drawable"下找到imageName,将会返回0
- LogPrintUtils.eTag(TAG, e, "getDrawableId2");
- return 0;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getDrawableId2");
- return 0;
- }
- }
-
- // ==
-
- /**
- * 获取 layout 布局文件
- * @param resName layout xml 的文件名
- * @return layout
- */
- public static int getLayoutId(String resName) {
- try {
- return DevUtils.getContext().getResources().getIdentifier(resName, "layout", DevUtils.getContext().getPackageName());
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getLayoutId");
- }
- return 0;
- }
-
- /**
- * 获取 string 值
- * @param resName string name的名称
- * @return string
- */
- public static int getStringId(String resName) {
- try {
- return DevUtils.getContext().getResources().getIdentifier(resName, "string", DevUtils.getContext().getPackageName());
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getStringId");
- }
- return 0;
- }
-
- /**
- * 获取 drawable
- * @param resName drawable 的名称
- * @return drawable
- */
- public static int getDrawableId(String resName) {
- try {
- return DevUtils.getContext().getResources().getIdentifier(resName, "drawable", DevUtils.getContext().getPackageName());
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getDrawableId");
- }
- return 0;
- }
-
- /**
- * 获取 mipmap
- * @param resName
- * @return
- */
- public static int getMipmapId(String resName) {
- try {
- return DevUtils.getContext().getResources().getIdentifier(resName, "mipmap", DevUtils.getContext().getPackageName());
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getMipmapId");
- }
- return 0;
- }
-
-
- /**
- * 获取 style
- * @param resName style的名称
- * @return style
- */
- public static int getStyleId(String resName) {
- try {
- return DevUtils.getContext().getResources().getIdentifier(resName, "style", DevUtils.getContext().getPackageName());
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getStyleId");
- }
- return 0;
- }
-
- /**
- * 获取 styleable
- * @param resName styleable 的名称
- * @return styleable
- */
- public static Object getStyleableId(String resName){
- try {
- return DevUtils.getContext().getResources().getIdentifier(resName, "styleable", DevUtils.getContext().getPackageName());
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getStyleableId");
- }
- return 0;
- }
-
-
- /**
- * 获取 anim
- * @param resName anim xml 文件名称
- * @return anim
- */
- public static int getAnimId(String resName) {
- try {
- return DevUtils.getContext().getResources().getIdentifier(resName, "anim", DevUtils.getContext().getPackageName());
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getAnimId");
- }
- return 0;
- }
-
- /**
- * 获取 id
- * @param resName id 的名称
- * @return
- */
- public static int getId(String resName) {
- try {
- return DevUtils.getContext().getResources().getIdentifier(resName, "id", DevUtils.getContext().getPackageName());
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getId");
- }
- return 0;
- }
-
- /**
- * color
- * @param resName color 名称
- * @return
- */
- public static int getColorId(String resName) {
- try {
- return DevUtils.getContext().getResources().getIdentifier(resName, "color", DevUtils.getContext().getPackageName());
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getColorId");
- }
- return 0;
- }
-
- // == ----------------------------------------- ==
-
- /**
- * 获取 Assets 资源文件数据
- * @param fileName 资源文件名,可分成,如根目录,a.txt 或者子目录 /www/a.html
- * @return byte[] , - > new String(byte[],encode)
- */
- public static byte[] readBytesFromAssets(String fileName) {
- if (DevUtils.getContext() != null && !TextUtils.isEmpty(fileName)) {
- InputStream iStream = null;
- try {
- iStream = DevUtils.getContext().getResources().getAssets().open(fileName);
- int length = iStream.available();
- byte[] buffer = new byte[length];
- iStream.read(buffer);
- iStream.close();
- iStream = null;
- return buffer;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "readBytesFromAssets");
- } finally {
- if(iStream != null) {
- try {
- iStream.close();
- } catch (Exception e) {
- }
- }
- }
- }
- return null;
- }
-
- /**
- * 读取字符串 来自 Assets文件
- * @param fileName
- * @return
- */
- public static String readStringFromAssets(String fileName) {
- try {
- return new String(readBytesFromAssets(fileName), "UTF-8");
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "readStringFromAssets");
- }
- return null;
- }
-
- /**
- * 从res/raw 中获取内容。
- * @param resId 资源id
- * @return byte[] , - > new String(byte[],encode)
- */
- public static byte[] readBytesFromRaw(int resId) {
- if (DevUtils.getContext() != null) {
- InputStream iStream = null;
- try {
- iStream = DevUtils.getContext().getResources().openRawResource(resId);
- int length = iStream.available();
- byte[] buffer = new byte[length];
- iStream.read(buffer);
- iStream.close();
- iStream = null;
- return buffer;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "readBytesFromRaw");
- } finally {
- if(iStream != null) {
- try {
- iStream.close();
- } catch (Exception e) {
- }
- }
- }
- }
- return null;
- }
-
- /**
- * 读取字符串 来自Raw 文件
- * @param resId
- * @return
- */
- public static String readStringFromRaw(int resId) {
- try {
- return new String(readBytesFromRaw(resId), "UTF-8");
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "readStringFromRaw");
- }
- return null;
- }
-
- // ==
-
- /**
- * 获取 Assets 资源文件数据(返回ArrayList 一行的全部内容属于一个索引)
- * @param fileName 资源文件名,可分成,如根目录,a.txt 或者子目录 /www/a.html
- * @return
- */
- public static ArrayList geFileToListFromAssets(String fileName) {
- if (DevUtils.getContext() != null && !TextUtils.isEmpty(fileName)) {
- InputStream iStream = null;
- InputStreamReader inReader = null;
- BufferedReader bufReader = null;
- try {
- iStream = DevUtils.getContext().getResources().getAssets().open(fileName);
- inReader = new InputStreamReader(iStream);
- bufReader = new BufferedReader(inReader);
- ArrayList fileContent = new ArrayList();
- String line;
- while ((line = bufReader.readLine()) != null) {
- fileContent.add(line);
- }
- return fileContent;
- } catch (IOException e) {
- LogPrintUtils.eTag(TAG, e, "geFileToListFromAssets");
- } finally {
- try {
- bufReader.close();
- inReader.close();
- iStream.close();
- } catch (Exception e) {
- }
- }
- }
- return null;
- }
-
- /**
- * 从res/raw 中获取内容。(返回ArrayList 一行的全部内容属于一个索引)
- * @param resId 资源id
- * @return
- */
- public static List geFileToListFromRaw(int resId) {
- if (DevUtils.getContext() != null) {
- InputStream iStream = null;
- InputStreamReader inReader = null;
- BufferedReader bufReader = null;
- try {
- iStream = DevUtils.getContext().getResources().openRawResource(resId);
- inReader = new InputStreamReader(iStream);
- bufReader = new BufferedReader(inReader);
- List fileContent = new ArrayList();
- String line = null;
- while ((line = bufReader.readLine()) != null) {
- fileContent.add(line);
- }
- return fileContent;
- } catch (IOException e) {
- LogPrintUtils.eTag(TAG, e, "geFileToListFromRaw");
- } finally {
- try {
- bufReader.close();
- inReader.close();
- iStream.close();
- } catch (Exception e) {
- }
- }
- }
- return null;
- }
-
-
- // ========
- /**
- * 从Assets 资源中获取内容并保存到本地
- * @param fileName 资源文件名,可分成,如根目录,a.txt 或者子目录 /www/a.html
- * @param file 保存地址
- * @return 是否保存成功
- */
- public static boolean saveAssetsFormFile(String fileName, File file) {
- if (DevUtils.getContext() != null) {
- try {
- // 获取 Assets 文件
- InputStream iStream = DevUtils.getContext().getResources().getAssets().open(fileName);
- // 存入SDCard
- FileOutputStream fileOutputStream = new FileOutputStream(file);
- // 设置数据缓冲
- byte[] buffer = new byte[1024];
- // 创建输入输出流
- ByteArrayOutputStream outStream = new ByteArrayOutputStream();
- int len = 0;
- while ((len = iStream.read(buffer)) != -1) {
- outStream.write(buffer, 0, len);
- }
- // 保存数据
- byte[] bytes = outStream.toByteArray();
- // 写入保存的文件
- fileOutputStream.write(bytes);
- // 关闭流
- outStream.close();
- iStream.close();
- // --
- fileOutputStream.flush();
- fileOutputStream.close();
- return true;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "saveAssetsFormFile");
- }
- }
- return false;
- }
-
- /**
- * 从res/raw 中获取内容并保存到本地
- * @param resId 资源id
- * @param file 保存地址
- * @return 是否保存成功
- */
- public static boolean saveRawFormFile(int resId, File file) {
- if (DevUtils.getContext() != null) {
- try {
- // 获取raw 文件
- InputStream iStream = DevUtils.getContext().getResources().openRawResource(resId);
- // 存入SDCard
- FileOutputStream fileOutputStream = new FileOutputStream(file);
- // 设置数据缓冲
- byte[] buffer = new byte[1024];
- // 创建输入输出流
- ByteArrayOutputStream outStream = new ByteArrayOutputStream();
- int len = 0;
- while ((len = iStream.read(buffer)) != -1) {
- outStream.write(buffer, 0, len);
- }
- // 保存数据
- byte[] bytes = outStream.toByteArray();
- // 写入保存的文件
- fileOutputStream.write(bytes);
- // 关闭流
- outStream.close();
- iStream.close();
- // --
- fileOutputStream.flush();
- fileOutputStream.close();
- return true;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "saveRawFormFile");
- }
- }
- return false;
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/SDCardUtils.java b/DevLibUtils/src/main/java/dev/utils/app/SDCardUtils.java
deleted file mode 100644
index ff1f9bddfb..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/SDCardUtils.java
+++ /dev/null
@@ -1,323 +0,0 @@
-package dev.utils.app;
-
-import android.content.Context;
-import android.os.Environment;
-import android.os.StatFs;
-import android.os.storage.StorageManager;
-import android.text.format.Formatter;
-
-import java.io.File;
-import java.lang.reflect.Array;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-
-import dev.DevUtils;
-import dev.utils.LogPrintUtils;
-import dev.utils.common.FileUtils;
-
-/**
- * detail: SD卡相关辅助类
- * Created by Ttt
- */
-public final class SDCardUtils {
-
- private SDCardUtils() {
- }
-
- // 日志TAG
- private static final String TAG = SDCardUtils.class.getSimpleName();
-
- // == ----------------------------------------- ==
-
- /**
- * 判断SDCard是否正常挂载
- * @return
- */
- public static boolean isSDCardEnable() {
- // android.os.Environment
- return Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED);
- }
-
- /**
- * 获取SD卡路径(File对象)
- * @return
- */
- public static File getSDCardFile() {
- return Environment.getExternalStorageDirectory();
- }
-
- /**
- * 获取SD卡路径(无添加 -> / -> File.separator)
- * @return
- */
- public static String getSDCardPath() {
- return Environment.getExternalStorageDirectory().getAbsolutePath();
- }
-
- // ==
-
- /**
- * 判断 SD 卡是否可用
- * @return true : 可用, false : 不可用
- */
- public static boolean isSDCardEnablePath() {
- return !getSDCardPaths().isEmpty();
- }
-
- /**
- * 获取 SD 卡路径
- * @param removable true : 外置 SD 卡, false : 内置 SD 卡
- * @return SD 卡路径
- */
- @SuppressWarnings("TryWithIdenticalCatches")
- public static List getSDCardPaths(final boolean removable) {
- List listPaths = new ArrayList<>();
- try {
- StorageManager storageManager = (StorageManager) DevUtils.getContext().getSystemService(Context.STORAGE_SERVICE);
- Class> storageVolumeClazz = Class.forName("android.os.storage.StorageVolume");
- Method getVolumeList = StorageManager.class.getMethod("getVolumeList");
- Method getPath = storageVolumeClazz.getMethod("getPath");
- Method isRemovable = storageVolumeClazz.getMethod("isRemovable");
- Object result = getVolumeList.invoke(storageManager);
- final int length = Array.getLength(result);
- for (int i = 0; i < length; i++) {
- Object storageVolumeElement = Array.get(result, i);
- String path = (String) getPath.invoke(storageVolumeElement);
- boolean res = (Boolean) isRemovable.invoke(storageVolumeElement);
- if (removable == res) {
- listPaths.add(path);
- }
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getSDCardPaths");
- }
- return listPaths;
- }
-
- /**
- * 获取 SD 卡路径
- * @return SD 卡路径
- */
- @SuppressWarnings("TryWithIdenticalCatches")
- public static List getSDCardPaths() {
- List listPaths = new ArrayList<>();
- try {
- StorageManager storageManager = (StorageManager) DevUtils.getContext().getSystemService(Context.STORAGE_SERVICE);
- Method getVolumePathsMethod = StorageManager.class.getMethod("getVolumePaths");
- getVolumePathsMethod.setAccessible(true);
- Object invoke = getVolumePathsMethod.invoke(storageManager);
- listPaths = Arrays.asList((String[]) invoke);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getSDCardPaths");
- }
- return listPaths;
- }
-
- // ==
-
- /**
- * 返回对应路径的空间总大小
- * @param path
- * @return
- */
- public static long getAllBlockSize(String path) {
- try {
- // 获取路径的存储空间信息
- StatFs statFs = new StatFs(path);
- // 获取单个数据块的大小(Byte)
- long blockSize = statFs.getBlockSize();
- // 获取数据块的数量
- long blockCount = statFs.getBlockCount();
- // 返回空间总大小
- return (blockCount * blockSize);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getAllBlockSize");
- }
- return -1l;
- }
-
- /**
- * 返回对应路径的空闲空间(byte 字节大小)
- * @param path
- * @return
- */
- public static long getAvailableBlocks(String path) {
- try {
- // 获取路径的存储空间信息
- StatFs statFs = new StatFs(path);
- // 获取单个数据块的大小(Byte)
- long blockSize = statFs.getBlockSize();
- // 空闲的数据块的数量
- long freeBlocks = statFs.getAvailableBlocks();
- // 返回空闲空间
- return (freeBlocks * blockSize);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getAvailableBlocks");
- }
- return -1l;
- }
-
-
- /**
- * 返回对应路径,已使用的空间大小
- * @param path
- * @return
- */
- public static long getAlreadyBlock(String path) {
- try {
- // 获取路径的存储空间信息
- StatFs statFs = new StatFs(path);
- // 获取单个数据块的大小(Byte)
- long blockSize = statFs.getBlockSize();
- // 获取数据块的数量
- long blockCount = statFs.getBlockCount();
- // 空闲的数据块的数量
- long freeBlocks = statFs.getAvailableBlocks();
- // 返回空间总大小
- return ((blockCount - freeBlocks)* blockSize);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getAlreadyBlock");
- }
- return -1l;
- }
-
- /**
- * 返回对应路径的空间大小信息
- * @return 返回数据,0 = 总空间大小,1 = 空闲控件大小 , 2 = 已使用空间大小
- */
- public static long[] getBlockSizeInfos(String path) {
- try {
- // 获取路径的存储空间信息
- StatFs statFs = new StatFs(path);
- // 获取单个数据块的大小(Byte)
- long blockSize = statFs.getBlockSize();
- // 获取数据块的数量
- long blockCount = statFs.getBlockCount();
- // 空闲的数据块的数量
- long freeBlocks = statFs.getAvailableBlocks();
- // 计算空间大小信息
- long[] blocks = new long[3];
- blocks[0] = blockSize * blockCount;
- blocks[1] = blockSize * freeBlocks;
- blocks[2] = ((blockCount - freeBlocks)* blockSize);
- // 返回空间大小信息
- return blocks;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getBlockSizeInfos");
- }
- return null;
- }
-
- /**
- * 获得 SD 卡总大小
- * @return
- */
- public static String getSDTotalSize() {
- try {
- File path = Environment.getExternalStorageDirectory();
- StatFs stat = new StatFs(path.getPath());
- long blockSize = stat.getBlockSizeLong();
- long totalBlocks = stat.getBlockCountLong();
- return Formatter.formatFileSize(DevUtils.getContext(), blockSize * totalBlocks);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getSDTotalSize");
- }
- return "unknown";
- }
-
- /**
- * 获得 SD 卡剩余容量,即可用大小
- * @return
- */
- public static String getSDAvailableSize() {
- try {
- File path = Environment.getExternalStorageDirectory();
- StatFs stat = new StatFs(path.getPath());
- long blockSize = stat.getBlockSizeLong();
- long availableBlocks = stat.getAvailableBlocksLong();
- return Formatter.formatFileSize(DevUtils.getContext(), blockSize * availableBlocks);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getSDAvailableSize");
- }
- return "unknown";
- }
-
- /**
- * 获得机身内存总大小
- * @return
- */
- public static String getRomTotalSize() {
- try {
- File path = Environment.getDataDirectory();
- StatFs stat = new StatFs(path.getPath());
- long blockSize = stat.getBlockSizeLong();
- long totalBlocks = stat.getBlockCountLong();
- return Formatter.formatFileSize(DevUtils.getContext(), blockSize * totalBlocks);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getRomTotalSize");
- }
- return "unknown";
- }
-
- /**
- * 获得机身可用内存
- * @return
- */
- public static String getRomAvailableSize() {
- try {
- File path = Environment.getDataDirectory();
- StatFs stat = new StatFs(path.getPath());
- long blockSize = stat.getBlockSizeLong();
- long availableBlocks = stat.getAvailableBlocksLong();
- return Formatter.formatFileSize(DevUtils.getContext(), blockSize * availableBlocks);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getRomAvailableSize");
- }
- return "unknown";
- }
-
- // -
-
- /**
- * 获取缓存地址
- * @return
- */
- public static String getDiskCacheDir() {
- String cachePath;
- if (isSDCardEnable()) { // 判断SDCard是否挂载
- cachePath = DevUtils.getContext().getExternalCacheDir().getPath();
- } else {
- cachePath = DevUtils.getContext().getCacheDir().getPath();
- }
- // 防止不存在目录文件,自动创建
- FileUtils.createFolder(cachePath);
- // 返回文件存储地址
- return cachePath;
- }
-
- /**
- * 获取缓存资源地址
- * @param fPath 文件地址
- * @return
- */
- public static File getCacheFile(String fPath) {
- return new File(getCachePath(fPath));
- }
-
- /**
- * 获取缓存资源地址
- * @param fPath 文件地址
- * @return
- */
- public static String getCachePath(String fPath){
- // 获取缓存地址
- String cachePath = new File(getDiskCacheDir(), fPath).getAbsolutePath();
- // 防止不存在目录文件,自动创建
- FileUtils.createFolder(cachePath);
- // 返回头像地址
- return cachePath;
- }
-}
-
diff --git a/DevLibUtils/src/main/java/dev/utils/app/ScreenUtils.java b/DevLibUtils/src/main/java/dev/utils/app/ScreenUtils.java
deleted file mode 100644
index d711d6e1ae..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/ScreenUtils.java
+++ /dev/null
@@ -1,729 +0,0 @@
-package dev.utils.app;
-
-import android.app.Activity;
-import android.app.KeyguardManager;
-import android.content.Context;
-import android.content.pm.ActivityInfo;
-import android.content.res.Configuration;
-import android.content.res.Resources;
-import android.graphics.Bitmap;
-import android.graphics.Point;
-import android.graphics.Rect;
-import android.os.Build;
-import android.provider.Settings;
-import android.support.annotation.NonNull;
-import android.util.DisplayMetrics;
-import android.view.Surface;
-import android.view.View;
-import android.view.Window;
-import android.view.WindowManager;
-
-import java.lang.reflect.Method;
-import java.text.DecimalFormat;
-
-import dev.DevUtils;
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: 屏幕相关工具类
- * Created by Ttt
- */
-public final class ScreenUtils {
-
- private ScreenUtils() {
- }
-
- // 日志TAG
- private static final String TAG = ScreenUtils.class.getSimpleName();
-
- /**
- * 通过上下文获取 DisplayMetrics (获取关于显示的通用信息,如显示大小,分辨率和字体)
- * @return
- */
- private static DisplayMetrics getDisplayMetrics() {
- try {
- WindowManager wManager = (WindowManager) DevUtils.getContext().getSystemService(Context.WINDOW_SERVICE);
- if (wManager != null) {
- DisplayMetrics dMetrics = new DisplayMetrics();
- wManager.getDefaultDisplay().getMetrics(dMetrics);
- return dMetrics;
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getDisplayMetrics");
- }
- return null;
- }
-
- // == ----------------------------------------- ==
-
-// /**
-// * 通过上下文获取屏幕宽度
-// * @param mContext
-// * @return
-// */
-// @SuppressWarnings("deprecation")
-// public static int getScreenWidth() {
-// try {
-// // 获取屏幕信息
-// DisplayMetrics dMetrics = getDisplayMetrics();
-// if (dMetrics != null) {
-// return dMetrics.widthPixels;
-// }
-// // 这种也可以获取,不过已经提问过时(下面这段可以注释掉)
-// WindowManager wManager = (WindowManager) DevUtils.getContext().getSystemService(Context.WINDOW_SERVICE);
-// if (wManager != null) {
-// return wManager.getDefaultDisplay().getWidth();
-// }
-// } catch (Exception e) {
-// LogPrintUtils.eTag(TAG, e, "getScreenWidth");
-// }
-// return -1;
-// }
-//
-// /**
-// * 通过上下文获取屏幕高度
-// * @param mContext
-// * @return
-// */
-// @SuppressWarnings("deprecation")
-// public static int getScreenHeight() {
-// try {
-// // 获取屏幕信息
-// DisplayMetrics dMetrics = getDisplayMetrics();
-// if (dMetrics != null) {
-// return dMetrics.heightPixels;
-// }
-// // 这种也可以获取,不过已经提示过时(下面这段可以注释掉)
-// WindowManager wManager = (WindowManager) DevUtils.getContext().getSystemService(Context.WINDOW_SERVICE);
-// if (wManager != null) {
-// return wManager.getDefaultDisplay().getHeight();
-// }
-// } catch (Exception e) {
-// LogPrintUtils.eTag(TAG, e, "getScreenHeight");
-// }
-// return -1;
-// }
-//
-// /**
-// * 通过上下文获取屏幕宽度高度
-// * @param mContext
-// * @return int[] 0 = 宽度,1 = 高度
-// */
-// @SuppressWarnings("deprecation")
-// public static int[] getScreenWidthHeight() {
-// try {
-// // 获取屏幕信息
-// DisplayMetrics dMetrics = getDisplayMetrics();
-// if (dMetrics != null) {
-// return new int[] { dMetrics.widthPixels, dMetrics.heightPixels };
-// }
-// // 这种也可以获取,不过已经提示过时(下面这段可以注释掉)
-// WindowManager wManager = (WindowManager) DevUtils.getContext().getSystemService(Context.WINDOW_SERVICE);
-// if (wManager != null) {
-// int width = wManager.getDefaultDisplay().getWidth();
-// int height = wManager.getDefaultDisplay().getHeight();
-// return new int[] { width, height };
-// }
-// } catch (Exception e) {
-// LogPrintUtils.eTag(TAG, e, "getScreenWidthHeight");
-// }
-// return null;
-// }
-
- /**
- * 获取屏幕的宽度(单位:px)
- * @return 屏幕宽
- */
- public static int getScreenWidth() {
- try {
- WindowManager windowManager = (WindowManager) DevUtils.getContext().getSystemService(Context.WINDOW_SERVICE);
- if (windowManager == null) {
- return DevUtils.getContext().getResources().getDisplayMetrics().widthPixels;
- }
- Point point = new Point();
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
- windowManager.getDefaultDisplay().getRealSize(point);
- } else {
- windowManager.getDefaultDisplay().getSize(point);
- }
- return point.x;
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getScreenWidth");
- }
- return -1;
- }
-
- /**
- * 获取屏幕的高度(单位:px)
- * @return 屏幕高
- */
- public static int getScreenHeight() {
- try {
- WindowManager windowManager = (WindowManager) DevUtils.getContext().getSystemService(Context.WINDOW_SERVICE);
- if (windowManager == null) {
- return DevUtils.getContext().getResources().getDisplayMetrics().heightPixels;
- }
- Point point = new Point();
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
- windowManager.getDefaultDisplay().getRealSize(point);
- } else {
- windowManager.getDefaultDisplay().getSize(point);
- }
- return point.y;
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getScreenHeight");
- }
- return -1;
- }
-
- /**
- * 通过上下文获取屏幕宽度高度
- * @return point.x 宽, point.y 高
- */
- public static Point getScreenWidthHeightToPoint() {
- try {
- WindowManager windowManager = (WindowManager) DevUtils.getContext().getSystemService(Context.WINDOW_SERVICE);
- if (windowManager == null) {
- DisplayMetrics dMetrics = DevUtils.getContext().getResources().getDisplayMetrics();
- return new Point(dMetrics.widthPixels, dMetrics.heightPixels);
- }
- Point point = new Point();
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
- windowManager.getDefaultDisplay().getRealSize(point);
- } else {
- windowManager.getDefaultDisplay().getSize(point);
- }
- return point;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getScreenWidthHeightToPoint");
- }
- return null;
- }
-
- /**
- * 通过上下文获取屏幕宽度高度
- * @return int[] 0 = 宽度,1 = 高度
- */
- public static int[] getScreenWidthHeight() {
- try {
- WindowManager windowManager = (WindowManager) DevUtils.getContext().getSystemService(Context.WINDOW_SERVICE);
- if (windowManager == null) {
- DisplayMetrics dMetrics = DevUtils.getContext().getResources().getDisplayMetrics();
- return new int[] { dMetrics.widthPixels, dMetrics.heightPixels };
- }
- Point point = new Point();
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
- windowManager.getDefaultDisplay().getRealSize(point);
- } else {
- windowManager.getDefaultDisplay().getSize(point);
- }
- return new int[] { point.x, point.y };
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getScreenWidthHeight");
- }
- return new int[] { 0, 0 };
- }
-
- /**
- * 获取屏幕分辨率
- * @return
- */
- public static String getScreenSize() {
- try {
- // 获取分辨率
- int[] whArys = getScreenWidthHeight();
- // 返回分辨率信息
- return whArys[1] + "x" + whArys[0];
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getScreenSize");
- }
- return "unknown";
- }
-
- /**
- * 获取屏幕英寸 例5.5英寸
- * @return
- */
- public static String getScreenSizeOfDevice() {
- // https://blog.csdn.net/lincyang/article/details/42679589
- try {
- Point point = new Point();
- WindowManager windowManager = (WindowManager) DevUtils.getContext().getSystemService(Context.WINDOW_SERVICE);
- windowManager.getDefaultDisplay().getRealSize(point);
- DisplayMetrics dm = DevUtils.getContext().getResources().getDisplayMetrics();
- double x = Math.pow(point.x/ dm.xdpi, 2);
- double y = Math.pow(point.y / dm.ydpi, 2);
- double screenInches = Math.sqrt(x + y);
- // 转换大小
- DecimalFormat df = new DecimalFormat("#.0");
- return df.format(screenInches);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getScreenSizeOfDevice");
- }
- return "unknown";
- }
-
- // ==
-
- /**
- * 通过上下文获取屏幕密度
- * @return
- */
- public static float getDensity() {
- try {
- // 获取屏幕信息
- DisplayMetrics dMetrics = getDisplayMetrics();
- if (dMetrics != null) {
- // 屏幕密度(0.75 / 1.0 / 1.5 / 2.0)
- return dMetrics.density;
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getDensity");
- }
- return -1;
- }
-
- /**
- * 通过上下文获取屏幕密度Dpi
- * @return
- */
- public static int getDensityDpi() {
- try {
- // 获取屏幕信息
- DisplayMetrics dMetrics = getDisplayMetrics();
- if (dMetrics != null) {
- // 屏幕密度DPI(120 / 160 / 240 / 320)
- return dMetrics.densityDpi;
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getDensityDpi");
- }
- return -1;
- }
-
- /**
- * 通过上下文获取屏幕缩放密度
- * @return
- */
- public static float getScaledDensity() {
- try {
- // 获取屏幕信息
- DisplayMetrics dMetrics = getDisplayMetrics();
- if (dMetrics != null) {
- return dMetrics.scaledDensity;
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getScaledDensity");
- }
- return -1f;
- }
-
- /**
- * 获取 X轴 dpi
- * @return
- */
- public static float getXDpi() {
- try {
- // 获取屏幕信息
- DisplayMetrics dMetrics = getDisplayMetrics();
- if (dMetrics != null) {
- return dMetrics.xdpi;
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getXDpi");
- }
- return -1f;
- }
-
- /**
- * 获取 Y轴 dpi
- * @return
- */
- public static float getYDpi() {
- try {
- // 获取屏幕信息
- DisplayMetrics dMetrics = getDisplayMetrics();
- if (dMetrics != null) {
- return dMetrics.ydpi;
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getYDpi");
- }
- return -1f;
- }
-
- /**
- * 获取 宽度比例 dpi 基准
- * @return
- */
- public static float getWidthDpi() {
- try {
- // 获取屏幕信息
- DisplayMetrics dMetrics = getDisplayMetrics();
- if (dMetrics != null) {
- return dMetrics.widthPixels / dMetrics.density;
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getWidthDpi");
- }
- return -1f;
- }
-
- /**
- * 获取 高度比例 dpi 基准
- * @return
- */
- public static float getHeightDpi() {
- try {
- // 获取屏幕信息
- DisplayMetrics dMetrics = getDisplayMetrics();
- if (dMetrics != null) {
- return dMetrics.heightPixels / dMetrics.density;
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getHeightDpi");
- }
- return -1f;
- }
-
- /**
- * 获取屏幕信息
- * @return
- */
- public static String getScreenInfo(){
- StringBuilder sBuilder = new StringBuilder();
- // 获取屏幕信息
- DisplayMetrics dMetrics = getDisplayMetrics();
- if (dMetrics != null) {
- try {
- int heightPixels = dMetrics.heightPixels;
- int widthPixels = dMetrics.widthPixels;
-
- float xdpi = dMetrics.xdpi;
- float ydpi = dMetrics.ydpi;
- int densityDpi = dMetrics.densityDpi;
-
- float density = dMetrics.density;
- float scaledDensity = dMetrics.scaledDensity;
-
- float heightDpi = heightPixels / density;
- float widthDpi = widthPixels / density;
- // -
- sBuilder.append("\nheightPixels: " + heightPixels + "px");
- sBuilder.append("\nwidthPixels: " + widthPixels + "px");
-
- sBuilder.append("\nxdpi: " + xdpi + "dip");
- sBuilder.append("\nydpi: " + ydpi + "dpi");
- sBuilder.append("\ndensityDpi: " + densityDpi + "dpi");
-
- sBuilder.append("\ndensity: " + density);
- sBuilder.append("\nscaledDensity: " + scaledDensity);
-
- sBuilder.append("\nheightDpi: " + heightDpi + "dpi");
- sBuilder.append("\nwidthDpi: " + widthDpi + "dpi");
-
- return sBuilder.toString();
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getScreenInfo");
- }
- }
- return sBuilder.toString();
- }
-
- // ==
-
- /**
- * 设置屏幕为全屏
- * @param activity
- */
- public static void setFullScreen(@NonNull final Activity activity) {
- try {
- activity.requestWindowFeature(Window.FEATURE_NO_TITLE);// 隐藏标题
- activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "setFullScreen");
- }
- }
-
- /**
- * 设置屏幕为横屏
- * 还有一种就是在 Activity 中加属性 android:screenOrientation="landscape"
- * 不设置 Activity 的 android:configChanges 时,
- * 切屏会重新调用各个生命周期,切横屏时会执行一次,切竖屏时会执行两次
- * 设置 Activity 的 android:configChanges="orientation"时,
- * 切屏还是会重新调用各个生命周期,切横、竖屏时只会执行一次
- * 设置 Activity 的 android:configChanges="orientation|keyboardHidden|screenSize"
- * (4.0 以上必须带最后一个参数)时
- * 切屏不会重新调用各个生命周期,只会执行 onConfigurationChanged 方法
- * @param activity
- */
- public static void setLandscape(@NonNull final Activity activity) {
- try {
- activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "setLandscape");
- }
- }
-
- /**
- * 设置屏幕为竖屏
- * @param activity
- */
- public static void setPortrait(@NonNull final Activity activity) {
- try {
- activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "setPortrait");
- }
- }
-
- /**
- * 判断是否横屏
- * @return true : 是, false : 否
- */
- public static boolean isLandscape() {
- try {
- return DevUtils.getContext().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "isLandscape");
- }
- return false;
- }
-
- /**
- * 判断是否竖屏
- * @return true : 是, false : 否
- */
- public static boolean isPortrait() {
- try {
- return DevUtils.getContext().getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "isPortrait");
- }
- return false;
- }
-
- /**
- * 获取屏幕旋转角度
- * @param activity
- * @return 屏幕旋转角度
- */
- public static int getScreenRotation(@NonNull final Activity activity) {
- try {
- switch (activity.getWindowManager().getDefaultDisplay().getRotation()) {
- case Surface.ROTATION_0:
- return 0;
- case Surface.ROTATION_90:
- return 90;
- case Surface.ROTATION_180:
- return 180;
- case Surface.ROTATION_270:
- return 270;
- default:
- return 0;
- }
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getScreenRotation");
- }
- return 0;
- }
-
- /**
- * 判断是否锁屏
- * @return true : 是, false : 否
- */
- public static boolean isScreenLock() {
- try {
- KeyguardManager keyguardManager = (KeyguardManager) DevUtils.getContext().getSystemService(Context.KEYGUARD_SERVICE);
- return keyguardManager != null && keyguardManager.inKeyguardRestrictedInputMode();
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "isScreenLock");
- }
- return false;
- }
-
- /**
- * 判断是否是平板
- * @return true : 是, false : 否
- */
- public static boolean isTablet() {
- try {
- return (DevUtils.getContext().getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) >= Configuration.SCREENLAYOUT_SIZE_LARGE;
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "isTablet");
- }
- return false;
- }
-
- // == ----------------------------------------- ==
-
- /**
- * 获得状态栏的高度(无关 android:theme 获取状态栏高度)
- * @return
- */
- public static int getStatusHeight() {
- try {
- Class> clazz = Class.forName("com.android.internal.R$dimen");
- Object object = clazz.newInstance();
- int height = Integer.parseInt(clazz.getField("status_bar_height").get(object).toString());
- return DevUtils.getContext().getResources().getDimensionPixelSize(height);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getStatusHeight");
- }
- return -1;
- }
-
- /**
- * 获取应用区域 TitleBar 高度 (顶部灰色TitleBar高度,没有设置 android:theme 的 NoTitleBar 时会显示)
- * @param activity
- * @return
- */
- public static int getStatusBarHeight(Activity activity) {
- try {
- Rect rect = new Rect();
- activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
- return rect.top;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getStatusBarHeight");
- }
- return -1;
- }
-
- /**
- * 设置进入休眠时长 - 需添加权限
- * @param duration 时长
- */
- public static void setSleepDuration(final int duration) {
- try {
- Settings.System.putInt(DevUtils.getContext().getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, duration);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "setSleepDuration");
- }
- }
-
- /**
- * 获取进入休眠时长
- * @return 进入休眠时长,报错返回-123
- */
- public static int getSleepDuration() {
- try {
- return Settings.System.getInt(DevUtils.getContext().getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getSleepDuration");
- return -1;
- }
- }
-
- // == 截图(有用) ==
-
- // https://www.cnblogs.com/angel88/p/7933437.html
-
- // https://github.com/weizongwei5/AndroidScreenShot_SysApi
-
- /**
- * 获取当前屏幕截图,包含状态栏 (顶部灰色TitleBar高度,没有设置 android:theme 的 NoTitleBar 时会显示)
- * @param activity
- * @return
- */
- public static Bitmap snapShotWithStatusBar(Activity activity) {
- try {
- View view = activity.getWindow().getDecorView();
- view.setDrawingCacheEnabled(true);
- view.buildDrawingCache();
- Bitmap bmp = view.getDrawingCache();
- int[] sParams = getScreenWidthHeight();
-
- // 主要是 getWindowVisibleDisplayFrame 内容才不为null
- Rect frame = new Rect();
- activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
- // 创建新的图片
- Bitmap bitmap = Bitmap.createBitmap(bmp, 0, 0, sParams[0], sParams[1]);
- view.destroyDrawingCache();
- return bitmap;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "snapShotWithStatusBar");
- }
- return null;
- }
-
- /**
- * 获取当前屏幕截图,不包含状态栏 (如果 android:theme 全屏了,则截图无状态栏)
- * @param activity
- * @return
- */
- public static Bitmap snapShotWithoutStatusBar(Activity activity) {
- View view = activity.getWindow().getDecorView();
- view.setDrawingCacheEnabled(true);
- view.buildDrawingCache();
- Bitmap bmp = view.getDrawingCache();
- int[] sParams = getScreenWidthHeight();
-
- // 获取状态栏高度
- int statusBarHeight = getStatusBarHeight(activity);
- if(statusBarHeight == -1) {
- statusBarHeight = 0;
- }
-
- Rect frame = new Rect();
- activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
- // 创建新的图片
- Bitmap bitmap = Bitmap.createBitmap(bmp, 0, statusBarHeight, sParams[0], sParams[1] - statusBarHeight);
- view.destroyDrawingCache();
- return bitmap;
- }
-
- // ==
-
- /**
- * 获取底部导航栏高度
- * @return
- */
- public static int getNavigationBarHeight() {
- int navigationBarHeight = 0;
- try {
- Resources resources = DevUtils.getContext().getResources();
- // 获取对应方向字符串
- String orientation = resources.getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT ? "navigation_bar_height" : "navigation_bar_height_landscape";
- // 获取对应的id
- int resourceId = resources.getIdentifier(orientation, "dimen", "android");
- if (resourceId > 0 && checkDeviceHasNavigationBar()) {
- navigationBarHeight = resources.getDimensionPixelSize(resourceId);
- }
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getNavigationBarHeight");
- }
- return navigationBarHeight;
- }
-
- /**
- * 检测是否具有底部导航栏
- * hint: 一加手机上判断不准确
- * @return
- */
- public static boolean checkDeviceHasNavigationBar() {
- boolean hasNavigationBar = false;
- try {
- Resources resources = DevUtils.getContext().getResources();
- int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
- if (id > 0) {
- hasNavigationBar = resources.getBoolean(id);
- }
- try {
- Class systemPropertiesClass = Class.forName("android.os.SystemProperties");
- Method m = systemPropertiesClass.getMethod("get", String.class);
- String navBarOverride = (String) m.invoke(systemPropertiesClass, "qemu.hw.mainkeys");
- if ("1".equals(navBarOverride)) {
- hasNavigationBar = false;
- } else if ("0".equals(navBarOverride)) {
- hasNavigationBar = true;
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "checkDeviceHasNavigationBar - SystemProperties");
- }
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "checkDeviceHasNavigationBar");
- }
- return hasNavigationBar;
- }
-}
-
diff --git a/DevLibUtils/src/main/java/dev/utils/app/ServiceUtils.java b/DevLibUtils/src/main/java/dev/utils/app/ServiceUtils.java
deleted file mode 100644
index e4deef4cdc..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/ServiceUtils.java
+++ /dev/null
@@ -1,189 +0,0 @@
-package dev.utils.app;
-
-import android.app.ActivityManager;
-import android.app.ActivityManager.RunningServiceInfo;
-import android.content.Context;
-import android.content.Intent;
-import android.content.ServiceConnection;
-
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import dev.DevUtils;
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: 服务相关工具类
- * Created by Blankj
- * http://blankj.com
- * Update to Ttt
- */
-public final class ServiceUtils {
-
- private ServiceUtils() {
- }
-
- // 日志TAG
- private static final String TAG = ServiceUtils.class.getSimpleName();
-
- /**
- * 判断服务是否运行
- * @param className 完整包名的服务类名
- * @return true : 是, false : 否
- */
- public static boolean isServiceRunning(final String className) {
- try {
- ActivityManager activityManager = (ActivityManager) DevUtils.getContext().getSystemService(Context.ACTIVITY_SERVICE);
- if (activityManager == null) return false;
- List listInfos = activityManager.getRunningServices(0x7FFFFFFF);
- if (listInfos == null || listInfos.size() == 0) return false;
- for (RunningServiceInfo rInfo : listInfos) {
- if (className.equals(rInfo.service.getClassName())) return true;
- }
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "isServiceRunning");
- }
- return false;
- }
-
- /**
- * 判断服务是否运行
- * @param cls The service class.
- * @return true : 是, false : 否
- */
- public static boolean isServiceRunning(final Class> cls) {
- return isServiceRunning(cls.getName());
- }
-
- /**
- * 获取所有运行的服务
- * @return 服务名集合
- */
- public static Set getAllRunningService() {
- try {
- ActivityManager activityManager = (ActivityManager) DevUtils.getContext().getSystemService(Context.ACTIVITY_SERVICE);
- if (activityManager == null) return Collections.emptySet();
- List listInfos = activityManager.getRunningServices(0x7FFFFFFF);
- if (listInfos == null || listInfos.size() == 0) return null;
- Set names = new HashSet<>();
- for (RunningServiceInfo rInfo : listInfos) {
- names.add(rInfo.service.getClassName());
- }
- return names;
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getAllRunningService");
- }
- return Collections.emptySet();
- }
-
- /**
- * 启动服务
- * @param className 完整包名的服务类名
- */
- public static void startService(final String className) {
- try {
- startService(Class.forName(className));
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "startService");
- }
- }
-
- /**
- * 启动服务
- * @param cls 服务类
- */
- public static void startService(final Class> cls) {
- try {
- Intent intent = new Intent(DevUtils.getContext(), cls);
- DevUtils.getContext().startService(intent);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "startService");
- }
- }
-
- /**
- * 停止服务
- * @param className 完整包名的服务类名
- * @return true : 停止成功, false : 停止失败
- */
- public static boolean stopService(final String className) {
- try {
- return stopService(Class.forName(className));
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "stopService");
- return false;
- }
- }
-
- /**
- * 停止服务
- * @param cls 服务类
- * @return true : 停止成功, false : 停止失败
- */
- public static boolean stopService(final Class> cls) {
- try {
- Intent intent = new Intent(DevUtils.getContext(), cls);
- return DevUtils.getContext().stopService(intent);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "stopService");
- return false;
- }
- }
-
- /**
- * 绑定服务
- * @param className 完整包名的服务类名
- * @param conn 服务连接对象
- * @param flags 绑定选项
- * ====
- * {@link Context#BIND_AUTO_CREATE}
- * {@link Context#BIND_DEBUG_UNBIND}
- * {@link Context#BIND_NOT_FOREGROUND}
- * {@link Context#BIND_ABOVE_CLIENT}
- * {@link Context#BIND_ALLOW_OOM_MANAGEMENT}
- * {@link Context#BIND_WAIVE_PRIORITY}
- */
- public static void bindService(final String className, final ServiceConnection conn, final int flags) {
- try {
- bindService(Class.forName(className), conn, flags);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "bindService");
- }
- }
-
- /**
- * 绑定服务
- * @param cls 服务类
- * @param conn 服务连接对象
- * @param flags 绑定选项
- * ====
- * {@link Context#BIND_AUTO_CREATE}
- * {@link Context#BIND_DEBUG_UNBIND}
- * {@link Context#BIND_NOT_FOREGROUND}
- * {@link Context#BIND_ABOVE_CLIENT}
- * {@link Context#BIND_ALLOW_OOM_MANAGEMENT}
- * {@link Context#BIND_WAIVE_PRIORITY}
- */
- public static void bindService(final Class> cls, final ServiceConnection conn, final int flags) {
- try {
- Intent intent = new Intent(DevUtils.getContext(), cls);
- DevUtils.getContext().bindService(intent, conn, flags);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "bindService");
- }
- }
-
- /**
- * 解绑服务
- * @param conn 服务连接对象
- */
- public static void unbindService(final ServiceConnection conn) {
- try {
- DevUtils.getContext().unbindService(conn);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "unbindService");
- }
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/ShapeUtils.java b/DevLibUtils/src/main/java/dev/utils/app/ShapeUtils.java
deleted file mode 100644
index dec8114091..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/ShapeUtils.java
+++ /dev/null
@@ -1,430 +0,0 @@
-package dev.utils.app;
-
-import android.content.res.ColorStateList;
-import android.graphics.Color;
-import android.graphics.drawable.GradientDrawable;
-import android.os.Build;
-import android.support.annotation.ColorInt;
-import android.support.annotation.ColorRes;
-import android.support.annotation.RequiresApi;
-import android.support.v4.content.ContextCompat;
-import android.text.TextUtils;
-import android.view.View;
-
-import dev.DevUtils;
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: Shape 工具类
- * Created by Ttt
- * https://blog.csdn.net/tanghongchang123/article/details/80283686
- * https://www.cnblogs.com/popfisher/p/5606690.html
- * https://www.cnblogs.com/dongdong230/p/4183079.html
- * https://www.cnblogs.com/zhongle/archive/2012/08/28/2659902.html
- * https://www.2cto.com/kf/201601/456024.html
- */
-public final class ShapeUtils {
-
- // 日志TAG
- private static final String TAG = ShapeUtils.class.getSimpleName();
-
- private final GradientDrawable drawable;
-
- private ShapeUtils(Builder builder) {
- drawable = builder.gradientDrawable;
- }
-
- public GradientDrawable getDrawable() {
- return drawable;
- }
-
- public void setDrawable(View view){
- if (view != null){
- view.setBackground(drawable);
- }
- }
-
- // ==
-
- /**
- * detail: 构造者模式
- * Created by Ttt
- */
- public final static class Builder {
-
- private GradientDrawable gradientDrawable = new GradientDrawable();
-
- public Builder() {
- }
-
- public Builder(GradientDrawable drawable){
- if (drawable != null){
- this.gradientDrawable = drawable;
- }
- }
-
- /**
- * 获取 Shape 工具类
- * @return
- */
- public ShapeUtils build(){
- return new ShapeUtils(this);
- }
-
- // ====
-
- // = 设置圆角 =
-
- /**
- * 设置圆角
- * @param radius
- * @return
- */
- public Builder setRadius(float radius){
- if (gradientDrawable != null){
- gradientDrawable.setCornerRadius(radius);
- }
- return this;
- }
-
- // == 设置左边 ==
-
- /**
- * 设置圆角
- * @param left
- * @return
- */
- public Builder setRadiusLeft(float left){
- setCornerRadii(left, 0, 0, left);
- return this;
- }
-
- /**
- * 设置圆角
- * @param leftTop
- * @param leftBottom
- * @return
- */
- public Builder setRadiusLeft(float leftTop, float leftBottom){
- setCornerRadii(leftTop, 0, 0, leftBottom);
- return this;
- }
-
- // == 设置右边 ==
-
- /**
- * 设置圆角
- * @param right
- * @return
- */
- public Builder setRadiusRight(float right){
- setCornerRadii(0, right, right, 0);
- return this;
- }
-
- /**
- * 设置圆角
- * @param rightTop
- * @param rightBottom
- * @return
- */
- public Builder setRadiusRight(float rightTop, float rightBottom){
- setCornerRadii(0, rightTop, rightBottom, 0);
- return this;
- }
-
- // == 圆角内部处理 ==
-
- /**
- * 内部处理方法
- * @param leftTop
- * @param rightTop
- * @param rightBottom
- * @param leftBottom
- */
- public Builder setCornerRadii(float leftTop, float rightTop, float rightBottom, float leftBottom) {
-//
-
- if (gradientDrawable != null){
- // radii 数组分别指定四个圆角的半径,每个角可以指定[X_Radius,Y_Radius],四个圆角的顺序为左上,右上,右下,左下。如果X_Radius,Y_Radius为0表示还是直角。
- gradientDrawable.setCornerRadii(new float[] { leftTop, leftTop, rightTop, rightTop, rightBottom, rightBottom, leftBottom, leftBottom });
- }
- return this;
- }
-
- // == 设置背景色(填充) ==
-
-//
-
- /**
- * 设置背景色(填充铺满)
- * @param color
- * @return
- */
- public Builder setColor(String color){
- if (gradientDrawable != null && !TextUtils.isEmpty(color)){
- try {
- gradientDrawable.setColor(Color.parseColor(color));
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "setColor");
- }
- }
- return this;
- }
-
- /**
- * 设置背景色(填充铺满)
- * @param color
- * @return
- */
- public Builder setColor(@ColorRes int color){
- if (gradientDrawable != null){
- try {
- gradientDrawable.setColor(ContextCompat.getColor(DevUtils.getContext(), color));
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "setColor");
- }
- }
- return this;
- }
-
- // == 设置边框颜色 ==
-
-//
-
- /**
- * 设置大小
- * @param width
- * @param height
- * @return
- */
- public Builder setSize(int width, int height){
- if (gradientDrawable != null){
- try {
- gradientDrawable.setSize(width, height);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "setSize");
- }
- }
- return this;
- }
-
- // == 设置边距 ==
-
-// /**
-// * 设置边距
-// * @param padding
-// * @return
-// */
-// public Builder setPadding(int padding){
-// if (gradientDrawable != null){
-// try {
-// Rect rect = new Rect();
-// rect.left = padding;
-// rect.top = padding;
-// rect.right = padding;
-// rect.bottom = padding;
-// gradientDrawable.getPadding(rect);
-// } catch (Exception e){
-// LogPrintUtils.eTag(TAG, e, "setPadding");
-// }
-// }
-// return this;
-// }
-
- // == 设置渐变 ==
-
-//
-//
-
-// switch (angle) {
-// case 0:
-// st.mOrientation = Orientation.LEFT_RIGHT;
-// break;
-// case 45:
-// st.mOrientation = Orientation.BL_TR;
-// break;
-// case 90:
-// st.mOrientation = Orientation.BOTTOM_TOP;
-// break;
-// case 135:
-// st.mOrientation = Orientation.BR_TL;
-// break;
-// case 180:
-// st.mOrientation = Orientation.RIGHT_LEFT;
-// break;
-// case 225:
-// st.mOrientation = Orientation.TR_BL;
-// break;
-// case 270:
-// st.mOrientation = Orientation.TOP_BOTTOM;
-// break;
-// case 315:
-// st.mOrientation = Orientation.TL_BR;
-// break;
-// }
-
- /**
- * 设置渐变颜色
- * @param colors
- */
- public Builder(@ColorInt int[] colors){
- this(new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM, colors));
- }
-
- /**
- * 设置渐变颜色
- * @param orientation
- * @param colors
- */
- public Builder(GradientDrawable.Orientation orientation, @ColorInt int[] colors){
- this(new GradientDrawable(orientation, colors));
- }
- }
-
- // == 快捷方法 ==
-
- /**
- * 创建新的 Shape Builder 对象
- * @param radius
- * @param color
- * @return
- */
- public static Builder newBuilder(float radius, @ColorRes int color){
- return new Builder().setRadius(radius).setColor(color);
- }
-
- /**
- * 创建新的 Shape Builder 对象
- * @param left 通用左上, 左下
- * @param color
- * @return
- */
- public static Builder newBuilderToLeft(float left, @ColorRes int color){
- return new Builder().setRadiusLeft(left).setColor(color);
- }
-
- /**
- * 创建新的 Shape Builder 对象
- * @param right 通用右上, 左下
- * @param color
- * @return
- */
- public static Builder newBuilderToRight(float right, @ColorRes int color){
- return new Builder().setRadiusRight(right).setColor(color);
- }
-
- /**
- * 创建渐变的 Shape Builder 对象
- * @param colors
- * @return
- */
- public static Builder newBuilderToGradient(@ColorInt int[] colors){
- return new Builder(colors);
- }
-
- /**
- * 创建渐变的 Shape Builder 对象
- * @param orientation
- * @param colors
- * @return
- */
- public static Builder newBuilderToGradient(GradientDrawable.Orientation orientation, @ColorInt int[] colors){
- return new Builder(orientation, colors);
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/ShellUtils.java b/DevLibUtils/src/main/java/dev/utils/app/ShellUtils.java
deleted file mode 100644
index a188d94de8..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/ShellUtils.java
+++ /dev/null
@@ -1,164 +0,0 @@
-package dev.utils.app;
-
-import java.io.BufferedReader;
-import java.io.DataOutputStream;
-import java.io.InputStreamReader;
-import java.util.List;
-
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: Shell 相关工具类
- * Created by Blankj
- * http://blankj.com
- * Update to Ttt
- */
-public final class ShellUtils {
-
- private ShellUtils() {
- }
-
- // 日志TAG
- private static final String TAG = ShellUtils.class.getSimpleName();
-
- // 换行符
- private static final String LINE_SEP = System.getProperty("line.separator");
-
- /**
- * 是否是在 root 下执行命令
- * @param command 命令
- * @param isRoot 是否需要 root 权限执行
- * @return CommandResult
- */
- public static CommandResult execCmd(final String command, final boolean isRoot) {
- return execCmd(new String[]{ command }, isRoot, true);
- }
-
- /**
- * 是否是在 root 下执行命令
- * @param commands 多条命令链表
- * @param isRoot 是否需要 root 权限执行
- * @return CommandResult
- */
- public static CommandResult execCmd(final List commands, final boolean isRoot) {
- return execCmd(commands == null ? null : commands.toArray(new String[]{}), isRoot, true);
- }
-
- /**
- * 是否是在 root 下执行命令
- * @param commands 多条命令数组
- * @param isRoot 是否需要 root 权限执行
- * @return CommandResult
- */
- public static CommandResult execCmd(final String[] commands, final boolean isRoot) {
- return execCmd(commands, isRoot, true);
- }
-
- /**
- * 是否是在 root 下执行命令
- * @param command 命令
- * @param isRoot 是否需要 root 权限执行
- * @param isNeedResultMsg 是否需要结果消息
- * @return CommandResult
- */
- public static CommandResult execCmd(final String command, final boolean isRoot, final boolean isNeedResultMsg) {
- return execCmd(new String[]{ command }, isRoot, isNeedResultMsg);
- }
-
- /**
- * 是否是在 root 下执行命令
- * @param commands 命令链表
- * @param isRoot 是否需要 root 权限执行
- * @param isNeedResultMsg 是否需要结果消息
- * @return CommandResult
- */
- public static CommandResult execCmd(final List commands, final boolean isRoot, final boolean isNeedResultMsg) {
- return execCmd(commands == null ? null : commands.toArray(new String[]{}), isRoot, isNeedResultMsg);
- }
-
- /**
- * 是否是在 root 下执行命令
- * @param commands 命令数组
- * @param isRoot 是否需要 root 权限执行
- * @param isNeedResultMsg 是否需要结果消息
- * @return CommandResult
- */
- public static CommandResult execCmd(final String[] commands, final boolean isRoot, final boolean isNeedResultMsg) {
- int result = -1;
- if (commands == null || commands.length == 0) {
- return new CommandResult(result, null, null);
- }
- Process process = null;
- BufferedReader successResult = null;
- BufferedReader errorResult = null;
- StringBuilder successMsg = null;
- StringBuilder errorMsg = null;
- DataOutputStream os = null;
- try {
- process = Runtime.getRuntime().exec(isRoot ? "su" : "sh");
- os = new DataOutputStream(process.getOutputStream());
- for (String command : commands) {
- if (command == null) continue;
- os.write(command.getBytes());
- os.writeBytes(LINE_SEP);
- os.flush();
- }
- os.writeBytes("exit" + LINE_SEP);
- os.flush();
- result = process.waitFor();
- if (isNeedResultMsg) {
- successMsg = new StringBuilder();
- errorMsg = new StringBuilder();
- successResult = new BufferedReader(new InputStreamReader(process.getInputStream(), "UTF-8"));
- errorResult = new BufferedReader(new InputStreamReader(process.getErrorStream(), "UTF-8"));
- String line;
- if ((line = successResult.readLine()) != null) {
- successMsg.append(line);
- while ((line = successResult.readLine()) != null) {
- successMsg.append(LINE_SEP).append(line);
- }
- }
- if ((line = errorResult.readLine()) != null) {
- errorMsg.append(line);
- while ((line = errorResult.readLine()) != null) {
- errorMsg.append(LINE_SEP).append(line);
- }
- }
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "execCmd");
- } finally {
- try {
- os.close();
- successResult.close();
- errorResult.close();
- } catch (Exception e) {
- }
- if (process != null) {
- process.destroy();
- }
- }
- return new CommandResult(
- result,
- successMsg == null ? null : successMsg.toString(),
- errorMsg == null ? null : errorMsg.toString()
- );
- }
-
- /** 返回的命令结果 */
- public static class CommandResult {
-
- /** 结果码 */
- public int result;
- /** 成功信息 */
- public String successMsg;
- /** 错误信息 */
- public String errorMsg;
-
- public CommandResult(final int result, final String successMsg, final String errorMsg) {
- this.result = result;
- this.successMsg = successMsg;
- this.errorMsg = errorMsg;
- }
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/ShortCutUtils.java b/DevLibUtils/src/main/java/dev/utils/app/ShortCutUtils.java
deleted file mode 100644
index 496652077d..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/ShortCutUtils.java
+++ /dev/null
@@ -1,93 +0,0 @@
-package dev.utils.app;
-
-import android.content.ComponentName;
-import android.content.ContentResolver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.Intent.ShortcutIconResource;
-import android.database.Cursor;
-import android.net.Uri;
-
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: 创建删除快捷图标工具类
- * Created by Ttt
- * 需要权限:
- * com.android.launcher.permission.INSTALL_SHORTCUT
- * com.android.launcher.permission.UNINSTALL_SHORTCUT
- */
-public final class ShortCutUtils {
-
- private ShortCutUtils() {
- }
-
- // 日志TAG
- private static final String TAG = ShortCutUtils.class.getSimpleName();
-
- /**
- * 检测是否存在桌面快捷方式
- * @param context
- * @param name
- * @return 是否存在桌面图标
- */
- public static boolean hasShortcut(Context context, String name) {
- boolean isInstallShortcut = false;
- Cursor cursor = null;
- try {
- ContentResolver cr = context.getContentResolver();
- String AUTHORITY = "com.android.launcher.settings";
- Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/favorites?notify=true");
- cursor = cr.query(CONTENT_URI, new String[]{"title", "iconResource"}, "title=?", new String[]{ name }, null);
- if (cursor != null && cursor.getCount() > 0) {
- isInstallShortcut = true;
- }
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "hasShortcut");
- } finally {
- if (cursor != null) {
- try {
- cursor.close();
- } catch (Exception e) {
- }
- }
- }
- return isInstallShortcut;
- }
-
- /**
- * 为程序创建桌面快捷方式
- * @param context
- * @param clasName
- * @param name
- * @param res
- */
- public static void addShortcut(Context context, String clasName, String name, int res) {
- Intent shortcut = new Intent( "com.android.launcher.action.INSTALL_SHORTCUT");
- shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, name); // 快捷方式的名称
- shortcut.putExtra("duplicate", false); // 不允许重复创建
- // 设置 快捷方式跳转页面
- Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
- shortcutIntent.setClassName(context, clasName);
- shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
- // 快捷方式的图标
- ShortcutIconResource iconRes = ShortcutIconResource.fromContext(context, res);
- shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
- context.sendBroadcast(shortcut);
- }
-
- /**
- * 删除程序的快捷方式
- * @param context
- * @param name
- */
- public static void delShortcut(Context context, String clasName, String name) {
- Intent shortcut = new Intent( "com.android.launcher.action.UNINSTALL_SHORTCUT");
- // 快捷方式的名称
- shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
- String appClass = context.getPackageName() + "." + clasName;
- ComponentName comp = new ComponentName(context.getPackageName(), appClass);
- shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));
- context.sendBroadcast(shortcut);
- }
-}
\ No newline at end of file
diff --git a/DevLibUtils/src/main/java/dev/utils/app/SignaturesUtils.java b/DevLibUtils/src/main/java/dev/utils/app/SignaturesUtils.java
deleted file mode 100644
index 358e768846..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/SignaturesUtils.java
+++ /dev/null
@@ -1,232 +0,0 @@
-package dev.utils.app;
-
-import android.content.pm.Signature;
-
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.security.MessageDigest;
-import java.security.cert.Certificate;
-import java.security.cert.CertificateFactory;
-import java.security.cert.X509Certificate;
-import java.util.jar.JarEntry;
-import java.util.jar.JarFile;
-
-import javax.security.auth.x500.X500Principal;
-
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: 签名工具类(获取app,签名信息)
- * Created by Ttt
- */
-public final class SignaturesUtils {
-
- private SignaturesUtils() {
- }
-
- // 日志TAG
- private static final String TAG = SignaturesUtils.class.getSimpleName();
-
- // 如需要小写则把ABCDEF改成小写
- private static final char HEX_DIGITS[] = { '0', '1', '2', '3', '4', '5',
- '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
-
- /**
- * 检测应用程序是否是用"CN=Android Debug,O=Android,C=US"的debug信息来签名的
- * 判断签名是debug签名还是release签名
- */
- private final static X500Principal DEBUG_DN = new X500Principal("CN=Android Debug,O=Android,C=US");
-
- /**
- * 进行转换
- * @param bData
- * @return
- */
- public static String toHexString(byte[] bData) {
- StringBuilder sb = new StringBuilder(bData.length * 2);
- for (int i = 0, len = bData.length; i < len; i++) {
- sb.append(HEX_DIGITS[(bData[i] & 0xf0) >>> 4]);
- sb.append(HEX_DIGITS[bData[i] & 0x0f]);
- }
- return sb.toString();
- }
-
- /**
- * 返回MD5
- * @param signatures
- * @return
- */
- public static String signatureMD5(Signature[] signatures) {
- try {
- MessageDigest digest = MessageDigest.getInstance("MD5");
- if (signatures != null) {
- for (Signature s : signatures)
- digest.update(s.toByteArray());
- }
- return toHexString(digest.digest());
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "signatureMD5");
- return "";
- }
- }
-
- /**
- * SHA1
- */
- public static String signatureSHA1(Signature[] signatures) {
- try {
- MessageDigest digest = MessageDigest.getInstance("SHA-1");
- if (signatures != null) {
- for (Signature s : signatures)
- digest.update(s.toByteArray());
- }
- return toHexString(digest.digest());
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "signatureSHA1");
- return "";
- }
- }
-
- /**
- * SHA256
- */
- public static String signatureSHA256(Signature[] signatures) {
- try {
- MessageDigest digest = MessageDigest.getInstance("SHA-256");
- if (signatures != null) {
- for (Signature s : signatures)
- digest.update(s.toByteArray());
- }
- return toHexString(digest.digest());
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "signatureSHA256");
- return "";
- }
- }
-
- /**
- * 判断签名是debug签名还是release签名
- * @return true = 开发(debug.keystore),false = 上线发布(非.android默认debug.keystore)
- */
- public static boolean isDebuggable(Signature[] signatures) {
- // 判断是否默认key(默认是)
- boolean debuggable = true;
- try {
- for (int i = 0, len = signatures.length; i < len; i++) {
- CertificateFactory cf = CertificateFactory.getInstance("X.509");
- ByteArrayInputStream stream = new ByteArrayInputStream(signatures[i].toByteArray());
- X509Certificate cert = (X509Certificate) cf.generateCertificate(stream);
- debuggable = cert.getSubjectX500Principal().equals(DEBUG_DN);
- if (debuggable) {
- break;
- }
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "isDebuggable");
- }
- return debuggable;
- }
-
- /**
- * 获取App 证书对象
- */
- public static X509Certificate getX509Certificate(Signature[] signatures){
- try {
- CertificateFactory cf = CertificateFactory.getInstance("X.509");
- ByteArrayInputStream stream = new ByteArrayInputStream(signatures[0].toByteArray());
- X509Certificate cert = (X509Certificate) cf.generateCertificate(stream);
- return cert;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getX509Certificate");
- }
- return null;
- }
-
- /**
- * 打印签名信息
- * @param signatures
- * @return
- */
- public static void printSignatureName(Signature[] signatures){
- try {
- for (int i = 0, len = signatures.length; i < len; i++) {
- CertificateFactory cf = CertificateFactory.getInstance("X.509");
- ByteArrayInputStream stream = new ByteArrayInputStream(signatures[i].toByteArray());
- X509Certificate cert = (X509Certificate) cf.generateCertificate(stream);
-
- String pubKey = cert.getPublicKey().toString(); // 公钥
- String signNumber = cert.getSerialNumber().toString();
-
- LogPrintUtils.dTag(TAG, "signName:" + cert.getSigAlgName());//算法名
- LogPrintUtils.dTag(TAG, "pubKey:" + pubKey);
- LogPrintUtils.dTag(TAG, "signNumber:" + signNumber);//证书序列编号
- LogPrintUtils.dTag(TAG, "subjectDN:"+cert.getSubjectDN().toString());
- LogPrintUtils.dTag(TAG, cert.getNotAfter() + "--" + cert.getNotBefore());
- }
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "signatureNameA");
- }
- }
-
- // --
-
- // Android的APK应用签名机制以及读取签名的方法
- // http://www.jb51.net/article/79894.htm
-
- /**
- * 从APK中读取签名
- * @param file
- * @return
- * @throws IOException
- */
- public static Signature[] getSignaturesFromApk(File file) {
- try {
- Certificate[] certificates = getCertificateFromApk(file);
- Signature[] signatures = new Signature[] { new Signature(certificates[0].getEncoded()) };
- return signatures;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getSignaturesFromApk");
- }
- return null;
- }
-
- /**
- * 从APK中读取签名
- * @param file
- * @return
- * @throws IOException
- */
- public static Certificate[] getCertificateFromApk(File file) {
- try {
- JarFile jarFile = new JarFile(file);
- JarEntry je = jarFile.getJarEntry("AndroidManifest.xml");
- byte[] readBuffer = new byte[8192];
- return loadCertificates(jarFile, je, readBuffer);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getCertificateFromApk");
- }
- return null;
- }
-
- /**
- * 加载签名
- * @param jarFile
- * @param je
- * @param readBuffer
- * @return
- */
- private static Certificate[] loadCertificates(JarFile jarFile, JarEntry je, byte[] readBuffer) {
- try {
- InputStream is = jarFile.getInputStream(je);
- while (is.read(readBuffer, 0, readBuffer.length) != -1) {
- }
- is.close();
- return je != null ? je.getCertificates() : null;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "loadCertificates");
- }
- return null;
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/SizeUtils.java b/DevLibUtils/src/main/java/dev/utils/app/SizeUtils.java
deleted file mode 100644
index 8b247c2290..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/SizeUtils.java
+++ /dev/null
@@ -1,208 +0,0 @@
-package dev.utils.app;
-
-import android.util.DisplayMetrics;
-import android.util.TypedValue;
-import android.view.View;
-import android.view.ViewGroup;
-
-import dev.DevUtils;
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: dp,px,sp转换、View获取宽高等
- * Created by Ttt
- */
-public final class SizeUtils {
-
- private SizeUtils() {
- }
-
- // 日志TAG
- private static final String TAG = SizeUtils.class.getSimpleName();
-
- /**
- * 根据手机的分辨率从 dp 的单位 转成为 px(像素)
- * @param dpValue
- */
- public static int dipConvertPx(float dpValue) {
- try {
- float scale = DevUtils.getContext().getResources().getDisplayMetrics().density;
- return (int) (dpValue * scale + 0.5f);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "dipConvertPx");
- }
- return -1;
- }
-
- /**
- * 根据手机的分辨率从 px(像素) 的单位 转成为 dp
- * @param pxValue
- */
- public static int pxConvertDip(float pxValue) {
- try {
- float scale = DevUtils.getContext().getResources().getDisplayMetrics().density;
- return (int) (pxValue / scale + 0.5f);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "pxConvertDip");
- }
- return -1;
- }
-
- /**
- * 根据手机的分辨率从 px(像素) 的单位 转成为 sp
- * @param pxValue
- */
- public static int pxConvertSp(float pxValue) {
- try {
- float scale = DevUtils.getContext().getResources().getDisplayMetrics().scaledDensity;
- return (int) (pxValue / scale + 0.5f);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "pxConvertSp");
- }
- return -1;
- }
-
- /**
- * 根据手机的分辨率从 sp 的单位 转成为 px
- * @param spValue
- */
- public static int spConvertPx(float spValue) {
- try {
- float scale = DevUtils.getContext().getResources().getDisplayMetrics().scaledDensity;
- return (int) (spValue * scale + 0.5f);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "spConvertPx");
- }
- return -1;
- }
-
- /**
- * 根据手机的分辨率从 dp 的单位 转成为 px(像素) 第二种
- * @param dpValue
- */
- public static int dipConvertPx2(float dpValue) {
- try {
- return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dpValue, DevUtils.getContext().getResources().getDisplayMetrics());
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "dipConvertPx2");
- }
- return -1;
- }
-
- /**
- * 根据手机的分辨率从 sp 的单位 转成为 px 第二种
- * @param spValue
- */
- public static int spConvertPx2(float spValue) {
- try {
- // android.util.TypedValue
- return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, spValue, DevUtils.getContext().getResources().getDisplayMetrics());
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "spConvertPx2");
- }
- return -1;
- }
-
- /**
- * 各种单位转换 - 该方法存在于 TypedValue
- * @param unit 单位
- * @param value 值
- * @param metrics DisplayMetrics
- * @return 转换结果
- */
- public static float applyDimension(final int unit, final float value, final DisplayMetrics metrics) {
- switch (unit) {
- case TypedValue.COMPLEX_UNIT_PX:
- return value;
- case TypedValue.COMPLEX_UNIT_DIP:
- return value * metrics.density;
- case TypedValue.COMPLEX_UNIT_SP:
- return value * metrics.scaledDensity;
- case TypedValue.COMPLEX_UNIT_PT:
- return value * metrics.xdpi * (1.0f / 72);
- case TypedValue.COMPLEX_UNIT_IN:
- return value * metrics.xdpi;
- case TypedValue.COMPLEX_UNIT_MM:
- return value * metrics.xdpi * (1.0f / 25.4f);
- }
- return -1;
- }
-
- // ==
-
- /**
- * 在 onCreate 中获取视图的尺寸 - 需回调 onGetSizeListener 接口,在 onGetSize 中获取 view 宽高
- * 用法示例如下所示
- * SizeUtils.forceGetViewSize(view, new SizeUtils.onGetSizeListener() {
- * Override
- * public void onGetSize(final View view) {
- * view.getWidth();
- * }
- * });
- * @param view 视图
- * @param listener 监听器
- */
- public static void forceGetViewSize(final View view, final onGetSizeListener listener) {
- view.post(new Runnable() {
- @Override
- public void run() {
- if (listener != null) {
- listener.onGetSize(view);
- }
- }
- });
- }
-
- /** 获取到 View 尺寸的监听 */
- public interface onGetSizeListener {
- void onGetSize(View view);
- }
-
- // ==
-
- /**
- * 测量视图尺寸
- * @param view 视图
- * @return arr[0]: 视图宽度, arr[1]: 视图高度
- */
- public static int[] measureView(final View view) {
- try {
- ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
- if (layoutParams == null) {
- layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
- }
- int widthSpec = ViewGroup.getChildMeasureSpec(0, 0, layoutParams.width);
- int lpHeight = layoutParams.height;
- int heightSpec;
- if (lpHeight > 0) {
- heightSpec = View.MeasureSpec.makeMeasureSpec(lpHeight, View.MeasureSpec.EXACTLY);
- } else {
- heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
- }
- view.measure(widthSpec, heightSpec);
- return new int[]{ view.getMeasuredWidth(), view.getMeasuredHeight() };
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "measureView");
- return new int[] { 0, 0 };
- }
- }
-
- /**
- * 获取测量视图宽度
- * @param view 视图
- * @return 视图宽度
- */
- public static int getMeasuredWidth(final View view) {
- return measureView(view)[0];
- }
-
- /**
- * 获取测量视图高度
- * @param view 视图
- * @return 视图高度
- */
- public static int getMeasuredHeight(final View view) {
- return measureView(view)[1];
- }
-}
-
diff --git a/DevLibUtils/src/main/java/dev/utils/app/StateListUtils.java b/DevLibUtils/src/main/java/dev/utils/app/StateListUtils.java
deleted file mode 100644
index 9bb603c6d4..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/StateListUtils.java
+++ /dev/null
@@ -1,317 +0,0 @@
-package dev.utils.app;
-
-import android.content.Context;
-import android.content.res.ColorStateList;
-import android.graphics.Color;
-import android.graphics.drawable.Drawable;
-import android.graphics.drawable.StateListDrawable;
-import android.support.annotation.ColorRes;
-import android.support.annotation.DrawableRes;
-import android.support.v4.content.ContextCompat;
-
-import dev.DevUtils;
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: 颜色状态列表 工具类
- * Created by Ttt
- * https://blog.csdn.net/wuqilianga/article/details/72964884
- * https://blog.csdn.net/CrazyMo_/article/details/53456541
- */
-public final class StateListUtils {
-
- private StateListUtils() {
- }
-
- // 日志TAG
- private static final String TAG = StateListUtils.class.getSimpleName();
-
-// android:state_active 是否处于激活状态
-// android:state_checkable 是否可勾选
-// android:state_checked 是否已勾选
-// android:state_enabled 是否可用
-// android:state_first 是否开始状态
-// android:state_focused 是否已获取焦点
-// android:state_last 是否处于结束
-// android:state_middle 是否处于中间
-// android:state_pressed 是否处于按下状态 .
-// android:state_selected 是否处于选中状态
-// android:state_window_focused 是否窗口已获得焦点
-
- /**
- * 通过上下文获取
- * @param id
- * @return
- */
- public static ColorStateList getColorStateList(int id) {
- try {
- return ContextCompat.getColorStateList(DevUtils.getContext(), id);
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "getColorStateList");
- }
- return null;
- }
-
- // === 设置字体颜色 ===
-
- // == 字符串颜色 ==
-
- /**
- * 创建 颜色状态列表 => createColorStateList("#ffffffff", "#ff44e6ff")
- * @param pressed
- * @param normal
- * @return
- */
- public static ColorStateList createColorStateList(String pressed, String normal) {
- // 颜色值
- int[] colors = new int[]{ Color.parseColor(pressed), Color.parseColor(normal) };
- // 状态值
- int[][] states = new int[2][];
- states[0] = new int[]{ android.R.attr.state_pressed }; // 选中颜色
- states[1] = new int[]{ }; // 默认颜色
- // 生成对应的List对象
- ColorStateList colorList = new ColorStateList(states, colors);
- return colorList;
- }
-
- /**
- * 创建 颜色状态列表
- * @param selected
- * @param pressed
- * @param normal
- * @return
- */
- public static ColorStateList createColorStateList(String selected, String pressed, String normal) {
- // 颜色值
- int[] colors = new int[]{ Color.parseColor(selected), Color.parseColor(pressed), Color.parseColor(normal) };
- // 状态值
- int[][] states = new int[3][];
- states[0] = new int[]{ android.R.attr.state_selected }; // 选中颜色
- states[1] = new int[]{ android.R.attr.state_pressed }; // 点击颜色
- states[2] = new int[]{ }; // 默认颜色
- // 生成对应的List对象
- ColorStateList colorList = new ColorStateList(states, colors);
- return colorList;
- }
-
- /**
- * 创建 颜色状态列表
- * @param selected
- * @param pressed
- * @param focused
- * @param checked
- * @param normal
- * @return
- */
- public static ColorStateList createColorStateList(String selected, String pressed, String focused, String checked, String normal) {
- // 颜色值
- int[] colors = new int[]{ Color.parseColor(selected), Color.parseColor(pressed), Color.parseColor(focused), Color.parseColor(checked), Color.parseColor(normal) };
- // 状态值
- int[][] states = new int[5][];
- states[0] = new int[]{ android.R.attr.state_selected }; // 选中颜色
- states[1] = new int[]{ android.R.attr.state_pressed }; // 点击颜色
- states[2] = new int[]{ android.R.attr.state_focused }; // 获取焦点
- states[3] = new int[]{ android.R.attr.state_checked }; // 选中
- states[4] = new int[]{ }; // 默认颜色
- // 生成对应的List对象
- ColorStateList colorList = new ColorStateList(states, colors);
- return colorList;
- }
-
- // == int ==
-
- /**
- * 创建 颜色状态列表 => createColorStateList(R.color.whilte, R.color.black)
- * @param pressed
- * @param normal
- * @return
- */
- public static ColorStateList createColorStateList(@ColorRes int pressed, @ColorRes int normal) {
- Context context = DevUtils.getContext();
- // 颜色值
- int[] colors = new int[2];
- colors[0] = ContextCompat.getColor(context, pressed);
- colors[1] = ContextCompat.getColor(context, normal);
- // 状态值
- int[][] states = new int[2][];
- states[0] = new int[]{ android.R.attr.state_pressed }; // 选中颜色
- states[1] = new int[]{ }; // 默认颜色
- // 生成对应的List对象
- ColorStateList colorList = new ColorStateList(states, colors);
- return colorList;
- }
-
- /**
- * 创建 颜色状态列表
- * @param selected
- * @param pressed
- * @param normal
- * @return
- */
- public static ColorStateList createColorStateList(@ColorRes int selected, @ColorRes int pressed, @ColorRes int normal) {
- Context context = DevUtils.getContext();
- // 颜色值
- int[] colors = new int[3];
- colors[0] = ContextCompat.getColor(context, selected);
- colors[1] = ContextCompat.getColor(context, pressed);
- colors[2] = ContextCompat.getColor(context, normal);
- // 状态值
- int[][] states = new int[3][];
- states[0] = new int[]{ android.R.attr.state_selected }; // 选中颜色
- states[1] = new int[]{ android.R.attr.state_pressed }; // 点击颜色
- states[2] = new int[]{ }; // 默认颜色
- // 生成对应的List对象
- ColorStateList colorList = new ColorStateList(states, colors);
- return colorList;
- }
-
- /**
- * 创建 颜色状态列表
- * @param selected
- * @param pressed
- * @param focused
- * @param checked
- * @param normal
- * @return
- */
- public static ColorStateList createColorStateList(@ColorRes int selected, @ColorRes int pressed, @ColorRes int focused, @ColorRes int checked, @ColorRes int normal) {
- Context context = DevUtils.getContext();
- // 颜色值
- int[] colors = new int[5];
- colors[0] = ContextCompat.getColor(context, selected);
- colors[1] = ContextCompat.getColor(context, pressed);
- colors[2] = ContextCompat.getColor(context, focused);
- colors[3] = ContextCompat.getColor(context, checked);
- colors[4] = ContextCompat.getColor(context, normal);
- // 状态值
- int[][] states = new int[5][];
- states[0] = new int[]{ android.R.attr.state_selected }; // 选中颜色
- states[1] = new int[]{ android.R.attr.state_pressed }; // 点击颜色
- states[2] = new int[]{ android.R.attr.state_focused }; // 获取焦点
- states[3] = new int[]{ android.R.attr.state_checked }; // 选中
- states[4] = new int[]{ }; // 默认颜色
- // 生成对应的List对象
- ColorStateList colorList = new ColorStateList(states, colors);
- return colorList;
- }
-
- // === 设置背景切换 Drawable ===
-
- /**
- * 创建 Drawable选择切换 list => view.setBackground(Drawable)
- * @param pressed
- * @param normal
- * @return
- */
- public static StateListDrawable newSelector(@DrawableRes int pressed, @DrawableRes int normal) {
- Context context = DevUtils.getContext();
- // == 获取 Drawable ==
- Drawable pressedDraw = ContextCompat.getDrawable(context, pressed);
- Drawable normalDraw = ContextCompat.getDrawable(context, normal);
- // 默认初始化
- StateListDrawable stateListDrawable = new StateListDrawable();
- stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, pressedDraw);
- stateListDrawable.addState(new int[] {}, normalDraw);
- return stateListDrawable;
- }
-
- /**
- * 创建 Drawable选择切换 list
- * @param selected
- * @param pressed
- * @param normal
- * @return
- */
- public static StateListDrawable newSelector(@DrawableRes int selected, @DrawableRes int pressed, @DrawableRes int normal) {
- Context context = DevUtils.getContext();
- // == 获取 Drawable ==
- Drawable selectedDraw = ContextCompat.getDrawable(context, selected);
- Drawable pressedDraw = ContextCompat.getDrawable(context, pressed);
- Drawable normalDraw = ContextCompat.getDrawable(context, normal);
- // 默认初始化
- StateListDrawable stateListDrawable = new StateListDrawable();
- stateListDrawable.addState(new int[] { android.R.attr.state_selected }, selectedDraw);
- stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, pressedDraw);
- stateListDrawable.addState(new int[] {}, normalDraw);
- return stateListDrawable;
- }
-
- /**
- * 创建 Drawable选择切换 list
- * @param selected
- * @param pressed
- * @param focused
- * @param checked
- * @param normal
- * @return
- */
- public static StateListDrawable newSelector(@DrawableRes int selected, @DrawableRes int pressed, @DrawableRes int focused, @DrawableRes int checked, @DrawableRes int normal) {
- Context context = DevUtils.getContext();
- // == 获取 Drawable ==
- Drawable selectedDraw = ContextCompat.getDrawable(context, selected);
- Drawable pressedDraw = ContextCompat.getDrawable(context, pressed);
- Drawable focusedDraw = ContextCompat.getDrawable(context, focused);
- Drawable checkedDraw = ContextCompat.getDrawable(context, checked);
- Drawable normalDraw = ContextCompat.getDrawable(context, normal);
- // 默认初始化
- StateListDrawable stateListDrawable = new StateListDrawable();
- stateListDrawable.addState(new int[] { android.R.attr.state_selected }, selectedDraw);
- stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, pressedDraw);
- stateListDrawable.addState(new int[] { android.R.attr.state_focused }, focusedDraw);
- stateListDrawable.addState(new int[] { android.R.attr.state_checked }, checkedDraw);
- stateListDrawable.addState(new int[] {}, normalDraw);
- return stateListDrawable;
- }
-
- // === 设置背景切换 Drawable ===
-
- /**
- * 创建 Drawable选择切换 list => view.setBackground(Drawable)
- * @param pressed
- * @param normal
- * @return
- */
- public static StateListDrawable newSelector(Drawable pressed, Drawable normal) {
- // 默认初始化
- StateListDrawable stateListDrawable = new StateListDrawable();
- stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, pressed);
- stateListDrawable.addState(new int[] {}, normal);
- return stateListDrawable;
- }
-
- /**
- * 创建 Drawable选择切换 list
- * @param selected
- * @param pressed
- * @param normal
- * @return
- */
- public static StateListDrawable newSelector(Drawable selected, Drawable pressed, Drawable normal) {
- // 默认初始化
- StateListDrawable stateListDrawable = new StateListDrawable();
- stateListDrawable.addState(new int[] { android.R.attr.state_selected }, selected);
- stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, pressed);
- stateListDrawable.addState(new int[] {}, normal);
- return stateListDrawable;
- }
-
- /**
- * 创建 Drawable选择切换 list
- * @param selected
- * @param pressed
- * @param focused
- * @param checked
- * @param normal
- * @return
- */
- public static StateListDrawable newSelector(Drawable selected, Drawable pressed, Drawable focused, Drawable checked, Drawable normal) {
- // 默认初始化
- StateListDrawable stateListDrawable = new StateListDrawable();
- stateListDrawable.addState(new int[] { android.R.attr.state_selected }, selected);
- stateListDrawable.addState(new int[] { android.R.attr.state_pressed }, pressed);
- stateListDrawable.addState(new int[] { android.R.attr.state_focused }, focused);
- stateListDrawable.addState(new int[] { android.R.attr.state_checked }, checked);
- stateListDrawable.addState(new int[] {}, normal);
- return stateListDrawable;
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/TextViewUtils.java b/DevLibUtils/src/main/java/dev/utils/app/TextViewUtils.java
deleted file mode 100644
index 099624eec4..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/TextViewUtils.java
+++ /dev/null
@@ -1,582 +0,0 @@
-package dev.utils.app;
-
-import android.app.Activity;
-import android.graphics.Paint;
-import android.graphics.Rect;
-import android.support.annotation.ColorInt;
-import android.support.annotation.IdRes;
-import android.text.Html;
-import android.view.View;
-import android.view.Window;
-import android.widget.TextView;
-
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: TextView 工具类
- * Created by Ttt
- */
-public final class TextViewUtils {
-
- private TextViewUtils() {
- }
-
- // 日志TAG
- private static final String TAG = TextViewUtils.class.getSimpleName();
-
- /**
- * 获取TextView
- * @param view
- * @return
- */
- public static TextView getTextView(View view){
- if (view != null){
- try {
- return (TextView) view;
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getTextView");
- }
- }
- return null;
- }
-
- /**
- * 获取TextView
- * @param view
- * @return
- */
- public static TextView getTextView(View view, @IdRes int id){
- if (view != null){
- try {
- return view.findViewById(id);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getTextView");
- }
- }
- return null;
- }
-
- /**
- * 获取TextView
- * @param activity
- * @return
- */
- public static TextView getTextView(Activity activity, @IdRes int id){
- if (activity != null){
- try {
- return activity.findViewById(id);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getTextView");
- }
- }
- return null;
- }
-
- /**
- * 获取TextView
- * @param window
- * @return
- */
- public static TextView getTextView(Window window, @IdRes int id){
- if (window != null){
- try {
- return window.findViewById(id);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getTextView");
- }
- }
- return null;
- }
-
- // =
-
- /**
- * 获取文本
- * @param textView
- * @return
- */
- public static String getText(TextView textView){
- if (textView != null){
- return textView.getText().toString();
- }
- return null;
- }
-
- /**
- * 获取文本
- * @param view
- * @return
- */
- public static String getText(View view) {
- if (view != null){
- try {
- return ((TextView) view).getText().toString();
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getText");
- }
- }
- return null;
- }
-
-
- /**
- * 获取文本
- * @param view
- * @return
- */
- public static String getText(View view, @IdRes int id){
- if (view != null){
- try {
- return ((TextView) view.findViewById(id)).getText().toString();
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getText");
- }
- }
- return null;
- }
-
- /**
- * 获取文本
- * @param activity
- * @return
- */
- public static String getText(Activity activity, @IdRes int id){
- if (activity != null){
- try {
- return ((TextView) activity.findViewById(id)).getText().toString();
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getText");
- }
- }
- return null;
- }
-
- /**
- * 获取文本
- * @param window
- * @return
- */
- public static String getText(Window window, @IdRes int id){
- if (window != null){
- try {
- return ((TextView) window.findViewById(id)).getText().toString();
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getText");
- }
- }
- return null;
- }
-
- // =
-
-
- /**
- * 设置字体颜色
- * @param view
- * @param color
- */
- public static void setTextColor(View view, @ColorInt int color){
- if (view != null){
- if (view instanceof TextView){
- ((TextView) view).setTextColor(color);
- }
- }
- }
-
- /**
- * 设置字体颜色
- * @param textView
- * @param color
- */
- public static void setTextColor(TextView textView, @ColorInt int color){
- if (textView != null){
- textView.setTextColor(color);
- }
- }
-
- /**
- * 设置字体颜色
- * @param view
- * @param id
- * @param color
- */
- public static void setTextColor(View view, @IdRes int id, @ColorInt int color){
- if (view != null){
- try {
- ((TextView) view.findViewById(id)).setTextColor(color);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "setTextColor");
- }
- }
- }
-
- /**
- * 设置字体颜色
- * @param activity
- * @param id
- * @param color
- */
- public static void setTextColor(Activity activity, @IdRes int id, @ColorInt int color){
- if (activity != null){
- try {
- ((TextView) activity.findViewById(id)).setTextColor(color);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "setTextColor");
- }
- }
- }
-
- /**
- * 设置字体颜色
- * @param window
- * @param id
- * @param color
- */
- public static void setTextColor(Window window, @IdRes int id, @ColorInt int color){
- if (window != null){
- try {
- ((TextView) window.findViewById(id)).setTextColor(color);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "setTextColor");
- }
- }
- }
-
- // =
-
- /**
- * 设置内容
- * @param view
- * @param content
- */
- public static void setText(View view, String content){
- if (view != null && content != null){
- if (view instanceof TextView){
- ((TextView) view).setText(content);
- }
- }
- }
-
- /**
- * 设置内容
- * @param view
- * @param id
- * @param content
- */
- public static void setText(View view, @IdRes int id, String content){
- if (view != null){
- try {
- ((TextView) view.findViewById(id)).setText(content);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "setText");
- }
- }
- }
-
- /**
- * 设置内容
- * @param activity
- * @param id
- * @param content
- */
- public static void setText(Activity activity, @IdRes int id, String content){
- if (activity != null){
- try {
- ((TextView) activity.findViewById(id)).setText(content);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "setText");
- }
- }
- }
-
- /**
- * 设置内容
- * @param window
- * @param id
- * @param content
- */
- public static void setText(Window window, @IdRes int id, String content){
- if (window != null){
- try {
- ((TextView) window.findViewById(id)).setText(content);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "setText");
- }
- }
- }
-
- // =
-
- /**
- * 设置 Html 内容
- * @param view
- * @param content
- */
- public static void setHtmlText(View view, String content){
- if (view != null && content != null){
- if (view instanceof TextView){
- ((TextView) view).setText(Html.fromHtml(content));
- }
- }
- }
-
- /**
- * 设置 Html 内容
- * @param view
- * @param id
- * @param content
- */
- public static void setHtmlText(View view, @IdRes int id, String content){
- if (view != null){
- try {
- ((TextView) view.findViewById(id)).setText(Html.fromHtml(content));
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "setHtmlText");
- }
- }
- }
-
- /**
- * 设置 Html 内容
- * @param activity
- * @param id
- * @param content
- */
- public static void setHtmlText(Activity activity, @IdRes int id, String content){
- if (activity != null){
- try {
- ((TextView) activity.findViewById(id)).setText(Html.fromHtml(content));
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "setHtmlText");
- }
- }
- }
-
- /**
- * 设置 Html 内容
- * @param window
- * @param id
- * @param content
- */
- public static void setHtmlText(Window window, @IdRes int id, String content){
- if (window != null){
- try {
- ((TextView) window.findViewById(id)).setText(Html.fromHtml(content));
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "setHtmlText");
- }
- }
- }
-
- // -
-
- /**
- * 设置内容
- * @param textView
- * @param content
- */
- public static void setText(TextView textView, String content){
- if (textView != null && content != null){
- textView.setText(content);
- }
- }
-
- /**
- * 设置 Html 内容
- * @param textView
- * @param content
- */
- public static void setHtmlText(TextView textView, String content){
- if (textView != null && content != null){
- textView.setText(Html.fromHtml(content));
- }
- }
-
- /**
- * 给TextView设置下划线
- * @param textView
- */
- public static void setTVUnderLine(TextView textView) {
- if (textView != null){
- Paint paint = textView.getPaint();
- paint.setFlags(Paint.UNDERLINE_TEXT_FLAG);
- paint.setAntiAlias(true);
- }
- }
-
- /**
- * 获取字体高度
- * @param textView
- * @return
- */
- public static int getTextHeight(TextView textView){
- if (textView != null){
- return getTextHeight(textView.getPaint());
- }
- return -1;
- }
-
- /**
- * 获取字体高度
- * @param paint
- * @return
- */
- public static int getTextHeight(Paint paint){
- // https://blog.csdn.net/superbigcupid/article/details/47153139
- // 获取字体高度
- Paint.FontMetricsInt fontMetrics = paint.getFontMetricsInt();
- // 计算内容高度
- int tHeight = (int) Math.ceil((fontMetrics.descent - fontMetrics.ascent));
- // 返回字体高度
- return tHeight;
- }
-
- /**
- * 获取字体顶部偏移高度
- * @param textView
- * @return
- */
- public static int getTextTopOffsetHeight(TextView textView){
- if (textView != null){
- return getTextTopOffsetHeight(textView.getPaint());
- }
- return -1;
- }
-
- /**
- * 获取字体顶部偏移高度
- * @param paint
- * @return
- */
- public static int getTextTopOffsetHeight(Paint paint){
- // 获取字体高度
- Paint.FontMetricsInt fontMetrics = paint.getFontMetricsInt();
- // 计算字体偏差(顶部偏差)
- int baseLine = (int) Math.ceil(Math.abs(fontMetrics.top) - Math.abs(fontMetrics.ascent));
- // 返回顶部偏差
- return baseLine;
- }
-
- /**
- * 计算字体宽度
- * @param textView
- * @return
- */
- public static float getTextWidth(TextView textView){
- return getTextWidth(textView.getPaint(), textView.getText().toString());
- }
-
- /**
- * 计算字体宽度
- * @param paint
- * @param hintStr
- * @return
- */
- public static float getTextWidth(Paint paint, String hintStr){
- return paint.measureText(hintStr);
- }
-
- /**
- * 获取画布中间居中位置
- * @param targetRect
- * @param paint
- * @return
- */
- public static int getCenterRectY(Rect targetRect, Paint paint){
- // 将字画在矩形背景的正中位置
- // https://blog.csdn.net/superbigcupid/article/details/47153139
- // 获取字体高度
- Paint.FontMetricsInt fontMetrics = paint.getFontMetricsInt();
- // 获取底部Y轴居中位置
- return targetRect.top + (targetRect.bottom - targetRect.top) / 2 - (fontMetrics.bottom - fontMetrics.top) / 2 - fontMetrics.top;
- // canvas.drawText(testString, targetRect.centerX(), baseline, paint);
- }
-
- /**
- * 通过需要的高度, 计算字体大小
- * @param tHeight 需要的字体高度
- * @return
- */
- public static float reckonTextSize(int tHeight){
- // 创建画笔
- Paint paint = new Paint();
- // 默认字体大小
- float textSize = 90.0f;
- // 计算内容高度
- int calcTextHeight = -1;
- // 循环计算
- while (true){
- // 设置画笔大小
- paint.setTextSize(textSize);
- // 获取字体高度
- Paint.FontMetricsInt fontMetrics = paint.getFontMetricsInt();
- // 计算内容高度
- calcTextHeight = (int) Math.ceil((fontMetrics.descent - fontMetrics.ascent));
- // 符合条件则直接返回
- if (calcTextHeight == tHeight){
- return textSize;
- } else if (calcTextHeight > tHeight){ // 如果计算的字体高度大于
- textSize -= 0.5f;
- } else {
- textSize += 0.5f;
- }
- }
- }
-
- /**
- * 计算第几位超过宽度
- * @param textView
- * @param width
- * @return -1 表示没超过
- */
- public static int calcTextWidth(TextView textView, float width){
- if (textView != null){
- return calcTextWidth(textView.getPaint(), textView.getText().toString(), width);
- }
- return -1;
- }
-
- /**
- * 计算第几位超过宽度
- * @param text
- * @param width
- * @return -1 表示没超过
- */
- public static int calcTextWidth(Paint paint, String text, float width){
- // 先获取宽度
- float textWidth = getTextWidth(paint, text);
- // 判断是否超过
- if (textWidth <= width){
- return -1; // 表示没超过
- }
- // 获取数据长度
- int length = text.length();
- // 循环除2
- while (true) {
- // 数据至少为2位以上
- if (length < 2) {
- return 0; // 表示第一位已经超过
- }
- // 从中间取值
- length = length / 2;
- // 计算宽度
- textWidth = getTextWidth(paint, text.substring(0, length));
- // 判断是否小于宽度 - 进行返回长度
- if (textWidth <= width){
- break;
- }
- }
- // 遍历计算
- for (int i = length, len = text.length(); i < len; i++){
- // 获取字体内容宽度
- float tWidth = paint.measureText(text.substring(0, i));
- // 判断是否大于指定宽度
- if (tWidth > width){
- return i - 1; // 返回超过前的长度
- } else if (tWidth == width){
- return i; // 返回超过前的长度
- }
- }
- return -1;
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/UriUtils.java b/DevLibUtils/src/main/java/dev/utils/app/UriUtils.java
deleted file mode 100644
index c3f704c1c1..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/UriUtils.java
+++ /dev/null
@@ -1,70 +0,0 @@
-package dev.utils.app;
-
-import android.net.Uri;
-import android.os.Build;
-import android.support.v4.content.FileProvider;
-
-import java.io.File;
-
-import dev.DevUtils;
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: Uri 工具类
- * Created by Blankj
- * http://blankj.com
- * Update to Ttt
- */
-public final class UriUtils {
-
- private UriUtils() {
- }
-
- // 日志TAG
- private static final String TAG = UriUtils.class.getSimpleName();
-
- /**
-
-
-
- */
-
- /**
- * 返回处理后的Uri, 单独传递名字, 自动添加包名 ${applicationId}
- * @param file
- * @param name
- * @return
- * getUriForFileToName(file, "fileProvider");
- * getUriForFile(file, "包名.fileProvider");
- */
- public static Uri getUriForFileToName(final File file, String name){
- try {
- String authority = DevUtils.getContext().getPackageName() + "." + name;
- return getUriForFile(file, authority);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getUriForFileToName");
- }
- return null;
- }
-
-
- /**
- * Return a content URI for a given file.
- * @param file The file.
- * @return a content URI for a given file
- */
- public static Uri getUriForFile(final File file, final String authority) {
- if (file == null) return null;
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
- return FileProvider.getUriForFile(DevUtils.getContext(), authority, file);
- } else {
- return Uri.fromFile(file);
- }
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/VibrationUtils.java b/DevLibUtils/src/main/java/dev/utils/app/VibrationUtils.java
deleted file mode 100644
index 3e5715e4e7..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/VibrationUtils.java
+++ /dev/null
@@ -1,61 +0,0 @@
-package dev.utils.app;
-
-import android.content.Context;
-import android.os.Vibrator;
-
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: 震动相关工具类
- * Created by Ttt
- */
-public final class VibrationUtils {
-
- private VibrationUtils() {
- }
-
- // 日志TAG
- private static final String TAG = VibrationUtils.class.getSimpleName();
-
- /**
- * 震动
- *
- * @param context 上下文
- * @param milliseconds 振动时长
- */
- public static void vibrate(final Context context, final long milliseconds) {
- try {
- Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
- vibrator.vibrate(milliseconds);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "vibrate");
- }
- }
-
- /**
- * 指定手机以pattern模式振动
- * @param context
- * @param pattern new long[]{400,800,1200,1600},就是指定在 400ms、800ms、1200ms、1600ms 这些时间点交替启动、关闭手机振动器
- * @param repeat 指定pattern数组的索引,指定pattern数组中从repeat索引开始的振动进行循环。-1表示只振动一次,非-1表示从 pattern的指定下标开始重复振动。
- */
- public static void vibrate(final Context context, final long[] pattern, final int repeat) {
- try {
- Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
- vibrator.vibrate(pattern, repeat);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "vibrate");
- }
- }
-
- /**
- * 取消振动
- * @param context 上下文
- */
- public static void cancel(final Context context) {
- try {
- ((Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE)).cancel();
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "cancel");
- }
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/ViewUtils.java b/DevLibUtils/src/main/java/dev/utils/app/ViewUtils.java
deleted file mode 100644
index ec4b9d6e3a..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/ViewUtils.java
+++ /dev/null
@@ -1,640 +0,0 @@
-package dev.utils.app;
-
-import android.app.Activity;
-import android.content.Context;
-import android.content.ContextWrapper;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.ViewParent;
-import android.view.Window;
-import android.widget.AbsListView;
-import android.widget.GridView;
-import android.widget.ImageView;
-import android.widget.ListAdapter;
-import android.widget.ListView;
-
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: View 操作相关工具类
- * Created by Ttt
- */
-public final class ViewUtils {
-
- private ViewUtils() {
- }
-
- // 日志TAG
- private static final String TAG = ViewUtils.class.getSimpleName();
-
- /**
- * 获取上下文
- * @param view
- * @return
- */
- public static Context getContext(View view){
- if (view != null){
- return view.getContext();
- }
- return null;
- }
-
- /**
- * 判断View 是否为null
- * @param view
- * @return
- */
- public static boolean isEmpty(View view){
- return view == null;
- }
-
- /**
- * 判断View 是否为null
- * @param views
- * @return
- */
- public static boolean isEmpty(View... views){
- if (views != null && views.length != 0){
- for (int i = 0, len = views.length; i < len; i++){
- View view = views[i];
- if (view == null){
- return true;
- }
- }
- return false;
- }
- return true;
- }
-
- /**
- * 判断View 是否显示
- * @param view
- * @return
- */
- public static boolean isVisibility(View view){
- return isVisibility(view, true);
- }
-
- /**
- * 判断 View 是否显示
- * @param view
- * @param isDf
- * @return
- */
- public static boolean isVisibility(View view, boolean isDf){
- if (view != null){
- // 判断是否显示
- return (view.getVisibility() == View.VISIBLE);
- }
- // 出现意外返回默认值
- return isDf;
- }
-
- /**
- * 判断 View 是否都显示显示
- * @param views
- * @return
- */
- public static boolean isVisibilitys(View... views){
- if (views != null && views.length != 0){
- for (int i = 0, len = views.length; i < len; i++){
- View view = views[i];
- if (view != null && view.getVisibility() == View.VISIBLE){
- } else {
- return false;
- }
- }
- return true;
- }
- return false;
- }
-
- /**
- * 判断View 是否隐藏占位
- * @param view
- * @return
- */
- public static boolean isVisibilityIN(View view){
- return isVisibilityIN(view, false);
- }
-
- /**
- * 判断View 是否隐藏占位
- * @param view
- * @param isDf
- * @return
- */
- public static boolean isVisibilityIN(View view, boolean isDf){
- if (view != null){
- // 判断是否显示
- return (view.getVisibility() == View.INVISIBLE);
- }
- // 出现意外返回默认值
- return isDf;
- }
-
- /**
- * 判断View 是否隐藏
- * @param view
- * @return
- */
- public static boolean isVisibilityGone(View view){
- return isVisibilityGone(view, false);
- }
-
- /**
- * 判断View 是否隐藏
- * @param view
- * @param isDf
- * @return
- */
- public static boolean isVisibilityGone(View view, boolean isDf){
- if (view != null){
- // 判断是否显示
- return (view.getVisibility() == View.GONE);
- }
- // 出现意外返回默认值
- return isDf;
- }
-
- // ==
-
- /**
- * 获取显示的状态 (View.VISIBLE : View.GONE)
- * @param isVisibility
- * @return
- */
- public static int getVisibility(boolean isVisibility){
- return isVisibility ? View.VISIBLE : View.GONE;
- }
-
- /**
- * 获取显示的状态 (View.VISIBLE : View.INVISIBLE)
- * @param isVisibility
- * @return
- */
- public static int getVisibilityIN(boolean isVisibility){
- return isVisibility ? View.VISIBLE : View.INVISIBLE;
- }
-
- // --
-
- /**
- * 设置View显示状态
- * @param isVisibility
- * @param view
- */
- public static boolean setVisibility(boolean isVisibility, View view){
- if (view != null){
- view.setVisibility(isVisibility ? View.VISIBLE : View.GONE);
- }
- return isVisibility;
- }
-
- /**
- * 设置View显示的状态
- * @param isVisibility
- * @param view
- */
- public static boolean setVisibility(int isVisibility, View view){
- if (view != null){
- view.setVisibility(isVisibility);
- }
- return (isVisibility == View.VISIBLE);
- }
-
- // --
-
- /**
- * 设置View 显示的状态
- * @param isVisibility
- * @param views
- */
- public static boolean setVisibilitys(boolean isVisibility, View... views){
- return setVisibilitys(getVisibility(isVisibility), views);
- }
-
- /**
- * 设置View 显示的状态
- * @param isVisibility
- * @param views
- */
- public static boolean setVisibilitys(int isVisibility, View... views){
- if (views != null && views.length != 0){
- for (int i = 0, len = views.length; i < len; i++){
- View view = views[i];
- if (view != null){
- view.setVisibility(isVisibility);
- }
- }
- }
- return (isVisibility == View.VISIBLE);
- }
-
- /**
- * 切换View 显示的状态
- * @param view
- * @param views
- */
- public static void toggleVisibilitys(View view, View... views){
- if (view != null){
- view.setVisibility(View.VISIBLE);
- }
- setVisibilitys(View.GONE, views);
- }
-
- /**
- * 切换View 显示的状态
- * @param viewArys
- * @param views
- */
- public static void toggleVisibilitys(View[] viewArys, View... views){
- toggleVisibilitys(viewArys, View.GONE, views);
- }
-
- /**
- * 切换View 显示的状态
- * @param viewArys
- * @param status
- * @param views
- */
- public static void toggleVisibilitys(View[] viewArys, int status, View... views){
- // 默认前面显示
- setVisibilitys(View.VISIBLE, viewArys);
- // 更具状态处理
- setVisibilitys(status, views);
- }
-
- // ==
-
- /**
- * 切换View状态
- * @param isChange 是否改变
- * @param isVisibility 是否显示
- * @param view 需要判断的View
- * @return
- */
- public static boolean toogleView(boolean isChange, int isVisibility, View view){
- if (isChange && view != null){
- view.setVisibility(isVisibility);
- }
- return isChange;
- }
-
- // --
-
- /**
- * 设置View 图片资源
- * @param draw
- * @param views
- */
- public static void setViewImageRes(int draw, ImageView... views){
- setViewImageRes(draw, View.VISIBLE, views);
- }
-
- /**
- * 设置View 图片资源
- * @param draw
- * @param isVisibility
- * @param views
- */
- public static void setViewImageRes(int draw, int isVisibility, ImageView... views){
- if (views != null && views.length != 0){
- for (int i = 0, len = views.length; i < len; i++){
- ImageView view = views[i];
- if (view != null){
- try {
- // 设置背景
- view.setImageResource(draw);
- // 是否显示
- view.setVisibility(isVisibility);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "setViewImageRes");
- }
- }
- }
- }
- }
-
- // == 初始化View操作等 ==
-
- /**
- * 初始化View
- * @param view
- * @param id
- * @param
- * @return
- */
- public static T findViewById(View view, int id) {
- return view.findViewById(id);
- }
-
- /**
- * 初始化View
- * @param window
- * @param id
- * @param
- * @return
- */
- public static T findViewById(Window window, int id){
- return window.findViewById(id);
- }
-
- /**
- * 初始化View
- * @param activity
- * @param id
- * @param
- * @return
- */
- public static T findViewById(Activity activity, int id) {
- return activity.findViewById(id);
- }
-
- /**
- * 把自身从父View中移除
- * @param view
- */
- public static void removeSelfFromParent(View view) {
- if (view != null) {
- ViewParent parent = view.getParent();
- if (parent != null && parent instanceof ViewGroup) {
- ViewGroup group = (ViewGroup) parent;
- group.removeView(view);
- }
- }
- }
-
- /**
- * 判断触点是否落在该View上
- * @param ev
- * @param v
- * @return
- */
- public static boolean isTouchInView(MotionEvent ev, View v) {
- int[] vLoc = new int[2];
- v.getLocationOnScreen(vLoc);
- float motionX = ev.getRawX();
- float motionY = ev.getRawY();
- return motionX >= vLoc[0] && motionX <= (vLoc[0] + v.getWidth())
- && motionY >= vLoc[1] && motionY <= (vLoc[1] + v.getHeight());
- }
-
- /**
- * View 改变请求
- * @param view
- * @param isAll
- */
- public static void requestLayoutParent(View view, boolean isAll) {
- ViewParent parent = view.getParent();
- while (parent != null && parent instanceof View) {
- if (!parent.isLayoutRequested()) {
- parent.requestLayout();
- if (!isAll) {
- break;
- }
- }
- parent = parent.getParent();
- }
- }
-
- /**
- * 测量 view
- * @param view
- */
- public static void measureView(View view) {
- ViewGroup.LayoutParams p = view.getLayoutParams();
- if (p == null) {
- p = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
- }
- int childWidthSpec = ViewGroup.getChildMeasureSpec(0, 0, p.width);
- int lpHeight = p.height;
- int childHeightSpec;
- if (lpHeight > 0) {
- childHeightSpec = View.MeasureSpec.makeMeasureSpec(lpHeight, View.MeasureSpec.EXACTLY);
- } else {
- childHeightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
- }
- view.measure(childWidthSpec, childHeightSpec);
- }
-
- /**
- * 获取view的宽度
- * @param view
- * @return
- */
- public static int getViewWidth(View view) {
- measureView(view);
- return view.getMeasuredWidth();
- }
-
- /**
- * 获取view的高度
- * @param view
- * @return
- */
- public static int getViewHeight(View view) {
- measureView(view);
- return view.getMeasuredHeight();
- }
-
- /**
- * 获取view的上下文
- * @param view
- * @return
- */
- public static Activity getActivity(View view) {
- try {
- Context context = view.getContext();
- while (context instanceof ContextWrapper) {
- if (context instanceof Activity) {
- return (Activity) context;
- }
- context = ((ContextWrapper) context).getBaseContext();
- }
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getActivity");
- }
- return null;
- }
-
- // === ListView ===
-
- /**
- * 计算ListView Item 高度
- * @param listView
- */
- public static int calcListViewItemHeight(ListView listView) {
- return calcListViewItemHeight(listView, false);
- }
-
- /**
- * 计算ListView Item 高度
- * @param listView
- * @param isSet 是否 setLayoutParams
- * ==
- * hint: 解决 ScrollView 嵌套 ListView 时, 会无法正确的计算ListView的大小
- */
- public static int calcListViewItemHeight(ListView listView, boolean isSet) {
- // 获取 Adapter
- ListAdapter listAdapter = listView.getAdapter();
- // 防止为null
- if (listAdapter == null) {
- return 0 ;
- }
- // 获取总体高度
- int totalHeight = 0;
- // 遍历累加
- for (int i = 0, len = listAdapter.getCount(); i < len; i++) {
- // 累加 Item 高度
- totalHeight += getItemHeighet(listAdapter, listView, i);
- }
- // ==
- // 获取子项间分隔符占用的高度
- // listView.getDividerHeight();
- // 累加分割线高度
- totalHeight += (listView.getDividerHeight() * (listAdapter.getCount() - 1));
- // 判断是否需要设置高度
- if (isSet){
- ViewGroup.LayoutParams params = listView.getLayoutParams();
- params.height = totalHeight;
- listView.setLayoutParams(params);
- }
- // 返回总体高度
- return totalHeight;
- }
-
- // === GridView ===
-
- /**
- * 计算GridView Item 高度
- * @param gridView
- * @param numColumns
- */
- public static int calcGridViewItemHeight(GridView gridView, int numColumns) {
- return calcGridViewItemHeight(gridView, numColumns, false);
- }
-
- /**
- * 计算GridView Item 高度
- * @param gridView
- * @param numColumns
- * @param isSet 是否 setLayoutParams
- * ==
- * hint: 解决 ScrollView 嵌套 GridView 时, 会无法正确的计算ListView的大小
- */
- public static int calcGridViewItemHeight(GridView gridView, int numColumns, boolean isSet) {
- // 获取 Adapter
- ListAdapter listAdapter = gridView.getAdapter();
- // 防止为null
- if (listAdapter == null) {
- return 0 ;
- }
- // 最高高度
- int singleMax = 0;
- // 获取总体高度
- int totalHeight = 0;
- // 获取总数
- int count = listAdapter.getCount();
- // 判断是否整数
- count = (count % numColumns == 0) ? (count / numColumns) : (count / numColumns + 1);
- // 遍历累加
- for (int i = 0; i < count; i++) {
- // 默认表示第一个的高度
- singleMax = getItemHeighet(listAdapter, gridView, i * numColumns);
- // 遍历判断
- for (int eqI = 1; eqI < numColumns; eqI++){
- // 临时高度
- int tempHeight = 0;
- // 进行判断处理
- if (i * numColumns + eqI <= count){
- // 获取对应的高度
- tempHeight = getItemHeighet(listAdapter, gridView, i * numColumns + eqI);
- }
- // 判断是否在最大高度
- if (tempHeight > singleMax){
- singleMax = tempHeight;
- }
- }
- // 累加 Item 高度
- totalHeight += singleMax;
- }
- // 每列之间的间隔 |
- //int hSpaec = gridView.getHorizontalSpacing();
- // 每行之间的间隔 -
- int vSpace = gridView.getVerticalSpacing();
- // 最后获取整个gridView完整显示需要的高度
- totalHeight += (vSpace * (count - 1));
- // 判断是否需要设置高度
- if (isSet){
- ViewGroup.LayoutParams params = gridView.getLayoutParams();
- params.height = totalHeight;
- gridView.setLayoutParams(params);
- }
- // 返回总体高度
- return totalHeight;
- }
-
- // ==
-
- /**
- * 获取单独一个Item 高度
- * @param absViews
- * @param pos
- * @return
- */
- public static int getItemHeighet(AbsListView absViews, int pos){
- if (absViews != null){
- return getItemHeighet(absViews.getAdapter(), absViews, pos, 0);
- }
- return 0;
- }
-
- /**
- * 获取单独一个Item 高度
- * @param absViews
- * @param pos
- * @param dfHeight
- * @return
- */
- public static int getItemHeighet(AbsListView absViews, int pos, int dfHeight){
- if (absViews != null){
- return getItemHeighet(absViews.getAdapter(), absViews, pos, dfHeight);
- }
- return dfHeight;
- }
-
- /**
- * 获取单独一个Item 高度
- * @param listAdapter
- * @param absViews
- * @param pos
- * @return
- */
- public static int getItemHeighet(ListAdapter listAdapter, AbsListView absViews, int pos){
- return getItemHeighet(listAdapter, absViews, pos, 0);
- }
-
- /**
- * 获取单独一个Item 高度
- * @param listAdapter
- * @param absViews
- * @param pos
- * @param dfHeight
- * @return
- */
- public static int getItemHeighet(ListAdapter listAdapter, AbsListView absViews, int pos, int dfHeight){
- try {
- // listAdapter.getCount()返回数据项的数目
- View listItem = listAdapter.getView(pos, null, absViews);
- // 计算子项View 的宽高
- listItem.measure(0, 0);
- // 统计所有子项的总高度
- return listItem.getMeasuredHeight();
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "getItemHeighet");
- return dfHeight;
- }
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/anim/AnimationUtils.java b/DevLibUtils/src/main/java/dev/utils/app/anim/AnimationUtils.java
deleted file mode 100644
index 7bd4beb5be..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/anim/AnimationUtils.java
+++ /dev/null
@@ -1,263 +0,0 @@
-package dev.utils.app.anim;
-
-import android.view.animation.AlphaAnimation;
-import android.view.animation.Animation;
-import android.view.animation.Animation.AnimationListener;
-import android.view.animation.RotateAnimation;
-import android.view.animation.ScaleAnimation;
-
-/**
- * detail: 动画工具类
- * Created by Ttt
- */
-public final class AnimationUtils {
-
- private AnimationUtils() {
- }
-
- /**
- * 默认动画持续时间
- */
- public static final long DEFAULT_ANIMATION_DURATION = 400;
-
- /**
- * 获取一个旋转动画
- * @param fromDegrees 开始角度
- * @param toDegrees 结束角度
- * @param pivotXType 旋转中心点X轴坐标相对类型
- * @param pivotXValue 旋转中心点X轴坐标
- * @param pivotYType 旋转中心点Y轴坐标相对类型
- * @param pivotYValue 旋转中心点Y轴坐标
- * @param durationMillis 持续时间
- * @param animationListener 动画监听器
- * @return 一个旋转动画
- */
- public static RotateAnimation getRotateAnimation(float fromDegrees, float toDegrees, int pivotXType, float pivotXValue, int pivotYType, float pivotYValue, long durationMillis, AnimationListener animationListener) {
- RotateAnimation rotateAnimation = new RotateAnimation(fromDegrees, toDegrees, pivotXType, pivotXValue, pivotYType, pivotYValue);
- rotateAnimation.setDuration(durationMillis);
- if (animationListener != null) {
- rotateAnimation.setAnimationListener(animationListener);
- }
- return rotateAnimation;
- }
-
- /**
- * 获取一个根据视图自身中心点旋转的动画
- * @param durationMillis 动画持续时间
- * @param animationListener 动画监听器
- * @return 一个根据中心点旋转的动画
- */
- public static RotateAnimation getRotateAnimationByCenter(long durationMillis, AnimationListener animationListener) {
- return getRotateAnimation(0f, 359f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f, durationMillis, animationListener);
- }
-
- /**
- * 获取一个根据中心点旋转的动画
- * @param duration 动画持续时间
- * @return 一个根据中心点旋转的动画
- */
- public static RotateAnimation getRotateAnimationByCenter(long duration) {
- return getRotateAnimationByCenter(duration, null);
- }
-
- /**
- * 获取一个根据视图自身中心点旋转的动画
- * @param animationListener 动画监听器
- * @return 一个根据中心点旋转的动画
- */
- public static RotateAnimation getRotateAnimationByCenter(AnimationListener animationListener) {
- return getRotateAnimationByCenter(DEFAULT_ANIMATION_DURATION, animationListener);
- }
-
- /**
- * 获取一个根据中心点旋转的动画
- * @return 一个根据中心点旋转的动画,默认持续时间为DEFAULT_ANIMATION_DURATION
- */
- public static RotateAnimation getRotateAnimationByCenter() {
- return getRotateAnimationByCenter(DEFAULT_ANIMATION_DURATION, null);
- }
-
- /**
- * 获取一个透明度渐变动画
- * @param fromAlpha 开始时的透明度
- * @param toAlpha 结束时的透明度都
- * @param durationMillis 持续时间
- * @param animationListener 动画监听器
- * @return 一个透明度渐变动画
- */
- public static AlphaAnimation getAlphaAnimation(float fromAlpha, float toAlpha, long durationMillis, AnimationListener animationListener) {
- AlphaAnimation alphaAnimation = new AlphaAnimation(fromAlpha, toAlpha);
- alphaAnimation.setDuration(durationMillis);
- if (animationListener != null) {
- alphaAnimation.setAnimationListener(animationListener);
- }
- return alphaAnimation;
- }
-
- /**
- * 获取一个透明度渐变动画
- * @param fromAlpha 开始时的透明度
- * @param toAlpha 结束时的透明度都
- * @param durationMillis 持续时间
- * @return 一个透明度渐变动画
- */
- public static AlphaAnimation getAlphaAnimation(float fromAlpha, float toAlpha, long durationMillis) {
- return getAlphaAnimation(fromAlpha, toAlpha, durationMillis, null);
- }
-
- /**
- * 获取一个透明度渐变动画
- * @param fromAlpha 开始时的透明度
- * @param toAlpha 结束时的透明度都
- * @param animationListener 动画监听器
- * @return 一个透明度渐变动画,默认持续时间为DEFAULT_ANIMATION_DURATION
- */
- public static AlphaAnimation getAlphaAnimation(float fromAlpha, float toAlpha, AnimationListener animationListener) {
- return getAlphaAnimation(fromAlpha, toAlpha, DEFAULT_ANIMATION_DURATION, animationListener);
- }
-
- /**
- * 获取一个透明度渐变动画
- * @param fromAlpha 开始时的透明度
- * @param toAlpha 结束时的透明度都
- * @return 一个透明度渐变动画,默认持续时间为DEFAULT_ANIMATION_DURATION
- */
- public static AlphaAnimation getAlphaAnimation(float fromAlpha, float toAlpha) {
- return getAlphaAnimation(fromAlpha, toAlpha, DEFAULT_ANIMATION_DURATION, null);
- }
-
- /**
- * 获取一个由完全显示变为不可见的透明度渐变动画
- * @param durationMillis 持续时间
- * @param animationListener 动画监听器
- * @return 一个由完全显示变为不可见的透明度渐变动画
- */
- public static AlphaAnimation getHiddenAlphaAnimation(long durationMillis, AnimationListener animationListener) {
- return getAlphaAnimation(1.0f, 0.0f, durationMillis, animationListener);
- }
-
- /**
- * 获取一个由完全显示变为不可见的透明度渐变动画
- * @param durationMillis 持续时间
- * @return 一个由完全显示变为不可见的透明度渐变动画
- */
- public static AlphaAnimation getHiddenAlphaAnimation(long durationMillis) {
- return getHiddenAlphaAnimation(durationMillis, null);
- }
-
- /**
- * 获取一个由完全显示变为不可见的透明度渐变动画
- * @param animationListener 动画监听器
- * @return 一个由完全显示变为不可见的透明度渐变动画,默认持续时间为DEFAULT_ANIMATION_DURATION
- */
- public static AlphaAnimation getHiddenAlphaAnimation(AnimationListener animationListener) {
- return getHiddenAlphaAnimation(DEFAULT_ANIMATION_DURATION, animationListener);
- }
-
- /**
- * 获取一个由完全显示变为不可见的透明度渐变动画
- * @return 一个由完全显示变为不可见的透明度渐变动画,默认持续时间为DEFAULT_ANIMATION_DURATION
- */
- public static AlphaAnimation getHiddenAlphaAnimation() {
- return getHiddenAlphaAnimation(DEFAULT_ANIMATION_DURATION, null);
- }
-
- /**
- * 获取一个由不可见变为完全显示的透明度渐变动画
- * @param durationMillis 持续时间
- * @param animationListener 动画监听器
- * @return 一个由不可见变为完全显示的透明度渐变动画
- */
- public static AlphaAnimation getShowAlphaAnimation(long durationMillis, AnimationListener animationListener) {
- return getAlphaAnimation(0.0f, 1.0f, durationMillis, animationListener);
- }
-
- /**
- * 获取一个由不可见变为完全显示的透明度渐变动画
- * @param durationMillis 持续时间
- * @return 一个由不可见变为完全显示的透明度渐变动画
- */
- public static AlphaAnimation getShowAlphaAnimation(long durationMillis) {
- return getAlphaAnimation(0.0f, 1.0f, durationMillis, null);
- }
-
- /**
- * 获取一个由不可见变为完全显示的透明度渐变动画
- * @param animationListener 动画监听器
- * @return 一个由不可见变为完全显示的透明度渐变动画,默认持续时间为DEFAULT_ANIMATION_DURATION
- */
- public static AlphaAnimation getShowAlphaAnimation(AnimationListener animationListener) {
- return getAlphaAnimation(0.0f, 1.0f, DEFAULT_ANIMATION_DURATION, animationListener);
- }
-
- /**
- * 获取一个由不可见变为完全显示的透明度渐变动画
- * @return 一个由不可见变为完全显示的透明度渐变动画,默认持续时间为DEFAULT_ANIMATION_DURATION
- */
- public static AlphaAnimation getShowAlphaAnimation() {
- return getAlphaAnimation(0.0f, 1.0f, DEFAULT_ANIMATION_DURATION, null);
- }
-
- /**
- * 获取一个缩小动画
- * @param durationMillis
- * @param animationListener
- * @return
- */
- public static ScaleAnimation getLessenScaleAnimation(long durationMillis, AnimationListener animationListener) {
- ScaleAnimation scaleAnimation = new ScaleAnimation(1.0f, 0.0f, 1.0f, 0.0f, ScaleAnimation.RELATIVE_TO_SELF, ScaleAnimation.RELATIVE_TO_SELF);
- scaleAnimation.setDuration(durationMillis);
- scaleAnimation.setAnimationListener(animationListener);
- return scaleAnimation;
- }
-
- /**
- * 获取一个缩小动画
- * @param durationMillis
- * @return
- */
- public static ScaleAnimation getLessenScaleAnimation(long durationMillis) {
- return getLessenScaleAnimation(durationMillis, null);
- }
-
- /**
- * 获取一个缩小动画
- * @param animationListener
- * @return
- */
- public static ScaleAnimation getLessenScaleAnimation(AnimationListener animationListener) {
- return getLessenScaleAnimation(DEFAULT_ANIMATION_DURATION, animationListener);
- }
-
- /**
- * 获取一个放大动画
- * @param durationMillis
- * @param animationListener
- * @return
- */
- public static ScaleAnimation getAmplificationAnimation(long durationMillis, AnimationListener animationListener) {
- ScaleAnimation scaleAnimation = new ScaleAnimation(0.0f, 1.0f, 0.0f, 1.0f, ScaleAnimation.RELATIVE_TO_SELF, ScaleAnimation.RELATIVE_TO_SELF);
- scaleAnimation.setDuration(durationMillis);
- scaleAnimation.setAnimationListener(animationListener);
- return scaleAnimation;
- }
-
- /**
- * 获取一个放大动画
- * @param durationMillis
- * @return
- */
- public static ScaleAnimation getAmplificationAnimation(long durationMillis) {
- return getAmplificationAnimation(durationMillis, null);
- }
-
- /**
- * 获取一个放大动画
- * @param animationListener
- * @return
- */
- public static ScaleAnimation getAmplificationAnimation(AnimationListener animationListener) {
- return getAmplificationAnimation(DEFAULT_ANIMATION_DURATION, animationListener);
- }
-
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/anim/ToolAnimation.java b/DevLibUtils/src/main/java/dev/utils/app/anim/ToolAnimation.java
deleted file mode 100644
index 66890943b1..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/anim/ToolAnimation.java
+++ /dev/null
@@ -1,129 +0,0 @@
-package dev.utils.app.anim;
-
-import android.graphics.ColorMatrixColorFilter;
-import android.view.MotionEvent;
-import android.view.View;
-import android.view.View.OnTouchListener;
-import android.widget.ImageView;
-
-/**
- * detail: 控件点击效果动画工具类
- * @Description:主要功能:控件点击效果动画工具类
- * @Prject: CommonUtilLibrary
- * @Package: com.jingewenku.abrahamcaijin.commonutil
- * @author: AbrahamCaiJin
- * @date: 2017年05月15日 11:42
- * @Copyright: 个人版权所有
- * @Company:
- * @version: 1.0.0
- */
-
-public class ToolAnimation {
- /**
- * 给视图添加点击效果,让背景变深
- * */
- public static void addTouchDrak(View view, boolean isClick) {
- view.setOnTouchListener(VIEW_TOUCH_DARK);
-
- if (!isClick) {
- view.setOnClickListener(new View.OnClickListener() {
-
- @Override
- public void onClick(View v) {
- }
- });
- }
- }
-
- /**
- * 给视图添加点击效果,让背景变暗
- * */
- public static void addTouchLight(View view, boolean isClick) {
- view.setOnTouchListener(VIEW_TOUCH_LIGHT);
-
- if (!isClick) {
- view.setOnClickListener(new View.OnClickListener() {
-
- @Override
- public void onClick(View v) {
- }
- });
- }
- }
-
- /**
- * 让控件点击时,颜色变深
- * */
- public static final OnTouchListener VIEW_TOUCH_DARK = new OnTouchListener() {
-
- public final float[] BT_SELECTED = new float[] { 1, 0, 0, 0, -50, 0, 1,
- 0, 0, -50, 0, 0, 1, 0, -50, 0, 0, 0, 1, 0 };
- public final float[] BT_NOT_SELECTED = new float[] { 1, 0, 0, 0, 0, 0,
- 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0 };
-
- @SuppressWarnings("deprecation")
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- if (event.getAction() == MotionEvent.ACTION_DOWN) {
- if (v instanceof ImageView) {
- ImageView iv = (ImageView) v;
- iv.setColorFilter(new ColorMatrixColorFilter(BT_SELECTED));
- } else {
- v.getBackground().setColorFilter(
- new ColorMatrixColorFilter(BT_SELECTED));
- v.setBackgroundDrawable(v.getBackground());
- }
- } else if (event.getAction() == MotionEvent.ACTION_UP) {
- if (v instanceof ImageView) {
- ImageView iv = (ImageView) v;
- iv.setColorFilter(new ColorMatrixColorFilter(
- BT_NOT_SELECTED));
- } else {
- v.getBackground().setColorFilter(
- new ColorMatrixColorFilter(BT_NOT_SELECTED));
- v.setBackgroundDrawable(v.getBackground());
- }
- }
- return false;
- }
- };
-
- /**
- * 让控件点击时,颜色变暗
- * */
- public static final OnTouchListener VIEW_TOUCH_LIGHT = new OnTouchListener() {
-
- public final float[] BT_SELECTED = new float[] { 1, 0, 0, 0, 50, 0, 1,
- 0, 0, 50, 0, 0, 1, 0, 50, 0, 0, 0, 1, 0 };
- public final float[] BT_NOT_SELECTED = new float[] { 1, 0, 0, 0, 0, 0,
- 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0 };
-
- @SuppressWarnings("deprecation")
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- if (event.getAction() == MotionEvent.ACTION_DOWN) {
- if (v instanceof ImageView) {
- ImageView iv = (ImageView) v;
- iv.setDrawingCacheEnabled(true);
-
- iv.setColorFilter(new ColorMatrixColorFilter(BT_SELECTED));
- } else {
- v.getBackground().setColorFilter(
- new ColorMatrixColorFilter(BT_SELECTED));
- v.setBackgroundDrawable(v.getBackground());
- }
- } else if (event.getAction() == MotionEvent.ACTION_UP) {
- if (v instanceof ImageView) {
- ImageView iv = (ImageView) v;
- iv.setColorFilter(new ColorMatrixColorFilter(
- BT_NOT_SELECTED));
- } else {
- v.getBackground().setColorFilter(
- new ColorMatrixColorFilter(BT_NOT_SELECTED));
- v.setBackgroundDrawable(v.getBackground());
- }
- }
- return false;
- }
- };
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/anim/ViewAnimationUtils.java b/DevLibUtils/src/main/java/dev/utils/app/anim/ViewAnimationUtils.java
deleted file mode 100644
index cbfaf649a1..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/anim/ViewAnimationUtils.java
+++ /dev/null
@@ -1,519 +0,0 @@
-package dev.utils.app.anim;
-
-import android.view.View;
-import android.view.animation.AlphaAnimation;
-import android.view.animation.Animation;
-import android.view.animation.Animation.AnimationListener;
-import android.view.animation.CycleInterpolator;
-import android.view.animation.TranslateAnimation;
-
-/**
- * detail: 视图动画工具箱,提供简单的控制视图的动画的工具方法
- * Created by Ttt
- */
-public final class ViewAnimationUtils {
-
- private ViewAnimationUtils() {
- }
-
- // ==================
- // 视图透明度渐变动画
- // ==================
-
- /**
- * 将给定视图渐渐隐去(view.setVisibility(View.INVISIBLE))
- * @param view 被处理的视图
- * @param isBanClick 在执行动画的过程中是否禁止点击
- * @param durationMillis 持续时间,毫秒
- * @param animationListener 动画监听器
- */
- public static void invisibleViewByAlpha(final View view, long durationMillis, final boolean isBanClick, final AnimationListener animationListener) {
- if (view.getVisibility() != View.INVISIBLE) {
- view.setVisibility(View.INVISIBLE);
- AlphaAnimation hiddenAlphaAnimation = AnimationUtils.getHiddenAlphaAnimation(durationMillis);
- hiddenAlphaAnimation.setAnimationListener(new AnimationListener() {
- @Override
- public void onAnimationStart(Animation animation) {
- if (isBanClick) {
- view.setClickable(false);
- }
- if (animationListener != null) {
- animationListener.onAnimationStart(animation);
- }
- }
-
- @Override
- public void onAnimationRepeat(Animation animation) {
- if (animationListener != null) {
- animationListener.onAnimationRepeat(animation);
- }
- }
-
- @Override
- public void onAnimationEnd(Animation animation) {
- if (isBanClick) {
- view.setClickable(true);
- }
- if (animationListener != null) {
- animationListener.onAnimationEnd(animation);
- }
- }
- });
- view.startAnimation(hiddenAlphaAnimation);
- }
- }
-
- /**
- * 将给定视图渐渐隐去(view.setVisibility(View.INVISIBLE))
- * @param view 被处理的视图
- * @param durationMillis 持续时间,毫秒
- * @param animationListener 动画监听器
- */
- public static void invisibleViewByAlpha(final View view, long durationMillis, final AnimationListener animationListener) {
- invisibleViewByAlpha(view, durationMillis, false, animationListener);
- }
-
- /**
- * 将给定视图渐渐隐去(view.setVisibility(View.INVISIBLE))
- * @param view 被处理的视图
- * @param durationMillis 持续时间,毫秒
- * @param isBanClick 在执行动画的过程中是否禁止点击
- */
- public static void invisibleViewByAlpha(final View view, long durationMillis, boolean isBanClick) {
- invisibleViewByAlpha(view, durationMillis, isBanClick, null);
- }
-
- /**
- * 将给定视图渐渐隐去(view.setVisibility(View.INVISIBLE))
- * @param view 被处理的视图
- * @param durationMillis 持续时间,毫秒
- */
- public static void invisibleViewByAlpha(final View view, long durationMillis) {
- invisibleViewByAlpha(view, durationMillis, false, null);
- }
-
- /**
- * 将给定视图渐渐隐去(view.setVisibility(View.INVISIBLE)),
- * 默认的持续时间为DEFAULT_ALPHA_ANIMATION_DURATION
- * @param view 被处理的视图
- * @param isBanClick 在执行动画的过程中是否禁止点击
- * @param animationListener 动画监听器
- */
- public static void invisibleViewByAlpha(final View view, boolean isBanClick, final AnimationListener animationListener) {
- invisibleViewByAlpha(view, AnimationUtils.DEFAULT_ANIMATION_DURATION, isBanClick, animationListener);
- }
-
- /**
- * 将给定视图渐渐隐去(view.setVisibility(View.INVISIBLE)),
- * 默认的持续时间为DEFAULT_ALPHA_ANIMATION_DURATION
- * @param view 被处理的视图
- * @param animationListener 动画监听器
- */
- public static void invisibleViewByAlpha(final View view, final AnimationListener animationListener) {
- invisibleViewByAlpha(view, AnimationUtils.DEFAULT_ANIMATION_DURATION,false, animationListener);
- }
-
- /**
- * 将给定视图渐渐隐去(view.setVisibility(View.INVISIBLE)),
- * 默认的持续时间为DEFAULT_ALPHA_ANIMATION_DURATION
- * @param view 被处理的视图
- * @param isBanClick 在执行动画的过程中是否禁止点击
- */
- public static void invisibleViewByAlpha(final View view, boolean isBanClick) {
- invisibleViewByAlpha(view, AnimationUtils.DEFAULT_ANIMATION_DURATION, isBanClick, null);
- }
-
- /**
- * 将给定视图渐渐隐去(view.setVisibility(View.INVISIBLE)),
- * 默认的持续时间为DEFAULT_ALPHA_ANIMATION_DURATION
- * @param view 被处理的视图
- */
- public static void invisibleViewByAlpha(final View view) {
- invisibleViewByAlpha(view, AnimationUtils.DEFAULT_ANIMATION_DURATION,false, null);
- }
-
- /**
- * 将给定视图渐渐隐去最后从界面中移除(view.setVisibility(View.GONE))
- * @param view 被处理的视图
- * @param durationMillis 持续时间,毫秒
- * @param isBanClick 在执行动画的过程中是否禁止点击
- * @param animationListener 动画监听器
- */
- public static void goneViewByAlpha(final View view, long durationMillis, final boolean isBanClick, final AnimationListener animationListener) {
- if (view.getVisibility() != View.GONE) {
- view.setVisibility(View.GONE);
- AlphaAnimation hiddenAlphaAnimation = AnimationUtils.getHiddenAlphaAnimation(durationMillis);
- hiddenAlphaAnimation.setAnimationListener(new AnimationListener() {
- @Override
- public void onAnimationStart(Animation animation) {
- if (isBanClick) {
- view.setClickable(false);
- }
- if (animationListener != null) {
- animationListener.onAnimationStart(animation);
- }
- }
-
- @Override
- public void onAnimationRepeat(Animation animation) {
- if (animationListener != null) {
- animationListener.onAnimationRepeat(animation);
- }
- }
-
- @Override
- public void onAnimationEnd(Animation animation) {
- if (isBanClick) {
- view.setClickable(true);
- }
- if (animationListener != null) {
- animationListener.onAnimationEnd(animation);
- }
- }
- });
- view.startAnimation(hiddenAlphaAnimation);
- }
- }
-
- /**
- * 将给定视图渐渐隐去最后从界面中移除(view.setVisibility(View.GONE))
- * @param view 被处理的视图
- * @param durationMillis 持续时间,毫秒
- * @param animationListener 动画监听器
- */
- public static void goneViewByAlpha(final View view, long durationMillis, final AnimationListener animationListener) {
- goneViewByAlpha(view, durationMillis, false, animationListener);
- }
-
- /**
- * 将给定视图渐渐隐去最后从界面中移除(view.setVisibility(View.GONE))
- * @param view 被处理的视图
- * @param durationMillis 持续时间,毫秒
- * @param isBanClick 在执行动画的过程中是否禁止点击
- */
- public static void goneViewByAlpha(final View view, long durationMillis, final boolean isBanClick) {
- goneViewByAlpha(view, durationMillis, isBanClick, null);
- }
-
- /**
- * 将给定视图渐渐隐去最后从界面中移除(view.setVisibility(View.GONE))
- * @param view 被处理的视图
- * @param durationMillis 持续时间,毫秒
- */
- public static void goneViewByAlpha(final View view, long durationMillis) {
- goneViewByAlpha(view, durationMillis, false, null);
- }
-
- /**
- * 将给定视图渐渐隐去最后从界面中移除(view.setVisibility(View.GONE)),
- * 默认的持续时间为DEFAULT_ALPHA_ANIMATION_DURATION
- * @param view 被处理的视图
- * @param isBanClick 在执行动画的过程中是否禁止点击
- * @param animationListener 动画监听器
- */
- public static void goneViewByAlpha(final View view, final boolean isBanClick, final AnimationListener animationListener) {
- goneViewByAlpha(view, AnimationUtils.DEFAULT_ANIMATION_DURATION, isBanClick, animationListener);
- }
-
- /**
- * 将给定视图渐渐隐去最后从界面中移除(view.setVisibility(View.GONE)),
- * 默认的持续时间为DEFAULT_ALPHA_ANIMATION_DURATION
- * @param view 被处理的视图
- * @param animationListener 动画监听器
- */
- public static void goneViewByAlpha(final View view, final AnimationListener animationListener) {
- goneViewByAlpha(view, AnimationUtils.DEFAULT_ANIMATION_DURATION, false, animationListener);
- }
-
- /**
- * 将给定视图渐渐隐去最后从界面中移除(view.setVisibility(View.GONE)),
- * 默认的持续时间为DEFAULT_ALPHA_ANIMATION_DURATION
- * @param view 被处理的视图
- * @param isBanClick 在执行动画的过程中是否禁止点击
- */
- public static void goneViewByAlpha(final View view, final boolean isBanClick) {
- goneViewByAlpha(view, AnimationUtils.DEFAULT_ANIMATION_DURATION, isBanClick, null);
- }
-
- /**
- * 将给定视图渐渐隐去最后从界面中移除(view.setVisibility(View.GONE)),
- * 默认的持续时间为DEFAULT_ALPHA_ANIMATION_DURATION
- * @param view 被处理的视图
- */
- public static void goneViewByAlpha(final View view) {
- goneViewByAlpha(view, AnimationUtils.DEFAULT_ANIMATION_DURATION, false,null);
- }
-
- /**
- * 将给定视图渐渐显示出来(view.setVisibility(View.VISIBLE))
- * @param view 被处理的视图
- * @param durationMillis 持续时间,毫秒
- * @param isBanClick 在执行动画的过程中是否禁止点击
- * @param animationListener 动画监听器
- */
- public static void visibleViewByAlpha(final View view, long durationMillis, final boolean isBanClick, final AnimationListener animationListener) {
- if (view.getVisibility() != View.VISIBLE) {
- view.setVisibility(View.VISIBLE);
- AlphaAnimation showAlphaAnimation = AnimationUtils.getShowAlphaAnimation(durationMillis);
- showAlphaAnimation.setAnimationListener(new AnimationListener() {
- @Override
- public void onAnimationStart(Animation animation) {
- if (isBanClick) {
- view.setClickable(false);
- }
- if (animationListener != null) {
- animationListener.onAnimationStart(animation);
- }
- }
-
- @Override
- public void onAnimationRepeat(Animation animation) {
- if (animationListener != null) {
- animationListener.onAnimationRepeat(animation);
- }
- }
-
- @Override
- public void onAnimationEnd(Animation animation) {
- if (isBanClick) {
- view.setClickable(true);
- }
- if (animationListener != null) {
- animationListener.onAnimationEnd(animation);
- }
- }
- });
- view.startAnimation(showAlphaAnimation);
- }
- }
-
- /**
- * 将给定视图渐渐显示出来(view.setVisibility(View.VISIBLE))
- * @param view 被处理的视图
- * @param durationMillis 持续时间,毫秒
- * @param animationListener 动画监听器
- */
- public static void visibleViewByAlpha(final View view, long durationMillis, final AnimationListener animationListener) {
- visibleViewByAlpha(view, durationMillis, false, animationListener);
- }
-
- /**
- * 将给定视图渐渐显示出来(view.setVisibility(View.VISIBLE))
- * @param view 被处理的视图
- * @param durationMillis 持续时间,毫秒
- * @param isBanClick 在执行动画的过程中是否禁止点击
- */
- public static void visibleViewByAlpha(final View view, long durationMillis, final boolean isBanClick) {
- visibleViewByAlpha(view, durationMillis, isBanClick, null);
- }
-
- /**
- * 将给定视图渐渐显示出来(view.setVisibility(View.VISIBLE))
- * @param view 被处理的视图
- * @param durationMillis 持续时间,毫秒
- */
- public static void visibleViewByAlpha(final View view, long durationMillis) {
- visibleViewByAlpha(view, durationMillis, false, null);
- }
-
- /**
- * 将给定视图渐渐显示出来(view.setVisibility(View.VISIBLE)),
- * 默认的持续时间为DEFAULT_ALPHA_ANIMATION_DURATION
- * @param view 被处理的视图
- * @param animationListener 动画监听器
- * @param isBanClick 在执行动画的过程中是否禁止点击
- */
- public static void visibleViewByAlpha(final View view, final boolean isBanClick, final AnimationListener animationListener) {
- visibleViewByAlpha(view, AnimationUtils.DEFAULT_ANIMATION_DURATION, isBanClick, animationListener);
- }
-
- /**
- * 将给定视图渐渐显示出来(view.setVisibility(View.VISIBLE)),
- * 默认的持续时间为DEFAULT_ALPHA_ANIMATION_DURATION
- * @param view 被处理的视图
- * @param animationListener 动画监听器
- */
- public static void visibleViewByAlpha(final View view, final AnimationListener animationListener) {
- visibleViewByAlpha(view, AnimationUtils.DEFAULT_ANIMATION_DURATION,false, animationListener);
- }
-
- /**
- * 将给定视图渐渐显示出来(view.setVisibility(View.VISIBLE)),
- * 默认的持续时间为DEFAULT_ALPHA_ANIMATION_DURATION
- * @param view 被处理的视图
- * @param isBanClick 在执行动画的过程中是否禁止点击
- */
- public static void visibleViewByAlpha(final View view, final boolean isBanClick) {
- visibleViewByAlpha(view, AnimationUtils.DEFAULT_ANIMATION_DURATION, isBanClick, null);
- }
-
- /**
- * 将给定视图渐渐显示出来(view.setVisibility(View.VISIBLE)),
- * 默认的持续时间为DEFAULT_ALPHA_ANIMATION_DURATION
- * @param view 被处理的视图
- */
- public static void visibleViewByAlpha(final View view) {
- visibleViewByAlpha(view, AnimationUtils.DEFAULT_ANIMATION_DURATION,false, null);
- }
-
- // ============
- // 视图移动动画
- // ============
-
- /**
- * 视图移动
- * @param view 要移动的视图
- * @param fromXDelta X轴开始坐标
- * @param toXDelta X轴结束坐标
- * @param fromYDelta Y轴开始坐标
- * @param toYDelta Y轴结束坐标
- * @param cycles 重复
- * @param durationMillis 持续时间
- * @param isBanClick 在执行动画的过程中是否禁止点击
- */
- public static void translate(final View view, float fromXDelta, float toXDelta, float fromYDelta, float toYDelta, float cycles, long durationMillis, final boolean isBanClick) {
- TranslateAnimation translateAnimation = new TranslateAnimation(fromXDelta, toXDelta, fromYDelta, toYDelta);
- translateAnimation.setDuration(durationMillis);
- if (cycles > 0.0) {
- translateAnimation.setInterpolator(new CycleInterpolator(cycles));
- }
- translateAnimation.setAnimationListener(new AnimationListener() {
- @Override
- public void onAnimationStart(Animation animation) {
- if (isBanClick) {
- view.setClickable(false);
- }
- }
-
- @Override
- public void onAnimationRepeat(Animation animation) {
-
- }
-
- @Override
- public void onAnimationEnd(Animation animation) {
- if (isBanClick) {
- view.setClickable(true);
- }
- }
- });
- view.startAnimation(translateAnimation);
- }
-
- /**
- * 视图移动
- * @param view 要移动的视图
- * @param fromXDelta X轴开始坐标
- * @param toXDelta X轴结束坐标
- * @param fromYDelta Y轴开始坐标
- * @param toYDelta Y轴结束坐标
- * @param cycles 重复
- * @param durationMillis 持续时间
- */
- public static void translate(final View view, float fromXDelta, float toXDelta, float fromYDelta, float toYDelta, float cycles, long durationMillis) {
- translate(view, fromXDelta, toXDelta, fromYDelta, toYDelta, cycles, durationMillis, false);
- }
-
- /**
- * 视图摇晃
- * @param view 要摇动的视图
- * @param fromXDelta X轴开始坐标
- * @param toXDelta X轴结束坐标
- * @param cycles 重复次数
- * @param durationMillis 持续时间
- * @param isBanClick 在执行动画的过程中是否禁止点击
- */
- public static void shake(View view, float fromXDelta, float toXDelta, float cycles, long durationMillis, final boolean isBanClick) {
- translate(view, fromXDelta, toXDelta, 0.0f, 0.0f, cycles, durationMillis, isBanClick);
- }
-
- /**
- * 视图摇晃
- * @param view 要摇动的视图
- * @param fromXDelta X轴开始坐标
- * @param toXDelta X轴结束坐标
- * @param cycles 重复次数
- * @param durationMillis 持续时间
- */
- public static void shake(View view, float fromXDelta, float toXDelta, float cycles, long durationMillis) {
- translate(view, fromXDelta, toXDelta, 0.0f, 0.0f, cycles, durationMillis, false);
- }
-
- /**
- * 视图摇晃,默认摇晃幅度为10,重复7次
- * @param view
- * @param cycles 重复次数
- * @param durationMillis 持续时间
- * @param isBanClick 在执行动画的过程中是否禁止点击
- */
- public static void shake(View view, float cycles, long durationMillis, final boolean isBanClick) {
- translate(view, 0.0f, 10.0f, 0.0f, 0.0f, cycles, durationMillis, isBanClick);
- }
-
- /**
- * 视图摇晃,默认摇晃幅度为10,持续700毫秒
- * @param view
- * @param cycles 重复次数
- * @param isBanClick 在执行动画的过程中是否禁止点击
- */
- public static void shake(View view, float cycles, final boolean isBanClick) {
- translate(view, 0.0f, 10.0f, 0.0f, 0.0f, cycles, 700, isBanClick);
- }
-
- /**
- * 视图摇晃,默认摇晃幅度为10
- * @param view
- * @param cycles 重复次数
- * @param durationMillis 持续时间
- */
- public static void shake(View view, float cycles, long durationMillis) {
- translate(view, 0.0f, 10.0f, 0.0f, 0.0f, cycles, durationMillis, false);
- }
-
- /**
- * 视图摇晃,默认摇晃幅度为10,重复7次
- * @param view
- * @param durationMillis 持续时间
- * @param isBanClick 在执行动画的过程中是否禁止点击
- */
- public static void shake(View view, long durationMillis, final boolean isBanClick) {
- translate(view, 0.0f, 10.0f, 0.0f, 0.0f, 7, durationMillis, isBanClick);
- }
-
- /**
- * 视图摇晃,默认摇晃幅度为10,持续700毫秒
- * @param view 要摇动的视图
- * @param cycles 重复次数
- */
- public static void shake(View view, float cycles) {
- translate(view, 0.0f, 10.0f, 0.0f, 0.0f, cycles, 700, false);
- }
-
- /**
- * 视图摇晃,默认摇晃幅度为10,重复7次
- * @param view
- * @param durationMillis 持续时间
- */
- public static void shake(View view, long durationMillis) {
- translate(view, 0.0f, 10.0f, 0.0f, 0.0f, 7, durationMillis, false);
- }
-
- /**
- * 视图摇晃,默认摇晃幅度为10,重复7次,持续700毫秒
- * @param view
- * @param isBanClick 在执行动画的过程中是否禁止点击
- */
- public static void shake(View view, final boolean isBanClick) {
- translate(view, 0.0f, 10.0f, 0.0f, 0.0f, 7, 700, isBanClick);
- }
-
- /**
- * 视图摇晃,默认摇晃幅度为10,重复7次,持续700毫秒
- * @param view
- */
- public static void shake(View view) {
- translate(view, 0.0f, 10.0f, 0.0f, 0.0f, 7, 700, false);
- }
-
-}
-
diff --git a/DevLibUtils/src/main/java/dev/utils/app/assist/AsyncExecutor.java b/DevLibUtils/src/main/java/dev/utils/app/assist/AsyncExecutor.java
deleted file mode 100644
index 1dca496507..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/assist/AsyncExecutor.java
+++ /dev/null
@@ -1,129 +0,0 @@
-package dev.utils.app.assist;
-
-import android.os.Handler;
-import android.os.Looper;
-
-import java.util.concurrent.Callable;
-import java.util.concurrent.CancellationException;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.FutureTask;
-
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: 异步执行
- * @author MaTianyu
- */
-public class AsyncExecutor {
-
- // 日志TAG
- private final String TAG = AsyncExecutor.class.getSimpleName();
- // 线程池
- private static ExecutorService threadPool;
- // 主线程 Hander
- public static Handler handler = new Handler(Looper.getMainLooper());
-
- public AsyncExecutor() {
- this(null);
- }
-
- public AsyncExecutor(ExecutorService threadPool) {
- if (AsyncExecutor.threadPool != null) {
- shutdownNow();
- }
- if (threadPool == null) {
- AsyncExecutor.threadPool = Executors.newCachedThreadPool();
- } else {
- AsyncExecutor.threadPool = threadPool;
- }
- }
-
- public static synchronized void shutdownNow() {
- if (threadPool != null && !threadPool.isShutdown()) threadPool.shutdownNow();
- threadPool = null;
- }
-
- /**
- * 将任务投入线程池执行
- * @param worker
- * @return
- */
- public FutureTask execute(final Worker worker) {
- Callable call = new Callable() {
- @Override
- public T call() throws Exception {
- return postResult(worker, worker.doInBackground());
- }
- };
- FutureTask task = new FutureTask(call) {
- @Override
- protected void done() {
- try {
- get();
- } catch (InterruptedException e) {
- LogPrintUtils.eTag(TAG, e, "execute");
- worker.abort();
- postCancel(worker);
- } catch (ExecutionException e) {
- LogPrintUtils.eTag(TAG, e, "execute");
- throw new RuntimeException("An error occured while executing doInBackground()", e.getCause());
- } catch (CancellationException e) {
- worker.abort();
- postCancel(worker);
- LogPrintUtils.eTag(TAG, e, "execute");
- }
- }
- };
- threadPool.execute(task);
- return task;
- }
-
- /**
- * 将子线程结果传递到UI线程
- * @param worker
- * @param result
- * @return
- */
- private T postResult(final Worker worker, final T result) {
- handler.post(new Runnable() {
- @Override
- public void run() {
- worker.onPostExecute(result);
- }
- });
- return result;
- }
-
- /**
- * 将子线程结果传递到UI线程
- * @param worker
- * @return
- */
- private void postCancel(final Worker worker) {
- handler.post(new Runnable() {
- @Override
- public void run() {
- worker.onCanceled();
- }
- });
- }
-
- public FutureTask execute(Callable call) {
- FutureTask task = new FutureTask(call);
- threadPool.execute(task);
- return task;
- }
-
- public static abstract class Worker {
-
- protected abstract T doInBackground();
-
- protected void onPostExecute(T data) {}
-
- protected void onCanceled() {}
-
- protected void abort() {}
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/assist/BeepVibrateAssist.java b/DevLibUtils/src/main/java/dev/utils/app/assist/BeepVibrateAssist.java
deleted file mode 100644
index 3f00033fde..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/assist/BeepVibrateAssist.java
+++ /dev/null
@@ -1,279 +0,0 @@
-package dev.utils.app.assist;
-
-import android.app.Activity;
-import android.content.Context;
-import android.content.res.AssetFileDescriptor;
-import android.media.AudioManager;
-import android.media.MediaPlayer;
-import android.os.Vibrator;
-import android.support.annotation.RawRes;
-
-import java.io.Closeable;
-
-import dev.utils.LogPrintUtils;
-
-/**
- * detail: 播放“bee”的声音, 并且震动 辅助类
- * Created by Ttt
- */
-public final class BeepVibrateAssist implements Closeable {
-
- // 日志TAG
- private static final String TAG = BeepVibrateAssist.class.getSimpleName();
- // 上下文
- private final Context context;
- // 播放资源对象
- private MediaPlayer mediaPlayer = null;
- // 是否需要震动
- private boolean vibrate = true;
- // 震动时间
- private long vibrateDuration = 200L;
-
- /**
- * 构造函数
- * @param context
- */
- public BeepVibrateAssist(Context context) {
- this.context = context;
- }
-
- /**
- * 构造函数
- * @param context
- * @param rawId
- */
- public BeepVibrateAssist(Context context, @RawRes int rawId) {
- this.context = context;
- this.mediaPlayer = buildMediaPlayer(context, rawId);
- }
-
- /**
- * 构造函数
- * @param context
- * @param path 只支持本地资源
- */
- public BeepVibrateAssist(Context context, String path) {
- this.context = context;
- this.mediaPlayer = buildMediaPlayer(path);
- }
-
- // == 内部判断方法 ==
-
- /**
- * 检查是否允许播放声音
- * @return
- */
- private boolean shouldBeep() {
- boolean shouldPlayBeep = true;
- if (shouldPlayBeep) {
- try {
- // RINGER_MODE_NORMAL(普通)、RINGER_MODE_SILENT(静音)、RINGER_MODE_VIBRATE(震动)
- AudioManager audioService = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
- if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
- shouldPlayBeep = false; // 进入只有属于, 静音、震动,才不播放
- }
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "shouldBeep");
- }
- }
- return shouldPlayBeep;
- }
-
- /**
- * 内部检查更新
- */
- private synchronized void update() {
- if (shouldBeep() && mediaPlayer != null) {
- // The volume on STREAM_SYSTEM is not adjustable, and users found it too loud,
- // so we now play on the music stream.
- try {
- ((Activity) context).setVolumeControlStream(AudioManager.STREAM_MUSIC);
- } catch (Exception e){
- LogPrintUtils.eTag(TAG, e, "update");
- }
- }
- }
-
- // == 对外公开方法 ==
-
- /**
- * 判断是否允许播放声音
- * @return
- */
- public boolean isPlayBeep() {
- return shouldBeep();
- }
-
- /**
- * 获取是否允许震动
- * @return
- */
- public boolean isVibrate() {
- return vibrate;
- }
-
- /**
- * 设置是否允许震动
- * @param vibrate
- */
- public BeepVibrateAssist setVibrate(boolean vibrate) {
- setVibrate(vibrate, 200l);
- return this;
- }
-
- /**
- * 设置是否允许震动
- * @param vibrate
- * @param vibrateDuration 震动时间
- */
- public BeepVibrateAssist setVibrate(boolean vibrate, long vibrateDuration) {
- this.vibrate = vibrate;
- return this;
- }
-
- /**
- * 设置播放资源对象
- * @param mediaPlayer
- */
- public BeepVibrateAssist setMediaPlayer(MediaPlayer mediaPlayer) {
- this.mediaPlayer = mediaPlayer;
- // 进行更新
- update();
- return this;
- }
-
- /**
- * 进行播放声音, 并且振动
- */
- public synchronized void playBeepSoundAndVibrate() {
- // 判断是否允许播放
- if (shouldBeep() && mediaPlayer != null) {
- try {
- // 播放
- mediaPlayer.start();
- } catch (Exception e){
- }
- }
- // 判断是否允许震动
- if (vibrate) {
- try {
- Vibrator vibrator = (Vibrator) context.getSystemService(Context.VIBRATOR_SERVICE);
- vibrator.vibrate(vibrateDuration);
- } catch (Exception e){
- }
- }
- }
-
- @Override
- public synchronized void close() {
- if (mediaPlayer != null) {
- mediaPlayer.release();
- mediaPlayer = null;
- }
- }
-
- // == 创建 MediaPlayer 处理 ==
-
- /**
- * 创建 MediaPlayer 对象
- * @param context 上下文
- * @param rawId 响声资源id
- * @return
- */
- public static final MediaPlayer buildMediaPlayer(Context context, @RawRes int rawId) {
- return buildMediaPlayer(context, rawId, 0.1f);
- }
-
- /**
- * 创建 MediaPlayer 对象
- * @param context 上下文
- * @param rawId 响声资源id
- * @param beepVolume 音量
- * @return
- */
- public static final MediaPlayer buildMediaPlayer(Context context, @RawRes int rawId, float beepVolume) {
- final MediaPlayer mediaPlayer = new MediaPlayer();
- mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
- mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
- @Override
- public void onCompletion(MediaPlayer mp) {
- LogPrintUtils.dTag(TAG, "buildMediaPlayer - onCompletion");
-// if (mediaPlayer != null){
-// mediaPlayer.seekTo(0);
-// }
- }
- });
- mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
- @Override
- public synchronized boolean onError(MediaPlayer mp, int what, int extra) {
- LogPrintUtils.dTag(TAG, "buildMediaPlayer - onError => what: " + what + ", extra: " + extra);
- // 播放异常, 直接不处理
- return true;
- }
- });
- try {
- AssetFileDescriptor file = context.getResources().openRawResourceFd(rawId);
- try {
- mediaPlayer.setDataSource(file.getFileDescriptor(), file.getStartOffset(), file.getLength());
- } finally {
- file.close();
- }
- mediaPlayer.setVolume(beepVolume, beepVolume);
- mediaPlayer.prepare();
- return mediaPlayer;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "buildMediaPlayer");
- mediaPlayer.release();
- return null;
- }
- }
-
- // =
-
- /**
- * 创建 MediaPlayer 对象
- * @param path 响声资源路径(只支持本地资源)
- * @return
- */
- public static final MediaPlayer buildMediaPlayer(String path) {
- return buildMediaPlayer(path, 0.1f);
- }
-
- /**
- * 创建 MediaPlayer 对象
- * @param path 响声资源路径(只支持本地资源)
- * @param beepVolume 音量
- * @return
- */
- public static final MediaPlayer buildMediaPlayer(String path, float beepVolume) {
- final MediaPlayer mediaPlayer = new MediaPlayer();
- mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
- mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
- @Override
- public void onCompletion(MediaPlayer mp) {
- LogPrintUtils.dTag(TAG, "buildMediaPlayer - onCompletion");
-// if (mediaPlayer != null){
-// mediaPlayer.seekTo(0);
-// }
- }
- });
- mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() {
- @Override
- public synchronized boolean onError(MediaPlayer mp, int what, int extra) {
- LogPrintUtils.dTag(TAG, "buildMediaPlayer - onError => what: " + what + ", extra: " + extra);
- // 播放异常, 直接不处理
- return true;
- }
- });
- try {
- mediaPlayer.setDataSource(path);
- mediaPlayer.setVolume(beepVolume, beepVolume);
- mediaPlayer.prepare();
- return mediaPlayer;
- } catch (Exception e) {
- LogPrintUtils.eTag(TAG, e, "buildMediaPlayer");
- mediaPlayer.release();
- return null;
- }
- }
-}
diff --git a/DevLibUtils/src/main/java/dev/utils/app/assist/InactivityTimerAssist.java b/DevLibUtils/src/main/java/dev/utils/app/assist/InactivityTimerAssist.java
deleted file mode 100644
index ecd5f9444c..0000000000
--- a/DevLibUtils/src/main/java/dev/utils/app/assist/InactivityTimerAssist.java
+++ /dev/null
@@ -1,145 +0,0 @@
-package dev.utils.app.assist;
-
-import android.app.Activity;
-import android.content.BroadcastReceiver;
-import android.content.Context;
-import android.content.Intent;
-import android.content.IntentFilter;
-import android.os.AsyncTask;
-import android.os.BatteryManager;
-import android.os.Build;
-
-/**
- * detail: Activity 无操作定时辅助类
- * Created by Ttt
- * 需要注意的试, 需要在对应的生命周期内,调用对应的 onXXX 方法
- */
-public final class InactivityTimerAssist {
-
- // 无操作时间(到时间自动关闭) - 默认五分钟
- private long inactivityTime = 5 * 60 * 1000L;
- // 对应的页面
- private Activity activity;
- // 电池广播(充电中, 则不处理, 主要是为了省点)
- private BroadcastReceiver powerStatusReceiver;
- // 检查任务
- private AsyncTask