1 package com.hwloc.lstopo;
2 
3 import android.app.Activity;
4 import android.content.Intent;
5 import android.os.Bundle;
6 import android.util.DisplayMetrics;
7 import android.view.View;
8 import android.widget.Button;
9 import android.widget.CheckBox;
10 import android.widget.RadioButton;
11 import android.widget.RadioGroup;
12 
13 import java.util.ArrayList;
14 
15 // Create a window to choose the filter to download topology
16 public class Options extends Activity {
17     @Override
onCreate(Bundle savedInstanceState)18     protected void onCreate(Bundle savedInstanceState) {
19         super.onCreate(savedInstanceState);
20 
21         setContentView(R.layout.options);
22         final Button apply = findViewById(R.id.apply);
23         final RadioButton logicalIndexes = findViewById(R.id.indexes_logical);
24         final RadioButton physicalIndexes = findViewById(R.id.indexes_physical);
25         final RadioButton defaultIndexes = findViewById(R.id.indexes_default);
26         final RadioButton ioObjectsWhole = findViewById(R.id.IO_object_whole);
27         final RadioButton ioObjectsNone = findViewById(R.id.IO_object_none);
28         final RadioButton ioObjectsDefault = findViewById(R.id.IO_object_default);
29         final CheckBox noFactorize = findViewById(R.id.no_factorize);
30         final CheckBox includeDisallowed = findViewById(R.id.include_disallowed);
31         final CheckBox noLegend = findViewById(R.id.no_legend);
32         final ArrayList<String> options = new ArrayList<>();
33 
34         final RadioGroup indexes1 = findViewById(R.id.indexes_group1);
35         final RadioGroup indexes2 = findViewById(R.id.indexes_group2);
36         final RadioGroup ioObjects1 = findViewById(R.id.IO_objects_group1);
37         final RadioGroup ioObjects2 = findViewById(R.id.IO_objects_group2);
38         syncRadioGroup(indexes1, indexes2);
39         syncRadioGroup(ioObjects1, ioObjects2);
40 
41         Intent intent = getIntent();
42         int i = 0;
43         while(intent.getStringExtra(Integer.toString(i)) != null) {
44             switch(intent.getStringExtra(Integer.toString(i))) {
45                 case "-l":
46                     logicalIndexes.setChecked(true);
47                     break;
48                 case "-p":
49                     physicalIndexes.setChecked(true);
50                     break;
51 
52                 case "--no-io":
53                     ioObjectsNone.setChecked(true);
54                     break;
55                 case "--whole-io":
56                     ioObjectsWhole.setChecked(true);
57                     break;
58 
59                 case "--no-factorize":
60                     noFactorize.setChecked(true);
61                     break;
62 
63                 case "--disallowed":
64                     includeDisallowed.setChecked(true);
65                     break;
66 
67                 case "--no-legend":
68                     noLegend.setChecked(true);
69                     break;
70             }
71             i++;
72         }
73 
74         // Set windows size
75         DisplayMetrics dm = new DisplayMetrics();
76         getWindowManager().getDefaultDisplay().getMetrics(dm);
77         int width = dm.widthPixels;
78         int height = dm.heightPixels;
79         getWindow().setLayout((int) (width * 0.8), (int) (height * 0.8));
80 
81         apply.setOnClickListener(new View.OnClickListener() {
82             @Override
83             public void onClick(View v) {
84                 if(logicalIndexes.isChecked())
85                     options.add("-l");
86                 else if(physicalIndexes.isChecked())
87                     options.add("-p");
88 
89                 if(ioObjectsNone.isChecked())
90                     options.add("--no-io");
91                 else if(ioObjectsWhole.isChecked())
92                     options.add("--whole-io");
93 
94                 if(noFactorize.isChecked())
95                     options.add("--no-factorize");
96                 if(includeDisallowed.isChecked())
97                     options.add("--disallowed");
98                 if(noLegend.isChecked())
99                     options.add("--no-legend");
100 
101                 // Send the options back to mainActivity
102                 Intent returnIntent = new Intent();
103                 returnIntent.putStringArrayListExtra("options", options);
104                 setResult(RESULT_OK, returnIntent);
105                 finish();
106             }
107         });
108 
109         if(!logicalIndexes.isChecked() && !physicalIndexes.isChecked())
110             defaultIndexes.setChecked(true);
111         if(!ioObjectsNone.isChecked() && !ioObjectsWhole.isChecked())
112             ioObjectsDefault.setChecked(true);
113     }
114 
syncRadioGroup(final RadioGroup radioGroup1, final RadioGroup radioGroup2)115     private void syncRadioGroup(final RadioGroup radioGroup1, final RadioGroup radioGroup2) {
116         radioGroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
117             @Override
118             public void onCheckedChanged(RadioGroup radioGroup, int i) {
119                 RadioButton rButton = ((RadioButton) radioGroup.findViewById(i));
120                 if (rButton != null && rButton.isChecked())
121                     radioGroup2.clearCheck();
122             }
123         });
124 
125         radioGroup2.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
126             @Override
127             public void onCheckedChanged(RadioGroup radioGroup, int i) {
128                 RadioButton rButton = ((RadioButton) radioGroup.findViewById(i));
129                 if (rButton != null && rButton.isChecked())
130                     radioGroup1.clearCheck();
131             }
132         });
133     }
134 
135 }
136