List of usage examples for android.util Base64 DEFAULT
int DEFAULT
To view the source code for android.util Base64 DEFAULT.
Click Source Link
From source file:com.farmerbb.notepad.fragment.NoteViewFragment.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override//from www. j a va2s . c o m public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); // Set values setRetainInstance(true); setHasOptionsMenu(true); // Get filename of saved note filename = getArguments().getString("filename"); // Change window title String title; try { title = listener.loadNoteTitle(filename); } catch (IOException e) { title = getResources().getString(R.string.view_note); } getActivity().setTitle(title); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { Bitmap bitmap = ((BitmapDrawable) ContextCompat.getDrawable(getActivity(), R.drawable.ic_recents_logo)) .getBitmap(); ActivityManager.TaskDescription taskDescription = new ActivityManager.TaskDescription(title, bitmap, ContextCompat.getColor(getActivity(), R.color.primary)); getActivity().setTaskDescription(taskDescription); } // Show the Up button in the action bar. ((AppCompatActivity) getActivity()).getSupportActionBar().setDisplayHomeAsUpEnabled(true); // Animate elevation change if (getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-large") && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { LinearLayout noteViewEdit = getActivity().findViewById(R.id.noteViewEdit); LinearLayout noteList = getActivity().findViewById(R.id.noteList); noteList.animate().z(0f); if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) noteViewEdit.animate() .z(getResources().getDimensionPixelSize(R.dimen.note_view_edit_elevation_land)); else noteViewEdit.animate().z(getResources().getDimensionPixelSize(R.dimen.note_view_edit_elevation)); } // Set up content view TextView noteContents = getActivity().findViewById(R.id.textView); markdownView = getActivity().findViewById(R.id.markdownView); // Apply theme SharedPreferences pref = getActivity().getSharedPreferences(getActivity().getPackageName() + "_preferences", Context.MODE_PRIVATE); ScrollView scrollView = getActivity().findViewById(R.id.scrollView); String theme = pref.getString("theme", "light-sans"); int textSize = -1; int textColor = -1; String fontFamily = null; if (theme.contains("light")) { if (noteContents != null) { noteContents.setTextColor(ContextCompat.getColor(getActivity(), R.color.text_color_primary)); noteContents.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background)); } if (markdownView != null) { markdownView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background)); textColor = ContextCompat.getColor(getActivity(), R.color.text_color_primary); } scrollView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background)); } if (theme.contains("dark")) { if (noteContents != null) { noteContents.setTextColor(ContextCompat.getColor(getActivity(), R.color.text_color_primary_dark)); noteContents .setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark)); } if (markdownView != null) { markdownView .setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark)); textColor = ContextCompat.getColor(getActivity(), R.color.text_color_primary_dark); } scrollView.setBackgroundColor(ContextCompat.getColor(getActivity(), R.color.window_background_dark)); } if (theme.contains("sans")) { if (noteContents != null) noteContents.setTypeface(Typeface.SANS_SERIF); if (markdownView != null) fontFamily = "sans-serif"; } if (theme.contains("serif")) { if (noteContents != null) noteContents.setTypeface(Typeface.SERIF); if (markdownView != null) fontFamily = "serif"; } if (theme.contains("monospace")) { if (noteContents != null) noteContents.setTypeface(Typeface.MONOSPACE); if (markdownView != null) fontFamily = "monospace"; } switch (pref.getString("font_size", "normal")) { case "smallest": textSize = 12; break; case "small": textSize = 14; break; case "normal": textSize = 16; break; case "large": textSize = 18; break; case "largest": textSize = 20; break; } if (noteContents != null) noteContents.setTextSize(textSize); String css = ""; if (markdownView != null) { String topBottom = " " + Float.toString(getResources().getDimension(R.dimen.padding_top_bottom) / getResources().getDisplayMetrics().density) + "px"; String leftRight = " " + Float.toString(getResources().getDimension(R.dimen.padding_left_right) / getResources().getDisplayMetrics().density) + "px"; String fontSize = " " + Integer.toString(textSize) + "px"; String fontColor = " #" + StringUtils.remove(Integer.toHexString(textColor), "ff"); String linkColor = " #" + StringUtils.remove( Integer.toHexString(new TextView(getActivity()).getLinkTextColors().getDefaultColor()), "ff"); css = "body { " + "margin:" + topBottom + topBottom + leftRight + leftRight + "; " + "font-family:" + fontFamily + "; " + "font-size:" + fontSize + "; " + "color:" + fontColor + "; " + "}" + "a { " + "color:" + linkColor + "; " + "}"; markdownView.getSettings().setJavaScriptEnabled(false); markdownView.getSettings().setLoadsImagesAutomatically(false); markdownView.setWebViewClient(new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) try { startActivity(intent); } catch (ActivityNotFoundException | FileUriExposedException e) { /* Gracefully fail */ } else try { startActivity(intent); } catch (ActivityNotFoundException e) { /* Gracefully fail */ } return true; } }); } // Load note contents try { contentsOnLoad = listener.loadNote(filename); } catch (IOException e) { showToast(R.string.error_loading_note); // Add NoteListFragment or WelcomeFragment Fragment fragment; if (getActivity().findViewById(R.id.layoutMain).getTag().equals("main-layout-normal")) fragment = new NoteListFragment(); else fragment = new WelcomeFragment(); getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteListFragment") .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN).commit(); } // Set TextView contents if (noteContents != null) noteContents.setText(contentsOnLoad); if (markdownView != null) markdownView.loadMarkdown(contentsOnLoad, "data:text/css;base64," + Base64.encodeToString(css.getBytes(), Base64.DEFAULT)); // Show a toast message if this is the user's first time viewing a note final SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE); firstLoad = sharedPref.getInt("first-load", 0); if (firstLoad == 0) { // Show dialog with info DialogFragment firstLoad = new FirstViewDialogFragment(); firstLoad.show(getFragmentManager(), "firstloadfragment"); // Set first-load preference to 1; we don't need to show the dialog anymore SharedPreferences.Editor editor = sharedPref.edit(); editor.putInt("first-load", 1); editor.apply(); } // Detect single and double-taps using GestureDetector final GestureDetector detector = new GestureDetector(getActivity(), new GestureDetector.OnGestureListener() { @Override public boolean onSingleTapUp(MotionEvent e) { return false; } @Override public void onShowPress(MotionEvent e) { } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { return false; } @Override public void onLongPress(MotionEvent e) { } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { return false; } @Override public boolean onDown(MotionEvent e) { return false; } }); detector.setOnDoubleTapListener(new GestureDetector.OnDoubleTapListener() { @Override public boolean onDoubleTap(MotionEvent e) { if (sharedPref.getBoolean("show_double_tap_message", true)) { SharedPreferences.Editor editor = sharedPref.edit(); editor.putBoolean("show_double_tap_message", false); editor.apply(); } Bundle bundle = new Bundle(); bundle.putString("filename", filename); Fragment fragment = new NoteEditFragment(); fragment.setArguments(bundle); getFragmentManager().beginTransaction().replace(R.id.noteViewEdit, fragment, "NoteEditFragment") .commit(); return false; } @Override public boolean onDoubleTapEvent(MotionEvent e) { return false; } @Override public boolean onSingleTapConfirmed(MotionEvent e) { if (sharedPref.getBoolean("show_double_tap_message", true) && showMessage) { showToastLong(R.string.double_tap); showMessage = false; } return false; } }); if (noteContents != null) noteContents.setOnTouchListener((v, event) -> { detector.onTouchEvent(event); return false; }); if (markdownView != null) markdownView.setOnTouchListener((v, event) -> { detector.onTouchEvent(event); return false; }); }
From source file:mobisocial.bento.todo.io.BentoManager.java
synchronized public void addTodo(TodoListItem item, Bitmap image, String msg) { mBento.bento.todoList.add(0, item);/*from w w w. j a va 2 s . co m*/ if (image == null) { pushUpdate(msg); } else { String data = Base64.encodeToString(BitmapHelper.bitmapToBytes(image), Base64.DEFAULT); pushUpdate(msg, item.uuid, data, false); } }
From source file:org.telegram.android.MessagesController.java
public void updateConfig(final TLRPC.TL_config config) { AndroidUtilities.runOnUIThread(new Runnable() { //TODO use new config params @Override//from ww w.j av a 2s .c o m public void run() { maxBroadcastCount = config.broadcast_size_max; maxGroupCount = config.chat_size_max; groupBigSize = config.chat_big_size; disabledFeatures = config.disabled_features; SharedPreferences preferences = ApplicationLoader.applicationContext .getSharedPreferences("mainconfig", Activity.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); editor.putInt("maxGroupCount", maxGroupCount); editor.putInt("maxBroadcastCount", maxBroadcastCount); editor.putInt("groupBigSize", groupBigSize); try { SerializedData data = new SerializedData(); data.writeInt32(disabledFeatures.size()); for (TLRPC.TL_disabledFeature disabledFeature : disabledFeatures) { disabledFeature.serializeToStream(data); } String string = Base64.encodeToString(data.toByteArray(), Base64.DEFAULT); if (string != null && string.length() != 0) { editor.putString("disabledFeatures", string); } } catch (Exception e) { editor.remove("disabledFeatures"); FileLog.e("tmessages", e); } editor.commit(); } }); }
From source file:com.remobile.file.LocalFilesystem.java
@Override public long writeToFileAtURL(LocalFilesystemURL inputURL, String data, int offset, boolean isBinary) throws IOException, NoModificationAllowedException { boolean append = false; if (offset > 0) { this.truncateFileAtURL(inputURL, offset); append = true;//from w w w . ja va2 s .co m } byte[] rawData; if (isBinary) { rawData = Base64.decode(data, Base64.DEFAULT); } else { rawData = data.getBytes(); } ByteArrayInputStream in = new ByteArrayInputStream(rawData); try { byte buff[] = new byte[rawData.length]; String absolutePath = filesystemPathForURL(inputURL); FileOutputStream out = new FileOutputStream(absolutePath, append); try { in.read(buff, 0, buff.length); out.write(buff, 0, rawData.length); out.flush(); } finally { // Always close the output out.close(); } if (isPublicDirectory(absolutePath)) { broadcastNewFile(Uri.fromFile(new File(absolutePath))); } } catch (NullPointerException e) { // This is a bug in the Android implementation of the Java Stack NoModificationAllowedException realException = new NoModificationAllowedException(inputURL.toString()); throw realException; } return rawData.length; }
From source file:com.diona.fileReader.CipherUtil.java
/** * Generates a random Base64 encoded string value. * //from w w w .j av a 2 s . c om * @param length * The length of the key. * @return A random key value. */ public String generateRandomKeyString(final int length) { return Base64.encodeToString(generateRandomKeyBytes(length), Base64.DEFAULT); }
From source file:com.aknowledge.v1.automation.RemoteActivity.java
private void doCommand(String myTag, String command) { final String curCommand = command; final String curTag = myTag; HashMap<String, String> params = new HashMap<String, String>(); params.put("command=", "off"); Log.d("RemoteActivity", "doCommand:" + hostname + "/api/device/" + myTag + " " + params.toString()); JsonObjectRequest req = new JsonObjectRequest(Method.POST, hostname + "/api/device/" + myTag, null, new Response.Listener<JSONObject>() { @Override//from ww w. j ava 2 s.co m public void onResponse(JSONObject response) { if (dialog != null && dialog.isShowing()) { dialog.dismiss(); } Log.d("RemoteActivity", "doCommand" + response.toString()); for (PytoDevice dev : myDevices) { View myView = remoteFrag.getView().findViewWithTag(curTag); if (dev.getDevID().equalsIgnoreCase(curTag)) { try { String devState = response.getString("state"); dev.setDevState(devState); if (devState.equalsIgnoreCase("on")) { myView.setBackgroundResource(R.drawable.light_bulb_on); } else { if (devState.equalsIgnoreCase("off")) { myView.setBackgroundResource(R.drawable.light_bulb_off); } else { myView.setBackgroundResource(R.drawable.light_bulb_dimmed); } } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } // pDialog.hide(); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) { Log.d("RemoteActivity", "doCommand Error: " + error.getMessage()); // pDialog.hide(); } }) { @Override public Map<String, String> getHeaders() throws AuthFailureError { HashMap<String, String> headers = new HashMap<String, String>(); String authString = user + ":" + pass; String encodedPass = null; try { encodedPass = Base64.encodeToString(authString.getBytes(), Base64.DEFAULT); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } Log.d("Remote Activity", pass + " " + encodedPass); // headers.put("Content-Type", "application/json"); headers.put("Authorization", "Basic " + encodedPass); return headers; } @Override public byte[] getBody() { // Map<String, String> params = new HashMap<String, String>(); // params.put("command", "on"); // params.put("email", "abc@androidhive.info"); // params.put("password", "password123"); String params = "command=" + curCommand; return params.getBytes(); } }; PyHomeController.getInstance().addToRequestQueue(req, commandTag); }
From source file:com.jrummyapps.android.safetynet.SafetyNetHelper.java
private SafetyNetVerification verify(SafetyNetResponse response) { Boolean isValidSignature = null; if (!TextUtils.isEmpty(apiKey)) { try {/*from www.j a v a 2 s. c om*/ isValidSignature = validate(response.jws, apiKey); } catch (SafetyNetError e) { Log.d(TAG, "An error occurred while using the Android Device Verification API", e); } } String nonce = Base64.encodeToString(this.nonce, Base64.DEFAULT).trim(); boolean isValidNonce = TextUtils.equals(nonce, response.nonce); long durationOfReq = response.timestampMs - requestTimestamp; boolean isValidResponseTime = durationOfReq < MAX_TIMESTAMP_DURATION; boolean isValidApkSignature = true; if (response.apkCertificateDigestSha256 != null && response.apkCertificateDigestSha256.length > 0) { isValidApkSignature = Arrays.equals(getApkCertificateDigests().toArray(), response.apkCertificateDigestSha256); } boolean isValidApkDigest = true; if (!TextUtils.isEmpty(response.apkDigestSha256)) { isValidApkDigest = TextUtils.equals(getApkDigestSha256(), response.apkDigestSha256); } return new SafetyNetVerification(isValidSignature, isValidNonce, isValidResponseTime, isValidApkSignature, isValidApkDigest); }
From source file:mobisocial.bento.ebento.io.EventManager.java
synchronized public void updateEvent(Event event, String msg, boolean bFirst) { mEvent = event;//w w w.ja va 2 s . co m String uuid = null; String data = null; if (mEvent.image != null) { uuid = mEvent.uuid; data = Base64.encodeToString(BitmapHelper.bitmapToBytes(mEvent.image), Base64.DEFAULT); } pushUpdate(msg, uuid, data, bFirst); }
From source file:com.theonespy.util.Util.java
public static String encodeToBase64(Bitmap image) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); image.compress(Bitmap.CompressFormat.JPEG, 100, outputStream); byte[] b = outputStream.toByteArray(); return Base64.encodeToString(b, Base64.DEFAULT); }
From source file:com.android.server.wifi.WifiLogger.java
private static String compressToBase64(byte[] input) { String result;/* w ww .j a va 2s . c om*/ //compress Deflater compressor = new Deflater(); compressor.setLevel(Deflater.BEST_COMPRESSION); compressor.setInput(input); compressor.finish(); ByteArrayOutputStream bos = new ByteArrayOutputStream(input.length); final byte[] buf = new byte[1024]; while (!compressor.finished()) { int count = compressor.deflate(buf); bos.write(buf, 0, count); } try { compressor.end(); bos.close(); } catch (IOException e) { Log.e(TAG, "ByteArrayOutputStream close error"); result = android.util.Base64.encodeToString(input, Base64.DEFAULT); return result; } byte[] compressed = bos.toByteArray(); if (DBG) { Log.d(TAG, " length is:" + (compressed == null ? "0" : compressed.length)); } //encode result = android.util.Base64.encodeToString(compressed.length < input.length ? compressed : input, Base64.DEFAULT); if (DBG) { Log.d(TAG, "FwMemoryDump length is :" + result.length()); } return result; }