@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getResources().getBoolean(R.bool.portrait_only)) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } setContentView(R.layout.activity_review_poll); setupActionBar(); if (getResources().getBoolean(R.bool.display_bottom_bar) == false) { findViewById(R.id.layout_bottom_bar).setVisibility(View.GONE); } AndroidApplication.getInstance().setCurrentActivity(this); AndroidApplication.getInstance().getNetworkInterface().lockGroup(); btnStartPollPeriod = (Button) findViewById(R.id.button_start_poll_period); btnStartPollPeriod.setOnClickListener(this); if (savedInstanceState != null) { poll = (Poll) savedInstanceState.getSerializable("poll"); sender = savedInstanceState.getString("sender"); } Poll intentPoll = (Poll) getIntent().getSerializableExtra("poll"); if (intentPoll != null) { poll = intentPoll; sender = getIntent().getStringExtra("sender"); } FragmentManager fm = getFragmentManager(); fragment = new PollReviewFragment(); Bundle bundle = new Bundle(); bundle.putSerializable("poll", poll); bundle.putString("sender", sender); fragment.setArguments(bundle); fm.beginTransaction().replace(R.id.fragment_container, fragment, "review").commit(); // Is NFC available on this device? nfcAvailable = this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC); if (nfcAvailable) { nfcAdapter = NfcAdapter.getDefaultAdapter(this); if (nfcAdapter.isEnabled()) { // Setting up a pending intent that is invoked when an NFC tag // is tapped on the back pendingIntent = PendingIntent.getActivity( this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); } else { nfcAvailable = false; } } }
@Override protected void onResume() { AndroidApplication.getInstance().setCurrentActivity(this); LocalBroadcastManager.getInstance(NetworkConfigActivity.this) .registerReceiver( serviceStartedListener, new IntentFilter(BroadcastIntentTypes.networkConnectionSuccessful)); active = true; rescanWifiTask = new AsyncTask<Object, Object, Object>() { @Override protected Object doInBackground(Object... arg0) { while (active) { SystemClock.sleep(5000); wifi.startScan(); } return null; } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); if (nfcAdapter != null && nfcAdapter.isEnabled()) { nfcAvailable = true; } // make sure that this activity is the first one which can handle the // NFC tags if (nfcAvailable) { nfcAdapter.enableForegroundDispatch(this, pendingIntent, Utility.getNFCIntentFilters(), null); } super.onResume(); }
@Override public void onReceive(Context context, Intent intent) { LocalBroadcastManager.getInstance(ReviewPollAdminActivity.this).unregisterReceiver(this); Poll poll = (Poll) intent.getSerializableExtra("poll"); if (isContainedInParticipants( AndroidApplication.getInstance().getNetworkInterface().getMyUniqueId(), poll.getParticipants().values())) { Intent i = new Intent(context, VoteActivity.class); i.putExtras(intent.getExtras()); AndroidApplication.getInstance().getCurrentActivity().startActivity(i); } else { Intent i = new Intent(context, WaitForVotesAdminActivity.class); i.putExtras(intent.getExtras()); AndroidApplication.getInstance().getCurrentActivity().startActivity(i); } }
/** Start the vote phase */ private void startVotePeriod() { for (Participant p : poll.getParticipants().values()) { if (!p.hasAcceptedReview()) { for (int i = 0; i < 2; i++) Toast.makeText(this, R.string.toast_not_everybody_accepted, Toast.LENGTH_LONG).show(); return; } } poll.setStartTime(System.currentTimeMillis()); AndroidApplication.getInstance().getProtocolInterface().beginVotingPeriod(poll); }
public void onActivityResult(int requestCode, int resultCode, Intent intent) { if (requestCode == 0) { if (resultCode == RESULT_OK) { String[] config = intent.getStringExtra("SCAN_RESULT").split("\\|\\|"); // saving the values that we got SharedPreferences.Editor editor = preferences.edit(); editor.putString("SSID", config[0]); editor.commit(); AndroidApplication.getInstance().getNetworkInterface().setGroupName(config[1]); AndroidApplication.getInstance().getNetworkInterface().setGroupPassword(config[2]); if (checkIdentification()) { // connect to the network connect(config, this); } } else if (resultCode == RESULT_CANCELED) { // Handle cancel } } }
@Override protected void onResume() { AndroidApplication.getInstance().setCurrentActivity(this); LocalBroadcastManager.getInstance(this) .registerReceiver( showNextActivityListener, new IntentFilter(BroadcastIntentTypes.showNextActivity)); if (nfcAdapter != null && nfcAdapter.isEnabled()) { nfcAvailable = true; } // make sure that this activity is the first one which can handle the // NFC tags if (nfcAvailable) { nfcAdapter.enableForegroundDispatch(this, pendingIntent, Utility.getNFCIntentFilters(), null); } super.onResume(); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getResources().getBoolean(R.bool.portrait_only)) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } final FrameLayout overlayFramelayout = new FrameLayout(this); FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams( FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT); layoutParams.setMargins( getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin), 0, getResources().getDimensionPixelSize(R.dimen.activity_horizontal_margin), 0); overlayFramelayout.setLayoutParams(layoutParams); View view = getLayoutInflater().inflate(R.layout.activity_network_config, overlayFramelayout, false); overlayFramelayout.addView(view); final SharedPreferences settings = getSharedPreferences(AndroidApplication.PREFS_NAME, MODE_PRIVATE); if (settings.getBoolean("first_run", true)) { // Show General Help Overlay final View overlay_view = getLayoutInflater().inflate(R.layout.overlay_parent_button, null, false); overlayFramelayout.addView(overlay_view); overlay_view.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { overlayFramelayout.removeView(overlay_view); settings.edit().putBoolean("first_run", false).commit(); // Show Help Overlay for this activity if (settings.getBoolean( "first_run_" + NetworkConfigActivity.this.getClass().getSimpleName(), true)) { final View overlay_view = getLayoutInflater().inflate(R.layout.overlay_network_config, null, false); overlayFramelayout.addView(overlay_view); overlay_view.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { overlayFramelayout.removeView(overlay_view); settings .edit() .putBoolean( "first_run_" + NetworkConfigActivity.this.getClass().getSimpleName(), false) .commit(); } }); } } }); } else if (settings.getBoolean("first_run_" + this.getClass().getSimpleName(), true)) { // Show Help Overlay for this activity final View overlay_view = getLayoutInflater().inflate(R.layout.overlay_network_config, null, false); overlayFramelayout.addView(overlay_view); overlay_view.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View v) { overlayFramelayout.removeView(overlay_view); settings .edit() .putBoolean( "first_run_" + NetworkConfigActivity.this.getClass().getSimpleName(), false) .commit(); } }); } setContentView(overlayFramelayout); AndroidApplication.getInstance().setCurrentActivity(this); Fragment fg = new NetworkOptionsFragment(); // adding fragment to relative layout by using layout id getFragmentManager().beginTransaction().add(R.id.fragment_container, fg).commit(); // Show the Up button in the action bar. setupActionBar(); Poll serializedPoll = (Poll) getIntent().getSerializableExtra("poll"); if (serializedPoll != null) { poll = serializedPoll; } // reading the identification from the preferences, if it is not there // it will try to read the name of the device owner preferences = getSharedPreferences(AndroidApplication.PREFS_NAME, 0); String identification = preferences.getString("identification", ""); // if (identification.equals("")) { // identification = readOwnerName(); // // saving the identification field // SharedPreferences.Editor editor = preferences.edit(); // editor.putString("identification", identification); // editor.commit(); // } etIdentification = (EditText) findViewById(R.id.edittext_identification); etIdentification.setText(identification); etIdentification.addTextChangedListener(this); serviceStartedListener = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { active = false; rescanWifiTask.cancel(true); LocalBroadcastManager.getInstance(NetworkConfigActivity.this).unregisterReceiver(this); if (AndroidApplication.getInstance().isAdmin()) { Intent i = new Intent(NetworkConfigActivity.this, NetworkInformationActivity.class); i.putExtra("poll", poll); startActivity(i); } else { startActivity(new Intent(NetworkConfigActivity.this, CheckElectorateActivity.class)); } } }; wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); active = true; rescanWifiTask = new AsyncTask<Object, Object, Object>() { @Override protected Object doInBackground(Object... arg0) { while (active) { SystemClock.sleep(5000); wifi.startScan(); } return null; } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); // Is NFC available on this device? nfcAvailable = this.getPackageManager().hasSystemFeature(PackageManager.FEATURE_NFC); if (nfcAvailable) { nfcAdapter = NfcAdapter.getDefaultAdapter(this); if (nfcAdapter.isEnabled()) { // Setting up a pending intent that is invoked when an NFC tag // is tapped on the back pendingIntent = PendingIntent.getActivity( this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0); } else { nfcAvailable = false; } } }