/** * call this function with parameter as true to enable the debugging for javascript. The * debuggable for javascript will get enabled only after KITKAT version. * * @param setEnabled */ @JavascriptInterface public void setDebuggableEnabled(final String setEnabled) { Logger.d(tag, "set debuggable enabled called with " + setEnabled); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (null == mHandler) { return; } mHandler.post( new Runnable() { @SuppressLint("NewApi") @Override public void run() { if (Boolean.valueOf(setEnabled)) { WebView.setWebContentsDebuggingEnabled(true); } else { WebView.setWebContentsDebuggingEnabled(false); } } }); } }
@Override public STResult call() throws Exception { Logger.d(getClass().getSimpleName(), "CategoryId: " + category.getCategoryId()); String directoryPath = StickerManager.getInstance().getStickerDirectoryForCategoryId(category.getCategoryId()); if (directoryPath == null) { setException(new StickerException(StickerException.DIRECTORY_NOT_EXISTS)); Logger.e( StickerDownloadManager.TAG, "Sticker download failed directory does not exist for task : " + taskId); return STResult.DOWNLOAD_FAILED; } File largeStickerDir = new File(directoryPath + HikeConstants.LARGE_STICKER_ROOT); File smallStickerDir = new File(directoryPath + HikeConstants.SMALL_STICKER_ROOT); int totalNumber = 0; boolean reachedEnd = false; boolean retry = true; int existingStickerNumber = 0; JSONArray existingStickerIds = new JSONArray(); if (smallStickerDir.exists()) { String[] stickerIds = smallStickerDir.list(StickerManager.getInstance().stickerFileFilter); for (String stickerId : stickerIds) { existingStickerIds.put(stickerId); existingStickerNumber++; Logger.d(getClass().getSimpleName(), "Existing id: " + stickerId); } } else { smallStickerDir.mkdirs(); Logger.d(getClass().getSimpleName(), "No existing sticker"); } if (!largeStickerDir.exists()) largeStickerDir.mkdirs(); Utils.makeNoMediaFile(largeStickerDir); Utils.makeNoMediaFile(smallStickerDir); while (shouldContinue(reachedEnd, totalNumber, existingStickerNumber)) { try { JSONObject request = new JSONObject(); request.put(StickerManager.CATEGORY_ID, category.getCategoryId()); request.put(HikeConstants.STICKER_IDS, existingStickerIds); request.put(HikeConstants.RESOLUTION_ID, Utils.getResolutionId()); request.put(HikeConstants.NUMBER_OF_STICKERS, getStickerDownloadSize()); if (source != null) { request.put(HikeConstants.DOWNLOAD_SOURCE, source.ordinal()); } String urlString = AccountUtils.base + "/stickers"; if (AccountUtils.ssl) { urlString = AccountUtils.HTTPS_STRING + AccountUtils.host + "/v1" + "/stickers"; } setDownloadUrl(urlString); Logger.d( StickerDownloadManager.TAG, "Sticker Download Task Request : " + request.toString()); Logger.d( StickerDownloadManager.TAG, "Starting download task : " + taskId + " url : " + urlString); JSONObject response = (JSONObject) download(request, HttpRequestType.POST); if (response == null || !HikeConstants.OK.equals(response.getString(HikeConstants.STATUS))) { setException(new StickerException(StickerException.NULL_OR_INVALID_RESPONSE)); Logger.e( StickerDownloadManager.TAG, "Sticker download failed null or invalid response for task : " + taskId); return STResult.DOWNLOAD_FAILED; } Logger.d( StickerDownloadManager.TAG, "Got response for download task : " + taskId + " response : " + response.toString()); int length = response.toString().getBytes().length; if (length > Utils.getFreeSpace()) { setException(new StickerException(StickerException.OUT_OF_SPACE)); Logger.e( StickerDownloadManager.TAG, "Sticker download failed directory out of space for task : " + taskId); return STResult.DOWNLOAD_FAILED; } totalNumber = response.optInt(HikeConstants.TOTAL_STICKERS, -1); reachedEnd = response.optBoolean(HikeConstants.REACHED_STICKER_END); Logger.d(getClass().getSimpleName(), "Reached end? " + reachedEnd); Logger.d(getClass().getSimpleName(), "Sticker count: " + totalNumber); JSONObject data = response.getJSONObject(HikeConstants.DATA_2); for (Iterator<String> keys = data.keys(); keys.hasNext(); ) { String stickerId = keys.next(); String stickerData = data.getString(stickerId); existingStickerIds.put(stickerId); existingStickerNumber++; try { byte[] byteArray = StickerManager.getInstance() .saveLargeStickers(largeStickerDir.getAbsolutePath(), stickerId, stickerData); StickerManager.getInstance() .saveSmallStickers(smallStickerDir.getAbsolutePath(), stickerId, byteArray); } catch (FileNotFoundException e) { Logger.w(getClass().getSimpleName(), e); } catch (IOException e) { Logger.w(getClass().getSimpleName(), e); } } } catch (StickerException e) { Logger.e(StickerDownloadManager.TAG, "Sticker download failed for task : " + taskId, e); setException(e); return STResult.DOWNLOAD_FAILED; } catch (Exception e) { Logger.e(StickerDownloadManager.TAG, "Sticker download failed for task : " + taskId, e); setException(new StickerException(e)); return STResult.DOWNLOAD_FAILED; } if (getRetryPolicy() != null) { ((DefaultRetryPolicy) getRetryPolicy()).reset(); } if (totalNumber != 0) { sendProgressOrResult(null, true, existingStickerNumber / totalNumber); } if (category.getTotalStickers() != totalNumber) { category.setTotalStickers(totalNumber); HikeConversationsDatabase.getInstance() .updateStickerCountForStickerCategory(category.getCategoryId(), totalNumber); } } if (isSucessfull(reachedEnd, totalNumber, existingStickerNumber)) { return STResult.SUCCESS; } else { return STResult.DOWNLOAD_FAILED; } }
@Override public void onReceive(Context context, Intent intent) { /* * no name setting, so don't bother pulling in SMS's yet or The user doesn't want us pulling in his SMS. */ Logger.d("HikeMessageReceiver", System.currentTimeMillis() + ""); Logger.d("HikeMessageReceiver", "message received"); // If the User is not authenticated and the GCMID is not sent to the server and the user is // connected. HikeSharedPreferenceUtil mprefs = HikeSharedPreferenceUtil.getInstance(); if (Utils.isUserOnline(context) && (!Utils.isUserAuthenticated(context)) && !mprefs.getData(HikeMessengerApp.GCM_ID_SENT_PRELOAD, false)) { Intent in = new Intent(HikeService.REGISTER_TO_GCM_ACTION); mprefs.saveData(HikeConstants.REGISTER_GCM_SIGNUP, HikeConstants.REGISTEM_GCM_BEFORE_SIGNUP); LocalBroadcastManager.getInstance(context.getApplicationContext()).sendBroadcast(in); return; } if (!Utils.isUserSignedUp(context, false) || !PreferenceManager.getDefaultSharedPreferences(context) .getBoolean(HikeConstants.RECEIVE_SMS_PREF, false)) { return; } Logger.d(getClass().getSimpleName(), "Received SMS message"); Bundle extras = intent.getExtras(); if (extras != null) { Logger.d(getClass().getSimpleName(), "Received SMS message with extras " + extras.keySet()); Object[] extra = (Object[]) extras.get("pdus"); Logger.d(getClass().getSimpleName(), "Extras length is " + extra.length); for (int i = 0; i < extra.length; ++i) { SmsMessage sms = SmsMessage.createFromPdu((byte[]) extra[i]); String body = sms.getMessageBody(); long timestamp = sms.getTimestampMillis() / 1000; String from = sms.getOriginatingAddress(); ContactInfo contactInfo = HikeMessengerApp.getContactManager().getContact(from, true, true); if (contactInfo == null) { Logger.d( getClass().getSimpleName(), "Ignoring SMS message because contact not in addressbook phone_no=" + from); return; } try { JSONObject msg = new JSONObject(); msg.put(HikeConstants.TYPE, HikeConstants.MqttMessageTypes.MESSAGE); msg.put(HikeConstants.FROM, contactInfo.getMsisdn()); JSONObject data = new JSONObject(); data.put(HikeConstants.SMS_MESSAGE, body); data.put(HikeConstants.TIMESTAMP, timestamp); data.put(HikeConstants.MESSAGE_ID, makeSMSId(from, body, timestamp)); msg.put(HikeConstants.DATA, data); writeToNativeSMSDb(context, msg); Logger.d(getClass().getSimpleName(), "Received SMS " + msg.toString()); Intent smsReceivedIntent = new Intent(context, HikeService.class); smsReceivedIntent.putExtra(HikeConstants.Extras.SMS_MESSAGE, msg.toString()); context.startService(smsReceivedIntent); this.abortBroadcast(); } catch (JSONException e) { Logger.e(getClass().getSimpleName(), "Invalid data for SMS message", e); return; } } } }
@Override public void onCreate(Bundle icicle) { overridePendingTransition(R.anim.fade_in_animation, R.anim.fade_out_animation); super.onCreate(icicle); mContentResolver = getContentResolver(); getWindow() .setFlags( WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.cropimage); /* * Added to fix a Android issue for devices that support hardware acceleration. http://android-developers.blogspot.in/2011/03/android-30 -hardware-acceleration.html */ mImageView = (CropImageView) findViewById(R.id.image); try { Method method = mImageView.getClass().getMethod("setLayerType", Integer.TYPE, Paint.class); method.invoke(mImageView, 1, null); } catch (IllegalArgumentException e) { Logger.e(getClass().getSimpleName(), "Exception during reflection", e); } catch (IllegalAccessException e) { Logger.e(getClass().getSimpleName(), "Exception during reflection", e); } catch (InvocationTargetException e) { Logger.e(getClass().getSimpleName(), "Exception during reflection", e); } catch (SecurityException e) { Logger.e(getClass().getSimpleName(), "Exception during reflection", e); } catch (NoSuchMethodException e) { Logger.e(getClass().getSimpleName(), "Exception during reflection", e); } showStorageToast(this); Intent intent = getIntent(); Bundle extras = intent.getExtras(); if (extras != null) { if (extras.getString(HikeConstants.Extras.CIRCLE_CROP) != null) { mCircleCrop = true; mAspectX = 1; mAspectY = 1; } if (extras.containsKey(HikeConstants.Extras.RETURN_CROP_RESULT_TO_FILE)) { returnToFile = extras.getBoolean(HikeConstants.Extras.RETURN_CROP_RESULT_TO_FILE); } mImagePath = extras.getString(HikeConstants.Extras.IMAGE_PATH); mSaveUri = extras.containsKey(MediaStore.EXTRA_OUTPUT) ? getImageUri(extras.getString(MediaStore.EXTRA_OUTPUT)) : null; // look here mBitmap = getBitmap(mImagePath); String imageOrientation = Utils.getImageOrientation(mImagePath); mBitmap = HikeBitmapFactory.rotateBitmap(mBitmap, Utils.getRotatedAngle(imageOrientation)); mAspectX = extras.getInt(HikeConstants.Extras.ASPECT_X); mAspectY = extras.getInt(HikeConstants.Extras.ASPECT_Y); mOutputX = extras.getInt(HikeConstants.Extras.OUTPUT_X); mOutputY = extras.getInt(HikeConstants.Extras.OUTPUT_Y); mScale = extras.getBoolean(HikeConstants.Extras.SCALE, true); mScaleUp = extras.getBoolean(HikeConstants.Extras.SCALE_UP, true); } if (mBitmap == null) { Toast toast = Toast.makeText(this, getResources().getString(R.string.image_failed), Toast.LENGTH_LONG); toast.show(); Logger.d(TAG, "Unable to open bitmap"); finish(); return; } // Make UI fullscreen. getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); findViewById(R.id.rotateLeft) .setOnClickListener( new View.OnClickListener() { public void onClick(View v) { mBitmap = Util.rotateImage(mBitmap, -90); RotateBitmap rotateBitmap = new RotateBitmap(mBitmap); mImageView.setImageRotateBitmapResetBase(rotateBitmap, true); mRunFaceDetection.run(); } }); setupActionBar(); startFaceDetection(); }