Search in sources :

Example 96 with ScrollView

use of android.widget.ScrollView in project snips-platform-android-demo by snipsco.

the class MainActivity method startMegazordService.

private void startMegazordService() {
    if (client == null) {
        // a dir where the assistant models was unziped. it should contain the folders asr dialogue hotword and nlu
        File assistantDir = new File(Environment.getExternalStorageDirectory().toString(), "snips_android_assistant");
        client = new SnipsPlatformClient.Builder(assistantDir).enableDialogue(// defaults to true
        true).enableHotword(// defaults to true
        true).enableSnipsWatchHtml(// defaults to false
        true).enableLogs(// defaults to false
        true).withHotwordSensitivity(// defaults to 0.5
        0.5f).enableStreaming(// defaults to false
        true).build();
        client.setOnPlatformReady(new Function0<Unit>() {

            @Override
            public Unit invoke() {
                runOnUiThread(new Runnable() {

                    @Override
                    public void run() {
                        findViewById(R.id.loadingPanel).setVisibility(View.GONE);
                        findViewById(R.id.scrollView).setVisibility(View.VISIBLE);
                        final Button button = findViewById(R.id.start);
                        button.setEnabled(true);
                        button.setText(R.string.start_dialog_session);
                        button.setOnClickListener(new OnClickListener() {

                            @Override
                            public void onClick(View view) {
                                // programmatically start a dialogue session
                                client.startSession(null, new ArrayList<String>(), false, null);
                            }
                        });
                    }
                });
                return null;
            }
        });
        client.setOnHotwordDetectedListener(new Function0<Unit>() {

            @Override
            public Unit invoke() {
                Log.d(TAG, "an hotword was detected !");
                // Do your magic here :D
                return null;
            }
        });
        client.setOnIntentDetectedListener(new Function1<IntentMessage, Unit>() {

            @Override
            public Unit invoke(IntentMessage intentMessage) {
                Log.d(TAG, "received an intent: " + intentMessage);
                // Do your magic here :D
                // For now, lets just use a random sentence to tell the user we understood but don't know what to do
                List<String> answers = Arrays.asList("This is only a demo app. I understood you but I don't know how to do that", "Can you teach me how to do that?", "Oops! This action has not be coded yet!", "Yes Master! ... hum, ..., er, ... imagine this as been done", "Let's pretend I've done it! OK?");
                client.endSession(intentMessage.getSessionId(), answers.get(Math.abs(ThreadLocalRandom.current().nextInt()) % answers.size()));
                return null;
            }
        });
        client.setOnListeningStateChangedListener(new Function1<Boolean, Unit>() {

            @Override
            public Unit invoke(Boolean isListening) {
                Log.d(TAG, "asr listening state: " + isListening);
                // Do you magic here :D
                return null;
            }
        });
        client.setOnSessionStartedListener(new Function1<SessionStartedMessage, Unit>() {

            @Override
            public Unit invoke(SessionStartedMessage sessionStartedMessage) {
                Log.d(TAG, "dialogue session started: " + sessionStartedMessage);
                return null;
            }
        });
        client.setOnSessionQueuedListener(new Function1<SessionQueuedMessage, Unit>() {

            @Override
            public Unit invoke(SessionQueuedMessage sessionQueuedMessage) {
                Log.d(TAG, "dialogue session queued: " + sessionQueuedMessage);
                return null;
            }
        });
        client.setOnSessionEndedListener(new Function1<SessionEndedMessage, Unit>() {

            @Override
            public Unit invoke(SessionEndedMessage sessionEndedMessage) {
                Log.d(TAG, "dialogue session ended: " + sessionEndedMessage);
                return null;
            }
        });
        // This api is really for debugging purposes and you should not have features depending on its output
        // If you need us to expose more APIs please do ask !
        client.setOnSnipsWatchListener(new Function1<String, Unit>() {

            public Unit invoke(final String s) {
                runOnUiThread(new Runnable() {

                    public void run() {
                        // We enabled html logs in the builder, hence the fromHtml. If you only log to the console,
                        // or don't want colors to be displayed, do not enable the option
                        ((EditText) findViewById(R.id.text)).append(Html.fromHtml(s + "<br />"));
                        findViewById(R.id.scrollView).post(new Runnable() {

                            @Override
                            public void run() {
                                ((ScrollView) findViewById(R.id.scrollView)).fullScroll(View.FOCUS_DOWN);
                            }
                        });
                    }
                });
                return null;
            }
        });
        // We enabled steaming in the builder, so we need to provide the platform an audio stream. If you don't want
        // to manage the audio stream do no enable the option, and the snips platform will grab the mic by itself
        startStreaming();
        client.connect(this.getApplicationContext());
    }
}
Also used : EditText(android.widget.EditText) SessionEndedMessage(ai.snips.hermes.SessionEndedMessage) ArrayList(java.util.ArrayList) IntentMessage(ai.snips.hermes.IntentMessage) SessionQueuedMessage(ai.snips.hermes.SessionQueuedMessage) Unit(kotlin.Unit) View(android.view.View) ScrollView(android.widget.ScrollView) Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) SessionStartedMessage(ai.snips.hermes.SessionStartedMessage) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Example 97 with ScrollView

