Search in sources :

Example 31 with PopupWindow

use of android.widget.PopupWindow in project android_frameworks_base by DirtyUnicorns.

the class KeyboardView method showKey.

private void showKey(final int keyIndex) {
    final PopupWindow previewPopup = mPreviewPopup;
    final Key[] keys = mKeys;
    if (keyIndex < 0 || keyIndex >= mKeys.length)
        return;
    Key key = keys[keyIndex];
    if (key.icon != null) {
        mPreviewText.setCompoundDrawables(null, null, null, key.iconPreview != null ? key.iconPreview : key.icon);
        mPreviewText.setText(null);
    } else {
        mPreviewText.setCompoundDrawables(null, null, null, null);
        mPreviewText.setText(getPreviewText(key));
        if (key.label.length() > 1 && key.codes.length < 2) {
            mPreviewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mKeyTextSize);
            mPreviewText.setTypeface(Typeface.DEFAULT_BOLD);
        } else {
            mPreviewText.setTextSize(TypedValue.COMPLEX_UNIT_PX, mPreviewTextSizeLarge);
            mPreviewText.setTypeface(Typeface.DEFAULT);
        }
    }
    mPreviewText.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    int popupWidth = Math.max(mPreviewText.getMeasuredWidth(), key.width + mPreviewText.getPaddingLeft() + mPreviewText.getPaddingRight());
    final int popupHeight = mPreviewHeight;
    LayoutParams lp = mPreviewText.getLayoutParams();
    if (lp != null) {
        lp.width = popupWidth;
        lp.height = popupHeight;
    }
    if (!mPreviewCentered) {
        mPopupPreviewX = key.x - mPreviewText.getPaddingLeft() + mPaddingLeft;
        mPopupPreviewY = key.y - popupHeight + mPreviewOffset;
    } else {
        // TODO: Fix this if centering is brought back
        mPopupPreviewX = 160 - mPreviewText.getMeasuredWidth() / 2;
        mPopupPreviewY = -mPreviewText.getMeasuredHeight();
    }
    mHandler.removeMessages(MSG_REMOVE_PREVIEW);
    getLocationInWindow(mCoordinates);
    // Offset may be zero
    mCoordinates[0] += mMiniKeyboardOffsetX;
    // Offset may be zero
    mCoordinates[1] += mMiniKeyboardOffsetY;
    // Set the preview background state
    mPreviewText.getBackground().setState(key.popupResId != 0 ? LONG_PRESSABLE_STATE_SET : EMPTY_STATE_SET);
    mPopupPreviewX += mCoordinates[0];
    mPopupPreviewY += mCoordinates[1];
    // If the popup cannot be shown above the key, put it on the side
    getLocationOnScreen(mCoordinates);
    if (mPopupPreviewY + mCoordinates[1] < 0) {
        // the right, offset by enough to see at least one key to the left/right.
        if (key.x + key.width <= getWidth() / 2) {
            mPopupPreviewX += (int) (key.width * 2.5);
        } else {
            mPopupPreviewX -= (int) (key.width * 2.5);
        }
        mPopupPreviewY += popupHeight;
    }
    if (previewPopup.isShowing()) {
        previewPopup.update(mPopupPreviewX, mPopupPreviewY, popupWidth, popupHeight);
    } else {
        previewPopup.setWidth(popupWidth);
        previewPopup.setHeight(popupHeight);
        previewPopup.showAtLocation(mPopupParent, Gravity.NO_GRAVITY, mPopupPreviewX, mPopupPreviewY);
    }
    mPreviewText.setVisibility(VISIBLE);
}
Also used : LayoutParams(android.view.ViewGroup.LayoutParams) PopupWindow(android.widget.PopupWindow) Key(android.inputmethodservice.Keyboard.Key) Paint(android.graphics.Paint)

Example 32 with PopupWindow

use of android.widget.PopupWindow in project StandOut by pingpongboss.

the class Window method getSystemDecorations.

/**
 * Returns the system window decorations if the implementation sets
 * {@link #FLAG_DECORATION_SYSTEM}.
 *
 * <p>
 * The system window decorations support hiding, closing, moving, and
 * resizing.
 *
 * @return The frame view containing the system window decorations.
 */
