Ejemplo n.º 1
0
 public void hideToFromView() {
   if (vFrom != null) {
     AlphaAnimation animAlpha = new AlphaAnimation(1, 0);
     animAlpha.setDuration(AnimationDuration);
     vMask.startAnimation(animAlpha);
     int x = 0;
     int y = (screenHeight - statusBarHeight - screenWidth) / 2 + statusBarHeight;
     int[] location = new int[2];
     vFrom.getLocationInWindow(location);
     int toX = location[0];
     int toY = location[1];
     float scale = (float) vFrom.getWidth() / (float) UIUtil.getScreenWidth();
     ScaleAnimation animScale = new ScaleAnimation(1, scale, 1, scale);
     animScale.setDuration(AnimationDuration);
     TranslateAnimation animTrans = new TranslateAnimation(0, toX - x, 0, toY - y);
     animTrans.setDuration(AnimationDuration);
     AnimationSet animSet = new AnimationSet(true);
     animSet.addAnimation(animScale);
     animSet.addAnimation(animTrans);
     flImages.startAnimation(animSet);
     postDelayed(
         new Runnable() {
           @Override
           public void run() {
             setVisibility(View.GONE);
           }
         },
         AnimationDuration);
   } else {
     setVisibility(View.GONE);
   }
 }
Ejemplo n.º 2
0
 public void showPicFromPosition(
     final String content, final Bitmap placeHolder, final int x, final int y, final int width) {
   initView();
   setVisibility(View.VISIBLE);
   iv.setVisibility(View.INVISIBLE);
   ivPlaceHolder.setImageBitmap(placeHolder);
   final int size = Math.min(screenHeight, screenWidth);
   new Thread() {
     public void run() {
       final Bitmap bmp = Qr.bitmap(content, size);
       post(
           new Runnable() {
             @Override
             public void run() {
               iv.setImageBitmap(bmp);
               iv.setVisibility(View.VISIBLE);
             }
           });
     };
   }.start();
   AlphaAnimation animAlpha = new AlphaAnimation(0, 1);
   animAlpha.setDuration(AnimationDuration);
   vMask.startAnimation(animAlpha);
   int toX = 0;
   int toY = (screenHeight - statusBarHeight - screenWidth) / 2 + statusBarHeight;
   int toWidth = UIUtil.getScreenWidth();
   float scale = (float) width / (float) toWidth;
   ScaleAnimation animScale = new ScaleAnimation(scale, 1, scale, 1);
   animScale.setDuration(AnimationDuration);
   TranslateAnimation animTrans = new TranslateAnimation(x - toX, 0, y - toY, 0);
   animTrans.setDuration(AnimationDuration);
   AnimationSet animSet = new AnimationSet(true);
   animSet.setFillBefore(true);
   animSet.setDuration(AnimationDuration);
   animSet.addAnimation(animScale);
   animSet.addAnimation(animTrans);
   flImages.startAnimation(animSet);
 }
Ejemplo n.º 3
0
 private void configureTopBarSize() {
   int sideBarSize = UIUtil.getScreenWidth() / 3 - UIUtil.getScreenWidth() / 18;
   tbtnMessage.getLayoutParams().width = sideBarSize;
   tbtnMe.getLayoutParams().width = sideBarSize;
 }
Ejemplo n.º 4
0
 private void firstInit() {
   statusBarHeight = ImageManageUtil.getStatusBarHeight(BitherApplication.hotActivity.getWindow());
   screenHeight = UIUtil.getScreenHeight();
   screenWidth = UIUtil.getScreenWidth();
 }
Ejemplo n.º 5
0
public class DialogDonate extends CenterDialog implements OnDismissListener, OnShowListener {
  private static final int ListItemHeight = UIUtil.dip2pix(45);
  private static final int MinListHeight = UIUtil.dip2pix(100);
  private static final int MaxListHeight =
      Math.min(UIUtil.dip2pix(360), UIUtil.getScreenHeight() - UIUtil.dip2pix(70));

  private ListView lv;
  private ProgressBar pb;
  private TextView tvNoAddress;
  private FrameLayout fl;
  private ArrayList<AddressBalance> addresses = new ArrayList<AddressBalance>();
  private Intent intent;