use of android.widget.ScrollView in project snips-platform-android-demo by snipsco.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ensurePermissions();
    findViewById(R.id.start).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            if (ensurePermissions()) {
                final Button button = (Button) findViewById(R.id.start);
                button.setEnabled(false);
                button.setText(R.string.loading);
                final View scrollView = findViewById(R.id.scrollView);
                scrollView.setVisibility(View.GONE);
                final View loadingPanel = findViewById(R.id.loadingPanel);
                loadingPanel.setVisibility(View.VISIBLE);
                startMegazordService();
            }
        }
    });
}
Also used : Button(android.widget.Button) OnClickListener(android.view.View.OnClickListener) View(android.view.View) ScrollView(android.widget.ScrollView)

Example 98 with ScrollView

use of android.widget.ScrollView in project qksms by moezbhatti.

the class MMSDialogFragment method onCreateDialog.

/**
 * Builds the dialog using all the View parameters.
 */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Dialog dialog = new Dialog(mContext);
    Window window = dialog.getWindow();
    window.requestFeature(Window.FEATURE_NO_TITLE);
    window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    LayoutInflater inflater = getActivity().getLayoutInflater();
    View view = inflater.inflate(R.layout.dialog_material, null);
    if (mTitleEnabled || mMessageEnabled) {
        mContentPanel = (LinearLayout) view.findViewById(R.id.contentPanel);
        mContentPanel.setVisibility(View.VISIBLE);
    }
    if (mTitleEnabled) {
        mTitleView = (QKTextView) view.findViewById(R.id.alertTitle);
        mTitleView.setVisibility(View.VISIBLE);
        mTitleView.setText(mTitleText);
    }
    if (mMessageEnabled) {
        mMessageView = (QKTextView) view.findViewById(R.id.message);
        mMessageView.setVisibility(View.VISIBLE);
        mMessageView.setText(mMessageText);
    }
    if (mCustomViewEnabled) {
        mCustomPanel = (LinearLayout) view.findViewById(R.id.customPanel);
        mCustomPanel.setVisibility(View.VISIBLE);
        if (mCustomView instanceof ListView) {
            mCustomPanel.addView(mCustomView);
        } else {
            ScrollView scrollView = new ScrollView(mContext);
            scrollView.addView(mCustomView);
            mCustomPanel.addView(scrollView);
        }
    }
    if (mPositiveButtonEnabled || mNeutralButtonEnabled || mNegativeButtonEnabled) {
        mButtonBar = (LinearLayout) view.findViewById(R.id.buttonPanel);
        mButtonBar.setVisibility(View.VISIBLE);
        mButtonBar.setOrientation(mButtonBarOrientation);
    }
    if (mPositiveButtonEnabled) {
        mPositiveButtonView = (QKTextView) view.findViewById(R.id.buttonPositive);
        mPositiveButtonView.setVisibility(View.VISIBLE);
        mPositiveButtonView.setText(mPositiveButtonText);
        mPositiveButtonView.setTextColor(ThemeManager.getColor());
        mPositiveButtonView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                onResult(POSITIVE_BUTTON_RESULT);
            }
        });
    }
    if (mNeutralButtonEnabled) {
        mNeutralButtonView = (QKTextView) view.findViewById(R.id.buttonNeutral);
        mNeutralButtonView.setVisibility(View.VISIBLE);
        mNeutralButtonView.setText(mNeutralButtonText);
        mNeutralButtonView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                onResult(NEUTRAL_BUTTON_RESULT);
            }
        });
    }
    if (mNegativeButtonEnabled) {
        mNegativeButtonView = (QKTextView) view.findViewById(R.id.buttonNegative);
        mNegativeButtonView.setVisibility(View.VISIBLE);
        mNegativeButtonView.setText(mNegativeButtonText);
        mNegativeButtonView.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                onResult(NEGATIVE_BUTTON_RESULT);
            }
        });
    }
    dialog.setContentView(view);
    return dialog;
}
Also used : Window(android.view.Window) ListView(android.widget.ListView) ColorDrawable(android.graphics.drawable.ColorDrawable) ScrollView(android.widget.ScrollView) Dialog(android.app.Dialog) LayoutInflater(android.view.LayoutInflater) QKTextView(com.moez.QKSMS.ui.view.QKTextView) ScrollView(android.widget.ScrollView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView)

Example 99 with ScrollView

use of android.widget.ScrollView in project qksms by moezbhatti.

the class SlideView method enableMMSConformanceMode.

/**
 * Makes the SlideView working on  MMSConformance Mode. The view will be
 * re-layout to the linear view.
 * <p>
 * This is Chinese requirement about mms conformance.
 * The most popular Mms service in China is newspaper which is MMS conformance,
 * normally it mixes the image and text and has a number of slides. The
 * AbsoluteLayout doesn't have good user experience for this kind of message,
 * for example,
 *
 * 1. AbsoluteLayout exactly follows the smil's layout which is not optimized,
 * and actually, no other MMS applications follow the smil's layout, they adjust
 * the layout according their screen size. MMS conformance doc also allows the
 * implementation to adjust the layout.
 *
 * 2. The TextView is fixed in the small area of screen, and other part of screen
 * is empty once there is no image in the current slide.
 *
 * 3. The TextView is scrollable in a small area of screen and the font size is
 * small which make the user experience bad.
 *
 * The better UI for the MMS conformance message could be putting the image/video
 * and text in a linear layout view and making them scrollable together.
 *
 * Another reason for only applying the LinearLayout to the MMS conformance message
 * is that the AbsoluteLayout has ability to play image and video in a same screen.
 * which shouldn't be broken.
 */
