public ChattingFooterMoreBtnBar(Context paramContext, AttributeSet paramAttributeSet) {
   super(paramContext, paramAttributeSet);
   setOrientation(0);
   setGravity(16);
   setBackgroundResource(a.h.bottombar_bg);
   int i = getResources().getDimensionPixelSize(a.g.SmallListHeight);
   paramAttributeSet = new LinearLayout.LayoutParams(0, i, 1.0F);
   topMargin = a.fromDPToPix(getContext(), 0);
   iTV = new ImageButton(getContext());
   iTV.setImageResource(a.h.chat_more_tran_btn);
   iTV.setScaleType(ImageView.ScaleType.CENTER);
   iTV.setBackgroundResource(0);
   iTV.setContentDescription(paramContext.getString(a.n.chatting_more_share));
   addView(iTV, paramAttributeSet);
   paramAttributeSet = new LinearLayout.LayoutParams(0, i, 1.0F);
   topMargin = a.fromDPToPix(getContext(), 0);
   iTY = new ImageButton(getContext());
   iTY.setImageResource(a.h.chat_more_fav_btn);
   iTY.setScaleType(ImageView.ScaleType.CENTER);
   iTY.setBackgroundResource(0);
   iTY.setContentDescription(paramContext.getString(a.n.chatting_more_favorite));
   addView(iTY, paramAttributeSet);
   paramAttributeSet = new LinearLayout.LayoutParams(0, i, 1.0F);
   topMargin = a.fromDPToPix(getContext(), 0);
   dii = new ImageButton(getContext());
   dii.setImageResource(a.h.chat_more_del_btn);
   dii.setScaleType(ImageView.ScaleType.CENTER);
   dii.setBackgroundResource(0);
   dii.setContentDescription(paramContext.getString(a.n.chatting_more_delete));
   addView(dii, paramAttributeSet);
   if (au.aOj().size() > 0) {
     paramAttributeSet = new LinearLayout.LayoutParams(0, i, 1.0F);
     topMargin = a.fromDPToPix(getContext(), 0);
     iTX = new ImageButton(getContext());
     iTX.setImageResource(a.h.chat_more_more_btn);
     iTX.setScaleType(ImageView.ScaleType.CENTER);
     iTX.setBackgroundResource(0);
     iTX.setContentDescription(paramContext.getString(a.n.chatting_more));
     addView(iTX, paramAttributeSet);
     return;
   }
   paramAttributeSet = new LinearLayout.LayoutParams(0, i, 1.0F);
   topMargin = a.fromDPToPix(getContext(), 0);
   iTW = new ImageButton(getContext());
   iTW.setImageResource(a.h.chat_more_email_btn);
   iTW.setScaleType(ImageView.ScaleType.CENTER);
   iTW.setBackgroundResource(0);
   iTW.setContentDescription(paramContext.getString(a.n.chatting_more_email));
   addView(iTW, paramAttributeSet);
 }
예제 #2
0
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.friendadd2);
   back18 = (ImageButton) findViewById(R.id.back18);
   back18.setScaleType(ImageView.ScaleType.FIT_XY);
 }
  public void start() {
    setContentView(R.layout.game_matrix_layout);
    matrika = new ImageButton[vrstice][stolpci];

    TableLayout tlMatrika = (TableLayout) findViewById(R.id.tableLayoutMatrika);
    for (int i = 0; i < vrstice; i++) {
      TableRow tr = new TableRow(this);
      tlMatrika.addView(tr);
      for (int j = 0; j < stolpci; j++) {
        final int vrstica = i;
        final int stolpec = j;
        final ImageButton ib = new ImageButton(this);
        ib.setAdjustViewBounds(true);
        ib.setImageResource(R.drawable.blank);
        ib.setMaxHeight(60);
        ib.setScaleType(ScaleType.CENTER_INSIDE);

        matrika[i][j] = ib;

        ib.setOnClickListener(
            new OnClickListener() {

              @Override
              public void onClick(View v) {
                pozicijaVrstica = vrstica;
                pozicijaStolpec = stolpec;
              }
            });
        tr.addView(ib);
      }
    }

    NIgra ni = new NIgra(this, matrika, mHandler, msgHandler);
    ni.start();
  }
  /**
   * The system calls this to perform work in the UI thread and delivers the result from
   * doInBackground()
   */
  protected void onPostExecute(final Article result) {
    // Preserve aspect ratio of image
    i.setScaleType(ImageView.ScaleType.CENTER_CROP);
    i.setCropToPadding(true);

    // Set downloaded bitmap
    i.setImageBitmap(result.getBitmap());

    // When clicked, should open webview to article
    i.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent articlePageIntent =
                new Intent(mCWrapper, ArticleActivity.class)
                    .putExtra(Intent.EXTRA_HTML_TEXT, result.getLink())
                    .putExtra(Intent.EXTRA_SHORTCUT_NAME, result.getTitle());
            mFragment.startActivity(articlePageIntent);
          }
        });

    // Title
    textView.setText(result.getTitle());

    // Remove loading bar
    progressBar.setVisibility(ProgressBar.GONE);

    // Make title visible
    textView.setVisibility(TextView.VISIBLE);

    // Save new data to HeadlineFragment
    mFragment.setArticle(result);
  }
