Example usage for android.view View getParent

List of usage examples for android.view View getParent

Introduction

In this page you can find the example usage for android.view View getParent.

Prototype

public final ViewParent getParent() 

Source Link

Document

Gets the parent of this view.

Usage

From source file:biz.bokhorst.xprivacy.ActivityMain.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    final int userId = Util.getUserId(Process.myUid());

    // Check privacy service client
    if (!PrivacyService.checkClient())
        return;// ww w  .  j  a  va 2  s.  com

    // Import license file
    if (Intent.ACTION_VIEW.equals(getIntent().getAction()))
        if (Util.importProLicense(new File(getIntent().getData().getPath())) != null)
            Toast.makeText(this, getString(R.string.menu_pro), Toast.LENGTH_LONG).show();

    // Set layout
    setContentView(R.layout.mainlist);
    setSupportActionBar((Toolbar) findViewById(R.id.widgetToolbar));
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    // Set sub title
    if (Util.hasProLicense(this) != null)
        getSupportActionBar().setSubtitle(R.string.menu_pro);

    // Annotate
    Meta.annotate(this.getResources());

    // Get localized restriction name
    List<String> listRestrictionName = new ArrayList<String>(
            PrivacyManager.getRestrictions(this).navigableKeySet());
    listRestrictionName.add(0, getString(R.string.menu_all));

    // Build spinner adapter
    SpinnerAdapter spAdapter = new SpinnerAdapter(this, android.R.layout.simple_spinner_item);
    spAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spAdapter.addAll(listRestrictionName);

    // Handle info
    ImageView imgInfo = (ImageView) findViewById(R.id.imgInfo);
    imgInfo.setOnClickListener(new View.OnClickListener() {
        @SuppressLint("SetJavaScriptEnabled")
        @Override
        public void onClick(View view) {
            int position = spRestriction.getSelectedItemPosition();
            if (position != AdapterView.INVALID_POSITION) {
                String query = (position == 0 ? "restrictions"
                        : (String) PrivacyManager.getRestrictions(ActivityMain.this).values().toArray()[position
                                - 1]);

                WebView webview = new WebView(ActivityMain.this);
                webview.getSettings().setUserAgentString("Mozilla/5.0");
                // needed for hashtag
                webview.getSettings().setJavaScriptEnabled(true);
                webview.loadUrl("https://github.com/M66B/XPrivacy#" + query);

                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityMain.this);
                alertDialogBuilder.setTitle((String) spRestriction.getSelectedItem());
                alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
                alertDialogBuilder.setView(webview);
                alertDialogBuilder.setCancelable(true);
                AlertDialog alertDialog = alertDialogBuilder.create();
                alertDialog.show();
            }
        }
    });

    // Setup category spinner
    spRestriction = (Spinner) findViewById(R.id.spRestriction);
    spRestriction.setAdapter(spAdapter);
    spRestriction.setOnItemSelectedListener(this);
    int pos = getSelectedCategory(userId);
    spRestriction.setSelection(pos);

    // Setup sort
    mSortMode = Integer.parseInt(PrivacyManager.getSetting(userId, PrivacyManager.cSettingSortMode, "0"));
    mSortInvert = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingSortInverted, false);

    // Start task to get app list
    AppListTask appListTask = new AppListTask();
    appListTask.executeOnExecutor(mExecutor, (Object) null);

    // Check environment
    Requirements.check(this);

    // Licensing
    checkLicense();

    // Listen for package add/remove
    IntentFilter iff = new IntentFilter();
    iff.addAction(Intent.ACTION_PACKAGE_ADDED);
    iff.addAction(Intent.ACTION_PACKAGE_REMOVED);
    iff.addDataScheme("package");
    registerReceiver(mPackageChangeReceiver, iff);
    mPackageChangeReceiverRegistered = true;

    boolean showChangelog = true;

    // First run
    if (PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFirstRun, true)) {
        showChangelog = false;
        optionAbout();
    }

    // Tutorial
    if (!PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingTutorialMain, false)) {
        showChangelog = false;
        ((ScrollView) findViewById(R.id.svTutorialHeader)).setVisibility(View.VISIBLE);
        ((ScrollView) findViewById(R.id.svTutorialDetails)).setVisibility(View.VISIBLE);
    }
    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ViewParent parent = view.getParent();
            while (!parent.getClass().equals(ScrollView.class))
                parent = parent.getParent();
            ((View) parent).setVisibility(View.GONE);
            PrivacyManager.setSetting(userId, PrivacyManager.cSettingTutorialMain, Boolean.TRUE.toString());
        }
    };
    ((Button) findViewById(R.id.btnTutorialHeader)).setOnClickListener(listener);
    ((Button) findViewById(R.id.btnTutorialDetails)).setOnClickListener(listener);

    // Legacy
    if (!PrivacyManager.cVersion3) {
        long now = new Date().getTime();
        String legacy = PrivacyManager.getSetting(userId, PrivacyManager.cSettingLegacy, null);
        if (legacy == null || now > Long.parseLong(legacy) + 7 * 24 * 60 * 60 * 1000L) {
            showChangelog = false;
            PrivacyManager.setSetting(userId, PrivacyManager.cSettingLegacy, Long.toString(now));

            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
            alertDialogBuilder.setTitle(R.string.app_name);
            alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
            alertDialogBuilder.setMessage(R.string.title_update_legacy);
            alertDialogBuilder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Util.viewUri(ActivityMain.this,
                            Uri.parse("https://github.com/M66B/XPrivacy/blob/master/CHANGELOG.md#xprivacy3"));
                }
            });
            alertDialogBuilder.setNegativeButton(android.R.string.cancel,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // Do nothing
                        }
                    });

            // Show dialog
            AlertDialog alertDialog = alertDialogBuilder.create();
            alertDialog.show();
        }
    }

    // Show changelog
    if (showChangelog) {
        String sVersion = PrivacyManager.getSetting(userId, PrivacyManager.cSettingChangelog, null);
        Version changelogVersion = new Version(sVersion == null ? "0.0" : sVersion);
        Version currentVersion = new Version(Util.getSelfVersionName(this));
        if (sVersion == null || changelogVersion.compareTo(currentVersion) < 0)
            optionChangelog();
    }
}