  public DialogDonate(Context context) {
    super(context);
    setContentView(R.layout.dialog_donate);
    setOnDismissListener(this);
    setOnShowListener(this);
    tvNoAddress = (TextView) findViewById(R.id.tv_no_address);
    lv = (ListView) findViewById(R.id.lv);
    pb = (ProgressBar) findViewById(R.id.pb);
    fl = (FrameLayout) findViewById(R.id.fl);
    lv.setAdapter(adapter);
  }

  @Override
  public void onShow(DialogInterface dialog) {
    loadData();
  }

  @Override
  public void onDismiss(DialogInterface dialog) {
    if (intent != null) {
      if (getContext() instanceof Activity) {
        Activity a = (Activity) getContext();
        a.startActivityForResult(intent, SelectAddressToSendActivity.SEND_REQUEST_CODE);
      } else {
        getContext().startActivity(intent);
      }
    }
  }

  private void loadData() {
    pb.setVisibility(View.VISIBLE);
    lv.setVisibility(View.INVISIBLE);
    tvNoAddress.setVisibility(View.GONE);
    addresses.clear();
    new Thread() {
      public void run() {
        List<Address> as = AddressManager.getInstance().getAllAddresses();
        ArrayList<AddressBalance> availableAddresses = new ArrayList<AddressBalance>();
        for (Address a : as) {
          long balance = a.getBalance();
          if (balance > 0) {
            availableAddresses.add(new AddressBalance(a, balance));
          }
        }
        addresses.addAll(availableAddresses);
        lv.post(
            new Runnable() {
              @Override
              public void run() {
                fl.getLayoutParams().height = getFlHeight();
                adapter.notifyDataSetChanged();
                if (addresses.size() > 0) {
                  lv.setVisibility(View.VISIBLE);
                  tvNoAddress.setVisibility(View.GONE);
                } else {
                  lv.setVisibility(View.GONE);
                  tvNoAddress.setVisibility(View.VISIBLE);
                }
                pb.setVisibility(View.GONE);
              }
            });
      }
    }.start();
  }

  private BaseAdapter adapter =
      new BaseAdapter() {
        private LayoutInflater inflater;

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
          if (inflater == null) {
            inflater = LayoutInflater.from(getContext());
          }
          ViewHolder h;
          if (convertView != null
              && convertView.getTag() != null
              && convertView.getTag() instanceof ViewHolder) {
            h = (ViewHolder) convertView.getTag();
          } else {
            convertView = inflater.inflate(R.layout.list_item_select_address_to_send, null);
            h = new ViewHolder(convertView);
            convertView.setTag(h);
          }
          AddressBalance a = getItem(position);
          h.tvAddress.setText(a.address.getShortAddress());
          h.tvBalance.setText(GenericUtils.formatValueWithBold(a.balance));
          if (a.address.hasPrivKey()) {
            h.ivType.setImageResource(R.drawable.address_type_private);
          } else {
            h.ivType.setImageResource(R.drawable.address_type_watchonly);
          }
          h.ibtnAddressFull.setVisibility(View.GONE);
          convertView.setOnClickListener(new ListItemClick(a));
          return convertView;
        }

        @Override
        public long getItemId(int position) {
          return position;
        }

        @Override
        public AddressBalance getItem(int position) {
          return addresses.get(position);
        }

        @Override
        public int getCount() {
          return addresses.size();
        }

        class ViewHolder {
          TextView tvAddress;
          TextView tvBalance;
          ImageView ivType;
          ImageButton ibtnAddressFull;

