Android Open Source - miner Grid Cell






From Project

Back to project page miner.

License

The source code is released under:

Apache License

If you think the Android project miner 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.kolomiyets.miner.view;
/*from w w w .ja  v  a 2  s .c  o  m*/
import java.util.zip.Inflater;

import com.kolomiyets.miner.R;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class GridCell extends LinearLayout {

  public static final String MINE = "X";
  public static final String MARK = "M";
  
  boolean isMystery = true;
  String val;
  TextView valLbl;
  
  public GridCell(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs);
    init(context);
  }
  
  public GridCell(Context context, AttributeSet attrs) {
    super(context, attrs);
    init(context);
  }
  
  public GridCell(Context context) {
    super(context, null);
    init(context);
  }
  
  private void init(Context context){
    LayoutInflater.from(getContext()).inflate(R.layout.grid_cell_layout, this, true);
    valLbl = (TextView)findViewById(R.id.lbl_cell_value);
    val = "";
  }

  public void setMine(boolean isMasked){
    setCellValue(MINE, R.color.black, isMasked);
  }
  
  public void setMine(){
    setMine(false);
  }
  
  public void setMark() {
    if(getIsMarked()) return;
    if(!isMystery) throw new IllegalStateException();
    valLbl.setText(MARK);
    isMystery = false;
  }
  
  public void removeMark(){
    if(!getIsMarked()) throw new IllegalStateException();
    setMystery();  
  }
  
  public void setMystery(){
    isMystery = true;
    valLbl.setText("");
    valLbl.setBackground(getResources().getDrawable(
        R.drawable.btn_square_overlay_normal));
  }
  
  public void setIndication(int number, boolean isMasked){
    int colorResId;
    switch (number) {
    case 1:
      colorResId = R.color.blue;
      break;
    case 2:
      colorResId = R.color.green;
      break;
    case 3:
    case 4:
      colorResId = R.color.orange;
      break;
    case 5:
    case 6:
      colorResId = R.color.redish;
      break;
    case 7:
    case 8:
      colorResId = R.color.red;
      break;
    default:
      colorResId = R.color.black;
      break;
    }
    setCellValue(String.valueOf(number), colorResId, isMasked);
  }
  
  public void setIndication(int number) {
    setIndication(number, false);
  }
  
  public void clear(){
    setCellValue("", R.color.black, false);
  }
  
  public void blowUp(){
    setCellValue(MINE, R.color.black, false);
    highlight(R.color.red);
  }
  
  @SuppressLint("ResourceAsColor")
  private void setCellValue(String value, int colorResId, boolean isMasked){
    val = value;
    if(isMasked){
      setMystery();
    } else {
      isMystery = false;
      valLbl.setBackgroundColor(getResources().getColor(R.color.grey));
      valLbl.setText(val);
    }
    valLbl.setTextColor(getResources().getColor(colorResId));
  }
  
  public boolean getIsMined(){
    return val.equals(MINE);
  }
  
  public boolean getIsMarked(){
    return valLbl.getText().toString().equals(MARK);
  }
  
  public boolean getIsMystery(){
    return isMystery;
  }
  
  public boolean getIsClear(){
    return val.equals("") && valLbl.getText().toString().equals("");
  }
  
  public void highlight(int colorResId){
    valLbl.setBackgroundColor(getResources().getColor(colorResId));
  }
  
  public String getCellValue() {
    return val;
  }
  
  @Override
  public void setOnClickListener(final OnClickListener l) {
    valLbl.setOnClickListener(new OnClickListener() {
      
      @Override
      public void onClick(View v) {
        l.onClick(GridCell.this);
      }
    });
  }
  
  @Override
  public void setOnLongClickListener(final OnLongClickListener l) {
    valLbl.setOnLongClickListener(new OnLongClickListener() {
      
      @Override
      public boolean onLongClick(View v) {
        l.onLongClick(GridCell.this);
        return true;
      }
    });
  }
  
  @Override
  public void setEnabled(boolean enabled) {
    valLbl.setEnabled(enabled);
    super.setEnabled(enabled);
  }
}




Java Source Code List

com.kolomiyets.miner.MinerActivity.java
com.kolomiyets.miner.Miner.java
com.kolomiyets.miner.bt.BtStateMonitor.java
com.kolomiyets.miner.bt.ConnectionBase.java
com.kolomiyets.miner.bt.ConnectionManager.java
com.kolomiyets.miner.bt.ConnectionMaster.java
com.kolomiyets.miner.bt.ConnectionProcessor.java
com.kolomiyets.miner.bt.ConnectionSlave.java
com.kolomiyets.miner.bt.EConnectMethod.java
com.kolomiyets.miner.bt.IBtEnableCallback.java
com.kolomiyets.miner.bt.IRequestBtResult.java
com.kolomiyets.miner.bt.notification.BtListener.java
com.kolomiyets.miner.bt.notification.BtNotificationCmd.java
com.kolomiyets.miner.bt.notification.BtNotificationConnect.java
com.kolomiyets.miner.bt.notification.BtNotificationDiscoveryDevice.java
com.kolomiyets.miner.bt.notification.BtNotificationDiscoveryState.java
com.kolomiyets.miner.bt.notification.BtNotificationDiscovery.java
com.kolomiyets.miner.bt.notification.BtNotificationHandshake.java
com.kolomiyets.miner.bt.notification.BtNotificationPower.java
com.kolomiyets.miner.bt.notification.BtNotificationState.java
com.kolomiyets.miner.bt.notification.BtNotification.java
com.kolomiyets.miner.bt.notification.EConnectionSate.java
com.kolomiyets.miner.bt.notification.NotificationManager.java
com.kolomiyets.miner.bt.protocol.CmdBase.java
com.kolomiyets.miner.bt.protocol.CmdFactory.java
com.kolomiyets.miner.bt.protocol.CmdFieldState.java
com.kolomiyets.miner.bt.protocol.CmdGameState.java
com.kolomiyets.miner.bt.protocol.CmdGameTeam.java
com.kolomiyets.miner.bt.protocol.CmdHandshake.java
com.kolomiyets.miner.bt.protocol.CmdPing.java
com.kolomiyets.miner.bt.protocol.CmdResponse.java
com.kolomiyets.miner.bt.protocol.ECmdName.java
com.kolomiyets.miner.bt.protocol.EGameState.java
com.kolomiyets.miner.dialog.DialogProvider.java
com.kolomiyets.miner.dialog.EDialogType.java
com.kolomiyets.miner.dialog.IDialogResult.java
com.kolomiyets.miner.screen.PlayGroundBase.java
com.kolomiyets.miner.screen.PlayGroundMiner.java
com.kolomiyets.miner.screen.PlayGroundSapper.java
com.kolomiyets.miner.screen.ScreenBase.java
com.kolomiyets.miner.screen.ScreenConnectingGame.java
com.kolomiyets.miner.screen.ScreenCreateGame.java
com.kolomiyets.miner.screen.ScreenDevices.java
com.kolomiyets.miner.screen.ScreenManager.java
com.kolomiyets.miner.screen.ScreenSelectPlayer.java
com.kolomiyets.miner.view.GridCell.java