how can i print persian with bixolon printers - android

I create an app for android in this app i connect to a bixolon(350plusll) printer and i print a tiket when my String is in english it is ok and my tiket print good but when my String is in persian my result print is not ok and my characters is revers and not correct
i use screenshot it was ok but it was very slow and not logiacal
please help me for resolve this problem
thanks alot
this is my code
package com.example.bahram.myapplication;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import com.bixolon.printer.BixolonPrinter;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
public class PrintTicketActivity extends Activity {
Button btn;
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_print_tiket);
btn= findViewById(R.id.button);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//I set code page of the printer here because i want the printer print persian so i set that on Farsi
MainActivity.mBixolonPrinter.setSingleByteFont(BixolonPrinter.CODE_PAGE_FARSI);
//i have a file it's name is new2.txt and readContentOfFile is a method which read all of text in new2.txt and at last print data on the paper
MainActivity.mBixolonPrinter.printText(readContentOfFile(),BixolonPrinter.ALIGNMENT_CENTER,BixolonPrinter.TEXT_ATTRIBUTE_FONT_A,BixolonPrinter.TEXT_SIZE_HORIZONTAL1,true);
}
});
}
//read all of the text in new2.txt and return text
String readContentOfFile() {
StringBuilder text = new StringBuilder();
InputStream inputStream = getResources().openRawResource(R.raw.new2);
try {
BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
String line;
while ((line = br.readLine()) != null) {
text.append(line);
text.append('\n');
}
br.close();
} catch (IOException e) {
//You'll need to add proper error handling here
}
return text.toString();
}
}
content of new2.txt is bottom text
اما جدیدترین شاهکار سازمان لیگ و هیات فوتبال استان تهران که از سوی همین سازمان لیگ به عنوان برترین هیات ایران انتخاب شد، جانمایی توپ شروع مسابقه روی قیف(یا کنز) بود که در دیدار سایپا و پیکان صورت گرفت.

You can use one of the Farsi options available for the Bixolon printer, for example one of the following:
// Farsi option : Mixed
MainActivity.mBixolonPrinter.setFarsiOption(BixolonPrinter.OPT_REORDER_FARSI_MIXED);
// Farsi option : Right to Left
MainActivity.mBixolonPrinter.setFarsiOption(BixolonPrinter.OPT_REORDER_FARSI_RTL);

Related

Can not connect to "xampp server localhost" with android studio

