コード例 #1
0
  /**
   * Start activity for result.
   *
   * @param intent Intent to start activity.
   * @param callback Result call-back.
   * @return Handle to this operation.
   */
  public Handle startActivityForResult(Intent intent, ActivityResultCallback callback) {
    // check parameter
    if (intent == null) {
      Log.e(TAG, "startActivityForResult() - No intent");
      return null;
    }

    // check state
    this.verifyAccess();

    // generate request code
    int requestCode = 64;
    for (; requestCode > 0; --requestCode) {
      if (m_ActivityResultHandles.get(requestCode) == null) break;
    }
    if (requestCode <= 0) {
      Log.e(TAG, "startActivityForResult() - No available request code");
      return null;
    }

    // create handle
    ActivityResultHandle handle = new ActivityResultHandle(callback);
    m_ActivityResultHandles.put(requestCode, handle);

    // start activity for result
    try {
      this.startActivityForResult(intent, requestCode);
      return handle;
    } catch (Throwable ex) {
      Log.e(TAG, "startActivityForResult() - Fail to start activity", ex);
      m_ActivityResultHandles.delete(requestCode);
      return null;
    }
  }
コード例 #2
0
  private void onItemClicked(int index, View view) {
    // check state
    if (m_MediaList == null) return;
    if (index < 0 || index >= m_MediaList.size()) {
      Log.e(TAG, "onItemClicked() - Invalid index : " + index);
      return;
    }

    // raise event
    Media media = m_MediaList.get(index);
    this.raise(EVENT_MEDIA_CLICKED, new ListItemEventArgs<Media>(index, media));
  }
コード例 #3
0
  // Called when creating.
  @Override
  protected final void onCreate(Bundle savedInstanceState) {
    // start tracking
    trackInstance(this);

    // call super
    super.onCreate(savedInstanceState);

    // setup instance state
    Intent intent = this.getIntent();
    String sharedGalleryId =
        (intent != null ? intent.getStringExtra(EXTRA_SHARED_GALLERY_ID) : null);
    InstanceStateFragment stateFragment =
        (InstanceStateFragment)
            this.getFragmentManager().findFragmentByTag(InstanceStateFragment.TAG);
    m_Gallery = Gallery.fromId(sharedGalleryId);
    if (m_Gallery == null) {
      if (stateFragment != null) {
        Log.w(TAG, "onCreate() - Use existent Gallery : " + stateFragment.gallery.getId());
        m_Gallery = stateFragment.gallery;
        m_ActivityResultHandles = stateFragment.activityResultHandles;
      } else {
        Log.w(TAG, "onCreate() - Create new Gallery");
        m_Gallery = GalleryApplication.current().createGallery();
        m_ActivityResultHandles = new SparseArray<>();
      }
    } else {
      Log.w(TAG, "onCreate() - Use shared Gallery : " + m_Gallery.getId());
      m_ActivityResultHandles = new SparseArray<>();
      m_IsSharedGallery = true;
    }

    // attach to gallery
    m_GalleryAttachHandle = m_Gallery.attachActivity(this);
    if (!Handle.isValid(m_GalleryAttachHandle)) {
      Log.e(TAG, "onCreate() - Fail to attach to Gallery");
      this.finish();
      return;
    }
    m_Gallery.addCallback(Gallery.PROP_IS_NAVIGATION_BAR_VISIBLE, m_NavBarVisibilityCallback);
    m_Gallery.addCallback(Gallery.PROP_IS_STATUS_BAR_VISIBLE, m_StatusBarVisibilityCallback);

    // initialize screen size
    this.updateScreenSize();

    // create
    this.onCreate(savedInstanceState, stateFragment != null ? stateFragment.extras : null);
  }
