Example usage for android.content Intent getIntExtra

List of usage examples for android.content Intent getIntExtra

Introduction

In this page you can find the example usage for android.content Intent getIntExtra.

Prototype

public int getIntExtra(String name, int defaultValue) 

Source Link

Document

Retrieve extended data from the intent.

Usage

From source file:com.daiv.android.twitter.services.SendTweet.java

@Override
public int onStartCommand(Intent intent, int i, int x) {

    final Context context = this;
    final AppSettings settings = AppSettings.getInstance(this);

    try {//from   www  .ja va2s . c o  m
        if (intent == null) {
            return START_NOT_STICKY;
        }
    } catch (Exception e) {
        // null pointer... what the hell
    }
    // set up the tweet from the intent
    message = intent.getStringExtra("message");
    tweetId = intent.getLongExtra("tweet_id", 0l);
    remainingChars = intent.getIntExtra("char_remaining", 0);
    pwiccer = intent.getBooleanExtra("pwiccer", false);
    attachedUri = intent.getStringExtra("attached_uri");
    secondAcc = intent.getBooleanExtra("second_account", false);

    if (attachedUri == null) {
        attachedUri = "";
    }

    sendingNotification();

    new Thread(new Runnable() {
        @Override
        public void run() {
            boolean sent = sendTweet(settings, context);

            if (sent) {
                finishedTweetingNotification();
            } else {
                makeFailedNotification(message, settings);
            }

            finished = true;

            stopSelf();
        }
    }).start();

    // if it takes longer than 2 mins to preform the sending, then something is wrong and we will just shut it down.
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            if (!finished) {
                stopForeground(true);
                makeFailedNotification(message, settings);
                stopSelf();
            }
        }
    }, 120000);

    return START_STICKY;
}

From source file:com.jesusla.google.BillingReceiver.java

/**
 * This is the entry point for all asynchronous messages sent from Android Market to
 * the application. This method forwards the messages on to the
 * {@link BillingService}, which handles the communication back to Android Market.
 * The {@link BillingService} also reports state changes back to the application through
 * the {@link ResponseHandler}.//from  w  ww. j  ava 2s.co  m
 */
@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (Consts.ACTION_PURCHASE_STATE_CHANGED.equals(action)) {
        String signedData = intent.getStringExtra(Consts.INAPP_SIGNED_DATA);
        String signature = intent.getStringExtra(Consts.INAPP_SIGNATURE);
        purchaseStateChanged(context, signedData, signature);
    } else if (Consts.ACTION_NOTIFY.equals(action)) {
        String notifyId = intent.getStringExtra(Consts.NOTIFICATION_ID);
        if (Consts.DEBUG) {
            Log.i(TAG, "notifyId: " + notifyId);
        }
        notify(context, notifyId);
    } else if (Consts.ACTION_RESPONSE_CODE.equals(action)) {
        long requestId = intent.getLongExtra(Consts.INAPP_REQUEST_ID, -1);
        int responseCodeIndex = intent.getIntExtra(Consts.INAPP_RESPONSE_CODE,
                ResponseCode.RESULT_ERROR.ordinal());
        checkResponseCode(context, requestId, responseCodeIndex);
    } else {
        Log.w(TAG, "unexpected action: " + action);
    }
}

From source file:com.android.packageinstaller.PackageInstallerActivity.java

/** Get the originating uid if possible, or VerificationParams.NO_UID if not available */
private int getOriginatingUid(Intent intent) {
    // The originating uid from the intent. We only trust/use this if it comes from a
    // system application
    int uidFromIntent = intent.getIntExtra(Intent.EXTRA_ORIGINATING_UID, VerificationParams.NO_UID);

    // Get the source info from the calling package, if available. This will be the
    // definitive calling package, but it only works if the intent was started using
    // startActivityForResult,
    ApplicationInfo sourceInfo = getSourceInfo();
    if (sourceInfo != null) {
        if (uidFromIntent != VerificationParams.NO_UID
                && (mSourceInfo.privateFlags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0) {
            return uidFromIntent;

        }/*from   w  w w. j a va  2s .  co  m*/
        // We either didn't get a uid in the intent, or we don't trust it. Use the
        // uid of the calling package instead.
        return sourceInfo.uid;
    }

    // We couldn't get the specific calling package. Let's get the uid instead
    int callingUid;
    try {
        callingUid = ActivityManagerNative.getDefault().getLaunchedFromUid(getActivityToken());
    } catch (android.os.RemoteException ex) {
        Log.w(TAG, "Could not determine the launching uid.");
        // nothing else we can do
        return VerificationParams.NO_UID;
    }

    // If we got a uid from the intent, we need to verify that the caller is a
    // privileged system package before we use it
    if (uidFromIntent != VerificationParams.NO_UID) {
        String[] callingPackages = mPm.getPackagesForUid(callingUid);
        if (callingPackages != null) {
            for (String packageName : callingPackages) {
                try {
                    ApplicationInfo applicationInfo = mPm.getApplicationInfo(packageName, 0);

                    if ((applicationInfo.privateFlags & ApplicationInfo.PRIVATE_FLAG_PRIVILEGED) != 0) {
                        return uidFromIntent;
                    }
                } catch (NameNotFoundException ex) {
                    // ignore it, and try the next package
                }
            }
        }
    }
    // We either didn't get a uid from the intent, or we don't trust it. Use the
    // calling uid instead.
    return callingUid;
}

From source file:com.amaze.filemanager.asynchronous.services.CopyService.java

@Override
public int onStartCommand(Intent intent, int flags, final int startId) {

    Bundle b = new Bundle();
    isRootExplorer = intent.getBooleanExtra(TAG_IS_ROOT_EXPLORER, false);
    ArrayList<HybridFileParcelable> files = intent.getParcelableArrayListExtra(TAG_COPY_SOURCES);
    String targetPath = intent.getStringExtra(TAG_COPY_TARGET);
    int mode = intent.getIntExtra(TAG_COPY_OPEN_MODE, OpenMode.UNKNOWN.ordinal());
    final boolean move = intent.getBooleanExtra(TAG_COPY_MOVE, false);
    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(c);
    accentColor = ((AppConfig) getApplication()).getUtilsProvider().getColorPreference()
            .getCurrentUserColorPreferences(this, sharedPreferences).accent;

    mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    b.putInt(TAG_COPY_START_ID, startId);

    Intent notificationIntent = new Intent(this, MainActivity.class);
    notificationIntent.setAction(Intent.ACTION_MAIN);
    notificationIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    notificationIntent.putExtra(MainActivity.KEY_INTENT_PROCESS_VIEWER, true);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    customSmallContentViews = new RemoteViews(getPackageName(), R.layout.notification_service_small);
    customBigContentViews = new RemoteViews(getPackageName(), R.layout.notification_service_big);

    Intent stopIntent = new Intent(TAG_BROADCAST_COPY_CANCEL);
    PendingIntent stopPendingIntent = PendingIntent.getBroadcast(c, 1234, stopIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    NotificationCompat.Action action = new NotificationCompat.Action(R.drawable.ic_content_copy_white_36dp,
            getString(R.string.stop_ftp), stopPendingIntent);

    mBuilder = new NotificationCompat.Builder(c, NotificationConstants.CHANNEL_NORMAL_ID)
            .setContentIntent(pendingIntent).setSmallIcon(R.drawable.ic_content_copy_white_36dp)
            .setCustomContentView(customSmallContentViews).setCustomBigContentView(customBigContentViews)
            .setCustomHeadsUpContentView(customSmallContentViews)
            .setStyle(new NotificationCompat.DecoratedCustomViewStyle()).addAction(action).setOngoing(true)
            .setColor(accentColor);/*from w w  w .  java2 s .co m*/

    // set default notification views text

    NotificationConstants.setMetadata(c, mBuilder, NotificationConstants.TYPE_NORMAL);

    startForeground(NotificationConstants.COPY_ID, mBuilder.build());
    initNotificationViews();

    b.putBoolean(TAG_COPY_MOVE, move);
    b.putString(TAG_COPY_TARGET, targetPath);
    b.putInt(TAG_COPY_OPEN_MODE, mode);
    b.putParcelableArrayList(TAG_COPY_SOURCES, files);

    super.onStartCommand(intent, flags, startId);
    super.progressHalted();
    //going async
    new DoInBackground(isRootExplorer).execute(b);

    // If we get killed, after returning from here, restart
    return START_STICKY;
}

From source file:dk.ciid.android.infobooth.activities.SubscriptionFinalActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    /* Variables received through Intent */
    Intent openActivity = getIntent(); // this is just for example purpose
    isInDebugMode = openActivity.getBooleanExtra("isInDebugMode", true); // should the app send a welcome sms after subscribing?
    phoneNum = openActivity.getStringExtra("phoneNum"); // get the phonenumber submitted in the last activity
    selectedService = openActivity.getIntExtra("selectedService", 1); // array position of selected service in last activity
    serviceIdItems = openActivity.getStringArrayListExtra("serviceIdItems"); // arraylist of service id's (in database)      
    serviceNameItems = openActivity.getStringArrayListExtra("serviceNameItems"); // arraylist of service names
    serviceDescItems = openActivity.getStringArrayListExtra("serviceDescItems"); // arraylist of service descriptions            
    voice1 = openActivity.getStringExtra("voice1"); // path to voice file 1
    voice2 = openActivity.getStringExtra("voice2"); // path to voice file 2
    voice3 = openActivity.getStringExtra("voice3"); // path to voice file 3
    voice4 = openActivity.getStringExtra("voice4"); // path to voice file 4
    voice5 = openActivity.getStringExtra("voice5"); // path to voice file 5   
    voice6 = openActivity.getStringExtra("voice6"); // path to voice file 6
    /* Variables received through Intent */

    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    /* ARDUINO COMMUNICATION STUFF ********************************************/
    // a reference to the USB system service is obtained so that you can call its methods later on
    mUsbManager = UsbManager.getInstance(this);
    mPermissionIntent = PendingIntent.getBroadcast(this, 0, new Intent(ACTION_USB_PERMISSION), 0);
    IntentFilter filter = new IntentFilter(ACTION_USB_PERMISSION);
    filter.addAction(UsbManager.ACTION_USB_ACCESSORY_DETACHED);
    registerReceiver(mUsbReceiver, filter);

    if (getLastNonConfigurationInstance() != null) {
        mAccessory = (UsbAccessory) getLastNonConfigurationInstance();
        openAccessory(mAccessory);//from ww w. j a v a2  s .  c  o  m
    }
    /* ARDUINO COMMUNICATION STUFF ********************************************/

    gestureScanner = new GestureDetector(this);

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    setContentView(R.layout.activity_subscription_final);
    if (!isInDebugMode) {
        try {
            //SmsManager smsManager = SmsManager.getDefault();
            //smsManager.sendTextMessage(phoneNumber, null, SMSMessage, null, null);
            Toast.makeText(getApplicationContext(), "Thanks for subscribing!", Toast.LENGTH_SHORT).show();
        } catch (Exception e) {
            Toast.makeText(getApplicationContext(), "SMS failed, please try again later!", Toast.LENGTH_SHORT)
                    .show();
            e.printStackTrace();
        }
    } else {
        Toast.makeText(getApplicationContext(), "Debug mode - no SMS sent to save money :)", Toast.LENGTH_SHORT)
                .show();
    }

    // Set up sound playback
    initMediaPlayer();
}

From source file:ch.blinkenlights.android.vanilla.LibraryActivity.java

/**
 * Called by LibraryAdapters when a row's expand arrow has been clicked.
 *
 * @param rowData The data for the row that was clicked.
 *///from   w  ww.j a v a2 s.  c  o  m
public void onItemExpanded(Intent rowData) {
    int type = rowData.getIntExtra(LibraryAdapter.DATA_TYPE, MediaUtils.TYPE_INVALID);
    if (type == MediaUtils.TYPE_PLAYLIST)
        editPlaylist(rowData);
    else
        expand(rowData);
}

From source file:com.hichinaschool.flashcards.anki.multimediacard.activity.MultimediaCardEditorActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_CODE_EDIT_FIELD) {
        if (resultCode == RESULT_OK) {

            IField field = (IField) data.getSerializableExtra(EditFieldActivity.EXTRA_RESULT_FIELD);
            int index = data.getIntExtra(EditFieldActivity.EXTRA_RESULT_FIELD_INDEX, -1);

            // Failed editing activity
            if (index == -1) {
                return;
            }/*from ww  w  .ja  v a 2s  .c  om*/

            mNote.setField(index, field);
            createEditorUI(mNote);
        }

        super.onActivityResult(requestCode, resultCode, data);
    }
}

From source file:com.mozilla.SUTAgentAndroid.SUTAgentAndroid.java

private void monitorBatteryState() {
    battReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            StringBuilder sb = new StringBuilder();

            int rawlevel = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1); // charge level from 0 to scale inclusive
            int scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1); // Max value for charge level
            int status = intent.getIntExtra(BatteryManager.EXTRA_STATUS, -1);
            int health = intent.getIntExtra(BatteryManager.EXTRA_HEALTH, -1);
            boolean present = intent.getBooleanExtra(BatteryManager.EXTRA_PRESENT, false);
            int plugged = intent.getIntExtra(BatteryManager.EXTRA_PLUGGED, -1); //0 if the device is not plugged in; 1 if plugged into an AC power adapter; 2 if plugged in via USB.
            //                int voltage = intent.getIntExtra(BatteryManager.EXTRA_VOLTAGE, -1); // voltage in millivolts
            nBatteryTemp = intent.getIntExtra(BatteryManager.EXTRA_TEMPERATURE, -1); // current battery temperature in tenths of a degree Centigrade
            //                String technology = intent.getStringExtra(BatteryManager.EXTRA_TECHNOLOGY);

            nChargeLevel = -1; // percentage, or -1 for unknown
            if (rawlevel >= 0 && scale > 0) {
                nChargeLevel = (rawlevel * 100) / scale;
            }//from   w ww .java2  s . co  m

            if (plugged > 0)
                sACStatus = "ONLINE";
            else
                sACStatus = "OFFLINE";

            if (present == false)
                sb.append("NO BATTERY");
            else {
                if (nChargeLevel < 10)
                    sb.append("Critical");
                else if (nChargeLevel < 33)
                    sb.append("LOW");
                else if (nChargeLevel > 80)
                    sb.append("HIGH");
            }

            if (BatteryManager.BATTERY_HEALTH_OVERHEAT == health) {
                sb.append("Overheated ");
                sb.append((((float) (nBatteryTemp)) / 10));
                sb.append("(C)");
            } else {
                switch (status) {
                case BatteryManager.BATTERY_STATUS_UNKNOWN:
                    // old emulator; maybe also when plugged in with no battery
                    if (present == true)
                        sb.append(" UNKNOWN");
                    break;
                case BatteryManager.BATTERY_STATUS_CHARGING:
                    sb.append(" CHARGING");
                    break;
                case BatteryManager.BATTERY_STATUS_DISCHARGING:
                    sb.append(" DISCHARGING");
                    break;
                case BatteryManager.BATTERY_STATUS_NOT_CHARGING:
                    sb.append(" NOTCHARGING");
                    break;
                case BatteryManager.BATTERY_STATUS_FULL:
                    sb.append(" FULL");
                    break;
                default:
                    if (present == true)
                        sb.append("Unknown");
                    break;
                }
            }

            sPowerStatus = sb.toString();
        }
    };

    IntentFilter battFilter = new IntentFilter(Intent.ACTION_BATTERY_CHANGED);
    registerReceiver(battReceiver, battFilter);
}

From source file:com.brobwind.brodm.DeviceActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.device);/*from  ww w. j  av a2  s.  c o  m*/

    startService(new Intent(this, NetworkService.class));
    mKit = new Kit();

    Intent intent = getIntent();
    mIpAddr = intent.getStringExtra(STR_IP);
    mPort = intent.getIntExtra(STR_PORT, -1);

    SharedPreferences.Editor editor = getSharedPreferences(STR_PREF, MODE_PRIVATE).edit();
    editor.putString(STR_IP, mIpAddr);
    editor.putInt(STR_PORT, mPort);
    editor.commit();

    TextView statusTv = (TextView) findViewById(R.id.status);
    statusTv.setText(mIpAddr + ":" + mPort);

    // /privet/info
    mTryInfo = (Button) findViewById(R.id.try_info);
    mTryInfo.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mNetService.deviceInfo(mIpAddr, mPort, new NetworkUtils.OnMessage() {
                @Override
                public void onMessage(final String msg, String error) {
                    if (notifyError(mInfo, msg, error))
                        return;

                    int securePort = -1;
                    try {
                        JSONObject target = new JSONObject(msg);
                        JSONObject endpoints = target.getJSONObject("endpoints");
                        securePort = endpoints.getInt("httpsPort");
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                    mNetService.init(mIpAddr, mPort, securePort, new NetworkUtils.Callback() {
                        @Override
                        public void onCertAvailable(X509Certificate chains[], String authType) {
                            final StringBuilder sb = new StringBuilder();
                            for (X509Certificate chain : chains) {
                                sb.append(chain.toString());
                            }
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    mCert.setText(sb.toString());
                                }
                            });
                        }
                    });

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            enableFuncs(mFuncInfo, null /*mFuncPairing*/);
                            mInfo.setText(msg);
                        }
                    });
                }
            });
        }
    });
    mInfo = (TextView) findViewById(R.id.info);

    // CERT: /privet/info
    mTryCert = (Button) findViewById(R.id.try_cert);
    mTryCert.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mNetService.fetchCert("/privet/info", new NetworkUtils.OnMessage() {
                @Override
                public void onMessage(final String msg, String error) {
                    Toast.makeText(DeviceActivity.this, "Web server certificate fetched!", Toast.LENGTH_SHORT)
                            .show();
                }
            });
        }
    });
    mCert = (TextView) findViewById(R.id.cert);

    // /privet/v3/pairing/start
    mTryPairingStart = (Button) findViewById(R.id.try_pairing_start);
    mTryPairingStart.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mNetService.pairingStart("/privet/v3/pairing/start", new NetworkUtils.OnMessage() {
                @Override
                public void onMessage(final String msg, String error) {
                    if (notifyError(mPairingStart, msg, error))
                        return;

                    try {
                        JSONObject target = new JSONObject(msg);
                        String id = target.getString("sessionId");
                        String devCmt = target.getString("deviceCommitment");

                        mKit.create("hello", id, devCmt);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            //                        enableFuncs(mFuncPairing, new Button[] { mTryAuth} );
                            mPairingStart.setText(msg);
                        }
                    });
                }
            });
        }
    });
    mPairingStart = (TextView) findViewById(R.id.pairing_start);

    // /privet/v3/pairing/confirm
    mTryPairingConfirm = (Button) findViewById(R.id.try_pairing_confirm);
    mTryPairingConfirm.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mNetService.pairingConfirm("/privet/v3/pairing/confirm", mKit.getId(), mKit.getCliCmt(),
                    new NetworkUtils.OnMessage() {
                        @Override
                        public void onMessage(final String msg, String error) {
                            if (notifyError(mPairingConfirm, msg, error))
                                return;

                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    //                        enableFuncs(new Button[] { mTryAuth }, null);
                                    mPairingConfirm.setText(msg);
                                }
                            });
                        }
                    });
        }
    });
    mPairingConfirm = (TextView) findViewById(R.id.pairing_confirm);

    // /privet/v3/pairing/cancel
    mTryPairingCancel = (Button) findViewById(R.id.try_pairing_cancel);
    mTryPairingCancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mNetService.pairingCancel("/privet/v3/pairing/cancel", mKit.getId(), new NetworkUtils.OnMessage() {
                @Override
                public void onMessage(final String msg, String error) {
                    if (notifyError(mPairingStart, msg, error))
                        return;

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            mPairingCancel.setText(msg);
                        }
                    });
                }
            });
        }
    });
    mPairingCancel = (TextView) findViewById(R.id.pairing_cancel);

    // /privet/v3/auth
    mTryAuth = (Button) findViewById(R.id.try_auth);
    mTryAuth.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mNetService.startAuth("/privet/v3/auth", mKit.getId(), mKit.getAuthCode(),
                    new NetworkUtils.OnMessage() {
                        @Override
                        public void onMessage(final String msg, String error) {
                            if (notifyError(mPairingStart, msg, error))
                                return;

                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    mAuth.setText(msg);
                                }
                            });

                            try {
                                JSONObject target = new JSONObject(msg);
                                mAccessToken = target.getString("accessToken");
                            } catch (JSONException e) {
                                e.printStackTrace();
                            }
                        }
                    });
        }
    });
    mAuth = (TextView) findViewById(R.id.auth);

    // /privet/v3/traits
    mTryTraits = (Button) findViewById(R.id.try_traits);
    mTryTraits.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mNetService.showTraits("/privet/v3/traits", mAccessToken, new NetworkUtils.OnMessage() {
                @Override
                public void onMessage(final String msg, String error) {
                    if (notifyError(mTraits, msg, error))
                        return;

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            mTraits.setText(msg);
                        }
                    });
                }
            });
        }
    });
    mTraits = (TextView) findViewById(R.id.traits);

    // /privet/v3/components
    mTryComponents = (Button) findViewById(R.id.try_components);
    mTryComponents.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mNetService.showComponents("/privet/v3/components", mAccessToken, new NetworkUtils.OnMessage() {
                @Override
                public void onMessage(final String msg, String error) {
                    if (notifyError(mComponents, msg, error))
                        return;

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            mComponents.setText(msg);
                        }
                    });
                }
            });
        }
    });
    mComponents = (TextView) findViewById(R.id.components);

    // /privet/v3/state
    mTryState = (Button) findViewById(R.id.try_state);
    mTryState.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String cmd = "{}";
            mNetService.showCommand("/privet/v3/state", mAccessToken, cmd, new NetworkUtils.OnMessage() {
                @Override
                public void onMessage(final String msg, String error) {
                    if (notifyError(mCmdInfo, msg, error))
                        return;

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            mCmdInfo.setText(msg);
                        }
                    });
                }
            });
        }
    });
    // /privet/v3/commandDefs
    mTryCmdDefs = (Button) findViewById(R.id.try_cmd_defs);
    mTryCmdDefs.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String cmd = "{}";
            mNetService.showCommand("/privet/v3/commandDefs", mAccessToken, cmd, new NetworkUtils.OnMessage() {
                @Override
                public void onMessage(final String msg, String error) {
                    if (notifyError(mCmdInfo, msg, error))
                        return;

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            mCmdInfo.setText(msg);
                        }
                    });
                }
            });
        }
    });
    // /privet/v3/command/status
    mTryCmdStatus = (Button) findViewById(R.id.try_cmd_status);
    mTryCmdStatus.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String cmd = "{}";
            mNetService.showCommand("/privet/v3/commands/status", mAccessToken, cmd,
                    new NetworkUtils.OnMessage() {
                        @Override
                        public void onMessage(final String msg, String error) {
                            if (notifyError(mCmdInfo, msg, error))
                                return;

                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    mCmdInfo.setText(msg);
                                }
                            });
                        }
                    });
        }
    });
    // /privet/v3/command/list
    mTryCmdList = (Button) findViewById(R.id.try_cmd_list);
    mTryCmdList.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String cmd = "{}";
            mNetService.showCommand("/privet/v3/commands/list", mAccessToken, cmd,
                    new NetworkUtils.OnMessage() {
                        @Override
                        public void onMessage(final String msg, String error) {
                            if (notifyError(mCmdInfo, msg, error))
                                return;

                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    mCmdInfo.setText(msg);
                                }
                            });
                        }
                    });
        }
    });
    mCmdInfo = (TextView) findViewById(R.id.cmd_info);

    // /privet/v3/command/exectue
    mTryCmdExec = (Button) findViewById(R.id.try_cmd_exec);
    mTryCmdExec.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            String cmd = ((CharSequence) mCmd.getText()).toString();
            mNetService.showCommand("/privet/v3/commands/execute", mAccessToken, cmd,
                    new NetworkUtils.OnMessage() {
                        @Override
                        public void onMessage(final String msg, String error) {
                            if (notifyError(mCmdExec, msg, error))
                                return;

                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    mCmdExec.setText(msg);
                                }
                            });
                        }
                    });
        }
    });
    mCmd = (EditText) findViewById(R.id.cmd);
    mCmd.setText(/*
                 "{\n" +
                 "   \"component\": \"_ledflasher\",\n" +
                 "   \"name\": \"_ledflasher.set\",\n" +
                 "   \"parameters\": {\n" +
                 "      \"led\": 2,\n" +
                 "      \"on\": true\n" +
                 "   }\n" +
                 "}" */
            "{\n" + "   \"name\": \"_ledflasher.animate\",\n" + "   \"parameters\": {\n"
                    + "      \"duration\": 0.2,\n" + "      \"type\": \"marquee_left\"\n" + "   }\n" + "}");
    mCmdExec = (TextView) findViewById(R.id.cmd_exec);

    mFuncAll = new Button[] { mTryInfo, mTryCert, mTryPairingStart, mTryPairingConfirm, mTryPairingCancel,
            mTryAuth, mTryTraits, mTryComponents, mTryState, mTryCmdDefs, mTryCmdStatus, mTryCmdList,
            mTryCmdExec, };
    mFuncInfo = new Button[] { mTryCert, mTryPairingStart, mTryPairingConfirm, mTryPairingCancel, mTryAuth,
            mTryTraits, mTryComponents, mTryState, mTryCmdDefs, mTryCmdStatus, mTryCmdList, mTryCmdExec, };
    mFuncPairing = new Button[] { mTryPairingConfirm, mTryPairingCancel, mTryAuth };
}

