...
Code Block |
---|
|
@Override
protected void onCreate(Bundle savedInstanceState)
{
...
m_ARES = new ARESDelegate( this );
m_CommonUI = new CommonUIDelegate();
...
CFxARESInstance.instance().delegate = m_ARES;
CFxARESInstance.instance().start( this );
CFxCommonUI.instance().startWithDelegate( m_CommonUI );
...
m_ARESView = findViewById( R.id.id_aresview )
...
} |
File: ARESDelegate.java
Code Block |
---|
|
@Override
public CFxARESDocumentView getDocumentView()
{
return m_Host.m_ARESView;
} |
DWG Viewer - Load drawing
...
File: ARESDelegate.java
Code Block |
---|
@Override
public void documentCreated(){...}
@Override
public void documentActivated(){...} |
...
Code Block |
---|
private void LoadDrawing(){
...
m_ARESView.setVisibility( View.VISIBLE );...String fileName = "assets:/Samples/" + sampleDrawings[ which ];
String command = "_OPEN\n" + fileName + "\n";
CFxARESInstance.instance().runCommand( command, false );
...
}
public void DocumentCreated(){...}
public void DocumentActivated(String[] layouts){...} |
...
File: ARESDelegate.java
Code Block |
---|
@Override
public void documentDestroyed(){...} |
...
Code Block |
---|
private void LoadDrawing(){
...
if ( m_DocumentOpened )
{
String command = "_CLOSE\n";
CFxARESInstance.instance().runCommand( command, false );
return;
}
...
}
public void DocumentClosed(){
...
m_ARESView.setVisibility( View.GONE );
} |
DWG Viewer - Change viewing modes
...
Code Block |
---|
private void SwitchViewMode( boolean panMode ){
...
CFxARESInstance.instance().runCommand("'2dmode $M=$(if,$(and,$(getvar,2dmode),1),$(-,$(getvar,2dmode),1),$(+,$(getva r,2dmode),1))");
} |
Note: The core also provides commands like ZOOM or PAN to achieve similar results.
...
Code Block |
---|
private void SetBackground( @BackgroundColor final int color )
{
CFxARESInstance.instance().runOnWorkingThread(new Runnable()
{
@Override
public void run()
{
JNI.SetBackgroundColor( color );
}
});
} |
File: JNI.java
Code Block |
---|
|
public static native void SetBackgroundColor( int color ); |
...
File: ARES_Simplified_JNI.cpp
Code Block |
---|
|
JNIEXPORT void JNICALL Java_com_graebert_aressimplified_JNI_SetBackgroundColor( JNIEnv * env, jclass clazz, jint color ){ ... } |
...
The DWG Viewer uses a native method GetLayoutNames() to get all available sheets of the drawing when documentActivated() is triggered. All layouts are passed to the method DocumentActivated() of the main activity and a corresponding button is created for each layout. The button is linked with a command expression that is executed when tapped. The command _SHEET_CONTROL handles the layout switch. The native method GetLayoutNames() manipulates the UI of the application and must be executed from the ui thread of the host application. A suitable method runOnUiThread() is provided by CFxARESInstance.instance().
File: JNI.java
Code Block |
---|
|
public static native String[] GetLayoutNames(); |
File: ARES_Simplified_JNI.cpp
Code Block |
---|
|
JNIEXPORT jobjectArray JNICALL Java_com_graebert_aressimplified_JNI_GetLayoutNames( JNIEnv * env, jclass clazz ){ ... } |
...
File: ARESDelegate.java
Code Block |
---|
@Override
public void documentActivated()
{
final String layouts[] = JNI.GetLayoutNames();
CFxARESInstance.instance().runOnUiThread(new Runnable()
{
@Override
public void run()
{
m_Host.DocumentActivated( layouts );
}
});
} |
File: MainActivity.java
Code Block |
---|
public void DocumentActivated(String[] layouts)
{
for ( final String layout : layouts )
{
Button layoutActivateButton = new Button( this );
layoutActivateButton.setText( layout );
layoutActivateButton.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
String command = "_SHEET_CONTROL\n_ACTIVATE\n" + layout + "\n";
CFxARESInstance.instance().runCommand( command );
}
});
m_Layouts.addView( layoutActivateButton, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT ) );
}
} |