Blog Image

Ruhua Yan's Blog

A Language Lover

From virtual languages to real languages

Install VirtualBox in Fedora 25

android Posted on Thu, May 04, 2017 15:41

When i installed Fedoral in my Acer Windows 10 laptop, i enabled secure boot to have dual boot. Everything worked fine until i tried to install VirtualBox in Fedoral. It gave me an error:

WARNING: The vboxdrv kernel module is not loaded. Either there is no module
available for the current kernel (4.5.7-202.fc23.x86_64) or it failed to
load. Please recompile the kernel module and install it by

After about an hour of searching, i came cross this site: https://gorka.eguileor.com/vbox-vmware-in-secureboot-linux-2016-update/. The process looked too complicated for me. I followed the instructions without trying to understand a bit.

In the end, it worked. Save my day !!!!!!



Porker Game: 24 points

android Posted on Wed, November 23, 2016 11:21

Description: The game uses ordinary deck of playing cards, the aces are taken to have value of 1. The basic game proceeds by having 4 cards dealt and the first player that can achieve the number 24 exactly using only allowed operations (addition, subtraction, multiplication, division and parentheses) wins the hand.

Support Language: Chinese, English, French

Source code:
Card.java: I created Class Card to implement Parcelable because i need it to pass the Card instant ArrayList to onSaveInstanceState Event in GameActivity(MainActivity). So that when user change layout, the App will remember how many cards left in the ArrayList.

click to see the source code

Deck.java: click to see the source code
GameActivity.java: click to see the source code
PopupFragment.java: click to the source code

screenshots:



Tiled Image Game

android Posted on Wed, November 23, 2016 11:13

he App is written in Android Studio.

Description:
When App loads, it crops an image into two formats (3×3, 4×4 small tiled images), and these tiled images are placed in random order. User will need to put them back to where they are.

There are three images in the App. And user can choose other images from her/his device. Even better, user can use the camera of the device to take a photo as the image to play.

The scores is recorded on the time of completion.

Support Language: English, Chinese, French

Source code:

GameActivity.java: click to see the source code
SignInActivity.java: click to see the source code
PopupFragment.java: click to see the source code








How is the data passing in AsyncTask

android Posted on Mon, November 14, 2016 18:54

The following is the example to send data to server from android App using AsyncTask:

private class AsyncCustomerTable extends AsyncTask<String, String, String> {
ProgressDialog pdLoading = new ProgressDialog(CategoryActivity.this);
HttpURLConnection conn;
URL url = null;

@Override
protected void onPreExecute() {
super.onPreExecute();
//this method will be running on UI thread
pdLoading.setMessage(“\tconnecting…”);
pdLoading.setCancelable(false);
pdLoading.show();

}
@Override
protected String doInBackground(String… params) {
try {
// Enter URL address where your php file resides
url = new URL(“http://www.richyan.com/android/bonsushi/customerTable.php”);
} catch (MalformedURLException e) {
e.printStackTrace();
return “exception”;
}
try {
// Setup HttpURLConnection class to send and receive data from php and mysql
conn = (HttpURLConnection)url.openConnection();
conn.setReadTimeout(READ_TIMEOUT);
conn.setConnectTimeout(CONNECTION_TIMEOUT);
conn.setRequestMethod(“POST”);

// setDoInput and setDoOutput method depict handling of both send and receive
conn.setDoInput(true);
conn.setDoOutput(true);

// Append parameters to URL
Uri.Builder builder = new Uri.Builder()
.appendQueryParameter(“customerID”, params[0])
.appendQueryParameter(“tableID”, params[1])
.appendQueryParameter(“numCustomer”, params[2]);
// .appendQueryParameter(“preTableID”, params[3]);
String query = builder.build().getEncodedQuery();

// Open connection for sending data
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, “UTF-8”));
writer.write(query);
writer.flush();
writer.close();
os.close();
conn.connect();

} catch (IOException e1) {
e1.printStackTrace();
return “exception”;
}
try {

int response_code = conn.getResponseCode();
// Check if successful connection made
if (response_code == HttpURLConnection.HTTP_OK) {
// Read data sent from server
InputStream input = conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(input));
StringBuilder result = new StringBuilder();
String line;

while ((line = reader.readLine()) != null) {
result.append(line);
}
// Pass data to onPostExecute method
return(result.toString());
}else{
return(“false”);
}
} catch (IOException e) {
e.printStackTrace();
return “exception”;
} finally {
conn.disconnect();
}
}

@Override
protected void onPostExecute(String result) {
//this method will be running on UI thread
pdLoading.dismiss();
if (result.equalsIgnoreCase(“false”)||result.equalsIgnoreCase(“exception”)){
Toast toast = Toast.makeText(CategoryActivity.this, “Internet Connection Problem”, Toast.LENGTH_LONG);
toast.show();

} else {
try{
int custTableID = Integer.parseInt(result);
Globals.getInstance().setCustTableID(custTableID);
int catID = (int)spOrderCat.getSelectedItemId();
startMenuActivity(catID);

}catch (Exception e){
Toast toast = Toast.makeText(CategoryActivity.this, “Database Connection Problem”, Toast.LENGTH_LONG);
toast.show();
}
}
}

}

Data diagram: