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.facebook.android.GraphExplorer.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mHandler = new Handler();

    setContentView(R.layout.graph_explorer);

    url = BASE_GRAPH_URL; // Base URL

    mInputId = (EditText) findViewById(R.id.inputId);
    mOutput = (TextView) findViewById(R.id.output);
    mSubmitButton = (Button) findViewById(R.id.submitButton);
    mViewURLButton = (Button) findViewById(R.id.viewURLButton);
    mGetPermissionsButton = (Button) findViewById(R.id.accessTokenButton);
    mFieldsConnectionsButton = (Button) findViewById(R.id.fieldsAndConnectionsButton);
    mBackParentButton = (Button) findViewById(R.id.backParentButton);

    mScrollView = (ScrollView) findViewById(R.id.ScrollView01);

    mTextDeleteButton = (Button) findViewById(R.id.textDeleteButton);
    mMeButton = (Button) findViewById(R.id.meButton);
    if (Utility.mFacebook.isSessionValid()) {
        mMeButton.setVisibility(View.VISIBLE);
    }/*  ww w .  j  a  va 2s  .  c o m*/

    params = new Bundle();
    mSubmitButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {

            ((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE))
                    .hideSoftInputFromWindow(mInputId.getWindowToken(), 0);

            // Prepare the URL to be shown on 'View URL' click action. This
            // is not used by the SDK
            url = BASE_GRAPH_URL; // Base URL

            /*
             * Source Tag: graph_explorer
             */
            rootString = mInputId.getText().toString();
            if (!TextUtils.isEmpty(rootString)) {
                dialog = ProgressDialog.show(GraphExplorer.this, "", getString(R.string.please_wait), true,
                        true);
                params.putString("metadata", "1");
                Utility.mAsyncRunner.request(rootString, params, new graphApiRequestListener());
                url += "/" + rootString; // Relative Path provided by you
            }

        }
    });

    mViewURLButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setText(url);
            Linkify.addLinks(mOutput, Linkify.WEB_URLS);
        }
    });

    mGetPermissionsButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (Utility.mFacebook.isSessionValid()) {
                dialog = ProgressDialog.show(GraphExplorer.this, "",
                        getString(R.string.fetching_current_permissions), true, true);
                Bundle params = new Bundle();
                params.putString("access_token", Utility.mFacebook.getAccessToken());
                Utility.mAsyncRunner.request("me/permissions", params, new permissionsRequestListener());
            } else {
                new PermissionsDialog(GraphExplorer.this).show();
            }
        }
    });

    mFieldsConnectionsButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (metadataObject == null) {
                makeToast("No fields, connections availalbe for this object.");
            } else {
                new FieldsConnectionsDialog(GraphExplorer.this, metadataObject).show();
            }
        }
    });

    mTextDeleteButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            url = BASE_GRAPH_URL; // Base URL
            mParentObjectId = "";
            mInputId.setText("");
            params.clear();
            metadataObject = null;
            setText("");
            mBackParentButton.setVisibility(View.INVISIBLE);
        }
    });

    mMeButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mInputId.setText("me");
            mSubmitButton.performClick();
        }
    });

    mBackParentButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            mInputId.setText(mParentObjectId);
            mParentObjectId = "";
            mSubmitButton.performClick();
        }
    });
}

From source file:net.carlh.toast.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    pager = (ViewPager) findViewById(R.id.pager);
    adapter = new Adapter(getSupportFragmentManager());
    pager.setAdapter(adapter);/*w  w w. j  av  a  2 s . c  om*/

    /* State: this must update the UI and the server
       when it changes.
    */

    state = new State(this);
    state.addHandler(new Handler() {
        public void handleMessage(Message message) {

            /* Send the change to the server (unless it's something
               that only goes server -> client).
            */
            int property = message.getData().getInt("property");
            if (property != State.TEMPERATURES && client != null) {
                JSONObject json = new JSONObject();
                try {
                    json.put("type", "change");
                } catch (JSONException e) {
                }
                state.addAsJSON(json, property);
                client.send(json);
            }

            /* Update the whole UI */
            update();
        }
    });

    startClient();
}

From source file:com.breadwallet.tools.manager.CurrencyManager.java