From source file:com.bangz.shotrecorder.RecordActivity.java

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

    setContentView(R.layout.activity_recorder);

    ActionBar bar = getSupportActionBar();
    bar.setDisplayHomeAsUpEnabled(true);

    strModeNames = getResources().getStringArray(R.array.mode_names);
    strModeValNames = getResources().getStringArray(R.array.mode_value_names);

    mMode = MODE.COMSTOCK;//  ww w .j  ava 2 s .co  m

    setDigitFont();

    initButtonsListener();

    TextView v = (TextView) findViewById(R.id.textTIME);
    v.setText("------");

    FragmentManager fm = getSupportFragmentManager();
    SplitListFragment splitfragment = (SplitListFragment) fm.findFragmentById(R.id.splitlist);

    mSplitAdapter = new SplitArrayAdapter(this, mSplitManager.getSplits());

    splitfragment.setListAdapter(mSplitAdapter);

    if (savedInstanceState == null) {
        Intent intent = getIntent();
        if (intent.getBooleanExtra(EXTRA_STARTFROMNOTIFY, false)) {
            mState = STATE_RECORDING;

            int mode = intent.getIntExtra(RecordService.EXTRA_MODE, 0);
            Log.d(TAG, "get mode in RecordActivity from service mode = " + mode);
            mMode = MODE.values()[mode];

            mSampleRate = intent.getIntExtra(RecordService.EXTRA_SAMPLERATE, 44100);
            mChannels = intent.getIntExtra(RecordService.EXTRA_CHANNLES, AudioFormat.CHANNEL_IN_MONO);
            mEncoding = intent.getIntExtra(RecordService.EXTRA_ENCODDING, AudioFormat.ENCODING_PCM_16BIT);

            mMaxShots = intent.getIntExtra(RecordService.EXTRA_MAXSHOT, 0);
            mMaxParTime = intent.getIntExtra(RecordService.EXTRA_MAXPARTIME, 0) / 1000.0f;

            mCaptureSize = intent.getIntExtra(RecordService.EXTRA_CAPTURESIZE, 0);
            mMaxRecordTime = intent.getIntExtra(RecordService.EXTRA_MAXRECORDTIME, 5 * 60);
        }

    }

    updateMode();
    updateStatus();

}