예제 #1
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // 메모 리스트
    mMemoListView = (ListView) findViewById(R.id.memoList);
    mMemoListAdapter = new MemoListAdapter(this);
    mMemoListView.setAdapter(mMemoListAdapter);
    mMemoListView.setOnItemClickListener(
        new OnItemClickListener() {
          public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
            viewMemo(position);
          }
        });

    // 새 메모 버튼 설정
    TitleBitmapButton newMemoBtn = (TitleBitmapButton) findViewById(R.id.newMemoBtn);
    newMemoBtn.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            Log.d(TAG, "newMemoBtn clicked.");
          }
        });

    // 닫기 버튼 설정
    TitleBitmapButton closeBtn = (TitleBitmapButton) findViewById(R.id.closeBtn);
    closeBtn.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            finish();
          }
        });

    loadMemoListData();
  }
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.handwriting_dialog);

    this.setTitle("펜 굵기 선택");

    mGridView = (GridView) findViewById(R.id.colorGrid);
    mCloseBtn = (TitleBitmapButton) findViewById(R.id.closeBtn);

    mGridView.setColumnWidth(12);
    mGridView.setBackgroundColor(Color.GRAY);
    mGridView.setVerticalSpacing(4);
    mGridView.setHorizontalSpacing(4);

    mAdapter = new PenDataAdapter(this);
    mGridView.setAdapter(mAdapter);
    mGridView.setNumColumns(mAdapter.getNumColumns());

    mCloseBtn.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            finish();
          }
        });
  }
  public View getView(int position, View view, ViewGroup group) {
    Log.d("PenDataAdapter", "getView(" + position + ") called.");

    // calculate position
    int rowIndex = position / rowCount;
    int columnIndex = position % rowCount;
    Log.d("PenDataAdapter", "Index : " + rowIndex + ", " + columnIndex);

    GridView.LayoutParams params =
        new GridView.LayoutParams(
            GridView.LayoutParams.FILL_PARENT, GridView.LayoutParams.FILL_PARENT);

    // create a Pen Image
    int areaWidth = 10;
    int areaHeight = 20;

    Bitmap penBitmap = Bitmap.createBitmap(areaWidth, areaHeight, Bitmap.Config.ARGB_8888);
    Canvas penCanvas = new Canvas();
    penCanvas.setBitmap(penBitmap);

    Paint mPaint = new Paint();
    mPaint.setColor(Color.WHITE);
    penCanvas.drawRect(0, 0, areaWidth, areaHeight, mPaint);

    mPaint.setColor(Color.BLACK);
    mPaint.setStrokeWidth((float) pens[position]);
    penCanvas.drawLine(0, areaHeight / 2, areaWidth - 1, areaHeight / 2, mPaint);
    BitmapDrawable penDrawable = new BitmapDrawable(mContext.getResources(), penBitmap);

    // create a Button with the color
    TitleBitmapButton aItem = new TitleBitmapButton(mContext);
    aItem.setText(" ");
    aItem.setLayoutParams(params);
    aItem.setPadding(4, 4, 4, 4);
    aItem.setBackgroundDrawable(penDrawable);
    aItem.setHeight(48);
    aItem.setTag(pens[position]);

    // set listener
    aItem.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            if (PenPaletteDialog.mSelectedListener != null) {
              PenPaletteDialog.mSelectedListener.onPenSelected(((Integer) v.getTag()).intValue());
            }

            ((PenPaletteDialog) mContext).finish();
          }
        });

    return aItem;
  }