Colored Logcat


Source link: https://gist.github.com/kevinmcmahon/1642404

Colored Logcat

Python file (4 KB): coloredlogcat.py

#!/usr/bin/python  '''
  Copyright 2009, The Android Open Source Project

Licensed under the Apache License, Version 2.0 (the "License");

you may not use this file except in compliance with the License.

You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

 Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an "AS IS" BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License. '''  # script to highlight adb logcat output for console # written by jeff sharkey, http://jsharkey.org/ # piping detection and popen() added by other android team members
import os, sys, re, StringIO import fcntl, termios, struct  # unpack the current terminal width/height data = fcntl.ioctl(sys.stdout.fileno(), termios.TIOCGWINSZ, '1234') HEIGHT, WIDTH = struct.unpack('hh',data)  BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE = range(8)  def format(fg=None, bg=None, bright=False, bold=False, dim=False, reset=False):
  # manually derived from http://en.wikipedia.org/wiki/ANSI_escape_code#Codes
  codes = []
  if reset: codes.append("0")
  else:

if not fg is None: codes.append("3%d" % (fg))

if not bg is None:

 if not bright: codes.append("4%d" % (bg))

 else: codes.append("10%d" % (bg))

if bold: codes.append("1")

elif dim: codes.append("2")

else: codes.append("22")
  return "\033[%sm" % (";".join(codes))
def indent_wrap(message, indent=0, width=80):
  wrap_area = width - indent
  messagebuf = StringIO.StringIO()
  current = 0
  while current < len(message):

next = min(current + wrap_area, len(message))

messagebuf.write(message[current:next])

if next < len(message):

 messagebuf.write("\n%s" % (" " * indent))

current = next
  return messagebuf.getvalue()
LAST_USED = [RED,GREEN,YELLOW,BLUE,MAGENTA,CYAN,WHITE] KNOWN_TAGS = {

  "dalvikvm": BLUE,
  "Process": BLUE,
  "ActivityManager": CYAN,
  "ActivityThread": CYAN, 
}
  def allocate_color(tag):
  # this will allocate a unique format for the given tag
  # since we dont have very many colors, we always keep track of the LRU
  if not tag in KNOWN_TAGS:

KNOWN_TAGS[tag] = LAST_USED[0]
  color = KNOWN_TAGS[tag]
  LAST_USED.remove(color)
  LAST_USED.append(color)
  return color
RULES = {

  #re.compile(r"([\w\.@]+)=([\w\.@]+)"): r"%s\1%s=%s\2%s" % (format(fg=BLUE), format(fg=GREEN), format(fg=BLUE), format(reset=True)), 
}
  TAGTYPE_WIDTH = 3 TAG_WIDTH = 20 PROCESS_WIDTH = 8 # 8 or -1 HEADER_SIZE = TAGTYPE_WIDTH + 1 + TAG_WIDTH + 1 + PROCESS_WIDTH + 1  TAGTYPES = {

  "V": "%s%s%s " % (format(fg=WHITE, bg=BLACK), "V".center(TAGTYPE_WIDTH), format(reset=True)),
  "D": "%s%s%s " % (format(fg=BLACK, bg=BLUE), "D".center(TAGTYPE_WIDTH), format(reset=True)),
  "I": "%s%s%s " % (format(fg=BLACK, bg=GREEN), "I".center(TAGTYPE_WIDTH), format(reset=True)),
  "W": "%s%s%s " % (format(fg=BLACK, bg=YELLOW), "W".center(TAGTYPE_WIDTH), format(reset=True)),
  "E": "%s%s%s " % (format(fg=BLACK, bg=RED), "E".center(TAGTYPE_WIDTH), format(reset=True)), 
}
  retag = re.compile("^([A-Z])/([^\(]+)\(([^\)]+)\): (.*)$")  # to pick up -d or -e adb_args = ' '.join(sys.argv[1:])  # if someone is piping in to us, use stdin as input.  if not, invoke adb logcat if os.isatty(sys.stdin.fileno()):
  input = os.popen("adb %s logcat" % adb_args) else:
  input = sys.stdin  while True:
  try:

line = input.readline()
  except KeyboardInterrupt:

break

match = retag.match(line)
  if not match is None:

tagtype, tag, owner, message = match.groups()

linebuf = StringIO.StringIO()

 # center process info

if PROCESS_WIDTH > 0:

 owner = owner.strip().center(PROCESS_WIDTH)

 linebuf.write("%s%s%s " % (format(fg=BLACK, bg=BLACK, bright=True), owner, format(reset=True)))

 # right-align tag title and allocate color if needed

tag = tag.strip()

color = allocate_color(tag)

tag = tag[-TAG_WIDTH:].rjust(TAG_WIDTH)

linebuf.write("%s%s %s" % (format(fg=color, dim=False), tag, format(reset=True)))

 # write out tagtype colored edge

if not tagtype in TAGTYPES: break

linebuf.write(TAGTYPES[tagtype])

 # insert line wrapping as needed

message = indent_wrap(message, HEADER_SIZE, WIDTH)

 # format tag message using rules

for matcher in RULES:

 replace = RULES[matcher]

 message = matcher.sub(replace, message)

 linebuf.write(message)

line = linebuf.getvalue()

print line
  if len(line) == 0: break

Resources

The lib provides an easy way to store your settings in SharedPreferences.

Using Html to render Android native view.

Other than Webview, HtmlNative directly parses HTML and CSS into Android native views, which will:

  • Reach better user-expirence by native widgets
  • Make UI dynamic, no need to release new version of application
  • Easy to write html and css
  • Define your own html tag
  • Support script of Lua, by which you can control the logic inside of this view.

This library is a package of functions that let you manipulate objects and or java date string. It combines the most common functions used when managing dates under android, such as converting a mysql / sqlLite date to a Date object and vis-versa, etc.

Custom view written in Kotlin to Display a translucent frame with corners as known from cameras. You can set the frame's alpha, the frame size, the length of the lines in the corner, their color and the width of them.

Improved AsyncQueryHandler that supports Bulk Insert operation

An Input box with different validators and ripple transition for android. It lets you to define custom animation for error text entrance and also comes up with seven ready validators.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes