Java Code Examples for android.support.v4.app.fragmentactivity#runOnUiThread()

The following examples show how to use android.support.v4.app.fragmentactivity#runOnUiThread() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MediaItemsDataSource.java    From YImagePicker with Apache License 2.0 6 votes vote down vote up
/**
 * 回调所有数据
 *
 * @param context     FragmentActivity
 * @param imageItems  所有文件
 * @param allVideoSet 当加载所有媒体库文件时,默认会生成一个全部视频的文件夹,是本地虚拟的文件夹
 */
private void notifyMediaItem(final FragmentActivity context, final ArrayList<ImageItem> imageItems,
                             final ImageSet allVideoSet) {
    context.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (context.isDestroyed()) {
                return;
            }
            if (mediaItemProvider != null) {
                mediaItemProvider.providerMediaItems(imageItems, allVideoSet);
            }

            if (mLoaderManager != null) {
                mLoaderManager.destroyLoader(LOADER_ID);
            }
        }
    });
}
 
Example 2
Source File: BaseAppLockFragment.java    From MobileGuard with MIT License 6 votes vote down vote up
/**
 * distribute the apps and refresh ListView
 *
 * @param context
 * @param appsInfo
 */
private void initAppsAndRefreshUi(final FragmentActivity context, final List<AppInfoBean> appsInfo) {
    // refresh ui need run on ui thread
    // and remember the change data should'n in background thread
    context.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            // clear data
            apps.clear();
            // distribute apps
            AppLockDao dao = new AppLockDao(context);
            for (AppInfoBean app : appsInfo) {
                // if in locked list
                if (isNeededApp(dao, app.getPackageName())) {
                    // add to locked list
                    apps.add(app);
                }
            }
            // notify update ListView
            adapter.notifyDataSetChanged();
            // hide loading bar
            pvLoading.setVisibility(View.GONE);
        }
    });
}
 
Example 3
Source File: CircleFragment.java    From BusyIndicator with Apache License 2.0 6 votes vote down vote up
@Override
protected Object doInBackground(Object[] params) {
    final Random rand = new Random();

    FragmentActivity activity = getActivity();

    while (true) {
        final int a = rand.nextInt(3) + 1;

        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                infiniteCircleBusyIndicator.setAngleModifier(a);
            }
        });

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
 
Example 4
Source File: TyWebViewToolbarFragment.java    From tysq-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void setTitle(String title) {
    FragmentActivity activity = getActivity();
    if (activity != null) {
        activity.runOnUiThread(() -> tvTitle.setText(title));
    }
}
 
Example 5
Source File: MediaItemsDataSource.java    From YImagePicker with Apache License 2.0 5 votes vote down vote up
/**
 * 回调预加载的媒体文件,主线程
 *
 * @param context    FragmentActivity
 * @param imageItems 预加载列表
 */
private void notifyPreloadItem(final FragmentActivity context, final ArrayList<ImageItem> imageItems) {
    context.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (context.isDestroyed()) {
                return;
            }
            preloadProvider.providerMediaItems(imageItems);
            preloadProvider = null;
        }
    });
}
 
Example 6
Source File: ChartFragment.java    From mytracks with Apache License 2.0 5 votes vote down vote up
/**
 * Runs a runnable on the UI thread if possible.
 * 
 * @param runnable the runnable
 */
private void runOnUiThread(Runnable runnable) {
  FragmentActivity fragmentActivity = getActivity();
  if (fragmentActivity != null) {
    fragmentActivity.runOnUiThread(runnable);
  }
}
 
Example 7
Source File: MultiLoaderFragment.java    From BusyIndicator with Apache License 2.0 5 votes vote down vote up
@Override
protected Object doInBackground(Object[] objects) {

    final Random rand = new Random();
    int i = 0;

    FragmentActivity activity = getActivity();

    while (i < 84) {
        final int a = i;
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
            multiBusyIndicator1.setValue(a);
            }
        });

        i = i + rand.nextInt(20) + 1;

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            multiBusyIndicator1.setValue(83);
            busy1Done = true;
            if (busy1Done && busy2Done && busy3Done)
                loadingStatusText.setText("done");
        }
    });

    return null;
}
 
Example 8
Source File: MultiLoaderFragment.java    From BusyIndicator with Apache License 2.0 5 votes vote down vote up
@Override
protected Object doInBackground(Object[] objects) {

    final Random rand = new Random();
    int i = 0;

    FragmentActivity activity = getActivity();

    while (i < 531) {
        final int a = i;
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
            multiBusyIndicator2.setValue(a);
            }
        });

        i = i + rand.nextInt(90) + 1;

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            multiBusyIndicator2.setValue(530);
            busy2Done = true;
            if (busy1Done && busy2Done && busy3Done)
                loadingStatusText.setText("done");
        }
    });

    return null;
}
 
Example 9
Source File: MultiLoaderFragment.java    From BusyIndicator with Apache License 2.0 5 votes vote down vote up
@Override
protected Object doInBackground(Object[] objects) {

    final Random rand = new Random();
    int i = 0;

    FragmentActivity activity = getActivity();

    while (i < 963) {
        final int a = i;
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
            multiBusyIndicator3.setValue(a);
            }
        });

        i = i + rand.nextInt(190) + 1;

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            multiBusyIndicator3.setValue(962);
            busy3Done = true;
            if (busy1Done && busy2Done && busy3Done)
                loadingStatusText.setText("done");
        }
    });

    return null;
}
 
Example 10
Source File: RectangleFragment.java    From BusyIndicator with Apache License 2.0 5 votes vote down vote up
@Override
protected Object doInBackground(Object[] objects) {

    final Random rand = new Random();
    int i = 0;

    FragmentActivity activity = getActivity();

    while (i < 315) {
        final int a = i;
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
            rectangleBusyIndicator.setValue(a);
            }
        });

        i = i + rand.nextInt(60) + 1;

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
        rectangleBusyIndicator.setValue(314);
        }
    });

    return null;
}
 
Example 11
Source File: TransFragment.java    From BusyIndicator with Apache License 2.0 5 votes vote down vote up
@Override
protected Object doInBackground(Object[] objects) {

    final Random rand = new Random();
    int i = 0;

    FragmentActivity activity = getActivity();

    while (i < 84) {
        final int a = i;
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
            transBusyIndicator.setValue(a);
            }
        });

        i = i + rand.nextInt(20) + 1;

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            transBusyIndicator.setValue(83);
        }
    });

    return null;
}
 
Example 12
Source File: CircleFragment.java    From BusyIndicator with Apache License 2.0 5 votes vote down vote up
@Override
protected Object doInBackground(Object[] objects) {

    final Random rand = new Random();
    int i = 0;

    FragmentActivity activity = getActivity();

    while (i < 103) {
        final int a = i;
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
            circleBusyIndicator.setValue(a);
            }
        });

        i = i + rand.nextInt(20) + 1;

        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    activity.runOnUiThread(new Runnable() {
        @Override
        public void run() {
        circleBusyIndicator.setValue(103);
        }
    });

    return null;
}
 
Example 13
Source File: FragmentTestActivity.java    From android-task with Apache License 2.0 5 votes vote down vote up
@Override
public void onProgress(final long progress, final long max) {
    final ProgressDialog dialog = (ProgressDialog) getDialog();
    FragmentActivity activity = getActivity();

    if (dialog != null && activity != null) {
        activity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                dialog.setMax((int) max);
                dialog.setProgress((int) progress);
            }
        });
    }
}