예제 #5
0
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {

    Log.d(TAG, "I'm here in ImageCollector's onActivityResult");

    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == Activity.RESULT_OK) {

      int iBWidth = mImageButton.getWidth();
      int iBHeight = mImageButton.getHeight();

      // First decode with inJustDecodeBounds=true to check dimensions
      BitmapFactory.Options options = new BitmapFactory.Options();
      options.inJustDecodeBounds = true;
      BitmapFactory.decodeFile(mCurrentPhotoPath, options);

      // Calculate inSampleSize
      options.inSampleSize = ImageAdapter.calculateInSampleSize(options, iBWidth, iBHeight);
      options.inJustDecodeBounds = false;

      mImageButton.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
      mImageButton.setImageBitmap(BitmapFactory.decodeFile(mCurrentPhotoPath, options));

      GridView imageGrid = (GridView) findViewById(R.id.image_collector_grid);
      imageGrid.setAdapter(mAdapter);
      // mAdapter.loadBitmap(mImageButton, mThumbPosition);
      // mAdapter.notifyDataSetChanged();
    } else Log.d(TAG, "Image Capture Failed or Cancelled");
  }
 @Override
 protected void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   requestWindowFeature(Window.FEATURE_NO_TITLE); // Ìî³ä±êÌâÀ¸
   setContentView(R.layout.activity_infomanagement);
   back15 = (ImageButton) findViewById(R.id.back15);
   back15.setScaleType(ImageView.ScaleType.FIT_XY);
 }
예제 #7
0
  private View addMenuButton(final MenuItem item) {

    final ImageButton actionButton = new ImageButton(mContext, null, R.attr.actionBarItemStyle);

    final LayoutParams params =
        new LayoutParams(
            (int) getResources().getDimension(R.dimen.actionbar_button_width),
            ViewGroup.LayoutParams.MATCH_PARENT);
    params.weight = 1;

    actionButton.setLayoutParams(params);

    actionButton.setImageDrawable(item.getIcon());
    actionButton.setScaleType(ScaleType.CENTER);
    actionButton.setContentDescription(item.getTitle());
    actionButton.setEnabled(item.isEnabled());
    actionButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(final View view) {
            if (!item.isEnabled()) return;
            if (item.hasSubMenu()) {
              mPopupMenu = PopupMenu.getInstance(mContext, view);
              mPopupMenu.setOnMenuItemClickListener(MenuBar.this);
              mPopupMenu.setMenu(item.getSubMenu());
              mPopupMenu.show();
            } else {
              if (mItemClickListener != null) {
                mItemClickListener.onMenuItemClick(item);
              }
            }
          }
        });
    actionButton.setOnLongClickListener(
        new View.OnLongClickListener() {

          @Override
          public boolean onLongClick(final View v) {
            if (item.getItemId() == android.R.id.home) return false;

            final Toast t = Toast.makeText(mContext, item.getTitle(), Toast.LENGTH_SHORT);
            final int[] screenPos = new int[2];
            v.getLocationOnScreen(screenPos);

            final int height = v.getHeight();

            t.setGravity(
                Gravity.TOP | Gravity.LEFT, screenPos[0], (int) (screenPos[1] - height * 1.5));
            t.show();
            return true;
          }
        });

    addView(actionButton);
    return actionButton;
  }
예제 #8
0
  /**
   * Adds an action button to the compatibility action bar, using menu information from a {@link
   * android.view.MenuItem}. If the menu item ID is <code>menu_refresh</code>, the menu item's state
   * can be changed to show a loading spinner using {@link
   * com.lsn.LoadSensing.actionbar.example.android.actionbarcompat.ActionBarHelperBase#setRefreshActionItemState(boolean)}
   * .
   */
  private View addActionItemCompatFromMenuItem(final MenuItem item) {
    final int itemId = item.getItemId();

    final ViewGroup actionBar = getActionBarCompat();
    if (actionBar == null) {
      return null;
    }

    // Create the button
    ImageButton actionButton =
        new ImageButton(
            mActivity,
            null,
            itemId == android.R.id.home
                ? R.attr.actionbarCompatItemHomeStyle
                : R.attr.actionbarCompatItemStyle);
    actionButton.setLayoutParams(
        new ViewGroup.LayoutParams(
            (int)
                mActivity
                    .getResources()
                    .getDimension(
                        itemId == android.R.id.home
                            ? R.dimen.actionbar_compat_button_home_width
                            : R.dimen.actionbar_compat_button_width),
            ViewGroup.LayoutParams.MATCH_PARENT));

    actionButton.setImageDrawable(item.getIcon());
    actionButton.setScaleType(ImageView.ScaleType.CENTER);
    actionButton.setContentDescription(item.getTitle());

    if (itemId == R.id.menu_star) {
      actionButton.setId(R.id.actionbar_compat_item_faves);
      if (trobat) {
        actionButton.setImageResource(R.drawable.ic_action_star_on);
      } else {
        actionButton.setImageResource(R.drawable.ic_action_star_off);
      }
    }

    actionButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View view) {
            mActivity.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, item);
          }
        });

    actionBar.addView(actionButton);

    return actionButton;
  }
