private void setupContainer() { if (mPieContainer == null) { mPieContainer = new PieView(mContext, mStatusBar, mNavigationBarOverlay); mPieContainer.setOnSnapListener(this); mPieContainer.setOnExitListener(this); if (mTelephonyManager != null) { mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_SERVICE_STATE); } /** * Add intent actions to listen on it. Battery change for the battery, screen off to get rid * of the pie, apps available to check if apps on external sdcard are available and * reconstruct the button icons */ IntentFilter filter = new IntentFilter(); filter.addAction(Intent.ACTION_BATTERY_CHANGED); filter.addAction(Intent.ACTION_SCREEN_OFF); filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE); filter.addAction(Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE); mContext.registerReceiver(mBroadcastReceiver, filter); // Construct the slices constructSlices(); } }
@Override public void onLongClick(PieItem item) { String type = (String) item.longTag; if (!Action.isActionKeyEvent(type)) { mPieContainer.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS); } mPieContainer.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_LONG_CLICKED); Action.processAction(mContext, type, true); }
@Override public void onClick(PieItem item) { String type = (String) item.tag; if (!Action.isActionKeyEvent(type)) { mPieContainer.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); } if (!type.equals(ActionConstants.ACTION_MENU)) { mPieContainer.playSoundEffect(SoundEffectConstants.CLICK); } mPieContainer.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED); Action.processAction(mContext, type, false); }
public boolean activateFromListener(int touchX, int touchY, EdgeGesturePosition position) { if (isShowing()) { return false; } doHapticTriggerFeedback(); mPosition = position; Point center = new Point(touchX, touchY); mPieContainer.setSnapPoints(mPieTriggerMask & ~mPieTriggerSlots); mPieContainer.activate(center, position); mWindowManager.addView(mPieContainer, generateLayoutParam()); return true; }
public void handleMessage(Message m) { final InputManager inputManager = InputManager.getInstance(); switch (m.what) { case MSG_PIE_GAIN_FOCUS: if (mPieContainer != null) { if (!mPieActivationListener.gainTouchFocus(mPieContainer.getWindowToken())) { mPieContainer.exit(); } } else { mPieActivationListener.restoreListenerState(); } break; } }
public void constructSlices() { final Resources res = mContext.getResources(); // Clear the slices mPieContainer.clearSlices(); // Construct navbar slice int inner = res.getDimensionPixelSize(R.dimen.pie_navbar_radius); int outer = inner + res.getDimensionPixelSize(R.dimen.pie_navbar_height); mNavigationSlice = new PieSliceContainer(mPieContainer, PieSlice.IMPORTANT | PieDrawable.DISPLAY_ALL); mNavigationSlice.setGeometry(START_ANGLE, 180 - 2 * EMPTY_ANGLE, inner, outer); // Construct maybe navbar slice second layer ArrayList<ActionConfig> buttonsConfig = ActionHelper.getPieSecondLayerConfig(mContext); mSecondLayerActive = buttonsConfig.size() > 0; if (mSecondLayerActive) { inner = res.getDimensionPixelSize(R.dimen.pie_navbar_second_layer_radius); outer = inner + res.getDimensionPixelSize(R.dimen.pie_navbar_height); mNavigationSliceSecondLayer = new PieSliceContainer(mPieContainer, PieSlice.IMPORTANT | PieDrawable.DISPLAY_ALL); mNavigationSliceSecondLayer.setGeometry(START_ANGLE, 180 - 2 * EMPTY_ANGLE, inner, outer); } // Setup buttons and add the slices finally mPieContainer.addSlice(mNavigationSlice); if (mSecondLayerActive) { mPieContainer.addSlice(mNavigationSliceSecondLayer); // Adjust dimensions for sysinfo when second layer is active inner = res.getDimensionPixelSize(R.dimen.pie_sysinfo_second_layer_radius); } else { inner = res.getDimensionPixelSize(R.dimen.pie_sysinfo_radius); } // Construct sysinfo slice outer = inner + res.getDimensionPixelSize(R.dimen.pie_sysinfo_height); mSysInfo = new PieSysInfo(mContext, mPieContainer, this, PieDrawable.DISPLAY_NOT_AT_TOP); mSysInfo.setGeometry(START_ANGLE, 180 - 2 * EMPTY_ANGLE, inner, outer); mPieContainer.addSlice(mSysInfo); }
@Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); if (Intent.ACTION_BATTERY_CHANGED.equals(action)) { mBatteryLevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, 0); mBatteryStatus = intent.getIntExtra( BatteryManager.EXTRA_STATUS, BatteryManager.BATTERY_STATUS_UNKNOWN); } else if (Intent.ACTION_EXTERNAL_APPLICATIONS_UNAVAILABLE.equals(action) || Intent.ACTION_EXTERNAL_APPLICATIONS_AVAILABLE.equals(action)) { setupNavigationItems(); } else if (Intent.ACTION_SCREEN_OFF.equals(action)) { // Give up on screen off. what's the point in pie controls if you don't see them? if (isShowing()) { mPieContainer.exit(); } } }
public void detachContainer(boolean onExit) { if (mPieContainer == null || !mAttached) { return; } if (isShowing() && !onExit) { mIsDetaching = true; return; } mIsDetaching = false; mAttached = false; mPieManager.updateEdgeGestureActivationListener(mPieActivationListener, 0); if (mTelephonyManager != null) { mTelephonyManager.listen(mPhoneStateListener, PhoneStateListener.LISTEN_NONE); } mContext.getContentResolver().unregisterContentObserver(mSettingsObserver); mContext.unregisterReceiver(mBroadcastReceiver); mPieContainer.clearSlices(); mPieContainer = null; }
public boolean isShowing() { return mPieContainer != null && mPieContainer.isShowing(); }