hi dear developers .
I want to create an app (something like a compiler) and now i am working on key entery of keyboard
for example I want to control these keys '{' , '}' , '(' , ')' and etc.
I put a textbox in my app .
in Key_Down event i write down these codes :
Code:
private void CompilerTextBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
if(e.Key == System.Windows.Input.Key.)
}
but i see there's no special characters like these things I'm looking for .
after that I tried this code to find what is the Key Code of these characters in WP8 :
Code:
private void CompilerTextBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
MessageBox.Show(e.PlatformKeyCode.ToString());
}
I received some Interesting result!
these characters are all using one Key Code : 142 !!!!!!!!!!!!!!!
it means '{' = 142 , '}' = 142 '[' = 142 , ']' = 142 , '(' = 142 , ')' = 142 !
what I have to do ?
Related
### Description:
I think that almost all themers gets tired when they needs to make resources-redirections file (at /res/xml/ folder).
### How to use it?
- Put themed icons to /acHelper/themed/ folder
- Run /acHelper/run.bat (If you're Linux user - launch achelper.jar by hands)
- Type icons prefix
- Enjoy
### Sources:
Code:
import java.io.File;
import java.io.IOException;
import java.io.FileWriter;
import java.util.Scanner;
import java.util.Date;
public class ThemeHelper {
private static final String VERSION_NAME = "0.1";
private static final String FOLDER_THEMED_NAME = "themed";
private static File mRootFolder = null;
public static void main(String[] args) {
try {
mRootFolder = new File(ThemeHelper.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath()).getParentFile();
} catch (Exception ex) { return; }
logln(3);
logln("Program:");
logln(" acHelper "+VERSION_NAME);
logln("Contact:");
logln(" 2012 (C) [email protected]");
logln(" <[email protected]>");
logln(1);
log("Type resources prefix: ");
Scanner input = new Scanner(System.in);
String prefix = input.nextLine();
input.close();
logln("- - - - - - - - - - - - - - - - - -");
long beginTime = new Date().getTime();
createResourceRedirectionsFile(mRootFolder.getPath()+"/"+FOLDER_THEMED_NAME, prefix);
logln("- - - - - - - - - - - - - - - - - -");
logln(" Elapsed time: "+(new Date().getTime()-beginTime)+"ms.");
}
private static void createResourceRedirectionsFile(String directory, String patch){
int i, i2;
log(" - Building list of files... ");
final File[] files = new File(directory).listFiles(); logln("Successfully.");
log(" - Parcing files... ");
int length = files.length; String[] names = new String[length]; int ctrl = 0;
for (i = 0; i<length; i++) {
names[i+ctrl] = files[i].getName();
int nameLength = names[i+ctrl].length();
for (i2 = 0; i2 < nameLength; i2++)
if (names[i+ctrl].charAt(i2)=='.')
break;
if (i2 == nameLength) ctrl--;
else names[i+ctrl]=names[i+ctrl].substring(0, i2);
}
length = length+ctrl; logln(ctrl==0 ? "Successfully." : "Has warnings!");
try {
log(" - Opening output file... ");
File file = new File(mRootFolder
, patch.substring(0, patch.length()-1)+".xml");
file.delete();
FileWriter writer = new FileWriter(file); logln("Successfully.");
log(" - Parcing and writing values... ");
int patchLength = patch.length();
for (i = 0; i < length; i++){
if (names[i].length()>patchLength && names[i].substring(0, patchLength).equals(patch))
writer.append("<item name=\"drawable/"+names[i].substring(patchLength, names[i].length())+"\">@drawable/"+names[i]+"</item>\n");
}
writer.flush();
writer.close();
logln("Successfully.");
} catch (Exception ex) {
logln("Error!");
}
}
/**
* Short named analog of System.out.print(String msg);
*/
private static void log(String str){
System.out.print(str);
}
/**
* Recursive dividers
*/
private static void logln(int number){
if (number>1) logln(number-1);
logln("");
}
/**
* Short named analog of System.out.println(String msg);
*/
private static void logln(String str){
System.out.println(str);
}
}
acHelper Tool. 2012 © AChep
If you want copy it, let me know about it and make a link to my profile and thread.
Regards, AChep.
Reserved for renamer tool
Reserved for my greedy
Спасибо земляк!
Thanx AChep! :good:
What exactly is this tool?
Hi. I want to ask some comparison problem in Android studio. I have implement a bluetooth data receiving code in Android studio to receive data from Arduino. If it receive "abcde", an audio should be play (mysound). But it can't play as expected. May I ask what is the problem in the below code? Thank you.
Arduino:
BT.println("abcde");
Android:
h = new Handler() {
public void handleMessage(android.os.Message msg) {
switch (msg.what) {
case RECIEVE_MESSAGE: // if receive massage
byte[ ] readBuf = (byte[ ]) msg.obj;
String strIncom = new String(readBuf, 0, msg.arg1); // create string from bytes array
sb.append(strIncom); // append string
int endOfLineIndex = sb.indexOf("\r\n"); // determine the end-of-line
//txtArduino.setText(strIncom);
if (endOfLineIndex > 0) { // if end-of-line,
String sbprint = sb.substring(0, endOfLineIndex); // extract string
sb.delete(0, sb.length()); // and clear
txtArduino.setText(sbprint); // update TextView
if(sbprint=="abcde"){
mySound.start();}
break;
}
};
};
Code:
imageDialog.setIcon(android.R.drawable.btn_star_big_on);
imageDialog.setTitle("message : " + MyArrList.get(position).get("ImageDesc"));
imageDialog.setMessage("message : " + MyArrList.get(position).get("ImageDesc2") + "\n" + " message : " + MyArrList.get(position).get("ImageDesc3"));
imageDialog.setView(layout);
imageDialog.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
Intent MyArrList = new Intent(Intent.ACTION_CALL);
String strTel = MyArrList.get(position).get("ImageDesc3"); //.get ( red color code)
MyArrList.setData(Uri.parse("tel:" + strTel));
}
});
deleted
Hi there,
I have an issue with writing my app. I want to obtain the data (as shown below) and get the corresponding value from it. When I run my app on the emulator it crashes when I click the button, precisely on this line:
Code:
JSONObject jsonObject = json.getJSONObject(0);
Can someone at least, please skim through and let me know what I could be doing wrong. It must be something simple, because I am not trying to break into CIA from my phone.
This is a data from the link:
HTML:
// [ { "id": "304466804484872" ,"t" : "GOOG" ,"e" : "NASDAQ" ,"l" : "759.66" ,"l_fix" : "759.66" ,"l_cur" : "759.66" ,"s": "0" ,"ltt":"4:00PM EDT" ,"lt" : "Sep 9, 4:00PM EDT" ,"lt_dts" : "2016-09-09T16:00:03Z" ,"c" : "-15.66" ,"c_fix" : "-15.66" ,"cp" : "-2.02" ,"cp_fix" : "-2.02" ,"ccol" : "chr" ,"pcls_fix" : "775.32" } ]
Here is my class:
Code:
public JSONArray getJson(String url){
// Read response to string
HttpURLConnection connection = null;
BufferedReader reader = null;
try {
URL Url = new URL(url);
connection = (HttpURLConnection) Url.openConnection();
connection.connect();
InputStream stream = connection.getInputStream();
reader = new BufferedReader(new InputStreamReader(stream));
StringBuilder sb = new StringBuilder();
String line = "";
while ((line = reader.readLine()) != null) {
sb.append(line+"\n");
}
is.close();
result = sb.toString();
} catch(Exception e) {
return null;
}
// Convert string to object
try {
String token[] = result.split("//");
JSONArray jarr = new JSONArray (token[1]);
} catch(JSONException e){
return null;
}
return jarr;
}
This is how I use it on a click of a button:
Code:
quotebutton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Constructing a URL
String urlprefix = "http://finance.google.com/finance/info?client=ig&q=";
String Symbol = editTextSymbol.getText().toString();
String Exchange = editTextExchange.getText().toString();
String url = urlprefix + Exchange + ":" + Symbol;
JSONArray json = getJson(url);
try {
JSONObject jsonObject = json.getJSONObject(0);
String id = jsonObject.getString("id");
EditTextQuoteTime.setText(id);
} catch (JSONException e){
EditTextQuoteTime.setText("ERROR");
}
//try {
// String id = json.getString("id");
// EditTextQuoteTime.setText(id);
//} catch (JSONException e){
// EditTextQuoteTime.setText("ERROR");
// }
}
});
I know I may have asked a question that is widely available online, but most of the posts are from the time before which the libraries were updated and parsing from the URL changed. Most of the posts are slightly different and I feel I am missing something.
I think I have a main problem with decoding the actual JSON string which is shown in the HTML above. I don't know how to omit the first few signs and then get my string from there. Can anyone help, please?
App launched from phone doesn't behave as from android studio
Function load data works fine on phone when app is run from android studio via USB, but not when launched from the icon on the phone.
private fun loadSteps() {
val file = File(filesDir, "data.txt")
// Read data from the file
if (file.exists()) {
val input = FileInputStream(file)
val buffer = ByteArray(input.available())
input.read(buffer)
input.close()
// Convert the JSON string to a list of DataBlock
val json = String(buffer)
allSteps = DataBlock.fromJson(json) ?: mutableListOf()
}
val today = Calendar.getInstance().apply {
set(Calendar.HOUR_OF_DAY, 0)
set(Calendar.MINUTE, 0)
set(Calendar.SECOND, 0)
set(Calendar.MILLISECOND, 0)
}.time
if (allSteps.isEmpty()) {
// Add a new DataBlock with today's date and steps = 0
allSteps.add(DataBlock(today, 0))
} else {
val latestDate = allSteps.last().date
var latestCalendar = Calendar.getInstance().apply { time = latestDate }
val currentDate = Calendar.getInstance().apply {
set(Calendar.HOUR_OF_DAY, 0)
set(Calendar.MINUTE, 0)
set(Calendar.SECOND, 0)
set(Calendar.MILLISECOND, 0)
}
// Add new DataBlocks for missing dates between the latest date and today
while (latestCalendar.before(currentDate)) {
latestCalendar.add(Calendar.DATE, 1)
allSteps.add(DataBlock(latestCalendar.time, 0))
}
}
}
This part work ok
if (file.exists()) {
val input = FileInputStream(file)
val buffer = ByteArray(input.available())
input.read(buffer)
input.close()
// Convert the JSON string to a list of DataBlock
val json = String(buffer)
allSteps = DataBlock.fromJson(json) ?: mutableListOf()
}
but the rest of the code doesn't get executed. This is my first app and I ran into a wall.
Any thoughts?
Thanks for your reply!
Problem solved:
I have called this function within onCreate, so when app resumed or started it did not got called.