예제 #9
0
  private void getPic(Intent data) {
    if (null != data) {
      // 取出所选图片的路径
      Uri selectedImage = data.getData();
      String[] filePathColumn = {MediaStore.Images.Media.DATA};

      Cursor cursor = getContentResolver().query(selectedImage, filePathColumn, null, null, null);
      cursor.moveToFirst();

      int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
      String picuri = cursor.getString(columnIndex);
      cursor.close();

      // 将图片贴到控件上
      BitmapFactory.Options options = new BitmapFactory.Options();
      options.inJustDecodeBounds = true;
      BitmapFactory.decodeFile(picuri, options);
      int width = options.outWidth;
      int height = options.outHeight;
      if (100 > width || 40 > height) {
        // 图片分辨率太低
        Toast.makeText(this, getString(R.string.question_imagetoosmall), Toast.LENGTH_SHORT).show();
        MobclickAgent.onEvent(this, "addQP_F");
        return;
      }

      BitmapFactory.Options opts = new BitmapFactory.Options();
      opts.inJustDecodeBounds = true;
      BitmapFactory.decodeFile(picuri, opts);
      opts.inSampleSize = computeSampleSize(opts, -1, 700 * 272);
      opts.inJustDecodeBounds = false;
      try {
        bitmap = BitmapFactory.decodeFile(picuri, opts);
      } catch (OutOfMemoryError err) {
        // showNotification("图片过大!");
        MobclickAgent.onEvent(this, "addQP_F");
        Toast.makeText(this, getString(R.string.question_imagetoolarge), Toast.LENGTH_SHORT).show();
        return;
      }
      MobclickAgent.onEvent(this, "addQP_S");
      image.setScaleType(ImageView.ScaleType.FIT_CENTER);
      image.setImageBitmap(bitmap);
      hint.setText(getString(R.string.question_removeimage_hint));
    }
  }
예제 #10
0
 @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
 @Override
 public Object instantiateItem(ViewGroup container, int position) {
   LayoutInflater inflater =
       (LayoutInflater) QuickLaunchView.this.getContext().getSystemService("layout_inflater");
   LinearLayout pageView =
       (LinearLayout) inflater.inflate(R.layout.shade_quick_launch_page, null);
   for (int i = position * 5; i < (position * 5) + 5; i++) {
     ImageButton button = (ImageButton) inflater.inflate(R.layout.quicklaunch_button, null);
     button.setScaleType(ScaleType.FIT_CENTER);
     if (i < this.quickLaunchApps.size()) {
       App app = this.quickLaunchApps.get(i);
       button.setImageDrawable(app.getAppIcon());
       button.setOnClickListener(new AnonymousClass_1(app));
     } else {
       button.setBackground(null);
       button.setOnClickListener(null);
     }
     pageView.addView(button, new LayoutParams(-1, -1, 0.5f));
   }
   container.addView(pageView);
   return pageView;
 }
예제 #11
0
    public View getView(final int i, View convertView, ViewGroup viewGroup) {
      ImageButton imageButton;
      if (convertView == null) {
        imageButton = new ImageButton(mContext);
        imageButton.setAdjustViewBounds(true);
        imageButton.setBackgroundResource(R.drawable.site);
        imageButton.setScaleType(ImageView.ScaleType.FIT_CENTER);
      } else {
        imageButton = (ImageButton) convertView;
      }

      imageButton.setImageResource(image_array[i]);

      imageButton.setOnClickListener(
          new View.OnClickListener() {

            public void onClick(View view) {

              String type = (String) getItem(i);

              if (TikaConstants.TYPE_SINA_WEIBO.equals(type)) {
                if (SinaAccountUtil.alreadyBinded(SiteActivity.this)) {
                  Intent intent = new Intent(SiteActivity.this, SinaSourceSelectionActivity.class);
                  intent.putExtra("type", type);
                  intent.putExtra("next", SinaSourceSelectionActivity.class.getName());
                  startActivity(intent);
                  overridePendingTransition(android.R.anim.slide_in_left, R.anim.fade);
                } else {
                  final Intent intent = new Intent(SiteActivity.this, SinaAccountActivity.class);
                  intent.putExtra(
                      "PROMPTTEXT", SiteActivity.this.getString(R.string.gotosinaoauth));
                  startActivity(intent);
                  overridePendingTransition(android.R.anim.slide_in_left, R.anim.fade);
                }
                //                        finish();
              }
              if (TikaConstants.TYPE_GOOGLE_READER.equals(type)) {
                startActivity(new Intent(SiteActivity.this, GoogleAccountActivity.class));
                overridePendingTransition(android.R.anim.slide_in_left, R.anim.fade);
                //                        finish();
              }
              if (TikaConstants.TYPE_RSS.equals(type)) {
                Intent intent = new Intent(SiteActivity.this, RSSSourceSelectionActivity.class);
                intent.putExtra("type", type);
                startActivity(intent);
                overridePendingTransition(android.R.anim.slide_in_left, R.anim.fade);
                //                        finish();
              }
              if (Constants.TYPE_FLIPDROID.equals(type)) {
                Intent intent = new Intent(SiteActivity.this, FlipdroidSourceActivity.class);
                intent.putExtra("type", type);
                startActivity(intent);
                overridePendingTransition(android.R.anim.slide_in_left, R.anim.fade);
                //                        finish();
              }

              if (Constants.TYPE_BAIDUSEARCH.equals(type)) {
                Intent intent = new Intent(SiteActivity.this, BaiduSearchSourceActivity.class);
                intent.putExtra("type", type);
                startActivity(intent);
                overridePendingTransition(android.R.anim.slide_in_left, R.anim.fade);
                //                        finish();
              }

              //                        if(Constants.TYPE_TENCENT_WEIBO.equals(type)){
              //                            //TODO: Tencent Login
              //                        } if(Constants.TYPE_TWITTER.equals(type)){
              //                            //TODO: Twitter Login
              //                        }

            }
          });
      return imageButton;
    }
