通过以下代码片段,我一直在尝试使用 Espresso(用于自动填写用户输入字段)使用OpenID OAuth 2.0 库UiAutomator
测试登录身份验证流程,其中通过自定义 Chrome Tab 意图在外部进行登录成功登录通过启动活动的回调将用户带回应用程序,然后运行一些逻辑(通过验证在这种情况下是否显示下一个屏幕的视图来断言屏幕确实发生了变化)。但事实证明,该应用程序在登录后无法正确恢复,稍后会抛出.onActivityResult()
NoActivityResumedException
是的,我尝试过使用Espresso-Intents
,但无法弄清楚如何在这种情况下将其绑定,因为我将尽可能测试登录屏幕中的整体登录流程ActivityTestRule
,特别是触发其自己的意图(身份验证请求按下登录按钮后。我觉得到目前为止我走在正确的轨道上,所以任何帮助我指明正确方向的帮助将不胜感激!
登录屏幕:
class LoginActivity : AppCompatActivity() {
companion object {
const val RC_AUTH_LOGIN = 100
}
private lateinit var authService: AuthorizationService
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
initAuthService()
initViews()
}
override fun onDestroy() {
authService.dispose()
super.onDestroy()
}
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
super.onActivityResult(requestCode, resultCode, data)
if (resultCode == Activity.RESULT_OK) {
when (requestCode) {
RC_AUTH_LOGIN -> initViewModelAndObserve(data)
else -> …
Run Code Online (Sandbox Code Playgroud) 基于以下代码片段,我想知道如何隐藏软键(状态栏和导航栏)并在整个应用程序会话中保持沉浸模式,即使显示 AlertDialog 也是如此:
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
AlertDialog.Builder dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dialog = new AlertDialog.Builder(this);
findViewById(R.id.button).setOnClickListener(this);
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.button:
dialog.setTitle("Title");
dialog.setMessage("Message");
dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
// Dismisses dialog.
}
}).create().show(); …
Run Code Online (Sandbox Code Playgroud) android focus android-alertdialog android-statusbar android-navigation-bar
我想知道是否有办法在应用程序启动时隐藏 Android 设备的软键(状态和导航栏)?以一个游戏为例,它最初显示黑屏,同时在运行时隐藏品牌、标题和主菜单屏幕之前的软键。
我在我的 MainActivity 中包含了以下代码片段,当应用程序启动时,我最初在运行时看到一个带有软键的白屏大约一秒钟,然后当 MainActivity 的线程完成运行时软键消失:
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢一堆。
* 2017 年 1 月 19 日更新:* 包括:
<item name="android:windowFullscreen">true</item>
Run Code Online (Sandbox Code Playgroud)
...进入应用程序的主题,只有状态栏按时隐藏,而不是导航栏。我的第二篇文章 -在应用启动时立即隐藏导航栏
android runtime launch android-statusbar android-navigation-bar
我想知道是否有可能实现以下(消息线程;首先从发送者的右侧开始,而不是从接收者的一侧开始)视图:
...使用支持库中的Android约束而不是maxWidth属性,特别是对于文本气泡的宽度-我非常希望容器的宽度(由TextView以及其圆角背景以及发送者的ImageView图标组成)的宽度最多为屏幕的五分之四,然后像标准消息传递应用程序一样将下面的几行文字换行如下。因为到目前为止,我无法使用约束条件的指导来实现它,如下所示:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.constraint.Guideline
android:id="@+id/left_margin_guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.2"/>
<android.support.constraint.ConstraintLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:padding="@dimen/padding_one_half"
app:layout_constraintStart_toEndOf="@+id/left_margin_guideline"
app:layout_constraintEnd_toEndOf="parent">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/message_icon"
android:layout_width="@dimen/conversation_icon_size"
android:layout_height="@dimen/conversation_icon_size"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
tools:src="@drawable/ic_toolbar_logo"/>
<io.github.rockerhieu.emojicon.EmojiconTextView
android:id="@+id/message_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_curved_corners_message"
android:padding="@dimen/padding_one_half"
android:layout_marginRight="@dimen/padding_one_half"
android:layout_marginEnd="@dimen/padding_one_half"
app:layout_constraintEnd_toStartOf="@+id/message_icon"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
tools:text="This is a message that should wrap if it gets too long or if there is a \nnewline in the middle of the message"/>
<TextView
android:id="@+id/message_posted"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/font_small"
android:textColor="@color/colorGrayXLight"
android:layout_marginTop="@dimen/padding_one_half"
app:layout_constraintTop_toBottomOf="@+id/message_text"
app:layout_constraintEnd_toEndOf="@+id/message_text"
tools:text="2:45 PM"/>
</android.support.constraint.ConstraintLayout> …
Run Code Online (Sandbox Code Playgroud) xml android android-support-library android-constraintlayout
我想知道如何使用Java 编写游戏Mastermind代码,但事情有所提升(我想告诉用户不仅有多少钉子他们对错,还有他们在错误的插槽中猜错了多少) .
例如,假设数字1-6的5位数的RNG答案是:
22354
...而用户的猜测是:
32624
导致:
这是我的代码,用于告知用户他们的内容是正确的:
String answer = "22354";
String guess = "32624";
int correctPegs = 0;
for (int i = 0; i < 5; i++) {
char a = answer.charAt(i);
char g = guess.charAt(i);
if (a == g) {
correctPegs++;
}
}
System.out.println(correctPegs);
Run Code Online (Sandbox Code Playgroud)
我怎样才能找到部分正确的?
...并且为了计算用户猜错的数量,我在考虑使用基本代数在找到正确且部分正确的字符后找到剩余的字符.