Java Code Examples for android.widget.PopupWindow#setTouchable()

The following examples show how to use android.widget.PopupWindow#setTouchable() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomPopWindow.java    From LLApp with Apache License 2.0 6 votes vote down vote up
/**
 * 添加一些属性设置
 * @param popupWindow
 */
private void apply(PopupWindow popupWindow){
    popupWindow.setClippingEnabled(mClippEnable);
    if(mIgnoreCheekPress){
        popupWindow.setIgnoreCheekPress();
    }
    if(mInputMode!=-1){
        popupWindow.setInputMethodMode(mInputMode);
    }
    if(mSoftInputMode!=-1){
        popupWindow.setSoftInputMode(mSoftInputMode);
    }
    if(mOnDismissListener!=null){
        popupWindow.setOnDismissListener(mOnDismissListener);
    }
    if(mOnTouchListener!=null){
        popupWindow.setTouchInterceptor(mOnTouchListener);
    }
    popupWindow.setTouchable(mTouchable);



}
 
Example 2
Source File: DropPopMenu.java    From zhangshangwuda with Apache License 2.0 6 votes vote down vote up
private void initList() {
	View popupWindow_view = LayoutInflater.from(context).inflate(
			R.layout.droppopmenu, null);
	popupWindow_view.setFocusableInTouchMode(true);
	// 设置popupWindow的布局
	popupWindow = new PopupWindow(popupWindow_view,
			WindowManager.LayoutParams.WRAP_CONTENT,
			WindowManager.LayoutParams.WRAP_CONTENT);
	popupWindow.setTouchable(true);
	popupWindow.setFocusable(true);
	// 这个是为了点击“返回Back”也能使其消失,并且并不会影响你的背景
	popupWindow.setBackgroundDrawable(new ColorDrawable(
			android.R.color.transparent));
	// 设置允许在外点击消失
	popupWindow.setOutsideTouchable(true);
	listView = (ListView) popupWindow_view
			.findViewById(R.id.droppopmenu_listView);
	popupWindow.update();
}
 
Example 3
Source File: ChooseSetPopupWindow.java    From AssistantBySDK with Apache License 2.0 6 votes vote down vote up
private void initView() {
    View contentView = LayoutInflater.from(mContext).inflate(R.layout.popup_choose_set, null);
    contentView.findViewById(R.id.ll_shade).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    mChooseWindow = new PopupWindow(contentView, -1, -1);
    //点击空白处的时候PopupWindow会消失
    mChooseWindow.setFocusable(true);
    mChooseWindow.setTouchable(true);
    mChooseWindow.setOutsideTouchable(true);
    mChooseWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    // mChooseWindow.setAnimationStyle(R.style.popupAnim);

    //初始化集数列表
    RecyclerView rvChooseSet = (RecyclerView) contentView.findViewById(R.id.rv_choose_set);
    rvChooseSet.setHasFixedSize(true);
    rvChooseSet.setLayoutManager(new GridLayoutManager(mContext, 4));
    rvChooseSet.setAdapter(new ChooseSetAdapter());
}
 
Example 4
Source File: CustomPopupWindow.java    From YCDialog with Apache License 2.0 6 votes vote down vote up
private void apply(PopupWindow mPopupWindow) {
    mPopupWindow.setClippingEnabled(this.mClippEnable);
    if(this.mIgnoreCheekPress) {
        mPopupWindow.setIgnoreCheekPress();
    }

    if(this.mInputMode != -1) {
        mPopupWindow.setInputMethodMode(this.mInputMode);
    }

    if(this.mSoftInputMode != -1) {
        mPopupWindow.setSoftInputMode(this.mSoftInputMode);
    }

    if(this.mOnDismissListener != null) {
        mPopupWindow.setOnDismissListener(this.mOnDismissListener);
    }

    if(this.mOnTouchListener != null) {
        mPopupWindow.setTouchInterceptor(this.mOnTouchListener);
    }

    mPopupWindow.setTouchable(this.mTouchable);
}
 
Example 5
Source File: BigImgView.java    From Android-Application-ZJB with Apache License 2.0 6 votes vote down vote up
public BigImgView(final Context context, String url, final View view) {
    // 一个自定义的布局,作为显示的内容
    final View contentView = LayoutInflater.from(context).inflate(
            R.layout.vw_bigimg, null);

    popupWindow = new PopupWindow(contentView,
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, true);
    popupWindow.setOutsideTouchable(true);
    popupWindow.setTouchable(true);

    ImageView imageView = (ImageView) contentView.findViewById(R.id.bigImg_img);
    ViewUtils.showImage(imageView, url);

    Logger.i("显示图片:"+url);
    imageView.setOnClickListener(this);
    contentView.findViewById(R.id.bigImgPop_layout).setOnClickListener(this);

    // 如果不设置PopupWindow的背景,无论是点击外部区域还是Back键都无法dismiss弹框
    // 我觉得这里是API的一个bug
    popupWindow.setBackgroundDrawable(new BitmapDrawable());

    popupWindow.showAtLocation(view, Gravity.NO_GRAVITY, 0, 0);
}
 
Example 6
Source File: SelectRemindWayPopup.java    From Android-AlarmManagerClock with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
public SelectRemindWayPopup(Context context) {
    mContext = context;
    mPopupWindow = new PopupWindow(context);
    mPopupWindow.setBackgroundDrawable(new BitmapDrawable());
    mPopupWindow.setWidth(WindowManager.LayoutParams.FILL_PARENT);
    mPopupWindow.setHeight(WindowManager.LayoutParams.FILL_PARENT);
    mPopupWindow.setTouchable(true);
    mPopupWindow.setFocusable(true);
    mPopupWindow.setOutsideTouchable(true);
    mPopupWindow.setAnimationStyle(R.style.AnimBottom);
    mPopupWindow.setContentView(initViews());

    mPopupWindow.getContentView().setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            mPopupWindow.setFocusable(false);
            mPopupWindow.dismiss();
            return true;
        }
    });

}
 
Example 7
Source File: SelectRemindCyclePopup.java    From Android-AlarmManagerClock with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
public SelectRemindCyclePopup(Context context) {
    mContext = context;
    mPopupWindow = new PopupWindow(context);
    mPopupWindow.setBackgroundDrawable(new BitmapDrawable());
    mPopupWindow.setWidth(WindowManager.LayoutParams.FILL_PARENT);
    mPopupWindow.setHeight(WindowManager.LayoutParams.FILL_PARENT);
    mPopupWindow.setTouchable(true);
    mPopupWindow.setFocusable(true);
    mPopupWindow.setOutsideTouchable(true);
    mPopupWindow.setAnimationStyle(R.style.AnimBottom);
    mPopupWindow.setContentView(initViews());
    mPopupWindow.getContentView().setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            mPopupWindow.setFocusable(false);
            // mPopupWindow.dismiss();
            return true;
        }
    });

}
 
Example 8
Source File: DemoQSVideoView.java    From QSVideoPlayer with Apache License 2.0 5 votes vote down vote up
private PopupWindow getPopupWindow(View popupView) {
    PopupWindow mPopupWindow = new PopupWindow(popupView, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, true);
    mPopupWindow.setTouchable(true);
    mPopupWindow.setOutsideTouchable(true);
    mPopupWindow.setBackgroundDrawable(new ColorDrawable(0));
    mPopupWindow.setAnimationStyle(R.style.jc_popup_toast_anim);
    return mPopupWindow;
}
 
Example 9
Source File: LordFragment.java    From MyHearts with Apache License 2.0 5 votes vote down vote up
private void initPopup() {
        View popupWindow = LayoutInflater.from(getContext())
                .inflate(R.layout.lord_popup_window_layout, null);

        mReAddGroup = (RelativeLayout) popupWindow.findViewById(R.id.re_add_group);
        mReAddGroup.setOnClickListener(this);
        mReSearchGroup = (RelativeLayout) popupWindow.findViewById(R.id.re_search_group);
        mReSearchGroup.setOnClickListener(this);
        mPopupWindow = new PopupWindow(popupWindow);
        mPopupWindow.setWidth(ViewGroup.LayoutParams.FILL_PARENT);
        mPopupWindow.setHeight(ViewGroup.LayoutParams.FILL_PARENT);
        mPopupWindow.setTouchable(true);
        mPopupWindow.setOutsideTouchable(true);
        mPopupWindow.setBackgroundDrawable(new BitmapDrawable(getContext().getResources()));

        mLlDismiss = (LinearLayout) popupWindow.findViewById(R.id.ll_dismiss);
        mLlDismiss.setOnClickListener(view -> {
            mPopupWindow.dismiss();
        });

//        // 设置背景颜色变暗
//        WindowManager.LayoutParams lp = getActivity().getWindow().getAttributes();
//        lp.alpha = 0.7f;
//        getActivity().getWindow().setAttributes(lp);
//        mPopupWindow.setOnDismissListener(() -> {
//            WindowManager.LayoutParams lp1 = getActivity().getWindow().getAttributes();
//            lp1.alpha = 1f;
//            getActivity().getWindow().setAttributes(lp1);
//        });
    }
 
Example 10
Source File: PopupWindowManager.java    From PlayTogether with Apache License 2.0 5 votes vote down vote up
public static PopupWindow getPopupWindow(View contentView, int width, int height, final View
				dimView, final onCloseListener listener)
{
	final PopupWindow mPopupWindow = new PopupWindow(contentView, width, height, true);
	mPopupWindow.setTouchable(true);
	mPopupWindow.setAnimationStyle(R.style.selectPopupWindowAnim);
	mPopupWindow.setBackgroundDrawable(new BitmapDrawable());
	mPopupWindow.setTouchInterceptor(new View.OnTouchListener()
	{
		@Override
		public boolean onTouch(View v, MotionEvent event)
		{
			if (event.getAction() == MotionEvent.ACTION_OUTSIDE)
			{
				mPopupWindow.dismiss();
				return true;
			}
			return false;
		}
	});
	mPopupWindow.setOnDismissListener(new PopupWindow.OnDismissListener()
	{
		@Override
		public void onDismiss()
		{
			if (dimView != null)
				toggleLight(false, dimView);
			if (listener != null)
				listener.onClose();
		}
	});
	return mPopupWindow;
}
 
Example 11
Source File: IntroController.java    From geoar-app with Apache License 2.0 5 votes vote down vote up
private static void initPopupShow() {
	introViewer = new IntroViewer(activity, activity.getResources()
			.getString(R.string.intro_start_title), activity.getResources()
			.getString(R.string.intro_start_desc));

	graph = new TaskGraph();

	popup = new PopupWindow(introViewer, LayoutParams.MATCH_PARENT,
			LayoutParams.MATCH_PARENT);
	popup.setTouchable(false);
	popup.setFocusable(true);
	popup.setOutsideTouchable(true);
	popup.setTouchInterceptor(new OnTouchListener() {

		@Override
		public boolean onTouch(View v, MotionEvent event) {
			return false;
		}

	});

	activity.getWindow().getDecorView().post(new Runnable() {
		@Override
		public void run() {
			if(popup!=null)
			popup.showAtLocation(activity.getWindow().getDecorView()
					.getRootView(), Gravity.TOP, 0, 0);
		}
	});
}
 
Example 12
Source File: FrmPopMenu.java    From quickhybrid-android with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * 获取弹出视图
 *
 * @return
 */
public void setPopWindow() {
    ListView lv = new ListView(context);
    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(DensityUtil.dip2px(context, 150), ViewGroup.LayoutParams.WRAP_CONTENT);
    lp.setMargins(15, 0, 15, 15);
    lv.setLayoutParams(lp);
    lv.setBackgroundColor(Color.WHITE);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        lv.setElevation(15);
    }
    lv.setAdapter(new IconAdapter());
    lv.setOnItemClickListener(this);

    LinearLayout ll = new LinearLayout(context);
    ll.setLayoutParams(new ViewGroup.LayoutParams(DensityUtil.dip2px(context, 200), ViewGroup.LayoutParams.WRAP_CONTENT));
    ll.addView(lv);
    pop = new PopupWindow(ll, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, true);
    pop.setTouchable(true);
    pop.setOutsideTouchable(true);
    //必须添加背景,否则点击空白无法自动隐藏
    pop.setBackgroundDrawable(new BitmapDrawable());
    pop.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {
            if (changedListener != null) {
                changedListener.onHide(FrmPopMenu.this);
            }
        }
    });
}
 
Example 13
Source File: TestActivity.java    From YCDialog with Apache License 2.0 5 votes vote down vote up
private void showPopupWindow() {
    //创建对象
    PopupWindow popupWindow = new PopupWindow(this);
    View inflate = LayoutInflater.from(this).inflate(R.layout.view_pop_custom, null);
    //设置view布局
    popupWindow.setContentView(inflate);
    popupWindow.setWidth(LinearLayout.LayoutParams.WRAP_CONTENT);
    popupWindow.setHeight(LinearLayout.LayoutParams.WRAP_CONTENT);
    //设置动画的方法
    popupWindow.setAnimationStyle(R.style.BottomDialog);
    //设置PopUpWindow的焦点,设置为true之后,PopupWindow内容区域,才可以响应点击事件
    popupWindow.setTouchable(true);
    //设置背景透明
    popupWindow.setBackgroundDrawable(new ColorDrawable(0x00000000));
    //点击空白处的时候让PopupWindow消失
    popupWindow.setOutsideTouchable(true);
    // true时,点击返回键先消失 PopupWindow
    // 但是设置为true时setOutsideTouchable,setTouchable方法就失效了(点击外部不消失,内容区域也不响应事件)
    // false时PopupWindow不处理返回键,默认是false
    popupWindow.setFocusable(false);
    //设置dismiss事件
    popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {
        @Override
        public void onDismiss() {

        }
    });
    boolean showing = popupWindow.isShowing();
    if (!showing){
        //show,并且可以设置位置
        popupWindow.showAsDropDown(mTv1);
    }
    //popupWindow.dismiss();
}
 
Example 14
Source File: ImportFragment.java    From apkextractor with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    swipeRefreshLayout=view.findViewById(R.id.content_swipe);
    recyclerView=view.findViewById(R.id.content_recyclerview);
    viewGroup_no_content=view.findViewById(R.id.no_content_att);
    viewGroup_progress=view.findViewById(R.id.loading);
    progressBar=view.findViewById(R.id.loading_pg);
    progressTextView=view.findViewById(R.id.loading_text);
    card_multi_select=view.findViewById(R.id.import_card_multi_select);
    tv_multi_select_head=view.findViewById(R.id.import_card_att);
    btn_select=view.findViewById(R.id.import_select_all);
    btn_delete=view.findViewById(R.id.import_delete);
    btn_import=view.findViewById(R.id.import_action);
    btn_more =view.findViewById(R.id.import_more);
    View popupView=LayoutInflater.from(getActivity()).inflate(R.layout.pp_more_import,null);
    popupView.findViewById(R.id.popup_file_rename).setOnClickListener(this);
    popupView.findViewById(R.id.popup_share).setOnClickListener(this);
    popupWindow=new PopupWindow(popupView,ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT,true);
    popupWindow.setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.color_popup_window)));
    popupWindow.setTouchable(true);
    popupWindow.setOutsideTouchable(true);

    try {
        IntentFilter intentFilter=new IntentFilter();
        intentFilter.addAction(Constants.ACTION_REFRESH_IMPORT_ITEMS_LIST);
        if(getActivity()!=null)getActivity().registerReceiver(receiver,intentFilter);
    } catch (Exception e) {
        e.printStackTrace();
    }

    initView();
}
 
Example 15
Source File: SettingsActivity.java    From Nimingban with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.config_settings);

    mACCookies = findPreference(KEY_AC_COOKIES);
    mAddCookies = findPreference(KEY_ADD_COOKIES);
    mSaveCookies = findPreference(KEY_SAVE_COOKIES);
    mRestoreCookies = findPreference(KEY_RESTORE_COOKIES);
    mFeedId = findPreference(Settings.KEY_FEED_ID);
    mImageSaveLocation = findPreference(Settings.KEY_IMAGE_SAVE_LOACTION);
    mChaosLevel = findPreference(Settings.KEY_CHAOS_LEVEL);
    mAppIcon = (IconListPreference) findPreference(KEY_APP_ICON);
    mRestoreIgnoredPosts = findPreference(KEY_RESTORE_IGNORED_POSTS);
    mAboutAnalysis = findPreference(KEY_ABOUT_ANALYSIS);

    mACCookies.setOnPreferenceClickListener(this);
    mAddCookies.setOnPreferenceClickListener(this);
    mSaveCookies.setOnPreferenceClickListener(this);
    mRestoreCookies.setOnPreferenceClickListener(this);
    mFeedId.setOnPreferenceClickListener(this);
    mImageSaveLocation.setOnPreferenceClickListener(this);
    mRestoreIgnoredPosts.setOnPreferenceClickListener(this);
    mAboutAnalysis.setOnPreferenceClickListener(this);

    mChaosLevel.setOnPreferenceChangeListener(this);
    mAppIcon.setOnPreferenceChangeListener(this);

    long maxAge = ACSite.getInstance().getCookieMaxAge(getActivity());
    setACCookiesSummary(maxAge);
    updateFeedIdSummary();
    updateImageSaveLocation();

    mPopupTextView = new PopupTextView(getActivity());
    mPopupWindow = new PopupWindow(mPopupTextView);
    mPopupWindow.setOutsideTouchable(false);
    mPopupWindow.setTouchable(false);
    mPopupWindow.setFocusable(false);
    mPopupWindow.setAnimationStyle(0);

    // Popup window
    ((SettingsActivity) getActivity()).getListView()
            .getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            ((SettingsActivity) getActivity()).getListView().getViewTreeObserver().removeGlobalOnLayoutListener(this);
            ensurePopupWindow();
        }
    });
}
 
Example 16
Source File: LatinKeyboardView.java    From hackerskeyboard with Apache License 2.0 4 votes vote down vote up
public LatinKeyboardView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // TODO(klausw): migrate attribute styles to LatinKeyboardView?
    TypedArray a = context.obtainStyledAttributes(
            attrs, R.styleable.LatinKeyboardBaseView, defStyle, R.style.LatinKeyboardBaseView);
    LayoutInflater inflate =
            (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    int previewLayout = 0;
    int n = a.getIndexCount();
    for (int i = 0; i < n; i++) {
        int attr = a.getIndex(i);

        switch (attr) {
        case R.styleable.LatinKeyboardBaseView_keyPreviewLayout:
            previewLayout = a.getResourceId(attr, 0);
            if (previewLayout == R.layout.null_layout) previewLayout = 0;
            break;
        case R.styleable.LatinKeyboardBaseView_keyPreviewOffset:
            mPreviewOffset = a.getDimensionPixelOffset(attr, 0);
            break;
        case R.styleable.LatinKeyboardBaseView_keyPreviewHeight:
            mPreviewHeight = a.getDimensionPixelSize(attr, 80);
            break;
        case R.styleable.LatinKeyboardBaseView_popupLayout:
            mPopupLayout = a.getResourceId(attr, 0);
            if (mPopupLayout == R.layout.null_layout) mPopupLayout = 0;
            break;
        }
    }

    final Resources res = getResources();

    // If true, popups are forced to remain inside the keyboard area. If false,
    // they can extend above it. Enable clipping just for Android P since drawing
    // outside the keyboard area doesn't work on that version.
    boolean clippingEnabled = (Build.VERSION.SDK_INT >= 28 /* Build.VERSION_CODES.P */);

    if (previewLayout != 0) {
        mPreviewPopup = new PopupWindow(context);
        if (!isInEditMode())
            Log.i(TAG, "new mPreviewPopup " + mPreviewPopup + " from " + this);
        mPreviewText = (TextView) inflate.inflate(previewLayout, null);
        mPreviewTextSizeLarge = (int) res.getDimension(R.dimen.key_preview_text_size_large);
        mPreviewPopup.setContentView(mPreviewText);
        mPreviewPopup.setBackgroundDrawable(null);
        mPreviewPopup.setTouchable(false);
        mPreviewPopup.setAnimationStyle(R.style.KeyPreviewAnimation);
        mPreviewPopup.setClippingEnabled(clippingEnabled);
    } else {
        mShowPreview = false;
    }

    if (mPopupLayout != 0) {
        mMiniKeyboardParent = this;
        mMiniKeyboardPopup = new PopupWindow(context);
        if (!isInEditMode())
            Log.i(TAG, "new mMiniKeyboardPopup " + mMiniKeyboardPopup + " from " + this);
        mMiniKeyboardPopup.setBackgroundDrawable(null);
        mMiniKeyboardPopup.setAnimationStyle(R.style.MiniKeyboardAnimation);
        mMiniKeyboardPopup.setClippingEnabled(clippingEnabled);
        mMiniKeyboardVisible = false;
    }
}
 
Example 17
Source File: KeyboardView.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public KeyboardView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    TypedArray a = context.obtainStyledAttributes(
            attrs, android.R.styleable.KeyboardView, defStyleAttr, defStyleRes);

    LayoutInflater inflate =
            (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    int previewLayout = 0;
    int keyTextSize = 0;

    int n = a.getIndexCount();

    for (int i = 0; i < n; i++) {
        int attr = a.getIndex(i);

        switch (attr) {
        case com.android.internal.R.styleable.KeyboardView_keyBackground:
            mKeyBackground = a.getDrawable(attr);
            break;
        case com.android.internal.R.styleable.KeyboardView_verticalCorrection:
            mVerticalCorrection = a.getDimensionPixelOffset(attr, 0);
            break;
        case com.android.internal.R.styleable.KeyboardView_keyPreviewLayout:
            previewLayout = a.getResourceId(attr, 0);
            break;
        case com.android.internal.R.styleable.KeyboardView_keyPreviewOffset:
            mPreviewOffset = a.getDimensionPixelOffset(attr, 0);
            break;
        case com.android.internal.R.styleable.KeyboardView_keyPreviewHeight:
            mPreviewHeight = a.getDimensionPixelSize(attr, 80);
            break;
        case com.android.internal.R.styleable.KeyboardView_keyTextSize:
            mKeyTextSize = a.getDimensionPixelSize(attr, 18);
            break;
        case com.android.internal.R.styleable.KeyboardView_keyTextColor:
            mKeyTextColor = a.getColor(attr, 0xFF000000);
            break;
        case com.android.internal.R.styleable.KeyboardView_labelTextSize:
            mLabelTextSize = a.getDimensionPixelSize(attr, 14);
            break;
        case com.android.internal.R.styleable.KeyboardView_popupLayout:
            mPopupLayout = a.getResourceId(attr, 0);
            break;
        case com.android.internal.R.styleable.KeyboardView_shadowColor:
            mShadowColor = a.getColor(attr, 0);
            break;
        case com.android.internal.R.styleable.KeyboardView_shadowRadius:
            mShadowRadius = a.getFloat(attr, 0f);
            break;
        }
    }

    a = mContext.obtainStyledAttributes(
            com.android.internal.R.styleable.Theme);
    mBackgroundDimAmount = a.getFloat(android.R.styleable.Theme_backgroundDimAmount, 0.5f);

    mPreviewPopup = new PopupWindow(context);
    if (previewLayout != 0) {
        mPreviewText = (TextView) inflate.inflate(previewLayout, null);
        mPreviewTextSizeLarge = (int) mPreviewText.getTextSize();
        mPreviewPopup.setContentView(mPreviewText);
        mPreviewPopup.setBackgroundDrawable(null);
    } else {
        mShowPreview = false;
    }

    mPreviewPopup.setTouchable(false);

    mPopupKeyboard = new PopupWindow(context);
    mPopupKeyboard.setBackgroundDrawable(null);
    //mPopupKeyboard.setClippingEnabled(false);

    mPopupParent = this;
    //mPredicting = true;

    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setTextSize(keyTextSize);
    mPaint.setTextAlign(Align.CENTER);
    mPaint.setAlpha(255);

    mPadding = new Rect(0, 0, 0, 0);
    mMiniKeyboardCache = new HashMap<Key,View>();
    mKeyBackground.getPadding(mPadding);

    mSwipeThreshold = (int) (500 * getResources().getDisplayMetrics().density);
    mDisambiguateSwipe = getResources().getBoolean(
            com.android.internal.R.bool.config_swipeDisambiguation);

    mAccessibilityManager = AccessibilityManager.getInstance(context);
    mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

    resetMultiTap();
}
 
