Skip to content

[LlamaDemo] Add a button to toggle thinking mode #10667

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.core.content.res.ResourcesCompat;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import java.lang.reflect.Type;
Expand All @@ -56,6 +57,7 @@

public class MainActivity extends AppCompatActivity implements Runnable, LlmCallback {
private EditText mEditTextMessage;
private ImageButton mThinkModeButton;
private ImageButton mSendButton;
private ImageButton mGalleryButton;
private ImageButton mCameraButton;
Expand All @@ -77,6 +79,7 @@ public class MainActivity extends AppCompatActivity implements Runnable, LlmCall
private SettingsFields mCurrentSettingsFields;
private Handler mMemoryUpdateHandler;
private Runnable memoryUpdater;
private boolean mThinkMode = false;
private int promptID = 0;
private long startPos = 0;
private static final int CONVERSATION_HISTORY_MESSAGE_LOOKBACK = 2;
Expand Down Expand Up @@ -252,6 +255,7 @@ protected void onCreate(Bundle savedInstanceState) {
finish();
}

mThinkModeButton = requireViewById(R.id.thinkModeButton);
mEditTextMessage = requireViewById(R.id.editTextMessage);
mSendButton = requireViewById(R.id.sendButton);
mSendButton.setEnabled(false);
Expand All @@ -271,6 +275,28 @@ protected void onCreate(Bundle savedInstanceState) {
MainActivity.this.startActivity(myIntent);
});

mThinkModeButton.setOnClickListener(
view -> {
if (mThinkMode) {
mThinkMode = false;
mThinkModeButton.setImageDrawable(
ResourcesCompat.getDrawable(
getResources(), R.drawable.baseline_lightbulb_24, null));
} else {
mThinkMode = true;
mThinkModeButton.setImageDrawable(
ResourcesCompat.getDrawable(getResources(), R.drawable.blue_lightbulb_24, null));
}
runOnUiThread(
() -> {
String thinkingModeText = mThinkMode ? "on" : "off";
mMessageAdapter.add(
new Message(
"Thinking mode is " + thinkingModeText, false, MessageType.SYSTEM, 0));
mMessageAdapter.notifyDataSetChanged();
});
});

mCurrentSettingsFields = new SettingsFields();
mMemoryUpdateHandler = new Handler(Looper.getMainLooper());
onModelRunStopped();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#FFFFFF" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M9,21c0,0.5 0.4,1 1,1h4c0.6,0 1,-0.5 1,-1v-1L9,20v1zM12,2C8.1,2 5,5.1 5,9c0,2.4 1.2,4.5 3,5.7L8,17c0,0.5 0.4,1 1,1h6c0.6,0 1,-0.5 1,-1v-2.3c1.8,-1.3 3,-3.4 3,-5.7 0,-3.9 -3.1,-7 -7,-7z"/>

</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#6684EC" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">

<path android:fillColor="@android:color/white" android:pathData="M9,21c0,0.5 0.4,1 1,1h4c0.6,0 1,-0.5 1,-1v-1L9,20v1zM12,2C8.1,2 5,5.1 5,9c0,2.4 1.2,4.5 3,5.7L8,17c0,0.5 0.4,1 1,1h6c0.6,0 1,-0.5 1,-1v-2.3c1.8,-1.3 3,-3.4 3,-5.7 0,-3.9 -3.1,-7 -7,-7z"/>

</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,14 @@
android:padding="10dp"
android:src="@drawable/baseline_add_24" />

<ImageButton
android:id="@+id/thinkModeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:padding="10dp"
android:src="@drawable/baseline_lightbulb_24" />

<EditText
android:id="@+id/editTextMessage"
android:layout_width="match_parent"
Expand Down
Loading