kernel_memory_dump

Untitled

Jan 30th, 2014
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.54 KB | None | 0 0
  1. package pedja.kalkulator;
  2.  
  3.  
  4. import pedja.kalkulator.R;
  5. import android.net.Uri;
  6. import android.os.Bundle;
  7. import android.provider.MediaStore;
  8. import android.app.Activity;
  9. import android.content.Intent;
  10. import android.content.SharedPreferences;
  11. import android.graphics.Color;
  12. import android.view.Menu;
  13. import android.view.MenuItem;
  14. import android.view.View;
  15. import android.widget.Button;
  16. import android.widget.EditText;
  17. import android.widget.Toast;
  18.  
  19. public class MainActivity extends Activity {
  20.      
  21.  public String str ="";
  22.  Character op = 'q';
  23.  int i,num,numtemp;
  24.     EditText showResult;
  25.     @Override
  26.     public void onCreate(Bundle savedInstanceState) {
  27.         super.onCreate(savedInstanceState);
  28.         setContentView(R.layout.activity_main);
  29.  
  30.        
  31.         SharedPreferences settings = getSharedPreferences("test",  MODE_PRIVATE);
  32.        
  33.         SharedPreferences.Editor prefEditor = settings.edit();
  34.         prefEditor.putString("ime", "Sebastian");
  35.         prefEditor.commit();
  36.         showResult = (EditText)findViewById(R.id.result_id);
  37.        
  38.       }
  39.    
  40.    
  41.       public void btn1Clicked(View v){
  42.           SharedPreferences prefs = getPreferences(MODE_PRIVATE);
  43.           String text = prefs.getString("ime", null);
  44.  
  45.     Toast toast = Toast.makeText(getApplicationContext(), text, Toast.LENGTH_LONG);
  46.     toast.show();
  47.        insert(1);
  48.        
  49.       }
  50.        
  51.  public void btn2Clicked(View v){
  52.        insert(2);
  53.        
  54.       }
  55.       public void btn3Clicked(View v){
  56.        insert(3);
  57.        
  58.       }
  59.       public void btn4Clicked(View v){
  60.        insert(4);
  61.        
  62.       }
  63.       public void btn5Clicked(View v){
  64.        insert(5);
  65.        
  66.       }
  67.       public void btn6Clicked(View v){
  68.        insert(6);
  69.       }
  70.       public void btn7Clicked(View v){
  71.        insert(7);
  72.        
  73.       }
  74.       public void btn8Clicked(View v){
  75.        insert(8);
  76.        
  77.       }
  78.       public void btn9Clicked(View v){
  79.        insert(9);
  80.        
  81.       }
  82.       public void btnplusClicked(View v){
  83.        perform();
  84.        op = '+';
  85.    
  86.       }
  87.        
  88.  public void btnminusClicked(View v){
  89.     perform();
  90.          op = '-';
  91.    
  92.       }
  93.       public void btndivideClicked(View v){
  94.        perform();
  95.        op = '/';
  96.    
  97.       }
  98.       public void btnmultiClicked(View v){
  99.        perform();
  100.        op = '*';
  101.      
  102.       }
  103.       public void btnequalClicked(View v){
  104.        calculate();
  105.        
  106.       }
  107.        
  108.  public void btnclearClicked(View v){
  109.        reset();
  110.       }
  111.       private void reset() {
  112.   // TODO Auto-generated method stub
  113.    str ="";
  114.    op ='q';
  115.    num = 0;
  116.    numtemp = 0;
  117.    showResult.setText("");
  118.  }
  119.  private void insert(int j) {
  120.     // TODO Auto-generated method stub
  121.        int value;      
  122.        str = str+Integer.toString(j);
  123.        try{
  124.            num = Integer.valueOf(str).intValue();
  125.        }catch(Exception NumberFormatException){
  126.            num = 0;
  127.        }
  128.        
  129.      
  130.        showResult.setText(str);
  131.        
  132.      
  133.    }
  134.       private void perform() {
  135.     // TODO Auto-generated method stub
  136.     str = "";
  137.     numtemp = num;
  138.    }
  139.       private void calculate() {
  140.     // TODO Auto-generated method stub
  141.     if(op == '+')
  142.      num = numtemp+num;
  143.     else if(op == '-')
  144.      num = numtemp-num;
  145.     else if(op == '/')
  146.      num = numtemp/num;
  147.     else if(op == '*')
  148.      num = numtemp*num;
  149.     showResult.setText(""+num);
  150.    }
  151.      
  152.       ////////////////////////////////////////////////////////////////////////////////////
  153.       public boolean onCreateOptionsMenu (Menu menu){
  154.           super.onCreateOptionsMenu(menu);
  155.            CreateMenu(menu);
  156.            return true;
  157.     }
  158.      
  159.     private void CreateMenu(Menu menu){
  160.         MenuItem opcija1 = menu.add(0,0,0,"Prva opcija");
  161.         {
  162.            // opcija1.setIcon(R.drawable.dugmeLogo);\
  163.             opcija1.setIcon(R.drawable.dugme_logo);
  164.             opcija1.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
  165.         }
  166.      
  167.      
  168.     }
  169.      
  170.     public boolean onOptionsItemSelected (MenuItem item){
  171.             return MenuChoice(item);
  172.     }
  173.      
  174.     private boolean MenuChoice (MenuItem item){
  175.        
  176.     switch( item.getItemId()){
  177.        case 0:
  178.                 Toast.makeText(this, "Отвара се страна сајта Школе Рајак", Toast.LENGTH_LONG).show();
  179.                 Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://rajak.rs/sr/component/content/article/54-kursevi/253-android-kurs"));
  180.                 startActivity(myIntent);
  181.                 break;
  182.     }
  183.     return true;
  184.     }
  185.      
  186.      
  187.      
  188. }
Advertisement
Add Comment
Please, Sign In to add comment