Android Open Source - MinerStatus Add Miner Activity






From Project

Back to project page MinerStatus.

License

The source code is released under:

Apache License

If you think the Android project MinerStatus 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 me.davidgreene.minerstatus;
//from ww w. j a  va  2s  .c  o m
import static me.davidgreene.minerstatus.util.MinerStatusConstants.POOL_DIRECTIONS;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

public class AddMinerActivity extends AbstractMinerStatusActivity {
  
  //private static final String tag = "TX";
  
  private String poolToAdd;
  
  @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.addminer1);
        int bgColor = themeService.getTheme().getBackgroundColor();
        int color = themeService.getTheme().getTextColor();
        ScrollView scrollView = (ScrollView) findViewById(R.id.addMinerScrollView);
        scrollView.setBackgroundColor(bgColor);
      TextView minerNameLabel = (TextView) findViewById(R.id.minerNameLabel);
      minerNameLabel.setTextColor(color);
      TextView minerDirections = (TextView) findViewById(R.id.minerDirections);
      minerDirections.setTextColor(color);
        
      final RadioButton radio_bitcoinpool = (RadioButton) findViewById(R.id.radio_bitcoinpool);
      final RadioButton radio_slush = (RadioButton) findViewById(R.id.radio_slush);
      final RadioButton radio_deepbit = (RadioButton) findViewById(R.id.radio_deepbit);
      final RadioButton radio_btcmine = (RadioButton) findViewById(R.id.radio_btcmine);
      final RadioButton radio_btcguild = (RadioButton) findViewById(R.id.radio_btcguild);

      radio_btcmine.setOnClickListener(radio_listener);
      radio_btcmine.setTextColor(color);
      
      radio_deepbit.setOnClickListener(radio_listener);
      radio_deepbit.setTextColor(color);
      
        radio_bitcoinpool.setOnClickListener(radio_listener);
        radio_bitcoinpool.setTextColor(color);
        
        radio_slush.setOnClickListener(radio_listener);
        radio_slush.setTextColor(color);

        radio_btcguild.setOnClickListener(radio_listener);
        radio_btcguild.setTextColor(color);
    }
  
  private OnClickListener radio_listener = new OnClickListener() {
      public void onClick(View v) {
          // Perform action on clicks
          RadioButton rb = (RadioButton) v;
        final TextView minerNameLabel = (TextView) findViewById(R.id.minerNameLabel);
        final EditText minerName = (EditText) findViewById(R.id.minerName);  
        final Button addMinerButton = (Button) findViewById(R.id.addMinerButton);  
        final TextView minerDirections = (TextView) findViewById(R.id.minerDirections);  
          if(rb.getText().equals("Bitcoin Pool")){
            poolToAdd = "bitcoinpool";
            minerNameLabel.setText("Miner Name");
          } else if (rb.getText().equals("Slush's Pool")){
            poolToAdd = "slush";
            minerNameLabel.setText("API Key");
          } else if (rb.getText().equals("Deepbit.net")){
            poolToAdd = "deepbit";
            minerNameLabel.setText("API Key");
          } else if (rb.getText().equals("BtcMine")){
            poolToAdd = "btcmine";
            minerNameLabel.setText("API Key");
          } else if (rb.getText().equals("Btcguild")){
            poolToAdd = "btcguild";
            minerNameLabel.setText("API Key");
          }
          minerNameLabel.setVisibility(TextView.VISIBLE);
          minerName.setVisibility(EditText.VISIBLE);   
          addMinerButton.setVisibility(Button.VISIBLE);
          minerDirections.setVisibility(TextView.VISIBLE);  
          minerDirections.setText(POOL_DIRECTIONS.get(poolToAdd));
      }
  };
  
  public void addMiner(View view){
    final EditText minerName = (EditText) findViewById(R.id.minerName);  
    if (insertMiner(minerName.getText().toString(), poolToAdd)){
      Toast.makeText(getApplicationContext(), minerName.getText().toString()+"/"+poolToAdd+" added",
        Toast.LENGTH_LONG).show();      
      AddMinerActivity.this.finish();
    } else {
      Toast.makeText(getApplicationContext(), minerName.getText().toString()+"/"+poolToAdd+" is invalid",
          Toast.LENGTH_LONG).show();      
    }
  }
    
  private Boolean validateMiner(String miner, String pool){
    if (miner == null || miner.length() == 0){
      return Boolean.FALSE;
    }
    if (pool == null || pool.length() == 0){
      return Boolean.FALSE;
    }
    if(pool.equals("slush")){
      for(Character c : miner.toCharArray()){
        if (!Character.isLetterOrDigit(c) && !c.equals('-')){
          return Boolean.FALSE;
        }
      }
      return Boolean.TRUE;
    } else if(pool.equals("deepbit")){
      for(Character c : miner.toCharArray()){
        if (!Character.isLetterOrDigit(c) && !c.equals('_')){
          return Boolean.FALSE;
        }
      }
      return Boolean.TRUE;
    } else if(pool.equals("btcmine") || pool.equals("btcguild") || pool.equals("bitcoinpool")){
      for(Character c : miner.toCharArray()){
        if (!Character.isLetterOrDigit(c)){
          return Boolean.FALSE;
        }
      }
      return Boolean.TRUE;
    }
    return Boolean.FALSE;
  }
  
  private Boolean insertMiner(String miner, String pool){
    if (validateMiner(miner, pool) && !minerService.minerExists(miner, pool)){
      minerService.insertMiner(miner, pool);
      return Boolean.TRUE;
    } else{
      Toast.makeText(getApplicationContext(), "Invalid Miner name: "+miner,
          Toast.LENGTH_LONG).show();
    }
    return Boolean.FALSE;
  }
    
}




