List of usage examples for android.graphics Typeface SANS_SERIF
Typeface SANS_SERIF
To view the source code for android.graphics Typeface SANS_SERIF.
Click Source Link
From source file:android.support.v7.widget.SwitchCompat.java
private void setSwitchTypefaceByIndex(int typefaceIndex, int styleIndex) { Typeface tf = null;/* w w w. j av a 2 s .c o m*/ switch (typefaceIndex) { case SANS: tf = Typeface.SANS_SERIF; break; case SERIF: tf = Typeface.SERIF; break; case MONOSPACE: tf = Typeface.MONOSPACE; break; } setSwitchTypeface(tf, styleIndex); }
From source file:android.support.v7.widget.AppCompatTextHelper.java
private void updateTypefaceAndStyle(Context context, TintTypedArray a) { mStyle = a.getInt(R.styleable.TextAppearance_android_textStyle, mStyle); if (a.hasValue(R.styleable.TextAppearance_android_fontFamily) || a.hasValue(R.styleable.TextAppearance_fontFamily)) { mFontTypeface = null;//from ww w . j a v a 2 s .co m int fontFamilyId = a.hasValue(R.styleable.TextAppearance_fontFamily) ? R.styleable.TextAppearance_fontFamily : R.styleable.TextAppearance_android_fontFamily; if (!context.isRestricted()) { final WeakReference<TextView> textViewWeak = new WeakReference<>(mView); ResourcesCompat.FontCallback replyCallback = new ResourcesCompat.FontCallback() { @Override public void onFontRetrieved(@NonNull Typeface typeface) { onAsyncTypefaceReceived(textViewWeak, typeface); } @Override public void onFontRetrievalFailed(int reason) { // Do nothing. } }; try { // Note the callback will be triggered on the UI thread. mFontTypeface = a.getFont(fontFamilyId, mStyle, replyCallback); // If this call gave us an immediate result, ignore any pending callbacks. mAsyncFontPending = mFontTypeface == null; } catch (UnsupportedOperationException | Resources.NotFoundException e) { // Expected if it is not a font resource. } } if (mFontTypeface == null) { // Try with String. This is done by TextView JB+, but fails in ICS String fontFamilyName = a.getString(fontFamilyId); if (fontFamilyName != null) { mFontTypeface = Typeface.create(fontFamilyName, mStyle); } } return; } if (a.hasValue(R.styleable.TextAppearance_android_typeface)) { // Ignore previous pending fonts mAsyncFontPending = false; int typefaceIndex = a.getInt(R.styleable.TextAppearance_android_typeface, SANS); switch (typefaceIndex) { case SANS: mFontTypeface = Typeface.SANS_SERIF; break; case SERIF: mFontTypeface = Typeface.SERIF; break; case MONOSPACE: mFontTypeface = Typeface.MONOSPACE; break; } } }
From source file:com.matthewtamlin.sliding_intro_screen_manual_testing.TestButtonConfig.java
/** * Modifies the Behaviour and Appearance of the buttons. *///from www . j a v a2 s .co m private void makeChanges() { // Modify the left button final IntroButtonAccessor leftButtonAccessor = getLeftButtonAccessor(); leftButtonAccessor.setBehaviour(LEFT_BUTTON_BEHAVIOUR); leftButtonAccessor.setAppearance(LEFT_BUTTON_APPEARANCE); leftButtonAccessor.setText(LEFT_BUTTON_TEXT, null); leftButtonAccessor.setIcon(leftDrawable, null); leftButtonAccessor.setTextColor(LEFT_BUTTON_COLOR); leftButtonAccessor.setTextSize(LEFT_BUTTON_TEXT_SIZE_SP); leftButtonAccessor.setTypeface(Typeface.DEFAULT_BOLD); // Modify the right button final IntroButtonAccessor rightButtonAccessor = getRightButtonAccessor(); rightButtonAccessor.setBehaviour(RIGHT_BUTTON_BEHAVIOUR); rightButtonAccessor.setAppearance(RIGHT_BUTTON_APPEARANCE); rightButtonAccessor.setText(RIGHT_BUTTON_TEXT, null); rightButtonAccessor.setIcon(rightDrawable, null); rightButtonAccessor.setTextColor(RIGHT_BUTTON_COLOR); rightButtonAccessor.setTextSize(RIGHT_BUTTON_TEXT_SIZE_SP); rightButtonAccessor.setTypeface(Typeface.MONOSPACE); // Modify the final button final IntroButtonAccessor finalButtonAccessor = getFinalButtonAccessor(); finalButtonAccessor.setBehaviour(FINAL_BUTTON_BEHAVIOUR); finalButtonAccessor.setAppearance(FINAL_BUTTON_APPEARANCE); finalButtonAccessor.setText(FINAL_BUTTON_TEXT, null); finalButtonAccessor.setIcon(finalDrawable, null); finalButtonAccessor.setTextColor(FINAL_BUTTON_COLOR); finalButtonAccessor.setTextSize(FINAL_BUTTON_TEXT_SIZE_SP); finalButtonAccessor.setTypeface(Typeface.SANS_SERIF); }
From source file:com.gsbabil.antitaintdroid.UtilityFunctions.java
public int captureBitmapCache(String in) { TextView tv = (TextView) MyApp.context.findViewById(R.id.ocrTextview); String tvText = tv.getText().toString(); float tvTextSize = tv.getTextSize(); int tvColor = tv.getCurrentTextColor(); Bitmap bitmap = null;/* w ww . java 2 s. c o m*/ tv.setTextSize(36); tv.setTextColor(Color.CYAN); tv.setTypeface(Typeface.SANS_SERIF); tv.setText(in); while (bitmap == null) { // http://stackoverflow.com/questions/2339429/android-view-getdrawingcache-returns-null-only-null tv.measure(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED)); tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight()); tv.setDrawingCacheEnabled(true); tv.buildDrawingCache(true); bitmap = Bitmap.createBitmap(tv.getDrawingCache()); tv.destroyDrawingCache(); tv.setDrawingCacheEnabled(false); } FileOutputStream fos = null; int res = -1; try { fos = new FileOutputStream(currentDirectory() + "/files/" + MyApp.SCREENSHOT_FILENAME); if (fos != null) { bitmap.compress(Bitmap.CompressFormat.JPEG, 90, fos); fos.close(); res = 0; } } catch (Throwable e) { Log.i(MyApp.TAG, e.getMessage().toString()); res = -1; } tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, tvTextSize); tv.setTypeface(Typeface.MONOSPACE); tv.setText(tvText); tv.setTextColor(tvColor); return res; }
From source file:com.jjoe64.graphview_demos.fragments.StartSensors.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_WORD_LIST_ACTIVITY) { if (resultCode == getActivity().RESULT_OK) { try { String strWord = data.getStringExtra("word"); //etWrite.setText(strWord); // Set a cursor position last //etWrite.setSelection(etWrite.getText().length()); } catch (Exception e) { Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show(); }//from w w w .j a va 2s .c om } } else if (requestCode == REQUEST_PREFERENCE) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getActivity()); String res = pref.getString("display_list", Integer.toString(DISP_CHAR)); mDisplayType = Integer.valueOf(res); res = pref.getString("fontsize_list", Integer.toString(12)); mTextFontSize = Integer.valueOf(res); //mTvSerial.setTextSize(mTextFontSize); res = pref.getString("typeface_list", Integer.toString(3)); switch (Integer.valueOf(res)) { case 0: mTextTypeface = Typeface.DEFAULT; break; case 1: mTextTypeface = Typeface.SANS_SERIF; break; case 2: mTextTypeface = Typeface.SERIF; break; case 3: mTextTypeface = Typeface.MONOSPACE; break; } //mTvSerial.setTypeface(mTextTypeface); //etWrite.setTypeface(mTextTypeface); res = pref.getString("readlinefeedcode_list", Integer.toString(LINEFEED_CODE_CRLF)); mReadLinefeedCode = Integer.valueOf(res); res = pref.getString("writelinefeedcode_list", Integer.toString(LINEFEED_CODE_CRLF)); mWriteLinefeedCode = Integer.valueOf(res); res = pref.getString("email_edittext", "@gmail.com"); mEmailAddress = res; int intRes; res = pref.getString("baudrate_list", Integer.toString(57600)); intRes = Integer.valueOf(res); if (mBaudrate != intRes) { mBaudrate = intRes; mSerial.setBaudrate(mBaudrate); } res = pref.getString("databits_list", Integer.toString(UartConfig.DATA_BITS8)); intRes = Integer.valueOf(res); if (mDataBits != intRes) { mDataBits = Integer.valueOf(res); mSerial.setDataBits(mDataBits); } res = pref.getString("parity_list", Integer.toString(UartConfig.PARITY_NONE)); intRes = Integer.valueOf(res); if (mParity != intRes) { mParity = intRes; mSerial.setParity(mParity); } res = pref.getString("stopbits_list", Integer.toString(UartConfig.STOP_BITS1)); intRes = Integer.valueOf(res); if (mStopBits != intRes) { mStopBits = intRes; mSerial.setStopBits(mStopBits); } res = pref.getString("flowcontrol_list", Integer.toString(UartConfig.FLOW_CONTROL_OFF)); intRes = Integer.valueOf(res); if (mFlowControl != intRes) { mFlowControl = intRes; if (mFlowControl == UartConfig.FLOW_CONTROL_ON) { mSerial.setDtrRts(true, true); } else { mSerial.setDtrRts(false, false); } } /* res = pref.getString("break_list", Integer.toString(FTDriver.FTDI_SET_NOBREAK)); intRes = Integer.valueOf(res) << 14; if (mBreak != intRes) { mBreak = intRes; mSerial.setSerialPropertyBreak(mBreak, FTDriver.CH_A); mSerial.setSerialPropertyToChip(FTDriver.CH_A); } */ } }
From source file:com.jjoe64.graphview_demos.fragments.CollectData.java
@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_WORD_LIST_ACTIVITY) { if (resultCode == getActivity().RESULT_OK) { try { String strWord = data.getStringExtra("word"); //etWrite.setText(strWord); // Set a cursor position last //etWrite.setSelection(etWrite.getText().length()); } catch (Exception e) { Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_LONG).show(); }//from www . j av a 2s. c o m } } else if (requestCode == REQUEST_PREFERENCE) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getActivity()); String res = pref.getString("display_list", Integer.toString(DISP_CHAR)); mDisplayType = Integer.valueOf(res); res = pref.getString("fontsize_list", Integer.toString(12)); mTextFontSize = Integer.valueOf(res); mTvSerial.setTextSize(mTextFontSize); res = pref.getString("typeface_list", Integer.toString(3)); switch (Integer.valueOf(res)) { case 0: mTextTypeface = Typeface.DEFAULT; break; case 1: mTextTypeface = Typeface.SANS_SERIF; break; case 2: mTextTypeface = Typeface.SERIF; break; case 3: mTextTypeface = Typeface.MONOSPACE; break; } mTvSerial.setTypeface(mTextTypeface); // etWrite.setTypeface(mTextTypeface); res = pref.getString("readlinefeedcode_list", Integer.toString(LINEFEED_CODE_CRLF)); mReadLinefeedCode = Integer.valueOf(res); res = pref.getString("writelinefeedcode_list", Integer.toString(LINEFEED_CODE_CRLF)); mWriteLinefeedCode = Integer.valueOf(res); res = pref.getString("email_edittext", "@gmail.com"); mEmailAddress = res; int intRes; res = pref.getString("baudrate_list", Integer.toString(57600)); intRes = Integer.valueOf(res); if (mBaudrate != intRes) { mBaudrate = intRes; mSerial.setBaudrate(mBaudrate); } res = pref.getString("databits_list", Integer.toString(UartConfig.DATA_BITS8)); intRes = Integer.valueOf(res); if (mDataBits != intRes) { mDataBits = Integer.valueOf(res); mSerial.setDataBits(mDataBits); } res = pref.getString("parity_list", Integer.toString(UartConfig.PARITY_NONE)); intRes = Integer.valueOf(res); if (mParity != intRes) { mParity = intRes; mSerial.setParity(mParity); } res = pref.getString("stopbits_list", Integer.toString(UartConfig.STOP_BITS1)); intRes = Integer.valueOf(res); if (mStopBits != intRes) { mStopBits = intRes; mSerial.setStopBits(mStopBits); } res = pref.getString("flowcontrol_list", Integer.toString(UartConfig.FLOW_CONTROL_OFF)); intRes = Integer.valueOf(res); if (mFlowControl != intRes) { mFlowControl = intRes; if (mFlowControl == UartConfig.FLOW_CONTROL_ON) { mSerial.setDtrRts(true, true); } else { mSerial.setDtrRts(false, false); } } /* res = pref.getString("break_list", Integer.toString(FTDriver.FTDI_SET_NOBREAK)); intRes = Integer.valueOf(res) << 14; if (mBreak != intRes) { mBreak = intRes; mSerial.setSerialPropertyBreak(mBreak, FTDriver.CH_A); mSerial.setSerialPropertyToChip(FTDriver.CH_A); } */ } }
From source file:org.numixproject.hermes.activity.ConversationActivity.java
/** * On create// w w w. j a v a 2s . c o m */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //Initialize Facebook SDK FacebookSdk.sdkInitialize(getApplicationContext()); tinydb = new TinyDB(getApplicationContext()); serverId = getIntent().getExtras().getInt("serverId"); server = Hermes.getInstance().getServerById(serverId); loadPinnedItems(); loadRecentItems(); server.setAutoJoinChannels(pinnedRooms); // Remove duplicates from Recent items HashSet hs = new HashSet(); hs.addAll(recentList); recentList.clear(); recentList.addAll(hs); saveRecentItems(); Settings settings = new Settings(this); // Finish activity if server does not exist anymore - See #55 if (server == null) { this.finish(); } String key = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5B4Oomgmm2D8XVSxh1DIFGtU3p1N2w6Xi2ZO7MoeZRAhvVjk3B8MfrOatlO9HfozRGhEkCkq0MfstB4Cjci3dsnYZieNmHOVYIFBWERqdwfdtnUIfI554xFsAC3Ah7PTP3MwKE7qTT1VLTTHxxsE7GH4sLtvLwrAzsVrLK+dgQk+e9bDJMvhhEPBgabRFaTvKaTtSzB/BBwrCa5mv0pte6WfrNbugFjiAJC43b7NNY2PV9UA8mukiBNZ9mPrK5fZeSEfcVqenyqbvZZG+P+O/cohAHbIEzPMuAS1EBf0VBsZtm3fjQ45PgCvEB7Ye3ucfR9BQ9ADjDwdqivExvXndQIDAQAB"; inAppPayments = new iap(); bp = inAppPayments.getBilling(this, key); bp.loadOwnedPurchasesFromGoogle(); // Load AdMob Ads if (!inAppPayments.isPurchased()) { mInterstitialAd = new InterstitialAd(this); mInterstitialAd.setAdUnitId("ca-app-pub-2834532364021285/7438037454"); requestNewInterstitial(); mInterstitialAd.setAdListener(new AdListener() { @Override public void onAdClosed() { requestNewInterstitial(); } }); } try { setTitle(server.getTitle()); } catch (Exception e) { } isFirstTimeStarred = tinydb.getBoolean("isFirstTimeStarred", true); isFirstTimeRefresh = tinydb.getBoolean("isFirstTimeRefresh", true); setContentView(R.layout.conversations); boolean isLandscape = (getResources() .getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE); final ImageView sendButton = (ImageView) findViewById(R.id.send_button); sendButton.setVisibility(View.GONE); input = (AutoCompleteTextView) findViewById(R.id.input); input.setOnKeyListener(inputKeyListener); input.addTextChangedListener(new TextWatcher() { @Override public void afterTextChanged(Editable s) { // Do nothing } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // Do nothing } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { if (input.getText().toString().equals("")) { sendButton.setVisibility(View.GONE); } else { sendButton.setVisibility(View.VISIBLE); } } }); pager = (ViewPager) findViewById(R.id.pager); pagerAdapter = new ConversationPagerAdapter(this, server); pager.setAdapter(pagerAdapter); final float density = getResources().getDisplayMetrics().density; indicator = (ConversationIndicator) findViewById(R.id.titleIndicator); indicator.setServer(server); indicator.setViewPager(pager); indicator.setFooterColor(Color.parseColor("#d1d1d1")); indicator.setFooterLineHeight(1); indicator.setPadding(10, 10, 10, 10); indicator.setFooterIndicatorStyle(IndicatorStyle.Underline); indicator.setFooterIndicatorHeight(2 * density); indicator.setSelectedColor(0xFF222222); indicator.setSelectedBold(false); indicator.setBackgroundColor(Color.parseColor("#fff5f5f5")); historySize = settings.getHistorySize(); if (server.getStatus() == Status.PRE_CONNECTING) { server.clearConversations(); pagerAdapter.clearConversations(); server.getConversation(ServerInfo.DEFAULT_NAME).setHistorySize(historySize); } indicator.setTextSize(TypedValue.COMPLEX_UNIT_SP, 35); input.setTypeface(Typeface.SANS_SERIF); // Optimization : cache field lookups Collection<Conversation> mConversations = server.getConversations(); for (Conversation conversation : mConversations) { // Only scroll to new conversation if it was selected before if (conversation.getStatus() == Conversation.STATUS_SELECTED) { onNewConversation(conversation.getName()); } else { createNewConversation(conversation.getName()); } } input.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { openSoftKeyboard(v); updateAutoComplete(); } }); conversationLayout = (FrameLayout) findViewById(R.id.conversationFragment); conversationLayout.setVisibility(LinearLayout.INVISIBLE); roomsLayout = (FrameLayout) findViewById(R.id.roomsLayout); // Create a new scrollback history scrollback = new Scrollback(); getSupportActionBar().setDisplayHomeAsUpEnabled(true); swipeRefresh = (SwipeRefreshLayout) findViewById(R.id.swipeRefresh); swipeRefresh.setColorSchemeResources(R.color.refresh_progress_1, R.color.refresh_progress_2, R.color.refresh_progress_3); swipeRefresh.getViewTreeObserver() .addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() { @Override public void onScrollChanged() { Rect scrollBounds = new Rect(); swipeRefresh.getHitRect(scrollBounds); TextView firstItem = (TextView) findViewById(R.id.firstItem); if (firstItem.getLocalVisibleRect(scrollBounds)) { if (conversationLayout.getVisibility() != View.VISIBLE) { swipeRefresh.setEnabled(true); } else { swipeRefresh.setEnabled(false); } } else { swipeRefresh.setEnabled(false); } } }); swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() { @Override public void onRefresh() { if (swipeRefresh.getScrollY() == 0) { refreshActivity(); } } }); // Adapter section roomsList = (ExpandableHeightListView) findViewById(R.id.roomsActivityList); roomsList.setExpanded(true); SwipeDismissListViewTouchListener touchListener = new SwipeDismissListViewTouchListener(roomsList, new SwipeDismissListViewTouchListener.DismissCallbacks() { @Override public boolean canDismiss(int position) { return true; } @Override public void onDismiss(ListView listView, int[] reverseSortedPositions) { for (int position : reverseSortedPositions) { roomAdapter.remove(position); } roomAdapter.notifyDataSetChanged(); if (Math.random() * 100 < 30) { showAd(); } } }); roomsList.setOnTouchListener(touchListener); // Setting this scroll listener is required to ensure that during ListView scrolling, // we don't look for swipes. roomsList.setOnScrollListener(touchListener.makeScrollListener()); ArrayList<String> channels = new ArrayList<String>(); ArrayList<String> query = new ArrayList<String>(); channels = server.getCurrentChannelNames(); query = server.getCurrentQueryNames(); for (int i = 0; i < channels.size(); i++) { try { Conversation conversation = server.getConversation(channels.get(i)); int Mentions = conversation.getNewMentions(); RoomsList.add(channels.get(i)); MentionsList.add(Mentions); } catch (Exception E) { // Do nothing } } // FAB section fab = (FloatingActionButton) findViewById(R.id.room_fab); fab.setOnTouchListener(new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { joinRoom(v); } return true; } }); roomAdapter = new mentionsAdapter(RoomsList, MentionsList); roomsList.setAdapter(roomAdapter); roomsList.setEmptyView(findViewById(R.id.roomsActivityList_empty)); roomsList.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // Set conversation VISIBLE invalidateOptionsMenu(); swipeRefresh.setEnabled(false); int pagerPosition; String name; // Find channel name from TextView TextView roomName = (TextView) view.findViewById(R.id.room_name); name = roomName.getText().toString(); // Find room's position in pager pagerPosition = pagerAdapter.getPositionByName(name); // Set position in pager pager.setCurrentItem(pagerPosition, true); showConversationLayout(); } }); // Click on Others CardView otherCard = (CardView) findViewById(R.id.card_view_other); otherCard.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { invalidateOptionsMenu(); swipeRefresh.setEnabled(false); pager.setCurrentItem(0); showConversationLayout(); } }); int counter; for (counter = 0; counter < recentList.size(); counter++) { if (RoomsList.contains(recentList.get(counter))) { recentList.remove(counter); saveRecentItems(); } } LinearLayout recentLabel = (LinearLayout) findViewById(R.id.recentName); if (recentList.size() != 0) { recentLabel.setVisibility(View.VISIBLE); } else { recentLabel.setVisibility(View.GONE); } recentView = (ExpandableHeightListView) findViewById(R.id.recentList); loadLastItems(); int k; for (k = 0; k < lastRooms.size(); k++) { String lastRoom = lastRooms.get(k); if (RoomsList.contains(lastRoom)) { } else { recentList.add(lastRoom); } } lastRooms.clear(); saveLastItems(); saveRecentItems(); recentAdapter = new recentAdapter(recentList); recentView.setAdapter(recentAdapter); recentView.setExpanded(true); recentView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapter, View v, int position, long arg3) { final String room = (String) recentAdapter.getRoomAtPosition(position); if (RoomsList.size() > 0) { invalidateOptionsMenu(); new Thread() { @Override public void run() { try { binder.getService().getConnection(serverId).joinChannel(room); } catch (Exception E) { // Do nothing } } }.start(); recentList.remove(position); saveRecentItems(); refreshActivity(); } else { new Thread() { @Override public void run() { try { binder.getService().getConnection(serverId).joinChannel(room); } catch (Exception E) { // Do nothing } } }.start(); saveRecentItems(); refreshActivity(); } } }); SwipeDismissListViewTouchListener touchListenerRecent = new SwipeDismissListViewTouchListener(recentView, new SwipeDismissListViewTouchListener.DismissCallbacks() { @Override public boolean canDismiss(int position) { return true; } @Override public void onDismiss(ListView listView, int[] reverseSortedPositions) { for (int position : reverseSortedPositions) { recentAdapter.remove(position); saveRecentItems(); } recentAdapter.notifyDataSetChanged(); if (Math.random() * 100 < 10) { showAd(); } } }); recentView.setOnTouchListener(touchListenerRecent); // Setting this scroll listener is required to ensure that during ListView scrolling, // we don't look for swipes. recentView.setOnScrollListener(touchListenerRecent.makeScrollListener()); }
From source file:gov.wa.wsdot.android.wsdot.ui.trafficmap.TrafficMapActivity.java
@Override protected void onResume() { super.onResume(); mGoogleApiClient.connect();// w ww. ja v a 2 s . c om SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this); boolean seenTip = settings.getBoolean("KEY_SEEN_TRAFFIC_LAYERS_TIP", false); if (!seenTip) { try { TapTargetView.showFor(this, // `this` is an Activity TapTarget .forView(fabLayers, "Map Layers", "Tap to edit what information displays on the Traffic Map.") // All options below are optional .outerCircleColor(R.color.primary_default).titleTextSize(20) .titleTextColor(R.color.white).descriptionTextSize(15).textColor(R.color.white) .textTypeface(Typeface.SANS_SERIF).dimColor(R.color.black).drawShadow(true) .cancelable(true).tintTarget(true).transparentTarget(true).targetRadius(40), new TapTargetView.Listener() { @Override public void onTargetClick(TapTargetView view) { super.onTargetClick(view); // This call is optional showFABMenu(); } }); } catch (NullPointerException | IllegalArgumentException e) { Log.e(TAG, "Exception while trying to show tip view"); Log.e(TAG, e.getMessage()); } } settings.edit().putBoolean("KEY_SEEN_TRAFFIC_LAYERS_TIP", true).apply(); }
From source file:com.hughes.android.dictionary.DictionaryActivity.java
@Override public void onCreate(Bundle savedInstanceState) { // This needs to be before super.onCreate, otherwise ActionbarSherlock // doesn't makes the background of the actionbar white when you're // in the dark theme. setTheme(((DictionaryApplication) getApplication()).getSelectedTheme().themeId); Log.d(LOG, "onCreate:" + this); super.onCreate(savedInstanceState); final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); // Don't auto-launch if this fails. prefs.edit().remove(C.DICT_FILE).commit(); setContentView(R.layout.dictionary_activity); application = (DictionaryApplication) getApplication(); theme = application.getSelectedTheme(); textColorFg = getResources().getColor(theme.tokenRowFgColor); final Intent intent = getIntent(); String intentAction = intent.getAction(); /**/*w ww . ja va 2 s. c o m*/ * @author Dominik Kppl Querying the Intent * com.hughes.action.ACTION_SEARCH_DICT is the advanced query * Arguments: SearchManager.QUERY -> the phrase to search from * -> language in which the phrase is written to -> to which * language shall be translated */ if (intentAction != null && intentAction.equals("com.hughes.action.ACTION_SEARCH_DICT")) { String query = intent.getStringExtra(SearchManager.QUERY); String from = intent.getStringExtra("from"); if (from != null) from = from.toLowerCase(Locale.US); String to = intent.getStringExtra("to"); if (to != null) to = to.toLowerCase(Locale.US); if (query != null) { getIntent().putExtra(C.SEARCH_TOKEN, query); } if (intent.getStringExtra(C.DICT_FILE) == null && (from != null || to != null)) { Log.d(LOG, "DictSearch: from: " + from + " to " + to); List<DictionaryInfo> dicts = application.getDictionariesOnDevice(null); for (DictionaryInfo info : dicts) { boolean hasFrom = from == null; boolean hasTo = to == null; for (IndexInfo index : info.indexInfos) { if (!hasFrom && index.shortName.toLowerCase(Locale.US).equals(from)) hasFrom = true; if (!hasTo && index.shortName.toLowerCase(Locale.US).equals(to)) hasTo = true; } if (hasFrom && hasTo) { if (from != null) { int which_index = 0; for (; which_index < info.indexInfos.size(); ++which_index) { if (info.indexInfos.get(which_index).shortName.toLowerCase(Locale.US).equals(from)) break; } intent.putExtra(C.INDEX_SHORT_NAME, info.indexInfos.get(which_index).shortName); } intent.putExtra(C.DICT_FILE, application.getPath(info.uncompressedFilename).toString()); break; } } } } /** * @author Dominik Kppl Querying the Intent Intent.ACTION_SEARCH is a * simple query Arguments follow from android standard (see * documentation) */ if (intentAction != null && intentAction.equals(Intent.ACTION_SEARCH)) { String query = intent.getStringExtra(SearchManager.QUERY); if (query != null) getIntent().putExtra(C.SEARCH_TOKEN, query); } /** * @author Dominik Kppl If no dictionary is chosen, use the default * dictionary specified in the preferences If this step does * fail (no default directory specified), show a toast and * abort. */ if (intent.getStringExtra(C.DICT_FILE) == null) { String dictfile = prefs.getString(getString(R.string.defaultDicKey), null); if (dictfile != null) intent.putExtra(C.DICT_FILE, application.getPath(dictfile).toString()); } String dictFilename = intent.getStringExtra(C.DICT_FILE); if (dictFilename == null) { Toast.makeText(this, getString(R.string.no_dict_file), Toast.LENGTH_LONG).show(); startActivity(DictionaryManagerActivity.getLaunchIntent(getApplicationContext())); finish(); return; } if (dictFilename != null) dictFile = new File(dictFilename); ttsReady = false; textToSpeech = new TextToSpeech(getApplicationContext(), new OnInitListener() { @Override public void onInit(int status) { ttsReady = true; updateTTSLanguage(indexIndex); } }); try { final String name = application.getDictionaryName(dictFile.getName()); this.setTitle("QuickDic: " + name); dictRaf = new RandomAccessFile(dictFile, "r"); dictionary = new Dictionary(dictRaf); } catch (Exception e) { Log.e(LOG, "Unable to load dictionary.", e); if (dictRaf != null) { try { dictRaf.close(); } catch (IOException e1) { Log.e(LOG, "Unable to close dictRaf.", e1); } dictRaf = null; } Toast.makeText(this, getString(R.string.invalidDictionary, "", e.getMessage()), Toast.LENGTH_LONG) .show(); startActivity(DictionaryManagerActivity.getLaunchIntent(getApplicationContext())); finish(); return; } String targetIndex = intent.getStringExtra(C.INDEX_SHORT_NAME); if (savedInstanceState != null && savedInstanceState.getString(C.INDEX_SHORT_NAME) != null) { targetIndex = savedInstanceState.getString(C.INDEX_SHORT_NAME); } indexIndex = 0; for (int i = 0; i < dictionary.indices.size(); ++i) { if (dictionary.indices.get(i).shortName.equals(targetIndex)) { indexIndex = i; break; } } Log.d(LOG, "Loading index " + indexIndex); index = dictionary.indices.get(indexIndex); setListAdapter(new IndexAdapter(index)); // Pre-load the collators. new Thread(new Runnable() { public void run() { android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND); final long startMillis = System.currentTimeMillis(); try { TransliteratorManager.init(new TransliteratorManager.Callback() { @Override public void onTransliteratorReady() { uiHandler.post(new Runnable() { @Override public void run() { onSearchTextChange(searchView.getQuery().toString()); } }); } }); for (final Index index : dictionary.indices) { final String searchToken = index.sortedIndexEntries.get(0).token; final IndexEntry entry = index.findExact(searchToken); if (entry == null || !searchToken.equals(entry.token)) { Log.e(LOG, "Couldn't find token: " + searchToken + ", " + (entry == null ? "null" : entry.token)); } } indexPrepFinished = true; } catch (Exception e) { Log.w(LOG, "Exception while prepping. This can happen if dictionary is closed while search is happening."); } Log.d(LOG, "Prepping indices took:" + (System.currentTimeMillis() - startMillis)); } }).start(); String fontName = prefs.getString(getString(R.string.fontKey), "FreeSerif.otf.jpg"); if ("SYSTEM".equals(fontName)) { typeface = Typeface.DEFAULT; } else if ("SERIF".equals(fontName)) { typeface = Typeface.SERIF; } else if ("SANS_SERIF".equals(fontName)) { typeface = Typeface.SANS_SERIF; } else if ("MONOSPACE".equals(fontName)) { typeface = Typeface.MONOSPACE; } else { if ("FreeSerif.ttf.jpg".equals(fontName)) { fontName = "FreeSerif.otf.jpg"; } try { typeface = Typeface.createFromAsset(getAssets(), fontName); } catch (Exception e) { Log.w(LOG, "Exception trying to use typeface, using default.", e); Toast.makeText(this, getString(R.string.fontFailure, e.getLocalizedMessage()), Toast.LENGTH_LONG) .show(); } } if (typeface == null) { Log.w(LOG, "Unable to create typeface, using default."); typeface = Typeface.DEFAULT; } final String fontSize = prefs.getString(getString(R.string.fontSizeKey), "14"); try { fontSizeSp = Integer.parseInt(fontSize.trim()); } catch (NumberFormatException e) { fontSizeSp = 14; } // ContextMenu. registerForContextMenu(getListView()); // Cache some prefs. wordList = application.getWordListFile(); saveOnlyFirstSubentry = prefs.getBoolean(getString(R.string.saveOnlyFirstSubentryKey), false); clickOpensContextMenu = prefs.getBoolean(getString(R.string.clickOpensContextMenuKey), false); Log.d(LOG, "wordList=" + wordList + ", saveOnlyFirstSubentry=" + saveOnlyFirstSubentry); onCreateSetupActionBarAndSearchView(); // Set the search text from the intent, then the saved state. String text = getIntent().getStringExtra(C.SEARCH_TOKEN); if (savedInstanceState != null) { text = savedInstanceState.getString(C.SEARCH_TOKEN); } if (text == null) { text = ""; } setSearchText(text, true); Log.d(LOG, "Trying to restore searchText=" + text); setDictionaryPrefs(this, dictFile, index.shortName, searchView.getQuery().toString()); updateLangButton(); searchView.requestFocus(); // http://stackoverflow.com/questions/2833057/background-listview-becomes-black-when-scrolling // getListView().setCacheColorHint(0); }
From source file:jp.ksksue.app.terminal.AndroidUSBSerialMonitorLite.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); if (requestCode == REQUEST_WORD_LIST_ACTIVITY) { if (resultCode == RESULT_OK) { try { String strWord = data.getStringExtra("word"); etWrite.setText(strWord); // Set a cursor position last etWrite.setSelection(etWrite.getText().length()); } catch (Exception e) { Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show(); }/*from ww w . j a v a 2s . c o m*/ } } else if (requestCode == REQUEST_PREFERENCE) { SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(this); String res = pref.getString("display_list", Integer.toString(DISP_CHAR)); mDisplayType = Integer.valueOf(res); res = pref.getString("fontsize_list", Integer.toString(12)); mTextFontSize = Integer.valueOf(res); mTvSerial.setTextSize(mTextFontSize); res = pref.getString("typeface_list", Integer.toString(3)); switch (Integer.valueOf(res)) { case 0: mTextTypeface = Typeface.DEFAULT; break; case 1: mTextTypeface = Typeface.SANS_SERIF; break; case 2: mTextTypeface = Typeface.SERIF; break; case 3: mTextTypeface = Typeface.MONOSPACE; break; } mTvSerial.setTypeface(mTextTypeface); etWrite.setTypeface(mTextTypeface); res = pref.getString("readlinefeedcode_list", Integer.toString(LINEFEED_CODE_CRLF)); mReadLinefeedCode = Integer.valueOf(res); res = pref.getString("writelinefeedcode_list", Integer.toString(LINEFEED_CODE_CRLF)); mWriteLinefeedCode = Integer.valueOf(res); res = pref.getString("email_edittext", "@gmail.com"); mEmailAddress = res; int intRes; res = pref.getString("baudrate_list", Integer.toString(9600)); intRes = Integer.valueOf(res); if (mBaudrate != intRes) { mBaudrate = intRes; mSerial.setBaudrate(mBaudrate); } res = pref.getString("databits_list", Integer.toString(UartConfig.DATA_BITS8)); intRes = Integer.valueOf(res); if (mDataBits != intRes) { mDataBits = Integer.valueOf(res); mSerial.setDataBits(mDataBits); } res = pref.getString("parity_list", Integer.toString(UartConfig.PARITY_NONE)); intRes = Integer.valueOf(res); if (mParity != intRes) { mParity = intRes; mSerial.setParity(mParity); } res = pref.getString("stopbits_list", Integer.toString(UartConfig.STOP_BITS1)); intRes = Integer.valueOf(res); if (mStopBits != intRes) { mStopBits = intRes; mSerial.setStopBits(mStopBits); } res = pref.getString("flowcontrol_list", Integer.toString(UartConfig.FLOW_CONTROL_OFF)); intRes = Integer.valueOf(res); if (mFlowControl != intRes) { mFlowControl = intRes; if (mFlowControl == UartConfig.FLOW_CONTROL_ON) { mSerial.setDtrRts(true, true); } else { mSerial.setDtrRts(false, false); } } /* res = pref.getString("break_list", Integer.toString(FTDriver.FTDI_SET_NOBREAK)); intRes = Integer.valueOf(res) << 14; if (mBreak != intRes) { mBreak = intRes; mSerial.setSerialPropertyBreak(mBreak, FTDriver.CH_A); mSerial.setSerialPropertyToChip(FTDriver.CH_A); } */ res = pref.getString("play_interval", "3"); intRes = Integer.valueOf(res); mPlayIntervalSeconds = intRes; } }