Android Open Source - power-consumption-android Takequiz






From Project

Back to project page power-consumption-android.

License

The source code is released under:

Apache License

If you think the Android project power-consumption-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.wolfsoft.epower;
// ww  w  .j  a  v a  2 s.  c  o  m
import android.app.ActionBar;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast;

public class Takequiz extends Activity {
  

  int total;
  int waittime=3000;
  int i = 0;
  
  

  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    
    setContentView(R.layout.quiz); 
    
    
    
    // get action bar   
        ActionBar actionBar = getActionBar();
        // Enabling Up / Back navigation
        actionBar.setDisplayHomeAsUpEnabled(true);
    
    
    findViewById(R.id.wrong1).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
          
          Toast display= Toast.makeText(getApplicationContext(), 
                "Wrong Answer", 0);  
           
            
                 display.setGravity(Gravity.BOTTOM, 0, 0);
                 display.setDuration(Toast.LENGTH_SHORT);
                   display.show();
          total=0;
          
          TextView right = (TextView)findViewById(R.id.right);
        TextView wrong1 = (TextView)findViewById(R.id.wrong1);
        wrong1.setTextColor(Color.parseColor("#ED2E2E"));
        right.setTextColor(Color.parseColor("#3775A6"));
        
      
        Thread mythread = new Thread() {
          public void run() {
          try {
          while (i < waittime) {
          
          i=i+200;
          sleep(100);
             
          }
          } 
          catch(Exception e) {}
          finally {
          Intent q1 = new Intent(Takequiz.this, Question2.class);
          q1.putExtra("total", total);
          startActivity(q1);
          overridePendingTransition(R.anim.anim_slide_in_left,
                        R.anim.anim_slide_out_right);
          }
          }
          };
          mythread.start();
          }
        });
    
    findViewById(R.id.wrong2).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

          total=0;
          Toast display= Toast.makeText(getApplicationContext(), 
              "Wrong Answer", 0);  
         
          
               display.setGravity(Gravity.BOTTOM, 0, 0);
               display.setDuration(Toast.LENGTH_SHORT);
                 display.show();
          
          TextView right = (TextView)findViewById(R.id.right);
        TextView wrong2 = (TextView)findViewById(R.id.wrong2);
        wrong2.setTextColor(Color.parseColor("#ED2E2E"));
        right.setTextColor(Color.parseColor("#3775A6"));
        
      
        Thread mythread = new Thread() {
          public void run() {
          try {
          while (i < waittime) {
          
          i=i+200;
          sleep(100);
             
          }
          } 
          catch(Exception e) {}
          finally {
          Intent q1 = new Intent(Takequiz.this, Question2.class);
          q1.putExtra("total", total);
          startActivity(q1);
           overridePendingTransition(R.anim.anim_slide_in_left,
                        R.anim.anim_slide_out_right);
          }
          }
          };
          mythread.start();
          }
        });
    
    findViewById(R.id.right).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

          Toast display= Toast.makeText(getApplicationContext(), 
                "Right Answer", 0);  
           
            
                 display.setGravity(Gravity.BOTTOM, 0, 0);
                 display.setDuration(Toast.LENGTH_SHORT);
                   display.show();
          total=10;
          
          
          TextView right = (TextView)findViewById(R.id.right);
        right.setTextColor(Color.parseColor("#3775A6"));
        
      
        Thread mythread = new Thread() {
          public void run() {
          try {
          while (i < waittime) {
          
          i=i+200;
          sleep(100);
             
          }
          } 
          catch(Exception e) {}
          finally {
          Intent intent = new Intent(Takequiz.this, Question2.class);
          intent.putExtra("total", total);
          startActivity(intent);
           overridePendingTransition(R.anim.anim_slide_in_left,
                        R.anim.anim_slide_out_right);
          }
          }
          };
          mythread.start();
          }
        });
    
  }
  
  
  public void hint(View v)
  {
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    
    alertDialogBuilder.setTitle("Hint!!");
    alertDialogBuilder
    .setMessage("Compared to general-service incandescent lamps giving the same amount of visible light, CFLs use one-fifth to one-third the electric power, and last eight to fifteen times longer. A CFL has a higher purchase price than an incandescent lamp, but can save over five times its purchase price in electricity costs over the lamp's lifetime")
    .setPositiveButton("Ok",new DialogInterface.OnClickListener() {
      public void onClick(DialogInterface dialog,int id) {
        // if this button is clicked, close
        // current activity
        dialog.cancel();
      }
      });
    AlertDialog alertDialog = alertDialogBuilder.create();
    alertDialog.show();
  }
  
  
  
  @Override
  public boolean onOptionsItemSelected(MenuItem item) { 
      switch (item.getItemId()) {
      case android.R.id.home:
      Intent intent = new Intent(this,MainActivity.class);
      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
      startActivity(intent);
       overridePendingTransition(R.anim.anim_slide_in_left,
                    R.anim.anim_slide_out_right);
              default:
              return super.onOptionsItemSelected(item); 
      }
  }
  
  
}




Java Source Code List

com.wolfsoft.epower.Appliancetips.java
com.wolfsoft.epower.EstimateCost.java
com.wolfsoft.epower.Heatcold.java
com.wolfsoft.epower.Lighttips.java
com.wolfsoft.epower.Links.java
com.wolfsoft.epower.MainActivity.java
com.wolfsoft.epower.Question2.java
com.wolfsoft.epower.Question3.java
com.wolfsoft.epower.Question4.java
com.wolfsoft.epower.Question5.java
com.wolfsoft.epower.Takequiz.java
com.wolfsoft.epower.Tips.java
com.wolfsoft.epower.Total.java