Example usage for android.view ViewGroup PERSISTENT_ALL_CACHES

List of usage examples for android.view ViewGroup PERSISTENT_ALL_CACHES

Introduction

In this page you can find the example usage for android.view ViewGroup PERSISTENT_ALL_CACHES.

Prototype

int PERSISTENT_ALL_CACHES

To view the source code for android.view ViewGroup PERSISTENT_ALL_CACHES.

Click Source Link

Document

Used to indicate that all drawing caches should be kept in memory.

Usage

From source file:com.ryan.ryanreader.fragments.PostListingFragment.java

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

    super.onCreateView(inflater, container, savedInstanceState);
    final Context context = container.getContext();
    sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);

    final LinearLayout outer = new LinearLayout(context) {
        @Override// ww  w. j  av  a 2s .  c o m
        protected void onAttachedToWindow() {
            super.onAttachedToWindow();
            getLayoutParams().height = ViewGroup.LayoutParams.FILL_PARENT;
        }
    };

    outer.setOrientation(android.widget.LinearLayout.VERTICAL);

    fragmentHeader = createVerticalLinearLayout(context);
    final LinearLayout listHeader = createVerticalLinearLayout(context);
    listHeaderNotifications = createVerticalLinearLayout(context);
    listFooterNotifications = createVerticalLinearLayout(context);

    if (subreddit.isReal()) {
        final SubredditHeader subredditHeader = new SubredditHeader(context, subreddit);
        listHeader.addView(subredditHeader);
    }

    listHeader.addView(listHeaderNotifications);

    lv = (ListView) inflater.inflate(R.layout.reddit_post_list);
    lv.setOnScrollListener(this);
    lv.addHeaderView(listHeader);
    lv.addFooterView(listFooterNotifications, null, false);

    lv.setPersistentDrawingCache(ViewGroup.PERSISTENT_ALL_CACHES);
    lv.setAlwaysDrawnWithCacheEnabled(true);

    adapter = new PostListingAdapter(lv, this);
    lv.setAdapter(adapter);

    final ListOverlayView lov = new ListOverlayView(context, lv);

    outer.addView(fragmentHeader);
    outer.addView(lov);

    lv.getLayoutParams().height = ViewGroup.LayoutParams.FILL_PARENT;

    request = new PostListingRequest(url, RedditAccountManager.getInstance(context).getDefaultAccount(),
            session, downloadType, true);

    CacheManager.getInstance(context).makeRequest(request);

    return outer;
}

From source file:org.lol.reddit.fragments.PostListingFragment.java

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

    super.onCreateView(inflater, container, savedInstanceState);
    final Context context = container.getContext();
    sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);

    final LinearLayout outer = new LinearLayout(context) {
        @Override/*from   w w w. j a v  a  2  s  .  c  o m*/
        protected void onAttachedToWindow() {
            super.onAttachedToWindow();
            getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
        }
    };

    outer.setOrientation(android.widget.LinearLayout.VERTICAL);

    fragmentHeader = createVerticalLinearLayout(context);

    // TODO output failed URL
    if (postListingURL == null) {
        fragmentHeader.addView(new ErrorView(getSupportActivity(),
                new RRError("Invalid post listing URL", "Could not navigate to that URL.")));
        return outer;
    }

    listHeader = createVerticalLinearLayout(context);
    listHeaderNotifications = createVerticalLinearLayout(context);
    listFooterNotifications = createVerticalLinearLayout(context);

    downloadPostCount = PrefsUtility.pref_behaviour_post_count(context, sharedPrefs);
    restackRefreshCount();
    loadMoreView = (TextView) LayoutInflater.from(context).inflate(R.layout.load_more_posts, null);
    loadMoreView.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            listFooterNotifications.removeView(loadMoreView);
            restackRefreshCount();
            onLoadMoreItemsCheck();
        }
    });

    listHeader.addView(listHeaderNotifications);

    lv = (ListView) inflater.inflate(R.layout.reddit_post_list);
    lv.setOnScrollListener(this);
    lv.addHeaderView(listHeader);
    lv.addFooterView(listFooterNotifications, null, true);

    lv.setPersistentDrawingCache(ViewGroup.PERSISTENT_ALL_CACHES);
    lv.setAlwaysDrawnWithCacheEnabled(true);

    adapter = new PostListingAdapter(lv, this);
    lv.setAdapter(adapter);

    final ListOverlayView lov = new ListOverlayView(context, lv);

    outer.addView(fragmentHeader);
    outer.addView(lov);

    lv.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;

    request = new PostListingRequest(postListingURL.generateJsonUri(),
            RedditAccountManager.getInstance(context).getDefaultAccount(), session, downloadType, true);

    CacheManager.getInstance(context).makeRequest(request);

    switch (postListingURL.pathType()) {

    case UserPostListingURL:
    case SearchPostListingURL:
        setHeader(postListingURL.humanReadableName(getSupportActivity(), true),
                postListingURL.humanReadableUrl());
        break;

    case SubredditPostListingURL:

        SubredditPostListURL subredditPostListURL = (SubredditPostListURL) postListingURL;

        switch (subredditPostListURL.type) {

        case FRONTPAGE:
        case ALL:
        case SUBREDDIT_COMBINATION:
        case ALL_SUBTRACTION:
            setHeader(postListingURL.humanReadableName(getSupportActivity(), true),
                    postListingURL.humanReadableUrl());
            break;

        case SUBREDDIT: {

            // Request the subreddit data

            final RequestResponseHandler<RedditSubreddit, SubredditRequestFailure> subredditHandler = new RequestResponseHandler<RedditSubreddit, SubredditRequestFailure>() {
                @Override
                public void onRequestFailed(SubredditRequestFailure failureReason) {
                    // Ignore
                }

                @Override
                public void onRequestSuccess(RedditSubreddit result, long timeCached) {
                    subreddit = result;
                    onSubredditReceived();
                }
            };

            try {
                RedditSubredditManager
                        .getInstance(getSupportActivity(),
                                RedditAccountManager.getInstance(getSupportActivity()).getDefaultAccount())
                        .getSubreddit(RedditSubreddit.getCanonicalName(subredditPostListURL.subreddit),
                                TimestampBound.NONE, subredditHandler, null);
            } catch (RedditSubreddit.InvalidSubredditNameException e) {
                throw new RuntimeException(e);
            }
            break;
        }
        }

        break;
    }

    return outer;
}

