Skip to content

Commit

Permalink
Improve ENC object scaling, improve Android settings responsiveness.
Browse files Browse the repository at this point in the history
  • Loading branch information
David Register committed Jul 29, 2015
1 parent 71a8a74 commit 1c27c56
Show file tree
Hide file tree
Showing 15 changed files with 119 additions and 63 deletions.
20 changes: 10 additions & 10 deletions buildandroid/android/src/org/opencpn/OCPNSettingsActivity.java
Expand Up @@ -71,7 +71,7 @@ public void onBuildHeaders(List<Header> target) {
String settings = extras.getString("SETTINGS_STRING");

Log.i("DEBUGGER_TAG", "OCPNSettingsActivity");
Log.i("DEBUGGER_TAG", settings);
// Log.i("DEBUGGER_TAG", settings);

m_settings = settings;
m_newSettings = "";
Expand All @@ -82,13 +82,13 @@ public void onBuildHeaders(List<Header> target) {

while(tkz.hasMoreTokens()){
String tk = tkz.nextToken();
Log.i("DEBUGGER_TAG", tk);
// Log.i("DEBUGGER_TAG", tk);

if( tk.startsWith("ChartDir") ){
int mark = tk.indexOf(":");
if(mark > 0){
String dir = tk.substring(mark+1);
Log.i("DEBUGGER_TAG", dir);
// Log.i("DEBUGGER_TAG", dir);
m_chartDirList.add(dir);
}
}
Expand Down Expand Up @@ -122,8 +122,8 @@ else if( tk.startsWith("prefs_") ){ // simple string
int mark = tk.indexOf(":");
if(mark > 0){
String key = tk.substring(0, mark);
Log.i("DEBUGGER_TAG", key);
Log.i("DEBUGGER_TAG", (mbS52)?"True":"False");
// Log.i("DEBUGGER_TAG", key);
// Log.i("DEBUGGER_TAG", (mbS52)?"True":"False");
String value = tk.substring(mark+1);
editor.putString(key, value);
}
Expand Down Expand Up @@ -232,7 +232,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {

String message = fileCreated? "File created" : "File opened";
message += ": " + filePath + " parentDir:" + parentDir;;
Log.i("DEBUGGER_TAG", message);
// Log.i("DEBUGGER_TAG", message);
m_chartDirList.add(filePath);

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
Expand Down Expand Up @@ -297,10 +297,10 @@ private void createSettingsString()
for(int i=0 ; i < m_chartDirList.size() ; ++i){
m_newSettings = m_newSettings.concat("ChartDir:");
String dir = m_chartDirList.get(i);
Log.i("DEBUGGER_TAG", dir);
// Log.i("DEBUGGER_TAG", dir);
m_newSettings = m_newSettings.concat(dir);
m_newSettings = m_newSettings.concat(";");
Log.i("DEBUGGER_TAG", m_newSettings);
// Log.i("DEBUGGER_TAG", m_newSettings);

}

Expand Down Expand Up @@ -343,7 +343,7 @@ private void createSettingsString()
m_newSettings = m_newSettings.concat(appendStringSetting("prefs_chartScaleFactor", preferences.getString("prefs_chartScaleFactor", "?")));
m_newSettings = m_newSettings.concat(appendStringSetting("prefs_chartInitDir", preferences.getString("prefs_chartInitDir", "?")));

Log.i("DEBUGGER_TAG", m_newSettings);
// Log.i("DEBUGGER_TAG", m_newSettings);

}

Expand Down Expand Up @@ -409,7 +409,7 @@ public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Can retrieve arguments from preference XML.
Log.i("args", "Arguments: " + getArguments());
// Log.i("args", "Arguments: " + getArguments());

// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.charts_vector_settings);
Expand Down
Expand Up @@ -163,7 +163,7 @@ public class QtActivity extends Activity implements ActionBar.OnNavigationListen

// Definitions found in OCPN "chart1.h"
private final static int ID_CMD_APPLY_SETTINGS = 300;

private final static int ID_CMD_NULL_REFRESH = 301;

private final static int CHART_TYPE_CM93COMP = 7; // must line up with OCPN types
private final static int CHART_FAMILY_RASTER = 1;
Expand Down Expand Up @@ -502,9 +502,24 @@ public String getDisplayMetrics(){

Log.i("DEBUGGER_TAG", ret);



return ret;
}

public String getDeviceInfo(){
String s="Device Info:";
s += "\n OS Version: " + System.getProperty("os.version") + "(" + android.os.Build.VERSION.INCREMENTAL + ")";
s += "\n OS API Level: "+android.os.Build.VERSION.RELEASE + "("+android.os.Build.VERSION.SDK_INT+")";
s += "\n Device: " + android.os.Build.DEVICE;
s += "\n Model (and Product): " + android.os.Build.MODEL + " ("+ android.os.Build.PRODUCT + ")";

Log.i("DEBUGGER_TAG", s);

return s;
}


public String showBusyCircle(){
// Log.i("DEBUGGER_TAG", "show");

Expand Down Expand Up @@ -1733,19 +1748,27 @@ public boolean super_dispatchTrackballEvent(MotionEvent event)
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
Log.i("DEBUGGER_TAG", "onActivityResultA");
// Log.i("DEBUGGER_TAG", "onActivityResultA");
if (requestCode == OCPN_SETTINGS_REQUEST_CODE) {
Log.i("DEBUGGER_TAG", "onqtActivityResultC");
// Log.i("DEBUGGER_TAG", "onqtActivityResultC");
// Make sure the request was successful
if (resultCode == RESULT_OK)
{
Log.i("DEBUGGER_TAG", "onqtActivityResultD");
// Log.i("DEBUGGER_TAG", "onqtActivityResultD");
m_settingsReturn = data.getStringExtra("SettingsString");
nativeLib.invokeCmdEventCmdString( ID_CMD_APPLY_SETTINGS, m_settingsReturn);
Log.i("DEBUGGER_TAG", m_settingsReturn);
nativeLib.invokeCmdEventCmdString( ID_CMD_NULL_REFRESH, m_settingsReturn);

// defer hte application of settings until the screen refreshes
Handler handler = new Handler();
handler.postDelayed(new Runnable() {
public void run() {
nativeLib.invokeCmdEventCmdString( ID_CMD_APPLY_SETTINGS, m_settingsReturn);
}
}, 100);
// Log.i("DEBUGGER_TAG", m_settingsReturn);
}
else if (resultCode == RESULT_CANCELED){
Log.i("DEBUGGER_TAG", "onqtActivityResultE");
// Log.i("DEBUGGER_TAG", "onqtActivityResultE");
}

super.onActivityResult(requestCode, resultCode, data);
Expand Down
1 change: 1 addition & 0 deletions include/OCPNPlatform.h
Expand Up @@ -100,6 +100,7 @@ class OCPNPlatform
wxDirDialog *AdjustDirDialogFont(wxWindow *container, wxDirDialog *dlg);

void PositionAISAlert( wxWindow *alert_window);
float getChartScaleFactorExp( float scale_linear );

//--------------------------------------------------------------------------
// Per-Platform file/directory support
Expand Down
2 changes: 2 additions & 0 deletions include/androidUTIL.h
Expand Up @@ -56,6 +56,8 @@

extern bool androidUtilInit( void );

extern wxString androidGetDeviceInfo();

extern bool androidGetMemoryStatus( int *mem_total, int *mem_used );

extern double GetAndroidDisplaySize();
Expand Down
1 change: 1 addition & 0 deletions include/chart1.h
Expand Up @@ -198,6 +198,7 @@ enum
// Command identifiers for wxCommandEvents coming from the outside world.
// Removed from enum to facilitate constant definition
#define ID_CMD_APPLY_SETTINGS 300
#define ID_CMD_NULL_REFRESH 301



Expand Down
23 changes: 23 additions & 0 deletions src/OCPNPlatform.cpp
Expand Up @@ -215,6 +215,7 @@ extern wxArrayOfConnPrm *g_pConnectionParams;
extern bool g_fog_overzoom;
extern double g_overzoom_emphasis_base;
extern bool g_oz_vector_scale;
extern int g_nTrackPrecision;

#ifdef ocpnUSE_GL
extern ocpnGLOptions g_GLOptions;
Expand Down Expand Up @@ -509,8 +510,12 @@ void OCPNPlatform::Initialize_1( void )

// Called from MyApp() immediately before creation of MyFrame()
// Config is known to be loaded and stable
// Log is available
void OCPNPlatform::Initialize_2( void )
{
#ifdef __OCPN__ANDROID__
wxLogMessage(androidGetDeviceInfo());
#endif
}

// Called from MyApp() just before end of MyApp::OnInit()
Expand Down Expand Up @@ -559,6 +564,7 @@ void OCPNPlatform::SetDefaultOptions( void )
g_bShowAreaNotices = false;
g_bDrawAISSize = false;
g_bShowAISName = false;
g_nTrackPrecision = 2;


#ifdef __OCPN__ANDROID__
Expand Down Expand Up @@ -1331,6 +1337,23 @@ double OCPNPlatform::GetCompassScaleFactor( int GUIScaleFactor )
return rv;
}

float OCPNPlatform::getChartScaleFactorExp( float scale_linear )
{
double factor = 1.0;
#ifndef __OCPN__ANDROID__
factor = exp( scale_linear * (0.693 / 5.0) ); // exp(2)

#else
// the idea here is to amplify the scale factor for higher density displays, in a measured way....
factor = exp( scale_linear * (0.693 / 5.0) * getAndroidDisplayDensity());
#endif

factor = wxMax(factor, .5);
factor = wxMin(factor, 4.);


return factor;
}


#ifdef __WXMSW__
Expand Down
6 changes: 2 additions & 4 deletions src/RoutePoint.cpp
Expand Up @@ -53,7 +53,7 @@ extern float g_fWaypointRangeRingsStep;
extern int g_iWaypointRangeRingsStepUnits;
extern wxColour g_colourWaypointRangeRingsColour;

extern int g_ChartScaleFactor;
extern float g_ChartScaleFactorExp;

#include <wx/listimpl.cpp>
WX_DEFINE_LIST ( RoutePointList );
Expand Down Expand Up @@ -594,9 +594,7 @@ void RoutePoint::DrawGL( ViewPort &vp, OCPNRegion &region,bool use_cached_screen

float scale = 1.0;
if(g_bresponsive){
scale = exp( g_ChartScaleFactor * (0.693 / 5.0) ); // exp(2)
scale = wxMax(scale, .5);
scale = wxMin(scale, 4.);
scale = g_ChartScaleFactorExp;
}

float ws = r1.width * scale;
Expand Down
6 changes: 2 additions & 4 deletions src/ais.cpp
Expand Up @@ -118,8 +118,8 @@ extern double g_AckTimeout_Mins;
extern bool bGPSValid;
extern ArrayOfMMSIProperties g_MMSI_Props_Array;

extern int g_ChartScaleFactor;
extern bool g_bresponsive;
extern float g_ChartScaleFactorExp;

extern PlugInManager *g_pi_manager;
extern ocpnStyle::StyleManager* g_StyleManager;
Expand Down Expand Up @@ -823,9 +823,7 @@ static void AISDrawTarget( AIS_Target_Data *td, ocpnDC& dc )

float scale_factor = 1.0;
if(g_bresponsive){
scale_factor = exp( g_ChartScaleFactor * (0.693 / 5.0) ); // exp(2)
scale_factor = wxMax(scale_factor, .5);
scale_factor = wxMin(scale_factor, 4.);
scale_factor = g_ChartScaleFactorExp;
}

// Skip anchored/moored (interpreted as low speed) targets if requested
Expand Down
28 changes: 17 additions & 11 deletions src/androidUTIL.cpp
Expand Up @@ -698,9 +698,6 @@ extern "C"{
{
qDebug() << "onResume";

if(cc1)
cc1->RenderLastGLCanvas();

g_bSleep = false;

return 96;
Expand Down Expand Up @@ -847,18 +844,20 @@ wxString callActivityMethod_vs(const char *method)
QAndroidJniObject data = activity.callObjectMethod(method, "()Ljava/lang/String;");

jstring s = data.object<jstring>();
qDebug() << s;

// Need a Java environment to decode the resulting string
if (java_vm->GetEnv( (void **) &jenv, JNI_VERSION_1_6) != JNI_OK) {
qDebug() << "GetEnv failed.";
}
else {
const char *ret_string = (jenv)->GetStringUTFChars(s, NULL);
return_string = wxString(ret_string, wxConvUTF8);
if(s){
// Need a Java environment to decode the resulting string
if (java_vm->GetEnv( (void **) &jenv, JNI_VERSION_1_6) != JNI_OK) {
qDebug() << "GetEnv failed.";
}
else {
const char *ret_string = (jenv)->GetStringUTFChars(s, NULL);
return_string = wxString(ret_string, wxConvUTF8);
}
}

return return_string;

}


Expand Down Expand Up @@ -1044,6 +1043,13 @@ wxString callActivityMethod_s4s(const char *method, wxString parm1, wxString par
}


wxString androidGetDeviceInfo()
{
wxString info = callActivityMethod_vs("getDeviceInfo");

return info;
}

wxString androidGetHomeDir()
{
return g_androidFilesDir + _T("/");
Expand Down
16 changes: 14 additions & 2 deletions src/chart1.cpp
Expand Up @@ -357,6 +357,7 @@ bool g_config_display_size_manual;

int g_GUIScaleFactor;
int g_ChartScaleFactor;
float g_ChartScaleFactorExp;

#ifdef USE_S57
s52plib *ps52plib;
Expand Down Expand Up @@ -4058,6 +4059,11 @@ void MyFrame::OnToolLeftClick( wxCommandEvent& event )
break;
}

case ID_CMD_NULL_REFRESH:{
Refresh(true);
break;
}

default: {
// Look for PlugIn tools
// If found, make the callback.
Expand Down Expand Up @@ -9175,8 +9181,10 @@ void MyFrame::UpdateAISMOBRoute( AIS_Target_Data *ptarget )

}


void MyFrame::applySettingsString( wxString settings)
{
g_Platform->ShowBusySpinner();

// Parse the passed settings string
// wxLogMessage( settings );
Expand Down Expand Up @@ -9295,8 +9303,10 @@ void MyFrame::applySettingsString( wxString settings)

else if(token.StartsWith( _T("prefs_chartScaleFactor"))){
double a;
if(val.ToDouble(&a))
if(val.ToDouble(&a)){
g_ChartScaleFactor = wxRound( (a / 10.) - 5.);
g_ChartScaleFactorExp = g_Platform->getChartScaleFactorExp( g_ChartScaleFactor );
}
}

else if(token.StartsWith( _T("prefs_chartInitDir"))){
Expand Down Expand Up @@ -9449,7 +9459,6 @@ void MyFrame::applySettingsString( wxString settings)
}
}


ProcessOptionsDialog( rr, &NewDirArray );

if(previous_expert && !g_bUIexpert){
Expand All @@ -9463,6 +9472,7 @@ void MyFrame::applySettingsString( wxString settings)
ShowChartBarIfEnabled();

gFrame->Raise();

cc1->InvalidateGL();
DoChartUpdate();
UpdateControlBar();
Expand Down Expand Up @@ -9506,6 +9516,8 @@ void MyFrame::applySettingsString( wxString settings)
if (NMEALogWindow::Get().Active())
NMEALogWindow::Get().GetTTYWindow()->Raise();

g_Platform->HideBusySpinner();

}


Expand Down

0 comments on commit 1c27c56

Please sign in to comment.