public Bitmap getBitmapFromView() {
   RelativeLayout v = (RelativeLayout) mInflater.inflate(R.layout.new_action_item, null);
   v.setLayoutParams(
       new LayoutParams(
           RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
   v.measure(
       MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
       MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
   v.layout(0, 0, v.getMeasuredWidth(), v.getMeasuredHeight());
   Bitmap b =
       Bitmap.createBitmap(v.getMeasuredWidth(), v.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
   Canvas c = new Canvas(b);
   v.draw(c);
   return b;
 }
Пример #2
0
  /** init drop down style, only init once */
  private void initDropDownStyle() {
    if (headerLayout != null) {
      if (isDropDownStyle) {
        addHeaderView(headerLayout);
      } else {
        removeHeaderView(headerLayout);
      }
      return;
    }
    if (!isDropDownStyle) {
      return;
    }

    headerReleaseMinDistance =
        context
            .getResources()
            .getDimensionPixelSize(R.dimen.drop_down_list_header_release_min_distance);
    flipAnimation =
        new RotateAnimation(
            0, 180, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    flipAnimation.setInterpolator(new LinearInterpolator());
    flipAnimation.setDuration(250);
    flipAnimation.setFillAfter(true);
    reverseFlipAnimation =
        new RotateAnimation(
            -180, 0, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
    reverseFlipAnimation.setInterpolator(new LinearInterpolator());
    reverseFlipAnimation.setDuration(250);
    reverseFlipAnimation.setFillAfter(true);

    headerDefaultText = context.getString(R.string.drop_down_list_header_default_text);
    headerPullText = context.getString(R.string.drop_down_list_header_pull_text);
    headerReleaseText = context.getString(R.string.drop_down_list_header_release_text);
    headerLoadingText = context.getString(R.string.drop_down_list_header_loading_text);

    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    headerLayout = (RelativeLayout) inflater.inflate(R.layout.drop_down_list_header, this, false);
    headerText = (TextView) headerLayout.findViewById(R.id.drop_down_list_header_default_text);
    headerImage = (ImageView) headerLayout.findViewById(R.id.drop_down_list_header_image);
    headerProgressBar =
        (ProgressBar) headerLayout.findViewById(R.id.drop_down_list_header_progress_bar);
    headerSecondText = (TextView) headerLayout.findViewById(R.id.drop_down_list_header_second_text);
    headerLayout.setClickable(true);
    headerLayout.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            onDropDown();
          }
        });
    headerText.setText(headerDefaultText);
    addHeaderView(headerLayout);

    measureHeaderLayout(headerLayout);
    headerOriginalHeight = headerLayout.getMeasuredHeight();
    headerOriginalTopPadding = headerLayout.getPaddingTop();
    currentHeaderStatus = HEADER_STATUS_CLICK_TO_LOAD;
  }
Пример #3
0
  /** 初始化标题题目 */
  private void initTitleText() {
    int padLeft = DisplayUtil.dip2px(mContext, 25);
    int h = 0;
    if (mTitleImage != null) {
      h = mTitleImage.getMinimumHeight();
    }
    TextView tv = new TextView(mContext);
    tv.setTextSize(title_size);
    tv.setTextColor(title_color);
    tv.setText(mTitlt);
    int padTop = DisplayUtil.dip2px(mContext, 10);
    tv.setPadding(padLeft + h, padTop, 0, padTop);
    title.addView(tv);
    mButton = new ImageButton(mContext);
    mButton.setImageDrawable(mCollapsed ? mExpandDrawable : mCollapseDrawable);
    h = mExpandDrawable.getMinimumHeight();
    MarginLayoutParams mp = new MarginLayoutParams(h, h); // item的宽高
    mp.setMargins(0, 0, padLeft, 0); // 分别是margin_top那四个属性
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(mp);
    params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    params.addRule(RelativeLayout.CENTER_VERTICAL);
    mButton.setLayoutParams(params);
    title.addView(mButton);
    //        title.measure(0, 0);

    View line = new View(mContext);
    line.setBackgroundColor(line_color);
    h = DisplayUtil.dip2px(mContext, 1);
    MarginLayoutParams mpLine = new MarginLayoutParams(LayoutParams.MATCH_PARENT, h); // item的宽高
    title.measure(0, 0);
    h = title.getMeasuredHeight() - h;
    mpLine.setMargins(0, h, 0, 0); // 分别是margin_top那四个属性
    RelativeLayout.LayoutParams mpLineparams = new RelativeLayout.LayoutParams(mpLine);
    line.setLayoutParams(mpLineparams);
    title.addView(line);

    View line1 = new View(mContext);
    line1.setBackgroundColor(line_color);
    h = DisplayUtil.dip2px(mContext, 1);
    MarginLayoutParams mpLine1 = new MarginLayoutParams(LayoutParams.MATCH_PARENT, h); // item的宽高
    RelativeLayout.LayoutParams mpLineparams1 = new RelativeLayout.LayoutParams(mpLine1);
    line1.setLayoutParams(mpLineparams1);
    title.addView(line1);

    mMinHeight = title.getMeasuredHeight();
    addView(title);
  }
Пример #4
0
 @Override
 protected void onSizeChanged(int w, int h, int oldw, int oldh) {
   super.onSizeChanged(w, h, oldw, oldh);
   width = vg_left.getMeasuredWidth();
   height = vg_left.getMeasuredHeight();
   // 可以水平拖拽滑动的距离 一共为屏幕宽度的80%
   range = (int) (width * 0.8f);
 }
  private void init(Context context) {
    // Load all of the animations we need in code rather than through XML

    // rotate relatively to center to 180 degrees
    mFlipAnimation =
        new RotateAnimation(
            0,
            -180,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f);
    mFlipAnimation.setInterpolator(new LinearInterpolator());
    mFlipAnimation.setDuration(250);
    mFlipAnimation.setFillAfter(true);

    // rotate relatively to center to 180 degrees back
    mReverseFlipAnimation =
        new RotateAnimation(
            -180,
            0,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f,
            RotateAnimation.RELATIVE_TO_SELF,
            0.5f);
    mReverseFlipAnimation.setInterpolator(new LinearInterpolator());
    mReverseFlipAnimation.setDuration(250);
    mReverseFlipAnimation.setFillAfter(true);

    mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    // get root relative layout of additional top view
    mRefreshView =
        (RelativeLayout)
            mInflater.inflate(R.layout.romanblack_coupon_pull_to_refresh_header, this, false);
    mRefreshViewText =
        (TextView) mRefreshView.findViewById(R.id.romanblack_coupon_pull_to_refresh_text);
    mRefreshViewImage =
        (ImageView) mRefreshView.findViewById(R.id.romanblack_coupon_pull_to_refresh_image);
    mRefreshViewProgress =
        (ProgressBar) mRefreshView.findViewById(R.id.romanblack_coupon_pull_to_refresh_progress);
    mRefreshViewLastUpdated =
        (TextView) mRefreshView.findViewById(R.id.romanblack_coupon_pull_to_refresh_updated_at);
    mRefreshViewImage.setMinimumHeight(50);

    mRefreshView.setOnClickListener(new OnClickRefreshListener());
    mRefreshOriginalTopPadding = mRefreshView.getPaddingTop();

    mRefreshState = TAP_TO_REFRESH;

    addHeaderView(mRefreshView);

    super.setOnScrollListener(this);

    measureView(mRefreshView);
    mRefreshViewHeight = mRefreshView.getMeasuredHeight();
  }
Пример #6
0
  /** Main Sections Motion Events * */
  private void sectionsUp(MotionEvent motionEvent) {

    // TODO make into global variables
    int barHeight = main_sections_bar.getMeasuredHeight();
    int almostUp = 0; // leaving this in case I want to set an upper limit to the bar

    // TODO add momentum logic
    if (motionEvent.getRawY() < MyHelpers.getUsableHeight(this) * main_section_threshold) {
      moveMainSections(main_sections, almostUp);
      main_section_threshold = main_section_threshold_o;
    } else {
      moveMainSections(main_sections, main_sections.getMeasuredHeight() - barHeight);
      main_section_threshold = (1 - main_section_threshold_o);
    }
  }
Пример #7
0
  @Override
  protected void onTimeChanged(WatchFaceTime oldTime, WatchFaceTime newTime) {
    if (layoutSet && (newTime.hasHourChanged(oldTime) || newTime.hasMinuteChanged(oldTime))) {
      wakeLock.acquire(50);
      final java.text.DateFormat timeFormat = DateFormat.getTimeFormat(BaseWatchFace.this);
      mTime.setText(timeFormat.format(System.currentTimeMillis()));
      mTimestamp.setText(readingAge());

      if (ageLevel() <= 0) {
        mSgv.setPaintFlags(mSgv.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG);
      } else {
        mSgv.setPaintFlags(mSgv.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG);
      }

      missedReadingAlert();
      mRelativeLayout.measure(specW, specH);
      mRelativeLayout.layout(
          0, 0, mRelativeLayout.getMeasuredWidth(), mRelativeLayout.getMeasuredHeight());
    }
  }
Пример #8
0
  private void makeNumPad(Context context) {
    textView = new TextView(context);
    textView.setBackgroundColor(0x00000000);
    TableLayout tableLayout = new TableLayout(context);

    tableLayout.setId(41);
    int numRows = 5;
    int numCols = 3;

    htKeys = new Hashtable<Button, String>();
    int[] bgRscs =
        new int[] {
          R.drawable.key1,
          R.drawable.key2,
          R.drawable.key3,
          R.drawable.key4,
          R.drawable.key5,
          R.drawable.key6,
          R.drawable.key7,
          R.drawable.key8,
          R.drawable.key9,
          R.drawable.key_star,
          R.drawable.key0,
          R.drawable.key_sharp,
          R.drawable.key_speed_dial,
          R.drawable.key_call,
          R.drawable.key_delete
        };

    String[] keyChars = new String[] {"1", "2", "3", "4", "5", "6", "7", "8", "9", "*", "0", "#"};

    int cntKey = 0;
    int w = APPWIDTH / numCols;
    int h = w * 2 / 3;
    for (int i = 0; i < numRows; i++) {
      TableRow tr = new TableRow(context);
      for (int j = 0; j < numCols; j++) {
        TableRow.LayoutParams params = new TableRow.LayoutParams(j);
        Button btn = new Button(context);
        btn.setBackgroundResource(bgRscs[cntKey]);
        btn.setLayoutParams(params);
        btn.setAlpha(0.60f);

        if (i < numRows - 1) {
          if (i == 0 && j == 0) {
            btnVoiceMail = btn;
            btn.setOnLongClickListener(
                new View.OnLongClickListener() {

                  @Override
                  public boolean onLongClick(View arg0) {
                    if (isCalling) {
                      return false;
                    }

                    posture = xacPostureSenseFeatureMaker.calculatePosture();
                    if (posture != xacPostureSenseFeatureMaker.NONE) {
                      return false;
                    }

                    //								Log.d(LOGTAG, "voice mail!");
                    LauncherManager.vibrate(500);
                    CallManager.playNextVoiceMail();
                    wasLongClick = true;
                    return false;
                  }
                });
          }

          htKeys.put(btn, keyChars[cntKey]);
          btn.setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                  if (isCalling) {
                    return;
                  }

                  posture = xacPostureSenseFeatureMaker.calculatePosture();
                  if (posture != xacPostureSenseFeatureMaker.NONE) {
                    return;
                  }

                  Button btn = (Button) view;
                  if (btn == btnVoiceMail && wasLongClick) {
                    wasLongClick = false;
                    return;
                  }
                  strKeys += htKeys.get(btn);
                  textView.setText(
                      new StringBuffer(
                              new StringBuffer(strKeys)
                                  .reverse()
                                  .toString()
                                  .substring(0, Math.min(strKeys.length(), 10)))
                          .reverse()
                          .toString());
                }
              });
        } else {
          if (i == 4 && j == 1) {
            // phone call

            btn.setOnClickListener(
                new View.OnClickListener() {

                  @Override
                  public void onClick(View arg0) {
                    if (isCalling) {
                      return;
                    }
                    //								layoutCallScreen.setBackgroundResource(R.drawable.call_out);
                    RelativeLayout.LayoutParams paramsCallScreen =
                        new RelativeLayout.LayoutParams(
                            RelativeLayout.LayoutParams.MATCH_PARENT,
                            RelativeLayout.LayoutParams.MATCH_PARENT);
                    //								paramsCallScreen.addRule(RelativeLayout.ABOVE, layoutViews.getId());
                    appLayout.addView(layoutCallScreen, paramsCallScreen);
                    isCalling = true;
                  }
                });

          } else if (i == 4 && j == 2) {
            // delete

            btn.setOnClickListener(
                new View.OnClickListener() {
                  @Override
                  public void onClick(View view) {
                    if (isCalling) {
                      return;
                    }

                    posture = xacPostureSenseFeatureMaker.calculatePosture();
                    if (posture != xacPostureSenseFeatureMaker.NONE) {
                      return;
                    }

                    if (strKeys.length() > 0) {
                      strKeys = strKeys.substring(0, strKeys.length() - 1);
                      textView.setText(
                          new StringBuffer(
                                  new StringBuffer(strKeys)
                                      .reverse()
                                      .toString()
                                      .substring(0, Math.min(strKeys.length(), 10)))
                              .reverse()
                              .toString());
                    }
                  }
                });
          }
        }

        tr.addView(btn, w, h);

        cntKey++;
      }
      tableLayout.addView(
          tr,
          new TableLayout.LayoutParams(
              TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT));
    }

    RelativeLayout.LayoutParams paramsKeys =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
    paramsKeys.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    layoutCall.addView(tableLayout, paramsKeys);

    //		textView.setBackgroundColor(0xFF000000);
    textView.setText("");
    textView.setTextColor(0xFFFFFFFF);
    textView.setTextSize(60);
    textView.setTypeface(LauncherManager.getTypeface(LauncherManager.NORMAL));
    RelativeLayout.LayoutParams paramsText =
        new RelativeLayout.LayoutParams(
            RelativeLayout.LayoutParams.MATCH_PARENT, layoutCall.getMeasuredHeight() - h * numRows);
    paramsText.addRule(RelativeLayout.ABOVE, tableLayout.getId());
    paramsText.bottomMargin = 100;
    layoutCall.addView(textView, paramsText);
  }
 public void setPraiseView(View v) {
   this.mPraiseView = v;
   parent = (RelativeLayout) mPraiseView.getParent();
   mViewHeight = parent.getMeasuredHeight();
 }
