3434import android .widget .TextView ;
3535
3636import androidx .activity .OnBackPressedCallback ;
37- import androidx .activity .result .ActivityResultLauncher ;
38- import androidx .activity .result .contract .ActivityResultContracts ;
37+ import androidx .activity .result .ActivityResult ;
3938import androidx .annotation .IntDef ;
4039import androidx .annotation .MenuRes ;
4140import androidx .annotation .Nullable ;
@@ -85,8 +84,7 @@ public class ToolbarLayout extends LinearLayout {
8584 private int mLayout ;
8685 private CharSequence mTitleExpanded ;
8786 private CharSequence mTitleCollapsed ;
88- private CharSequence mSubtitleExpanded ;
89- private CharSequence mSubtitleCollapsed ;
87+ private CharSequence mSubtitle ;
9088 private Boolean mExpandable ;
9189 private Boolean mExpanded ;
9290 private SamsungAppBarLayout appBarLayout ;
@@ -131,7 +129,7 @@ public interface OnMenuItemClickListener {
131129 private ToolbarImageButton search_navButton ;
132130 private ToolbarImageButton search_action_button ;
133131 private EditText search_edittext ;
134- private ActivityResultLauncher <Intent > voiceSearchResultLauncher ;
132+ // private ActivityResultLauncher<Intent> voiceSearchResultLauncher;
135133 private SearchModeListener searchModeListener = new SearchModeListener () {
136134 public void beforeTextChanged (CharSequence s , int start , int count , int after ) {
137135 }
@@ -144,6 +142,10 @@ public void afterTextChanged(Editable s) {
144142
145143 public void onKeyboardSearchClick (CharSequence s ) {
146144 }
145+
146+ @ Override
147+ public void onVoiceInputClick (Intent intent ) {
148+ }
147149 };
148150
149151 public interface SearchModeListener {
@@ -154,6 +156,8 @@ public interface SearchModeListener {
154156 void afterTextChanged (Editable s );
155157
156158 void onKeyboardSearchClick (CharSequence s );
159+
160+ void onVoiceInputClick (Intent intent );
157161 }
158162
159163 public ToolbarLayout (Context context , @ Nullable AttributeSet attrs ) {
@@ -169,7 +173,7 @@ public ToolbarLayout(Context context, @Nullable AttributeSet attrs) {
169173 mExpanded = attr .getBoolean (R .styleable .ToolBarLayout_expanded , true );
170174 mLayout = attr .getResourceId (R .styleable .ToolBarLayout_android_layout , mExpandable ? R .layout .samsung_appbar_toolbarlayout : R .layout .samsung_toolbar_toolbarlayout );
171175 mTitleExpanded = attr .getString (R .styleable .ToolBarLayout_title );
172- mSubtitleExpanded = attr .getString (R .styleable .ToolBarLayout_subtitle );
176+ mSubtitle = attr .getString (R .styleable .ToolBarLayout_subtitle );
173177 mNavigationIcon = attr .getDrawable (R .styleable .ToolBarLayout_navigationIcon );
174178 } finally {
175179 attr .recycle ();
@@ -204,7 +208,7 @@ public ToolbarLayout(Context context, @Nullable AttributeSet attrs) {
204208 search_navButton = findViewById (R .id .toolbar_layout_search_navigationButton );
205209 search_action_button = findViewById (R .id .search_view_action_button );
206210 search_edittext = findViewById (R .id .toolbar_layout_search_field );
207- voiceSearchResultLauncher = mActivity .registerForActivityResult (new ActivityResultContracts .StartActivityForResult (), result -> {
211+ /* voiceSearchResultLauncher = mActivity.registerForActivityResult(new ActivityResultContracts.StartActivityForResult(), result -> {
208212 if (result.getResultCode() == Activity.RESULT_OK) {
209213 final ArrayList<String> matches = result.getData().getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
210214 if (!matches.isEmpty()) {
@@ -213,14 +217,14 @@ public ToolbarLayout(Context context, @Nullable AttributeSet attrs) {
213217 search_edittext.setSelection(search_edittext.getText().length());
214218 }
215219 }
216- });
220+ });*/
217221
218222 mActivity .setSupportActionBar (toolbar );
219223 mActivity .getSupportActionBar ().setDisplayShowTitleEnabled (false );
220224 mActivity .getSupportActionBar ().setDisplayHomeAsUpEnabled (false );
221225 setNavigationButtonIcon (mNavigationIcon );
222226 setTitle (mTitleExpanded );
223- setSubtitle (mSubtitleExpanded );
227+ setSubtitle (mSubtitle );
224228
225229 if (mExpandable ) {
226230 appBarLayout .addOnOffsetChangedListener (new AppBarOffsetListener ());
@@ -387,16 +391,11 @@ public void setTitle(CharSequence expandedTitle, CharSequence collapsedTitle) {
387391 }
388392
389393 public void setSubtitle (CharSequence subtitle ) {
390- setSubtitle (subtitle , subtitle );
391- }
392-
393- public void setSubtitle (CharSequence expandedSubtitle , CharSequence collapsedSubtitle ) {
394- mSubtitleCollapsed = collapsedSubtitle ;
395- mSubtitleExpanded = expandedSubtitle ;
394+ mSubtitle = subtitle ;
396395 if (mExpandable ) {
397- collapsingToolbarLayout .setSubtitle (expandedSubtitle );
396+ collapsingToolbarLayout .setSubtitle (subtitle );
398397 }
399- collapsedSubTitleView .setText (collapsedSubtitle );
398+ collapsedSubTitleView .setText (subtitle );
400399
401400 updateCollapsedSubtitleVisibility ();
402401 }
@@ -405,7 +404,7 @@ private void updateCollapsedSubtitleVisibility() {
405404 TypedValue outValue = new TypedValue ();
406405 getResources ().getValue (R .dimen .sesl_appbar_height_proportion , outValue , true );
407406 if (!mExpandable || outValue .getFloat () == 0.0 ) {
408- collapsedSubTitleView .setVisibility ((mSubtitleCollapsed != null && mSubtitleCollapsed .length () != 0 ) ? VISIBLE : GONE );
407+ collapsedSubTitleView .setVisibility ((mSubtitle != null && mSubtitle .length () != 0 ) ? VISIBLE : GONE );
409408 } else {
410409 collapsedSubTitleView .setVisibility (GONE );
411410 }
@@ -640,7 +639,8 @@ private void setSearchModeActionButton(boolean microphone) {
640639 Intent intent = new Intent ("android.speech.action.RECOGNIZE_SPEECH" );
641640 intent .putExtra ("android.speech.extra.LANGUAGE_MODEL" , "free_form" );
642641 intent .putExtra ("android.speech.extra.LANGUAGE" , Locale .getDefault ());
643- voiceSearchResultLauncher .launch (intent );
642+ //voiceSearchResultLauncher.launch(intent);
643+ searchModeListener .onVoiceInputClick (intent );
644644 });
645645 } else {
646646 search_action_button .setImageResource (R .drawable .ic_samsung_close );
@@ -649,6 +649,17 @@ private void setSearchModeActionButton(boolean microphone) {
649649 }
650650 }
651651
652+ public void onSearchModeVoiceInputResult (ActivityResult result ) {
653+ if (result .getResultCode () == Activity .RESULT_OK ) {
654+ final ArrayList <String > matches = result .getData ().getStringArrayListExtra (RecognizerIntent .EXTRA_RESULTS );
655+ if (!matches .isEmpty ()) {
656+ String Query = matches .get (0 );
657+ search_edittext .setText (Query );
658+ search_edittext .setSelection (search_edittext .getText ().length ());
659+ }
660+ }
661+ }
662+
652663
653664 //
654665 // Navigation Button methods
0 commit comments