private CurrencyManager() {
    currencyListAdapter = new CurrencyListAdapter(ctx);
    handler = new Handler();
}

From source file:net.networksaremadeofstring.rhybudd.ZenossWidgetGraph.java

public void onUpdate(final Context context, final AppWidgetManager appWidgetManager, final int[] appWidgetIds) {
    if (settings == null)
        settings = PreferenceManager.getDefaultSharedPreferences(context);

    wContext = context;/*  w  ww . j  a  v a  2 s.c om*/

    Refresh();

    handler = new Handler() {
        public void handleMessage(Message msg) {
            if (msg.what == 1) {
                Bundle Values = msg.getData();

                final int N = appWidgetIds.length;
                RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.zenoss_widget_graph);
                //Intent intent = new Intent(context, rhestr.class);
                //PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);

                //Log.i("GraphWidget","Drawing Graph!");
                for (int i = 0; i < N; i++) {
                    int appWidgetId = appWidgetIds[i];
                    views.setImageViewBitmap(R.id.graphCanvas, RenderBarGraph(Values.getInt("CritCount"),
                            Values.getInt("ErrCount"), Values.getInt("WarnCount")));
                    appWidgetManager.updateAppWidget(appWidgetId, views);
                }
            }
        }
    };
}

From source file:com.gb.cwsup.activity.CarListActivity.java

private void initView() {
    inflater = LayoutInflater.from(this);
    loadingDialog = new LoadingDialog(this);
    mhandler = new Handler();
    nocar = (LinearLayout) findViewById(R.id.carlist_nomsg);
    carListView = (ListView) findViewById(R.id.carlist_ListView);
    carListView.setOnItemClickListener(new OnItemClickListener() {
        @Override/*ww  w. ja  va 2  s  . com*/
        public void onItemClick(AdapterView<?> arg0, View arg1, int item, long arg3) {
            CarBean car = cars.get(item);
            if (!TextUtils.isEmpty(TYPE) && TYPE.equals("CHOICE")) {
                Map<String, Object> data = new HashMap<String, Object>(1);
                data.put("choiceCAR", car);
                EventBus.getDefault().post(data);
                finish();
                return;
            }
            Intent intent = new Intent(CarListActivity.this, CarAddActivity.class);
            intent.putExtra("CAR", car);
            intent.putExtra("type", "UPDATE");
            CarListActivity.this.startActivity(intent);
        }
    });
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.task_editor);
    setResult(RESULT_CANCELED);/*from   w ww.ja  va  2 s. c  o  m*/
    String taskId = getIntent().getStringExtra("taskId");
    taskListId = getIntent().getStringExtra("taskListId");
    completed = (CheckBox) findViewById(R.id.completed);
    title = (EditText) findViewById(R.id.title);
    dueDate = (EditText) findViewById(R.id.due_date);
    notes = (EditText) findViewById(R.id.notes);
    insertPosition = (Spinner) findViewById(R.id.insert_position);
    insertPosition.setVisibility(taskId == null ? View.VISIBLE : View.GONE);
    if (taskId != null) {
        ((DoItLaterApplication) getApplication()).getTaskManager().getTask(taskListId, taskId, this,
                new Handler() {
                    @Override
                    public void handleMessage(Message msg) {
                        task = (Task) msg.obj;
                        updateCompletedView();
                        updateTitleView();
                        updateDueDateView();
                        updateNotesView();
                    }
                });
    } else {
        ((Button) findViewById(R.id.save)).setText(R.string.create);
        task = new Task();
    }
}

From source file:ibp.plugin.nsd.NSDPlugin.java