Example 18
Source File: KeyboardView.java    From libcommon with Apache License 2.0 4 votes vote down vote up
/**
	 * コンストラクタ
	 * @param context
	 * @param attrs
	 * @param defStyleAttr
	 */
	public KeyboardView(@NonNull final Context context,
		@Nullable final AttributeSet attrs, final int defStyleAttr) {

		super(context, attrs, defStyleAttr);

		if (DEBUG) Log.v(TAG, "コンストラクタ:");
		final TypedArray a = context.getTheme().obtainStyledAttributes(
			attrs, R.styleable.KeyboardView, defStyleAttr, 0);

		final LayoutInflater inflate = LayoutInflater.from(context);
		final Resources resources = context.getResources();

		mKeyBackground = a.getDrawable(R.styleable.KeyboardView_keyBackground);
		if (DEBUG) Log.v(TAG, "コンストラクタ:mKeyBackground=" + mKeyBackground);
		mVerticalCorrection = a.getDimensionPixelOffset( R.styleable.KeyboardView_verticalCorrection, 0);
		if (DEBUG) Log.v(TAG, "コンストラクタ:mVerticalCorrection=" + mVerticalCorrection);
		int previewLayout = a.getResourceId(R.styleable.KeyboardView_keyPreviewLayout, 0);
		if (DEBUG) Log.v(TAG, "コンストラクタ:previewLayout=" + previewLayout);
		mPreviewOffset = a.getDimensionPixelOffset(R.styleable.KeyboardView_keyPreviewOffset, 0);
		if (DEBUG) Log.v(TAG, "コンストラクタ:mPreviewOffset=" + mPreviewOffset);
		mPreviewHeight = a.getDimensionPixelSize(R.styleable.KeyboardView_keyPreviewHeight,
			resources.getDimensionPixelSize(R.dimen.keyboard_key_preview_height));
		if (DEBUG) Log.v(TAG, "コンストラクタ:mPreviewHeight=" + mPreviewHeight);
		mKeyTextSize = a.getDimension(R.styleable.KeyboardView_keyTextSize,
			resources.getDimension(R.dimen.keyboard_key_text_sz));
		if (DEBUG) Log.v(TAG, "コンストラクタ:mKeyTextSize=" + mKeyTextSize);

		if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
			mKeyTextColor = a.getColor(R.styleable.KeyboardView_keyTextColor,
				resources.getColor(R.color.keyboard_key_text_color, null));
			mLabelTextColor = a.getColor(R.styleable.KeyboardView_labelTextColor,
				resources.getColor(R.color.keyboard_key_label_color, null));
			mShadowColor = a.getColor(R.styleable.KeyboardView_shadowColor,
				resources.getColor(R.color.keyboard_key_label_color, null));
		} else {
			mKeyTextColor = a.getColor(R.styleable.KeyboardView_keyTextColor,
				resources.getColor(R.color.keyboard_key_text_color));
			mLabelTextColor = a.getColor(R.styleable.KeyboardView_labelTextColor,
				resources.getColor(R.color.keyboard_key_label_color));
			mShadowColor = a.getColor(R.styleable.KeyboardView_shadowColor,
				resources.getColor(R.color.keyboard_key_label_color));
		}
		if (DEBUG) Log.v(TAG, String.format("コンストラクタ:mKeyTextColor=%08x", mKeyTextColor));
		if (DEBUG) Log.v(TAG, String.format("コンストラクタ:mLabelTextColor=%08x", mLabelTextColor));
		if (DEBUG) Log.v(TAG, String.format("コンストラクタ:mShadowColor=%08x", mShadowColor));
		mLabelTextSize = a.getDimension(R.styleable.KeyboardView_labelTextSize,
			resources.getDimension(R.dimen.keyboard_label_sz));
		if (DEBUG) Log.v(TAG, "コンストラクタ:mLabelTextSize=" + mLabelTextSize);
		mPopupLayout = a.getResourceId(R.styleable.KeyboardView_popupLayout, 0);
		if (DEBUG) Log.v(TAG, "コンストラクタ:mPopupLayout=" + mPopupLayout);
		mShadowRadius = a.getFloat(R.styleable.KeyboardView_shadowRadius, 0f);
		if (DEBUG) Log.v(TAG, "コンストラクタ:mShadowRadius=" + mShadowRadius);
		a.recycle();

		mPreviewPopup = new PopupWindow(context);
		if (previewLayout != 0) {
			mPreviewText = (TextView) inflate.inflate(previewLayout, null);
			mPreviewTextSizeLarge = (int) mPreviewText.getTextSize();
			mPreviewPopup.setContentView(mPreviewText);
			mPreviewPopup.setBackgroundDrawable(null);
		} else {
			mShowPreview = false;
		}

		mPreviewPopup.setTouchable(false);

		mPopupKeyboard = new PopupWindow(context);
		mPopupKeyboard.setBackgroundDrawable(null);
		//mPopupKeyboard.setClippingEnabled(false);

		mPopupParent = this;
		//mPredicting = true;

		mPaint = new Paint();
		mPaint.setAntiAlias(true);
		mPaint.setTextSize(0);
		mPaint.setTextAlign(Paint.Align.CENTER);
		mPaint.setAlpha(255);

		mPadding = new Rect(0, 0, 0, 0);
		mMiniKeyboardCache = new HashMap<Keyboard.Key, View>();
		mKeyBackground.getPadding(mPadding);

		mSwipeThreshold = (int) (500 * getResources().getDisplayMetrics().density);
		mDisambiguateSwipe = getResources().getBoolean(R.bool.config_swipeDisambiguation);

		mAccessibilityManager
			= ContextUtils.requireSystemService(context, AccessibilityManager.class);
//		mAudioManager = ContextUtils.requireSystemService(context, AudioManager.class);

		resetMultiTap();
	}
 
