コード例 #1
0
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View rootView = inflater.inflate(R.layout.recorder_fragment, container, false);
    mShutter = (CheckedTextView) rootView.findViewById(R.id.shutter);
    mShutter.setOnClickListener(this);

    rootView.findViewById(R.id.bitrate_menu).setOnClickListener(this);
    rootView.findViewById(R.id.resolution_menu).setOnClickListener(this);
    rootView.findViewById(R.id.rotate_menu).setOnClickListener(this);

    mChosenBitrate = (TextView) rootView.findViewById(R.id.bitrate_value);
    mChosenResolution = (TextView) rootView.findViewById(R.id.resolution_value);
    mChosenRotate = (TextView) rootView.findViewById(R.id.rotate_value);

    mSubMenuContrainer = (LinearLayout) rootView.findViewById(R.id.sub_menu_contrainer);
    mSubMenuItems = new ArrayList<CheckedTextView>();
    for (int index = 0; index < RESERVED_SUB_MENU_ITEM_COUNT; ++index) {
      CheckedTextView ctv =
          (CheckedTextView) inflater.inflate(R.layout.sub_menu_items, mSubMenuContrainer, false);
      ctv.setId(index);
      ctv.setOnClickListener(this);
      mSubMenuItems.add(ctv);
    }

    mClipsAdapter =
        new ClipsAdapter(
            getActivity().getApplicationContext(), StorageHelper.sStorageHelper.getVideoClips());
    mClips = (GridViewWithHeaderAndFooter) rootView.findViewById(R.id.clips);
    mClips.setOnItemClickListener(
        new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            LogUtil.i(MODULE_TAG, "position:" + position);
            Cursor cursor = mClipsAdapter.getCursor();
            LogUtil.i(MODULE_TAG, "cursor:" + cursor);
            if (cursor != null) {
              cursor.moveToFirst();
              if (cursor.move(position)) {
                int columnIndex = cursor.getColumnIndex(MediaStore.Video.Media._ID);
                long mediaId = cursor.getLong(columnIndex);
                Uri uri =
                    Uri.withAppendedPath(
                        MediaStore.Video.Media.EXTERNAL_CONTENT_URI, Long.toString(mediaId));
                Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                intent.setDataAndType(uri, "video/mp4");
                startActivity(intent);
              }
            }
          }
        });

    Resources res = getActivity().getResources();
    View header = new View(getActivity());
    header.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0));

    int placeHolderHeight =
        2 * res.getDimensionPixelSize(R.dimen.shutter_vertical_padding)
            + res.getDimensionPixelSize(R.dimen.shutter_size)
            + res.getDimensionPixelSize(R.dimen.setting_menu_height);
    View footer = new View(getActivity());
    footer.setLayoutParams(
        new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, placeHolderHeight));

    mClips.addHeaderView(header);
    mClips.addFooterView(footer);
    mClips.setAdapter(mClipsAdapter);

    return rootView;
  }