add lproj localisation
This commit is contained in:
parent
fac2c7a49b
commit
5f4e2e513c
5 changed files with 48 additions and 12 deletions
|
@ -31,7 +31,8 @@ public class PassVisualizer {
|
|||
findById(res, R.id.navigateTo).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
NavigateToLocationsDialog.perform(activity, App.getPassStore().getPassbookForId(pass.getId()), false);
|
||||
final String lang = activity.getResources().getConfiguration().locale.getLanguage();
|
||||
NavigateToLocationsDialog.perform(activity, App.getPassStore().getPassbookForId(pass.getId(), lang), false);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
|
|
|
@ -61,7 +61,8 @@ public class AndroidFileSystemPassStore implements PassStore {
|
|||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
final Pass pass = AppleStylePassReader.read(getPathForID(id));
|
||||
final String language = context.getResources().getConfiguration().locale.getLanguage();
|
||||
final Pass pass = AppleStylePassReader.read(getPathForID(id), language);
|
||||
AXT.at(cachedFile).writeObject(pass);
|
||||
return pass;
|
||||
}
|
||||
|
@ -87,10 +88,10 @@ public class AndroidFileSystemPassStore implements PassStore {
|
|||
return passList.get(pos);
|
||||
}
|
||||
|
||||
public Pass getPassbookForId(final String id) {
|
||||
public Pass getPassbookForId(final String id,final String language) {
|
||||
final String mPath = path + "/" + id;
|
||||
// TODO read from cache
|
||||
return AppleStylePassReader.read(mPath);
|
||||
return AppleStylePassReader.read(mPath,language);
|
||||
}
|
||||
|
||||
public void sort(final SortOrder order) {
|
||||
|
|
|
@ -26,7 +26,7 @@ import java.util.regex.Pattern;
|
|||
|
||||
public class AppleStylePassReader {
|
||||
|
||||
public static Pass read(String path) {
|
||||
public static Pass read(String path,String language) {
|
||||
final PassImpl pass = new PassImpl();
|
||||
|
||||
if (path.endsWith("/")) {
|
||||
|
@ -39,9 +39,13 @@ public class AppleStylePassReader {
|
|||
|
||||
JSONObject pass_json = null, type_json = null;
|
||||
|
||||
pass.setIconBitmapFile(findBitmapFile(path, "icon"));
|
||||
pass.setLogoBitmapFile(findBitmapFile(path, "logo"));
|
||||
pass.setThumbnailBitmapFile(findBitmapFile(path, "thumbnail"));
|
||||
Optional<String> localized_path=Optional.absent();
|
||||
|
||||
localized_path=findLocalizedPath(path,language);
|
||||
|
||||
pass.setIconBitmapFile(findBitmapFile(path,localized_path, "icon"));
|
||||
pass.setLogoBitmapFile(findBitmapFile(path,localized_path, "logo"));
|
||||
pass.setThumbnailBitmapFile(findBitmapFile(path,localized_path, "thumbnail"));
|
||||
|
||||
final File file = new File(path + "/pass.json");
|
||||
|
||||
|
@ -210,8 +214,38 @@ public class AppleStylePassReader {
|
|||
return pass;
|
||||
}
|
||||
|
||||
private static String findBitmapFile(String path, String bitmap) {
|
||||
String res=path+"/"+bitmap+"@2x.png";
|
||||
private static Optional<String> findLocalizedPath(String path,String language) {
|
||||
|
||||
final File localized=new File(path,language+".lproj");
|
||||
|
||||
if (localized.exists() && localized.isDirectory()) {
|
||||
return Optional.of(localized.getPath());
|
||||
}
|
||||
|
||||
final File fallback=new File(path,"en.lproj");
|
||||
|
||||
if (fallback.exists() && fallback.isDirectory()) {
|
||||
return Optional.of(fallback.getPath());
|
||||
}
|
||||
|
||||
return Optional.absent();
|
||||
}
|
||||
|
||||
private static String findBitmapFile(String path, Optional<String> localizedPath, String bitmap) {
|
||||
String res;
|
||||
if (localizedPath.isPresent()) {
|
||||
res=localizedPath.get()+"/"+bitmap+"@2x.png";
|
||||
if (BitmapFactory.decodeFile(res)!=null) {
|
||||
return res;
|
||||
}
|
||||
|
||||
res=localizedPath.get()+"/"+bitmap+".png";
|
||||
if (BitmapFactory.decodeFile(res)!=null) {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
res=path+"/"+bitmap+"@2x.png";
|
||||
if (BitmapFactory.decodeFile(res)!=null) {
|
||||
return res;
|
||||
}
|
||||
|
|
|
@ -47,7 +47,7 @@ public interface PassStore {
|
|||
|
||||
public Pass getPassbookAt(int pos);
|
||||
|
||||
public Pass getPassbookForId(String id);
|
||||
public Pass getPassbookForId(String id,String language);
|
||||
|
||||
public void sort(SortOrder order);
|
||||
|
||||
|
|
|
@ -69,7 +69,7 @@ public class PassImportActivity extends ActionBarActivity {
|
|||
final String id = AXT.at(path.split("/")).last();
|
||||
|
||||
final PassStore store = App.getPassStore();
|
||||
store.setCurrentPass(store.getPassbookForId(id));
|
||||
store.setCurrentPass(store.getPassbookForId(id,getResources().getConfiguration().locale.getLanguage()));
|
||||
|
||||
AXT.at(PassImportActivity.this).startCommonIntent().activityFromClass(PassViewActivity.class);
|
||||
finish();
|
||||
|
|
Loading…
Reference in a new issue