コード例 #1
0
  private void setLayoutFunction() {

    Typeface FONT = Typeface.createFromAsset(getAssets(), "fonts/KIT45.TTF");

    // SET LAYOUT
    android.view.ViewGroup.LayoutParams L_headLayout = headLayout.getLayoutParams();
    android.view.ViewGroup.LayoutParams L_imgWave = imgWave.getLayoutParams();
    android.view.ViewGroup.LayoutParams L_BackBT = BackBT.getLayoutParams();
    android.view.ViewGroup.LayoutParams L_typeButton = typeButton.getLayoutParams();
    android.view.ViewGroup.LayoutParams L_Title = Linear_Title.getLayoutParams();
    android.view.ViewGroup.LayoutParams L_Checkin = checkinBT.getLayoutParams();
    android.view.ViewGroup.LayoutParams L_scDesc = scDesc.getLayoutParams();

    L_headLayout.height = dx(15);
    L_imgWave.height = dx(10);
    L_BackBT.height = dx(10);
    L_typeButton.height = dx(10);
    L_typeButton.width = dx(24);
    L_Checkin.height = dx(20);
    // L_Checkin			.width  = dx(20);
    L_scDesc.height = dx(30);
    L_Title.height = dx(17);

    if (dx(20) > 100) {
      L_Checkin.height = 100;
    }

    BackBT.setPadding(dx(3), 0, 0, 0);
    typeButton.setPadding(0, 0, dx(3), 0);
    Linear_Title.setPadding(0, dx(2), 0, dx(2));

    headLayout.setLayoutParams(L_headLayout);
    imgWave.setLayoutParams(L_imgWave);
    BackBT.setLayoutParams(L_BackBT);
    typeButton.setLayoutParams(L_typeButton);
    scDesc.setLayoutParams(L_scDesc);

    // FONT
    //		txtTitle			.setTextSize(dx(4));
    //		txtDesc				.setTextSize(dx(3));

  }
コード例 #2
0
ファイル: QuickAction.java プロジェクト: notbryant/NitroDroid
  /** Show quickaction popup. Popup is automatically positioned, on top or bottom of anchor view. */
  public void show(View anchor) {
    preShow();

    int xPos, yPos, arrowPos;

    mDidAction = false;

    int[] location = new int[2];

    anchor.getLocationOnScreen(location);

    Rect anchorRect =
        new Rect(
            location[0],
            location[1],
            location[0] + anchor.getWidth(),
            location[1] + anchor.getHeight());

    // mRootView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
    // LayoutParams.WRAP_CONTENT));

    mRootView.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    int rootHeight = mRootView.getMeasuredHeight();

    if (rootWidth == 0) {
      rootWidth = mRootView.getMeasuredWidth();
    }

    int screenWidth = mWindowManager.getDefaultDisplay().getWidth();
    int screenHeight = mWindowManager.getDefaultDisplay().getHeight();

    // automatically get X coord of popup (top left)
    if ((anchorRect.left + rootWidth) > screenWidth) {
      xPos = anchorRect.left - (rootWidth - anchor.getWidth());
      xPos = (xPos < 0) ? 0 : xPos;

      arrowPos = anchorRect.centerX() - xPos;

    } else {
      if (anchor.getWidth() > rootWidth) {
        xPos = anchorRect.centerX() - (rootWidth / 2);
      } else {
        xPos = anchorRect.left;
      }

      arrowPos = anchorRect.centerX() - xPos;
    }

    int dyTop = anchorRect.top;
    int dyBottom = screenHeight - anchorRect.bottom;

    boolean onTop = (dyTop > dyBottom) ? true : false;

    if (onTop) {
      if (rootHeight > dyTop) {
        yPos = 15;
        LayoutParams l = mScroller.getLayoutParams();
        l.height = dyTop - anchor.getHeight();
      } else {
        yPos = anchorRect.top - rootHeight;
      }
    } else {
      yPos = anchorRect.bottom;

      if (rootHeight > dyBottom) {
        LayoutParams l = mScroller.getLayoutParams();
        l.height = dyBottom;
      }
    }

    // showArrow(((onTop) ? R.id.arrow_down : R.id.arrow_up), arrowPos);

    setAnimationStyle(screenWidth, anchorRect.centerX(), onTop);

    mWindow.showAtLocation(anchor, Gravity.NO_GRAVITY, xPos, yPos);
  }
コード例 #3
0
ファイル: Main.java プロジェクト: LovlyN1/crocodilenote
  @SuppressWarnings("deprecation")
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (isP(_P.secrecy) && !ENC) {
      setTitle("Initializing " + Main.name + "...");
      return;
    }

    Intent caller = getIntent();
    if (caller != null) {
      try {
        String tmp = caller.getStringExtra(_I.Main_setAbsoluteFolder.name());
        if (tmp == null) {
          finish();
          return;
        }
        setAbsoluteFolder(tmp);

        tmp = caller.getStringExtra(_I.Main_setFolderShowname.name());
        if (tmp == null) {
          finish();
          return;
        }
        setFolderShowname(tmp);
      } catch (Exception e) {
        e.printStackTrace();
        return;
      }
    }

    WatchImpl.enable = false;

    l1 = new RelativeLayout(this);

    int xi = 0;
    while (true) {
      if (!checkFiles(xi)) break;
      xi++;
    }
    if (xi > max) max = xi;

    thetexts = new Vector<InnerEdit>(max + 5);

    ScrollView sv = new ScrollView(this);
    l1.addView(sv);

    RelativeLayout.LayoutParams sv_lp = (RelativeLayout.LayoutParams) sv.getLayoutParams();
    sv_lp.width = RelativeLayout.LayoutParams.MATCH_PARENT;
    sv_lp.height = RelativeLayout.LayoutParams.WRAP_CONTENT;
    sv_lp.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    sv.setLayoutParams(sv_lp);

    l2 = new LinearLayout(this);
    l2.setOrientation(LinearLayout.VERTICAL);
    l2.setLayoutParams(
        new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    sv.addView(l2);

    ArrayList<String> vals = null;
    ArrayList<Integer> ids = null;
    int newone = -1;
    int focusone = -1;

    if (caller != null) {
      if (caller.getBooleanExtra("OKAY", false)) {
        vals = caller.getStringArrayListExtra("vals");
        ids = caller.getIntegerArrayListExtra("ids");
        newone = caller.getIntExtra("newone", -1);
        focusone = caller.getIntExtra("curfocus", -1);
      }
    }

    if (newone > 0) max = newone + 1;

    setTitle(title(max));

    for (int i = 0; i < max; i++) {
      EditText t2 = new EditText(this);
      t2.setId(i);
      t2.setOnFocusChangeListener(
          new OnFocusChangeListener() {

            @Override
            public void onFocusChange(View v, boolean hasFocus) {
              if (hasFocus) curfocus = (EditText) v;
            }
          });
      t2.setImeOptions(EditorInfo.IME_ACTION_DONE);
      t2.setOnEditorActionListener(one);
      InnerEdit in = new InnerEdit(t2);
      thetexts.add(in);
      t2.addTextChangedListener(new WatchImpl(in));
      l2.addView(t2, 0);
      if (ids != null && ids.contains(i)) {
        String tmp = vals.get(ids.indexOf(i));
        if (tmp != null) t2.setText(tmp);
        else t2.setText("err");
        in.changed = true;
      } else {
        if (checkFiles(i)) {
          String x = loadFiles(i);
          t2.setText(x);
        } else {
          t2.setText("");
        }
      }

      if (focusone >= 0) {
        if (i == focusone) t2.requestFocus();
      } else {
        if (i == max - 1) t2.requestFocus();
      }
    }

    WatchImpl.enable = true;

    Button b1 = new Button(this);
    b1.setText("  Save  ");

    b1.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            int ctr = 0;
            for (int i = 0; i < max; i++) {
              if (thetexts.get(i).changed || !checkFiles(i)) {
                storeFiles(i, thetexts.get(i).edit.getText().toString());
                ctr++;
                thetexts.get(i).changed = false;
              }
            }
            Toast.makeText(me, "Saved (" + ctr + ")", Toast.LENGTH_SHORT).show();
          }
        });

    Button b2 = new Button(this);
    b2.setText("  Add  ");

    b2.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            EditText t2 = new EditText(me);
            t2.setOnFocusChangeListener(
                new OnFocusChangeListener() {

                  @Override
                  public void onFocusChange(View v, boolean hasFocus) {
                    if (hasFocus) curfocus = (EditText) v;
                  }
                });
            t2.setImeOptions(EditorInfo.IME_ACTION_DONE);
            t2.setOnEditorActionListener(one);

            l2.addView(t2, 0);
            t2.setId(max);
            max++;
            InnerEdit in = new InnerEdit(t2, true);
            thetexts.add(in);
            t2.addTextChangedListener(new WatchImpl(in));
            setTitle(title(max));
            t2.requestFocus();
          }
        });

    Button b3 = new Button(this);
    b3.setText("Save & Exit");
    b3.setOnClickListener(
        new OnClickListener() {
          // TODO: reduce redundancy

          @Override
          public void onClick(View v) {
            int ctr = 0;
            for (int i = 0; i < max; i++) {
              if (thetexts.get(i).changed || !checkFiles(i)) {
                storeFiles(i, thetexts.get(i).edit.getText().toString());
                ctr++;
                thetexts.get(i).changed = false;
              }
            }
            if (ctr > 0) Toast.makeText(me, "Saved (" + ctr + ")", Toast.LENGTH_SHORT).show();
            else Toast.makeText(me, "Quick Exit", Toast.LENGTH_SHORT).show();

            finish();
          }
        });

    Button b4 = new Button(this);
    b4.setText("Return");

    b4.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            for (int i = 0; i < max; i++) {
              if (thetexts.get(i).changed || !checkFiles(i)) {
                Toast.makeText(me, "unsaved data", Toast.LENGTH_SHORT).show();
                return;
              }
            }

            startActivity(new Intent(me, Startup.class));
            finish();
          }
        });

    HorizontalScrollView hori = new HorizontalScrollView(this);
    LinearLayout ll_hori = new LinearLayout(this);
    ll_hori.setOrientation(LinearLayout.HORIZONTAL);

    ll_hori.addView(b1);
    ll_hori.addView(b3);
    ll_hori.addView(b2);
    ll_hori.addView(b4);

    hori.addView(ll_hori);
    l1.addView(hori);
    RelativeLayout.LayoutParams lp =
        new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    hori.setLayoutParams(lp);
    hori.setId(121232);

    sv_lp = (RelativeLayout.LayoutParams) sv.getLayoutParams();
    sv_lp.addRule(RelativeLayout.ABOVE, hori.getId());
    sv.setLayoutParams(sv_lp);

    BitmapDrawable bd =
        new BitmapDrawable(
            getResources(), BitmapFactory.decodeResource(getResources(), R.drawable.back_base));
    bd.setTileModeXY(TileMode.MIRROR, TileMode.REPEAT);
    l1.setBackgroundDrawable(bd);

    setContentView(l1);
  }
