Android TextView actionbar works inconsistently

453 views Asked by At

I have an app about studying sacred Indian texts usually consisting of a verse and a commentary to this verse. To open it up I use DisplayText activity which has an ActionBar popping up when user selects some text from either a verse or its commentary.

My problem is that it works inconsistently - on my Samsung Galaxy Note 2 it works OK, but on sony xperia Z2 once I try to touch the action button it exits the action bar and nothing happens.

Samsung's Android version is 4.4.2 and Sony's version 4.4.4

Please check out this very short video for Sony device and also how it works for samsung device Please note that there are no error messages being shown in the LogCat view.

I would appreciate any suggestions on how I could possibly fix this problem Also any ways to get a work around would be much appreciated as well.

public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        //Log.v("DEBUG", "DisplaTEXT onCreate - Starting Activity");
        try
        {
             m_context=this;
         mtxtTransl2View.setCustomSelectionActionModeCallback(new CustomTextSelectCallback(mtxtTransl2View, false));
                     mtxtComment.setCustomSelectionActionModeCallback(new CustomTextSelectCallback(mtxtComment, true));

        }
        catch(Exception e)
        {
            e.printStackTrace();
        }

    }


@SuppressLint("NewApi")
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
class CustomTextSelectCallback implements ActionMode.Callback {
    public CustomTextSelectCallback(TextView tv, boolean b) {
        mTextView=tv;
        mbPurport=b;
    }

    //flag that selection is made in the purport, otherwise it is in shloka or translit

    private TextView mTextView;
    private boolean mbPurport;


    public boolean onCreateActionMode(ActionMode mode, Menu menu) {
        //Log.d(TAG, "onCreateActionMode");
        //if(mbPurport)
        { 
            MenuInflater inflater = mode.getMenuInflater();
            inflater.inflate(R.menu.text_selection_menu, menu);

            MenuItem item = menu.findItem(R.id.cab_menu_fb);
            ShareActionProvider actionProvider = (ShareActionProvider)item.getActionProvider();

            actionProvider.setShareIntent(createShareIntent());             

            actionProvider.setOnShareTargetSelectedListener(new OnShareTargetSelectedListener(){
                public boolean onShareTargetSelected(ShareActionProvider source, Intent intent) 
                {

                    try
                    {
                        getShareSubject("Share Subject","Please describe why would you like to share this (optional):");
                    }

                    catch(Throwable e)
                    {
                        String err="Error11: " + e.getMessage();
                        Toast.makeText(getApplicationContext(), err, Toast.LENGTH_LONG).show();
                    }       

                    if(mShareSubj.equals(SUBJ_CANCEL)) return false;

                    int start = mTextView.getSelectionStart();
                    int end = mTextView.getSelectionEnd();          
                    int tvID=mTextView.getId();
                    String sPlaceType = (tvID==R.id.textTransl2) ? "t":"p";
                    mTextURL=mTextURL+"?t="+sPlaceType+"&s="+start+"&e="+end;

                    mANText=mTextView.getText().subSequence(start, end).toString();

                    if ("com.facebook.katana".equals(intent.getComponent().getPackageName()) ) 
                    {
                        //mfacebooksharer.shareStatus(subject, text);
                        // Toast.makeText(this, "Facebook sharing", Toast.LENGTH_LONG).show();
                        shareOnFacebook();
                        return false;
                    }
                    else
                    {
                        if(!MyApp.mC.hasFlag(Cookies.FL_Sharing, m_context))   
                            return true;
                        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                        intent.putExtra(android.content.Intent.EXTRA_TEXT,   getShareBody(intent));
                        intent.putExtra(android.content.Intent.EXTRA_SUBJECT, mShareSubj);

                        getApplicationContext().startActivity(intent);

                        return true;
                    }


                }

            });
        }

        return true;
    }

    public boolean onPrepareActionMode(ActionMode mode, Menu menu) {

        return false;
    }

    public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
        //Log.d(TAG, String.format("onActionItemClicked item=%s/%d", item.toString(), item.getItemId()));

        int start = mTextView.getSelectionStart();
        int end = mTextView.getSelectionEnd();
        long note_id=-1;

        mANPlace=UserDataSQLHelper.NOTE_PLACE_TEXT;
        mANText=mTextView.getText().subSequence(start, end).toString();
        if(mbPurport) 
            mANPlace=UserDataSQLHelper.NOTE_PLACE_COMM;

        mANStartPos=start; 
        mANEndPos=end;
        mScrollPos = mScrollT.getScrollY();

        switch(item.getItemId()) {

        case R.id.cab_menu_fav:

            if(!MyApp.mC.hasFlag(Cookies.FL_TextHighlight, m_context)) return false;

            note_id=MyApp.mUserDB.addNote(m_dbtype, m_dblang, mCurrBookID, mCurrSong, mCurrChapterNum, mCurrTextNum, mRowID, UserDataSQLHelper.NOTE_TYPE_HIGHL, mANPlace, start, end, mScrollPos,
                    mANText, "", "");

            break;
        case R.id.cab_menu_comment: 
            if(!MyApp.mC.hasFlag(Cookies.FL_TextHighlightAddCommentsQuestions, m_context)) return false;

            Intent intent = new Intent(getApplicationContext(), NoteEditor.class);
            intent.putExtra("NOTEEDIT_ACTION", NoteEditor.ACTION_ADD);
            intent.putExtra("NOTEEDIT_TITLE", "Add Question or Note");

            startActivityForResult(intent, SUBACT_ADDEDITNOTE);
            break;

        }
        if (note_id!=-1){ 
            ReloadText();
            AddTags(note_id);
        }
        return false;
    }

    public void onDestroyActionMode(ActionMode mode) {
    }
}

Text selection menu xml code is here:

<menu xmlns:android="http://schemas.android.com/apk/res/android" >


       <item
        android:id="@+id/cab_menu_fb"
        android:orderInCategory="10"
        android:showAsAction="always"
        android:icon="@drawable/cab_facebook"
        android:actionProviderClass="android.widget.ShareActionProvider"
        android:title="@string/cab_menu_fb"/>

    <item
        android:id="@+id/cab_menu_fav"
        android:orderInCategory="20"
        android:showAsAction="ifRoom"
        android:icon="@drawable/cab_highl"
        android:title="@string/cab_menu_fav"/>


      <item
        android:id="@+id/cab_menu_comment"
        android:orderInCategory="30"
        android:showAsAction="ifRoom"
        android:icon="@drawable/cab_comment"
        android:title="@string/cab_menu_comment"/>

</menu>
0

There are 0 answers