public void enableMMSConformanceMode(int textLeft, int textTop, int imageLeft, int imageTop) {
    mConformanceMode = true;
    if (mScrollViewPort == null) {
        mScrollViewPort = new ScrollView(mContext) {

            private int mBottomY;

            @Override
            protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
                super.onLayout(changed, left, top, right, bottom);
                if (getChildCount() > 0) {
                    int childHeight = getChildAt(0).getHeight();
                    int height = getHeight();
                    mBottomY = height < childHeight ? childHeight - height : 0;
                }
            }

            @Override
            protected void onScrollChanged(int l, int t, int oldl, int oldt) {
                // Shows MediaController when the view is scrolled to the top/bottom of itself.
                if (t == 0 || t >= mBottomY) {
                    if (mMediaController != null && !((SlideshowActivity) mContext).isFinishing()) {
                        mMediaController.show();
                    }
                }
            }
        };
        mScrollViewPort.setScrollBarStyle(SCROLLBARS_INSIDE_OVERLAY);
        mViewPort = new LinearLayout(mContext);
        mViewPort.setOrientation(LinearLayout.VERTICAL);
        mViewPort.setGravity(Gravity.CENTER);
        mViewPort.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                if (mMediaController != null) {
                    mMediaController.show();
                }
            }
        });
        mScrollViewPort.addView(mViewPort, new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        addView(mScrollViewPort);
    }
    // Layout views to fit the LinearLayout from left to right, then top to
    // bottom.
    TreeMap<Position, View> viewsByPosition = new TreeMap<>(new Comparator<Position>() {

        public int compare(Position p1, Position p2) {
            int l1 = p1.mLeft;
            int t1 = p1.mTop;
            int l2 = p2.mLeft;
            int t2 = p2.mTop;
            int res = t1 - t2;
            if (res == 0) {
                res = l1 - l2;
            }
            if (res == 0) {
                // A view will be lost if return 0.
                return -1;
            }
            return res;
        }
    });
    if (textLeft >= 0 && textTop >= 0) {
        mTextView = new TextView(mContext);
        mTextView.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
        mTextView.setTextSize(18);
        mTextView.setPadding(5, 5, 5, 5);
        viewsByPosition.put(new Position(textLeft, textTop), mTextView);
    }
    if (imageLeft >= 0 && imageTop >= 0) {
        mImageView = new ImageView(mContext);
        mImageView.setPadding(0, 5, 0, 5);
        viewsByPosition.put(new Position(imageLeft, imageTop), mImageView);
        // According MMS Conformance Document, the image and video should use the same
        // region. So, put the VideoView below the ImageView.
        mVideoView = new VideoView(mContext);
        viewsByPosition.put(new Position(imageLeft + 1, imageTop), mVideoView);
    }
    for (View view : viewsByPosition.values()) {
        if (view instanceof VideoView) {
            mViewPort.addView(view, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutManager.getInstance().getLayoutParameters().getHeight()));
        } else {
            mViewPort.addView(view, new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
        }
        view.setVisibility(View.GONE);
    }
}
Also used : VideoView(android.widget.VideoView) TreeMap(java.util.TreeMap) ImageView(android.widget.ImageView) View(android.view.View) VideoView(android.widget.VideoView) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) ScrollView(android.widget.ScrollView) FrameLayout(android.widget.FrameLayout) TextView(android.widget.TextView) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout)

Example 100 with ScrollView

use of android.widget.ScrollView in project instructure-android by instructure.

the class RecipientEditTextView method onSizeChanged.

@Override
public void onSizeChanged(int width, int height, int oldw, int oldh) {
    super.onSizeChanged(width, height, oldw, oldh);
    if (width != 0 && height != 0) {
        checkChipWidths();
    }
    // Try to find the scroll view parent, if it exists.
    if (mScrollView == null && !mTriedGettingScrollView) {
        ViewParent parent = getParent();
        while (parent != null && !(parent instanceof ScrollView)) {
            parent = parent.getParent();
        }
        if (parent != null) {
            mScrollView = (ScrollView) parent;
        }
        mTriedGettingScrollView = true;
    }
}
Also used : ScrollView(android.widget.ScrollView) ViewParent(android.view.ViewParent)

Aggregations

ScrollView (android.widget.ScrollView)363 View (android.view.View)173 TextView (android.widget.TextView)149 LinearLayout (android.widget.LinearLayout)93 ImageView (android.widget.ImageView)65 ViewGroup (android.view.ViewGroup)53 Button (android.widget.Button)36 EditText (android.widget.EditText)36 ListView (android.widget.ListView)29 RecyclerView (android.support.v7.widget.RecyclerView)25 Intent (android.content.Intent)24 AbsListView (android.widget.AbsListView)24 AdapterView (android.widget.AdapterView)24 GridLayout (android.widget.GridLayout)24 ArrayList (java.util.ArrayList)21 SuppressLint (android.annotation.SuppressLint)20 WebView (android.webkit.WebView)19 FrameLayout (android.widget.FrameLayout)19 Dialog (android.app.Dialog)17 DialogInterface (android.content.DialogInterface)16