Java Source Code List

me.davidgreene.minerstatus.AbstractMinerStatusActivity.java
me.davidgreene.minerstatus.AddMinerActivity.java
me.davidgreene.minerstatus.MainMinerActivity.java
me.davidgreene.minerstatus.MinerStatusApp.java
me.davidgreene.minerstatus.OptionsActivity.java
me.davidgreene.minerstatus.ViewMinerActivity.java
me.davidgreene.minerstatus.beans.BitpoolPool.java
me.davidgreene.minerstatus.beans.BitpoolStatus.java
me.davidgreene.minerstatus.beans.BitpoolUser.java
me.davidgreene.minerstatus.beans.BtcMine.java
me.davidgreene.minerstatus.beans.BtcguildPool.java
me.davidgreene.minerstatus.beans.BtcguildStatus.java
me.davidgreene.minerstatus.beans.BtcguildUser.java
me.davidgreene.minerstatus.beans.BtcguildWorker.java
me.davidgreene.minerstatus.beans.DeepbitStatus.java
me.davidgreene.minerstatus.beans.MtGox.java
me.davidgreene.minerstatus.beans.Result.java
me.davidgreene.minerstatus.beans.SlushStatus.java
me.davidgreene.minerstatus.beans.Status.java
me.davidgreene.minerstatus.beans.Ticker.java
me.davidgreene.minerstatus.beans.WorkerStatus.java
me.davidgreene.minerstatus.beans.Worker.java
me.davidgreene.minerstatus.service.ConfigServiceImpl.java
me.davidgreene.minerstatus.service.ConfigService.java
me.davidgreene.minerstatus.service.MinerServiceImpl.java
me.davidgreene.minerstatus.service.MinerService.java
me.davidgreene.minerstatus.service.ThemeServiceImpl.java
me.davidgreene.minerstatus.service.ThemeService.java
me.davidgreene.minerstatus.theme.DarkTheme.java
me.davidgreene.minerstatus.theme.LightTheme.java
me.davidgreene.minerstatus.theme.ThemeFactory.java
me.davidgreene.minerstatus.theme.Theme.java
me.davidgreene.minerstatus.util.AsynchMinerUpdateThread.java
me.davidgreene.minerstatus.util.DbOpenHelper.java
me.davidgreene.minerstatus.util.MinerStatusConstants.java
me.davidgreene.minerstatus.util.StatusObjectFactory.java