President tells supporters at July 4 celebration that racial justice protests threaten foundations of US society.