Example usage for android.os Handler Handler

List of usage examples for android.os Handler Handler

Introduction

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

Prototype

public Handler() 

Source Link

Document

Default constructor associates this handler with the Looper for the current thread.

Usage

From source file:com.fastbootmobile.encore.cast.CastModule.java

/**
 * Default constructor//w w w . ja va 2  s .  c o  m
 * @param ctx The host context of the module
 */
public CastModule(Context ctx) {
    mContext = ctx;
    mHandler = new Handler();
    mConnectionCallbacks = new ConnectionCallbacks();
    mConnectionFailedListener = new ConnectionFailedListener();

    mMediaRouter = MediaRouter.getInstance(ctx);
    mSelector = new MediaRouteSelector.Builder()
            .addControlCategory(CastMediaControlIntent.categoryForCast(CAST_APP_ID)).build();

    mCastListener = new CastListener();
    mCastChannel = new CastChannel();
}

From source file:zjut.soft.finalwork.ui.SlidingActivity.java

private void init() {
    sp = getSharedPreferences(Constant.PREFERENCES_NAME, Context.MODE_PRIVATE);
    mSlidingMenu = (SlidingMenu) findViewById(R.id.slidingMenu);
    mHandler = new Handler();
    //      mSlidingMenu.setCanSliding(true,false);   // 
    //      mSlidingMenu.setCanSliding(false, true);   // 
    //      mSlidingMenu.setCanSliding(true, true); // 
    mSlidingMenu.setLeftView(getLayoutInflater().inflate(R.layout.left_frame, null));
    mSlidingMenu.setRightView(getLayoutInflater().inflate(R.layout.right_frame, null));
    mSlidingMenu.setCenterView(getLayoutInflater().inflate(R.layout.center_frame, null));

    FragmentTransaction t = this.getSupportFragmentManager().beginTransaction();
    leftFragment = new LeftFragment();
    t.replace(R.id.left_frame, leftFragment);

    rightFragment = new RightFragment();
    t.replace(R.id.right_frame, rightFragment);

    //      viewPageFragment = new ViewPageFragment();
    UserConfFragment userConfFrag = new UserConfFragment();
    t.replace(R.id.center_frame, userConfFrag);
    t.commit();/*from www  . j a v  a 2  s .co  m*/

    app = (YCApplication) getApplication();
    timeSchedule();
}

From source file:de.quadrillenschule.azocamsynca.job.JobProcessor.java

