public void setIndicator(string indicatorName) { if (TextUtils.IsEmpty(indicatorName)) { return; } Java.Lang.StringBuilder drawableClassName = new Java.Lang.StringBuilder(); if (!indicatorName.Contains(".")) { string defaultPackageName = Class.Package.Name; drawableClassName.Append(defaultPackageName) .Append(".indicators") .Append("."); } drawableClassName.Append(indicatorName); try { Class drawableClass = Class.ForName(drawableClassName.ToString()); CustomIndicator indicator = (CustomIndicator)drawableClass.NewInstance(); setIndicator(indicator); } catch (ClassNotFoundException e) { //Log.e(TAG, "Didn't find your class , check the name again !"); } catch (InstantiationException e) { } catch (IllegalAccessException e) { //e.printStackTrace(); } }
private string BuildFileName() { Java.Lang.StringBuilder sb = new Java.Lang.StringBuilder(); sb.Append(ObtainCurrentTimeStamp()); sb.Append(JSON_EXTENSION); return(sb.ToString()); }
public string getDescription() { string description = ""; try { Java.Lang.Process process = Runtime.GetRuntime().Exec("logcat -d HockeyApp:D *:S"); BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.InputStream)); Java.Lang.StringBuilder log = new Java.Lang.StringBuilder(); string line; while ((line = bufferedReader.ReadLine()) != null) { log.Append(line); log.Append(System.Environment.NewLine); } bufferedReader.Close(); description = log.ToString(); } catch (IOException e) { } return(description); }
public void PushDigit(char digit) { if (!char.IsDigit(digit)) throw new IllegalArgumentException("Only numbers are allowed"); RemoveLeadingZeros(); if (_input.Length() < _maxDigits && (_input.Length() > 0 || digit != '0')) { _input.Append(digit); } PadWithZeros(); }
private string GetMacByInterface() { var networkInterfaces = Collections.List(NetworkInterface.NetworkInterfaces); foreach (NetworkInterface networkInterface in networkInterfaces) { if (networkInterface.Name.Equals("wlan0")) { var macBytes = networkInterface.GetHardwareAddress(); if (macBytes == null) { return(null); } var mac = new Java.Lang.StringBuilder(); foreach (byte b in macBytes) { mac.Append(b); } if (mac.Length() > 0) { mac.DeleteCharAt(mac.Length() - 1); } return(mac.ToString()); } } return(string.Empty); }
private void DisplayAddress(Address address) { try { if (address != null) { _deviceAddress = new StringBuilder(); for (int i = 0; i < address.MaxAddressLineIndex; i++) { _deviceAddress.Append(address.GetAddressLine(i)); } Monitor.Text += "\r\n --->Location changed new Lat:" + _currentLocation.Latitude + " Long:" + _currentLocation.Longitude; MainDictionary["latitude"] = _currentLocation.Latitude.ToString(); MainDictionary["longitude"] = _currentLocation.Longitude.ToString(); Monitor.Text += "\r\n ------>Adress: " + _deviceAddress.ToString(); MainDictionary["address"] = _deviceAddress.ToString(); } else { Monitor.Text += "------>Error on adress location: Unable to determine the address. Try again in a few minutes."; } } catch (Exception e) { Monitor.Text = e.Message; } }
string GetType(ShortcutInfo shortcut) { StringBuilder sb = new StringBuilder(); string sep = ""; if (shortcut.IsDynamic) { sb.Append(sep); sb.Append("Dynamic"); sep = ", "; } if (shortcut.IsPinned) { sb.Append(sep); sb.Append("Pinned"); sep = ", "; } if (!shortcut.IsEnabled) { sb.Append(sep); sb.Append("Disabled"); sep = ", "; } return(sb.ToString()); }
private int ExecProcess(IList<string> cmds, FFMpegCallbacks sc) { //ensure that the arguments are in the correct Locale format // TODO: Useless since SOX is called internally. Remove. for ( int i = 0; i < cmds.Count; i++) { cmds[i] = string.Format(System.Globalization.CultureInfo.GetCultureInfo("en-US"), "%s", cmds[i]); } ProcessBuilder pb = new ProcessBuilder(cmds); pb.Directory(fileBinDir); var cmdlog = new Java.Lang.StringBuilder(); foreach (string cmd in cmds) { cmdlog.Append(cmd); cmdlog.Append(' '); } sc.ShellOut(cmdlog.ToString()); pb.RedirectErrorStream(true); var process = pb.Start(); StreamGobbler errorGobbler = new StreamGobbler(this, process.ErrorStream, "ERROR", sc); StreamGobbler outputGobbler = new StreamGobbler(this, process.InputStream, "OUTPUT", sc); errorGobbler.Run(); outputGobbler.Run(); int exitVal = process.WaitFor(); while (outputGobbler.IsAlive || errorGobbler.IsAlive); sc.ProcessComplete(exitVal); return exitVal; }
public string getMsg(FaceAttribute attribute) { Java.Lang.StringBuilder msg = new Java.Lang.StringBuilder(); if (attribute != null) { msg.Append((int)attribute.Age).Append(",") .Append(attribute.Race == 0 ? "黄种人" : attribute.Race == 1 ? "白种人" : attribute.Race == 2 ? "黑人" : attribute.Race == 3 ? "印度人" : "地球人").Append(",") .Append(attribute.Expression == 0 ? "正常" : attribute.Expression == 1 ? "微笑" : "大笑").Append(",") .Append(attribute.Gender == 0 ? "女" : attribute.Gender == 1 ? "男" : "婴儿").Append(",") .Append(attribute.Glasses == 0 ? "不戴眼镜" : attribute.Glasses == 1 ? "普通透明眼镜" : "太阳镜"); } return(msg.ToString()); }
private static String ToHexFormat(byte[] bytes) { var builder = new StringBuilder(bytes.Length * 2); for (int i = 0; i < bytes.Length; i++) { String hex = Integer.ToHexString(bytes[i]); int length = hex.Length; if (length == 1) { hex = "0" + hex; } if (length > 2) { hex = hex.Substring(length - 2, length); } builder.Append(hex.ToUpper()); if (i < (bytes.Length - 1)) { builder.Append(':'); } } return(builder.ToString()); }
public static string GenerateJwe(string issuerId, string dataJson) { string jwePrivateKey = Constant.PrivateKey; string sessionKeyPublicKey = Constant.SessionPublicKey; string sessionKey = RandomUtils.GenerateSecureRandomFactor(16); JObject jObject = JObject.Parse(dataJson); jObject.Add("iss", issuerId); // The first part: JWE Head JweHeader jweHeader = GetHeader(); string jweHeaderEncode = GetEncodeHeader(jweHeader); // The Second part: JWE Encrypted Key string encryptedKeyEncode = GetEncryptedKey(sessionKey, sessionKeyPublicKey); // The third part: JWE IV sbyte[] iv = AESUtils.GetIvByte(12); string ivHexStr = new string(HwHex.EncodeHexString(iv)); //Java.Lang.String ivHexString = (Java.Lang.String)ivHexStr; string ivEncode = Base64.EncodeToString(Encoding.UTF8.GetBytes(ivHexStr), Base64Flags.UrlSafe | Base64Flags.NoWrap); // The fourth part: JWE CipherText empty string cipherTextEncode = GetCipherText(jObject.ToString(), sessionKey, iv, jweHeader); // The fifth part: JWE Authentication Tag string authenticationTagEncode = GetAuthenticationTag(jwePrivateKey, sessionKey, jObject.ToString(), jweHeaderEncode, ivEncode); Java.Lang.StringBuilder stringBuilder = new Java.Lang.StringBuilder(); return(stringBuilder.Append(jweHeaderEncode) .Append(".") .Append(encryptedKeyEncode) .Append(".") .Append(ivEncode) .Append(".") .Append(cipherTextEncode) .Append(".") .Append(authenticationTagEncode) .ToString()); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.activity_main); webviewPayment = (WebView)FindViewById(Resource.Id.webView1); webviewPayment.Settings.JavaScriptEnabled = true; webviewPayment.Settings.SetSupportZoom(true); webviewPayment.Settings.DomStorageEnabled = true; webviewPayment.Settings.LoadWithOverviewMode = true; webviewPayment.Settings.UseWideViewPort = true; webviewPayment.Settings.CacheMode = CacheModes.NoCache; webviewPayment.Settings.SetSupportMultipleWindows(true); webviewPayment.Settings.JavaScriptCanOpenWindowsAutomatically = true; webviewPayment.AddJavascriptInterface(new PayUJavaScriptInterface(this), "PayUMoney"); //JavaInterface Java.Lang.StringBuilder url_s = new Java.Lang.StringBuilder(); url_s.Append("https://test.payu.in/_payment"); //PauMoney Test URL Log.Info(TAG, "call url " + url_s); webviewPayment.PostUrl(url_s.ToString(), Encoding.UTF8.GetBytes(getPostString())); webviewPayment.SetWebViewClient(webViewClient); }
public string getMacAddreess(Context context) { try { System.Collections.IList all = Java.Util.Collections.List(Java.Net.NetworkInterface.NetworkInterfaces); foreach (Java.Net.NetworkInterface nif in all) { if (nif.Name != "wlan0") { continue; } byte[] macBytes = nif.GetHardwareAddress(); if (macBytes == null) { return(""); } var res1 = new Java.Lang.StringBuilder(); foreach (byte b in macBytes) { res1.Append(Integer.ToHexString(b & 0xFF) + ":"); } if (res1.Length() > 0) { res1.DeleteCharAt(res1.Length() - 1); } return(res1.ToString()); } } catch (Java.Lang.Exception ex) { } return("02:00:00:00:00:00"); }
protected override string RunInBackground(params Dictionary <string, string>[] @params) { HttpURLConnection uRLConnection = null; try { URL uRL = new URL(URL_STRING); uRLConnection = (HttpURLConnection)uRL.OpenConnection(); uRLConnection.ConnectTimeout = 15000; uRLConnection.ReadTimeout = 15000; var responseCode = uRLConnection.ResponseCode; if (responseCode == HttpStatus.Ok) { Java.Lang.StringBuilder stringBuilder = new Java.Lang.StringBuilder(); using (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(uRLConnection.InputStream))) { string line; while ((line = bufferedReader.ReadLine()) != null) { stringBuilder.Append(line); } } JObject jsonResponse = JObject.Parse(stringBuilder.ToString()); string chatUrl = jsonResponse[JSON_CHAT_URL].ToString(); chatUrl = chatUrl.Replace(PLACEHOLDER_LICENCE, @params[0].GetValueOrDefault(ChatWindowFragment.KEY_LICENCE_NUMBER)); chatUrl = chatUrl.Replace(PLACEHOLDER_GROUP, @params[0].GetValueOrDefault(ChatWindowFragment.KEY_GROUP_ID)); chatUrl += "&native_platform=android"; if (@params[0].GetValueOrDefault(ChatWindowFragment.KEY_VISITOR_NAME) != null) { chatUrl += $"&name={URLEncoder.Encode(@params[0].GetValueOrDefault(ChatWindowFragment.KEY_VISITOR_NAME), "UTF-8").Replace("+", "%20")}"; } if (@params[0].GetValueOrDefault(ChatWindowFragment.KEY_VISITOR_EMAIL) != null) { chatUrl += $"&email={URLEncoder.Encode(@params[0].GetValueOrDefault(ChatWindowFragment.KEY_VISITOR_EMAIL), "UTF-8")}"; } string customParams = EscapeCustomParams(@params[0], chatUrl); if (!TextUtils.IsEmpty(customParams)) { chatUrl += $"¶ms={customParams}"; } if (!chatUrl.StartsWith("http")) { chatUrl = $"https://{chatUrl}"; } return(chatUrl); } } catch (MalformedURLException e) { e.PrintStackTrace(); } catch (IOException e) { e.PrintStackTrace(); } catch (JSONException e) { e.PrintStackTrace(); } catch (SecurityException e) { Log.Error("LiveChat Widget", "Missing internet permission!"); e.PrintStackTrace(); } finally { if (uRLConnection != null) { try { uRLConnection.Disconnect(); } catch (Java.Lang.Exception ex) { ex.PrintStackTrace(); } } } return(null); }
//PostString is Append All parameters private string getPostString() { string TxtStr = Generate(); string txnid = hashCal("SHA-256", TxtStr).Substring(0, 20); txnid = "TXN" + txnid; string key = "gtKFFx"; //Key string salt = "eCwWELxi"; //salt //string key = "rjOJ4xFL"; //Key //string salt = "mGuhbSDFIl"; //salt Java.Lang.StringBuilder post = new Java.Lang.StringBuilder(); post.Append("key="); post.Append(key); post.Append("&"); post.Append("txnid="); post.Append(txnid); post.Append("&"); post.Append("amount="); post.Append(totalAmount); post.Append("&"); post.Append("productinfo="); post.Append(productInfo); post.Append("&"); post.Append("firstname="); post.Append(firstname); post.Append("&"); post.Append("email="); post.Append(email); post.Append("&"); post.Append("phone="); post.Append(mobile); post.Append("&"); post.Append("surl="); post.Append(SUCCESS_URL); post.Append("&"); post.Append("furl="); post.Append(FAILED_URL); post.Append("&"); Java.Lang.StringBuilder checkSumStr = new Java.Lang.StringBuilder(); //MessageDigest digest = null; string hash; try { //digest = MessageDigest.GetInstance("SHA-512");// MessageDigest.getInstance("SHA-256"); checkSumStr.Append(key); checkSumStr.Append("|"); checkSumStr.Append(txnid); checkSumStr.Append("|"); checkSumStr.Append(totalAmount); checkSumStr.Append("|"); checkSumStr.Append(productInfo); checkSumStr.Append("|"); checkSumStr.Append(firstname); checkSumStr.Append("|"); checkSumStr.Append(email); checkSumStr.Append("|||||||||||"); checkSumStr.Append(salt); //digest.Update(Encoding.ASCII.GetBytes(checkSumStr.ToString())); hash = hashCal("SHA-512", checkSumStr.ToString()); // hash = "6a064463509801d8d25b8f165f7bd85fa5fd619d724443bae9f826b5d7f97e9e77cac1cd594120e90caa563203065914102b5994df4b85a516e5c39a911a0d48";// hashCal("SHA -512", digest.ToString()); post.Append("hash="); post.Append(hash); post.Append("&"); Log.Info(TAG, "SHA result is " + hash); } catch (NoSuchAlgorithmException e1) { // TODO Auto-generated catch block e1.PrintStackTrace(); } post.Append("service_provider="); post.Append(""); return(post.ToString()); }
//PostString is Append All parameters private string getPostString() { string TxtStr = Generate(); string txnid = hashCal("SHA-256", TxtStr).Substring(0, 20); txnid = "TXN" + txnid; string key = "rjQUPktU"; //Key string salt = "e5iIg1jwi8"; //salt Java.Lang.StringBuilder post = new Java.Lang.StringBuilder(); post.Append("key="); post.Append(key); post.Append("&"); post.Append("txnid="); post.Append(txnid); post.Append("&"); post.Append("amount="); post.Append(totalAmount); post.Append("&"); post.Append("productinfo="); post.Append(productInfo); post.Append("&"); post.Append("firstname="); post.Append(firstname); post.Append("&"); post.Append("email="); post.Append(email); post.Append("&"); post.Append("phone="); post.Append(mobile); post.Append("&"); post.Append("surl="); post.Append(SUCCESS_URL); post.Append("&"); post.Append("furl="); post.Append(FAILED_URL); post.Append("&"); Java.Lang.StringBuilder checkSumStr = new Java.Lang.StringBuilder(); MessageDigest digest = null; string hash; try { digest = MessageDigest.GetInstance("SHA-512");// MessageDigest.getInstance("SHA-256"); checkSumStr.Append(key); checkSumStr.Append("|"); checkSumStr.Append(txnid); checkSumStr.Append("|"); checkSumStr.Append(totalAmount); checkSumStr.Append("|"); checkSumStr.Append(productInfo); checkSumStr.Append("|"); checkSumStr.Append(firstname); checkSumStr.Append("|"); checkSumStr.Append(email); checkSumStr.Append("|||||||||||"); checkSumStr.Append(salt); digest.Update(Encoding.ASCII.GetBytes(checkSumStr.ToString())); hash = bytesToHexString(digest.Digest()); post.Append("hash="); post.Append(hash); post.Append("&"); Log.Info(TAG, "SHA result is " + hash); } catch (NoSuchAlgorithmException e1) { // TODO Auto-generated catch block e1.PrintStackTrace(); } post.Append("service_provider="); post.Append("payu_paisa"); return(post.ToString()); }
/** * Returns a Session Description that can be stored in a file or sent to a client with RTSP. * @return The Session Description. * @throws IllegalStateException Thrown when {@link #setDestination(String)} has never been called. */ public System.String getSessionDescription() { Java.Lang.StringBuilder sessionDescription = new Java.Lang.StringBuilder(); if (mDestination == null) { throw new IllegalStateException("setDestination() has not been called !"); } sessionDescription.Append("v=0\r\n"); // TODO: Add IPV6 support sessionDescription.Append("o=- " + mTimestamp + " " + mTimestamp + " IN IP4 " + mOrigin + "\r\n"); sessionDescription.Append("s=Unnamed\r\n"); sessionDescription.Append("i=N/A\r\n"); sessionDescription.Append("c=IN IP4 " + mDestination + "\r\n"); // t=0 0 means the session is permanent (we don't know when it will stop) sessionDescription.Append("t=0 0\r\n"); sessionDescription.Append("a=recvonly\r\n"); // Prevents two different sessions from using the same peripheral at the same time if (mAudioStream != null) { sessionDescription.Append(mAudioStream.getSessionDescription()); sessionDescription.Append("a=control:trackID=" + 0 + "\r\n"); } if (mVideoStream != null) { sessionDescription.Append(mVideoStream.getSessionDescription()); sessionDescription.Append("a=control:trackID=" + 1 + "\r\n"); } return sessionDescription.ToString(); }
public static List <byte[]> DecodeBitmapToDataList(Bitmap image, int parting) { if (parting <= 0 || parting > 255) { parting = 255; } if (image == null) { return(null); } int width = image.Width; int height = image.Height; if (width <= 0 || height <= 0) { return(null); } if (width > 2040) { // 8位9针,宽度限制2040像素(但一般纸张都没法打印那么宽,但并不影响打印) float scale = 2040 / (float)width; Matrix matrix = new Matrix(); matrix.PostScale(scale, scale); Bitmap resizeImage; try { resizeImage = Bitmap.CreateBitmap(image, 0, 0, width, height, matrix, true); var datas = DecodeBitmapToDataList(resizeImage, parting); resizeImage.Recycle(); return(datas); } catch (OutOfMemoryError) { return(null); } } // 宽命令 string widthHexString = Integer.ToHexString(width % 8 == 0 ? width / 8 : (width / 8 + 1)); if (widthHexString.Length > 2) { // 超过2040像素才会到达这里 return(null); } else if (widthHexString.Length == 1) { widthHexString = "0" + widthHexString; } widthHexString += "00"; // 每行字节数(除以8,不足补0) string zeroStr = ""; int zeroCount = width % 8; if (zeroCount > 0) { for (int i = 0; i < (8 - zeroCount); i++) { zeroStr += "0"; } } List <string> commandList = new List <string>(); // 高度每parting像素进行一次分割 int time = height % parting == 0 ? height / parting : (height / parting + 1);// 循环打印次数 for (int t = 0; t < time; t++) { int partHeight = t == time - 1 ? height % parting : parting;// 分段高度 // 高命令 string heightHexString = Integer.ToHexString(partHeight); if (heightHexString.Length > 2) { // 超过255像素才会到达这里 return(null); } else if (heightHexString.Length == 1) { heightHexString = "0" + heightHexString; } heightHexString += "00"; // 宽高指令 string commandHexString = "1D763000"; commandList.Add(commandHexString + widthHexString + heightHexString); List <string> list = new List <string>(); //binaryString list Java.Lang.StringBuilder sb = new Java.Lang.StringBuilder(); // 像素二值化,非黑即白 for (int i = 0; i < partHeight; i++) { sb.Delete(0, sb.Length()); for (int j = 0; j < width; j++) { // 实际在图片中的高度 int startHeight = t * parting + i; //得到当前像素的值 int color = image.GetPixel(j, startHeight); int red, green, blue; if (image.HasAlpha) { //得到alpha通道的值 int alpha = Color.GetAlphaComponent(color); //得到图像的像素RGB的值 red = Color.GetRedComponent(color); green = Color.GetGreenComponent(color); blue = Color.GetBlueComponent(color); float offset = alpha / 255.0f; // 根据透明度将白色与原色叠加 red = 0xFF + (int)Java.Lang.Math.Ceil((red - 0xFF) * offset); green = 0xFF + (int)Java.Lang.Math.Ceil((green - 0xFF) * offset); blue = 0xFF + (int)Java.Lang.Math.Ceil((blue - 0xFF) * offset); } else { //得到图像的像素RGB的值 red = Color.GetRedComponent(color); green = Color.GetGreenComponent(color); blue = Color.GetBlueComponent(color); } // 接近白色改为白色。其余黑色 if (red > 160 && green > 160 && blue > 160) { sb.Append("0"); } else { sb.Append("1"); } } // 每一行结束时,补充剩余的0 if (zeroCount > 0) { sb.Append(zeroStr); } list.Add(sb.ToString()); } // binaryStr每8位调用一次转换方法,再拼合 List <string> bmpHexList = new List <string>(); foreach (string binaryStr in list) { sb.Delete(0, sb.Length()); for (int i = 0; i < binaryStr.Length; i += 8) { string str = binaryStr.Substring(i, i + 8); // 2进制转成16进制 string hexString = BinaryStrToHexString(str); sb.Append(hexString); } bmpHexList.Add(sb.ToString()); } // 数据指令 commandList.AddRange(bmpHexList); } List <byte[]> data = new List <byte[]>(); foreach (string hexStr in commandList) { data.Add(HexStringToBytes(hexStr)); } return(data); }
private static bool IsValidSync(string webDomain, string permission, string packageName, string fingerprint) { if (CommonUtil.DEBUG) { Log.Debug(CommonUtil.TAG, "validating domain " + webDomain + " for pkg " + packageName + " and fingerprint " + fingerprint + " for permission" + permission); } if (!webDomain.StartsWith("http:") && !webDomain.StartsWith("https:")) { // Unfortunately AssistStructure.ViewNode does not tell what the domain is, so let's // assume it's https webDomain = "https://" + webDomain; } var restUrl = string.Format(REST_TEMPLATE, webDomain, permission, packageName, fingerprint); if (CommonUtil.DEBUG) { Log.Debug(CommonUtil.TAG, "DAL REST request: " + restUrl); } HttpURLConnection urlConnection = null; var output = new StringBuilder(); try { var url = new URL(restUrl); urlConnection = (HttpURLConnection)url.OpenConnection(); using (BufferedReader reader = new BufferedReader(new InputStreamReader(urlConnection.InputStream))) { string line; while ((line = reader.ReadLine()) != null) { output.Append(line); } } var response = output.ToString(); if (CommonUtil.VERBOSE) { Log.Verbose(CommonUtil.TAG, "DAL REST Response: " + response); } var jsonObject = new JSONObject(response); bool valid = jsonObject.OptBoolean("linked", false); if (CommonUtil.DEBUG) { Log.Debug(CommonUtil.TAG, "Valid: " + valid); } return(valid); } catch (Exception e) { throw new RuntimeException("Failed to validate", e); } finally { urlConnection?.Disconnect(); } }