List of usage examples for android.text Selection setSelection
public static final void setSelection(Spannable text, int index)
index
. From source file:dev.drsoran.moloko.fragments.ChangeTagsFragment.java
private void onListItemClick(ListView l, View v, int position, long id) { final ChangeTag tag = (ChangeTag) l.getAdapter().getItem(position); final Editable tagsEdit = editView.getEditableText(); if (tag.isAvailable) { if (TextUtils.isEmpty(tagsEdit)) { tagsEdit.append(tag.tag);/*from ww w . jav a2 s . com*/ } else { final int trimmedLength = TextUtils.getTrimmedLength(tagsEdit); if (tagsEdit.charAt(trimmedLength - 1) == ',') { tagsEdit.append(tag.tag); } else { tagsEdit.append(", " + tag.tag); } } } else { // Cut the removed tag including any trailing , String content = UIUtils.getTrimmedText(editView); content = content.replaceAll(tag.tag + "\\,*\\s*", Strings.EMPTY_STRING); editView.setText(content); } Selection.setSelection(tagsEdit, tagsEdit.length()); updateTagList(); }
From source file:com.android.launcher3.allapps.FullMergeAlgorithm.java
public AllAppsContainerView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); Resources res = context.getResources(); mLauncher = Launcher.getLauncher(context); mSectionNamesMargin = res.getDimensionPixelSize(R.dimen.all_apps_grid_view_start_margin); mApps = new AlphabeticalAppsList(context); mAdapter = new AllAppsGridAdapter(mLauncher, mApps, mLauncher, this); mApps.setAdapter(mAdapter);/* w ww .ja v a 2 s. c o m*/ mLayoutManager = mAdapter.getLayoutManager(); mItemDecoration = mAdapter.getItemDecoration(); DeviceProfile grid = mLauncher.getDeviceProfile(); if (FeatureFlags.LAUNCHER3_ALL_APPS_PULL_UP && !grid.isVerticalBarLayout()) { mRecyclerViewBottomPadding = 0; setPadding(0, 0, 0, 0); } else { mRecyclerViewBottomPadding = res.getDimensionPixelSize(R.dimen.all_apps_list_bottom_padding); } mSearchQueryBuilder = new SpannableStringBuilder(); Selection.setSelection(mSearchQueryBuilder, 0); }
From source file:org.chromium.chrome.browser.omnibox.LocationBarPhone.java
/** * Handles any actions to be performed after all other actions triggered by the URL focus * change. This will be called after any animations are performed to transition from one * focus state to the other./* www. ja v a 2 s . c o m*/ * @param hasFocus Whether the URL field has gained focus. */ public void finishUrlFocusChange(boolean hasFocus) { final WindowDelegate windowDelegate = getWindowDelegate(); if (!hasFocus) { // Remove the selection from the url text. The ending selection position // will determine the scroll position when the url field is restored. If // we do not clear this, it will scroll to the end of the text when you // enter/exit the tab stack. // We set the selection to 0 instead of removing the selection to avoid a crash that // happens if you clear the selection instead. // // Triggering the bug happens by: // 1.) Selecting some portion of the URL (where the two selection handles // appear) // 2.) Trigger a text change in the URL bar (i.e. by triggering a new URL load // by a command line intent) // 3.) Simultaneously moving one of the selection handles left and right. This will // occasionally throw an AssertionError on the bounds of the selection. if (!mUrlBar.scrollToTLD()) { Selection.setSelection(mUrlBar.getText(), 0); } // The animation rendering may not yet be 100% complete and hiding the keyboard makes // the animation quite choppy. postDelayed(new Runnable() { @Override public void run() { UiUtils.hideKeyboard(mUrlBar); } }, KEYBOARD_HIDE_DELAY_MS); // Convert the keyboard back to resize mode (delay the change for an arbitrary amount // of time in hopes the keyboard will be completely hidden before making this change). if (mKeyboardResizeModeTask == null && windowDelegate .getWindowSoftInputMode() != WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE) { mKeyboardResizeModeTask = new Runnable() { @Override public void run() { windowDelegate.setWindowSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); mKeyboardResizeModeTask = null; } }; postDelayed(mKeyboardResizeModeTask, KEYBOARD_MODE_CHANGE_DELAY_MS); } mUrlActionsContainer.setVisibility(GONE); } else { if (mKeyboardResizeModeTask != null) { removeCallbacks(mKeyboardResizeModeTask); mKeyboardResizeModeTask = null; } if (windowDelegate.getWindowSoftInputMode() != WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN) { windowDelegate.setWindowSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); } UiUtils.showKeyboard(mUrlBar); // As the position of the navigation icon has changed, ensure the suggestions are // updated to reflect the new position. if (getSuggestionList() != null && getSuggestionList().isShown()) { getSuggestionList().invalidateSuggestionViews(); } } setUrlFocusChangeInProgress(false); NewTabPage ntp = getToolbarDataProvider().getNewTabPageForCurrentTab(); if (hasFocus && ntp != null && ntp.isLocationBarShownInNTP() && mBottomSheet == null) { mFadingView.showFadingOverlay(); } }
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 ww w . j ava 2 s.co 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:info.papdt.blacklight.ui.statuses.NewPostActivity.java
@Binded public void topic() { CharSequence text = mText.getText(); mText.getText().insert(mText.getSelectionStart(), "##"); if (text instanceof Spannable) { Selection.setSelection((Spannable) text, text.length() - 1); }/*from w ww . j ava 2 s .co m*/ }
From source file:com.insthub.O2OMobile.Activity.D1_OrderActivity.java
private void showOrderPriceDialog() { LayoutInflater inflater = LayoutInflater.from(D1_OrderActivity.this); View view = inflater.inflate(R.layout.d1_order_price_dialog, null); mPriceDialog = new Dialog(D1_OrderActivity.this, R.style.dialog); mPriceDialog.setContentView(view);//from w w w .j av a 2s.co m mPriceDialog.setCanceledOnTouchOutside(false); mPriceDialog.show(); mOrderPriceDialogPrice = (TextView) view.findViewById(R.id.order_price_dialog_price); mOrderPriceDialogChangePrice = (EditText) view.findViewById(R.id.order_price_dialog_change_price); mOrderPriceDialogOk = (Button) view.findViewById(R.id.order_price_dialog_ok); mOrderPriceDialogCancel = (Button) view.findViewById(R.id.order_price_dialog_cancel); if (mOrderInfoModel.publicOrder.offer_price != null) { mOrderPriceDialogPrice.setText(Utils.formatBalance(mOrderInfoModel.publicOrder.offer_price) + ""); } mOrderPriceDialogChangePrice.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()); mOrderPriceDialogChangePrice.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()); mOrderPriceDialogChangePrice.setText(s); CharSequence charSequencePirce = mOrderPriceDialogChangePrice.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); mOrderPriceDialogChangePrice.setText(getstr); CharSequence charSequencePirce = mOrderPriceDialogChangePrice.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 } }); mOrderPriceDialogCancel.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub mPriceDialog.dismiss(); } }); mOrderPriceDialogOk.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub mOrderInfoModel.done(mOrderId, mOrderPriceDialogChangePrice.getText().toString()); mPriceDialog.dismiss(); } }); }
From source file:com.android.launcher2.Launcher.java
@Override protected void onCreate(Bundle savedInstanceState) { if (DEBUG_STRICT_MODE) { StrictMode.setThreadPolicy(//from w w w . j a va 2s . co m new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork() // or .detectAll() for all detectable problems .penaltyLog().build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects() .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build()); } super.onCreate(savedInstanceState); LauncherApplication app = ((LauncherApplication) getApplication()); mSharedPrefs = getSharedPreferences(LauncherApplication.getSharedPreferencesKey(), Context.MODE_PRIVATE); mModel = app.setLauncher(this); mIconCache = app.getIconCache(); mDragController = new DragController(this); mInflater = getLayoutInflater(); mAppWidgetManager = AppWidgetManager.getInstance(this); mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID); mAppWidgetHost.startListening(); // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here, // this also ensures that any synchronous binding below doesn't re-trigger another // LauncherModel load. mPaused = false; if (PROFILE_STARTUP) { android.os.Debug.startMethodTracing(Environment.getExternalStorageDirectory() + "/launcher"); } checkForLocaleChange(); setContentView(R.layout.launcher); setupViews(); showFirstRunWorkspaceCling(); registerContentObservers(); lockAllApps(); mSavedState = savedInstanceState; restoreState(mSavedState); // Update customization drawer _after_ restoring the states if (mAppsCustomizeContent != null) { mAppsCustomizeContent.onPackagesUpdated(); } if (PROFILE_STARTUP) { android.os.Debug.stopMethodTracing(); } if (!mRestoring) { if (sPausedFromUserAction) { // If the user leaves launcher, then we should just load items asynchronously when // they return. mModel.startLoader(true, -1); } else { // We only load the page synchronously if the user rotates (or triggers a // configuration change) while launcher is in the foreground mModel.startLoader(true, mWorkspace.getCurrentPage()); } } if (!mModel.isAllAppsLoaded()) { ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent(); mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent); } // For handling default keys mDefaultKeySsb = new SpannableStringBuilder(); Selection.setSelection(mDefaultKeySsb, 0); IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); registerReceiver(mCloseSystemDialogsReceiver, filter); updateGlobalIcons(); // On large interfaces, we want the screen to auto-rotate based on the current orientation unlockScreenOrientation(true); }
From source file:com.csipsimple.ui.dialpad.DialerFragment.java
/** * Set the value of the text field and put caret at the end * // w ww . j av a 2 s. c om * @param value the new text to see in the text field */ public void setTextFieldValue(CharSequence value) { if (digits == null) { initText = value.toString(); return; } digits.setText(value); // make sure we keep the caret at the end of the text view Editable spannable = digits.getText(); Selection.setSelection(spannable, spannable.length()); }
From source file:com.gxapplications.android.gxsuite.launcher.Launcher.java
@SuppressWarnings("unused") @Override/* w w w . ja v a 2 s.com*/ protected void onCreate(Bundle savedInstanceState) { if (DEBUG_STRICT_MODE) { StrictMode.setThreadPolicy( new StrictMode.ThreadPolicy.Builder().detectDiskReads().detectDiskWrites().detectNetwork() // or .detectAll() for all detectable problems .penaltyLog().build()); StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectLeakedSqlLiteObjects() .detectLeakedClosableObjects().penaltyLog().penaltyDeath().build()); } super.onCreate(savedInstanceState); LauncherApplication app = ((LauncherApplication) getApplication()); mSharedPrefs = getSharedPreferences(LauncherApplication.getSharedPreferencesKey(), Context.MODE_PRIVATE); mModel = app.setLauncher(this); mIconCache = app.getIconCache(); mDragController = new DragController(this); mInflater = getLayoutInflater(); mAppWidgetManager = AppWidgetManager.getInstance(this); mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID); mAppWidgetHost.startListening(); // If we are getting an onCreate, we can actually preempt onResume and unset mPaused here, // this also ensures that any synchronous binding below doesn't re-trigger another // LauncherModel load. mPaused = false; if (PROFILE_STARTUP) { android.os.Debug.startMethodTracing(Environment.getExternalStorageDirectory() + "/launcher"); } checkForLocaleChange(); if (MainConfiguration.SCREEN_COUNT == 2) { if (MainConfiguration.ALLOW_DRAWER) setContentView(R.layout.drawer_launcher_2); else setContentView(R.layout.launcher_2); } else if (MainConfiguration.SCREEN_COUNT == 3) { if (MainConfiguration.ALLOW_DRAWER) setContentView(R.layout.drawer_launcher_3); else setContentView(R.layout.launcher_3); } else if (MainConfiguration.SCREEN_COUNT == 4) { if (MainConfiguration.ALLOW_DRAWER) setContentView(R.layout.drawer_launcher_4); else setContentView(R.layout.launcher_4); } else if (MainConfiguration.SCREEN_COUNT == 5) { if (MainConfiguration.ALLOW_DRAWER) setContentView(R.layout.drawer_launcher_5); else setContentView(R.layout.launcher_5); } else if (MainConfiguration.SCREEN_COUNT == 6) { if (MainConfiguration.ALLOW_DRAWER) setContentView(R.layout.drawer_launcher_6); else setContentView(R.layout.launcher_6); } else if (MainConfiguration.SCREEN_COUNT == 7) { if (MainConfiguration.ALLOW_DRAWER) setContentView(R.layout.drawer_launcher_7); else setContentView(R.layout.launcher_7); } else { setContentView(R.layout.launcher_5); } setupViews(); showFirstRunWorkspaceCling(); if (MainConfiguration.ALLOW_DRAWER) { this.drawerLayout = (DrawerLayout) this.findViewById(R.id.drawer_layout); ((LauncherDrawerLayout) this.drawerLayout).postInit(this, this.mWorkspace, this.mSharedPrefs); } registerContentObservers(); lockAllApps(); mSavedState = savedInstanceState; restoreState(mSavedState); // Update customization drawer _after_ restoring the states if (mAppsCustomizeContent != null) { mAppsCustomizeContent.onPackagesUpdated(); } if (PROFILE_STARTUP) { android.os.Debug.stopMethodTracing(); } if (!mRestoring) { if (sPausedFromUserAction) { // If the user leaves launcher, then we should just load items asynchronously when // they return. mModel.startLoader(true, -1); } else { // We only load the page synchronously if the user rotates (or triggers a // configuration change) while launcher is in the foreground mModel.startLoader(true, mWorkspace.getCurrentPage()); } } if (!mModel.isAllAppsLoaded()) { ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent(); mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent); } // For handling default keys mDefaultKeySsb = new SpannableStringBuilder(); Selection.setSelection(mDefaultKeySsb, 0); IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); registerReceiver(mCloseSystemDialogsReceiver, filter); updateGlobalIcons(); // On large interfaces, we want the screen to auto-rotate based on the current orientation unlockScreenOrientation(true); }
From source file:com.ywesee.amiko.MainActivity.java
/** * Changes to "suggestView" - called from ExpertInfoView *//*from ww w . j a v a 2s. c o m*/ public void setSuggestView() { // Enable flag mRestoringState = true; // Set view setCurrentView(mSuggestView, true); // Remove search hit counter mSearchHitsCntView.setVisibility(View.GONE); // Old search query if (!mSearchQuery.isEmpty()) mSearch.setText(mSearchQuery); else mSearch.getText().clear(); Editable s = mSearch.getText(); // Set cursor at the end Selection.setSelection(s, s.length()); // Restore search results showResults(mMedis); // Restore hint mSearch.setHint(getString(R.string.search) + " " + mActionName); // Show keyboard showSoftKeyboard(300); // Disable flag mRestoringState = false; }