コード例 #4
0
  private void setSheetItems() {
    if (sheetItemList == null || sheetItemList.size() <= 0) {
      return;
    }

    int size = sheetItemList.size();
    if (size >= 7) {
      LayoutParams params = (LayoutParams) sLayout_content.getLayoutParams();
      params.height = display.getHeight() / 2;
      sLayout_content.setLayoutParams(params);
    }

    for (int i = 1; i <= size; i++) {
      final int index = i;
      SheetItem sheetItem = sheetItemList.get(i - 1);
      String strItem = sheetItem.name;
      SheetItemColor color = sheetItem.color;
      final OnSheetItemClickListener listener = sheetItem.itemClickListener;
      TextView textView = new TextView(context);
      textView.setText(strItem);
      textView.setTextSize(18);
      textView.setGravity(Gravity.CENTER);
      if (size == 1) {
        if (showTitle) {
          textView.setBackgroundResource(R.drawable.actionsheet_bottom_selector);
        } else {
          textView.setBackgroundResource(R.drawable.actionsheet_single_selector);
        }
      } else {
        if (showTitle) {
          if (i >= 1 && i < size) {
            textView.setBackgroundResource(R.drawable.actionsheet_middle_selector);
          } else {
            textView.setBackgroundResource(R.drawable.actionsheet_bottom_selector);
          }
        } else {
          if (i == 1) {
            textView.setBackgroundResource(R.drawable.actionsheet_top_selector);
          } else if (i < size) {
            textView.setBackgroundResource(R.drawable.actionsheet_middle_selector);
          } else {
            textView.setBackgroundResource(R.drawable.actionsheet_bottom_selector);
          }
        }
      }
      if (color == null) {
        textView.setTextColor(Color.parseColor(SheetItemColor.Blue.getName()));
      } else {
        textView.setTextColor(Color.parseColor(color.getName()));
      }
      float scale = context.getResources().getDisplayMetrics().density;
      int height = (int) (45 * scale + 0.5f);
      textView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, height));
      textView.setOnClickListener(
          new OnClickListener() {
            @Override
            public void onClick(View v) {
              listener.onClick(index);
              dialog.dismiss();
            }
          });
      lLayout_content.addView(textView);
    }
  }