I have tried to connect to my localhost xampp with android studio using AsyncTask class. Here is AsyncTask but it gives error saying Failed to connect
to /10.0.2.2:800
I tried my real ip address cmd --> ipconfig IPV4 and some other tricks but
they did not succeed
belwow is my app structure
AsyncTask using class
package app.buil.land.food.doymaj.doymaj;
import android.app.AlertDialog;
import android.content.Context;
import android.os.AsyncTask;
import android.util.Log;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;
/**
* Created by ProgrammingKnowledge on 1/5/2016.
*/
public class backGroundActivities extends AsyncTask<String,Void,String> {
Context context;
AlertDialog alertDialog;
backGroundActivities (Context ctx) {
context = ctx;
}
#Override
protected String doInBackground(String... params) {
String type = params[0];
String login_url = "http://10.0.2.2:800/login.php";
if(type.equals("login")) {
try {
String phone_number = params[1];
// String password = params[2];
URL url = new URL(login_url);
HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();
httpURLConnection.setRequestMethod("POST");
httpURLConnection.setDoOutput(true);
httpURLConnection.setDoInput(true);
OutputStream outputStream = httpURLConnection.getOutputStream();
BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream, "UTF-8"));
String post_data = URLEncoder.encode("phone_number","UTF-8")+"="+URLEncoder.encode(phone_number,"UTF-8");
bufferedWriter.write(post_data);
bufferedWriter.flush();
bufferedWriter.close();
outputStream.close();
InputStream inputStream = httpURLConnection.getInputStream();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream,"iso-8859-1"));
String result="";
String line="";
while((line = bufferedReader.readLine())!= null) {
result += line;
Log.e("Line_from_php_server",result);
}
bufferedReader.close();
inputStream.close();
httpURLConnection.disconnect();
return result;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
#Override
protected void onPreExecute() {
alertDialog = new AlertDialog.Builder(context).create();
alertDialog.setTitle("Login Status");
}
#Override
protected void onPostExecute(String result) {
alertDialog.setMessage(result);
alertDialog.show();
}
#Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
}
}
here is my MainActivity
package app.buil.land.food.doymaj.doymaj;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
EditText phone_Number;
EditText user_Name;
EditText pass_Word;
Button singButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// singButton = (Button)findViewById(R.id.sing_id);
// singButton.setOnClickListener(kyListener);
phone_Number =(EditText)findViewById(R.id.mobile_id);
user_Name =(EditText)findViewById(R.id.name_id);
pass_Word =(EditText)findViewById(R.id.p_id);
}
// Push_Identity db = new Push_Identity(this,"CustomerDatabas.db",null,1);
public boolean validate(EditText[] fields){
for(int i = 0; i < fields.length; i++){
EditText currentField = fields[i];
if(currentField.getText().toString().length() <= 0){
switch (i){
case 0:
Toast.makeText(getApplicationContext(),"شماره تلفن وارد نشده ",Toast.LENGTH_LONG).show() ;
break;
case 1:
Toast.makeText(getApplicationContext(),"نام کاربری وارد نشده ",Toast.LENGTH_LONG).show() ;
break;
case 2:
Toast.makeText(getApplicationContext(),"رمز وارد نشده ",Toast.LENGTH_LONG).show() ;
break;
}
return false;
}
}
return true;
}
//private View.OnClickListener kyListener = new View.OnClickListener() {
public void send_number(View v) {
// do something when the button is clicked
// Yes we will handle click here but which button clicked??? We don't know
boolean fieldsOK = validate(new EditText[] { phone_Number, user_Name, pass_Word });
if (fieldsOK ==true){
String Phon = phone_Number.getText().toString();
Toast.makeText(getApplicationContext(),Phon,Toast.LENGTH_LONG);
// the Tooast dose not display anything
// it seems that the EditText is empty buy i enter the value in
// in it.
String type ="login";
backGroundActivities back = new backGroundActivities(this);
back.execute(type,Phon);
//
}
}
// };
}
XML
<EditText
android:id="#+id/mobile_id"
android:layout_width="match_parent"
android:layout_height="43dp"
android:background="#drawable/customized_edtitext"
android:drawablePadding="15dp"
android:paddingRight="10dp"
android:paddingLeft="15dp"
android:drawableRight="#drawable/ic_smartphone"
android:elevation="2dp"
android:textStyle="bold"
android:hint="#string/register_phone_commnet"
android:fontFamily="#font/iransansmedium"
android:textSize="12sp"
/>
<EditText
android:id="#+id/name_id"
android:layout_width="match_parent"
android:layout_height="43dp"
android:layout_below="#id/mobile_id"
android:background="#drawable/customized_edtitext1"
android:drawablePadding="15dp"
android:paddingRight="10dp"
android:paddingLeft="15dp"
android:drawableRight="#mipmap/ic_user"
android:elevation="2dp"
android:textStyle="bold"
android:hint="#string/register_user_commnet"
android:fontFamily="#font/iransansmedium"
android:textSize="12dp" />
<EditText
android:id="#+id/p_id"
android:layout_width="match_parent"
android:layout_height="43dp"
android:layout_below="#+id/name_id"
android:background="#drawable/customized_edtitext2"
android:drawablePadding="15dp"
android:paddingRight="10dp"
android:paddingLeft="15dp"
android:drawableRight="#mipmap/ic_unlocked"
android:elevation="2dp"
android:textStyle="bold"
android:hint="#string/register_pass_commnet"
android:fontFamily="#font/iransansmedium"
android:textSize="12sp"
android:paddingEnd="10dp" />
here is the url of my php page
enter image description here
And some more information: I have Genymotion installed and also bluestack, and VirtaulBox. Do they confilct about port? I mean could these softwares cause conflicting ports Apache xampp and their ports?
My Xampp was working with Port: 80 as shown in below image. So writing below ip address as http://10.0.2.2:80/ worked for me.
If you have wifi and your computer and real device (mobile) is connected to the same wifi you can use NGROK software tool to run and debug your app in your real device.
Run the ngrok.exe and type ngrok http 80, it will give you an address like the below image.
Just use the url in your app where you use your ip address.
It is best to use.
This answer assumes, that the browser screenshot shows a successful page load. I believe, the error page is a bit more gray.
There might be a firewall issue at hand. Since you are using a non-standard port, the firewall exceptions that are installed with XAMPP might not cover that.
Go to the Windows Firewall Advanced settings -> inbound rules. Now add a rule that allows for traffic on the TCP port 800. Make sure, that you uncheck the public profile so that if you are on a public wifi, nobody will be able to connect to this application.
Now check with a browser from the smartphone, if your PHP Application is accessible.

