I'm creating an app that allows the user to add a signature by drawing it onto a canvas. From my previous research, I've decided to use a library I've discovered on Github called SignatureView.
The signature view works fine until scrolling is enabled, at this point, the scrolling still takes place when the user is drawing, meaning the canvas moves during their input.
Due to this, I would like to disable scrolling when the user is interacting with the signature view. So far I've attempted to place the view in a nested scroll view and multiple xml attributes, but non of these seem to have any effect.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fitsSystemWindows="true"
xmlns:tools="http://schemas.android.com/tools"
tools:context="com.example.jordan.promise.fragments.EnterSignature"
android:configChanges="orientation|screenSize"
android:name=".MainActivity"
android:label="@string/app_name">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="56dp"
android:paddingLeft="24dp"
android:paddingRight="24dp">
<com.kyanogen.signatureview.SignatureView
xmlns:sign="http://schemas.android.com/apk/res-auto"
android:id="@+id/signature_view"
android:layout_width="fill_parent"
android:layout_height="200dp"
android:layout_weight="1"
sign:penSize="5dp"
sign:backgroundColor="#ffffff"
sign:penColor="#000000"
sign:enableSignature="true"/>
</ScrollView>
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (getArguments() != null) {
mParam1 = getArguments().getString(ARG_PARAM1);
mParam2 = getArguments().getString(ARG_PARAM2);
}
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.fragment_enter_signature, container, false);
SharedPreferences sharedPref = getActivity().getPreferences(Context.MODE_PRIVATE);
String defaultValue = getResources().getString(R.string.error_name);
String firstName = sharedPref.getString(getString(R.string.user_first), defaultValue);
//Greet User and provide instructionsView for entering signature
helloFirst = view.findViewById(R.id.hello_first);
instructionsView = view.findViewById(R.id.sig_instructions);
String hello = getResources().getString(R.string.hello);
String instructions = getResources().getString(R.string.enter_signature_instruction);
helloFirst.setText(String.format("%s %s!", hello, firstName)); //Title/Welcome text
instructionsView.setText(instructions);
sigBtn = view.findViewById(R.id.signatureBtn);//Continue button, changes text if signature is present
isDirty = false; //Solves API bug were isDirty only detects if a gesture is taking place
//Signature Capture
clearSignature = view.findViewById(R.id.clearBtn);
clearSignature.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
signatureView.clearCanvas();
isDirty = false;
}
});
//Check That Signature Field is not Empty
thread = new Thread() {
@Override
public void run() {
try {
while(true) {
sleep(1000);
Log.i("handler" , "running");
if(signatureView.isDirty() || isDirty) {
sigBtn.setText(getResources().getString(R.string.accept_sig));
isDirty = true;
}
else {
sigBtn.setText(getResources().getString(R.string.decline_sig));
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
};
thread.start();
setHasOptionsMenu(true);
signatureView = view.findViewById(R.id.signature_view);
return view;
}
Thank you in advance for any help. I hope this makes sense but please let me know if you need any clarifications or more information.
In case anyone stumbles across this. My solution was to create a separate layout for landscape, I then placed and sized the elements so that scrolling wouldn't be an issue.