コード例 #4
0
  // Set system UI visibility
  protected void setSystemUiVisibility(boolean visible) {
    // check state
    Gallery gallery = this.getGallery();
    if (gallery == null) {
      Log.e(TAG, "setSystemUiVisibility() - No gallery");
      return;
    }

    Log.v(TAG, "setSystemUiVisibility() - Visible: ", visible);

    // set visibility
    if (visible) {
      gallery.setNavigationBarVisibility(true);
      gallery.setStatusBarVisibility(true);
    } else {
      gallery.setNavigationBarVisibility(false);
      gallery.setStatusBarVisibility(false);
    }
  }
コード例 #5
0
    // create a new ImageView for each item referenced by the Adapter
    public View getView(int position, View convertView, ViewGroup parent) {
      final GridViewItemHolder holder;
      if (convertView == null) {
        // Log.d(TAG, "convertView == null getView position:" + position);
        // holder initialize
        convertView = m_inflater.inflate(R.layout.fragment_gridview_item, parent, false);
        holder = new GridViewItemHolder(convertView);
      } else {
        // recycled view
        holder = (GridViewItemHolder) convertView.getTag();
        ((ViewGroup) holder.typeIconView.getParent()).setVisibility(View.GONE);
      }
      holder.thumbnailImageView.setImageDrawable(m_GreySquare);
      holder.position = position;
      holder.thumbDecoded = false;

      boolean isCameraRoll = get(PROP_IS_CAMERA_ROLL);
      if (m_MediaList != null) {
        if (holder.position == 0 && isCameraRoll) {
          // Set item thumbnail
          holder.thumbnailImageView.setImageResource(R.drawable.camera);
          holder.contentUri = null;
          holder.smallThumbDecodeHandle = null;
          holder.thumbDecodeHandle = null;
        } else {
          Log.e(TAG, "holder.m_ItemPosition: " + holder.position);
          // -1 for the first one for CameraIcon to start camera activity
          Media media = m_MediaList.get(isCameraRoll ? position - 1 : position);
          String filePath = media.getFilePath();
          holder.contentUri = media.getContentUri();
          holder.mimeType = media.getMimeType();
          if (filePath != null) {
            holder.smallThumbDecodeHandle =
                m_SmallBitmapPool.decode(
                    media.getFilePath(),
                    m_GridviewItemWidth,
                    m_GridviewItemHeight,
                    BitmapPool.FLAG_ASYNC | BitmapPool.FLAG_URGENT,
                    holder.smallThumbDecodeCallback,
                    GridViewFragment.this.getHandler());
            holder.thumbDecodeHandle =
                m_BitmapPool.decode(
                    media.getFilePath(),
                    m_GridviewItemWidth,
                    m_GridviewItemHeight,
                    BitmapPool.FLAG_ASYNC | BitmapPool.FLAG_URGENT,
                    holder.thumbDecodeCallback,
                    GridViewFragment.this.getHandler());
          } else {
            int mediaType =
                (media instanceof VideoMedia
                    ? BitmapPool.MEDIA_TYPE_VIDEO
                    : BitmapPool.MEDIA_TYPE_PHOTO);
            holder.smallThumbDecodeHandle =
                m_SmallBitmapPool.decode(
                    getActivity(),
                    holder.contentUri,
                    mediaType,
                    m_GridviewItemWidth,
                    m_GridviewItemHeight,
                    BitmapPool.FLAG_ASYNC | BitmapPool.FLAG_URGENT,
                    holder.smallThumbDecodeCallback,
                    GridViewFragment.this.getHandler());
            holder.thumbDecodeHandle =
                m_BitmapPool.decode(
                    getActivity(),
                    holder.contentUri,
                    mediaType,
                    m_GridviewItemWidth,
                    m_GridviewItemHeight,
                    BitmapPool.FLAG_ASYNC | BitmapPool.FLAG_URGENT,
                    holder.thumbDecodeCallback,
                    GridViewFragment.this.getHandler());
          }
          if (media instanceof VideoMedia) {
            ((ViewGroup) holder.typeIconView.getParent()).setVisibility(View.VISIBLE);
            holder.typeIconView.setImageResource(R.drawable.about);
            holder.durationTextView.setText(getVideoTime((VideoMedia) media));
          }
        }
      }
      return convertView;
    }