예제 #1
0
  private boolean setMediaList(MediaList value) {

    // check instance
    if (m_MediaList == value) return false;

    // detach from previous media list
    if (m_MediaList != null) {
      m_MediaList.removeHandler(MediaList.EVENT_MEDIA_ADDED, m_MediaAddedHandler);
      m_MediaList.removeHandler(MediaList.EVENT_MEDIA_REMOVED, m_MediaRemovedHandler);
    }

    // attach to new media list
    m_MediaList = value;
    if (m_MediaList == null) Log.d(TAG, "m_MediaList value null");
    else {
      Log.d(TAG, "m_MediaList value");
      m_MediaList.addHandler(MediaList.EVENT_MEDIA_ADDED, m_MediaAddedHandler);
      m_MediaList.addHandler(MediaList.EVENT_MEDIA_REMOVED, m_MediaRemovedHandler);
    }

    // update UI
    if (m_GridViewItemAdapter != null) m_GridViewItemAdapter.notifyDataSetChanged();
    if (value != null && !value.isEmpty()) this.showGridView();
    else this.showNoMedia();

    // complete
    return true;
  }
  /**
   * 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;
    }
  }
  // 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
  // Create view.
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.d(TAG, "onCreateView");
    View view = inflater.inflate(R.layout.fragment_gridview, container, false);
    m_GridView = (GridView) view.findViewById(R.id.gridview);
    if (m_GridViewItemAdapter == null)
      m_GridViewItemAdapter = new GridViewItemAdapter(this.getActivity());
    m_GridView.setAdapter(m_GridViewItemAdapter);
    m_GridView.setOnItemClickListener(
        new OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Log.d(TAG, "gridview onItemClick event item position:" + position);
            Toast.makeText(GridViewFragment.this.getActivity(), "" + position, Toast.LENGTH_SHORT)
                .show();
            onItemClicked(position, view);
          }
        });

    m_NoMediaView = view.findViewById(R.id.no_photo);
    m_NoMediaView.setOnClickListener(
        new OnClickListener() {
          @Override
          public void onClick(View v) {
            Intent intent = new Intent("android.media.action.STILL_IMAGE_CAMERA");
            startActivity(intent);
          }
        });

    if (m_MediaList != null && !m_MediaList.isEmpty()) this.showGridView();
    else this.showNoMedia();

    return view;
  }
  // Save instance state.
  @Override
  protected final void onSaveInstanceState(Bundle outState) {
    // get instance state fragment
    InstanceStateFragment stateFragment =
        (InstanceStateFragment)
            this.getFragmentManager().findFragmentByTag(InstanceStateFragment.TAG);
    if (stateFragment == null) {
      stateFragment = new InstanceStateFragment();
      this.getFragmentManager()
          .beginTransaction()
          .add(stateFragment, InstanceStateFragment.TAG)
          .commit();
    }

    // save instance state
    Log.w(TAG, "onSaveInstanceState() - Keep Gallery instance : " + m_Gallery.getId());
    stateFragment.gallery = m_Gallery;
    stateFragment.activityResultHandles = m_ActivityResultHandles;
    this.onSaveInstanceState(outState, stateFragment.extras);

    // call super
    super.onSaveInstanceState(outState);

    // update state
    m_IsInstanceStateSaved = true;
  }
  // 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);
    }
  }
예제 #7
0
 public Object getItem(int position) {
   Log.d(TAG, "getItem position: " + position);
   if (m_MediaList != null) {
     if (get(PROP_IS_CAMERA_ROLL)) {
       if (position == 0) return null;
       return m_MediaList.get(position - 1);
     }
     return m_MediaList.get(position);
   }
   return null;
 }
예제 #8
0
  @Override
  public void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    Log.d(TAG, "onCreate");
    m_GridviewItemHeight = this.getResources().getDimensionPixelSize(R.dimen.gridview_item_height);
    m_GridviewItemWidth = this.getResources().getDimensionPixelSize(R.dimen.gridview_item_width);

    // Prepare greySquare
    m_GreySquare = new SquareDrawable(m_GridviewItemWidth, m_GridviewItemHeight);
  }
예제 #9
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));
  }
예제 #10
0
 @Override
 public void onDestroyView() {
   Log.d(TAG, "onDestroyView");
   // clear references
   if (m_GridView != null) {
     m_GridView.setAdapter(null);
     m_GridView = null;
   }
   m_NoMediaView = null;
   // call super
   super.onDestroyView();
 }
  // Check alive instances.
  private static void checkInstances(long delayMillis) {
    // check immediately
    Handler handler = GalleryApplication.current().getHandler();
    handler.removeCallbacks(m_CheckInstancesRunnable);
    if (delayMillis <= 0) {
      for (int i = m_TrackingInstances.size() - 1; i >= 0; --i) {
        Object instance = m_TrackingInstances.get(i).get();
        if (instance == null) m_TrackingInstances.remove(i);
      }
      Log.w(
          "GalleryActivity", "checkInstances() - Alive instances : " + m_TrackingInstances.size());
      return;
    }

    // check later
    handler.postDelayed(m_CheckInstancesRunnable, delayMillis);
  }
  // Called when destroying.
  @Override
  protected void onDestroy() {
    // detach from gallery
    m_Gallery.removeCallback(Gallery.PROP_IS_NAVIGATION_BAR_VISIBLE, m_NavBarVisibilityCallback);
    m_Gallery.removeCallback(Gallery.PROP_IS_STATUS_BAR_VISIBLE, m_StatusBarVisibilityCallback);
    m_GalleryAttachHandle = Handle.close(m_GalleryAttachHandle);

    // release gallery
    if (!m_IsInstanceStateSaved && !m_IsSharedGallery) {
      Log.w(TAG, "onDestroy() - Release Gallery");
      m_Gallery.release();
    }

    // release references
    m_ActivityResultHandles = null;

    // call super
    super.onDestroy();

    // check instances
    checkInstances(DURATION_CHECK_INSTANCES_DELAY);
  }
예제 #13
0
 @Override
 public void onResume() {
   // TODO Auto-generated method stub
   super.onResume();
   Log.d(TAG, "onResume");
 }
예제 #14
0
 private void onInitialize() {
   Log.d(TAG, "onInitialize");
 }
예제 #15
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;
    }
예제 #16
0
 public long getItemId(int position) {
   Log.d(TAG, "getItemId position: " + position);
   return position;
 }
예제 #17
0
 @Override
 public void onActivityCreated(Bundle savedInstanceState) {
   super.onActivityCreated(savedInstanceState);
   Log.d(TAG, "onActivityCreated");
 }
예제 #18
0
 @Override
 public void onAttach(Activity activity) {
   super.onAttach(activity);
   Log.d(TAG, "onAttach");
 }