@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);
          }
        }
Example #4
0
 private void updatePpi() {
   DisplayMetrics metrics = new DisplayMetrics();
   app.getWindowManager().getDefaultDisplay().getMetrics(metrics);
   ppiX = metrics.xdpi;
   ppiY = metrics.ydpi;
   ppcX = metrics.xdpi / 2.54f;
   ppcY = metrics.ydpi / 2.54f;
   density = metrics.density;
 }
  private void setupMockServer(HashMap<String, String> override_map) {
    HashMap<String, String> map = new HashMap<>(Util.RESPONSE_MAP);

    if (override_map != null) {
      for (String key : override_map.keySet()) {
        map.put(key, override_map.get(key));
      }
    }

    Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    AndroidApplication app =
        (AndroidApplication) instrumentation.getTargetContext().getApplicationContext();

    // setup objectGraph to inject Mock API
    List modules = Collections.singletonList(new DummyAPIModule(map));
    ObjectGraph graph = ObjectGraph.create(modules.toArray());
    app.setObjectGraph(graph);
    app.getObjectGraph().inject(app);
  }
  /** 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();
  }
Example #9
0
 @Override
 public void onSurfaceCreated(javax.microedition.khronos.opengles.GL10 gl, EGLConfig config) {
   eglContext = ((EGL10) EGLContext.getEGL()).eglGetCurrentContext();
   setupGL(gl);
   logConfig(config);
   updatePpi();
   Mesh.invalidateAllMeshes(app);
   Texture.invalidateAllTextures(app);
   ShaderProgram.invalidateAllShaderPrograms(app);
   FrameBuffer.invalidateAllFrameBuffers(app);
   Gdx.app.log("AndroidGraphics", Mesh.getManagedStatus());
   Gdx.app.log("AndroidGraphics", Texture.getManagedStatus());
   Gdx.app.log("AndroidGraphics", ShaderProgram.getManagedStatus());
   Gdx.app.log("AndroidGraphics", FrameBuffer.getManagedStatus());
   Display display = app.getWindowManager().getDefaultDisplay();
   this.width = display.getWidth();
   this.height = display.getHeight();
   mean = new WindowedMean(5);
   this.lastFrameTime = System.nanoTime();
   gl.glViewport(0, 0, this.width, this.height);
   isSurfaceCreated = true;
 }
  @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;
      }
    }
  }
Example #11
0
 @Override
 public DisplayMode getDesktopDisplayMode() {
   DisplayMetrics metrics = new DisplayMetrics();
   app.getWindowManager().getDefaultDisplay().getMetrics(metrics);
   return new AndroidDisplayMode(metrics.widthPixels, metrics.heightPixels, 0, 0);
 }
Example #12
0
 @Override
 public void onDrawFrame(javax.microedition.khronos.opengles.GL10 gl) {
   // Gdx.app.log("AndroidGraphics", "onDrawFrame");
   // Log.i( "opt" , "opt onDrawFrame" );
   boolean logTime = false;
   if (!app.hasFocus) {
     if (app.justResume) {
       app.justResume = false;
       logTime = true;
       // Log.i("opt", "return:onDrawFrame,draw after resume");
     } else {
       // Log.i( "opt" , "opt onDrawFrame,return" );
       AndroidApplication.swapSurface = false;
       return;
     }
   }
   long time = System.nanoTime();
   deltaTime = (time - lastFrameTime) / 1000000000.0f;
   lastFrameTime = time;
   mean.addValue(deltaTime);
   boolean lrunning = false;
   boolean lpause = false;
   boolean ldestroy = false;
   boolean lresume = false;
   boolean lforceRender = false;
   synchronized (synch) {
     lrunning = running;
     lpause = pause;
     ldestroy = destroy;
     lresume = resume;
     lforceRender = forceRender > 0;
     if (resume) {
       resume = false;
     }
     if (pause) {
       pause = false;
       synch.notifyAll();
     }
     if (destroy) {
       destroy = false;
       synch.notifyAll();
     }
     if (forceRender > 0) {
       forceRender--;
       if (forceRender < 0) forceRender = 0;
       this.requestRendering();
     }
   }
   if (lresume) {
     app.listener.resume();
     Gdx.app.log("AndroidGraphics", "resumed");
   }
   // if(logTime)Log.i("opt", "return:onDrawFrame,time1:"+(System.nanoTime()-time)/1000000);
   time = System.nanoTime();
   synchronized (app.urgentRunnables) {
     app.executedUrgentRunnables.clear();
     app.executedUrgentRunnables.addAll(app.urgentRunnables);
     app.urgentRunnables.clear();
   }
   for (int i = 0; i < app.executedUrgentRunnables.size; i++) {
     try {
       app.executedUrgentRunnables.get(i).run();
     } catch (Throwable t) {
       throw new RuntimeException(t);
     }
   }
   if (lrunning || lforceRender) {
     synchronized (app.runnables) {
       app.executedRunnables.clear();
       app.executedRunnables.addAll(app.runnables);
       app.runnables.clear();
     }
     for (int i = 0; i < app.executedRunnables.size; i++) {
       try {
         app.executedRunnables.get(i).run();
       } catch (Throwable t) {
         throw new RuntimeException(t);
       }
     }
     //			}
     // if(logTime)Log.i("opt", "return:onDrawFrame,time2:"+(System.nanoTime()-time)/1000000);
     time = System.nanoTime();
     app.input.processEvents();
     app.listener.render();
     // if(logTime)Log.i("opt", "return:onDrawFrame,time3:"+(System.nanoTime()-time)/1000000);
     time = System.nanoTime();
   } else {
     Gdx.app.log("AndroidGraphics", "not render");
   }
   if (lpause) {
     app.listener.pause();
     ((AndroidApplication) app).audio.pause();
     Gdx.app.log("AndroidGraphics", "paused");
   }
   if (ldestroy) {
     app.listener.dispose();
     ((AndroidApplication) app).audio.dispose();
     ((AndroidApplication) app).audio = null;
     Gdx.app.log("AndroidGraphics", "destroyed");
   }
   if (enable_showFPS) {
     if (time - frameStart > 1000000000) {
       fps = frames;
       frames = 0;
       frameStart = time;
       framesEverySecond.add(fps);
       //				Gdx.app.log( "xiatian - framesEverySecond" , "====start" );
       //				for( int i = 0 ; i < framesEverySecond.size() - 1 ; i++ )
       //				{
       //					Gdx.app.log( "xiatian - framesEverySecond" , "--" + ( i + 1 ) + "--:" +
       // framesEverySecond.get( i ) );
       //				}
       //				Gdx.app.log( "xiatian - framesEverySecond" , "====end" );
       FpsAverageValue = calculateFpsAverageValue();
       FpsCrestValue = calculateFpsCrestValue();
       FpsVarianceValue = calculateFpsVarianceValue();
     }
     frames++;
   }
   // if(logTime)Log.i("opt", "return:onDrawFrame,time4:"+(System.nanoTime()-time)/1000000);
 }