From source file:com.android.soma.Launcher.java

public boolean onLongClick(View v) {
    if (!isDraggingEnabled())
        return false;
    if (isWorkspaceLocked())
        return false;
    if (mState != State.WORKSPACE)
        return false;

    if (v instanceof Workspace) {
        if (!mWorkspace.isInOverviewMode()) {
            if (mWorkspace.enterOverviewMode()) {
                mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
                        HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
                return true;
            } else {
                return false;
            }//from w w w  . j  a  v a 2s .  co m
        }
    }

    if (!(v instanceof CellLayout)) {
        v = (View) v.getParent().getParent();
    }

    resetAddInfo();
    CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag();
    // This happens when long clicking an item with the dpad/trackball
    if (longClickCellInfo == null) {
        return true;
    }

    // The hotseat touch handling does not go through Workspace, and we always allow long press
    // on hotseat items.
    final View itemUnderLongClick = longClickCellInfo.cell;
    boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress();
    if (allowLongPress && !mDragController.isDragging()) {
        if (itemUnderLongClick == null) {
            // User long pressed on empty space
            mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
                    HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
            // Disabling reordering until we sort out some issues.
            if (mWorkspace.isInOverviewMode()) {
                mWorkspace.startReordering(v);
            } else {
                mWorkspace.enterOverviewMode();
            }
        } else {
            if (!(itemUnderLongClick instanceof Folder)) {
                // User long pressed on an item
                mWorkspace.startDrag(longClickCellInfo);
            }
        }
    }
    return true;
}

From source file:android.app.Activity.java

public void onWindowAttributesChanged(WindowManager.LayoutParams params) {
    // Update window manager if: we have a view, that view is
    // attached to its parent (which will be a RootView), and
    // this activity is not embedded.
    if (mParent == null) {
        View decor = mDecor;
        if (decor != null && decor.getParent() != null) {
            getWindowManager().updateViewLayout(decor, params);
        }//from   w  w w .  j ava 2s. c o  m
    }
}

From source file:android.support.v7.widget.RecyclerView.java

/**
 * Retrieve the {@link ViewHolder} for the given child view.
 *
 * @param child Child of this RecyclerView to query for its ViewHolder
 * @return The child view's ViewHolder/*from w ww  . ja va2  s.  c o  m*/
 */
public ViewHolder getChildViewHolder(View child) {
    final ViewParent parent = child.getParent();
    if (parent != null && parent != this) {
        throw new IllegalArgumentException("View " + child + " is not a direct child of " + this);
    }
    return getChildViewHolderInt(child);
}

From source file:com.android.launcher3.Workspace.java

