UI not refreshed after first toggle the sliding menu on Android 5.0 lollipop
Asked Answered
A

3

6

I have a ResponsiveUIActivity which extends SlidingFragmentActivity. My application works perfectly below android version 5.0. But my UI is not refreshed and not clickable when I first toggle the sliding menu. For example, I can not scroll the ListView or write something on EditText after first toggle. If I toggle the sliding menu, the UI is refreshed and I can see the changes. How can I solve this problem?

ResponsiveUIActivity.java

public class ResponsiveUIActivity extends SlidingFragmentActivity {
    private Fragment mContent;
    public static ResponsiveUIActivity rootActivity;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setTitle(R.string.responsive_ui);
        setContentView(R.layout.responsive_content_frame);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);

        rootActivity = this;

        // startNotificationService();

        // check if the content frame contains the menu frame
        if (findViewById(R.id.menu_frame) == null) {
            setBehindContentView(R.layout.menu_frame);
            getSlidingMenu().setSlidingEnabled(true);
            getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);

            // show home as up so we can toggle
            getActionBar().setDisplayHomeAsUpEnabled(false);
            getActionBar().setDisplayShowHomeEnabled(false);
        } else {
            // add a dummy view
            View v = new View(this);
            setBehindContentView(v);
            getSlidingMenu().setSlidingEnabled(false);
            getSlidingMenu().setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
        }

        // set the Above View Fragment
        if (savedInstanceState != null)
            mContent = getSupportFragmentManager().getFragment(
                    savedInstanceState, "mContent");
        if (mContent == null)
            mContent = new NewsFragment();

        // customize the SlidingMenu
        SlidingMenu sm = getSlidingMenu();
        sm.setBehindOffsetRes(R.dimen.slidingmenu_offset);
        sm.setShadowWidthRes(R.dimen.shadow_width);
        sm.setShadowDrawable(R.drawable.shadow);
        sm.setBehindScrollScale(0.25f);
        sm.setFadeDegree(0.25f);

        sm.setOnOpenedListener(new SlidingMenu.OnOpenedListener() {
            @Override
            public void onOpened() {
                Log.d("ToggleMenu", "onOpened");
            }
        });
        sm.setOnCloseListener(new SlidingMenu.OnCloseListener() {
            @Override
            public void onClose() {
                Log.d("ToggleMenu", "onClose");
            }
        });

        getSupportFragmentManager().beginTransaction()
                .replace(R.id.content_frame, mContent).commit();

        // set the Behind View Fragment
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.menu_frame,
                        new MenuFragment((ResponsiveUIActivity) rootActivity))
                .commit();

        // hide app icon from actionBar
        getActionBar().setIcon(android.R.color.transparent);
        getActionBar().setTitle("");

        /*
         * // show the explanation dialog if (savedInstanceState == null) new
         * AlertDialog.Builder(this) .setTitle(R.string.what_is_this)
         * .setMessage(R.string.responsive_explanation) .show();
         */
    }

    private void startNotificationService() {
        // TODO Auto-generated method stub
        // Intent intent = new Intent(rootActivity, NotificationService.class);
        // startService(intent);
    }

    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
        case android.R.id.home:
            toggle();
        }
        return super.onOptionsItemSelected((android.view.MenuItem) item);
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        getSupportFragmentManager().putFragment(outState, "mContent", mContent);
    }

    public void switchContent(final Fragment fragment) {
        mContent = fragment;
        getSupportFragmentManager().beginTransaction()
                .replace(R.id.content_frame, fragment).commit();
        Handler h = new Handler();
        h.postDelayed(new Runnable() {
            public void run() {
                getSlidingMenu().showContent();
            }
        }, 50);
    }

    @Override
    public void onBackPressed() {
        Log.v("SignUp", "onbackPressed !!!!!!");
        toggle();
    }

    public void finishActivity() {
        super.onBackPressed();
    }

}

MenuFragment.java

@SuppressLint("ValidFragment")
public class MenuFragment extends Fragment {

    LinearLayout newsClick, profileClick, adsClick, companyClick, wsClick,
            contactsClick, contactClick, backClick, settingsClick;
    ResponsiveUIActivity rootActivity;

    public MenuFragment(ResponsiveUIActivity rootActivity) {
        // TODO Auto-generated constructor stub
        this.rootActivity = rootActivity;
    }

    public MenuFragment() {
        super();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View v;

        if (PublicSharedPreferences.getDefaults(Constants.language,
                getActivity()).equals("T")) {
            v = inflater.inflate(R.layout.list_tr, null);
        } else {
            v = inflater.inflate(R.layout.list, null);
        }

        addMenuButtons(v);

        return v;
    }

    private void addMenuButtons(View v) {

        newsClick = (LinearLayout) v.findViewById(R.id.newsClick);
        newsClick.setOnClickListener(onclick);

        profileClick = (LinearLayout) v.findViewById(R.id.profileClick);
        profileClick.setOnClickListener(onclick);

        adsClick = (LinearLayout) v.findViewById(R.id.adsClick);
        adsClick.setOnClickListener(onclick);

        companyClick = (LinearLayout) v.findViewById(R.id.companyClick);
        companyClick.setOnClickListener(onclick);

        wsClick = (LinearLayout) v.findViewById(R.id.wsClick);
        wsClick.setOnClickListener(onclick);

        contactsClick = (LinearLayout) v.findViewById(R.id.contactsClick);
        contactsClick.setOnClickListener(onclick);

        contactClick = (LinearLayout) v.findViewById(R.id.contactClick);
        contactClick.setOnClickListener(onclick);

        backClick = (LinearLayout) v.findViewById(R.id.backClick);
        backClick.setOnClickListener(onclick);

        settingsClick = (LinearLayout) v.findViewById(R.id.settingsClick);
        settingsClick.setOnClickListener(onclick);

    }

