Skip to content

Commit

Permalink
Merge pull request #99 from dymmeh/access_raw_res_properly
Browse files Browse the repository at this point in the history
Access raw resources using R.raw instead of by a filename string
  • Loading branch information
Michael Spinelli authored May 28, 2021
2 parents 6875ad5 + fa65ad3 commit f2475bd
Show file tree
Hide file tree
Showing 11 changed files with 48 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public void loadRenderer() {

mir = MilStdIconRenderer.getInstance();
String cacheDir = getApplicationContext().getCacheDir().getAbsoluteFile().getAbsolutePath();
mir.init(cacheDir);
mir.init(this, cacheDir);
DisplayMetrics metrics = new DisplayMetrics();
//getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
getWindowManager().getDefaultDisplay().getMetrics(metrics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void loadRenderer()

mir = MilStdIconRenderer.getInstance();
String cacheDir = getApplicationContext().getCacheDir().getAbsoluteFile().getAbsolutePath();
mir.init(cacheDir);
mir.init(this, cacheDir);
DisplayMetrics metrics = new DisplayMetrics();
//getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
getWindowManager().getDefaultDisplay().getMetrics(metrics);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public void loadRenderer() {

mir = MilStdIconRenderer.getInstance();
String cacheDir = getApplicationContext().getCacheDir().getAbsoluteFile().getAbsolutePath();
mir.init(cacheDir);
mir.init(this, cacheDir);
DisplayMetrics metrics = new DisplayMetrics();
//getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
getWindowManager().getDefaultDisplay().getMetrics(metrics);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package armyc2.c2sd.renderer;

import android.content.Context;
import android.util.Log;
import android.util.SparseArray;

Expand Down Expand Up @@ -31,21 +32,21 @@ public static synchronized MilStdIconRenderer getInstance()
*
* @param cacheDir
*/
public synchronized void init(String cacheDir)// List<Typeface> fonts, List<String> xml
public synchronized void init(Context context, String cacheDir)// List<Typeface> fonts, List<String> xml
{
try {
if (!_initSucces.get()) {

_cacheDir = cacheDir;

// setup fonts
FontManager.getInstance().init(cacheDir);
FontManager.getInstance().init(context, cacheDir);

UnitDefTable.getInstance().init();
UnitFontLookup.getInstance().init();
SymbolDefTable.getInstance().init();
SinglePointLookup.getInstance().init();
TacticalGraphicLookup.getInstance().init();
UnitDefTable.getInstance().init(context);
UnitFontLookup.getInstance().init(context);
SymbolDefTable.getInstance().init(context);
SinglePointLookup.getInstance().init(context);
TacticalGraphicLookup.getInstance().init(context);

// PROTOTYPE SVG////////////////////////////////////////
// works, but half speed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package armyc2.c2sd.renderer.utilities;

import armyc2.c2sd.singlepointrenderer.R;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.UUID;

import android.content.Context;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
Expand All @@ -27,12 +30,6 @@ public class FontManager {
private Typeface _tfUnits = null;
private Typeface _tfSP = null;
private Typeface _tfTG = null;
private String unitFontName = "unitfont.ttf";
private String spFontName = "singlepointfont.ttf";
private String tgFontName = "tacticalgraphicsfont.ttf";//*/
/*private String unitFontName = "unitfont.otf";
private String spFontName = "singlepointfont.otf";
private String tgFontName = "tacticalgraphicsfont.otf";//*/
private String _cacheDir = "";

private FontManager()
Expand All @@ -48,14 +45,14 @@ public static synchronized FontManager getInstance()
return _instance;
}

public synchronized void init(String cacheDir)
public synchronized void init(Context context, String cacheDir)
{
if(!_initSuccess)
{
_cacheDir = cacheDir;
_tfUnits = loadFont(unitFontName);
_tfSP = loadFont(spFontName);
_tfTG = loadFont(tgFontName);
_tfUnits = loadFont(context, R.raw.unitfont);
_tfSP = loadFont(context, R.raw.singlepointfont);
_tfTG = loadFont(context, R.raw.tacticalgraphicsfont);
if( _tfUnits != null && _tfSP != null && _tfTG != null)
_initSuccess = true;
else
Expand Down Expand Up @@ -85,16 +82,15 @@ else if(fontName == FONT_MPTG)
throw new Error("FontManager: Must call \".init(String cacheDir)\" before using");
}

private Typeface loadFont(String fontName)
private Typeface loadFont(Context context, int fontName)
{
String fontFolder = "res/raw/";
Typeface tf = null;
InputStream is = null;
try
{

//InputStream fontStream = this.getClass().getClassLoader().getResourceAsStream("assets/fonts/unitfonts.ttf");
is = this.getClass().getClassLoader().getResourceAsStream(fontFolder + fontName);
is = context.getResources().openRawResource(fontName);

if(is != null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

package armyc2.c2sd.renderer.utilities;

import armyc2.c2sd.singlepointrenderer.R;

import android.content.Context;
import android.util.Log;

import java.io.BufferedInputStream;
Expand Down Expand Up @@ -52,15 +55,14 @@ public static synchronized SinglePointLookup getInstance()
return _instance;
}

public synchronized void init()
public synchronized void init(Context context)
{

if (_initCalled == false) {
_instance = new SinglePointLookup();

try {
DataInputStream dis = new DataInputStream(new BufferedInputStream(getClass().getClassLoader
().getResourceAsStream("res/raw/singlepoint.bin")));
DataInputStream dis = new DataInputStream(new BufferedInputStream(context.getResources().openRawResource(R.raw.singlepoint)));
readBinary(dis);
dis.close();
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
* import java.io.*; import java.util.HashMap; import java.util.Map;
*/

import armyc2.c2sd.singlepointrenderer.R;

import android.content.Context;
import android.util.Log;

import java.io.BufferedInputStream;
Expand Down Expand Up @@ -78,7 +81,7 @@ public static synchronized SymbolDefTable getInstance()
return _instance;
}

public final synchronized void init()
public final synchronized void init(Context context)
{
if (_initCalled == false) {
_SymbolDefinitionsB = new HashMap<>();
Expand All @@ -88,8 +91,7 @@ public final synchronized void init()
_SymbolDefDupsC = new ArrayList<>();

try {
DataInputStream dis = new DataInputStream(new BufferedInputStream(this.getClass()
.getClassLoader().getResourceAsStream("res/raw/symbolconstants.bin")));
DataInputStream dis = new DataInputStream(new BufferedInputStream(context.getResources().openRawResource(R.raw.symbolconstants)));
readBinary(dis);
dis.close();
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
*/
package armyc2.c2sd.renderer.utilities;

import armyc2.c2sd.singlepointrenderer.R;

import android.content.Context;
import android.util.Log;

import java.io.BufferedInputStream;
Expand Down Expand Up @@ -36,11 +39,10 @@ public static synchronized TacticalGraphicLookup getInstance()
return _instance;
}

public synchronized void init()
public synchronized void init(Context context)
{
try {
DataInputStream dis = new DataInputStream(new BufferedInputStream(getClass().getClassLoader
().getResourceAsStream("res/raw/tacticalgraphic.bin")));
DataInputStream dis = new DataInputStream(new BufferedInputStream(context.getResources().openRawResource(R.raw.tacticalgraphic)));
readBinary(dis);
dis.close();
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

package armyc2.c2sd.renderer.utilities;

import armyc2.c2sd.singlepointrenderer.R;

import android.content.Context;
import android.util.Log;

import java.io.BufferedInputStream;
Expand Down Expand Up @@ -49,7 +52,7 @@ public static synchronized UnitDefTable getInstance()
* if(foo.getHierarchy().equalsIgnoreCase(hierarchy)) { return } } }
*/

public synchronized void init()
public synchronized void init(Context context)
{
if (_initCalled == false) {

Expand All @@ -60,8 +63,7 @@ public synchronized void init()
_UnitDefDupsC = new ArrayList<>();

try {
DataInputStream dis = new DataInputStream(new BufferedInputStream(getClass().getClassLoader
().getResourceAsStream("res/raw/unitconstants.bin")));
DataInputStream dis = new DataInputStream(new BufferedInputStream(context.getResources().openRawResource(R.raw.unitconstants)));
readBinary(dis);
dis.close();
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

package armyc2.c2sd.renderer.utilities;

import armyc2.c2sd.singlepointrenderer.R;

import android.content.Context;
import android.util.Log;

import java.io.BufferedInputStream;
Expand Down Expand Up @@ -90,14 +93,13 @@ public static synchronized UnitFontLookup getInstance()
return _instance;
}

public synchronized void init()
public synchronized void init(Context context)
{
if (_initCalled == false) {
_instance = new UnitFontLookup();

try {
DataInputStream dis = new DataInputStream(new BufferedInputStream(getClass().getClassLoader
().getResourceAsStream("res/raw/unitfontmappings.bin")));
DataInputStream dis = new DataInputStream(new BufferedInputStream(context.getResources().openRawResource(R.raw.unitfontmappings)));
readBinary(dis);
dis.close();
} catch (IOException e) {
Expand Down
5 changes: 3 additions & 2 deletions renderer/src/main/java/sec/web/render/SECWebRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// It requires that you import the plugins.jar from the jdk folder into the project libraries
//import netscape.javascript.JSObject;

import android.content.Context;
import android.graphics.BitmapShader;
import android.graphics.Shader;
import android.util.SparseArray;
Expand Down Expand Up @@ -75,13 +76,13 @@ public final class SECWebRenderer /* extends Applet */ {
private static boolean _initSuccess = false;


public static synchronized void init(String cacheDir) {
public static synchronized void init(Context context, String cacheDir) {

try
{
if(_initSuccess == false)
{
MilStdIconRenderer.getInstance().init(cacheDir);
MilStdIconRenderer.getInstance().init(context, cacheDir);
//use SECWebRenderer.setLoggingLevel()

//sets default value for single point symbology to have an outline.
Expand Down

0 comments on commit f2475bd

Please sign in to comment.