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.insthub.O2OMobile.Activity.D1_OrderActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.d1_order_listview);

    mBack = (ImageView) findViewById(R.id.top_view_back);
    mTitle = (TextView) findViewById(R.id.top_view_title);
    mRightText = (TextView) findViewById(R.id.top_view_right_text);
    mBack.setOnClickListener(new OnClickListener() {

        @Override/*from   w  w  w . ja v  a  2s .c o  m*/
        public void onClick(View v) {
            // TODO Auto-generated method stub
            finish();
        }
    });
    mTitle.setText(getString(R.string.order_detail));
    mRightText.setVisibility(View.VISIBLE);

    DisplayMetrics dm = getResources().getDisplayMetrics();
    mWidthPixels = dm.widthPixels;

    Intent intent = getIntent();
    mOrderId = intent.getIntExtra(ORDER_ID, 0);

    mHeaderView = LayoutInflater.from(this).inflate(R.layout.d1_order, null);
    mXListView = (XListView) findViewById(R.id.order_listview);
    mXListView.addHeaderView(mHeaderView);
    mXListView.setPullLoadEnable(false);
    mXListView.loadMoreHide();
    mXListView.setRefreshTime();
    mXListView.setXListViewListener(this, 1);
    mXListView.setAdapter(null);

    mOrderBtnCancel = (Button) findViewById(R.id.order_button_cancel);
    mOrderBtnOk = (Button) findViewById(R.id.order_button_ok);
    mOrderEmptyView = (ImageView) findViewById(R.id.order_empty_view);

    mOrderPlay = findViewById(R.id.order_play);
    mOrderPlayOrderView = (LinearLayout) findViewById(R.id.order_play_order_view);
    mOrderPlayOrderSn = (TextView) findViewById(R.id.order_play_order_sn);
    mOrderPlayOrderServiceType = (TextView) findViewById(R.id.order_play_order_service_type);
    mOrderPlayOrderLocation = (TextView) findViewById(R.id.order_play_order_location);
    mOrderPlayOrderPrice = (TextView) findViewById(R.id.order_play_order_price);
    mOrderPlayButtonView = (LinearLayout) findViewById(R.id.order_play_button_view);
    mOrderPlayOnline = (Button) findViewById(R.id.order_play_online);
    mOrderPlayOffline = (Button) findViewById(R.id.order_play_offline);
    mOrderPlayCancel = (Button) findViewById(R.id.order_play_cancel);

    mOrderEmployerAvatar = (RoundedWebImageView) mHeaderView.findViewById(R.id.order_employer_avatar);
    mOrderEmployerName = (TextView) mHeaderView.findViewById(R.id.order_employer_name);
    mOrderEmployerPhone = (ImageView) mHeaderView.findViewById(R.id.order_employer_phone);
    mOrderTime = (TextView) mHeaderView.findViewById(R.id.order_time);
    mOrderSn = (TextView) mHeaderView.findViewById(R.id.order_sn);
    mOrderServiceType = (TextView) mHeaderView.findViewById(R.id.order_service_type);
    mOrderAppointmentTime = (TextView) mHeaderView.findViewById(R.id.order_appointment_time);
    mOrderLocation = (TextView) mHeaderView.findViewById(R.id.order_location);
    mOrderPrice = (TextView) mHeaderView.findViewById(R.id.order_price);
    mOrderTransactionPriceView = (LinearLayout) mHeaderView.findViewById(R.id.order_transaction_price_view);
    mOrderTransactionPrice = (TextView) mHeaderView.findViewById(R.id.order_transaction_price);
    mOrderContentText = (TextView) mHeaderView.findViewById(R.id.order_content_text);
    mOrderContentVoiceView = (LinearLayout) mHeaderView.findViewById(R.id.order_content_voice_view);
    mOrderContentVoiceIcon = (ImageView) mHeaderView.findViewById(R.id.order_content_voice_icon);
    mOrderContentVoiceTime = (TextView) mHeaderView.findViewById(R.id.order_content_voice_time);
    mOrderStatusView = (LinearLayout) mHeaderView.findViewById(R.id.order_status_view);
    mOrderStatus = (TextView) mHeaderView.findViewById(R.id.order_status);
    mOrderStatusArrow = (ImageView) mHeaderView.findViewById(R.id.order_status_arrow);
    mOrderVisibleButtonView = mHeaderView.findViewById(R.id.order_visible_button_view);
    mOrderWaitView = (LinearLayout) mHeaderView.findViewById(R.id.order_wait_view);
    mOrderEmployeeCount = (TextView) mHeaderView.findViewById(R.id.order_employee_count);
    mOrderEmployeeView = (LinearLayout) mHeaderView.findViewById(R.id.order_employee_view);
    mOrderEmployeeAvatar = (RoundedWebImageView) mHeaderView.findViewById(R.id.order_employee_avatar);
    mOrderEmployeeName = (TextView) mHeaderView.findViewById(R.id.order_employee_name);
    mOrderEmployeePhone = (ImageView) mHeaderView.findViewById(R.id.order_employee_phone);
    mOrderCommentView = (LinearLayout) mHeaderView.findViewById(R.id.order_comment_view);
    mAcceptOrderTime = (TextView) mHeaderView.findViewById(R.id.accept_order_time);

    mRightText.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(D1_OrderActivity.this, G0_ReportActivity.class);
            intent.putExtra("orderId", mOrderId);
            startActivity(intent);
        }
    });
    mOrderEmptyView.setOnClickListener(null);
    mOrderPlayOrderView.setOnClickListener(null);
    mOrderPlay.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            AnimationUtil.backAnimationFromBottom(mOrderPlayOrderView);
            mOrderPlayOrderView.setVisibility(View.GONE);
            AnimationUtil.backAnimation(mOrderPlayButtonView);
            mOrderPlayButtonView.setVisibility(View.GONE);
            Handler mHandler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    super.handleMessage(msg);
                    mOrderPlay.setVisibility(View.GONE);
                    mOrderBtnCancel.setVisibility(View.VISIBLE);
                }
            };
            mHandler.sendEmptyMessageDelayed(0, 200);
        }
    });

    mOrderPlayOnline.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            payCode = ENUM_PAY_CODE.PAY_ONLINE;
            mOrderInfoModel.pay(mOrderId, ENUM_PAY_CODE.PAY_ONLINE.value());

        }
    });

    mOrderPlayOffline.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            payCode = ENUM_PAY_CODE.PAY_OFFLINE;
            mOrderInfoModel.pay(mOrderId, ENUM_PAY_CODE.PAY_OFFLINE.value());
        }
    });

    mOrderPlayCancel.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            AnimationUtil.backAnimationFromBottom(mOrderPlayOrderView);
            mOrderPlayOrderView.setVisibility(View.GONE);
            AnimationUtil.backAnimation(mOrderPlayButtonView);
            mOrderPlayButtonView.setVisibility(View.GONE);
            Handler mHandler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    super.handleMessage(msg);
                    mOrderPlay.setVisibility(View.GONE);
                    mOrderBtnCancel.setVisibility(View.VISIBLE);
                }
            };
            mHandler.sendEmptyMessageDelayed(0, 200);
        }
    });

    mOrderStatusView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Intent intent = new Intent(D1_OrderActivity.this, D2_OrderHistoryActivity.class);
            intent.putExtra("order_id", mOrderId);
            startActivity(intent);
        }
    });

    mOrderInfoModel = new OrderInfoModel(this);
    mOrderInfoModel.addResponseListener(this);
    mOrderInfoModel.get(mOrderId);

}

From source file:com.mobiperf.MeasurementScheduler.java

/**
 * Adds a string to the corresponding console depending on whether the result is a user
 * measurement or a system measurement/*from ww w  .jav  a 2s. co m*/
 */
private void updateResultsConsole(Intent intent) {
    int priority = intent.getIntExtra(UpdateIntent.TASK_PRIORITY_PAYLOAD, MeasurementTask.INVALID_PRIORITY);
    String msg = intent.getStringExtra(UpdateIntent.STRING_PAYLOAD);
    if (msg == null) {
        // Pull out error string instead
        msg = intent.getStringExtra(UpdateIntent.ERROR_STRING_PAYLOAD);
    }
    if (msg != null) {
        if (priority == MeasurementTask.USER_PRIORITY) {
            insertStringToConsole(userResults, msg);
        } else if (priority != MeasurementTask.INVALID_PRIORITY) {
            insertStringToConsole(systemResults, msg);
        }
    }
}

From source file:com.google.android.apps.santatracker.presentquest.PlacesIntentService.java

@Override
protected void onHandleIntent(Intent intent) {
    if (intent != null) {
        final String action = intent.getAction();
        switch (action) {
        case ACTION_SEARCH_NEARBY:
            // Don't allow more than X queries at once.
            if (mQueriesInProgress.get() >= MAX_QUERIES_IN_PROGRESS) {
                Log.d(TAG, "Dropping excess query");
                return;
            }//from  w ww  . j a  v  a 2  s  . c  om

            // Mark query started
            mQueriesInProgress.incrementAndGet();

            if (mPreferences == null) {
                mPreferences = new PreferencesUtil(this);
            }
            if (mConfig == null) {
                mConfig = new Config();
            }

            // Perform query
            final LatLng center = intent.getParcelableExtra(EXTRA_LAT_LNG);
            final int radius = intent.getIntExtra(EXTRA_RADIUS, 0);
            getPlaceAndBroadcast(center, radius);

            // Mark query finished
            mQueriesInProgress.decrementAndGet();
            break;
        default:
            Log.w(TAG, "Unknown action: " + action);
        }
    }
}