Dictionary app using Oxford Dictionary API

I am trying to make a dictionary application using Oxford Dictionary api. There is something wrong with my code JSON. Can anyone tell me how do I extract only the definition of the searched word, rather getting the whole JSON file
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import javax.net.ssl.HttpsURLConnection;
public class MainActivity extends AppCompatActivity {
private static final String APP_ID= "59028fc6";
private static final String API_KEY = "ad3e310307d7b2f8bf474c45e1efd01f";
private static final String TAG = MainActivity.class.getSimpleName();
private OkHttpClient okHttpClient;
private EditText textInput;
private Button submitButton;
private TextView definitionView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// initialize ok http
okHttpClient = new OkHttpClient();
textInput = findViewById(R.id.textInput);
submitButton = findViewById(R.id.submitButton);
definitionView = findViewById(R.id.textMeaning);
submitButton.setOnClickListener(
new View.OnClickListener() {
#Override
public void onClick(View view) {
findMeaningOfEnteredWord();
}
});
}
private void findMeaningOfEnteredWord() {
String word = textInput.getText().toString();
if (word.isEmpty()) {
Toast.makeText(this, "Nothing entered", Toast.LENGTH_SHORT).show();
return;
}
// create url from the word
String lowerCaseWord = word.toLowerCase();
String httpRequestUrl = "https://od-api.oxforddictionaries.com:443/api/v1/entries/en/" + lowerCaseWord;
// make request with REST url
new RequestAsyncTask().execute(httpRequestUrl);
}
private class RequestAsyncTask extends AsyncTask<String, Integer, String> {
#Override
protected String doInBackground(String... params) {
String requestUrl = params[0];
Request request = new Request.Builder()
.url(requestUrl)
.addHeader("Accept", "application/json")
.addHeader("app_id", APP_ID)
.addHeader("app_key", API_KEY)
.build();
Response response = null;
try {
response = okHttpClient.newCall(request).execute();
return response.body().string();
} catch (IOException ex) {
Log.e(TAG, "caught error: " + ex.getMessage());
}
return "";
}
#Override
protected void onPostExecute(String result) {
try {
JSONObject responseAsJson = new JSONObject(result);
JSONArray results = responseAsJson.getJSONArray("results");
if (results.length() > 0) { // valid definitions were found
String lexicalEntries = results.getJSONObject(0).getString("lexicalEntries");
definitionView.setText(lexicalEntries);
}
Log.d(TAG, " " + responseAsJson.toString());
} catch (Exception ex) {
Log.d(TAG, "exception during json parsing: " + ex.getMessage());
}
}
}
}
JSON:
{"id":"aeroplane",
"language":"en",
"lexicalEntries": [
{
"entries": [{"etymologies":["late 19th century: from French aéroplane, from aéro- ‘air’ + Greek -planos ‘wandering’"],
"grammaticalFeatures":[{"text":"Singular","type":"Number"}],
"homographNumber":"000",
"senses":[{"crossReferenceMarkers":["North American term airplane"],
"crossReferences":[{"id":"airplane","text":"airplane","type":"see also"}],
"definitions":["a powered flying vehicle with fixed wings and a weight greater than that of the air it displaces."],
"domains":["Aviation"],
"id":"m_en_gbus0013220.005",
"regions":["British"],
"short_definitions":["powered flying vehicle with fixed wings"],
"thesaurusLinks":[{"entry_id":"plane","sense_id":"t_en_gb0011151.001"}]}]}],"language":"en","lexicalCategory":"Noun","pronunciations":[{"audioFile":"http:\/\/audio.oxforddictionaries.com\/en\/mp3\/aeroplane_gb_2.mp3","dialects":["British English"],"phoneticNotation":"IPA","phoneticSpelling":"ˈɛːrəpleɪn"}],"text":"aeroplane"}],
"type":"headword","word":"aeroplane"
}
Modify these lines :
String lexicalEntries = results.getJSONObject(0).getString("lexicalEntries");
definitionView.setText(lexicalEntries);
to :
String definition = results.getJSONObject(0).getString("lexicalEntries")
.getJSONArray("entries").getJSONObject(0).getJSONArray("senses")
.getJSONObject(0).getJSONArray("definitions").getString(0);
definitionView.setText(definition);
Of course you may need to modify your UI based on the number of definitions a word has.
Also, you should probably consider using POJOs instead of directly dealing with the JSON response.
I'd recommend Jackson or GSON for doing this.
String definitions=results.getJSONArray("lexicalEntries")
.getJSONObject(0)
.getJSONArray("entries")
.getJSONObject(0)
.getJSONArray("senses")
.getJSONArray("definitions")
.get(0)
So , The thing is , There are a lot of gaps in the JSON for different words .
Which means a word may have an array of "synonyms" but others don't , So in your code you are trying to reach something that doesn't actually exist (a NULL value) which is likely to throw an exception every time you search for a word that the JSON returned doesn't match the JSON you are expecting , Because there are missing (NULL) values .
The app I made using oxford dictionary required a lot of work just to make sure there is no thrown exception .
I used retrofit with moshi converter factory , And then Do the following :
1-In your custom classes , Make sure you annotate every data member with
#Json and provide the name of the keys in the JSON of oxford
2-make sure that every declared type is nullable , including both List and the type inside of it
You'll then be able to get the result , And Now comes the part where you handle evey call that may be null
I know this is a bit old question , But It happened that I struggled with this api once , So I hope this may help someone :)