From source file:pt.aptoide.backupapps.Aptoide.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (!isRunning) {

        Thread.currentThread().setPriority(Thread.MAX_PRIORITY);

        theme = new ContextThemeWrapper(this, R.style.DialogTheme);

        //         currentAppsList = EnumAppsLists.Backup;

        //         handlingMyapps = new ArrayList<ViewMyapp>();

        queuedFlipperChanges = new ArrayList<EnumAptoideInterfaceTasks>();

        //         swypeDetector = new GestureDetector(new SwypeDetector());
        //         swypeListener = new View.OnTouchListener() {
        //                           @Override
        //                           public boolean onTouch(View v, MotionEvent event) {
        //                              return swypeDetector.onTouchEvent(event);
        //                           }
        //                        };
        //         swyping = new AtomicBoolean(false);
        //         swypeDelayHandler = new Handler();

        synchronizingInstalledApps = new AtomicBoolean(false);
        loadingRepos = new AtomicBoolean(false);
        //         resettingFlipper = new AtomicBoolean(false);
        highPriority = new AtomicBoolean(true);

        makeSureServiceDataIsRunning();//  w w  w  . ja va  2s .  c  om

        isRunning = true;

        setContentView(R.layout.aptoide);

        //         searchView = (ImageView) findViewById(R.id.search_button);
        //         searchView.setOnTouchListener(new SearchClickListener());

        //         previousViewArrow = (ImageView) findViewById(R.id.previous);
        //         previousViewArrow.setOnClickListener(new OnPreviousClickedListener());
        //         previousViewArrow.setVisibility(View.INVISIBLE);

        //         previousListTitle = (TextView) findViewById(R.id.previous_title);
        //         previousListTitle.setText(getString(R.string.available));
        //         previousListTitle.setOnClickListener(new OnPreviousClickedListener());
        //         previousListTitle.setVisibility(View.INVISIBLE);
        //         currentListTitle = (TextView) findViewById(R.id.current_title);
        //         currentListTitle.setText(getString(R.string.available));
        //         currentListTitle.setClickable(false);
        //         nextListTitle = (TextView) findViewById(R.id.next_title);
        //         nextListTitle.setText(getString(R.string.installed));
        //         nextListTitle.setOnClickListener(new OnNextClickedListener());

        //         nextViewArrow = (ImageView) findViewById(R.id.next);
        //         nextViewArrow.setOnClickListener(new OnNextClickedListener());

        //         View categoriesView = LinearLayout.inflate(this, R.layout.apps_list, appsListFlipper);
        View availableView = LinearLayout.inflate(this, R.layout.list_apps, appsListPager);
        View installedView = LinearLayout.inflate(this, R.layout.list_apps, appsListPager);
        //         View updatableView = LinearLayout.inflate(this, R.layout.list_apps, appsListFlipper);

        //         emptyCategoriesList = categoriesView.findViewById(android.R.id.empty);
        //         emptyCategoriesList.setVisibility(View.GONE);
        //         emptyAvailableAppsList = LinearLayout.inflate(this, R.layout.list_apps_empty, appsListFlipper);
        emptyAvailableAppsList = availableView.findViewById(android.R.id.empty);
        emptyAvailableAppsList.setVisibility(View.GONE);
        emptyAvailableAppsList.setTag(EnumAppsLists.RESTORE);
        //         emptyInstalledAppsList = LinearLayout.inflate(this, R.layout.list_apps_empty, appsListFlipper);
        emptyInstalledAppsList = installedView.findViewById(android.R.id.empty);
        emptyInstalledAppsList.setVisibility(View.GONE);
        emptyInstalledAppsList.setTag(EnumAppsLists.BACKUP);
        //         emptyUpdatableAppsList = LinearLayout.inflate(this, R.layout.list_apps_empty, appsListFlipper);
        //         emptyUpdatableAppsList = updatableView.findViewById(android.R.id.empty);
        //         emptyUpdatableAppsList.setVisibility(View.GONE);
        //         emptyUpdatableAppsList.setTag(EnumAppsLists.Updates);

        //         loadingCategoriesList = categoriesView.findViewById(R.id.loading);
        //         loadingAvailableAppsList = LinearLayout.inflate(this, R.layout.list_loading, appsListFlipper);
        loadingAvailableAppsList = availableView.findViewById(R.id.loading);
        loadingAvailableAppsList.setTag(EnumAppsLists.RESTORE);
        loadingAppsTitle = loadingAvailableAppsList.findViewById(R.id.loading_title);
        loadingAppsTitleWaitingOnServer = loadingAvailableAppsList
                .findViewById(R.id.loading_title_waiting_on_server);
        loadingAvailableAppsUnknownProgress = (ProgressBar) loadingAvailableAppsList
                .findViewById(R.id.loading_bar);
        loadingAvailableAppsProgress = (ProgressBar) loadingAvailableAppsList
                .findViewById(R.id.loading_progress_bar);
        loadingAvailableAppsProgressCompletionTarget = new AtomicInteger(0);
        loadingAvailableAppsProgressCurrent = new AtomicInteger(0);
        //         loadingInstalledAppsList = LinearLayout.inflate(this, R.layout.list_loading, appsListFlipper);
        loadingInstalledAppsList = installedView.findViewById(R.id.loading);
        loadingInstalledAppsList.setTag(EnumAppsLists.BACKUP);
        //         loadingUpdatableAppsList = LinearLayout.inflate(this, R.layout.list_loading, appsListFlipper);
        //         loadingUpdatableAppsList = updatableView.findViewById(R.id.loading);
        //         loadingUpdatableAppsList.setTag(EnumAppsLists.Updates);

        //         categoriesListView = new ListView(this);
        //         categoriesListView = (ListView) categoriesView.findViewById(android.R.id.list);
        //         categoriesListView.setCacheColorHint(Color.TRANSPARENT);
        //         categoriesListView.setOnTouchListener(swypeListener);
        //         categoriesListView.setOnItemClickListener(this);
        //         categoriesListView.setTag(EnumAppsLists.Available);
        //         categoriesListView.setPersistentDrawingCache(ViewGroup.PERSISTENT_ALL_CACHES);

        //         availableAppsListView = new ListView(this);
        availableAppsListView = (ListView) availableView.findViewById(android.R.id.list);
        availableAppsListView.setCacheColorHint(Color.TRANSPARENT);
        //         availableAppsListView.setOnTouchListener(swypeListener);
        availableAppsListView.setOnItemClickListener(this);
        availableAppsListView.setTag(EnumAppsLists.RESTORE);
        availableAppsListView.setPersistentDrawingCache(ViewGroup.PERSISTENT_ALL_CACHES);
        //      appsListFlipper.addView(availableAppsList);

        //         installedAppsListView = new ListView(this);
        installedAppsListView = (ListView) installedView.findViewById(android.R.id.list);
        installedAppsListView.setCacheColorHint(Color.TRANSPARENT);
        //         installedAppsListView.setOnTouchListener(swypeListener);
        installedAppsListView.setOnItemClickListener(this);
        installedAppsListView.setTag(EnumAppsLists.BACKUP);
        installedAppsListView.setPersistentDrawingCache(ViewGroup.PERSISTENT_ALL_CACHES);
        //      appsListFlipper.addView(installedAppsList);

        //         updatableAppsListView = new ListView(this);
        //         updatableAppsListView = (ListView) updatableView.findViewById(android.R.id.list);
        //         updatableAppsListView.setCacheColorHint(Color.TRANSPARENT);
        //         updatableAppsListView.setOnTouchListener(swypeListener);
        //         updatableAppsListView.setOnItemClickListener(this);
        //         updatableAppsListView.setTag(EnumAppsLists.Updates);
        //         updatableAppsListView.setPersistentDrawingCache(ViewGroup.PERSISTENT_ALL_CACHES);
        //      appsListFlipper.addView(updatableAppsList);

        Button backup = (Button) installedView.findViewById(R.id.action);
        backup.setText(R.string.backup_selected_apps);
        backup.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Log.d("Aptoide-AppsBackup", "Clicked on backup");

                //               if(selectedVersion.getRepoUri() != null){
                //                  if(authenticationToken == null){
                //                     try {
                //                        authenticationToken = serviceDataCaller.callGetServerToken();
                //                     } catch (RemoteException e) {
                //                        // TODO Auto-generated catch block
                //                        e.printStackTrace();
                //                     }
                //                  }
                //                  if(authenticationToken == null){
                //                     Log.d("Aptoide-AppsBackup", "No login set");
                //                     DialogLogin loginComments = new DialogLogin(AppInfo.this, serviceDataCaller, DialogLogin.InvoqueNature.NO_CREDENTIALS_SET);
                //                     loginComments.setOnDismissListener(new OnDismissListener() {
                //                        @Override
                //                        public void onDismiss(DialogInterface dialog) {
                //                           addAppVersionComment();
                //                        }
                //                     });
                //                     loginComments.show();
                //                  }else{
                //                     addAppVersionComment();                  
                //                  }
                //               }
                try {
                    authenticationToken = serviceDataCaller.callGetServerToken();
                } catch (RemoteException e) {
                    e.printStackTrace();
                }

                ViewListIds uploads = new ViewListIds();

                for (int i = 0; i < installedAdapter.getCount(); i++) {
                    if (((ViewDisplayApplicationBackup) installedAdapter.getItem(i)).isChecked()) {
                        uploads.add(installedAdapter.getItem(i).getAppHashid());
                    }
                }

                if (uploads.size() > 0) {
                    installedAdapter.unselectAll();
                    if (authenticationToken != null) {
                        Intent upload = new Intent(Aptoide.this, Upload.class);
                        upload.putIntegerArrayListExtra("uploads", uploads);
                        startActivity(upload);
                    } else {
                        AptoideLog.d(Aptoide.this, "can't backup with no server login configured");
                        //                  Toast.makeText(Aptoide.this, R.string.login_required, Toast.LENGTH_SHORT).show();
                        login(uploads, EnumAppsLists.BACKUP);
                    }
                }

            }
        });

        Button restore = (Button) availableView.findViewById(R.id.action);
        restore.setText(R.string.restore_selected_apps);
        restore.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Log.d("Aptoide-AppsBackup", "Clicked on restore");
                try {
                    anyReposInUse = serviceDataCaller.callAnyReposInUse();
                } catch (RemoteException e) {
                    e.printStackTrace();
                }

                ViewListIds restores = new ViewListIds();
                ViewDisplayApplicationBackup app;
                for (int i = 0; i < availableAdapter.getCount(); i++) {
                    app = ((ViewDisplayApplicationBackup) availableAdapter.getItem(i));
                    if (app.isChecked()) {
                        restores.add(availableAdapter.getItem(i).getAppHashid());
                        Toast.makeText(Aptoide.this,
                                getString(R.string.restoring_app, availableAdapter.getItem(i).getAppName()),
                                Toast.LENGTH_SHORT).show();
                    }
                }

                availableAdapter.unselectAll();

                if (anyReposInUse) {
                    for (Integer appHashid : restores) {
                        try {
                            serviceDataCaller.callInstallApp(appHashid);
                        } catch (RemoteException e) {
                            e.printStackTrace();
                        }
                    }
                } else {
                    AptoideLog.d(Aptoide.this, "can't restore with no repo configured");
                    //                  Toast.makeText(Aptoide.this, R.string.login_required, Toast.LENGTH_SHORT).show();
                    login(restores, EnumAppsLists.RESTORE);
                }
            }
        });

        ArrayList<View> pages = new ArrayList<View>();
        pages.add(installedView);
        pages.add(availableView);

        appsListPager = (ViewPager) findViewById(R.id.list_pager);
        ViewPagerAdapter pagerAdapter = new ViewPagerAdapter(pages);
        appsListPager.setAdapter(pagerAdapter);

        pageIndicator = (FixedTabsView) findViewById(R.id.indicator);
        pageIndicatorAdapter = new FixedTabsAdapter(this);
        pageIndicator.setAdapter(pageIndicatorAdapter);
        pageIndicator.setViewPager(appsListPager);

        //         appsListFlipper.addView(loadingAvailableAppsList);
        //         appsListFlipper.addView(loadingInstalledAppsList);
        //         appsListFlipper.addView(loadingUpdatableAppsList);
        //         appsListPager.addView(availableView);
        //         appsListPager.addView(installedView);
        //         appsListFlipper.addView(updatableView);
    }
}