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());
}
}
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();
}
}
});
}
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;
}
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);
}
}
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;
}
}
Aggregations