예제 #12
0
  private void init() {
    mCurrentDirectory = Environment.getExternalStorageDirectory();
    mInitialDirectory = Environment.getExternalStorageDirectory();

    this.setBackgroundResource(R.drawable.bg_pathbar);
    this.setInAnimation(getContext(), R.anim.fade_in);
    this.setOutAnimation(getContext(), R.anim.fade_out);

    // RelativeLayout1
    RelativeLayout standardModeLayout = new RelativeLayout(getContext());
    { // I use a block here so that layoutParams can be used as a variable name further down.
      android.widget.ViewFlipper.LayoutParams layoutParams =
          new android.widget.ViewFlipper.LayoutParams(
              LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
      standardModeLayout.setLayoutParams(layoutParams);

      this.addView(standardModeLayout);
    }

    // ImageButton -- GONE. Kept this code in case we need to use an right-aligned button in the
    // future.
    mSwitchToManualModeButton = new ImageButton(getContext());
    {
      android.widget.RelativeLayout.LayoutParams layoutParams =
          new android.widget.RelativeLayout.LayoutParams(
              LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
      layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

      mSwitchToManualModeButton.setLayoutParams(layoutParams);
      mSwitchToManualModeButton.setId(10);
      mSwitchToManualModeButton.setImageResource(R.drawable.ic_navbar_edit);
      mSwitchToManualModeButton.setBackgroundResource(R.drawable.bg_navbar_btn);
      mSwitchToManualModeButton.setVisibility(View.GONE);

      standardModeLayout.addView(mSwitchToManualModeButton);
    }

    // ImageButton -- GONE. Kept this code in case we need to use an left-aligned button in the
    // future.
    ImageButton cdToRootButton = new ImageButton(getContext());
    {
      android.widget.RelativeLayout.LayoutParams layoutParams =
          new android.widget.RelativeLayout.LayoutParams(
              LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
      layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);

      cdToRootButton.setLayoutParams(layoutParams);
      cdToRootButton.setId(11);
      cdToRootButton.setBackgroundResource(R.drawable.bg_navbar_btn);
      cdToRootButton.setImageResource(R.drawable.ic_navbar_home);
      cdToRootButton.setScaleType(ScaleType.CENTER_INSIDE);
      cdToRootButton.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View v) {
              cd("/");
            }
          });
      cdToRootButton.setVisibility(View.GONE);

      standardModeLayout.addView(cdToRootButton);
    }

    // Horizontal ScrollView container
    mPathButtonsContainer = new HorizontalScrollView(getContext());
    {
      android.widget.RelativeLayout.LayoutParams layoutParams =
          new android.widget.RelativeLayout.LayoutParams(
              LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
      layoutParams.addRule(RelativeLayout.LEFT_OF, mSwitchToManualModeButton.getId());
      layoutParams.addRule(RelativeLayout.RIGHT_OF, cdToRootButton.getId());
      layoutParams.alignWithParent = true;

      mPathButtonsContainer.setLayoutParams(layoutParams);
      mPathButtonsContainer.setHorizontalScrollBarEnabled(false);
      mPathButtonsContainer.setHorizontalFadingEdgeEnabled(true);

      standardModeLayout.addView(mPathButtonsContainer);
    }

    // PathButtonLayout
    mPathButtons = new PathButtonLayout(getContext());
    {
      android.widget.LinearLayout.LayoutParams layoutParams =
          new android.widget.LinearLayout.LayoutParams(
              LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);

      mPathButtons.setLayoutParams(layoutParams);
      mPathButtons.setNavigationBar(this);

      mPathButtonsContainer.addView(mPathButtons);
    }

    // RelativeLayout2
    RelativeLayout manualModeLayout = new RelativeLayout(getContext());
    {
      android.widget.ViewFlipper.LayoutParams layoutParams =
          new android.widget.ViewFlipper.LayoutParams(
              LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
      manualModeLayout.setLayoutParams(layoutParams);

      this.addView(manualModeLayout);
    }

    // ImageButton
    mGoButton = new ImageButton(getContext());
    {
      android.widget.RelativeLayout.LayoutParams layoutParams =
          new android.widget.RelativeLayout.LayoutParams(
              LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
      layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

      mGoButton.setLayoutParams(layoutParams);
      mGoButton.setId(20);
      mGoButton.setBackgroundResource(R.drawable.bg_navbar_btn);
      mGoButton.setImageResource(R.drawable.ic_navbar_accept);
      mGoButton.setScaleType(ScaleType.CENTER_INSIDE);
      mGoButton.setOnClickListener(
          new View.OnClickListener() {

            @Override
            public void onClick(View v) {
              manualInputCd(mPathEditText.getText().toString());
            }
          });

      manualModeLayout.addView(mGoButton);
    }

    // EditText
    mPathEditText = new EditText(getContext());
    {
      android.widget.RelativeLayout.LayoutParams layoutParams =
          new android.widget.RelativeLayout.LayoutParams(
              LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
      layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
      layoutParams.alignWithParent = true;
      layoutParams.addRule(RelativeLayout.LEFT_OF, mGoButton.getId());

      mPathEditText.setLayoutParams(layoutParams);
      mPathEditText.setBackgroundResource(R.drawable.bg_navbar_textfield);
      mPathEditText.setTextColor(Color.BLACK);
      mPathEditText.setInputType(InputType.TYPE_TEXT_VARIATION_URI);
      mPathEditText.setImeOptions(EditorInfo.IME_ACTION_GO);
      mPathEditText.setOnEditorActionListener(
          new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
              if (actionId == EditorInfo.IME_ACTION_GO
                  || (event.getAction() == KeyEvent.ACTION_DOWN
                      && (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_CENTER
                          || event.getKeyCode() == KeyEvent.KEYCODE_ENTER))) {
                if (manualInputCd(v.getText().toString()))
                  // Since we have successfully navigated.
                  return true;
              }

              return false;
            }
          });

      manualModeLayout.addView(mPathEditText);
    }
  }
예제 #13
0
  private LinearLayout createProductInfo(com.app.commons.JSONObject jo) {
    JSONArray ja = jo.getJSONArray("settleGoods");
    if (ja == null || ja.length() == 0) {
      return null;
    }
    final String productSku = jo.getString("productSku");
    LinearLayout info = new LinearLayout(CartActivtiy.this);
    int cart_height = Math.round(getResources().getDimension(R.dimen.cart_height));
    info.setLayoutParams(
        new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    info.setMinimumHeight(cart_height);
    info.setOrientation(LinearLayout.HORIZONTAL);
    info.setGravity(Gravity.CENTER_VERTICAL);
    info.setBackgroundResource(R.drawable.border2);
    info.setPadding(10, 0, 10, 0);
    final CheckBox rb = new CheckBox(CartActivtiy.this);
    rb.setPadding(0, 0, 10, 0);
    rb.setButtonDrawable(R.drawable.checkbox);
    if (jo.getBoolean("checked")) {
      rb.setChecked(true);
      settleNum = settleNum + 1;
    } else {
      rb.setChecked(false);
    }
    rb.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            Map<String, Object> param = new HashMap<>();
            param.put("ids", productSku);
            param.put("checkeds", rb.isChecked() ? "Y" : "N");
            Utils.asyncHttpRequestPost(
                Constants.URL_CART_CHANGESTATUS,
                param,
                new JsonHttpResponseHandler() {
                  @Override
                  public void onSuccess(int statusCode, Header[] headers, JSONObject res) {
                    com.app.commons.JSONObject jo = new com.app.commons.JSONObject(res);
                    if (statusCode == 200) {
                      if (jo.getBoolean("success")) {
                        flushCartInfo();
                      } else {
                        Toast.makeText(
                                CartActivtiy.this, jo.getString("errMsg"), Toast.LENGTH_SHORT)
                            .show();
                        flushCartInfo();
                      }
                    } else {
                      Toast.makeText(CartActivtiy.this, statusCode, Toast.LENGTH_SHORT).show();
                    }
                  }
                });
          }
        });
    info.addView(rb);
    LinearLayout center = new LinearLayout(CartActivtiy.this);
    LinearLayout.LayoutParams centerLP =
        new LinearLayout.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    centerLP.weight = 1;
    center.setOrientation(LinearLayout.VERTICAL);
    center.setLayoutParams(centerLP);
    center.setPadding(10, 0, 0, 0);
    int wh2 = Math.round(getResources().getDimension(R.dimen.btn_cart_height));
    if (ja != null && ja.length() > 0) {
      ImageView iv = new ImageView(CartActivtiy.this);
      int wh = Math.round(getResources().getDimension(R.dimen.cart_img_wh));
      iv.setLayoutParams(new ViewGroup.LayoutParams(wh, wh));
      iv.setImageResource(R.drawable.loading);
      Utils.asyncLoadInternetImageView(
          iv, Constants.URL_IMAGE + "/200X200" + ja.getJSONObject(0).getString("photoUrl"));
      info.addView(iv);
      TextView tv = new TextView(CartActivtiy.this);
      if (ja.length() == 1) {
        tv.setText(ja.getJSONObject(0).getString("goodsName"));
      } else {
        tv.setText(getResources().getString(R.string.goods_set));
      }
      center.addView(tv);
      LinearLayout bottom = new LinearLayout(CartActivtiy.this);
      bottom.setLayoutParams(
          new ViewGroup.LayoutParams(
              ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
      bottom.setOrientation(LinearLayout.HORIZONTAL);
      bottom.setPadding(0, 15, 0, 0);
      LinearLayout.LayoutParams wrap = new LinearLayout.LayoutParams(wh2, wh2);
      wrap.setMargins(5, 0, 5, 0);
      final EditText et = new EditText(CartActivtiy.this);
      et.setBackgroundResource(R.drawable.wrapcontent);
      et.setText(jo.getString("number"));
      et.setSingleLine(true);
      et.setKeyListener(new DigitsKeyListener(false, false));
      et.setLayoutParams(wrap);
      et.setGravity(Gravity.RIGHT);
      et.setPadding(5, 2, 5, 2);
      et.setFocusable(true);
      et.addTextChangedListener(
          new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {}

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {}

            @Override
            public void afterTextChanged(Editable editable) {
              if (editable.length() == 0) {
                editable.append(String.valueOf(def_num));
              } else if (Integer.parseInt(editable.toString()) <= 0) {
                editable.replace(0, 1, String.valueOf(def_num));
              } else if (editable.length() > 2) {
                editable.replace(0, editable.length(), String.valueOf(def_maxnum));
              }
              Map<String, Object> param = new HashMap<>();
              param.put("id", productSku);
              param.put("count", editable.toString());
              Utils.asyncHttpRequestPost(
                  Constants.URL_CART_CHANGENUMBER,
                  param,
                  new JsonHttpResponseHandler() {
                    @Override
                    public void onSuccess(int statusCode, Header[] headers, JSONObject res) {
                      com.app.commons.JSONObject jo = new com.app.commons.JSONObject(res);
                      if (statusCode == 200) {
                        if (jo.getBoolean("success")) {
                          flushCartInfo();
                        } else {
                          Toast.makeText(
                                  CartActivtiy.this, jo.getString("errMsg"), Toast.LENGTH_SHORT)
                              .show();
                          flushCartInfo();
                        }
                      } else {
                        Toast.makeText(CartActivtiy.this, statusCode, Toast.LENGTH_SHORT).show();
                      }
                    }
                  });
            }
          });
      ImageView sub = new ImageView(CartActivtiy.this);
      sub.setScaleType(ImageView.ScaleType.FIT_CENTER);
      sub.setLayoutParams(wrap);
      sub.setImageResource(R.drawable.cart_sub);
      sub.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              int num = Integer.parseInt(et.getText().toString());
              if (num > 1) {
                et.setText(String.valueOf((num - 1)));
              }
            }
          });
      ImageView add = new ImageView(CartActivtiy.this);
      add.setLayoutParams(wrap);
      add.setScaleType(ImageView.ScaleType.FIT_CENTER);
      add.setImageResource(R.drawable.cart_add);
      add.setOnClickListener(
          new View.OnClickListener() {
            @Override
            public void onClick(View view) {
              Integer num = Integer.parseInt(et.getText().toString());
              et.setText(String.valueOf(num + 1));
            }
          });
      bottom.addView(sub);
      bottom.addView(et);
      bottom.addView(add);
      if (jo.getString("remark") != null) {
        TextView remark = new TextView(CartActivtiy.this);
        remark.setText(jo.getString("remark"));
        remark.setTextColor(getResources().getColor(R.color.red));
        bottom.addView(remark);
      }
      center.addView(bottom);
    }
    LinearLayout right = new LinearLayout(CartActivtiy.this);
    right.setOrientation(LinearLayout.VERTICAL);
    right.setGravity(Gravity.CENTER);
    right.setPadding(0, 0, 0, 5);
    TextView tv2 = new TextView(CartActivtiy.this);
    tv2.setLayoutParams(
        new ViewGroup.LayoutParams(
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    tv2.setGravity(Gravity.CENTER);
    tv2.setText("¥" + jo.getString("amount"));
    tv2.setTextColor(getResources().getColor(R.color.red));
    right.addView(tv2);
    ImageButton ib = new ImageButton(CartActivtiy.this);
    int cdelw = Math.round(getResources().getDimension(R.dimen.cart_delete_width));
    int cdelh = Math.round(getResources().getDimension(R.dimen.cart_delete_height));
    ib.setLayoutParams(new ViewGroup.LayoutParams(cdelw, cdelh));
    ib.setScaleType(ImageView.ScaleType.FIT_CENTER);
    ib.setBackgroundResource(R.drawable.border3);
    ib.setImageResource(R.drawable.cart_delete);
    ib.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View view) {
            Map<String, Object> param = new HashMap<String, Object>();
            param.put("ids", productSku);
            Utils.asyncHttpRequestPost(
                Constants.URL_CART_DELETEPRODUCTS,
                param,
                new JsonHttpResponseHandler() {
                  @Override
                  public void onSuccess(int statusCode, Header[] headers, JSONObject res) {
                    com.app.commons.JSONObject jo = new com.app.commons.JSONObject(res);
                    if (statusCode == 200) {
                      if (jo.getBoolean("success")) {
                        flushCartInfo();
                      } else {
                        Toast.makeText(
                                CartActivtiy.this, jo.getString("errMsg"), Toast.LENGTH_SHORT)
                            .show();
                        flushCartInfo();
                      }
                    } else {
                      Toast.makeText(CartActivtiy.this, statusCode, Toast.LENGTH_SHORT).show();
                    }
                  }
                });
          }
        });
    right.addView(ib);
    info.addView(center);
    info.addView(right);
    return info;
  }