    OnClickListener onclick = new OnClickListener() {
        Fragment newContent = null;

        @Override
        public void onClick(View v) {
            switch (v.getId()) {
            case R.id.newsClick:
                newContent = new NewsFragment();
                break;

            case R.id.profileClick:
                newContent = new ProfileFragment();
                break;

            case R.id.adsClick:
                newContent = new RecruitmentAdsFragment();
                break;

            case R.id.companyClick:
                newContent = new CompanyProfileFragment();
                break;

            case R.id.wsClick:
                newContent = new WsFragment();
                break;

            case R.id.contactsClick:
                newContent = new ContactsFragment();
                break;

            case R.id.contactClick:
                newContent = new ContactFragment();
                break;

            case R.id.backClick:

                PublicSharedPreferences.removeDefaults(Constants.token,
                        getActivity().getApplicationContext());
                PublicSharedPreferences.removeDefaults(Constants.TURKISH_ID,
                        getActivity().getApplicationContext());

                if (PublicSharedPreferences.getDefaults(
                        Constants.TAG_NATIONALITY, getActivity()
                                .getApplicationContext()) != null) {
                    PublicSharedPreferences.removeDefaults(
                            Constants.TAG_NATIONALITY, getActivity()
                                    .getApplicationContext());
                }

                if (PublicSharedPreferences.getDefaults(
                        Constants.TAG_EXPERIENCE, getActivity()
                                .getApplicationContext()) != null) {
                    PublicSharedPreferences.removeDefaults(
                            Constants.TAG_EXPERIENCE, getActivity()
                                    .getApplicationContext());
                }

                if (PublicSharedPreferences.getDefaults(
                        Constants.TAG_DATE_OF_BIRTH, getActivity()
                                .getApplicationContext()) != null) {
                    PublicSharedPreferences.removeDefaults(
                            Constants.TAG_DATE_OF_BIRTH, getActivity()
                                    .getApplicationContext());
                }

                rootActivity.finishActivity();
                Intent preLoginIntent = new Intent(getActivity(),
                        PreLoginActivity.class);
                preLoginIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP
                        | Intent.FLAG_ACTIVITY_SINGLE_TOP);
                startActivity(preLoginIntent);
                getActivity().overridePendingTransition(
                        R.anim.animated_activity_slide_left_in,
                        R.anim.animated_activity_slide_right_out);

                break;

            case R.id.settingsClick:
                Log.v("Tekfen", "Settings");

                newContent = new SettingsFragment();
                break;

            default:
                break;
            }

            if (newContent != null)
                switchFragment(newContent);

        }
    };

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

    }

    // the meat of switching the above fragment private void
    public void switchFragment(Fragment fragment) {
        if (getActivity() == null)
            return;

        if (getActivity() instanceof ResponsiveUIActivity) {
            ResponsiveUIActivity ra = (ResponsiveUIActivity) getActivity();
            ra.switchContent(fragment);
        }
    }

}

styles.xml

<?xml version="1.0" encoding="utf-8"?>

<style name="ExampleTheme" parent="Theme.Sherlock.Light.DarkActionBar">
    <item name="homeAsUpIndicator">@drawable/new_indicator</item>
    <item name="android:homeAsUpIndicator">@drawable/new_indicator</item>
</style>

<style name="AppTheme" parent="@style/Theme.Sherlock">
    <item name="actionBarStyle">@style/AppTheme.ActionBar</item>
    <item name="android:actionBarStyle">@style/AppTheme.ActionBar</item>
    <item name="homeAsUpIndicator">@drawable/new_indicator</item>
    <item name="android:homeAsUpIndicator">@drawable/new_indicator</item>
    <item name="android:actionBarItemBackground">@android:color/transparent</item>
    <item name="actionBarItemBackground">@android:color/transparent</item>
    <item name="android:actionBarSize">100dp</item>
    <item name="android:windowActionBarOverlay">true</item>
    <item name="android:activatedBackgroundIndicator">@drawable/activated_background</item>
    <item name="activatedBackgroundIndicator">@drawable/activated_background</item>
</style>

<style name="AppTheme.ActionBar" parent="@style/Widget.Sherlock.ActionBar">
    <item name="android:background">@android:color/transparent</item>
    <item name="background">@android:color/transparent</item>
</style>

<style name="ProgressHUD" parent="@android:style/Theme.Dialog">
    <item name="android:windowFrame">@null</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowNoTitle">true</item>
</style>

<style name="list_view_divider">
    <item name="android:divider">#F0F0F0</item>
    <item name="android:dividerHeight">1dp</item>
</style>

Arthromere answered 17/2, 2015 at 14:5 Comment(3)
I have the exact same problem. I have tried almost everything. It seems that slidingMenu is affecting the fragments. Did you solve it?Contraoctave
Did your problem solved yet ? @ContraoctaveFelipa
I got the cause , you can check my answer belowFelipa
F
7

I've had the same problem but I've managed to solve this. The actual problem lies in a defect is regarding hardware acceleration so if you put in your AndroidManifest that your application is hardwareAccelerated="true" your problem will be solved.

Felipa answered 17/3, 2015 at 13:45 Comment(0)
C
1

I finally found the solution! Just set the targetSdkVersion tag inside manifest to 21.

Contraoctave answered 7/3, 2015 at 22:31 Comment(0)
P
1

Try to change line 1005:

boolean layer = percentOpen > 0.0f && percentOpen < 1.0f;

to

boolean layer = percentOpen >= 0.0f && percentOpen <= 1.0f;

in SlidingMenu.java

Pendent answered 17/4, 2015 at 15:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.