From source file:com.binomed.showtime.android.util.activity.AbstractCineShowTimeActivity.java

@Override
public void onPostContentChanged() {
    boolean titleSet = false;

    final Intent intent = getIntent();
    if (intent != null) {
        String title = intent.getStringExtra(ActionBarActivity.GD_ACTION_BAR_TITLE);
        if (title != null) {
            titleSet = true;/*from   w  w  w  .  j a v  a  2 s . c  o m*/
            setTitle(title);
        }
    }

    if (!titleSet) {
        // No title has been set via the Intent. Let's look in the
        // ActivityInfo
        try {
            final ActivityInfo activityInfo = getPackageManager().getActivityInfo(getComponentName(), 0);
            if (activityInfo.labelRes != 0) {
                setTitle(activityInfo.labelRes);
            }
        } catch (NameNotFoundException e) {
            // Do nothing
        }
    }

    final int visibility = intent.getIntExtra(ActionBarActivity.GD_ACTION_BAR_VISIBILITY, View.VISIBLE);
    getActionBar().setVisibility(visibility);

}

From source file:ch.teamuit.android.soundplusplus.LibraryActivity.java

/**
 * Creates a context menu for an adapter row.
 *
 * @param menu The menu to create./*from w  w  w  .j a  va  2s  . c o m*/
 * @param rowData Data for the adapter row.
 */
public void onCreateContextMenu(ContextMenu menu, Intent rowData) {
    if (rowData.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID) == LibraryAdapter.HEADER_ID) {
        menu.setHeaderTitle(getString(R.string.all_songs));
        menu.add(0, CTX_MENU_PLAY_ALL, 0, R.string.play_all).setIntent(rowData);
        menu.add(0, CTX_MENU_ENQUEUE_ALL, 0, R.string.enqueue_all).setIntent(rowData);
        menu.addSubMenu(0, CTX_MENU_ADD_TO_PLAYLIST, 0, R.string.add_to_playlist).getItem().setIntent(rowData);
    } else {
        int type = rowData.getIntExtra(LibraryAdapter.DATA_TYPE, MediaUtils.TYPE_INVALID);

        menu.setHeaderTitle(rowData.getStringExtra(LibraryAdapter.DATA_TITLE));

        if (FileUtils.canDispatchIntent(rowData))
            menu.add(0, CTX_MENU_OPEN_EXTERNAL, 0, R.string.open).setIntent(rowData);
        menu.add(0, CTX_MENU_PLAY, 0, R.string.play).setIntent(rowData);
        if (type <= MediaUtils.TYPE_SONG) {
            menu.add(0, CTX_MENU_PLAY_ALL, 0, R.string.play_all).setIntent(rowData);
        }
        menu.add(0, CTX_MENU_ENQUEUE_AS_NEXT, 0, R.string.enqueue_as_next).setIntent(rowData);
        menu.add(0, CTX_MENU_ENQUEUE, 0, R.string.enqueue).setIntent(rowData);
        if (type == MediaUtils.TYPE_PLAYLIST) {
            menu.add(0, CTX_MENU_RENAME_PLAYLIST, 0, R.string.rename).setIntent(rowData);
        } else if (rowData.getBooleanExtra(LibraryAdapter.DATA_EXPANDABLE, false)) {
            menu.add(0, CTX_MENU_EXPAND, 0, R.string.expand).setIntent(rowData);
        }
        if (type == MediaUtils.TYPE_ALBUM || type == MediaUtils.TYPE_SONG)
            menu.add(0, CTX_MENU_MORE_FROM_ARTIST, 0, R.string.more_from_artist).setIntent(rowData);
        if (type == MediaUtils.TYPE_SONG)
            menu.add(0, CTX_MENU_MORE_FROM_ALBUM, 0, R.string.more_from_album).setIntent(rowData);
        menu.addSubMenu(0, CTX_MENU_ADD_TO_PLAYLIST, 0, R.string.add_to_playlist).getItem().setIntent(rowData);
        menu.add(0, CTX_MENU_DELETE, 0, R.string.delete).setIntent(rowData);
    }
}