Пример #10
0
  void sectionsMove(MotionEvent motionEvent) {

    // TODO make into global variables
    int barHeight = main_sections_bar.getMeasuredHeight();
    int almostUp = 0; // leaving this in case I want to set an upper limit to the bar

    if (motionEvent.getRawY() > main_sections.getMeasuredHeight()) // Bar down stop
    {
      main_sections.setY(main_sections.getMeasuredHeight() - barHeight);
    } else if (motionEvent.getRawY() <= almostUp && main_sections.getY() <= almostUp) // Bar up stop
    {
      main_sections.setY(almostUp);
    } else // Bar moving
    {
      float newTabY = motionEvent.getRawY() - barHeight;

      if (newTabY <= almostUp) newTabY = almostUp;

      float thresh = .20f;
      if (motionEvent.getRawY() < main_sections.getMeasuredHeight() * main_section_threshold_o) {
        double total = main_sections.getMeasuredHeight() * thresh; // Distance of threshold
        double progr =
            main_sections.getMeasuredHeight() * thresh
                - motionEvent.getRawY(); // Progress into threshold
        double modifier = Math.pow((progr / total), 1.8); // 1.8 arbitrarily choosen
        newTabY -= (progr * (1 - modifier));
        if (newTabY <= almostUp) {
          newTabY = almostUp;
        }
        main_section_threshold = (main_section_threshold_o);
      } else if (motionEvent.getRawY()
          > main_sections.getMeasuredHeight() * (1 - main_section_threshold_o)) {
        double total =
            main_sections.getMeasuredHeight()
                - main_sections.getMeasuredHeight() * (1.0f - thresh); // Distance of threshold
        double progr_1 =
            main_sections.getMeasuredHeight()
                - motionEvent.getRawY(); // Progress Inverse into threshold
        double modifier = Math.pow((progr_1 / total), 1.8); // 1.8 arbitrarily choosen
        newTabY += (progr_1 * (1 - modifier));
        if (newTabY > main_sections.getMeasuredHeight() - barHeight) {
          newTabY = main_sections.getMeasuredHeight() - barHeight;
        }
        main_section_threshold = (1 - main_section_threshold_o);
      }

      main_sections.setY(newTabY);
    }
  }