public void processingLoop() {

    if (getRequestStatus() == ProcessorStatus.PAUSED) {
        setStatus(ProcessorStatus.PAUSED);
        return;//from w  ww.  jav a2 s.  c  om
    }
    setStatus(ProcessorStatus.PROCESSING);
    TriggerPhotoSerie currentJobT = null;
    for (TriggerPhotoSerie j : jobs) {
        if (j.getTriggerStatus() != TriggerPhotoSerie.TriggerJobStatus.FINISHED_TRIGGERING) {
            currentJobT = j;
            if ((j.getTriggerStatus() == PhotoSerie.TriggerJobStatus.WAITFORUSER)
                    && ((alertDialog != null) && (alertDialog.isShowing()))) {
                return;
            }
            if ((j.getTriggerStatus() == PhotoSerie.TriggerJobStatus.WAITFORUSER)) {
                currentJobT.setTriggerStatus(PhotoSerie.TriggerJobStatus.NEW);
            }
            break;
        }
    }
    if (currentJobT == null) {
        setStatus(ProcessorStatus.PAUSED);
        return;
    }

    final TriggerPhotoSerie currentJob = currentJobT;
    final NikonIR camera = ((AzoTriggerServiceApplication) getActivity().getApplication()).getCamera();

    if (currentJob.getTriggerStatus() == PhotoSerie.TriggerJobStatus.NEW) {
        currentJob.setTriggerStatus(PhotoSerie.TriggerJobStatus.WAITFORUSER);
        if (currentJob.getSeriesName().equals(PhotoSerie.TESTSHOTS)) {
            doTestShots(currentJob);
            return;
        }
        AlertDialog.Builder ad = new AlertDialog.Builder(getActivity(), R.style.dialog);
        ad.setTitle(currentJob.getProject() + ": " + currentJob.getSeriesName());
        ad.setMessage(
                currentJob.getNumber() + " x " + (int) (currentJob.getExposure() / 1000) + "s\n\n"
                        + "Delay after each exposure:" + currentJob.getDelayAfterEachExposure() / 1000 + "s\n"
                        + "Camera controls time: " + camera.isExposureSetOnCamera(currentJob.getExposure())
                        + "\n" + "Total time: "
                        + ((currentJob.getNumber()
                                * (currentJob.getExposure() + currentJob.getDelayAfterEachExposure())) / 1000)
                        + "s");

        ad.setPositiveButton("Confirm", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface arg0, int arg1) {
                currentJob.setTriggerStatus(PhotoSerie.TriggerJobStatus.PREPARED);
                processingLoop();
            }
        });
        ad.setNegativeButton("Pause", new DialogInterface.OnClickListener() {

            public void onClick(DialogInterface arg0, int arg1) {
                currentJob.setTriggerStatus(PhotoSerie.TriggerJobStatus.NEW);
                pause();
            }
        });

        MediaPlayer mediaPlayer = MediaPlayer.create(activity, R.raw.oida_peda);
        mediaPlayer.start();
        ad.create();
        alertDialog = ad.show();

    }

    final Handler handler = new Handler();

    if ((currentJob.getTriggerStatus() == PhotoSerie.TriggerJobStatus.PREPARED
            || currentJob.getTriggerStatus() == PhotoSerie.TriggerJobStatus.RUNNING)) {
        handler.postDelayed(new Runnable() {

            public void run() {
                if ((((AzoTriggerServiceApplication) getActivity().getApplication()).getJobProcessor()
                        .getStatus() == ProcessorStatus.PAUSED) && (!currentJob.isToggleIsOpen())) {

                    return;
                }
                camera.trigger();
                for (JobProgressListener j : jobProgressListeners) {
                    j.jobProgressed(currentJob);
                }
                if (currentJob.getFirstTriggerTime() == 0) {
                    currentJob.setFirstTriggerTime(System.currentTimeMillis());
                }
                currentJob.setTriggerStatus(PhotoSerie.TriggerJobStatus.RUNNING);

                if (!camera.isExposureSetOnCamera(currentJob.getExposure())) {
                    if (!currentJob.isToggleIsOpen()) {
                        currentJob.setToggleIsOpen(!currentJob.isToggleIsOpen());

                        currentJob.setLastTriggerTime(System.currentTimeMillis());
                    } else {
                        currentJob.setToggleIsOpen(!currentJob.isToggleIsOpen());
                        currentJob.setTriggered(currentJob.getTriggered() + 1);

                    }
                } else {

                    currentJob.setTriggered(currentJob.getTriggered() + 1);

                }
                if (currentJob.getTriggered() < currentJob.getNumber()) {
                    long time;
                    if (camera.isExposureSetOnCamera(currentJob.getExposure())) {
                        time = currentJob.getExposure() + currentJob.getDelayAfterEachExposure();
                    } else {
                        if (currentJob.isToggleIsOpen()) {
                            time = currentJob.getExposure();
                        } else {
                            time = currentJob.getDelayAfterEachExposure();
                        }
                    }
                    handler.postDelayed(this, time);
                } else {
                    currentJob.setTriggerStatus(PhotoSerie.TriggerJobStatus.FINISHED_TRIGGERING);
                    processingLoop();
                }
            }
        }, currentJob.getInitialDelay());
    } else {
    }

}

From source file:org.csp.everyaware.internet.StoreAndForwardService.java

@Override
public void onCreate() {
    Log.d("StoreAndForwardService", "***************************** onCreate() ***************************");

    mHandler = new Handler();
    mDbManager = DbManager.getInstance(getApplicationContext());
    mPostDataThread = new PostDataThread();
}

From source file:cw.kop.autobackground.sources.SourceInfoFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preferences_source);
    handler = new Handler();
    setRetainInstance(true);//from  w w  w .  j  a va2s.com
}

From source file:com.app.jdy.ui.MyFaceActivity.java

public void initView() {
    Calendar now = Calendar.getInstance();
    Constants.SELECT_YEAR = now.get(Calendar.YEAR) + "";
    mBackImg = (ImageView) findViewById(R.id.back_img);
    mBackImg.setVisibility(View.VISIBLE);
    title = (TextView) findViewById(R.id.title_tv);
    title.setText("??");
    my_face_sum = (TextView) findViewById(R.id.my_face_sum);
    select_year_click = (TextView) findViewById(R.id.select_year_click);
    select_year = (TextView) findViewById(R.id.select_year);

    SharedPreferences userPreferences = getSharedPreferences("umeng_general_config", Context.MODE_PRIVATE);
    ID = userPreferences.getString("ID", "").trim();

    handler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case 0:
                Toast.makeText(MyFaceActivity.this, Constants.NO_INTENT_TIPS, Toast.LENGTH_SHORT).show();
                break;
            case 1:
                try {
                    JSONArray jsonArray = new JSONArray(dataJson);
                    for (int i = 0; i < lineValues[0].length; i++) {
                        lineValues[0][i] = 0;
                    }// w  w  w  .  j a v  a  2 s.  c  om
                    for (int i = 0; i < jsonArray.length(); i++) {
                        lineValues[0][jsonArray.getJSONObject(i).getInt("month")] = (float) jsonArray
                                .getJSONObject(i).getDouble("totol");
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                my_face_sum.setText(getSumValue() + "");
                select_year.setText(Constants.SELECT_YEAR + "");
                getMaxValue();
                updateLineChart();
                break;
            case 2:
                for (int i = 0; i < lineValues[0].length; i++) {
                    lineValues[0][i] = 0;
                }
                LINE_MAX = 20;
                my_face_sum.setText("0");
                select_year.setText(Constants.SELECT_YEAR + "");
                updateLineChart();
                Toast.makeText(MyFaceActivity.this, "?",
                        Toast.LENGTH_SHORT).show();
                break;

            default:
                break;
            }
        }
    };
}

From source file:com.app.jdy.ui.MyCommunityActivity.java

public void initView() {
    Calendar now = Calendar.getInstance();
    Constants.SELECT_YEAR = now.get(Calendar.YEAR) + "";
    mBackImg = (ImageView) findViewById(R.id.back_img);
    mBackImg.setVisibility(View.VISIBLE);
    title = (TextView) findViewById(R.id.title_tv);
    title.setText("?");
    my_community_sum = (TextView) findViewById(R.id.my_community_sum);
    select_year_click = (TextView) findViewById(R.id.select_year_click);
    select_year = (TextView) findViewById(R.id.select_year);

    SharedPreferences userPreferences = getSharedPreferences("umeng_general_config", Context.MODE_PRIVATE);
    ID = userPreferences.getString("ID", "").trim();

    handler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case 0:
                Toast.makeText(MyCommunityActivity.this, Constants.NO_INTENT_TIPS, Toast.LENGTH_SHORT).show();
                break;
            case 1:
                Log.v("ppppppppppppppppppppppppppp", dataJson);
                try {
                    JSONArray jsonArray = new JSONArray(dataJson);
                    for (int i = 0; i < lineValues[0].length; i++) {
                        lineValues[0][i] = 0;
                    }/*from w  ww  . java2  s .com*/
                    for (int i = 0; i < jsonArray.length(); i++) {
                        lineValues[0][jsonArray.getJSONObject(i).getInt("month")] = (float) jsonArray
                                .getJSONObject(i).getDouble("total");
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                my_community_sum.setText(getSumValue() + "");
                select_year.setText(Constants.SELECT_YEAR + "");
                getMaxValue();
                updateLineChart();
                break;
            case 2:
                for (int i = 0; i < lineValues[0].length; i++) {
                    lineValues[0][i] = 0;
                }
                LINE_MAX = 20;
                my_community_sum.setText("0");
                select_year.setText(Constants.SELECT_YEAR + "");
                updateLineChart();
                Toast.makeText(MyCommunityActivity.this, "?",
                        Toast.LENGTH_SHORT).show();
                break;

            default:
                break;
            }
        }
    };
}

From source file:li.klass.fhem.fragments.SendCommandFragment.java

@Override
public void update(boolean doUpdate) {
    Intent intent = new Intent(Actions.RECENT_COMMAND_LIST);
    intent.setClass(getActivity(), SendCommandIntentService.class);
    intent.putExtra(BundleExtraKeys.RESULT_RECEIVER, new ResultReceiver(new Handler()) {
        @Override/* w w  w .  j  a  v  a 2  s  .  c  om*/
        protected void onReceiveResult(int resultCode, Bundle resultData) {
            if (resultCode != ResultCodes.SUCCESS || resultData == null
                    || !resultData.containsKey(BundleExtraKeys.RECENT_COMMANDS)) {
                return;
            }

            View view = getView();
            if (view == null)
                return;

            recentCommands = resultData.getStringArrayList(BundleExtraKeys.RECENT_COMMANDS);
            recentCommandsAdapter.clear();

            // careful: addAll method is only available since API level 11 (Android 3.0)
            for (String recentCommand : recentCommands) {
                recentCommandsAdapter.add(recentCommand);
            }
            recentCommandsAdapter.notifyDataSetChanged();

            ListViewUtil.setHeightBasedOnChildren((ListView) view.findViewById(R.id.command_history));

            getActivity().sendBroadcast(new Intent(Actions.DISMISS_EXECUTING_DIALOG));
        }
    });
    getActivity().startService(intent);
}

From source file:net.grappendorf.doitlater.TaskEditorActivity.java

private void updateTask() {
    ((DoItLaterApplication) getApplication()).getTaskManager().updateTask(taskListId, task, this,
            new Handler() {
                @Override//  ww  w. j a  v a2  s.  co m
                public void handleMessage(Message msg) {
                    if (msg.obj != null) {
                        Intent intent = new Intent();
                        intent.putExtra("taskId", task.getId());
                        setResult(RESULT_OK, intent);
                        finish();
                    } else {
                        Toast.makeText(getApplicationContext(), R.string.save_error, Toast.LENGTH_LONG).show();
                    }
                }
            });
}

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

@Override
public void run() {
    Looper.prepare();/*from  w  ww  . ja  va 2  s  .co m*/
    mHandler = new Handler() {
        @Override
        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();
}