From source file:com.cyanogenmod.eleven.ui.activities.HomeActivity.java

/**
 * Checks whether the passed intent contains a playback request,
 * and starts playback if that's the case
 * @return true if the intent was consumed
 *///from w  ww  .j  av  a 2s  . c om
private boolean handlePlaybackIntent(Intent intent) {

    if (intent == null) {
        return false;
    } else if (!MusicUtils.isPlaybackServiceConnected()) {
        mHasPendingPlaybackRequest = true;
        return false;
    }

    Uri uri = intent.getData();
    String mimeType = intent.getType();
    boolean handled = false;

    if (uri != null && uri.toString().length() > 0) {
        MusicUtils.playFile(this, uri);
        handled = true;
    } else if (MediaStore.Audio.Playlists.CONTENT_TYPE.equals(mimeType)) {
        long id = parseIdFromIntent(intent, "playlistId", "playlist", -1);
        if (id >= 0) {
            MusicUtils.playPlaylist(this, id, false);
            handled = true;
        }
    } else if (MediaStore.Audio.Albums.CONTENT_TYPE.equals(mimeType)) {
        long id = parseIdFromIntent(intent, "albumId", "album", -1);
        if (id >= 0) {
            int position = intent.getIntExtra("position", 0);
            MusicUtils.playAlbum(this, id, position, false);
            handled = true;
        }
    } else if (MediaStore.Audio.Artists.CONTENT_TYPE.equals(mimeType)) {
        long id = parseIdFromIntent(intent, "artistId", "artist", -1);
        if (id >= 0) {
            int position = intent.getIntExtra("position", 0);
            MusicUtils.playArtist(this, id, position, false);
            handled = true;
        }
    }

    // reset intent as it was handled as a playback request
    if (handled) {
        setIntent(new Intent());
    }

    return handled;

}

