Fix providing resources
This commit is contained in:
parent
f6065fa950
commit
eca63fa59b
5 changed files with 167 additions and 23 deletions
|
@ -61,6 +61,13 @@ public class Algoritms {
|
|||
}
|
||||
}
|
||||
|
||||
public static void oneByteStreamCopy(InputStream in, OutputStream out) throws IOException{
|
||||
int read;
|
||||
while ((read = in.read()) != -1) {
|
||||
out.write(read);
|
||||
}
|
||||
}
|
||||
|
||||
public static void closeStream(Closeable stream){
|
||||
try {
|
||||
if(stream != null){
|
||||
|
|
5
OsmAnd/assets/distributed_assets.xml
Normal file
5
OsmAnd/assets/distributed_assets.xml
Normal file
|
@ -0,0 +1,5 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<assets>
|
||||
<asset name="basemap.obf.jpg" destination="basemap.obf"/>
|
||||
<asset name="voice/en-tts/_ttsconfig.p" destination="voice/en-tts/_ttsconfig.p"/>
|
||||
</assets>
|
120
OsmAnd/assets/voice/en-tts/_ttsconfig.p
Normal file
120
OsmAnd/assets/voice/en-tts/_ttsconfig.p
Normal file
|
@ -0,0 +1,120 @@
|
|||
:- op('==', xfy, 500).
|
||||
version(100).
|
||||
language(en).
|
||||
|
||||
% before each announcement (beep)
|
||||
preamble - [].
|
||||
|
||||
|
||||
%% TURNS
|
||||
turn('left', ['turn left ']).
|
||||
turn('left_sh', ['sharp left ']).
|
||||
turn('left_sl', ['turn slightly left ']).
|
||||
turn('right', ['turn right ']).
|
||||
turn('right_sh', ['sharp right ']).
|
||||
turn('right_sl', ['turn slightly right ']).
|
||||
|
||||
prepare_turn(Turn, Dist) == ['Prepare to ', M, ' after ', D] :-
|
||||
distance(Dist) == D, turn(Turn, M).
|
||||
turn(Turn, Dist) == ['After ', D, M] :-
|
||||
distance(Dist) == D, turn(Turn, M).
|
||||
turn(Turn) == M :- turn(Turn, M).
|
||||
|
||||
|
||||
prepare_make_ut(Dist) == ['Prepare to turn after ', D, ' turn back'] :-
|
||||
distance(Dist) == D.
|
||||
|
||||
prepare_roundabout(Dist) == ['Prepare to enter roundabout after ', D] :-
|
||||
distance(Dist) == D.
|
||||
|
||||
make_ut(Dist) == ['After ', D, ' turn back '] :-
|
||||
distance(Dist) == D.
|
||||
make_ut == ['Turn back '].
|
||||
|
||||
roundabout(Dist, _Angle, Exit) == ['After ', D, ' enter the roundabout, and take the ', E, 'exit'] :- distance(Dist) == D, nth(Exit, E).
|
||||
roundabout(_Angle, Exit) == ['taking the ', E, 'exit'] :- nth(Exit, E).
|
||||
|
||||
and_arrive_destination == ['and arrive at your destination ']. % Miss and?
|
||||
then == ['then '].
|
||||
reached_destination == ['you have reached your destination '].
|
||||
bear_right == ['keep right '].
|
||||
bear_left == ['keep left '].
|
||||
route_recalc(_Dist) == []. % ['recalculating route ']. %nothing to said possibly beep?
|
||||
route_new_calc(Dist) == ['The trip is ', D] :- distance(Dist) == D. % nothing to said possibly beep?
|
||||
|
||||
go_ahead(Dist) == ['Drive for ', D]:- distance(Dist) == D.
|
||||
go_ahead == ['Continue straight ahead '].
|
||||
|
||||
%%
|
||||
nth(1, '1st ').
|
||||
nth(2, '2nd ').
|
||||
nth(3, '3rd ').
|
||||
nth(4, '4th ').
|
||||
nth(5, '5th ').
|
||||
nth(6, '6th ').
|
||||
nth(7, '7th ').
|
||||
nth(8, '8th ').
|
||||
nth(9, '9th ').
|
||||
nth(10, '10th ').
|
||||
nth(11, '11th ').
|
||||
nth(12, '12th ').
|
||||
nth(13, '13th ').
|
||||
nth(14, '14th ').
|
||||
nth(15, '15th ').
|
||||
nth(16, '16th ').
|
||||
nth(17, '17th ').
|
||||
|
||||
|
||||
%%% distance measure
|
||||
distance(Dist) == T :- Dist < 1000, dist(Dist, F), append(F, ' meters',T).
|
||||
dist(D, ['10 ']) :- D < 20, !.
|
||||
dist(D, ['20 ']) :- D < 30, !.
|
||||
dist(D, ['30 ']) :- D < 40, !.
|
||||
dist(D, ['40 ']) :- D < 50, !.
|
||||
dist(D, ['50 ']) :- D < 60, !.
|
||||
dist(D, ['60 ']) :- D < 70, !.
|
||||
dist(D, ['70 ']) :- D < 80, !.
|
||||
dist(D, ['80 ']) :- D < 90, !.
|
||||
dist(D, ['90 ']) :- D < 100, !.
|
||||
dist(D, ['100 ']) :- D < 150, !.
|
||||
dist(D, ['150 ']) :- D < 200, !.
|
||||
dist(D, ['200 ']) :- D < 250, !.
|
||||
dist(D, ['250 ']) :- D < 300, !.
|
||||
dist(D, ['300 ']) :- D < 350, !.
|
||||
dist(D, ['350 ']) :- D < 400, !.
|
||||
dist(D, ['400 ']) :- D < 450, !.
|
||||
dist(D, ['450 ']) :- D < 500, !.
|
||||
dist(D, ['500 ']) :- D < 550, !.
|
||||
dist(D, ['550 ']) :- D < 600, !.
|
||||
dist(D, ['600 ']) :- D < 650, !.
|
||||
dist(D, ['650 ']) :- D < 700, !.
|
||||
dist(D, ['700 ']) :- D < 750, !.
|
||||
dist(D, ['750 ']) :- D < 800, !.
|
||||
dist(D, ['800 ']) :- D < 850, !.
|
||||
dist(D, ['850 ']) :- D < 900, !.
|
||||
dist(D, ['900 ']) :- D < 950, !.
|
||||
dist(D, ['950 ']) :- !.
|
||||
|
||||
distance(Dist) == ['more than 1 kilometer '] :- Dist < 1500.
|
||||
distance(Dist) == ['more than 2 kilometers '] :- Dist < 3000.
|
||||
distance(Dist) == ['more than 3 kilometers '] :- Dist < 4000.
|
||||
distance(Dist) == ['more than 4 kilometers '] :- Dist < 5000.
|
||||
distance(Dist) == ['more than 5 kilometers '] :- Dist < 6000.
|
||||
distance(Dist) == ['more than 6 kilometers '] :- Dist < 7000.
|
||||
distance(Dist) == ['more than 7 kilometers '] :- Dist < 8000.
|
||||
distance(Dist) == ['more than 8 kilometers '] :- Dist < 9000.
|
||||
distance(Dist) == ['more than 9 kilometers '] :- Dist < 10000.
|
||||
distance(Dist) == ['more than ', X, ' kilometers '] :- D is Dist/1000, dist(D, X).
|
||||
|
||||
%% resolve command main method
|
||||
%% if you are familar with Prolog you can input specific to the whole mechanism,
|
||||
%% by adding exception cases.
|
||||
flatten(X, Y) :- flatten(X, [], Y), !.
|
||||
flatten([], Acc, Acc).
|
||||
flatten([X|Y], Acc, Res):-
|
||||
flatten(Y, Acc, R), flatten(X, R, Res).
|
||||
flatten(X, Acc, [X|Acc]).
|
||||
|
||||
resolve(X, Y) :- resolve_impl(X,Z), flatten(Z, Y).
|
||||
resolve_impl([],[]).
|
||||
resolve_impl([X|Rest], List) :- resolve_impl(Rest, Tail), ((X == L) -> append(L, Tail, List); List = Tail).
|
|
@ -10,6 +10,7 @@ import java.text.Collator;
|
|||
import java.text.MessageFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
@ -37,6 +38,9 @@ import net.osmand.plus.render.MapRenderRepositories;
|
|||
import net.osmand.plus.views.POIMapLayer;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.xmlpull.v1.XmlPullParser;
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
import org.xmlpull.v1.XmlPullParserFactory;
|
||||
|
||||
import android.content.res.AssetManager;
|
||||
import android.database.sqlite.SQLiteException;
|
||||
|
@ -352,21 +356,22 @@ public class ResourceManager {
|
|||
|
||||
public List<String> reloadIndexes(IProgress progress){
|
||||
close();
|
||||
List<String> warnings = new ArrayList<String>();
|
||||
// check we have some assets to copy to sdcard
|
||||
checkAssets(progress);
|
||||
warnings.addAll(checkAssets(progress));
|
||||
initRenderers(progress);
|
||||
// do it lazy
|
||||
// indexingImageTiles(progress);
|
||||
List<String> warnings = new ArrayList<String>();
|
||||
warnings.addAll(indexingPoi(progress));
|
||||
warnings.addAll(indexingMaps(progress));
|
||||
return warnings;
|
||||
}
|
||||
|
||||
private void checkAssets(IProgress progress) {
|
||||
private List<String> checkAssets(IProgress progress) {
|
||||
File file = context.getSettings().extendOsmandPath(APP_DIR);
|
||||
file.mkdirs();
|
||||
if(file.canWrite()){
|
||||
// TODO delete
|
||||
if(!Version.APP_VERSION.equalsIgnoreCase(context.getSettings().PREVIOUS_INSTALLED_VERSION.get())){
|
||||
try {
|
||||
progress.startTask(context.getString(R.string.installing_new_resources), -1);
|
||||
|
@ -375,33 +380,40 @@ public class ResourceManager {
|
|||
context.getSettings().PREVIOUS_INSTALLED_VERSION.set(Version.APP_VERSION);
|
||||
} catch (IOException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
} catch (XmlPullParserException e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
private void copyingAssets(AssetManager assetManager, String ref, File dir, IProgress progress) throws IOException {
|
||||
for(String asset : assetManager.list(ref)) {
|
||||
boolean isDirectory = !asset.contains(".");
|
||||
File file = new File(dir, asset);
|
||||
String fullName = ref+asset;
|
||||
if(isDirectory){
|
||||
file.mkdirs();
|
||||
copyingAssets(assetManager, fullName +"/", file , progress);
|
||||
} else {
|
||||
// asset descriptor can not be opened for some files
|
||||
// AssetFileDescriptor fd = assetManager.openFd(fullName);
|
||||
// long declaredLength = fd.getDeclaredLength();
|
||||
// fd.close();
|
||||
//if(!file.exists() || file.length() != declaredLength){
|
||||
InputStream is = assetManager.open(fullName, AssetManager.ACCESS_STREAMING);
|
||||
FileOutputStream out = new FileOutputStream(file);
|
||||
Algoritms.streamCopy(is, out);
|
||||
out.close();
|
||||
is.close();
|
||||
//}
|
||||
private void copyingAssets(AssetManager assetManager, String ref, File dir, IProgress progress) throws IOException, XmlPullParserException {
|
||||
XmlPullParser parser = XmlPullParserFactory.newInstance().newPullParser();
|
||||
|
||||
Map<String, String> resourcesToCopy = new LinkedHashMap<String, String>();
|
||||
InputStream open = assetManager.open("distributed_assets.xml");
|
||||
parser.setInput(open, "UTF-8");
|
||||
int next = 0;
|
||||
while((next = parser.next()) != XmlPullParser.END_DOCUMENT){
|
||||
if(next == XmlPullParser.START_TAG && parser.getName().equals("asset")){
|
||||
String in = parser.getAttributeValue(null, "name");
|
||||
String out = parser.getAttributeValue(null, "destination");
|
||||
resourcesToCopy.put(in, out);
|
||||
}
|
||||
}
|
||||
open.close();
|
||||
|
||||
for (String asset : resourcesToCopy.keySet()) {
|
||||
String destination = resourcesToCopy.get(asset);
|
||||
File file = new File(dir, destination);
|
||||
file.mkdirs();
|
||||
InputStream is = assetManager.open(asset, AssetManager.ACCESS_STREAMING);
|
||||
FileOutputStream out = new FileOutputStream(file);
|
||||
Algoritms.streamCopy(is, out);
|
||||
out.close();
|
||||
is.close();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue