Commit b802ed46 authored by Alan McNatty's avatar Alan McNatty
Browse files

New Catalan translation and QR scanning support

parent b8cd936c
......@@ -6,4 +6,7 @@
<item android:id="@+id/reset"
android:icon="@drawable/menu_revert"
android:title="@string/pref_menu_reset" />
<item android:id="@+id/scan"
android:icon="@drawable/menu_scan"
android:title="@string/pref_menu_scan" />
</menu>
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">MaharaDroid</string>
<string name="startup_text">Benvinguts a MaharaDroid</string>
<string name="prefs_app_name">Preferències de MaharaDroid</string>
<string name="pref_upload_url_key">upload.uri</string>
<string name="pref_upload_url_title">URI de la pujada</string>
<string name="pref_upload_url_summary">Escriviu la URL per pujar fitxers a Mahara</string>
<string name="pref_upload_url_default">http://master.dev.mahara.org/artefact/file/mobileupload.php</string>
<string name="pref_upload_token_key">upload.token</string>
<string name="pref_upload_token_title">Token</string>
<string name="pref_upload_token_summary">Escriviu el vostre token de càrrega a Mahara</string>
<string name="pref_upload_username_key">upload.username</string>
<string name="pref_upload_username_title">Nom d\'usuari</string>
<string name="pref_upload_username_summary">Escriviu el vostre Nom d\'usuari a Mahara</string>
<string name="prefcat_advanced">Avançat</string>
<string name="pref_upload_folder_key">upload.folder</string>
<string name="pref_upload_folder_title">Carpeta de càrrega</string>
<string name="pref_upload_folder_summary">Escriviu el nom de la carpeta (base) on carregar els vostres artefactes</string>
<string name="pref_upload_folder_default">MobileUploads</string>
<string name="pref_upload_tags_key">upload.tags</string>
<string name="pref_upload_tags_title">Etiquetes</string>
<string name="pref_upload_tags_summary">Escriviu les etiquetes separades per espais per afegir a tots els artefactes carregats</string>
<string name="pref_upload_tags_default">Android</string>
<string name="pref_upload_view_key">upload.view</string>
<string name="pref_upload_view_title">Crea una Vista pública</string>
<string name="pref_upload_view_summary">Voleu crear automàticament una Vista pública d\'aquesta carpeta?</string>
<string name="pref_menu_reset">Reinicia</string>
<string name="pref_menu_about">Sobre</string>
<string name="btnok">OK</string>
<string name="btnupload">Carrega</string>
<string name="btnsendlabel">Envia</string>
<string name="btncancellabel">Cancel·la</string>
<string name="lbluploadoptions">Configuració de la càrrega</string>
<string name="artifact_retrieve_error">Hi ha hagut un error al recuperar els detalls de l\'artefacte</string>
<string name="artifactsettings">Propietats de l\'artefacte</string>
<string name="transferprogress">Progrés en la transmissió del fitxer</string>
<string name="uploadstarting">Ha començat la càrrega</string>
<string name="uploadfinished">S\'ha acabat la càrrega</string>
<string name="uploadfailed">Ha fallat la càrrega</string>
<string name="uploadingartifact">Carregant artefacte</string>
<string name="uploading">Carregant</string>
<string name="filetransfers">Transferència de fitxers</string>
<string name="upload_confirm_label">Sí:</string>
<string name="upload_confirm_text">El fitxer que estic intentant carregar és meu o tinc l\'autorització expressa per reproduir i / o distribuir aquest article.
L\'ús que faré d\'aquest fitxer no infringeix la legislació de Drets d\'autor local.
Aquest fitxer també s\'afegeix als termes i condicions descrits en aquest lloc.</string>
<string name="upload_title_label">Títol:</string>
<string name="upload_description_label">Desc:</string>
<string name="upload_tags_label">Etiqueta(s):</string>
<!-- About page -->
<string name="about_title">Sobre MaharaDroid</string>
<string name="about_top_section_title">MaharaDroid</string>
<string name="about_sponsors_section_title">Patrocinadors</string>
<string name="about_code_contributors_section_title">Components de Tercers</string>
<string name="about_licenses_section_title">Llicències</string>
<string name="about_version_label">Versió</string>
<string name="about_license_label">Llicència</string>
</resources>
......@@ -35,6 +35,7 @@
<string name="pref_menu_reset">Reset</string>
<string name="pref_menu_about">About</string>
<string name="pref_menu_scan">Scan</string>
<string name="btnok">OK</string>
<string name="btnupload">Upload</string>
......@@ -63,7 +64,12 @@
<string name="upload_description_label">Desc:</string>
<string name="upload_tags_label">Tag(s):</string>
<!-- About page -->
<string name="load_config_download_error">Sorry there was an error downloading the configuration file.</string>
<string name="load_config_error">Sorry there was an error parsing the configuration file.</string>
<string name="load_config_success">Successfully loaded the configuration file.</string>
<string name="scan_not_available">Sorry you need to install ZXing Barcode Scanner for this.</string>
<!-- About page -->
<string name="about_title">About MaharaDroid</string>
<string name="about_top_section_title">MaharaDroid</string>
<string name="about_sponsors_section_title">Sponsors</string>
......
......@@ -21,8 +21,27 @@
package nz.net.catalyst.MaharaDroid;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import nz.net.catalyst.MaharaDroid.ui.about.AboutActivity;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
......@@ -33,6 +52,7 @@ import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;
public class EditPreferences extends PreferenceActivity implements OnSharedPreferenceChangeListener {
......@@ -80,6 +100,16 @@ public class EditPreferences extends PreferenceActivity implements OnSharedPrefe
case R.id.reset:
resetToDefaults();
return true;
case R.id.scan:
try {
Intent intent = new Intent(GlobalResources.CONFIG_SCAN_INTENT);
intent.putExtra("SCAN_MODE", GlobalResources.CONFIG_SCAN_MODE);
startActivityForResult(intent, 0);
} catch (ActivityNotFoundException e) {
Toast.makeText(this, getResources().getString(R.string.scan_not_available),
Toast.LENGTH_SHORT).show();
}
return true;
default:
return super.onOptionsItemSelected(item);
}
......@@ -116,5 +146,121 @@ public class EditPreferences extends PreferenceActivity implements OnSharedPrefe
finish();
startActivity(getIntent());
}
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
if (resultCode == Activity.RESULT_OK) {
String contents = intent.getStringExtra("SCAN_RESULT");
String formatName = intent.getStringExtra("SCAN_RESULT_FORMAT");
if ( DEBUG ) Log.d(TAG, "scanResult: " + contents + " (" + formatName + ")");
ConfigXMLHandler cx = null;
if ( contents.toLowerCase().startsWith("http://") ) {
try {
cx = new ConfigXMLHandler(this, new URL(contents).openStream());
} catch (MalformedURLException e) {
Toast.makeText(this, getResources().getString(R.string.load_config_download_error), Toast.LENGTH_SHORT).show();
e.printStackTrace();
} catch (IOException e) {
Toast.makeText(this, getResources().getString(R.string.load_config_download_error), Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
} else {
cx = new ConfigXMLHandler(this, new ByteArrayInputStream( contents.getBytes() ) );
}
if ( cx.parseConfig() ) {
Toast.makeText(this, getResources().getString(R.string.load_config_success), Toast.LENGTH_SHORT).show();
// refresh displayed values by restarting activity (a hack, but apparently there
// isn't a nicer way)
finish();
startActivity(getIntent());
} else {
Toast.makeText(this, getResources().getString(R.string.load_config_error), Toast.LENGTH_SHORT).show();
}
}
}
public static class ConfigXMLHandler extends DefaultHandler {
// Number of config items to process
private static final int CONFIG_LIMIT = 50;
SharedPreferences mPrefs;
String curKey = "";
String curValue = "";
int count = 0;
SAXParserFactory spf;
SAXParser sp;
XMLReader xr;
Context ctx;
InputSource is;
URL url;
public ConfigXMLHandler(Context context, InputStream ins) {
ctx = context;
mPrefs = PreferenceManager.getDefaultSharedPreferences(ctx);
is = new InputSource(ins);
try {
spf = SAXParserFactory.newInstance();
sp = spf.newSAXParser();
xr = sp.getXMLReader();
xr.setContentHandler(this);
} catch (SAXException e) {
Log.e(TAG, "ConfigXMLHandler: SAXException: " + e.toString());
} catch (ParserConfigurationException e) {
Log.e(TAG, "ConfigXMLHandler: ParserConfigurationException: " + e.toString());
}
}
public Boolean parseConfig() {
try {
xr.parse(is);
return true;
} catch (IOException e) {
return false;
} catch (SAXException e) {
return false;
}
}
public void startElement(String uri, String name, String qName,
Attributes atts) throws SAXException {
if( mPrefs.contains(name.trim()) )
curKey = name.trim();
//else
// Log.d(TAG, "startElement ignoring " + name.trim());
count++;
// Lets check if we've hit our limit on number of Records
if (count > CONFIG_LIMIT)
throw new SAXException();
}
public void endElement(String uri, String name, String qName) {
if (name.trim().equals(curKey) && ( curKey.startsWith("upload.") ) ) {
if (curValue.length() > 0) {
if ( DEBUG ) Log.d(TAG, curKey + ": " + curValue);
mPrefs.edit()
.putString(curKey, curValue)
.commit()
;
}
}
else
if ( DEBUG ) Log.d(TAG, "endElement ignoring " + name.trim());
curKey = curValue = "";
}
public void characters(char ch[], int start, int length) throws SAXException {
String chars = new String(ch, start, length);
if (curKey != "")
curValue = curValue + chars.trim();
}
}
}
......@@ -40,6 +40,9 @@ public class GlobalResources {
public static final String TRANSFER_TYPE_UPLOAD = "Upload";
public static final String CONFIG_SCAN_INTENT = "com.google.zxing.client.android.SCAN";
public static final String CONFIG_SCAN_MODE = "QR_CODE_MODE";
public static int ERROR_DELAY_MS = 1000;
static final int UPLOADER_ID = 243;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment