Java Code Examples for android.widget.TextView.setOnTouchListener()

The following are Jave code examples for showing how to use setOnTouchListener() of the android.widget.TextView class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: OSchina_resources_android   File: TabPickerView.java   View Source Code Vote up 7 votes
ViewHolder(View view) {
    super(view);
    mViewTab = (TextView) view.findViewById(R.id.tv_content);
    mViewBubble = (TextView) view.findViewById(R.id.tv_bubble);
    mViewDel = (ImageView) view.findViewById(R.id.iv_delete);

    mViewTab.setTextColor(new ColorStateList(new int[][]{
                    new int[]{-android.R.attr.state_activated},
                    new int[]{}
            }, new int[]{0XFF24CF5F, 0XFF6A6A6A})
    );
    mViewTab.setActivated(true);

    mViewTab.setTag(this);
    mViewDel.setTag(this);
    mViewDel.setOnClickListener(getDeleteItemListener());
    mViewTab.setOnClickListener(getClickTabItemListener());
    mViewTab.setOnTouchListener(getTouchTabItemListener());
}
 
Example 2
Project: IslamicLibraryAndroid   File: NotePopupFragment.java   View Source Code Vote up 6 votes
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    Bundle args = getArguments();


    TextView mHighlightText = view.findViewById(R.id.text_view_highlight_text);

    mHighlightText.setOnTouchListener(new MovingTouchListener(getDialog().getWindow()));
    String title = args.getString(HIGHLIGHT_TEXT_KEY, "TEXT");
    mHighlightText.setText(title);
    int highlightColor = args.getInt(HIGHLIGHT_COLOR_KEY);
    mHighlightText.setBackgroundColor(highlightColor);


    mNoteEditText = view.findViewById(R.id.toc_card_body);
    String note = args.getString(HIGHLIGHT_NOTE_KEY, "");
    mNoteEditText.setText(note);
    int highlightDarkColor = args.getInt(HIGHLIGHT_DARK_COLOR_KEY);
    mNoteEditText.setBackgroundColor(highlightDarkColor);
    if (note.isEmpty()) {
        // Show soft keyboard automatically and request focus to field
        mNoteEditText.requestFocus();
        getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
    }
}
 
Example 3
Project: Simpler   File: StatusDataSetter.java   View Source Code Vote up 6 votes
/**
 * 格式化微博或评论正文
 *
 * @param text      文本内容
 * @param tvContent TextView
 */
public void formatContent(final boolean comment, final long id, String text, final TextView tvContent) {
    SpannableStringBuilder builder;
    if (comment) {
        builder = mCommentContent.get(id);
    } else {
        builder = mTextContent.get(id);
    }
    if (builder != null) {
        tvContent.setText(builder);
    } else {
        if (mStatusListener == null) {
            mStatusListener = new StatusListener();
        }
        mAnalyzeTask = StatusAnalyzeTask.getInstance(mActivity, mStatusListener);
        mAnalyzeTask.setStatusAnalyzeListener(new StatusAnalyzeListener() {
            @Override
            public void onSpannableStringComplete(SpannableStringBuilder ssb) {
                if (comment) {
                    mCommentContent.put(id, ssb);
                } else {
                    mTextContent.put(id, ssb);
                }
                tvContent.setText(ssb);
            }
        });
        mAnalyzeTask.execute(text);

        tvContent.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return textTouchEvent((TextView) v, event);
            }
        });
    }
}
 