예제 #14
0
  private void init(Context context) {
    int width = (int) context.getResources().getDimension(R.dimen.title_button_width);
    LayoutParams leftLayoutParams = new LayoutParams(width, LayoutParams.MATCH_PARENT);
    imgLeft = new ImageButton(context);
    imgLeft.setId(R.id.common_title_left_img);
    imgLeft.setPadding(padding, padding, padding, padding);
    imgLeft.setLayoutParams(leftLayoutParams);
    imgLeft.setScaleType(ScaleType.CENTER_INSIDE);
    imgLeft.setBackgroundResource(R.drawable.b_button);
    imgLeft.setOnClickListener(this);
    if (leftDrawable == null && TextUtils.isEmpty(leftText)) {
      imgLeft.setImageResource(R.drawable.backarrow);
      imgLeft.setContentDescription("Back");
    } else {
      imgLeft.setImageDrawable(leftDrawable);
    }

    LayoutParams leftLayoutParams2 =
        new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
    btnLeft = new Button(context);
    btnLeft.setId(R.id.common_title_left_txt);
    btnLeft.setTextColor(getResources().getColor(R.color.blue));
    btnLeft.setLayoutParams(leftLayoutParams2);
    btnLeft.setMinimumWidth(width);
    btnLeft.setBackgroundResource(R.drawable.b_button);
    btnLeft.setOnClickListener(this);
    if (!TextUtils.isEmpty(leftText)) {
      btnLeft.setText(leftText);
    } else {
      btnLeft.setVisibility(View.INVISIBLE);
    }

    LayoutParams rightLayoutParams = new LayoutParams(width, LayoutParams.MATCH_PARENT);
    rightLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
    imgRight = new ImageButton(context);
    imgRight.setId(R.id.common_title_right_img);
    imgRight.setPadding(padding, padding, padding, padding);
    imgRight.setLayoutParams(rightLayoutParams);
    imgRight.setScaleType(ScaleType.CENTER_INSIDE);
    imgRight.setBackgroundResource(R.drawable.b_button);
    if (rightDrawable != null) {
      imgRight.setImageDrawable(rightDrawable);
    } else {
      imgRight.setVisibility(View.INVISIBLE);
    }

    LayoutParams rightLayoutParams2 =
        new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
    rightLayoutParams2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
    btnRight = new Button(context);
    btnRight.setId(R.id.common_title_right_txt);
    btnRight.setTextColor(getResources().getColor(R.color.blue));
    btnRight.setLayoutParams(rightLayoutParams2);
    btnRight.setMinimumWidth(width);
    btnRight.setBackgroundResource(R.drawable.b_button);
    if (!TextUtils.isEmpty(rightText)) {
      btnRight.setText(rightText);
    } else {
      btnRight.setVisibility(View.INVISIBLE);
    }

    LayoutParams titleLayoutParams =
        new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    titleLayoutParams.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
    titleLayoutParams.addRule(RelativeLayout.RIGHT_OF, R.id.common_title_left_img);
    titleLayoutParams.addRule(RelativeLayout.LEFT_OF, R.id.common_title_right_img);
    txtTitle = new TextView(context);
    txtTitle.setId(R.id.common_title_title_txt);
    txtTitle.setTextSize(
        TypedValue.COMPLEX_UNIT_PX, getResources().getDimension(R.dimen.font_size_large_x));
    txtTitle.setLayoutParams(titleLayoutParams);
    txtTitle.setTextColor(getResources().getColor(R.color.blue));
    txtTitle.setBackgroundColor(0x00000000);
    txtTitle.setSingleLine();
    txtTitle.setEllipsize(TruncateAt.MARQUEE);
    txtTitle.setGravity(Gravity.CENTER);
    txtTitle.setSelected(true);
    if (title == null) {
      txtTitle.setText("");
    } else {
      txtTitle.setText(title);
    }

    LayoutParams divisionLayoutParams = new LayoutParams(LayoutParams.MATCH_PARENT, 2);
    divisionLayoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
    View division = new View(context);
    division.setLayoutParams(divisionLayoutParams);
    division.setBackgroundColor(getResources().getColor(R.color.gray_division));
    this.addView(imgLeft);
    this.addView(btnLeft);
    this.addView(txtTitle);
    this.addView(imgRight);
    this.addView(btnRight);
    this.addView(division);
    setBackgroundColor(0xffffffff);
  }