public void addToCustomContentPage(View customContent, CustomContentCallbacks callbacks, String description) {
    if (getPageIndexForScreenId(CUSTOM_CONTENT_SCREEN_ID) < 0) {
        throw new RuntimeException("Expected custom content screen to exist");
    }/*from w  w w .j  a  va  2  s  .  c  o m*/

    // Add the custom content to the full screen custom page
    CellLayout customScreen = getScreenWithId(CUSTOM_CONTENT_SCREEN_ID);
    int spanX = customScreen.getCountX();
    int spanY = customScreen.getCountY();
    CellLayout.LayoutParams lp = new CellLayout.LayoutParams(0, 0, spanX, spanY);
    lp.canReorder = false;
    lp.isFullscreen = true;
    if (customContent instanceof Insettable) {
        ((Insettable) customContent).setInsets(mInsets);
    }

    // Verify that the child is removed from any existing parent.
    if (customContent.getParent() instanceof ViewGroup) {
        ViewGroup parent = (ViewGroup) customContent.getParent();
        parent.removeView(customContent);
    }
    customScreen.removeAllViews();
    customScreen.addViewToCellLayout(customContent, 0, 0, lp, true);
    mCustomContentDescription = description;

    mCustomContentCallbacks = callbacks;
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

public boolean onLongClick(View v) {
    if (mDesktopLocked) {
        return false;
    }//w ww  .  jav a2  s  . c  o  m
    // ADW: Show previews on longpressing the dots
    switch (v.getId()) {
    case R.id.btn_scroll_left:
        mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
                HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
        showPreviousPreview(v);
        return true;
    case R.id.btn_scroll_right:
        mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS,
                HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING);
        showNextPreview(v);
        return true;
    }

    if (!(v instanceof PersonaCellLayout)) {
        v = (View) v.getParent();
    }

    PersonaCellLayout.CellInfo cellInfo = (PersonaCellLayout.CellInfo) v.getTag();

    // This happens when long clicking an item with the dpad/trackball
    if (cellInfo == null) {
        return true;
    }

    if (mWorkspace.allowLongPress() && !mBlockDesktop) {
        if (cellInfo.cell == null) {
            if (cellInfo.valid) {
                // User long pressed on empty space
                mWorkspace.setAllowLongPress(false);
                showAddDialog(cellInfo);
            }
        } else {
            if (!(cellInfo.cell instanceof PersonaFolder)) {
                // User long pressed on an item
                mWorkspace.startDrag(cellInfo);
            }
        }
    }
    return true;
}

From source file:com.appunite.list.AbsHorizontalListView.java

@Override
public void getFocusedRect(Rect r) {
    View view = getSelectedView();
    if (view != null && view.getParent() == this) {
        // the focused rectangle of the selected view offset into the
        // coordinate space of this view.
        view.getFocusedRect(r);//  w w w . j  a v  a  2  s .co  m
        offsetDescendantRectToMyCoords(view, r);
    } else {
        // otherwise, just the norm
        super.getFocusedRect(r);
    }
}

From source file:com.wb.launcher3.Workspace.java

public void onRestoreIcon(final DragObject d) {
    isDeleteApp = false;/*from  w  w w  . j  av a2  s  . co  m*/
    mDragViewVisualCenter = getDragViewVisualCenter(d.x, d.y, d.xOffset, d.yOffset, d.dragView,
            mDragViewVisualCenter);

    CellLayout dropTargetLayout = mDropToLayout;

    // We want the point to be mapped to the dragTarget.
    if (dropTargetLayout != null) {
        if (mLauncher.isHotseatLayout(dropTargetLayout)) {
            mapPointFromSelfToHotseatLayout(mLauncher.getHotseat(), mDragViewVisualCenter);
        } else {
            mapPointFromSelfToChild(dropTargetLayout, mDragViewVisualCenter, null);
        }
    }

    int snapScreen = -1;
    boolean resizeOnDrop = false;
    if (mDragInfo != null) {
        final View cell = mDragInfo.cell;

        Runnable resizeRunnable = null;
        if (dropTargetLayout != null && !d.cancelled) {
            // Move internally
            boolean hasMovedIntoHotseat = mLauncher.isHotseatLayout(dropTargetLayout);
            long container = hasMovedIntoHotseat ? LauncherSettings.Favorites.CONTAINER_HOTSEAT
                    : LauncherSettings.Favorites.CONTAINER_DESKTOP;
            long screenId = (mTargetCell[0] < 0) ? mDragInfo.screenId : getIdForScreen(dropTargetLayout);
            int spanX = mDragInfo != null ? mDragInfo.spanX : 1;
            int spanY = mDragInfo != null ? mDragInfo.spanY : 1;
            // Aside from the special case where we're dropping a shortcut onto a shortcut,
            // we need to find the nearest cell location that is vacant
            ItemInfo item = (ItemInfo) d.dragInfo;
            int minSpanX = item.spanX;
            int minSpanY = item.spanY;
            if (item.minSpanX > 0 && item.minSpanY > 0) {
                minSpanX = item.minSpanX;
                minSpanY = item.minSpanY;
            }

            CellLayout.LayoutParams lp = (CellLayout.LayoutParams) cell.getLayoutParams();
            mTargetCell[0] = lp.cellX;
            mTargetCell[1] = lp.cellY;
            CellLayout layout = (CellLayout) cell.getParent().getParent();
            layout.markCellsAsOccupiedForView(cell);
        }

        final CellLayout parent = (CellLayout) cell.getParent().getParent();
        final Runnable finalResizeRunnable = resizeRunnable;
        // Prepare it to be animated into its new position
        // This must be called after the view has been re-parented
        final Runnable onCompleteRunnable = new Runnable() {
            @Override
            public void run() {
                mAnimatingViewIntoPlace = false;
                updateChildrenLayersEnabled(false);
                if (finalResizeRunnable != null) {
                    finalResizeRunnable.run();
                }
                stripEmptyScreens();
            }
        };
        mAnimatingViewIntoPlace = true;
        if (d.dragView.hasDrawn()) {
            final ItemInfo info = (ItemInfo) cell.getTag();
            if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET) {
                int animationType = resizeOnDrop ? ANIMATE_INTO_POSITION_AND_RESIZE
                        : ANIMATE_INTO_POSITION_AND_DISAPPEAR;
                animateWidgetDrop(info, parent, d.dragView, onCompleteRunnable, animationType, cell, false);
            } else {
                int duration = snapScreen < 0 ? -1 : ADJACENT_SCREEN_DROP_DURATION;
                mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, cell, duration, onCompleteRunnable,
                        this);
            }
        } else {
            d.deferDragViewCleanupPostAnimation = false;
            cell.setVisibility(VISIBLE);
        }
        parent.onDropChild(cell);

    }
}

