List of usage examples for android.os Debug isDebuggerConnected
public static boolean isDebuggerConnected()
From source file:Main.java
public static boolean isDebuggerAttached() { return (Debug.isDebuggerConnected()) || (Debug.waitingForDebugger()); }
From source file:Main.java
public static boolean isDebuggerAttached() { return (Debug.isDebuggerConnected() || Debug.waitingForDebugger()) ? true : CLS_TRACE_DEFAULT; }
From source file:com.sabdroidex.utils.json.impl.SimpleJSONMarshaller.java
/** * This method creates an instance of the object targeted by the Class passed to the constructor, * it then tries to call all the methods with the JSONSetter annotation with the corresponding field. * //w ww.j a v a2 s . c o m * @param jsonObject * This is the JSON object that will be used to fill-up an * instance of the Class that is targeted. * @return * @throws ClassNotFoundException * @throws InstantiationException * @throws IllegalAccessException */ @SuppressWarnings("unchecked") public Object unMarshal(final JSONObject jsonObject) throws InstantiationException, IllegalAccessException { Object result = clazz.newInstance(); try { Method[] methods = clazz.getMethods(); for (int i = 0; i < methods.length; i++) { JSONSetter setter = methods[i].getAnnotation(JSONSetter.class); /** * Checking if the method has the JSONSetter annotation This * only allows one parameter per setter method */ if (setter != null) { /** * Checking the JSONType defined in the annotation */ if (setter.type() == JSONType.SIMPLE) { /** * Used for simple object (String, Integer, etc ...) */ try { Object parameter = jsonObject.get(setter.name()); methods[i].invoke(result, parameter); } catch (JSONException exception) { if (Debug.isDebuggerConnected()) { Log.d(TAG, methods[i].getName() + " " + exception.getLocalizedMessage()); } } catch (IllegalArgumentException exception) { /** * This happens if the object returned by the getter * is a null, it would be defined as a JSONObject * and thus cause an IllegalArgumentException when * calling the targeted method. * * This is yet another problem in an Android API * which is bypassed by creating an empty object of * the awaited type. */ if (Debug.isDebuggerConnected()) { Log.w(TAG, methods[i].getName() + " " + exception.getLocalizedMessage()); } try { Constructor<?>[] constructors = methods[i].getParameterTypes()[0].getConstructors(); Object parameter = null; /** * Checking all the constructor of the parameter * object. */ for (Constructor<?> constructor : constructors) { Class<?>[] params = constructor.getParameterTypes(); if (params.length == 0) { /** * If the empty constructor is found we * use it. */ parameter = constructor.newInstance(); break; } else if (params[0].isPrimitive()) { /** * If a constructor using a primitive is * found we use it, this happens for * classes that extend Number. */ parameter = constructor.newInstance(0); } } methods[i].invoke(result, parameter); } catch (Exception e) { if (Debug.isDebuggerConnected()) { Log.d(TAG, methods[i].getName() + " " + e.getLocalizedMessage()); } } } } else if (setter.type() == JSONType.JSON_OBJECT) { /** * Used for object that are instantiated from JSON * (Show, Movie, etc ...) */ try { SimpleJSONMarshaller simpleJSONMarshaller = new SimpleJSONMarshaller( methods[i].getParameterTypes()[0]); JSONObject jsonElement = jsonObject.getJSONObject(setter.name()); Object parameter = simpleJSONMarshaller.unMarshal(jsonElement); methods[i].invoke(result, parameter); } catch (JSONException exception) { if (Debug.isDebuggerConnected()) { Log.d(TAG, methods[i].getName() + " " + exception.getLocalizedMessage()); } try { Constructor<?>[] constructors = methods[i].getParameterTypes()[0].getConstructors(); Object parameter = null; /** * Checking all the constructor of the parameter * object. */ for (Constructor<?> constructor : constructors) { Class<?>[] params = constructor.getParameterTypes(); if (params.length == 0) { /** * If the empty constructor is found we * use it. */ parameter = constructor.newInstance(); break; } else if (params[0].isPrimitive()) { /** * If a constructor using a primitive is * found we use it, this happens for * classes that extend Number. */ parameter = constructor.newInstance(0); } } methods[i].invoke(result, parameter); } catch (Exception e) { if (Debug.isDebuggerConnected()) { Log.d(TAG, methods[i].getName() + " " + e.getLocalizedMessage()); } } } } else if (setter.type() == JSONType.LIST) { /** * Used for object that represent a Collection (List, * ArrayList, Vector, etc ...) */ try { JSONArray jsonArray = jsonObject.getJSONArray(setter.name()); Collection<Object> collection = null; if (methods[i].getParameterTypes()[0] == List.class) { collection = (Collection<Object>) setter.listClazz().newInstance(); } else { collection = (Collection<Object>) methods[i].getParameterTypes()[0].newInstance(); } for (int j = 0; j < jsonArray.length(); j++) { Object element = jsonArray.get(j); if (setter.objectClazz() != Void.class) { SimpleJSONMarshaller simpleJSONMarshaller = new SimpleJSONMarshaller( setter.objectClazz()); element = simpleJSONMarshaller.unMarshal((JSONObject) element); } collection.add(element); } methods[i].invoke(result, collection); } catch (JSONException exception) { if (Debug.isDebuggerConnected()) { Log.d(TAG, methods[i].getName() + " " + exception.getLocalizedMessage()); } } } else if (setter.type() == JSONType.UNKNOWN_KEY_ELEMENTS) { /** * Used for object that represent a Collection (List, * ArrayList, Vector, etc ...) and that do not have a * key that is predefined. */ try { Collection<Object> collection = null; if (methods[i].getParameterTypes()[0] == List.class) { collection = (Collection<Object>) setter.listClazz().newInstance(); } else { collection = (Collection<Object>) methods[i].getParameterTypes()[0].newInstance(); } Iterator<?> iterator = jsonObject.keys(); while (iterator.hasNext()) { String key = (String) iterator.next(); Object element = jsonObject.get(key); if (setter.objectClazz() != Void.class) { SimpleJSONMarshaller simpleJSONMarshaller = new SimpleJSONMarshaller( setter.objectClazz()); element = simpleJSONMarshaller.unMarshal((JSONObject) element); if (element instanceof UnknowMappingElement) { ((UnknowMappingElement) element).setId(key); } } collection.add(element); } methods[i].invoke(result, collection); } catch (JSONException exception) { if (Debug.isDebuggerConnected()) { Log.d(TAG, methods[i].getName() + " " + exception.getLocalizedMessage()); } } } } } } catch (Exception e) { if (Debug.isDebuggerConnected()) { Log.d(TAG, e.getLocalizedMessage()); } } return result; }
From source file:com.intel.xdk.base.Base.java
public void showSplashScreen() { cordova.getActivity().runOnUiThread(new Runnable() { public void run() { //treat displays larger than 6" as tablets DisplayMetrics dm = new DisplayMetrics(); cordova.getActivity().getWindowManager().getDefaultDisplay().getMetrics(dm); double x = Math.pow(dm.widthPixels / dm.xdpi, 2); double y = Math.pow(dm.heightPixels / dm.ydpi, 2); double screenInches = Math.sqrt(x + y); if (screenInches > 6) { isTablet = true;/* w w w. ja va 2 s .c o m*/ } //used for calculating status bar height int deviceWidth = dm.widthPixels; int deviceHeight = dm.heightPixels; if (deviceWidth > deviceHeight) { deviceWidth = dm.heightPixels; deviceHeight = dm.widthPixels; } //get the splash screen image from asssets Bitmap bm = null; try { if (isTablet) { bm = getBitmapFromAsset("www/intel.xdk.base/android/splash_screen_tablet.jpg"); } else { bm = getBitmapFromAsset("www/intel.xdk.base/android/splash_screen.jpg"); } } catch (IOException ioe) { } //if the splash screen assets are missing, don't try to show the splash screen if (bm == null) { return; } if (Debug.isDebuggerConnected()) Log.i("[intel.xdk]", "splash"); ActivityInfo ai = null; int splashViewId = 0; try { ai = cordova.getActivity().getPackageManager().getActivityInfo( cordova.getActivity().getComponentName(), PackageManager.GET_ACTIVITIES | PackageManager.GET_META_DATA); if (isTablet) { if (ai.screenOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) { splashViewId = cordova.getActivity().getResources().getIdentifier("splash_tablet_ls", "layout", cordova.getActivity().getPackageName()); } else { splashViewId = cordova.getActivity().getResources().getIdentifier("splash_tablet", "layout", cordova.getActivity().getPackageName()); } } else { if (ai.screenOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) { splashViewId = cordova.getActivity().getResources().getIdentifier("splash_ls", "layout", cordova.getActivity().getPackageName()); } else { splashViewId = cordova.getActivity().getResources().getIdentifier("splash", "layout", cordova.getActivity().getPackageName()); } } LayoutInflater inflater = LayoutInflater.from(cordova.getActivity()); splashView = inflater.inflate(splashViewId, null); //set the splash screen image //http://stackoverflow.com/questions/7776445/in-android-can-i-use-image-from-assets-in-layout-xml ImageView backgroundImage = (ImageView) splashView .findViewById(cordova.getActivity().getResources().getIdentifier("background", "id", cordova.getActivity().getPackageName())); backgroundImage.setImageBitmap(bm); ((ViewGroup) root.getParent()).addView(splashView); splashView.bringToFront(); //hack to fix splash screen size when it is smaller than screen ImageView splashImage = (ImageView) cordova.getActivity() .findViewById(cordova.getActivity().getResources().getIdentifier("background", "id", cordova.getActivity().getPackageName())); LayoutParams params = splashImage.getLayoutParams(); Rect imgBounds = splashImage.getDrawable().getBounds(); int splashHeight = params.height; int splashWidth = params.width; //make copies in case we have to switch for landscape - not sure if needed, this is a last minute hack int deviceWidthCopy, deviceHeightCopy; deviceWidthCopy = deviceWidth; deviceHeightCopy = deviceHeight; if (ai.screenOrientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) { int temp = deviceWidthCopy; deviceWidthCopy = deviceHeightCopy; deviceHeightCopy = temp; } if (splashHeight < deviceHeightCopy || splashWidth < deviceWidthCopy) { float scaleH = (float) deviceHeightCopy / splashHeight; float scaleW = (float) deviceWidthCopy / splashWidth; float scale = Math.max(scaleH, scaleW); params.height *= scale; params.width *= scale; splashImage.setLayoutParams(params); } cordova.getActivity().setProgressBarIndeterminateVisibility(true); } catch (Exception e) { e.printStackTrace(); } } }); }
From source file:com.intel.xdk.facebook.IntelXDKFacebook.java
/** * Executes the request and returns PluginResult. */*from w w w.j av a 2s .c om*/ * @param action The action to execute. * @param args JSONArray of arguments for the plugin. * @param callbackContext The callback context used when calling back into JavaScript. * @return True when the action was valid, false otherwise. */ public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (action.equals("enableFrictionlessRequests")) { this.enableFrictionlessRequests(); } else if (action.equals("login")) { this.login(args.getString(0)); } else if (action.equals("logout")) { this.logout(); } else if (action.equals("requestWithGraphAPI")) { //this.callbackContext = callbackContext; this.requestWithGraphAPI(new String[] { args.getString(0), args.getString(1), args.getString(2) }); } else if (action.equals("requestWithRestAPI")) { //this.requestWithRestAPI(args.toString().replace("[", "").replace("]", "").split(",")); if (Debug.isDebuggerConnected()) Log.d("[IntelXCKFacebook]", "requestWithRestAPI: Has been deprecated."); String js = "javascript: var e = document.createEvent('Events');e.initEvent('intel.xdk.facebook.request.response',true,true);e.success=false;e.error='Facebook REST APIs have been deprecated.';e.raw='';e.data={};document.dispatchEvent(e);"; //webView.loadUrl(js); injectJS(js); } else if (action.equals("showAppRequestDialog")) { this.showAppRequestDialog(args.getString(0)); } else if (action.equals("showNewsFeedDialog")) { this.showNewsFeedDialog(args.getString(0)); } else { return false; } // All actions are async. //callbackContext.success(); return true; }
From source file:com.intel.xdk.cache.Cache.java
private String getCookies() { Map<String, ?> valueMap = activity.getSharedPreferences(cookies, 0).getAll(); SharedPreferences.Editor valueEditor = activity.getSharedPreferences(cookies, 0).edit(); Map<String, ?> expiresMap = activity.getSharedPreferences(cookiesExpires, 0).getAll(); SharedPreferences.Editor expiresEditor = activity.getSharedPreferences(cookiesExpires, 0).edit(); StringBuffer cookies = new StringBuffer("{"); Iterator<String> keys = valueMap.keySet().iterator(); while (keys.hasNext()) { String key = keys.next(); String value = (String) valueMap.get(key); String expires = (String) expiresMap.get(key); Date expiresDate = null, now = new Date(); if (!expires.equals(DONOTEXPIRE)) { try { expiresDate = sdf.parse(expires); } catch (ParseException e) { e.printStackTrace();//ww w.j a v a 2s . com } } if (expiresDate == null || expiresDate.after(now)) { value = value.replaceAll("'", "\\\\'"); cookies.append(key + ":{value:'" + value + "'}"); if (keys.hasNext()) { cookies.append(", "); } } else { //coookie is expired - remove it from prefs valueEditor.remove(key); expiresEditor.remove(key); } } valueEditor.commit(); expiresEditor.commit(); cookies.append("}"); if (Debug.isDebuggerConnected()) Log.i(tag, "intel.xdk.cookies: " + cookies.toString()); return cookies.toString(); }
From source file:at.tugraz.ist.akm.activities.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { if (Debug.isDebuggerConnected()) { UncaughtExceptionLogger exLogger = new UncaughtExceptionLogger(mLog); exLogger.register();/*from w w w . ja v a2 s . c o m*/ } MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.default_actionbar, menu); getActionBar().setDisplayHomeAsUpEnabled(true); return true; }
From source file:com.intel.xdk.camera.Camera.java
private void savePicture(final String outputFile, final int quality, final boolean isPNG) { //busy could be false if activity had been stopped busy = true;/* w w w . j ava 2 s. c o m*/ try { String dir = pictureDir(); File dirFile = new File(dir); if (!dirFile.exists()) dirFile.mkdirs(); String baseName = getNextPictureFile(isPNG); String filePath = String.format("%1$s/%2$s", dir, baseName); try { if (debug) System.out.println("AppMobiCamera.takePicture: file = " + filePath); OutputStream out = new BufferedOutputStream(new FileOutputStream(filePath), 0x8000); Bitmap bitMap = BitmapFactory.decodeFile(outputFile); if (bitMap == null || !bitMap .compress((isPNG ? Bitmap.CompressFormat.PNG : Bitmap.CompressFormat.JPEG), 70, out)) { throw new IOException("Error converting to PNG"); } bitMap.recycle(); out.close(); fireJSEvent("camera.internal.picture.add", true, null, new String[] { String.format("ev.filename='%1$s';", baseName) }); fireJSEvent("camera.picture.add", true, null, new String[] { String.format("ev.filename='%1$s';", baseName) }); callbackContext.success(""); } catch (IOException e) { postAddError(baseName); if (debug) System.out.println("AppMobiCamera.takePicture err: " + e.getMessage()); } finally { callbackContext = null; busy = false; } } catch (Exception e) { //sometimes a NPE occurs after resuming, catch it here but do nothing if (Debug.isDebuggerConnected()) Log.e("[intel.xdk]", "handled camera resume NPE:\n" + e.getMessage(), e); } }
From source file:com.intel.xdk.cache.Cache.java
private String getMediaCache() { File[] physicalMediaCache = cachedMediaDirectory.listFiles(); if (physicalMediaCache != null) if (Debug.isDebuggerConnected()) Log.i(tag, "****physical media cache****: " + Arrays.asList(physicalMediaCache)); Map<String, ?> valueMap = mediaCache.getAll(); //TODO: should verify that list is in synch with filesystem here //inject js/*from w w w .j a v a 2 s. c o m*/ StringBuffer mediaJS = new StringBuffer("{"); Iterator<String> keys = valueMap.keySet().iterator(); while (keys.hasNext()) { if (mediaJS.length() != 1) mediaJS.append(", "); String key = keys.next(); mediaJS.append("\"" + key + "\":"); String value = (String) valueMap.get(key); mediaJS.append("\"" + value + "\""); } mediaJS.append("}"); if (Debug.isDebuggerConnected()) Log.i(tag, "intel.xdk.mediacache: " + mediaJS.toString()); return mediaJS.toString(); }
From source file:com.intel.xdk.cache.Cache.java
public void clearMediaCache() { // if(webView.config!=null && !webView.config.hasCaching) return; resetPhysicalMediaCache();//from w ww . j a v a 2 s . c o m //update js object and fire private and public events String js = "javascript:var _e = document.createEvent('Events');_e.initEvent('intel.xdk.cache.internal.media.clear',true,true);document.dispatchEvent(_e);" + "var e = document.createEvent('Events');e.initEvent('intel.xdk.cache.media.clear',true,true);document.dispatchEvent(e);"; if (Debug.isDebuggerConnected()) Log.i(tag, js); injectJS(js); }