private View getSystemDecorations() {
    final View decorations = mLayoutInflater.inflate(R.layout.system_window_decorators, null);
    // icon
    final ImageView icon = (ImageView) decorations.findViewById(R.id.window_icon);
    icon.setImageResource(mContext.getAppIcon());
    icon.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            PopupWindow dropDown = mContext.getDropDown(id);
            if (dropDown != null) {
                dropDown.showAsDropDown(icon);
            }
        }
    });
    // title
    TextView title = (TextView) decorations.findViewById(R.id.title);
    title.setText(mContext.getTitle(id));
    // hide
    View hide = decorations.findViewById(R.id.hide);
    hide.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            mContext.hide(id);
        }
    });
    hide.setVisibility(View.GONE);
    // maximize
    View maximize = decorations.findViewById(R.id.maximize);
    maximize.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            StandOutLayoutParams params = getLayoutParams();
            boolean isMaximized = data.getBoolean(WindowDataKeys.IS_MAXIMIZED);
            if (isMaximized && params.width == displayWidth && params.height == displayHeight && params.x == 0 && params.y == 0) {
                data.putBoolean(WindowDataKeys.IS_MAXIMIZED, false);
                int oldWidth = data.getInt(WindowDataKeys.WIDTH_BEFORE_MAXIMIZE, -1);
                int oldHeight = data.getInt(WindowDataKeys.HEIGHT_BEFORE_MAXIMIZE, -1);
                int oldX = data.getInt(WindowDataKeys.X_BEFORE_MAXIMIZE, -1);
                int oldY = data.getInt(WindowDataKeys.Y_BEFORE_MAXIMIZE, -1);
                edit().setSize(oldWidth, oldHeight).setPosition(oldX, oldY).commit();
            } else {
                data.putBoolean(WindowDataKeys.IS_MAXIMIZED, true);
                data.putInt(WindowDataKeys.WIDTH_BEFORE_MAXIMIZE, params.width);
                data.putInt(WindowDataKeys.HEIGHT_BEFORE_MAXIMIZE, params.height);
                data.putInt(WindowDataKeys.X_BEFORE_MAXIMIZE, params.x);
                data.putInt(WindowDataKeys.Y_BEFORE_MAXIMIZE, params.y);
                edit().setSize(1f, 1f).setPosition(0, 0).commit();
            }
        }
    });
    // close
    View close = decorations.findViewById(R.id.close);
    close.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            mContext.close(id);
        }
    });
    // move
    View titlebar = decorations.findViewById(R.id.titlebar);
    titlebar.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // handle dragging to move
            boolean consumed = mContext.onTouchHandleMove(id, Window.this, v, event);
            return consumed;
        }
    });
    // resize
    View corner = decorations.findViewById(R.id.corner);
    corner.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // handle dragging to move
            boolean consumed = mContext.onTouchHandleResize(id, Window.this, v, event);
            return consumed;
        }
    });
    // set window appearance and behavior based on flags
    if (Utils.isSet(flags, StandOutFlags.FLAG_WINDOW_HIDE_ENABLE)) {
        hide.setVisibility(View.VISIBLE);
    }
    if (Utils.isSet(flags, StandOutFlags.FLAG_DECORATION_MAXIMIZE_DISABLE)) {
        maximize.setVisibility(View.GONE);
    }
    if (Utils.isSet(flags, StandOutFlags.FLAG_DECORATION_CLOSE_DISABLE)) {
        close.setVisibility(View.GONE);
    }
    if (Utils.isSet(flags, StandOutFlags.FLAG_DECORATION_MOVE_DISABLE)) {
        titlebar.setOnTouchListener(null);
    }
    if (Utils.isSet(flags, StandOutFlags.FLAG_DECORATION_RESIZE_DISABLE)) {
        corner.setVisibility(View.GONE);
    }
    return decorations;
}
Also used : PopupWindow(android.widget.PopupWindow) StandOutLayoutParams(wei.mark.standout.StandOutWindow.StandOutLayoutParams) TextView(android.widget.TextView) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) MotionEvent(android.view.MotionEvent)

Example 33 with PopupWindow

use of android.widget.PopupWindow in project SocialRec by Jkuras.

the class QR_Scan method onActivityResult.