Example 19
Source File: IdentitySettingsActivity.java    From secure-quick-reliable-login with MIT License 4 votes vote down vote up
public void setupSavePopupWindow(LayoutInflater layoutInflater) {
    View popupView = layoutInflater.inflate(R.layout.fragment_save_settings, null);

    savePopupWindow = new PopupWindow(popupView,
            ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT,
            true);

    savePopupWindow.setTouchable(true);
    savePopupWindow.setFocusable(true);

    final EditText txtPassword = popupView.findViewById(R.id.txtPassword);

    SQRLStorage storage = SQRLStorage.getInstance(IdentitySettingsActivity.this.getApplicationContext());

    popupView.findViewById(R.id.btnCloseSaveSettings).setOnClickListener(v -> savePopupWindow.dismiss());
    final Button btnSaveSettings = popupView.findViewById(R.id.btnSaveSettings);
    btnSaveSettings.setOnClickListener(v -> new Thread(() -> {
        handler.post(() -> {
            savePopupWindow.dismiss();
            showProgressPopup();
        });
        storage.clearQuickPass();
        boolean decryptStatus = storage.decryptIdentityKey(txtPassword.getText().toString(), entropyHarvester, false);
        if(!decryptStatus) {
            showErrorMessage(R.string.decrypt_identity_fail);
            storage.clearQuickPass();
            storage.clear();
            handler.post(() -> {
                hideProgressPopup();
                txtPassword.setText("");
            });
            return;
        }

        int quickPassLength = getIntValue(txtQuickPassLength);
        int passwordVerify = getIntValue(txtPwdVerifySecs);
        int quickPassTimeout = getIntValue(txtQuickPassTimeout);

        storage.setHintLength(quickPassLength);
        storage.setPasswordVerify(passwordVerify);
        storage.setIdleTimeout(quickPassTimeout);
        storage.setSQRLOnly(cbSQRLOnly.isChecked());
        storage.setNoByPass(cbNoBypass.isChecked());

        boolean encryptStatus = storage.encryptIdentityKey(txtPassword.getText().toString(), entropyHarvester);
        if (!encryptStatus) {
            showErrorMessage(R.string.encrypt_identity_fail);
            handler.post(() -> {
                hideProgressPopup();
                txtPassword.setText("");
            });
            return;
        }
        storage.clear();
        storage.clearQuickPass();

        long currentId = SqrlApplication.getCurrentId(this.getApplication());
        mDbHelper.updateIdentityData(currentId, storage.createSaveData());

        handler.post(() -> {
            txtPassword.setText("");
            hideProgressPopup();
            IdentitySettingsActivity.this.finish();
        });

    }).start());
}
 
Example 20
Source File: CustomKeyboardView.java    From FirefoxReality with Mozilla Public License 2.0 4 votes vote down vote up
public CustomKeyboardView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    LayoutInflater inflate =
            (LayoutInflater) context
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    int previewLayout = 0;
    int keyTextSize = 0;
    mKeyBackground = context.getDrawable(R.drawable.keyboard_key_background);
    mKeyCapStartBackground = context.getDrawable(R.drawable.keyboard_key_background);
    mVerticalCorrection = 0;
    previewLayout = 0;
    mPreviewOffset = 0;
    mPreviewHeight = 80;
    mKeyTextSize = context.getResources().getDimensionPixelSize(R.dimen.keyboard_key_text_size);
    mKeyTextColor = 0xFFFFFFFF;
    mLabelTextSize = context.getResources().getDimensionPixelSize(R.dimen.keyboard_key_longtext_size);
    mPopupLayout = R.layout.keyboard;
    mShadowColor = 0;
    mShadowRadius = 0;
    mBackgroundDimAmount = 0.5f;
    clearHover();

    mPreviewPopup = new PopupWindow(context);
    if (previewLayout != 0) {
        mPreviewText = (TextView) inflate.inflate(previewLayout, null);
        mPreviewTextSizeLarge = (int) mPreviewText.getTextSize();
        mPreviewPopup.setContentView(mPreviewText);
        mPreviewPopup.setBackgroundDrawable(null);
    } else {
        mShowPreview = false;
    }

    mPreviewPopup.setTouchable(false);

    mPopupKeyboard = new PopupWindow(context);
    mPopupKeyboard.setBackgroundDrawable(null);
    //mPopupKeyboard.setClippingEnabled(false);

    mPopupParent = this;
    //mPredicting = true;

    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setTextSize(keyTextSize);
    mPaint.setTextAlign(Align.CENTER);
    mPaint.setAlpha(255);
    mPaint.setTypeface(Typeface.create("sans-serif",Typeface.NORMAL));

    mPadding = new Rect(0, 0, 0, 0);
    mMiniKeyboardCache = new HashMap<>();
    mKeyBackground.getPadding(mPadding);
    mKeyboardHoveredPadding = getResources().getDimensionPixelSize(R.dimen.keyboard_key_hovered_padding);
    mKeyboardPressedPadding = getResources().getDimensionPixelSize(R.dimen.keyboard_key_pressed_padding);

    mSwipeThreshold = (int) (500 * getResources().getDisplayMetrics().density);
    mDisambiguateSwipe = false;

    mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);

    resetMultiTap();

    mForegroundColor = context.getColor(R.color.asphalt);
    mSelectedForegroundColor = context.getColor(R.color.fog);
}