From source file:com.insthub.O2OMobile.Activity.C1_PublishOrderActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.c1_publish_order);
    mFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    File file = new File(newFileName());
    if (file.exists()) {
        file.delete();/*from  w w w. j  a  v  a  2 s  .c o  m*/
    }

    Intent intent = getIntent();
    mServiceType = (SERVICE_TYPE) intent.getSerializableExtra(O2OMobileAppConst.SERVICE_TYPE);
    mDefaultReceiverId = intent.getIntExtra(DEFAULT_RECEIVER_ID, 0);
    service_list = intent.getStringExtra("service_list");

    mBack = (ImageView) findViewById(R.id.top_view_back);
    mTitle = (TextView) findViewById(R.id.top_view_title);
    mBack.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            finish();
        }
    });
    mArrowImage = (ImageView) findViewById(R.id.top_view_arrow_image);
    mClose = (ImageView) findViewById(R.id.top_view_right_close);
    mTitleView = (LinearLayout) findViewById(R.id.top_view_title_view);
    mServiceTypeView = (FrameLayout) findViewById(R.id.c1_publish_order_service_type_view);
    mServiceTypeListview = (ListView) findViewById(R.id.c1_publish_order_service_type_list);
    mPrice = (EditText) findViewById(R.id.c1_publish_order_price);
    mTime = (TextView) findViewById(R.id.c1_publish_order_time);
    mLocation = (EditText) findViewById(R.id.c1_publish_order_location);
    mText = (EditText) findViewById(R.id.c1_publish_order_text);
    mVoice = (Button) findViewById(R.id.c1_publish_order_voice);
    mVoicePlay = (Button) findViewById(R.id.c1_publish_order_voicePlay);
    mVoiceReset = (ImageView) findViewById(R.id.c1_publish_order_voiceReset);
    mPublish = (Button) findViewById(R.id.c1_publish_order_publish);
    mVoiceView = (FrameLayout) findViewById(R.id.c1_publish_order_voice_view);
    mVoiceAnim = (ImageView) findViewById(R.id.c1_publish_order_voice_anim);
    mVoiceAnim.setImageResource(R.anim.voice_animation);
    mAnimationDrawable = (AnimationDrawable) mVoiceAnim.getDrawable();
    mAnimationDrawable.setOneShot(false);
    mTitleView.setEnabled(false);
    mServiceTypeView.setOnClickListener(null);
    mServiceTypeListview.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            // TODO Auto-generated method stub
            if (mDefaultReceiverId == 0) {
                mTitle.setText(mHomeModel.publicServiceTypeList.get(position).title);
                mServiceTypeId = mHomeModel.publicServiceTypeList.get(position).id;
                mC1PublishOrderAdapter = new C1_PublishOrderAdapter(C1_PublishOrderActivity.this,
                        mHomeModel.publicServiceTypeList, position);
                mServiceTypeListview.setAdapter(mC1PublishOrderAdapter);
                mClose.setVisibility(View.GONE);
                mArrowImage.setImageResource(R.drawable.b3_arrow_down);
                AnimationUtil.backAnimationFromBottom(mServiceTypeListview);
                Handler mHandler = new Handler() {
                    @Override
                    public void handleMessage(Message msg) {
                        super.handleMessage(msg);
                        mServiceTypeView.setVisibility(View.GONE);
                    }
                };
                mHandler.sendEmptyMessageDelayed(0, 200);
            } else {
                mTitle.setText(mServiceTypeList.get(position).title);
                mServiceTypeId = mServiceTypeList.get(position).id;
                mC1PublishOrderAdapter = new C1_PublishOrderAdapter(C1_PublishOrderActivity.this,
                        mServiceTypeList, position);
                mServiceTypeListview.setAdapter(mC1PublishOrderAdapter);
                mClose.setVisibility(View.GONE);
                mArrowImage.setImageResource(R.drawable.b3_arrow_down);
                AnimationUtil.backAnimationFromBottom(mServiceTypeListview);
                Handler mHandler = new Handler() {
                    @Override
                    public void handleMessage(Message msg) {
                        super.handleMessage(msg);
                        mServiceTypeView.setVisibility(View.GONE);
                    }
                };
                mHandler.sendEmptyMessageDelayed(0, 200);
            }

        }
    });

    mTitleView.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            if (mServiceTypeView.getVisibility() == View.GONE) {
                mServiceTypeView.setVisibility(View.VISIBLE);
                mClose.setVisibility(View.VISIBLE);
                mArrowImage.setImageResource(R.drawable.b4_arrow_up);
                AnimationUtil.showAnimationFromTop(mServiceTypeListview);
                closeKeyBoard();
            } else {
                mClose.setVisibility(View.GONE);
                mArrowImage.setImageResource(R.drawable.b3_arrow_down);
                AnimationUtil.backAnimationFromBottom(mServiceTypeListview);
                Handler mHandler = new Handler() {
                    @Override
                    public void handleMessage(Message msg) {
                        super.handleMessage(msg);
                        mServiceTypeView.setVisibility(View.GONE);
                    }
                };
                mHandler.sendEmptyMessageDelayed(0, 200);
            }
        }
    });

    mClose.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            mClose.setVisibility(View.GONE);
            mArrowImage.setImageResource(R.drawable.b3_arrow_down);
            AnimationUtil.backAnimationFromBottom(mServiceTypeListview);
            Handler mHandler = new Handler() {
                @Override
                public void handleMessage(Message msg) {
                    super.handleMessage(msg);
                    mServiceTypeView.setVisibility(View.GONE);
                }
            };
            mHandler.sendEmptyMessageDelayed(0, 200);
        }
    });

    mPrice.addTextChangedListener(new TextWatcher() {

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // TODO Auto-generated method stub
            if (s.toString().length() > 0) {
                if (s.toString().substring(0, 1).equals(".")) {
                    s = s.toString().substring(1, s.length());
                    mPrice.setText(s);
                }
            }
            if (s.toString().length() > 1) {
                if (s.toString().substring(0, 1).equals("0")) {
                    if (!s.toString().substring(1, 2).equals(".")) {
                        s = s.toString().substring(1, s.length());
                        mPrice.setText(s);
                        CharSequence charSequencePirce = mPrice.getText();
                        if (charSequencePirce instanceof Spannable) {
                            Spannable spanText = (Spannable) charSequencePirce;
                            Selection.setSelection(spanText, charSequencePirce.length());
                        }
                    }
                }
            }
            boolean flag = false;
            for (int i = 0; i < s.toString().length() - 1; i++) {
                String getstr = s.toString().substring(i, i + 1);
                if (getstr.equals(".")) {
                    flag = true;
                    break;
                }
            }
            if (flag) {
                int i = s.toString().indexOf(".");
                if (s.toString().length() - 3 > i) {
                    String getstr = s.toString().substring(0, i + 3);
                    mPrice.setText(getstr);
                    CharSequence charSequencePirce = mPrice.getText();
                    if (charSequencePirce instanceof Spannable) {
                        Spannable spanText = (Spannable) charSequencePirce;
                        Selection.setSelection(spanText, charSequencePirce.length());
                    }
                }
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // TODO Auto-generated method stub
        }

        @Override
        public void afterTextChanged(Editable s) {
            // TODO Auto-generated method stub
        }
    });

    initData();

    mHomeModel = new HomeModel(this);
    mHomeModel.addResponseListener(this);
    if (mDefaultReceiverId == 0) {
        mShared = getSharedPreferences(O2OMobileAppConst.USERINFO, 0);
        mHomeData = mShared.getString("home_data", "");
        if ("".equals(mHomeData)) {
            mHomeModel.getServiceTypeList();
        } else {
            try {
                servicetypelistResponse response = new servicetypelistResponse();
                response.fromJson(new JSONObject(mHomeData));
                mHomeModel.publicServiceTypeList = response.services;
                setServiceTypeAdater();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    } else {
        if (service_list != null && !"".equals(service_list)) {
            try {
                JSONObject userJson = new JSONObject(service_list);
                myservicelistResponse response = new myservicelistResponse();
                response.fromJson(userJson);
                for (int i = 0; i < response.services.size(); i++) {
                    SERVICE_TYPE service = new SERVICE_TYPE();
                    service = response.services.get(i).service_type;
                    mServiceTypeList.add(service);
                }
                if (mServiceTypeList.size() > 0) {
                    mTitleView.setEnabled(true);
                    mArrowImage.setVisibility(View.VISIBLE);
                    if (mServiceType != null) {
                        for (int i = 0; i < mServiceTypeList.size(); i++) {
                            if (mServiceType.id == mServiceTypeList.get(i).id) {
                                mC1PublishOrderAdapter = new C1_PublishOrderAdapter(this, mServiceTypeList, i);
                                mServiceTypeListview.setAdapter(mC1PublishOrderAdapter);
                                mTitle.setText(mServiceTypeList.get(i).title);
                                mServiceTypeId = mServiceTypeList.get(i).id;
                                break;
                            }
                        }
                    } else {
                        mC1PublishOrderAdapter = new C1_PublishOrderAdapter(this, mServiceTypeList);
                        mServiceTypeListview.setAdapter(mC1PublishOrderAdapter);
                        mTitle.setText(getString(R.string.select_service));
                    }

                }
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } else {
            mShared = getSharedPreferences(O2OMobileAppConst.USERINFO, 0);
            mHomeData = mShared.getString("home_data", "");
            if ("".equals(mHomeData)) {
                mHomeModel.getServiceTypeList();
            } else {
                try {
                    servicetypelistResponse response = new servicetypelistResponse();
                    response.fromJson(new JSONObject(mHomeData));
                    mHomeModel.publicServiceTypeList = response.services;
                    setServiceTypeAdater();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
    }
    mLocationInfoModel = new LocationInfoModel(this);
    mLocationInfoModel.addResponseListener(this);
    mLocationInfoModel.get();

    mOrderPublishModel = new OrderPublishModel(this);
    mOrderPublishModel.addResponseListener(this);

    //??
    CharSequence charSequencePirce = mPrice.getText();
    if (charSequencePirce instanceof Spannable) {
        Spannable spanText = (Spannable) charSequencePirce;
        Selection.setSelection(spanText, charSequencePirce.length());
    }
    CharSequence charSequenceLocation = mLocation.getText();
    if (charSequenceLocation instanceof Spannable) {
        Spannable spanText = (Spannable) charSequenceLocation;
        Selection.setSelection(spanText, charSequenceLocation.length());
    }

    mVoice.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                closeKeyBoard();
                mVoice.setKeepScreenOn(true);
                mMaxTime = MAX_TIME;
                mVoiceView.setVisibility(View.VISIBLE);
                mAnimationDrawable.start();
                startRecording();
            } else if (event.getAction() == MotionEvent.ACTION_UP) {
                mVoice.setKeepScreenOn(false);
                mVoiceView.setVisibility(View.GONE);
                mAnimationDrawable.stop();
                if (mMaxTime > 28) {
                    mVoice.setEnabled(false);
                    Handler mHandler = new Handler() {
                        @Override
                        public void handleMessage(Message msg) {
                            super.handleMessage(msg);
                            stopRecording();
                            mVoice.setEnabled(true);
                        }
                    };
                    mHandler.sendEmptyMessageDelayed(0, 500);
                } else {
                    stopRecording();
                }
            } else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
                mVoice.setKeepScreenOn(false);
                mVoiceView.setVisibility(View.GONE);
                mAnimationDrawable.stop();
                if (mMaxTime > 28) {
                    mVoice.setEnabled(false);
                    Handler mHandler = new Handler() {
                        @Override
                        public void handleMessage(Message msg) {
                            super.handleMessage(msg);
                            stopRecording();
                            mVoice.setEnabled(true);
                        }
                    };
                    mHandler.sendEmptyMessageDelayed(0, 500);
                } else {
                    stopRecording();
                }
            } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
                mVoice.getParent().requestDisallowInterceptTouchEvent(true);
            }
            return false;
        }
    });

    mVoicePlay.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if (mPlayer == null) {
                File file = new File(mFileName);
                if (file.exists()) {
                    mPlayer = new MediaPlayer();
                    mVoicePlay.setBackgroundResource(R.anim.record_animation);
                    mAnimationDrawable2 = (AnimationDrawable) mVoicePlay.getBackground();
                    mAnimationDrawable2.setOneShot(false);
                    mAnimationDrawable2.start();
                    try {
                        mPlayer.setDataSource(mFileName);
                        mPlayer.prepare();
                        mPlayer.start();
                        mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
                            @Override
                            public void onCompletion(MediaPlayer mp) {
                                mp.reset();
                                mPlayer = null;
                                mVoicePlay.setBackgroundResource(R.drawable.b5_play_btn);
                                mAnimationDrawable2.stop();
                            }
                        });
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                } else {
                    Toast.makeText(C1_PublishOrderActivity.this, getString(R.string.file_does_not_exist),
                            Toast.LENGTH_SHORT).show();
                }
            } else {
                mPlayer.release();
                mPlayer = null;
                mVoicePlay.setBackgroundResource(R.drawable.b5_play_btn);
                mAnimationDrawable2.stop();
            }
        }
    });

    mVoiceReset.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if (mPlayer != null) {
                mPlayer.release();
                mPlayer = null;
                mVoicePlay.setBackgroundResource(R.drawable.b5_play_btn);
                mAnimationDrawable2.stop();
            }
            File file = new File(mFileName);
            if (file.exists()) {
                file.delete();
            }
            mVoice.setVisibility(View.VISIBLE);
            mVoicePlay.setVisibility(View.GONE);
            mVoiceReset.setVisibility(View.GONE);
        }
    });

    mPublish.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            File file = new File(newFileName());
            int duration = 0;
            if (file.exists()) {
                MediaPlayer mp = MediaPlayer.create(C1_PublishOrderActivity.this, Uri.parse(mFileName));
                if (null != mp) {
                    duration = mp.getDuration();//? ms
                    mp.release();
                }
                if (duration % 1000 > 500) {
                    duration = duration / 1000 + 1;
                } else {
                    duration = duration / 1000;
                }
            } else {
                file = null;
            }
            int num = 0;
            try { // ??
                Date date = new Date();
                Date date1 = mFormat.parse(mFormat.format(date));
                Date date2 = mFormat.parse(mTime.getText().toString());
                num = date2.compareTo(date1);

                if (num < 0) {
                    long diff = date1.getTime() - date2.getTime();
                    long mins = diff / (1000 * 60);
                    if (mins < 3) {
                        num = 1;
                    }
                }
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            if (mServiceTypeId == 0) {
                ToastView toast = new ToastView(C1_PublishOrderActivity.this,
                        getString(R.string.select_service));
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            } else if (mPrice.getText().toString().equals("")) {
                ToastView toast = new ToastView(C1_PublishOrderActivity.this, getString(R.string.price_range));
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            } else if (mPrice.getText().toString().equals("0.")) {
                ToastView toast = new ToastView(C1_PublishOrderActivity.this, getString(R.string.right_price));
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            } else if (mTime.getText().toString().equals("")) {
                ToastView toast = new ToastView(C1_PublishOrderActivity.this, getString(R.string.appoint_time));
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            } else if (num < 0) {
                ToastView toast = new ToastView(C1_PublishOrderActivity.this,
                        getString(R.string.wrong_appoint_time_hint));
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            } else if (mLocation.getText().toString().equals("")) {
                ToastView toast = new ToastView(C1_PublishOrderActivity.this,
                        getString(R.string.appoint_location_hint));
                toast.setGravity(Gravity.CENTER, 0, 0);
                toast.show();
            } else {
                mOrderPublishModel.publish(mPrice.getText().toString(), mTime.getText().toString(),
                        mLocation.getText().toString(), mText.getText().toString(), file, mServiceTypeId,
                        mDefaultReceiverId, duration);
            }
        }
    });
}

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