@Override
protected void onActivityResult(int requestCode, int resultCode, final Intent data) {
    if (requestCode == BARCODE_READER_REQUEST_CODE) {
        if (resultCode == CommonStatusCodes.SUCCESS) {
            if (data != null) {
                final Barcode barcode = data.getParcelableExtra(BarcodeCaptureActivity.BarcodeObject);
                final FirebaseDatabase database = FirebaseDatabase.getInstance();
                // make sure the substring w/the id code does not contain . # $ [ or ]
                if (!authenticateBarcode(barcode.displayValue)) {
                    mResultTextView.setText("Invalid QR code scanned");
                } else {
                    // parse barcode, remove "uid: " from barcode value
                    final String string = barcode.displayValue.substring(5);
                    // set ref to store/:barcodevalue
                    DatabaseReference aref = database.getReference("stores/" + string);
                    final ValueEventListener postListener = new ValueEventListener() {

                        @Override
                        public void onDataChange(DataSnapshot dataSnapshot) {
                            // if the result is not null, it IS a registered store
                            if (dataSnapshot.getValue() != null) {
                                Store store = dataSnapshot.getValue(Store.class);
                                mResultTextView.setText("Welcome to " + store.getName() + "!");
                                FirebaseDatabase database = FirebaseDatabase.getInstance();
                                // TODO: PART OF CLEANUP
                                // set ref to the reward corresponding to the store
                                DatabaseReference ref = database.getReference("users/" + MainActivity.mAuth.getCurrentUser().getUid() + "/storeRewards/" + string);
                                // get the correct reward
                                StoreReward reward = MainActivity.mUser.getStoreRewards().get(string);
                                // if they have current rewards
                                if (reward != null) {
                                    // increment visit
                                    reward.incrementVisit();
                                    // WIN CONDITION
                                    if (reward.getVisits() % reward.getReward() == 0 & reward.getVisits() != 0) {
                                        LayoutInflater inflater = (LayoutInflater) getApplicationContext().getSystemService(LAYOUT_INFLATER_SERVICE);
                                        View rewardView = inflater.inflate(R.layout.popup_get_reward, null);
                                        final PopupWindow rewardPopup = new PopupWindow(rewardView, 1200, 800);
                                        mRewardTextView.setText("Reward Time!");
                                        rewardPopup.setOutsideTouchable(false);
                                        rewardPopup.showAtLocation(findViewById(R.id.result_textview), Gravity.CENTER, 0, 0);
                                        Button confirmRewardButton = (Button) rewardView.findViewById(R.id.reward_confirm_button);
                                        confirmRewardButton.setOnClickListener(new View.OnClickListener() {

                                            @Override
                                            public void onClick(View view) {
                                                rewardPopup.dismiss();
                                            }
                                        });
                                    } else // NO REWARD CONDITION
                                    {
                                        // tell how many more you need for your next reward
                                        mRewardTextView.setText(reward.getVisits() % reward.getReward() + " out of " + reward.getReward() + " visits");
                                    }
                                    // add the user to the stores customers section
                                    DatabaseReference bref = database.getReference("stores/" + dataSnapshot.getKey() + "/customers/" + MainActivity.mAuth.getCurrentUser().getUid() + "/visits");
                                    bref.setValue(reward.getVisits());
                                    // save storerewards back to the db
                                    ref.setValue(reward);
                                    // increment users total visit counter, and save it to db
                                    MainActivity.mUser.incrementtotalVisits();
                                    database.getReference("users/" + MainActivity.mAuth.getCurrentUser().getUid() + "/totalVisits").setValue(MainActivity.mUser.getTotalVisits());
                                    return;
                                // IF THIS if TRIGGERS NONE OF THE FOLLOWING 20ish LINES WILL HAPPEN
                                }
                                // if they have never visited that store, add a new storeReward
                                mRewardTextView.setText("first visit");
                                reward = (new StoreReward(store.getName(), 1, store.getReward().getReward()));
                                // add the user to the stores customers section
                                DatabaseReference bref = database.getReference("stores/" + dataSnapshot.getKey() + "/customers/" + MainActivity.mAuth.getCurrentUser().getUid());
                                bref.setValue(new StoreReward(MainActivity.mUser.getMyName(), 1, store.getReward().getReward()));
                                // save to db
                                ref.setValue(reward);
                                // increment total visits
                                MainActivity.mUser.incrementtotalVisits();
                                database.getReference("users/" + MainActivity.mAuth.getCurrentUser().getUid() + "/totalVisits").setValue(MainActivity.mUser.getTotalVisits());
                            } else {
                                mResultTextView.setText("Not a Store");
                                mRewardTextView.setText("n/a");
                            }
                        }

                        @Override
                        public void onCancelled(DatabaseError databaseError) {
                            // Getting Post failed, log a message
                            Log.w("", "loadPost:onCancelled", databaseError.toException());
                        // ...
                        }
                    };
                    aref.addListenerForSingleValueEvent(postListener);
                }
            } else
                mResultTextView.setText("No barcode captured");
        } else
            Log.e(LOG_TAG, String.format("Barcode format error", CommonStatusCodes.getStatusCodeString(resultCode)));
    } else
        super.onActivityResult(requestCode, resultCode, data);
}
Also used : FirebaseDatabase(com.google.firebase.database.FirebaseDatabase) DatabaseReference(com.google.firebase.database.DatabaseReference) PopupWindow(android.widget.PopupWindow) DataSnapshot(com.google.firebase.database.DataSnapshot) TextView(android.widget.TextView) View(android.view.View) DatabaseError(com.google.firebase.database.DatabaseError) Button(android.widget.Button) Barcode(com.google.android.gms.vision.barcode.Barcode) LayoutInflater(android.view.LayoutInflater) ValueEventListener(com.google.firebase.database.ValueEventListener)