Example 4
Project: ExtraMapUtils   File: AppUtils.java   View Source Code Vote up 5 votes
public static void setTextWithLinks(TextView textView, CharSequence html) {
    textView.setText(html);
    textView.setOnTouchListener(new View.OnTouchListener() {
        @SuppressLint("ClickableViewAccessibility")
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            int action = event.getAction();
            if (action == MotionEvent.ACTION_UP ||
                    action == MotionEvent.ACTION_DOWN) {
                int x = (int) event.getX();
                int y = (int) event.getY();

                TextView widget = (TextView) v;
                x -= widget.getTotalPaddingLeft();
                y -= widget.getTotalPaddingTop();

                x += widget.getScrollX();
                y += widget.getScrollY();

                Layout layout = widget.getLayout();
                int line = layout.getLineForVertical(y);
                int off = layout.getOffsetForHorizontal(line, x);

                ClickableSpan[] link = Spannable.Factory.getInstance()
                        .newSpannable(widget.getText())
                        .getSpans(off, off, ClickableSpan.class);

                if (link.length != 0) {
                    if (action == MotionEvent.ACTION_UP) {
                        link[0].onClick(widget);
                    }
                    return true;
                }
            }
            return false;
        }
    });
}
 
Example 5
Project: AssistantBySDK   File: RspMsgItemView.java   View Source Code Vote up 5 votes
protected void init(Context mContext) {
    LayoutInflater iflater = LayoutInflater.from(mContext);
    iflater.inflate(R.layout.common_bubble_dialog_left, this);
    mTextView = (TextView) findViewById(R.id.common_bubble_left_text);
    mTextView.setOnTouchListener(this);
    mListDrawable = (LevelListDrawable) mTextView.getBackground();
}
 
Example 6
Project: MyFlightbookAndroid   File: PropertyEdit.java   View Source Code Vote up 5 votes
@SuppressLint("ClickableViewAccessibility")
private void handleStupidFocusStuffInListViews(TextView tv) {
    // Wow.  See https://stackoverflow.com/questions/38890059/edittext-in-expandablelistview.  EditTexts inside ListView's are a pain in the ass
    // because of all of the re-using of the controls.
    tv.setFocusable(false);
    tv.setOnTouchListener((view, motionEvent) -> {
        view.setFocusableInTouchMode(true);
        view.performClick();
        return false;
    });
}
 
Example 7
Project: egma-handwriting-numbers   File: WriteNumberActivity.java   View Source Code Vote up 5 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i(getClass().getName(), "onCreate");
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_write);

    DaoSession daoSession = ContentProvider.getDaoSession();
    audioDao = daoSession.getAudioDao();

    List<Number> unlockedNumbers = ContentProvider.getUnlockedNumbers();
    number = unlockedNumbers.get((int)(Math.random() * unlockedNumbers.size()));
    Log.i(getClass().getName(), "number: " + number);
    TextView textView = (TextView) findViewById(R.id.textView);
    textView.setText(number.getValue().toString());
    // Set on listener to restart the drawing with a blank screen
    textView.setOnTouchListener(this);

    initTensorFlowAndLoadModel();

    mModel = new DrawModel(PIXEL_WIDTH, PIXEL_WIDTH);

    mDrawView = (DrawView) findViewById(R.id.view_draw);
    mDrawView.setModel(mModel);
    DrawViewOnTouchListener listener = new DrawViewOnTouchListener(mDrawView, mModel, inferenceInterface, number.getValue(), getApplicationContext());
    mDrawView.setOnTouchListener(listener);
}
 
Example 8
Project: FlickLauncher   File: Hotseat.java   View Source Code Vote up 5 votes
void resetLayout() {
    mContent.removeAllViewsInLayout();

    if (!FeatureFlags.NO_ALL_APPS_ICON) {
        // Add the Apps button
        Context context = getContext();
        int allAppsButtonRank = mLauncher.getDeviceProfile().inv.getAllAppsButtonRank();

        LayoutInflater inflater = LayoutInflater.from(context);
        TextView allAppsButton = (TextView)
                inflater.inflate(R.layout.all_apps_button, mContent, false);
        Drawable d = context.getResources().getDrawable(R.drawable.all_apps_button_icon);

        mLauncher.resizeIconDrawable(d);
        int scaleDownPx = getResources().getDimensionPixelSize(R.dimen.all_apps_button_scale_down);
        Rect bounds = d.getBounds();
        d.setBounds(bounds.left, bounds.top + scaleDownPx / 2, bounds.right - scaleDownPx,
                bounds.bottom - scaleDownPx / 2);
        allAppsButton.setCompoundDrawables(null, d, null, null);

        allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label));
        allAppsButton.setOnKeyListener(new HotseatIconKeyEventListener());
        if (mLauncher != null) {
            mLauncher.setAllAppsButton(allAppsButton);
            allAppsButton.setOnTouchListener(mLauncher.getHapticFeedbackTouchListener());
            allAppsButton.setOnClickListener(mLauncher);
            allAppsButton.setOnLongClickListener(mLauncher);
            allAppsButton.setOnFocusChangeListener(mLauncher.mFocusHandler);
        }

        // Note: We do this to ensure that the hotseat is always laid out in the orientation of
        // the hotseat in order regardless of which orientation they were added
        int x = getCellXFromOrder(allAppsButtonRank);
        int y = getCellYFromOrder(allAppsButtonRank);
        CellLayout.LayoutParams lp = new CellLayout.LayoutParams(x, y, 1, 1);
        lp.canReorder = false;
        mContent.addViewToCellLayout(allAppsButton, -1, allAppsButton.getId(), lp, true);
    }
}
 
Example 9
Project: sctalk   File: MessageOperatePopup.java   View Source Code Vote up 5 votes
@SuppressWarnings("deprecation")
private MessageOperatePopup(Context ctx, View parent) {
    View view = LayoutInflater.from(ctx).inflate(R.layout.tt_popup_list,
            null);
    this.context = ctx;

    // popView = (LinearLayout) view.findViewById(R.id.popup_list);

    copyBtn = (TextView) view.findViewById(R.id.copy_btn);
    copyBtn.setOnClickListener(this);
    copyBtn.setOnTouchListener(this);
    copyBtn.setPadding(0, 13, 0, 8);

    resendBtn = (TextView) view.findViewById(R.id.resend_btn);
    resendBtn.setOnClickListener(this);
    resendBtn.setOnTouchListener(this);
    resendBtn.setPadding(0, 13, 0, 8);

    speakerBtn = (TextView) view.findViewById(R.id.speaker_btn);
    speakerBtn.setOnClickListener(this);
    speakerBtn.setOnTouchListener(this);
    speakerBtn.setPadding(0, 13, 0, 8);

    mWidth = (int) context.getResources().getDimension(
            R.dimen.message_item_popup_width_single_short);
    mHeight = (int) context.getResources().getDimension(
            R.dimen.message_item_popup_height);

    int[] location = new int[2];
    parent.getLocationOnScreen(location);
    mParentTop = location[1];
    mPopup = new PopupWindow(view, mWidth, mHeight);
    // mPopup.setFocusable(true);
    // 设置允许在外点击消失
    mPopup.setOutsideTouchable(true);
    // 这个是为了点击“返回Back”也能使其消失,并且并不会影响你的背景
    mPopup.setBackgroundDrawable(new BitmapDrawable());
}
 
Example 10
Project: AppTycoon   File: TextViewListenerBinder.java   View Source Code Vote up 5 votes
/**
 * Sets an OnClickListener that when clicked, performs the action given as param.
 * Also, sets an OnTouchListener that changes the color of the TextView when it's touched
 * to simulate the feel of an object that can be interacted with.
 *
 * @param textView TextView to set these listeners to
 * @param action Action to perform when the TextView is clicked
 */
public static void bindActionToTextView(TextView textView, final Action action) {
    textView.setOnTouchListener(new TextViewChangeColourOnTouchListener(Color.GRAY,
            textView.getCurrentTextColor()));
    textView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            action.doAction();
        }
    });
}
 
Example 11
Project: AppTycoon   File: MainActivity.java   View Source Code Vote up 5 votes
/**
 * Sets listeners for navigation drawer textviews.
 * @param navItem The item to set listeners for.
 * @param linkItemTo The fragment that the item should navigate to.
 */
private void setNavItemListeners(TextView navItem, int linkItemTo) {
    // Set the listeners
    navItem.setOnClickListener(new NavItemOnClickListener(linkItemTo));
    navItem.setOnTouchListener(new NavItemOnTouchListener());

    // And add the TextView to the list of navigation drawer text views
    mNavigationTextViews.add(navItem);
}
 
Example 12
Project: SimpleUILauncher   File: Hotseat.java   View Source Code Vote up 5 votes
void resetLayout() {
    mContent.removeAllViewsInLayout();

    // 在hotseat中显示进入所有应用列表的图标
    if (!FeatureFlags.NO_ALL_APPS_ICON) {
        // Add the Apps button
        Context context = getContext();
        int allAppsButtonRank = mLauncher.getDeviceProfile().inv.getAllAppsButtonRank();

        LayoutInflater inflater = LayoutInflater.from(context);
        TextView allAppsButton = (TextView)
                inflater.inflate(R.layout.all_apps_button, mContent, false);
        Drawable d = context.getResources().getDrawable(R.drawable.all_apps_button_icon);

        mLauncher.resizeIconDrawable(d);
        int scaleDownPx = getResources().getDimensionPixelSize(R.dimen.all_apps_button_scale_down);
        Rect bounds = d.getBounds();
        d.setBounds(bounds.left, bounds.top + scaleDownPx / 2, bounds.right - scaleDownPx,
                bounds.bottom - scaleDownPx / 2);
        allAppsButton.setCompoundDrawables(null, d, null, null);

        allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label));
        allAppsButton.setOnKeyListener(new HotseatIconKeyEventListener());
        if (mLauncher != null) {
            mLauncher.setAllAppsButton(allAppsButton);
            allAppsButton.setOnTouchListener(mLauncher.getHapticFeedbackTouchListener());
            allAppsButton.setOnClickListener(mLauncher);
            allAppsButton.setOnLongClickListener(mLauncher);
            allAppsButton.setOnFocusChangeListener(mLauncher.mFocusHandler);
        }

        // Note: We do this to ensure that the hotseat is always laid out in the orientation of
        // the hotseat in order regardless of which orientation they were added
        int x = getCellXFromOrder(allAppsButtonRank);
        int y = getCellYFromOrder(allAppsButtonRank);
        CellLayout.LayoutParams lp = new CellLayout.LayoutParams(x, y, 1, 1);
        lp.canReorder = false;
        mContent.addViewToCellLayout(allAppsButton, -1, allAppsButton.getId(), lp, true);
    }
}
 
Example 13
Project: PC-Handler   File: MainActivity.java   View Source Code Vote up 4 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    context = this;
    playPauseButton = (Button)findViewById(R.id.playPauseButton);
    nextButton = (Button)findViewById(R.id.nextButton);
    previousButton = (Button)findViewById(R.id.previousButton);

    relativeLayout=(RelativeLayout)findViewById(R.id.activity_main);

    playPauseButton.setOnClickListener(this);
    nextButton.setOnClickListener(this);
    previousButton.setOnClickListener(this);

    mousePad = (TextView)findViewById(R.id.mousePad);
    mousePad.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if(isConnected && out!=null){
                switch(event.getAction()){
                    case MotionEvent.ACTION_DOWN:
                        //save X and Y positions when user touches the TextView
                        initX =event.getX();
                        initY =event.getY();
                        mouseMoved=false;
                        break;
                    case MotionEvent.ACTION_MOVE:
                        disX = event.getX()- initX;
                        disY = event.getY()- initY;
                        initX = event.getX();
                        initY = event.getY();
                        if(disX !=0|| disY !=0){
                            new SendMessage().execute(disX +","+ disY);
                        }
                        mouseMoved=true;
                        break;
                    case MotionEvent.ACTION_UP:
                        //consider a tap only if usr did not move mouse after ACTION_DOWN
                        if(!mouseMoved){
                            new SendMessage().execute(Constants.MOUSE_LEFT_CLICK);
                        }
                }
            }
            return true;
        }
    });
}
 
Example 14
Project: AppTycoon   File: AppTycoonDialog.java   View Source Code Vote up 4 votes
private void setActionTextViewListener(TextView view, View.OnClickListener listener) {
    view.setOnTouchListener(new TextViewChangeColourOnTouchListener(Color.BLACK,
            view.getCurrentTextColor()));
    view.setOnClickListener(listener);
}
 
Example 15
Project: AppTycoon   File: ProductsFragment.java   View Source Code Vote up 4 votes
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_products, container, false);

    mGameState = GameEngine.getInstance().getGameState();

    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recyclerViewProducts);
    ProductRecyclerViewAdapter recyclerAdapter;
    recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
    recyclerAdapter = new ProductRecyclerViewAdapter(mGameState.getCompany().getProducts());
    recyclerView.setAdapter(recyclerAdapter);

    // New product button
    TextView newProductTextView = (TextView) view.findViewById(R.id.textViewAction);
    newProductTextView.setOnTouchListener(new TextViewChangeColourOnTouchListener(
            Color.BLACK,
            newProductTextView.getCurrentTextColor()));
    newProductTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // First select the type of the new product.
            ActionSelectDialogBuilder builder = new ActionSelectDialogBuilder(getContext());

            for (final ProductType type : ProductType.getAllTypes()) {
                builder.addCustomActionEntry(type.getName(), new ActionSelectDialogBuilder.Action() {
                    @Override
                    public void doAction() {
                        // Then when selected, go to configuring it.
                        Message msg = UiUpdateHandler.obtainReplaceFragmentMessage(MainActivity.FRAGMENT_NEW_PRODUCT);
                        Bundle args = msg.getData();
                        args.putInt(UiUpdateHandler.ARG_NEW_PRODUCT_TYPE, type.getType());
                        msg.setData(args);
                        msg.sendToTarget();
                    }
                });
            }

            builder.show();
        }
    });

    return view;
}
 
Example 16
Project: AppTycoon   File: NewProjectFragment.java   View Source Code Vote up 4 votes
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_new_project, container, false);

    TextView viewBack = (TextView) view.findViewById(R.id.textViewBack);
    viewBack.setOnClickListener(new FragmentBackButtonOnClickListener());
    viewBack.setOnTouchListener(new TextViewChangeColourOnTouchListener(Color.BLACK, viewBack.getCurrentTextColor()));

    TextView viewStartProject = (TextView) view.findViewById(R.id.textViewAction);
    viewStartProject.setOnClickListener(new StartProjectOnClickListener());
    viewStartProject.setOnTouchListener(new TextViewChangeColourOnTouchListener(Color.BLACK, viewBack.getCurrentTextColor()));

    // Load project slot.
    int projectSlotIndex = getArguments().getInt(UiUpdateHandler.ARG_PROJECT_SLOT_INDEX);
    Log.d(TAG, "onCreateView() - projectSlotIndex = " + projectSlotIndex);
    mProjectSlot = GameEngine.getInstance().getGameState()
            .getCompany().getProjectSlots().get(projectSlotIndex);


    // TODO: Now just gets a random ContractingProject for testing purposes
    mProject = ContractingProject.getRandomContractingProject();

    // Get the header layout based on the project type.
    View headerView = new View(getContext());
    if (mProject instanceof ContractingProject) {
        ContractingProject cProject = (ContractingProject) mProject;
        Log.d(TAG, "onCreateView() - project was a ContractingProject");
        headerView = inflater.inflate(R.layout.child_new_project_contracting_header, null);

        TextView twProjectName = (TextView) headerView.findViewById(R.id.textViewProjectName);
        TextView twReward = (TextView) headerView.findViewById(R.id.textViewReward);
        TextView twCustomer = (TextView) headerView.findViewById(R.id.textViewCustomer);
        TextView twComplexity = (TextView) headerView.findViewById(R.id.textViewProductComplexity);
        TextView twQualityReq = (TextView) headerView.findViewById(R.id.textViewQualityReq);
        TextView twTime = (TextView) headerView.findViewById(R.id.textViewTime);

        twProjectName.setText(cProject.getName());
        twReward.setText("$ " + Utils.largeNumberToNiceString(cProject.getReward(), 2));
        twCustomer.setText(cProject.getCustomer());
        twComplexity.setText(Long.toString(cProject.getWorkAmount()));
        twQualityReq.setText(Long.toString(cProject.getRequiredQuality()));
        twTime.setText(Utils.millisecondsToTimeString(cProject.getTimeLeft()));
    }

    LinearLayout headerContainer = (LinearLayout) view.findViewById(R.id.layoutHeaderContainer);
    headerContainer.addView(headerView);

    // Populate project tasks RecyclerView
    RecyclerView recyclerViewProjectTasks = (RecyclerView) view.findViewById(R.id.recyclerViewProjectTasks);
    recyclerViewProjectTasks.setHasFixedSize(true); // performance boot for static content
    recyclerViewProjectTasks.setLayoutManager(new LinearLayoutManager(getContext()));
    recyclerViewProjectTasks.setAdapter(new ProjectTasksRecyclerViewAdapter(mProject.getTasks()));
    return view;
}
 
Example 17
Project: AOSP-Kayboard-7.1.2   File: EmojiPalettesView.java   View Source Code Vote up 4 votes
@Override
protected void onFinishInflate() {
    mTabHost = (TabHost)findViewById(R.id.emoji_category_tabhost);
    mTabHost.setup();
    for (final EmojiCategory.CategoryProperties properties
            : mEmojiCategory.getShownCategories()) {
        addTab(mTabHost, properties.mCategoryId);
    }
    mTabHost.setOnTabChangedListener(this);
    final TabWidget tabWidget = mTabHost.getTabWidget();
    tabWidget.setStripEnabled(mCategoryIndicatorEnabled);
    if (mCategoryIndicatorEnabled) {
        // On TabWidget's strip, what looks like an indicator is actually a background.
        // And what looks like a background are actually left and right drawables.
        tabWidget.setBackgroundResource(mCategoryIndicatorDrawableResId);
        tabWidget.setLeftStripDrawable(mCategoryIndicatorBackgroundResId);
        tabWidget.setRightStripDrawable(mCategoryIndicatorBackgroundResId);
    }

    mEmojiPalettesAdapter = new EmojiPalettesAdapter(mEmojiCategory, this);

    mEmojiPager = (ViewPager)findViewById(R.id.emoji_keyboard_pager);
    mEmojiPager.setAdapter(mEmojiPalettesAdapter);
    mEmojiPager.setOnPageChangeListener(this);
    mEmojiPager.setOffscreenPageLimit(0);
    mEmojiPager.setPersistentDrawingCache(PERSISTENT_NO_CACHE);
    mEmojiLayoutParams.setPagerProperties(mEmojiPager);

    mEmojiCategoryPageIndicatorView =
            (EmojiCategoryPageIndicatorView)findViewById(R.id.emoji_category_page_id_view);
    mEmojiCategoryPageIndicatorView.setColors(
            mCategoryPageIndicatorColor, mCategoryPageIndicatorBackground);
    mEmojiLayoutParams.setCategoryPageIdViewProperties(mEmojiCategoryPageIndicatorView);

    setCurrentCategoryId(mEmojiCategory.getCurrentCategoryId(), true /* force */);

    final LinearLayout actionBar = (LinearLayout)findViewById(R.id.emoji_action_bar);
    mEmojiLayoutParams.setActionBarProperties(actionBar);

    // deleteKey depends only on OnTouchListener.
    mDeleteKey = (ImageButton)findViewById(R.id.emoji_keyboard_delete);
    mDeleteKey.setBackgroundResource(mFunctionalKeyBackgroundId);
    mDeleteKey.setTag(Constants.CODE_DELETE);
    mDeleteKey.setOnTouchListener(mDeleteKeyOnTouchListener);

    // {@link #mAlphabetKeyLeft}, {@link #mAlphabetKeyRight, and spaceKey depend on
    // {@link View.OnClickListener} as well as {@link View.OnTouchListener}.
    // {@link View.OnTouchListener} is used as the trigger of key-press, while
    // {@link View.OnClickListener} is used as the trigger of key-release which does not occur
    // if the event is canceled by moving off the finger from the view.
    // The text on alphabet keys are set at
    // {@link #startEmojiPalettes(String,int,float,Typeface)}.
    mAlphabetKeyLeft = (TextView)findViewById(R.id.emoji_keyboard_alphabet_left);
    mAlphabetKeyLeft.setBackgroundResource(mFunctionalKeyBackgroundId);
    mAlphabetKeyLeft.setTag(Constants.CODE_ALPHA_FROM_EMOJI);
    mAlphabetKeyLeft.setOnTouchListener(this);
    mAlphabetKeyLeft.setOnClickListener(this);
    mAlphabetKeyRight = (TextView)findViewById(R.id.emoji_keyboard_alphabet_right);
    mAlphabetKeyRight.setBackgroundResource(mFunctionalKeyBackgroundId);
    mAlphabetKeyRight.setTag(Constants.CODE_ALPHA_FROM_EMOJI);
    mAlphabetKeyRight.setOnTouchListener(this);
    mAlphabetKeyRight.setOnClickListener(this);
    mSpacebar = findViewById(R.id.emoji_keyboard_space);
    mSpacebar.setBackgroundResource(mSpacebarBackgroundId);
    mSpacebar.setTag(Constants.CODE_SPACE);
    mSpacebar.setOnTouchListener(this);
    mSpacebar.setOnClickListener(this);
    mEmojiLayoutParams.setKeyProperties(mSpacebar);
    mSpacebarIcon = findViewById(R.id.emoji_keyboard_space_icon);
}
 
Example 18
Project: TIS_android   File: MainActivity.java   View Source Code Vote up 4 votes
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    
    db = new DatabaseHandler(this);
    
    dataIta = cursorToArray(db.getData("Ita"));
    dataEng = cursorToArray(db.getData("Eng"));
    
    btnAddFav = (StarView) findViewById(R.id.btnAddFav);
    btnCheckFav = (StarView) findViewById(R.id.btnCheckFav);
    
    fontReg = Typeface.createFromAsset(getAssets(), "fonts/ZillaSlab-Regular.ttf");
    fontIta = Typeface.createFromAsset(getAssets(), "fonts/ZillaSlab-Italic.ttf");
    fontBold = Typeface.createFromAsset(getAssets(), "fonts/ZillaSlab-Bold.ttf");

    tvTitle = (TextView) findViewById(R.id.tvTitle);
    tvTitle.setTypeface(fontBold);
    
    btnInfo = (ToggleButton) findViewById(R.id.btnInfo);
    
    tvIta = (TextView) findViewById(R.id.tvIta);
    tvIta.setTypeface(fontIta);
    
    tvEng = (TextView) findViewById(R.id.tvEng);
    tvEng.setTypeface(fontReg);
    
    tvMain = (TextView) findViewById(R.id.tvMain);

    btnInfo.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                tvMain.setVisibility(View.INVISIBLE);
                btnAddFav.setVisibility(View.INVISIBLE);
                showInfo();
            } else {
                tvMain.setVisibility(View.VISIBLE);
                btnAddFav.setVisibility(View.VISIBLE);
                changeSays();
            }
        }
    });

    tvMain.setOnTouchListener(new OnSwipeTouchListener(MainActivity.this) {
        @Override
        public void onSwipeRight() {changeSays(); }
        @Override
        public void onSwipeLeft() { changeSays(); }
    });

    changeSays();
}