List of usage examples for android.util Base64 decode
public static byte[] decode(byte[] input, int flags)
From source file:keyboard.ecloga.com.eclogakeyboard.EclogaKeyboard.java
@Override public void onStartInputView(EditorInfo info, boolean restarting) { initializeKeyboard();/*from ww w .j a v a2s . co m*/ onRotate(); if (mVoiceRecognitionTrigger != null) { mVoiceRecognitionTrigger.onStartInputView(); } vbListenerPause = false; if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("random")) { Random rand = new Random(); int randInt = rand.nextInt(25); switch (randInt) { case 1: kv.setBackgroundColor(getResources().getColor(R.color.white)); break; case 2: kv.setBackgroundColor(getResources().getColor(R.color.black)); break; case 3: kv.setBackgroundColor(getResources().getColor(R.color.purple)); break; case 4: kv.setBackgroundColor(getResources().getColor(R.color.red)); break; case 5: kv.setBackgroundColor(getResources().getColor(R.color.pink)); break; case 6: kv.setBackgroundColor(getResources().getColor(R.color.blue)); break; case 7: kv.setBackgroundColor(getResources().getColor(R.color.green)); break; case 8: kv.setBackgroundColor(getResources().getColor(R.color.yellow)); break; case 9: kv.setBackgroundColor(getResources().getColor(R.color.orange)); break; case 10: kv.setBackgroundColor(getResources().getColor(R.color.grey)); break; case 11: kv.setBackgroundColor(getResources().getColor(R.color.lightpurple)); break; case 12: kv.setBackgroundColor(getResources().getColor(R.color.lightred)); break; case 13: kv.setBackgroundColor(getResources().getColor(R.color.lightpink)); break; case 14: kv.setBackgroundColor(getResources().getColor(R.color.lightblue)); break; case 15: kv.setBackgroundColor(getResources().getColor(R.color.lightgreen)); break; case 16: kv.setBackgroundColor(getResources().getColor(R.color.lightyellow)); break; case 17: kv.setBackgroundColor(getResources().getColor(R.color.lightgrey)); break; case 18: kv.setBackgroundColor(getResources().getColor(R.color.lightorange)); break; case 19: kv.setBackgroundColor(getResources().getColor(R.color.darkpurple)); break; case 20: kv.setBackgroundColor(getResources().getColor(R.color.darkorange)); break; case 21: kv.setBackgroundColor(getResources().getColor(R.color.darkblue)); break; case 22: kv.setBackgroundColor(getResources().getColor(R.color.darkgreen)); break; case 23: kv.setBackgroundColor(getResources().getColor(R.color.darkred)); break; case 24: kv.setBackgroundColor(getResources().getColor(R.color.darkyellow)); break; case 25: kv.setBackgroundColor(getResources().getColor(R.color.darkpink)); break; } } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_1")) { kv.setBackgroundResource(R.drawable.pattern_1); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_2")) { kv.setBackgroundResource(R.drawable.pattern_2); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_3")) { kv.setBackgroundResource(R.drawable.pattern_3); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_4")) { kv.setBackgroundResource(R.drawable.pattern_4); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_5")) { kv.setBackgroundResource(R.drawable.pattern_5); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_6")) { kv.setBackgroundResource(R.drawable.pattern_6); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_7")) { kv.setBackgroundResource(R.drawable.pattern_7); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_8")) { kv.setBackgroundResource(R.drawable.pattern_8); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_9")) { kv.setBackgroundResource(R.drawable.pattern_9); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_10")) { kv.setBackgroundResource(R.drawable.pattern_10); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_11")) { kv.setBackgroundResource(R.drawable.pattern_11); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_12")) { kv.setBackgroundResource(R.drawable.pattern_12); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_13")) { kv.setBackgroundResource(R.drawable.pattern_13); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_14")) { kv.setBackgroundResource(R.drawable.pattern_14); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_15")) { kv.setBackgroundResource(R.drawable.pattern_15); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_16")) { kv.setBackgroundResource(R.drawable.pattern_16); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pattern_17")) { kv.setBackgroundResource(R.drawable.pattern_17); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_1")) { kv.setBackgroundResource(R.drawable.nature_1); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_2")) { kv.setBackgroundResource(R.drawable.nature_2); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_3")) { kv.setBackgroundResource(R.drawable.nature_3); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_4")) { kv.setBackgroundResource(R.drawable.nature_4); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_5")) { kv.setBackgroundResource(R.drawable.nature_5); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_6")) { kv.setBackgroundResource(R.drawable.nature_6); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_7")) { kv.setBackgroundResource(R.drawable.nature_7); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_8")) { kv.setBackgroundResource(R.drawable.nature_8); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_9")) { kv.setBackgroundResource(R.drawable.nature_9); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_10")) { kv.setBackgroundResource(R.drawable.nature_10); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_11")) { kv.setBackgroundResource(R.drawable.nature_11); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_12")) { kv.setBackgroundResource(R.drawable.nature_12); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_13")) { kv.setBackgroundResource(R.drawable.nature_13); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("nature_14")) { kv.setBackgroundResource(R.drawable.nature_14); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("black")) { kv.setBackgroundColor(getResources().getColor(R.color.black)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("white")) { kv.setBackgroundColor(getResources().getColor(R.color.white)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("transparent")) { kv.setBackgroundColor(getResources().getColor(R.color.transparent)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_1")) { kv.setBackgroundResource(R.drawable.gradient_1); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_2")) { kv.setBackgroundResource(R.drawable.gradient_2); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_3")) { kv.setBackgroundResource(R.drawable.gradient_3); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_4")) { kv.setBackgroundResource(R.drawable.gradient_4); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_5")) { kv.setBackgroundResource(R.drawable.gradient_5); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_6")) { kv.setBackgroundResource(R.drawable.gradient_6); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_7")) { kv.setBackgroundResource(R.drawable.gradient_7); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_8")) { kv.setBackgroundResource(R.drawable.gradient_8); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_9")) { kv.setBackgroundResource(R.drawable.gradient_9); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("gradient_10")) { kv.setBackgroundResource(R.drawable.gradient_10); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("red")) { kv.setBackgroundColor(getResources().getColor(R.color.red)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("pink")) { kv.setBackgroundColor(getResources().getColor(R.color.pink)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("purple")) { kv.setBackgroundColor(getResources().getColor(R.color.purple)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("blue")) { kv.setBackgroundColor(getResources().getColor(R.color.blue)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("green")) { kv.setBackgroundColor(getResources().getColor(R.color.green)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("yellow")) { kv.setBackgroundColor(getResources().getColor(R.color.yellow)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("orange")) { kv.setBackgroundColor(getResources().getColor(R.color.orange)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("grey")) { kv.setBackgroundColor(getResources().getColor(R.color.grey)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("lightred")) { kv.setBackgroundColor(getResources().getColor(R.color.lightred)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("lightpink")) { kv.setBackgroundColor(getResources().getColor(R.color.lightpink)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("lightpurple")) { kv.setBackgroundColor(getResources().getColor(R.color.lightpurple)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("lightblue")) { kv.setBackgroundColor(getResources().getColor(R.color.lightblue)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("lightgreen")) { kv.setBackgroundColor(getResources().getColor(R.color.lightgreen)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("lightyellow")) { kv.setBackgroundColor(getResources().getColor(R.color.lightyellow)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("lightorange")) { kv.setBackgroundColor(getResources().getColor(R.color.lightorange)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("lightgrey")) { kv.setBackgroundColor(getResources().getColor(R.color.lightgrey)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("darkred")) { kv.setBackgroundColor(getResources().getColor(R.color.darkred)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("darkpink")) { kv.setBackgroundColor(getResources().getColor(R.color.darkpink)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("darkpurple")) { kv.setBackgroundColor(getResources().getColor(R.color.darkpurple)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("darkblue")) { kv.setBackgroundColor(getResources().getColor(R.color.darkblue)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("darkgreen")) { kv.setBackgroundColor(getResources().getColor(R.color.darkgreen)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("darkyellow")) { kv.setBackgroundColor(getResources().getColor(R.color.darkyellow)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("darkorange")) { kv.setBackgroundColor(getResources().getColor(R.color.darkorange)); } else if (Preferences.getDefaults("bgcolor", getApplicationContext()).equals("darkgrey")) { kv.setBackgroundColor(getResources().getColor(R.color.darkgrey)); } else { String uploadString = Preferences.getDefaults("bgcolor", getApplicationContext()); byte[] decodedString = Base64.decode(uploadString, Base64.URL_SAFE); Bitmap photo = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length); BitmapDrawable bdrawable = new BitmapDrawable(getApplication().getResources(), photo); kv.setBackgroundDrawable(bdrawable); } if (Preferences.getDefaults("autocapitalize", getApplicationContext()).equals("true")) { autoCapitalize = true; } else if (Preferences.getDefaults("autocapitalize", getApplicationContext()).equals("false")) { autoCapitalize = false; } if (Preferences.getDefaults("volumebuttons", getApplicationContext()).equals("true")) { volumeButtons = true; } else if (Preferences.getDefaults("volumebuttons", getApplicationContext()).equals("false")) { volumeButtons = false; } if (Preferences.getDefaults("allcaps", getApplicationContext()).equals("true")) { allCaps = true; } else if (Preferences.getDefaults("allcaps", getApplicationContext()).equals("false")) { allCaps = false; } if (Preferences.getDefaults("autospacing", getApplicationContext()).equals("true")) { autoSpacing = true; } else if (Preferences.getDefaults("autospacing", getApplicationContext()).equals("false")) { autoSpacing = false; } if (Preferences.getDefaults("changekeyboard", getApplicationContext()).equals("true")) { changeKeyboard = true; } else if (Preferences.getDefaults("changekeyboard", getApplicationContext()).equals("false")) { changeKeyboard = false; } if (Preferences.getDefaults("shakedelete", getApplicationContext()).equals("true")) { shakeDelete = true; } else if (Preferences.getDefaults("shakedelete", getApplicationContext()).equals("false")) { shakeDelete = false; } if (Preferences.getDefaults("doublespace", getApplicationContext()).equals("true")) { spaceDot = true; } else if (Preferences.getDefaults("doublespace", getApplicationContext()).equals("false")) { spaceDot = false; } if (Preferences.getDefaults("voiceinput", getApplicationContext()).equals("true")) { voiceInput = true; } else if (Preferences.getDefaults("voiceinout", getApplicationContext()).equals("false")) { voiceInput = false; } if (Preferences.getDefaults("popup", getApplicationContext()).equals("true")) { popupKeypress = true; } else if (Preferences.getDefaults("popup", getApplicationContext()).equals("false")) { popupKeypress = false; } if (Preferences.getDefaults("oppositecase", getApplicationContext()).equals("true")) { oppositeCase = true; } else if (Preferences.getDefaults("oppositecase", getApplicationContext()).equals("false")) { oppositeCase = false; } if (changeKeyboard) { MovementDetector.getInstance(getApplicationContext()).start(); MovementDetector.getInstance(getApplicationContext()).addListener(new MovementDetector.Listener() { @Override public void onMotionDetected(SensorEvent event, float acceleration) { if (MovementDetector.direction[1].equals("LEFT")) { playSwipeH(); onSwipeLeft(); } else if (MovementDetector.direction[1].equals("RIGHT")) { playSwipeH(); onSwipeRight(); } if (MovementDetector.direction[0].equals("UP")) { playSwipeV(); onSwipeUp(); } else if (MovementDetector.direction[0].equals("DOWN")) { playSwipeV(); onSwipeDown(); } } }); } keypresscounter1 = Preferences.getDefaults("keypresscounter1", getApplicationContext()); keypresscounter2 = Preferences.getDefaults("keypresscounter2", getApplicationContext()); keypresscounter3 = Preferences.getDefaults("keypresscounter3", getApplicationContext()); keyPressCounter = Integer.parseInt(Preferences.getDefaults("keypresses", getApplicationContext())); time1 = Preferences.getDefaults("time1", getApplicationContext()); time2 = Preferences.getDefaults("time2", getApplicationContext()); time3 = Preferences.getDefaults("time3", getApplicationContext()); time = Integer.parseInt(Preferences.getDefaults("time", getApplicationContext())); tTime = new CountDownTimer(60000, 1000) { @Override public void onTick(long millisUntilFinished) { time = time + 1; if (time > 300 && time <= 960 && time1.equals("false")) { NotificationManager notif = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); Notification notify = new Notification(R.drawable.notify, "Ecloga Keyboard", System.currentTimeMillis()); PendingIntent pending = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(getApplicationContext(), Home.class), 0); notify.setLatestEventInfo(getApplicationContext(), "Warming up!", "Type more than 360 seconds", pending); notif.notify(0, notify); Preferences.setDefaults("time1", "true", getApplicationContext()); } else if (time > 960 && time <= 3600 && time2.equals("false")) { NotificationManager notif = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); Notification notify = new Notification(R.drawable.notify, "Ecloga Keyboard", System.currentTimeMillis()); PendingIntent pending = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(getApplicationContext(), Home.class), 0); notify.setLatestEventInfo(getApplicationContext(), "Keep it up!", "Type more than 960 seconds", pending); notif.notify(0, notify); Preferences.setDefaults("time2", "true", getApplicationContext()); } else if (time > 3600 && time3.equals("false")) { NotificationManager notif = (NotificationManager) getSystemService( Context.NOTIFICATION_SERVICE); Notification notify = new Notification(R.drawable.notify, "Ecloga Keyboard", System.currentTimeMillis()); PendingIntent pending = PendingIntent.getActivity(getApplicationContext(), 0, new Intent(getApplicationContext(), Home.class), 0); notify.setLatestEventInfo(getApplicationContext(), "Typing master!", "Type more than 3600 seconds", pending); notif.notify(0, notify); Preferences.setDefaults("time3", "true", getApplicationContext()); } Preferences.setDefaults("time", String.valueOf(time), getApplicationContext()); } @Override public void onFinish() { tTime.start(); } }.start(); if (popupKeypress) { kv.setPreviewEnabled(true); } else { kv.setPreviewEnabled(false); } if (shakeDelete) { mShaker = new ShakeListener(this); mShaker.setOnShakeListener(new ShakeListener.OnShakeListener() { public void onShake() { InputConnection ic = getCurrentInputConnection(); ic.deleteSurroundingText(500, 500); } }); } super.onStartInputView(info, restarting); }
From source file:piuk.blockchain.android.MyWallet.java
public static String decrypt(String ciphertext, String password, final int PBKDF2Iterations) throws Exception { byte[] cipherdata = Base64.decode(ciphertext, Base64.NO_WRAP); //Sperate the IV and cipher data byte[] iv = copyOfRange(cipherdata, 0, AESBlockSize * 4); byte[] input = copyOfRange(cipherdata, AESBlockSize * 4, cipherdata.length); PBEParametersGenerator generator = new PKCS5S2ParametersGenerator(); generator.init(PBEParametersGenerator.PKCS5PasswordToUTF8Bytes(password.toCharArray()), iv, PBKDF2Iterations);/* w w w . j a v a 2s. com*/ KeyParameter keyParam = (KeyParameter) generator.generateDerivedParameters(256); CipherParameters params = new ParametersWithIV(keyParam, iv); // setup AES cipher in CBC mode with PKCS7 padding BlockCipherPadding padding = new ISO10126d2Padding(); BufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESEngine()), padding); cipher.reset(); cipher.init(false, params); // create a temporary buffer to decode into (it'll include padding) byte[] buf = new byte[cipher.getOutputSize(input.length)]; int len = cipher.processBytes(input, 0, input.length, buf, 0); len += cipher.doFinal(buf, len); // remove padding byte[] out = new byte[len]; System.arraycopy(buf, 0, out, 0, len); // return string representation of decoded bytes return new String(out, "UTF-8"); }
From source file:eu.codeplumbers.cosi.services.CosiContactService.java
/** * Make remote request to get all calls stored in Cozy *///w w w .ja va 2 s. c om public void getRemoteContacts() { URL urlO = null; try { urlO = new URL(designUrl); HttpURLConnection conn = (HttpURLConnection) urlO.openConnection(); conn.setConnectTimeout(5000); conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8"); conn.setRequestProperty("Authorization", authHeader); conn.setDoInput(true); conn.setRequestMethod("POST"); // read the response int status = conn.getResponseCode(); InputStream in = null; if (status >= HttpURLConnection.HTTP_BAD_REQUEST) { in = conn.getErrorStream(); } else { in = conn.getInputStream(); } StringWriter writer = new StringWriter(); IOUtils.copy(in, writer, "UTF-8"); String result = writer.toString(); JSONArray jsonArray = new JSONArray(result); if (jsonArray != null) { if (jsonArray.length() == 0) { EventBus.getDefault() .post(new ContactSyncEvent(SYNC_MESSAGE, "Your Cozy has no contacts stored.")); Contact.setAllUnsynced(); } else { for (int i = 0; i < jsonArray.length(); i++) { Log.d("Contact", i + ""); EventBus.getDefault().post(new ContactSyncEvent(SYNC_MESSAGE, "Reading contacts on Cozy " + (i + 1) + "/" + jsonArray.length() + "...")); try { JSONObject contactJson = jsonArray.getJSONObject(i).getJSONObject("value"); Contact contact = Contact.getByRemoteId(contactJson.get("_id").toString()); if (contact == null) { contact = Contact.getByName(contactJson.getString("n")); if (contact == null) { contact = new Contact(contactJson); } else { if (contactJson.has("n")) contact.setN(contactJson.getString("n")); else contact.setN(""); if (contactJson.has("fn")) contact.setFn(contactJson.getString("fn")); else contact.setFn(""); if (contactJson.has("revision")) { contact.setRevision(contactJson.getString("revision")); } else { contact.setRevision(DateUtils.formatDate(new Date().getTime())); } if (contactJson.has("tags") && !contactJson.getString("tags").equalsIgnoreCase("")) { contact.setTags(contactJson.getJSONArray("tags").toString()); } else { contact.setTags(new JSONArray().toString()); } contact.setPhotoBase64(""); contact.setAnniversary(""); if (contactJson.has("deviceId")) { contact.setDeviceId(contactJson.getString("deviceId")); } if (contactJson.has("systemId")) { contact.setSystemId(contactJson.getString("systemId")); } contact.setRemoteId(contactJson.getString("_id")); if (contactJson.has("_attachments")) { JSONObject attachment = contactJson.getJSONObject("_attachments"); contact.setAttachments(attachment.toString()); if (attachment.has("picture")) { JSONObject picture = attachment.getJSONObject("picture"); String attachmentName = new String( Base64.decode(picture.getString("digest").replace("md5-", ""), Base64.DEFAULT)); Log.d("Contact", attachmentName); } } contact.save(); if (contactJson.has("datapoints")) { JSONArray datapoints = contactJson.getJSONArray("datapoints"); for (int j = 0; j < datapoints.length(); j++) { JSONObject datapoint = datapoints.getJSONObject(j); String value = datapoint.getString("value"); ContactDataPoint contactDataPoint = ContactDataPoint.getByValue(contact, value); if (contactDataPoint == null && !value.isEmpty()) { contactDataPoint = new ContactDataPoint(); contactDataPoint.setPref(false); contactDataPoint.setType(datapoint.getString("type")); contactDataPoint.setValue(value); contactDataPoint.setName(datapoint.getString("name")); contactDataPoint.setContact(contact); contactDataPoint.save(); } } } } } else { if (contactJson.has("n")) contact.setN(contactJson.getString("n")); else contact.setN(""); if (contactJson.has("fn")) contact.setFn(contactJson.getString("fn")); else contact.setFn(""); if (contactJson.has("revision")) { contact.setRevision(contactJson.getString("revision")); } else { contact.setRevision(DateUtils.formatDate(new Date().getTime())); } if (contactJson.has("tags") && !contactJson.getString("tags").equalsIgnoreCase("")) { contact.setTags(contactJson.getJSONArray("tags").toString()); } else { contact.setTags(new JSONArray().toString()); } contact.setPhotoBase64(""); contact.setAnniversary(""); if (contactJson.has("deviceId")) { contact.setDeviceId(contactJson.getString("deviceId")); } if (contactJson.has("systemId")) { contact.setSystemId(contactJson.getString("systemId")); } contact.setRemoteId(contactJson.getString("_id")); if (contactJson.has("_attachments")) { JSONObject attachment = contactJson.getJSONObject("_attachments"); contact.setAttachments(attachment.toString()); if (attachment.has("picture")) { JSONObject picture = attachment.getJSONObject("picture"); String attachmentName = new String(Base64.decode( picture.getString("digest").replace("md5-", ""), Base64.DEFAULT)); Log.d("Contact", attachmentName); } } contact.save(); if (contactJson.has("datapoints")) { JSONArray datapoints = contactJson.getJSONArray("datapoints"); for (int j = 0; j < datapoints.length(); j++) { JSONObject datapoint = datapoints.getJSONObject(j); String value = datapoint.getString("value"); ContactDataPoint contactDataPoint = ContactDataPoint.getByValue(contact, value); if (contactDataPoint == null && !value.isEmpty()) { contactDataPoint = new ContactDataPoint(); contactDataPoint.setPref(false); contactDataPoint.setType(datapoint.getString("type")); contactDataPoint.setValue(value); contactDataPoint.setName(datapoint.getString("name")); contactDataPoint.setContact(contact); contactDataPoint.save(); } } } } contact.save(); allContacts.add(contact); } catch (JSONException e) { EventBus.getDefault() .post(new ContactSyncEvent(SERVICE_ERROR, e.getLocalizedMessage())); stopSelf(); } } } } else { errorMessage = new JSONObject(result).getString("error"); EventBus.getDefault().post(new ContactSyncEvent(SERVICE_ERROR, errorMessage)); stopSelf(); } in.close(); conn.disconnect(); } catch (MalformedURLException e) { EventBus.getDefault().post(new ContactSyncEvent(SERVICE_ERROR, e.getLocalizedMessage())); stopSelf(); } catch (ProtocolException e) { EventBus.getDefault().post(new ContactSyncEvent(SERVICE_ERROR, e.getLocalizedMessage())); stopSelf(); } catch (IOException e) { EventBus.getDefault().post(new ContactSyncEvent(SERVICE_ERROR, e.getLocalizedMessage())); stopSelf(); } catch (JSONException e) { EventBus.getDefault().post(new ContactSyncEvent(SERVICE_ERROR, e.getLocalizedMessage())); stopSelf(); } }
From source file:com.mattprecious.notisync.service.SecondaryService.java
/** * @param encodedString/*from w ww .jav a 2 s . com*/ * @return bitmap (from given string) */ public Bitmap stringToBitmap(String encodedString) { if (encodedString != null && !encodedString.equals("")) { try { byte[] encodeByte = Base64.decode(encodedString, Base64.DEFAULT); Bitmap bitmap = BitmapFactory.decodeByteArray(encodeByte, 0, encodeByte.length); return bitmap; } catch (Exception e) { e.getMessage(); return null; } } return null; }
From source file:com.example.SmartBoard.MQTTHandler.java
public static Bitmap stringToBitmap(String encodedBitmap) { byte[] bitmapBytesOptImg = Base64.decode(encodedBitmap, Base64.DEFAULT); return BitmapFactory.decodeByteArray(bitmapBytesOptImg, 0, bitmapBytesOptImg.length); }
From source file:ru.gkpromtech.exhibition.db.Table.java
private ContentValues jsonToRow(ObjectNode object) throws IllegalAccessException, ParseException { ContentValues values = new ContentValues(); for (int i = 0; i < mFields.length; ++i) { String fieldName = mFields[i].getName(); JsonNode field = object.get(fieldName); if (field == null) continue; if (field.isNull()) { values.putNull(mColumns[i]); continue; }// ww w . j a v a 2s . c om switch (mType[i]) { case INTEGER: values.put(mColumns[i], field.asInt()); break; case SHORT: values.put(mColumns[i], (short) field.asInt()); break; case LONG: values.put(mColumns[i], field.asLong()); break; case FLOAT: values.put(mColumns[i], (float) field.asDouble()); break; case DOUBLE: values.put(mColumns[i], field.asDouble()); break; case STRING: values.put(mColumns[i], field.asText()); break; case BYTE_ARRAY: values.put(mColumns[i], Base64.decode(field.asText(), Base64.DEFAULT)); break; case DATE: values.put(mColumns[i], mDateFormat.parse(field.asText()).getTime()); break; case BOOLEAN: values.put(mColumns[i], field.asBoolean() ? 1 : 0); break; } } return values; }
From source file:be.blinkt.openvpn.activities.MainActivity.java
public void onResume() { super.onResume(); try {//from ww w. j av a 2 s .c o m AppConfiguration appConf = getManagedConfiguration(); if (appConf != null) { String commonConfStr = new String(Base64.decode(appConf.getCommonConfiguration(), Base64.DEFAULT)); String userConfStr = new String(Base64.decode(appConf.getUserConfiguration(), Base64.DEFAULT)); Reader reader = new StringReader((commonConfStr + userConfStr)); ProfileManager pm = ProfileManager.getInstance(this); if (pm.getProfileByName("afw_vpn") == null) { ConfigParser confParser = new ConfigParser(); confParser.parseConfig(reader); VpnProfile profile = confParser.convertProfile(); //profile.mUsername = "jan"; //profile.mPassword = "jan"; profile.mName = "afw_vpn"; pm.addProfile(profile); profile.mAllowedAppsVpnAreDisallowed = false; String allowedApps = appConf.getAllowedApps(); String[] allowedAppsArray = allowedApps.split(","); for (String allowedApp : allowedAppsArray) profile.mAllowedAppsVpn.add(allowedApp); profile.writeConfigFile(this); } else { System.out.println("Profile already exists, not creating new"); } } else { System.out.println("EMPTY CONF"); } } catch (Exception e) { System.out.println("Exception managed profile: " + e); } }
From source file:ch.ethz.twimight.net.opportunistic.ScanningService.java
private boolean saveFile(File file, String fileContent) { try {//from w w w . j ava 2 s . c o m FileOutputStream fOut = new FileOutputStream(file); byte[] decodedString = Base64.decode(fileContent, Base64.DEFAULT); fOut.write(decodedString); fOut.close(); return true; } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return false; }
From source file:se.leap.bitmaskclient.ProviderAPI.java
private String base64toHex(String base64_input) { byte[] byteArray = Base64.decode(base64_input, Base64.DEFAULT); int readBytes = byteArray.length; StringBuffer hexData = new StringBuffer(); int onebyte;//from ww w . j a va 2 s . c o m for (int i = 0; i < readBytes; i++) { onebyte = ((0x000000ff & byteArray[i]) | 0xffffff00); hexData.append(Integer.toHexString(onebyte).substring(6)); } return hexData.toString(); }
From source file:piuk.blockchain.android.MyWallet.java
public static ECKey decodeBase64PK(String base64Priv) throws Exception { byte[] privBytes = Base64.decode(base64Priv, Base64.NO_PADDING); // Prppend a zero byte to make the biginteger unsigned byte[] appendZeroByte = ArrayUtils.addAll(new byte[1], privBytes); ECKey ecKey = new ECKey(new BigInteger(appendZeroByte)); return ecKey; }