Android Open Source - AndroidSettlers Resource View






From Project

Back to project page AndroidSettlers.

License

The source code is released under:

GNU General Public License

If you think the Android project AndroidSettlers 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.settlers.hd;
//  w  w w .j  av a2s . c o m
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.view.Gravity;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class ResourceView extends LinearLayout {

  private static final int[] RESOURCES = { R.drawable.res_lumber_medium, R.drawable.res_wool_medium,
      R.drawable.res_grain_medium, R.drawable.res_brick_medium, R.drawable.res_ore_medium, };

  private TextView[] views;

  private Context context;

  public ResourceView(Context context) {
    super(context);
    this.context = context;

    int padding = (int) (10 * context.getResources().getDisplayMetrics().density);

    setVisibility(View.INVISIBLE);
    setGravity(Gravity.CENTER);

    views = new TextView[RESOURCES.length];

    for (int i = 0; i < RESOURCES.length; i++) {
      final int resource = i;

      ImageView image = new ImageView(context);
      image.setImageResource(RESOURCES[i]);

      TextView text = new TextView(context);
      text.setText("");
      text.setTextColor(Color.WHITE);
      text.setTextSize(24);
      text.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
      text.setGravity(Gravity.BOTTOM);
      views[i] = text;

      LinearLayout row = new LinearLayout(context);
      row.setOrientation(LinearLayout.HORIZONTAL);
      row.setPadding(padding, padding, padding, padding);
      row.addView(image);
      row.addView(text);

      row.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View view) {
          if (Settlers.getInstance().getBoardInstance().isBuild()) {
            Intent intent = new Intent(ResourceView.this.context, PlayerTrade.class);
            intent.putExtra(PlayerTrade.TYPE_KEY, resource);
            ResourceView.this.context.startActivity(intent);
          }
        }
      });

      addView(row);
    }
  }

  public void setValues(Player player) {
    if (player == null || !player.isHuman()) {
      setVisibility(View.INVISIBLE);
      return;
    }

    setVisibility(View.VISIBLE);
    setBackgroundColor(Color.argb(200, 0, 0, 0));

    int[] resources = player.getResources();
    for (int i = 0; i < Hexagon.TYPES.length; i++)
      views[i].setText(String.valueOf(resources[i]));
  }
}




Java Source Code List

com.settlers.hd.AcceptTrade.java
com.settlers.hd.AutomatedPlayer.java
com.settlers.hd.BalancedAI.java
com.settlers.hd.Board.java
com.settlers.hd.CounterOffer.java
com.settlers.hd.Discard.java
com.settlers.hd.Edge.java
com.settlers.hd.GameActivity.java
com.settlers.hd.GameRenderer.java
com.settlers.hd.GameView.java
com.settlers.hd.Geometry.java
com.settlers.hd.Hexagon.java
com.settlers.hd.LocalGame.java
com.settlers.hd.Main.java
com.settlers.hd.PlayerTrade.java
com.settlers.hd.Player.java
com.settlers.hd.Reference.java
com.settlers.hd.ResourceView.java
com.settlers.hd.Rules.java
com.settlers.hd.Settings.java
com.settlers.hd.Settlers.java
com.settlers.hd.Square.java
com.settlers.hd.Stats.java
com.settlers.hd.Status.java
com.settlers.hd.TextureManager.java
com.settlers.hd.Trader.java
com.settlers.hd.UIButton.java
com.settlers.hd.Vertex.java