Exemplo n.º 1
0
  @Override
  public Object instantiateItem(ViewGroup container, int position) {
    if (mCurTransaction == null) {
      mCurTransaction = mFragmentManager.beginTransaction();
    }

    final long itemId = getItemId(position);

    // Do we already have this fragment?
    String name = makeFragmentName(container.getId(), itemId);
    Fragment fragment = mFragmentManager.findFragmentByTag(name);
    if (fragment != null) {
      if (DEBUG) Log.v(TAG, "Attaching item #" + itemId + ": f=" + fragment);
      mCurTransaction.attach(fragment);
    } else {
      fragment = getItem(position);
      if (DEBUG) Log.v(TAG, "Adding item #" + itemId + ": f=" + fragment);
      mCurTransaction.add(container.getId(), fragment, makeFragmentName(container.getId(), itemId));
    }
    if (fragment != mCurrentPrimaryItem) {
      // FragmentCompat.setMenuVisibility(fragment, false);
      // FragmentCompat.setUserVisibleHint(fragment, false);
      setMenuVisibility(fragment, false);
      setUserVisibleHint(fragment, false);
    }

    return fragment;
  }
 public static ViewOverlayPreJellybean getOverlay(ViewGroup sceneRoot) {
   if (sceneRoot != null) {
     ViewGroup group = sceneRoot;
     while (group.getId() != android.R.id.content
         && group.getParent() != null
         && group.getParent() instanceof ViewGroup) {
       group = (ViewGroup) group.getParent();
     }
     for (int i = 0; i < group.getChildCount(); i++) {
       View child = group.getChildAt(i);
       if (child instanceof ViewOverlayPreJellybean) {
         return (ViewOverlayPreJellybean) child;
       }
     }
     final FrameLayout.LayoutParams params =
         new FrameLayout.LayoutParams(
             ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
     params.gravity = Gravity.FILL;
     ViewOverlayPreJellybean viewOverlay = new ViewOverlayPreJellybean(sceneRoot.getContext());
     group.addView(viewOverlay, params);
     return viewOverlay;
   } else {
     return null;
   }
 }
 public Object instantiateItem(ViewGroup paramViewGroup, int paramInt) {
   if (mFragments.size() > paramInt) {
     localFragment = (Fragment) mFragments.get(paramInt);
     if (localFragment != null) {
       return localFragment;
     }
   }
   if (mCurTransaction == null) {
     mCurTransaction = mFragmentManager.beginTransaction();
   }
   Fragment localFragment = getItem(paramInt);
   if (mSavedState.size() > paramInt) {
     Fragment.SavedState localSavedState = (Fragment.SavedState) mSavedState.get(paramInt);
     if (localSavedState != null) {
       localFragment.setInitialSavedState(localSavedState);
     }
   }
   while (mFragments.size() <= paramInt) {
     mFragments.add(null);
   }
   localFragment.setMenuVisibility(false);
   localFragment.setUserVisibleHint(false);
   mFragments.set(paramInt, localFragment);
   mCurTransaction.add(paramViewGroup.getId(), localFragment);
   return localFragment;
 }
Exemplo n.º 4
0
 public Object instantiateItem(ViewGroup viewgroup, int i) {
   if (e == null) {
     e = f.beginTransaction();
   }
   Object obj = ((c) b.get(i)).d;
   obj = f.findFragmentByTag(((String) (obj)));
   if (obj != null) {
     e.attach(((Fragment) (obj)));
   } else {
     Fragment fragment = f.findFragmentByTag(((c) b.get(i)).d);
     obj = fragment;
     if (fragment == null) {
       c c1 = (c) b.get(i);
       obj = Fragment.instantiate(c, c1.a.getName(), c1.b);
       c1.d = (new StringBuilder("PagerFragment.")).append(i).toString();
     }
     e.add(
         viewgroup.getId(),
         ((Fragment) (obj)),
         (new StringBuilder("PagerFragment.")).append(i).toString());
   }
   if (obj != d) {
     ((Fragment) (obj)).setMenuVisibility(false);
     ((Fragment) (obj)).setUserVisibleHint(false);
   }
   return obj;
 }
Exemplo n.º 5
0
 public View layoutHeaderOrFooterView(TiViewProxy viewProxy) {
   TiUIView tiView = viewProxy.peekView();
   if (tiView != null) {
     TiViewProxy parentProxy = viewProxy.getParent();
     // Remove parent view if possible
     if (parentProxy != null) {
       TiUIView parentView = parentProxy.peekView();
       if (parentView != null) {
         parentView.remove(tiView);
       }
     }
   } else {
     tiView = viewProxy.forceCreateView();
   }
   View outerView = tiView.getOuterView();
   ViewGroup parentView = (ViewGroup) outerView.getParent();
   if (parentView != null && parentView.getId() == HEADER_FOOTER_WRAP_ID) {
     return parentView;
   } else {
     // add a wrapper so layout params such as height, width takes in effect.
     TiCompositeLayout wrapper =
         new TiCompositeLayout(viewProxy.getActivity(), LayoutArrangement.DEFAULT, null);
     AbsListView.LayoutParams params =
         new AbsListView.LayoutParams(
             AbsListView.LayoutParams.MATCH_PARENT, AbsListView.LayoutParams.WRAP_CONTENT);
     wrapper.setLayoutParams(params);
     outerView = tiView.getOuterView();
     wrapper.addView(outerView, tiView.getLayoutParams());
     wrapper.setId(HEADER_FOOTER_WRAP_ID);
     return wrapper;
   }
 }
 @Override
 public Object instantiateItem(ViewGroup container, int position) {
   Fragment fragment;
   // If we already have this item instantiated, there is nothing
   // to do.  This can happen when we are restoring the entire pager
   // from its saved state, where the fragment manager has already
   // taken care of restoring the fragments we previously had instantiated.
   fragment = mFragments.get(position);
   if (fragment != null) {
     return fragment;
   }
   if (mCurTransaction == null) {
     mCurTransaction = mFragmentManager.beginTransaction();
   }
   FragmentState fs = mFragmentStates.get(position);
   if (fs != null) {
     FragmentManager fragmentManager = getFragmentActivity().getSupportFragmentManager();
     if (getParentFragment() != null) {
       fragmentManager = getParentFragment().getChildFragmentManager();
     }
     // Fix Can't change tag of fragment Error
     // http://stackoverflow.com/questions/24355838/cant-change-tag-of-fragment-error-trying-to-use-a-pageradapter-for-switching
     if ((fs.mTag != null && fs.mTag.equals(mFragmentTags.get(position)))
         || (fs.mTag == null && mFragmentTags.get(position) == null)) {
       fragment =
           fs.instantiate(
               FragmentUtils.getFragmentHostCallback(fragmentManager),
               getParentFragment(),
               FragmentUtils.getFragmentManagerNonConfig(fragmentManager));
       // Fix bug
       // http://stackoverflow.com/questions/11381470/classnotfoundexception-when-unmarshalling-android-support-v4-view-viewpagersav
       if (fragment.mSavedFragmentState != null) {
         fragment.mSavedFragmentState.setClassLoader(fragment.getClass().getClassLoader());
       }
     } else {
       Log.e(
           TAG,
           String.format(
               "Fragment tag isn't equal! Origin: %s %s", fs.mTag, mFragmentTags.get(position)));
       mFragmentStates.set(position, null);
     }
   }
   if (fragment == null) {
     fragment =
         Fragment.instantiate(
             getFragmentActivity(),
             mFragmentClassNames.get(position),
             mFragmentArgs.get(position));
   }
   if (DEBUG) {
     Log.v(TAG, "Adding item #" + position + ": f=" + fragment);
   }
   fragment.setMenuVisibility(false);
   fragment.setUserVisibleHint(false);
   mFragments.set(position, fragment);
   mFragmentStates.set(position, null);
   mCurTransaction.add(container.getId(), fragment, mFragmentTags.get(position));
   return fragment;
 }
Exemplo n.º 7
0
  public View getUpperViewIn(View view, String listId) {
    ViewGroup p = (ViewGroup) view.getParent();
    ViewGroup t = null;
    while (p != null) {
      LogEx.i(p.toString());
      t = (ViewGroup) p.getParent();
      if (t != null && t.getId() == this.getId(listId)) return p;
      p = t;
    }

    return null;
  }
    @Override
    public Object instantiateItem(final ViewGroup container, final int position) {
      if (currentTransaction == null) currentTransaction = fragmentManager.beginTransaction();

      final String tag = (position == 0) ? TAG_LEFT : TAG_RIGHT;
      final Fragment fragment = (position == 0) ? left : right;
      currentTransaction.add(container.getId(), fragment, tag);

      if (fragment != currentPrimaryItem) {
        fragment.setMenuVisibility(false);
        fragment.setUserVisibleHint(false);
      }

      return fragment;
    }
  @Nullable
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.reminderlist_wearable_list_layout, container, false);
    Log.d("TAG", "ReminderList:::" + MobileApplication.getInstance().getReminderList());

    if (!TextUtils.isEmpty(MobileApplication.getInstance().getReminderList())) {
      remindersDTOList =
          JSONParser.getInstance()
              .getRemindersList(MobileApplication.getInstance().getReminderList());
    } else {
      // Dummy Data
      populateWorkList();
    }

    // This is our list header

    //        listHeader = (RelativeLayout)view.findViewById(R.id.reminder_header);

    WearableListView wearableListView = (WearableListView) view.findViewById(R.id.reminder_List);
    mContainerId = container.getId();
    Toolbar mToolBar = (Toolbar) getActivity().findViewById(R.id.toolbar);
    TextView toolbarTitle = (TextView) mToolBar.findViewById(R.id.title);
    toolbarTitle.setText("Reminders");
    ImageView back_img = (ImageView) mToolBar.findViewById(R.id.back);
    back_img.setVisibility(View.VISIBLE);
    back_img.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            FragmentManager fragmentManager = getFragmentManager();
            FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
            fragmentTransaction
                .replace(mContainerId, new DashBoardWearableListFragment())
                .addToBackStack(null)
                .commit();
          }
        });
    wearableListView.setAdapter(new ReminderListAdapter(getActivity(), remindersDTOList));
    WearableListView.ItemDecoration itemDecoration =
        new DividerItemDecoration(getActivity(), DividerItemDecoration.VERTICAL_LIST);
    wearableListView.addItemDecoration(itemDecoration);
    wearableListView.setClickListener(mClickListener);
    wearableListView.addOnScrollListener(mOnScrollListener);

    return view;
  }
  @Override
  public View onCreateView(
      LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    View view = inflater.inflate(R.layout.wearable_inset_list, container, false);

    mContainerId = container.getId();
    listView = (WearableListView) view.findViewById(R.id.wearable_list);
    listView.setGreedyTouchMode(true);

    Toolbar mToolBar = (Toolbar) getActivity().findViewById(R.id.toolbar);
    toolBarTitle = (TextView) mToolBar.findViewById(R.id.title);
    checkOut = (TextView) mToolBar.findViewById(R.id.checkout);

    return view;
  }
  @Override
  public Object instantiateItem(ViewGroup container, int position) {

    createIdCache();

    // If we already have this item instantiated, there is nothing
    // to do.  This can happen when we are restoring the entire pager
    // from its saved state, where the fragment manager has already
    // taken care of restoring the fragments we previously had instantiated.
    if (mFragments.size() > position) {
      Fragment f = mFragments.get(position);
      if (f != null) {
        return f;
      }
    }

    if (mCurTransaction == null) {
      mCurTransaction = mFragmentManager.beginTransaction();
    }

    Fragment fragment = getItem(position);
    if (DEBUG) Log.v(TAG, "Adding item #" + position + ": f=" + fragment);
    if (mSavedState.size() > position) {
      Fragment.SavedState fss = mSavedState.get(position);
      if (fss != null) {
        fragment.setInitialSavedState(fss);
      }
    }
    while (mFragments.size() <= position) {
      mFragments.add(null);
    }
    fragment.setMenuVisibility(false);
    fragment.setUserVisibleHint(false);
    mFragments.set(position, fragment);
    mCurTransaction.add(container.getId(), fragment);

    return fragment;
  }
  @SuppressWarnings("unchecked")
  @Override
  protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    printLog(
        Consts.TAG,
        "onCreate: savedInstanceState " + (savedInstanceState == null ? "==" : "!=") + " null");

    // This has to be called before setContentView and you must use the
    // class in android.support.v4.view and NOT android.view

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    setContentView(R.layout.activity_main);

    /*
     * if(Consts.DEVELOPER_MODE) Debug.startMethodTracing();
     */
    fm = getSupportFragmentManager();

    if (Consts.DEVELOPER_MODE) FragmentManager.enableDebugLogging(true);

    /* CREATE OUR DISK CACHE TO STORE IMAGES */
    if (Utils.isExternalStorageAvailable())
      imageDiskCache =
          new DiskLruImageCache(
              this,
              "diskcache",
              Consts.DISK_CACHE_SIZE,
              CompressFormat.PNG,
              Consts.COMPRESS_QUALITY);

    // Restore state

    if (savedInstanceState != null) {
      // The fragment manager will handle restoring them if we are being
      // restored from a saved state
      /* restore our call backs after config change */
      isFromSavedState = true;
      /* restore our call backs after config change */
      mFragmentListCallback =
          (TweeterListFragment) fm.findFragmentByTag(TweeterListFragment.class.getName());

      /* on orientation change restore the data */
      tweeters =
          (ArrayList<ArrayList<HashMap<String, String>>>)
              savedInstanceState.getSerializable(Consts.SAVED_INSTANCE_TWEETERS);
      restoredIndex = savedInstanceState.getInt(Consts.SAVED_INSTANCE_POSITION);

      isEditing = savedInstanceState.getBoolean(Consts.SAVED_INSTANCE_EDIT_MODE);

    }
    // If this is the first creation of the activity, add fragments to it
    else {

      /*
       * If our layout has a container for the modifytweeters fragment,
       * create and add it. btw if this exist, we know we are in two pane
       * mode
       */
      mModiftyTweetersLayout = (ViewGroup) findViewById(R.id.activity_modifytweeters_container);
      if (mModiftyTweetersLayout != null) {
        printLog(Consts.TAG, "onCreate: adding modifytweeters Fragment to MainActivity");

        // Add modify tweeters fragment to the activity's container layout
        ModifyTweetersFragment modifyTweetersFragment = new ModifyTweetersFragment();
        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(
            mModiftyTweetersLayout.getId(),
            modifyTweetersFragment,
            ModifyTweetersFragment.class.getName());

        // Commit the transaction
        fragmentTransaction.commit();
      }

      // If our layout has a container for the tweetslist fragment, create
      // it and add it
      mTweetslistLayout = (ViewGroup) findViewById(R.id.activity_tweetslist_container);
      if (mTweetslistLayout != null) {
        printLog(Consts.TAG, "onCreate: adding tweetslist Fragment to MainActivity");

        // Add tweeter list fragment to the activity's container layout
        TweeterListFragment tweeterListFragment = new TweeterListFragment();
        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
        fragmentTransaction.replace(
            mTweetslistLayout.getId(), tweeterListFragment, TweeterListFragment.class.getName());

        mFragmentListCallback = (TweeterListObserver) tweeterListFragment;

        // Commit the transaction
        fragmentTransaction.commit();
      }
    }
  }
 @Override
 protected void onDestroy() {
   super.onDestroy();
   ViewGroup root = (ViewGroup) getWindow().getDecorView().findViewById(android.R.id.content);
   cleanupView(findViewById(root.getId()));
 }
  private static String constructManageChildrenErrorMessage(
      ViewGroup viewToManage,
      ViewGroupManager viewManager,
      @Nullable int[] indicesToRemove,
      @Nullable ViewAtIndex[] viewsToAdd,
      @Nullable int[] tagsToDelete) {
    StringBuilder stringBuilder = new StringBuilder();

    stringBuilder.append("View tag:" + viewToManage.getId() + "\n");
    stringBuilder.append("  children(" + viewManager.getChildCount(viewToManage) + "): [\n");
    for (int index = 0; index < viewManager.getChildCount(viewToManage); index += 16) {
      for (int innerOffset = 0;
          ((index + innerOffset) < viewManager.getChildCount(viewToManage)) && innerOffset < 16;
          innerOffset++) {
        stringBuilder.append(
            viewManager.getChildAt(viewToManage, index + innerOffset).getId() + ",");
      }
      stringBuilder.append("\n");
    }
    stringBuilder.append(" ],\n");
    if (indicesToRemove != null) {
      stringBuilder.append("  indicesToRemove(" + indicesToRemove.length + "): [\n");
      for (int index = 0; index < indicesToRemove.length; index += 16) {
        for (int innerOffset = 0;
            ((index + innerOffset) < indicesToRemove.length) && innerOffset < 16;
            innerOffset++) {
          stringBuilder.append(indicesToRemove[index + innerOffset] + ",");
        }
        stringBuilder.append("\n");
      }
      stringBuilder.append(" ],\n");
    }
    if (viewsToAdd != null) {
      stringBuilder.append("  viewsToAdd(" + viewsToAdd.length + "): [\n");
      for (int index = 0; index < viewsToAdd.length; index += 16) {
        for (int innerOffset = 0;
            ((index + innerOffset) < viewsToAdd.length) && innerOffset < 16;
            innerOffset++) {
          stringBuilder.append(
              "["
                  + viewsToAdd[index + innerOffset].mIndex
                  + ","
                  + viewsToAdd[index + innerOffset].mTag
                  + "],");
        }
        stringBuilder.append("\n");
      }
      stringBuilder.append(" ],\n");
    }
    if (tagsToDelete != null) {
      stringBuilder.append("  tagsToDelete(" + tagsToDelete.length + "): [\n");
      for (int index = 0; index < tagsToDelete.length; index += 16) {
        for (int innerOffset = 0;
            ((index + innerOffset) < tagsToDelete.length) && innerOffset < 16;
            innerOffset++) {
          stringBuilder.append(tagsToDelete[index + innerOffset] + ",");
        }
        stringBuilder.append("\n");
      }
      stringBuilder.append(" ]\n");
    }

    return stringBuilder.toString();
  }