List of usage examples for android.os Looper getMainLooper
public static Looper getMainLooper()
From source file:com.doplgangr.secrecy.Util.java
public static void alert(final Context context, final String title, final String message, final DialogInterface.OnClickListener positive, final DialogInterface.OnClickListener negative) { new Handler(Looper.getMainLooper()).post(new Runnable() { @Override//from w w w. j av a 2 s .co m public void run() { AlertDialog.Builder a = new AlertDialog.Builder(context); if (title != null) a.setTitle(title); if (message != null) a.setMessage(message); if (positive != null) a.setPositiveButton(context.getString(R.string.OK), positive); if (negative != null) a.setNegativeButton(context.getString(R.string.CANCEL), negative); a.setCancelable(false); a.show(); } }); }
From source file:angel.zhuoxiu.library.pusher.PusherCallback.java
public PusherCallback() { super(Looper.getMainLooper()); }
From source file:com.doplgangr.secrecy.utils.Util.java
public static void alert(final Context context, final String title, final String message, final DialogInterface.OnClickListener positive, final DialogInterface.OnClickListener negative) { new Handler(Looper.getMainLooper()).post(new Runnable() { @Override//from www . j ava 2 s . c om public void run() { AlertDialog.Builder a = new AlertDialog.Builder(context); if (title != null) a.setTitle(title); if (message != null) a.setMessage(message); if (positive != null) a.setPositiveButton("OK", positive); if (negative != null) a.setNegativeButton("CANCEL", negative); a.setCancelable(false); a.show(); } }); }
From source file:com.appsimobile.appsii.module.home.config.MockHomeItemConfiguration.java
public MockHomeItemConfiguration(Context context) { super(context); mProperties = new SimpleArrayMap<>(); mHandler = new Handler(Looper.getMainLooper()); }
From source file:com.example.etsmith.gcmupstream.MyGcmListenerService.java
@Override public void onMessageReceived(String from, final Bundle data) { super.onMessageReceived(from, data); Handler handler = new Handler(Looper.getMainLooper()); handler.post(new Runnable() { public void run() { Toast.makeText(getApplicationContext(), "Message Received: " + data.toString(), Toast.LENGTH_SHORT) .show();//from w ww .j a va2 s. co m } }); for (String dataTag : data.keySet()) { if (!dataTag.equals(Constants.NOTIFICATION_BUNDLE)) { Log.d(TAG, dataTag + ": " + data.getString(dataTag)); } else { Bundle bundle = data.getBundle(dataTag); for (String bundleTag : bundle.keySet()) { Log.d(TAG, bundleTag + ": " + data.getString(bundleTag)); } } } String action = data.getString(Constants.ACTION); String status = data.getString(Constants.STATUS); if (Constants.REGISTER_NEW_CLIENT.equals(action) && Constants.STATUS_REGISTERED.equals(status)) { Log.d(TAG, "Registration Success"); } else if (Constants.UNREGISTER_CLIENT.equals(action) && Constants.STATUS_UNREGISTERED.equals(status)) { // token = ""; Log.d(TAG, "Unregistration Success"); } else if (from.startsWith(Constants.TOPIC_ROOT)) { Log.d(TAG, "Topic message: " + data.toString()); } else { Log.d(TAG, "Other type of action: " + data.toString()); } }
From source file:com.simas.vc.background_tasks.FFprobe.java
/** * This operation is synchronous and cannot be run on the UI thread. *///from w ww . j a v a2 s.c o m @SuppressWarnings("ResultOfMethodCallIgnored") public synchronized static FileAttributes parseAttributes(File inputFile) throws VCException { if (Looper.myLooper() == Looper.getMainLooper()) { throw new IllegalStateException("parseAttributes cannot be run on the UI thread!"); } /* Executable call used ./ffprobe -i 'nature/bee.mp4' \ -v quiet -print_format json \ -show_format -show_entries format=duration,size,format_name,format_long_name,filename,nb_streams \ -show_streams -show_entries stream=codec_name,codec_long_name,codec_type,sample_rate,channels,duration,display_aspect_ratio,width,height,time_base,codec_time_base,r_frame_rate */ // Check if input exists if (!inputFile.exists()) { throw new VCException(Utils.getString(R.string.input_not_found)); } // Create a temporary file to hold the stdout output File tmpFile; try { tmpFile = File.createTempFile("vc-out", null); tmpFile.delete(); tmpFile.createNewFile(); } catch (IOException e) { e.printStackTrace(); throw new VCException(Utils.getString(R.string.tmp_not_created)); } // Create arguments for ffprobe final String[] args = new ArgumentBuilder(TAG).add("-i").addSpaced("%s", inputFile.getPath()) // Spaced input file path .add("-v quiet -print_format json") // Output quietly in JSON // Format entries to show .add("-show_format -show_entries format=%s,%s,%s,%s,%s,%s", Utils.getString(R.string.format_duration), Utils.getString(R.string.format_size), Utils.getString(R.string.format_name), Utils.getString(R.string.format_long_name), Utils.getString(R.string.format_filename), Utils.getString(R.string.format_stream_count)) // Stream entries to show .add("-show_streams -show_entries stream=%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s", Utils.getString(R.string.stream_name), Utils.getString(R.string.stream_long_name), Utils.getString(R.string.stream_type), Utils.getString(R.string.stream_sample_rate), Utils.getString(R.string.stream_channels), Utils.getString(R.string.stream_duration), Utils.getString(R.string.stream_aspect_ratio), Utils.getString(R.string.stream_width), Utils.getString(R.string.stream_height), Utils.getString(R.string.stream_tbn), Utils.getString(R.string.stream_tbc), Utils.getString(R.string.stream_tbr), Utils.getString(R.string.stream_codec_tag)) .build(); if (cFFprobe(args, tmpFile.getPath()) != 0) { throw new VCException(Utils.getString(R.string.ffprobe_fail)); } BufferedReader reader = null; FileAttributes fa = null; try { // Parse file reader = new BufferedReader(new FileReader(tmpFile)); StringBuilder sb = new StringBuilder(); String line = reader.readLine(); while (line != null) { sb.append(line); sb.append('\n'); line = reader.readLine(); } String content = sb.toString(); int firstOpeningBrace = content.indexOf('{'); int lastClosingBrace = content.lastIndexOf('}'); if (firstOpeningBrace == -1 || lastClosingBrace == -1) { return null; } String json = content.substring(firstOpeningBrace, lastClosingBrace + 1); // Parse JSON fa = parseJsonAttributes(json); Log.i(TAG, "Parsed attributes: " + fa); } catch (IOException e) { e.printStackTrace(); throw new VCException(Utils.getString(R.string.ffprobe_fail)); } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } } // Delete the tmp file tmpFile.delete(); // No support for files with no audio/video streams (for now?) if (fa != null) { if (fa.getAudioStreams().size() == 0) { throw new VCException(Utils.getString(R.string.audioless_unsupported)); } else if (fa.getVideoStreams().size() == 0) { throw new VCException(Utils.getString(R.string.videoless_unsupported)); } } return fa; }
From source file:com.fatelon.lib.photobooth.framework.ControllerBackedFragment.java
/** * Constructor.//from w ww.j a v a 2s.c o m */ public ControllerBackedFragment() { super(); mUiHandler = new Handler(Looper.getMainLooper()) { @Override public void handleMessage(Message msg) { handleUiUpdate(msg); } }; }
From source file:com.baitouwei.aswiperefresh.sample.BaseFragment.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); for (int i = 0; i <= dataNum; i++) { data.add(String.valueOf(i)); }/* w w w . j a v a 2s . com*/ handler = new Handler(Looper.getMainLooper()); getActivity().setTitle(this.getClass().getSimpleName()); }
From source file:android.support.v7.util.MessageThreadUtil.java
public MainThreadCallback<T> getMainThreadProxy(final MainThreadCallback<T> callback) { return new MainThreadCallback<T>() { final private MessageQueue mQueue = new MessageQueue(); final private Handler mMainThreadHandler = new Handler(Looper.getMainLooper()); private static final int UPDATE_ITEM_COUNT = 1; private static final int ADD_TILE = 2; private static final int REMOVE_TILE = 3; @Override/*w w w . j av a 2s. c o m*/ public void updateItemCount(int generation, int itemCount) { sendMessage(SyncQueueItem.obtainMessage(UPDATE_ITEM_COUNT, generation, itemCount)); } @Override public void addTile(int generation, TileList.Tile<T> tile) { sendMessage(SyncQueueItem.obtainMessage(ADD_TILE, generation, tile)); } @Override public void removeTile(int generation, int position) { sendMessage(SyncQueueItem.obtainMessage(REMOVE_TILE, generation, position)); } private void sendMessage(SyncQueueItem msg) { mQueue.sendMessage(msg); mMainThreadHandler.post(mMainThreadRunnable); } private Runnable mMainThreadRunnable = new Runnable() { @Override public void run() { SyncQueueItem msg = mQueue.next(); while (msg != null) { switch (msg.what) { case UPDATE_ITEM_COUNT: callback.updateItemCount(msg.arg1, msg.arg2); break; case ADD_TILE: //noinspection unchecked callback.addTile(msg.arg1, (TileList.Tile<T>) msg.data); break; case REMOVE_TILE: callback.removeTile(msg.arg1, msg.arg2); break; default: Log.e("ThreadUtil", "Unsupported message, what=" + msg.what); } msg = mQueue.next(); } } }; }; }
From source file:com.ferdi2005.secondgram.support.util.MessageThreadUtil.java
@Override public MainThreadCallback<T> getMainThreadProxy(final MainThreadCallback<T> callback) { return new MainThreadCallback<T>() { final MessageQueue mQueue = new MessageQueue(); final private Handler mMainThreadHandler = new Handler(Looper.getMainLooper()); static final int UPDATE_ITEM_COUNT = 1; static final int ADD_TILE = 2; static final int REMOVE_TILE = 3; @Override// www.jav a 2 s .c o m public void updateItemCount(int generation, int itemCount) { sendMessage(SyncQueueItem.obtainMessage(UPDATE_ITEM_COUNT, generation, itemCount)); } @Override public void addTile(int generation, TileList.Tile<T> tile) { sendMessage(SyncQueueItem.obtainMessage(ADD_TILE, generation, tile)); } @Override public void removeTile(int generation, int position) { sendMessage(SyncQueueItem.obtainMessage(REMOVE_TILE, generation, position)); } private void sendMessage(SyncQueueItem msg) { mQueue.sendMessage(msg); mMainThreadHandler.post(mMainThreadRunnable); } private Runnable mMainThreadRunnable = new Runnable() { @Override public void run() { SyncQueueItem msg = mQueue.next(); while (msg != null) { switch (msg.what) { case UPDATE_ITEM_COUNT: callback.updateItemCount(msg.arg1, msg.arg2); break; case ADD_TILE: //noinspection unchecked callback.addTile(msg.arg1, (TileList.Tile<T>) msg.data); break; case REMOVE_TILE: callback.removeTile(msg.arg1, msg.arg2); break; default: Log.e("ThreadUtil", "Unsupported message, what=" + msg.what); } msg = mQueue.next(); } } }; }; }