コード例 #5
0
  /** Show popup window. Popup is automatically positioned, on top or bottom of anchor view. */
  public void show(View anchor) {

    preShow();

    int xPos, yPos;

    int[] location = new int[2];

    anchor.getLocationOnScreen(location);

    Rect anchorRect =
        new Rect(
            location[0],
            location[1],
            location[0] + anchor.getWidth(),
            location[1] + anchor.getHeight());

    // notice, see also:
    // http://stackoverflow.com/questions/8226676/java-lang-classcastexception-android-view-viewgrouplayoutparams-without-layout
    /*mRootView.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));*/
    mRootView.setLayoutParams(
        new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    mRootView.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    int rootHeight = mRootView.getMeasuredHeight();
    int rootWidth = mRootView.getMeasuredWidth();

    int screenWidth = mWindowManager.getDefaultDisplay().getWidth();
    int screenHeight = mWindowManager.getDefaultDisplay().getHeight();

    // automatically get X coord of popup (top left)

    if ((anchorRect.left + rootWidth) > screenWidth)
      xPos = anchorRect.left - (rootWidth - anchor.getWidth());
    else
      xPos =
          (anchor.getWidth() > rootWidth)
              ? anchorRect.centerX() - (rootWidth / 2)
              : anchorRect.left;

    int dyTop = anchorRect.top;
    int dyBottom = screenHeight - anchorRect.bottom;

    boolean onTop = (dyTop > dyBottom) ? true : false;

    if (onTop) {

      if (rootHeight > dyTop) {

        LayoutParams l = mScroller.getLayoutParams();
        l.height = dyTop - anchor.getHeight();

        mRootView.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        rootHeight = mRootView.getMeasuredHeight();
        rootWidth = mRootView.getMeasuredWidth();

        yPos = rootHeight > dyTop ? 15 : anchorRect.top - rootHeight;

      } else {
        mRootView.measure(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        yPos = anchorRect.top - rootHeight;
      }
    } else {
      yPos = anchorRect.bottom;

      if (rootHeight > dyBottom) {

        LayoutParams l = mScroller.getLayoutParams();
        l.height = dyBottom;
      }
    }

    showArrow(
        ((onTop) ? R.id.arrow_down : R.id.arrow_up),
        xPos > 0 ? anchorRect.centerX() - xPos : anchorRect.centerX());

    setAnimationStyle(screenWidth, anchorRect.centerX(), onTop);

    mWindow.showAtLocation(anchor, Gravity.NO_GRAVITY, xPos, yPos);
  }