Reading file from AVD sd card and displaying text view

I have a text file that has this information
Casino Canberra;21 Binara Street, Canberra ACT, 2601;Canberra Casino is a casino located in Civic in the central part of the Australian capital city of Canberra. The Casino is relatively small compared with other casinos in Australia.;(02) 6257 7074;www.canberracasino.com.au
National Museum of Canberra;Parkes Place, Canberra ACT, 2601;The National Museum of Australia explores the land, nation and people of Australia. Open 9am - 5pm every day except Christmas Day. General admission free.;(02) 6240 6411;www.nga.gov.au
which is stored in the sdcard
after this i retrieve the values using this method
package au.edu.canberra.g30813706;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import android.app.Activity;
import android.os.Environment;
public class FileReader extends Activity{{
ArrayList<read> sInfo = new ArrayList<read>();
ArrayList<String> sLines = new ArrayList<String>();
String line;
String[] saLineElements;
String txtName = "AccomodationTxt.txt";
File root = Environment.getExternalStorageDirectory();
File path = new File(root, "CanberraTourism/" + txtName);
try {
BufferedReader br = new BufferedReader (
new InputStreamReader(
new FileInputStream(path)));
while ((line = br.readLine()) != null)
{
sLines.add(line);
//The information is split into segments and stored into the array
saLineElements = line.split(";");
//for (int i = 0; i < saLineElements.length; i++)
// sInfo.add(new read(saLineElements[i]));
sInfo.add(new read(saLineElements[0], saLineElements[1], saLineElements[3], saLineElements[4], saLineElements[5]));
}
br.close();
}
catch (FileNotFoundException e) {
System.err.println("FileNotFoundException: " + e.getMessage());
}
catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}}
}
But i also have and object class to store each individual item into
package au.edu.canberra.g30813706;
public class read {
public String name;
public String address;
public String info;
public String phone;
public String www;
public read (String name, String address, String info, String phone, String www)
{
this.name = name;
this.address = address;
this.info = info;
this.phone = phone;
this.www = www;
}
}
The only issue im having is trying to display the information in a text view which i have no idea how to call the values i need
This is where im trying to insert it
package au.edu.canberra.g30813706;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import au.edu.canberra.g30813706.FileReader;
import au.edu.canberra.g30813706.read;
public class Accommodation_info extends Activity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.accommodation_layout);
}}
You should probably look into using the Application class. You can think of Application as a GUI-less activity which works like the model in a program following the MVC pattern. You can put all of your read objects into a data structure in your Application and then access them with accessors and mutators of your own design.
Take a look at this official doc.
As your code stands, you can only access your instances of read by obtaining a reference to your FileReader class, but your two activities are separate entities. You'd have to do something like this:
// This is the main activity and should be launched first
// Check your manifest to make sure it launches with this activity
package au.edu.canberra.g30813706;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
import au.edu.canberra.g30813706.FileReader;
import au.edu.canberra.g30813706.read;
public class Accommodation_info extends Activity
{
// Declare the file reader so you'll have a reference
FileReader reader;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.accommodation_layout);
// Instantiate the file reader
reader = new FileReader();
// Now you can access the array inside FileReader
// obviously, you need to have a text view called my_textView defined in the
// layout file associated with this activity
TextView myTextView = (TextView)findViewById(R.id.my_textView);
// displays the first element in FileReader's array list
myTextView.setText((String)reader.get(0));
}}
At the moment, you might be in a bit deep for your current understanding of Android and/or Java. I would encourage you to follow as many code examples as possible, get comfortable with Android and then go back to your project when you have a little more experience.

