public void updateTabCountAndAnimate(int count) { if (mCount > count) { mTabsCount.setInAnimation(mSlideDownIn); mTabsCount.setOutAnimation(mSlideDownOut); } else if (mCount < count) { mTabsCount.setInAnimation(mSlideUpIn); mTabsCount.setOutAnimation(mSlideUpOut); } else { return; } mTabsCount.setText(String.valueOf(count)); mCount = count; mTabs.setContentDescription(mContext.getString(R.string.num_tabs, count)); mHandler.postDelayed( new Runnable() { public void run() { ((TextView) mTabsCount.getCurrentView()) .setTextColor(mContext.getResources().getColor(R.color.url_bar_text_highlight)); } }, mDuration); mHandler.postDelayed( new Runnable() { public void run() { ((TextView) mTabsCount.getCurrentView()) .setTextColor(mContext.getResources().getColor(R.color.tabs_counter_color)); } }, 2 * mDuration); }
// AnimationSet as; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); words = getResources().getStringArray(R.array.quotes); _handler = new Handler(); _quote = (TextSwitcher) findViewById(R.id.quote_text); _quote.setFactory( new ViewFactory() { public View makeView() { TextView quote = new TextView(getApplicationContext()); quote.setGravity(Gravity.CENTER); quote.setTextColor(color.GhostWhite); quote.setTextAppearance(getApplicationContext(), android.R.style.TextAppearance_Large); quote.setTypeface(null, Typeface.ITALIC); return quote; } }); in = new AlphaAnimation(0.0f, 1.0f); in.setDuration(2000); out = new AlphaAnimation(1.0f, 0.0f); out.setDuration(2000); _quote.setInAnimation(in); _quote.setOutAnimation(out); _handler.postDelayed(_updateQuoteTask, 0); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ButterKnife.bind(this); mContext = this; mUrl = getIntent().getStringExtra(EXTRA_URL); mTitle = getIntent().getStringExtra(EXTRA_TITLE); WebSettings settings = mWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setLoadWithOverviewMode(true); settings.setAppCacheEnabled(true); settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN); settings.setSupportZoom(true); mWebView.setWebChromeClient(new ChromeClient()); mWebView.setWebViewClient(new LoveClient()); mWebView.loadUrl(mUrl); mTextSwitcher.setFactory( () -> { TextView textView = new TextView(this); textView.setTextAppearance(this, R.style.WebTitle); textView.setSingleLine(true); textView.setEllipsize(TextUtils.TruncateAt.MARQUEE); textView.postDelayed(() -> textView.setSelected(true), 1738); return textView; }); mTextSwitcher.setInAnimation(this, android.R.anim.fade_in); mTextSwitcher.setOutAnimation(this, android.R.anim.fade_out); if (mTitle != null) setTitle(mTitle); }
/** * onCreate之后调用,可以用来初始化view * * @param savedInstanceState the saved instance state */ @Override public final void onCreateAfter(Bundle savedInstanceState) { parseIntent(); enableJavascript(); enableCaching(); enableClient(); enableAdjust(); zoomedOut(); // 网页标题 mTextSwitcher.setFactory( () -> { TextView textView = new TextView(this); textView.setTextAppearance(this, R.style.WebTitle); textView.setSingleLine(true); textView.setEllipsize(TextUtils.TruncateAt.MARQUEE); textView.postDelayed(() -> textView.setSelected(true), 1738); return textView; }); mTextSwitcher.setInAnimation(this, android.R.anim.fade_in); mTextSwitcher.setOutAnimation(this, android.R.anim.fade_out); if (title != null) setTitle(title); if (mProgressBar != null) mProgressBar.setReachedBarColor(BaseApplication.color(R.color.colorPrimary)); // 设置滑动监听 mWebView.setOnScrollChangedCallback( (dx, dy, x, y) -> { // 滑动监听 }); onCreateAfterLater(); }
private void initialiseTextSwitcher() { mSwitcher = (TextSwitcher) rootView.findViewById(R.id.textSwitcher); mSwitcher.setFactory( new ViewFactory() { public View makeView() { TextView myText = new TextView(getActivity()); myText.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL); myText.setTextSize(28); myText.setTextColor(Color.BLACK); return myText; } }); // Declare the in and out animations and initialize them Animation in = AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_in); Animation out = AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_out); mSwitcher.setInAnimation(in); mSwitcher.setOutAnimation(out); mSwitcher.setOnClickListener(myhandler1); /** ******************************************************** */ // Create Inner Thread Class background = new Thread( new Runnable() { // After call for background.start this run method call public void run() { try { while (true) { handler.sendEmptyMessage(0); SystemClock.sleep(2200); } } catch (Throwable t) { } } // Define the Handler that receives messages from the thread and update the progress @SuppressLint("HandlerLeak") private final Handler handler = new Handler() { public void handleMessage(Message msg) { doUpdate(); } }; }); // Start Thread background.start(); // After call start method thread called run Method /** ******************************************************************************** */ }
public void updateTabs(int count) { if (mCount > count) { mTabsCount.setInAnimation(mSlideDownIn); mTabsCount.setOutAnimation(mSlideDownOut); } else if (mCount < count) { mTabsCount.setInAnimation(mSlideUpIn); mTabsCount.setOutAnimation(mSlideUpOut); } if (count > 1) mTabs.setImageLevel(count); else mTabs.setImageLevel(0); mTabsCount.setVisibility(View.VISIBLE); mTabsCount.setText(String.valueOf(count)); mCount = count; mHandler.postDelayed( new Runnable() { public void run() { ((TextView) mTabsCount.getCurrentView()).setTextColor(mColor); } }, mDuration); mHandler.postDelayed( new Runnable() { public void run() { if (Tabs.getInstance().getCount() == 1) { mTabs.setImageLevel(1); mTabsCount.setVisibility(View.GONE); ((TextView) mTabsCount.getCurrentView()).setTextColor(mCounterColor); } else { ((TextView) mTabsCount.getCurrentView()).setTextColor(mCounterColor); } } }, 2 * mDuration); }
/** * Initializes the score TextSwitcher for the specified {@code textSwitcher}. It also sets the * {@code listener}. * * @param listener The listener which will update the text. */ private void initializeTextSwitcher( final TextSwitcher textSwitcher, View.OnTouchListener listener) { textSwitcher.setFactory( new ViewSwitcher.ViewFactory() { @Override public View makeView() { TextView textView = new TextView(textSwitcher.getContext()); textView.setTextSize(36); return textView; } }); textSwitcher.setOnTouchListener(listener); textSwitcher.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in)); textSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out)); textSwitcher.setText(getText(R.string.defaultInitialGameScore)); }
private void setupDetails() { detailsSwitcher.setInAnimation(getAnimation(R.anim.alpha_in, true)); detailsSwitcher.setOutAnimation(getAnimation(R.anim.alpha_out, false)); detailsSwitcher.setFactory( new ViewSwitcher.ViewFactory() { @Override public View makeView() { TextView view = (TextView) getLayoutInflater().inflate(R.layout.view_details, null); if (view != null && detailsTextColor != -1) { view.setTextColor(detailsTextColor); } return view; } }); detailsSwitcher.setText(""); }
private void setupError() { errorSwitcher.setInAnimation(getAnimation(android.R.anim.slide_in_left, true)); errorSwitcher.setOutAnimation(getAnimation(android.R.anim.slide_out_right, false)); errorSwitcher.setFactory( new ViewSwitcher.ViewFactory() { @Override public View makeView() { TextView view = (TextView) getLayoutInflater().inflate(R.layout.view_error, null); if (view != null && errorTextColor != -1) { view.setTextColor(errorTextColor); } return view; } }); errorSwitcher.setText(""); }
private void setupTitle() { titleSwitcher.setInAnimation(getAnimation(R.anim.slide_in_to_bottom, true)); titleSwitcher.setOutAnimation(getAnimation(R.anim.slide_out_to_top, false)); titleSwitcher.setFactory( new ViewSwitcher.ViewFactory() { @Override public View makeView() { TextView view = (TextView) getLayoutInflater().inflate(R.layout.view_title, null); if (view != null) { view.setTextColor(titleTextColor); } return view; } }); titleSwitcher.setText(""); }
private void initializeTextViews() { textViewQuestion = (TextView) findViewById(R.id.textViewQuestion); textViewNumberOfQuestionsLeft = (TextView) findViewById(R.id.textViewNumberOfQuestionsLeft); textViewQuestionLevel = (TextView) findViewById(R.id.textViewQuestionLevel); textViewLivesLeftValue = (TextView) findViewById(R.id.textViewLivesLeftValue); textViewTimesPlayedTitle = (TextView) findViewById(R.id.textViewTimesPlayedTitle); textViewGameScoreText = (TextView) findViewById(R.id.textViewGameScoreText); textViewHowManyTimesQuestionsBeenAsked = (TextView) findViewById(R.id.textViewHowManyTimesQuestionsBeenAsked); textSwitcherTime = (TextSwitcher) findViewById(R.id.textViewTime); textSwitcherTime.setFactory(this); Animation inAnimation = AnimationUtils.loadAnimation(this, android.R.anim.fade_in); Animation outAnimation = AnimationUtils.loadAnimation(this, android.R.anim.fade_out); textSwitcherTime.setInAnimation(inAnimation); textSwitcherTime.setOutAnimation(outAnimation); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); sharedPrefs = getSharedPreferences( "com.klinker.android.twitter_world_preferences", Context.MODE_WORLD_READABLE + Context.MODE_WORLD_WRITEABLE); context = this; settings = AppSettings.getInstance(context); // context.sendBroadcast(new Intent("com.klinker.android.twitter.STOP_PUSH")); Utils.setUpTheme(context, settings); setContentView(R.layout.login_activity); setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); ConfigurationBuilder builder = new ConfigurationBuilder(); builder.setOAuthConsumerKey(settings.TWITTER_CONSUMER_KEY); builder.setOAuthConsumerSecret(settings.TWITTER_CONSUMER_SECRET); Configuration configuration = builder.build(); TwitterFactory factory = new TwitterFactory(configuration); twitter = factory.getInstance(); btnLoginTwitter = (Button) findViewById(R.id.btnLoginTwitter); noThanks = (Button) findViewById(R.id.dont_follow); title = (TextSwitcher) findViewById(R.id.welcome); summary = (TextSwitcher) findViewById(R.id.info); progDescription = (TextSwitcher) findViewById(R.id.progress_desc); progressBar = (ProgressBar) findViewById(R.id.progress_bar); main = (LinearLayout) findViewById(R.id.mainLayout); Animation in = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left); Animation out = AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right); title.setFactory( new ViewSwitcher.ViewFactory() { public View makeView() { TextView myText = new TextView(LoginActivity.this); myText.setTextSize(30); return myText; } }); // set the animation type of textSwitcher title.setInAnimation(in); title.setOutAnimation(out); summary.setFactory( new ViewSwitcher.ViewFactory() { public View makeView() { TextView myText = new TextView(LoginActivity.this); myText.setTextSize(17); return myText; } }); // set the animation type of textSwitcher summary.setInAnimation(in); summary.setOutAnimation(out); progDescription.setFactory( new ViewSwitcher.ViewFactory() { public View makeView() { TextView myText = new TextView(LoginActivity.this); myText.setTextSize(17); return myText; } }); // set the animation type of textSwitcher progDescription.setInAnimation(in); progDescription.setOutAnimation(out); title.setText(getResources().getString(R.string.first_welcome)); summary.setText(getResources().getString(R.string.first_info)); progressBar.setProgress(100); CookieSyncManager.createInstance(this); CookieManager cookieManager = CookieManager.getInstance(); cookieManager.removeAllCookie(); mWebView = (WebView) findViewById(R.id.loginWebView); try { mWebView.getSettings().setJavaScriptEnabled(true); } catch (Exception e) { } mWebView.getSettings().setAppCacheEnabled(false); mWebView.getSettings().setSavePassword(false); mWebView.getSettings().setSaveFormData(false); mWebView.setWebViewClient( new WebViewClient() { @Override public boolean shouldOverrideUrlLoading(WebView webView, String url) { Log.v("talon_login", "url: " + url); if (url != null && url.startsWith("oauth:///talonforandroid")) { handleTwitterCallback(url); } else if (url.equals("https://twitter.com/")) { webView.loadUrl(requestUrl); } else { webView.loadUrl(url); } return true; } }); noThanks.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View view) { new FollowMe().execute(); btnLoginTwitter.setText(getResources().getString(R.string.back_to_timeline)); noThanks.setVisibility(View.GONE); summary.setText(getResources().getString(R.string.third_info)); } }); btnLoginTwitter.setOnClickListener( new View.OnClickListener() { @Override public void onClick(View arg0) { // Call login_activity twitter function if (btnLoginTwitter .getText() .toString() .contains(getResources().getString(R.string.login_to_twitter))) { if (Utils.hasInternetConnection(context)) { btnLoginTwitter.setEnabled(false); new AlertDialog.Builder(context) .setMessage( "Twitter may display that Talon cannot authenticate any more users. " + "\n\n" + "If so, and you have logged into Talon in the past, simply hit the 'Sign In' button in the top right and it will allow you to log in as normal. " + "\n\n" + "If you have never logged into Talon, then you will have to wait to login. Twitter seems to allow more users access every few hours.") .setPositiveButton( R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }) .setNegativeButton( "More Info", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { startActivity( new Intent( Intent.ACTION_VIEW, Uri.parse( "https://plus.google.com/117432358268488452276/posts/KG4AcH3YA2U"))); } }) .show(); new RetreiveFeedTask().execute(); } else { Toast.makeText( context, getResources().getString(R.string.no_network) + "!", Toast.LENGTH_SHORT) .show(); } } else if (btnLoginTwitter .getText() .toString() .contains(getResources().getString(R.string.initial_sync))) { new getTimeLine().execute(); } else if (btnLoginTwitter .getText() .toString() .contains(getResources().getString(R.string.no_thanks))) { btnLoginTwitter.setText(getResources().getString(R.string.back_to_timeline)); noThanks.setVisibility(View.GONE); summary.setText(getResources().getString(R.string.third_info)); } else { if (settings.timelineRefresh != 0) { // user only wants manual AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); long now = new Date().getTime(); long alarm = now + settings.timelineRefresh; PendingIntent pendingIntent = PendingIntent.getService( context, HomeFragment.HOME_REFRESH_ID, new Intent(context, TimelineRefreshService.class), 0); am.setRepeating( AlarmManager.RTC_WAKEUP, alarm, settings.timelineRefresh, pendingIntent); now = new Date().getTime(); alarm = now + settings.mentionsRefresh; PendingIntent pendingIntent2 = PendingIntent.getService( context, MentionsFragment.MENTIONS_REFRESH_ID, new Intent(context, MentionsRefreshService.class), 0); am.setRepeating( AlarmManager.RTC_WAKEUP, alarm, settings.mentionsRefresh, pendingIntent2); alarm = now + settings.dmRefresh; PendingIntent pendingIntent3 = PendingIntent.getService( context, DMFragment.DM_REFRESH_ID, new Intent(context, DirectMessageRefreshService.class), 0); am.setRepeating(AlarmManager.RTC_WAKEUP, alarm, settings.dmRefresh, pendingIntent3); } // set up the autotrim AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); long now = new Date().getTime(); long alarm = now + AlarmManager.INTERVAL_DAY; Log.v("alarm_date", "auto trim " + new Date(alarm).toString()); PendingIntent pendingIntent = PendingIntent.getService( context, 161, new Intent(context, TrimDataService.class), 0); am.set(AlarmManager.RTC_WAKEUP, alarm, pendingIntent); finish(); Intent timeline = new Intent(context, MainActivity.class); timeline.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP); timeline.putExtra("tutorial", true); sharedPrefs.edit().putBoolean("should_refresh", false).commit(); sharedPrefs.edit().putBoolean("refresh_me", true).commit(); sharedPrefs.edit().putBoolean("refresh_me_mentions", true).commit(); sharedPrefs.edit().putBoolean("refresh_me_dm", true).commit(); sharedPrefs.edit().putBoolean("need_new_dm", false).commit(); sharedPrefs.edit().putBoolean("need_clean_databases_version_1_3_0", false).commit(); sharedPrefs.edit().putBoolean("setup_v_two", true).commit(); sharedPrefs.edit().putBoolean("version_2_2_7_1", false).commit(); AppSettings.invalidate(); startActivity(timeline); } } }); }