          public ViewHolder(View v) {
            tvAddress = (TextView) v.findViewById(R.id.tv_address);
            tvBalance = (TextView) v.findViewById(R.id.tv_balance);
            ivType = (ImageView) v.findViewById(R.id.iv_type);
            ibtnAddressFull = (ImageButton) v.findViewById(R.id.ibtn_address_full);
            tvAddress.setTextColor(Color.WHITE);
            tvBalance.setTextColor(Color.WHITE);
          }
        }
      };

  private class ListItemClick implements View.OnClickListener {
    private AddressBalance address;

    public ListItemClick(AddressBalance address) {
      this.address = address;
    }

    @Override
    public void onClick(View v) {
      int position;
      Class<?> target;
      if (address.address.hasPrivKey()) {
        position = AddressManager.getInstance().getPrivKeyAddresses().indexOf(address.address);
        target = SendActivity.class;
      } else {
        position = AddressManager.getInstance().getWatchOnlyAddresses().indexOf(address.address);
        target = GenerateUnsignedTxActivity.class;
      }
      intent = new Intent(getContext(), target);
      intent.putExtra(BitherSetting.INTENT_REF.ADDRESS_POSITION_PASS_VALUE_TAG, position);
      intent.putExtra(
          SelectAddressToSendActivity.INTENT_EXTRA_ADDRESS, BitherSetting.DONATE_ADDRESS);
      if (address.balance > BitherSetting.DONATE_AMOUNT) {
        intent.putExtra(
            SelectAddressToSendActivity.INTENT_EXTRA_AMOUNT, BitherSetting.DONATE_AMOUNT);
      } else {
        intent.putExtra(SelectAddressToSendActivity.INTENT_EXTRA_AMOUNT, address.balance);
      }
      dismiss();
    }
  }

  private static final class AddressBalance implements Comparable<AddressBalance> {
    public Address address;
    public long balance;

    public AddressBalance(Address address, long balance) {
      this.address = address;
      this.balance = balance;
    }

    @Override
    public int compareTo(AddressBalance another) {
      if (address.hasPrivKey() && !another.address.hasPrivKey()) {
        return 1;
      }
      if (!address.hasPrivKey() && another.address.hasPrivKey()) {
        return -1;
      }
      long gap = balance - another.balance;
      return gap == 0 ? 0 : (int) (gap / Math.abs(gap));
    }
  }

  private int getFlHeight() {
    int listHeight =
        addresses.size() * ListItemHeight + (addresses.size() - 1) * lv.getDividerHeight();
    return Math.min(MaxListHeight, Math.max(listHeight, MinListHeight));
  }
}
 @Override
 public int getSuggestHeight() {
   return UIUtil.dip2pix(200);
 }
Ejemplo n.º 7
0
public class FancyQrCodeThread extends Thread {
  public static interface FancyQrCodeListener {
    public void generated(Bitmap bmp);
  }

  public static final float AvatarSizeRate = 0.24f;
  public static final int MarginSize = UIUtil.dip2pix(16);
  private FancyQrCodeListener listener;
  private String content;
  private int size;
  private int fgColor = Color.BLACK;
  private int bgColor = Color.WHITE;
  private boolean addAvatar;

  public FancyQrCodeThread(
      String content, int size, int fgColor, int bgColor, FancyQrCodeListener listener) {
    this(content, size, fgColor, bgColor, listener, true);
  }

  public FancyQrCodeThread(
      String content,
      int size,
      int fgColor,
      int bgColor,
      FancyQrCodeListener listener,
      boolean addAvatar) {
    this.content = content;
    this.listener = listener;
    this.size = size;
    this.fgColor = fgColor;
    this.bgColor = bgColor;
    this.addAvatar = addAvatar;
  }

  @Override
  public void run() {
    final Bitmap qrCode = Qr.bitmap(content, size, fgColor, bgColor, MarginSize);
    final int qrCodeSize = Math.min(qrCode.getWidth(), qrCode.getHeight());
    if (addAvatar && AppSharedPreference.getInstance().hasUserAvatar()) {
      ImageManageUtil.getAvatarForFancyQrCode(
          new IGetAvatarListener() {
            @Override
            public void success(Bitmap bit) {
              if (bit != null) {
                Canvas c = new Canvas(qrCode);
                int avatarSize = (int) (qrCodeSize * AvatarSizeRate);
                int avaterOffset = (qrCodeSize - avatarSize) / 2;
                Paint paint = new Paint();
                paint.setAntiAlias(true);
                c.drawBitmap(
                    bit,
                    null,
                    new Rect(
                        avaterOffset,
                        avaterOffset,
                        avaterOffset + avatarSize,
                        avaterOffset + avatarSize),
                    paint);
              }
            }

            @Override
            public void fileNoExist() {}
          });
    }

    if (listener != null) {
      ThreadUtil.runOnMainThread(
          new Runnable() {
            @Override
            public void run() {
              listener.generated(qrCode);
            }
          });
    }
  }
}