private void initNsd(CallbackContext callbackContext) {
    final CallbackContext cbc = callbackContext;
    initNsdCB = callbackContext;/*  www.ja  v  a2s  . c  o m*/
    try {
        if (null == mHandler) {
            mHandler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    String type = msg.getData().getString("type");
                    String message = msg.getData().getString("msg");

                    JSONObject data = new JSONObject();
                    try {
                        data.put("type", new String(type));
                        data.put("data", new String(message));
                    } catch (JSONException e) {
                    }
                    PluginResult result = new PluginResult(PluginResult.Status.OK, data);
                    result.setKeepCallback(true);
                    cbc.sendPluginResult(result);
                }
            };
            if (null == mNsdHelper) {
                mNsdHelper = new NSDHelper(cordova.getActivity(), mHandler);
                mNsdHelper.initializeNsd();
            }
            PluginResult result = new PluginResult(PluginResult.Status.OK, "initNsd: success.");
            result.setKeepCallback(true);
            callbackContext.sendPluginResult(result);
        } else {
            PluginResult result = new PluginResult(PluginResult.Status.ERROR,
                    "initNsd: Nsd Has been Initialized.");
            callbackContext.sendPluginResult(result);
        }
    } catch (Exception e) {
        PluginResult result = new PluginResult(PluginResult.Status.ERROR, "initNsd Exception: " + e);
        callbackContext.sendPluginResult(result);
    }
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_face_value);

    initView();//from   ww w  .j a v a  2 s.c o m

    handler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
            case 0:
                Toast.makeText(FaceValueActivity.this, Constants.NO_INTENT_TIPS, Toast.LENGTH_SHORT).show();
                break;
            case 1:
                list = new ArrayList<FaceValue>();
                try {
                    JSONObject jsonObject = new JSONObject(dataJson);
                    if (jsonObject.getString("sum").equals("null")) {
                        face_vale_sum.setText("0");
                        face_vale_sum_yuan.setText("");
                    } else {
                        face_vale_sum
                                .setText(ChineseMoneyUtils.numWithDigitArray(jsonObject.getDouble("sum"))[0]);
                        face_vale_sum_yuan
                                .setText(ChineseMoneyUtils.numWithDigitArray(jsonObject.getDouble("sum"))[1]);
                    }
                    JSONArray jsonArray = jsonObject.getJSONArray("data");

                    for (int i = 0; i < jsonArray.length(); i++) {

                        FaceValue faceValue = new FaceValue();
                        faceValue.setTime(jsonArray.getJSONObject(i).getString("create_time"));
                        faceValue.setName(jsonArray.getJSONObject(i).getString("name"));
                        faceValue.setMoney(jsonArray.getJSONObject(i).getString("income"));
                        list.add(faceValue);
                    }
                    faceValueAdapter = new FaceValueAdapter(FaceValueActivity.this, R.layout.face_value_item,
                            list);
                    face_value_list.setAdapter(faceValueAdapter);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                break;
            default:
                break;
            }
        }
    };

    getData();
    mBackImg.setOnClickListener(this);
}

From source file:com.nextgis.uikobserver.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mFillDataHandler = new Handler() {
        public void handleMessage(Message msg) {
            Bundle resultData = msg.getData();
            boolean bHaveErr = resultData.getBoolean("error");
            if (bHaveErr) {
                Toast.makeText(MainActivity.this, getResources().getText(R.string.sFailed), Toast.LENGTH_LONG)
                        .show();/*w  w  w  . j  ava 2s  . c om*/
            } else {
                Toast.makeText(MainActivity.this, getResources().getText(R.string.sSuccess), Toast.LENGTH_LONG)
                        .show();
            }
        };
    };

    sendButton = (Button) findViewById(R.id.sendDataBtn);
    sendButton.setEnabled(false);
    sendButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            SendData();
        }
    });

    tvLoc = (TextView) findViewById(R.id.locationString);

    tvUIK = (TextView) findViewById(R.id.uikNo);
    tvEMail = (TextView) findViewById(R.id.userMail);
    tvNote = (TextView) findViewById(R.id.notesString);

    locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
    currentLocationListener = new CurrentLocationListener();

    dfLon = 200;
    dfLat = 200;

    sN = (String) getResources().getText(R.string.compas_N);
    sS = (String) getResources().getText(R.string.compas_S);
    sW = (String) getResources().getText(R.string.compas_W);
    sE = (String) getResources().getText(R.string.compas_E);

    sCoordLat = (String) getResources().getText(R.string.coord_lat);
    sCoordLon = (String) getResources().getText(R.string.coord_lon);

    //sUIK, sMail, sNote

    requestLocationUpdates();
}

From source file:com.mrcaps.taskswidget.TasksHelper.java

private static Handler getHandler() {
    if (handl == null) {
        handl = new Handler();
    }
    return handl;
}