/**
 * Creates a context menu for an adapter row.
 *
 * @param menu The menu to create./*from   w  w  w  .j av a  2  s  .c o  m*/
 * @param rowData Data for the adapter row.
 */
public void onCreateContextMenu(ContextMenu menu, Intent rowData) {
    if (rowData.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID) == LibraryAdapter.HEADER_ID) {
        menu.setHeaderTitle(getString(R.string.all_songs));
        menu.add(0, CTX_MENU_PLAY_ALL, 0, R.string.play_all).setIntent(rowData);
        menu.add(0, CTX_MENU_ENQUEUE_ALL, 0, R.string.enqueue_all).setIntent(rowData);
        menu.addSubMenu(0, CTX_MENU_ADD_TO_PLAYLIST, 0, R.string.add_to_playlist).getItem().setIntent(rowData);
    } else {
        int type = rowData.getIntExtra(LibraryAdapter.DATA_TYPE, MediaUtils.TYPE_INVALID);

        menu.setHeaderTitle(rowData.getStringExtra(LibraryAdapter.DATA_TITLE));

        if (FileUtils.canDispatchIntent(rowData))
            menu.add(0, CTX_MENU_OPEN_EXTERNAL, 0, R.string.open).setIntent(rowData);
        menu.add(0, CTX_MENU_PLAY, 0, R.string.play).setIntent(rowData);
        if (type <= MediaUtils.TYPE_SONG) {
            menu.add(0, CTX_MENU_PLAY_ALL, 0, R.string.play_all).setIntent(rowData);
        }
        menu.add(0, CTX_MENU_ENQUEUE_AS_NEXT, 0, R.string.enqueue_as_next).setIntent(rowData);
        menu.add(0, CTX_MENU_ENQUEUE, 0, R.string.enqueue).setIntent(rowData);
        if (type == MediaUtils.TYPE_PLAYLIST) {
            menu.add(0, CTX_MENU_RENAME_PLAYLIST, 0, R.string.rename).setIntent(rowData);
        } else if (rowData.getBooleanExtra(LibraryAdapter.DATA_EXPANDABLE, false)) {
            menu.add(0, CTX_MENU_EXPAND, 0, R.string.expand).setIntent(rowData);
        }
        if (type == MediaUtils.TYPE_ALBUM || type == MediaUtils.TYPE_SONG)
            menu.add(0, CTX_MENU_MORE_FROM_ARTIST, 0, R.string.more_from_artist).setIntent(rowData);
        if (type == MediaUtils.TYPE_SONG) {
            menu.add(0, CTX_MENU_MORE_FROM_ALBUM, 0, R.string.more_from_album).setIntent(rowData);
            if (PluginUtils.checkPlugins(this))
                menu.add(0, CTX_MENU_PLUGINS, 1, R.string.plugins).setIntent(rowData); // last in order
        }
        menu.addSubMenu(0, CTX_MENU_ADD_TO_PLAYLIST, 0, R.string.add_to_playlist).getItem().setIntent(rowData);
        menu.add(0, CTX_MENU_DELETE, 0, R.string.delete).setIntent(rowData);
    }
}

From source file:com.codemodlabs.coordinate.MainActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    switch (requestCode) {
    case RC_SIGN_IN:
        if (resultCode == RESULT_OK) {
            // If the error resolution was successful we should continue
            // processing errors.
            mSignInProgress = STATE_SIGN_IN;
        } else {//  www  . j a va2s. c  om
            // If the error resolution was not successful or the user canceled,
            // we should stop processing errors.
            mSignInProgress = STATE_DEFAULT;
        }

        if (!mGoogleApiClient.isConnecting()) {
            // If Google Play services resolved the issue with a dialog then
            // onStart is not called so we need to re-attempt connection here.
            mGoogleApiClient.connect();
        }
        break;
    case 10:
        if (resultCode == 2) {
            uberAPI.access_token = data.getStringExtra("access_token");
            uberAPI.expires_in = data.getIntExtra("expires_in", 0);

            SharedPreferences sharedPref = getSharedPreferences("apppreferences", Context.MODE_MULTI_PROCESS);
            SharedPreferences.Editor editor = sharedPref.edit();
            editor.putString("access_token", uberAPI.access_token);
            editor.putInt("expires_in", uberAPI.expires_in);
            editor.commit();

            uberAPI.authenticate();
        }
        break;
    }
}