예제 #15
0
  // Draws the Events
  private void drawEvents() {

    int counter = 0;
    layout.removeAllViews();
    for (JSONObject j : events) {
      try {
        final String eid = j.getString("eid");
        final String name = j.getString("name");
        final int icon = j.getInt("icon");
        final int creator = j.getInt("creator");
        String update = j.getString("updated");
        final String temp = j.getString("datetime");
        String month = temp.substring(5, 7);
        String day = temp.substring(8, 10);
        String date = day + '-' + month;

        RelativeLayout.LayoutParams lp_icon = new RelativeLayout.LayoutParams(height, height);
        RelativeLayout.LayoutParams lp_button = new RelativeLayout.LayoutParams(width, height);
        RelativeLayout.LayoutParams lp_date = new RelativeLayout.LayoutParams(dateWidth, height);
        RelativeLayout.LayoutParams lp_div = new RelativeLayout.LayoutParams(width, divHeight);

        /**
         * Adds the icon: to limit the use of data we store the images in a local database, and in
         * an online database. Whenever someone uploads a new icon a new random icon_ID gets
         * generated when the icon_ID in your local DB doesn't equal the one in the online database,
         * the one in the online DB gets downloaded and the offline DB gets updated with this EID
         * and image.
         */
        lp_icon.setMargins(0, (height + divHeight) * counter, 0, 0);
        final ImageButton img = new ImageButton(this);
        if (icon == 0) {
          img.setImageResource(R.drawable.group);
          img.setPadding(12, 12, 12, 12);
          user_db.deleteBlob(eid);
        } else {
          if (icon == user_db.getVersion(eid)) {
            byte[] image = user_db.getBlob(eid);
            img.setImageBitmap(BitmapFactory.decodeByteArray(image, 0, image.length));
            img.setPadding(7, 7, 7, 7);
          } else {
            String tag_icon = "req_icon";
            StringRequest stringRequest =
                new StringRequest(
                    Request.Method.POST,
                    URL_ICON,
                    new Response.Listener<String>() {

                      @Override
                      public void onResponse(String response) {
                        try {
                          JSONObject jObj = new JSONObject(response);
                          boolean error = jObj.getBoolean("error");

                          if (!error) {
                            byte[] blob = Base64.decode(jObj.getString("blob"), Base64.DEFAULT);
                            if (user_db.getVersion(eid) == 0) {
                              user_db.addBLOB(eid, icon, blob);
                            } else {
                              user_db.updateBlob(eid, icon, blob);
                            }
                            img.setImageBitmap(BitmapFactory.decodeByteArray(blob, 0, blob.length));
                            img.setPadding(7, 7, 7, 7);
                          }
                        } catch (JSONException e) {
                          e.printStackTrace();
                        }
                      }
                    },
                    new Response.ErrorListener() {

                      @Override
                      public void onErrorResponse(VolleyError error) {}
                    }) {

                  @Override
                  protected Map<String, String> getParams() {
                    Map<String, String> params = new HashMap<String, String>();
                    params.put("tag", "get");
                    params.put("eid", eid);
                    return params;
                  }
                };
            AppController.getInstance().addToRequestQueue(stringRequest, tag_icon);
          }
        }
        img.setLayoutParams(lp_icon);
        img.setBackground(null);
        img.setScaleType(ImageView.ScaleType.FIT_CENTER);
        layout.addView(img);

        // Add the button
        lp_button.setMargins(height, (height + divHeight) * counter, height, 0);
        TextView button = new TextView(this);
        button.setText(name);
        button.setTypeface(express);
        button.setTextSize(getResources().getDimension(R.dimen.button_text));
        button.setTextColor(getResources().getColor(R.color.black));
        button.setGravity(Gravity.CENTER_VERTICAL);
        button.setLayoutParams(lp_button);
        layout.addView(button);
        button.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                Intent intent = new Intent(MainActivity.this, EventActivity.class);
                Bundle b = new Bundle();
                b.putString("eid", eid);
                b.putString("name", name);
                b.putInt("icon", icon);
                b.putInt("creator", creator);
                b.putString("date", temp);
                intent.putExtras(b);
                startActivity(intent);
              }
            });

        // Add the Date
        if (!month.equals("00") && !day.equals("00")) {
          lp_date.setMargins(0, (height + divHeight) * counter, 0, 0);
          lp_date.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
          TextView datetime = new TextView(this);
          datetime.setText(date);
          datetime.setGravity(Gravity.CENTER);
          datetime.setLayoutParams(lp_date);
          layout.addView(datetime);
        }

        // Add the Divider
        lp_div.setMargins(height, (height + divHeight) * counter + height, 20, 0);
        ImageView div = new ImageView(this);
        div.setImageResource(R.drawable.divider);
        div.setLayoutParams(lp_div);
        layout.addView(div);

        counter++;
      } catch (JSONException ex) {

      }
    }
  }
  /**
   * Adds an action button to the compatibility action bar, using menu information from a {@link
   * android.view.MenuItem}. If the menu item ID is <code>menu_refresh</code>, the menu item's state
   * can be changed to show a loading spinner using {@link
   * com.example.android.actionbarcompat.ActionBarHelperBase#setRefreshActionItemState(boolean)}.
   */
  private View addActionItemCompatFromMenuItem(final MenuItem item) {
    final int itemId = item.getItemId();

    final ViewGroup actionBar = getActionBarCompat();
    if (actionBar == null) {
      return null;
    }

    // Create the button
    ImageButton actionButton =
        new ImageButton(
            mActivity,
            null,
            itemId == android.R.id.home
                ? R.attr.actionbarCompatItemHomeStyle
                : R.attr.actionbarCompatItemStyle);
    actionButton.setLayoutParams(
        new ViewGroup.LayoutParams(
            (int)
                mActivity
                    .getResources()
                    .getDimension(
                        itemId == android.R.id.home
                            ? R.dimen.actionbar_compat_button_home_width
                            : R.dimen.actionbar_compat_button_width),
            ViewGroup.LayoutParams.FILL_PARENT));
    if (itemId == R.id.menu_refresh) {
      actionButton.setId(R.id.actionbar_compat_item_refresh);
    }
    actionButton.setImageDrawable(item.getIcon());
    actionButton.setScaleType(ImageView.ScaleType.CENTER);
    actionButton.setContentDescription(item.getTitle());
    actionButton.setOnClickListener(
        new View.OnClickListener() {
          public void onClick(View view) {
            mActivity.onMenuItemSelected(Window.FEATURE_OPTIONS_PANEL, item);
          }
        });

    actionBar.addView(actionButton);

    if (item.getItemId() == R.id.menu_refresh) {
      // Refresh buttons should be stateful, and allow for indeterminate progress indicators,
      // so add those.
      ProgressBar indicator =
          new ProgressBar(mActivity, null, R.attr.actionbarCompatProgressIndicatorStyle);

      final int buttonWidth =
          mActivity.getResources().getDimensionPixelSize(R.dimen.actionbar_compat_button_width);
      final int buttonHeight =
          mActivity.getResources().getDimensionPixelSize(R.dimen.actionbar_compat_height);
      final int progressIndicatorWidth = buttonWidth / 2;

      LinearLayout.LayoutParams indicatorLayoutParams =
          new LinearLayout.LayoutParams(progressIndicatorWidth, progressIndicatorWidth);
      indicatorLayoutParams.setMargins(
          (buttonWidth - progressIndicatorWidth) / 2,
          (buttonHeight - progressIndicatorWidth) / 2,
          (buttonWidth - progressIndicatorWidth) / 2,
          0);
      indicator.setLayoutParams(indicatorLayoutParams);
      indicator.setVisibility(View.GONE);
      indicator.setId(R.id.actionbar_compat_item_refresh_progress);
      actionBar.addView(indicator);
    }

    return actionButton;
  }