Posts

Showing posts with the label Android

Working with Android Hierarchy Viewer

Working with Hierarchy Viewer #Hierarchy Viewer allows you to debug and optimize your user interface. #It provides a visual representation of the layout's View hierarchy (the Layout View) and a magnified inspector of the display. # Connect your mobile device to your computer. # Open your application in Android Studio, build the source, and run it on your device. (debug application only) # From Android Studio, start the Android Device Monitor: Tools > Android > Android Device Monitor. # Allow USB Debugging on your phone (if asked). # Make sure your device and the package for your application are showing in the Devices (DDMS mode) or Windows (Hierarchy Viewer mode) tab. You can choose Window > Reset Perspective to get back to the default arrangement. # In Android Device Monitor (ADM), in the menu bar, choose Window > Open Perspective, and in the popup click Hierarchy View. The left dot represents the Draw Process of the rendering pipeline. - Measure Th...

React-Native: Android React Native Setup

# Install Adnroid SDK # Install Node Js # Install react # run the following commands npm install -g react-native-cli react-native init AwesomeProject # To run with local server, run the following commands under your react-native project root directory react-native start  /dev/null 2>&1 & adb reverse tcp:8081 tcp:8081

Android: Events from JavaScript to Android

//Add interface to webview webView.addJavascriptInterface( new WebAppInterface(getApplicationContext()), "Android" ); class WebAppInterface { Context mContext ; /** * Instantiate the interface and set the context */   WebAppInterface(Context c) { mContext = c; } /** * Show a toast from the web page */   @JavascriptInterface   public void showToast(String toast) { Toast. makeText ( mContext , toast, Toast. LENGTH_SHORT ).show(); } //Create a toast / event in JavaScript <input type="button" value="Say hello" onClick="showAndroidToast('Hello Android!')" /> <script type="text/javascript"> function showAndroidToast(toast) { Android.showToast(toast); } </script>

Android: ProGuard source code

Enable ProGuard in Android gradle build, make sure that the build variant is same. minifyEnabled true Add following snippet to App ' proguard-rules.pro' file -optimizationpasses 5 -dontusemixedcaseclassnames -dontskipnonpubliclibraryclasses -dontskipnonpubliclibraryclassmembers -dontpreverify -dontnote -ignorewarnings -verbose -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* # not to proguard dependent library packages -keep class com.squareup.** -keep class com.android.volley.** # not to proguard android components -keep public class * extends android.app.Activity -keep public class * extends android.app.Fragment -keep public class * extends android.support.v4.app.Fragment -keep public class * extends android.app.Application -keep public class * extends android.app.Service -keep public class * extends android.content.BroadcastReceiver -dontwarn ** -dontnote ** # to generate the mapping.txt file -printmapping mapping.txt

Android: de compile an android apk file

extract apk file as zip or rar file convert the dex file to jar using dex2jar tool then open the jar file with jd_gui tool.

Android: Display Manager

public class AppDisplayManager { private static AppDisplayManager ourInstance = new AppDisplayManager(); private Display mDisplay ; public static AppDisplayManager getInstance() { return ourInstance ; } private AppDisplayManager() { WindowManager wm = (WindowManager) CommonUtil. getAppContext ().getSystemService(Context. WINDOW_SERVICE ); mDisplay = wm.getDefaultDisplay(); } public int getDeviceWidth() { if ( null != mDisplay ) { if (android.os.Build.VERSION. SDK_INT >=  android.os.Build.VERSION_CODES. HONEYCOMB_MR2 ) { Point point = new Point(); mDisplay .getSize(point); return point. x ; } else { return mDisplay .getWidth(); } } else { return 0 ; } } public int getDeviceHeight() { if ( null != mDisplay ) { if (andro...