List of usage examples for android.os Looper prepare
public static void prepare()
From source file:com.eboxlive.ebox.image.ImageCache.java
public void initDiskCache() { synchronized (mDiskCacheLock) { // ? //from w ww.j av a 2 s .c o m File file = mCacheParams.diskCacheDir; if (!file.exists()) { file.mkdirs(); } if (ImageCache.getUsableSpace(mCacheParams.diskCacheDir) < HTTP_CACHE_SIZE) { Looper.prepare(); Toast.makeText(OcApplication.getApplication(), "?,", Toast.LENGTH_LONG) .show(); Looper.loop(); } mDiskCacheStarting = false; mDiskCacheLock.notifyAll(); } }
From source file:com.android.pc.ioc.image.ImageCache.java
public void initDiskCache() { synchronized (mDiskCacheLock) { // ? /*from w w w .j a v a 2 s . c om*/ File file = mCacheParams.diskCacheDir; if (!file.exists()) { file.mkdirs(); } if (ImageCache.getUsableSpace(mCacheParams.diskCacheDir) < HTTP_CACHE_SIZE) { Looper.prepare(); Toast.makeText(Ioc.getIoc().getApplication(), "?,", Toast.LENGTH_LONG) .show(); Looper.loop(); } mDiskCacheStarting = false; mDiskCacheLock.notifyAll(); } }
From source file:it.angelic.soulissclient.fragments.TagDetailFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.recycler_view_frag, container, false); rootView.setTag(TAG);/* ww w .j a va 2 s. c om*/ Log.i(Constants.TAG, "onCreateView with size of data:" + collectedTagTypicals.size()); appBarLayout = (AppBarLayout) getActivity().findViewById(R.id.appBar_layout); swipeLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeRefreshContainer); swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { new Thread(new Runnable() { @Override public void run() { Looper.prepare(); if (collectedTag != null) { UDPHelper.stateRequest(opzioni, 1, collectedTag.getAssignedTypicals().get(0).getNodeId()); Log.d(Constants.TAG, "stateRequest for node:" + collectedTag.getAssignedTypicals().get(0).getNodeId()); } if (!opzioni.isSoulissReachable()) { getActivity().runOnUiThread(new Runnable() { public void run() { Toast.makeText(getActivity(), getString(R.string.status_souliss_notreachable), Toast.LENGTH_SHORT).show(); swipeLayout.setRefreshing(false); } }); } } }).start(); } }); swipeLayout.setColorSchemeResources(R.color.std_blue, R.color.std_blue_shadow); // BEGIN_INCLUDE(initializeRecyclerView) mRecyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerView); swipeLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipeRefreshContainer); // LinearLayout tagContainer = (LinearLayout) rootView.findViewById(R.id.tagContainer); //mLayoutManager = new LinearLayoutManager(getActivity()); if (savedInstanceState != null) { // Restore saved layout manager type. mCurrentLayoutManagerType = (LayoutManagerType) savedInstanceState.getSerializable(KEY_LAYOUT_MANAGER); } mCurrentLayoutManagerType = getResources() .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE ? LayoutManagerType.GRID_LAYOUT_MANAGER : LayoutManagerType.LINEAR_LAYOUT_MANAGER; setRecyclerViewLayoutManager(mCurrentLayoutManagerType); parallaxExtAdapter = new ParallaxExenderAdapter(opzioni, (TagDetailActivity) getActivity(), collectedTagTypicals, tagId); //HeaderLayoutManagerFixed layoutManagerFixed = new HeaderLayoutManagerFixed(getActivity()); //HEADER // View header = getLayoutInflater(null).inflate(R.layout.head_tagdetail, tagContainer, false); // layoutManagerFixed.setHeaderIncrementFixer(header); mLogoIcon = (ImageView) getActivity().findViewById(R.id.imageTagIcon); if (collectedTag.getIconResourceId() != 0) mLogoIcon.setImageResource(collectedTag.getIconResourceId()); mLogoImg = (ImageView) getActivity().findViewById(R.id.photo); bro = (TextView) getActivity().findViewById(R.id.tagTextView); collapseToolbar = (CollapsingToolbarLayout) getActivity().findViewById(R.id.Collapselayout); fab = (FloatingActionButton) getActivity().findViewById(R.id.fabTag); //EDIT TAG fab.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { AlertDialog.Builder alert = AlertDialogHelper.renameSoulissObjectDialog(getActivity(), bro, null, datasource, collectedTag); alert.show(); } }); fab.hide(false); fab.postDelayed(new Runnable() { @Override public void run() { fab.show(true); } }, 500); swipeLayout.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { new Thread(new Runnable() { @Override public void run() { Looper.prepare(); for (SoulissTypical typ : collectedTagTypicals) { UDPHelper.stateRequest(opzioni, 4, typ.getSlot()); } //Avvisa solo if (!opzioni.isSoulissReachable()) { getActivity().runOnUiThread(new Runnable() { public void run() { Toast.makeText(getActivity(), getString(R.string.status_souliss_notreachable), Toast.LENGTH_SHORT).show(); swipeLayout.setRefreshing(false); } }); } } }).start(); } }); swipeLayout.setColorSchemeResources(R.color.std_blue, R.color.std_blue_shadow); if (bro != null && collectedTag != null) { // bro.setText(collectedTag.getNiceName()); collapseToolbar.setTitle(collectedTag.getNiceName()); } if (collectedTag != null && collectedTag.getImagePath() != null) { File picture = new File(getRealPathFromURI(Uri.parse(collectedTag.getImagePath()))); // File picture = new File(Uri.parse(collectedTag.getImagePath()).getPath()); if (picture.exists()) { //ImageView imageView = (ImageView)findViewById(R.id.imageView); BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 2; Bitmap myBitmap = BitmapFactory.decodeFile(picture.getAbsolutePath(), options); if (myBitmap.getHeight() > mRecyclerView.getWidth()) myBitmap = Bitmap.createScaledBitmap(myBitmap, myBitmap.getWidth() / 2, myBitmap.getHeight() / 2, true); Log.i(Constants.TAG, "bitmap size " + myBitmap.getRowBytes()); mLogoImg.setImageBitmap(myBitmap); } try { mLogoImg.setImageURI(Uri.parse(collectedTag.getImagePath())); } catch (Exception e) { Log.d(TAG, "can't set logo", e); } } //parallaxExtAdapter.setShouldClipView(true); // parallaxExtAdapter.setParallaxHeader(header, mRecyclerView); registerForContextMenu(mRecyclerView); return rootView; }
From source file:org.moire.ultrasonic.service.DownloadServiceImpl.java
@SuppressLint("NewApi") @Override/*www.j ava 2 s .c o m*/ public void onCreate() { super.onCreate(); new Thread(new Runnable() { @Override public void run() { Thread.currentThread().setName("DownloadServiceImpl"); Looper.prepare(); if (mediaPlayer != null) { mediaPlayer.release(); } mediaPlayer = new MediaPlayer(); mediaPlayer.setWakeMode(DownloadServiceImpl.this, PowerManager.PARTIAL_WAKE_LOCK); mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() { @Override public boolean onError(MediaPlayer mediaPlayer, int what, int more) { handleError(new Exception(String.format("MediaPlayer error: %d (%d)", what, more))); return false; } }); try { Intent i = new Intent(AudioEffect.ACTION_OPEN_AUDIO_EFFECT_CONTROL_SESSION); i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, mediaPlayer.getAudioSessionId()); i.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, getPackageName()); sendBroadcast(i); } catch (Throwable e) { // Froyo or lower } mediaPlayerLooper = Looper.myLooper(); mediaPlayerHandler = new Handler(mediaPlayerLooper); Looper.loop(); } }).start(); audioManager = (AudioManager) this.getSystemService(Context.AUDIO_SERVICE); setUpRemoteControlClient(); if (equalizerAvailable) { equalizerController = new EqualizerController(this, mediaPlayer); if (!equalizerController.isAvailable()) { equalizerController = null; } else { equalizerController.loadSettings(); } } if (visualizerAvailable) { visualizerController = new VisualizerController(mediaPlayer); if (!visualizerController.isAvailable()) { visualizerController = null; } } PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this.getClass().getName()); wakeLock.setReferenceCounted(false); instance = this; lifecycleSupport.onCreate(); }
From source file:nl.sogeti.android.gpstracker.viewer.LoggerMap.java
/** * Called when the activity is first created. *//*from w w w.j av a 2 s. co m*/ @Override protected void onCreate(Bundle load) { try { super.onCreate(load); } catch (NullPointerException exceptions) { // Unrecoverable Google Maps V1 crash Toast.makeText(this, R.string.error_map_nullpointer, Toast.LENGTH_LONG); } setContentView(R.layout.map); Toolbar toolbar = (Toolbar) findViewById(R.id.support_actionbar); setSupportActionBar(toolbar); findViewById(R.id.mapScreen).setDrawingCacheEnabled(true); mUnits = new UnitsI18n(this); mLoggerServiceManager = new GPSLoggerServiceManager(); final Semaphore calulatorSemaphore = new Semaphore(0); Thread calulator = new Thread("OverlayCalculator") { @Override public void run() { Looper.prepare(); mHandler = new Handler(); calulatorSemaphore.release(); Looper.loop(); } }; calulator.start(); try { calulatorSemaphore.acquire(); } catch (InterruptedException e) { Log.e(this, "Failed waiting for a semaphore", e); } mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this); mMapView = (MapView) findViewById(R.id.myMapView); setupHardwareAcceleration(); mMylocation = new FixedMyLocationOverlay(this, mMapView); mMapView.setBuiltInZoomControls(true); mMapView.setClickable(true); TextView[] speeds = { (TextView) findViewById(R.id.speedview05), (TextView) findViewById(R.id.speedview04), (TextView) findViewById(R.id.speedview03), (TextView) findViewById(R.id.speedview02), (TextView) findViewById(R.id.speedview01), (TextView) findViewById(R.id.speedview00) }; mSpeedtexts = speeds; mLastGPSSpeedView = (TextView) findViewById(R.id.currentSpeed); mLastGPSAltitudeView = (TextView) findViewById(R.id.currentAltitude); mDistanceView = (TextView) findViewById(R.id.currentDistance); mFab = (FloatingActionButton) findViewById(R.id.tracking_control); createListeners(); if (load != null) { onRestoreInstanceState(load); } if (getIntent() != null) { handleIntentData(getIntent()); } }
From source file:com.feedhenry.sdk.tests.api.FHSDKTest.java
private void runAsyncRequest(final FHAct pRequest, final FHActCallback pCallback) throws Exception { // The AsyncHttpClient uses Looper & Handlers to implement async http calls. // It requires the calling thread to have a looper attached to it. // When requests are made from the main UI thread, it will work find as the // main UI thread contains a main Looper. // However, if the app creates another Thread which will be used to invoke // the call, it should use the sync mode or attach the looper to the thread // as demoed below. // The main thread that runs the tests doesn't work with Handlers either. Thread testThread = new Thread() { @Override/*from ww w. j a v a2 s .c o m*/ public void run() { try { Looper.prepare(); pRequest.executeAsync(new FHActCallback() { @Override public void success(FHResponse pResponse) { System.out.println("Got response " + pResponse.getRawResponse()); pCallback.success(pResponse); Looper.myLooper().quit(); } @Override public void fail(FHResponse pResponse) { System.out.println("Got error response : " + pResponse.getRawResponse()); pCallback.fail(pResponse); Looper.myLooper().quit(); } }); Looper.loop(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }; testThread.start(); testThread.join(); }
From source file:com.android.yijiang.kzx.http.AsyncHttpResponseHandler.java
final public void sendSuccessMessage(int statusCode, Header[] headers, byte[] responseBytes) { String content = new String(responseBytes); if (content.indexOf("invalid key") != -1 || content.indexOf("token missing") != -1) { if (ApplicationController.mCount > 0) { return; }/*from w w w .j av a 2s . c om*/ new Thread(new Runnable() { @Override public void run() { Looper.prepare(); ApplicationController.mCount++; MsgTools.toast(ApplicationController.getInstance(), "?,?!", Toast.LENGTH_LONG); new Handler().postDelayed(new Runnable() { @Override public void run() { gotoLogin(); } }, Toast.LENGTH_SHORT); ApplicationController.mCount = 0; Looper.loop(); } }).run(); } else if (content.indexOf("need team") != -1) { Intent i = new Intent(ApplicationController.getInstance(), ContentFragmentActivity.class); i.putExtra("action", "create_team"); i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK); ApplicationController.getInstance().startActivity(i); } else { try { final boolean success = new JSONObject(content).optBoolean("success", false); final String message = new JSONObject(content).optString("message"); final String data = new JSONObject(content).optString("data"); if (!success && "null".equals(data) && StringUtils.isEmpty(message)) { gotoLogin(); return; } else if (!success && "null".equals(data) && !StringUtils.isEmpty(message)) { new Thread(new Runnable() { @Override public void run() { Looper.prepare(); MsgTools.toast(ApplicationController.getInstance(), message, Toast.LENGTH_LONG); sendFinishMessage(); Looper.loop(); } }).run(); return; } } catch (JSONException e) { e.printStackTrace(); sendMessage(obtainMessage(SUCCESS_MESSAGE, new Object[] { statusCode, headers, responseBytes })); } sendMessage(obtainMessage(SUCCESS_MESSAGE, new Object[] { statusCode, headers, responseBytes })); } }
From source file:fi.mikuz.boarder.gui.DropboxMenu.java
private void loadCbla() throws NullPointerException { mCbla = new ExtendedCheckBoxListAdapter(this); if (mOperation == UPLOAD_OPERATION) { setTitle("Dropbox - Upload"); for (File file : SoundboardMenu.mSbDir.listFiles()) { if (file.isDirectory()) { mCbla.addItem(new ExtendedCheckBox(file.getName(), false)); }// w w w.j a v a 2 s. com } mHandler.post(mUpdateList); } else if (mOperation == DOWNLOAD_OPERATION) { setTitle("Dropbox - Download"); mWaitDialog = ProgressDialog.show(this, "", "Please wait", true); mWaitDialog.setCancelable(true); t = new Thread() { public void run() { Looper.prepare(); try { DropboxAPI.Account account = null; try { account = mApi.accountInfo(); } catch (DropboxException e) { Log.e(TAG, "Account info missing", e); } if (account != null) { for (Entry board : mApi.metadata("/", 0, null, true, null).contents) { if (board.isDir) { mCbla.addItem(new ExtendedCheckBox(board.fileName(), false)); } } } else { mWaitDialog.dismiss(); } } catch (DropboxException e) { Log.e(TAG, "Error getting Dropbox content", e); } mHandler.post(mUpdateList); mWaitDialog.dismiss(); } }; t.start(); } }
From source file:com.z3r0byte.magistify.DashboardActivity.java
private void relogin() { final Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.fragment_login); dialog.setTitle(R.string.msg_relogin); Button button = (Button) dialog.findViewById(R.id.button_login); button.setOnClickListener(new View.OnClickListener() { @Override/* ww w . j a va2s . c o m*/ public void onClick(View view) { new Thread(new Runnable() { @Override public void run() { Looper.prepare(); EditText usertxt = (EditText) dialog.findViewById(R.id.edit_text_username); EditText passwordtxt = (EditText) dialog.findViewById(R.id.edit_text_password); String username = usertxt.getText().toString(); String password = passwordtxt.getText().toString(); School school = new Gson().fromJson(configUtil.getString("School"), School.class); try { Magister magister = Magister.login(school, username, password); } catch (final IOException | NullPointerException e) { runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(DashboardActivity.this, R.string.err_no_connection, Toast.LENGTH_SHORT).show(); } }); return; } catch (ParseException e) { e.printStackTrace(); runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(DashboardActivity.this, R.string.err_unknown, Toast.LENGTH_SHORT) .show(); } }); return; } catch (InvalidParameterException e) { runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(DashboardActivity.this, R.string.err_wrong_username_or_password, Toast.LENGTH_SHORT).show(); } }); return; } Log.d(TAG, "onClick: login succeeded!"); User user = new User(username, password, false); configUtil.setString("User", new Gson().toJson(user)); configUtil.setInteger("failed_auth", 0); GlobalAccount.USER = user; dialog.dismiss(); } }).start(); } }); dialog.show(); }
From source file:com.mediatek.systemupdate.HttpManager.java
private HttpManager(Context context) { mContext = context;/*from www. j av a 2s . com*/ mDownloadInfo = DownloadInfo.getInstance(mContext); mNotification = new NotifyManager(mContext); initHttpParam(); initHttpClientMgr(); new Thread() { public void run() { Xlog.v(TAG, "thread run " + Thread.currentThread().getName()); Looper.prepare(); mToastHandler = new Handler(Looper.myLooper()) { @Override public void handleMessage(Message msg) { switch (msg.what) { case NETWORK_ERROR_TOAST: Toast.makeText(mContext, R.string.network_error, Toast.LENGTH_SHORT).show(); break; case SERVER_VERSION_ERROR_TOAST: Toast.makeText(mContext, R.string.server_version_error, Toast.LENGTH_LONG).show(); break; default: break; } } }; Looper.loop(); } }.start(); }