Guest User

Untitled

a guest
Jul 16th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. Bitmap image = null;
  2.  
  3. @Override
  4. protected void onCreate(Bundle savedInstanceState) {
  5. super.onCreate(savedInstanceState);
  6.  
  7. image = (Bitmap) getLastNonConfigurationInstance();
  8.  
  9. if(bitmap == null){
  10. image = downloadImage();
  11. }
  12. setImage(bitmap);
  13. }
  14.  
  15.  
  16. @Override
  17. public Object onRetainNonConfigurationInstance() {
  18. return bitmap;
  19. }
  20.  
  21. <activity android:name=".Explorer" android:label="@string/app_name"
  22. android:configChanges="orientation" android:launchMode="standard">
  23. </activity>
  24.  
  25. @Override
  26. public void onConfigurationChanged(Configuration _newConfig){
  27. super.onConfigurationChanged(_newConfig);
  28. int height = getWindowManager().getDefaultDisplay().getHeight();
  29. int width = getWindowManager().getDefaultDisplay().getWidth();
  30. if(width > height){
  31. // layout for landscape
  32. }else{
  33. // layout for portrait
  34. }
  35. }
  36.  
  37. void showDataView()
  38. {
  39. setContentView(mainView);
  40. currentView = mainView;
  41. }
  42.  
  43. void showGraphView()
  44. {
  45. if(currentView == mainView){
  46. if(graphView == null){
  47. setContentView(R.layout.graphview);
  48. graphView = (GraphView)findViewById(R.id.graphview);
  49. }
  50. setContentView(graphView);
  51. currentView = graphView;
  52. graphView.setDataToPlot(DATA_TO_PLOT);
  53. graphView.clear();
  54. }
  55. }
  56.  
  57. @Override
  58. public void onConfigurationChanged(Configuration _newConfig){
  59. super.onConfigurationChanged(_newConfig);
  60. int height = getWindowManager().getDefaultDisplay().getHeight();
  61. int width = getWindowManager().getDefaultDisplay().getWidth();
  62. if(width > height){
  63. showGraphView();
  64. }else{
  65. showDataView();
  66. }
  67. if(graphView != null) graphView.setGraphWidth(width);
  68. }
Add Comment
Please, Sign In to add comment