From source file:cc.flydev.launcher.Workspace.java

public void beginDragShared(View child, DragSource source) {
    // The drag bitmap follows the touch point around on the screen
    final Bitmap b = createDragBitmap(child, new Canvas(), DRAG_BITMAP_PADDING);

    final int bmpWidth = b.getWidth();
    final int bmpHeight = b.getHeight();

    float scale = mLauncher.getDragLayer().getLocationInDragLayer(child, mTempXY);
    int dragLayerX = Math.round(mTempXY[0] - (bmpWidth - scale * child.getWidth()) / 2);
    int dragLayerY = Math.round(mTempXY[1] - (bmpHeight - scale * bmpHeight) / 2 - DRAG_BITMAP_PADDING / 2);

    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
    Point dragVisualizeOffset = null;
    Rect dragRect = null;//from   w  w w .  j ava2s .c  o  m
    if (child instanceof BubbleTextView || child instanceof PagedViewIcon) {
        int iconSize = grid.iconSizePx;
        int top = child.getPaddingTop();
        int left = (bmpWidth - iconSize) / 2;
        int right = left + iconSize;
        int bottom = top + iconSize;
        dragLayerY += top;
        // Note: The drag region is used to calculate drag layer offsets, but the
        // dragVisualizeOffset in addition to the dragRect (the size) to position the outline.
        dragVisualizeOffset = new Point(-DRAG_BITMAP_PADDING / 2, DRAG_BITMAP_PADDING / 2);
        dragRect = new Rect(left, top, right, bottom);
    } else if (child instanceof FolderIcon) {
        int previewSize = grid.folderIconSizePx;
        dragRect = new Rect(0, child.getPaddingTop(), child.getWidth(), previewSize);
    }

    // Clear the pressed state if necessary
    if (child instanceof BubbleTextView) {
        BubbleTextView icon = (BubbleTextView) child;
        icon.clearPressedOrFocusedBackground();
    }

    mDragController.startDrag(b, dragLayerX, dragLayerY, source, child.getTag(),
            DragController.DRAG_ACTION_MOVE, dragVisualizeOffset, dragRect, scale);

    if (child.getParent() instanceof ShortcutAndWidgetContainer) {
        mDragSourceInternal = (ShortcutAndWidgetContainer) child.getParent();
    }

    b.recycle();
}

From source file:com.aliasapps.seq.scroller.TwoWayView.java

@Override
public void getFocusedRect(Rect r) {
    View view = getSelectedView();

    if (view != null && view.getParent() == this) {
        // The focused rectangle of the selected view offset into the
        // coordinate space of this view.
        view.getFocusedRect(r);//  w ww .j  a  v  a  2  s.c o m
        offsetDescendantRectToMyCoords(view, r);
    } else {
        super.getFocusedRect(r);
    }
}