Parsing a text file using Jsoup

I have a Continent.txt file placed in my res/raw folder. Inside it contains the following.
<div class="continents">
US
Canada
Europe
</div>
I am able to parse the text US, Canada, Europe using jsoup, but when I display them to a TextView, they show up in one line. The output looks like this.
US Canada Europe
I want the ouput to be like this.
US
Canada
Europe
This is my code.
package com.example.readfile;
import java.io.InputStream;
import java.util.ArrayList;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.content.res.Resources;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView txtContinent;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtContinent = (TextView) findViewById(R.id.textView1);
new MyTask().execute();
}
class MyTask extends AsyncTask<Void, Void, ArrayList<String>> {
ArrayList<String> arr_linkText = new ArrayList<String>();
#Override
protected ArrayList<String> doInBackground(Void... params) {
Document doc;
try {
Resources res = getResources();
InputStream in_s = res.openRawResource(R.raw.continent);
byte[] b = new byte[in_s.available()];
in_s.read(b);
doc = Jsoup.parse(new String(b));
Element link = doc.select("a").first();
String text = doc.body().text();
arr_linkText.add(text);
} catch (Exception e) {
// e.printStackTrace();
txtContinent.setText("Error: can't open file.");
}
return arr_linkText; // << retrun ArrayList from here
}
#Override
protected void onPostExecute(ArrayList<String> result) {
for (String temp_result : result) {
txtContinent.append(temp_result + "\n");
}
}
}
}
I do not know how to read the file line by line, I hope someone can illustrate it to me. Thank you!
You are taking the text of the entire body of the document at once. You need to parse it out by each element, like so
Elements links = doc.select("a");
for (Element link : links) {
arr_linkText.add(link.text());
}
in case it wasn't clear, the above code is meant to replace the following --
Element link = doc.select("a").first();
String text = doc.body().text();
arr_linkText.add(text);
Have you set android:inputType to include textMultiLine?