Example 34 with PopupWindow

use of android.widget.PopupWindow in project EhViewer by seven332.

the class Slider method init.

@SuppressWarnings("deprecation")
private void init(Context context, AttributeSet attrs) {
    mContext = context;
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    Paint textPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    textPaint.setTextAlign(Paint.Align.CENTER);
    Resources resources = context.getResources();
    mBubbleMinWidth = resources.getDimensionPixelOffset(R.dimen.slider_bubble_width);
    mBubbleMinHeight = resources.getDimensionPixelOffset(R.dimen.slider_bubble_height);
    mBubble = new BubbleView(context, textPaint);
    mBubble.setScaleX(0.0f);
    mBubble.setScaleY(0.0f);
    AbsoluteLayout absoluteLayout = new AbsoluteLayout(context);
    absoluteLayout.addView(mBubble);
    absoluteLayout.setBackgroundDrawable(null);
    mPopup = new PopupWindow(absoluteLayout);
    mPopup.setOutsideTouchable(false);
    mPopup.setTouchable(false);
    mPopup.setFocusable(false);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Slider);
    textPaint.setColor(a.getColor(R.styleable.Slider_textColor, Color.WHITE));
    textPaint.setTextSize(a.getDimensionPixelSize(R.styleable.Slider_textSize, 12));
    updateTextSize();
    setRange(a.getInteger(R.styleable.Slider_start, 0), a.getInteger(R.styleable.Slider_end, 0));
    setProgress(a.getInteger(R.styleable.Slider_slider_progress, 0));
    mThickness = a.getDimension(R.styleable.Slider_thickness, 2);
    mRadius = a.getDimension(R.styleable.Slider_radius, 6);
    setColor(a.getColor(R.styleable.Slider_color, Color.BLACK));
    mBgPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    mBgPaint.setColor(a.getBoolean(R.styleable.Slider_dark, false) ? 0x4dffffff : 0x42000000);
    a.recycle();
    mProgressAnimation = new ValueAnimator();
    mProgressAnimation.setInterpolator(AnimationUtils.FAST_SLOW_INTERPOLATOR);
    mProgressAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(@NonNull ValueAnimator animation) {
            float value = (Float) animation.getAnimatedValue();
            mDrawPercent = value;
            mDrawProgress = Math.round(MathUtils.lerp((float) mStart, mEnd, value));
            updateBubblePosition();
            mBubble.setProgress(mDrawProgress);
            invalidate();
        }
    });
    mBubbleScaleAnimation = new ValueAnimator();
    mBubbleScaleAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(@NonNull ValueAnimator animation) {
            float value = (Float) animation.getAnimatedValue();
            mDrawBubbleScale = value;
            mBubble.setScaleX(value);
            mBubble.setScaleY(value);
            invalidate();
        }
    });
}
Also used : TypedArray(android.content.res.TypedArray) PopupWindow(android.widget.PopupWindow) Paint(android.graphics.Paint) Resources(android.content.res.Resources) ValueAnimator(android.animation.ValueAnimator) AbsoluteLayout(android.widget.AbsoluteLayout)

Example 35 with PopupWindow

use of android.widget.PopupWindow in project keleFanfou by kelefun.

the class FolderWindow method setPopupWindowTouchModal.

public static void setPopupWindowTouchModal(PopupWindow popupWindow, boolean touchModal) {
    if (null == popupWindow) {
        return;
    }
    Method method;
    try {
        method = PopupWindow.class.getDeclaredMethod("setTouchModal", boolean.class);
        method.setAccessible(true);
        method.invoke(popupWindow, touchModal);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : PopupWindow(android.widget.PopupWindow) Method(java.lang.reflect.Method)

Aggregations

PopupWindow (android.widget.PopupWindow)133 View (android.view.View)66 TextView (android.widget.TextView)48 ColorDrawable (android.graphics.drawable.ColorDrawable)27 ImageView (android.widget.ImageView)24 Paint (android.graphics.Paint)22 Key (android.inputmethodservice.Keyboard.Key)14 AdapterView (android.widget.AdapterView)14 LinearLayout (android.widget.LinearLayout)14 LayoutInflater (android.view.LayoutInflater)13 Button (android.widget.Button)13 ListView (android.widget.ListView)13 Activity (android.app.Activity)12 BitmapDrawable (android.graphics.drawable.BitmapDrawable)12 OnClickListener (android.view.View.OnClickListener)11 ViewGroup (android.view.ViewGroup)11 Context (android.content.Context)10 Resources (android.content.res.Resources)10 EditText (android.widget.EditText)10 ScrollView (android.widget.ScrollView)10