is there any way to make a webview running android 4.0 perform at an acceptable level?

On both the emulator and on my galaxy nexus device, this simple demo app takes an entire 1000 milliseconds or longer to select or deselect a checkbox. I wanted to write the majority of my app in javascript so I could reuse the code across ios / android / web, but this is a deal breaker.
Here is my code:
(The Activity)
package com.mycompanyname;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.webkit.ConsoleMessage;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebSettings.RenderPriority;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import com.mycompanyname.R;
public class JavascriptListViewTestActivity extends Activity {
private JavascriptListViewTestActivity parent = this;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebChromeClient chrome = new WebChromeClient() {
#Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
parent.showDialog(consoleMessage.message() + "\n" + consoleMessage.lineNumber());
return true;
}
};
WebViewClient client = new WebViewClient() {
};
WebView webView = (WebView)findViewById(R.id.webView1);
webView.setWebChromeClient(chrome);
webView.setWebViewClient(client);
webView.getSettings().setJavaScriptEnabled(false);
webView.getSettings().setAllowFileAccess(false);
webView.getSettings().setAppCacheEnabled(false);
webView.getSettings().setBuiltInZoomControls(false);
webView.getSettings().setDatabaseEnabled(false);
webView.getSettings().setDomStorageEnabled(false);
webView.getSettings().setGeolocationEnabled(false);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
webView.getSettings().setLightTouchEnabled(false);
webView.getSettings().setLoadWithOverviewMode(false);
webView.getSettings().setNavDump(false);
webView.getSettings().setNeedInitialFocus(false);
webView.getSettings().setPluginsEnabled(false);
webView.getSettings().setRenderPriority(RenderPriority.HIGH);
webView.getSettings().setSaveFormData(false);
webView.getSettings().setSavePassword(false);
webView.getSettings().setSupportMultipleWindows(false);
webView.getSettings().setSupportZoom(false);
webView.getSettings().setUseDoubleTree(false);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
String html = readText(R.raw.listview);
webView.loadData(html, "text/html", "UTF-8");
}
private void showDialog(String message)
{
AlertDialog alert = new AlertDialog.Builder(parent).create();
alert.setMessage(message);
alert.show();
}
private String readText(int resourceId)
{
InputStream is = this.getResources().openRawResource(resourceId);
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String readLine = null;
StringBuffer outputBuffer = new StringBuffer();
try
{
while ((readLine = br.readLine()) != null)
{
outputBuffer.append(readLine);
}
return outputBuffer.toString();
}
catch (Exception e) {
e.printStackTrace();
return "";
}
finally
{
// TODO: might throw - use IOUtils.close()
try
{
is.close();
br.close();
}
catch (IOException ex)
{
showDialog(ex.toString());
}
}
}
}
(The xml layout)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<WebView
android:id="#+id/webView1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
(The html loaded in the webview)
<html>
<body>
<input type="checkbox" />
</body>
</html>
I realize this is over a year old, but you could try implementing fastclick.js: https://github.com/ftlabs/fastclick
I've used it successfully on quite a few projects. As the page explains:
...mobile browsers will wait approximately 300ms from the time that
you tap the button to fire the click event. The reason for this is
that the browser is waiting to see if you are actually performing a
double tap.
Same goes for interactions within a webview (as far as I know).

Categories

Resources